1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #define BTSTACK_FILE__ "daemon_cmds.c" 39 40 /* 41 * hci_cmd.c 42 * 43 * Created by Matthias Ringwald on 7/23/09. 44 */ 45 46 #include "daemon_cmds.h" 47 #include "hci.h" 48 49 // calculate combined ogf/ocf value 50 #define OPCODE(ogf, ocf) (ocf | ogf << 10) 51 52 // BTstack commands 53 const hci_cmd_t btstack_get_state = { 54 DAEMON_OPCODE_BTSTACK_GET_STATE, "" 55 }; 56 57 /** 58 * @param power_mode (0 = off, 1 = on) 59 */ 60 const hci_cmd_t btstack_set_power_mode = { 61 DAEMON_OPCODE_BTSTACK_SET_POWER_MODE, "1" 62 }; 63 64 /** 65 * @param acl_capture_mode (0 = off, 1 = on) 66 */ 67 const hci_cmd_t btstack_set_acl_capture_mode = { 68 DAEMON_OPCODE_BTSTACK_SET_ACL_CAPTURE_MODE, "1" 69 }; 70 71 const hci_cmd_t btstack_get_version = { 72 DAEMON_OPCODE_BTSTACK_GET_VERSION, "" 73 }; 74 75 const hci_cmd_t btstack_get_system_bluetooth_enabled = { 76 DAEMON_OPCODE_BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED, "" 77 }; 78 79 /** 80 * @param bluetooth_enabled_flag (0 = off, 1 = on, only used by btstack config) 81 */ 82 const hci_cmd_t btstack_set_system_bluetooth_enabled = { 83 DAEMON_OPCODE_BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED, "1" 84 }; 85 86 /** 87 * @param discoverable_flag (0 = off, 1 = on) 88 */ 89 const hci_cmd_t btstack_set_discoverable = { 90 DAEMON_OPCODE_BTSTACK_SET_DISCOVERABLE, "1" 91 }; 92 93 /** 94 * @param bluetooth_enabled_flag (0 = off, 1 = on, only used by btstack config) 95 */ 96 const hci_cmd_t btstack_set_bluetooth_enabled = { 97 DAEMON_OPCODE_BTSTACK_SET_BLUETOOTH_ENABLED, "1" 98 }; 99 100 /** 101 * @param bd_addr (48) 102 * @param psm (16) 103 */ 104 const hci_cmd_t l2cap_create_channel_cmd = { 105 DAEMON_OPCODE_L2CAP_CREATE_CHANNEL, "B2" 106 }; 107 108 /** 109 * @param bd_addr (48) 110 * @param psm (16) 111 * @param mtu (16) 112 */ 113 const hci_cmd_t l2cap_create_channel_mtu_cmd = { 114 DAEMON_OPCODE_L2CAP_CREATE_CHANNEL_MTU, "B22" 115 // @param bd_addr(48), psm (16), mtu (16) 116 }; 117 118 /** 119 * @param channel (16) 120 * @param reason (16) 121 */ 122 const hci_cmd_t l2cap_disconnect_cmd = { 123 DAEMON_OPCODE_L2CAP_DISCONNECT, "21" 124 }; 125 126 /** 127 * @param psm (16) 128 * @param mtu (16) 129 */ 130 const hci_cmd_t l2cap_register_service_cmd = { 131 DAEMON_OPCODE_L2CAP_REGISTER_SERVICE, "22" 132 }; 133 134 /** 135 * @param psm (16) 136 */ 137 const hci_cmd_t l2cap_unregister_service_cmd = { 138 DAEMON_OPCODE_L2CAP_UNREGISTER_SERVICE, "2" 139 }; 140 141 /** 142 * @param source_cid (16) 143 */ 144 const hci_cmd_t l2cap_accept_connection_cmd = { 145 DAEMON_OPCODE_L2CAP_ACCEPT_CONNECTION, "2" 146 }; 147 148 /** 149 * @param source_cid (16) 150 * @param reason (deprecated) 151 */ 152 const hci_cmd_t l2cap_decline_connection_cmd = { 153 DAEMON_OPCODE_L2CAP_DECLINE_CONNECTION, "21" 154 }; 155 156 157 /** 158 * @param service_record 159 */ 160 const hci_cmd_t sdp_register_service_record_cmd = { 161 DAEMON_OPCODE_SDP_REGISTER_SERVICE_RECORD, "S" 162 }; 163 164 /** 165 * @param service_record_handle 166 */ 167 const hci_cmd_t sdp_unregister_service_record_cmd = { 168 DAEMON_OPCODE_SDP_UNREGISTER_SERVICE_RECORD, "4" 169 }; 170 171 /** 172 * @param bd_addr 173 * @param service_search_pattern 174 */ 175 const hci_cmd_t sdp_client_query_rfcomm_services_cmd = { 176 DAEMON_OPCODE_SDP_CLIENT_QUERY_RFCOMM_SERVICES, "BS" 177 }; 178 179 /** 180 * @param bd_addr 181 * @param service_search_pattern 182 * @param attribute_ID_list 183 */ 184 const hci_cmd_t sdp_client_query_services_cmd = { 185 DAEMON_OPCODE_SDP_CLIENT_QUERY_SERVICES, "BSS" 186 }; 187 188 /** 189 * @param bd_addr 190 * @param server_channel 191 */ 192 const hci_cmd_t rfcomm_create_channel_cmd = { 193 DAEMON_OPCODE_RFCOMM_CREATE_CHANNEL, "B1" 194 }; 195 196 /** 197 * @param bd_addr 198 * @param server_channel 199 * @param mtu 200 * @param credits 201 */ 202 const hci_cmd_t rfcomm_create_channel_with_initial_credits_cmd = { 203 DAEMON_OPCODE_RFCOMM_CREATE_CHANNEL_WITH_INITIAL_CREDITS, "B121" 204 }; 205 206 /** 207 * @param rfcomm_cid 208 * @param credits 209 */ 210 const hci_cmd_t rfcomm_grants_credits_cmd = { 211 DAEMON_OPCODE_RFCOMM_GRANTS_CREDITS, "21" 212 }; 213 214 /** 215 * @param rfcomm_cid 216 * @param reason 217 */ 218 const hci_cmd_t rfcomm_disconnect_cmd = { 219 DAEMON_OPCODE_RFCOMM_DISCONNECT, "21" 220 }; 221 222 /** 223 * @param server_channel 224 * @param mtu 225 */ 226 const hci_cmd_t rfcomm_register_service_cmd = { 227 DAEMON_OPCODE_RFCOMM_REGISTER_SERVICE, "12" 228 }; 229 230 /** 231 * @param server_channel 232 * @param mtu 233 * @param initial_credits 234 */ 235 const hci_cmd_t rfcomm_register_service_with_initial_credits_cmd = { 236 DAEMON_OPCODE_RFCOMM_REGISTER_SERVICE_WITH_INITIAL_CREDITS, "121" 237 }; 238 239 /** 240 * @param service_channel 241 */ 242 const hci_cmd_t rfcomm_unregister_service_cmd = { 243 DAEMON_OPCODE_RFCOMM_UNREGISTER_SERVICE, "2" 244 }; 245 246 /** 247 * @param source_cid 248 */ 249 const hci_cmd_t rfcomm_accept_connection_cmd = { 250 DAEMON_OPCODE_RFCOMM_ACCEPT_CONNECTION, "2" 251 }; 252 253 254 /** 255 * @param source_cid 256 * @param reason 257 */ 258 const hci_cmd_t rfcomm_decline_connection_cmd = { 259 DAEMON_OPCODE_RFCOMM_DECLINE_CONNECTION, "21" 260 }; 261 262 // request persistent rfcomm channel number for named service 263 /** 264 * @param named_service 265 */ 266 const hci_cmd_t rfcomm_persistent_channel_for_service_cmd = { 267 DAEMON_OPCODE_RFCOMM_PERSISTENT_CHANNEL_FOR_SERVICE, "N" 268 }; 269 270 /** 271 * @param handle 272 */ 273 const hci_cmd_t gap_disconnect_cmd = { 274 DAEMON_OPCODE_GAP_DISCONNECT, "H" 275 }; 276 277 /** 278 */ 279 const hci_cmd_t gap_le_scan_start = { 280 DAEMON_OPCODE_GAP_LE_SCAN_START, "" 281 }; 282 283 /** 284 */ 285 const hci_cmd_t gap_le_scan_stop = { 286 DAEMON_OPCODE_GAP_LE_SCAN_STOP, "" 287 }; 288 289 /** 290 * @param scan_type 291 * @param scan_interval 292 * @param scan_window 293 */ 294 const hci_cmd_t gap_le_set_scan_parameters = { 295 DAEMON_OPCODE_GAP_LE_SET_SCAN_PARAMETERS, "122" 296 }; 297 298 /** 299 * @param peer_address_type 300 * @param peer_address 301 */ 302 const hci_cmd_t gap_le_connect_cmd = { 303 DAEMON_OPCODE_GAP_LE_CONNECT, "1B" 304 }; 305 306 /** 307 * @param peer_address_type 308 * @param peer_address 309 */ 310 const hci_cmd_t gap_le_connect_cancel_cmd = { 311 DAEMON_OPCODE_GAP_LE_CONNECT_CANCEL, "" 312 }; 313 314 /** 315 * @param handle 316 */ 317 const hci_cmd_t gatt_discover_primary_services_cmd = { 318 DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES, "H" 319 }; 320 321 /** 322 * @param handle 323 * @param uuid16 324 */ 325 const hci_cmd_t gatt_discover_primary_services_by_uuid16_cmd = { 326 DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID16, "H2" 327 }; 328 329 /** 330 * @param handle 331 * @param uuid128 332 */ 333 const hci_cmd_t gatt_discover_primary_services_by_uuid128_cmd = { 334 DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID128, "HU" 335 }; 336 337 /** 338 * @param handle 339 * @param service 340 */ 341 const hci_cmd_t gatt_find_included_services_for_service_cmd = { 342 DAEMON_OPCODE_GATT_FIND_INCLUDED_SERVICES_FOR_SERVICE, "HX" 343 }; 344 345 /** 346 * @param handle 347 * @param service 348 */ 349 const hci_cmd_t gatt_discover_characteristics_for_service_cmd = { 350 DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE, "HX" 351 }; 352 353 /** 354 * @param handle 355 * @param service 356 * @param uuid128 357 */ 358 const hci_cmd_t gatt_discover_characteristics_for_service_by_uuid128_cmd = { 359 DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID128, "HXU" 360 }; 361 362 /** 363 * @param handle 364 * @param characteristic 365 */ 366 const hci_cmd_t gatt_discover_characteristic_descriptors_cmd = { 367 DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS, "HY" 368 }; 369 370 /** 371 * @param handle 372 * @param characteristic 373 */ 374 const hci_cmd_t gatt_read_value_of_characteristic_cmd = { 375 DAEMON_OPCODE_GATT_READ_VALUE_OF_CHARACTERISTIC, "HY" 376 }; 377 378 /** 379 * @param handle 380 * @param characteristic 381 */ 382 const hci_cmd_t gatt_read_long_value_of_characteristic_cmd = { 383 DAEMON_OPCODE_GATT_READ_LONG_VALUE_OF_CHARACTERISTIC, "HY" 384 }; 385 386 /** 387 * @param handle 388 * @param characteristic 389 * @param data_length 390 * @param data 391 */ 392 const hci_cmd_t gatt_write_value_of_characteristic_without_response_cmd = { 393 DAEMON_OPCODE_GATT_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE, "HYLV" 394 }; 395 396 /** 397 * @param handle 398 * @param characteristic 399 * @param data_length 400 * @param data 401 */ 402 const hci_cmd_t gatt_write_value_of_characteristic_cmd = { 403 DAEMON_OPCODE_GATT_WRITE_VALUE_OF_CHARACTERISTIC, "HYLV" 404 }; 405 406 /** 407 * @param handle 408 * @param characteristic 409 * @param data_length 410 * @param data 411 */ 412 const hci_cmd_t gatt_write_long_value_of_characteristic_cmd = { 413 DAEMON_OPCODE_GATT_WRITE_LONG_VALUE_OF_CHARACTERISTIC, "HYLV" 414 }; 415 416 /** 417 * @param handle 418 * @param characteristic 419 * @param data_length 420 * @param data 421 */ 422 const hci_cmd_t gatt_reliable_write_long_value_of_characteristic_cmd = { 423 DAEMON_OPCODE_GATT_RELIABLE_WRITE_LONG_VALUE_OF_CHARACTERISTIC, "HYLV" 424 }; 425 426 /** 427 * @param handle 428 * @param descriptor 429 */ 430 const hci_cmd_t gatt_read_characteristic_descriptor_cmd = { 431 DAEMON_OPCODE_GATT_READ_CHARACTERISTIC_DESCRIPTOR, "HZ" 432 }; 433 434 /** 435 * @param handle 436 * @param descriptor 437 */ 438 const hci_cmd_t gatt_read_long_characteristic_descriptor_cmd = { 439 DAEMON_OPCODE_GATT_READ_LONG_CHARACTERISTIC_DESCRIPTOR, "HZ" 440 }; 441 442 /** 443 * @param handle 444 * @param descriptor 445 * @param data_length 446 * @param data 447 */ 448 const hci_cmd_t gatt_write_characteristic_descriptor_cmd = { 449 DAEMON_OPCODE_GATT_WRITE_CHARACTERISTIC_DESCRIPTOR, "HZLV" 450 }; 451 452 /** 453 * @param handle 454 * @param descriptor 455 * @param data_length 456 * @param data 457 */ 458 const hci_cmd_t gatt_write_long_characteristic_descriptor_cmd = { 459 DAEMON_OPCODE_GATT_WRITE_LONG_CHARACTERISTIC_DESCRIPTOR, "HZLV" 460 }; 461 462 /** 463 * @param handle 464 * @param characteristic 465 * @param configuration 466 */ 467 const hci_cmd_t gatt_write_client_characteristic_configuration_cmd = { 468 DAEMON_OPCODE_GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, "HY2" 469 }; 470 471 /** 472 * @param handle 473 */ 474 const hci_cmd_t gatt_get_mtu = { 475 DAEMON_OPCODE_GATT_GET_MTU, "H" 476 }; 477 478 /** 479 * @brief Sets the requested authentication requirements, bonding yes/no, MITM yes/no, SC yes/no, keypress yes/no 480 * @param auth_req OR combination of SM_AUTHREQ_ flags 481 */ 482 const hci_cmd_t sm_set_authentication_requirements_cmd = { 483 DAEMON_OPCODE_SM_SET_AUTHENTICATION_REQUIREMENTS, "1" 484 }; 485 486 /** 487 * @brief Sets the available IO Capabilities 488 * @param io_capabilities 489 */ 490 const hci_cmd_t sm_set_io_capabilities_cmd = { 491 DAEMON_OPCODE_SM_SET_IO_CAPABILITIES, "1" 492 }; 493 494 /** 495 * @brief Decline bonding triggered by event before 496 * @param con_handle 497 */ 498 const hci_cmd_t sm_bonding_decline_cmd = { 499 DAEMON_OPCODE_SM_BONDING_DECLINE, "H" 500 }; 501 502 /** 503 * @brief Confirm Just Works bonding 504 * @param con_handle 505 */ 506 const hci_cmd_t sm_just_works_confirm_cmd = { 507 DAEMON_OPCODE_SM_JUST_WORKS_CONFIRM, "H" 508 }; 509 510 /** 511 * @brief Confirm value from SM_EVENT_NUMERIC_COMPARISON_REQUEST for Numeric Comparison bonding 512 * @param con_handle 513 */ 514 const hci_cmd_t sm_numeric_comparison_confirm_cmd = { 515 DAEMON_OPCODE_SM_NUMERIC_COMPARISON_CONFIRM, "H" 516 }; 517 518 /** 519 * @brief Reports passkey input by user 520 * @param con_handle 521 * @param passkey in [0..999999] 522 */ 523 const hci_cmd_t sm_passkey_input_cmd = { 524 DAEMON_OPCODE_SM_PASSKEY_INPUT, "H4" 525 }; 526