1 /*  Bluetooth Mesh */
2 
3 /*
4  * Copyright (c) 2017 Intel Corporation
5  * Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 #ifndef _ADV_H_
11 #define _ADV_H_
12 
13 #include "mesh_access.h"
14 #include "mesh_bearer_adapt.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /* Maximum advertising data payload for a single data type */
21 #define BLE_MESH_ADV_DATA_SIZE 29
22 
23 /* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
24 #define BLE_MESH_ADV_USER_DATA_SIZE 4
25 
26 #define BLE_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf))
27 
28 typedef struct bt_mesh_msg {
29     bool  relay;        /* Flag indicates if the packet is a relayed one */
30     void *arg;          /* Pointer to the struct net_buf */
31     uint16_t src;       /* Source address for relay packets */
32     uint16_t dst;       /* Destination address for relay packets */
33     uint32_t timestamp; /* Timestamp recorded when the relay packet is posted to queue */
34 } bt_mesh_msg_t;
35 
36 enum bt_mesh_adv_type {
37     BLE_MESH_ADV_PROV,
38     BLE_MESH_ADV_DATA,
39     BLE_MESH_ADV_BEACON,
40     BLE_MESH_ADV_URI,
41     BLE_MESH_ADV_BLE,
42 };
43 
44 struct bt_mesh_adv {
45     const struct bt_mesh_send_cb *cb;
46     void *cb_data;
47 
48     uint8_t type:3,
49             busy:1;
50     uint8_t xmit;
51 };
52 
53 typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
54 
55 /* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */
56 struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
57                                    int32_t timeout);
58 
59 typedef enum {
60     BLE_MESH_BUF_REF_EQUAL,
61     BLE_MESH_BUF_REF_SMALL,
62     BLE_MESH_BUF_REF_MAX,
63 } bt_mesh_buf_ref_flag_t;
64 
65 void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
66                                uint8_t ref_cmp, bt_mesh_buf_ref_flag_t flag);
67 
68 struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
69                                              bt_mesh_adv_alloc_t get_id,
70                                              enum bt_mesh_adv_type type,
71                                              uint8_t xmit, int32_t timeout);
72 
73 void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool);
74 
75 void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
76                       void *cb_data);
77 
78 struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
79                                          int32_t timeout);
80 
81 void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
82                             void *cb_data, uint16_t src, uint16_t dst);
83 
84 uint16_t bt_mesh_get_stored_relay_count(void);
85 
86 void bt_mesh_adv_update(void);
87 
88 void bt_mesh_adv_init(void);
89 void bt_mesh_adv_deinit(void);
90 
91 #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
92 int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param,
93                                   const struct bt_mesh_ble_adv_data *data, uint8_t *index);
94 
95 int bt_mesh_stop_ble_advertising(uint8_t index);
96 #endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* _ADV_H_ */
103