1 /* Bluetooth Mesh */ 2 3 /* 4 * SPDX-FileCopyrightText: 2017 Intel Corporation 5 * SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD 6 * 7 * SPDX-License-Identifier: Apache-2.0 8 */ 9 10 #ifndef _TRANSPORT_H_ 11 #define _TRANSPORT_H_ 12 13 #include "net.h" 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 #define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff 20 21 #define BLE_MESH_SDU_UNSEG_MAX 11 22 #define BLE_MESH_CTL_SEG_SDU_MAX 8 23 #define BLE_MESH_APP_SEG_SDU_MAX 12 24 #define BLE_MESH_TX_SDU_MAX (CONFIG_BLE_MESH_TX_SEG_MAX * 12) 25 26 #define TRANS_SEQ_ZERO_MASK ((uint16_t)BIT_MASK(13)) 27 #define TRANS_CTL_OP_MASK ((uint8_t)BIT_MASK(7)) 28 #define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK) 29 #define TRANS_CTL_HDR(op, seg) ((op & TRANS_CTL_OP_MASK) | (seg << 7)) 30 31 #define TRANS_CTL_OP_ACK 0x00 32 #define TRANS_CTL_OP_FRIEND_POLL 0x01 33 #define TRANS_CTL_OP_FRIEND_UPDATE 0x02 34 #define TRANS_CTL_OP_FRIEND_REQ 0x03 35 #define TRANS_CTL_OP_FRIEND_OFFER 0x04 36 #define TRANS_CTL_OP_FRIEND_CLEAR 0x05 37 #define TRANS_CTL_OP_FRIEND_CLEAR_CFM 0x06 38 #define TRANS_CTL_OP_FRIEND_SUB_ADD 0x07 39 #define TRANS_CTL_OP_FRIEND_SUB_REM 0x08 40 #define TRANS_CTL_OP_FRIEND_SUB_CFM 0x09 41 #define TRANS_CTL_OP_HEARTBEAT 0x0a 42 43 struct bt_mesh_ctl_friend_poll { 44 uint8_t fsn; 45 } __packed; 46 47 struct bt_mesh_ctl_friend_update { 48 uint8_t flags; 49 uint32_t iv_index; 50 uint8_t md; 51 } __packed; 52 53 struct bt_mesh_ctl_friend_req { 54 uint8_t criteria; 55 uint8_t recv_delay; 56 uint8_t poll_to[3]; 57 uint16_t prev_addr; 58 uint8_t num_elem; 59 uint16_t lpn_counter; 60 } __packed; 61 62 struct bt_mesh_ctl_friend_offer { 63 uint8_t recv_win; 64 uint8_t queue_size; 65 uint8_t sub_list_size; 66 int8_t rssi; 67 uint16_t frnd_counter; 68 } __packed; 69 70 struct bt_mesh_ctl_friend_clear { 71 uint16_t lpn_addr; 72 uint16_t lpn_counter; 73 } __packed; 74 75 struct bt_mesh_ctl_friend_clear_confirm { 76 uint16_t lpn_addr; 77 uint16_t lpn_counter; 78 } __packed; 79 80 #define BLE_MESH_FRIEND_SUB_MIN_LEN (1 + 2) 81 struct bt_mesh_ctl_friend_sub { 82 uint8_t xact; 83 uint16_t addr_list[5]; 84 } __packed; 85 86 struct bt_mesh_ctl_friend_sub_confirm { 87 uint8_t xact; 88 } __packed; 89 90 uint8_t bt_mesh_get_seg_retrans_num(void); 91 92 int32_t bt_mesh_get_seg_retrans_timeout(uint8_t ttl); 93 94 void bt_mesh_set_hb_sub_dst(uint16_t addr); 95 96 struct bt_mesh_app_key *bt_mesh_app_key_find(uint16_t app_idx); 97 98 bool bt_mesh_tx_in_progress(void); 99 100 void bt_mesh_rx_reset(bool erase); 101 void bt_mesh_tx_reset(void); 102 void bt_mesh_rx_reset_single(uint16_t src); 103 void bt_mesh_tx_reset_single(uint16_t dst); 104 105 int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, uint8_t ctl_op, void *data, 106 size_t data_len, const struct bt_mesh_send_cb *cb, 107 void *cb_data); 108 109 int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, 110 const struct bt_mesh_send_cb *cb, void *cb_data); 111 112 int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx); 113 114 void bt_mesh_trans_init(void); 115 void bt_mesh_trans_deinit(bool erase); 116 117 bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match); 118 119 void bt_mesh_heartbeat_send(void); 120 121 int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, uint16_t app_idx, 122 const uint8_t **key, uint8_t *aid, uint8_t role, uint16_t dst); 123 124 #ifdef __cplusplus 125 } 126 #endif 127 128 #endif /* _TRANSPORT_H_ */ 129