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