xref: /btstack/platform/daemon/src/daemon_cmds.c (revision f25e60dece291970e0c7612fc7fda3d74ae3ceba)
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  * @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  * @param bd_addr
314  * @param pin_length
315  * @param pin (c-string)
316  */
317 const hci_cmd_t gap_pin_code_response_cmd = {
318     DAEMON_OPCODE_GAP_PIN_CODE_RESPONSE, "B1P"
319 };
320 
321 /**
322  * @param bd_addr
323  */
324 const hci_cmd_t gap_pin_code_negative_cmd = {
325     DAEMON_OPCODE_GAP_PIN_CODE_NEGATIVE, "B"
326 };
327 
328 
329 /**
330  */
331 const hci_cmd_t gap_le_scan_start = {
332     DAEMON_OPCODE_GAP_LE_SCAN_START, ""
333 };
334 
335 /**
336  */
337 const hci_cmd_t gap_le_scan_stop = {
338     DAEMON_OPCODE_GAP_LE_SCAN_STOP, ""
339 };
340 
341 /**
342  * @param scan_type
343  * @param scan_interval
344  * @param scan_window
345  */
346 const hci_cmd_t gap_le_set_scan_parameters = {
347     DAEMON_OPCODE_GAP_LE_SET_SCAN_PARAMETERS, "122"
348 };
349 
350 /**
351  * @param peer_address_type
352  * @param peer_address
353  */
354 const hci_cmd_t gap_le_connect_cmd = {
355     DAEMON_OPCODE_GAP_LE_CONNECT, "1B"
356 };
357 
358 /**
359  * @param peer_address_type
360  * @param peer_address
361  */
362 const hci_cmd_t gap_le_connect_cancel_cmd = {
363     DAEMON_OPCODE_GAP_LE_CONNECT_CANCEL, ""
364 };
365 
366 /**
367  * @param handle
368  */
369 const hci_cmd_t gatt_discover_primary_services_cmd = {
370     DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES, "H"
371 };
372 
373 /**
374  * @param handle
375  * @param uuid16
376  */
377 const hci_cmd_t gatt_discover_primary_services_by_uuid16_cmd = {
378     DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID16, "H2"
379 };
380 
381 /**
382  * @param handle
383  * @param uuid128
384  */
385 const hci_cmd_t gatt_discover_primary_services_by_uuid128_cmd = {
386     DAEMON_OPCODE_GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID128, "HU"
387 };
388 
389 /**
390  * @param handle
391  * @param service
392  */
393 const hci_cmd_t gatt_find_included_services_for_service_cmd = {
394     DAEMON_OPCODE_GATT_FIND_INCLUDED_SERVICES_FOR_SERVICE, "HX"
395 };
396 
397 /**
398  * @param handle
399  * @param service
400  */
401 const hci_cmd_t gatt_discover_characteristics_for_service_cmd = {
402     DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE, "HX"
403 };
404 
405 /**
406  * @param handle
407  * @param service
408  * @param uuid128
409  */
410 const hci_cmd_t gatt_discover_characteristics_for_service_by_uuid128_cmd = {
411     DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID128, "HXU"
412 };
413 
414 /**
415  * @param handle
416  * @param characteristic
417  */
418 const hci_cmd_t gatt_discover_characteristic_descriptors_cmd = {
419     DAEMON_OPCODE_GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS, "HY"
420 };
421 
422 /**
423  * @param handle
424  * @param characteristic
425  */
426 const hci_cmd_t gatt_read_value_of_characteristic_cmd = {
427     DAEMON_OPCODE_GATT_READ_VALUE_OF_CHARACTERISTIC, "HY"
428 };
429 
430 /**
431  * @param handle
432  * @param characteristic
433  */
434 const hci_cmd_t gatt_read_long_value_of_characteristic_cmd = {
435     DAEMON_OPCODE_GATT_READ_LONG_VALUE_OF_CHARACTERISTIC, "HY"
436 };
437 
438 /**
439  * @param handle
440  * @param characteristic
441  * @param data_length
442  * @param data
443  */
444 const hci_cmd_t gatt_write_value_of_characteristic_without_response_cmd = {
445     DAEMON_OPCODE_GATT_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE, "HYLV"
446 };
447 
448 /**
449  * @param handle
450  * @param characteristic
451  * @param data_length
452  * @param data
453  */
454 const hci_cmd_t gatt_write_value_of_characteristic_cmd = {
455     DAEMON_OPCODE_GATT_WRITE_VALUE_OF_CHARACTERISTIC, "HYLV"
456 };
457 
458 /**
459  * @param handle
460  * @param characteristic
461  * @param data_length
462  * @param data
463  */
464 const hci_cmd_t gatt_write_long_value_of_characteristic_cmd = {
465     DAEMON_OPCODE_GATT_WRITE_LONG_VALUE_OF_CHARACTERISTIC, "HYLV"
466 };
467 
468 /**
469  * @param handle
470  * @param characteristic
471  * @param data_length
472  * @param data
473  */
474 const hci_cmd_t gatt_reliable_write_long_value_of_characteristic_cmd = {
475     DAEMON_OPCODE_GATT_RELIABLE_WRITE_LONG_VALUE_OF_CHARACTERISTIC, "HYLV"
476 };
477 
478 /**
479  * @param handle
480  * @param descriptor
481  */
482 const hci_cmd_t gatt_read_characteristic_descriptor_cmd = {
483     DAEMON_OPCODE_GATT_READ_CHARACTERISTIC_DESCRIPTOR, "HZ"
484 };
485 
486 /**
487  * @param handle
488  * @param descriptor
489  */
490 const hci_cmd_t gatt_read_long_characteristic_descriptor_cmd = {
491     DAEMON_OPCODE_GATT_READ_LONG_CHARACTERISTIC_DESCRIPTOR, "HZ"
492 };
493 
494 /**
495  * @param handle
496  * @param descriptor
497  * @param data_length
498  * @param data
499  */
500 const hci_cmd_t gatt_write_characteristic_descriptor_cmd = {
501     DAEMON_OPCODE_GATT_WRITE_CHARACTERISTIC_DESCRIPTOR, "HZLV"
502 };
503 
504 /**
505  * @param handle
506  * @param descriptor
507  * @param data_length
508  * @param data
509  */
510 const hci_cmd_t gatt_write_long_characteristic_descriptor_cmd = {
511     DAEMON_OPCODE_GATT_WRITE_LONG_CHARACTERISTIC_DESCRIPTOR, "HZLV"
512 };
513 
514 /**
515  * @param handle
516  * @param characteristic
517  * @param configuration
518  */
519 const hci_cmd_t gatt_write_client_characteristic_configuration_cmd = {
520     DAEMON_OPCODE_GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, "HY2"
521 };
522 
523 /**
524  * @param handle
525  */
526 const hci_cmd_t gatt_get_mtu = {
527     DAEMON_OPCODE_GATT_GET_MTU, "H"
528 };
529 
530 /**
531  * @brief Sets the requested authentication requirements, bonding yes/no, MITM yes/no, SC yes/no, keypress yes/no
532  * @param auth_req OR combination of SM_AUTHREQ_ flags
533  */
534 const hci_cmd_t sm_set_authentication_requirements_cmd = {
535     DAEMON_OPCODE_SM_SET_AUTHENTICATION_REQUIREMENTS, "1"
536 };
537 
538 /**
539  * @brief Sets the available IO Capabilities
540  * @param io_capabilities
541  */
542 const hci_cmd_t sm_set_io_capabilities_cmd = {
543     DAEMON_OPCODE_SM_SET_IO_CAPABILITIES, "1"
544 };
545 
546 /**
547  * @brief Decline bonding triggered by event before
548  * @param con_handle
549  */
550 const hci_cmd_t sm_bonding_decline_cmd = {
551     DAEMON_OPCODE_SM_BONDING_DECLINE, "H"
552 };
553 
554 /**
555  * @brief Confirm Just Works bonding
556  * @param con_handle
557  */
558 const hci_cmd_t sm_just_works_confirm_cmd = {
559     DAEMON_OPCODE_SM_JUST_WORKS_CONFIRM, "H"
560 };
561 
562 /**
563  * @brief Confirm value from SM_EVENT_NUMERIC_COMPARISON_REQUEST for Numeric Comparison bonding
564  * @param con_handle
565  */
566 const hci_cmd_t sm_numeric_comparison_confirm_cmd = {
567     DAEMON_OPCODE_SM_NUMERIC_COMPARISON_CONFIRM, "H"
568 };
569 
570 /**
571  * @brief Reports passkey input by user
572  * @param con_handle
573  * @param passkey in [0..999999]
574  */
575 const hci_cmd_t sm_passkey_input_cmd = {
576     DAEMON_OPCODE_SM_PASSKEY_INPUT, "H4"
577 };
578