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_LL_ADV_ 21 #define H_BLE_LL_ADV_ 22 23 #include "syscfg/syscfg.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /* 30 * ADV event timing 31 * T_advEvent = advInterval + advDelay 32 * 33 * advInterval: increments of 625 usecs 34 * advDelay: RAND[0, 10] msecs 35 * 36 */ 37 #define BLE_LL_ADV_ITVL (625) /* usecs */ 38 #define BLE_LL_ADV_ITVL_MIN (32) /* units */ 39 #define BLE_LL_ADV_ITVL_MAX (16384) /* units */ 40 #define BLE_LL_ADV_ITVL_MS_MIN (20) /* msecs */ 41 #define BLE_LL_ADV_ITVL_MS_MAX (10240) /* msecs */ 42 #define BLE_LL_ADV_ITVL_SCAN_MIN (160) /* units */ 43 #define BLE_LL_ADV_ITVL_SCAN_MS_MIN (100) /* msecs */ 44 #define BLE_LL_ADV_ITVL_NONCONN_MS_MIN (100) /* msecs */ 45 #define BLE_LL_ADV_DELAY_MS_MIN (0) /* msecs */ 46 #define BLE_LL_ADV_DELAY_MS_MAX (10) /* msecs */ 47 #define BLE_LL_ADV_PDU_ITVL_LD_MS_MAX (10) /* msecs */ 48 #define BLE_LL_ADV_PDU_ITVL_HD_MS_MAX (3750) /* usecs */ 49 #define BLE_LL_ADV_STATE_HD_MAX (1280) /* msecs */ 50 51 /* Maximum advertisement data length */ 52 #define BLE_ADV_LEGACY_DATA_MAX_LEN (31) 53 #define BLE_ADV_LEGACY_MAX_PKT_LEN (37) 54 55 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) 56 #define BLE_ADV_DATA_MAX_LEN MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) 57 #else 58 #define BLE_ADV_DATA_MAX_LEN BLE_ADV_LEGACY_DATA_MAX_LEN 59 #endif 60 61 /* 62 * ADV_IND 63 * -> AdvA (6 bytes) 64 * -> AdvData (0 - 31 bytes) 65 * 66 * The advertising address (AdvA) is a public address (TxAdd=0) or random 67 * address (TxAdd = 1) 68 */ 69 #define BLE_ADV_IND_MIN_LEN (6) 70 #define BLE_ADV_IND_MAX_LEN (37) 71 72 /* 73 * ADV_DIRECT_IND 74 * -> AdvA (6 bytes) 75 * -> InitA (6 bytes) 76 * 77 * AdvA is the advertisers public address (TxAdd=0) or random address 78 * (TxAdd = 1). 79 * 80 * InitA is the initiators public or random address. This is the address 81 * to which this packet is addressed. 82 * 83 */ 84 #define BLE_ADV_DIRECT_IND_LEN (12) 85 86 /* 87 * ADV_NONCONN_IND 88 * -> AdvA (6 bytes) 89 * -> AdvData (0 - 31 bytes) 90 * 91 * The advertising address (AdvA) is a public address (TxAdd=0) or random 92 * address (TxAdd = 1) 93 * 94 */ 95 #define BLE_ADV_NONCONN_IND_MIN_LEN (6) 96 #define BLE_ADV_NONCONN_IND_MAX_LEN (37) 97 98 /* 99 * ADV_SCAN_IND 100 * -> AdvA (6 bytes) 101 * -> AdvData (0 - 31 bytes) 102 * 103 * The advertising address (AdvA) is a public address (TxAdd=0) or random 104 * address (TxAdd = 1) 105 * 106 */ 107 #define BLE_ADV_SCAN_IND_MIN_LEN (6) 108 #define BLE_ADV_SCAN_IND_MAX_LEN (37) 109 110 /*---- HCI ----*/ 111 struct ble_ll_adv_sm; 112 struct ble_ll_conn_sm; 113 114 /* Start an advertiser */ 115 int ble_ll_adv_start_req(uint8_t adv_chanmask, uint8_t adv_type, 116 uint8_t *init_addr, uint16_t adv_itvl, void *handle); 117 118 /* Start or stop advertising */ 119 int ble_ll_adv_set_enable(uint8_t instance, uint8_t enable, int duration, 120 uint8_t event); 121 122 /* Set advertising data */ 123 int ble_ll_adv_set_adv_data(uint8_t *cmd, uint8_t cmd_len, uint8_t instance, 124 uint8_t operation); 125 126 /* Set scan response data */ 127 int ble_ll_adv_set_scan_rsp_data(uint8_t *cmd, uint8_t cmd_len, 128 uint8_t instance, uint8_t operation); 129 130 /* Set advertising parameters */ 131 int ble_ll_adv_set_adv_params(uint8_t *cmd); 132 133 /* Read advertising channel power */ 134 int ble_ll_adv_read_txpwr(uint8_t *rspbuf, uint8_t *rsplen); 135 136 /*---- API used by BLE LL ----*/ 137 /* Send the connection complete event */ 138 void ble_ll_adv_send_conn_comp_ev(struct ble_ll_conn_sm *connsm, 139 struct ble_mbuf_hdr *rxhdr); 140 141 /* Returns local resolvable private address */ 142 uint8_t *ble_ll_adv_get_local_rpa(struct ble_ll_adv_sm *advsm); 143 144 /* Returns peer resolvable private address */ 145 uint8_t *ble_ll_adv_get_peer_rpa(struct ble_ll_adv_sm *advsm); 146 147 /* Called to initialize advertising functionality. */ 148 void ble_ll_adv_init(void); 149 150 /* Called when LL wait for response timer expires in advertising state */ 151 void ble_ll_adv_wfr_timer_exp(void); 152 153 /* Called to reset the advertiser. */ 154 void ble_ll_adv_reset(void); 155 156 /* Called on rx pdu start when in advertising state */ 157 int ble_ll_adv_rx_isr_start(uint8_t pdu_type); 158 159 /* Called on rx pdu end when in advertising state */ 160 int ble_ll_adv_rx_isr_end(uint8_t pdu_type, struct os_mbuf *rxpdu, int crcok); 161 162 /* Processes received packets at the link layer task */ 163 void ble_ll_adv_rx_pkt_in(uint8_t ptype, uint8_t *rxbuf, 164 struct ble_mbuf_hdr *hdr); 165 166 /* Boolean function denoting whether or not the whitelist can be changed */ 167 int ble_ll_adv_can_chg_whitelist(void); 168 169 /* 170 * Called when an advertising event has been removed from the scheduler 171 * without being run. 172 */ 173 void ble_ll_adv_event_rmvd_from_sched(struct ble_ll_adv_sm *advsm); 174 175 /* Called to halt currently running advertising event */ 176 void ble_ll_adv_halt(void); 177 178 /* Called to determine if advertising is enabled */ 179 uint8_t ble_ll_adv_enabled(void); 180 181 int ble_ll_adv_set_random_addr(uint8_t *addr, uint8_t instance); 182 int ble_ll_adv_remove(uint8_t instance); 183 int ble_ll_adv_clear_all(void); 184 int ble_ll_adv_ext_set_param(uint8_t *cmdbuf, uint8_t *rspbuf, uint8_t *rsplen); 185 int ble_ll_adv_ext_set_adv_data(uint8_t *cmdbuf, uint8_t cmdlen); 186 int ble_ll_adv_ext_set_scan_rsp(uint8_t *cmdbuf, uint8_t cmdlen); 187 int ble_ll_adv_ext_set_enable(uint8_t *cmdbuf, uint8_t len); 188 189 /* Called to notify adv code about RPA rotation */ 190 void ble_ll_adv_rpa_timeout(void); 191 192 #ifdef __cplusplus 193 } 194 #endif 195 196 #endif /* H_BLE_LL_ADV_ */ 197