うおーるぼっとをiPhoneでコントロールするプログラムです。 iPhoneとはBTLEで接続しています。

Dependencies:   FatFileSystem HighSpeedAnalogIn TB6612FNG2 mbed

Committer:
jksoft
Date:
Fri May 10 11:48:07 2013 +0000
Revision:
0:373bcb197dc8
?????????

Who changed what in which revision?

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