Added support for obtaining BLE device name by parsing advertising data.

Fork of BLE_BlueNRG by Mridupawan Das

Committer:
mridup
Date:
Wed Jul 16 04:59:51 2014 +0000
Revision:
0:309c845d289d
Full BlueNRG library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mridup 0:309c845d289d 1 /******************************************************************************
mridup 0:309c845d289d 2 *
mridup 0:309c845d289d 3 * File Description
mridup 0:309c845d289d 4 * ---------------------
mridup 0:309c845d289d 5 * This file defines constants and functions for HCI layer.
mridup 0:309c845d289d 6 * See Bluetooth Core v 4.0, Vol. 2, Part E.
mridup 0:309c845d289d 7 *
mridup 0:309c845d289d 8 *******************************************************************************/
mridup 0:309c845d289d 9
mridup 0:309c845d289d 10 #ifndef __HCI_INTERNAL_H_
mridup 0:309c845d289d 11 #define __HCI_INTERNAL_H_
mridup 0:309c845d289d 12
mridup 0:309c845d289d 13 #include "compiler.h"
mridup 0:309c845d289d 14 #include "hal_types.h"
mridup 0:309c845d289d 15 #include "clock.h"
mridup 0:309c845d289d 16 #include "link_layer.h"
mridup 0:309c845d289d 17 #include "hci.h"
mridup 0:309c845d289d 18
mridup 0:309c845d289d 19 #define DEFAULT_TIMEOUT (CLOCK_SECOND/100)
mridup 0:309c845d289d 20
mridup 0:309c845d289d 21 #define HCI_MAX_EVENT_SIZE 260
mridup 0:309c845d289d 22
mridup 0:309c845d289d 23 #define HCI_MAX_PACKET_SIZE HCI_MAX_EVENT_SIZE
mridup 0:309c845d289d 24
mridup 0:309c845d289d 25 /* HCI Packet types */
mridup 0:309c845d289d 26 #define HCI_COMMAND_PKT 0x01
mridup 0:309c845d289d 27 #define HCI_ACLDATA_PKT 0x02
mridup 0:309c845d289d 28 #define HCI_SCODATA_PKT 0x03
mridup 0:309c845d289d 29 #define HCI_EVENT_PKT 0x04
mridup 0:309c845d289d 30 #define HCI_VENDOR_PKT 0xff
mridup 0:309c845d289d 31
mridup 0:309c845d289d 32
mridup 0:309c845d289d 33 typedef __packed struct _hci_uart_pckt{
mridup 0:309c845d289d 34 tHalUint8 type;
mridup 0:309c845d289d 35 tHalUint8 data[0];
mridup 0:309c845d289d 36 } PACKED hci_uart_pckt;
mridup 0:309c845d289d 37 #define HCI_HDR_SIZE 1
mridup 0:309c845d289d 38
mridup 0:309c845d289d 39 typedef __packed struct _hci_command_hdr{
mridup 0:309c845d289d 40 tHalUint16 opcode; /* OCF & OGF */
mridup 0:309c845d289d 41 tHalUint8 plen;
mridup 0:309c845d289d 42 } PACKED hci_command_hdr;
mridup 0:309c845d289d 43 #define HCI_COMMAND_HDR_SIZE 3
mridup 0:309c845d289d 44
mridup 0:309c845d289d 45 typedef __packed struct _hci_event_pckt{
mridup 0:309c845d289d 46 tHalUint8 evt;
mridup 0:309c845d289d 47 tHalUint8 plen;
mridup 0:309c845d289d 48 tHalUint8 data[0];
mridup 0:309c845d289d 49 } PACKED hci_event_pckt;
mridup 0:309c845d289d 50 #define HCI_EVENT_HDR_SIZE 2
mridup 0:309c845d289d 51
mridup 0:309c845d289d 52 typedef __packed struct _hci_acl_hdr{
mridup 0:309c845d289d 53 tHalUint16 handle; /* Handle & Flags(PB, BC) */
mridup 0:309c845d289d 54 tHalUint16 dlen;
mridup 0:309c845d289d 55 } PACKED hci_acl_hdr;
mridup 0:309c845d289d 56 #define HCI_ACL_HDR_SIZE 4
mridup 0:309c845d289d 57
mridup 0:309c845d289d 58
mridup 0:309c845d289d 59 /* Link Control */
mridup 0:309c845d289d 60 #define OGF_LINK_CTL 0x01
mridup 0:309c845d289d 61
mridup 0:309c845d289d 62 #define OCF_DISCONNECT 0x0006
mridup 0:309c845d289d 63 typedef __packed struct _disconnect_cp{
mridup 0:309c845d289d 64 uint16_t handle;
mridup 0:309c845d289d 65 uint8_t reason;
mridup 0:309c845d289d 66 } PACKED disconnect_cp;
mridup 0:309c845d289d 67 #define DISCONNECT_CP_SIZE 3
mridup 0:309c845d289d 68
mridup 0:309c845d289d 69
mridup 0:309c845d289d 70 /* Host Controller and Baseband */
mridup 0:309c845d289d 71 #define OGF_HOST_CTL 0x03
mridup 0:309c845d289d 72
mridup 0:309c845d289d 73 #define OCF_SET_EVENT_MASK 0x0001
mridup 0:309c845d289d 74 #define OCF_RESET 0x0003
mridup 0:309c845d289d 75
mridup 0:309c845d289d 76 #define OCF_READ_TRANSMIT_POWER_LEVEL 0x002D
mridup 0:309c845d289d 77 typedef __packed struct _read_transmit_power_level_cp{
mridup 0:309c845d289d 78 uint16_t handle;
mridup 0:309c845d289d 79 uint8_t type;
mridup 0:309c845d289d 80 } PACKED read_transmit_power_level_cp;
mridup 0:309c845d289d 81 #define READ_TRANSMIT_POWER_LEVEL_CP_SIZE 3
mridup 0:309c845d289d 82 typedef __packed struct _read_transmit_power_level_rp{
mridup 0:309c845d289d 83 uint8_t status;
mridup 0:309c845d289d 84 uint16_t handle;
mridup 0:309c845d289d 85 int8_t level;
mridup 0:309c845d289d 86 } PACKED read_transmit_power_level_rp;
mridup 0:309c845d289d 87 #define READ_TRANSMIT_POWER_LEVEL_RP_SIZE 4
mridup 0:309c845d289d 88
mridup 0:309c845d289d 89 #define OCF_SET_CONTROLLER_TO_HOST_FC 0x0031
mridup 0:309c845d289d 90 #define OCF_HOST_BUFFER_SIZE 0x0033
mridup 0:309c845d289d 91 #define OCF_HOST_NUM_COMP_PKTS 0x0035
mridup 0:309c845d289d 92
mridup 0:309c845d289d 93 /* Informational Parameters */
mridup 0:309c845d289d 94 #define OGF_INFO_PARAM 0x04
mridup 0:309c845d289d 95
mridup 0:309c845d289d 96 #define OCF_READ_LOCAL_VERSION 0x0001
mridup 0:309c845d289d 97 typedef __packed struct _read_local_version_rp{
mridup 0:309c845d289d 98 uint8_t status;
mridup 0:309c845d289d 99 uint8_t hci_version;
mridup 0:309c845d289d 100 uint16_t hci_revision;
mridup 0:309c845d289d 101 uint8_t lmp_pal_version;
mridup 0:309c845d289d 102 uint16_t manufacturer_name;
mridup 0:309c845d289d 103 uint16_t lmp_pal_subversion;
mridup 0:309c845d289d 104 } PACKED read_local_version_rp;
mridup 0:309c845d289d 105 #define READ_LOCAL_VERSION_RP_SIZE 9
mridup 0:309c845d289d 106
mridup 0:309c845d289d 107 #define OCF_READ_LOCAL_COMMANDS 0x0002
mridup 0:309c845d289d 108 #define OCF_READ_LOCAL_FEATURES 0x0003
mridup 0:309c845d289d 109
mridup 0:309c845d289d 110 #define OCF_READ_BD_ADDR 0x0009
mridup 0:309c845d289d 111 typedef __packed struct _read_bd_addr_rp{
mridup 0:309c845d289d 112 uint8_t status;
mridup 0:309c845d289d 113 tBDAddr bdaddr;
mridup 0:309c845d289d 114 } PACKED read_bd_addr_rp;
mridup 0:309c845d289d 115 #define READ_BD_ADDR_RP_SIZE 7
mridup 0:309c845d289d 116
mridup 0:309c845d289d 117 /* Status params */
mridup 0:309c845d289d 118 #define OGF_STATUS_PARAM 0x05
mridup 0:309c845d289d 119
mridup 0:309c845d289d 120 #define OCF_READ_RSSI 0x0005
mridup 0:309c845d289d 121 typedef __packed struct _read_rssi_cp{
mridup 0:309c845d289d 122 uint16_t handle;
mridup 0:309c845d289d 123 } PACKED read_rssi_cp;
mridup 0:309c845d289d 124 #define READ_RSSI_CP_SIZE 2
mridup 0:309c845d289d 125 typedef __packed struct _read_rssi_rp{
mridup 0:309c845d289d 126 uint8_t status;
mridup 0:309c845d289d 127 uint16_t handle;
mridup 0:309c845d289d 128 int8_t rssi;
mridup 0:309c845d289d 129 } PACKED read_rssi_rp;
mridup 0:309c845d289d 130 #define READ_RSSI_RP_SIZE 4
mridup 0:309c845d289d 131
mridup 0:309c845d289d 132
mridup 0:309c845d289d 133 /* LE commands */
mridup 0:309c845d289d 134 #define OGF_LE_CTL 0x08
mridup 0:309c845d289d 135
mridup 0:309c845d289d 136 #define OCF_LE_SET_EVENT_MASK 0x0001
mridup 0:309c845d289d 137 typedef __packed struct _le_set_event_mask_cp{
mridup 0:309c845d289d 138 uint8_t mask[8];
mridup 0:309c845d289d 139 } PACKED le_set_event_mask_cp;
mridup 0:309c845d289d 140 #define LE_SET_EVENT_MASK_CP_SIZE 8
mridup 0:309c845d289d 141
mridup 0:309c845d289d 142 #define OCF_LE_READ_BUFFER_SIZE 0x0002
mridup 0:309c845d289d 143 typedef __packed struct _le_read_buffer_size_rp{
mridup 0:309c845d289d 144 uint8_t status;
mridup 0:309c845d289d 145 uint16_t pkt_len;
mridup 0:309c845d289d 146 uint8_t max_pkt;
mridup 0:309c845d289d 147 } PACKED le_read_buffer_size_rp;
mridup 0:309c845d289d 148 #define LE_READ_BUFFER_SIZE_RP_SIZE 4
mridup 0:309c845d289d 149
mridup 0:309c845d289d 150 #define OCF_LE_READ_LOCAL_SUPPORTED_FEATURES 0x0003
mridup 0:309c845d289d 151 typedef __packed struct _le_read_local_supported_features_rp{
mridup 0:309c845d289d 152 uint8_t status;
mridup 0:309c845d289d 153 uint8_t features[8];
mridup 0:309c845d289d 154 } PACKED le_read_local_supported_features_rp;
mridup 0:309c845d289d 155 #define LE_READ_LOCAL_SUPPORTED_FEATURES_RP_SIZE 9
mridup 0:309c845d289d 156
mridup 0:309c845d289d 157 #define OCF_LE_SET_RANDOM_ADDRESS 0x0005
mridup 0:309c845d289d 158 typedef __packed struct _le_set_random_address_cp{
mridup 0:309c845d289d 159 tBDAddr bdaddr;
mridup 0:309c845d289d 160 } PACKED le_set_random_address_cp;
mridup 0:309c845d289d 161 #define LE_SET_RANDOM_ADDRESS_CP_SIZE 6
mridup 0:309c845d289d 162
mridup 0:309c845d289d 163 #define OCF_LE_SET_ADV_PARAMETERS 0x0006
mridup 0:309c845d289d 164 typedef __packed struct _le_set_adv_parameters_cp{
mridup 0:309c845d289d 165 uint16_t min_interval;
mridup 0:309c845d289d 166 uint16_t max_interval;
mridup 0:309c845d289d 167 uint8_t advtype;
mridup 0:309c845d289d 168 uint8_t own_bdaddr_type;
mridup 0:309c845d289d 169 uint8_t direct_bdaddr_type;
mridup 0:309c845d289d 170 tBDAddr direct_bdaddr;
mridup 0:309c845d289d 171 uint8_t chan_map;
mridup 0:309c845d289d 172 uint8_t filter;
mridup 0:309c845d289d 173 } PACKED le_set_adv_parameters_cp;
mridup 0:309c845d289d 174 #define LE_SET_ADV_PARAMETERS_CP_SIZE 15
mridup 0:309c845d289d 175
mridup 0:309c845d289d 176 #define OCF_LE_READ_ADV_CHANNEL_TX_POWER 0x0007
mridup 0:309c845d289d 177 typedef __packed struct _le_read_adv_channel_tx_power_rp{
mridup 0:309c845d289d 178 uint8_t status;
mridup 0:309c845d289d 179 int8_t level;
mridup 0:309c845d289d 180 } PACKED le_read_adv_channel_tx_power_rp;
mridup 0:309c845d289d 181 #define LE_READ_ADV_CHANNEL_TX_POWER_RP_SIZE 2
mridup 0:309c845d289d 182
mridup 0:309c845d289d 183 #define OCF_LE_SET_ADV_DATA 0x0008
mridup 0:309c845d289d 184 typedef __packed struct _le_set_adv_data_cp{
mridup 0:309c845d289d 185 uint8_t length;
mridup 0:309c845d289d 186 uint8_t data[31];
mridup 0:309c845d289d 187 } PACKED le_set_adv_data_cp;
mridup 0:309c845d289d 188 #define LE_SET_ADV_DATA_CP_SIZE 32
mridup 0:309c845d289d 189
mridup 0:309c845d289d 190 #define OCF_LE_SET_SCAN_RESPONSE_DATA 0x0009
mridup 0:309c845d289d 191 typedef __packed struct _le_set_scan_response_data_cp{
mridup 0:309c845d289d 192 uint8_t length;
mridup 0:309c845d289d 193 uint8_t data[31];
mridup 0:309c845d289d 194 } PACKED le_set_scan_response_data_cp;
mridup 0:309c845d289d 195 #define LE_SET_SCAN_RESPONSE_DATA_CP_SIZE 32
mridup 0:309c845d289d 196
mridup 0:309c845d289d 197 #define OCF_LE_SET_ADVERTISE_ENABLE 0x000A
mridup 0:309c845d289d 198 typedef __packed struct _le_set_advertise_enable_cp{
mridup 0:309c845d289d 199 uint8_t enable;
mridup 0:309c845d289d 200 } PACKED le_set_advertise_enable_cp;
mridup 0:309c845d289d 201 #define LE_SET_ADVERTISE_ENABLE_CP_SIZE 1
mridup 0:309c845d289d 202
mridup 0:309c845d289d 203 #define OCF_LE_SET_SCAN_PARAMETERS 0x000B
mridup 0:309c845d289d 204 typedef __packed struct _le_set_scan_parameters_cp{
mridup 0:309c845d289d 205 uint8_t type;
mridup 0:309c845d289d 206 uint16_t interval;
mridup 0:309c845d289d 207 uint16_t window;
mridup 0:309c845d289d 208 uint8_t own_bdaddr_type;
mridup 0:309c845d289d 209 uint8_t filter;
mridup 0:309c845d289d 210 } PACKED le_set_scan_parameters_cp;
mridup 0:309c845d289d 211 #define LE_SET_SCAN_PARAMETERS_CP_SIZE 7
mridup 0:309c845d289d 212
mridup 0:309c845d289d 213 #define OCF_LE_SET_SCAN_ENABLE 0x000C
mridup 0:309c845d289d 214 typedef __packed struct _le_set_scan_enable_cp{
mridup 0:309c845d289d 215 uint8_t enable;
mridup 0:309c845d289d 216 uint8_t filter_dup;
mridup 0:309c845d289d 217 } PACKED le_set_scan_enable_cp;
mridup 0:309c845d289d 218 #define LE_SET_SCAN_ENABLE_CP_SIZE 2
mridup 0:309c845d289d 219
mridup 0:309c845d289d 220 #define OCF_LE_CREATE_CONN 0x000D
mridup 0:309c845d289d 221 typedef __packed struct _le_create_connection_cp{
mridup 0:309c845d289d 222 uint16_t interval;
mridup 0:309c845d289d 223 uint16_t window;
mridup 0:309c845d289d 224 uint8_t initiator_filter;
mridup 0:309c845d289d 225 uint8_t peer_bdaddr_type;
mridup 0:309c845d289d 226 tBDAddr peer_bdaddr;
mridup 0:309c845d289d 227 uint8_t own_bdaddr_type;
mridup 0:309c845d289d 228 uint16_t min_interval;
mridup 0:309c845d289d 229 uint16_t max_interval;
mridup 0:309c845d289d 230 uint16_t latency;
mridup 0:309c845d289d 231 uint16_t supervision_timeout;
mridup 0:309c845d289d 232 uint16_t min_ce_length;
mridup 0:309c845d289d 233 uint16_t max_ce_length;
mridup 0:309c845d289d 234 } PACKED le_create_connection_cp;
mridup 0:309c845d289d 235 #define LE_CREATE_CONN_CP_SIZE 25
mridup 0:309c845d289d 236
mridup 0:309c845d289d 237 #define OCF_LE_CREATE_CONN_CANCEL 0x000E
mridup 0:309c845d289d 238
mridup 0:309c845d289d 239 #define OCF_LE_READ_WHITE_LIST_SIZE 0x000F
mridup 0:309c845d289d 240 typedef __packed struct _le_read_white_list_size_rp{
mridup 0:309c845d289d 241 uint8_t status;
mridup 0:309c845d289d 242 uint8_t size;
mridup 0:309c845d289d 243 } PACKED le_read_white_list_size_rp;
mridup 0:309c845d289d 244 #define LE_READ_WHITE_LIST_SIZE_RP_SIZE 2
mridup 0:309c845d289d 245
mridup 0:309c845d289d 246 #define OCF_LE_CLEAR_WHITE_LIST 0x0010
mridup 0:309c845d289d 247
mridup 0:309c845d289d 248 #define OCF_LE_ADD_DEVICE_TO_WHITE_LIST 0x0011
mridup 0:309c845d289d 249 typedef __packed struct _le_add_device_to_white_list_cp{
mridup 0:309c845d289d 250 uint8_t bdaddr_type;
mridup 0:309c845d289d 251 tBDAddr bdaddr;
mridup 0:309c845d289d 252 } PACKED le_add_device_to_white_list_cp;
mridup 0:309c845d289d 253 #define LE_ADD_DEVICE_TO_WHITE_LIST_CP_SIZE 7
mridup 0:309c845d289d 254
mridup 0:309c845d289d 255 #define OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST 0x0012
mridup 0:309c845d289d 256 typedef __packed struct _le_remove_device_from_white_list_cp{
mridup 0:309c845d289d 257 uint8_t bdaddr_type;
mridup 0:309c845d289d 258 tBDAddr bdaddr;
mridup 0:309c845d289d 259 } PACKED le_remove_device_from_white_list_cp;
mridup 0:309c845d289d 260 #define LE_REMOVE_DEVICE_FROM_WHITE_LIST_CP_SIZE 7
mridup 0:309c845d289d 261
mridup 0:309c845d289d 262 #define OCF_LE_CONN_UPDATE 0x0013
mridup 0:309c845d289d 263 typedef __packed struct _le_connection_update_cp{
mridup 0:309c845d289d 264 uint16_t handle;
mridup 0:309c845d289d 265 uint16_t min_interval;
mridup 0:309c845d289d 266 uint16_t max_interval;
mridup 0:309c845d289d 267 uint16_t latency;
mridup 0:309c845d289d 268 uint16_t supervision_timeout;
mridup 0:309c845d289d 269 uint16_t min_ce_length;
mridup 0:309c845d289d 270 uint16_t max_ce_length;
mridup 0:309c845d289d 271 } PACKED le_connection_update_cp;
mridup 0:309c845d289d 272 #define LE_CONN_UPDATE_CP_SIZE 14
mridup 0:309c845d289d 273
mridup 0:309c845d289d 274 #define OCF_LE_SET_HOST_CHANNEL_CLASSIFICATION 0x0014
mridup 0:309c845d289d 275 typedef __packed struct _le_set_host_channel_classification_cp{
mridup 0:309c845d289d 276 uint8_t map[5];
mridup 0:309c845d289d 277 } PACKED le_set_host_channel_classification_cp;
mridup 0:309c845d289d 278 #define LE_SET_HOST_CHANNEL_CLASSIFICATION_CP_SIZE 5
mridup 0:309c845d289d 279
mridup 0:309c845d289d 280 #define OCF_LE_READ_CHANNEL_MAP 0x0015
mridup 0:309c845d289d 281 typedef __packed struct _le_read_channel_map_cp{
mridup 0:309c845d289d 282 uint16_t handle;
mridup 0:309c845d289d 283 } PACKED le_read_channel_map_cp;
mridup 0:309c845d289d 284 #define LE_READ_CHANNEL_MAP_CP_SIZE 2
mridup 0:309c845d289d 285
mridup 0:309c845d289d 286 typedef __packed struct _le_read_channel_map_rp{
mridup 0:309c845d289d 287 uint8_t status;
mridup 0:309c845d289d 288 uint16_t handle;
mridup 0:309c845d289d 289 uint8_t map[5];
mridup 0:309c845d289d 290 } le_read_channel_map_rp;
mridup 0:309c845d289d 291 #define LE_READ_CHANNEL_MAP_RP_SIZE 8
mridup 0:309c845d289d 292
mridup 0:309c845d289d 293 #define OCF_LE_READ_REMOTE_USED_FEATURES 0x0016
mridup 0:309c845d289d 294 typedef __packed struct _le_read_remote_used_features_cp{
mridup 0:309c845d289d 295 uint16_t handle;
mridup 0:309c845d289d 296 } PACKED le_read_remote_used_features_cp;
mridup 0:309c845d289d 297 #define LE_READ_REMOTE_USED_FEATURES_CP_SIZE 2
mridup 0:309c845d289d 298
mridup 0:309c845d289d 299 #define OCF_LE_ENCRYPT 0x0017
mridup 0:309c845d289d 300 typedef __packed struct _le_encrypt_cp{
mridup 0:309c845d289d 301 uint8_t key[16];
mridup 0:309c845d289d 302 uint8_t plaintext[16];
mridup 0:309c845d289d 303 } PACKED le_encrypt_cp;
mridup 0:309c845d289d 304 #define LE_ENCRYPT_CP_SIZE 32
mridup 0:309c845d289d 305
mridup 0:309c845d289d 306 typedef __packed struct _le_encrypt_rp{
mridup 0:309c845d289d 307 uint8_t status;
mridup 0:309c845d289d 308 uint8_t encdata[16];
mridup 0:309c845d289d 309 } PACKED le_encrypt_rp;
mridup 0:309c845d289d 310 #define LE_ENCRYPT_RP_SIZE 17
mridup 0:309c845d289d 311
mridup 0:309c845d289d 312 #define OCF_LE_RAND 0x0018
mridup 0:309c845d289d 313 typedef __packed struct _le_rand_rp{
mridup 0:309c845d289d 314 uint8_t status;
mridup 0:309c845d289d 315 uint8_t random[8];
mridup 0:309c845d289d 316 } PACKED le_rand_rp;
mridup 0:309c845d289d 317 #define LE_RAND_RP_SIZE 9
mridup 0:309c845d289d 318
mridup 0:309c845d289d 319 #define OCF_LE_START_ENCRYPTION 0x0019
mridup 0:309c845d289d 320 typedef __packed struct _le_start_encryption_cp{
mridup 0:309c845d289d 321 uint16_t handle;
mridup 0:309c845d289d 322 uint8_t random[8];
mridup 0:309c845d289d 323 uint16_t diversifier;
mridup 0:309c845d289d 324 uint8_t key[16];
mridup 0:309c845d289d 325 } PACKED le_start_encryption_cp;
mridup 0:309c845d289d 326 #define LE_START_ENCRYPTION_CP_SIZE 28
mridup 0:309c845d289d 327
mridup 0:309c845d289d 328 #define OCF_LE_LTK_REPLY 0x001A
mridup 0:309c845d289d 329 typedef __packed struct _le_ltk_reply_cp{
mridup 0:309c845d289d 330 uint16_t handle;
mridup 0:309c845d289d 331 uint8_t key[16];
mridup 0:309c845d289d 332 } PACKED le_ltk_reply_cp;
mridup 0:309c845d289d 333 #define LE_LTK_REPLY_CP_SIZE 18
mridup 0:309c845d289d 334
mridup 0:309c845d289d 335 typedef __packed struct _le_ltk_reply_rp{
mridup 0:309c845d289d 336 uint8_t status;
mridup 0:309c845d289d 337 uint16_t handle;
mridup 0:309c845d289d 338 } PACKED le_ltk_reply_rp;
mridup 0:309c845d289d 339 #define LE_LTK_REPLY_RP_SIZE 3
mridup 0:309c845d289d 340
mridup 0:309c845d289d 341 #define OCF_LE_LTK_NEG_REPLY 0x001B
mridup 0:309c845d289d 342 typedef __packed struct _le_ltk_neg_reply_cp{
mridup 0:309c845d289d 343 uint16_t handle;
mridup 0:309c845d289d 344 } PACKED le_ltk_neg_reply_cp;
mridup 0:309c845d289d 345 #define LE_LTK_NEG_REPLY_CP_SIZE 2
mridup 0:309c845d289d 346
mridup 0:309c845d289d 347 typedef __packed struct _le_ltk_neg_reply_rp{
mridup 0:309c845d289d 348 uint8_t status;
mridup 0:309c845d289d 349 uint16_t handle;
mridup 0:309c845d289d 350 } PACKED le_ltk_neg_reply_rp;
mridup 0:309c845d289d 351 #define LE_LTK_NEG_REPLY_RP_SIZE 3
mridup 0:309c845d289d 352
mridup 0:309c845d289d 353 #define OCF_LE_READ_SUPPORTED_STATES 0x001C
mridup 0:309c845d289d 354 typedef __packed struct _le_read_supported_states_rp{
mridup 0:309c845d289d 355 uint8_t status;
mridup 0:309c845d289d 356 uint8_t states[8];
mridup 0:309c845d289d 357 } PACKED le_read_supported_states_rp;
mridup 0:309c845d289d 358 #define LE_READ_SUPPORTED_STATES_RP_SIZE 9
mridup 0:309c845d289d 359
mridup 0:309c845d289d 360 #define OCF_LE_RECEIVER_TEST 0x001D
mridup 0:309c845d289d 361 typedef __packed struct _le_receiver_test_cp{
mridup 0:309c845d289d 362 uint8_t frequency;
mridup 0:309c845d289d 363 } PACKED le_receiver_test_cp;
mridup 0:309c845d289d 364 #define LE_RECEIVER_TEST_CP_SIZE 1
mridup 0:309c845d289d 365
mridup 0:309c845d289d 366 #define OCF_LE_TRANSMITTER_TEST 0x001E
mridup 0:309c845d289d 367 typedef __packed struct _le_transmitter_test_cp{
mridup 0:309c845d289d 368 uint8_t frequency;
mridup 0:309c845d289d 369 uint8_t length;
mridup 0:309c845d289d 370 uint8_t payload;
mridup 0:309c845d289d 371 } PACKED le_transmitter_test_cp;
mridup 0:309c845d289d 372 #define LE_TRANSMITTER_TEST_CP_SIZE 3
mridup 0:309c845d289d 373
mridup 0:309c845d289d 374 #define OCF_LE_TEST_END 0x001F
mridup 0:309c845d289d 375 typedef __packed struct _le_test_end_rp{
mridup 0:309c845d289d 376 uint8_t status;
mridup 0:309c845d289d 377 uint16_t num_pkts;
mridup 0:309c845d289d 378 } PACKED le_test_end_rp;
mridup 0:309c845d289d 379 #define LE_TEST_END_RP_SIZE 3
mridup 0:309c845d289d 380
mridup 0:309c845d289d 381 /* Vendor specific commands */
mridup 0:309c845d289d 382 #define OGF_VENDOR_CMD 0x3f
mridup 0:309c845d289d 383
mridup 0:309c845d289d 384
mridup 0:309c845d289d 385 /*------------- Events -------------*/
mridup 0:309c845d289d 386 #define EVT_CONN_COMPLETE 0x03
mridup 0:309c845d289d 387 typedef __packed struct _evt_conn_complete{
mridup 0:309c845d289d 388 uint8_t status;
mridup 0:309c845d289d 389 uint16_t handle;
mridup 0:309c845d289d 390 tBDAddr bdaddr;
mridup 0:309c845d289d 391 uint8_t link_type;
mridup 0:309c845d289d 392 uint8_t encr_mode;
mridup 0:309c845d289d 393 } PACKED evt_conn_complete;
mridup 0:309c845d289d 394 #define EVT_CONN_COMPLETE_SIZE 13
mridup 0:309c845d289d 395
mridup 0:309c845d289d 396 #define EVT_DISCONN_COMPLETE 0x05
mridup 0:309c845d289d 397 typedef __packed struct _evt_disconn_complete{
mridup 0:309c845d289d 398 uint8_t status;
mridup 0:309c845d289d 399 uint16_t handle;
mridup 0:309c845d289d 400 uint8_t reason;
mridup 0:309c845d289d 401 } PACKED evt_disconn_complete;
mridup 0:309c845d289d 402 #define EVT_DISCONN_COMPLETE_SIZE 4
mridup 0:309c845d289d 403
mridup 0:309c845d289d 404 #define EVT_ENCRYPT_CHANGE 0x08
mridup 0:309c845d289d 405 typedef __packed struct _evt_encrypt_change{
mridup 0:309c845d289d 406 uint8_t status;
mridup 0:309c845d289d 407 uint16_t handle;
mridup 0:309c845d289d 408 uint8_t encrypt;
mridup 0:309c845d289d 409 } PACKED evt_encrypt_change;
mridup 0:309c845d289d 410 #define EVT_ENCRYPT_CHANGE_SIZE 5
mridup 0:309c845d289d 411
mridup 0:309c845d289d 412 #define EVT_READ_REMOTE_VERSION_COMPLETE 0x0C
mridup 0:309c845d289d 413
mridup 0:309c845d289d 414 #define EVT_CMD_COMPLETE 0x0E
mridup 0:309c845d289d 415 typedef __packed struct _evt_cmd_complete{
mridup 0:309c845d289d 416 tHalUint8 ncmd;
mridup 0:309c845d289d 417 tHalUint16 opcode;
mridup 0:309c845d289d 418 } PACKED evt_cmd_complete;
mridup 0:309c845d289d 419 #define EVT_CMD_COMPLETE_SIZE 3
mridup 0:309c845d289d 420
mridup 0:309c845d289d 421 #define EVT_CMD_STATUS 0x0F
mridup 0:309c845d289d 422 typedef __packed struct _evt_cmd_status{
mridup 0:309c845d289d 423 tHalUint8 status;
mridup 0:309c845d289d 424 tHalUint8 ncmd;
mridup 0:309c845d289d 425 tHalUint16 opcode;
mridup 0:309c845d289d 426 } PACKED evt_cmd_status;
mridup 0:309c845d289d 427 #define EVT_CMD_STATUS_SIZE 4
mridup 0:309c845d289d 428
mridup 0:309c845d289d 429 #define EVT_HARDWARE_ERROR 0x10
mridup 0:309c845d289d 430 typedef __packed struct _evt_hardware_error{
mridup 0:309c845d289d 431 uint8_t code;
mridup 0:309c845d289d 432 } PACKED evt_hardware_error;
mridup 0:309c845d289d 433 #define EVT_HARDWARE_ERROR_SIZE 1
mridup 0:309c845d289d 434
mridup 0:309c845d289d 435 #define EVT_NUM_COMP_PKTS 0x13
mridup 0:309c845d289d 436 typedef __packed struct _evt_num_comp_pkts{
mridup 0:309c845d289d 437 uint8_t num_hndl;
mridup 0:309c845d289d 438 /* variable length part */
mridup 0:309c845d289d 439 } PACKED evt_num_comp_pkts;
mridup 0:309c845d289d 440 #define EVT_NUM_COMP_PKTS_SIZE 1
mridup 0:309c845d289d 441
mridup 0:309c845d289d 442 /* variable length part of evt_num_comp_pkts. */
mridup 0:309c845d289d 443 typedef __packed struct _evt_num_comp_pkts_param{
mridup 0:309c845d289d 444 uint16_t hndl;
mridup 0:309c845d289d 445 uint16_t num_comp_pkts;
mridup 0:309c845d289d 446 } PACKED evt_num_comp_pkts_param;
mridup 0:309c845d289d 447 #define EVT_NUM_COMP_PKTS_PARAM_SIZE 1
mridup 0:309c845d289d 448
mridup 0:309c845d289d 449 #define EVT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30
mridup 0:309c845d289d 450 typedef __packed struct _evt_encryption_key_refresh_complete{
mridup 0:309c845d289d 451 uint8_t status;
mridup 0:309c845d289d 452 uint16_t handle;
mridup 0:309c845d289d 453 } PACKED evt_encryption_key_refresh_complete;
mridup 0:309c845d289d 454 #define EVT_ENCRYPTION_KEY_REFRESH_COMPLETE_SIZE 3
mridup 0:309c845d289d 455
mridup 0:309c845d289d 456 #define EVT_LE_META_EVENT 0x3E
mridup 0:309c845d289d 457 typedef __packed struct _evt_le_meta_event{
mridup 0:309c845d289d 458 tHalUint8 subevent;
mridup 0:309c845d289d 459 tHalUint8 data[0];
mridup 0:309c845d289d 460 } PACKED evt_le_meta_event;
mridup 0:309c845d289d 461 #define EVT_LE_META_EVENT_SIZE 1
mridup 0:309c845d289d 462
mridup 0:309c845d289d 463 #define EVT_LE_CONN_COMPLETE 0x01
mridup 0:309c845d289d 464 typedef __packed struct _evt_le_connection_complete{
mridup 0:309c845d289d 465 uint8_t status;
mridup 0:309c845d289d 466 uint16_t handle;
mridup 0:309c845d289d 467 uint8_t role;
mridup 0:309c845d289d 468 uint8_t peer_bdaddr_type;
mridup 0:309c845d289d 469 tBDAddr peer_bdaddr;
mridup 0:309c845d289d 470 uint16_t interval;
mridup 0:309c845d289d 471 uint16_t latency;
mridup 0:309c845d289d 472 uint16_t supervision_timeout;
mridup 0:309c845d289d 473 uint8_t master_clock_accuracy;
mridup 0:309c845d289d 474 } PACKED evt_le_connection_complete;
mridup 0:309c845d289d 475 #define EVT_LE_CONN_COMPLETE_SIZE 18
mridup 0:309c845d289d 476
mridup 0:309c845d289d 477 #define EVT_LE_ADVERTISING_REPORT 0x02
mridup 0:309c845d289d 478 typedef __packed struct _le_advertising_info{
mridup 0:309c845d289d 479 uint8_t evt_type;
mridup 0:309c845d289d 480 uint8_t bdaddr_type;
mridup 0:309c845d289d 481 tBDAddr bdaddr;
mridup 0:309c845d289d 482 uint8_t length;
mridup 0:309c845d289d 483 uint8_t data[0];
mridup 0:309c845d289d 484 } PACKED le_advertising_info;
mridup 0:309c845d289d 485 #define LE_ADVERTISING_INFO_SIZE 9
mridup 0:309c845d289d 486
mridup 0:309c845d289d 487 #define EVT_LE_CONN_UPDATE_COMPLETE 0x03
mridup 0:309c845d289d 488 typedef __packed struct _evt_le_connection_update_complete{
mridup 0:309c845d289d 489 uint8_t status;
mridup 0:309c845d289d 490 uint16_t handle;
mridup 0:309c845d289d 491 uint16_t interval;
mridup 0:309c845d289d 492 uint16_t latency;
mridup 0:309c845d289d 493 uint16_t supervision_timeout;
mridup 0:309c845d289d 494 } PACKED evt_le_connection_update_complete;
mridup 0:309c845d289d 495 #define EVT_LE_CONN_UPDATE_COMPLETE_SIZE 9
mridup 0:309c845d289d 496
mridup 0:309c845d289d 497 #define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04
mridup 0:309c845d289d 498 typedef __packed struct _evt_le_read_remote_used_features_complete{
mridup 0:309c845d289d 499 uint8_t status;
mridup 0:309c845d289d 500 uint16_t handle;
mridup 0:309c845d289d 501 uint8_t features[8];
mridup 0:309c845d289d 502 } PACKED evt_le_read_remote_used_features_complete;
mridup 0:309c845d289d 503 #define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE_SIZE 11
mridup 0:309c845d289d 504
mridup 0:309c845d289d 505 #define EVT_LE_LTK_REQUEST 0x05
mridup 0:309c845d289d 506 typedef __packed struct _evt_le_long_term_key_request{
mridup 0:309c845d289d 507 uint16_t handle;
mridup 0:309c845d289d 508 uint8_t random[8];
mridup 0:309c845d289d 509 uint16_t ediv;
mridup 0:309c845d289d 510 } PACKED evt_le_long_term_key_request;
mridup 0:309c845d289d 511 #define EVT_LE_LTK_REQUEST_SIZE 12
mridup 0:309c845d289d 512
mridup 0:309c845d289d 513
mridup 0:309c845d289d 514 /* Command opcode pack/unpack */
mridup 0:309c845d289d 515 #define cmd_opcode_pack(ogf, ocf) (tHalUint16)((ocf & 0x03ff)|(ogf << 10))
mridup 0:309c845d289d 516 #define cmd_opcode_ogf(op) (op >> 10)
mridup 0:309c845d289d 517 #define cmd_opcode_ocf(op) (op & 0x03ff)
mridup 0:309c845d289d 518
mridup 0:309c845d289d 519
mridup 0:309c845d289d 520 struct hci_request {
mridup 0:309c845d289d 521 uint16_t ogf;
mridup 0:309c845d289d 522 uint16_t ocf;
mridup 0:309c845d289d 523 int event;
mridup 0:309c845d289d 524 void *cparam;
mridup 0:309c845d289d 525 int clen;
mridup 0:309c845d289d 526 void *rparam;
mridup 0:309c845d289d 527 int rlen;
mridup 0:309c845d289d 528 };
mridup 0:309c845d289d 529
mridup 0:309c845d289d 530 int hci_send_cmd(uint16_t ogf, uint16_t ocf, uint8_t plen, void *param);
mridup 0:309c845d289d 531
mridup 0:309c845d289d 532 typedef enum {
mridup 0:309c845d289d 533 WAITING_TYPE,
mridup 0:309c845d289d 534 WAITING_OPCODE1,
mridup 0:309c845d289d 535 WAITING_OPCODE2,
mridup 0:309c845d289d 536 WAITING_EVENT_CODE,
mridup 0:309c845d289d 537 WAITING_HANDLE,
mridup 0:309c845d289d 538 WAITING_HANDLE_FLAG,
mridup 0:309c845d289d 539 WAITING_PARAM_LEN,
mridup 0:309c845d289d 540 WAITING_DATA_LEN1,
mridup 0:309c845d289d 541 WAITING_DATA_LEN2,
mridup 0:309c845d289d 542 WAITING_PAYLOAD
mridup 0:309c845d289d 543 }hci_state;
mridup 0:309c845d289d 544
mridup 0:309c845d289d 545 typedef void (*hci_packet_complete_callback)(void *pckt, tHalUint16 len);
mridup 0:309c845d289d 546
mridup 0:309c845d289d 547 /* HCI library functions. */
mridup 0:309c845d289d 548 void hci_init(void);
mridup 0:309c845d289d 549
mridup 0:309c845d289d 550 int hci_send_req(struct hci_request *r);
mridup 0:309c845d289d 551
mridup 0:309c845d289d 552 #endif /* __HCI_INTERNAL_H_ */