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