• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "mesh/mesh.h"
14 
15 #define BT_MESH_ADV(om) (*(struct bt_mesh_adv **) OS_MBUF_USRHDR(om))
16 
17 #define BT_MESH_ADV_DATA_SIZE 31
18 
19 /* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
20 #define BT_MESH_ADV_USER_DATA_SIZE (sizeof(struct bt_mesh_adv *))
21 
22 #define BT_MESH_MBUF_HEADER_SIZE (sizeof(struct os_mbuf_pkthdr) + \
23                                     BT_MESH_ADV_USER_DATA_SIZE +  \
24                     sizeof(struct os_mbuf))
25 
26 enum bt_mesh_adv_type {
27     BT_MESH_ADV_PROV,
28     BT_MESH_ADV_DATA,
29     BT_MESH_ADV_BEACON,
30     BT_MESH_ADV_URI,
31 };
32 
33 typedef void (*bt_mesh_adv_func_t)(struct os_mbuf *buf, u16_t duration,
34                                    int err, void *user_data);
35 
36 struct bt_mesh_adv {
37     const struct bt_mesh_send_cb *cb;
38     void *cb_data;
39 
40     u8_t      type : 2,
41               busy : 1;
42     u8_t      xmit;
43 
44     /* For transport layer segment sending */
45     struct {
46         u8_t attempts;
47     } seg;
48 
49     u8_t flags;
50 
51     int ref_cnt;
52     struct ble_npl_event ev;
53 };
54 
55 typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
56 
57 /* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */
58 struct os_mbuf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
59                                    s32_t timeout);
60 
61 struct os_mbuf *bt_mesh_adv_create_from_pool(struct os_mbuf_pool *pool,
62     bt_mesh_adv_alloc_t get_id,
63     enum bt_mesh_adv_type type,
64     u8_t xmit, s32_t timeout);
65 
66 void bt_mesh_adv_send(struct os_mbuf *buf, const struct bt_mesh_send_cb *cb,
67                       void *cb_data);
68 
69 void bt_mesh_adv_update(void);
70 
71 void bt_mesh_adv_init(void);
72 
73 int bt_mesh_scan_enable(void);
74 
75 int bt_mesh_scan_disable(void);
76 
77 int ble_adv_gap_mesh_cb(struct ble_gap_event *event, void *arg);
78 #endif