xref: /nrf52832-nimble/packages/NimBLE-latest/nimble/host/mesh/src/transport.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 /*  Bluetooth Mesh */
2 
3 /*
4  * Copyright (c) 2017 Intel Corporation
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include "syscfg/syscfg.h"
10 #include "mesh/mesh.h"
11 
12 #define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff
13 
14 #define BT_MESH_TX_SDU_MAX             (CONFIG_BT_MESH_TX_SEG_MAX * 12)
15 
16 #define TRANS_CTL_OP_MASK              ((u8_t)BIT_MASK(7))
17 #define TRANS_CTL_OP(data)             ((data)[0] & TRANS_CTL_OP_MASK)
18 #define TRANS_CTL_HDR(op, seg)         ((op & TRANS_CTL_OP_MASK) | (seg << 7))
19 
20 #define TRANS_CTL_OP_ACK               0x00
21 #define TRANS_CTL_OP_FRIEND_POLL       0x01
22 #define TRANS_CTL_OP_FRIEND_UPDATE     0x02
23 #define TRANS_CTL_OP_FRIEND_REQ        0x03
24 #define TRANS_CTL_OP_FRIEND_OFFER      0x04
25 #define TRANS_CTL_OP_FRIEND_CLEAR      0x05
26 #define TRANS_CTL_OP_FRIEND_CLEAR_CFM  0x06
27 #define TRANS_CTL_OP_FRIEND_SUB_ADD    0x07
28 #define TRANS_CTL_OP_FRIEND_SUB_REM    0x08
29 #define TRANS_CTL_OP_FRIEND_SUB_CFM    0x09
30 #define TRANS_CTL_OP_HEARTBEAT         0x0a
31 
32 struct bt_mesh_ctl_friend_poll {
33 	u8_t  fsn;
34 }__attribute__((__packed__));
35 
36 struct bt_mesh_ctl_friend_update {
37 	u8_t  flags;
38 	u32_t iv_index;
39 	u8_t  md;
40 }__attribute__((__packed__));
41 
42 struct bt_mesh_ctl_friend_req {
43 	u8_t  criteria;
44 	u8_t  recv_delay;
45 	u8_t  poll_to[3];
46 	u16_t prev_addr;
47 	u8_t  num_elem;
48 	u16_t lpn_counter;
49 }__attribute__((__packed__));
50 
51 struct bt_mesh_ctl_friend_offer {
52 	u8_t  recv_win;
53 	u8_t  queue_size;
54 	u8_t  sub_list_size;
55 	s8_t  rssi;
56 	u16_t frnd_counter;
57 }__attribute__((__packed__));
58 
59 struct bt_mesh_ctl_friend_clear {
60 	u16_t lpn_addr;
61 	u16_t lpn_counter;
62 }__attribute__((__packed__));
63 
64 struct bt_mesh_ctl_friend_clear_confirm {
65 	u16_t lpn_addr;
66 	u16_t lpn_counter;
67 }__attribute__((__packed__));
68 
69 #define BT_MESH_FRIEND_SUB_MIN_LEN (1 + 2)
70 struct bt_mesh_ctl_friend_sub {
71 	u8_t  xact;
72 	u16_t addr_list[5];
73 }__attribute__((__packed__));
74 
75 struct bt_mesh_ctl_friend_sub_confirm {
76 	u8_t  xact;
77 }__attribute__((__packed__));
78 
79 void bt_mesh_set_hb_sub_dst(u16_t addr);
80 
81 struct bt_mesh_app_key *bt_mesh_app_key_find(u16_t app_idx);
82 
83 bool bt_mesh_tx_in_progress(void);
84 
85 void bt_mesh_rx_reset(void);
86 void bt_mesh_tx_reset(void);
87 
88 int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
89 		     size_t data_len, u64_t *seq_auth,
90 		     const struct bt_mesh_send_cb *cb, void *cb_data);
91 
92 int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct os_mbuf *msg,
93 		       const struct bt_mesh_send_cb *cb, void *cb_data);
94 
95 int bt_mesh_trans_recv(struct os_mbuf *buf, struct bt_mesh_net_rx *rx);
96 
97 void bt_mesh_trans_init(void);
98 
99 void bt_mesh_rpl_clear(void);
100