Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of X_NUCLEO_IDB0XA1 by
bluenrg_gap_aci.c
00001 /******************** (C) COPYRIGHT 2014 STMicroelectronics ******************** 00002 * File Name : bluenrg_hci.c 00003 * Author : AMS - HEA&RF BU 00004 * Version : V1.0.0 00005 * Date : 4-Oct-2013 00006 * Description : File with HCI commands for BlueNRG FW6.0 and above. 00007 ******************************************************************************** 00008 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00009 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 00010 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 00012 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 00013 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00014 *******************************************************************************/ 00015 00016 #include "ble_hal_types.h" 00017 #include "ble_osal.h" 00018 #include "ble_status.h" 00019 #include "ble_hal.h" 00020 #include "ble_osal.h" 00021 #include "ble_hci_const.h" 00022 #include "bluenrg_aci_const.h" 00023 #include "bluenrg_gap_aci.h" 00024 #include "bluenrg_gatt_server.h" 00025 #include "bluenrg_gap.h" 00026 00027 #define MIN(a,b) ((a) < (b) )? (a) : (b) 00028 #define MAX(a,b) ((a) > (b) )? (a) : (b) 00029 00030 tBleStatus aci_gap_init_IDB05A1(uint8_t role, uint8_t privacy_enabled, uint8_t device_name_char_len, uint16_t* service_handle, uint16_t* dev_name_char_handle, uint16_t* appearance_char_handle) 00031 { 00032 struct hci_request rq; 00033 gap_init_cp_IDB05A1 cp; 00034 gap_init_rp resp; 00035 00036 cp.role = role; 00037 cp.privacy_enabled = privacy_enabled; 00038 cp.device_name_char_len = device_name_char_len; 00039 00040 Osal_MemSet(&resp, 0, sizeof(resp)); 00041 00042 Osal_MemSet(&rq, 0, sizeof(rq)); 00043 rq.ogf = OGF_VENDOR_CMD; 00044 rq.ocf = OCF_GAP_INIT; 00045 rq.cparam = &cp; 00046 rq.clen = sizeof(cp); 00047 rq.rparam = &resp; 00048 rq.rlen = GAP_INIT_RP_SIZE; 00049 00050 if (hci_send_req(&rq, FALSE) < 0) 00051 return BLE_STATUS_TIMEOUT; 00052 00053 if (resp.status) { 00054 return resp.status; 00055 } 00056 00057 *service_handle = btohs(resp.service_handle); 00058 *dev_name_char_handle = btohs(resp.dev_name_char_handle); 00059 *appearance_char_handle = btohs(resp.appearance_char_handle); 00060 00061 return 0; 00062 } 00063 tBleStatus aci_gap_init_IDB04A1(uint8_t role, uint16_t* service_handle, uint16_t* dev_name_char_handle, uint16_t* appearance_char_handle) 00064 { 00065 struct hci_request rq; 00066 gap_init_cp_IDB04A1 cp; 00067 gap_init_rp resp; 00068 00069 cp.role = role; 00070 00071 Osal_MemSet(&resp, 0, sizeof(resp)); 00072 00073 Osal_MemSet(&rq, 0, sizeof(rq)); 00074 rq.ogf = OGF_VENDOR_CMD; 00075 rq.ocf = OCF_GAP_INIT; 00076 rq.cparam = &cp; 00077 rq.clen = sizeof(cp); 00078 rq.rparam = &resp; 00079 rq.rlen = GAP_INIT_RP_SIZE; 00080 00081 if (hci_send_req(&rq, FALSE) < 0) 00082 return BLE_STATUS_TIMEOUT; 00083 00084 if (resp.status) { 00085 return resp.status; 00086 } 00087 00088 *service_handle = btohs(resp.service_handle); 00089 *dev_name_char_handle = btohs(resp.dev_name_char_handle); 00090 *appearance_char_handle = btohs(resp.appearance_char_handle); 00091 00092 return 0; 00093 } 00094 00095 tBleStatus aci_gap_set_non_discoverable(void) 00096 { 00097 struct hci_request rq; 00098 uint8_t status; 00099 00100 Osal_MemSet(&rq, 0, sizeof(rq)); 00101 rq.ogf = OGF_VENDOR_CMD; 00102 rq.ocf = OCF_GAP_SET_NON_DISCOVERABLE; 00103 rq.rparam = &status; 00104 rq.rlen = 1; 00105 00106 if (hci_send_req(&rq, FALSE) < 0) 00107 return BLE_STATUS_TIMEOUT; 00108 00109 return status; 00110 } 00111 00112 tBleStatus aci_gap_set_limited_discoverable(uint8_t AdvType, uint16_t AdvIntervMin, uint16_t AdvIntervMax, 00113 uint8_t OwnAddrType, uint8_t AdvFilterPolicy, uint8_t LocalNameLen, 00114 const char *LocalName, uint8_t ServiceUUIDLen, uint8_t* ServiceUUIDList, 00115 uint16_t SlaveConnIntervMin, uint16_t SlaveConnIntervMax) 00116 { 00117 struct hci_request rq; 00118 uint8_t status; 00119 uint8_t buffer[40]; 00120 uint8_t indx = 0; 00121 00122 if((unsigned int)(LocalNameLen+ServiceUUIDLen+14) > sizeof(buffer)) 00123 return BLE_STATUS_INVALID_PARAMS; 00124 00125 buffer[indx] = AdvType; 00126 indx++; 00127 00128 AdvIntervMin = htobs(AdvIntervMin); 00129 Osal_MemCpy(buffer + indx, &AdvIntervMin, 2); 00130 indx += 2; 00131 00132 AdvIntervMax = htobs(AdvIntervMax); 00133 Osal_MemCpy(buffer + indx, &AdvIntervMax, 2); 00134 indx += 2; 00135 00136 buffer[indx] = OwnAddrType; 00137 indx++; 00138 00139 buffer[indx] = AdvFilterPolicy; 00140 indx++; 00141 00142 buffer[indx] = LocalNameLen; 00143 indx++; 00144 00145 Osal_MemCpy(buffer + indx, LocalName, LocalNameLen); 00146 indx += LocalNameLen; 00147 00148 buffer[indx] = ServiceUUIDLen; 00149 indx++; 00150 00151 Osal_MemCpy(buffer + indx, ServiceUUIDList, ServiceUUIDLen); 00152 indx += ServiceUUIDLen; 00153 00154 Osal_MemCpy(buffer + indx, &SlaveConnIntervMin, 2); 00155 indx += 2; 00156 00157 Osal_MemCpy(buffer + indx, &SlaveConnIntervMax, 2); 00158 indx += 2; 00159 00160 Osal_MemSet(&rq, 0, sizeof(rq)); 00161 rq.ogf = OGF_VENDOR_CMD; 00162 rq.ocf = OCF_GAP_SET_LIMITED_DISCOVERABLE; 00163 rq.cparam = (void *)buffer; 00164 rq.clen = indx; 00165 rq.event = EVT_CMD_STATUS; 00166 rq.rparam = &status; 00167 rq.rlen = 1; 00168 00169 if (hci_send_req(&rq, FALSE) < 0) 00170 return BLE_STATUS_TIMEOUT; 00171 00172 return status; 00173 } 00174 00175 tBleStatus aci_gap_set_discoverable(uint8_t AdvType, uint16_t AdvIntervMin, uint16_t AdvIntervMax, 00176 uint8_t OwnAddrType, uint8_t AdvFilterPolicy, uint8_t LocalNameLen, 00177 const char *LocalName, uint8_t ServiceUUIDLen, uint8_t* ServiceUUIDList, 00178 uint16_t SlaveConnIntervMin, uint16_t SlaveConnIntervMax) 00179 { 00180 struct hci_request rq; 00181 uint8_t status; 00182 uint8_t buffer[40]; 00183 uint8_t indx = 0; 00184 00185 if ((unsigned int)(LocalNameLen+ServiceUUIDLen+14) > sizeof(buffer)) 00186 return BLE_STATUS_INVALID_PARAMS; 00187 00188 buffer[indx] = AdvType; 00189 indx++; 00190 00191 AdvIntervMin = htobs(AdvIntervMin); 00192 Osal_MemCpy(buffer + indx, &AdvIntervMin, 2); 00193 indx += 2; 00194 00195 AdvIntervMax = htobs(AdvIntervMax); 00196 Osal_MemCpy(buffer + indx, &AdvIntervMax, 2); 00197 indx += 2; 00198 00199 buffer[indx] = OwnAddrType; 00200 indx++; 00201 00202 buffer[indx] = AdvFilterPolicy; 00203 indx++; 00204 00205 buffer[indx] = LocalNameLen; 00206 indx++; 00207 00208 Osal_MemCpy(buffer + indx, LocalName, LocalNameLen); 00209 indx += LocalNameLen; 00210 00211 buffer[indx] = ServiceUUIDLen; 00212 indx++; 00213 00214 Osal_MemCpy(buffer + indx, ServiceUUIDList, ServiceUUIDLen); 00215 indx += ServiceUUIDLen; 00216 00217 SlaveConnIntervMin = htobs(SlaveConnIntervMin); 00218 Osal_MemCpy(buffer + indx, &SlaveConnIntervMin, 2); 00219 indx += 2; 00220 00221 SlaveConnIntervMax = htobs(SlaveConnIntervMax); 00222 Osal_MemCpy(buffer + indx, &SlaveConnIntervMax, 2); 00223 indx += 2; 00224 00225 Osal_MemSet(&rq, 0, sizeof(rq)); 00226 rq.ogf = OGF_VENDOR_CMD; 00227 rq.ocf = OCF_GAP_SET_DISCOVERABLE; 00228 rq.cparam = (void *)buffer; 00229 rq.clen = indx; 00230 rq.rparam = &status; 00231 rq.rlen = 1; 00232 00233 if (hci_send_req(&rq, FALSE) < 0) 00234 return BLE_STATUS_TIMEOUT; 00235 00236 if (status) { 00237 return status; 00238 } 00239 00240 return 0; 00241 } 00242 00243 tBleStatus aci_gap_set_direct_connectable_IDB05A1(uint8_t own_addr_type, uint8_t directed_adv_type, uint8_t initiator_addr_type, const uint8_t *initiator_addr) 00244 { 00245 struct hci_request rq; 00246 gap_set_direct_conectable_cp_IDB05A1 cp; 00247 uint8_t status; 00248 00249 cp.own_bdaddr_type = own_addr_type; 00250 cp.directed_adv_type = directed_adv_type; 00251 cp.direct_bdaddr_type = initiator_addr_type; 00252 Osal_MemCpy(cp.direct_bdaddr, initiator_addr, 6); 00253 00254 Osal_MemSet(&rq, 0, sizeof(rq)); 00255 rq.ogf = OGF_VENDOR_CMD; 00256 rq.ocf = OCF_GAP_SET_DIRECT_CONNECTABLE; 00257 rq.cparam = &cp; 00258 rq.clen = sizeof(cp); 00259 rq.rparam = &status; 00260 rq.rlen = 1; 00261 00262 if (hci_send_req(&rq, FALSE) < 0) 00263 return BLE_STATUS_TIMEOUT; 00264 00265 return status; 00266 } 00267 00268 tBleStatus aci_gap_set_direct_connectable_IDB04A1(uint8_t own_addr_type, uint8_t initiator_addr_type, const uint8_t *initiator_addr) 00269 { 00270 struct hci_request rq; 00271 gap_set_direct_conectable_cp_IDB04A1 cp; 00272 uint8_t status; 00273 00274 cp.own_bdaddr_type = own_addr_type; 00275 cp.direct_bdaddr_type = initiator_addr_type; 00276 Osal_MemCpy(cp.direct_bdaddr, initiator_addr, 6); 00277 00278 Osal_MemSet(&rq, 0, sizeof(rq)); 00279 rq.ogf = OGF_VENDOR_CMD; 00280 rq.ocf = OCF_GAP_SET_DIRECT_CONNECTABLE; 00281 rq.cparam = &cp; 00282 rq.clen = sizeof(cp); 00283 rq.rparam = &status; 00284 rq.rlen = 1; 00285 00286 if (hci_send_req(&rq, FALSE) < 0) 00287 return BLE_STATUS_TIMEOUT; 00288 00289 return status; 00290 } 00291 00292 tBleStatus aci_gap_set_io_capability(uint8_t io_capability) 00293 { 00294 struct hci_request rq; 00295 uint8_t status; 00296 gap_set_io_capability_cp cp; 00297 00298 cp.io_capability = io_capability; 00299 00300 Osal_MemSet(&rq, 0, sizeof(rq)); 00301 rq.ogf = OGF_VENDOR_CMD; 00302 rq.ocf = OCF_GAP_SET_IO_CAPABILITY; 00303 rq.cparam = &cp; 00304 rq.clen = sizeof(cp); 00305 rq.rparam = &status; 00306 rq.rlen = 1; 00307 00308 if (hci_send_req(&rq, FALSE) < 0) 00309 return BLE_STATUS_TIMEOUT; 00310 00311 return status; 00312 } 00313 00314 tBleStatus aci_gap_set_auth_requirement(uint8_t mitm_mode, 00315 uint8_t oob_enable, 00316 uint8_t oob_data[16], 00317 uint8_t min_encryption_key_size, 00318 uint8_t max_encryption_key_size, 00319 uint8_t use_fixed_pin, 00320 uint32_t fixed_pin, 00321 uint8_t bonding_mode) 00322 { 00323 struct hci_request rq; 00324 gap_set_auth_requirement_cp cp; 00325 uint8_t status; 00326 00327 cp.mitm_mode = mitm_mode; 00328 cp.oob_enable = oob_enable; 00329 Osal_MemCpy(cp.oob_data, oob_data, 16); 00330 cp.min_encryption_key_size = min_encryption_key_size; 00331 cp.max_encryption_key_size = max_encryption_key_size; 00332 cp.use_fixed_pin = use_fixed_pin; 00333 cp.fixed_pin = htobl(fixed_pin); 00334 cp.bonding_mode = bonding_mode; 00335 00336 Osal_MemSet(&rq, 0, sizeof(rq)); 00337 rq.ogf = OGF_VENDOR_CMD; 00338 rq.ocf = OCF_GAP_SET_AUTH_REQUIREMENT; 00339 rq.cparam = &cp; 00340 rq.clen = sizeof(cp); 00341 rq.rparam = &status; 00342 rq.rlen = 1; 00343 00344 if (hci_send_req(&rq, FALSE) < 0) 00345 return BLE_STATUS_TIMEOUT; 00346 00347 if (status) { 00348 return status; 00349 } 00350 00351 return 0; 00352 } 00353 00354 tBleStatus aci_gap_set_author_requirement(uint16_t conn_handle, uint8_t authorization_enable) 00355 { 00356 struct hci_request rq; 00357 gap_set_author_requirement_cp cp; 00358 uint8_t status; 00359 00360 cp.conn_handle = htobs(conn_handle); 00361 cp.authorization_enable = authorization_enable; 00362 00363 Osal_MemSet(&rq, 0, sizeof(rq)); 00364 rq.ogf = OGF_VENDOR_CMD; 00365 rq.ocf = OCF_GAP_SET_AUTHOR_REQUIREMENT; 00366 rq.cparam = &cp; 00367 rq.clen = sizeof(cp); 00368 rq.rparam = &status; 00369 rq.rlen = 1; 00370 00371 if (hci_send_req(&rq, FALSE) < 0) 00372 return BLE_STATUS_TIMEOUT; 00373 00374 return status; 00375 } 00376 00377 tBleStatus aci_gap_pass_key_response(uint16_t conn_handle, uint32_t passkey) 00378 { 00379 struct hci_request rq; 00380 gap_passkey_response_cp cp; 00381 uint8_t status; 00382 00383 cp.conn_handle = htobs(conn_handle); 00384 cp.passkey = htobl(passkey); 00385 00386 Osal_MemSet(&rq, 0, sizeof(rq)); 00387 rq.ogf = OGF_VENDOR_CMD; 00388 rq.ocf = OCF_GAP_PASSKEY_RESPONSE; 00389 rq.cparam = &cp; 00390 rq.clen = sizeof(cp); 00391 rq.event = EVT_CMD_STATUS; 00392 rq.rparam = &status; 00393 rq.rlen = 1; 00394 00395 if (hci_send_req(&rq, FALSE) < 0) 00396 return BLE_STATUS_TIMEOUT; 00397 00398 return status; 00399 } 00400 00401 tBleStatus aci_gap_authorization_response(uint16_t conn_handle, uint8_t authorize) 00402 { 00403 struct hci_request rq; 00404 gap_authorization_response_cp cp; 00405 uint8_t status; 00406 00407 cp.conn_handle = htobs(conn_handle); 00408 cp.authorize = authorize; 00409 00410 Osal_MemSet(&rq, 0, sizeof(rq)); 00411 rq.ogf = OGF_VENDOR_CMD; 00412 rq.ocf = OCF_GAP_AUTHORIZATION_RESPONSE; 00413 rq.cparam = &cp; 00414 rq.clen = sizeof(cp); 00415 rq.rparam = &status; 00416 rq.rlen = 1; 00417 00418 if (hci_send_req(&rq, FALSE) < 0) 00419 return BLE_STATUS_TIMEOUT; 00420 00421 return status; 00422 } 00423 00424 tBleStatus aci_gap_set_non_connectable_IDB05A1(uint8_t adv_type, uint8_t own_address_type) 00425 { 00426 struct hci_request rq; 00427 gap_set_non_connectable_cp_IDB05A1 cp; 00428 uint8_t status; 00429 00430 cp.advertising_event_type = adv_type; 00431 cp.own_address_type = own_address_type; 00432 Osal_MemSet(&rq, 0, sizeof(rq)); 00433 rq.ogf = OGF_VENDOR_CMD; 00434 rq.ocf = OCF_GAP_SET_NON_CONNECTABLE; 00435 rq.cparam = &cp; 00436 rq.clen = sizeof(cp); 00437 rq.rparam = &status; 00438 rq.rlen = 1; 00439 00440 if (hci_send_req(&rq, FALSE) < 0) 00441 return BLE_STATUS_TIMEOUT; 00442 00443 return status; 00444 } 00445 00446 tBleStatus aci_gap_set_non_connectable_IDB04A1(uint8_t adv_type) 00447 { 00448 struct hci_request rq; 00449 gap_set_non_connectable_cp_IDB04A1 cp; 00450 uint8_t status; 00451 00452 cp.advertising_event_type = adv_type; 00453 00454 Osal_MemSet(&rq, 0, sizeof(rq)); 00455 rq.ogf = OGF_VENDOR_CMD; 00456 rq.ocf = OCF_GAP_SET_NON_CONNECTABLE; 00457 rq.cparam = &cp; 00458 rq.clen = sizeof(cp); 00459 rq.rparam = &status; 00460 rq.rlen = 1; 00461 00462 if (hci_send_req(&rq, FALSE) < 0) 00463 return BLE_STATUS_TIMEOUT; 00464 00465 return status; 00466 } 00467 00468 tBleStatus aci_gap_set_undirected_connectable(uint8_t own_addr_type, uint8_t adv_filter_policy) 00469 { 00470 struct hci_request rq; 00471 gap_set_undirected_connectable_cp cp; 00472 uint8_t status; 00473 00474 cp.own_addr_type = own_addr_type; 00475 cp.adv_filter_policy = adv_filter_policy; 00476 00477 Osal_MemSet(&rq, 0, sizeof(rq)); 00478 rq.ogf = OGF_VENDOR_CMD; 00479 rq.ocf = OCF_GAP_SET_UNDIRECTED_CONNECTABLE; 00480 rq.cparam = &cp; 00481 rq.clen = sizeof(cp); 00482 rq.rparam = &status; 00483 rq.rlen = 1; 00484 00485 if (hci_send_req(&rq, FALSE) < 0) 00486 return BLE_STATUS_TIMEOUT; 00487 00488 return status; 00489 } 00490 00491 tBleStatus aci_gap_slave_security_request(uint16_t conn_handle, uint8_t bonding, uint8_t mitm_protection) 00492 { 00493 struct hci_request rq; 00494 gap_slave_security_request_cp cp; 00495 uint8_t status; 00496 00497 cp.conn_handle = htobs(conn_handle); 00498 cp.bonding = bonding; 00499 cp.mitm_protection = mitm_protection; 00500 00501 Osal_MemSet(&rq, 0, sizeof(rq)); 00502 rq.ogf = OGF_VENDOR_CMD; 00503 rq.ocf = OCF_GAP_SLAVE_SECURITY_REQUEST; 00504 rq.cparam = &cp; 00505 rq.clen = sizeof(cp); 00506 rq.event = EVT_CMD_STATUS; 00507 rq.rparam = &status; 00508 rq.rlen = 1; 00509 00510 if (hci_send_req(&rq, FALSE) < 0) 00511 return BLE_STATUS_TIMEOUT; 00512 00513 return status; 00514 00515 } 00516 00517 tBleStatus aci_gap_update_adv_data(uint8_t AdvLen, const uint8_t *AdvData) 00518 { 00519 struct hci_request rq; 00520 uint8_t status; 00521 uint8_t buffer[32]; 00522 uint8_t indx = 0; 00523 00524 if (AdvLen > (sizeof(buffer)-1)) 00525 return BLE_STATUS_INVALID_PARAMS; 00526 00527 buffer[indx] = AdvLen; 00528 indx++; 00529 00530 Osal_MemCpy(buffer + indx, AdvData, AdvLen); 00531 indx += AdvLen; 00532 00533 Osal_MemSet(&rq, 0, sizeof(rq)); 00534 rq.ogf = OGF_VENDOR_CMD; 00535 rq.ocf = OCF_GAP_UPDATE_ADV_DATA; 00536 rq.cparam = (void *)buffer; 00537 rq.clen = indx; 00538 rq.rparam = &status; 00539 rq.rlen = 1; 00540 00541 if (hci_send_req(&rq, FALSE) < 0) 00542 return BLE_STATUS_TIMEOUT; 00543 00544 return status; 00545 } 00546 00547 tBleStatus aci_gap_delete_ad_type(uint8_t ad_type) 00548 { 00549 struct hci_request rq; 00550 gap_delete_ad_type_cp cp; 00551 uint8_t status; 00552 00553 cp.ad_type = ad_type; 00554 00555 Osal_MemSet(&rq, 0, sizeof(rq)); 00556 rq.ogf = OGF_VENDOR_CMD; 00557 rq.ocf = OCF_GAP_DELETE_AD_TYPE; 00558 rq.cparam = &cp; 00559 rq.clen = sizeof(cp); 00560 rq.rparam = &status; 00561 rq.rlen = 1; 00562 00563 if (hci_send_req(&rq, FALSE) < 0) 00564 return BLE_STATUS_TIMEOUT; 00565 00566 return status; 00567 } 00568 00569 tBleStatus aci_gap_get_security_level(uint8_t* mitm_protection, uint8_t* bonding, 00570 uint8_t* oob_data, uint8_t* passkey_required) 00571 { 00572 struct hci_request rq; 00573 gap_get_security_level_rp resp; 00574 00575 Osal_MemSet(&resp, 0, sizeof(resp)); 00576 00577 Osal_MemSet(&rq, 0, sizeof(rq)); 00578 rq.ogf = OGF_VENDOR_CMD; 00579 rq.ocf = OCF_GAP_GET_SECURITY_LEVEL; 00580 rq.rparam = &resp; 00581 rq.rlen = GAP_GET_SECURITY_LEVEL_RP_SIZE; 00582 00583 if (hci_send_req(&rq, FALSE) < 0) 00584 return BLE_STATUS_TIMEOUT; 00585 00586 if (resp.status) { 00587 return resp.status; 00588 } 00589 00590 *mitm_protection = resp.mitm_protection; 00591 *bonding = resp.bonding; 00592 *oob_data = resp.oob_data; 00593 *passkey_required = resp.passkey_required; 00594 00595 return resp.status; 00596 } 00597 00598 tBleStatus aci_gap_configure_whitelist(void) 00599 { 00600 struct hci_request rq; 00601 uint8_t status; 00602 00603 Osal_MemSet(&rq, 0, sizeof(rq)); 00604 rq.ogf = OGF_VENDOR_CMD; 00605 rq.ocf = OCF_GAP_CONFIGURE_WHITELIST; 00606 rq.rparam = &status; 00607 rq.rlen = 1; 00608 00609 if (hci_send_req(&rq, FALSE) < 0) 00610 return BLE_STATUS_TIMEOUT; 00611 00612 return status; 00613 } 00614 00615 tBleStatus aci_gap_terminate(uint16_t conn_handle, uint8_t reason) 00616 { 00617 struct hci_request rq; 00618 gap_terminate_cp cp; 00619 uint8_t status; 00620 00621 cp.handle = htobs(conn_handle); 00622 cp.reason = reason; 00623 00624 Osal_MemSet(&rq, 0, sizeof(rq)); 00625 rq.ogf = OGF_VENDOR_CMD; 00626 rq.ocf = OCF_GAP_TERMINATE; 00627 rq.cparam = &cp; 00628 rq.clen = sizeof(cp); 00629 rq.event = EVT_CMD_STATUS; 00630 rq.rparam = &status; 00631 rq.rlen = 1; 00632 00633 if (hci_send_req(&rq, FALSE) < 0) 00634 return BLE_STATUS_TIMEOUT; 00635 00636 return status; 00637 } 00638 00639 tBleStatus aci_gap_clear_security_database(void) 00640 { 00641 struct hci_request rq; 00642 uint8_t status; 00643 00644 Osal_MemSet(&rq, 0, sizeof(rq)); 00645 rq.ogf = OGF_VENDOR_CMD; 00646 rq.ocf = OCF_GAP_CLEAR_SECURITY_DB; 00647 rq.rparam = &status; 00648 rq.rlen = 1; 00649 00650 if (hci_send_req(&rq, FALSE) < 0) 00651 return BLE_STATUS_TIMEOUT; 00652 00653 return status; 00654 } 00655 00656 tBleStatus aci_gap_allow_rebond_IDB05A1(uint16_t conn_handle) 00657 { 00658 struct hci_request rq; 00659 gap_allow_rebond_cp_IDB05A1 cp; 00660 uint8_t status; 00661 00662 cp.conn_handle = conn_handle; 00663 00664 Osal_MemSet(&rq, 0, sizeof(rq)); 00665 rq.ogf = OGF_VENDOR_CMD; 00666 rq.ocf = OCF_GAP_ALLOW_REBOND_DB; 00667 rq.cparam = &cp; 00668 rq.clen = sizeof(cp); 00669 rq.rparam = &status; 00670 rq.rlen = 1; 00671 00672 if (hci_send_req(&rq, FALSE) < 0) 00673 return BLE_STATUS_TIMEOUT; 00674 00675 return status; 00676 } 00677 tBleStatus aci_gap_allow_rebond_IDB04A1(void) 00678 { 00679 struct hci_request rq; 00680 uint8_t status; 00681 00682 Osal_MemSet(&rq, 0, sizeof(rq)); 00683 rq.ogf = OGF_VENDOR_CMD; 00684 rq.ocf = OCF_GAP_ALLOW_REBOND_DB; 00685 rq.rparam = &status; 00686 rq.rlen = 1; 00687 00688 if (hci_send_req(&rq, FALSE) < 0) 00689 return BLE_STATUS_TIMEOUT; 00690 00691 return status; 00692 } 00693 00694 tBleStatus aci_gap_start_limited_discovery_proc(uint16_t scanInterval, uint16_t scanWindow, 00695 uint8_t own_address_type, uint8_t filterDuplicates) 00696 { 00697 struct hci_request rq; 00698 gap_start_limited_discovery_proc_cp cp; 00699 uint8_t status; 00700 00701 cp.scanInterval = htobs(scanInterval); 00702 cp.scanWindow = htobs(scanWindow); 00703 cp.own_address_type = own_address_type; 00704 cp.filterDuplicates = filterDuplicates; 00705 00706 Osal_MemSet(&rq, 0, sizeof(rq)); 00707 rq.ogf = OGF_VENDOR_CMD; 00708 rq.ocf = OCF_GAP_START_LIMITED_DISCOVERY_PROC; 00709 rq.cparam = &cp; 00710 rq.clen = sizeof(cp); 00711 rq.event = EVT_CMD_STATUS; 00712 rq.rparam = &status; 00713 rq.rlen = 1; 00714 00715 if (hci_send_req(&rq, FALSE) < 0) 00716 return BLE_STATUS_TIMEOUT; 00717 00718 return status; 00719 } 00720 00721 tBleStatus aci_gap_start_general_discovery_proc(uint16_t scanInterval, uint16_t scanWindow, 00722 uint8_t own_address_type, uint8_t filterDuplicates) 00723 { 00724 struct hci_request rq; 00725 gap_start_general_discovery_proc_cp cp; 00726 uint8_t status; 00727 00728 cp.scanInterval = htobs(scanInterval); 00729 cp.scanWindow = htobs(scanWindow); 00730 cp.own_address_type = own_address_type; 00731 cp.filterDuplicates = filterDuplicates; 00732 00733 Osal_MemSet(&rq, 0, sizeof(rq)); 00734 rq.ogf = OGF_VENDOR_CMD; 00735 rq.ocf = OCF_GAP_START_GENERAL_DISCOVERY_PROC; 00736 rq.cparam = &cp; 00737 rq.clen = sizeof(cp); 00738 rq.event = EVT_CMD_STATUS; 00739 rq.rparam = &status; 00740 rq.rlen = 1; 00741 00742 if (hci_send_req(&rq, FALSE) < 0) 00743 return BLE_STATUS_TIMEOUT; 00744 00745 return status; 00746 } 00747 00748 00749 tBleStatus aci_gap_start_name_discovery_proc(uint16_t scanInterval, uint16_t scanWindow, 00750 uint8_t peer_bdaddr_type, tBDAddr peer_bdaddr, 00751 uint8_t own_bdaddr_type, uint16_t conn_min_interval, 00752 uint16_t conn_max_interval, uint16_t conn_latency, 00753 uint16_t supervision_timeout, uint16_t min_conn_length, 00754 uint16_t max_conn_length) 00755 { 00756 struct hci_request rq; 00757 gap_start_name_discovery_proc_cp cp; 00758 uint8_t status; 00759 00760 cp.scanInterval = htobs(scanInterval); 00761 cp.scanWindow = htobs(scanWindow); 00762 cp.peer_bdaddr_type = peer_bdaddr_type; 00763 Osal_MemCpy(cp.peer_bdaddr, peer_bdaddr, 6); 00764 cp.own_bdaddr_type = own_bdaddr_type; 00765 cp.conn_min_interval = htobs(conn_min_interval); 00766 cp.conn_max_interval = htobs(conn_max_interval); 00767 cp.conn_latency = htobs(conn_latency); 00768 cp.supervision_timeout = htobs(supervision_timeout); 00769 cp.min_conn_length = htobs(min_conn_length); 00770 cp.max_conn_length = htobs(max_conn_length); 00771 00772 Osal_MemSet(&rq, 0, sizeof(rq)); 00773 rq.ogf = OGF_VENDOR_CMD; 00774 rq.ocf = OCF_GAP_START_NAME_DISCOVERY_PROC; 00775 rq.cparam = &cp; 00776 rq.clen = sizeof(cp); 00777 rq.event = EVT_CMD_STATUS; 00778 rq.rparam = &status; 00779 rq.rlen = 1; 00780 00781 if (hci_send_req(&rq, FALSE) < 0) 00782 return BLE_STATUS_TIMEOUT; 00783 00784 return status; 00785 } 00786 00787 tBleStatus aci_gap_start_auto_conn_establish_proc_IDB05A1(uint16_t scanInterval, uint16_t scanWindow, 00788 uint8_t own_bdaddr_type, uint16_t conn_min_interval, 00789 uint16_t conn_max_interval, uint16_t conn_latency, 00790 uint16_t supervision_timeout, uint16_t min_conn_length, 00791 uint16_t max_conn_length, 00792 uint8_t num_whitelist_entries, 00793 const uint8_t *addr_array) 00794 { 00795 struct hci_request rq; 00796 uint8_t status; 00797 uint8_t buffer[HCI_MAX_PAYLOAD_SIZE]; 00798 uint8_t indx = 0; 00799 00800 if (((num_whitelist_entries*7)+25) > HCI_MAX_PAYLOAD_SIZE) 00801 return BLE_STATUS_INVALID_PARAMS; 00802 00803 scanInterval = htobs(scanInterval); 00804 Osal_MemCpy(buffer + indx, &scanInterval, 2); 00805 indx += 2; 00806 00807 scanWindow = htobs(scanWindow); 00808 Osal_MemCpy(buffer + indx, &scanWindow, 2); 00809 indx += 2; 00810 00811 buffer[indx] = own_bdaddr_type; 00812 indx++; 00813 00814 conn_min_interval = htobs(conn_min_interval); 00815 Osal_MemCpy(buffer + indx, &conn_min_interval, 2); 00816 indx += 2; 00817 00818 conn_max_interval = htobs(conn_max_interval); 00819 Osal_MemCpy(buffer + indx, &conn_max_interval, 2); 00820 indx += 2; 00821 00822 conn_latency = htobs(conn_latency); 00823 Osal_MemCpy(buffer + indx, &conn_latency, 2); 00824 indx += 2; 00825 00826 supervision_timeout = htobs(supervision_timeout); 00827 Osal_MemCpy(buffer + indx, &supervision_timeout, 2); 00828 indx += 2; 00829 00830 min_conn_length = htobs(min_conn_length); 00831 Osal_MemCpy(buffer + indx, &min_conn_length, 2); 00832 indx += 2; 00833 00834 max_conn_length = htobs(max_conn_length); 00835 Osal_MemCpy(buffer + indx, &max_conn_length, 2); 00836 indx += 2; 00837 00838 buffer[indx] = num_whitelist_entries; 00839 indx++; 00840 00841 Osal_MemCpy(buffer + indx, addr_array, (num_whitelist_entries*7)); 00842 indx += num_whitelist_entries * 7; 00843 00844 Osal_MemSet(&rq, 0, sizeof(rq)); 00845 rq.ogf = OGF_VENDOR_CMD; 00846 rq.ocf = OCF_GAP_START_AUTO_CONN_ESTABLISH_PROC; 00847 rq.cparam = (void *)buffer; 00848 rq.clen = indx; 00849 rq.event = EVT_CMD_STATUS; 00850 rq.rparam = &status; 00851 rq.rlen = 1; 00852 00853 if (hci_send_req(&rq, FALSE) < 0) 00854 return BLE_STATUS_TIMEOUT; 00855 00856 return status; 00857 } 00858 00859 tBleStatus aci_gap_start_auto_conn_establish_proc_IDB04A1(uint16_t scanInterval, uint16_t scanWindow, 00860 uint8_t own_bdaddr_type, uint16_t conn_min_interval, 00861 uint16_t conn_max_interval, uint16_t conn_latency, 00862 uint16_t supervision_timeout, uint16_t min_conn_length, 00863 uint16_t max_conn_length, 00864 uint8_t use_reconn_addr, 00865 const tBDAddr reconn_addr, 00866 uint8_t num_whitelist_entries, 00867 const uint8_t *addr_array) 00868 { 00869 struct hci_request rq; 00870 uint8_t status; 00871 uint8_t buffer[HCI_MAX_PAYLOAD_SIZE]; 00872 uint8_t indx = 0; 00873 00874 if (((num_whitelist_entries*7)+25) > HCI_MAX_PAYLOAD_SIZE) 00875 return BLE_STATUS_INVALID_PARAMS; 00876 00877 scanInterval = htobs(scanInterval); 00878 Osal_MemCpy(buffer + indx, &scanInterval, 2); 00879 indx += 2; 00880 00881 scanWindow = htobs(scanWindow); 00882 Osal_MemCpy(buffer + indx, &scanWindow, 2); 00883 indx += 2; 00884 00885 buffer[indx] = own_bdaddr_type; 00886 indx++; 00887 00888 conn_min_interval = htobs(conn_min_interval); 00889 Osal_MemCpy(buffer + indx, &conn_min_interval, 2); 00890 indx += 2; 00891 00892 conn_max_interval = htobs(conn_max_interval); 00893 Osal_MemCpy(buffer + indx, &conn_max_interval, 2); 00894 indx += 2; 00895 00896 conn_latency = htobs(conn_latency); 00897 Osal_MemCpy(buffer + indx, &conn_latency, 2); 00898 indx += 2; 00899 00900 supervision_timeout = htobs(supervision_timeout); 00901 Osal_MemCpy(buffer + indx, &supervision_timeout, 2); 00902 indx += 2; 00903 00904 min_conn_length = htobs(min_conn_length); 00905 Osal_MemCpy(buffer + indx, &min_conn_length, 2); 00906 indx += 2; 00907 00908 max_conn_length = htobs(max_conn_length); 00909 Osal_MemCpy(buffer + indx, &max_conn_length, 2); 00910 indx += 2; 00911 00912 buffer[indx] = use_reconn_addr; 00913 indx++; 00914 00915 Osal_MemCpy(buffer + indx, reconn_addr, 6); 00916 indx += 6; 00917 00918 buffer[indx] = num_whitelist_entries; 00919 indx++; 00920 00921 Osal_MemCpy(buffer + indx, addr_array, (num_whitelist_entries*7)); 00922 indx += num_whitelist_entries * 7; 00923 00924 Osal_MemSet(&rq, 0, sizeof(rq)); 00925 rq.ogf = OGF_VENDOR_CMD; 00926 rq.ocf = OCF_GAP_START_AUTO_CONN_ESTABLISH_PROC; 00927 rq.cparam = (void *)buffer; 00928 rq.clen = indx; 00929 rq.event = EVT_CMD_STATUS; 00930 rq.rparam = &status; 00931 rq.rlen = 1; 00932 00933 if (hci_send_req(&rq, FALSE) < 0) 00934 return BLE_STATUS_TIMEOUT; 00935 00936 return status; 00937 } 00938 00939 tBleStatus aci_gap_start_general_conn_establish_proc_IDB05A1(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window, 00940 uint8_t own_address_type, uint8_t filter_duplicates) 00941 { 00942 struct hci_request rq; 00943 gap_start_general_conn_establish_proc_cp_IDB05A1 cp; 00944 uint8_t status; 00945 00946 cp.scan_type = scan_type; 00947 cp.scan_interval = htobs(scan_interval); 00948 cp.scan_window = htobs(scan_window); 00949 cp.own_address_type = own_address_type; 00950 cp.filter_duplicates = filter_duplicates; 00951 00952 Osal_MemSet(&rq, 0, sizeof(rq)); 00953 rq.ogf = OGF_VENDOR_CMD; 00954 rq.ocf = OCF_GAP_START_GENERAL_CONN_ESTABLISH_PROC; 00955 rq.cparam = &cp; 00956 rq.clen = sizeof(cp); 00957 rq.event = EVT_CMD_STATUS; 00958 rq.rparam = &status; 00959 rq.rlen = 1; 00960 00961 if (hci_send_req(&rq, FALSE) < 0) 00962 return BLE_STATUS_TIMEOUT; 00963 00964 return status; 00965 } 00966 tBleStatus aci_gap_start_general_conn_establish_proc_IDB04A1(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window, 00967 uint8_t own_address_type, uint8_t filter_duplicates, uint8_t use_reconn_addr, const tBDAddr reconn_addr) 00968 { 00969 struct hci_request rq; 00970 gap_start_general_conn_establish_proc_cp_IDB04A1 cp; 00971 uint8_t status; 00972 00973 cp.scan_type = scan_type; 00974 cp.scan_interval = htobs(scan_interval); 00975 cp.scan_window = htobs(scan_window); 00976 cp.own_address_type = own_address_type; 00977 cp.filter_duplicates = filter_duplicates; 00978 cp.use_reconn_addr = use_reconn_addr; 00979 Osal_MemCpy(cp.reconn_addr, reconn_addr, 6); 00980 00981 Osal_MemSet(&rq, 0, sizeof(rq)); 00982 rq.ogf = OGF_VENDOR_CMD; 00983 rq.ocf = OCF_GAP_START_GENERAL_CONN_ESTABLISH_PROC; 00984 rq.cparam = &cp; 00985 rq.clen = sizeof(cp); 00986 rq.event = EVT_CMD_STATUS; 00987 rq.rparam = &status; 00988 rq.rlen = 1; 00989 00990 if (hci_send_req(&rq, FALSE) < 0) 00991 return BLE_STATUS_TIMEOUT; 00992 00993 return status; 00994 } 00995 00996 tBleStatus aci_gap_start_selective_conn_establish_proc(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window, 00997 uint8_t own_address_type, uint8_t filter_duplicates, uint8_t num_whitelist_entries, 00998 const uint8_t *addr_array) 00999 { 01000 struct hci_request rq; 01001 gap_start_selective_conn_establish_proc_cp cp; 01002 uint8_t status; 01003 01004 if (((num_whitelist_entries*7)+GAP_START_SELECTIVE_CONN_ESTABLISH_PROC_CP_SIZE) > HCI_MAX_PAYLOAD_SIZE) 01005 return BLE_STATUS_INVALID_PARAMS; 01006 01007 cp.scan_type = scan_type; 01008 cp.scan_interval = htobs(scan_interval); 01009 cp.scan_window = htobs(scan_window); 01010 cp.own_address_type = own_address_type; 01011 cp.filter_duplicates = filter_duplicates; 01012 cp.num_whitelist_entries = num_whitelist_entries; 01013 01014 Osal_MemCpy(cp.addr_array, addr_array, (num_whitelist_entries*7)); 01015 01016 Osal_MemSet(&rq, 0, sizeof(rq)); 01017 rq.ogf = OGF_VENDOR_CMD; 01018 rq.ocf = OCF_GAP_START_SELECTIVE_CONN_ESTABLISH_PROC; 01019 rq.cparam = &cp; 01020 rq.clen = GAP_START_SELECTIVE_CONN_ESTABLISH_PROC_CP_SIZE + (num_whitelist_entries*7); 01021 rq.event = EVT_CMD_STATUS; 01022 rq.rparam = &status; 01023 rq.rlen = 1; 01024 01025 if (hci_send_req(&rq, FALSE) < 0) 01026 return BLE_STATUS_TIMEOUT; 01027 01028 return status; 01029 } 01030 01031 tBleStatus aci_gap_create_connection(uint16_t scanInterval, uint16_t scanWindow, 01032 uint8_t peer_bdaddr_type, tBDAddr peer_bdaddr, 01033 uint8_t own_bdaddr_type, uint16_t conn_min_interval, 01034 uint16_t conn_max_interval, uint16_t conn_latency, 01035 uint16_t supervision_timeout, uint16_t min_conn_length, 01036 uint16_t max_conn_length) 01037 { 01038 struct hci_request rq; 01039 gap_create_connection_cp cp; 01040 uint8_t status; 01041 01042 cp.scanInterval = htobs(scanInterval); 01043 cp.scanWindow = htobs(scanWindow); 01044 cp.peer_bdaddr_type = peer_bdaddr_type; 01045 Osal_MemCpy(cp.peer_bdaddr, peer_bdaddr, 6); 01046 cp.own_bdaddr_type = own_bdaddr_type; 01047 cp.conn_min_interval = htobs(conn_min_interval); 01048 cp.conn_max_interval = htobs(conn_max_interval); 01049 cp.conn_latency = htobs(conn_latency); 01050 cp.supervision_timeout = htobs(supervision_timeout); 01051 cp.min_conn_length = htobs(min_conn_length); 01052 cp.max_conn_length = htobs(max_conn_length); 01053 01054 Osal_MemSet(&rq, 0, sizeof(rq)); 01055 rq.ogf = OGF_VENDOR_CMD; 01056 rq.ocf = OCF_GAP_CREATE_CONNECTION; 01057 rq.cparam = &cp; 01058 rq.clen = sizeof(cp); 01059 rq.event = EVT_CMD_STATUS; 01060 rq.rparam = &status; 01061 rq.rlen = 1; 01062 01063 if (hci_send_req(&rq, FALSE) < 0) 01064 return BLE_STATUS_TIMEOUT; 01065 01066 return status; 01067 } 01068 01069 tBleStatus aci_gap_terminate_gap_procedure(uint8_t procedure_code) 01070 { 01071 struct hci_request rq; 01072 uint8_t status; 01073 01074 Osal_MemSet(&rq, 0, sizeof(rq)); 01075 rq.ogf = OGF_VENDOR_CMD; 01076 rq.ocf = OCF_GAP_TERMINATE_GAP_PROCEDURE; 01077 rq.cparam = &procedure_code; 01078 rq.clen = 1; 01079 rq.rparam = &status; 01080 rq.rlen = 1; 01081 01082 if (hci_send_req(&rq, FALSE) < 0) 01083 return BLE_STATUS_TIMEOUT; 01084 01085 return status; 01086 01087 } 01088 01089 tBleStatus aci_gap_start_connection_update(uint16_t conn_handle, uint16_t conn_min_interval, 01090 uint16_t conn_max_interval, uint16_t conn_latency, 01091 uint16_t supervision_timeout, uint16_t min_conn_length, 01092 uint16_t max_conn_length) 01093 { 01094 struct hci_request rq; 01095 gap_start_connection_update_cp cp; 01096 uint8_t status; 01097 01098 cp.conn_handle = htobs(conn_handle); 01099 cp.conn_min_interval = htobs(conn_min_interval); 01100 cp.conn_max_interval = htobs(conn_max_interval); 01101 cp.conn_latency = htobs(conn_latency); 01102 cp.supervision_timeout = htobs(supervision_timeout); 01103 cp.min_conn_length = htobs(min_conn_length); 01104 cp.max_conn_length = htobs(max_conn_length); 01105 01106 Osal_MemSet(&rq, 0, sizeof(rq)); 01107 rq.ogf = OGF_VENDOR_CMD; 01108 rq.ocf = OCF_GAP_START_CONNECTION_UPDATE; 01109 rq.cparam = &cp; 01110 rq.clen = sizeof(cp); 01111 rq.event = EVT_CMD_STATUS; 01112 rq.rparam = &status; 01113 rq.rlen = 1; 01114 01115 if (hci_send_req(&rq, FALSE) < 0) 01116 return BLE_STATUS_TIMEOUT; 01117 01118 return status; 01119 } 01120 01121 tBleStatus aci_gap_send_pairing_request(uint16_t conn_handle, uint8_t force_rebond) 01122 { 01123 struct hci_request rq; 01124 gap_send_pairing_request_cp cp; 01125 uint8_t status; 01126 01127 cp.conn_handle = htobs(conn_handle); 01128 cp.force_rebond = force_rebond; 01129 01130 Osal_MemSet(&rq, 0, sizeof(rq)); 01131 rq.ogf = OGF_VENDOR_CMD; 01132 rq.ocf = OCF_GAP_SEND_PAIRING_REQUEST; 01133 rq.cparam = &cp; 01134 rq.clen = sizeof(cp); 01135 rq.event = EVT_CMD_STATUS; 01136 rq.rparam = &status; 01137 rq.rlen = 1; 01138 01139 if (hci_send_req(&rq, FALSE) < 0) 01140 return BLE_STATUS_TIMEOUT; 01141 01142 return status; 01143 } 01144 01145 tBleStatus aci_gap_resolve_private_address_IDB05A1(const tBDAddr private_address, tBDAddr actual_address) 01146 { 01147 struct hci_request rq; 01148 gap_resolve_private_address_cp cp; 01149 gap_resolve_private_address_rp rp; 01150 01151 Osal_MemCpy(cp.address, private_address, 6); 01152 01153 Osal_MemSet(&rq, 0, sizeof(rq)); 01154 rq.ogf = OGF_VENDOR_CMD; 01155 rq.ocf = OCF_GAP_RESOLVE_PRIVATE_ADDRESS; 01156 rq.cparam = &cp; 01157 rq.clen = sizeof(cp); 01158 rq.rparam = &rp; 01159 rq.rlen = sizeof(rp); 01160 01161 if (hci_send_req(&rq, FALSE) < 0) 01162 return BLE_STATUS_TIMEOUT; 01163 01164 if(rp.status) 01165 return rp.status; 01166 01167 Osal_MemCpy(actual_address, rp.address, 6); 01168 01169 return 0; 01170 } 01171 tBleStatus aci_gap_resolve_private_address_IDB04A1(const tBDAddr address) 01172 { 01173 struct hci_request rq; 01174 gap_resolve_private_address_cp cp; 01175 uint8_t status; 01176 01177 Osal_MemCpy(cp.address, address, 6); 01178 01179 Osal_MemSet(&rq, 0, sizeof(rq)); 01180 rq.ogf = OGF_VENDOR_CMD; 01181 rq.ocf = OCF_GAP_RESOLVE_PRIVATE_ADDRESS; 01182 rq.cparam = &cp; 01183 rq.clen = sizeof(cp); 01184 rq.rparam = &status; 01185 rq.rlen = 1; 01186 01187 if (hci_send_req(&rq, FALSE) < 0) 01188 return BLE_STATUS_TIMEOUT; 01189 01190 return status; 01191 } 01192 01193 tBleStatus aci_gap_set_broadcast_mode(uint16_t adv_interv_min, uint16_t adv_interv_max, uint8_t adv_type, 01194 uint8_t own_addr_type, uint8_t adv_data_length, const uint8_t *adv_data, uint8_t num_whitelist_entries, 01195 const uint8_t *addr_array) 01196 { 01197 struct hci_request rq; 01198 gap_set_broadcast_mode_cp cp; 01199 uint8_t status; 01200 uint8_t indx = 0; 01201 uint8_t variable_size = 1 + adv_data_length + 1 + num_whitelist_entries*7; 01202 01203 if (variable_size > sizeof(cp.var_len_data) ) 01204 return BLE_STATUS_INVALID_PARAMS; 01205 01206 cp.adv_interv_min = htobs(adv_interv_min); 01207 cp.adv_interv_max = htobs(adv_interv_max); 01208 cp.adv_type = adv_type; 01209 cp.own_addr_type = own_addr_type; 01210 01211 cp.var_len_data[indx] = adv_data_length; 01212 indx++; 01213 Osal_MemCpy(cp.var_len_data + indx, adv_data, adv_data_length); 01214 indx += adv_data_length; 01215 cp.var_len_data[indx] = num_whitelist_entries; 01216 indx ++; 01217 Osal_MemCpy(cp.var_len_data + indx, addr_array, num_whitelist_entries*7); 01218 01219 Osal_MemSet(&rq, 0, sizeof(rq)); 01220 rq.ogf = OGF_VENDOR_CMD; 01221 rq.ocf = OCF_GAP_SET_BROADCAST_MODE; 01222 rq.cparam = &cp; 01223 rq.clen = GAP_SET_BROADCAST_MODE_CP_SIZE + variable_size; 01224 rq.rparam = &status; 01225 rq.rlen = 1; 01226 01227 if (hci_send_req(&rq, FALSE) < 0) 01228 return BLE_STATUS_TIMEOUT; 01229 01230 return status; 01231 } 01232 01233 tBleStatus aci_gap_start_observation_procedure(uint16_t scan_interval, uint16_t scan_window, uint8_t scan_type, 01234 uint8_t own_address_type, uint8_t filter_duplicates) 01235 { 01236 struct hci_request rq; 01237 gap_start_observation_proc_cp cp; 01238 uint8_t status; 01239 01240 cp.scan_interval = scan_interval; 01241 cp.scan_window = scan_window; 01242 cp.scan_type = scan_type; 01243 cp.own_address_type = own_address_type; 01244 cp.filter_duplicates = filter_duplicates; 01245 01246 Osal_MemSet(&rq, 0, sizeof(rq)); 01247 rq.ogf = OGF_VENDOR_CMD; 01248 rq.ocf = OCF_GAP_START_OBSERVATION_PROC; 01249 rq.cparam = &cp; 01250 rq.clen = sizeof(cp); 01251 rq.event = EVT_CMD_STATUS; 01252 rq.rparam = &status; 01253 rq.rlen = 1; 01254 01255 if (hci_send_req(&rq, FALSE) < 0) 01256 return BLE_STATUS_TIMEOUT; 01257 01258 return status; 01259 } 01260 01261 tBleStatus aci_gap_is_device_bonded(uint8_t peer_address_type, const tBDAddr peer_address) 01262 { 01263 struct hci_request rq; 01264 gap_is_device_bonded_cp cp; 01265 uint8_t status; 01266 01267 cp.peer_address_type = peer_address_type; 01268 Osal_MemCpy(cp.peer_address, peer_address, sizeof(cp.peer_address)); 01269 01270 Osal_MemSet(&rq, 0, sizeof(rq)); 01271 rq.ogf = OGF_VENDOR_CMD; 01272 rq.ocf = OCF_GAP_IS_DEVICE_BONDED; 01273 rq.cparam = &cp; 01274 rq.clen = sizeof(cp); 01275 rq.rparam = &status; 01276 rq.rlen = 1; 01277 01278 if (hci_send_req(&rq, FALSE) < 0) 01279 return BLE_STATUS_TIMEOUT; 01280 01281 return status; 01282 } 01283 01284 tBleStatus aci_gap_get_bonded_devices(uint8_t *num_devices, uint8_t *device_list, uint8_t device_list_size) 01285 { 01286 struct hci_request rq; 01287 gap_get_bonded_devices_rp rp; 01288 01289 Osal_MemSet(&rq, 0, sizeof(rq)); 01290 rq.ogf = OGF_VENDOR_CMD; 01291 rq.ocf = OCF_GAP_GET_BONDED_DEVICES; 01292 rq.rparam = &rp; 01293 rq.rlen = sizeof(rp); 01294 01295 if (hci_send_req(&rq, FALSE) < 0) 01296 return BLE_STATUS_TIMEOUT; 01297 01298 if (rp.status) { 01299 return rp.status; 01300 } 01301 01302 *num_devices = rp.num_addr; 01303 if(device_list != NULL) 01304 Osal_MemCpy(device_list, rp.dev_list, MIN(device_list_size,rp.num_addr*7)); 01305 01306 return 0; 01307 }
Generated on Thu Jul 14 2022 09:39:26 by
1.7.2
