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 { 28 BT_MESH_ADV_PROV, 29 BT_MESH_ADV_DATA, 30 BT_MESH_ADV_BEACON, 31 BT_MESH_ADV_URI, 32 }; 33 34 typedef void (*bt_mesh_adv_func_t)(struct os_mbuf *buf, u16_t duration, 35 int err, void *user_data); 36 37 struct bt_mesh_adv { 38 const struct bt_mesh_send_cb *cb; 39 void *cb_data; 40 41 u8_t type:2, 42 busy:1; 43 u8_t xmit; 44 45 union { 46 /* Address, used e.g. for Friend Queue messages */ 47 u16_t addr; 48 49 /* For transport layer segment sending */ 50 struct { 51 u8_t attempts; 52 } seg; 53 }; 54 55 int ref_cnt; 56 struct ble_npl_event ev; 57 }; 58 59 typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id); 60 61 /* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */ 62 struct os_mbuf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit, 63 s32_t timeout); 64 65 struct os_mbuf *bt_mesh_adv_create_from_pool(struct os_mbuf_pool *pool, 66 bt_mesh_adv_alloc_t get_id, 67 enum bt_mesh_adv_type type, 68 u8_t xmit, s32_t timeout); 69 70 void bt_mesh_adv_send(struct os_mbuf *buf, const struct bt_mesh_send_cb *cb, 71 void *cb_data); 72 73 void bt_mesh_adv_update(void); 74 75 void bt_mesh_adv_init(void); 76 77 int bt_mesh_scan_enable(void); 78 79 int bt_mesh_scan_disable(void); 80 81 int ble_adv_gap_mesh_cb(struct ble_gap_event *event, void *arg); 82 #endif 83