13#ifndef INFUSE_SDK_INCLUDE_INFUSE_EPACKET_INTERFACE_H_
14#define INFUSE_SDK_INCLUDE_INFUSE_EPACKET_INTERFACE_H_
16#include <zephyr/device.h>
17#include <zephyr/net_buf.h>
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)))
43#define EPACKET_INTERFACE_PACKET_OVERHEAD(node_id) \
44 (DT_PROP(node_id, header_size) + DT_PROP(node_id, footer_size))
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))
59#define EPACKET_INTERFACE_MAX_PAYLOAD(node_id) \
60 (EPACKET_INTERFACE_PAYLOAD_FROM_PACKET(node_id, EPACKET_INTERFACE_MAX_PACKET(node_id)))
70#define EPACKET_INTERFACE_IS_COMPILED_IN(node_id) IS_ENABLED(DT_STRING_TOKEN(node_id, depends_on))
147 void (*
send)(
const struct device *dev,
struct net_buf *buf);
316 ret = sys_slist_find_and_remove(&data->
callback_list, &cb->node);
348#define GATEWAY_HANDLER_DEFINE(name, backhaul) \
349 static void name(struct net_buf *buf) \
351 epacket_gateway_receive_handler(backhaul, buf); \
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