NUCLEO-F401RE + BlueNRG shield client test (TI Sensortag reading)

Dependencies:   mbed-src

Committer:
ostapsky
Date:
Sat Aug 16 11:00:04 2014 +0000
Revision:
0:aa1e012ec210
CLIENT mode first revision

Who changed what in which revision?

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