xref: /btstack/platform/daemon/src/daemon_cmds.c (revision 6e7533547b03da0aff8f9952b29113dd77a7ef60)
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 BLUEKITCHEN
24  * GMBH 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  */
121 const hci_cmd_t l2cap_disconnect_cmd = {
122     DAEMON_OPCODE_L2CAP_DISCONNECT, "2"
123 };
124 
125 /**
126  * @param psm (16)
127  * @param mtu (16)
128  */
129 const hci_cmd_t l2cap_register_service_cmd = {
130     DAEMON_OPCODE_L2CAP_REGISTER_SERVICE, "22"
131 };
132 
133 /**
134  * @param psm (16)
135  */
136 const hci_cmd_t l2cap_unregister_service_cmd = {
137     DAEMON_OPCODE_L2CAP_UNREGISTER_SERVICE, "2"
138 };
139 
140 /**
141  * @param source_cid (16)
142  */
143 const hci_cmd_t l2cap_accept_connection_cmd = {
144     DAEMON_OPCODE_L2CAP_ACCEPT_CONNECTION, "2"
145 };
146 
147 /**
148  * @param source_cid (16)
149  * @param reason (deprecated)
150  */
151 const hci_cmd_t l2cap_decline_connection_cmd = {
152     DAEMON_OPCODE_L2CAP_DECLINE_CONNECTION, "21"
153 };
154 
155 /**
156  * @param l2cap_cid
157  */
158 const hci_cmd_t l2cap_request_can_send_now_cmd = {
159     DAEMON_OPCODE_L2CAP_REQUEST_CAN_SEND_NOW, "2"
160 };
161 
162 /**
163  * @param service_record
164  */
165 const hci_cmd_t sdp_register_service_record_cmd = {
166     DAEMON_OPCODE_SDP_REGISTER_SERVICE_RECORD, "S"
167 };
168 
169 /**
170  * @param service_record_handle
171  */
172 const hci_cmd_t sdp_unregister_service_record_cmd = {
173     DAEMON_OPCODE_SDP_UNREGISTER_SERVICE_RECORD, "4"
174 };
175 
176 /**
177  * @param bd_addr
178  * @param service_search_pattern
179  */
180 const hci_cmd_t sdp_client_query_rfcomm_services_cmd = {
181     DAEMON_OPCODE_SDP_CLIENT_QUERY_RFCOMM_SERVICES, "BS"
182 };
183 
184 /**
185  * @param bd_addr
186  * @param service_search_pattern
187  * @param attribute_ID_list
188  */
189 const hci_cmd_t sdp_client_query_services_cmd = {
190     DAEMON_OPCODE_SDP_CLIENT_QUERY_SERVICES, "BSS"
191 };
192 
193 /**
194  * @param bd_addr
195  * @param server_channel
196  */
197 const hci_cmd_t rfcomm_create_channel_cmd = {
198     DAEMON_OPCODE_RFCOMM_CREATE_CHANNEL, "B1"
199 };
200 
201 /**
202  * @param bd_addr
203  * @param server_channel
204  * @param mtu
205  * @param credits
206  */
207 const hci_cmd_t rfcomm_create_channel_with_initial_credits_cmd = {
208     DAEMON_OPCODE_RFCOMM_CREATE_CHANNEL_WITH_INITIAL_CREDITS, "B121"
209 };
210 
211 /**
212  * @param rfcomm_cid
213  * @param credits
214  */
215 const hci_cmd_t rfcomm_grants_credits_cmd = {
216     DAEMON_OPCODE_RFCOMM_GRANTS_CREDITS, "21"
217 };
218 
219 /**
220  * @param rfcomm_cid
221  * @param reason
222  */
223 const hci_cmd_t rfcomm_disconnect_cmd = {
224     DAEMON_OPCODE_RFCOMM_DISCONNECT, "21"
225 };
226 
227 /**
228  * @param server_channel
229  * @param mtu
230  */
231 const hci_cmd_t rfcomm_register_service_cmd = {
232     DAEMON_OPCODE_RFCOMM_REGISTER_SERVICE, "12"
233 };
234 
235 /**
236  * @param server_channel
237  * @param mtu
238  * @param initial_credits
239  */
240 const hci_cmd_t rfcomm_register_service_with_initial_credits_cmd = {
241     DAEMON_OPCODE_RFCOMM_REGISTER_SERVICE_WITH_INITIAL_CREDITS, "121"
242 };
243 
244 /**
245  * @param service_channel
246  */
247 const hci_cmd_t rfcomm_unregister_service_cmd = {
248     DAEMON_OPCODE_RFCOMM_UNREGISTER_SERVICE, "2"
249 };
250 
251 /**
252  * @param source_cid
253  */
254 const hci_cmd_t rfcomm_accept_connection_cmd = {
255     DAEMON_OPCODE_RFCOMM_ACCEPT_CONNECTION, "2"
256 };
257 
258 
259 /**
260  * @param source_cid
261  * @param reason
262  */
263 const hci_cmd_t rfcomm_decline_connection_cmd = {
264     DAEMON_OPCODE_RFCOMM_DECLINE_CONNECTION, "21"
265 };
266 
267 // request persistent rfcomm channel number for named service
268 /**
269  * @param named_service
270  */
271 const hci_cmd_t rfcomm_persistent_channel_for_service_cmd = {
272     DAEMON_OPCODE_RFCOMM_PERSISTENT_CHANNEL_FOR_SERVICE, "N"
273 };
274 
275 /**
276  * @param rfcomm_cid
277  */
278 const hci_cmd_t rfcomm_request_can_send_now_cmd = {
279     DAEMON_OPCODE_RFCOMM_REQUEST_CAN_SEND_NOW, "2"
280 };
281 
282 /**
283  * @param handle
284  */
285 const hci_cmd_t gap_disconnect_cmd = {
286     DAEMON_OPCODE_GAP_DISCONNECT, "H"
287 };
288 
289 /**
290  * @param duration in 1.28s units
291  */
292 const hci_cmd_t gap_inquiry_start_cmd = {
293     DAEMON_OPCODE_GAP_INQUIRY_START, "1"
294 };
295 
296 /**
297  */
298 const hci_cmd_t gap_inquiry_stop_cmd = {
299     DAEMON_OPCODE_GAP_INQUIRY_STOP, ""
300 };
301 
302 /**
303 * @param addr
304 * @param page_scan_repetition_mode
305 * @param clock_offset only used when bit 15 is set - pass 0 if not known
306  */
307 const hci_cmd_t gap_remote_name_request_cmd = {
308     DAEMON_OPCODE_GAP_REMOTE_NAME_REQUEST, "B12"
309 };
310 
311 /**
312 * @param addr
313  */
314 const hci_cmd_t gap_drop_link_key_cmd = {
315     DAEMON_OPCODE_GAP_DROP_LINK_KEY_FOR_BD_ADDR, "B"
316 };
317 
318 /**
319  */
320 const hci_cmd_t gap_delete_all_link_keys_cmd = {
321     DAEMON_OPCODE_GAP_DELETE_ALL_LINK_KEYS, ""
322 };
323 
324 /**
325  * @param bd_addr
326  * @param pin_length
327  * @param pin (c-string)
328  */
329 const hci_cmd_t gap_pin_code_response_cmd = {
330     DAEMON_OPCODE_GAP_PIN_CODE_RESPONSE, "B1P"
331 };
332 
333 /**
334  * @param bd_addr
335  */
336 const hci_cmd_t gap_pin_code_negative_cmd = {
337     DAEMON_OPCODE_GAP_PIN_CODE_NEGATIVE, "B"
338 };
339 
340 
341 /**
342  */
343 const hci_cmd_t gap_le_scan_start = {
344     DAEMON_OPCODE_GAP_LE_SCAN_START, ""
345 };
346 
347 /**
348  */
349 const hci_cmd_t gap_le_scan_stop = {
350     DAEMON_OPCODE_GAP_LE_SCAN_STOP, ""
351 };
352 
353 /**
354  * @param scan_type
355  * @param scan_interval
356  * @param scan_window
357  */
358 const hci_cmd_t gap_le_set_scan_parameters = {
359     DAEMON_OPCODE_GAP_LE_SET_SCAN_PARAMETERS, "122"
360 };
361 
362 /**
363  * @param peer_address_type
364  * @param peer_address
365  */
366 const hci_cmd_t gap_le_connect_cmd = {
367     DAEMON_OPCODE_GAP_LE_CONNECT, "1B"
368 };
369 
370 /**
371  * @param peer_address_type
372  * @param peer_address
373  */
374 const hci_cmd_t gap_le_connect_cancel_cmd = {
375     DAEMON_OPCODE_GAP_LE_CONNECT_CANCEL, ""
376 };
377 
378 /**
379  * @param handle
380  */
381 const hci_cmd_t gatt_discover_primary_services_cmd = {
382     DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES, "H"
383 };
384 
385 /**
386  * @param handle
387  * @param uuid16
388  */
389 const hci_cmd_t gatt_discover_primary_services_by_uuid16_cmd = {
390     DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID16, "H2"
391 };
392 
393 /**
394  * @param handle
395  * @param uuid128
396  */
397 const hci_cmd_t gatt_discover_primary_services_by_uuid128_cmd = {
398     DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID128, "HU"
399 };
400 
401 /**
402  * @param handle
403  * @param service
404  */
405 const hci_cmd_t gatt_find_included_services_for_service_cmd = {
406     DAEMON_OPCODE_GATT_FIND_INCLUDED_SERVICES_FOR_SERVICE, "HX"
407 };
408 
409 /**
410  * @param handle
411  * @param service
412  */
413 const hci_cmd_t gatt_discover_characteristics_for_service_cmd = {
414     DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE, "HX"
415 };
416 
417 /**
418  * @param handle
419  * @param service
420  * @param uuid128
421  */
422 const hci_cmd_t gatt_discover_characteristics_for_service_by_uuid128_cmd = {
423     DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID128, "HXU"
424 };
425 
426 /**
427  * @param handle
428  * @param characteristic
429  */
430 const hci_cmd_t gatt_discover_characteristic_descriptors_cmd = {
431     DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS, "HY"
432 };
433 
434 /**
435  * @param handle
436  * @param characteristic
437  */
438 const hci_cmd_t gatt_read_value_of_characteristic_cmd = {
439     DAEMON_OPCODE_GATT_READ_VALUE_OF_CHARACTERISTIC, "HY"
440 };
441 
442 /**
443  * @param handle
444  * @param characteristic
445  */
446 const hci_cmd_t gatt_read_long_value_of_characteristic_cmd = {
447     DAEMON_OPCODE_GATT_READ_LONG_VALUE_OF_CHARACTERISTIC, "HY"
448 };
449 
450 /**
451  * @param handle
452  * @param characteristic
453  * @param data_length
454  * @param data
455  */
456 const hci_cmd_t gatt_write_value_of_characteristic_without_response_cmd = {
457     DAEMON_OPCODE_GATT_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE, "HYLV"
458 };
459 
460 /**
461  * @param handle
462  * @param characteristic
463  * @param data_length
464  * @param data
465  */
466 const hci_cmd_t gatt_write_value_of_characteristic_cmd = {
467     DAEMON_OPCODE_GATT_WRITE_VALUE_OF_CHARACTERISTIC, "HYLV"
468 };
469 
470 /**
471  * @param handle
472  * @param characteristic
473  * @param data_length
474  * @param data
475  */
476 const hci_cmd_t gatt_write_long_value_of_characteristic_cmd = {
477     DAEMON_OPCODE_GATT_WRITE_LONG_VALUE_OF_CHARACTERISTIC, "HYLV"
478 };
479 
480 /**
481  * @param handle
482  * @param characteristic
483  * @param data_length
484  * @param data
485  */
486 const hci_cmd_t gatt_reliable_write_long_value_of_characteristic_cmd = {
487     DAEMON_OPCODE_GATT_RELIABLE_WRITE_LONG_VALUE_OF_CHARACTERISTIC, "HYLV"
488 };
489 
490 /**
491  * @param handle
492  * @param descriptor
493  */
494 const hci_cmd_t gatt_read_characteristic_descriptor_cmd = {
495     DAEMON_OPCODE_GATT_READ_CHARACTERISTIC_DESCRIPTOR, "HZ"
496 };
497 
498 /**
499  * @param handle
500  * @param descriptor
501  */
502 const hci_cmd_t gatt_read_long_characteristic_descriptor_cmd = {
503     DAEMON_OPCODE_GATT_READ_LONG_CHARACTERISTIC_DESCRIPTOR, "HZ"
504 };
505 
506 /**
507  * @param handle
508  * @param descriptor
509  * @param data_length
510  * @param data
511  */
512 const hci_cmd_t gatt_write_characteristic_descriptor_cmd = {
513     DAEMON_OPCODE_GATT_WRITE_CHARACTERISTIC_DESCRIPTOR, "HZLV"
514 };
515 
516 /**
517  * @param handle
518  * @param descriptor
519  * @param data_length
520  * @param data
521  */
522 const hci_cmd_t gatt_write_long_characteristic_descriptor_cmd = {
523     DAEMON_OPCODE_GATT_WRITE_LONG_CHARACTERISTIC_DESCRIPTOR, "HZLV"
524 };
525 
526 /**
527  * @param handle
528  * @param characteristic
529  * @param configuration
530  */
531 const hci_cmd_t gatt_write_client_characteristic_configuration_cmd = {
532     DAEMON_OPCODE_GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, "HY2"
533 };
534 
535 /**
536  * @param handle
537  */
538 const hci_cmd_t gatt_get_mtu = {
539     DAEMON_OPCODE_GATT_GET_MTU, "H"
540 };
541 
542 /**
543  * @brief Sets the requested authentication requirements, bonding yes/no, MITM yes/no, SC yes/no, keypress yes/no
544  * @param auth_req OR combination of SM_AUTHREQ_ flags
545  */
546 const hci_cmd_t sm_set_authentication_requirements_cmd = {
547     DAEMON_OPCODE_SM_SET_AUTHENTICATION_REQUIREMENTS, "1"
548 };
549 
550 /**
551  * @brief Sets the available IO Capabilities
552  * @param io_capabilities
553  */
554 const hci_cmd_t sm_set_io_capabilities_cmd = {
555     DAEMON_OPCODE_SM_SET_IO_CAPABILITIES, "1"
556 };
557 
558 /**
559  * @brief Decline bonding triggered by event before
560  * @param con_handle
561  */
562 const hci_cmd_t sm_bonding_decline_cmd = {
563     DAEMON_OPCODE_SM_BONDING_DECLINE, "H"
564 };
565 
566 /**
567  * @brief Confirm Just Works bonding
568  * @param con_handle
569  */
570 const hci_cmd_t sm_just_works_confirm_cmd = {
571     DAEMON_OPCODE_SM_JUST_WORKS_CONFIRM, "H"
572 };
573 
574 /**
575  * @brief Confirm value from SM_EVENT_NUMERIC_COMPARISON_REQUEST for Numeric Comparison bonding
576  * @param con_handle
577  */
578 const hci_cmd_t sm_numeric_comparison_confirm_cmd = {
579     DAEMON_OPCODE_SM_NUMERIC_COMPARISON_CONFIRM, "H"
580 };
581 
582 /**
583  * @brief Reports passkey input by user
584  * @param con_handle
585  * @param passkey in [0..999999]
586  */
587 const hci_cmd_t sm_passkey_input_cmd = {
588     DAEMON_OPCODE_SM_PASSKEY_INPUT, "H4"
589 };
590