mbed base bard check program for BlueTooth USB dongle module (3 switches, 6 leds, I2C LCD, A/D)
Fork of BTstack by
BTstack/hci.h@3:7b7d1273e2d5, 2016-10-17 (annotated)
- Committer:
- tamaki
- Date:
- Mon Oct 17 00:25:18 2016 +0000
- Revision:
- 3:7b7d1273e2d5
- Parent:
- 0:1ed23ab1345f
mbed base bard check program
; for BlueTooth USB dongle module
; (3 switches, 6 leds, I2C LCD, A/D)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:1ed23ab1345f | 1 | /* |
va009039 | 0:1ed23ab1345f | 2 | * Copyright (C) 2009-2012 by Matthias Ringwald |
va009039 | 0:1ed23ab1345f | 3 | * |
va009039 | 0:1ed23ab1345f | 4 | * Redistribution and use in source and binary forms, with or without |
va009039 | 0:1ed23ab1345f | 5 | * modification, are permitted provided that the following conditions |
va009039 | 0:1ed23ab1345f | 6 | * are met: |
va009039 | 0:1ed23ab1345f | 7 | * |
va009039 | 0:1ed23ab1345f | 8 | * 1. Redistributions of source code must retain the above copyright |
va009039 | 0:1ed23ab1345f | 9 | * notice, this list of conditions and the following disclaimer. |
va009039 | 0:1ed23ab1345f | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
va009039 | 0:1ed23ab1345f | 11 | * notice, this list of conditions and the following disclaimer in the |
va009039 | 0:1ed23ab1345f | 12 | * documentation and/or other materials provided with the distribution. |
va009039 | 0:1ed23ab1345f | 13 | * 3. Neither the name of the copyright holders nor the names of |
va009039 | 0:1ed23ab1345f | 14 | * contributors may be used to endorse or promote products derived |
va009039 | 0:1ed23ab1345f | 15 | * from this software without specific prior written permission. |
va009039 | 0:1ed23ab1345f | 16 | * 4. Any redistribution, use, or modification is done solely for |
va009039 | 0:1ed23ab1345f | 17 | * personal benefit and not for any commercial purpose or for |
va009039 | 0:1ed23ab1345f | 18 | * monetary gain. |
va009039 | 0:1ed23ab1345f | 19 | * |
va009039 | 0:1ed23ab1345f | 20 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS |
va009039 | 0:1ed23ab1345f | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
va009039 | 0:1ed23ab1345f | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
va009039 | 0:1ed23ab1345f | 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS |
va009039 | 0:1ed23ab1345f | 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
va009039 | 0:1ed23ab1345f | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
va009039 | 0:1ed23ab1345f | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
va009039 | 0:1ed23ab1345f | 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
va009039 | 0:1ed23ab1345f | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
va009039 | 0:1ed23ab1345f | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
va009039 | 0:1ed23ab1345f | 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
va009039 | 0:1ed23ab1345f | 31 | * SUCH DAMAGE. |
va009039 | 0:1ed23ab1345f | 32 | * |
va009039 | 0:1ed23ab1345f | 33 | * Please inquire about commercial licensing options at btstack@ringwald.ch |
va009039 | 0:1ed23ab1345f | 34 | * |
va009039 | 0:1ed23ab1345f | 35 | */ |
va009039 | 0:1ed23ab1345f | 36 | |
va009039 | 0:1ed23ab1345f | 37 | /* |
va009039 | 0:1ed23ab1345f | 38 | * hci.h |
va009039 | 0:1ed23ab1345f | 39 | * |
va009039 | 0:1ed23ab1345f | 40 | * Created by Matthias Ringwald on 4/29/09. |
va009039 | 0:1ed23ab1345f | 41 | * |
va009039 | 0:1ed23ab1345f | 42 | */ |
va009039 | 0:1ed23ab1345f | 43 | |
va009039 | 0:1ed23ab1345f | 44 | #pragma once |
va009039 | 0:1ed23ab1345f | 45 | |
va009039 | 0:1ed23ab1345f | 46 | #include "config.h" |
va009039 | 0:1ed23ab1345f | 47 | |
va009039 | 0:1ed23ab1345f | 48 | #include <btstack/hci_cmds.h> |
va009039 | 0:1ed23ab1345f | 49 | #include <btstack/utils.h> |
va009039 | 0:1ed23ab1345f | 50 | #include "hci_transport.h" |
va009039 | 0:1ed23ab1345f | 51 | #include "bt_control.h" |
va009039 | 0:1ed23ab1345f | 52 | #include "remote_device_db.h" |
va009039 | 0:1ed23ab1345f | 53 | |
va009039 | 0:1ed23ab1345f | 54 | #include <stdint.h> |
va009039 | 0:1ed23ab1345f | 55 | #include <stdlib.h> |
va009039 | 0:1ed23ab1345f | 56 | #include <stdarg.h> |
va009039 | 0:1ed23ab1345f | 57 | |
va009039 | 0:1ed23ab1345f | 58 | #if defined __cplusplus |
va009039 | 0:1ed23ab1345f | 59 | extern "C" { |
va009039 | 0:1ed23ab1345f | 60 | #endif |
va009039 | 0:1ed23ab1345f | 61 | |
va009039 | 0:1ed23ab1345f | 62 | // packet header sizes |
va009039 | 0:1ed23ab1345f | 63 | #define HCI_CMD_HEADER_SIZE 3 |
va009039 | 0:1ed23ab1345f | 64 | #define HCI_ACL_HEADER_SIZE 4 |
va009039 | 0:1ed23ab1345f | 65 | #define HCI_SCO_HEADER_SIZE 3 |
va009039 | 0:1ed23ab1345f | 66 | #define HCI_EVENT_HEADER_SIZE 2 |
va009039 | 0:1ed23ab1345f | 67 | |
va009039 | 0:1ed23ab1345f | 68 | // packet sizes (max payload) |
va009039 | 0:1ed23ab1345f | 69 | #define HCI_ACL_DM1_SIZE 17 |
va009039 | 0:1ed23ab1345f | 70 | #define HCI_ACL_DH1_SIZE 27 |
va009039 | 0:1ed23ab1345f | 71 | #define HCI_ACL_2DH1_SIZE 54 |
va009039 | 0:1ed23ab1345f | 72 | #define HCI_ACL_3DH1_SIZE 83 |
va009039 | 0:1ed23ab1345f | 73 | #define HCI_ACL_DM3_SIZE 121 |
va009039 | 0:1ed23ab1345f | 74 | #define HCI_ACL_DH3_SIZE 183 |
va009039 | 0:1ed23ab1345f | 75 | #define HCI_ACL_DM5_SIZE 224 |
va009039 | 0:1ed23ab1345f | 76 | #define HCI_ACL_DH5_SIZE 339 |
va009039 | 0:1ed23ab1345f | 77 | #define HCI_ACL_2DH3_SIZE 367 |
va009039 | 0:1ed23ab1345f | 78 | #define HCI_ACL_3DH3_SIZE 552 |
va009039 | 0:1ed23ab1345f | 79 | #define HCI_ACL_2DH5_SIZE 679 |
va009039 | 0:1ed23ab1345f | 80 | #define HCI_ACL_3DH5_SIZE 1021 |
va009039 | 0:1ed23ab1345f | 81 | |
va009039 | 0:1ed23ab1345f | 82 | #define HCI_EVENT_PAYLOAD_SIZE 255 |
va009039 | 0:1ed23ab1345f | 83 | #define HCI_CMD_PAYLOAD_SIZE 255 |
va009039 | 0:1ed23ab1345f | 84 | |
va009039 | 0:1ed23ab1345f | 85 | // packet buffer sizes |
va009039 | 0:1ed23ab1345f | 86 | // HCI_ACL_PAYLOAD_SIZE is configurable and defined in config.h |
va009039 | 0:1ed23ab1345f | 87 | #define HCI_EVENT_BUFFER_SIZE (HCI_EVENT_HEADER_SIZE + HCI_EVENT_PAYLOAD_SIZE) |
va009039 | 0:1ed23ab1345f | 88 | #define HCI_CMD_BUFFER_SIZE (HCI_CMD_HEADER_SIZE + HCI_CMD_PAYLOAD_SIZE) |
va009039 | 0:1ed23ab1345f | 89 | #define HCI_ACL_BUFFER_SIZE (HCI_ACL_HEADER_SIZE + HCI_ACL_PAYLOAD_SIZE) |
va009039 | 0:1ed23ab1345f | 90 | |
va009039 | 0:1ed23ab1345f | 91 | // size of hci buffers, big enough for command, event, or acl packet without H4 packet type |
va009039 | 0:1ed23ab1345f | 92 | // @note cmd buffer is bigger than event buffer |
va009039 | 0:1ed23ab1345f | 93 | #if HCI_ACL_BUFFER_SIZE > HCI_CMD_BUFFER_SIZE |
va009039 | 0:1ed23ab1345f | 94 | #define HCI_PACKET_BUFFER_SIZE HCI_ACL_BUFFER_SIZE |
va009039 | 0:1ed23ab1345f | 95 | #else |
va009039 | 0:1ed23ab1345f | 96 | #define HCI_PACKET_BUFFER_SIZE HCI_CMD_BUFFER_SIZE |
va009039 | 0:1ed23ab1345f | 97 | #endif |
va009039 | 0:1ed23ab1345f | 98 | |
va009039 | 0:1ed23ab1345f | 99 | // OGFs |
va009039 | 0:1ed23ab1345f | 100 | #define OGF_LINK_CONTROL 0x01 |
va009039 | 0:1ed23ab1345f | 101 | #define OGF_LINK_POLICY 0x02 |
va009039 | 0:1ed23ab1345f | 102 | #define OGF_CONTROLLER_BASEBAND 0x03 |
va009039 | 0:1ed23ab1345f | 103 | #define OGF_INFORMATIONAL_PARAMETERS 0x04 |
va009039 | 0:1ed23ab1345f | 104 | #define OGF_LE_CONTROLLER 0x08 |
va009039 | 0:1ed23ab1345f | 105 | #define OGF_BTSTACK 0x3d |
va009039 | 0:1ed23ab1345f | 106 | #define OGF_VENDOR 0x3f |
va009039 | 0:1ed23ab1345f | 107 | |
va009039 | 0:1ed23ab1345f | 108 | // cmds for BTstack |
va009039 | 0:1ed23ab1345f | 109 | // get state: @returns HCI_STATE |
va009039 | 0:1ed23ab1345f | 110 | #define BTSTACK_GET_STATE 0x01 |
va009039 | 0:1ed23ab1345f | 111 | |
va009039 | 0:1ed23ab1345f | 112 | // set power mode: @param HCI_POWER_MODE |
va009039 | 0:1ed23ab1345f | 113 | #define BTSTACK_SET_POWER_MODE 0x02 |
va009039 | 0:1ed23ab1345f | 114 | |
va009039 | 0:1ed23ab1345f | 115 | // set capture mode: @param on |
va009039 | 0:1ed23ab1345f | 116 | #define BTSTACK_SET_ACL_CAPTURE_MODE 0x03 |
va009039 | 0:1ed23ab1345f | 117 | |
va009039 | 0:1ed23ab1345f | 118 | // get BTstack version |
va009039 | 0:1ed23ab1345f | 119 | #define BTSTACK_GET_VERSION 0x04 |
va009039 | 0:1ed23ab1345f | 120 | |
va009039 | 0:1ed23ab1345f | 121 | // get system Bluetooth state |
va009039 | 0:1ed23ab1345f | 122 | #define BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED 0x05 |
va009039 | 0:1ed23ab1345f | 123 | |
va009039 | 0:1ed23ab1345f | 124 | // set system Bluetooth state |
va009039 | 0:1ed23ab1345f | 125 | #define BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED 0x06 |
va009039 | 0:1ed23ab1345f | 126 | |
va009039 | 0:1ed23ab1345f | 127 | // enable inquiry scan for this client |
va009039 | 0:1ed23ab1345f | 128 | #define BTSTACK_SET_DISCOVERABLE 0x07 |
va009039 | 0:1ed23ab1345f | 129 | |
va009039 | 0:1ed23ab1345f | 130 | // set global Bluetooth state |
va009039 | 0:1ed23ab1345f | 131 | #define BTSTACK_SET_BLUETOOTH_ENABLED 0x08 |
va009039 | 0:1ed23ab1345f | 132 | |
va009039 | 0:1ed23ab1345f | 133 | // create l2cap channel: @param bd_addr(48), psm (16) |
va009039 | 0:1ed23ab1345f | 134 | #define L2CAP_CREATE_CHANNEL 0x20 |
va009039 | 0:1ed23ab1345f | 135 | |
va009039 | 0:1ed23ab1345f | 136 | // disconnect l2cap disconnect, @param channel(16), reason(8) |
va009039 | 0:1ed23ab1345f | 137 | #define L2CAP_DISCONNECT 0x21 |
va009039 | 0:1ed23ab1345f | 138 | |
va009039 | 0:1ed23ab1345f | 139 | // register l2cap service: @param psm(16), mtu (16) |
va009039 | 0:1ed23ab1345f | 140 | #define L2CAP_REGISTER_SERVICE 0x22 |
va009039 | 0:1ed23ab1345f | 141 | |
va009039 | 0:1ed23ab1345f | 142 | // unregister l2cap disconnect, @param psm(16) |
va009039 | 0:1ed23ab1345f | 143 | #define L2CAP_UNREGISTER_SERVICE 0x23 |
va009039 | 0:1ed23ab1345f | 144 | |
va009039 | 0:1ed23ab1345f | 145 | // accept connection @param bd_addr(48), dest cid (16) |
va009039 | 0:1ed23ab1345f | 146 | #define L2CAP_ACCEPT_CONNECTION 0x24 |
va009039 | 0:1ed23ab1345f | 147 | |
va009039 | 0:1ed23ab1345f | 148 | // decline l2cap disconnect,@param bd_addr(48), dest cid (16), reason(8) |
va009039 | 0:1ed23ab1345f | 149 | #define L2CAP_DECLINE_CONNECTION 0x25 |
va009039 | 0:1ed23ab1345f | 150 | |
va009039 | 0:1ed23ab1345f | 151 | // create l2cap channel: @param bd_addr(48), psm (16), mtu (16) |
va009039 | 0:1ed23ab1345f | 152 | #define L2CAP_CREATE_CHANNEL_MTU 0x26 |
va009039 | 0:1ed23ab1345f | 153 | |
va009039 | 0:1ed23ab1345f | 154 | // register SDP Service Record: service record (size) |
va009039 | 0:1ed23ab1345f | 155 | #define SDP_REGISTER_SERVICE_RECORD 0x30 |
va009039 | 0:1ed23ab1345f | 156 | |
va009039 | 0:1ed23ab1345f | 157 | // unregister SDP Service Record |
va009039 | 0:1ed23ab1345f | 158 | #define SDP_UNREGISTER_SERVICE_RECORD 0x31 |
va009039 | 0:1ed23ab1345f | 159 | |
va009039 | 0:1ed23ab1345f | 160 | // RFCOMM "HCI" Commands |
va009039 | 0:1ed23ab1345f | 161 | #define RFCOMM_CREATE_CHANNEL 0x40 |
va009039 | 0:1ed23ab1345f | 162 | #define RFCOMM_DISCONNECT 0x41 |
va009039 | 0:1ed23ab1345f | 163 | #define RFCOMM_REGISTER_SERVICE 0x42 |
va009039 | 0:1ed23ab1345f | 164 | #define RFCOMM_UNREGISTER_SERVICE 0x43 |
va009039 | 0:1ed23ab1345f | 165 | #define RFCOMM_ACCEPT_CONNECTION 0x44 |
va009039 | 0:1ed23ab1345f | 166 | #define RFCOMM_DECLINE_CONNECTION 0x45 |
va009039 | 0:1ed23ab1345f | 167 | #define RFCOMM_PERSISTENT_CHANNEL 0x46 |
va009039 | 0:1ed23ab1345f | 168 | #define RFCOMM_CREATE_CHANNEL_WITH_CREDITS 0x47 |
va009039 | 0:1ed23ab1345f | 169 | #define RFCOMM_REGISTER_SERVICE_WITH_CREDITS 0x48 |
va009039 | 0:1ed23ab1345f | 170 | #define RFCOMM_GRANT_CREDITS 0x49 |
va009039 | 0:1ed23ab1345f | 171 | |
va009039 | 0:1ed23ab1345f | 172 | // |
va009039 | 0:1ed23ab1345f | 173 | #define IS_COMMAND(packet, command) (READ_BT_16(packet,0) == command.opcode) |
va009039 | 0:1ed23ab1345f | 174 | |
va009039 | 0:1ed23ab1345f | 175 | // data: event(8) |
va009039 | 0:1ed23ab1345f | 176 | #define DAEMON_EVENT_CONNECTION_OPENED 0x50 |
va009039 | 0:1ed23ab1345f | 177 | |
va009039 | 0:1ed23ab1345f | 178 | // data: event(8) |
va009039 | 0:1ed23ab1345f | 179 | #define DAEMON_EVENT_CONNECTION_CLOSED 0x51 |
va009039 | 0:1ed23ab1345f | 180 | |
va009039 | 0:1ed23ab1345f | 181 | // data: event(8), nr_connections(8) |
va009039 | 0:1ed23ab1345f | 182 | #define DAEMON_NR_CONNECTIONS_CHANGED 0x52 |
va009039 | 0:1ed23ab1345f | 183 | |
va009039 | 0:1ed23ab1345f | 184 | // data: event(8) |
va009039 | 0:1ed23ab1345f | 185 | #define DAEMON_EVENT_NEW_RFCOMM_CREDITS 0x53 |
va009039 | 0:1ed23ab1345f | 186 | |
va009039 | 0:1ed23ab1345f | 187 | // data: event() |
va009039 | 0:1ed23ab1345f | 188 | #define DAEMON_EVENT_HCI_PACKET_SENT 0x54 |
va009039 | 0:1ed23ab1345f | 189 | |
va009039 | 0:1ed23ab1345f | 190 | /** |
va009039 | 0:1ed23ab1345f | 191 | * Connection State |
va009039 | 0:1ed23ab1345f | 192 | */ |
va009039 | 0:1ed23ab1345f | 193 | typedef enum { |
va009039 | 0:1ed23ab1345f | 194 | AUTH_FLAGS_NONE = 0x00, |
va009039 | 0:1ed23ab1345f | 195 | RECV_LINK_KEY_REQUEST = 0x01, |
va009039 | 0:1ed23ab1345f | 196 | HANDLE_LINK_KEY_REQUEST = 0x02, |
va009039 | 0:1ed23ab1345f | 197 | SENT_LINK_KEY_REPLY = 0x04, |
va009039 | 0:1ed23ab1345f | 198 | SENT_LINK_KEY_NEGATIVE_REQUEST = 0x08, |
va009039 | 0:1ed23ab1345f | 199 | RECV_LINK_KEY_NOTIFICATION = 0x10, |
va009039 | 0:1ed23ab1345f | 200 | RECV_PIN_CODE_REQUEST = 0x20, |
va009039 | 0:1ed23ab1345f | 201 | SENT_PIN_CODE_REPLY = 0x40, |
va009039 | 0:1ed23ab1345f | 202 | SENT_PIN_CODE_NEGATIVE_REPLY = 0x80 |
va009039 | 0:1ed23ab1345f | 203 | } hci_authentication_flags_t; |
va009039 | 0:1ed23ab1345f | 204 | |
va009039 | 0:1ed23ab1345f | 205 | typedef enum { |
va009039 | 0:1ed23ab1345f | 206 | SENT_CREATE_CONNECTION = 1, |
va009039 | 0:1ed23ab1345f | 207 | RECEIVED_CONNECTION_REQUEST, |
va009039 | 0:1ed23ab1345f | 208 | ACCEPTED_CONNECTION_REQUEST, |
va009039 | 0:1ed23ab1345f | 209 | REJECTED_CONNECTION_REQUEST, |
va009039 | 0:1ed23ab1345f | 210 | OPEN, |
va009039 | 0:1ed23ab1345f | 211 | SENT_DISCONNECT |
va009039 | 0:1ed23ab1345f | 212 | } CONNECTION_STATE; |
va009039 | 0:1ed23ab1345f | 213 | |
va009039 | 0:1ed23ab1345f | 214 | typedef enum { |
va009039 | 0:1ed23ab1345f | 215 | BLUETOOTH_OFF = 1, |
va009039 | 0:1ed23ab1345f | 216 | BLUETOOTH_ON, |
va009039 | 0:1ed23ab1345f | 217 | BLUETOOTH_ACTIVE |
va009039 | 0:1ed23ab1345f | 218 | } BLUETOOTH_STATE; |
va009039 | 0:1ed23ab1345f | 219 | |
va009039 | 0:1ed23ab1345f | 220 | typedef struct { |
va009039 | 0:1ed23ab1345f | 221 | // linked list - assert: first field |
va009039 | 0:1ed23ab1345f | 222 | linked_item_t item; |
va009039 | 0:1ed23ab1345f | 223 | |
va009039 | 0:1ed23ab1345f | 224 | // remote side |
va009039 | 0:1ed23ab1345f | 225 | bd_addr_t address; |
va009039 | 0:1ed23ab1345f | 226 | |
va009039 | 0:1ed23ab1345f | 227 | // module handle |
va009039 | 0:1ed23ab1345f | 228 | hci_con_handle_t con_handle; |
va009039 | 0:1ed23ab1345f | 229 | |
va009039 | 0:1ed23ab1345f | 230 | // state |
va009039 | 0:1ed23ab1345f | 231 | CONNECTION_STATE state; |
va009039 | 0:1ed23ab1345f | 232 | |
va009039 | 0:1ed23ab1345f | 233 | // errands |
va009039 | 0:1ed23ab1345f | 234 | hci_authentication_flags_t authentication_flags; |
va009039 | 0:1ed23ab1345f | 235 | |
va009039 | 0:1ed23ab1345f | 236 | timer_source_t timeout; |
va009039 | 0:1ed23ab1345f | 237 | |
va009039 | 0:1ed23ab1345f | 238 | #ifdef HAVE_TIME |
va009039 | 0:1ed23ab1345f | 239 | // timer |
va009039 | 0:1ed23ab1345f | 240 | struct timeval timestamp; |
va009039 | 0:1ed23ab1345f | 241 | #endif |
va009039 | 0:1ed23ab1345f | 242 | #ifdef HAVE_TICK |
va009039 | 0:1ed23ab1345f | 243 | uint32_t timestamp; // timeout in system ticks |
va009039 | 0:1ed23ab1345f | 244 | #endif |
va009039 | 0:1ed23ab1345f | 245 | |
va009039 | 0:1ed23ab1345f | 246 | // ACL packet recombination - ACL Header + ACL payload |
va009039 | 0:1ed23ab1345f | 247 | uint8_t acl_recombination_buffer[4 + HCI_ACL_BUFFER_SIZE]; |
va009039 | 0:1ed23ab1345f | 248 | uint16_t acl_recombination_pos; |
va009039 | 0:1ed23ab1345f | 249 | uint16_t acl_recombination_length; |
va009039 | 0:1ed23ab1345f | 250 | |
va009039 | 0:1ed23ab1345f | 251 | // number ACL packets sent to controller |
va009039 | 0:1ed23ab1345f | 252 | uint8_t num_acl_packets_sent; |
va009039 | 0:1ed23ab1345f | 253 | |
va009039 | 0:1ed23ab1345f | 254 | } hci_connection_t; |
va009039 | 0:1ed23ab1345f | 255 | |
va009039 | 0:1ed23ab1345f | 256 | /** |
va009039 | 0:1ed23ab1345f | 257 | * main data structure |
va009039 | 0:1ed23ab1345f | 258 | */ |
va009039 | 0:1ed23ab1345f | 259 | typedef struct { |
va009039 | 0:1ed23ab1345f | 260 | // transport component with configuration |
va009039 | 0:1ed23ab1345f | 261 | hci_transport_t * hci_transport; |
va009039 | 0:1ed23ab1345f | 262 | void * config; |
va009039 | 0:1ed23ab1345f | 263 | |
va009039 | 0:1ed23ab1345f | 264 | // hardware power controller |
va009039 | 0:1ed23ab1345f | 265 | bt_control_t * control; |
va009039 | 0:1ed23ab1345f | 266 | |
va009039 | 0:1ed23ab1345f | 267 | // list of existing baseband connections |
va009039 | 0:1ed23ab1345f | 268 | linked_list_t connections; |
va009039 | 0:1ed23ab1345f | 269 | |
va009039 | 0:1ed23ab1345f | 270 | // single buffer for HCI Command assembly |
va009039 | 0:1ed23ab1345f | 271 | uint8_t hci_packet_buffer[HCI_PACKET_BUFFER_SIZE]; // opcode (16), len(8) |
va009039 | 0:1ed23ab1345f | 272 | |
va009039 | 0:1ed23ab1345f | 273 | /* host to controller flow control */ |
va009039 | 0:1ed23ab1345f | 274 | uint8_t num_cmd_packets; |
va009039 | 0:1ed23ab1345f | 275 | // uint8_t total_num_cmd_packets; |
va009039 | 0:1ed23ab1345f | 276 | uint8_t total_num_acl_packets; |
va009039 | 0:1ed23ab1345f | 277 | uint16_t acl_data_packet_length; |
va009039 | 0:1ed23ab1345f | 278 | |
va009039 | 0:1ed23ab1345f | 279 | // usable packet types given acl_data_packet_length and HCI_ACL_BUFFER_SIZE |
va009039 | 0:1ed23ab1345f | 280 | uint16_t packet_types; |
va009039 | 0:1ed23ab1345f | 281 | |
va009039 | 0:1ed23ab1345f | 282 | /* callback to L2CAP layer */ |
va009039 | 0:1ed23ab1345f | 283 | void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size); |
va009039 | 0:1ed23ab1345f | 284 | |
va009039 | 0:1ed23ab1345f | 285 | /* remote device db */ |
va009039 | 0:1ed23ab1345f | 286 | remote_device_db_t const*remote_device_db; |
va009039 | 0:1ed23ab1345f | 287 | |
va009039 | 0:1ed23ab1345f | 288 | /* hci state machine */ |
va009039 | 0:1ed23ab1345f | 289 | HCI_STATE state; |
va009039 | 0:1ed23ab1345f | 290 | uint8_t substate; |
va009039 | 0:1ed23ab1345f | 291 | uint8_t cmds_ready; |
va009039 | 0:1ed23ab1345f | 292 | |
va009039 | 0:1ed23ab1345f | 293 | uint8_t discoverable; |
va009039 | 0:1ed23ab1345f | 294 | uint8_t connectable; |
va009039 | 0:1ed23ab1345f | 295 | |
va009039 | 0:1ed23ab1345f | 296 | /* buffer for scan enable cmd - 0xff no change */ |
va009039 | 0:1ed23ab1345f | 297 | uint8_t new_scan_enable_value; |
va009039 | 0:1ed23ab1345f | 298 | |
va009039 | 0:1ed23ab1345f | 299 | // buffer for single connection decline |
va009039 | 0:1ed23ab1345f | 300 | uint8_t decline_reason; |
va009039 | 0:1ed23ab1345f | 301 | bd_addr_t decline_addr; |
va009039 | 0:1ed23ab1345f | 302 | |
va009039 | 0:1ed23ab1345f | 303 | } hci_stack_t; |
va009039 | 0:1ed23ab1345f | 304 | |
va009039 | 0:1ed23ab1345f | 305 | // create and send hci command packets based on a template and a list of parameters |
va009039 | 0:1ed23ab1345f | 306 | uint16_t hci_create_cmd(uint8_t *hci_cmd_buffer, hci_cmd_t *cmd, ...); |
va009039 | 0:1ed23ab1345f | 307 | uint16_t hci_create_cmd_internal(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr); |
va009039 | 0:1ed23ab1345f | 308 | |
va009039 | 0:1ed23ab1345f | 309 | // set up HCI |
va009039 | 0:1ed23ab1345f | 310 | void hci_init(hci_transport_t *transport, void *config, bt_control_t *control, remote_device_db_t const* remote_device_db); |
va009039 | 0:1ed23ab1345f | 311 | void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)); |
va009039 | 0:1ed23ab1345f | 312 | void hci_close(void); |
va009039 | 0:1ed23ab1345f | 313 | |
va009039 | 0:1ed23ab1345f | 314 | // power and inquriy scan control |
va009039 | 0:1ed23ab1345f | 315 | int hci_power_control(HCI_POWER_MODE mode); |
va009039 | 0:1ed23ab1345f | 316 | void hci_discoverable_control(uint8_t enable); |
va009039 | 0:1ed23ab1345f | 317 | void hci_connectable_control(uint8_t enable); |
va009039 | 0:1ed23ab1345f | 318 | |
va009039 | 0:1ed23ab1345f | 319 | /** |
va009039 | 0:1ed23ab1345f | 320 | * run the hci control loop once |
va009039 | 0:1ed23ab1345f | 321 | */ |
va009039 | 0:1ed23ab1345f | 322 | void hci_run(void); |
va009039 | 0:1ed23ab1345f | 323 | |
va009039 | 0:1ed23ab1345f | 324 | // create and send hci command packets based on a template and a list of parameters |
va009039 | 0:1ed23ab1345f | 325 | int hci_send_cmd(const hci_cmd_t *cmd, ...); |
va009039 | 0:1ed23ab1345f | 326 | |
va009039 | 0:1ed23ab1345f | 327 | // send complete CMD packet |
va009039 | 0:1ed23ab1345f | 328 | int hci_send_cmd_packet(uint8_t *packet, int size); |
va009039 | 0:1ed23ab1345f | 329 | |
va009039 | 0:1ed23ab1345f | 330 | // send ACL packet |
va009039 | 0:1ed23ab1345f | 331 | int hci_send_acl_packet(uint8_t *packet, int size); |
va009039 | 0:1ed23ab1345f | 332 | |
va009039 | 0:1ed23ab1345f | 333 | // non-blocking UART driver needs |
va009039 | 0:1ed23ab1345f | 334 | int hci_can_send_packet_now(uint8_t packet_type); |
va009039 | 0:1ed23ab1345f | 335 | |
va009039 | 0:1ed23ab1345f | 336 | hci_connection_t * connection_for_handle(hci_con_handle_t con_handle); |
va009039 | 0:1ed23ab1345f | 337 | uint8_t hci_number_outgoing_packets(hci_con_handle_t handle); |
va009039 | 0:1ed23ab1345f | 338 | uint8_t hci_number_free_acl_slots(void); |
va009039 | 0:1ed23ab1345f | 339 | int hci_authentication_active_for_handle(hci_con_handle_t handle); |
va009039 | 0:1ed23ab1345f | 340 | void hci_drop_link_key_for_bd_addr(bd_addr_t *addr); |
va009039 | 0:1ed23ab1345f | 341 | uint16_t hci_max_acl_data_packet_length(void); |
va009039 | 0:1ed23ab1345f | 342 | uint16_t hci_usable_acl_packet_types(void); |
va009039 | 0:1ed23ab1345f | 343 | uint8_t* hci_get_outgoing_acl_packet_buffer(void); |
va009039 | 0:1ed23ab1345f | 344 | |
va009039 | 0:1ed23ab1345f | 345 | // |
va009039 | 0:1ed23ab1345f | 346 | void hci_emit_state(void); |
va009039 | 0:1ed23ab1345f | 347 | void hci_emit_connection_complete(hci_connection_t *conn, uint8_t status); |
va009039 | 0:1ed23ab1345f | 348 | void hci_emit_l2cap_check_timeout(hci_connection_t *conn); |
va009039 | 0:1ed23ab1345f | 349 | void hci_emit_disconnection_complete(uint16_t handle, uint8_t reason); |
va009039 | 0:1ed23ab1345f | 350 | void hci_emit_nr_connections_changed(void); |
va009039 | 0:1ed23ab1345f | 351 | void hci_emit_hci_open_failed(void); |
va009039 | 0:1ed23ab1345f | 352 | void hci_emit_btstack_version(void); |
va009039 | 0:1ed23ab1345f | 353 | void hci_emit_system_bluetooth_enabled(uint8_t enabled); |
va009039 | 0:1ed23ab1345f | 354 | void hci_emit_remote_name_cached(bd_addr_t *addr, device_name_t *name); |
va009039 | 0:1ed23ab1345f | 355 | void hci_emit_discoverable_enabled(uint8_t enabled); |
va009039 | 0:1ed23ab1345f | 356 | |
va009039 | 0:1ed23ab1345f | 357 | #if defined __cplusplus |
va009039 | 0:1ed23ab1345f | 358 | } |
va009039 | 0:1ed23ab1345f | 359 | #endif |