3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/ioctl.h>
42 #include <sys/socket.h>
44 #include "bluetooth.h"
49 #define MIN(x, y) ((x) < (y) ? (x) : (y))
57 static char *hci_bit2str(hci_map *m, unsigned int val)
59 char *str = malloc(120);
67 if ((unsigned int) m->val & val)
68 ptr += sprintf(ptr, "%s ", m->str);
74 static int hci_str2bit(hci_map *map, char *str, unsigned int *val)
80 if (!str || !(str = ptr = strdup(str)))
85 while ((t = strsep(&ptr, ","))) {
86 for (m = map; m->str; m++) {
87 if (!strcasecmp(m->str, t)) {
88 *val |= (unsigned int) m->val;
98 static char *hci_uint2str(hci_map *m, unsigned int val)
100 char *str = malloc(50);
108 if ((unsigned int) m->val == val) {
109 ptr += sprintf(ptr, "%s", m->str);
117 static int hci_str2uint(hci_map *map, char *str, unsigned int *val)
126 str = ptr = strdup(str);
128 while ((t = strsep(&ptr, ","))) {
129 for (m = map; m->str; m++) {
130 if (!strcasecmp(m->str,t)) {
131 *val = (unsigned int) m->val;
142 char *hci_bustostr(int bus)
159 #ifdef __TIZEN_PATCH__
168 char *hci_dtypetostr(int type)
170 return hci_bustostr(type & 0x0f);
173 char *hci_typetostr(int type)
185 /* HCI dev flags mapping */
186 static hci_map dev_flags_map[] = {
188 { "INIT", HCI_INIT },
189 { "RUNNING", HCI_RUNNING },
191 { "PSCAN", HCI_PSCAN },
192 { "ISCAN", HCI_ISCAN },
193 { "INQUIRY", HCI_INQUIRY },
194 { "AUTH", HCI_AUTH },
195 { "ENCRYPT", HCI_ENCRYPT },
199 char *hci_dflagstostr(uint32_t flags)
201 char *str = bt_malloc(50);
203 hci_map *m = dev_flags_map;
210 if (!hci_test_bit(HCI_UP, &flags))
211 ptr += sprintf(ptr, "DOWN ");
214 if (hci_test_bit(m->val, &flags))
215 ptr += sprintf(ptr, "%s ", m->str);
221 /* HCI packet type mapping */
222 static hci_map pkt_type_map[] = {
232 { "2-DH1", HCI_2DH1 },
233 { "2-DH3", HCI_2DH3 },
234 { "2-DH5", HCI_2DH5 },
235 { "3-DH1", HCI_3DH1 },
236 { "3-DH3", HCI_3DH3 },
237 { "3-DH5", HCI_3DH5 },
241 static hci_map sco_ptype_map[] = {
248 { "2-EV3", HCI_2EV3 },
249 { "2-EV5", HCI_2EV5 },
250 { "3-EV3", HCI_3EV3 },
251 { "3-EV5", HCI_3EV5 },
255 char *hci_ptypetostr(unsigned int ptype)
257 return hci_bit2str(pkt_type_map, ptype);
260 int hci_strtoptype(char *str, unsigned int *val)
262 return hci_str2bit(pkt_type_map, str, val);
265 char *hci_scoptypetostr(unsigned int ptype)
267 return hci_bit2str(sco_ptype_map, ptype);
270 int hci_strtoscoptype(char *str, unsigned int *val)
272 return hci_str2bit(sco_ptype_map, str, val);
275 /* Link policy mapping */
276 static hci_map link_policy_map[] = {
278 { "RSWITCH", HCI_LP_RSWITCH },
279 { "HOLD", HCI_LP_HOLD },
280 { "SNIFF", HCI_LP_SNIFF },
281 { "PARK", HCI_LP_PARK },
285 char *hci_lptostr(unsigned int lp)
287 return hci_bit2str(link_policy_map, lp);
290 int hci_strtolp(char *str, unsigned int *val)
292 return hci_str2bit(link_policy_map, str, val);
295 /* Link mode mapping */
296 static hci_map link_mode_map[] = {
298 { "ACCEPT", HCI_LM_ACCEPT },
299 { "MASTER", HCI_LM_MASTER },
300 { "AUTH", HCI_LM_AUTH },
301 { "ENCRYPT", HCI_LM_ENCRYPT },
302 { "TRUSTED", HCI_LM_TRUSTED },
303 { "RELIABLE", HCI_LM_RELIABLE },
304 { "SECURE", HCI_LM_SECURE },
308 char *hci_lmtostr(unsigned int lm)
310 char *s, *str = bt_malloc(50);
315 if (!(lm & HCI_LM_MASTER))
316 strcpy(str, "SLAVE ");
318 s = hci_bit2str(link_mode_map, lm);
329 int hci_strtolm(char *str, unsigned int *val)
331 return hci_str2bit(link_mode_map, str, val);
334 /* Command mapping */
335 static hci_map commands_map[] = {
337 { "Inquiry Cancel", 1 },
338 { "Periodic Inquiry Mode", 2 },
339 { "Exit Periodic Inquiry Mode", 3 },
340 { "Create Connection", 4 },
342 { "Add SCO Connection", 6 },
343 { "Cancel Create Connection", 7 },
345 { "Accept Connection Request", 8 },
346 { "Reject Connection Request", 9 },
347 { "Link Key Request Reply", 10 },
348 { "Link Key Request Negative Reply", 11 },
349 { "PIN Code Request Reply", 12 },
350 { "PIN Code Request Negative Reply", 13 },
351 { "Change Connection Packet Type", 14 },
352 { "Authentication Requested", 15 },
354 { "Set Connection Encryption", 16 },
355 { "Change Connection Link Key", 17 },
356 { "Master Link Key", 18 },
357 { "Remote Name Request", 19 },
358 { "Cancel Remote Name Request", 20 },
359 { "Read Remote Supported Features", 21 },
360 { "Read Remote Extended Features", 22 },
361 { "Read Remote Version Information", 23 },
363 { "Read Clock Offset", 24 },
364 { "Read LMP Handle", 25 },
374 { "Sniff Mode", 34 },
375 { "Exit Sniff Mode", 35 },
376 { "Park State", 36 },
377 { "Exit Park State", 37 },
379 { "Role Discovery", 39 },
381 { "Switch Role", 40 },
382 { "Read Link Policy Settings", 41 },
383 { "Write Link Policy Settings", 42 },
384 { "Read Default Link Policy Settings", 43 },
385 { "Write Default Link Policy Settings", 44 },
386 { "Flow Specification", 45 },
387 { "Set Event Mask", 46 },
390 { "Set Event Filter", 48 },
392 { "Read PIN Type", 50 },
393 { "Write PIN Type", 51 },
394 { "Create New Unit Key", 52 },
395 { "Read Stored Link Key", 53 },
396 { "Write Stored Link Key", 54 },
397 { "Delete Stored Link Key", 55 },
399 { "Write Local Name", 56 },
400 { "Read Local Name", 57 },
401 { "Read Connection Accept Timeout", 58 },
402 { "Write Connection Accept Timeout", 59 },
403 { "Read Page Timeout", 60 },
404 { "Write Page Timeout", 61 },
405 { "Read Scan Enable", 62 },
406 { "Write Scan Enable", 63 },
408 { "Read Page Scan Activity", 64 },
409 { "Write Page Scan Activity", 65 },
410 { "Read Inquiry Scan Activity", 66 },
411 { "Write Inquiry Scan Activity", 67 },
412 { "Read Authentication Enable", 68 },
413 { "Write Authentication Enable", 69 },
414 { "Read Encryption Mode", 70 },
415 { "Write Encryption Mode", 71 },
417 { "Read Class Of Device", 72 },
418 { "Write Class Of Device", 73 },
419 { "Read Voice Setting", 74 },
420 { "Write Voice Setting", 75 },
421 { "Read Automatic Flush Timeout", 76 },
422 { "Write Automatic Flush Timeout", 77 },
423 { "Read Num Broadcast Retransmissions", 78 },
424 { "Write Num Broadcast Retransmissions", 79 },
426 { "Read Hold Mode Activity", 80 },
427 { "Write Hold Mode Activity", 81 },
428 { "Read Transmit Power Level", 82 },
429 { "Read Synchronous Flow Control Enable", 83 },
430 { "Write Synchronous Flow Control Enable", 84 },
431 { "Set Host Controller To Host Flow Control", 85 },
432 { "Host Buffer Size", 86 },
433 { "Host Number Of Completed Packets", 87 },
435 { "Read Link Supervision Timeout", 88 },
436 { "Write Link Supervision Timeout", 89 },
437 { "Read Number of Supported IAC", 90 },
438 { "Read Current IAC LAP", 91 },
439 { "Write Current IAC LAP", 92 },
440 { "Read Page Scan Period Mode", 93 },
441 { "Write Page Scan Period Mode", 94 },
442 { "Read Page Scan Mode", 95 },
444 { "Write Page Scan Mode", 96 },
445 { "Set AFH Channel Classification", 97 },
448 { "Read Inquiry Scan Type", 100 },
449 { "Write Inquiry Scan Type", 101 },
450 { "Read Inquiry Mode", 102 },
451 { "Write Inquiry Mode", 103 },
453 { "Read Page Scan Type", 104 },
454 { "Write Page Scan Type", 105 },
455 { "Read AFH Channel Assessment Mode", 106 },
456 { "Write AFH Channel Assessment Mode", 107 },
465 { "Read Local Version Information", 115 },
466 { "Read Local Supported Commands", 116 },
467 { "Read Local Supported Features", 117 },
468 { "Read Local Extended Features", 118 },
469 { "Read Buffer Size", 119 },
471 { "Read Country Code", 120 },
472 { "Read BD ADDR", 121 },
473 { "Read Failed Contact Counter", 122 },
474 { "Reset Failed Contact Counter", 123 },
475 { "Get Link Quality", 124 },
476 { "Read RSSI", 125 },
477 { "Read AFH Channel Map", 126 },
478 { "Read BD Clock", 127 },
480 { "Read Loopback Mode", 128 },
481 { "Write Loopback Mode", 129 },
482 { "Enable Device Under Test Mode", 130 },
483 { "Setup Synchronous Connection", 131 },
484 { "Accept Synchronous Connection", 132 },
485 { "Reject Synchronous Connection", 133 },
489 { "Read Extended Inquiry Response", 136 },
490 { "Write Extended Inquiry Response", 137 },
491 { "Refresh Encryption Key", 138 },
493 { "Sniff Subrating", 140 },
494 { "Read Simple Pairing Mode", 141 },
495 { "Write Simple Pairing Mode", 142 },
496 { "Read Local OOB Data", 143 },
498 { "Read Inquiry Response Transmit Power Level", 144 },
499 { "Write Inquiry Transmit Power Level", 145 },
500 { "Read Default Erroneous Data Reporting", 146 },
501 { "Write Default Erroneous Data Reporting", 147 },
505 { "IO Capability Request Reply", 151 },
507 { "User Confirmation Request Reply", 152 },
508 { "User Confirmation Request Negative Reply", 153 },
509 { "User Passkey Request Reply", 154 },
510 { "User Passkey Request Negative Reply", 155 },
511 { "Remote OOB Data Request Reply", 156 },
512 { "Write Simple Pairing Debug Mode", 157 },
513 { "Enhanced Flush", 158 },
514 { "Remote OOB Data Request Negative Reply", 159 },
518 { "Send Keypress Notification", 162 },
519 { "IO Capability Request Negative Reply", 163 },
520 { "Read Encryption Key Size", 164 },
525 { "Create Physical Link", 168 },
526 { "Accept Physical Link", 169 },
527 { "Disconnect Physical Link", 170 },
528 { "Create Logical Link", 171 },
529 { "Accept Logical Link", 172 },
530 { "Disconnect Logical Link", 173 },
531 { "Logical Link Cancel", 174 },
532 { "Flow Specification Modify", 175 },
534 { "Read Logical Link Accept Timeout", 176 },
535 { "Write Logical Link Accept Timeout", 177 },
536 { "Set Event Mask Page 2", 178 },
537 { "Read Location Data", 179 },
538 { "Write Location Data", 180 },
539 { "Read Local AMP Info", 181 },
540 { "Read Local AMP_ASSOC", 182 },
541 { "Write Remote AMP_ASSOC", 183 },
543 { "Read Flow Control Mode", 184 },
544 { "Write Flow Control Mode", 185 },
545 { "Read Data Block Size", 186 },
548 { "Enable AMP Receiver Reports", 189 },
549 { "AMP Test End", 190 },
550 { "AMP Test Command", 191 },
552 { "Read Enhanced Transmit Power Level", 192 },
554 { "Read Best Effort Flush Timeout", 194 },
555 { "Write Best Effort Flush Timeout", 195 },
556 { "Short Range Mode", 196 },
557 { "Read LE Host Support", 197 },
558 { "Write LE Host Support", 198 },
561 { "LE Set Event Mask", 200 },
562 { "LE Read Buffer Size", 201 },
563 { "LE Read Local Supported Features", 202 },
565 { "LE Set Random Address", 204 },
566 { "LE Set Advertising Parameters", 205 },
567 { "LE Read Advertising Channel TX Power", 206 },
568 { "LE Set Advertising Data", 207 },
570 { "LE Set Scan Response Data", 208 },
571 { "LE Set Advertise Enable", 209 },
572 { "LE Set Scan Parameters", 210 },
573 { "LE Set Scan Enable", 211 },
574 { "LE Create Connection", 212 },
575 { "LE Create Connection Cancel", 213 },
576 { "LE Read White List Size", 214 },
577 { "LE Clear White List", 215 },
579 { "LE Add Device To White List", 216 },
580 { "LE Remove Device From White List", 217 },
581 { "LE Connection Update", 218 },
582 { "LE Set Host Channel Classification", 219 },
583 { "LE Read Channel Map", 220 },
584 { "LE Read Remote Used Features", 221 },
585 { "LE Encrypt", 222 },
588 { "LE Start Encryption", 224 },
589 { "LE Long Term Key Request Reply", 225 },
590 { "LE Long Term Key Request Negative Reply", 226 },
591 { "LE Read Supported States", 227 },
592 { "LE Receiver Test", 228 },
593 { "LE Transmitter Test", 229 },
594 { "LE Test End", 230 },
595 #ifdef __TIZEN_PATCH__
596 { "LE Read Maximum Data Length", 231 },
605 char *hci_cmdtostr(unsigned int cmd)
607 return hci_uint2str(commands_map, cmd);
610 char *hci_commandstostr(uint8_t *commands, char *pref, int width)
612 unsigned int maxwidth = width - 3;
614 char *off, *ptr, *str;
620 if (commands[m->val / 8] & (1 << (m->val % 8)))
621 size += strlen(m->str) + (pref ? strlen(pref) : 0) + 3;
625 str = bt_malloc(size);
629 ptr = str; *ptr = '\0';
632 ptr += sprintf(ptr, "%s", pref);
639 if (commands[m->val / 8] & (1 << (m->val % 8))) {
640 if (strlen(off) + strlen(m->str) > maxwidth) {
641 ptr += sprintf(ptr, "\n%s", pref ? pref : "");
644 ptr += sprintf(ptr, "'%s' ", m->str);
652 /* Version mapping */
653 static hci_map ver_map[] = {
666 char *hci_vertostr(unsigned int ver)
668 return hci_uint2str(ver_map, ver);
671 int hci_strtover(char *str, unsigned int *ver)
673 return hci_str2uint(ver_map, str, ver);
676 char *lmp_vertostr(unsigned int ver)
678 return hci_uint2str(ver_map, ver);
681 int lmp_strtover(char *str, unsigned int *ver)
683 return hci_str2uint(ver_map, str, ver);
686 static hci_map pal_map[] = {
691 char *pal_vertostr(unsigned int ver)
693 return hci_uint2str(pal_map, ver);
696 int pal_strtover(char *str, unsigned int *ver)
698 return hci_str2uint(pal_map, str, ver);
701 /* LMP features mapping */
702 static hci_map lmp_features_map[8][9] = {
704 { "<3-slot packets>", LMP_3SLOT }, /* Bit 0 */
705 { "<5-slot packets>", LMP_5SLOT }, /* Bit 1 */
706 { "<encryption>", LMP_ENCRYPT }, /* Bit 2 */
707 { "<slot offset>", LMP_SOFFSET }, /* Bit 3 */
708 { "<timing accuracy>", LMP_TACCURACY }, /* Bit 4 */
709 { "<role switch>", LMP_RSWITCH }, /* Bit 5 */
710 { "<hold mode>", LMP_HOLD }, /* Bit 6 */
711 { "<sniff mode>", LMP_SNIFF }, /* Bit 7 */
715 { "<park state>", LMP_PARK }, /* Bit 0 */
716 { "<RSSI>", LMP_RSSI }, /* Bit 1 */
717 { "<channel quality>", LMP_QUALITY }, /* Bit 2 */
718 { "<SCO link>", LMP_SCO }, /* Bit 3 */
719 { "<HV2 packets>", LMP_HV2 }, /* Bit 4 */
720 { "<HV3 packets>", LMP_HV3 }, /* Bit 5 */
721 { "<u-law log>", LMP_ULAW }, /* Bit 6 */
722 { "<A-law log>", LMP_ALAW }, /* Bit 7 */
726 { "<CVSD>", LMP_CVSD }, /* Bit 0 */
727 { "<paging scheme>", LMP_PSCHEME }, /* Bit 1 */
728 { "<power control>", LMP_PCONTROL }, /* Bit 2 */
729 { "<transparent SCO>", LMP_TRSP_SCO }, /* Bit 3 */
730 { "<broadcast encrypt>",LMP_BCAST_ENC }, /* Bit 7 */
734 { "<no. 24>", 0x01 }, /* Bit 0 */
735 { "<EDR ACL 2 Mbps>", LMP_EDR_ACL_2M }, /* Bit 1 */
736 { "<EDR ACL 3 Mbps>", LMP_EDR_ACL_3M }, /* Bit 2 */
737 { "<enhanced iscan>", LMP_ENH_ISCAN }, /* Bit 3 */
738 { "<interlaced iscan>", LMP_ILACE_ISCAN }, /* Bit 4 */
739 { "<interlaced pscan>", LMP_ILACE_PSCAN }, /* Bit 5 */
740 { "<inquiry with RSSI>",LMP_RSSI_INQ }, /* Bit 6 */
741 { "<extended SCO>", LMP_ESCO }, /* Bit 7 */
745 { "<EV4 packets>", LMP_EV4 }, /* Bit 0 */
746 { "<EV5 packets>", LMP_EV5 }, /* Bit 1 */
747 { "<no. 34>", 0x04 }, /* Bit 2 */
748 { "<AFH cap. slave>", LMP_AFH_CAP_SLV }, /* Bit 3 */
749 { "<AFH class. slave>", LMP_AFH_CLS_SLV }, /* Bit 4 */
750 { "<BR/EDR not supp.>", LMP_NO_BREDR }, /* Bit 5 */
751 { "<LE support>", LMP_LE }, /* Bit 6 */
752 { "<3-slot EDR ACL>", LMP_EDR_3SLOT }, /* Bit 7 */
756 { "<5-slot EDR ACL>", LMP_EDR_5SLOT }, /* Bit 0 */
757 { "<sniff subrating>", LMP_SNIFF_SUBR }, /* Bit 1 */
758 { "<pause encryption>", LMP_PAUSE_ENC }, /* Bit 2 */
759 { "<AFH cap. master>", LMP_AFH_CAP_MST }, /* Bit 3 */
760 { "<AFH class. master>",LMP_AFH_CLS_MST }, /* Bit 4 */
761 { "<EDR eSCO 2 Mbps>", LMP_EDR_ESCO_2M }, /* Bit 5 */
762 { "<EDR eSCO 3 Mbps>", LMP_EDR_ESCO_3M }, /* Bit 6 */
763 { "<3-slot EDR eSCO>", LMP_EDR_3S_ESCO }, /* Bit 7 */
767 { "<extended inquiry>", LMP_EXT_INQ }, /* Bit 0 */
768 { "<LE and BR/EDR>", LMP_LE_BREDR }, /* Bit 1 */
769 { "<no. 50>", 0x04 }, /* Bit 2 */
770 { "<simple pairing>", LMP_SIMPLE_PAIR }, /* Bit 3 */
771 { "<encapsulated PDU>", LMP_ENCAPS_PDU }, /* Bit 4 */
772 { "<err. data report>", LMP_ERR_DAT_REP }, /* Bit 5 */
773 { "<non-flush flag>", LMP_NFLUSH_PKTS }, /* Bit 6 */
774 { "<no. 55>", 0x80 }, /* Bit 7 */
778 { "<LSTO>", LMP_LSTO }, /* Bit 1 */
779 { "<inquiry TX power>", LMP_INQ_TX_PWR }, /* Bit 1 */
780 { "<EPC>", LMP_EPC }, /* Bit 2 */
781 { "<no. 59>", 0x08 }, /* Bit 3 */
782 { "<no. 60>", 0x10 }, /* Bit 4 */
783 { "<no. 61>", 0x20 }, /* Bit 5 */
784 { "<no. 62>", 0x40 }, /* Bit 6 */
785 { "<extended features>",LMP_EXT_FEAT }, /* Bit 7 */
790 char *lmp_featurestostr(uint8_t *features, char *pref, int width)
792 unsigned int maxwidth = width - 1;
793 char *off, *ptr, *str;
796 for (i = 0; i < 8; i++) {
797 hci_map *m = lmp_features_map[i];
800 if (m->val & features[i])
801 size += strlen(m->str) +
802 (pref ? strlen(pref) : 0) + 1;
807 str = bt_malloc(size);
811 ptr = str; *ptr = '\0';
814 ptr += sprintf(ptr, "%s", pref);
818 for (i = 0; i < 8; i++) {
819 hci_map *m = lmp_features_map[i];
822 if (m->val & features[i]) {
823 if (strlen(off) + strlen(m->str) > maxwidth) {
824 ptr += sprintf(ptr, "\n%s",
828 ptr += sprintf(ptr, "%s ", m->str);
837 /* HCI functions that do not require open device */
838 int hci_for_each_dev(int flag, int (*func)(int dd, int dev_id, long arg),
841 struct hci_dev_list_req *dl;
842 struct hci_dev_req *dr;
846 sk = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
850 dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
856 memset(dl, 0, HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
858 dl->dev_num = HCI_MAX_DEV;
861 if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
866 for (i = 0; i < dl->dev_num; i++, dr++) {
867 if (hci_test_bit(flag, &dr->dev_opt))
868 if (!func || func(sk, dr->dev_id, arg)) {
887 static int __other_bdaddr(int dd, int dev_id, long arg)
889 struct hci_dev_info di = { .dev_id = dev_id };
891 if (ioctl(dd, HCIGETDEVINFO, (void *) &di))
894 if (hci_test_bit(HCI_RAW, &di.flags))
897 return bacmp((bdaddr_t *) arg, &di.bdaddr);
900 static int __same_bdaddr(int dd, int dev_id, long arg)
902 struct hci_dev_info di = { .dev_id = dev_id };
904 if (ioctl(dd, HCIGETDEVINFO, (void *) &di))
907 return !bacmp((bdaddr_t *) arg, &di.bdaddr);
910 int hci_get_route(bdaddr_t *bdaddr)
914 dev_id = hci_for_each_dev(HCI_UP, __other_bdaddr,
915 (long) (bdaddr ? bdaddr : BDADDR_ANY));
917 dev_id = hci_for_each_dev(HCI_UP, __same_bdaddr,
918 (long) (bdaddr ? bdaddr : BDADDR_ANY));
923 int hci_devid(const char *str)
928 if (!strncmp(str, "hci", 3) && strlen(str) >= 4) {
930 if (hci_devba(id, &ba) < 0)
935 id = hci_for_each_dev(HCI_UP, __same_bdaddr, (long) &ba);
941 int hci_devinfo(int dev_id, struct hci_dev_info *di)
945 dd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
949 memset(di, 0, sizeof(struct hci_dev_info));
952 ret = ioctl(dd, HCIGETDEVINFO, (void *) di);
961 int hci_devba(int dev_id, bdaddr_t *bdaddr)
963 struct hci_dev_info di;
965 memset(&di, 0, sizeof(di));
967 if (hci_devinfo(dev_id, &di))
970 if (!hci_test_bit(HCI_UP, &di.flags)) {
975 bacpy(bdaddr, &di.bdaddr);
980 int hci_inquiry(int dev_id, int len, int nrsp, const uint8_t *lap,
981 inquiry_info **ii, long flags)
983 struct hci_inquiry_req *ir;
984 uint8_t num_rsp = nrsp;
986 int dd, size, err, ret = -1;
994 dev_id = hci_get_route(NULL);
1001 dd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
1005 buf = malloc(sizeof(*ir) + (sizeof(inquiry_info) * (nrsp)));
1010 ir->dev_id = dev_id;
1011 ir->num_rsp = num_rsp;
1016 memcpy(ir->lap, lap, 3);
1023 ret = ioctl(dd, HCIINQUIRY, (unsigned long) buf);
1027 size = sizeof(inquiry_info) * ir->num_rsp;
1033 memcpy((void *) *ii, buf + sizeof(*ir), size);
1050 * Returns device descriptor (dd). */
1051 int hci_open_dev(int dev_id)
1053 struct sockaddr_hci a;
1056 /* Check for valid device id */
1062 /* Create HCI socket */
1063 dd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
1067 /* Bind socket to the HCI device */
1068 memset(&a, 0, sizeof(a));
1069 a.hci_family = AF_BLUETOOTH;
1071 if (bind(dd, (struct sockaddr *) &a, sizeof(a)) < 0)
1084 int hci_close_dev(int dd)
1089 /* HCI functions that require open device
1090 * dd - Device descriptor returned by hci_open_dev. */
1092 #ifdef __TIZEN_PATCH__
1093 int hci_send_data(int dd, uint16_t handle, uint8_t len, void *data)
1095 uint8_t type = HCI_ACLDATA_PKT;
1100 ac.handle = htobs(handle);
1101 ac.dlen= htobs(len);
1103 iv[0].iov_base = &type;
1105 iv[1].iov_base = ∾
1106 iv[1].iov_len = HCI_ACL_HDR_SIZE;
1110 iv[2].iov_base = data;
1111 iv[2].iov_len = len;
1115 while (writev(dd, iv, ivn) < 0) {
1116 if (errno == EAGAIN || errno == EINTR)
1124 int hci_send_cmd(int dd, uint16_t ogf, uint16_t ocf, uint8_t plen, void *param)
1126 uint8_t type = HCI_COMMAND_PKT;
1131 hc.opcode = htobs(cmd_opcode_pack(ogf, ocf));
1134 iv[0].iov_base = &type;
1136 iv[1].iov_base = &hc;
1137 iv[1].iov_len = HCI_COMMAND_HDR_SIZE;
1141 iv[2].iov_base = param;
1142 iv[2].iov_len = plen;
1146 while (writev(dd, iv, ivn) < 0) {
1147 if (errno == EAGAIN || errno == EINTR)
1154 int hci_send_req(int dd, struct hci_request *r, int to)
1156 unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr;
1157 uint16_t opcode = htobs(cmd_opcode_pack(r->ogf, r->ocf));
1158 struct hci_filter nf, of;
1164 if (getsockopt(dd, SOL_HCI, HCI_FILTER, &of, &olen) < 0)
1167 hci_filter_clear(&nf);
1168 hci_filter_set_ptype(HCI_EVENT_PKT, &nf);
1169 hci_filter_set_event(EVT_CMD_STATUS, &nf);
1170 hci_filter_set_event(EVT_CMD_COMPLETE, &nf);
1171 hci_filter_set_event(EVT_LE_META_EVENT, &nf);
1172 hci_filter_set_event(r->event, &nf);
1173 hci_filter_set_opcode(opcode, &nf);
1174 if (setsockopt(dd, SOL_HCI, HCI_FILTER, &nf, sizeof(nf)) < 0)
1177 if (hci_send_cmd(dd, r->ogf, r->ocf, r->clen, r->cparam) < 0)
1182 evt_cmd_complete *cc;
1184 evt_remote_name_req_complete *rn;
1185 evt_le_meta_event *me;
1186 remote_name_req_cp *cp;
1193 p.fd = dd; p.events = POLLIN;
1194 while ((n = poll(&p, 1, to)) < 0) {
1195 if (errno == EAGAIN || errno == EINTR)
1211 while ((len = read(dd, buf, sizeof(buf))) < 0) {
1212 if (errno == EAGAIN || errno == EINTR)
1217 hdr = (void *) (buf + 1);
1218 ptr = buf + (1 + HCI_EVENT_HDR_SIZE);
1219 len -= (1 + HCI_EVENT_HDR_SIZE);
1222 case EVT_CMD_STATUS:
1225 if (cs->opcode != opcode)
1228 if (r->event != EVT_CMD_STATUS) {
1236 r->rlen = MIN(len, r->rlen);
1237 memcpy(r->rparam, ptr, r->rlen);
1240 case EVT_CMD_COMPLETE:
1243 if (cc->opcode != opcode)
1246 ptr += EVT_CMD_COMPLETE_SIZE;
1247 len -= EVT_CMD_COMPLETE_SIZE;
1249 r->rlen = MIN(len, r->rlen);
1250 memcpy(r->rparam, ptr, r->rlen);
1253 case EVT_REMOTE_NAME_REQ_COMPLETE:
1254 if (hdr->evt != r->event)
1260 if (bacmp(&rn->bdaddr, &cp->bdaddr))
1263 r->rlen = MIN(len, r->rlen);
1264 memcpy(r->rparam, ptr, r->rlen);
1267 case EVT_LE_META_EVENT:
1270 if (me->subevent != r->event)
1274 r->rlen = MIN(len, r->rlen);
1275 memcpy(r->rparam, me->data, r->rlen);
1279 if (hdr->evt != r->event)
1282 r->rlen = MIN(len, r->rlen);
1283 memcpy(r->rparam, ptr, r->rlen);
1291 setsockopt(dd, SOL_HCI, HCI_FILTER, &of, sizeof(of));
1296 setsockopt(dd, SOL_HCI, HCI_FILTER, &of, sizeof(of));
1300 int hci_create_connection(int dd, const bdaddr_t *bdaddr, uint16_t ptype,
1301 uint16_t clkoffset, uint8_t rswitch,
1302 uint16_t *handle, int to)
1304 evt_conn_complete rp;
1306 struct hci_request rq;
1308 memset(&cp, 0, sizeof(cp));
1309 bacpy(&cp.bdaddr, bdaddr);
1310 cp.pkt_type = ptype;
1311 cp.pscan_rep_mode = 0x02;
1312 cp.clock_offset = clkoffset;
1313 cp.role_switch = rswitch;
1315 memset(&rq, 0, sizeof(rq));
1316 rq.ogf = OGF_LINK_CTL;
1317 rq.ocf = OCF_CREATE_CONN;
1318 rq.event = EVT_CONN_COMPLETE;
1320 rq.clen = CREATE_CONN_CP_SIZE;
1322 rq.rlen = EVT_CONN_COMPLETE_SIZE;
1324 if (hci_send_req(dd, &rq, to) < 0)
1332 *handle = rp.handle;
1336 int hci_disconnect(int dd, uint16_t handle, uint8_t reason, int to)
1338 evt_disconn_complete rp;
1340 struct hci_request rq;
1342 memset(&cp, 0, sizeof(cp));
1346 memset(&rq, 0, sizeof(rq));
1347 rq.ogf = OGF_LINK_CTL;
1348 rq.ocf = OCF_DISCONNECT;
1349 rq.event = EVT_DISCONN_COMPLETE;
1351 rq.clen = DISCONNECT_CP_SIZE;
1353 rq.rlen = EVT_DISCONN_COMPLETE_SIZE;
1355 if (hci_send_req(dd, &rq, to) < 0)
1365 int hci_le_add_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
1367 struct hci_request rq;
1368 le_add_device_to_white_list_cp cp;
1371 memset(&cp, 0, sizeof(cp));
1372 cp.bdaddr_type = type;
1373 bacpy(&cp.bdaddr, bdaddr);
1375 memset(&rq, 0, sizeof(rq));
1376 rq.ogf = OGF_LE_CTL;
1377 rq.ocf = OCF_LE_ADD_DEVICE_TO_WHITE_LIST;
1379 rq.clen = LE_ADD_DEVICE_TO_WHITE_LIST_CP_SIZE;
1380 rq.rparam = &status;
1383 if (hci_send_req(dd, &rq, to) < 0)
1394 int hci_le_rm_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
1396 struct hci_request rq;
1397 le_remove_device_from_white_list_cp cp;
1400 memset(&cp, 0, sizeof(cp));
1401 cp.bdaddr_type = type;
1402 bacpy(&cp.bdaddr, bdaddr);
1404 memset(&rq, 0, sizeof(rq));
1405 rq.ogf = OGF_LE_CTL;
1406 rq.ocf = OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST;
1408 rq.clen = LE_REMOVE_DEVICE_FROM_WHITE_LIST_CP_SIZE;
1409 rq.rparam = &status;
1412 if (hci_send_req(dd, &rq, to) < 0)
1423 int hci_le_read_white_list_size(int dd, uint8_t *size, int to)
1425 struct hci_request rq;
1426 le_read_white_list_size_rp rp;
1428 memset(&rp, 0, sizeof(rp));
1429 memset(&rq, 0, sizeof(rq));
1431 rq.ogf = OGF_LE_CTL;
1432 rq.ocf = OCF_LE_READ_WHITE_LIST_SIZE;
1434 rq.rlen = LE_READ_WHITE_LIST_SIZE_RP_SIZE;
1436 if (hci_send_req(dd, &rq, to) < 0)
1450 int hci_le_clear_white_list(int dd, int to)
1452 struct hci_request rq;
1455 memset(&rq, 0, sizeof(rq));
1456 rq.ogf = OGF_LE_CTL;
1457 rq.ocf = OCF_LE_CLEAR_WHITE_LIST;
1458 rq.rparam = &status;
1461 if (hci_send_req(dd, &rq, to) < 0)
1472 int hci_le_add_resolving_list(int dd, const bdaddr_t *bdaddr, uint8_t type,
1473 uint8_t *peer_irk, uint8_t *local_irk, int to)
1475 struct hci_request rq;
1476 le_add_device_to_resolv_list_cp cp;
1479 memset(&cp, 0, sizeof(cp));
1480 cp.bdaddr_type = type;
1481 bacpy(&cp.bdaddr, bdaddr);
1483 memcpy(cp.peer_irk, peer_irk, 16);
1485 memcpy(cp.local_irk, local_irk, 16);
1487 memset(&rq, 0, sizeof(rq));
1488 rq.ogf = OGF_LE_CTL;
1489 rq.ocf = OCF_LE_ADD_DEVICE_TO_RESOLV_LIST;
1491 rq.clen = LE_ADD_DEVICE_TO_RESOLV_LIST_CP_SIZE;
1492 rq.rparam = &status;
1495 if (hci_send_req(dd, &rq, to) < 0)
1506 int hci_le_rm_resolving_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
1508 struct hci_request rq;
1509 le_remove_device_from_resolv_list_cp cp;
1512 memset(&cp, 0, sizeof(cp));
1513 cp.bdaddr_type = type;
1514 bacpy(&cp.bdaddr, bdaddr);
1516 memset(&rq, 0, sizeof(rq));
1517 rq.ogf = OGF_LE_CTL;
1518 rq.ocf = OCF_LE_REMOVE_DEVICE_FROM_RESOLV_LIST;
1520 rq.clen = LE_REMOVE_DEVICE_FROM_RESOLV_LIST_CP_SIZE;
1521 rq.rparam = &status;
1524 if (hci_send_req(dd, &rq, to) < 0)
1535 int hci_le_clear_resolving_list(int dd, int to)
1537 struct hci_request rq;
1540 memset(&rq, 0, sizeof(rq));
1541 rq.ogf = OGF_LE_CTL;
1542 rq.ocf = OCF_LE_CLEAR_RESOLV_LIST;
1543 rq.rparam = &status;
1546 if (hci_send_req(dd, &rq, to) < 0)
1557 int hci_le_read_resolving_list_size(int dd, uint8_t *size, int to)
1559 struct hci_request rq;
1560 le_read_resolv_list_size_rp rp;
1562 memset(&rp, 0, sizeof(rp));
1563 memset(&rq, 0, sizeof(rq));
1565 rq.ogf = OGF_LE_CTL;
1566 rq.ocf = OCF_LE_READ_RESOLV_LIST_SIZE;
1568 rq.rlen = LE_READ_RESOLV_LIST_SIZE_RP_SIZE;
1570 if (hci_send_req(dd, &rq, to) < 0)
1584 int hci_le_set_address_resolution_enable(int dd, uint8_t enable, int to)
1586 struct hci_request rq;
1587 le_set_address_resolution_enable_cp cp;
1590 memset(&cp, 0, sizeof(cp));
1593 memset(&rq, 0, sizeof(rq));
1594 rq.ogf = OGF_LE_CTL;
1595 rq.ocf = OCF_LE_SET_ADDRESS_RESOLUTION_ENABLE;
1597 rq.clen = LE_SET_ADDRESS_RESOLUTION_ENABLE_CP_SIZE;
1598 rq.rparam = &status;
1601 if (hci_send_req(dd, &rq, to) < 0)
1612 int hci_read_local_name(int dd, int len, char *name, int to)
1614 read_local_name_rp rp;
1615 struct hci_request rq;
1617 memset(&rq, 0, sizeof(rq));
1618 rq.ogf = OGF_HOST_CTL;
1619 rq.ocf = OCF_READ_LOCAL_NAME;
1621 rq.rlen = READ_LOCAL_NAME_RP_SIZE;
1623 if (hci_send_req(dd, &rq, to) < 0)
1631 rp.name[247] = '\0';
1632 strncpy(name, (char *) rp.name, len);
1636 int hci_write_local_name(int dd, const char *name, int to)
1638 change_local_name_cp cp;
1639 struct hci_request rq;
1641 memset(&cp, 0, sizeof(cp));
1642 strncpy((char *) cp.name, name, sizeof(cp.name));
1644 memset(&rq, 0, sizeof(rq));
1645 rq.ogf = OGF_HOST_CTL;
1646 rq.ocf = OCF_CHANGE_LOCAL_NAME;
1648 rq.clen = CHANGE_LOCAL_NAME_CP_SIZE;
1650 if (hci_send_req(dd, &rq, to) < 0)
1656 int hci_read_remote_name_with_clock_offset(int dd, const bdaddr_t *bdaddr,
1657 uint8_t pscan_rep_mode,
1659 int len, char *name, int to)
1661 evt_remote_name_req_complete rn;
1662 remote_name_req_cp cp;
1663 struct hci_request rq;
1665 memset(&cp, 0, sizeof(cp));
1666 bacpy(&cp.bdaddr, bdaddr);
1667 cp.pscan_rep_mode = pscan_rep_mode;
1668 cp.clock_offset = clkoffset;
1670 memset(&rq, 0, sizeof(rq));
1671 rq.ogf = OGF_LINK_CTL;
1672 rq.ocf = OCF_REMOTE_NAME_REQ;
1674 rq.clen = REMOTE_NAME_REQ_CP_SIZE;
1675 rq.event = EVT_REMOTE_NAME_REQ_COMPLETE;
1677 rq.rlen = EVT_REMOTE_NAME_REQ_COMPLETE_SIZE;
1679 if (hci_send_req(dd, &rq, to) < 0)
1687 rn.name[247] = '\0';
1688 strncpy(name, (char *) rn.name, len);
1692 int hci_read_remote_name(int dd, const bdaddr_t *bdaddr, int len, char *name,
1695 return hci_read_remote_name_with_clock_offset(dd, bdaddr, 0x02, 0x0000,
1699 int hci_read_remote_name_cancel(int dd, const bdaddr_t *bdaddr, int to)
1701 remote_name_req_cancel_cp cp;
1702 struct hci_request rq;
1704 memset(&cp, 0, sizeof(cp));
1705 bacpy(&cp.bdaddr, bdaddr);
1707 memset(&rq, 0, sizeof(rq));
1708 rq.ogf = OGF_LINK_CTL;
1709 rq.ocf = OCF_REMOTE_NAME_REQ_CANCEL;
1711 rq.clen = REMOTE_NAME_REQ_CANCEL_CP_SIZE;
1713 if (hci_send_req(dd, &rq, to) < 0)
1719 int hci_read_remote_version(int dd, uint16_t handle, struct hci_version *ver,
1722 evt_read_remote_version_complete rp;
1723 read_remote_version_cp cp;
1724 struct hci_request rq;
1726 memset(&cp, 0, sizeof(cp));
1729 memset(&rq, 0, sizeof(rq));
1730 rq.ogf = OGF_LINK_CTL;
1731 rq.ocf = OCF_READ_REMOTE_VERSION;
1732 rq.event = EVT_READ_REMOTE_VERSION_COMPLETE;
1734 rq.clen = READ_REMOTE_VERSION_CP_SIZE;
1736 rq.rlen = EVT_READ_REMOTE_VERSION_COMPLETE_SIZE;
1738 if (hci_send_req(dd, &rq, to) < 0)
1746 ver->manufacturer = btohs(rp.manufacturer);
1747 ver->lmp_ver = rp.lmp_ver;
1748 ver->lmp_subver = btohs(rp.lmp_subver);
1752 int hci_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to)
1754 evt_read_remote_features_complete rp;
1755 read_remote_features_cp cp;
1756 struct hci_request rq;
1758 memset(&cp, 0, sizeof(cp));
1761 memset(&rq, 0, sizeof(rq));
1762 rq.ogf = OGF_LINK_CTL;
1763 rq.ocf = OCF_READ_REMOTE_FEATURES;
1764 rq.event = EVT_READ_REMOTE_FEATURES_COMPLETE;
1766 rq.clen = READ_REMOTE_FEATURES_CP_SIZE;
1768 rq.rlen = EVT_READ_REMOTE_FEATURES_COMPLETE_SIZE;
1770 if (hci_send_req(dd, &rq, to) < 0)
1779 memcpy(features, rp.features, 8);
1784 int hci_read_remote_ext_features(int dd, uint16_t handle, uint8_t page,
1785 uint8_t *max_page, uint8_t *features,
1788 evt_read_remote_ext_features_complete rp;
1789 read_remote_ext_features_cp cp;
1790 struct hci_request rq;
1792 memset(&cp, 0, sizeof(cp));
1796 memset(&rq, 0, sizeof(rq));
1797 rq.ogf = OGF_LINK_CTL;
1798 rq.ocf = OCF_READ_REMOTE_EXT_FEATURES;
1799 rq.event = EVT_READ_REMOTE_EXT_FEATURES_COMPLETE;
1801 rq.clen = READ_REMOTE_EXT_FEATURES_CP_SIZE;
1803 rq.rlen = EVT_READ_REMOTE_EXT_FEATURES_COMPLETE_SIZE;
1805 if (hci_send_req(dd, &rq, to) < 0)
1814 *max_page = rp.max_page_num;
1817 memcpy(features, rp.features, 8);
1822 int hci_read_clock_offset(int dd, uint16_t handle, uint16_t *clkoffset, int to)
1824 evt_read_clock_offset_complete rp;
1825 read_clock_offset_cp cp;
1826 struct hci_request rq;
1828 memset(&cp, 0, sizeof(cp));
1831 memset(&rq, 0, sizeof(rq));
1832 rq.ogf = OGF_LINK_CTL;
1833 rq.ocf = OCF_READ_CLOCK_OFFSET;
1834 rq.event = EVT_READ_CLOCK_OFFSET_COMPLETE;
1836 rq.clen = READ_CLOCK_OFFSET_CP_SIZE;
1838 rq.rlen = EVT_READ_CLOCK_OFFSET_COMPLETE_SIZE;
1840 if (hci_send_req(dd, &rq, to) < 0)
1848 *clkoffset = rp.clock_offset;
1852 int hci_read_local_version(int dd, struct hci_version *ver, int to)
1854 read_local_version_rp rp;
1855 struct hci_request rq;
1857 memset(&rq, 0, sizeof(rq));
1858 rq.ogf = OGF_INFO_PARAM;
1859 rq.ocf = OCF_READ_LOCAL_VERSION;
1861 rq.rlen = READ_LOCAL_VERSION_RP_SIZE;
1863 if (hci_send_req(dd, &rq, to) < 0)
1871 ver->manufacturer = btohs(rp.manufacturer);
1872 ver->hci_ver = rp.hci_ver;
1873 ver->hci_rev = btohs(rp.hci_rev);
1874 ver->lmp_ver = rp.lmp_ver;
1875 ver->lmp_subver = btohs(rp.lmp_subver);
1879 int hci_read_local_commands(int dd, uint8_t *commands, int to)
1881 read_local_commands_rp rp;
1882 struct hci_request rq;
1884 memset(&rq, 0, sizeof(rq));
1885 rq.ogf = OGF_INFO_PARAM;
1886 rq.ocf = OCF_READ_LOCAL_COMMANDS;
1888 rq.rlen = READ_LOCAL_COMMANDS_RP_SIZE;
1890 if (hci_send_req(dd, &rq, to) < 0)
1899 memcpy(commands, rp.commands, 64);
1904 int hci_read_local_features(int dd, uint8_t *features, int to)
1906 read_local_features_rp rp;
1907 struct hci_request rq;
1909 memset(&rq, 0, sizeof(rq));
1910 rq.ogf = OGF_INFO_PARAM;
1911 rq.ocf = OCF_READ_LOCAL_FEATURES;
1913 rq.rlen = READ_LOCAL_FEATURES_RP_SIZE;
1915 if (hci_send_req(dd, &rq, to) < 0)
1924 memcpy(features, rp.features, 8);
1929 int hci_read_local_ext_features(int dd, uint8_t page, uint8_t *max_page,
1930 uint8_t *features, int to)
1932 read_local_ext_features_cp cp;
1933 read_local_ext_features_rp rp;
1934 struct hci_request rq;
1938 memset(&rq, 0, sizeof(rq));
1939 rq.ogf = OGF_INFO_PARAM;
1940 rq.ocf = OCF_READ_LOCAL_EXT_FEATURES;
1942 rq.clen = READ_LOCAL_EXT_FEATURES_CP_SIZE;
1944 rq.rlen = READ_LOCAL_EXT_FEATURES_RP_SIZE;
1946 if (hci_send_req(dd, &rq, to) < 0)
1955 *max_page = rp.max_page_num;
1958 memcpy(features, rp.features, 8);
1963 int hci_read_bd_addr(int dd, bdaddr_t *bdaddr, int to)
1966 struct hci_request rq;
1968 memset(&rq, 0, sizeof(rq));
1969 rq.ogf = OGF_INFO_PARAM;
1970 rq.ocf = OCF_READ_BD_ADDR;
1972 rq.rlen = READ_BD_ADDR_RP_SIZE;
1974 if (hci_send_req(dd, &rq, to) < 0)
1983 bacpy(bdaddr, &rp.bdaddr);
1988 int hci_read_class_of_dev(int dd, uint8_t *cls, int to)
1990 read_class_of_dev_rp rp;
1991 struct hci_request rq;
1993 memset(&rq, 0, sizeof(rq));
1994 rq.ogf = OGF_HOST_CTL;
1995 rq.ocf = OCF_READ_CLASS_OF_DEV;
1997 rq.rlen = READ_CLASS_OF_DEV_RP_SIZE;
1999 if (hci_send_req(dd, &rq, to) < 0)
2007 memcpy(cls, rp.dev_class, 3);
2011 int hci_write_class_of_dev(int dd, uint32_t cls, int to)
2013 write_class_of_dev_cp cp;
2014 struct hci_request rq;
2016 memset(&rq, 0, sizeof(rq));
2017 cp.dev_class[0] = cls & 0xff;
2018 cp.dev_class[1] = (cls >> 8) & 0xff;
2019 cp.dev_class[2] = (cls >> 16) & 0xff;
2020 rq.ogf = OGF_HOST_CTL;
2021 rq.ocf = OCF_WRITE_CLASS_OF_DEV;
2023 rq.clen = WRITE_CLASS_OF_DEV_CP_SIZE;
2024 return hci_send_req(dd, &rq, to);
2027 int hci_read_voice_setting(int dd, uint16_t *vs, int to)
2029 read_voice_setting_rp rp;
2030 struct hci_request rq;
2032 memset(&rq, 0, sizeof(rq));
2033 rq.ogf = OGF_HOST_CTL;
2034 rq.ocf = OCF_READ_VOICE_SETTING;
2036 rq.rlen = READ_VOICE_SETTING_RP_SIZE;
2038 if (hci_send_req(dd, &rq, to) < 0)
2046 *vs = rp.voice_setting;
2050 int hci_write_voice_setting(int dd, uint16_t vs, int to)
2052 write_voice_setting_cp cp;
2053 struct hci_request rq;
2055 memset(&rq, 0, sizeof(rq));
2056 cp.voice_setting = vs;
2057 rq.ogf = OGF_HOST_CTL;
2058 rq.ocf = OCF_WRITE_VOICE_SETTING;
2060 rq.clen = WRITE_VOICE_SETTING_CP_SIZE;
2062 return hci_send_req(dd, &rq, to);
2065 int hci_read_current_iac_lap(int dd, uint8_t *num_iac, uint8_t *lap, int to)
2067 read_current_iac_lap_rp rp;
2068 struct hci_request rq;
2070 memset(&rq, 0, sizeof(rq));
2071 rq.ogf = OGF_HOST_CTL;
2072 rq.ocf = OCF_READ_CURRENT_IAC_LAP;
2074 rq.rlen = READ_CURRENT_IAC_LAP_RP_SIZE;
2076 if (hci_send_req(dd, &rq, to) < 0)
2084 *num_iac = rp.num_current_iac;
2085 memcpy(lap, rp.lap, rp.num_current_iac * 3);
2089 int hci_write_current_iac_lap(int dd, uint8_t num_iac, uint8_t *lap, int to)
2091 write_current_iac_lap_cp cp;
2092 struct hci_request rq;
2094 memset(&cp, 0, sizeof(cp));
2095 cp.num_current_iac = num_iac;
2096 memcpy(&cp.lap, lap, num_iac * 3);
2098 memset(&rq, 0, sizeof(rq));
2099 rq.ogf = OGF_HOST_CTL;
2100 rq.ocf = OCF_WRITE_CURRENT_IAC_LAP;
2102 rq.clen = num_iac * 3 + 1;
2104 return hci_send_req(dd, &rq, to);
2107 int hci_read_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to)
2109 read_stored_link_key_cp cp;
2110 struct hci_request rq;
2112 memset(&cp, 0, sizeof(cp));
2113 bacpy(&cp.bdaddr, bdaddr);
2116 memset(&rq, 0, sizeof(rq));
2117 rq.ogf = OGF_HOST_CTL;
2118 rq.ocf = OCF_READ_STORED_LINK_KEY;
2120 rq.clen = READ_STORED_LINK_KEY_CP_SIZE;
2122 return hci_send_req(dd, &rq, to);
2125 int hci_write_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t *key, int to)
2127 unsigned char cp[WRITE_STORED_LINK_KEY_CP_SIZE + 6 + 16];
2128 struct hci_request rq;
2130 memset(&cp, 0, sizeof(cp));
2132 bacpy((bdaddr_t *) (cp + 1), bdaddr);
2133 memcpy(cp + 7, key, 16);
2135 memset(&rq, 0, sizeof(rq));
2136 rq.ogf = OGF_HOST_CTL;
2137 rq.ocf = OCF_WRITE_STORED_LINK_KEY;
2139 rq.clen = WRITE_STORED_LINK_KEY_CP_SIZE + 6 + 16;
2141 return hci_send_req(dd, &rq, to);
2144 int hci_delete_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to)
2146 delete_stored_link_key_cp cp;
2147 struct hci_request rq;
2149 memset(&cp, 0, sizeof(cp));
2150 bacpy(&cp.bdaddr, bdaddr);
2151 cp.delete_all = all;
2153 memset(&rq, 0, sizeof(rq));
2154 rq.ogf = OGF_HOST_CTL;
2155 rq.ocf = OCF_DELETE_STORED_LINK_KEY;
2157 rq.clen = DELETE_STORED_LINK_KEY_CP_SIZE;
2159 return hci_send_req(dd, &rq, to);
2162 int hci_authenticate_link(int dd, uint16_t handle, int to)
2164 auth_requested_cp cp;
2165 evt_auth_complete rp;
2166 struct hci_request rq;
2170 rq.ogf = OGF_LINK_CTL;
2171 rq.ocf = OCF_AUTH_REQUESTED;
2172 rq.event = EVT_AUTH_COMPLETE;
2174 rq.clen = AUTH_REQUESTED_CP_SIZE;
2176 rq.rlen = EVT_AUTH_COMPLETE_SIZE;
2178 if (hci_send_req(dd, &rq, to) < 0)
2189 int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to)
2191 set_conn_encrypt_cp cp;
2192 evt_encrypt_change rp;
2193 struct hci_request rq;
2196 cp.encrypt = encrypt;
2198 rq.ogf = OGF_LINK_CTL;
2199 rq.ocf = OCF_SET_CONN_ENCRYPT;
2200 rq.event = EVT_ENCRYPT_CHANGE;
2202 rq.clen = SET_CONN_ENCRYPT_CP_SIZE;
2204 rq.rlen = EVT_ENCRYPT_CHANGE_SIZE;
2206 if (hci_send_req(dd, &rq, to) < 0)
2217 int hci_change_link_key(int dd, uint16_t handle, int to)
2219 change_conn_link_key_cp cp;
2220 evt_change_conn_link_key_complete rp;
2221 struct hci_request rq;
2225 rq.ogf = OGF_LINK_CTL;
2226 rq.ocf = OCF_CHANGE_CONN_LINK_KEY;
2227 rq.event = EVT_CHANGE_CONN_LINK_KEY_COMPLETE;
2229 rq.clen = CHANGE_CONN_LINK_KEY_CP_SIZE;
2231 rq.rlen = EVT_CHANGE_CONN_LINK_KEY_COMPLETE_SIZE;
2233 if (hci_send_req(dd, &rq, to) < 0)
2244 int hci_switch_role(int dd, bdaddr_t *bdaddr, uint8_t role, int to)
2248 struct hci_request rq;
2250 bacpy(&cp.bdaddr, bdaddr);
2252 rq.ogf = OGF_LINK_POLICY;
2253 rq.ocf = OCF_SWITCH_ROLE;
2255 rq.clen = SWITCH_ROLE_CP_SIZE;
2257 rq.rlen = EVT_ROLE_CHANGE_SIZE;
2258 rq.event = EVT_ROLE_CHANGE;
2260 if (hci_send_req(dd, &rq, to) < 0)
2271 int hci_park_mode(int dd, uint16_t handle, uint16_t max_interval,
2272 uint16_t min_interval, int to)
2276 struct hci_request rq;
2278 memset(&cp, 0, sizeof (cp));
2280 cp.max_interval = max_interval;
2281 cp.min_interval = min_interval;
2283 memset(&rq, 0, sizeof (rq));
2284 rq.ogf = OGF_LINK_POLICY;
2285 rq.ocf = OCF_PARK_MODE;
2286 rq.event = EVT_MODE_CHANGE;
2288 rq.clen = PARK_MODE_CP_SIZE;
2290 rq.rlen = EVT_MODE_CHANGE_SIZE;
2292 if (hci_send_req(dd, &rq, to) < 0)
2303 int hci_exit_park_mode(int dd, uint16_t handle, int to)
2305 exit_park_mode_cp cp;
2307 struct hci_request rq;
2309 memset(&cp, 0, sizeof (cp));
2312 memset (&rq, 0, sizeof (rq));
2313 rq.ogf = OGF_LINK_POLICY;
2314 rq.ocf = OCF_EXIT_PARK_MODE;
2315 rq.event = EVT_MODE_CHANGE;
2317 rq.clen = EXIT_PARK_MODE_CP_SIZE;
2319 rq.rlen = EVT_MODE_CHANGE_SIZE;
2321 if (hci_send_req(dd, &rq, to) < 0)
2332 int hci_read_inquiry_scan_type(int dd, uint8_t *type, int to)
2334 read_inquiry_scan_type_rp rp;
2335 struct hci_request rq;
2337 memset(&rq, 0, sizeof(rq));
2338 rq.ogf = OGF_HOST_CTL;
2339 rq.ocf = OCF_READ_INQUIRY_SCAN_TYPE;
2341 rq.rlen = READ_INQUIRY_SCAN_TYPE_RP_SIZE;
2343 if (hci_send_req(dd, &rq, to) < 0)
2355 int hci_write_inquiry_scan_type(int dd, uint8_t type, int to)
2357 write_inquiry_scan_type_cp cp;
2358 write_inquiry_scan_type_rp rp;
2359 struct hci_request rq;
2361 memset(&cp, 0, sizeof(cp));
2364 memset(&rq, 0, sizeof(rq));
2365 rq.ogf = OGF_HOST_CTL;
2366 rq.ocf = OCF_WRITE_INQUIRY_SCAN_TYPE;
2368 rq.clen = WRITE_INQUIRY_SCAN_TYPE_CP_SIZE;
2370 rq.rlen = WRITE_INQUIRY_SCAN_TYPE_RP_SIZE;
2372 if (hci_send_req(dd, &rq, to) < 0)
2383 int hci_read_inquiry_mode(int dd, uint8_t *mode, int to)
2385 read_inquiry_mode_rp rp;
2386 struct hci_request rq;
2388 memset(&rq, 0, sizeof(rq));
2389 rq.ogf = OGF_HOST_CTL;
2390 rq.ocf = OCF_READ_INQUIRY_MODE;
2392 rq.rlen = READ_INQUIRY_MODE_RP_SIZE;
2394 if (hci_send_req(dd, &rq, to) < 0)
2406 int hci_write_inquiry_mode(int dd, uint8_t mode, int to)
2408 write_inquiry_mode_cp cp;
2409 write_inquiry_mode_rp rp;
2410 struct hci_request rq;
2412 memset(&cp, 0, sizeof(cp));
2415 memset(&rq, 0, sizeof(rq));
2416 rq.ogf = OGF_HOST_CTL;
2417 rq.ocf = OCF_WRITE_INQUIRY_MODE;
2419 rq.clen = WRITE_INQUIRY_MODE_CP_SIZE;
2421 rq.rlen = WRITE_INQUIRY_MODE_RP_SIZE;
2423 if (hci_send_req(dd, &rq, to) < 0)
2434 int hci_read_afh_mode(int dd, uint8_t *mode, int to)
2436 read_afh_mode_rp rp;
2437 struct hci_request rq;
2439 memset(&rq, 0, sizeof(rq));
2440 rq.ogf = OGF_HOST_CTL;
2441 rq.ocf = OCF_READ_AFH_MODE;
2443 rq.rlen = READ_AFH_MODE_RP_SIZE;
2445 if (hci_send_req(dd, &rq, to) < 0)
2457 int hci_write_afh_mode(int dd, uint8_t mode, int to)
2459 write_afh_mode_cp cp;
2460 write_afh_mode_rp rp;
2461 struct hci_request rq;
2463 memset(&cp, 0, sizeof(cp));
2466 memset(&rq, 0, sizeof(rq));
2467 rq.ogf = OGF_HOST_CTL;
2468 rq.ocf = OCF_WRITE_AFH_MODE;
2470 rq.clen = WRITE_AFH_MODE_CP_SIZE;
2472 rq.rlen = WRITE_AFH_MODE_RP_SIZE;
2474 if (hci_send_req(dd, &rq, to) < 0)
2485 int hci_read_ext_inquiry_response(int dd, uint8_t *fec, uint8_t *data, int to)
2487 read_ext_inquiry_response_rp rp;
2488 struct hci_request rq;
2490 memset(&rq, 0, sizeof(rq));
2491 rq.ogf = OGF_HOST_CTL;
2492 rq.ocf = OCF_READ_EXT_INQUIRY_RESPONSE;
2494 rq.rlen = READ_EXT_INQUIRY_RESPONSE_RP_SIZE;
2496 if (hci_send_req(dd, &rq, to) < 0)
2505 memcpy(data, rp.data, HCI_MAX_EIR_LENGTH);
2510 int hci_write_ext_inquiry_response(int dd, uint8_t fec, uint8_t *data, int to)
2512 write_ext_inquiry_response_cp cp;
2513 write_ext_inquiry_response_rp rp;
2514 struct hci_request rq;
2516 memset(&cp, 0, sizeof(cp));
2518 memcpy(cp.data, data, HCI_MAX_EIR_LENGTH);
2520 memset(&rq, 0, sizeof(rq));
2521 rq.ogf = OGF_HOST_CTL;
2522 rq.ocf = OCF_WRITE_EXT_INQUIRY_RESPONSE;
2524 rq.clen = WRITE_EXT_INQUIRY_RESPONSE_CP_SIZE;
2526 rq.rlen = WRITE_EXT_INQUIRY_RESPONSE_RP_SIZE;
2528 if (hci_send_req(dd, &rq, to) < 0)
2539 int hci_read_simple_pairing_mode(int dd, uint8_t *mode, int to)
2541 read_simple_pairing_mode_rp rp;
2542 struct hci_request rq;
2544 memset(&rq, 0, sizeof(rq));
2545 rq.ogf = OGF_HOST_CTL;
2546 rq.ocf = OCF_READ_SIMPLE_PAIRING_MODE;
2548 rq.rlen = READ_SIMPLE_PAIRING_MODE_RP_SIZE;
2550 if (hci_send_req(dd, &rq, to) < 0)
2562 int hci_write_simple_pairing_mode(int dd, uint8_t mode, int to)
2564 write_simple_pairing_mode_cp cp;
2565 write_simple_pairing_mode_rp rp;
2566 struct hci_request rq;
2568 memset(&cp, 0, sizeof(cp));
2571 memset(&rq, 0, sizeof(rq));
2572 rq.ogf = OGF_HOST_CTL;
2573 rq.ocf = OCF_WRITE_SIMPLE_PAIRING_MODE;
2575 rq.clen = WRITE_SIMPLE_PAIRING_MODE_CP_SIZE;
2577 rq.rlen = WRITE_SIMPLE_PAIRING_MODE_RP_SIZE;
2579 if (hci_send_req(dd, &rq, to) < 0)
2590 int hci_read_local_oob_data(int dd, uint8_t *hash, uint8_t *randomizer, int to)
2592 read_local_oob_data_rp rp;
2593 struct hci_request rq;
2595 memset(&rq, 0, sizeof(rq));
2596 rq.ogf = OGF_HOST_CTL;
2597 rq.ocf = OCF_READ_LOCAL_OOB_DATA;
2599 rq.rlen = READ_LOCAL_OOB_DATA_RP_SIZE;
2601 if (hci_send_req(dd, &rq, to) < 0)
2609 memcpy(hash, rp.hash, 16);
2610 memcpy(randomizer, rp.randomizer, 16);
2614 int hci_read_inq_response_tx_power_level(int dd, int8_t *level, int to)
2616 read_inq_response_tx_power_level_rp rp;
2617 struct hci_request rq;
2619 memset(&rq, 0, sizeof(rq));
2620 rq.ogf = OGF_HOST_CTL;
2621 rq.ocf = OCF_READ_INQ_RESPONSE_TX_POWER_LEVEL;
2623 rq.rlen = READ_INQ_RESPONSE_TX_POWER_LEVEL_RP_SIZE;
2625 if (hci_send_req(dd, &rq, to) < 0)
2637 int hci_read_inquiry_transmit_power_level(int dd, int8_t *level, int to)
2639 return hci_read_inq_response_tx_power_level(dd, level, to);
2642 int hci_write_inquiry_transmit_power_level(int dd, int8_t level, int to)
2644 write_inquiry_transmit_power_level_cp cp;
2645 write_inquiry_transmit_power_level_rp rp;
2646 struct hci_request rq;
2648 memset(&cp, 0, sizeof(cp));
2651 memset(&rq, 0, sizeof(rq));
2652 rq.ogf = OGF_HOST_CTL;
2653 rq.ocf = OCF_WRITE_INQUIRY_TRANSMIT_POWER_LEVEL;
2655 rq.clen = WRITE_INQUIRY_TRANSMIT_POWER_LEVEL_CP_SIZE;
2657 rq.rlen = WRITE_INQUIRY_TRANSMIT_POWER_LEVEL_RP_SIZE;
2659 if (hci_send_req(dd, &rq, to) < 0)
2670 int hci_read_transmit_power_level(int dd, uint16_t handle, uint8_t type,
2671 int8_t *level, int to)
2673 read_transmit_power_level_cp cp;
2674 read_transmit_power_level_rp rp;
2675 struct hci_request rq;
2677 memset(&cp, 0, sizeof(cp));
2681 memset(&rq, 0, sizeof(rq));
2682 rq.ogf = OGF_HOST_CTL;
2683 rq.ocf = OCF_READ_TRANSMIT_POWER_LEVEL;
2685 rq.clen = READ_TRANSMIT_POWER_LEVEL_CP_SIZE;
2687 rq.rlen = READ_TRANSMIT_POWER_LEVEL_RP_SIZE;
2689 if (hci_send_req(dd, &rq, to) < 0)
2701 int hci_read_link_policy(int dd, uint16_t handle, uint16_t *policy, int to)
2703 read_link_policy_rp rp;
2704 struct hci_request rq;
2706 memset(&rq, 0, sizeof(rq));
2707 rq.ogf = OGF_LINK_POLICY;
2708 rq.ocf = OCF_READ_LINK_POLICY;
2709 rq.cparam = &handle;
2712 rq.rlen = READ_LINK_POLICY_RP_SIZE;
2714 if (hci_send_req(dd, &rq, to) < 0)
2722 *policy = rp.policy;
2726 int hci_write_link_policy(int dd, uint16_t handle, uint16_t policy, int to)
2728 write_link_policy_cp cp;
2729 write_link_policy_rp rp;
2730 struct hci_request rq;
2732 memset(&cp, 0, sizeof(cp));
2736 memset(&rq, 0, sizeof(rq));
2737 rq.ogf = OGF_LINK_POLICY;
2738 rq.ocf = OCF_WRITE_LINK_POLICY;
2740 rq.clen = WRITE_LINK_POLICY_CP_SIZE;
2742 rq.rlen = WRITE_LINK_POLICY_RP_SIZE;
2744 if (hci_send_req(dd, &rq, to) < 0)
2755 int hci_read_link_supervision_timeout(int dd, uint16_t handle,
2756 uint16_t *timeout, int to)
2758 read_link_supervision_timeout_rp rp;
2759 struct hci_request rq;
2761 memset(&rq, 0, sizeof(rq));
2762 rq.ogf = OGF_HOST_CTL;
2763 rq.ocf = OCF_READ_LINK_SUPERVISION_TIMEOUT;
2764 rq.cparam = &handle;
2767 rq.rlen = READ_LINK_SUPERVISION_TIMEOUT_RP_SIZE;
2769 if (hci_send_req(dd, &rq, to) < 0)
2777 *timeout = rp.timeout;
2781 int hci_write_link_supervision_timeout(int dd, uint16_t handle,
2782 uint16_t timeout, int to)
2784 write_link_supervision_timeout_cp cp;
2785 write_link_supervision_timeout_rp rp;
2786 struct hci_request rq;
2788 memset(&cp, 0, sizeof(cp));
2790 cp.timeout = timeout;
2792 memset(&rq, 0, sizeof(rq));
2793 rq.ogf = OGF_HOST_CTL;
2794 rq.ocf = OCF_WRITE_LINK_SUPERVISION_TIMEOUT;
2796 rq.clen = WRITE_LINK_SUPERVISION_TIMEOUT_CP_SIZE;
2798 rq.rlen = WRITE_LINK_SUPERVISION_TIMEOUT_RP_SIZE;
2800 if (hci_send_req(dd, &rq, to) < 0)
2811 int hci_set_afh_classification(int dd, uint8_t *map, int to)
2813 set_afh_classification_cp cp;
2814 set_afh_classification_rp rp;
2815 struct hci_request rq;
2817 memset(&cp, 0, sizeof(cp));
2818 memcpy(cp.map, map, 10);
2820 memset(&rq, 0, sizeof(rq));
2821 rq.ogf = OGF_HOST_CTL;
2822 rq.ocf = OCF_SET_AFH_CLASSIFICATION;
2824 rq.clen = SET_AFH_CLASSIFICATION_CP_SIZE;
2826 rq.rlen = SET_AFH_CLASSIFICATION_RP_SIZE;
2828 if (hci_send_req(dd, &rq, to) < 0)
2839 int hci_read_link_quality(int dd, uint16_t handle, uint8_t *link_quality,
2842 read_link_quality_rp rp;
2843 struct hci_request rq;
2845 memset(&rq, 0, sizeof(rq));
2846 rq.ogf = OGF_STATUS_PARAM;
2847 rq.ocf = OCF_READ_LINK_QUALITY;
2848 rq.cparam = &handle;
2851 rq.rlen = READ_LINK_QUALITY_RP_SIZE;
2853 if (hci_send_req(dd, &rq, to) < 0)
2861 *link_quality = rp.link_quality;
2865 int hci_read_rssi(int dd, uint16_t handle, int8_t *rssi, int to)
2868 struct hci_request rq;
2870 memset(&rq, 0, sizeof(rq));
2871 rq.ogf = OGF_STATUS_PARAM;
2872 rq.ocf = OCF_READ_RSSI;
2873 rq.cparam = &handle;
2876 rq.rlen = READ_RSSI_RP_SIZE;
2878 if (hci_send_req(dd, &rq, to) < 0)
2890 int hci_read_afh_map(int dd, uint16_t handle, uint8_t *mode, uint8_t *map,
2894 struct hci_request rq;
2896 memset(&rq, 0, sizeof(rq));
2897 rq.ogf = OGF_STATUS_PARAM;
2898 rq.ocf = OCF_READ_AFH_MAP;
2899 rq.cparam = &handle;
2902 rq.rlen = READ_AFH_MAP_RP_SIZE;
2904 if (hci_send_req(dd, &rq, to) < 0)
2913 memcpy(map, rp.map, 10);
2917 int hci_read_clock(int dd, uint16_t handle, uint8_t which, uint32_t *clock,
2918 uint16_t *accuracy, int to)
2922 struct hci_request rq;
2924 memset(&cp, 0, sizeof(cp));
2926 cp.which_clock = which;
2928 memset(&rq, 0, sizeof(rq));
2929 rq.ogf = OGF_STATUS_PARAM;
2930 rq.ocf = OCF_READ_CLOCK;
2932 rq.clen = READ_CLOCK_CP_SIZE;
2934 rq.rlen = READ_CLOCK_RP_SIZE;
2936 if (hci_send_req(dd, &rq, to) < 0)
2945 *accuracy = rp.accuracy;
2949 int hci_le_set_scan_enable(int dd, uint8_t enable, uint8_t filter_dup, int to)
2951 struct hci_request rq;
2952 le_set_scan_enable_cp scan_cp;
2955 memset(&scan_cp, 0, sizeof(scan_cp));
2956 scan_cp.enable = enable;
2957 scan_cp.filter_dup = filter_dup;
2959 memset(&rq, 0, sizeof(rq));
2960 rq.ogf = OGF_LE_CTL;
2961 rq.ocf = OCF_LE_SET_SCAN_ENABLE;
2962 rq.cparam = &scan_cp;
2963 rq.clen = LE_SET_SCAN_ENABLE_CP_SIZE;
2964 rq.rparam = &status;
2967 if (hci_send_req(dd, &rq, to) < 0)
2978 int hci_le_set_scan_parameters(int dd, uint8_t type,
2979 uint16_t interval, uint16_t window,
2980 uint8_t own_type, uint8_t filter, int to)
2982 struct hci_request rq;
2983 le_set_scan_parameters_cp param_cp;
2986 memset(¶m_cp, 0, sizeof(param_cp));
2987 param_cp.type = type;
2988 param_cp.interval = interval;
2989 param_cp.window = window;
2990 param_cp.own_bdaddr_type = own_type;
2991 param_cp.filter = filter;
2993 memset(&rq, 0, sizeof(rq));
2994 rq.ogf = OGF_LE_CTL;
2995 rq.ocf = OCF_LE_SET_SCAN_PARAMETERS;
2996 rq.cparam = ¶m_cp;
2997 rq.clen = LE_SET_SCAN_PARAMETERS_CP_SIZE;
2998 rq.rparam = &status;
3001 if (hci_send_req(dd, &rq, to) < 0)
3012 int hci_le_set_advertise_enable(int dd, uint8_t enable, int to)
3014 struct hci_request rq;
3015 le_set_advertise_enable_cp adv_cp;
3018 memset(&adv_cp, 0, sizeof(adv_cp));
3019 adv_cp.enable = enable;
3021 memset(&rq, 0, sizeof(rq));
3022 rq.ogf = OGF_LE_CTL;
3023 rq.ocf = OCF_LE_SET_ADVERTISE_ENABLE;
3024 rq.cparam = &adv_cp;
3025 rq.clen = LE_SET_ADVERTISE_ENABLE_CP_SIZE;
3026 rq.rparam = &status;
3029 if (hci_send_req(dd, &rq, to) < 0)
3040 int hci_le_create_conn(int dd, uint16_t interval, uint16_t window,
3041 uint8_t initiator_filter, uint8_t peer_bdaddr_type,
3042 bdaddr_t peer_bdaddr, uint8_t own_bdaddr_type,
3043 uint16_t min_interval, uint16_t max_interval,
3044 uint16_t latency, uint16_t supervision_timeout,
3045 uint16_t min_ce_length, uint16_t max_ce_length,
3046 uint16_t *handle, int to)
3048 struct hci_request rq;
3049 le_create_connection_cp create_conn_cp;
3050 evt_le_connection_complete conn_complete_rp;
3052 memset(&create_conn_cp, 0, sizeof(create_conn_cp));
3053 create_conn_cp.interval = interval;
3054 create_conn_cp.window = window;
3055 create_conn_cp.initiator_filter = initiator_filter;
3056 create_conn_cp.peer_bdaddr_type = peer_bdaddr_type;
3057 create_conn_cp.peer_bdaddr = peer_bdaddr;
3058 create_conn_cp.own_bdaddr_type = own_bdaddr_type;
3059 create_conn_cp.min_interval = min_interval;
3060 create_conn_cp.max_interval = max_interval;
3061 create_conn_cp.latency = latency;
3062 create_conn_cp.supervision_timeout = supervision_timeout;
3063 create_conn_cp.min_ce_length = min_ce_length;
3064 create_conn_cp.max_ce_length = max_ce_length;
3066 memset(&rq, 0, sizeof(rq));
3067 rq.ogf = OGF_LE_CTL;
3068 rq.ocf = OCF_LE_CREATE_CONN;
3069 rq.event = EVT_LE_CONN_COMPLETE;
3070 rq.cparam = &create_conn_cp;
3071 rq.clen = LE_CREATE_CONN_CP_SIZE;
3072 rq.rparam = &conn_complete_rp;
3073 rq.rlen = EVT_CONN_COMPLETE_SIZE;
3075 if (hci_send_req(dd, &rq, to) < 0)
3078 if (conn_complete_rp.status) {
3084 *handle = conn_complete_rp.handle;
3089 int hci_le_conn_update(int dd, uint16_t handle, uint16_t min_interval,
3090 uint16_t max_interval, uint16_t latency,
3091 uint16_t supervision_timeout, int to)
3093 evt_le_connection_update_complete evt;
3094 le_connection_update_cp cp;
3095 struct hci_request rq;
3097 memset(&cp, 0, sizeof(cp));
3099 cp.min_interval = min_interval;
3100 cp.max_interval = max_interval;
3101 cp.latency = latency;
3102 cp.supervision_timeout = supervision_timeout;
3103 cp.min_ce_length = htobs(0x0001);
3104 cp.max_ce_length = htobs(0x0001);
3106 memset(&rq, 0, sizeof(rq));
3107 rq.ogf = OGF_LE_CTL;
3108 rq.ocf = OCF_LE_CONN_UPDATE;
3110 rq.clen = LE_CONN_UPDATE_CP_SIZE;
3111 rq.event = EVT_LE_CONN_UPDATE_COMPLETE;
3113 rq.rlen = sizeof(evt);
3115 if (hci_send_req(dd, &rq, to) < 0)
3126 int hci_le_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to)
3128 evt_le_read_remote_used_features_complete rp;
3129 le_read_remote_used_features_cp cp;
3130 struct hci_request rq;
3132 memset(&cp, 0, sizeof(cp));
3135 memset(&rq, 0, sizeof(rq));
3136 rq.ogf = OGF_LE_CTL;
3137 rq.ocf = OCF_LE_READ_REMOTE_USED_FEATURES;
3138 rq.event = EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE;
3140 rq.clen = LE_READ_REMOTE_USED_FEATURES_CP_SIZE;
3142 rq.rlen = EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE_SIZE;
3144 if (hci_send_req(dd, &rq, to) < 0)
3153 memcpy(features, rp.features, 8);
3158 #ifdef __TIZEN_PATCH__
3159 int hci_le_read_maximum_data_length(
3160 int dd, uint8_t *status, uint16_t *tx_octets,
3161 uint16_t *tx_time, uint16_t *rx_octets,
3162 uint16_t *rx_time, int to)
3164 le_read_maximum_data_length_rp rp;
3165 struct hci_request rq;
3167 memset(&rq, 0, sizeof(rq));
3168 memset(&rp, 0, sizeof(rp));
3170 rq.ogf = OGF_LE_CTL;
3171 rq.ocf = OCF_LE_READ_MAXIMUM_DATA_LENGTH;
3173 rq.rlen = LE_READ_MAXIMUM_DATA_LENGTH_SIZE;
3175 if (hci_send_req(dd, &rq, to) < 0)
3183 *tx_octets = rp.max_tx_octets;
3184 *tx_time = rp.max_tx_time;
3185 *rx_octets = rp.max_rx_octets;
3186 *rx_time = rp.max_rx_time;
3187 *status = rp.status;
3191 int hci_le_write_host_suggested_data_length(
3192 int dd, uint16_t *def_tx_octets,
3193 uint16_t *def_tx_time, int to)
3195 le_write_host_suggested_data_length_cp cp;
3196 struct hci_request rq;
3199 memset(&cp, 0, sizeof(cp));
3200 cp.def_tx_octets = *def_tx_octets;
3201 cp.def_tx_time = *def_tx_time;
3203 memset(&rq, 0, sizeof(rq));
3204 rq.ogf = OGF_LE_CTL;
3205 rq.ocf = OCF_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH;
3207 rq.clen = LE_WRITE_HOST_SUGGESTED_DATA_LENGTH_CP_SIZE;
3208 rq.rparam = &status;
3211 if (hci_send_req(dd, &rq, to) < 0)
3222 int hci_le_read_host_suggested_data_length(
3223 int dd, uint8_t *status, uint16_t *def_tx_octets,
3224 uint16_t *def_tx_time, int to)
3226 le_read_host_suggested_data_length_rp rp;
3227 struct hci_request rq;
3229 memset(&rp, 0, sizeof(rp));
3230 memset(&rq, 0, sizeof(rq));
3232 rq.ogf = OGF_LE_CTL;
3233 rq.ocf = OCF_LE_READ_HOST_SUGGESTED_DATA_LENGTH;
3235 rq.rlen = LE_READ_HOST_SUGGESTED_DATA_LENGTH_SIZE;
3237 if (hci_send_req(dd, &rq, to) < 0)
3245 *def_tx_octets = rp.def_tx_octets;
3246 *def_tx_time = rp.def_tx_time;
3247 *status = rp.status;
3251 int hci_le_set_data_length(
3252 int dd, const bdaddr_t *bdaddr, uint16_t *max_tx_octets,
3253 uint16_t *max_tx_time, int to)
3255 le_set_data_length_cp cp;
3256 le_set_data_length_rp rp;
3257 struct hci_request rq;
3259 memset(&cp, 0, sizeof(cp));
3260 memset(&rp, 0, sizeof(rp));
3262 bacpy(&cp.bdaddr, bdaddr);
3263 cp.max_tx_octets = *max_tx_octets;
3264 cp.max_tx_time = *max_tx_time;
3266 memset(&rq, 0, sizeof(rq));
3267 rq.ogf = OGF_LE_CTL;
3268 rq.ocf = OCF_LE_SET_DATA_LENGTH;
3270 rq.clen = LE_SET_DATA_LENGTH_CP_SIZE;
3272 rq.rlen = LE_SET_DATA_LENGTH_RP_SIZE;
3274 if (hci_send_req(dd, &rq, to) < 0)