BLE UART example
Fork of Nucleo_BLE_BlueNRG by
hci/src/bluenrg_hci.c@3:104f1bba39ca, 2016-01-03 (annotated)
- Committer:
- sjallouli
- Date:
- Sun Jan 03 16:05:38 2016 +0000
- Revision:
- 3:104f1bba39ca
- Parent:
- 0:a948f5f3904c
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sjallouli | 0:a948f5f3904c | 1 | /******************** (C) COPYRIGHT 2013 STMicroelectronics ******************** |
sjallouli | 0:a948f5f3904c | 2 | * File Name : bluenrg_hci.c |
sjallouli | 0:a948f5f3904c | 3 | * Author : AMS - HEA&RF BU |
sjallouli | 0:a948f5f3904c | 4 | * Version : V1.0.0 |
sjallouli | 0:a948f5f3904c | 5 | * Date : 4-Oct-2013 |
sjallouli | 0:a948f5f3904c | 6 | * Description : File with HCI commands for BlueNRG FW6.0 and above. |
sjallouli | 0:a948f5f3904c | 7 | ******************************************************************************** |
sjallouli | 0:a948f5f3904c | 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
sjallouli | 0:a948f5f3904c | 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
sjallouli | 0:a948f5f3904c | 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
sjallouli | 0:a948f5f3904c | 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
sjallouli | 0:a948f5f3904c | 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
sjallouli | 0:a948f5f3904c | 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
sjallouli | 0:a948f5f3904c | 14 | *******************************************************************************/ |
sjallouli | 0:a948f5f3904c | 15 | |
sjallouli | 0:a948f5f3904c | 16 | #include "hal_types.h" |
sjallouli | 0:a948f5f3904c | 17 | #include "osal.h" |
sjallouli | 0:a948f5f3904c | 18 | #include "ble_status.h" |
sjallouli | 0:a948f5f3904c | 19 | #include "hal.h" |
sjallouli | 0:a948f5f3904c | 20 | #include "osal.h" |
sjallouli | 0:a948f5f3904c | 21 | #include "hci_internal.h" |
sjallouli | 0:a948f5f3904c | 22 | #include "bluenrg_hci_internal.h" |
sjallouli | 0:a948f5f3904c | 23 | #include "gatt_service.h" |
sjallouli | 0:a948f5f3904c | 24 | |
sjallouli | 0:a948f5f3904c | 25 | |
sjallouli | 0:a948f5f3904c | 26 | tBleStatus aci_gatt_init() |
sjallouli | 0:a948f5f3904c | 27 | { |
sjallouli | 0:a948f5f3904c | 28 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 29 | tHalUint8 status; |
sjallouli | 0:a948f5f3904c | 30 | |
sjallouli | 0:a948f5f3904c | 31 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 32 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 33 | rq.ocf = OCF_GATT_INIT; |
sjallouli | 0:a948f5f3904c | 34 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 35 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 36 | |
sjallouli | 0:a948f5f3904c | 37 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 38 | return -1; |
sjallouli | 0:a948f5f3904c | 39 | |
sjallouli | 0:a948f5f3904c | 40 | if (status) { |
sjallouli | 0:a948f5f3904c | 41 | return status; |
sjallouli | 0:a948f5f3904c | 42 | } |
sjallouli | 0:a948f5f3904c | 43 | |
sjallouli | 0:a948f5f3904c | 44 | return 0; |
sjallouli | 0:a948f5f3904c | 45 | } |
sjallouli | 0:a948f5f3904c | 46 | |
sjallouli | 0:a948f5f3904c | 47 | tBleStatus aci_gap_init(uint8_t role, uint16_t* service_handle, uint16_t* dev_name_char_handle, uint16_t* appearance_char_handle) |
sjallouli | 0:a948f5f3904c | 48 | { |
sjallouli | 0:a948f5f3904c | 49 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 50 | gap_init_cp cp; |
sjallouli | 0:a948f5f3904c | 51 | gap_init_rp resp; |
sjallouli | 0:a948f5f3904c | 52 | |
sjallouli | 0:a948f5f3904c | 53 | cp.role = role; |
sjallouli | 0:a948f5f3904c | 54 | |
sjallouli | 0:a948f5f3904c | 55 | Osal_MemSet(&resp, 0, sizeof(resp)); |
sjallouli | 0:a948f5f3904c | 56 | |
sjallouli | 0:a948f5f3904c | 57 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 58 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 59 | rq.ocf = OCF_GAP_INIT; |
sjallouli | 0:a948f5f3904c | 60 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 61 | rq.clen = GAP_INIT_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 62 | rq.rparam = &resp; |
sjallouli | 0:a948f5f3904c | 63 | rq.rlen = GAP_INIT_RP_SIZE; |
sjallouli | 0:a948f5f3904c | 64 | |
sjallouli | 0:a948f5f3904c | 65 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 66 | return -1; |
sjallouli | 0:a948f5f3904c | 67 | |
sjallouli | 0:a948f5f3904c | 68 | if (resp.status) { |
sjallouli | 0:a948f5f3904c | 69 | return resp.status; |
sjallouli | 0:a948f5f3904c | 70 | } |
sjallouli | 0:a948f5f3904c | 71 | |
sjallouli | 0:a948f5f3904c | 72 | *service_handle = resp.service_handle; |
sjallouli | 0:a948f5f3904c | 73 | *dev_name_char_handle = resp.dev_name_char_handle; |
sjallouli | 0:a948f5f3904c | 74 | *appearance_char_handle = resp.appearance_char_handle; |
sjallouli | 0:a948f5f3904c | 75 | |
sjallouli | 0:a948f5f3904c | 76 | return 0; |
sjallouli | 0:a948f5f3904c | 77 | } |
sjallouli | 0:a948f5f3904c | 78 | |
sjallouli | 0:a948f5f3904c | 79 | tBleStatus aci_gap_set_non_discoverable(void) |
sjallouli | 0:a948f5f3904c | 80 | { |
sjallouli | 0:a948f5f3904c | 81 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 82 | tHalUint8 status; |
sjallouli | 0:a948f5f3904c | 83 | |
sjallouli | 0:a948f5f3904c | 84 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 85 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 86 | rq.ocf = OCF_GAP_SET_NON_DISCOVERABLE; |
sjallouli | 0:a948f5f3904c | 87 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 88 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 89 | |
sjallouli | 0:a948f5f3904c | 90 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 91 | return -1; |
sjallouli | 0:a948f5f3904c | 92 | |
sjallouli | 0:a948f5f3904c | 93 | return status; |
sjallouli | 0:a948f5f3904c | 94 | } |
sjallouli | 0:a948f5f3904c | 95 | |
sjallouli | 0:a948f5f3904c | 96 | tBleStatus aci_gap_set_discoverable(uint8_t AdvType, uint16_t AdvIntervMin, uint16_t AdvIntervMax, |
sjallouli | 0:a948f5f3904c | 97 | uint8_t OwnAddrType, uint8_t AdvFilterPolicy, uint8_t LocalNameLen, |
sjallouli | 0:a948f5f3904c | 98 | const char *LocalName, uint8_t ServiceUUIDLen, const uint8_t* ServiceUUIDList, |
sjallouli | 0:a948f5f3904c | 99 | uint16_t SlaveConnIntervMin, uint16_t SlaveConnIntervMax) |
sjallouli | 0:a948f5f3904c | 100 | { |
sjallouli | 0:a948f5f3904c | 101 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 102 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 103 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 104 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 105 | |
sjallouli | 0:a948f5f3904c | 106 | buffer[indx] = AdvType; |
sjallouli | 0:a948f5f3904c | 107 | indx++; |
sjallouli | 0:a948f5f3904c | 108 | |
sjallouli | 0:a948f5f3904c | 109 | Osal_MemCpy(buffer + indx, &AdvIntervMin, 2); |
sjallouli | 0:a948f5f3904c | 110 | indx += 2; |
sjallouli | 0:a948f5f3904c | 111 | |
sjallouli | 0:a948f5f3904c | 112 | Osal_MemCpy(buffer + indx, &AdvIntervMax, 2); |
sjallouli | 0:a948f5f3904c | 113 | indx += 2; |
sjallouli | 0:a948f5f3904c | 114 | |
sjallouli | 0:a948f5f3904c | 115 | buffer[indx] = OwnAddrType; |
sjallouli | 0:a948f5f3904c | 116 | indx++; |
sjallouli | 0:a948f5f3904c | 117 | |
sjallouli | 0:a948f5f3904c | 118 | buffer[indx] = AdvFilterPolicy; |
sjallouli | 0:a948f5f3904c | 119 | indx++; |
sjallouli | 0:a948f5f3904c | 120 | |
sjallouli | 0:a948f5f3904c | 121 | buffer[indx] = LocalNameLen; |
sjallouli | 0:a948f5f3904c | 122 | indx++; |
sjallouli | 0:a948f5f3904c | 123 | |
sjallouli | 0:a948f5f3904c | 124 | Osal_MemCpy(buffer + indx, LocalName, LocalNameLen); |
sjallouli | 0:a948f5f3904c | 125 | indx += LocalNameLen; |
sjallouli | 0:a948f5f3904c | 126 | |
sjallouli | 0:a948f5f3904c | 127 | buffer[indx] = ServiceUUIDLen; |
sjallouli | 0:a948f5f3904c | 128 | indx++; |
sjallouli | 0:a948f5f3904c | 129 | |
sjallouli | 0:a948f5f3904c | 130 | Osal_MemCpy(buffer + indx, ServiceUUIDList, ServiceUUIDLen); |
sjallouli | 0:a948f5f3904c | 131 | indx += ServiceUUIDLen; |
sjallouli | 0:a948f5f3904c | 132 | |
sjallouli | 0:a948f5f3904c | 133 | Osal_MemCpy(buffer + indx, &SlaveConnIntervMin, 2); |
sjallouli | 0:a948f5f3904c | 134 | indx += 2; |
sjallouli | 0:a948f5f3904c | 135 | |
sjallouli | 0:a948f5f3904c | 136 | Osal_MemCpy(buffer + indx, &SlaveConnIntervMax, 2); |
sjallouli | 0:a948f5f3904c | 137 | indx += 2; |
sjallouli | 0:a948f5f3904c | 138 | |
sjallouli | 0:a948f5f3904c | 139 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 140 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 141 | rq.ocf = OCF_GAP_SET_DISCOVERABLE; |
sjallouli | 0:a948f5f3904c | 142 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 143 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 144 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 145 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 146 | |
sjallouli | 0:a948f5f3904c | 147 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 148 | return -1; |
sjallouli | 0:a948f5f3904c | 149 | |
sjallouli | 0:a948f5f3904c | 150 | if (status) { |
sjallouli | 0:a948f5f3904c | 151 | return status; |
sjallouli | 0:a948f5f3904c | 152 | } |
sjallouli | 0:a948f5f3904c | 153 | |
sjallouli | 0:a948f5f3904c | 154 | return 0; |
sjallouli | 0:a948f5f3904c | 155 | } |
sjallouli | 0:a948f5f3904c | 156 | |
sjallouli | 0:a948f5f3904c | 157 | tBleStatus aci_gap_update_adv_data(uint8_t AdvLen, const uint8_t *AdvData) |
sjallouli | 0:a948f5f3904c | 158 | { |
sjallouli | 0:a948f5f3904c | 159 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 160 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 161 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 162 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 163 | |
sjallouli | 0:a948f5f3904c | 164 | buffer[indx] = AdvLen; |
sjallouli | 0:a948f5f3904c | 165 | indx++; |
sjallouli | 0:a948f5f3904c | 166 | |
sjallouli | 0:a948f5f3904c | 167 | Osal_MemCpy(buffer + indx, AdvData, AdvLen); |
sjallouli | 0:a948f5f3904c | 168 | indx += AdvLen; |
sjallouli | 0:a948f5f3904c | 169 | |
sjallouli | 0:a948f5f3904c | 170 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 171 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 172 | rq.ocf = OCF_GAP_UPDATE_ADV_DATA; |
sjallouli | 0:a948f5f3904c | 173 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 174 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 175 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 176 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 177 | |
sjallouli | 0:a948f5f3904c | 178 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 179 | return -1; |
sjallouli | 0:a948f5f3904c | 180 | |
sjallouli | 0:a948f5f3904c | 181 | return status; |
sjallouli | 0:a948f5f3904c | 182 | } |
sjallouli | 0:a948f5f3904c | 183 | |
sjallouli | 0:a948f5f3904c | 184 | |
sjallouli | 0:a948f5f3904c | 185 | tBleStatus aci_gatt_add_serv(tHalUint8 service_uuid_type, const tHalUint8* service_uuid, tHalUint8 service_type, tHalUint8 max_attr_records, tHalUint16 *serviceHandle) |
sjallouli | 0:a948f5f3904c | 186 | { |
sjallouli | 0:a948f5f3904c | 187 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 188 | gatt_add_serv_rp resp; |
sjallouli | 0:a948f5f3904c | 189 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 190 | uint8_t uuid_len; |
sjallouli | 0:a948f5f3904c | 191 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 192 | |
sjallouli | 0:a948f5f3904c | 193 | buffer[indx] = service_uuid_type; |
sjallouli | 0:a948f5f3904c | 194 | indx++; |
sjallouli | 0:a948f5f3904c | 195 | |
sjallouli | 0:a948f5f3904c | 196 | if(service_uuid_type == 0x01){ |
sjallouli | 0:a948f5f3904c | 197 | uuid_len = 2; |
sjallouli | 0:a948f5f3904c | 198 | } |
sjallouli | 0:a948f5f3904c | 199 | else { |
sjallouli | 0:a948f5f3904c | 200 | uuid_len = 16; |
sjallouli | 0:a948f5f3904c | 201 | } |
sjallouli | 0:a948f5f3904c | 202 | Osal_MemCpy(buffer + indx, service_uuid, uuid_len); |
sjallouli | 0:a948f5f3904c | 203 | indx += uuid_len; |
sjallouli | 0:a948f5f3904c | 204 | |
sjallouli | 0:a948f5f3904c | 205 | buffer[indx] = service_type; |
sjallouli | 0:a948f5f3904c | 206 | indx++; |
sjallouli | 0:a948f5f3904c | 207 | |
sjallouli | 0:a948f5f3904c | 208 | buffer[indx] = max_attr_records; |
sjallouli | 0:a948f5f3904c | 209 | indx++; |
sjallouli | 0:a948f5f3904c | 210 | |
sjallouli | 0:a948f5f3904c | 211 | |
sjallouli | 0:a948f5f3904c | 212 | Osal_MemSet(&resp, 0, sizeof(resp)); |
sjallouli | 0:a948f5f3904c | 213 | |
sjallouli | 0:a948f5f3904c | 214 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 215 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 216 | rq.ocf = OCF_GATT_ADD_SERV; |
sjallouli | 0:a948f5f3904c | 217 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 218 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 219 | rq.rparam = &resp; |
sjallouli | 0:a948f5f3904c | 220 | rq.rlen = GATT_ADD_SERV_RP_SIZE; |
sjallouli | 0:a948f5f3904c | 221 | |
sjallouli | 0:a948f5f3904c | 222 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 223 | return -1; |
sjallouli | 0:a948f5f3904c | 224 | |
sjallouli | 0:a948f5f3904c | 225 | if (resp.status) { |
sjallouli | 0:a948f5f3904c | 226 | return resp.status; |
sjallouli | 0:a948f5f3904c | 227 | } |
sjallouli | 0:a948f5f3904c | 228 | |
sjallouli | 0:a948f5f3904c | 229 | *serviceHandle = resp.handle; |
sjallouli | 0:a948f5f3904c | 230 | |
sjallouli | 0:a948f5f3904c | 231 | return 0; |
sjallouli | 0:a948f5f3904c | 232 | } |
sjallouli | 0:a948f5f3904c | 233 | |
sjallouli | 0:a948f5f3904c | 234 | tBleStatus aci_gatt_add_char(tHalUint16 serviceHandle, |
sjallouli | 0:a948f5f3904c | 235 | tUuidType charUuidType, |
sjallouli | 0:a948f5f3904c | 236 | const tHalUint8* charUuid, |
sjallouli | 0:a948f5f3904c | 237 | tHalUint16 charValueLen, |
sjallouli | 0:a948f5f3904c | 238 | tHalUint8 charProperties, |
sjallouli | 0:a948f5f3904c | 239 | tAttrSecurityFlags secPermissions, |
sjallouli | 0:a948f5f3904c | 240 | tGattServerEvent gattEvtMask, |
sjallouli | 0:a948f5f3904c | 241 | tHalUint8 encryKeySize, |
sjallouli | 0:a948f5f3904c | 242 | tHalUint8 isVariable, |
sjallouli | 0:a948f5f3904c | 243 | tHalUint16* charHandle) |
sjallouli | 0:a948f5f3904c | 244 | |
sjallouli | 0:a948f5f3904c | 245 | |
sjallouli | 0:a948f5f3904c | 246 | { |
sjallouli | 0:a948f5f3904c | 247 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 248 | gatt_add_serv_rp resp; |
sjallouli | 0:a948f5f3904c | 249 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 250 | uint8_t uuid_len; |
sjallouli | 0:a948f5f3904c | 251 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 252 | |
sjallouli | 0:a948f5f3904c | 253 | Osal_MemCpy(buffer + indx, &serviceHandle, 2); |
sjallouli | 0:a948f5f3904c | 254 | indx += 2; |
sjallouli | 0:a948f5f3904c | 255 | |
sjallouli | 0:a948f5f3904c | 256 | buffer[indx] = charUuidType; |
sjallouli | 0:a948f5f3904c | 257 | indx++; |
sjallouli | 0:a948f5f3904c | 258 | |
sjallouli | 0:a948f5f3904c | 259 | if(charUuidType == 0x01){ |
sjallouli | 0:a948f5f3904c | 260 | uuid_len = 2; |
sjallouli | 0:a948f5f3904c | 261 | } |
sjallouli | 0:a948f5f3904c | 262 | else { |
sjallouli | 0:a948f5f3904c | 263 | uuid_len = 16; |
sjallouli | 0:a948f5f3904c | 264 | } |
sjallouli | 0:a948f5f3904c | 265 | Osal_MemCpy(buffer + indx, charUuid, uuid_len); |
sjallouli | 0:a948f5f3904c | 266 | indx += uuid_len; |
sjallouli | 0:a948f5f3904c | 267 | |
sjallouli | 0:a948f5f3904c | 268 | buffer[indx] = charValueLen; |
sjallouli | 0:a948f5f3904c | 269 | indx++; |
sjallouli | 0:a948f5f3904c | 270 | |
sjallouli | 0:a948f5f3904c | 271 | buffer[indx] = charProperties; |
sjallouli | 0:a948f5f3904c | 272 | indx++; |
sjallouli | 0:a948f5f3904c | 273 | |
sjallouli | 0:a948f5f3904c | 274 | buffer[indx] = secPermissions; |
sjallouli | 0:a948f5f3904c | 275 | indx++; |
sjallouli | 0:a948f5f3904c | 276 | |
sjallouli | 0:a948f5f3904c | 277 | buffer[indx] = gattEvtMask; |
sjallouli | 0:a948f5f3904c | 278 | indx++; |
sjallouli | 0:a948f5f3904c | 279 | |
sjallouli | 0:a948f5f3904c | 280 | buffer[indx] = encryKeySize; |
sjallouli | 0:a948f5f3904c | 281 | indx++; |
sjallouli | 0:a948f5f3904c | 282 | |
sjallouli | 0:a948f5f3904c | 283 | buffer[indx] = isVariable; |
sjallouli | 0:a948f5f3904c | 284 | indx++; |
sjallouli | 0:a948f5f3904c | 285 | |
sjallouli | 0:a948f5f3904c | 286 | Osal_MemSet(&resp, 0, sizeof(resp)); |
sjallouli | 0:a948f5f3904c | 287 | |
sjallouli | 0:a948f5f3904c | 288 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 289 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 290 | rq.ocf = OCF_GATT_ADD_CHAR; |
sjallouli | 0:a948f5f3904c | 291 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 292 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 293 | rq.rparam = &resp; |
sjallouli | 0:a948f5f3904c | 294 | rq.rlen = GATT_ADD_CHAR_RP_SIZE; |
sjallouli | 0:a948f5f3904c | 295 | |
sjallouli | 0:a948f5f3904c | 296 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 297 | return -1; |
sjallouli | 0:a948f5f3904c | 298 | |
sjallouli | 0:a948f5f3904c | 299 | if (resp.status) { |
sjallouli | 0:a948f5f3904c | 300 | return resp.status; |
sjallouli | 0:a948f5f3904c | 301 | } |
sjallouli | 0:a948f5f3904c | 302 | |
sjallouli | 0:a948f5f3904c | 303 | *charHandle = resp.handle; |
sjallouli | 0:a948f5f3904c | 304 | |
sjallouli | 0:a948f5f3904c | 305 | return 0; |
sjallouli | 0:a948f5f3904c | 306 | } |
sjallouli | 0:a948f5f3904c | 307 | |
sjallouli | 0:a948f5f3904c | 308 | tBleStatus aci_gatt_add_char_desc(tHalUint16 serviceHandle, |
sjallouli | 0:a948f5f3904c | 309 | tHalUint16 charHandle, |
sjallouli | 0:a948f5f3904c | 310 | tUuidType descUuidType, |
sjallouli | 0:a948f5f3904c | 311 | const tHalUint8* uuid, |
sjallouli | 0:a948f5f3904c | 312 | tHalUint8 descValueMaxLen, |
sjallouli | 0:a948f5f3904c | 313 | tHalUint8 descValueLen, |
sjallouli | 0:a948f5f3904c | 314 | const void* descValue, |
sjallouli | 0:a948f5f3904c | 315 | tAttrSecurityFlags secPermissions, |
sjallouli | 0:a948f5f3904c | 316 | tAttrSecurityFlags accPermissions, |
sjallouli | 0:a948f5f3904c | 317 | tGattServerEvent gattEvtMask, |
sjallouli | 0:a948f5f3904c | 318 | tHalUint8 encryKeySize, |
sjallouli | 0:a948f5f3904c | 319 | tHalUint8 isVariable, |
sjallouli | 0:a948f5f3904c | 320 | tHalUint16* descHandle) |
sjallouli | 0:a948f5f3904c | 321 | |
sjallouli | 0:a948f5f3904c | 322 | |
sjallouli | 0:a948f5f3904c | 323 | { |
sjallouli | 0:a948f5f3904c | 324 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 325 | gatt_add_char_desc_rp resp; |
sjallouli | 0:a948f5f3904c | 326 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 327 | uint8_t uuid_len; |
sjallouli | 0:a948f5f3904c | 328 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 329 | |
sjallouli | 0:a948f5f3904c | 330 | Osal_MemCpy(buffer + indx, &serviceHandle, 2); |
sjallouli | 0:a948f5f3904c | 331 | indx += 2; |
sjallouli | 0:a948f5f3904c | 332 | |
sjallouli | 0:a948f5f3904c | 333 | Osal_MemCpy(buffer + indx, &charHandle, 2); |
sjallouli | 0:a948f5f3904c | 334 | indx += 2; |
sjallouli | 0:a948f5f3904c | 335 | |
sjallouli | 0:a948f5f3904c | 336 | buffer[indx] = descUuidType; |
sjallouli | 0:a948f5f3904c | 337 | indx++; |
sjallouli | 0:a948f5f3904c | 338 | |
sjallouli | 0:a948f5f3904c | 339 | if(descUuidType == 0x01){ |
sjallouli | 0:a948f5f3904c | 340 | uuid_len = 2; |
sjallouli | 0:a948f5f3904c | 341 | } |
sjallouli | 0:a948f5f3904c | 342 | else { |
sjallouli | 0:a948f5f3904c | 343 | uuid_len = 16; |
sjallouli | 0:a948f5f3904c | 344 | } |
sjallouli | 0:a948f5f3904c | 345 | Osal_MemCpy(buffer + indx, uuid, uuid_len); |
sjallouli | 0:a948f5f3904c | 346 | indx += uuid_len; |
sjallouli | 0:a948f5f3904c | 347 | |
sjallouli | 0:a948f5f3904c | 348 | buffer[indx] = descValueMaxLen; |
sjallouli | 0:a948f5f3904c | 349 | indx++; |
sjallouli | 0:a948f5f3904c | 350 | |
sjallouli | 0:a948f5f3904c | 351 | buffer[indx] = descValueLen; |
sjallouli | 0:a948f5f3904c | 352 | indx++; |
sjallouli | 0:a948f5f3904c | 353 | |
sjallouli | 0:a948f5f3904c | 354 | Osal_MemCpy(buffer + indx, descValue, descValueLen); |
sjallouli | 0:a948f5f3904c | 355 | indx += descValueLen; |
sjallouli | 0:a948f5f3904c | 356 | |
sjallouli | 0:a948f5f3904c | 357 | buffer[indx] = secPermissions; |
sjallouli | 0:a948f5f3904c | 358 | indx++; |
sjallouli | 0:a948f5f3904c | 359 | |
sjallouli | 0:a948f5f3904c | 360 | buffer[indx] = accPermissions; |
sjallouli | 0:a948f5f3904c | 361 | indx++; |
sjallouli | 0:a948f5f3904c | 362 | |
sjallouli | 0:a948f5f3904c | 363 | buffer[indx] = gattEvtMask; |
sjallouli | 0:a948f5f3904c | 364 | indx++; |
sjallouli | 0:a948f5f3904c | 365 | |
sjallouli | 0:a948f5f3904c | 366 | buffer[indx] = encryKeySize; |
sjallouli | 0:a948f5f3904c | 367 | indx++; |
sjallouli | 0:a948f5f3904c | 368 | |
sjallouli | 0:a948f5f3904c | 369 | buffer[indx] = isVariable; |
sjallouli | 0:a948f5f3904c | 370 | indx++; |
sjallouli | 0:a948f5f3904c | 371 | |
sjallouli | 0:a948f5f3904c | 372 | Osal_MemSet(&resp, 0, sizeof(resp)); |
sjallouli | 0:a948f5f3904c | 373 | |
sjallouli | 0:a948f5f3904c | 374 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 375 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 376 | rq.ocf = OCF_GATT_ADD_CHAR_DESC; |
sjallouli | 0:a948f5f3904c | 377 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 378 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 379 | rq.rparam = &resp; |
sjallouli | 0:a948f5f3904c | 380 | rq.rlen = GATT_ADD_CHAR_DESC_RP_SIZE; |
sjallouli | 0:a948f5f3904c | 381 | |
sjallouli | 0:a948f5f3904c | 382 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 383 | return -1; |
sjallouli | 0:a948f5f3904c | 384 | |
sjallouli | 0:a948f5f3904c | 385 | if (resp.status) { |
sjallouli | 0:a948f5f3904c | 386 | return resp.status; |
sjallouli | 0:a948f5f3904c | 387 | } |
sjallouli | 0:a948f5f3904c | 388 | |
sjallouli | 0:a948f5f3904c | 389 | *descHandle = resp.handle; |
sjallouli | 0:a948f5f3904c | 390 | |
sjallouli | 0:a948f5f3904c | 391 | return 0; |
sjallouli | 0:a948f5f3904c | 392 | } |
sjallouli | 0:a948f5f3904c | 393 | |
sjallouli | 0:a948f5f3904c | 394 | |
sjallouli | 0:a948f5f3904c | 395 | tBleStatus aci_gatt_update_char_value(tHalUint16 servHandle, |
sjallouli | 0:a948f5f3904c | 396 | tHalUint16 charHandle, |
sjallouli | 0:a948f5f3904c | 397 | tHalUint8 charValOffset, |
sjallouli | 0:a948f5f3904c | 398 | tHalUint8 charValueLen, |
sjallouli | 0:a948f5f3904c | 399 | const tHalUint8 *charValue) |
sjallouli | 0:a948f5f3904c | 400 | { |
sjallouli | 0:a948f5f3904c | 401 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 402 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 403 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 404 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 405 | |
sjallouli | 0:a948f5f3904c | 406 | Osal_MemCpy(buffer + indx, &servHandle, 2); |
sjallouli | 0:a948f5f3904c | 407 | indx += 2; |
sjallouli | 0:a948f5f3904c | 408 | |
sjallouli | 0:a948f5f3904c | 409 | Osal_MemCpy(buffer + indx, &charHandle, 2); |
sjallouli | 0:a948f5f3904c | 410 | indx += 2; |
sjallouli | 0:a948f5f3904c | 411 | |
sjallouli | 0:a948f5f3904c | 412 | buffer[indx] = charValOffset; |
sjallouli | 0:a948f5f3904c | 413 | indx++; |
sjallouli | 0:a948f5f3904c | 414 | |
sjallouli | 0:a948f5f3904c | 415 | buffer[indx] = charValueLen; |
sjallouli | 0:a948f5f3904c | 416 | indx++; |
sjallouli | 0:a948f5f3904c | 417 | |
sjallouli | 0:a948f5f3904c | 418 | Osal_MemCpy(buffer + indx, charValue, charValueLen); |
sjallouli | 0:a948f5f3904c | 419 | indx += charValueLen; |
sjallouli | 0:a948f5f3904c | 420 | |
sjallouli | 0:a948f5f3904c | 421 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 422 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 423 | rq.ocf = OCF_GATT_UPD_CHAR_VAL; |
sjallouli | 0:a948f5f3904c | 424 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 425 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 426 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 427 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 428 | |
sjallouli | 0:a948f5f3904c | 429 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 430 | return -1; |
sjallouli | 0:a948f5f3904c | 431 | |
sjallouli | 0:a948f5f3904c | 432 | if (status) { |
sjallouli | 0:a948f5f3904c | 433 | return status; |
sjallouli | 0:a948f5f3904c | 434 | } |
sjallouli | 0:a948f5f3904c | 435 | |
sjallouli | 0:a948f5f3904c | 436 | return 0; |
sjallouli | 0:a948f5f3904c | 437 | } |
sjallouli | 0:a948f5f3904c | 438 | |
sjallouli | 0:a948f5f3904c | 439 | tBleStatus aci_gatt_allow_read(tHalUint16 conn_handle) |
sjallouli | 0:a948f5f3904c | 440 | { |
sjallouli | 0:a948f5f3904c | 441 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 442 | gatt_allow_read_cp cp; |
sjallouli | 0:a948f5f3904c | 443 | tHalUint8 status; |
sjallouli | 0:a948f5f3904c | 444 | |
sjallouli | 0:a948f5f3904c | 445 | cp.conn_handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 446 | |
sjallouli | 0:a948f5f3904c | 447 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 448 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 449 | rq.ocf = OCF_GATT_ALLOW_READ; |
sjallouli | 0:a948f5f3904c | 450 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 451 | rq.clen = GATT_ALLOW_READ_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 452 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 453 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 454 | |
sjallouli | 0:a948f5f3904c | 455 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 456 | return -1; |
sjallouli | 0:a948f5f3904c | 457 | |
sjallouli | 0:a948f5f3904c | 458 | if (status) { |
sjallouli | 0:a948f5f3904c | 459 | return status; |
sjallouli | 0:a948f5f3904c | 460 | } |
sjallouli | 0:a948f5f3904c | 461 | |
sjallouli | 0:a948f5f3904c | 462 | return 0; |
sjallouli | 0:a948f5f3904c | 463 | } |
sjallouli | 0:a948f5f3904c | 464 | |
sjallouli | 0:a948f5f3904c | 465 | tBleStatus aci_gatt_set_desc_value(tHalUint16 servHandle, |
sjallouli | 0:a948f5f3904c | 466 | tHalUint16 charHandle, |
sjallouli | 0:a948f5f3904c | 467 | tHalUint16 charDescHandle, |
sjallouli | 0:a948f5f3904c | 468 | tHalUint16 charDescValOffset, |
sjallouli | 0:a948f5f3904c | 469 | tHalUint8 charDescValueLen, |
sjallouli | 0:a948f5f3904c | 470 | const tHalUint8 *charDescValue) |
sjallouli | 0:a948f5f3904c | 471 | { |
sjallouli | 0:a948f5f3904c | 472 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 473 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 474 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 475 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 476 | |
sjallouli | 0:a948f5f3904c | 477 | Osal_MemCpy(buffer + indx, &servHandle, 2); |
sjallouli | 0:a948f5f3904c | 478 | indx += 2; |
sjallouli | 0:a948f5f3904c | 479 | |
sjallouli | 0:a948f5f3904c | 480 | Osal_MemCpy(buffer + indx, &charHandle, 2); |
sjallouli | 0:a948f5f3904c | 481 | indx += 2; |
sjallouli | 0:a948f5f3904c | 482 | |
sjallouli | 0:a948f5f3904c | 483 | Osal_MemCpy(buffer + indx, &charDescHandle, 2); |
sjallouli | 0:a948f5f3904c | 484 | indx += 2; |
sjallouli | 0:a948f5f3904c | 485 | |
sjallouli | 0:a948f5f3904c | 486 | Osal_MemCpy(buffer + indx, &charDescValOffset, 2); |
sjallouli | 0:a948f5f3904c | 487 | indx += 2; |
sjallouli | 0:a948f5f3904c | 488 | |
sjallouli | 0:a948f5f3904c | 489 | buffer[indx] = charDescValueLen; |
sjallouli | 0:a948f5f3904c | 490 | indx++; |
sjallouli | 0:a948f5f3904c | 491 | |
sjallouli | 0:a948f5f3904c | 492 | Osal_MemCpy(buffer + indx, charDescValue, charDescValueLen); |
sjallouli | 0:a948f5f3904c | 493 | indx += charDescValueLen; |
sjallouli | 0:a948f5f3904c | 494 | |
sjallouli | 0:a948f5f3904c | 495 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 496 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 497 | rq.ocf = OCF_GATT_SET_DESC_VAL; |
sjallouli | 0:a948f5f3904c | 498 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 499 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 500 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 501 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 502 | |
sjallouli | 0:a948f5f3904c | 503 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 504 | return -1; |
sjallouli | 0:a948f5f3904c | 505 | |
sjallouli | 0:a948f5f3904c | 506 | if (status) { |
sjallouli | 0:a948f5f3904c | 507 | return status; |
sjallouli | 0:a948f5f3904c | 508 | } |
sjallouli | 0:a948f5f3904c | 509 | |
sjallouli | 0:a948f5f3904c | 510 | return 0; |
sjallouli | 0:a948f5f3904c | 511 | } |
sjallouli | 0:a948f5f3904c | 512 | |
sjallouli | 0:a948f5f3904c | 513 | tBleStatus aci_gatt_disc_all_prim_services(uint16_t conn_handle) |
sjallouli | 0:a948f5f3904c | 514 | { |
sjallouli | 0:a948f5f3904c | 515 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 516 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 517 | gatt_disc_all_prim_services_cp cp; |
sjallouli | 0:a948f5f3904c | 518 | |
sjallouli | 0:a948f5f3904c | 519 | cp.conn_handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 520 | |
sjallouli | 0:a948f5f3904c | 521 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 522 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 523 | rq.ocf = OCF_GATT_DISC_ALL_PRIM_SERVICES; |
sjallouli | 0:a948f5f3904c | 524 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 525 | rq.clen = GATT_DISC_ALL_PRIM_SERVICES_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 526 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 527 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 528 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 529 | |
sjallouli | 0:a948f5f3904c | 530 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 531 | return -1; |
sjallouli | 0:a948f5f3904c | 532 | |
sjallouli | 0:a948f5f3904c | 533 | return status; |
sjallouli | 0:a948f5f3904c | 534 | } |
sjallouli | 0:a948f5f3904c | 535 | |
sjallouli | 0:a948f5f3904c | 536 | tBleStatus aci_gatt_find_included_services(uint16_t conn_handle, uint16_t start_service_handle, |
sjallouli | 0:a948f5f3904c | 537 | uint16_t end_service_handle) |
sjallouli | 0:a948f5f3904c | 538 | { |
sjallouli | 0:a948f5f3904c | 539 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 540 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 541 | gatt_find_included_services_cp cp; |
sjallouli | 0:a948f5f3904c | 542 | |
sjallouli | 0:a948f5f3904c | 543 | cp.conn_handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 544 | cp.start_handle = start_service_handle; |
sjallouli | 0:a948f5f3904c | 545 | cp.end_handle = end_service_handle; |
sjallouli | 0:a948f5f3904c | 546 | |
sjallouli | 0:a948f5f3904c | 547 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 548 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 549 | rq.ocf = OCF_GATT_FIND_INCLUDED_SERVICES; |
sjallouli | 0:a948f5f3904c | 550 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 551 | rq.clen = GATT_FIND_INCLUDED_SERVICES_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 552 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 553 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 554 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 555 | |
sjallouli | 0:a948f5f3904c | 556 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 557 | return -1; |
sjallouli | 0:a948f5f3904c | 558 | |
sjallouli | 0:a948f5f3904c | 559 | return status; |
sjallouli | 0:a948f5f3904c | 560 | } |
sjallouli | 0:a948f5f3904c | 561 | |
sjallouli | 0:a948f5f3904c | 562 | tBleStatus aci_gatt_disc_all_charac_of_serv(uint16_t conn_handle, uint16_t start_attr_handle, |
sjallouli | 0:a948f5f3904c | 563 | uint16_t end_attr_handle) |
sjallouli | 0:a948f5f3904c | 564 | { |
sjallouli | 0:a948f5f3904c | 565 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 566 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 567 | gatt_disc_all_charac_of_serv_cp cp; |
sjallouli | 0:a948f5f3904c | 568 | |
sjallouli | 0:a948f5f3904c | 569 | cp.conn_handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 570 | cp.start_attr_handle = start_attr_handle; |
sjallouli | 0:a948f5f3904c | 571 | cp.end_attr_handle = end_attr_handle; |
sjallouli | 0:a948f5f3904c | 572 | |
sjallouli | 0:a948f5f3904c | 573 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 574 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 575 | rq.ocf = OCF_GATT_DISC_ALL_CHARAC_OF_SERV; |
sjallouli | 0:a948f5f3904c | 576 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 577 | rq.clen = GATT_DISC_ALL_CHARAC_OF_SERV_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 578 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 579 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 580 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 581 | |
sjallouli | 0:a948f5f3904c | 582 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 583 | return -1; |
sjallouli | 0:a948f5f3904c | 584 | |
sjallouli | 0:a948f5f3904c | 585 | return status; |
sjallouli | 0:a948f5f3904c | 586 | } |
sjallouli | 0:a948f5f3904c | 587 | |
sjallouli | 0:a948f5f3904c | 588 | tBleStatus aci_gatt_disc_all_charac_descriptors(uint16_t conn_handle, uint16_t char_val_handle, |
sjallouli | 0:a948f5f3904c | 589 | uint16_t char_end_handle) |
sjallouli | 0:a948f5f3904c | 590 | { |
sjallouli | 0:a948f5f3904c | 591 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 592 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 593 | gatt_disc_all_charac_descriptors_cp cp; |
sjallouli | 0:a948f5f3904c | 594 | |
sjallouli | 0:a948f5f3904c | 595 | cp.conn_handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 596 | cp.char_val_handle = char_val_handle; |
sjallouli | 0:a948f5f3904c | 597 | cp.char_end_handle = char_end_handle; |
sjallouli | 0:a948f5f3904c | 598 | |
sjallouli | 0:a948f5f3904c | 599 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 600 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 601 | rq.ocf = OCF_GATT_DISC_ALL_CHARAC_DESCRIPTORS; |
sjallouli | 0:a948f5f3904c | 602 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 603 | rq.clen = GATT_DISC_ALL_CHARAC_DESCRIPTORS_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 604 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 605 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 606 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 607 | |
sjallouli | 0:a948f5f3904c | 608 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 609 | return -1; |
sjallouli | 0:a948f5f3904c | 610 | |
sjallouli | 0:a948f5f3904c | 611 | return status; |
sjallouli | 0:a948f5f3904c | 612 | } |
sjallouli | 0:a948f5f3904c | 613 | |
sjallouli | 0:a948f5f3904c | 614 | tBleStatus aci_gatt_write_without_response(uint16_t conn_handle, uint16_t attr_handle, |
sjallouli | 0:a948f5f3904c | 615 | uint8_t value_len, uint8_t *attr_value) |
sjallouli | 0:a948f5f3904c | 616 | { |
sjallouli | 0:a948f5f3904c | 617 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 618 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 619 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 620 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 621 | |
sjallouli | 0:a948f5f3904c | 622 | Osal_MemCpy(buffer + indx, &conn_handle, 2); |
sjallouli | 0:a948f5f3904c | 623 | indx += 2; |
sjallouli | 0:a948f5f3904c | 624 | |
sjallouli | 0:a948f5f3904c | 625 | Osal_MemCpy(buffer + indx, &attr_handle, 2); |
sjallouli | 0:a948f5f3904c | 626 | indx += 2; |
sjallouli | 0:a948f5f3904c | 627 | |
sjallouli | 0:a948f5f3904c | 628 | buffer[indx] = value_len; |
sjallouli | 0:a948f5f3904c | 629 | indx++; |
sjallouli | 0:a948f5f3904c | 630 | |
sjallouli | 0:a948f5f3904c | 631 | Osal_MemCpy(buffer + indx, attr_value, value_len); |
sjallouli | 0:a948f5f3904c | 632 | indx += value_len; |
sjallouli | 0:a948f5f3904c | 633 | |
sjallouli | 0:a948f5f3904c | 634 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 635 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 636 | rq.ocf = OCF_GATT_WRITE_WITHOUT_RESPONSE; |
sjallouli | 0:a948f5f3904c | 637 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 638 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 639 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 640 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 641 | |
sjallouli | 0:a948f5f3904c | 642 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 643 | return -1; |
sjallouli | 0:a948f5f3904c | 644 | |
sjallouli | 0:a948f5f3904c | 645 | return status; |
sjallouli | 0:a948f5f3904c | 646 | |
sjallouli | 0:a948f5f3904c | 647 | } |
sjallouli | 0:a948f5f3904c | 648 | |
sjallouli | 0:a948f5f3904c | 649 | tBleStatus aci_gatt_write_response(uint16_t conn_handle, |
sjallouli | 0:a948f5f3904c | 650 | uint16_t attr_handle, |
sjallouli | 0:a948f5f3904c | 651 | uint8_t write_status, |
sjallouli | 0:a948f5f3904c | 652 | uint8_t err_code, |
sjallouli | 0:a948f5f3904c | 653 | uint8_t att_val_len, |
sjallouli | 0:a948f5f3904c | 654 | uint8_t *att_val) |
sjallouli | 0:a948f5f3904c | 655 | { |
sjallouli | 0:a948f5f3904c | 656 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 657 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 658 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 659 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 660 | |
sjallouli | 0:a948f5f3904c | 661 | Osal_MemCpy(buffer + indx, &conn_handle, 2); |
sjallouli | 0:a948f5f3904c | 662 | indx += 2; |
sjallouli | 0:a948f5f3904c | 663 | |
sjallouli | 0:a948f5f3904c | 664 | Osal_MemCpy(buffer + indx, &attr_handle, 2); |
sjallouli | 0:a948f5f3904c | 665 | indx += 2; |
sjallouli | 0:a948f5f3904c | 666 | |
sjallouli | 0:a948f5f3904c | 667 | buffer[indx] = write_status; |
sjallouli | 0:a948f5f3904c | 668 | indx += 1; |
sjallouli | 0:a948f5f3904c | 669 | |
sjallouli | 0:a948f5f3904c | 670 | buffer[indx] = err_code; |
sjallouli | 0:a948f5f3904c | 671 | indx += 1; |
sjallouli | 0:a948f5f3904c | 672 | |
sjallouli | 0:a948f5f3904c | 673 | buffer[indx] = att_val_len; |
sjallouli | 0:a948f5f3904c | 674 | indx += 1; |
sjallouli | 0:a948f5f3904c | 675 | |
sjallouli | 0:a948f5f3904c | 676 | Osal_MemCpy(buffer + indx, &att_val, att_val_len); |
sjallouli | 0:a948f5f3904c | 677 | indx += att_val_len; |
sjallouli | 0:a948f5f3904c | 678 | |
sjallouli | 0:a948f5f3904c | 679 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 680 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 681 | rq.ocf = OCF_GATT_WRITE_RESPONSE; |
sjallouli | 0:a948f5f3904c | 682 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 683 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 684 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 685 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 686 | |
sjallouli | 0:a948f5f3904c | 687 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 688 | return -1; |
sjallouli | 0:a948f5f3904c | 689 | |
sjallouli | 0:a948f5f3904c | 690 | if (status) { |
sjallouli | 0:a948f5f3904c | 691 | return status; |
sjallouli | 0:a948f5f3904c | 692 | } |
sjallouli | 0:a948f5f3904c | 693 | |
sjallouli | 0:a948f5f3904c | 694 | return 0; |
sjallouli | 0:a948f5f3904c | 695 | } |
sjallouli | 0:a948f5f3904c | 696 | |
sjallouli | 0:a948f5f3904c | 697 | tBleStatus aci_gatt_read_charac_val(uint16_t conn_handle, uint16_t attr_handle) |
sjallouli | 0:a948f5f3904c | 698 | { |
sjallouli | 0:a948f5f3904c | 699 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 700 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 701 | gatt_read_charac_val_cp cp; |
sjallouli | 0:a948f5f3904c | 702 | |
sjallouli | 0:a948f5f3904c | 703 | cp.conn_handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 704 | cp.attr_handle = attr_handle; |
sjallouli | 0:a948f5f3904c | 705 | |
sjallouli | 0:a948f5f3904c | 706 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 707 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 708 | rq.ocf = OCF_GATT_READ_CHARAC_VAL; |
sjallouli | 0:a948f5f3904c | 709 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 710 | rq.clen = GATT_READ_CHARAC_VAL_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 711 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 712 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 713 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 714 | |
sjallouli | 0:a948f5f3904c | 715 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 716 | return -1; |
sjallouli | 0:a948f5f3904c | 717 | |
sjallouli | 0:a948f5f3904c | 718 | return status; |
sjallouli | 0:a948f5f3904c | 719 | } |
sjallouli | 0:a948f5f3904c | 720 | |
sjallouli | 0:a948f5f3904c | 721 | tBleStatus aci_gatt_read_long_charac_val(uint16_t conn_handle, uint16_t attr_handle, |
sjallouli | 0:a948f5f3904c | 722 | uint16_t val_offset) |
sjallouli | 0:a948f5f3904c | 723 | { |
sjallouli | 0:a948f5f3904c | 724 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 725 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 726 | gatt_read_long_charac_val_cp cp; |
sjallouli | 0:a948f5f3904c | 727 | |
sjallouli | 0:a948f5f3904c | 728 | cp.conn_handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 729 | cp.attr_handle = attr_handle; |
sjallouli | 0:a948f5f3904c | 730 | cp.val_offset = val_offset; |
sjallouli | 0:a948f5f3904c | 731 | |
sjallouli | 0:a948f5f3904c | 732 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 733 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 734 | rq.ocf = OCF_GATT_READ_LONG_CHARAC_VAL; |
sjallouli | 0:a948f5f3904c | 735 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 736 | rq.clen = GATT_READ_LONG_CHARAC_VAL_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 737 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 738 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 739 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 740 | |
sjallouli | 0:a948f5f3904c | 741 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 742 | return -1; |
sjallouli | 0:a948f5f3904c | 743 | |
sjallouli | 0:a948f5f3904c | 744 | return status; |
sjallouli | 0:a948f5f3904c | 745 | } |
sjallouli | 0:a948f5f3904c | 746 | |
sjallouli | 0:a948f5f3904c | 747 | tBleStatus aci_gatt_write_charac_value(uint16_t conn_handle, uint16_t attr_handle, |
sjallouli | 0:a948f5f3904c | 748 | uint8_t value_len, uint8_t *attr_value) |
sjallouli | 0:a948f5f3904c | 749 | { |
sjallouli | 0:a948f5f3904c | 750 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 751 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 752 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 753 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 754 | |
sjallouli | 0:a948f5f3904c | 755 | Osal_MemCpy(buffer + indx, &conn_handle, 2); |
sjallouli | 0:a948f5f3904c | 756 | indx += 2; |
sjallouli | 0:a948f5f3904c | 757 | |
sjallouli | 0:a948f5f3904c | 758 | Osal_MemCpy(buffer + indx, &attr_handle, 2); |
sjallouli | 0:a948f5f3904c | 759 | indx += 2; |
sjallouli | 0:a948f5f3904c | 760 | |
sjallouli | 0:a948f5f3904c | 761 | buffer[indx] = value_len; |
sjallouli | 0:a948f5f3904c | 762 | indx++; |
sjallouli | 0:a948f5f3904c | 763 | |
sjallouli | 0:a948f5f3904c | 764 | Osal_MemCpy(buffer + indx, attr_value, value_len); |
sjallouli | 0:a948f5f3904c | 765 | indx += value_len; |
sjallouli | 0:a948f5f3904c | 766 | |
sjallouli | 0:a948f5f3904c | 767 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 768 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 769 | rq.ocf = OCF_GATT_WRITE_CHAR_VALUE; |
sjallouli | 0:a948f5f3904c | 770 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 771 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 772 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 773 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 774 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 775 | |
sjallouli | 0:a948f5f3904c | 776 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 777 | return -1; |
sjallouli | 0:a948f5f3904c | 778 | |
sjallouli | 0:a948f5f3904c | 779 | return status; |
sjallouli | 0:a948f5f3904c | 780 | } |
sjallouli | 0:a948f5f3904c | 781 | |
sjallouli | 0:a948f5f3904c | 782 | tBleStatus aci_gatt_write_charac_descriptor(uint16_t conn_handle, uint16_t attr_handle, |
sjallouli | 0:a948f5f3904c | 783 | uint8_t value_len, uint8_t *attr_value) |
sjallouli | 0:a948f5f3904c | 784 | { |
sjallouli | 0:a948f5f3904c | 785 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 786 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 787 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 788 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 789 | |
sjallouli | 0:a948f5f3904c | 790 | Osal_MemCpy(buffer + indx, &conn_handle, 2); |
sjallouli | 0:a948f5f3904c | 791 | indx += 2; |
sjallouli | 0:a948f5f3904c | 792 | |
sjallouli | 0:a948f5f3904c | 793 | Osal_MemCpy(buffer + indx, &attr_handle, 2); |
sjallouli | 0:a948f5f3904c | 794 | indx += 2; |
sjallouli | 0:a948f5f3904c | 795 | |
sjallouli | 0:a948f5f3904c | 796 | buffer[indx] = value_len; |
sjallouli | 0:a948f5f3904c | 797 | indx++; |
sjallouli | 0:a948f5f3904c | 798 | |
sjallouli | 0:a948f5f3904c | 799 | Osal_MemCpy(buffer + indx, attr_value, value_len); |
sjallouli | 0:a948f5f3904c | 800 | indx += value_len; |
sjallouli | 0:a948f5f3904c | 801 | |
sjallouli | 0:a948f5f3904c | 802 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 803 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 804 | rq.ocf = OCF_GATT_WRITE_CHAR_DESCRIPTOR; |
sjallouli | 0:a948f5f3904c | 805 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 806 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 807 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 808 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 809 | |
sjallouli | 0:a948f5f3904c | 810 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 811 | return -1; |
sjallouli | 0:a948f5f3904c | 812 | |
sjallouli | 0:a948f5f3904c | 813 | return status; |
sjallouli | 0:a948f5f3904c | 814 | } |
sjallouli | 0:a948f5f3904c | 815 | |
sjallouli | 0:a948f5f3904c | 816 | tBleStatus aci_hal_write_config_data(tHalUint8 offset, |
sjallouli | 0:a948f5f3904c | 817 | tHalUint8 len, |
sjallouli | 0:a948f5f3904c | 818 | const tHalUint8 *val) |
sjallouli | 0:a948f5f3904c | 819 | { |
sjallouli | 0:a948f5f3904c | 820 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 821 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 822 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 823 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 824 | |
sjallouli | 0:a948f5f3904c | 825 | buffer[indx] = offset; |
sjallouli | 0:a948f5f3904c | 826 | indx++; |
sjallouli | 0:a948f5f3904c | 827 | |
sjallouli | 0:a948f5f3904c | 828 | buffer[indx] = len; |
sjallouli | 0:a948f5f3904c | 829 | indx++; |
sjallouli | 0:a948f5f3904c | 830 | |
sjallouli | 0:a948f5f3904c | 831 | Osal_MemCpy(buffer + indx, val, len); |
sjallouli | 0:a948f5f3904c | 832 | indx += len; |
sjallouli | 0:a948f5f3904c | 833 | |
sjallouli | 0:a948f5f3904c | 834 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 835 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 836 | rq.ocf = OCF_HAL_WRITE_CONFIG_DATA; |
sjallouli | 0:a948f5f3904c | 837 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 838 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 839 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 840 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 841 | |
sjallouli | 0:a948f5f3904c | 842 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 843 | return -1; |
sjallouli | 0:a948f5f3904c | 844 | |
sjallouli | 0:a948f5f3904c | 845 | if (status) { |
sjallouli | 0:a948f5f3904c | 846 | return status; |
sjallouli | 0:a948f5f3904c | 847 | } |
sjallouli | 0:a948f5f3904c | 848 | |
sjallouli | 0:a948f5f3904c | 849 | return 0; |
sjallouli | 0:a948f5f3904c | 850 | } |
sjallouli | 0:a948f5f3904c | 851 | |
sjallouli | 0:a948f5f3904c | 852 | tBleStatus aci_hal_set_tx_power_level(uint8_t en_high_power, uint8_t pa_level) |
sjallouli | 0:a948f5f3904c | 853 | { |
sjallouli | 0:a948f5f3904c | 854 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 855 | hal_set_tx_power_level_cp cp; |
sjallouli | 0:a948f5f3904c | 856 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 857 | |
sjallouli | 0:a948f5f3904c | 858 | cp.en_high_power = en_high_power; |
sjallouli | 0:a948f5f3904c | 859 | cp.pa_level = pa_level; |
sjallouli | 0:a948f5f3904c | 860 | |
sjallouli | 0:a948f5f3904c | 861 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 862 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 863 | rq.ocf = OCF_HAL_SET_TX_POWER_LEVEL; |
sjallouli | 0:a948f5f3904c | 864 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 865 | rq.clen = HAL_SET_TX_POWER_LEVEL_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 866 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 867 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 868 | |
sjallouli | 0:a948f5f3904c | 869 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 870 | return -1; |
sjallouli | 0:a948f5f3904c | 871 | |
sjallouli | 0:a948f5f3904c | 872 | if (status) { |
sjallouli | 0:a948f5f3904c | 873 | return status; |
sjallouli | 0:a948f5f3904c | 874 | } |
sjallouli | 0:a948f5f3904c | 875 | |
sjallouli | 0:a948f5f3904c | 876 | return 0; |
sjallouli | 0:a948f5f3904c | 877 | } |
sjallouli | 0:a948f5f3904c | 878 | |
sjallouli | 0:a948f5f3904c | 879 | tBleStatus aci_gap_set_auth_requirement(uint8_t mitm_mode, |
sjallouli | 0:a948f5f3904c | 880 | uint8_t oob_enable, |
sjallouli | 0:a948f5f3904c | 881 | uint8_t oob_data[16], |
sjallouli | 0:a948f5f3904c | 882 | uint8_t min_encryption_key_size, |
sjallouli | 0:a948f5f3904c | 883 | uint8_t max_encryption_key_size, |
sjallouli | 0:a948f5f3904c | 884 | uint8_t use_fixed_pin, |
sjallouli | 0:a948f5f3904c | 885 | uint32_t fixed_pin, |
sjallouli | 0:a948f5f3904c | 886 | uint8_t bonding_mode) |
sjallouli | 0:a948f5f3904c | 887 | { |
sjallouli | 0:a948f5f3904c | 888 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 889 | gap_set_auth_requirement_cp cp; |
sjallouli | 0:a948f5f3904c | 890 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 891 | |
sjallouli | 0:a948f5f3904c | 892 | cp.mitm_mode = mitm_mode; |
sjallouli | 0:a948f5f3904c | 893 | cp.oob_enable = oob_enable; |
sjallouli | 0:a948f5f3904c | 894 | Osal_MemCpy(cp.oob_data, oob_data, 16); |
sjallouli | 0:a948f5f3904c | 895 | cp.min_encryption_key_size = min_encryption_key_size; |
sjallouli | 0:a948f5f3904c | 896 | cp.max_encryption_key_size = max_encryption_key_size; |
sjallouli | 0:a948f5f3904c | 897 | cp.use_fixed_pin = use_fixed_pin; |
sjallouli | 0:a948f5f3904c | 898 | cp.fixed_pin = fixed_pin; |
sjallouli | 0:a948f5f3904c | 899 | cp.bonding_mode = bonding_mode; |
sjallouli | 0:a948f5f3904c | 900 | |
sjallouli | 0:a948f5f3904c | 901 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 902 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 903 | rq.ocf = OCF_GAP_SET_AUTH_REQUIREMENT; |
sjallouli | 0:a948f5f3904c | 904 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 905 | rq.clen = GAP_SET_AUTH_REQUIREMENT_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 906 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 907 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 908 | |
sjallouli | 0:a948f5f3904c | 909 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 910 | return -1; |
sjallouli | 0:a948f5f3904c | 911 | |
sjallouli | 0:a948f5f3904c | 912 | if (status) { |
sjallouli | 0:a948f5f3904c | 913 | return status; |
sjallouli | 0:a948f5f3904c | 914 | } |
sjallouli | 0:a948f5f3904c | 915 | |
sjallouli | 0:a948f5f3904c | 916 | return 0; |
sjallouli | 0:a948f5f3904c | 917 | |
sjallouli | 0:a948f5f3904c | 918 | } |
sjallouli | 0:a948f5f3904c | 919 | |
sjallouli | 0:a948f5f3904c | 920 | tBleStatus aci_gap_start_limited_discovery_proc(uint16_t scanInterval, uint16_t scanWindow, |
sjallouli | 0:a948f5f3904c | 921 | uint8_t own_address_type, uint8_t filterDuplicates) |
sjallouli | 0:a948f5f3904c | 922 | { |
sjallouli | 0:a948f5f3904c | 923 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 924 | gap_start_limited_discovery_proc_cp cp; |
sjallouli | 0:a948f5f3904c | 925 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 926 | |
sjallouli | 0:a948f5f3904c | 927 | cp.scanInterval = scanInterval; |
sjallouli | 0:a948f5f3904c | 928 | cp.scanWindow = scanWindow; |
sjallouli | 0:a948f5f3904c | 929 | cp.own_address_type = own_address_type; |
sjallouli | 0:a948f5f3904c | 930 | cp.filterDuplicates = filterDuplicates; |
sjallouli | 0:a948f5f3904c | 931 | |
sjallouli | 0:a948f5f3904c | 932 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 933 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 934 | rq.ocf = OCF_GAP_START_LIMITED_DISCOVERY_PROC; |
sjallouli | 0:a948f5f3904c | 935 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 936 | rq.clen = GAP_START_LIMITED_DISCOVERY_PROC_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 937 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 938 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 939 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 940 | |
sjallouli | 0:a948f5f3904c | 941 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 942 | return -1; |
sjallouli | 0:a948f5f3904c | 943 | |
sjallouli | 0:a948f5f3904c | 944 | return status; |
sjallouli | 0:a948f5f3904c | 945 | } |
sjallouli | 0:a948f5f3904c | 946 | |
sjallouli | 0:a948f5f3904c | 947 | tBleStatus aci_gap_start_general_discovery_proc(uint16_t scanInterval, uint16_t scanWindow, |
sjallouli | 0:a948f5f3904c | 948 | uint8_t own_address_type, uint8_t filterDuplicates) |
sjallouli | 0:a948f5f3904c | 949 | { |
sjallouli | 0:a948f5f3904c | 950 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 951 | gap_start_general_discovery_proc_cp cp; |
sjallouli | 0:a948f5f3904c | 952 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 953 | |
sjallouli | 0:a948f5f3904c | 954 | cp.scanInterval = scanInterval; |
sjallouli | 0:a948f5f3904c | 955 | cp.scanWindow = scanWindow; |
sjallouli | 0:a948f5f3904c | 956 | cp.own_address_type = own_address_type; |
sjallouli | 0:a948f5f3904c | 957 | cp.filterDuplicates = filterDuplicates; |
sjallouli | 0:a948f5f3904c | 958 | |
sjallouli | 0:a948f5f3904c | 959 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 960 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 961 | rq.ocf = OCF_GAP_START_GENERAL_DISCOVERY_PROC; |
sjallouli | 0:a948f5f3904c | 962 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 963 | rq.clen = GAP_START_GENERAL_DISCOVERY_PROC_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 964 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 965 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 966 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 967 | |
sjallouli | 0:a948f5f3904c | 968 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 969 | return -1; |
sjallouli | 0:a948f5f3904c | 970 | |
sjallouli | 0:a948f5f3904c | 971 | return status; |
sjallouli | 0:a948f5f3904c | 972 | } |
sjallouli | 0:a948f5f3904c | 973 | |
sjallouli | 0:a948f5f3904c | 974 | |
sjallouli | 0:a948f5f3904c | 975 | tBleStatus aci_gap_start_auto_conn_establishment(uint16_t scanInterval, uint16_t scanWindow, |
sjallouli | 0:a948f5f3904c | 976 | uint8_t own_bdaddr_type, uint16_t conn_min_interval, |
sjallouli | 0:a948f5f3904c | 977 | uint16_t conn_max_interval, uint16_t conn_latency, |
sjallouli | 0:a948f5f3904c | 978 | uint16_t supervision_timeout, uint16_t min_conn_length, |
sjallouli | 0:a948f5f3904c | 979 | uint16_t max_conn_length, uint8_t num_whitelist_entries, |
sjallouli | 0:a948f5f3904c | 980 | uint8_t *addr_array) |
sjallouli | 0:a948f5f3904c | 981 | { |
sjallouli | 0:a948f5f3904c | 982 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 983 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 984 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 985 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 986 | |
sjallouli | 0:a948f5f3904c | 987 | Osal_MemCpy(buffer + indx, &scanInterval, 2); |
sjallouli | 0:a948f5f3904c | 988 | indx += 2; |
sjallouli | 0:a948f5f3904c | 989 | |
sjallouli | 0:a948f5f3904c | 990 | Osal_MemCpy(buffer + indx, &scanWindow, 2); |
sjallouli | 0:a948f5f3904c | 991 | indx += 2; |
sjallouli | 0:a948f5f3904c | 992 | |
sjallouli | 0:a948f5f3904c | 993 | buffer[indx] = own_bdaddr_type; |
sjallouli | 0:a948f5f3904c | 994 | indx++; |
sjallouli | 0:a948f5f3904c | 995 | |
sjallouli | 0:a948f5f3904c | 996 | Osal_MemCpy(buffer + indx, &conn_min_interval, 2); |
sjallouli | 0:a948f5f3904c | 997 | indx += 2; |
sjallouli | 0:a948f5f3904c | 998 | |
sjallouli | 0:a948f5f3904c | 999 | Osal_MemCpy(buffer + indx, &conn_max_interval, 2); |
sjallouli | 0:a948f5f3904c | 1000 | indx += 2; |
sjallouli | 0:a948f5f3904c | 1001 | |
sjallouli | 0:a948f5f3904c | 1002 | Osal_MemCpy(buffer + indx, &conn_latency, 2); |
sjallouli | 0:a948f5f3904c | 1003 | indx += 2; |
sjallouli | 0:a948f5f3904c | 1004 | |
sjallouli | 0:a948f5f3904c | 1005 | Osal_MemCpy(buffer + indx, &supervision_timeout, 2); |
sjallouli | 0:a948f5f3904c | 1006 | indx += 2; |
sjallouli | 0:a948f5f3904c | 1007 | |
sjallouli | 0:a948f5f3904c | 1008 | Osal_MemCpy(buffer + indx, &min_conn_length, 2); |
sjallouli | 0:a948f5f3904c | 1009 | indx += 2; |
sjallouli | 0:a948f5f3904c | 1010 | |
sjallouli | 0:a948f5f3904c | 1011 | Osal_MemCpy(buffer + indx, &max_conn_length, 2); |
sjallouli | 0:a948f5f3904c | 1012 | indx += 2; |
sjallouli | 0:a948f5f3904c | 1013 | |
sjallouli | 0:a948f5f3904c | 1014 | buffer[indx] = num_whitelist_entries; |
sjallouli | 0:a948f5f3904c | 1015 | indx++; |
sjallouli | 0:a948f5f3904c | 1016 | |
sjallouli | 0:a948f5f3904c | 1017 | Osal_MemCpy(buffer + indx, addr_array, (num_whitelist_entries*7)); |
sjallouli | 0:a948f5f3904c | 1018 | indx += num_whitelist_entries * 7; |
sjallouli | 0:a948f5f3904c | 1019 | |
sjallouli | 0:a948f5f3904c | 1020 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1021 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1022 | rq.ocf = OCF_GAP_START_AUTO_CONN_ESTABLISHMENT; |
sjallouli | 0:a948f5f3904c | 1023 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 1024 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 1025 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 1026 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1027 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1028 | |
sjallouli | 0:a948f5f3904c | 1029 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1030 | return -1; |
sjallouli | 0:a948f5f3904c | 1031 | |
sjallouli | 0:a948f5f3904c | 1032 | return status; |
sjallouli | 0:a948f5f3904c | 1033 | } |
sjallouli | 0:a948f5f3904c | 1034 | |
sjallouli | 0:a948f5f3904c | 1035 | tBleStatus aci_gap_create_connection(uint16_t scanInterval, uint16_t scanWindow, |
sjallouli | 0:a948f5f3904c | 1036 | uint8_t peer_bdaddr_type, tBDAddr peer_bdaddr, |
sjallouli | 0:a948f5f3904c | 1037 | uint8_t own_bdaddr_type, uint16_t conn_min_interval, |
sjallouli | 0:a948f5f3904c | 1038 | uint16_t conn_max_interval, uint16_t conn_latency, |
sjallouli | 0:a948f5f3904c | 1039 | uint16_t supervision_timeout, uint16_t min_conn_length, |
sjallouli | 0:a948f5f3904c | 1040 | uint16_t max_conn_length) |
sjallouli | 0:a948f5f3904c | 1041 | { |
sjallouli | 0:a948f5f3904c | 1042 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1043 | gap_create_connection_cp cp; |
sjallouli | 0:a948f5f3904c | 1044 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 1045 | |
sjallouli | 0:a948f5f3904c | 1046 | cp.scanInterval = scanInterval; |
sjallouli | 0:a948f5f3904c | 1047 | cp.scanWindow = scanWindow; |
sjallouli | 0:a948f5f3904c | 1048 | cp.peer_bdaddr_type = peer_bdaddr_type; |
sjallouli | 0:a948f5f3904c | 1049 | Osal_MemCpy(cp.peer_bdaddr, peer_bdaddr, 6); |
sjallouli | 0:a948f5f3904c | 1050 | cp.own_bdaddr_type = own_bdaddr_type; |
sjallouli | 0:a948f5f3904c | 1051 | cp.conn_min_interval = conn_min_interval; |
sjallouli | 0:a948f5f3904c | 1052 | cp.conn_max_interval = conn_max_interval; |
sjallouli | 0:a948f5f3904c | 1053 | cp.conn_latency = conn_latency; |
sjallouli | 0:a948f5f3904c | 1054 | cp.supervision_timeout = supervision_timeout; |
sjallouli | 0:a948f5f3904c | 1055 | cp.min_conn_length = min_conn_length; |
sjallouli | 0:a948f5f3904c | 1056 | cp.max_conn_length = max_conn_length; |
sjallouli | 0:a948f5f3904c | 1057 | |
sjallouli | 0:a948f5f3904c | 1058 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1059 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1060 | rq.ocf = OCF_GAP_CREATE_CONNECTION; |
sjallouli | 0:a948f5f3904c | 1061 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 1062 | rq.clen = GAP_CREATE_CONNECTION_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 1063 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 1064 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1065 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1066 | |
sjallouli | 0:a948f5f3904c | 1067 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1068 | return -1; |
sjallouli | 0:a948f5f3904c | 1069 | |
sjallouli | 0:a948f5f3904c | 1070 | return status; |
sjallouli | 0:a948f5f3904c | 1071 | } |
sjallouli | 0:a948f5f3904c | 1072 | |
sjallouli | 0:a948f5f3904c | 1073 | tBleStatus aci_gap_terminate_gap_procedure(uint8_t procedure_code) |
sjallouli | 0:a948f5f3904c | 1074 | { |
sjallouli | 0:a948f5f3904c | 1075 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1076 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 1077 | |
sjallouli | 0:a948f5f3904c | 1078 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1079 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1080 | rq.ocf = OCF_GAP_TERMINATE_GAP_PROCEDURE; |
sjallouli | 0:a948f5f3904c | 1081 | rq.cparam = &procedure_code; |
sjallouli | 0:a948f5f3904c | 1082 | rq.clen = 1; |
sjallouli | 0:a948f5f3904c | 1083 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1084 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1085 | |
sjallouli | 0:a948f5f3904c | 1086 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1087 | return -1; |
sjallouli | 0:a948f5f3904c | 1088 | |
sjallouli | 0:a948f5f3904c | 1089 | return status; |
sjallouli | 0:a948f5f3904c | 1090 | |
sjallouli | 0:a948f5f3904c | 1091 | } |
sjallouli | 0:a948f5f3904c | 1092 | |
sjallouli | 0:a948f5f3904c | 1093 | tBleStatus aci_gap_terminate(uint16_t conn_handle, uint8_t reason) |
sjallouli | 0:a948f5f3904c | 1094 | { |
sjallouli | 0:a948f5f3904c | 1095 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1096 | gap_terminate_cp cp; |
sjallouli | 0:a948f5f3904c | 1097 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 1098 | |
sjallouli | 0:a948f5f3904c | 1099 | cp.handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 1100 | cp.reason = reason; |
sjallouli | 0:a948f5f3904c | 1101 | |
sjallouli | 0:a948f5f3904c | 1102 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1103 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1104 | rq.ocf = OCF_GAP_TERMINATE; |
sjallouli | 0:a948f5f3904c | 1105 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 1106 | rq.clen = GAP_TERMINATE_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 1107 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 1108 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1109 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1110 | |
sjallouli | 0:a948f5f3904c | 1111 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1112 | return -1; |
sjallouli | 0:a948f5f3904c | 1113 | |
sjallouli | 0:a948f5f3904c | 1114 | return status; |
sjallouli | 0:a948f5f3904c | 1115 | } |
sjallouli | 0:a948f5f3904c | 1116 | |
sjallouli | 0:a948f5f3904c | 1117 | tBleStatus aci_l2cap_connection_parameter_update_request(uint16_t conn_handle, uint16_t interval_min, uint16_t interval_max, |
sjallouli | 0:a948f5f3904c | 1118 | uint16_t slave_latency, uint16_t timeout_mult) |
sjallouli | 0:a948f5f3904c | 1119 | { |
sjallouli | 0:a948f5f3904c | 1120 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1121 | l2cap_conn_param_upd_cp cp; |
sjallouli | 0:a948f5f3904c | 1122 | tHalUint8 status; |
sjallouli | 0:a948f5f3904c | 1123 | |
sjallouli | 0:a948f5f3904c | 1124 | cp.handle = conn_handle; |
sjallouli | 0:a948f5f3904c | 1125 | cp.interval_min = interval_min; |
sjallouli | 0:a948f5f3904c | 1126 | cp.interval_max = interval_max; |
sjallouli | 0:a948f5f3904c | 1127 | cp.slave_latency = slave_latency; |
sjallouli | 0:a948f5f3904c | 1128 | cp.timeout_multiplier = timeout_mult; |
sjallouli | 0:a948f5f3904c | 1129 | |
sjallouli | 0:a948f5f3904c | 1130 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1131 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1132 | rq.ocf = OCF_L2CAP_CONN_PARAM_UPD_REQ; |
sjallouli | 0:a948f5f3904c | 1133 | rq.event = EVT_CMD_STATUS; |
sjallouli | 0:a948f5f3904c | 1134 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 1135 | rq.clen = L2CAP_CONN_PARAM_UPD_REQ_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 1136 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1137 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1138 | |
sjallouli | 0:a948f5f3904c | 1139 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1140 | return -1; |
sjallouli | 0:a948f5f3904c | 1141 | |
sjallouli | 0:a948f5f3904c | 1142 | return status; |
sjallouli | 0:a948f5f3904c | 1143 | } |
sjallouli | 0:a948f5f3904c | 1144 | |
sjallouli | 0:a948f5f3904c | 1145 | |
sjallouli | 0:a948f5f3904c | 1146 | tBleStatus aci_hal_tone_start(uint8_t rf_channel) |
sjallouli | 0:a948f5f3904c | 1147 | { |
sjallouli | 0:a948f5f3904c | 1148 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1149 | hal_tone_start_cp cp; |
sjallouli | 0:a948f5f3904c | 1150 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 1151 | |
sjallouli | 0:a948f5f3904c | 1152 | cp.rf_channel = rf_channel; |
sjallouli | 0:a948f5f3904c | 1153 | |
sjallouli | 0:a948f5f3904c | 1154 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1155 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1156 | rq.ocf = OCF_HAL_TONE_START; |
sjallouli | 0:a948f5f3904c | 1157 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 1158 | rq.clen = HAL_TONE_START_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 1159 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1160 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1161 | |
sjallouli | 0:a948f5f3904c | 1162 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1163 | return -1; |
sjallouli | 0:a948f5f3904c | 1164 | |
sjallouli | 0:a948f5f3904c | 1165 | if (status) { |
sjallouli | 0:a948f5f3904c | 1166 | return status; |
sjallouli | 0:a948f5f3904c | 1167 | } |
sjallouli | 0:a948f5f3904c | 1168 | |
sjallouli | 0:a948f5f3904c | 1169 | return 0; |
sjallouli | 0:a948f5f3904c | 1170 | } |
sjallouli | 0:a948f5f3904c | 1171 | |
sjallouli | 0:a948f5f3904c | 1172 | tBleStatus aci_updater_start(void) |
sjallouli | 0:a948f5f3904c | 1173 | { |
sjallouli | 0:a948f5f3904c | 1174 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1175 | tHalUint8 status; |
sjallouli | 0:a948f5f3904c | 1176 | |
sjallouli | 0:a948f5f3904c | 1177 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1178 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1179 | rq.ocf = OCF_UPDATER_START; |
sjallouli | 0:a948f5f3904c | 1180 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1181 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1182 | |
sjallouli | 0:a948f5f3904c | 1183 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1184 | return -1; |
sjallouli | 0:a948f5f3904c | 1185 | |
sjallouli | 0:a948f5f3904c | 1186 | return status; |
sjallouli | 0:a948f5f3904c | 1187 | } |
sjallouli | 0:a948f5f3904c | 1188 | |
sjallouli | 0:a948f5f3904c | 1189 | tBleStatus aci_updater_reboot() |
sjallouli | 0:a948f5f3904c | 1190 | { |
sjallouli | 0:a948f5f3904c | 1191 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1192 | tHalUint8 status; |
sjallouli | 0:a948f5f3904c | 1193 | |
sjallouli | 0:a948f5f3904c | 1194 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1195 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1196 | rq.ocf = OCF_UPDATER_REBOOT; |
sjallouli | 0:a948f5f3904c | 1197 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1198 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1199 | |
sjallouli | 0:a948f5f3904c | 1200 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1201 | return -1; |
sjallouli | 0:a948f5f3904c | 1202 | |
sjallouli | 0:a948f5f3904c | 1203 | return status; |
sjallouli | 0:a948f5f3904c | 1204 | } |
sjallouli | 0:a948f5f3904c | 1205 | |
sjallouli | 0:a948f5f3904c | 1206 | tBleStatus aci_get_updater_version(uint8_t *version) |
sjallouli | 0:a948f5f3904c | 1207 | { |
sjallouli | 0:a948f5f3904c | 1208 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1209 | get_updater_version_rp resp; |
sjallouli | 0:a948f5f3904c | 1210 | |
sjallouli | 0:a948f5f3904c | 1211 | Osal_MemSet(&resp, 0, sizeof(resp)); |
sjallouli | 0:a948f5f3904c | 1212 | |
sjallouli | 0:a948f5f3904c | 1213 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1214 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1215 | rq.ocf = OCF_GET_UPDATER_VERSION; |
sjallouli | 0:a948f5f3904c | 1216 | rq.rparam = &resp; |
sjallouli | 0:a948f5f3904c | 1217 | rq.rlen = GET_UPDATER_VERSION_RP_SIZE; |
sjallouli | 0:a948f5f3904c | 1218 | |
sjallouli | 0:a948f5f3904c | 1219 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1220 | return -1; |
sjallouli | 0:a948f5f3904c | 1221 | |
sjallouli | 0:a948f5f3904c | 1222 | *version = resp.version; |
sjallouli | 0:a948f5f3904c | 1223 | |
sjallouli | 0:a948f5f3904c | 1224 | return resp.status; |
sjallouli | 0:a948f5f3904c | 1225 | } |
sjallouli | 0:a948f5f3904c | 1226 | |
sjallouli | 0:a948f5f3904c | 1227 | tBleStatus aci_get_updater_buffer_size(uint8_t *buffer_size) |
sjallouli | 0:a948f5f3904c | 1228 | { |
sjallouli | 0:a948f5f3904c | 1229 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1230 | get_updater_bufsize_rp resp; |
sjallouli | 0:a948f5f3904c | 1231 | |
sjallouli | 0:a948f5f3904c | 1232 | Osal_MemSet(&resp, 0, sizeof(resp)); |
sjallouli | 0:a948f5f3904c | 1233 | |
sjallouli | 0:a948f5f3904c | 1234 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1235 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1236 | rq.ocf = OCF_GET_UPDATER_BUFSIZE; |
sjallouli | 0:a948f5f3904c | 1237 | rq.rparam = &resp; |
sjallouli | 0:a948f5f3904c | 1238 | rq.rlen = GET_UPDATER_BUFSIZE_RP_SIZE; |
sjallouli | 0:a948f5f3904c | 1239 | |
sjallouli | 0:a948f5f3904c | 1240 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1241 | return -1; |
sjallouli | 0:a948f5f3904c | 1242 | |
sjallouli | 0:a948f5f3904c | 1243 | *buffer_size = resp.buffer_size; |
sjallouli | 0:a948f5f3904c | 1244 | |
sjallouli | 0:a948f5f3904c | 1245 | return resp.status; |
sjallouli | 0:a948f5f3904c | 1246 | } |
sjallouli | 0:a948f5f3904c | 1247 | |
sjallouli | 0:a948f5f3904c | 1248 | tBleStatus aci_erase_blue_flag() |
sjallouli | 0:a948f5f3904c | 1249 | { |
sjallouli | 0:a948f5f3904c | 1250 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1251 | tHalUint8 status; |
sjallouli | 0:a948f5f3904c | 1252 | |
sjallouli | 0:a948f5f3904c | 1253 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1254 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1255 | rq.ocf = OCF_UPDATER_ERASE_BLUE_FLAG; |
sjallouli | 0:a948f5f3904c | 1256 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1257 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1258 | |
sjallouli | 0:a948f5f3904c | 1259 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1260 | return -1; |
sjallouli | 0:a948f5f3904c | 1261 | |
sjallouli | 0:a948f5f3904c | 1262 | return status; |
sjallouli | 0:a948f5f3904c | 1263 | } |
sjallouli | 0:a948f5f3904c | 1264 | |
sjallouli | 0:a948f5f3904c | 1265 | tBleStatus aci_reset_blue_flag() |
sjallouli | 0:a948f5f3904c | 1266 | { |
sjallouli | 0:a948f5f3904c | 1267 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1268 | tHalUint8 status; |
sjallouli | 0:a948f5f3904c | 1269 | |
sjallouli | 0:a948f5f3904c | 1270 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1271 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1272 | rq.ocf = OCF_UPDATER_RESET_BLUE_FLAG; |
sjallouli | 0:a948f5f3904c | 1273 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1274 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1275 | |
sjallouli | 0:a948f5f3904c | 1276 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1277 | return -1; |
sjallouli | 0:a948f5f3904c | 1278 | |
sjallouli | 0:a948f5f3904c | 1279 | return status; |
sjallouli | 0:a948f5f3904c | 1280 | } |
sjallouli | 0:a948f5f3904c | 1281 | |
sjallouli | 0:a948f5f3904c | 1282 | tBleStatus aci_updater_erase_sector(uint32_t address) |
sjallouli | 0:a948f5f3904c | 1283 | { |
sjallouli | 0:a948f5f3904c | 1284 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1285 | updater_erase_sector_cp cp; |
sjallouli | 0:a948f5f3904c | 1286 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 1287 | |
sjallouli | 0:a948f5f3904c | 1288 | cp.address = address; |
sjallouli | 0:a948f5f3904c | 1289 | |
sjallouli | 0:a948f5f3904c | 1290 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1291 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1292 | rq.ocf = OCF_UPDATER_ERASE_SECTOR; |
sjallouli | 0:a948f5f3904c | 1293 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 1294 | rq.clen = UPDATER_ERASE_SECTOR_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 1295 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1296 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1297 | |
sjallouli | 0:a948f5f3904c | 1298 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1299 | return -1; |
sjallouli | 0:a948f5f3904c | 1300 | |
sjallouli | 0:a948f5f3904c | 1301 | return status; |
sjallouli | 0:a948f5f3904c | 1302 | } |
sjallouli | 0:a948f5f3904c | 1303 | |
sjallouli | 0:a948f5f3904c | 1304 | tBleStatus aci_updater_program_data_block(uint32_t address, |
sjallouli | 0:a948f5f3904c | 1305 | uint16_t len, |
sjallouli | 0:a948f5f3904c | 1306 | const uint8_t *data) |
sjallouli | 0:a948f5f3904c | 1307 | { |
sjallouli | 0:a948f5f3904c | 1308 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1309 | uint8_t status; |
sjallouli | 0:a948f5f3904c | 1310 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 1311 | uint8_t indx = 0; |
sjallouli | 0:a948f5f3904c | 1312 | |
sjallouli | 0:a948f5f3904c | 1313 | if(len > HCI_MAX_PACKET_SIZE) |
sjallouli | 0:a948f5f3904c | 1314 | return -1; |
sjallouli | 0:a948f5f3904c | 1315 | |
sjallouli | 0:a948f5f3904c | 1316 | Osal_MemCpy(buffer + indx, &address, 4); |
sjallouli | 0:a948f5f3904c | 1317 | indx += 4; |
sjallouli | 0:a948f5f3904c | 1318 | |
sjallouli | 0:a948f5f3904c | 1319 | Osal_MemCpy(buffer + indx, &len, 2); |
sjallouli | 0:a948f5f3904c | 1320 | indx += 2; |
sjallouli | 0:a948f5f3904c | 1321 | |
sjallouli | 0:a948f5f3904c | 1322 | Osal_MemCpy(buffer + indx, data, len); |
sjallouli | 0:a948f5f3904c | 1323 | indx += len; |
sjallouli | 0:a948f5f3904c | 1324 | |
sjallouli | 0:a948f5f3904c | 1325 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1326 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1327 | rq.ocf = OCF_UPDATER_PROG_DATA_BLOCK; |
sjallouli | 0:a948f5f3904c | 1328 | rq.cparam = (void *)buffer; |
sjallouli | 0:a948f5f3904c | 1329 | rq.clen = indx; |
sjallouli | 0:a948f5f3904c | 1330 | rq.rparam = &status; |
sjallouli | 0:a948f5f3904c | 1331 | rq.rlen = 1; |
sjallouli | 0:a948f5f3904c | 1332 | |
sjallouli | 0:a948f5f3904c | 1333 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1334 | return -1; |
sjallouli | 0:a948f5f3904c | 1335 | |
sjallouli | 0:a948f5f3904c | 1336 | return status; |
sjallouli | 0:a948f5f3904c | 1337 | } |
sjallouli | 0:a948f5f3904c | 1338 | |
sjallouli | 0:a948f5f3904c | 1339 | tBleStatus aci_updater_read_data_block(uint32_t address, |
sjallouli | 0:a948f5f3904c | 1340 | uint16_t data_len, |
sjallouli | 0:a948f5f3904c | 1341 | uint8_t *data) |
sjallouli | 0:a948f5f3904c | 1342 | { |
sjallouli | 0:a948f5f3904c | 1343 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1344 | updater_read_data_block_cp cp; |
sjallouli | 0:a948f5f3904c | 1345 | uint8_t buffer[HCI_MAX_PACKET_SIZE]; |
sjallouli | 0:a948f5f3904c | 1346 | |
sjallouli | 0:a948f5f3904c | 1347 | if(data_len > HCI_MAX_PACKET_SIZE - 1) |
sjallouli | 0:a948f5f3904c | 1348 | return -1; |
sjallouli | 0:a948f5f3904c | 1349 | |
sjallouli | 0:a948f5f3904c | 1350 | cp.address = address; |
sjallouli | 0:a948f5f3904c | 1351 | cp.data_len = data_len; |
sjallouli | 0:a948f5f3904c | 1352 | |
sjallouli | 0:a948f5f3904c | 1353 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1354 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1355 | rq.ocf = OCF_UPDATER_READ_DATA_BLOCK; |
sjallouli | 0:a948f5f3904c | 1356 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 1357 | rq.clen = UPDATER_READ_DATA_BLOCK_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 1358 | rq.rparam = buffer; |
sjallouli | 0:a948f5f3904c | 1359 | rq.rlen = data_len + 1; |
sjallouli | 0:a948f5f3904c | 1360 | |
sjallouli | 0:a948f5f3904c | 1361 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1362 | return -1; |
sjallouli | 0:a948f5f3904c | 1363 | |
sjallouli | 0:a948f5f3904c | 1364 | Osal_MemCpy(data, buffer+1, data_len); |
sjallouli | 0:a948f5f3904c | 1365 | |
sjallouli | 0:a948f5f3904c | 1366 | return buffer[0]; |
sjallouli | 0:a948f5f3904c | 1367 | } |
sjallouli | 0:a948f5f3904c | 1368 | |
sjallouli | 0:a948f5f3904c | 1369 | tBleStatus aci_updater_calc_crc(uint32_t address, |
sjallouli | 0:a948f5f3904c | 1370 | uint8_t num_sectors, |
sjallouli | 0:a948f5f3904c | 1371 | uint32_t *crc) |
sjallouli | 0:a948f5f3904c | 1372 | { |
sjallouli | 0:a948f5f3904c | 1373 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1374 | updater_calc_crc_cp cp; |
sjallouli | 0:a948f5f3904c | 1375 | updater_calc_crc_rp resp; |
sjallouli | 0:a948f5f3904c | 1376 | |
sjallouli | 0:a948f5f3904c | 1377 | Osal_MemSet(&resp, 0, sizeof(resp)); |
sjallouli | 0:a948f5f3904c | 1378 | |
sjallouli | 0:a948f5f3904c | 1379 | cp.address = address; |
sjallouli | 0:a948f5f3904c | 1380 | cp.num_sectors = num_sectors; |
sjallouli | 0:a948f5f3904c | 1381 | |
sjallouli | 0:a948f5f3904c | 1382 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1383 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1384 | rq.ocf = OCF_UPDATER_CALC_CRC; |
sjallouli | 0:a948f5f3904c | 1385 | rq.cparam = &cp; |
sjallouli | 0:a948f5f3904c | 1386 | rq.clen = UPDATER_CALC_CRC_CP_SIZE; |
sjallouli | 0:a948f5f3904c | 1387 | rq.rparam = &resp; |
sjallouli | 0:a948f5f3904c | 1388 | rq.rlen = UPDATER_CALC_CRC_RP_SIZE; |
sjallouli | 0:a948f5f3904c | 1389 | |
sjallouli | 0:a948f5f3904c | 1390 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1391 | return -1; |
sjallouli | 0:a948f5f3904c | 1392 | |
sjallouli | 0:a948f5f3904c | 1393 | *crc = resp.crc; |
sjallouli | 0:a948f5f3904c | 1394 | |
sjallouli | 0:a948f5f3904c | 1395 | return resp.status; |
sjallouli | 0:a948f5f3904c | 1396 | } |
sjallouli | 0:a948f5f3904c | 1397 | |
sjallouli | 0:a948f5f3904c | 1398 | tBleStatus aci_updater_hw_version(uint8_t *version) |
sjallouli | 0:a948f5f3904c | 1399 | { |
sjallouli | 0:a948f5f3904c | 1400 | struct hci_request rq; |
sjallouli | 0:a948f5f3904c | 1401 | updater_hw_version_rp resp; |
sjallouli | 0:a948f5f3904c | 1402 | |
sjallouli | 0:a948f5f3904c | 1403 | Osal_MemSet(&resp, 0, sizeof(resp)); |
sjallouli | 0:a948f5f3904c | 1404 | |
sjallouli | 0:a948f5f3904c | 1405 | Osal_MemSet(&rq, 0, sizeof(rq)); |
sjallouli | 0:a948f5f3904c | 1406 | rq.ogf = OGF_VENDOR_CMD; |
sjallouli | 0:a948f5f3904c | 1407 | rq.ocf = OCF_UPDATER_HW_VERSION; |
sjallouli | 0:a948f5f3904c | 1408 | rq.rparam = &resp; |
sjallouli | 0:a948f5f3904c | 1409 | rq.rlen = UPDATER_HW_VERSION_RP_SIZE; |
sjallouli | 0:a948f5f3904c | 1410 | |
sjallouli | 0:a948f5f3904c | 1411 | if (hci_send_req(&rq) < 0) |
sjallouli | 0:a948f5f3904c | 1412 | return -1; |
sjallouli | 0:a948f5f3904c | 1413 | |
sjallouli | 0:a948f5f3904c | 1414 | *version = resp.version; |
sjallouli | 0:a948f5f3904c | 1415 | |
sjallouli | 0:a948f5f3904c | 1416 | return resp.status; |
sjallouli | 0:a948f5f3904c | 1417 | } |