Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1
12
13#ifndef INFUSE_SDK_INCLUDE_INFUSE_EPACKET_PACKET_H_
14#define INFUSE_SDK_INCLUDE_INFUSE_EPACKET_PACKET_H_
15
16#include <stdint.h>
17
18#include <zephyr/kernel.h>
19#include <zephyr/device.h>
20#include <zephyr/toolchain.h>
21#include <zephyr/net_buf.h>
22#include <zephyr/bluetooth/bluetooth.h>
23
24#include <infuse/security_ids.h>
25#include <infuse/types.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
38
52
58 bt_addr_le_t bluetooth;
59};
60
62#define EPACKET_ADDR_ALL ((union epacket_interface_address){0})
63
72typedef void (*epacket_tx_done_cb)(const struct device *dev, struct net_buf *pkt, int result,
73 void *user_data);
74
79#ifdef CONFIG_EPACKET_BUFFERS_TX_DELAYABLE_WORK
81 struct k_work_delayable dwork;
82#endif
84 const struct device *interface;
96 uint16_t flags;
98 uint16_t sequence;
101};
102
132
151
155#define EPACKET_KEY_ID_REQ_MAGIC 0x4D
156
160 uint8_t device_key_id[3];
161} __packed;
162
164#define EPACKET_RATE_LIMIT_REQ_MAGIC 0x4E
165
169 uint8_t magic;
171 uint8_t delay_ms;
172} __packed;
173
177 uint8_t magic;
180} __packed;
181
185 uint8_t type;
187 uint8_t addr[6];
188} __packed;
189BUILD_ASSERT(sizeof(struct epacket_interface_address_bt_le) == 7);
190
200 uint8_t rssi;
202 uint8_t interface;
203} __packed;
204
208 uint64_t device_id;
210 uint32_t gps_time;
212 uint8_t type;
214 uint16_t flags;
216 uint16_t sequence;
218 uint8_t key_id[3];
219} __packed;
220
224 uint16_t length;
226 uint8_t interface;
229} __packed;
230
244
262
266 uint8_t interface;
268 int16_t reason;
270 uint8_t address[];
271} __packed;
272
277
284void epacket_rate_limit_tx(k_ticks_t *last_call, uint16_t bytes_transmitted);
285
293void epacket_global_flags_set(uint16_t flags);
294
301
308
315
326struct net_buf *epacket_alloc_tx(k_timeout_t timeout);
327
335struct net_buf *epacket_alloc_rx(k_timeout_t timeout);
336
345static inline struct net_buf *epacket_alloc_tx_for_interface(const struct device *dev,
346 k_timeout_t timeout)
347{
348 const struct epacket_interface_common_config *config = dev->config;
349 struct net_buf *buf = epacket_alloc_tx(timeout);
350 uint16_t size;
351
352 if (buf == NULL) {
353 return NULL;
354 }
355 /* Reserve space for header */
356 net_buf_reserve(buf, config->header_size);
357 /* Limit size based on interface */
359 if (size > (config->header_size + config->footer_size)) {
360 /* Hacky reservation for footer, automatically reversed by epacket_queue */
361 buf->size = size - config->footer_size;
362 } else {
363 /* 0 payload size */
364 buf->size = config->header_size;
365 }
366 return buf;
367}
368
379static inline void epacket_set_tx_metadata_core(struct net_buf *buf, enum epacket_auth auth,
380 uint32_t key_identifier, uint16_t flags,
381 enum infuse_type type,
382 union epacket_interface_address dest)
383{
384 struct epacket_tx_metadata *meta = net_buf_user_data(buf);
385
386 meta->auth = auth;
389 meta->type = type;
390 meta->tx_done = NULL;
391 meta->interface_address = dest;
392}
393
405static inline void epacket_set_tx_metadata(struct net_buf *buf, enum epacket_auth auth,
406 uint16_t flags, enum infuse_type type,
407 union epacket_interface_address dest)
408{
409 uint32_t key_id = 0x00;
410
411 if (auth == EPACKET_AUTH_DEVICE) {
413 } else if (auth == EPACKET_AUTH_NETWORK) {
415 }
416
417 epacket_set_tx_metadata_core(buf, auth, key_id, flags, type, dest);
418}
419
427static inline void epacket_set_tx_callback(struct net_buf *buf, epacket_tx_done_cb tx_done,
428 void *user_data)
429{
430 struct epacket_tx_metadata *meta = net_buf_user_data(buf);
431
432 meta->tx_done = tx_done;
433 meta->tx_done_user_data = user_data;
434}
435
445int epacket_received_packet_append(struct net_buf *storage_buf, struct net_buf *received_buf);
446
450
451#ifdef __cplusplus
452}
453#endif
454
455#endif /* INFUSE_SDK_INCLUDE_INFUSE_EPACKET_PACKET_H_ */
epacket_interface_id
Identifier for ePacket interface.
Definition interface.h:75
static uint16_t epacket_interface_max_packet_size(const struct device *dev)
Get current maximum packet size.
Definition interface.h:258
epacket_auth
ePacket authentication levels
Definition packet.h:42
struct net_buf * epacket_alloc_tx(k_timeout_t timeout)
Allocate ePacket TX buffer.
int epacket_received_packet_append(struct net_buf *storage_buf, struct net_buf *received_buf)
Append received packet to storage buffer.
struct net_buf * epacket_alloc_rx(k_timeout_t timeout)
Allocate ePacket RX buffer.
void epacket_global_flags_set(uint16_t flags)
Set global flags for all transmitted packets.
void epacket_rate_limit_reset(void)
Reset any active rate limits.
epacket_flags
Global ePacket flags.
Definition packet.h:136
void(* epacket_tx_done_cb)(const struct device *dev, struct net_buf *pkt, int result, void *user_data)
Callback run when packet is transmitted.
Definition packet.h:72
int epacket_num_buffers_free_rx(void)
Query the number of free RX buffers.
int epacket_num_buffers_free_tx(void)
Query the number of free TX buffers.
static void epacket_set_tx_metadata(struct net_buf *buf, enum epacket_auth auth, uint16_t flags, enum infuse_type type, union epacket_interface_address dest)
Set metadata on a packet.
Definition packet.h:405
static void epacket_set_tx_metadata_core(struct net_buf *buf, enum epacket_auth auth, uint32_t key_identifier, uint16_t flags, enum infuse_type type, union epacket_interface_address dest)
Set all metadata on a packet.
Definition packet.h:379
static struct net_buf * epacket_alloc_tx_for_interface(const struct device *dev, k_timeout_t timeout)
Allocate ePacket TX buffer for a specific interface.
Definition packet.h:345
uint16_t epacket_global_flags_get(void)
Get the current global flags value.
static void epacket_set_tx_callback(struct net_buf *buf, epacket_tx_done_cb tx_done, void *user_data)
Set callback to be run after packet sent.
Definition packet.h:427
epacket_forward_auto_conn_flags
Flags for epacket_forward_auto_conn_header::flags.
Definition packet.h:234
void epacket_rate_limit_tx(k_ticks_t *last_call, uint16_t bytes_transmitted)
Limit the transmission rate of bulk data paths.
@ EPACKET_AUTH_NETWORK
Packet is encrypted with a network key.
Definition packet.h:48
@ EPACKET_AUTH_DEVICE
Packet is encrypted with a device key.
Definition packet.h:50
@ EPACKET_AUTH_FAILURE
Packet failed to decrypt.
Definition packet.h:44
@ EPACKET_AUTH_REMOTE_ENCRYPTED
Packet is encrypted for remote device.
Definition packet.h:46
@ EPACKET_FLAGS_ENCRYPTION_NETWORK
Bit 15: Encryption type is network key.
Definition packet.h:140
@ EPACKET_FLAGS_CLOUD_SELF
Bit 12: Device sends its own data to the cloud.
Definition packet.h:146
@ EPACKET_FLAGS_ENCRYPTION_DEVICE
Bit 15: Encryption type is device key.
Definition packet.h:138
@ EPACKET_FLAGS_INTERFACE_MASK
Bits 0-7: Interface specific.
Definition packet.h:149
@ EPACKET_FLAGS_ACK_REQUEST
Bit 14: Transmitting device requests an ACK.
Definition packet.h:142
@ EPACKET_FLAGS_CLOUD_FORWARDING
Bit 13: Device can forward data to the cloud.
Definition packet.h:144
@ EPACKET_FORWARD_AUTO_CONN_DC_NOTIFICATION
Send a INFUSE_EPACKET_CONN_TERMINATED on connection terminated.
Definition packet.h:240
@ EPACKET_FORWARD_AUTO_CONN_SUB_DATA
Subscribe to data while connected.
Definition packet.h:238
@ EPACKET_FORWARD_AUTO_CONN_PRIORITISE_UPLINK
Prioritise uplink throughput to the connection associated with this request.
Definition packet.h:242
@ EPACKET_FORWARD_AUTO_CONN_SINGLE_RPC
Automatically disconnect on the first received INFUSE_RPC_RSP.
Definition packet.h:236
uint32_t infuse_security_network_key_identifier(void)
Get the current network key identifier.
uint32_t infuse_security_device_key_identifier(void)
Get the current device key identifier.
infuse_type
Core Infuse Data Types.
Definition types.h:27
Core Infuse-IoT platform types.
ePacket Interface API
Infuse Platform Security Identifiers.
Packet for INFUSE_EPACKET_CONN_TERMINATED.
Definition packet.h:264
uint8_t interface
Value from epacket_interface_id.
Definition packet.h:266
int16_t reason
Reason that interface disconnected.
Definition packet.h:268
uint8_t address[]
Interface address that disconnected.
Definition packet.h:270
Common header for INFUSE_EPACKET_FORWARD_AUTO_CONN.
Definition packet.h:246
uint8_t conn_timeout
Connection timeout (seconds)
Definition packet.h:254
uint8_t conn_idle_timeout
Connection idle timeout (seconds)
Definition packet.h:256
uint8_t destination_payload[]
Destination interface address + packet bytes.
Definition packet.h:260
uint8_t interface
Value from epacket_interface_id.
Definition packet.h:250
uint8_t conn_absolute_timeout
Unconditional connection timeout (seconds)
Definition packet.h:258
uint8_t flags
Flags from epacket_forward_auto_conn_flags.
Definition packet.h:252
uint16_t length
Total length of this header + payload.
Definition packet.h:248
Common header for INFUSE_EPACKET_FORWARD.
Definition packet.h:222
uint8_t destination_payload[]
Destination interface address + packet bytes.
Definition packet.h:228
uint16_t length
Total length of this header + payload.
Definition packet.h:224
uint8_t interface
Value from epacket_interface_id.
Definition packet.h:226
Format of BLE address in INFUSE_RECEIVED_EPACKET and INFUSE_EPACKET_FORWARD.
Definition packet.h:183
uint8_t type
Bluetooth LE address type.
Definition packet.h:185
uint8_t addr[6]
Bluetooth LE address value.
Definition packet.h:187
Common config struct for all interfaces.
Definition interface.h:203
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
Format of INFUSE_KEY_IDS packet.
Definition packet.h:158
uint8_t device_key_id[3]
24 bit device key identifier
Definition packet.h:160
Magic two byte packet that requests a pause in data transmission.
Definition packet.h:167
uint8_t magic
EPACKET_RATE_LIMIT_REQ_MAGIC
Definition packet.h:169
uint8_t delay_ms
Duration to pause transmission for.
Definition packet.h:171
Magic three byte packet that sets a target data throughput.
Definition packet.h:175
uint16_t target_throughput_kbps
Target data throughput in kilobits/sec.
Definition packet.h:179
uint8_t magic
EPACKET_RATE_LIMIT_REQ_MAGIC
Definition packet.h:177
Common header for INFUSE_RECEIVED_EPACKET.
Definition packet.h:192
uint8_t rssi
Received packet signal strength, negated (0 - val)
Definition packet.h:200
uint8_t interface
Value from epacket_interface_id.
Definition packet.h:202
uint16_t len_encrypted
Bit 15: 1 when packet is still encrypted, 0 when packet is decrypted Bits 0-14: Total length of heade...
Definition packet.h:198
Header for INFUSE_RECEIVED_EPACKET where packet was decrypted.
Definition packet.h:206
uint16_t sequence
Sequence number.
Definition packet.h:216
uint16_t flags
Packet flags (epacket_flags)
Definition packet.h:214
uint8_t type
Packet type.
Definition packet.h:212
uint64_t device_id
Device ID in the packet.
Definition packet.h:208
uint32_t gps_time
GPS time in the packet.
Definition packet.h:210
uint8_t key_id[3]
ID associated with the key.
Definition packet.h:218
Metadata for packets that have been received.
Definition packet.h:106
enum infuse_type type
Type of packet.
Definition packet.h:118
uint16_t flags
Flags associated with packet (epacket_flags)
Definition packet.h:120
k_ticks_t rx_timestamp
Local time packet was received (ticks)
Definition packet.h:110
uint32_t key_identifier
Key ID used by packet.
Definition packet.h:114
enum epacket_auth auth
Authentication level of packet.
Definition packet.h:116
uint32_t packet_gps_time
GPS time in packet.
Definition packet.h:112
uint16_t sequence
Sequence number of packet.
Definition packet.h:130
uint64_t packet_device_id
Device ID in packet.
Definition packet.h:108
int16_t rssi
RSSI of packet (0 = 0dBm, 20 = 20dBm, etc)
Definition packet.h:128
union epacket_interface_address interface_address
Interface specific address.
Definition packet.h:126
const struct device * interface
ePacket interface packet was received on
Definition packet.h:122
enum epacket_interface_id interface_id
Numerical ID for interface.
Definition packet.h:124
Metadata for packets that will be transmitted.
Definition packet.h:78
epacket_tx_done_cb tx_done
Callback run when TX completes.
Definition packet.h:86
enum infuse_type type
Packet type.
Definition packet.h:92
enum epacket_auth auth
Authentication level of packet.
Definition packet.h:90
union epacket_interface_address interface_address
Interface specific address.
Definition packet.h:100
uint16_t flags
Flags to apply to packet (epacket_flags)
Definition packet.h:96
uint32_t key_identifier
Key identifier to use to encrypt packet for the auth level.
Definition packet.h:94
const struct device * interface
ePacket interface packet will be transmitted on
Definition packet.h:84
uint16_t sequence
Sequence number used for packet.
Definition packet.h:98
void * tx_done_user_data
Context provided to epacket_tx_metadata::tx_done.
Definition packet.h:88
Interface specific addresses.
Definition packet.h:56
bt_addr_le_t bluetooth
Bluetooth LE address.
Definition packet.h:58