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