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 * @param duration in 1.28s units 279 */ 280 const hci_cmd_t gap_inquiry_start_cmd = { 281 DAEMON_OPCODE_GAP_INQUIRY_START, "1" 282 }; 283 284 /** 285 */ 286 const hci_cmd_t gap_inquiry_stop_cmd = { 287 DAEMON_OPCODE_GAP_INQUIRY_STOP, "" 288 }; 289 290 /** 291 * @param addr 292 * @param page_scan_repetition_mode 293 * @param clock_offset only used when bit 15 is set - pass 0 if not known 294 */ 295 const hci_cmd_t gap_remote_name_request_cmd = { 296 DAEMON_OPCODE_GAP_REMOTE_NAME_REQUEST, "B12" 297 }; 298 299 /** 300 * @param addr 301 */ 302 const hci_cmd_t gap_drop_link_key_cmd = { 303 DAEMON_OPCODE_GAP_DROP_LINK_KEY_FOR_BD_ADDR, "B" 304 }; 305 306 /** 307 */ 308 const hci_cmd_t gap_delete_all_link_keys_cmd = { 309 DAEMON_OPCODE_GAP_DELETE_ALL_LINK_KEYS, "" 310 }; 311 312 /** 313 */ 314 const hci_cmd_t gap_le_scan_start = { 315 DAEMON_OPCODE_GAP_LE_SCAN_START, "" 316 }; 317 318 /** 319 */ 320 const hci_cmd_t gap_le_scan_stop = { 321 DAEMON_OPCODE_GAP_LE_SCAN_STOP, "" 322 }; 323 324 /** 325 * @param scan_type 326 * @param scan_interval 327 * @param scan_window 328 */ 329 const hci_cmd_t gap_le_set_scan_parameters = { 330 DAEMON_OPCODE_GAP_LE_SET_SCAN_PARAMETERS, "122" 331 }; 332 333 /** 334 * @param peer_address_type 335 * @param peer_address 336 */ 337 const hci_cmd_t gap_le_connect_cmd = { 338 DAEMON_OPCODE_GAP_LE_CONNECT, "1B" 339 }; 340 341 /** 342 * @param peer_address_type 343 * @param peer_address 344 */ 345 const hci_cmd_t gap_le_connect_cancel_cmd = { 346 DAEMON_OPCODE_GAP_LE_CONNECT_CANCEL, "" 347 }; 348 349 /** 350 * @param handle 351 */ 352 const hci_cmd_t gatt_discover_primary_services_cmd = { 353 DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES, "H" 354 }; 355 356 /** 357 * @param handle 358 * @param uuid16 359 */ 360 const hci_cmd_t gatt_discover_primary_services_by_uuid16_cmd = { 361 DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID16, "H2" 362 }; 363 364 /** 365 * @param handle 366 * @param uuid128 367 */ 368 const hci_cmd_t gatt_discover_primary_services_by_uuid128_cmd = { 369 DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID128, "HU" 370 }; 371 372 /** 373 * @param handle 374 * @param service 375 */ 376 const hci_cmd_t gatt_find_included_services_for_service_cmd = { 377 DAEMON_OPCODE_GATT_FIND_INCLUDED_SERVICES_FOR_SERVICE, "HX" 378 }; 379 380 /** 381 * @param handle 382 * @param service 383 */ 384 const hci_cmd_t gatt_discover_characteristics_for_service_cmd = { 385 DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE, "HX" 386 }; 387 388 /** 389 * @param handle 390 * @param service 391 * @param uuid128 392 */ 393 const hci_cmd_t gatt_discover_characteristics_for_service_by_uuid128_cmd = { 394 DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID128, "HXU" 395 }; 396 397 /** 398 * @param handle 399 * @param characteristic 400 */ 401 const hci_cmd_t gatt_discover_characteristic_descriptors_cmd = { 402 DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS, "HY" 403 }; 404 405 /** 406 * @param handle 407 * @param characteristic 408 */ 409 const hci_cmd_t gatt_read_value_of_characteristic_cmd = { 410 DAEMON_OPCODE_GATT_READ_VALUE_OF_CHARACTERISTIC, "HY" 411 }; 412 413 /** 414 * @param handle 415 * @param characteristic 416 */ 417 const hci_cmd_t gatt_read_long_value_of_characteristic_cmd = { 418 DAEMON_OPCODE_GATT_READ_LONG_VALUE_OF_CHARACTERISTIC, "HY" 419 }; 420 421 /** 422 * @param handle 423 * @param characteristic 424 * @param data_length 425 * @param data 426 */ 427 const hci_cmd_t gatt_write_value_of_characteristic_without_response_cmd = { 428 DAEMON_OPCODE_GATT_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE, "HYLV" 429 }; 430 431 /** 432 * @param handle 433 * @param characteristic 434 * @param data_length 435 * @param data 436 */ 437 const hci_cmd_t gatt_write_value_of_characteristic_cmd = { 438 DAEMON_OPCODE_GATT_WRITE_VALUE_OF_CHARACTERISTIC, "HYLV" 439 }; 440 441 /** 442 * @param handle 443 * @param characteristic 444 * @param data_length 445 * @param data 446 */ 447 const hci_cmd_t gatt_write_long_value_of_characteristic_cmd = { 448 DAEMON_OPCODE_GATT_WRITE_LONG_VALUE_OF_CHARACTERISTIC, "HYLV" 449 }; 450 451 /** 452 * @param handle 453 * @param characteristic 454 * @param data_length 455 * @param data 456 */ 457 const hci_cmd_t gatt_reliable_write_long_value_of_characteristic_cmd = { 458 DAEMON_OPCODE_GATT_RELIABLE_WRITE_LONG_VALUE_OF_CHARACTERISTIC, "HYLV" 459 }; 460 461 /** 462 * @param handle 463 * @param descriptor 464 */ 465 const hci_cmd_t gatt_read_characteristic_descriptor_cmd = { 466 DAEMON_OPCODE_GATT_READ_CHARACTERISTIC_DESCRIPTOR, "HZ" 467 }; 468 469 /** 470 * @param handle 471 * @param descriptor 472 */ 473 const hci_cmd_t gatt_read_long_characteristic_descriptor_cmd = { 474 DAEMON_OPCODE_GATT_READ_LONG_CHARACTERISTIC_DESCRIPTOR, "HZ" 475 }; 476 477 /** 478 * @param handle 479 * @param descriptor 480 * @param data_length 481 * @param data 482 */ 483 const hci_cmd_t gatt_write_characteristic_descriptor_cmd = { 484 DAEMON_OPCODE_GATT_WRITE_CHARACTERISTIC_DESCRIPTOR, "HZLV" 485 }; 486 487 /** 488 * @param handle 489 * @param descriptor 490 * @param data_length 491 * @param data 492 */ 493 const hci_cmd_t gatt_write_long_characteristic_descriptor_cmd = { 494 DAEMON_OPCODE_GATT_WRITE_LONG_CHARACTERISTIC_DESCRIPTOR, "HZLV" 495 }; 496 497 /** 498 * @param handle 499 * @param characteristic 500 * @param configuration 501 */ 502 const hci_cmd_t gatt_write_client_characteristic_configuration_cmd = { 503 DAEMON_OPCODE_GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, "HY2" 504 }; 505 506 /** 507 * @param handle 508 */ 509 const hci_cmd_t gatt_get_mtu = { 510 DAEMON_OPCODE_GATT_GET_MTU, "H" 511 }; 512 513 /** 514 * @brief Sets the requested authentication requirements, bonding yes/no, MITM yes/no, SC yes/no, keypress yes/no 515 * @param auth_req OR combination of SM_AUTHREQ_ flags 516 */ 517 const hci_cmd_t sm_set_authentication_requirements_cmd = { 518 DAEMON_OPCODE_SM_SET_AUTHENTICATION_REQUIREMENTS, "1" 519 }; 520 521 /** 522 * @brief Sets the available IO Capabilities 523 * @param io_capabilities 524 */ 525 const hci_cmd_t sm_set_io_capabilities_cmd = { 526 DAEMON_OPCODE_SM_SET_IO_CAPABILITIES, "1" 527 }; 528 529 /** 530 * @brief Decline bonding triggered by event before 531 * @param con_handle 532 */ 533 const hci_cmd_t sm_bonding_decline_cmd = { 534 DAEMON_OPCODE_SM_BONDING_DECLINE, "H" 535 }; 536 537 /** 538 * @brief Confirm Just Works bonding 539 * @param con_handle 540 */ 541 const hci_cmd_t sm_just_works_confirm_cmd = { 542 DAEMON_OPCODE_SM_JUST_WORKS_CONFIRM, "H" 543 }; 544 545 /** 546 * @brief Confirm value from SM_EVENT_NUMERIC_COMPARISON_REQUEST for Numeric Comparison bonding 547 * @param con_handle 548 */ 549 const hci_cmd_t sm_numeric_comparison_confirm_cmd = { 550 DAEMON_OPCODE_SM_NUMERIC_COMPARISON_CONFIRM, "H" 551 }; 552 553 /** 554 * @brief Reports passkey input by user 555 * @param con_handle 556 * @param passkey in [0..999999] 557 */ 558 const hci_cmd_t sm_passkey_input_cmd = { 559 DAEMON_OPCODE_SM_PASSKEY_INPUT, "H4" 560 }; 561