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
12
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
35#define EPACKET_INTERFACE_MAX_PACKET(node_id) \
36 (MIN(CONFIG_EPACKET_PACKET_SIZE_MAX, \
37 DT_PROP_OR(node_id, max_packet_size, CONFIG_EPACKET_PACKET_SIZE_MAX)))
38
43#define EPACKET_INTERFACE_PACKET_OVERHEAD(node_id) \
44 (DT_PROP(node_id, header_size) + DT_PROP(node_id, footer_size))
45
51#define EPACKET_INTERFACE_PAYLOAD_FROM_PACKET(node_id, packet_size) \
52 (MIN(packet_size, CONFIG_EPACKET_PACKET_SIZE_MAX) - \
53 EPACKET_INTERFACE_PACKET_OVERHEAD(node_id))
54
59#define EPACKET_INTERFACE_MAX_PAYLOAD(node_id) \
60 (EPACKET_INTERFACE_PAYLOAD_FROM_PACKET(node_id, EPACKET_INTERFACE_MAX_PACKET(node_id)))
61
70#define EPACKET_INTERFACE_IS_COMPILED_IN(node_id) IS_ENABLED(DT_STRING_TOKEN(node_id, depends_on))
71
91
100 void (*interface_state)(uint16_t current_max_payload, void *user_ctx);
101
109 void (*tx_result)(const struct net_buf *buf, int result, void *user_ctx);
110
125 bool (*packet_received)(struct net_buf *buf, bool decrypted, void *user_ctx);
126
128 void *user_ctx;
129
131 sys_snode_t node;
133};
134
147 void (*send)(const struct device *dev, struct net_buf *buf);
158 void (*decrypt_result)(const struct device *dev, struct net_buf *buf, int decrypt_result);
168 int (*receive_ctrl)(const struct device *dev, bool enable);
178 uint16_t (*max_packet_size)(const struct device *dev);
179};
180
186typedef void (*epacket_receive_handler)(struct net_buf *packet);
187
193 struct k_work_delayable receive_timeout;
195 struct k_spinlock callback_lock;
197 sys_slist_t callback_list;
199 const struct device *dev;
200};
201
211
218void epacket_queue(const struct device *dev, struct net_buf *buf);
219
238int epacket_receive(const struct device *dev, k_timeout_t timeout);
239
249int epacket_send_key_ids(const struct device *dev, k_timeout_t timeout);
250
258static inline uint16_t epacket_interface_max_packet_size(const struct device *dev)
259{
260 const struct epacket_interface_common_config *cfg = dev->config;
261 const struct epacket_interface_api *api = dev->api;
262
263 if (api->max_packet_size) {
264 return api->max_packet_size(dev);
265 } else {
266 return cfg->max_packet_size;
267 }
268}
269
276static inline void epacket_set_receive_handler(const struct device *dev,
278{
279 struct epacket_interface_common_data *data = dev->data;
280
281 data->receive_handler = handler;
282}
283
290static inline void epacket_register_callback(const struct device *dev,
291 struct epacket_interface_cb *cb)
292{
293 struct epacket_interface_common_data *data = dev->data;
294
295 K_SPINLOCK(&data->callback_lock) {
296 sys_slist_append(&data->callback_list, &cb->node);
297 }
298}
299
309static inline bool epacket_unregister_callback(const struct device *dev,
310 struct epacket_interface_cb *cb)
311{
312 struct epacket_interface_common_data *data = dev->data;
313 bool ret = 0;
314
315 K_SPINLOCK(&data->callback_lock) {
316 ret = sys_slist_find_and_remove(&data->callback_list, &cb->node);
317 }
318
319 return ret;
320}
321
329void epacket_default_receive_handler(struct net_buf *buf);
330
340void epacket_gateway_receive_handler(const struct device *backhaul, struct net_buf *buf);
341
348#define GATEWAY_HANDLER_DEFINE(name, backhaul) \
349 static void name(struct net_buf *buf) \
350 { \
351 epacket_gateway_receive_handler(backhaul, buf); \
352 }
353
357
358#ifdef __cplusplus
359}
360#endif
361
362#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:309
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
Identifier for ePacket interface.
Definition interface.h:75
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:276
static uint16_t epacket_interface_max_packet_size(const struct device *dev)
Get current maximum packet size.
Definition interface.h:258
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:186
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:290
@ EPACKET_INTERFACE_UDP
UDP interface.
Definition interface.h:79
@ EPACKET_INTERFACE_HCI
HCI interface.
Definition interface.h:87
@ EPACKET_INTERFACE_SERIAL
Serial interface.
Definition interface.h:77
@ EPACKET_INTERFACE_BT_ADV
Bluetooth advertising interface.
Definition interface.h:81
@ EPACKET_INTERFACE_BT_PERIPHERAL
Bluetooth GATT peripheral interface.
Definition interface.h:83
@ EPACKET_INTERFACE_BT_CENTRAL
Bluetooth GATT central interface.
Definition interface.h:85
@ EPACKET_INTERFACE_DUMMY
Dummy interface for testing.
Definition interface.h:89
ePacket interface driver API
Definition interface.h:138
uint16_t(* max_packet_size)(const struct device *dev)
Get current maximum packet size.
Definition interface.h:178
void(* send)(const struct device *dev, struct net_buf *buf)
Send a packet over the interface.
Definition interface.h:147
int(* receive_ctrl)(const struct device *dev, bool enable)
Control receiving on the interface.
Definition interface.h:168
void(* decrypt_result)(const struct device *dev, struct net_buf *buf, int decrypt_result)
Callback for packet decryption result.
Definition interface.h:158
ePacket interface callback structure.
Definition interface.h:93
bool(* packet_received)(struct net_buf *buf, bool decrypted, void *user_ctx)
A packet was received on the interface.
Definition interface.h:125
void(* interface_state)(uint16_t current_max_payload, void *user_ctx)
The interface connection state has changed.
Definition interface.h:100
void * user_ctx
User provided context pointer.
Definition interface.h:128
void(* tx_result)(const struct net_buf *buf, int result, void *user_ctx)
The interface attempted to transmit a packet.
Definition interface.h:109
Common config struct for all interfaces.
Definition interface.h:203
uint16_t max_packet_size
Maximum packet size on the interface.
Definition interface.h:205
uint8_t footer_size
Size of the interface footer on each packet.
Definition interface.h:209
uint8_t header_size
Size of the interface header on each packet.
Definition interface.h:207
Common data struct for all interfaces.
Definition interface.h:189
epacket_receive_handler receive_handler
Handler run on packets received on the interface.
Definition interface.h:191
const struct device * dev
Interface device this data belongs to.
Definition interface.h:199
struct k_work_delayable receive_timeout
Work item that disables receiving at the end of an epacket_receive window.
Definition interface.h:193
sys_slist_t callback_list
List of registered epacket_interface_cb callbacks.
Definition interface.h:197
struct k_spinlock callback_lock
Lock protecting epacket_interface_common_data::callback_list.
Definition interface.h:195