my fork

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bluenrg_gap_aci.c Source File

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 "hal_types.h"
00017 #include "osal.h"
00018 #include "ble_status.h"
00019 #include "hal.h"
00020 #include "osal.h"
00021 #include "hci_const.h"
00022 #include "bluenrg_aci_const.h"
00023 #include "bluenrg_gap_aci.h"
00024 #include "gatt_server.h"
00025 #include "gap.h"
00026 
00027 #define MIN(a,b)            ((a) < (b) )? (a) : (b)
00028 #define MAX(a,b)            ((a) > (b) )? (a) : (b)
00029 
00030 
00031 tBleStatus aci_gap_init(uint8_t role, uint16_t* service_handle, uint16_t* dev_name_char_handle, uint16_t* appearance_char_handle)
00032 {
00033   struct hci_request rq;
00034   gap_init_cp cp;
00035   gap_init_rp resp;
00036 
00037   cp.role = role;
00038     
00039   Osal_MemSet(&resp, 0, sizeof(resp));
00040   
00041   Osal_MemSet(&rq, 0, sizeof(rq));
00042   rq.ogf = OGF_VENDOR_CMD;
00043   rq.ocf = OCF_GAP_INIT;
00044   rq.cparam = &cp;
00045   rq.clen = GAP_INIT_CP_SIZE;
00046   rq.rparam = &resp;
00047   rq.rlen = GAP_INIT_RP_SIZE;
00048   
00049   if (hci_send_req(&rq) < 0)
00050     return BLE_STATUS_TIMEOUT;
00051   
00052   if (resp.status) {
00053     return resp.status;
00054   }
00055   
00056   *service_handle = btohs(resp.service_handle);
00057   *dev_name_char_handle = btohs(resp.dev_name_char_handle);
00058   *appearance_char_handle = btohs(resp.appearance_char_handle);
00059   
00060   return 0;
00061 }
00062 
00063 tBleStatus aci_gap_set_non_discoverable(void)
00064 {
00065   struct hci_request rq;
00066   uint8_t status;
00067   
00068   Osal_MemSet(&rq, 0, sizeof(rq));
00069   rq.ogf = OGF_VENDOR_CMD;
00070   rq.ocf = OCF_GAP_SET_NON_DISCOVERABLE;
00071   rq.rparam = &status;
00072   rq.rlen = 1;
00073   
00074   if (hci_send_req(&rq) < 0)
00075     return BLE_STATUS_TIMEOUT;
00076   
00077   return status;  
00078 }
00079 
00080 tBleStatus aci_gap_set_limited_discoverable(uint8_t AdvType, uint16_t AdvIntervMin, uint16_t AdvIntervMax,
00081                         uint8_t OwnAddrType, uint8_t AdvFilterPolicy, uint8_t LocalNameLen,
00082                         const char *LocalName, uint8_t ServiceUUIDLen, uint8_t* ServiceUUIDList,
00083                         uint16_t SlaveConnIntervMin, uint16_t SlaveConnIntervMax)
00084 {
00085   struct hci_request rq;
00086   uint8_t status;    
00087   uint8_t buffer[40];
00088   uint8_t indx = 0;
00089     
00090   if ((LocalNameLen+ServiceUUIDLen+14) > sizeof(buffer))
00091     return BLE_STATUS_INVALID_PARAMS;
00092 
00093   buffer[indx] = AdvType;
00094   indx++;
00095     
00096   AdvIntervMin = htobs(AdvIntervMin);
00097   Osal_MemCpy(buffer + indx, &AdvIntervMin, 2);
00098   indx +=  2;
00099     
00100   AdvIntervMax = htobs(AdvIntervMax);
00101   Osal_MemCpy(buffer + indx, &AdvIntervMax, 2);
00102   indx +=  2;
00103     
00104   buffer[indx] = OwnAddrType;
00105   indx++;
00106     
00107   buffer[indx] = AdvFilterPolicy;
00108   indx++;
00109     
00110   buffer[indx] = LocalNameLen;
00111   indx++;
00112     
00113   Osal_MemCpy(buffer + indx, LocalName, LocalNameLen);
00114   indx +=  LocalNameLen;
00115 
00116   buffer[indx] = ServiceUUIDLen;
00117   indx++;
00118 
00119   Osal_MemCpy(buffer + indx, ServiceUUIDList, ServiceUUIDLen);
00120   indx +=  ServiceUUIDLen;
00121 
00122   Osal_MemCpy(buffer + indx, &SlaveConnIntervMin, 2);
00123   indx +=  2;
00124 
00125   Osal_MemCpy(buffer + indx, &SlaveConnIntervMax, 2);
00126   indx +=  2;    
00127 
00128   Osal_MemSet(&rq, 0, sizeof(rq));
00129   rq.ogf = OGF_VENDOR_CMD;
00130   rq.ocf = OCF_GAP_SET_LIMITED_DISCOVERABLE;
00131   rq.cparam = (void *)buffer;
00132   rq.clen = indx;
00133   rq.event = EVT_CMD_STATUS;
00134   rq.rparam = &status;
00135   rq.rlen = 1;
00136 
00137   if (hci_send_req(&rq) < 0)
00138     return BLE_STATUS_TIMEOUT;
00139 
00140   return status;
00141 }
00142 
00143 tBleStatus aci_gap_set_discoverable(uint8_t AdvType, uint16_t AdvIntervMin, uint16_t AdvIntervMax,
00144                              uint8_t OwnAddrType, uint8_t AdvFilterPolicy, uint8_t LocalNameLen,
00145                              const char *LocalName, uint8_t ServiceUUIDLen, uint8_t* ServiceUUIDList,
00146                              uint16_t SlaveConnIntervMin, uint16_t SlaveConnIntervMax)
00147 {
00148   struct hci_request rq;
00149   uint8_t status;    
00150   uint8_t buffer[40];
00151   uint8_t indx = 0;
00152   
00153   if ((LocalNameLen+ServiceUUIDLen+14) > sizeof(buffer))
00154     return BLE_STATUS_INVALID_PARAMS;
00155 
00156   buffer[indx] = AdvType;
00157   indx++;
00158   
00159   AdvIntervMin = htobs(AdvIntervMin);
00160   Osal_MemCpy(buffer + indx, &AdvIntervMin, 2);
00161   indx +=  2;
00162     
00163   AdvIntervMax = htobs(AdvIntervMax);
00164   Osal_MemCpy(buffer + indx, &AdvIntervMax, 2);
00165   indx +=  2;
00166     
00167   buffer[indx] = OwnAddrType;
00168   indx++;
00169     
00170   buffer[indx] = AdvFilterPolicy;
00171   indx++;
00172     
00173   buffer[indx] = LocalNameLen;
00174   indx++;
00175     
00176   Osal_MemCpy(buffer + indx, LocalName, LocalNameLen);
00177   indx +=  LocalNameLen;
00178   
00179   buffer[indx] = ServiceUUIDLen;
00180   indx++;
00181 
00182   Osal_MemCpy(buffer + indx, ServiceUUIDList, ServiceUUIDLen);
00183   indx +=  ServiceUUIDLen;  
00184 
00185   SlaveConnIntervMin = htobs(SlaveConnIntervMin);
00186   Osal_MemCpy(buffer + indx, &SlaveConnIntervMin, 2);
00187   indx +=  2;
00188   
00189   SlaveConnIntervMax = htobs(SlaveConnIntervMax);
00190   Osal_MemCpy(buffer + indx, &SlaveConnIntervMax, 2);
00191   indx +=  2;    
00192 
00193   Osal_MemSet(&rq, 0, sizeof(rq));
00194   rq.ogf = OGF_VENDOR_CMD;
00195   rq.ocf = OCF_GAP_SET_DISCOVERABLE;
00196   rq.cparam = (void *)buffer;
00197   rq.clen = indx;
00198   rq.rparam = &status;
00199   rq.rlen = 1;
00200 
00201   if (hci_send_req(&rq) < 0)
00202     return BLE_STATUS_TIMEOUT;
00203 
00204   if (status) {
00205     return status;
00206   }
00207 
00208   return 0;
00209 }
00210 
00211 tBleStatus aci_gap_set_direct_connectable(uint8_t own_addr_type, uint8_t initiator_addr_type, const uint8_t *initiator_addr)
00212 {
00213   struct hci_request rq;
00214   gap_set_direct_conectable_cp cp;
00215   uint8_t status;    
00216 
00217   cp.own_bdaddr_type = own_addr_type;
00218   cp.direct_bdaddr_type = initiator_addr_type;
00219   Osal_MemCpy(cp.direct_bdaddr, initiator_addr, 6);
00220 
00221   Osal_MemSet(&rq, 0, sizeof(rq));
00222   rq.ogf = OGF_VENDOR_CMD;
00223   rq.ocf = OCF_GAP_SET_DIRECT_CONNECTABLE;
00224   rq.cparam = &cp;
00225   rq.clen = GAP_SET_DIRECT_CONNECTABLE_CP_SIZE;
00226   rq.rparam = &status;
00227   rq.rlen = 1;
00228     
00229   if (hci_send_req(&rq) < 0)
00230     return BLE_STATUS_TIMEOUT;
00231     
00232   return status;
00233 }
00234 
00235 tBleStatus aci_gap_set_io_capabilitiy(uint8_t io_capability)
00236 {
00237   struct hci_request rq;
00238   uint8_t status;
00239   gap_set_io_capability_cp cp;
00240     
00241   cp.io_capability = io_capability;
00242 
00243   Osal_MemSet(&rq, 0, sizeof(rq));
00244   rq.ogf = OGF_VENDOR_CMD;
00245   rq.ocf = OCF_GAP_SET_IO_CAPABILITY;
00246   rq.cparam = &cp;
00247   rq.clen = GAP_SET_IO_CAPABILITY_CP_SIZE;
00248   rq.rparam = &status;
00249   rq.rlen = 1;
00250     
00251   if (hci_send_req(&rq) < 0)
00252     return BLE_STATUS_TIMEOUT;
00253     
00254   return status;
00255 }
00256 
00257 tBleStatus aci_gap_set_auth_requirement(uint8_t mitm_mode,
00258                                         uint8_t oob_enable,
00259                                         uint8_t oob_data[16],
00260                                         uint8_t min_encryption_key_size,
00261                                         uint8_t max_encryption_key_size,
00262                                         uint8_t use_fixed_pin,
00263                                         uint32_t fixed_pin,
00264                                         uint8_t bonding_mode)
00265 {
00266   struct hci_request rq;
00267   gap_set_auth_requirement_cp cp;    
00268   uint8_t status;
00269     
00270   cp.mitm_mode = mitm_mode;
00271   cp.oob_enable = oob_enable;
00272   Osal_MemCpy(cp.oob_data, oob_data, 16);
00273   cp.min_encryption_key_size = min_encryption_key_size;
00274   cp.max_encryption_key_size = max_encryption_key_size;
00275   cp.use_fixed_pin = use_fixed_pin;
00276   cp.fixed_pin = htobl(fixed_pin);
00277   cp.bonding_mode = bonding_mode;
00278 
00279   Osal_MemSet(&rq, 0, sizeof(rq));
00280   rq.ogf = OGF_VENDOR_CMD;
00281   rq.ocf = OCF_GAP_SET_AUTH_REQUIREMENT;
00282   rq.cparam = &cp;
00283   rq.clen = GAP_SET_AUTH_REQUIREMENT_CP_SIZE;
00284   rq.rparam = &status;
00285   rq.rlen = 1;
00286 
00287   if (hci_send_req(&rq) < 0)
00288     return BLE_STATUS_TIMEOUT;
00289 
00290   if (status) {
00291     return status;
00292   }
00293     
00294   return 0;
00295 }
00296 
00297 tBleStatus aci_gap_set_author_requirement(uint16_t conn_handle, uint8_t authorization_enable)
00298 {
00299   struct hci_request rq;
00300   gap_set_author_requirement_cp cp;    
00301   uint8_t status;
00302     
00303   cp.conn_handle = htobs(conn_handle);
00304   cp.authorization_enable = authorization_enable;
00305 
00306   Osal_MemSet(&rq, 0, sizeof(rq));
00307   rq.ogf = OGF_VENDOR_CMD;
00308   rq.ocf = OCF_GAP_SET_AUTHOR_REQUIREMENT;
00309   rq.cparam = &cp;
00310   rq.clen = GAP_SET_AUTHOR_REQUIREMENT_CP_SIZE;
00311   rq.rparam = &status;
00312   rq.rlen = 1;
00313 
00314   if (hci_send_req(&rq) < 0)
00315     return BLE_STATUS_TIMEOUT;
00316   
00317   return status;
00318 }
00319 
00320 tBleStatus aci_gap_pass_key_response(uint16_t conn_handle, uint32_t passkey)
00321 {
00322   struct hci_request rq;
00323   gap_passkey_response_cp cp;    
00324   uint8_t status;
00325     
00326   cp.conn_handle = htobs(conn_handle);
00327   cp.passkey = htobl(passkey);
00328 
00329   Osal_MemSet(&rq, 0, sizeof(rq));
00330   rq.ogf = OGF_VENDOR_CMD;
00331   rq.ocf = OCF_GAP_PASSKEY_RESPONSE;
00332   rq.cparam = &cp;
00333   rq.clen = GAP_PASSKEY_RESPONSE_CP_SIZE;
00334   rq.event = EVT_CMD_STATUS;
00335   rq.rparam = &status;
00336   rq.rlen = 1;
00337   
00338   if (hci_send_req(&rq) < 0)
00339     return BLE_STATUS_TIMEOUT;
00340   
00341   return status;
00342 }
00343 
00344 tBleStatus aci_gap_authorization_response(uint16_t conn_handle, uint8_t authorize)
00345 {
00346   struct hci_request rq;
00347   gap_authorization_response_cp cp;    
00348   uint8_t status;
00349     
00350   cp.conn_handle = htobs(conn_handle);
00351   cp.authorize = authorize;
00352 
00353   Osal_MemSet(&rq, 0, sizeof(rq));
00354   rq.ogf = OGF_VENDOR_CMD;
00355   rq.ocf = OCF_GAP_AUTHORIZATION_RESPONSE;
00356   rq.cparam = &cp;
00357   rq.clen = GAP_AUTHORIZATION_RESPONSE_CP_SIZE;
00358   rq.rparam = &status;
00359   rq.rlen = 1;
00360   
00361   if (hci_send_req(&rq) < 0)
00362     return BLE_STATUS_TIMEOUT;
00363   
00364   return status;
00365 }
00366 
00367 tBleStatus aci_gap_set_non_connectable(uint8_t adv_type)
00368 {
00369   struct hci_request rq;
00370   gap_set_non_connectable_cp cp;    
00371   uint8_t status;
00372     
00373   cp.advertising_event_type = adv_type;
00374 
00375   Osal_MemSet(&rq, 0, sizeof(rq));
00376   rq.ogf = OGF_VENDOR_CMD;
00377   rq.ocf = OCF_GAP_SET_NON_CONNECTABLE;
00378   rq.cparam = &cp;
00379   rq.clen = GAP_SET_NON_CONNECTABLE_CP_SIZE;
00380   rq.rparam = &status;
00381   rq.rlen = 1;
00382   
00383   if (hci_send_req(&rq) < 0)
00384     return BLE_STATUS_TIMEOUT;
00385   
00386   return status;
00387 }
00388 
00389 tBleStatus aci_gap_set_undirected_connectable(uint8_t own_addr_type, uint8_t adv_filter_policy)
00390 {
00391   struct hci_request rq;
00392   gap_set_undirected_connectable_cp cp;    
00393   uint8_t status;
00394     
00395   cp.own_addr_type = own_addr_type;
00396   cp.adv_filter_policy = adv_filter_policy;
00397 
00398   Osal_MemSet(&rq, 0, sizeof(rq));
00399   rq.ogf = OGF_VENDOR_CMD;
00400   rq.ocf = OCF_GAP_SET_UNDIRECTED_CONNECTABLE;
00401   rq.cparam = &cp;
00402   rq.clen = GAP_SET_UNDIRECTED_CONNECTABLE_CP_SIZE;
00403   rq.rparam = &status;
00404   rq.rlen = 1;
00405   
00406   if (hci_send_req(&rq) < 0)
00407     return BLE_STATUS_TIMEOUT;
00408   
00409   return status;
00410 }
00411 
00412 tBleStatus aci_gap_slave_security_request(uint16_t conn_handle, uint8_t bonding, uint8_t mitm_protection)
00413 {
00414   struct hci_request rq;
00415   gap_slave_security_request_cp cp;
00416   uint8_t status;
00417 
00418   cp.conn_handle = htobs(conn_handle);
00419   cp.bonding = bonding;
00420   cp.mitm_protection = mitm_protection;
00421   
00422   Osal_MemSet(&rq, 0, sizeof(rq));
00423   rq.ogf = OGF_VENDOR_CMD;
00424   rq.ocf = OCF_GAP_SLAVE_SECURITY_REQUEST;
00425   rq.cparam = &cp;
00426   rq.clen = GAP_SLAVE_SECURITY_REQUEST_CP_SIZE;
00427   rq.event = EVT_CMD_STATUS;
00428   rq.rparam = &status;
00429   rq.rlen = 1;
00430   
00431   if (hci_send_req(&rq) < 0)
00432     return BLE_STATUS_TIMEOUT;
00433 
00434   return status;
00435 
00436 }
00437 
00438 tBleStatus aci_gap_update_adv_data(uint8_t AdvLen, uint8_t *AdvData)
00439 {
00440   struct hci_request rq;
00441   uint8_t status;
00442   uint8_t buffer[32];
00443   uint8_t indx = 0;
00444     
00445   if (AdvLen > (sizeof(buffer)-1))
00446     return BLE_STATUS_INVALID_PARAMS;
00447 
00448   buffer[indx] = AdvLen;
00449   indx++;
00450     
00451   Osal_MemCpy(buffer + indx, AdvData, AdvLen);
00452   indx +=  AdvLen;
00453     
00454   Osal_MemSet(&rq, 0, sizeof(rq));
00455   rq.ogf = OGF_VENDOR_CMD;
00456   rq.ocf = OCF_GAP_UPDATE_ADV_DATA;
00457   rq.cparam = (void *)buffer;
00458   rq.clen = indx;
00459   rq.rparam = &status;
00460   rq.rlen = 1;
00461     
00462   if (hci_send_req(&rq) < 0)
00463     return BLE_STATUS_TIMEOUT;
00464     
00465   return status;
00466 }
00467 
00468 tBleStatus aci_gap_configure_whitelist(void)
00469 {
00470   struct hci_request rq;
00471   uint8_t status, dummy;
00472   
00473   dummy = 0;
00474   
00475   Osal_MemSet(&rq, 0, sizeof(rq));
00476   rq.ogf = OGF_VENDOR_CMD;
00477   rq.ocf = OCF_GAP_CONFIGURE_WHITELIST;
00478   rq.cparam = (void*)&dummy;
00479   rq.clen = 0;
00480   rq.rparam = &status;
00481   rq.rlen = 1;
00482   
00483   if (hci_send_req(&rq) < 0)
00484     return BLE_STATUS_TIMEOUT;
00485 
00486   return status;
00487 }
00488 
00489 tBleStatus aci_gap_terminate(uint16_t conn_handle, uint8_t reason)
00490 {
00491   struct hci_request rq;
00492   gap_terminate_cp cp;
00493   uint8_t status;  
00494 
00495   cp.handle = htobs(conn_handle);
00496   cp.reason = reason;
00497 
00498   Osal_MemSet(&rq, 0, sizeof(rq));
00499   rq.ogf = OGF_VENDOR_CMD;
00500   rq.ocf = OCF_GAP_TERMINATE;
00501   rq.cparam = &cp;
00502   rq.clen = GAP_TERMINATE_CP_SIZE;
00503   rq.event = EVT_CMD_STATUS;
00504   rq.rparam = &status;
00505   rq.rlen = 1;
00506   
00507   if (hci_send_req(&rq) < 0)
00508     return BLE_STATUS_TIMEOUT;
00509 
00510   return status; 
00511 }
00512 
00513 tBleStatus aci_gap_clear_security_database(void)
00514 {
00515   struct hci_request rq;
00516   uint8_t status, dummy;
00517   
00518   dummy = 0;
00519   
00520   Osal_MemSet(&rq, 0, sizeof(rq));
00521   rq.ogf = OGF_VENDOR_CMD;
00522   rq.ocf = OCF_GAP_CLEAR_SECURITY_DB;
00523   rq.cparam = (void*)&dummy;
00524   rq.clen = 0;
00525   rq.rparam = &status;
00526   rq.rlen = 1;
00527   
00528   if (hci_send_req(&rq) < 0)
00529     return BLE_STATUS_TIMEOUT;
00530 
00531   return status;
00532 }
00533 
00534 tBleStatus aci_gap_allow_rebond(void)
00535 {
00536   struct hci_request rq;
00537   uint8_t status, dummy;
00538   
00539   dummy = 0;
00540   
00541   Osal_MemSet(&rq, 0, sizeof(rq));
00542   rq.ogf = OGF_VENDOR_CMD;
00543   rq.ocf = OCF_GAP_ALLOW_REBOND_DB;
00544   rq.cparam = (void*)&dummy;
00545   rq.clen = 0;
00546   rq.rparam = &status;
00547   rq.rlen = 1;
00548   
00549   if (hci_send_req(&rq) < 0)
00550     return BLE_STATUS_TIMEOUT;
00551 
00552   return status;
00553 }
00554 
00555 tBleStatus aci_gap_start_limited_discovery_proc(uint16_t scanInterval, uint16_t scanWindow,
00556                         uint8_t own_address_type, uint8_t filterDuplicates)
00557 {
00558   struct hci_request rq;
00559   gap_start_limited_discovery_proc_cp cp;
00560   uint8_t status;  
00561 
00562   cp.scanInterval = htobs(scanInterval);
00563   cp.scanWindow = htobs(scanWindow);
00564   cp.own_address_type = own_address_type;
00565   cp.filterDuplicates = filterDuplicates;
00566 
00567   Osal_MemSet(&rq, 0, sizeof(rq));
00568   rq.ogf = OGF_VENDOR_CMD;
00569   rq.ocf = OCF_GAP_START_LIMITED_DISCOVERY_PROC;
00570   rq.cparam = &cp;
00571   rq.clen = GAP_START_LIMITED_DISCOVERY_PROC_CP_SIZE;
00572   rq.event = EVT_CMD_STATUS;
00573   rq.rparam = &status;
00574   rq.rlen = 1;
00575   
00576   if (hci_send_req(&rq) < 0)
00577     return BLE_STATUS_TIMEOUT;
00578 
00579   return status;
00580 }
00581 
00582 tBleStatus aci_gap_start_general_discovery_proc(uint16_t scanInterval, uint16_t scanWindow,
00583                         uint8_t own_address_type, uint8_t filterDuplicates)
00584 {
00585   struct hci_request rq;
00586   gap_start_general_discovery_proc_cp cp;
00587   uint8_t status;  
00588 
00589   cp.scanInterval = htobs(scanInterval);
00590   cp.scanWindow = htobs(scanWindow);
00591   cp.own_address_type = own_address_type;
00592   cp.filterDuplicates = filterDuplicates;
00593 
00594   Osal_MemSet(&rq, 0, sizeof(rq));
00595   rq.ogf = OGF_VENDOR_CMD;
00596   rq.ocf = OCF_GAP_START_GENERAL_DISCOVERY_PROC;
00597   rq.cparam = &cp;
00598   rq.clen = GAP_START_GENERAL_DISCOVERY_PROC_CP_SIZE;
00599   rq.event = EVT_CMD_STATUS;
00600   rq.rparam = &status;
00601   rq.rlen = 1;
00602   
00603   if (hci_send_req(&rq) < 0)
00604     return BLE_STATUS_TIMEOUT;
00605 
00606   return status;
00607 }
00608 
00609 
00610 tBleStatus aci_gap_start_auto_conn_establishment(uint16_t scanInterval, uint16_t scanWindow,
00611                          uint8_t own_bdaddr_type, uint16_t conn_min_interval,   
00612                          uint16_t conn_max_interval, uint16_t conn_latency, 
00613                          uint16_t supervision_timeout, uint16_t min_conn_length, 
00614                          uint16_t max_conn_length, uint8_t num_whitelist_entries,
00615                          uint8_t *addr_array)
00616 {
00617   struct hci_request rq;
00618   uint8_t status;
00619   uint8_t buffer[HCI_MAX_PACKET_SIZE];
00620   uint8_t indx = 0;
00621     
00622   if (((num_whitelist_entries*7)+18) > HCI_MAX_PACKET_SIZE)
00623     return BLE_STATUS_INVALID_PARAMS;
00624 
00625   scanInterval = htobs(scanInterval);
00626   Osal_MemCpy(buffer + indx, &scanInterval, 2);
00627   indx += 2;
00628     
00629   scanWindow = htobs(scanWindow);
00630   Osal_MemCpy(buffer + indx, &scanWindow, 2);
00631   indx += 2;
00632 
00633   buffer[indx] = own_bdaddr_type;
00634   indx++;
00635   
00636   conn_min_interval = htobs(conn_min_interval);
00637   Osal_MemCpy(buffer + indx, &conn_min_interval, 2);
00638   indx +=  2;
00639 
00640   conn_max_interval = htobs(conn_max_interval);
00641   Osal_MemCpy(buffer + indx, &conn_max_interval, 2);
00642   indx +=  2;
00643 
00644   conn_latency = htobs(conn_latency);
00645   Osal_MemCpy(buffer + indx, &conn_latency, 2);
00646   indx +=  2;
00647 
00648   supervision_timeout = htobs(supervision_timeout);
00649   Osal_MemCpy(buffer + indx, &supervision_timeout, 2);
00650   indx +=  2;
00651 
00652   min_conn_length = htobs(min_conn_length);
00653   Osal_MemCpy(buffer + indx, &min_conn_length, 2);
00654   indx +=  2;
00655 
00656   max_conn_length = htobs(max_conn_length);
00657   Osal_MemCpy(buffer + indx, &max_conn_length, 2);
00658   indx +=  2;
00659 
00660   buffer[indx] = num_whitelist_entries;
00661   indx++;
00662 
00663   Osal_MemCpy(buffer + indx, addr_array, (num_whitelist_entries*7));
00664   indx +=  num_whitelist_entries * 7;
00665 
00666   Osal_MemSet(&rq, 0, sizeof(rq));
00667   rq.ogf = OGF_VENDOR_CMD;
00668   rq.ocf = OCF_GAP_START_AUTO_CONN_ESTABLISHMENT;
00669   rq.cparam = (void *)buffer;
00670   rq.clen = indx;
00671   rq.event = EVT_CMD_STATUS;
00672   rq.rparam = &status;
00673   rq.rlen = 1;
00674 
00675   if (hci_send_req(&rq) < 0)
00676     return BLE_STATUS_TIMEOUT;
00677 
00678   return status;  
00679 }
00680 
00681 tBleStatus aci_gap_create_connection(uint16_t scanInterval, uint16_t scanWindow,
00682                      uint8_t peer_bdaddr_type, tBDAddr peer_bdaddr, 
00683                      uint8_t own_bdaddr_type, uint16_t conn_min_interval,   
00684                      uint16_t conn_max_interval, uint16_t conn_latency, 
00685                      uint16_t supervision_timeout, uint16_t min_conn_length, 
00686                      uint16_t max_conn_length)
00687 {
00688   struct hci_request rq;
00689   gap_create_connection_cp cp;
00690   uint8_t status;  
00691 
00692   cp.scanInterval = htobs(scanInterval);
00693   cp.scanWindow = htobs(scanWindow);
00694   cp.peer_bdaddr_type = peer_bdaddr_type;
00695   Osal_MemCpy(cp.peer_bdaddr, peer_bdaddr, 6);
00696   cp.own_bdaddr_type = own_bdaddr_type;
00697   cp.conn_min_interval = htobs(conn_min_interval);
00698   cp.conn_max_interval = htobs(conn_max_interval);
00699   cp.conn_latency = htobs(conn_latency);
00700   cp.supervision_timeout = htobs(supervision_timeout);
00701   cp.min_conn_length = htobs(min_conn_length);
00702   cp.max_conn_length = htobs(max_conn_length);
00703 
00704   Osal_MemSet(&rq, 0, sizeof(rq));
00705   rq.ogf = OGF_VENDOR_CMD;
00706   rq.ocf = OCF_GAP_CREATE_CONNECTION;
00707   rq.cparam = &cp;
00708   rq.clen = GAP_CREATE_CONNECTION_CP_SIZE;
00709   rq.event = EVT_CMD_STATUS;
00710   rq.rparam = &status;
00711   rq.rlen = 1;
00712   
00713   if (hci_send_req(&rq) < 0)
00714     return BLE_STATUS_TIMEOUT;
00715 
00716   return status;
00717 }
00718 
00719 tBleStatus aci_gap_terminate_gap_procedure(uint8_t procedure_code)
00720 {
00721   struct hci_request rq;
00722   uint8_t status;  
00723 
00724   Osal_MemSet(&rq, 0, sizeof(rq));
00725   rq.ogf = OGF_VENDOR_CMD;
00726   rq.ocf = OCF_GAP_TERMINATE_GAP_PROCEDURE;
00727   rq.cparam = &procedure_code;
00728   rq.clen = 1;
00729   rq.rparam = &status;
00730   rq.rlen = 1;
00731   
00732   if (hci_send_req(&rq) < 0)
00733     return BLE_STATUS_TIMEOUT;
00734 
00735   return status;
00736 
00737 }
00738 
00739 tBleStatus aci_gap_send_pairing_request(uint16_t conn_handle, uint8_t force_rebond)
00740 {
00741   struct hci_request rq;
00742   gap_send_pairing_request_cp cp;
00743   uint8_t status;
00744 
00745   cp.conn_handle = htobs(conn_handle);
00746   cp.force_rebond = force_rebond;
00747 
00748   Osal_MemSet(&rq, 0, sizeof(rq));
00749   rq.ogf = OGF_VENDOR_CMD;
00750   rq.ocf = OCF_GAP_SEND_PAIRING_REQUEST;
00751   rq.cparam = &cp;
00752   rq.clen = GAP_SEND_PAIRING_REQUEST_CP_SIZE;
00753   rq.event = EVT_CMD_STATUS;
00754   rq.rparam = &status;
00755   rq.rlen = 1;
00756 
00757   if (hci_send_req(&rq) < 0)
00758     return BLE_STATUS_TIMEOUT;
00759 
00760   return status;
00761 }
00762