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