1 /* 2 * Copyright (c) 2017 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff 8 9 #define BT_MESH_SDU_UNSEG_MAX 11 10 #define BT_MESH_CTL_SEG_SDU_MAX 8 11 12 #define BT_MESH_RX_CTL_MAX MAX((BT_MESH_RX_SEG_MAX * \ 13 BT_MESH_CTL_SEG_SDU_MAX), \ 14 BT_MESH_SDU_UNSEG_MAX) 15 16 #define TRANS_SEQ_ZERO_MASK ((uint16_t)BIT_MASK(13)) 17 #define TRANS_CTL_OP_MASK ((uint8_t)BIT_MASK(7)) 18 #define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK) 19 #define TRANS_CTL_HDR(op, seg) ((op & TRANS_CTL_OP_MASK) | (seg << 7)) 20 21 #define TRANS_CTL_OP_ACK 0x00 22 #define TRANS_CTL_OP_FRIEND_POLL 0x01 23 #define TRANS_CTL_OP_FRIEND_UPDATE 0x02 24 #define TRANS_CTL_OP_FRIEND_REQ 0x03 25 #define TRANS_CTL_OP_FRIEND_OFFER 0x04 26 #define TRANS_CTL_OP_FRIEND_CLEAR 0x05 27 #define TRANS_CTL_OP_FRIEND_CLEAR_CFM 0x06 28 #define TRANS_CTL_OP_FRIEND_SUB_ADD 0x07 29 #define TRANS_CTL_OP_FRIEND_SUB_REM 0x08 30 #define TRANS_CTL_OP_FRIEND_SUB_CFM 0x09 31 #define TRANS_CTL_OP_HEARTBEAT 0x0a 32 33 struct bt_mesh_ctl_friend_poll { 34 uint8_t fsn; 35 } __packed; 36 37 struct bt_mesh_ctl_friend_update { 38 uint8_t flags; 39 uint32_t iv_index; 40 uint8_t md; 41 } __packed; 42 43 struct bt_mesh_ctl_friend_req { 44 uint8_t criteria; 45 uint8_t recv_delay; 46 uint8_t poll_to[3]; 47 uint16_t prev_addr; 48 uint8_t num_elem; 49 uint16_t lpn_counter; 50 } __packed; 51 52 struct bt_mesh_ctl_friend_offer { 53 uint8_t recv_win; 54 uint8_t queue_size; 55 uint8_t sub_list_size; 56 int8_t rssi; 57 uint16_t frnd_counter; 58 } __packed; 59 60 struct bt_mesh_ctl_friend_clear { 61 uint16_t lpn_addr; 62 uint16_t lpn_counter; 63 } __packed; 64 65 struct bt_mesh_ctl_friend_clear_confirm { 66 uint16_t lpn_addr; 67 uint16_t lpn_counter; 68 } __packed; 69 70 #define BT_MESH_FRIEND_SUB_MIN_LEN (1 + 2) 71 struct bt_mesh_ctl_friend_sub { 72 uint8_t xact; 73 uint16_t addr_list[5]; 74 } __packed; 75 76 struct bt_mesh_ctl_friend_sub_confirm { 77 uint8_t xact; 78 } __packed; 79 80 bool bt_mesh_tx_in_progress(void); 81 82 void bt_mesh_rx_reset(void); 83 84 int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, uint8_t ctl_op, void *data, 85 size_t data_len, const struct bt_mesh_send_cb *cb, 86 void *cb_data); 87 88 /** @brief Send an access payload message. 89 * 90 * @param tx Network TX parameters. Only @c ctx, @c src and @c friend_cred 91 * have to be filled. 92 * @param msg Access payload to send. 93 * @param cb Message callback. 94 * @param cb_data Message callback data. 95 * 96 * @return 0 on success, or (negative) error code otherwise. 97 */ 98 int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, 99 const struct bt_mesh_send_cb *cb, void *cb_data); 100 101 int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx); 102 103 void bt_mesh_trans_init(void); 104 void bt_mesh_trans_reset(void); 105