1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /* Maximum advertising data payload for a single data type */
8 #define BT_MESH_ADV_DATA_SIZE 29
9 
10 /* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
11 #define BT_MESH_ADV_USER_DATA_SIZE 4
12 
13 #define BT_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf))
14 
15 #define BT_MESH_ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5)
16 #define BT_MESH_SCAN_INTERVAL_MS 30
17 #define BT_MESH_SCAN_WINDOW_MS   30
18 
19 enum bt_mesh_adv_type {
20 	BT_MESH_ADV_PROV,
21 	BT_MESH_ADV_DATA,
22 	BT_MESH_ADV_BEACON,
23 	BT_MESH_ADV_URI,
24 
25 	BT_MESH_ADV_TYPES,
26 };
27 
28 enum bt_mesh_adv_tag {
29 	BT_MESH_LOCAL_ADV = BIT(0),
30 	BT_MESH_RELAY_ADV = BIT(1),
31 	BT_MESH_PROXY_ADV = BIT(2),
32 	BT_MESH_FRIEND_ADV = BIT(3),
33 };
34 
35 struct bt_mesh_adv {
36 	const struct bt_mesh_send_cb *cb;
37 	void *cb_data;
38 
39 	uint8_t      type:2,
40 		  started:1,
41 		  busy:1,
42 		  tag:4;
43 
44 	uint8_t      xmit;
45 };
46 
47 /* Lookup table for Advertising data types for bt_mesh_adv_type: */
48 extern const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES];
49 
50 /* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */
51 struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type,
52 				   enum bt_mesh_adv_tag tag,
53 				   uint8_t xmit, k_timeout_t timeout);
54 
55 void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
56 		      void *cb_data);
57 
58 struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout);
59 
60 struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout);
61 
62 void bt_mesh_adv_gatt_update(void);
63 
64 void bt_mesh_adv_buf_get_cancel(void);
65 
66 void bt_mesh_adv_init(void);
67 
68 int bt_mesh_scan_enable(void);
69 
70 int bt_mesh_scan_disable(void);
71 
72 int bt_mesh_adv_enable(void);
73 
74 void bt_mesh_adv_buf_local_ready(void);
75 
76 void bt_mesh_adv_buf_relay_ready(void);
77 
78 void bt_mesh_adv_buf_friend_ready(void);
79 
80 int bt_mesh_adv_gatt_send(void);
81 
82 int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int32_t duration,
83 			   const struct bt_data *ad, size_t ad_len,
84 			   const struct bt_data *sd, size_t sd_len);
85 
86 void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv);
87 
88 int bt_mesh_scan_active_set(bool active);
89 
90 int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_interval,
91 			     const struct bt_data *ad, size_t ad_len);
92