NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
adv.h
1/* Bluetooth Mesh */
2
3/*
4 * Copyright (c) 2017 Intel Corporation
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9#ifndef __ADV_H__
10#define __ADV_H__
11
12/* Maximum advertising data payload for a single data type */
13#include "../include/mesh/mesh.h"
14
15#define BT_MESH_ADV(om) (*(struct bt_mesh_adv **) OS_MBUF_USRHDR(om))
16
17#define BT_MESH_ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5)
18#define BT_MESH_SCAN_INTERVAL_MS 30
19#define BT_MESH_SCAN_WINDOW_MS 30
20
21#define BT_MESH_ADV_DATA_SIZE 31
22
23/* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
24#define BT_MESH_ADV_USER_DATA_SIZE 4
25
26#define BT_MESH_MBUF_HEADER_SIZE (sizeof(struct os_mbuf_pkthdr) + \
27 BT_MESH_ADV_USER_DATA_SIZE +\
28 sizeof(struct os_mbuf))
29
30/* We declare it as extern here to share it between 'adv' and 'adv_legacy' */
31extern struct os_mbuf_pool adv_os_mbuf_pool;
32extern struct ble_npl_eventq bt_mesh_adv_queue;
33extern struct os_mempool adv_buf_mempool;
34extern os_membuf_t adv_buf_mem[];
35
36enum bt_mesh_adv_type
37{
38 BT_MESH_ADV_PROV,
39 BT_MESH_ADV_DATA,
40 BT_MESH_ADV_BEACON,
41 BT_MESH_ADV_URI,
42
43 BT_MESH_ADV_TYPES,
44};
45
46typedef void (*bt_mesh_adv_func_t)(struct os_mbuf *buf, uint16_t duration,
47 int err, void *user_data);
48
49
50static inline void adv_send_start(uint16_t duration, int err,
51 const struct bt_mesh_send_cb *cb,
52 void *cb_data)
53{
54 if (cb && cb->start) {
55 cb->start(duration, err, cb_data);
56 }
57}
58
59struct bt_mesh_adv {
61 struct os_mbuf *frags;
62
63 const struct bt_mesh_send_cb *cb;
64 void *cb_data;
65
66 uint8_t type:2,
67 started:1,
68 busy:1;
69
70 uint8_t xmit;
71
72 uint8_t flags;
73
74 int ref_cnt;
75 struct ble_npl_event ev;
76};
77
78typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
79
80/* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */
81struct os_mbuf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
82 int32_t timeout);
83
84struct os_mbuf *bt_mesh_adv_create_from_pool(struct os_mbuf_pool *pool,
85 bt_mesh_adv_alloc_t get_id,
86 enum bt_mesh_adv_type type,
87 uint8_t xmit, int32_t timeout);
88
89void bt_mesh_adv_send(struct os_mbuf *buf, const struct bt_mesh_send_cb *cb,
90 void *cb_data);
91
92void bt_mesh_adv_update(void);
93
94void bt_mesh_adv_init(void);
95
96int bt_mesh_scan_enable(void);
97
98int bt_mesh_scan_disable(void);
99int bt_mesh_adv_enable(void);
100
101void bt_mesh_adv_buf_ready(void);
102
103int bt_mesh_adv_start(const struct ble_gap_adv_params *param, int32_t duration,
104 const struct bt_data *ad, size_t ad_len,
105 const struct bt_data *sd, size_t sd_len);
106
107static inline void bt_mesh_adv_send_start(uint16_t duration, int err,
108 struct bt_mesh_adv *adv)
109{
110 if (!adv->started) {
111 adv->started = 1;
112
113 if (adv->cb && adv->cb->start) {
114 adv->cb->start(duration, err, adv->cb_data);
115 }
116
117 if (err) {
118 adv->cb = NULL;
119 }
120 }
121}
122
123static inline void bt_mesh_adv_send_end(
124 int err, struct bt_mesh_adv const *adv)
125{
126 if (adv->started && adv->cb && adv->cb->end) {
127 adv->cb->end(err, adv->cb_data);
128 }
129}
130int ble_adv_gap_mesh_cb(struct ble_gap_event *event, void *arg);
131#endif
Definition ble_gap.h:220
Definition ble_gap.h:510
Definition glue.h:334
Definition os_mbuf.h:52
Definition os_mbuf.h:86
Definition os_mempool.h:57