Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
interface.h
Go to the documentation of this file.
1
13#ifndef INFUSE_SDK_INCLUDE_INFUSE_EPACKET_INTERFACE_H_
14#define INFUSE_SDK_INCLUDE_INFUSE_EPACKET_INTERFACE_H_
15
16#include <zephyr/device.h>
17#include <zephyr/net_buf.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
29/* Maximum packet size on an interface, limited by CONFIG_EPACKET_PACKET_SIZE_MAX */
30#define EPACKET_INTERFACE_MAX_PACKET(node_id) \
31 (MIN(CONFIG_EPACKET_PACKET_SIZE_MAX, \
32 DT_PROP_OR(node_id, max_packet_size, CONFIG_EPACKET_PACKET_SIZE_MAX)))
33/* Overhead of the interface on packet size */
34#define EPACKET_INTERFACE_PACKET_OVERHEAD(node_id) \
35 (DT_PROP(node_id, header_size) + DT_PROP(node_id, footer_size))
36/* Get the maximum payload size for a given packet size */
37#define EPACKET_INTERFACE_PAYLOAD_FROM_PACKET(node_id, packet_size) \
38 (MIN(packet_size, CONFIG_EPACKET_PACKET_SIZE_MAX) - \
39 EPACKET_INTERFACE_PACKET_OVERHEAD(node_id))
40/* Maximum payload size on an interface */
41#define EPACKET_INTERFACE_MAX_PAYLOAD(node_id) \
42 (EPACKET_INTERFACE_PAYLOAD_FROM_PACKET(node_id, EPACKET_INTERFACE_MAX_PACKET(node_id)))
43
52#define EPACKET_INTERFACE_IS_COMPILED_IN(node_id) IS_ENABLED(DT_STRING_TOKEN(node_id, depends_on))
53
54/* Identifier for ePacket interface */
64
73 void (*interface_state)(uint16_t current_max_payload, void *user_ctx);
74
82 void (*tx_failure)(const struct net_buf *buf, int reason, void *user_ctx);
83
98 bool (*packet_received)(struct net_buf *buf, bool decrypted, void *user_ctx);
99
100 /* User provided context pointer */
101 void *user_ctx;
102
103 sys_snode_t node;
104};
105
115 void (*send)(const struct device *dev, struct net_buf *buf);
125 void (*decrypt_result)(const struct device *dev, struct net_buf *buf, int decrypt_result);
135 int (*receive_ctrl)(const struct device *dev, bool enable);
145 uint16_t (*max_packet_size)(const struct device *dev);
146};
147
153typedef void (*epacket_receive_handler)(struct net_buf *packet);
154
158 struct k_work_delayable receive_timeout;
159 struct k_spinlock callback_lock;
160 sys_slist_t callback_list;
161 const struct device *dev;
162};
163
170
177void epacket_queue(const struct device *dev, struct net_buf *buf);
178
197int epacket_receive(const struct device *dev, k_timeout_t timeout);
198
208int epacket_send_key_ids(const struct device *dev, k_timeout_t timeout);
209
217static inline uint16_t epacket_interface_max_packet_size(const struct device *dev)
218{
219 const struct epacket_interface_common_config *cfg = dev->config;
220 const struct epacket_interface_api *api = dev->api;
221
222 if (api->max_packet_size) {
223 return api->max_packet_size(dev);
224 } else {
225 return cfg->max_packet_size;
226 }
227}
228
235static inline void epacket_set_receive_handler(const struct device *dev,
237{
238 struct epacket_interface_common_data *data = dev->data;
239
240 data->receive_handler = handler;
241}
242
249static inline void epacket_register_callback(const struct device *dev,
250 struct epacket_interface_cb *cb)
251{
252 struct epacket_interface_common_data *data = dev->data;
253
254 K_SPINLOCK(&data->callback_lock) {
255 sys_slist_append(&data->callback_list, &cb->node);
256 }
257}
258
268static inline bool epacket_unregister_callback(const struct device *dev,
269 struct epacket_interface_cb *cb)
270{
271 struct epacket_interface_common_data *data = dev->data;
272 bool ret = 0;
273
274 K_SPINLOCK(&data->callback_lock) {
275 ret = sys_slist_find_and_remove(&data->callback_list, &cb->node);
276 }
277
278 return ret;
279}
280
288void epacket_default_receive_handler(struct net_buf *buf);
289
299void epacket_gateway_receive_handler(const struct device *backhaul, struct net_buf *buf);
300
307#define GATEWAY_HANDLER_DEFINE(name, backhaul) \
308 static void name(struct net_buf *buf) \
309 { \
310 epacket_gateway_receive_handler(backhaul, buf); \
311 }
312
317#ifdef __cplusplus
318}
319#endif
320
321#endif /* INFUSE_SDK_INCLUDE_INFUSE_EPACKET_INTERFACE_H_ */
static bool epacket_unregister_callback(const struct device *dev, struct epacket_interface_cb *cb)
Unregister from interface events.
Definition interface.h:268
int epacket_send_key_ids(const struct device *dev, k_timeout_t timeout)
Send a INFUSE_KEY_IDS packet on an interface.
epacket_interface_id
Definition interface.h:55
static void epacket_set_receive_handler(const struct device *dev, epacket_receive_handler handler)
Set the ePacket receive handler for an interface.
Definition interface.h:235
static uint16_t epacket_interface_max_packet_size(const struct device *dev)
Get current maximum packet size.
Definition interface.h:217
void epacket_gateway_receive_handler(const struct device *backhaul, struct net_buf *buf)
Default gateway receive handler.
void epacket_default_receive_handler(struct net_buf *buf)
Default ePacket receive handler.
void epacket_queue(const struct device *dev, struct net_buf *buf)
Queue an ePacket for sending over an interface.
void(* epacket_receive_handler)(struct net_buf *packet)
Callback to run on received packet.
Definition interface.h:153
int epacket_receive(const struct device *dev, k_timeout_t timeout)
Enable receiving on the interface for a duration.
static void epacket_register_callback(const struct device *dev, struct epacket_interface_cb *cb)
Register to be notified of interface events.
Definition interface.h:249
@ EPACKET_INTERFACE_UDP
Definition interface.h:57
@ EPACKET_INTERFACE_HCI
Definition interface.h:61
@ EPACKET_INTERFACE_SERIAL
Definition interface.h:56
@ EPACKET_INTERFACE_BT_ADV
Definition interface.h:58
@ EPACKET_INTERFACE_BT_PERIPHERAL
Definition interface.h:59
@ EPACKET_INTERFACE_BT_CENTRAL
Definition interface.h:60
@ EPACKET_INTERFACE_DUMMY
Definition interface.h:62
Definition interface.h:106
uint16_t(* max_packet_size)(const struct device *dev)
Get current maximum packet size.
Definition interface.h:145
void(* send)(const struct device *dev, struct net_buf *buf)
Send a packet over the interface.
Definition interface.h:115
int(* receive_ctrl)(const struct device *dev, bool enable)
Control receiving on the interface.
Definition interface.h:135
void(* decrypt_result)(const struct device *dev, struct net_buf *buf, int decrypt_result)
Callback for packet decryption result.
Definition interface.h:125
ePacket interface callback structure.
Definition interface.h:66
void(* tx_failure)(const struct net_buf *buf, int reason, void *user_ctx)
A packet failed to transmit on the interface.
Definition interface.h:82
sys_snode_t node
Definition interface.h:103
bool(* packet_received)(struct net_buf *buf, bool decrypted, void *user_ctx)
A packet was received on the interface.
Definition interface.h:98
void(* interface_state)(uint16_t current_max_payload, void *user_ctx)
The interface connection state has changed.
Definition interface.h:73
void * user_ctx
Definition interface.h:101
Common config struct for all interfaces.
Definition interface.h:165
uint16_t max_packet_size
Definition interface.h:166
uint8_t footer_size
Definition interface.h:168
uint8_t header_size
Definition interface.h:167
Common data struct for all interfaces.
Definition interface.h:156
epacket_receive_handler receive_handler
Definition interface.h:157
const struct device * dev
Definition interface.h:161
struct k_work_delayable receive_timeout
Definition interface.h:158
sys_slist_t callback_list
Definition interface.h:160
struct k_spinlock callback_lock
Definition interface.h:159