zephyr/subsys/bluetooth/mesh/transport.h
Trond Einar Snekvik 824c2ebc58 Bluetooth: Mesh: Slab based segmentation handling
Allocates segmented message buffers as slabs in a common pool for RX and
TX. This reduces memory requirements for both TX and RX, as TX messages
can be stored without the network and advertising buffer overhead, and
RX can use only the slabs it needs, instead of allocating a full size
segmented message. This approach also removes the need for decrypting
the segments for each retransmission, reducing overall processing load.

Slab based segmentation for tx also introduces queuing of segmented
messages, which allows the application layer to send multiple messages
to the same destination without violating Bluetooth Mesh specification
v1.0.1, section 3.6.4.1. This mechanism is provided through a flag that
blocks segmented messages to a destination which a message is already
being sent to until the previous message finishes.

This changes the SDU size configuration to a symmetrical
RX_SEG_MAX/TX_SEG_MAX pair of configurations, plus a new segment pool
side configuration. It also removes the binding between the TX_SEG_MAX
config and the advertising buffers, reducing the minimum advertising
buffer count from 6 to 3.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-19 15:54:26 +02:00

108 lines
2.8 KiB
C

/* Bluetooth Mesh */
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff
#define BT_MESH_SDU_UNSEG_MAX 11
#define BT_MESH_CTL_SEG_SDU_MAX 8
#define BT_MESH_APP_SEG_SDU_MAX 12
#define BT_MESH_TX_SDU_MAX (CONFIG_BT_MESH_TX_SEG_MAX * BT_MESH_APP_SEG_SDU_MAX)
#define BT_MESH_RX_SDU_MAX (CONFIG_BT_MESH_RX_SEG_MAX * BT_MESH_APP_SEG_SDU_MAX)
#define BT_MESH_RX_CTL_MAX (CONFIG_BT_MESH_RX_SEG_MAX * BT_MESH_CTL_SEG_SDU_MAX)
#define TRANS_SEQ_ZERO_MASK ((u16_t)BIT_MASK(13))
#define TRANS_CTL_OP_MASK ((u8_t)BIT_MASK(7))
#define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK)
#define TRANS_CTL_HDR(op, seg) ((op & TRANS_CTL_OP_MASK) | (seg << 7))
#define TRANS_CTL_OP_ACK 0x00
#define TRANS_CTL_OP_FRIEND_POLL 0x01
#define TRANS_CTL_OP_FRIEND_UPDATE 0x02
#define TRANS_CTL_OP_FRIEND_REQ 0x03
#define TRANS_CTL_OP_FRIEND_OFFER 0x04
#define TRANS_CTL_OP_FRIEND_CLEAR 0x05
#define TRANS_CTL_OP_FRIEND_CLEAR_CFM 0x06
#define TRANS_CTL_OP_FRIEND_SUB_ADD 0x07
#define TRANS_CTL_OP_FRIEND_SUB_REM 0x08
#define TRANS_CTL_OP_FRIEND_SUB_CFM 0x09
#define TRANS_CTL_OP_HEARTBEAT 0x0a
struct bt_mesh_ctl_friend_poll {
u8_t fsn;
} __packed;
struct bt_mesh_ctl_friend_update {
u8_t flags;
u32_t iv_index;
u8_t md;
} __packed;
struct bt_mesh_ctl_friend_req {
u8_t criteria;
u8_t recv_delay;
u8_t poll_to[3];
u16_t prev_addr;
u8_t num_elem;
u16_t lpn_counter;
} __packed;
struct bt_mesh_ctl_friend_offer {
u8_t recv_win;
u8_t queue_size;
u8_t sub_list_size;
s8_t rssi;
u16_t frnd_counter;
} __packed;
struct bt_mesh_ctl_friend_clear {
u16_t lpn_addr;
u16_t lpn_counter;
} __packed;
struct bt_mesh_ctl_friend_clear_confirm {
u16_t lpn_addr;
u16_t lpn_counter;
} __packed;
#define BT_MESH_FRIEND_SUB_MIN_LEN (1 + 2)
struct bt_mesh_ctl_friend_sub {
u8_t xact;
u16_t addr_list[5];
} __packed;
struct bt_mesh_ctl_friend_sub_confirm {
u8_t xact;
} __packed;
void bt_mesh_set_hb_sub_dst(u16_t addr);
struct bt_mesh_app_key *bt_mesh_app_key_find(u16_t app_idx);
bool bt_mesh_tx_in_progress(void);
void bt_mesh_rx_reset(void);
void bt_mesh_tx_reset(void);
int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
size_t data_len, const struct bt_mesh_send_cb *cb,
void *cb_data);
int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data);
int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx);
void bt_mesh_trans_init(void);
void bt_mesh_rpl_clear(void);
void bt_mesh_heartbeat_send(void);
int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,
u16_t addr, const u8_t **key, u8_t *aid);