ver:init
x-nucleo-idb0xa1/bluenrg-hci/ble_hci.h@0:4946262d6030, 2017-06-18 (annotated)
- Committer:
- iv123
- Date:
- Sun Jun 18 16:11:03 2017 +0000
- Revision:
- 0:4946262d6030
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iv123 | 0:4946262d6030 | 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** |
iv123 | 0:4946262d6030 | 2 | * File Name : hci.h |
iv123 | 0:4946262d6030 | 3 | * Author : AMS - HEA&RF BU |
iv123 | 0:4946262d6030 | 4 | * Version : V1.0.0 |
iv123 | 0:4946262d6030 | 5 | * Date : 19-July-2012 |
iv123 | 0:4946262d6030 | 6 | * Description : Constants and functions for HCI layer. See Bluetooth Core |
iv123 | 0:4946262d6030 | 7 | * v 4.0, Vol. 2, Part E. |
iv123 | 0:4946262d6030 | 8 | ******************************************************************************** |
iv123 | 0:4946262d6030 | 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
iv123 | 0:4946262d6030 | 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
iv123 | 0:4946262d6030 | 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
iv123 | 0:4946262d6030 | 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
iv123 | 0:4946262d6030 | 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
iv123 | 0:4946262d6030 | 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
iv123 | 0:4946262d6030 | 15 | *******************************************************************************/ |
iv123 | 0:4946262d6030 | 16 | |
iv123 | 0:4946262d6030 | 17 | #ifndef __HCI_H_ |
iv123 | 0:4946262d6030 | 18 | #define __HCI_H_ |
iv123 | 0:4946262d6030 | 19 | |
iv123 | 0:4946262d6030 | 20 | #include "ble_hal_types.h" |
iv123 | 0:4946262d6030 | 21 | #include "ble_link_layer.h" |
iv123 | 0:4946262d6030 | 22 | #include <ble_list.h> |
iv123 | 0:4946262d6030 | 23 | |
iv123 | 0:4946262d6030 | 24 | #define HCI_READ_PACKET_SIZE 128 //71 |
iv123 | 0:4946262d6030 | 25 | |
iv123 | 0:4946262d6030 | 26 | /*** Data types ***/ |
iv123 | 0:4946262d6030 | 27 | |
iv123 | 0:4946262d6030 | 28 | /* structure used to read received data */ |
iv123 | 0:4946262d6030 | 29 | typedef struct _tHciDataPacket |
iv123 | 0:4946262d6030 | 30 | { |
iv123 | 0:4946262d6030 | 31 | tListNode currentNode; |
iv123 | 0:4946262d6030 | 32 | uint8_t dataBuff[HCI_READ_PACKET_SIZE]; |
iv123 | 0:4946262d6030 | 33 | uint8_t data_len; |
iv123 | 0:4946262d6030 | 34 | } tHciDataPacket; |
iv123 | 0:4946262d6030 | 35 | |
iv123 | 0:4946262d6030 | 36 | typedef enum |
iv123 | 0:4946262d6030 | 37 | { |
iv123 | 0:4946262d6030 | 38 | BUSY, |
iv123 | 0:4946262d6030 | 39 | AVAILABLE |
iv123 | 0:4946262d6030 | 40 | } HCI_CMD_STATUS_t; |
iv123 | 0:4946262d6030 | 41 | |
iv123 | 0:4946262d6030 | 42 | /** |
iv123 | 0:4946262d6030 | 43 | * @defgroup HCI_Error_codes HCI Error codes |
iv123 | 0:4946262d6030 | 44 | * @{ |
iv123 | 0:4946262d6030 | 45 | */ |
iv123 | 0:4946262d6030 | 46 | #define HCI_UNKNOWN_COMMAND 0x01 |
iv123 | 0:4946262d6030 | 47 | #define HCI_NO_CONNECTION 0x02 |
iv123 | 0:4946262d6030 | 48 | #define HCI_HARDWARE_FAILURE 0x03 |
iv123 | 0:4946262d6030 | 49 | #define HCI_PAGE_TIMEOUT 0x04 |
iv123 | 0:4946262d6030 | 50 | #define HCI_AUTHENTICATION_FAILURE 0x05 |
iv123 | 0:4946262d6030 | 51 | #define HCI_PIN_OR_KEY_MISSING 0x06 |
iv123 | 0:4946262d6030 | 52 | #define HCI_MEMORY_FULL 0x07 |
iv123 | 0:4946262d6030 | 53 | #define HCI_CONNECTION_TIMEOUT 0x08 |
iv123 | 0:4946262d6030 | 54 | #define HCI_MAX_NUMBER_OF_CONNECTIONS 0x09 |
iv123 | 0:4946262d6030 | 55 | #define HCI_MAX_NUMBER_OF_SCO_CONNECTIONS 0x0a |
iv123 | 0:4946262d6030 | 56 | #define HCI_ACL_CONNECTION_EXISTS 0x0b |
iv123 | 0:4946262d6030 | 57 | #define HCI_COMMAND_DISALLOWED 0x0c |
iv123 | 0:4946262d6030 | 58 | #define HCI_REJECTED_LIMITED_RESOURCES 0x0d |
iv123 | 0:4946262d6030 | 59 | #define HCI_REJECTED_SECURITY 0x0e |
iv123 | 0:4946262d6030 | 60 | #define HCI_REJECTED_PERSONAL 0x0f |
iv123 | 0:4946262d6030 | 61 | #define HCI_HOST_TIMEOUT 0x10 |
iv123 | 0:4946262d6030 | 62 | #define HCI_UNSUPPORTED_FEATURE 0x11 |
iv123 | 0:4946262d6030 | 63 | #define HCI_INVALID_PARAMETERS 0x12 |
iv123 | 0:4946262d6030 | 64 | #define HCI_OE_USER_ENDED_CONNECTION 0x13 |
iv123 | 0:4946262d6030 | 65 | #define HCI_OE_LOW_RESOURCES 0x14 |
iv123 | 0:4946262d6030 | 66 | #define HCI_OE_POWER_OFF 0x15 |
iv123 | 0:4946262d6030 | 67 | #define HCI_CONNECTION_TERMINATED 0x16 |
iv123 | 0:4946262d6030 | 68 | #define HCI_REPEATED_ATTEMPTS 0x17 |
iv123 | 0:4946262d6030 | 69 | #define HCI_PAIRING_NOT_ALLOWED 0x18 |
iv123 | 0:4946262d6030 | 70 | #define HCI_UNKNOWN_LMP_PDU 0x19 |
iv123 | 0:4946262d6030 | 71 | #define HCI_UNSUPPORTED_REMOTE_FEATURE 0x1a |
iv123 | 0:4946262d6030 | 72 | #define HCI_SCO_OFFSET_REJECTED 0x1b |
iv123 | 0:4946262d6030 | 73 | #define HCI_SCO_INTERVAL_REJECTED 0x1c |
iv123 | 0:4946262d6030 | 74 | #define HCI_AIR_MODE_REJECTED 0x1d |
iv123 | 0:4946262d6030 | 75 | #define HCI_INVALID_LMP_PARAMETERS 0x1e |
iv123 | 0:4946262d6030 | 76 | #define HCI_UNSPECIFIED_ERROR 0x1f |
iv123 | 0:4946262d6030 | 77 | #define HCI_UNSUPPORTED_LMP_PARAMETER_VALUE 0x20 |
iv123 | 0:4946262d6030 | 78 | #define HCI_ROLE_CHANGE_NOT_ALLOWED 0x21 |
iv123 | 0:4946262d6030 | 79 | #define HCI_LMP_RESPONSE_TIMEOUT 0x22 |
iv123 | 0:4946262d6030 | 80 | #define HCI_LMP_ERROR_TRANSACTION_COLLISION 0x23 |
iv123 | 0:4946262d6030 | 81 | #define HCI_LMP_PDU_NOT_ALLOWED 0x24 |
iv123 | 0:4946262d6030 | 82 | #define HCI_ENCRYPTION_MODE_NOT_ACCEPTED 0x25 |
iv123 | 0:4946262d6030 | 83 | #define HCI_UNIT_LINK_KEY_USED 0x26 |
iv123 | 0:4946262d6030 | 84 | #define HCI_QOS_NOT_SUPPORTED 0x27 |
iv123 | 0:4946262d6030 | 85 | #define HCI_INSTANT_PASSED 0x28 |
iv123 | 0:4946262d6030 | 86 | #define HCI_PAIRING_NOT_SUPPORTED 0x29 |
iv123 | 0:4946262d6030 | 87 | #define HCI_TRANSACTION_COLLISION 0x2a |
iv123 | 0:4946262d6030 | 88 | #define HCI_QOS_UNACCEPTABLE_PARAMETER 0x2c |
iv123 | 0:4946262d6030 | 89 | #define HCI_QOS_REJECTED 0x2d |
iv123 | 0:4946262d6030 | 90 | #define HCI_CLASSIFICATION_NOT_SUPPORTED 0x2e |
iv123 | 0:4946262d6030 | 91 | #define HCI_INSUFFICIENT_SECURITY 0x2f |
iv123 | 0:4946262d6030 | 92 | #define HCI_PARAMETER_OUT_OF_RANGE 0x30 |
iv123 | 0:4946262d6030 | 93 | #define HCI_ROLE_SWITCH_PENDING 0x32 |
iv123 | 0:4946262d6030 | 94 | #define HCI_SLOT_VIOLATION 0x34 |
iv123 | 0:4946262d6030 | 95 | #define HCI_ROLE_SWITCH_FAILED 0x35 |
iv123 | 0:4946262d6030 | 96 | #define HCI_EIR_TOO_LARGE 0x36 |
iv123 | 0:4946262d6030 | 97 | #define HCI_SIMPLE_PAIRING_NOT_SUPPORTED 0x37 |
iv123 | 0:4946262d6030 | 98 | #define HCI_HOST_BUSY_PAIRING 0x38 |
iv123 | 0:4946262d6030 | 99 | #define HCI_CONN_REJ_NO_CH_FOUND 0x39 |
iv123 | 0:4946262d6030 | 100 | #define HCI_CONTROLLER_BUSY 0x3A |
iv123 | 0:4946262d6030 | 101 | #define HCI_UNACCEPTABLE_CONN_INTERV 0x3B |
iv123 | 0:4946262d6030 | 102 | #define HCI_DIRECTED_ADV_TIMEOUT 0x3C |
iv123 | 0:4946262d6030 | 103 | #define HCI_CONN_TERM_MIC_FAIL 0x3D |
iv123 | 0:4946262d6030 | 104 | #define HCI_CONN_FAIL_TO_BE_ESTABL 0x3E |
iv123 | 0:4946262d6030 | 105 | #define HCI_MAC_CONN_FAILED 0x3F |
iv123 | 0:4946262d6030 | 106 | /** |
iv123 | 0:4946262d6030 | 107 | * @} |
iv123 | 0:4946262d6030 | 108 | */ |
iv123 | 0:4946262d6030 | 109 | |
iv123 | 0:4946262d6030 | 110 | |
iv123 | 0:4946262d6030 | 111 | /* |
iv123 | 0:4946262d6030 | 112 | * HCI library functions. |
iv123 | 0:4946262d6030 | 113 | * Each function returns 0 in case of success, otherwise one of the error codes. |
iv123 | 0:4946262d6030 | 114 | */ |
iv123 | 0:4946262d6030 | 115 | |
iv123 | 0:4946262d6030 | 116 | int hci_reset(void); |
iv123 | 0:4946262d6030 | 117 | |
iv123 | 0:4946262d6030 | 118 | int hci_disconnect(uint16_t handle, uint8_t reason); |
iv123 | 0:4946262d6030 | 119 | |
iv123 | 0:4946262d6030 | 120 | int hci_le_set_advertise_enable(uint8_t enable); |
iv123 | 0:4946262d6030 | 121 | |
iv123 | 0:4946262d6030 | 122 | int hci_le_set_advertising_parameters(uint16_t min_interval, uint16_t max_interval, uint8_t advtype, |
iv123 | 0:4946262d6030 | 123 | uint8_t own_bdaddr_type, uint8_t direct_bdaddr_type, const tBDAddr direct_bdaddr, uint8_t chan_map, |
iv123 | 0:4946262d6030 | 124 | uint8_t filter); |
iv123 | 0:4946262d6030 | 125 | |
iv123 | 0:4946262d6030 | 126 | int hci_le_set_scan_parameters(uint8_t type, uint16_t interval, |
iv123 | 0:4946262d6030 | 127 | uint16_t window, uint8_t own_bdaddr_type, |
iv123 | 0:4946262d6030 | 128 | uint8_t filter); |
iv123 | 0:4946262d6030 | 129 | |
iv123 | 0:4946262d6030 | 130 | int hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dup); |
iv123 | 0:4946262d6030 | 131 | |
iv123 | 0:4946262d6030 | 132 | int hci_le_set_advertising_data(uint8_t length, const uint8_t data[]); |
iv123 | 0:4946262d6030 | 133 | |
iv123 | 0:4946262d6030 | 134 | int hci_le_set_scan_resp_data(uint8_t length, const uint8_t data[]); |
iv123 | 0:4946262d6030 | 135 | |
iv123 | 0:4946262d6030 | 136 | int hci_le_rand(uint8_t random_number[8]); |
iv123 | 0:4946262d6030 | 137 | |
iv123 | 0:4946262d6030 | 138 | int hci_le_read_advertising_channel_tx_power(int8_t *tx_power_level); |
iv123 | 0:4946262d6030 | 139 | |
iv123 | 0:4946262d6030 | 140 | int hci_acl_data(const uint8_t * data, uint16_t len); |
iv123 | 0:4946262d6030 | 141 | |
iv123 | 0:4946262d6030 | 142 | int hci_le_set_random_address(tBDAddr bdaddr); |
iv123 | 0:4946262d6030 | 143 | |
iv123 | 0:4946262d6030 | 144 | int hci_read_bd_addr(tBDAddr bdaddr); |
iv123 | 0:4946262d6030 | 145 | |
iv123 | 0:4946262d6030 | 146 | int hci_le_read_white_list_size(uint8_t *size); |
iv123 | 0:4946262d6030 | 147 | |
iv123 | 0:4946262d6030 | 148 | int hci_le_clear_white_list(void); |
iv123 | 0:4946262d6030 | 149 | |
iv123 | 0:4946262d6030 | 150 | int hci_le_add_device_to_white_list(uint8_t bdaddr_type, tBDAddr bdaddr); |
iv123 | 0:4946262d6030 | 151 | |
iv123 | 0:4946262d6030 | 152 | int hci_le_remove_device_from_white_list(uint8_t bdaddr_type, tBDAddr bdaddr); |
iv123 | 0:4946262d6030 | 153 | |
iv123 | 0:4946262d6030 | 154 | int hci_le_encrypt(uint8_t key[16], uint8_t plaintextData[16], uint8_t encryptedData[16]); |
iv123 | 0:4946262d6030 | 155 | |
iv123 | 0:4946262d6030 | 156 | int hci_le_ltk_request_reply(uint8_t key[16]); |
iv123 | 0:4946262d6030 | 157 | |
iv123 | 0:4946262d6030 | 158 | int hci_le_ltk_request_neg_reply(void); |
iv123 | 0:4946262d6030 | 159 | |
iv123 | 0:4946262d6030 | 160 | int hci_le_read_buffer_size(uint16_t *pkt_len, uint8_t *max_pkt); |
iv123 | 0:4946262d6030 | 161 | |
iv123 | 0:4946262d6030 | 162 | int hci_le_create_connection(uint16_t interval, uint16_t window, uint8_t initiator_filter, uint8_t peer_bdaddr_type, |
iv123 | 0:4946262d6030 | 163 | const tBDAddr peer_bdaddr, uint8_t own_bdaddr_type, uint16_t min_interval, uint16_t max_interval, |
iv123 | 0:4946262d6030 | 164 | uint16_t latency, uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length); |
iv123 | 0:4946262d6030 | 165 | |
iv123 | 0:4946262d6030 | 166 | int hci_le_create_connection_cancel(void); |
iv123 | 0:4946262d6030 | 167 | |
iv123 | 0:4946262d6030 | 168 | int hci_read_transmit_power_level(uint16_t *conn_handle, uint8_t type, int8_t *tx_level); |
iv123 | 0:4946262d6030 | 169 | |
iv123 | 0:4946262d6030 | 170 | int hci_read_rssi(uint16_t *conn_handle, int8_t *rssi); |
iv123 | 0:4946262d6030 | 171 | |
iv123 | 0:4946262d6030 | 172 | int hci_le_read_local_supported_features(uint8_t *features); |
iv123 | 0:4946262d6030 | 173 | |
iv123 | 0:4946262d6030 | 174 | int hci_le_read_channel_map(uint16_t conn_handle, uint8_t ch_map[5]); |
iv123 | 0:4946262d6030 | 175 | |
iv123 | 0:4946262d6030 | 176 | int hci_le_read_supported_states(uint8_t states[8]); |
iv123 | 0:4946262d6030 | 177 | |
iv123 | 0:4946262d6030 | 178 | int hci_le_receiver_test(uint8_t frequency); |
iv123 | 0:4946262d6030 | 179 | |
iv123 | 0:4946262d6030 | 180 | int hci_le_transmitter_test(uint8_t frequency, uint8_t length, uint8_t payload); |
iv123 | 0:4946262d6030 | 181 | |
iv123 | 0:4946262d6030 | 182 | int hci_le_test_end(uint16_t *num_pkts); |
iv123 | 0:4946262d6030 | 183 | |
iv123 | 0:4946262d6030 | 184 | int hci_le_read_local_version(uint8_t *hci_version, uint16_t *hci_revision, uint8_t *lmp_pal_version, |
iv123 | 0:4946262d6030 | 185 | uint16_t *manufacturer_name, uint16_t *lmp_pal_subversion); |
iv123 | 0:4946262d6030 | 186 | |
iv123 | 0:4946262d6030 | 187 | /** |
iv123 | 0:4946262d6030 | 188 | * This function must be used to pass the packet received from the HCI |
iv123 | 0:4946262d6030 | 189 | * interface to the BLE Stack HCI state machine. |
iv123 | 0:4946262d6030 | 190 | * |
iv123 | 0:4946262d6030 | 191 | * @param[in] hciReadPacket The packet that is received from HCI interface. |
iv123 | 0:4946262d6030 | 192 | * |
iv123 | 0:4946262d6030 | 193 | */ |
iv123 | 0:4946262d6030 | 194 | void HCI_Input(tHciDataPacket *hciReadPacket); |
iv123 | 0:4946262d6030 | 195 | |
iv123 | 0:4946262d6030 | 196 | /** |
iv123 | 0:4946262d6030 | 197 | * Initialization function. Must be done before any data can be received from |
iv123 | 0:4946262d6030 | 198 | * BLE controller. |
iv123 | 0:4946262d6030 | 199 | */ |
iv123 | 0:4946262d6030 | 200 | void HCI_Init(void); |
iv123 | 0:4946262d6030 | 201 | |
iv123 | 0:4946262d6030 | 202 | /** |
iv123 | 0:4946262d6030 | 203 | * Callback used to pass events to application. |
iv123 | 0:4946262d6030 | 204 | * |
iv123 | 0:4946262d6030 | 205 | * @param[in] pckt The event. |
iv123 | 0:4946262d6030 | 206 | * |
iv123 | 0:4946262d6030 | 207 | */ |
iv123 | 0:4946262d6030 | 208 | extern void HCI_Event_CB(void *pckt); |
iv123 | 0:4946262d6030 | 209 | |
iv123 | 0:4946262d6030 | 210 | /** |
iv123 | 0:4946262d6030 | 211 | * Processing function that must be called after an event is received from |
iv123 | 0:4946262d6030 | 212 | * HCI interface. Must be called outside ISR. It will call HCI_Event_CB if |
iv123 | 0:4946262d6030 | 213 | * necessary. |
iv123 | 0:4946262d6030 | 214 | */ |
iv123 | 0:4946262d6030 | 215 | void HCI_Process(void); |
iv123 | 0:4946262d6030 | 216 | |
iv123 | 0:4946262d6030 | 217 | /** |
iv123 | 0:4946262d6030 | 218 | * @brief Check if queue of HCI event is empty or not. |
iv123 | 0:4946262d6030 | 219 | * @note This funtion can be used to check if the event queue from BlueNRG is empty. This |
iv123 | 0:4946262d6030 | 220 | * is useful when checking if it is safe to go to sleep. |
iv123 | 0:4946262d6030 | 221 | * @return TRUE if event queue is empty. FALSE otherwhise. |
iv123 | 0:4946262d6030 | 222 | */ |
iv123 | 0:4946262d6030 | 223 | BOOL HCI_Queue_Empty(void); |
iv123 | 0:4946262d6030 | 224 | /** |
iv123 | 0:4946262d6030 | 225 | * Iterrupt service routine that must be called when the BlueNRG |
iv123 | 0:4946262d6030 | 226 | * reports a packet received or an event to the host through the |
iv123 | 0:4946262d6030 | 227 | * BlueNRG interrupt line. |
iv123 | 0:4946262d6030 | 228 | */ |
iv123 | 0:4946262d6030 | 229 | #ifdef __DMA_LP__ |
iv123 | 0:4946262d6030 | 230 | void HCI_Isr(uint8_t *buffer, uint8_t event_payload_len); |
iv123 | 0:4946262d6030 | 231 | void HCI_Process_Notification_Request(void); |
iv123 | 0:4946262d6030 | 232 | void HCI_Cmd_Status(HCI_CMD_STATUS_t Hci_Cmd_Status); |
iv123 | 0:4946262d6030 | 233 | void HCI_Wait_For_Response(void); |
iv123 | 0:4946262d6030 | 234 | #else |
iv123 | 0:4946262d6030 | 235 | void HCI_Isr(void); |
iv123 | 0:4946262d6030 | 236 | #endif /* __DMA_LP__ */ |
iv123 | 0:4946262d6030 | 237 | |
iv123 | 0:4946262d6030 | 238 | extern tListNode hciReadPktPool; |
iv123 | 0:4946262d6030 | 239 | extern tListNode hciReadPktRxQueue; |
iv123 | 0:4946262d6030 | 240 | |
iv123 | 0:4946262d6030 | 241 | #endif /* __HCI_H_ */ |