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
28
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_result)(const struct net_buf *buf, int result, 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);
126 void (*decrypt_result)(const struct device *dev, struct net_buf *buf, int decrypt_result);
136 int (*receive_ctrl)(const struct device *dev, bool enable);
146 uint16_t (*max_packet_size)(const struct device *dev);
147};
148
154typedef void (*epacket_receive_handler)(struct net_buf *packet);
155
159 struct k_work_delayable receive_timeout;
160 struct k_spinlock callback_lock;
161 sys_slist_t callback_list;
162 const struct device *dev;
163};
164
171
178void epacket_queue(const struct device *dev, struct net_buf *buf);
179
198int epacket_receive(const struct device *dev, k_timeout_t timeout);
199
209int epacket_send_key_ids(const struct device *dev, k_timeout_t timeout);
210
218static inline uint16_t epacket_interface_max_packet_size(const struct device *dev)
219{
220 const struct epacket_interface_common_config *cfg = dev->config;
221 const struct epacket_interface_api *api = dev->api;
222
223 if (api->max_packet_size) {
224 return api->max_packet_size(dev);
225 } else {
226 return cfg->max_packet_size;
227 }
228}
229
236static inline void epacket_set_receive_handler(const struct device *dev,
238{
239 struct epacket_interface_common_data *data = dev->data;
240
241 data->receive_handler = handler;
242}
243
250static inline void epacket_register_callback(const struct device *dev,
251 struct epacket_interface_cb *cb)
252{
253 struct epacket_interface_common_data *data = dev->data;
254
255 K_SPINLOCK(&data->callback_lock) {
256 sys_slist_append(&data->callback_list, &cb->node);
257 }
258}
259
269static inline bool epacket_unregister_callback(const struct device *dev,
270 struct epacket_interface_cb *cb)
271{
272 struct epacket_interface_common_data *data = dev->data;
273 bool ret = 0;
274
275 K_SPINLOCK(&data->callback_lock) {
276 ret = sys_slist_find_and_remove(&data->callback_list, &cb->node);
277 }
278
279 return ret;
280}
281
289void epacket_default_receive_handler(struct net_buf *buf);
290
300void epacket_gateway_receive_handler(const struct device *backhaul, struct net_buf *buf);
301
308#define GATEWAY_HANDLER_DEFINE(name, backhaul) \
309 static void name(struct net_buf *buf) \
310 { \
311 epacket_gateway_receive_handler(backhaul, buf); \
312 }
313
317
318#ifdef __cplusplus
319}
320#endif
321
322#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:269
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:236
static uint16_t epacket_interface_max_packet_size(const struct device *dev)
Get current maximum packet size.
Definition interface.h:218
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:154
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:250
@ 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:146
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:136
void(* decrypt_result)(const struct device *dev, struct net_buf *buf, int decrypt_result)
Callback for packet decryption result.
Definition interface.h:126
ePacket interface callback structure.
Definition interface.h:66
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
void(* tx_result)(const struct net_buf *buf, int result, void *user_ctx)
The interface attempted to transmit a packet.
Definition interface.h:82
Common config struct for all interfaces.
Definition interface.h:166
uint16_t max_packet_size
Definition interface.h:167
uint8_t footer_size
Definition interface.h:169
uint8_t header_size
Definition interface.h:168
Common data struct for all interfaces.
Definition interface.h:157
epacket_receive_handler receive_handler
Definition interface.h:158
const struct device * dev
Definition interface.h:162
struct k_work_delayable receive_timeout
Definition interface.h:159
sys_slist_t callback_list
Definition interface.h:161
struct k_spinlock callback_lock
Definition interface.h:160