tset

Fork of X_NUCLEO_IDB0XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bluenrg_gatt_aci.c Source File

bluenrg_gatt_aci.c

00001 /******************** (C) COPYRIGHT 2014 STMicroelectronics ********************
00002 * File Name          : bluenrg_gatt_aci.c
00003 * Author             : AMS - AAS
00004 * Version            : V1.0.0
00005 * Date               : 26-Jun-2014
00006 * Description        : File with GATT commands for BlueNRG FW6.3.
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_hci_const.h"
00021 #include "bluenrg_aci_const.h"
00022 #include "bluenrg_gatt_aci.h"
00023 #include "bluenrg_gatt_server.h"
00024 #include "bluenrg_gap.h"
00025 
00026 #define MIN(a,b)            ((a) < (b) )? (a) : (b)
00027 #define MAX(a,b)            ((a) > (b) )? (a) : (b)
00028 
00029 
00030 tBleStatus aci_gatt_init(void)
00031 {
00032   struct hci_request rq;
00033   uint8_t status;
00034 
00035   Osal_MemSet(&rq, 0, sizeof(rq));
00036   rq.ogf = OGF_VENDOR_CMD;
00037   rq.ocf = OCF_GATT_INIT;
00038   rq.rparam = &status;
00039   rq.rlen = 1;
00040 
00041   if (hci_send_req(&rq, FALSE) < 0)
00042     return BLE_STATUS_TIMEOUT;
00043 
00044   return status;
00045 }
00046 
00047 tBleStatus aci_gatt_add_serv(uint8_t service_uuid_type, const uint8_t* service_uuid, uint8_t service_type, uint8_t max_attr_records, uint16_t *serviceHandle)
00048 {
00049   struct hci_request rq;
00050   gatt_add_serv_rp resp;    
00051   uint8_t buffer[19];
00052   uint8_t uuid_len;
00053   uint8_t indx = 0;
00054     
00055   buffer[indx] = service_uuid_type;
00056   indx++;
00057     
00058   if(service_uuid_type == UUID_TYPE_16){
00059     uuid_len = 2;
00060   }
00061   else {
00062     uuid_len = 16;
00063   }        
00064   Osal_MemCpy(buffer + indx, service_uuid, uuid_len);
00065   indx +=  uuid_len;
00066     
00067   buffer[indx] = service_type;
00068   indx++;
00069     
00070   buffer[indx] = max_attr_records;
00071   indx++;
00072     
00073     
00074   Osal_MemSet(&resp, 0, sizeof(resp));
00075 
00076   Osal_MemSet(&rq, 0, sizeof(rq));
00077   rq.ogf = OGF_VENDOR_CMD;
00078   rq.ocf = OCF_GATT_ADD_SERV;
00079   rq.cparam = (void *)buffer;
00080   rq.clen = indx;
00081   rq.rparam = &resp;
00082   rq.rlen = GATT_ADD_SERV_RP_SIZE;
00083 
00084   if (hci_send_req(&rq, FALSE) < 0)
00085     return BLE_STATUS_TIMEOUT;
00086 
00087   if (resp.status) {
00088     return resp.status;
00089   }
00090     
00091   *serviceHandle = btohs(resp.handle);
00092 
00093   return 0;
00094 }
00095 
00096 tBleStatus aci_gatt_include_service(uint16_t service_handle, uint16_t included_start_handle,
00097                     uint16_t included_end_handle, uint8_t included_uuid_type,
00098                     const uint8_t* included_uuid, uint16_t *included_handle)
00099 {
00100   struct hci_request rq;
00101   gatt_include_serv_rp resp;    
00102   uint8_t buffer[23];
00103   uint8_t uuid_len;
00104   uint8_t indx = 0;
00105 
00106   service_handle = htobs(service_handle);
00107   Osal_MemCpy(buffer, &service_handle, 2);
00108   indx += 2;
00109     
00110   included_start_handle = htobs(included_start_handle);
00111   Osal_MemCpy(buffer+indx, &included_start_handle, 2);
00112   indx += 2;
00113 
00114   included_end_handle = htobs(included_end_handle);
00115   Osal_MemCpy(buffer+indx, &included_end_handle, 2);
00116   indx += 2;
00117 
00118   if(included_uuid_type == UUID_TYPE_16){
00119     uuid_len = 2;
00120   } else {
00121     uuid_len = 16;
00122   }        
00123 
00124   buffer[indx] = included_uuid_type;
00125   indx++;
00126 
00127   Osal_MemCpy(buffer + indx, included_uuid, uuid_len);
00128   indx += uuid_len;
00129     
00130   Osal_MemSet(&resp, 0, sizeof(resp));
00131 
00132   Osal_MemSet(&rq, 0, sizeof(rq));
00133   rq.ogf = OGF_VENDOR_CMD;
00134   rq.ocf = OCF_GATT_INCLUDE_SERV;
00135   rq.cparam = (void *)buffer;
00136   rq.clen = indx;
00137   rq.rparam = &resp;
00138   rq.rlen = GATT_INCLUDE_SERV_RP_SIZE;
00139 
00140   if (hci_send_req(&rq, FALSE) < 0)
00141     return BLE_STATUS_TIMEOUT;
00142 
00143   if (resp.status) {
00144     return resp.status;
00145   }
00146     
00147   *included_handle = btohs(resp.handle);
00148 
00149   return 0;
00150 }
00151 
00152 tBleStatus aci_gatt_add_char(uint16_t serviceHandle,
00153                  uint8_t charUuidType,
00154                  const uint8_t* charUuid, 
00155                  uint8_t charValueLen, 
00156                  uint8_t charProperties,
00157                  uint8_t secPermissions,
00158                  uint8_t gattEvtMask,
00159                  uint8_t encryKeySize,
00160                  uint8_t isVariable,
00161                  uint16_t* charHandle)                     
00162 {
00163   struct hci_request rq;
00164   gatt_add_serv_rp resp;
00165   uint8_t buffer[25];
00166   uint8_t uuid_len;
00167   uint8_t indx = 0;
00168     
00169   serviceHandle = htobs(serviceHandle);
00170   Osal_MemCpy(buffer + indx, &serviceHandle, 2);
00171   indx += 2;
00172     
00173   buffer[indx] = charUuidType;
00174   indx++;
00175     
00176   if(charUuidType == UUID_TYPE_16){
00177     uuid_len = 2;
00178   }
00179   else {
00180     uuid_len = 16;
00181   }        
00182   Osal_MemCpy(buffer + indx, charUuid, uuid_len);
00183   indx +=  uuid_len;
00184     
00185   buffer[indx] = charValueLen;
00186   indx++;
00187     
00188   buffer[indx] = charProperties;
00189   indx++;
00190     
00191   buffer[indx] = secPermissions;
00192   indx++;
00193     
00194   buffer[indx] = gattEvtMask;
00195   indx++;
00196     
00197   buffer[indx] = encryKeySize;
00198   indx++;
00199     
00200   buffer[indx] = isVariable;
00201   indx++;
00202     
00203   Osal_MemSet(&resp, 0, sizeof(resp));
00204 
00205   Osal_MemSet(&rq, 0, sizeof(rq));
00206   rq.ogf = OGF_VENDOR_CMD;
00207   rq.ocf = OCF_GATT_ADD_CHAR;
00208   rq.cparam = (void *)buffer;
00209   rq.clen = indx;
00210   rq.rparam = &resp;
00211   rq.rlen = GATT_ADD_CHAR_RP_SIZE;
00212 
00213   if (hci_send_req(&rq, FALSE) < 0)
00214     return BLE_STATUS_TIMEOUT;
00215 
00216   if (resp.status) {
00217     return resp.status;
00218   }
00219     
00220   *charHandle = btohs(resp.handle);
00221 
00222   return 0;
00223 }
00224 
00225 tBleStatus aci_gatt_add_char_desc(uint16_t serviceHandle,
00226                                   uint16_t charHandle,
00227                                   uint8_t descUuidType,
00228                                   const uint8_t* uuid, 
00229                                   uint8_t descValueMaxLen,
00230                                   uint8_t descValueLen,
00231                                   const void* descValue, 
00232                                   uint8_t secPermissions,
00233                                   uint8_t accPermissions,
00234                                   uint8_t gattEvtMask,
00235                                   uint8_t encryKeySize,
00236                                   uint8_t isVariable,
00237                                   uint16_t* descHandle)                     
00238 {
00239   struct hci_request rq;
00240   gatt_add_char_desc_rp resp;
00241   uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
00242   uint8_t uuid_len;
00243   uint8_t indx = 0;
00244     
00245   serviceHandle = htobs(serviceHandle);
00246   Osal_MemCpy(buffer + indx, &serviceHandle, 2);
00247   indx += 2;
00248     
00249   charHandle = htobs(charHandle);
00250   Osal_MemCpy(buffer + indx, &charHandle, 2);
00251   indx += 2;
00252     
00253   buffer[indx] = descUuidType;
00254   indx++;
00255     
00256   if(descUuidType == UUID_TYPE_16){
00257     uuid_len = 2;
00258   }
00259   else {
00260     uuid_len = 16;
00261   }        
00262   Osal_MemCpy(buffer + indx, uuid, uuid_len);
00263   indx +=  uuid_len;
00264     
00265   buffer[indx] = descValueMaxLen;
00266   indx++;
00267     
00268   buffer[indx] = descValueLen;
00269   indx++;
00270 
00271   if ((descValueLen+indx+5) > HCI_MAX_PAYLOAD_SIZE)
00272     return BLE_STATUS_INVALID_PARAMS;
00273   
00274   Osal_MemCpy(buffer + indx, descValue, descValueLen);
00275   indx += descValueLen;
00276     
00277   buffer[indx] = secPermissions;
00278   indx++;
00279     
00280   buffer[indx] = accPermissions;
00281   indx++;
00282     
00283   buffer[indx] = gattEvtMask;
00284   indx++;
00285     
00286   buffer[indx] = encryKeySize;
00287   indx++;
00288     
00289   buffer[indx] = isVariable;
00290   indx++;
00291     
00292   Osal_MemSet(&resp, 0, sizeof(resp));
00293 
00294   Osal_MemSet(&rq, 0, sizeof(rq));
00295   rq.ogf = OGF_VENDOR_CMD;
00296   rq.ocf = OCF_GATT_ADD_CHAR_DESC;
00297   rq.cparam = (void *)buffer;
00298   rq.clen = indx;
00299   rq.rparam = &resp;
00300   rq.rlen = GATT_ADD_CHAR_DESC_RP_SIZE;
00301 
00302   if (hci_send_req(&rq, FALSE) < 0)
00303     return BLE_STATUS_TIMEOUT;
00304 
00305   if (resp.status) {
00306     return resp.status;
00307   }
00308     
00309   *descHandle = btohs(resp.handle);
00310 
00311   return 0;
00312 }
00313 
00314 
00315 tBleStatus aci_gatt_update_char_value(uint16_t servHandle, 
00316                       uint16_t charHandle,
00317                       uint8_t charValOffset,
00318                       uint8_t charValueLen,   
00319                       const void *charValue)
00320 {
00321   struct hci_request rq;
00322   uint8_t status;
00323   uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
00324   uint8_t indx = 0;
00325     
00326   if ((charValueLen+6) > HCI_MAX_PAYLOAD_SIZE)
00327     return BLE_STATUS_INVALID_PARAMS;
00328 
00329   servHandle = htobs(servHandle);
00330   Osal_MemCpy(buffer + indx, &servHandle, 2);
00331   indx += 2;
00332     
00333   charHandle = htobs(charHandle);
00334   Osal_MemCpy(buffer + indx, &charHandle, 2);
00335   indx += 2;
00336     
00337   buffer[indx] = charValOffset;
00338   indx++;
00339     
00340   buffer[indx] = charValueLen;
00341   indx++;
00342         
00343   Osal_MemCpy(buffer + indx, charValue, charValueLen);
00344   indx +=  charValueLen;
00345 
00346   Osal_MemSet(&rq, 0, sizeof(rq));
00347   rq.ogf = OGF_VENDOR_CMD;
00348   rq.ocf = OCF_GATT_UPD_CHAR_VAL;
00349   rq.cparam = (void *)buffer;
00350   rq.clen = indx;
00351   rq.rparam = &status;
00352   rq.rlen = 1;
00353 
00354   if (hci_send_req(&rq, FALSE) < 0)
00355     return BLE_STATUS_TIMEOUT;
00356 
00357   if (status) {
00358     return status;
00359   }
00360 
00361   return 0;
00362 }
00363 
00364 tBleStatus aci_gatt_del_char(uint16_t servHandle, uint16_t charHandle)
00365 {
00366   struct hci_request rq;
00367   uint8_t status;
00368   gatt_del_char_cp cp;
00369 
00370   cp.service_handle = htobs(servHandle);
00371   cp.char_handle = htobs(charHandle);
00372 
00373   Osal_MemSet(&rq, 0, sizeof(rq));
00374   rq.ogf = OGF_VENDOR_CMD;
00375   rq.ocf = OCF_GATT_DEL_CHAR;
00376   rq.cparam = &cp;
00377   rq.clen = GATT_DEL_CHAR_CP_SIZE;
00378   rq.rparam = &status;
00379   rq.rlen = 1;
00380 
00381   if (hci_send_req(&rq, FALSE) < 0)
00382     return BLE_STATUS_TIMEOUT;
00383 
00384   return status;
00385 }
00386                                       
00387 tBleStatus aci_gatt_del_service(uint16_t servHandle)
00388 {
00389   struct hci_request rq;
00390   uint8_t status;
00391   gatt_del_serv_cp cp;
00392 
00393   cp.service_handle = htobs(servHandle);
00394 
00395   Osal_MemSet(&rq, 0, sizeof(rq));
00396   rq.ogf = OGF_VENDOR_CMD;
00397   rq.ocf = OCF_GATT_DEL_SERV;
00398   rq.cparam = &cp;
00399   rq.clen = GATT_DEL_SERV_CP_SIZE;
00400   rq.rparam = &status;
00401   rq.rlen = 1;
00402 
00403   if (hci_send_req(&rq, FALSE) < 0)
00404     return BLE_STATUS_TIMEOUT;
00405 
00406   return status;
00407 }
00408 
00409 tBleStatus aci_gatt_del_include_service(uint16_t servHandle, uint16_t includeServHandle)
00410 {
00411   struct hci_request rq;
00412   uint8_t status;
00413   gatt_del_inc_serv_cp cp;
00414 
00415   cp.service_handle = htobs(servHandle);
00416   cp.inc_serv_handle = htobs(includeServHandle);
00417 
00418   Osal_MemSet(&rq, 0, sizeof(rq));
00419   rq.ogf = OGF_VENDOR_CMD;
00420   rq.ocf = OCF_GATT_DEL_INC_SERV;
00421   rq.cparam = &cp;
00422   rq.clen = GATT_DEL_INC_SERV_CP_SIZE;
00423   rq.rparam = &status;
00424   rq.rlen = 1;
00425 
00426   if (hci_send_req(&rq, FALSE) < 0)
00427     return BLE_STATUS_TIMEOUT;
00428 
00429   return status;
00430 }
00431 
00432 tBleStatus aci_gatt_set_event_mask(uint32_t event_mask)
00433 {
00434   struct hci_request rq;
00435   uint8_t status;
00436   gatt_set_evt_mask_cp cp;
00437 
00438   cp.evt_mask = htobs(event_mask);
00439 
00440   Osal_MemSet(&rq, 0, sizeof(rq));
00441   rq.ogf = OGF_VENDOR_CMD;
00442   rq.ocf = OCF_GATT_SET_EVT_MASK;
00443   rq.cparam = &cp;
00444   rq.clen = GATT_SET_EVT_MASK_CP_SIZE;
00445   rq.rparam = &status;
00446   rq.rlen = 1;
00447 
00448   if (hci_send_req(&rq, FALSE) < 0)
00449     return BLE_STATUS_TIMEOUT;
00450 
00451   return status;
00452 }
00453   
00454 tBleStatus aci_gatt_exchange_configuration(uint16_t conn_handle)
00455 {
00456   struct hci_request rq;
00457   uint8_t status;
00458   gatt_exchange_config_cp cp;
00459 
00460   cp.conn_handle = htobs(conn_handle);
00461 
00462   Osal_MemSet(&rq, 0, sizeof(rq));
00463   rq.ogf = OGF_VENDOR_CMD;
00464   rq.ocf = OCF_GATT_EXCHANGE_CONFIG;
00465   rq.cparam = &cp;
00466   rq.clen = GATT_EXCHANGE_CONFIG_CP_SIZE;
00467   rq.event = EVT_CMD_STATUS; 
00468   rq.rparam = &status;
00469   rq.rlen = 1;
00470 
00471   if (hci_send_req(&rq, FALSE) < 0)
00472     return BLE_STATUS_TIMEOUT;
00473 
00474   return status;
00475 }
00476   
00477 tBleStatus aci_att_find_information_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle)
00478 {
00479   struct hci_request rq;
00480   uint8_t status;
00481   att_find_info_req_cp cp;
00482 
00483   cp.conn_handle = htobs(conn_handle);
00484   cp.start_handle = htobs(start_handle);
00485   cp.end_handle = htobs(end_handle);
00486 
00487   Osal_MemSet(&rq, 0, sizeof(rq));
00488   rq.ogf = OGF_VENDOR_CMD;
00489   rq.ocf = OCF_ATT_FIND_INFO_REQ;
00490   rq.cparam = &cp;
00491   rq.clen = ATT_FIND_INFO_REQ_CP_SIZE;
00492   rq.rparam = &status;
00493   rq.rlen = 1;
00494 
00495   if (hci_send_req(&rq, FALSE) < 0)
00496     return BLE_STATUS_TIMEOUT;
00497 
00498   return status;
00499 }
00500 
00501 tBleStatus aci_att_find_by_type_value_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
00502                                           uint8_t* uuid, uint8_t attr_val_len, uint8_t* attr_val)
00503 {
00504   struct hci_request rq;
00505   uint8_t status;
00506   att_find_by_type_value_req_cp cp;
00507   
00508   if(attr_val_len > sizeof(cp.attr_val))
00509     return BLE_STATUS_INVALID_PARAMS;
00510 
00511   cp.conn_handle = htobs(conn_handle);
00512   cp.start_handle = htobs(start_handle);
00513   cp.end_handle = htobs(end_handle);
00514   Osal_MemCpy(cp.uuid, uuid, 2);
00515   cp.attr_val_len = attr_val_len;
00516   Osal_MemCpy(cp.attr_val, attr_val, attr_val_len);
00517 
00518   Osal_MemSet(&rq, 0, sizeof(rq));
00519   rq.ogf = OGF_VENDOR_CMD;
00520   rq.ocf = OCF_ATT_FIND_BY_TYPE_VALUE_REQ;
00521   rq.cparam = &cp;
00522   rq.clen = ATT_FIND_BY_TYPE_VALUE_REQ_CP_SIZE + attr_val_len;
00523   rq.rparam = &status;
00524   rq.rlen = 1;
00525 
00526   if (hci_send_req(&rq, FALSE) < 0)
00527     return BLE_STATUS_TIMEOUT;
00528 
00529   return status;
00530 }
00531 
00532 tBleStatus aci_att_read_by_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
00533                                     uint8_t  uuid_type, uint8_t* uuid)
00534 {
00535   struct hci_request rq;
00536   uint8_t status;
00537   att_read_by_type_req_cp cp;
00538   uint8_t uuid_len;
00539   
00540   if(uuid_type == UUID_TYPE_16){
00541     uuid_len = 2;
00542   }
00543   else{
00544     uuid_len = 16;
00545   }
00546 
00547   cp.conn_handle = htobs(conn_handle);
00548   cp.start_handle = htobs(start_handle);
00549   cp.end_handle = htobs(end_handle);
00550   cp.uuid_type = uuid_type;
00551   Osal_MemCpy(cp.uuid, uuid, uuid_len);
00552 
00553   Osal_MemSet(&rq, 0, sizeof(rq));
00554   rq.ogf = OGF_VENDOR_CMD;
00555   rq.ocf = OCF_ATT_READ_BY_TYPE_REQ;
00556   rq.cparam = &cp;
00557   rq.clen = ATT_READ_BY_TYPE_REQ_CP_SIZE + uuid_len;
00558   rq.rparam = &status;
00559   rq.rlen = 1;
00560 
00561   if (hci_send_req(&rq, FALSE) < 0)
00562     return BLE_STATUS_TIMEOUT;
00563 
00564   return status;
00565 }
00566 
00567 tBleStatus aci_att_read_by_group_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
00568                                     uint8_t  uuid_type, uint8_t* uuid)
00569 {
00570   struct hci_request rq;
00571   uint8_t status;
00572   att_read_by_group_type_req_cp cp;
00573   uint8_t uuid_len;
00574   
00575   if(uuid_type == UUID_TYPE_16){
00576     uuid_len = 2;
00577   }
00578   else{
00579     uuid_len = 16;
00580   }
00581 
00582   cp.conn_handle = htobs(conn_handle);
00583   cp.start_handle = htobs(start_handle);
00584   cp.end_handle = htobs(end_handle);
00585   cp.uuid_type = uuid_type;
00586   Osal_MemCpy(cp.uuid, uuid, uuid_len);
00587 
00588   Osal_MemSet(&rq, 0, sizeof(rq));
00589   rq.ogf = OGF_VENDOR_CMD;
00590   rq.ocf = OCF_ATT_READ_BY_GROUP_TYPE_REQ;
00591   rq.cparam = &cp;
00592   rq.clen = ATT_READ_BY_GROUP_TYPE_REQ_CP_SIZE + uuid_len;
00593   rq.rparam = &status;
00594   rq.rlen = 1;
00595 
00596   if (hci_send_req(&rq, FALSE) < 0)
00597     return BLE_STATUS_TIMEOUT;
00598 
00599   return status;
00600 }
00601 
00602 tBleStatus aci_att_prepare_write_req(uint16_t conn_handle, uint16_t attr_handle, uint16_t value_offset,
00603                                     uint8_t  attr_val_len, uint8_t* attr_val)
00604 {
00605   struct hci_request rq;
00606   uint8_t status;
00607   att_prepare_write_req_cp cp;
00608   
00609   if(attr_val_len > sizeof(cp.attr_val))
00610     return BLE_STATUS_INVALID_PARAMS;
00611 
00612   cp.conn_handle = htobs(conn_handle);
00613   cp.attr_handle = htobs(attr_handle);
00614   cp.value_offset = htobs(value_offset);
00615   cp.attr_val_len = attr_val_len;
00616   Osal_MemCpy(cp.attr_val, attr_val, attr_val_len);
00617 
00618   Osal_MemSet(&rq, 0, sizeof(rq));
00619   rq.ogf = OGF_VENDOR_CMD;
00620   rq.ocf = OCF_ATT_PREPARE_WRITE_REQ;
00621   rq.cparam = &cp;
00622   rq.clen = ATT_PREPARE_WRITE_REQ_CP_SIZE + attr_val_len;
00623   rq.rparam = &status;
00624   rq.rlen = 1;
00625 
00626   if (hci_send_req(&rq, FALSE) < 0)
00627     return BLE_STATUS_TIMEOUT;
00628 
00629   return status;
00630 }
00631 
00632 tBleStatus aci_att_execute_write_req(uint16_t conn_handle, uint8_t execute)
00633 {
00634   struct hci_request rq;
00635   uint8_t status;
00636   att_execute_write_req_cp cp;
00637 
00638   cp.conn_handle = htobs(conn_handle);
00639   cp.execute = execute;
00640 
00641   Osal_MemSet(&rq, 0, sizeof(rq));
00642   rq.ogf = OGF_VENDOR_CMD;
00643   rq.ocf = OCF_ATT_EXECUTE_WRITE_REQ;
00644   rq.cparam = &cp;
00645   rq.clen = ATT_EXECUTE_WRITE_REQ_CP_SIZE;
00646   rq.rparam = &status;
00647   rq.rlen = 1;
00648 
00649   if (hci_send_req(&rq, FALSE) < 0)
00650     return BLE_STATUS_TIMEOUT;
00651 
00652   return status;
00653 }
00654 
00655 tBleStatus aci_gatt_disc_all_prim_services(uint16_t conn_handle)
00656 {
00657   struct hci_request rq;
00658   uint8_t status;
00659   gatt_disc_all_prim_services_cp cp;
00660 
00661   cp.conn_handle = htobs(conn_handle);
00662 
00663   Osal_MemSet(&rq, 0, sizeof(rq));
00664   rq.ogf = OGF_VENDOR_CMD;
00665   rq.ocf = OCF_GATT_DISC_ALL_PRIM_SERVICES;
00666   rq.cparam = &cp;
00667   rq.clen = GATT_DISC_ALL_PRIM_SERVICES_CP_SIZE;
00668   rq.event = EVT_CMD_STATUS;
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 
00678 tBleStatus aci_gatt_disc_prim_service_by_uuid(uint16_t conn_handle, uint8_t uuid_type, uint8_t* uuid)
00679 {
00680   struct hci_request rq;
00681   uint8_t status;
00682   gatt_disc_prim_service_by_uuid_cp cp;
00683   uint8_t uuid_len;
00684   
00685   if(uuid_type == UUID_TYPE_16){
00686     uuid_len = 2;
00687   }
00688   else{
00689     uuid_len = 16;
00690   }
00691 
00692   cp.conn_handle = htobs(conn_handle);
00693   cp.uuid_type = uuid_type;
00694   Osal_MemCpy(cp.uuid, uuid, uuid_len);
00695 
00696   Osal_MemSet(&rq, 0, sizeof(rq));
00697   rq.ogf = OGF_VENDOR_CMD;
00698   rq.ocf = OCF_GATT_DISC_PRIM_SERVICE_BY_UUID;
00699   rq.cparam = &cp;
00700   rq.clen = GATT_DISC_PRIM_SERVICE_BY_UUID_CP_SIZE + uuid_len;
00701   rq.event = EVT_CMD_STATUS;
00702   rq.rparam = &status;
00703   rq.rlen = 1;
00704 
00705   if (hci_send_req(&rq, FALSE) < 0)
00706     return BLE_STATUS_TIMEOUT;
00707 
00708   return status;
00709 }
00710 
00711 tBleStatus aci_gatt_find_included_services(uint16_t conn_handle, uint16_t start_service_handle, 
00712                        uint16_t end_service_handle)
00713 {
00714   struct hci_request rq;
00715   uint8_t status;
00716   gatt_find_included_services_cp cp;
00717 
00718   cp.conn_handle = htobs(conn_handle);
00719   cp.start_handle = htobs(start_service_handle);
00720   cp.end_handle = htobs(end_service_handle);
00721 
00722   Osal_MemSet(&rq, 0, sizeof(rq));
00723   rq.ogf = OGF_VENDOR_CMD;
00724   rq.ocf = OCF_GATT_FIND_INCLUDED_SERVICES;
00725   rq.cparam = &cp;
00726   rq.clen = GATT_FIND_INCLUDED_SERVICES_CP_SIZE;
00727   rq.event = EVT_CMD_STATUS;
00728   rq.rparam = &status;
00729   rq.rlen = 1;
00730 
00731   if (hci_send_req(&rq, FALSE) < 0)
00732     return BLE_STATUS_TIMEOUT;
00733 
00734   return status;
00735 }
00736 
00737 tBleStatus aci_gatt_disc_all_charac_of_serv(uint16_t conn_handle, uint16_t start_attr_handle, 
00738                         uint16_t end_attr_handle)
00739 {
00740   struct hci_request rq;
00741   uint8_t status;
00742   gatt_disc_all_charac_of_serv_cp cp;
00743 
00744   cp.conn_handle = htobs(conn_handle);
00745   cp.start_attr_handle = htobs(start_attr_handle);
00746   cp.end_attr_handle = htobs(end_attr_handle);
00747 
00748   Osal_MemSet(&rq, 0, sizeof(rq));
00749   rq.ogf = OGF_VENDOR_CMD;
00750   rq.ocf = OCF_GATT_DISC_ALL_CHARAC_OF_SERV;
00751   rq.cparam = &cp;
00752   rq.clen = GATT_DISC_ALL_CHARAC_OF_SERV_CP_SIZE;
00753   rq.event = EVT_CMD_STATUS;
00754   rq.rparam = &status;
00755   rq.rlen = 1;
00756 
00757   if (hci_send_req(&rq, FALSE) < 0)
00758     return BLE_STATUS_TIMEOUT;
00759 
00760   return status;
00761 }
00762 
00763 tBleStatus aci_gatt_disc_charac_by_uuid(uint16_t conn_handle, uint16_t start_handle,
00764                                      uint16_t end_handle, uint8_t charUuidType,
00765                                                      const uint8_t* charUuid)
00766 {
00767   struct hci_request rq;
00768   uint8_t status;
00769   
00770   uint8_t buffer[23];
00771   uint8_t uuid_len;
00772   uint8_t indx = 0;
00773     
00774   conn_handle = htobs(conn_handle);
00775   Osal_MemCpy(buffer + indx, &conn_handle, 2);
00776   indx += 2;
00777     
00778   start_handle = htobs(start_handle);
00779   Osal_MemCpy(buffer + indx, &start_handle, 2);
00780   indx += 2;
00781   
00782   end_handle = htobs(end_handle);
00783   Osal_MemCpy(buffer + indx, &end_handle, 2);
00784   indx += 2;
00785   
00786   buffer[indx] = charUuidType;
00787   indx++;
00788     
00789   if(charUuidType == 0x01){
00790     uuid_len = 2;
00791   }
00792   else {
00793     uuid_len = 16;
00794   }        
00795   Osal_MemCpy(buffer + indx, charUuid, uuid_len);
00796   indx +=  uuid_len;
00797 
00798   Osal_MemSet(&rq, 0, sizeof(rq));
00799   rq.ogf = OGF_VENDOR_CMD;
00800   rq.ocf = OCF_GATT_DISC_CHARAC_BY_UUID;
00801   rq.cparam = (void *)buffer;
00802   rq.clen = indx;
00803   rq.event = EVT_CMD_STATUS;
00804   rq.rparam = &status;
00805   rq.rlen = 1;
00806 
00807   if (hci_send_req(&rq, FALSE) < 0)
00808     return BLE_STATUS_TIMEOUT;
00809 
00810   return status;
00811 }
00812 
00813 tBleStatus aci_gatt_disc_all_charac_descriptors(uint16_t conn_handle, uint16_t char_val_handle, 
00814                         uint16_t char_end_handle)
00815 {
00816   struct hci_request rq;
00817   uint8_t status;
00818   gatt_disc_all_charac_descriptors_cp cp;
00819 
00820   cp.conn_handle = htobs(conn_handle);
00821   cp.char_val_handle = htobs(char_val_handle);
00822   cp.char_end_handle = htobs(char_end_handle);
00823 
00824   Osal_MemSet(&rq, 0, sizeof(rq));
00825   rq.ogf = OGF_VENDOR_CMD;
00826   rq.ocf = OCF_GATT_DISC_ALL_CHARAC_DESCRIPTORS;
00827   rq.cparam = &cp;
00828   rq.clen = GATT_DISC_ALL_CHARAC_DESCRIPTORS_CP_SIZE;
00829   rq.event = EVT_CMD_STATUS;
00830   rq.rparam = &status;
00831   rq.rlen = 1;
00832 
00833   if (hci_send_req(&rq, FALSE) < 0)
00834     return BLE_STATUS_TIMEOUT;
00835 
00836   return status;
00837 }
00838 
00839 tBleStatus aci_gatt_read_charac_val(uint16_t conn_handle, uint16_t attr_handle)
00840 {
00841   struct hci_request rq;
00842   uint8_t status;
00843   gatt_read_charac_val_cp cp;
00844 
00845   cp.conn_handle = htobs(conn_handle);
00846   cp.attr_handle = htobs(attr_handle);
00847 
00848   Osal_MemSet(&rq, 0, sizeof(rq));
00849   rq.ogf = OGF_VENDOR_CMD;
00850   rq.ocf = OCF_GATT_READ_CHARAC_VAL;
00851   rq.cparam = &cp;
00852   rq.clen = GATT_READ_CHARAC_VAL_CP_SIZE;
00853   rq.event = EVT_CMD_STATUS;
00854   rq.rparam = &status;
00855   rq.rlen = 1;
00856 
00857   if (hci_send_req(&rq, FALSE) < 0)
00858     return BLE_STATUS_TIMEOUT;
00859   
00860   return status;
00861 }
00862 
00863 tBleStatus aci_gatt_read_using_charac_uuid(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle,
00864                                     uint8_t  uuid_type, uint8_t* uuid)
00865 {
00866   struct hci_request rq;
00867   uint8_t status;
00868   gatt_read_using_charac_uuid_cp cp;
00869   uint8_t uuid_len;
00870   
00871   if(uuid_type == UUID_TYPE_16){
00872     uuid_len = 2;
00873   }
00874   else{
00875     uuid_len = 16;
00876   }
00877 
00878   cp.conn_handle = htobs(conn_handle);
00879   cp.start_handle = htobs(start_handle);
00880   cp.end_handle = htobs(end_handle);
00881   cp.uuid_type = uuid_type;
00882   Osal_MemCpy(cp.uuid, uuid, uuid_len);
00883 
00884   Osal_MemSet(&rq, 0, sizeof(rq));
00885   rq.ogf = OGF_VENDOR_CMD;
00886   rq.ocf = OCF_GATT_READ_USING_CHARAC_UUID;
00887   rq.cparam = &cp;
00888   rq.clen = GATT_READ_USING_CHARAC_UUID_CP_SIZE + uuid_len;
00889   rq.rparam = &status;
00890   rq.rlen = 1;
00891 
00892   if (hci_send_req(&rq, FALSE) < 0)
00893     return BLE_STATUS_TIMEOUT;
00894 
00895   return status;
00896 }
00897 
00898 tBleStatus aci_gatt_read_long_charac_val(uint16_t conn_handle, uint16_t attr_handle, 
00899                      uint16_t val_offset)
00900 {
00901   struct hci_request rq;
00902   uint8_t status;
00903   gatt_read_long_charac_val_cp cp;
00904 
00905   cp.conn_handle = htobs(conn_handle);
00906   cp.attr_handle = htobs(attr_handle);
00907   cp.val_offset = htobs(val_offset);
00908 
00909   Osal_MemSet(&rq, 0, sizeof(rq));
00910   rq.ogf = OGF_VENDOR_CMD;
00911   rq.ocf = OCF_GATT_READ_LONG_CHARAC_VAL;
00912   rq.cparam = &cp;
00913   rq.clen = GATT_READ_LONG_CHARAC_VAL_CP_SIZE;
00914   rq.event = EVT_CMD_STATUS;
00915   rq.rparam = &status;
00916   rq.rlen = 1;
00917 
00918   if (hci_send_req(&rq, FALSE) < 0)
00919     return BLE_STATUS_TIMEOUT;
00920 
00921   return status;
00922 }
00923 
00924 tBleStatus aci_gatt_read_multiple_charac_val(uint16_t conn_handle, uint8_t num_handles, 
00925                                              uint8_t* set_of_handles)
00926 {
00927   struct hci_request rq;
00928   uint8_t status;
00929   gatt_read_multiple_charac_val_cp cp;
00930   
00931   if(num_handles*2 > sizeof(cp.set_of_handles))
00932     return BLE_STATUS_INVALID_PARAMS;
00933 
00934   cp.conn_handle = htobs(conn_handle);
00935   cp.num_handles = htobs(num_handles);
00936   Osal_MemCpy(cp.set_of_handles, set_of_handles, 2*num_handles);
00937 
00938   Osal_MemSet(&rq, 0, sizeof(rq));
00939   rq.ogf = OGF_VENDOR_CMD;
00940   rq.ocf = OCF_GATT_READ_MULTIPLE_CHARAC_VAL;
00941   rq.cparam = &cp;
00942   rq.clen = GATT_READ_MULTIPLE_CHARAC_VAL_CP_SIZE + 2*num_handles;
00943   rq.event = EVT_CMD_STATUS;
00944   rq.rparam = &status;
00945   rq.rlen = 1;
00946 
00947   if (hci_send_req(&rq, FALSE) < 0)
00948     return BLE_STATUS_TIMEOUT;
00949 
00950   return status;
00951 }
00952 
00953 
00954 
00955 tBleStatus aci_gatt_write_charac_value(uint16_t conn_handle, uint16_t attr_handle, 
00956                        uint8_t value_len, uint8_t *attr_value)
00957 {
00958   struct hci_request rq;
00959   uint8_t status;
00960   uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
00961   uint8_t indx = 0;
00962     
00963   if ((value_len+5) > HCI_MAX_PAYLOAD_SIZE)
00964     return BLE_STATUS_INVALID_PARAMS;
00965 
00966   conn_handle = htobs(conn_handle);
00967   Osal_MemCpy(buffer + indx, &conn_handle, 2);
00968   indx += 2;
00969     
00970   attr_handle = htobs(attr_handle);
00971   Osal_MemCpy(buffer + indx, &attr_handle, 2);
00972   indx += 2;
00973 
00974   buffer[indx] = value_len;
00975   indx++;
00976         
00977   Osal_MemCpy(buffer + indx, attr_value, value_len);
00978   indx +=  value_len;
00979 
00980   Osal_MemSet(&rq, 0, sizeof(rq));
00981   rq.ogf = OGF_VENDOR_CMD;
00982   rq.ocf = OCF_GATT_WRITE_CHAR_VALUE;
00983   rq.cparam = (void *)buffer;
00984   rq.clen = indx;
00985   rq.event = EVT_CMD_STATUS;
00986   rq.rparam = &status;
00987   rq.rlen = 1;
00988 
00989   if (hci_send_req(&rq, FALSE) < 0)
00990     return BLE_STATUS_TIMEOUT;
00991 
00992   return status;
00993 }
00994 
00995 tBleStatus aci_gatt_write_long_charac_val(uint16_t conn_handle, uint16_t attr_handle,
00996                                           uint16_t val_offset, uint8_t val_len, const uint8_t* attr_val)
00997 {
00998   struct hci_request rq;
00999   uint8_t status;
01000   gatt_write_long_charac_val_cp cp;
01001   
01002   if(val_len > sizeof(cp.attr_val))
01003     return BLE_STATUS_INVALID_PARAMS;
01004 
01005   cp.conn_handle = htobs(conn_handle);
01006   cp.attr_handle = htobs(attr_handle);
01007   cp.val_offset = htobs(val_offset);
01008   cp.val_len = val_len;
01009   Osal_MemCpy(cp.attr_val, attr_val, val_len);
01010 
01011   Osal_MemSet(&rq, 0, sizeof(rq));
01012   rq.ogf = OGF_VENDOR_CMD;
01013   rq.ocf = OCF_GATT_WRITE_LONG_CHARAC_VAL;
01014   rq.cparam = &cp;
01015   rq.clen = GATT_WRITE_LONG_CHARAC_VAL_CP_SIZE + val_len;
01016   rq.event = EVT_CMD_STATUS;
01017   rq.rparam = &status;
01018   rq.rlen = 1;
01019 
01020   if (hci_send_req(&rq, FALSE) < 0)
01021     return BLE_STATUS_TIMEOUT;
01022 
01023   return status;
01024 }
01025 
01026 tBleStatus aci_gatt_write_charac_reliable(uint16_t conn_handle, uint16_t attr_handle,
01027                                           uint16_t val_offset, uint8_t val_len, uint8_t* attr_val)
01028 {
01029   struct hci_request rq;
01030   uint8_t status;
01031   gatt_write_charac_reliable_cp cp;
01032   
01033   if(val_len > sizeof(cp.attr_val))
01034     return BLE_STATUS_INVALID_PARAMS;
01035 
01036   cp.conn_handle = htobs(conn_handle);
01037   cp.attr_handle = htobs(attr_handle);
01038   cp.val_offset = htobs(val_offset);
01039   cp.val_len = val_len;
01040   Osal_MemCpy(cp.attr_val, attr_val, val_len);
01041 
01042   Osal_MemSet(&rq, 0, sizeof(rq));
01043   rq.ogf = OGF_VENDOR_CMD;
01044   rq.ocf = OCF_GATT_WRITE_CHARAC_RELIABLE;
01045   rq.cparam = &cp;
01046   rq.clen = GATT_WRITE_CHARAC_RELIABLE_CP_SIZE + val_len;
01047   rq.event = EVT_CMD_STATUS;
01048   rq.rparam = &status;
01049   rq.rlen = 1;
01050 
01051   if (hci_send_req(&rq, FALSE) < 0)
01052     return BLE_STATUS_TIMEOUT;
01053 
01054   return status;
01055 }
01056 
01057 tBleStatus aci_gatt_write_long_charac_desc(uint16_t conn_handle, uint16_t attr_handle,
01058                                           uint16_t val_offset, uint8_t val_len, uint8_t* attr_val)
01059 {
01060   struct hci_request rq;
01061   uint8_t status;
01062   gatt_write_charac_reliable_cp cp;
01063   
01064   if(val_len > sizeof(cp.attr_val))
01065     return BLE_STATUS_INVALID_PARAMS;
01066 
01067   cp.conn_handle = htobs(conn_handle);
01068   cp.attr_handle = htobs(attr_handle);
01069   cp.val_offset = htobs(val_offset);
01070   cp.val_len = val_len;
01071   Osal_MemCpy(cp.attr_val, attr_val, val_len);
01072 
01073   Osal_MemSet(&rq, 0, sizeof(rq));
01074   rq.ogf = OGF_VENDOR_CMD;
01075   rq.ocf = OCF_GATT_WRITE_LONG_CHARAC_DESC;
01076   rq.cparam = &cp;
01077   rq.clen = GATT_WRITE_LONG_CHARAC_DESC_CP_SIZE + val_len;
01078   rq.event = EVT_CMD_STATUS;
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 tBleStatus aci_gatt_read_long_charac_desc(uint16_t conn_handle, uint16_t attr_handle,
01089                                           uint16_t val_offset)
01090 {
01091   struct hci_request rq;
01092   uint8_t status;
01093   gatt_read_long_charac_desc_cp cp;
01094 
01095   cp.conn_handle = htobs(conn_handle);
01096   cp.attr_handle = htobs(attr_handle);
01097   cp.val_offset = htobs(val_offset);
01098 
01099   Osal_MemSet(&rq, 0, sizeof(rq));
01100   rq.ogf = OGF_VENDOR_CMD;
01101   rq.ocf = OCF_GATT_READ_LONG_CHARAC_DESC;
01102   rq.cparam = &cp;
01103   rq.clen = GATT_READ_LONG_CHARAC_DESC_CP_SIZE;
01104   rq.event = EVT_CMD_STATUS;
01105   rq.rparam = &status;
01106   rq.rlen = 1;
01107 
01108   if (hci_send_req(&rq, FALSE) < 0)
01109     return BLE_STATUS_TIMEOUT;
01110 
01111   return status;
01112 }
01113 
01114 tBleStatus aci_gatt_write_charac_descriptor(uint16_t conn_handle, uint16_t attr_handle, 
01115                        uint8_t value_len, uint8_t *attr_value)
01116 {
01117   struct hci_request rq;
01118   uint8_t status;
01119   uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
01120   uint8_t indx = 0;
01121     
01122   if ((value_len+5) > HCI_MAX_PAYLOAD_SIZE)
01123     return BLE_STATUS_INVALID_PARAMS;
01124 
01125   conn_handle = htobs(conn_handle);
01126   Osal_MemCpy(buffer + indx, &conn_handle, 2);
01127   indx += 2;
01128     
01129   attr_handle = htobs(attr_handle);
01130   Osal_MemCpy(buffer + indx, &attr_handle, 2);
01131   indx += 2;
01132 
01133   buffer[indx] = value_len;
01134   indx++;
01135         
01136   Osal_MemCpy(buffer + indx, attr_value, value_len);
01137   indx +=  value_len;
01138 
01139   Osal_MemSet(&rq, 0, sizeof(rq));
01140   rq.ogf = OGF_VENDOR_CMD;
01141   rq.ocf = OCF_GATT_WRITE_CHAR_DESCRIPTOR;
01142   rq.cparam = (void *)buffer;
01143   rq.clen = indx;
01144   rq.event = EVT_CMD_STATUS; 
01145   rq.rparam = &status;
01146   rq.rlen = 1;
01147 
01148   if (hci_send_req(&rq, FALSE) < 0)
01149     return BLE_STATUS_TIMEOUT;
01150 
01151   return status;
01152 }
01153 
01154 tBleStatus aci_gatt_read_charac_desc(uint16_t conn_handle, uint16_t attr_handle)
01155 {
01156   struct hci_request rq;
01157   uint8_t status;
01158   gatt_read_long_charac_desc_cp cp;
01159 
01160   cp.conn_handle = htobs(conn_handle);
01161   cp.attr_handle = htobs(attr_handle);
01162 
01163   Osal_MemSet(&rq, 0, sizeof(rq));
01164   rq.ogf = OGF_VENDOR_CMD;
01165   rq.ocf = OCF_GATT_READ_CHAR_DESCRIPTOR;
01166   rq.cparam = &cp;
01167   rq.clen = GATT_READ_CHAR_DESCRIPTOR_CP_SIZE;
01168   rq.event = EVT_CMD_STATUS;
01169   rq.rparam = &status;
01170   rq.rlen = 1;
01171 
01172   if (hci_send_req(&rq, FALSE) < 0)
01173     return BLE_STATUS_TIMEOUT;
01174 
01175   return status;
01176 }
01177 
01178 tBleStatus aci_gatt_write_without_response(uint16_t conn_handle, uint16_t attr_handle,
01179                                               uint8_t val_len, const uint8_t* attr_val)
01180 {
01181   struct hci_request rq;
01182   uint8_t status;
01183   gatt_write_without_resp_cp cp;
01184   
01185   if(val_len > sizeof(cp.attr_val))
01186     return BLE_STATUS_INVALID_PARAMS;
01187 
01188   cp.conn_handle = htobs(conn_handle);
01189   cp.attr_handle = htobs(attr_handle);
01190   cp.val_len = val_len;
01191   Osal_MemCpy(cp.attr_val, attr_val, val_len);
01192 
01193   Osal_MemSet(&rq, 0, sizeof(rq));
01194   rq.ogf = OGF_VENDOR_CMD;
01195   rq.ocf = OCF_GATT_WRITE_WITHOUT_RESPONSE;
01196   rq.cparam = &cp;
01197   rq.clen = GATT_WRITE_WITHOUT_RESPONSE_CP_SIZE + val_len; 
01198   rq.rparam = &status;
01199   rq.rlen = 1;
01200 
01201   if (hci_send_req(&rq, FALSE) < 0)
01202     return BLE_STATUS_TIMEOUT;
01203 
01204   return status;
01205 }
01206 
01207 tBleStatus aci_gatt_signed_write_without_resp(uint16_t conn_handle, uint16_t attr_handle,
01208                                               uint8_t val_len, uint8_t* attr_val)
01209 {
01210   struct hci_request rq;
01211   uint8_t status;
01212   gatt_signed_write_without_resp_cp cp;
01213   
01214   if(val_len > sizeof(cp.attr_val))
01215     return BLE_STATUS_INVALID_PARAMS;
01216 
01217   cp.conn_handle = htobs(conn_handle);
01218   cp.attr_handle = htobs(attr_handle);
01219   cp.val_len = val_len;
01220   Osal_MemCpy(cp.attr_val, attr_val, val_len);
01221 
01222   Osal_MemSet(&rq, 0, sizeof(rq));
01223   rq.ogf = OGF_VENDOR_CMD;
01224   rq.ocf = OCF_GATT_SIGNED_WRITE_WITHOUT_RESPONSE;
01225   rq.cparam = &cp;
01226   rq.clen = GATT_SIGNED_WRITE_WITHOUT_RESPONSE_CP_SIZE + val_len;
01227   rq.rparam = &status;
01228   rq.rlen = 1;
01229 
01230   if (hci_send_req(&rq, FALSE) < 0)
01231     return BLE_STATUS_TIMEOUT;
01232 
01233   return status;
01234 }
01235 
01236 tBleStatus aci_gatt_confirm_indication(uint16_t conn_handle)
01237 {
01238   struct hci_request rq;
01239   uint8_t status;
01240   gatt_confirm_indication_cp cp;
01241 
01242   cp.conn_handle = htobs(conn_handle);
01243   
01244   Osal_MemSet(&rq, 0, sizeof(rq));
01245   rq.ogf = OGF_VENDOR_CMD;
01246   rq.ocf = OCF_GATT_CONFIRM_INDICATION;
01247   rq.cparam = &cp;
01248   rq.clen = GATT_CONFIRM_INDICATION_CP_SIZE;
01249   rq.rparam = &status;
01250   rq.rlen = 1;
01251 
01252   if (hci_send_req(&rq, FALSE) < 0)
01253     return BLE_STATUS_TIMEOUT;
01254   
01255   return status;
01256 }
01257 
01258 tBleStatus aci_gatt_write_response(uint16_t conn_handle,
01259                                    uint16_t attr_handle,
01260                                    uint8_t write_status,
01261                                    uint8_t err_code,
01262                                    uint8_t att_val_len,
01263                                    uint8_t *att_val)
01264 {
01265   struct hci_request rq;
01266   uint8_t status;
01267   uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
01268   uint8_t indx = 0;
01269   
01270   if ((att_val_len+7) > HCI_MAX_PAYLOAD_SIZE)
01271     return BLE_STATUS_INVALID_PARAMS;
01272 
01273   conn_handle = htobs(conn_handle);  
01274   Osal_MemCpy(buffer + indx, &conn_handle, 2);
01275   indx += 2;
01276     
01277   attr_handle = htobs(attr_handle);
01278   Osal_MemCpy(buffer + indx, &attr_handle, 2);
01279   indx += 2;
01280     
01281   buffer[indx] = write_status;
01282   indx += 1;
01283     
01284   buffer[indx] = err_code;
01285   indx += 1;
01286     
01287   buffer[indx] = att_val_len;
01288   indx += 1;
01289     
01290   Osal_MemCpy(buffer + indx, att_val, att_val_len);
01291   indx += att_val_len;
01292 
01293   Osal_MemSet(&rq, 0, sizeof(rq));
01294   rq.ogf = OGF_VENDOR_CMD;
01295   rq.ocf = OCF_GATT_WRITE_RESPONSE;
01296   rq.cparam = (void *)buffer;
01297   rq.clen = indx;
01298   rq.rparam = &status;
01299   rq.rlen = 1;
01300 
01301   if (hci_send_req(&rq, FALSE) < 0)
01302     return BLE_STATUS_TIMEOUT;
01303 
01304   if (status) {
01305     return status;
01306   }
01307 
01308   return 0;
01309 }
01310 
01311 tBleStatus aci_gatt_allow_read(uint16_t conn_handle)
01312 {
01313     struct hci_request rq;
01314     gatt_allow_read_cp cp;
01315     uint8_t status;
01316     
01317     cp.conn_handle = htobs(conn_handle);
01318 
01319     Osal_MemSet(&rq, 0, sizeof(rq));
01320     rq.ogf = OGF_VENDOR_CMD;
01321     rq.ocf = OCF_GATT_ALLOW_READ;
01322     rq.cparam = &cp;
01323     rq.clen = GATT_ALLOW_READ_CP_SIZE;
01324     rq.rparam = &status;
01325     rq.rlen = 1;
01326 
01327     if (hci_send_req(&rq, FALSE) < 0)
01328       return BLE_STATUS_TIMEOUT;
01329 
01330     return status;
01331 }
01332 
01333 tBleStatus aci_gatt_set_security_permission(uint16_t service_handle, uint16_t attr_handle,
01334                                             uint8_t security_permission)
01335 {
01336     struct hci_request rq;
01337     gatt_set_security_permission_cp cp;
01338     uint8_t status;
01339     
01340     cp.service_handle = htobs(service_handle);
01341     cp.attr_handle = htobs(attr_handle);
01342     cp.security_permission = security_permission;
01343 
01344     Osal_MemSet(&rq, 0, sizeof(rq));
01345     rq.ogf = OGF_VENDOR_CMD;
01346     rq.ocf = OCF_GATT_SET_SECURITY_PERMISSION;
01347     rq.cparam = &cp;
01348     rq.clen = GATT_GATT_SET_SECURITY_PERMISSION_CP_SIZE;
01349     rq.rparam = &status;
01350     rq.rlen = 1;
01351 
01352     if (hci_send_req(&rq, FALSE) < 0)
01353       return BLE_STATUS_TIMEOUT;
01354 
01355     return status;
01356 }
01357 
01358 tBleStatus aci_gatt_set_desc_value(uint16_t servHandle, 
01359                    uint16_t charHandle,
01360                    uint16_t charDescHandle,
01361                    uint16_t charDescValOffset,
01362                    uint8_t charDescValueLen,   
01363                    const void *charDescValue)
01364 {
01365   struct hci_request rq;
01366   uint8_t status;
01367   uint8_t buffer[HCI_MAX_PAYLOAD_SIZE];
01368   uint8_t indx = 0;
01369     
01370   if ((charDescValueLen+9) > HCI_MAX_PAYLOAD_SIZE)
01371     return BLE_STATUS_INVALID_PARAMS;
01372 
01373   servHandle = htobs(servHandle);
01374   Osal_MemCpy(buffer + indx, &servHandle, 2);
01375   indx += 2;
01376     
01377   charHandle = htobs(charHandle);
01378   Osal_MemCpy(buffer + indx, &charHandle, 2);
01379   indx += 2;
01380     
01381   charDescHandle = htobs(charDescHandle);
01382   Osal_MemCpy(buffer + indx, &charDescHandle, 2);
01383   indx += 2;
01384     
01385   Osal_MemCpy(buffer + indx, &charDescValOffset, 2);
01386   indx += 2;
01387     
01388   buffer[indx] = charDescValueLen;
01389   indx++;
01390         
01391   Osal_MemCpy(buffer + indx, charDescValue, charDescValueLen);
01392   indx +=  charDescValueLen;
01393 
01394   Osal_MemSet(&rq, 0, sizeof(rq));
01395   rq.ogf = OGF_VENDOR_CMD;
01396   rq.ocf = OCF_GATT_SET_DESC_VAL;
01397   rq.cparam = (void *)buffer;
01398   rq.clen = indx;
01399   rq.rparam = &status;
01400   rq.rlen = 1;
01401 
01402   if (hci_send_req(&rq, FALSE) < 0)
01403     return BLE_STATUS_TIMEOUT;
01404 
01405   return status;
01406 }
01407 
01408 tBleStatus aci_gatt_read_handle_value(uint16_t attr_handle, uint16_t data_len, uint16_t *data_len_out_p, uint8_t *data)
01409 {
01410   struct hci_request rq;
01411   gatt_read_handle_val_cp cp;
01412   gatt_read_handle_val_rp rp;
01413  
01414   if(data_len > sizeof(rp.value))
01415     return BLE_STATUS_INVALID_PARAMS;
01416 
01417   cp.attr_handle = htobs(attr_handle);
01418 
01419   Osal_MemSet(&rq, 0, sizeof(rq));
01420   rq.ogf = OGF_VENDOR_CMD;
01421   rq.ocf = OCF_GATT_READ_HANDLE_VALUE;
01422   rq.cparam = &cp;
01423   rq.clen = sizeof(cp);
01424   rq.rparam = &rp;
01425   rq.rlen = sizeof(rp);
01426 
01427   if (hci_send_req(&rq, FALSE) < 0)
01428     return BLE_STATUS_TIMEOUT;
01429   
01430   if(rp.status)
01431     return rp.status;
01432 
01433   *data_len_out_p = btohs(rp.value_len);
01434 
01435   Osal_MemCpy(data, rp.value, MIN(data_len, *data_len_out_p));
01436 
01437   return 0;
01438 }
01439 
01440 tBleStatus aci_gatt_read_handle_value_offset_IDB05A1(uint16_t attr_handle, uint8_t offset, uint16_t data_len, uint16_t *data_len_out_p, uint8_t *data)
01441 {
01442   struct hci_request rq;
01443   gatt_read_handle_val_offset_cp cp;
01444   gatt_read_handle_val_offset_rp rp;
01445   
01446   if(data_len > sizeof(rp.value))
01447     return BLE_STATUS_INVALID_PARAMS;
01448 
01449   cp.attr_handle = htobs(attr_handle);
01450   cp.offset = offset;
01451 
01452   Osal_MemSet(&rq, 0, sizeof(rq));
01453   rq.ogf = OGF_VENDOR_CMD;
01454   rq.ocf = OCF_GATT_READ_HANDLE_VALUE_OFFSET;
01455   rq.cparam = &cp;
01456   rq.clen = sizeof(cp);
01457   rq.rparam = &rp;
01458   rq.rlen = sizeof(rp);
01459 
01460   if (hci_send_req(&rq, FALSE) < 0)
01461     return BLE_STATUS_TIMEOUT;
01462   
01463   if(rp.status)
01464     return rp.status;
01465 
01466   *data_len_out_p = rp.value_len;
01467 
01468   Osal_MemCpy(data, rp.value, MIN(data_len, *data_len_out_p));
01469 
01470   return 0; 
01471 }