BTstack Bluetooth stack

Dependencies:   mbed USBHost

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hci_cmds.h Source File

hci_cmds.h

00001 /*
00002  * Copyright (C) 2009 by Matthias Ringwald
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
00021  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  */
00031 
00032 /*
00033  *  hci_cmds.h
00034  *
00035  *  Created by Matthias Ringwald on 7/23/09.
00036  */
00037 
00038 #pragma once
00039 
00040 #include <stdint.h>
00041 
00042 #if defined __cplusplus
00043 extern "C" {
00044 #endif
00045     
00046 /**
00047  * packet types - used in BTstack and over the H4 UART interface
00048  */
00049 #define HCI_COMMAND_DATA_PACKET 0x01
00050 #define HCI_ACL_DATA_PACKET     0x02
00051 #define HCI_SCO_DATA_PACKET     0x03
00052 #define HCI_EVENT_PACKET        0x04
00053 
00054 // extension for client/server communication
00055 #define DAEMON_EVENT_PACKET     0x05
00056     
00057 // L2CAP data
00058 #define L2CAP_DATA_PACKET       0x06
00059 
00060 // RFCOMM data
00061 #define RFCOMM_DATA_PACKET      0x07
00062 
00063 // Attribute protocol data
00064 #define ATT_DATA_PACKET         0x08
00065 
00066 // Security Manager protocol data
00067 #define SM_DATA_PACKET          0x09
00068     
00069 // debug log messages
00070 #define LOG_MESSAGE_PACKET      0xfc
00071 
00072     
00073 // Fixed PSM numbers
00074 #define PSM_SDP    0x01
00075 #define PSM_RFCOMM 0x03
00076 #define PSM_HID_CONTROL 0x11
00077 #define PSM_HID_INTERRUPT 0x13
00078 
00079 // Events from host controller to host
00080 #define HCI_EVENT_INQUIRY_COMPLETE                         0x01
00081 #define HCI_EVENT_INQUIRY_RESULT                           0x02
00082 #define HCI_EVENT_CONNECTION_COMPLETE                      0x03
00083 #define HCI_EVENT_CONNECTION_REQUEST                       0x04
00084 #define HCI_EVENT_DISCONNECTION_COMPLETE                   0x05
00085 #define HCI_EVENT_AUTHENTICATION_COMPLETE_EVENT            0x06
00086 #define HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE             0x07
00087 #define HCI_EVENT_ENCRYPTION_CHANGE                        0x08
00088 #define HCI_EVENT_CHANGE_CONNECTION_LINK_KEY_COMPLETE      0x09
00089 #define HCI_EVENT_MASTER_LINK_KEY_COMPLETE                 0x0A
00090 #define HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE  0x0B
00091 #define HCI_EVENT_READ_REMOTE_VERSION_INFORMATION_COMPLETE 0x0C
00092 #define HCI_EVENT_QOS_SETUP_COMPLETE                       0x0D
00093 #define HCI_EVENT_COMMAND_COMPLETE                         0x0E
00094 #define HCI_EVENT_COMMAND_STATUS                           0x0F
00095 #define HCI_EVENT_HARDWARE_ERROR                           0x10
00096 #define HCI_EVENT_FLUSH_OCCURED                            0x11
00097 #define HCI_EVENT_ROLE_CHANGE                              0x12
00098 #define HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS              0x13
00099 #define HCI_EVENT_MODE_CHANGE_EVENT                        0x14
00100 #define HCI_EVENT_RETURN_LINK_KEYS                         0x15
00101 #define HCI_EVENT_PIN_CODE_REQUEST                         0x16
00102 #define HCI_EVENT_LINK_KEY_REQUEST                         0x17
00103 #define HCI_EVENT_LINK_KEY_NOTIFICATION                    0x18
00104 #define HCI_EVENT_DATA_BUFFER_OVERFLOW                     0x1A
00105 #define HCI_EVENT_MAX_SLOTS_CHANGED                        0x1B
00106 #define HCI_EVENT_READ_CLOCK_OFFSET_COMPLETE               0x1C
00107 #define HCI_EVENT_PACKET_TYPE_CHANGED                      0x1D
00108 #define HCI_EVENT_INQUIRY_RESULT_WITH_RSSI                 0x22
00109 #define HCI_EVENT_EXTENDED_INQUIRY_RESPONSE                0x2F
00110 #define HCI_EVENT_LE_META                                  0x3E
00111 #define HCI_EVENT_VENDOR_SPECIFIC                          0xFF
00112 
00113 #define HCI_SUBEVENT_LE_CONNECTION_COMPLETE                0x01
00114 #define HCI_SUBEVENT_LE_ADVERTISING_REPORT                 0x02
00115 #define HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE         0x03
00116 #define HCI_SUBEVENT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04
00117 #define HCI_SUBEVENT_LE_LONG_TERM_KEY_REQUEST              0x05
00118     
00119 // last used HCI_EVENT in 2.1 is 0x3d
00120 
00121 // events 0x50-0x5f are used internally
00122 
00123 // BTSTACK DAEMON EVENTS
00124 
00125 // events from BTstack for application/client lib
00126 #define BTSTACK_EVENT_STATE                                0x60
00127 
00128 // data: event(8), len(8), nr hci connections
00129 #define BTSTACK_EVENT_NR_CONNECTIONS_CHANGED               0x61
00130 
00131 // data: none
00132 #define BTSTACK_EVENT_POWERON_FAILED                       0x62
00133 
00134 // data: majot (8), minor (8), revision(16)
00135 #define BTSTACK_EVENT_VERSION                              0x63
00136 
00137 // data: system bluetooth on/off (bool)
00138 #define BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED             0x64
00139 
00140 // data: event (8), len(8), status (8) == 0, address (48), name (1984 bits = 248 bytes)
00141 #define BTSTACK_EVENT_REMOTE_NAME_CACHED                   0x65
00142 
00143 // data: discoverable enabled (bool)
00144 #define BTSTACK_EVENT_DISCOVERABLE_ENABLED                 0x66
00145 
00146 // L2CAP EVENTS
00147     
00148 // data: event (8), len(8), status (8), address(48), handle (16), psm (16), local_cid(16), remote_cid (16), local_mtu(16), remote_mtu(16) 
00149 #define L2CAP_EVENT_CHANNEL_OPENED                         0x70
00150 
00151 // data: event (8), len(8), channel (16)
00152 #define L2CAP_EVENT_CHANNEL_CLOSED                         0x71
00153 
00154 // data: event (8), len(8), address(48), handle (16), psm (16), local_cid(16), remote_cid (16) 
00155 #define L2CAP_EVENT_INCOMING_CONNECTION                    0x72
00156 
00157 // data: event(8), len(8), handle(16)
00158 #define L2CAP_EVENT_TIMEOUT_CHECK                          0x73
00159 
00160 // data: event(8), len(8), local_cid(16), credits(8)
00161 #define L2CAP_EVENT_CREDITS                                0x74
00162 
00163 // data: event(8), len(8), status (8), psm (16)
00164 #define L2CAP_EVENT_SERVICE_REGISTERED                     0x75
00165 
00166 
00167 // RFCOMM EVENTS
00168     
00169 // data: event(8), len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16)
00170 #define RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE                 0x80
00171     
00172 // data: event(8), len(8), rfcomm_cid(16)
00173 #define RFCOMM_EVENT_CHANNEL_CLOSED                        0x81
00174     
00175 // data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
00176 #define RFCOMM_EVENT_INCOMING_CONNECTION                   0x82
00177     
00178 // data: event (8), len(8), rfcommid (16), ...
00179 #define RFCOMM_EVENT_REMOTE_LINE_STATUS                    0x83
00180     
00181 // data: event(8), len(8), rfcomm_cid(16), credits(8)
00182 #define RFCOMM_EVENT_CREDITS                               0x84
00183     
00184 // data: event(8), len(8), status (8), rfcomm server channel id (8) 
00185 #define RFCOMM_EVENT_SERVICE_REGISTERED                    0x85
00186     
00187 // data: event(8), len(8), status (8), rfcomm server channel id (8) 
00188 #define RFCOMM_EVENT_PERSISTENT_CHANNEL                    0x86
00189     
00190     
00191 // data: event(8), len(8), status(8), service_record_handle(32)
00192 #define SDP_SERVICE_REGISTERED                             0x90
00193 
00194     
00195 // last error code in 2.1 is 0x38 - we start with 0x50 for BTstack errors
00196 
00197 #define BTSTACK_CONNECTION_TO_BTDAEMON_FAILED              0x50
00198 #define BTSTACK_ACTIVATION_FAILED_SYSTEM_BLUETOOTH         0x51
00199 #define BTSTACK_ACTIVATION_POWERON_FAILED                  0x52
00200 #define BTSTACK_ACTIVATION_FAILED_UNKNOWN                  0x53
00201 #define BTSTACK_NOT_ACTIVATED                              0x54
00202 #define BTSTACK_BUSY                                       0x55
00203 #define BTSTACK_MEMORY_ALLOC_FAILED                        0x56
00204 #define BTSTACK_ACL_BUFFERS_FULL                           0x57
00205 
00206 // l2cap errors - enumeration by the command that created them
00207 #define L2CAP_COMMAND_REJECT_REASON_COMMAND_NOT_UNDERSTOOD 0x60
00208 #define L2CAP_COMMAND_REJECT_REASON_SIGNALING_MTU_EXCEEDED 0x61
00209 #define L2CAP_COMMAND_REJECT_REASON_INVALID_CID_IN_REQUEST 0x62
00210 
00211 #define L2CAP_CONNECTION_RESPONSE_RESULT_SUCCESSFUL        0x63
00212 #define L2CAP_CONNECTION_RESPONSE_RESULT_PENDING           0x64
00213 #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_PSM       0x65
00214 #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_SECURITY  0x66
00215 #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_RESOURCES 0x65
00216 
00217 #define L2CAP_CONFIG_RESPONSE_RESULT_SUCCESSFUL            0x66
00218 #define L2CAP_CONFIG_RESPONSE_RESULT_UNACCEPTABLE_PARAMS   0x67
00219 #define L2CAP_CONFIG_RESPONSE_RESULT_REJECTED              0x68
00220 #define L2CAP_CONFIG_RESPONSE_RESULT_UNKNOWN_OPTIONS       0x69
00221 #define L2CAP_SERVICE_ALREADY_REGISTERED                   0x6a
00222     
00223 #define RFCOMM_MULTIPLEXER_STOPPED                         0x70
00224 #define RFCOMM_CHANNEL_ALREADY_REGISTERED                  0x71
00225 #define RFCOMM_NO_OUTGOING_CREDITS                         0x72
00226 
00227 #define SDP_HANDLE_ALREADY_REGISTERED                      0x80
00228  
00229 /**
00230  * Default INQ Mode
00231  */
00232 #define HCI_INQUIRY_LAP 0x9E8B33L  // 0x9E8B33: General/Unlimited Inquiry Access Code (GIAC)
00233 /**
00234  *  Hardware state of Bluetooth controller 
00235  */
00236 typedef enum {
00237     HCI_POWER_OFF = 0,
00238     HCI_POWER_ON,
00239     HCI_POWER_SLEEP
00240 } HCI_POWER_MODE;
00241 
00242 /**
00243  * State of BTstack 
00244  */
00245 typedef enum {
00246     HCI_STATE_OFF = 0,
00247     HCI_STATE_INITIALIZING,
00248     HCI_STATE_WORKING,
00249     HCI_STATE_HALTING,
00250     HCI_STATE_SLEEPING,
00251     HCI_STATE_FALLING_ASLEEP
00252 } HCI_STATE;
00253 
00254 /** 
00255  * compact HCI Command packet description
00256  */
00257  typedef struct {
00258     uint16_t    opcode;
00259     const char *format;
00260 } hci_cmd_t;
00261 
00262 
00263 // HCI Commands - see hci_cmds.c for info on parameters
00264 extern const hci_cmd_t btstack_get_state;
00265 extern const hci_cmd_t btstack_set_power_mode;
00266 extern const hci_cmd_t btstack_set_acl_capture_mode;
00267 extern const hci_cmd_t btstack_get_version;
00268 extern const hci_cmd_t btstack_get_system_bluetooth_enabled;
00269 extern const hci_cmd_t btstack_set_system_bluetooth_enabled;
00270 extern const hci_cmd_t btstack_set_discoverable;
00271 extern const hci_cmd_t btstack_set_bluetooth_enabled;    // only used by btstack config
00272     
00273 extern const hci_cmd_t hci_accept_connection_request;
00274 extern const hci_cmd_t hci_authentication_requested;
00275 extern const hci_cmd_t hci_change_connection_link_key;
00276 extern const hci_cmd_t hci_create_connection;
00277 extern const hci_cmd_t hci_create_connection_cancel;
00278 extern const hci_cmd_t hci_delete_stored_link_key;
00279 extern const hci_cmd_t hci_disconnect;
00280 extern const hci_cmd_t hci_host_buffer_size;
00281 extern const hci_cmd_t hci_inquiry;
00282 extern const hci_cmd_t hci_inquiry_cancel;
00283 extern const hci_cmd_t hci_link_key_request_negative_reply;
00284 extern const hci_cmd_t hci_link_key_request_reply;
00285 extern const hci_cmd_t hci_pin_code_request_reply;
00286 extern const hci_cmd_t hci_pin_code_request_negative_reply;
00287 extern const hci_cmd_t hci_qos_setup;
00288 extern const hci_cmd_t hci_read_bd_addr;
00289 extern const hci_cmd_t hci_read_buffer_size;
00290 extern const hci_cmd_t hci_read_le_host_supported;
00291 extern const hci_cmd_t hci_read_link_policy_settings;
00292 extern const hci_cmd_t hci_read_link_supervision_timeout;
00293 extern const hci_cmd_t hci_read_local_supported_features;
00294 extern const hci_cmd_t hci_read_num_broadcast_retransmissions;
00295 extern const hci_cmd_t hci_reject_connection_request;
00296 extern const hci_cmd_t hci_remote_name_request;
00297 extern const hci_cmd_t hci_remote_name_request_cancel;
00298 extern const hci_cmd_t hci_reset;
00299 extern const hci_cmd_t hci_role_discovery;
00300 extern const hci_cmd_t hci_set_event_mask;
00301 extern const hci_cmd_t hci_set_connection_encryption;
00302 extern const hci_cmd_t hci_sniff_mode;
00303 extern const hci_cmd_t hci_switch_role_command;
00304 extern const hci_cmd_t hci_write_authentication_enable;
00305 extern const hci_cmd_t hci_write_class_of_device;
00306 extern const hci_cmd_t hci_write_extended_inquiry_response;
00307 extern const hci_cmd_t hci_write_inquiry_mode;
00308 extern const hci_cmd_t hci_write_le_host_supported;
00309 extern const hci_cmd_t hci_write_link_policy_settings;
00310 extern const hci_cmd_t hci_write_link_supervision_timeout;
00311 extern const hci_cmd_t hci_write_local_name;
00312 extern const hci_cmd_t hci_write_num_broadcast_retransmissions;
00313 extern const hci_cmd_t hci_write_page_timeout;
00314 extern const hci_cmd_t hci_write_scan_enable;
00315 extern const hci_cmd_t hci_write_simple_pairing_mode;
00316 
00317 extern const hci_cmd_t hci_le_add_device_to_whitelist;
00318 extern const hci_cmd_t hci_le_clear_white_list;
00319 extern const hci_cmd_t hci_le_connection_update;
00320 extern const hci_cmd_t hci_le_create_connection;
00321 extern const hci_cmd_t hci_le_create_connection_cancel;
00322 extern const hci_cmd_t hci_le_encrypt;
00323 extern const hci_cmd_t hci_le_long_term_key_negative_reply;
00324 extern const hci_cmd_t hci_le_long_term_key_request_reply;
00325 extern const hci_cmd_t hci_le_rand;
00326 extern const hci_cmd_t hci_le_read_advertising_channel_tx_power;
00327 extern const hci_cmd_t hci_le_read_buffer_size ;
00328 extern const hci_cmd_t hci_le_read_channel_map;
00329 extern const hci_cmd_t hci_le_read_remote_used_features;
00330 extern const hci_cmd_t hci_le_read_supported_features;
00331 extern const hci_cmd_t hci_le_read_supported_states;
00332 extern const hci_cmd_t hci_le_read_white_list_size;
00333 extern const hci_cmd_t hci_le_receiver_test;
00334 extern const hci_cmd_t hci_le_remove_device_from_whitelist;
00335 extern const hci_cmd_t hci_le_set_advertise_enable;
00336 extern const hci_cmd_t hci_le_set_advertising_data;
00337 extern const hci_cmd_t hci_le_set_advertising_parameters;
00338 extern const hci_cmd_t hci_le_set_event_mask;
00339 extern const hci_cmd_t hci_le_set_host_channel_classification;
00340 extern const hci_cmd_t hci_le_set_random_address;
00341 extern const hci_cmd_t hci_le_set_scan_enable;
00342 extern const hci_cmd_t hci_le_set_scan_parameters;
00343 extern const hci_cmd_t hci_le_set_scan_response_data;
00344 extern const hci_cmd_t hci_le_start_encryption;
00345 extern const hci_cmd_t hci_le_test_end;
00346 extern const hci_cmd_t hci_le_transmitter_test;
00347     
00348 extern const hci_cmd_t l2cap_accept_connection;
00349 extern const hci_cmd_t l2cap_create_channel;
00350 extern const hci_cmd_t l2cap_create_channel_mtu;
00351 extern const hci_cmd_t l2cap_decline_connection;
00352 extern const hci_cmd_t l2cap_disconnect;
00353 extern const hci_cmd_t l2cap_register_service;
00354 extern const hci_cmd_t l2cap_unregister_service;
00355 
00356 extern const hci_cmd_t sdp_register_service_record;
00357 extern const hci_cmd_t sdp_unregister_service_record;
00358 
00359 // accept connection @param bd_addr(48), rfcomm_cid (16)
00360 extern const hci_cmd_t rfcomm_accept_connection;
00361 // create rfcomm channel: @param bd_addr(48), channel (8)
00362 extern const hci_cmd_t rfcomm_create_channel;
00363 // create rfcomm channel: @param bd_addr(48), channel (8), mtu (16), credits (8)
00364 extern const hci_cmd_t rfcomm_create_channel_with_initial_credits;
00365 // decline rfcomm disconnect,@param bd_addr(48), rfcomm cid (16), reason(8)
00366 extern const hci_cmd_t rfcomm_decline_connection;
00367 // disconnect rfcomm disconnect, @param rfcomm_cid(8), reason(8)
00368 extern const hci_cmd_t rfcomm_disconnect;
00369 // register rfcomm service: @param channel(8), mtu (16)
00370 extern const hci_cmd_t rfcomm_register_service;
00371 // register rfcomm service: @param channel(8), mtu (16), initial credits (8)
00372 extern const hci_cmd_t rfcomm_register_service_with_initial_credits;
00373 // unregister rfcomm service, @param service_channel(16)
00374 extern const hci_cmd_t rfcomm_unregister_service;
00375 // request persisten rfcomm channel for service name: serive name (char*) 
00376 extern const hci_cmd_t rfcomm_persistent_channel_for_service;
00377     
00378 #if defined __cplusplus
00379 }
00380 #endif