1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_BLE_HS_ADV_ 21 #define H_BLE_HS_ADV_ 22 23 #include <stdint.h> 24 #include "host/ble_uuid.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #define BLE_HS_ADV_MAX_SZ BLE_HCI_MAX_ADV_DATA_LEN 31 32 /** Max field payload size (account for 2-byte header). */ 33 #define BLE_HS_ADV_MAX_FIELD_SZ (BLE_HS_ADV_MAX_SZ - 2) 34 35 struct ble_hs_adv_field { 36 uint8_t length; 37 uint8_t type; 38 uint8_t value[0]; 39 }; 40 41 typedef int (* ble_hs_adv_parse_func_t)(const struct ble_hs_adv_field *, 42 void *); 43 44 struct ble_hs_adv_fields { 45 /*** 0x01 - Flags. */ 46 uint8_t flags; 47 48 /*** 0x02,0x03 - 16-bit service class UUIDs. */ 49 const ble_uuid16_t *uuids16; 50 uint8_t num_uuids16; 51 unsigned uuids16_is_complete : 1; 52 53 /*** 0x04,0x05 - 32-bit service class UUIDs. */ 54 const ble_uuid32_t *uuids32; 55 uint8_t num_uuids32; 56 unsigned uuids32_is_complete : 1; 57 58 /*** 0x06,0x07 - 128-bit service class UUIDs. */ 59 const ble_uuid128_t *uuids128; 60 uint8_t num_uuids128; 61 unsigned uuids128_is_complete : 1; 62 63 /*** 0x08,0x09 - Local name. */ 64 const uint8_t *name; 65 uint8_t name_len; 66 unsigned name_is_complete : 1; 67 68 /*** 0x0a - Tx power level. */ 69 int8_t tx_pwr_lvl; 70 unsigned tx_pwr_lvl_is_present : 1; 71 72 /*** 0x0d - Slave connection interval range. */ 73 const uint8_t *slave_itvl_range; 74 75 /*** 0x16 - Service data - 16-bit UUID. */ 76 const uint8_t *svc_data_uuid16; 77 uint8_t svc_data_uuid16_len; 78 79 /*** 0x17 - Public target address. */ 80 const uint8_t *public_tgt_addr; 81 uint8_t num_public_tgt_addrs; 82 83 /*** 0x19 - Appearance. */ 84 uint16_t appearance; 85 unsigned appearance_is_present : 1; 86 87 /*** 0x1a - Advertising interval. */ 88 uint16_t adv_itvl; 89 unsigned adv_itvl_is_present : 1; 90 91 /*** 0x20 - Service data - 32-bit UUID. */ 92 const uint8_t *svc_data_uuid32; 93 uint8_t svc_data_uuid32_len; 94 95 /*** 0x21 - Service data - 128-bit UUID. */ 96 const uint8_t *svc_data_uuid128; 97 uint8_t svc_data_uuid128_len; 98 99 /*** 0x24 - URI. */ 100 const uint8_t *uri; 101 uint8_t uri_len; 102 103 /*** 0xff - Manufacturer specific data. */ 104 const uint8_t *mfg_data; 105 uint8_t mfg_data_len; 106 }; 107 108 #define BLE_HS_ADV_TYPE_FLAGS 0x01 109 #define BLE_HS_ADV_TYPE_INCOMP_UUIDS16 0x02 110 #define BLE_HS_ADV_TYPE_COMP_UUIDS16 0x03 111 #define BLE_HS_ADV_TYPE_INCOMP_UUIDS32 0x04 112 #define BLE_HS_ADV_TYPE_COMP_UUIDS32 0x05 113 #define BLE_HS_ADV_TYPE_INCOMP_UUIDS128 0x06 114 #define BLE_HS_ADV_TYPE_COMP_UUIDS128 0x07 115 #define BLE_HS_ADV_TYPE_INCOMP_NAME 0x08 116 #define BLE_HS_ADV_TYPE_COMP_NAME 0x09 117 #define BLE_HS_ADV_TYPE_TX_PWR_LVL 0x0a 118 #define BLE_HS_ADV_TYPE_SLAVE_ITVL_RANGE 0x12 119 #define BLE_HS_ADV_TYPE_SOL_UUIDS16 0x14 120 #define BLE_HS_ADV_TYPE_SOL_UUIDS128 0x15 121 #define BLE_HS_ADV_TYPE_SVC_DATA_UUID16 0x16 122 #define BLE_HS_ADV_TYPE_PUBLIC_TGT_ADDR 0x17 123 #define BLE_HS_ADV_TYPE_RANDOM_TGT_ADDR 0x18 124 #define BLE_HS_ADV_TYPE_APPEARANCE 0x19 125 #define BLE_HS_ADV_TYPE_ADV_ITVL 0x1a 126 #define BLE_HS_ADV_TYPE_SVC_DATA_UUID32 0x20 127 #define BLE_HS_ADV_TYPE_SVC_DATA_UUID128 0x21 128 #define BLE_HS_ADV_TYPE_URI 0x24 129 #define BLE_HS_ADV_TYPE_MESH_PROV 0x29 130 #define BLE_HS_ADV_TYPE_MESH_MESSAGE 0x2a 131 #define BLE_HS_ADV_TYPE_MESH_BEACON 0x2b 132 #define BLE_HS_ADV_TYPE_MFG_DATA 0xff 133 134 #define BLE_HS_ADV_FLAGS_LEN 1 135 #define BLE_HS_ADV_F_DISC_LTD 0x01 136 #define BLE_HS_ADV_F_DISC_GEN 0x02 137 #define BLE_HS_ADV_F_BREDR_UNSUP 0x04 138 139 #define BLE_HS_ADV_TX_PWR_LVL_LEN 1 140 141 /** 142 * Set the tx_pwr_lvl field to this if you want the stack to fill in the tx 143 * power level field. 144 */ 145 #define BLE_HS_ADV_TX_PWR_LVL_AUTO (-128) 146 147 #define BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN 4 148 149 #define BLE_HS_ADV_SVC_DATA_UUID16_MIN_LEN 2 150 151 #define BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN 6 152 153 #define BLE_HS_ADV_APPEARANCE_LEN 2 154 155 #define BLE_HS_ADV_ADV_ITVL_LEN 2 156 157 #define BLE_HS_ADV_SVC_DATA_UUID32_MIN_LEN 4 158 159 #define BLE_HS_ADV_SVC_DATA_UUID128_MIN_LEN 16 160 161 int ble_hs_adv_set_fields_mbuf(const struct ble_hs_adv_fields *adv_fields, 162 struct os_mbuf *om); 163 164 int ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields, 165 uint8_t *dst, uint8_t *dst_len, uint8_t max_len); 166 167 int ble_hs_adv_parse_fields(struct ble_hs_adv_fields *adv_fields, 168 const uint8_t *src, uint8_t src_len); 169 170 int ble_hs_adv_parse(const uint8_t *data, uint8_t length, 171 ble_hs_adv_parse_func_t func, void *user_data); 172 173 #ifdef __cplusplus 174 } 175 #endif 176 177 #endif 178