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 /* 39 * hci_cmd.c 40 * 41 * Created by Matthias Ringwald on 7/23/09. 42 */ 43 44 #include "daemon_cmds.h" 45 #include "hci.h" 46 47 // calculate combined ogf/ocf value 48 #define OPCODE(ogf, ocf) (ocf | ogf << 10) 49 50 // BTstack commands 51 const hci_cmd_t btstack_get_state = { 52 OPCODE(OGF_BTSTACK, BTSTACK_GET_STATE), "" 53 }; 54 55 /** 56 * @param power_mode (0 = off, 1 = on) 57 */ 58 const hci_cmd_t btstack_set_power_mode = { 59 OPCODE(OGF_BTSTACK, BTSTACK_SET_POWER_MODE), "1" 60 }; 61 62 /** 63 * @param acl_capture_mode (0 = off, 1 = on) 64 */ 65 const hci_cmd_t btstack_set_acl_capture_mode = { 66 OPCODE(OGF_BTSTACK, BTSTACK_SET_ACL_CAPTURE_MODE), "1" 67 }; 68 69 const hci_cmd_t btstack_get_version = { 70 OPCODE(OGF_BTSTACK, BTSTACK_GET_VERSION), "" 71 }; 72 73 const hci_cmd_t btstack_get_system_bluetooth_enabled = { 74 OPCODE(OGF_BTSTACK, BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED), "" 75 }; 76 77 /** 78 * @param bluetooth_enabled_flag (0 = off, 1 = on, only used by btstack config) 79 */ 80 const hci_cmd_t btstack_set_system_bluetooth_enabled = { 81 OPCODE(OGF_BTSTACK, BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED), "1" 82 }; 83 84 /** 85 * @param discoverable_flag (0 = off, 1 = on) 86 */ 87 const hci_cmd_t btstack_set_discoverable = { 88 OPCODE(OGF_BTSTACK, BTSTACK_SET_DISCOVERABLE), "1" 89 }; 90 91 /** 92 * @param bluetooth_enabled_flag (0 = off, 1 = on, only used by btstack config) 93 */ 94 const hci_cmd_t btstack_set_bluetooth_enabled = { 95 OPCODE(OGF_BTSTACK, BTSTACK_SET_BLUETOOTH_ENABLED), "1" 96 }; 97 98 /** 99 * @param bd_addr (48) 100 * @param psm (16) 101 */ 102 const hci_cmd_t l2cap_create_channel_cmd = { 103 OPCODE(OGF_BTSTACK, L2CAP_CREATE_CHANNEL), "B2" 104 }; 105 106 /** 107 * @param bd_addr (48) 108 * @param psm (16) 109 * @param mtu (16) 110 */ 111 const hci_cmd_t l2cap_create_channel_mtu_cmd = { 112 OPCODE(OGF_BTSTACK, L2CAP_CREATE_CHANNEL_MTU), "B22" 113 // @param bd_addr(48), psm (16), mtu (16) 114 }; 115 116 /** 117 * @param channel (16) 118 * @param reason (16) 119 */ 120 const hci_cmd_t l2cap_disconnect_cmd = { 121 OPCODE(OGF_BTSTACK, L2CAP_DISCONNECT), "21" 122 }; 123 124 /** 125 * @param psm (16) 126 * @param mtu (16) 127 */ 128 const hci_cmd_t l2cap_register_service_cmd = { 129 OPCODE(OGF_BTSTACK, L2CAP_REGISTER_SERVICE), "22" 130 }; 131 132 /** 133 * @param psm (16) 134 */ 135 const hci_cmd_t l2cap_unregister_service_cmd = { 136 OPCODE(OGF_BTSTACK, L2CAP_UNREGISTER_SERVICE), "2" 137 }; 138 139 /** 140 * @param source_cid (16) 141 */ 142 const hci_cmd_t l2cap_accept_connection_cmd = { 143 OPCODE(OGF_BTSTACK, L2CAP_ACCEPT_CONNECTION), "2" 144 }; 145 146 /** 147 * @param source_cid (16) 148 * @param reason (deprecated) 149 */ 150 const hci_cmd_t l2cap_decline_connection_cmd = { 151 OPCODE(OGF_BTSTACK, L2CAP_DECLINE_CONNECTION), "21" 152 }; 153 154 155 /** 156 * @param service_record 157 */ 158 const hci_cmd_t sdp_register_service_record_cmd = { 159 OPCODE(OGF_BTSTACK, SDP_REGISTER_SERVICE_RECORD), "S" 160 }; 161 162 /** 163 * @param service_record_handle 164 */ 165 const hci_cmd_t sdp_unregister_service_record_cmd = { 166 OPCODE(OGF_BTSTACK, SDP_UNREGISTER_SERVICE_RECORD), "4" 167 }; 168 169 /** 170 * @param bd_addr 171 * @param service_search_pattern 172 */ 173 const hci_cmd_t sdp_client_query_rfcomm_services_cmd = { 174 OPCODE(OGF_BTSTACK, SDP_CLIENT_QUERY_RFCOMM_SERVICES), "BS" 175 }; 176 177 /** 178 * @param bd_addr 179 * @param service_search_pattern 180 * @param attribute_ID_list 181 */ 182 const hci_cmd_t sdp_client_query_services_cmd = { 183 OPCODE(OGF_BTSTACK, SDP_CLIENT_QUERY_SERVICES), "BSS" 184 }; 185 186 /** 187 * @param bd_addr 188 * @param server_channel 189 */ 190 const hci_cmd_t rfcomm_create_channel_cmd = { 191 OPCODE(OGF_BTSTACK, RFCOMM_CREATE_CHANNEL), "B1" 192 }; 193 194 /** 195 * @param bd_addr 196 * @param server_channel 197 * @param mtu 198 * @param credits 199 */ 200 const hci_cmd_t rfcomm_create_channel_with_initial_credits_cmd = { 201 OPCODE(OGF_BTSTACK, RFCOMM_CREATE_CHANNEL_WITH_CREDITS), "B121" 202 }; 203 204 /** 205 * @param rfcomm_cid 206 * @param credits 207 */ 208 const hci_cmd_t rfcomm_grants_credits_cmd = { 209 OPCODE(OGF_BTSTACK, RFCOMM_GRANT_CREDITS), "21" 210 }; 211 212 /** 213 * @param rfcomm_cid 214 * @param reason 215 */ 216 const hci_cmd_t rfcomm_disconnect_cmd = { 217 OPCODE(OGF_BTSTACK, RFCOMM_DISCONNECT), "21" 218 }; 219 220 /** 221 * @param server_channel 222 * @param mtu 223 */ 224 const hci_cmd_t rfcomm_register_service_cmd = { 225 OPCODE(OGF_BTSTACK, RFCOMM_REGISTER_SERVICE), "12" 226 }; 227 228 /** 229 * @param server_channel 230 * @param mtu 231 * @param initial_credits 232 */ 233 const hci_cmd_t rfcomm_register_service_with_initial_credits_cmd = { 234 OPCODE(OGF_BTSTACK, RFCOMM_REGISTER_SERVICE_WITH_CREDITS), "121" 235 }; 236 237 /** 238 * @param service_channel 239 */ 240 const hci_cmd_t rfcomm_unregister_service_cmd = { 241 OPCODE(OGF_BTSTACK, RFCOMM_UNREGISTER_SERVICE), "2" 242 }; 243 244 /** 245 * @param source_cid 246 */ 247 const hci_cmd_t rfcomm_accept_connection_cmd = { 248 OPCODE(OGF_BTSTACK, RFCOMM_ACCEPT_CONNECTION), "2" 249 }; 250 251 252 /** 253 * @param source_cid 254 * @param reason 255 */ 256 const hci_cmd_t rfcomm_decline_connection_cmd = { 257 OPCODE(OGF_BTSTACK, RFCOMM_DECLINE_CONNECTION), "21" 258 }; 259 260 // request persistent rfcomm channel number for named service 261 /** 262 * @param named_service 263 */ 264 const hci_cmd_t rfcomm_persistent_channel_for_service_cmd = { 265 OPCODE(OGF_BTSTACK, RFCOMM_PERSISTENT_CHANNEL), "N" 266 }; 267 268 /** 269 * @param handle 270 */ 271 const hci_cmd_t gap_disconnect_cmd = { 272 OPCODE(OGF_BTSTACK, GAP_DISCONNECT), "H" 273 }; 274 275 /** 276 */ 277 const hci_cmd_t gap_le_scan_start = { 278 OPCODE(OGF_BTSTACK, GAP_LE_SCAN_START), "" 279 }; 280 281 /** 282 */ 283 const hci_cmd_t gap_le_scan_stop = { 284 OPCODE(OGF_BTSTACK, GAP_LE_SCAN_STOP), "" 285 }; 286 287 /** 288 * @param scan_type 289 * @param scan_interval 290 * @param scan_window 291 */ 292 const hci_cmd_t gap_le_set_scan_parameters = { 293 OPCODE(OGF_BTSTACK, GAP_LE_SET_SCAN_PARAMETERS), "122" 294 }; 295 296 /** 297 * @param peer_address_type 298 * @param peer_address 299 */ 300 const hci_cmd_t gap_le_connect_cmd = { 301 OPCODE(OGF_BTSTACK, GAP_LE_CONNECT), "1B" 302 }; 303 304 /** 305 * @param peer_address_type 306 * @param peer_address 307 */ 308 const hci_cmd_t gap_le_connect_cancel_cmd = { 309 OPCODE(OGF_BTSTACK, GAP_LE_CONNECT_CANCEL), "" 310 }; 311 312 /** 313 * @param handle 314 */ 315 const hci_cmd_t gatt_discover_primary_services_cmd = { 316 OPCODE(OGF_BTSTACK, GATT_DISCOVER_ALL_PRIMARY_SERVICES), "H" 317 }; 318 319 /** 320 * @param handle 321 * @param uuid16 322 */ 323 const hci_cmd_t gatt_discover_primary_services_by_uuid16_cmd = { 324 OPCODE(OGF_BTSTACK, GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID16), "H2" 325 }; 326 327 /** 328 * @param handle 329 * @param uuid128 330 */ 331 const hci_cmd_t gatt_discover_primary_services_by_uuid128_cmd = { 332 OPCODE(OGF_BTSTACK, GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID128), "HU" 333 }; 334 335 /** 336 * @param handle 337 * @param service 338 */ 339 const hci_cmd_t gatt_find_included_services_for_service_cmd = { 340 OPCODE(OGF_BTSTACK, GATT_FIND_INCLUDED_SERVICES_FOR_SERVICE), "HX" 341 }; 342 343 /** 344 * @param handle 345 * @param service 346 */ 347 const hci_cmd_t gatt_discover_characteristics_for_service_cmd = { 348 OPCODE(OGF_BTSTACK, GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE), "HX" 349 }; 350 351 /** 352 * @param handle 353 * @param service 354 * @param uuid128 355 */ 356 const hci_cmd_t gatt_discover_characteristics_for_service_by_uuid128_cmd = { 357 OPCODE(OGF_BTSTACK, GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID128), "HXU" 358 }; 359 360 /** 361 * @param handle 362 * @param characteristic 363 */ 364 const hci_cmd_t gatt_discover_characteristic_descriptors_cmd = { 365 OPCODE(OGF_BTSTACK, GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS), "HY" 366 }; 367 368 /** 369 * @param handle 370 * @param characteristic 371 */ 372 const hci_cmd_t gatt_read_value_of_characteristic_cmd = { 373 OPCODE(OGF_BTSTACK, GATT_READ_VALUE_OF_CHARACTERISTIC), "HY" 374 }; 375 376 /** 377 * @param handle 378 * @param characteristic 379 */ 380 const hci_cmd_t gatt_read_long_value_of_characteristic_cmd = { 381 OPCODE(OGF_BTSTACK, GATT_READ_LONG_VALUE_OF_CHARACTERISTIC), "HY" 382 }; 383 384 /** 385 * @param handle 386 * @param characteristic 387 * @param data_length 388 * @param data 389 */ 390 const hci_cmd_t gatt_write_value_of_characteristic_without_response_cmd = { 391 OPCODE(OGF_BTSTACK, GATT_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE), "HYLV" 392 }; 393 394 /** 395 * @param handle 396 * @param characteristic 397 * @param data_length 398 * @param data 399 */ 400 const hci_cmd_t gatt_write_value_of_characteristic_cmd = { 401 OPCODE(OGF_BTSTACK, GATT_WRITE_VALUE_OF_CHARACTERISTIC), "HYLV" 402 }; 403 404 /** 405 * @param handle 406 * @param characteristic 407 * @param data_length 408 * @param data 409 */ 410 const hci_cmd_t gatt_write_long_value_of_characteristic_cmd = { 411 OPCODE(OGF_BTSTACK, GATT_WRITE_LONG_VALUE_OF_CHARACTERISTIC), "HYLV" 412 }; 413 414 /** 415 * @param handle 416 * @param characteristic 417 * @param data_length 418 * @param data 419 */ 420 const hci_cmd_t gatt_reliable_write_long_value_of_characteristic_cmd = { 421 OPCODE(OGF_BTSTACK, GATT_RELIABLE_WRITE_LONG_VALUE_OF_CHARACTERISTIC), "HYLV" 422 }; 423 424 /** 425 * @param handle 426 * @param descriptor 427 */ 428 const hci_cmd_t gatt_read_characteristic_descriptor_cmd = { 429 OPCODE(OGF_BTSTACK, GATT_READ_CHARACTERISTIC_DESCRIPTOR), "HZ" 430 }; 431 432 /** 433 * @param handle 434 * @param descriptor 435 */ 436 const hci_cmd_t gatt_read_long_characteristic_descriptor_cmd = { 437 OPCODE(OGF_BTSTACK, GATT_READ_LONG_CHARACTERISTIC_DESCRIPTOR), "HZ" 438 }; 439 440 /** 441 * @param handle 442 * @param descriptor 443 * @param data_length 444 * @param data 445 */ 446 const hci_cmd_t gatt_write_characteristic_descriptor_cmd = { 447 OPCODE(OGF_BTSTACK, GATT_WRITE_CHARACTERISTIC_DESCRIPTOR), "HZLV" 448 }; 449 450 /** 451 * @param handle 452 * @param descriptor 453 * @param data_length 454 * @param data 455 */ 456 const hci_cmd_t gatt_write_long_characteristic_descriptor_cmd = { 457 OPCODE(OGF_BTSTACK, GATT_WRITE_LONG_CHARACTERISTIC_DESCRIPTOR), "HZLV" 458 }; 459 460 /** 461 * @param handle 462 * @param characteristic 463 * @param configuration 464 */ 465 const hci_cmd_t gatt_write_client_characteristic_configuration_cmd = { 466 OPCODE(OGF_BTSTACK, GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION), "HY2" 467 }; 468 469 /** 470 * @param handle 471 */ 472 const hci_cmd_t gatt_get_mtu = { 473 OPCODE(OGF_BTSTACK, GATT_GET_MTU), "H" 474 }; 475