ble_gatt_client
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
hci.c
Go to the documentation of this file.
1 
11 /*
12  *
13  * BlueZ - Bluetooth protocol stack for Linux
14  *
15  * Copyright (C) 2000-2001 Qualcomm Incorporated
16  * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
17  * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
18  *
19  *
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation; either version 2 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33  *
34  */
35 
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39 
40 #include <stdio.h>
41 #include <errno.h>
42 #include <fcntl.h>
43 #include <unistd.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <poll.h>
47 
48 #include <sys/param.h>
49 #include <sys/uio.h>
50 #include <sys/types.h>
51 #include <sys/ioctl.h>
52 #include <sys/socket.h>
53 
54 #include "bluetooth.h"
55 #include "hci.h"
56 #include "hci_lib.h"
57 
58 #ifndef MIN
59 #define MIN(x, y) ((x) < (y) ? (x) : (y))
60 #endif
61 
62 typedef struct {
63  char *str;
64  unsigned int val;
65 } hci_map;
66 
74 static char *hci_bit2str(hci_map *m, unsigned int val)
75 {
76  char *str = malloc(120);
77  char *ptr = str;
78 
79  if (!str)
80  return NULL;
81 
82  *ptr = 0;
83  while (m->str) {
84  if ((unsigned int) m->val & val)
85  ptr += sprintf(ptr, "%s ", m->str);
86  m++;
87  }
88  return str;
89 }
90 static int hci_str2bit(hci_map *map, char *str, unsigned int *val)
100 {
101  char *t, *ptr;
102  hci_map *m;
103  int set;
104 
105  if (!str || !(str = ptr = strdup(str)))
106  return 0;
107 
108  *val = set = 0;
109 
110  while ((t = strsep(&ptr, ","))) {
111  for (m = map; m->str; m++) {
112  if (!strcasecmp(m->str, t)) {
113  *val |= (unsigned int) m->val;
114  set = 1;
115  }
116  }
117  }
118  free(str);
119 
120  return set;
121 }
122 
130 static char *hci_uint2str(hci_map *m, unsigned int val)
131 {
132  char *str = malloc(50);
133  char *ptr = str;
134 
135  if (!str)
136  return NULL;
137 
138  *ptr = 0;
139  while (m->str) {
140  if ((unsigned int) m->val == val) {
141  ptr += sprintf(ptr, "%s", m->str);
142  break;
143  }
144  m++;
145  }
146  return str;
147 }
148 
158 static int hci_str2uint(hci_map *map, char *str, unsigned int *val)
159 {
160  char *t, *ptr;
161  hci_map *m;
162  int set = 0;
163 
164  if (!str)
165  return 0;
166 
167  str = ptr = strdup(str);
168 
169  while ((t = strsep(&ptr, ","))) {
170  for (m = map; m->str; m++) {
171  if (!strcasecmp(m->str,t)) {
172  *val = (unsigned int) m->val;
173  set = 1;
174  break;
175  }
176  }
177  }
178  free(str);
179 
180  return set;
181 }
182 
189 char *hci_bustostr(int bus)
190 {
191  switch (bus) {
192  case HCI_VIRTUAL:
193  return "VIRTUAL";
194  case HCI_USB:
195  return "USB";
196  case HCI_PCCARD:
197  return "PCCARD";
198  case HCI_UART:
199  return "UART";
200  case HCI_RS232:
201  return "RS232";
202  case HCI_PCI:
203  return "PCI";
204  case HCI_SDIO:
205  return "SDIO";
206  default:
207  return "UNKNOWN";
208  }
209 }
210 
218 {
219  return hci_bustostr(type & 0x0f);
220 }
221 
228 char *hci_typetostr(int type)
229 {
230  switch (type) {
231  case HCI_BREDR:
232  return "BR/EDR";
233  case HCI_AMP:
234  return "AMP";
235  default:
236  return "UNKNOWN";
237  }
238 }
239 
240 /* HCI dev flags mapping */
241 static hci_map dev_flags_map[] = {
242  { "UP", HCI_UP },
243  { "INIT", HCI_INIT },
244  { "RUNNING", HCI_RUNNING },
245  { "RAW", HCI_RAW },
246  { "PSCAN", HCI_PSCAN },
247  { "ISCAN", HCI_ISCAN },
248  { "INQUIRY", HCI_INQUIRY },
249  { "AUTH", HCI_AUTH },
250  { "ENCRYPT", HCI_ENCRYPT },
251  { NULL }
252 };
253 
260 char *hci_dflagstostr(uint32_t flags)
261 {
262  char *str = bt_malloc(50);
263  char *ptr = str;
264  hci_map *m = dev_flags_map;
265 
266  if (!str)
267  return NULL;
268 
269  *ptr = 0;
270 
271  if (!hci_test_bit(HCI_UP, &flags))
272  ptr += sprintf(ptr, "DOWN ");
273 
274  while (m->str) {
275  if (hci_test_bit(m->val, &flags))
276  ptr += sprintf(ptr, "%s ", m->str);
277  m++;
278  }
279  return str;
280 }
281 
282 /* HCI packet type mapping */
283 static hci_map pkt_type_map[] = {
284  { "DM1", HCI_DM1 },
285  { "DM3", HCI_DM3 },
286  { "DM5", HCI_DM5 },
287  { "DH1", HCI_DH1 },
288  { "DH3", HCI_DH3 },
289  { "DH5", HCI_DH5 },
290  { "HV1", HCI_HV1 },
291  { "HV2", HCI_HV2 },
292  { "HV3", HCI_HV3 },
293  { "2-DH1", HCI_2DH1 },
294  { "2-DH3", HCI_2DH3 },
295  { "2-DH5", HCI_2DH5 },
296  { "3-DH1", HCI_3DH1 },
297  { "3-DH3", HCI_3DH3 },
298  { "3-DH5", HCI_3DH5 },
299  { NULL }
300 };
301 
302 /* SCO (synchronous connection orientated) links */
303 static hci_map sco_ptype_map[] = {
304  { "HV1", 0x0001 },
305  { "HV2", 0x0002 },
306  { "HV3", 0x0004 },
307  { "EV3", HCI_EV3 },
308  { "EV4", HCI_EV4 },
309  { "EV5", HCI_EV5 },
310  { "2-EV3", HCI_2EV3 },
311  { "2-EV5", HCI_2EV5 },
312  { "3-EV3", HCI_3EV3 },
313  { "3-EV5", HCI_3EV5 },
314  { NULL }
315 };
316 
323 char *hci_ptypetostr(unsigned int ptype)
324 {
325  return hci_bit2str(pkt_type_map, ptype);
326 }
327 
335 int hci_strtoptype(char *str, unsigned int *val)
336 {
337  return hci_str2bit(pkt_type_map, str, val);
338 }
339 
346 char *hci_scoptypetostr(unsigned int ptype)
347 {
348  return hci_bit2str(sco_ptype_map, ptype);
349 }
350 
358 int hci_strtoscoptype(char *str, unsigned int *val)
359 {
360  return hci_str2bit(sco_ptype_map, str, val);
361 }
362 
363 /* Link policy mapping */
365  { "NONE", 0 },
366  { "RSWITCH", HCI_LP_RSWITCH },
367  { "HOLD", HCI_LP_HOLD },
368  { "SNIFF", HCI_LP_SNIFF },
369  { "PARK", HCI_LP_PARK },
370  { NULL }
371 };
372 
379 char *hci_lptostr(unsigned int lp)
380 {
381  return hci_bit2str(link_policy_map, lp);
382 }
383 
391 int hci_strtolp(char *str, unsigned int *val)
392 {
393  return hci_str2bit(link_policy_map, str, val);
394 }
395 
396 /* Link mode mapping */
397 static hci_map link_mode_map[] = {
398  { "NONE", 0 },
399  { "ACCEPT", HCI_LM_ACCEPT },
400  { "MASTER", HCI_LM_MASTER },
401  { "AUTH", HCI_LM_AUTH },
402  { "ENCRYPT", HCI_LM_ENCRYPT },
403  { "TRUSTED", HCI_LM_TRUSTED },
404  { "RELIABLE", HCI_LM_RELIABLE },
405  { "SECURE", HCI_LM_SECURE },
406  { NULL }
407 };
408 
415 char *hci_lmtostr(unsigned int lm)
416 {
417  char *s, *str = bt_malloc(50);
418  if (!str)
419  return NULL;
420 
421  *str = 0;
422  if (!(lm & HCI_LM_MASTER))
423  strcpy(str, "SLAVE ");
424 
425  s = hci_bit2str(link_mode_map, lm);
426  if (!s) {
427  bt_free(str);
428  return NULL;
429  }
430 
431  strcat(str, s);
432  free(s);
433  return str;
434 }
435 
443 int hci_strtolm(char *str, unsigned int *val)
444 {
445  return hci_str2bit(link_mode_map, str, val);
446 }
447 
448 /* Command mapping */
449 static hci_map commands_map[] = {
450  { "Inquiry", 0 },
451  { "Inquiry Cancel", 1 },
452  { "Periodic Inquiry Mode", 2 },
453  { "Exit Periodic Inquiry Mode", 3 },
454  { "Create Connection", 4 },
455  { "Disconnect", 5 },
456  { "Add SCO Connection", 6 },
457  { "Cancel Create Connection", 7 },
458 
459  { "Accept Connection Request", 8 },
460  { "Reject Connection Request", 9 },
461  { "Link Key Request Reply", 10 },
462  { "Link Key Request Negative Reply", 11 },
463  { "PIN Code Request Reply", 12 },
464  { "PIN Code Request Negative Reply", 13 },
465  { "Change Connection Packet Type", 14 },
466  { "Authentication Requested", 15 },
467 
468  { "Set Connection Encryption", 16 },
469  { "Change Connection Link Key", 17 },
470  { "Master Link Key", 18 },
471  { "Remote Name Request", 19 },
472  { "Cancel Remote Name Request", 20 },
473  { "Read Remote Supported Features", 21 },
474  { "Read Remote Extended Features", 22 },
475  { "Read Remote Version Information", 23 },
476 
477  { "Read Clock Offset", 24 },
478  { "Read LMP Handle", 25 },
479  { "Reserved", 26 },
480  { "Reserved", 27 },
481  { "Reserved", 28 },
482  { "Reserved", 29 },
483  { "Reserved", 30 },
484  { "Reserved", 31 },
485 
486  { "Reserved", 32 },
487  { "Hold Mode", 33 },
488  { "Sniff Mode", 34 },
489  { "Exit Sniff Mode", 35 },
490  { "Park State", 36 },
491  { "Exit Park State", 37 },
492  { "QoS Setup", 38 },
493  { "Role Discovery", 39 },
494 
495  { "Switch Role", 40 },
496  { "Read Link Policy Settings", 41 },
497  { "Write Link Policy Settings", 42 },
498  { "Read Default Link Policy Settings", 43 },
499  { "Write Default Link Policy Settings", 44 },
500  { "Flow Specification", 45 },
501  { "Set Event Mask", 46 },
502  { "Reset", 47 },
503 
504  { "Set Event Filter", 48 },
505  { "Flush", 49 },
506  { "Read PIN Type", 50 },
507  { "Write PIN Type", 51 },
508  { "Create New Unit Key", 52 },
509  { "Read Stored Link Key", 53 },
510  { "Write Stored Link Key", 54 },
511  { "Delete Stored Link Key", 55 },
512 
513  { "Write Local Name", 56 },
514  { "Read Local Name", 57 },
515  { "Read Connection Accept Timeout", 58 },
516  { "Write Connection Accept Timeout", 59 },
517  { "Read Page Timeout", 60 },
518  { "Write Page Timeout", 61 },
519  { "Read Scan Enable", 62 },
520  { "Write Scan Enable", 63 },
521 
522  { "Read Page Scan Activity", 64 },
523  { "Write Page Scan Activity", 65 },
524  { "Read Inquiry Scan Activity", 66 },
525  { "Write Inquiry Scan Activity", 67 },
526  { "Read Authentication Enable", 68 },
527  { "Write Authentication Enable", 69 },
528  { "Read Encryption Mode", 70 },
529  { "Write Encryption Mode", 71 },
530 
531  { "Read Class Of Device", 72 },
532  { "Write Class Of Device", 73 },
533  { "Read Voice Setting", 74 },
534  { "Write Voice Setting", 75 },
535  { "Read Automatic Flush Timeout", 76 },
536  { "Write Automatic Flush Timeout", 77 },
537  { "Read Num Broadcast Retransmissions", 78 },
538  { "Write Num Broadcast Retransmissions", 79 },
539 
540  { "Read Hold Mode Activity", 80 },
541  { "Write Hold Mode Activity", 81 },
542  { "Read Transmit Power Level", 82 },
543  { "Read Synchronous Flow Control Enable", 83 },
544  { "Write Synchronous Flow Control Enable", 84 },
545  { "Set Host Controller To Host Flow Control", 85 },
546  { "Host Buffer Size", 86 },
547  { "Host Number Of Completed Packets", 87 },
548 
549  { "Read Link Supervision Timeout", 88 },
550  { "Write Link Supervision Timeout", 89 },
551  { "Read Number of Supported IAC", 90 },
552  { "Read Current IAC LAP", 91 },
553  { "Write Current IAC LAP", 92 },
554  { "Read Page Scan Period Mode", 93 },
555  { "Write Page Scan Period Mode", 94 },
556  { "Read Page Scan Mode", 95 },
557 
558  { "Write Page Scan Mode", 96 },
559  { "Set AFH Channel Classification", 97 },
560  { "Reserved", 98 },
561  { "Reserved", 99 },
562  { "Read Inquiry Scan Type", 100 },
563  { "Write Inquiry Scan Type", 101 },
564  { "Read Inquiry Mode", 102 },
565  { "Write Inquiry Mode", 103 },
566 
567  { "Read Page Scan Type", 104 },
568  { "Write Page Scan Type", 105 },
569  { "Read AFH Channel Assessment Mode", 106 },
570  { "Write AFH Channel Assessment Mode", 107 },
571  { "Reserved", 108 },
572  { "Reserved", 109 },
573  { "Reserved", 110 },
574  { "Reserved", 111 },
575 
576  { "Reserved", 112 },
577  { "Reserved", 113 },
578  { "Reserved", 114 },
579  { "Read Local Version Information", 115 },
580  { "Read Local Supported Commands", 116 },
581  { "Read Local Supported Features", 117 },
582  { "Read Local Extended Features", 118 },
583  { "Read Buffer Size", 119 },
584 
585  { "Read Country Code", 120 },
586  { "Read BD ADDR", 121 },
587  { "Read Failed Contact Counter", 122 },
588  { "Reset Failed Contact Counter", 123 },
589  { "Get Link Quality", 124 },
590  { "Read RSSI", 125 },
591  { "Read AFH Channel Map", 126 },
592  { "Read BD Clock", 127 },
593 
594  { "Read Loopback Mode", 128 },
595  { "Write Loopback Mode", 129 },
596  { "Enable Device Under Test Mode", 130 },
597  { "Setup Synchronous Connection", 131 },
598  { "Accept Synchronous Connection", 132 },
599  { "Reject Synchronous Connection", 133 },
600  { "Reserved", 134 },
601  { "Reserved", 135 },
602 
603  { "Read Extended Inquiry Response", 136 },
604  { "Write Extended Inquiry Response", 137 },
605  { "Refresh Encryption Key", 138 },
606  { "Reserved", 139 },
607  { "Sniff Subrating", 140 },
608  { "Read Simple Pairing Mode", 141 },
609  { "Write Simple Pairing Mode", 142 },
610  { "Read Local OOB Data", 143 },
611 
612  { "Read Inquiry Response Transmit Power Level", 144 },
613  { "Write Inquiry Transmit Power Level", 145 },
614  { "Read Default Erroneous Data Reporting", 146 },
615  { "Write Default Erroneous Data Reporting", 147 },
616  { "Reserved", 148 },
617  { "Reserved", 149 },
618  { "Reserved", 150 },
619  { "IO Capability Request Reply", 151 },
620 
621  { "User Confirmation Request Reply", 152 },
622  { "User Confirmation Request Negative Reply", 153 },
623  { "User Passkey Request Reply", 154 },
624  { "User Passkey Request Negative Reply", 155 },
625  { "Remote OOB Data Request Reply", 156 },
626  { "Write Simple Pairing Debug Mode", 157 },
627  { "Enhanced Flush", 158 },
628  { "Remote OOB Data Request Negative Reply", 159 },
629 
630  { "Reserved", 160 },
631  { "Reserved", 161 },
632  { "Send Keypress Notification", 162 },
633  { "IO Capability Request Negative Reply", 163 },
634  { "Read Encryption Key Size", 164 },
635  { "Reserved", 165 },
636  { "Reserved", 166 },
637  { "Reserved", 167 },
638 
639  { "Create Physical Link", 168 },
640  { "Accept Physical Link", 169 },
641  { "Disconnect Physical Link", 170 },
642  { "Create Logical Link", 171 },
643  { "Accept Logical Link", 172 },
644  { "Disconnect Logical Link", 173 },
645  { "Logical Link Cancel", 174 },
646  { "Flow Specification Modify", 175 },
647 
648  { "Read Logical Link Accept Timeout", 176 },
649  { "Write Logical Link Accept Timeout", 177 },
650  { "Set Event Mask Page 2", 178 },
651  { "Read Location Data", 179 },
652  { "Write Location Data", 180 },
653  { "Read Local AMP Info", 181 },
654  { "Read Local AMP_ASSOC", 182 },
655  { "Write Remote AMP_ASSOC", 183 },
656 
657  { "Read Flow Control Mode", 184 },
658  { "Write Flow Control Mode", 185 },
659  { "Read Data Block Size", 186 },
660  { "Reserved", 187 },
661  { "Reserved", 188 },
662  { "Enable AMP Receiver Reports", 189 },
663  { "AMP Test End", 190 },
664  { "AMP Test Command", 191 },
665 
666  { "Read Enhanced Transmit Power Level", 192 },
667  { "Reserved", 193 },
668  { "Read Best Effort Flush Timeout", 194 },
669  { "Write Best Effort Flush Timeout", 195 },
670  { "Short Range Mode", 196 },
671  { "Read LE Host Support", 197 },
672  { "Write LE Host Support", 198 },
673  { "Reserved", 199 },
674 
675  { "LE Set Event Mask", 200 },
676  { "LE Read Buffer Size", 201 },
677  { "LE Read Local Supported Features", 202 },
678  { "Reserved", 203 },
679  { "LE Set Random Address", 204 },
680  { "LE Set Advertising Parameters", 205 },
681  { "LE Read Advertising Channel TX Power", 206 },
682  { "LE Set Advertising Data", 207 },
683 
684  { "LE Set Scan Response Data", 208 },
685  { "LE Set Advertise Enable", 209 },
686  { "LE Set Scan Parameters", 210 },
687  { "LE Set Scan Enable", 211 },
688  { "LE Create Connection", 212 },
689  { "LE Create Connection Cancel", 213 },
690  { "LE Read White List Size", 214 },
691  { "LE Clear White List", 215 },
692 
693  { "LE Add Device To White List", 216 },
694  { "LE Remove Device From White List", 217 },
695  { "LE Connection Update", 218 },
696  { "LE Set Host Channel Classification", 219 },
697  { "LE Read Channel Map", 220 },
698  { "LE Read Remote Used Features", 221 },
699  { "LE Encrypt", 222 },
700  { "LE Rand", 223 },
701 
702  { "LE Start Encryption", 224 },
703  { "LE Long Term Key Request Reply", 225 },
704  { "LE Long Term Key Request Negative Reply", 226 },
705  { "LE Read Supported States", 227 },
706  { "LE Receiver Test", 228 },
707  { "LE Transmitter Test", 229 },
708  { "LE Test End", 230 },
709  { "Reserved", 231 },
710 
711  { NULL }
712 };
713 
722 char *hci_cmdtostr(unsigned int cmd)
723 {
724  return hci_uint2str(commands_map, cmd);
725 }
726 
735 char *hci_commandstostr(uint8_t *commands, char *pref, int width)
736 {
737  unsigned int maxwidth = width - 3;
738  hci_map *m;
739  char *off, *ptr, *str;
740  int size = 10;
741 
742  m = commands_map;
743 
744  while (m->str) {
745  if (commands[m->val / 8] & (1 << (m->val % 8)))
746  size += strlen(m->str) + (pref ? strlen(pref) : 0) + 3;
747  m++;
748  }
749 
750  str = bt_malloc(size);
751  if (!str)
752  return NULL;
753 
754  ptr = str; *ptr = '\0';
755 
756  if (pref)
757  ptr += sprintf(ptr, "%s", pref);
758 
759  off = ptr;
760 
761  m = commands_map;
762 
763  while (m->str) {
764  if (commands[m->val / 8] & (1 << (m->val % 8))) {
765  if (strlen(off) + strlen(m->str) > maxwidth) {
766  ptr += sprintf(ptr, "\n%s", pref ? pref : "");
767  off = ptr;
768  }
769  ptr += sprintf(ptr, "'%s' ", m->str);
770  }
771  m++;
772  }
773 
774  return str;
775 }
776 
777 /* Version mapping */
778 static hci_map ver_map[] = {
779  { "1.0b", 0x00 },
780  { "1.1", 0x01 },
781  { "1.2", 0x02 },
782  { "2.0", 0x03 },
783  { "2.1", 0x04 },
784  { "3.0", 0x05 },
785  { "4.0", 0x06 },
786  { "4.1", 0x07 },
787  { "4.2", 0x08 },
788  { NULL }
789 };
790 
797 char *hci_vertostr(unsigned int ver)
798 {
799  return hci_uint2str(ver_map, ver);
800 }
801 
809 int hci_strtover(char *str, unsigned int *ver)
810 {
811  return hci_str2uint(ver_map, str, ver);
812 }
813 
820 char *lmp_vertostr(unsigned int ver)
821 {
822  return hci_uint2str(ver_map, ver);
823 }
824 
832 int lmp_strtover(char *str, unsigned int *ver)
833 {
834  return hci_str2uint(ver_map, str, ver);
835 }
836 
837 static hci_map pal_map[] = {
838  { "3.0", 0x01 },
839  { NULL }
840 };
841 
848 char *pal_vertostr(unsigned int ver)
849 {
850  return hci_uint2str(pal_map, ver);
851 }
852 
860 int pal_strtover(char *str, unsigned int *ver)
861 {
862  return hci_str2uint(pal_map, str, ver);
863 }
864 
865 /* LMP features mapping */
866 static hci_map lmp_features_map[8][9] = {
867  { /* Byte 0 */
868  { "<3-slot packets>", LMP_3SLOT }, /* Bit 0 */
869  { "<5-slot packets>", LMP_5SLOT }, /* Bit 1 */
870  { "<encryption>", LMP_ENCRYPT }, /* Bit 2 */
871  { "<slot offset>", LMP_SOFFSET }, /* Bit 3 */
872  { "<timing accuracy>", LMP_TACCURACY }, /* Bit 4 */
873  { "<role switch>", LMP_RSWITCH }, /* Bit 5 */
874  { "<hold mode>", LMP_HOLD }, /* Bit 6 */
875  { "<sniff mode>", LMP_SNIFF }, /* Bit 7 */
876  { NULL }
877  },
878  { /* Byte 1 */
879  { "<park state>", LMP_PARK }, /* Bit 0 */
880  { "<RSSI>", LMP_RSSI }, /* Bit 1 */
881  { "<channel quality>", LMP_QUALITY }, /* Bit 2 */
882  { "<SCO link>", LMP_SCO }, /* Bit 3 */
883  { "<HV2 packets>", LMP_HV2 }, /* Bit 4 */
884  { "<HV3 packets>", LMP_HV3 }, /* Bit 5 */
885  { "<u-law log>", LMP_ULAW }, /* Bit 6 */
886  { "<A-law log>", LMP_ALAW }, /* Bit 7 */
887  { NULL }
888  },
889  { /* Byte 2 */
890  { "<CVSD>", LMP_CVSD }, /* Bit 0 */
891  { "<paging scheme>", LMP_PSCHEME }, /* Bit 1 */
892  { "<power control>", LMP_PCONTROL }, /* Bit 2 */
893  { "<transparent SCO>", LMP_TRSP_SCO }, /* Bit 3 */
894  { "<broadcast encrypt>",LMP_BCAST_ENC }, /* Bit 7 */
895  { NULL }
896  },
897  { /* Byte 3 */
898  { "<no. 24>", 0x01 }, /* Bit 0 */
899  { "<EDR ACL 2 Mbps>", LMP_EDR_ACL_2M }, /* Bit 1 */
900  { "<EDR ACL 3 Mbps>", LMP_EDR_ACL_3M }, /* Bit 2 */
901  { "<enhanced iscan>", LMP_ENH_ISCAN }, /* Bit 3 */
902  { "<interlaced iscan>", LMP_ILACE_ISCAN }, /* Bit 4 */
903  { "<interlaced pscan>", LMP_ILACE_PSCAN }, /* Bit 5 */
904  { "<inquiry with RSSI>",LMP_RSSI_INQ }, /* Bit 6 */
905  { "<extended SCO>", LMP_ESCO }, /* Bit 7 */
906  { NULL }
907  },
908  { /* Byte 4 */
909  { "<EV4 packets>", LMP_EV4 }, /* Bit 0 */
910  { "<EV5 packets>", LMP_EV5 }, /* Bit 1 */
911  { "<no. 34>", 0x04 }, /* Bit 2 */
912  { "<AFH cap. slave>", LMP_AFH_CAP_SLV }, /* Bit 3 */
913  { "<AFH class. slave>", LMP_AFH_CLS_SLV }, /* Bit 4 */
914  { "<BR/EDR not supp.>", LMP_NO_BREDR }, /* Bit 5 */
915  { "<LE support>", LMP_LE }, /* Bit 6 */
916  { "<3-slot EDR ACL>", LMP_EDR_3SLOT }, /* Bit 7 */
917  { NULL }
918  },
919  { /* Byte 5 */
920  { "<5-slot EDR ACL>", LMP_EDR_5SLOT }, /* Bit 0 */
921  { "<sniff subrating>", LMP_SNIFF_SUBR }, /* Bit 1 */
922  { "<pause encryption>", LMP_PAUSE_ENC }, /* Bit 2 */
923  { "<AFH cap. master>", LMP_AFH_CAP_MST }, /* Bit 3 */
924  { "<AFH class. master>",LMP_AFH_CLS_MST }, /* Bit 4 */
925  { "<EDR eSCO 2 Mbps>", LMP_EDR_ESCO_2M }, /* Bit 5 */
926  { "<EDR eSCO 3 Mbps>", LMP_EDR_ESCO_3M }, /* Bit 6 */
927  { "<3-slot EDR eSCO>", LMP_EDR_3S_ESCO }, /* Bit 7 */
928  { NULL }
929  },
930  { /* Byte 6 */
931  { "<extended inquiry>", LMP_EXT_INQ }, /* Bit 0 */
932  { "<LE and BR/EDR>", LMP_LE_BREDR }, /* Bit 1 */
933  { "<no. 50>", 0x04 }, /* Bit 2 */
934  { "<simple pairing>", LMP_SIMPLE_PAIR }, /* Bit 3 */
935  { "<encapsulated PDU>", LMP_ENCAPS_PDU }, /* Bit 4 */
936  { "<err. data report>", LMP_ERR_DAT_REP }, /* Bit 5 */
937  { "<non-flush flag>", LMP_NFLUSH_PKTS }, /* Bit 6 */
938  { "<no. 55>", 0x80 }, /* Bit 7 */
939  { NULL }
940  },
941  { /* Byte 7 */
942  { "<LSTO>", LMP_LSTO }, /* Bit 1 */
943  { "<inquiry TX power>", LMP_INQ_TX_PWR }, /* Bit 1 */
944  { "<EPC>", LMP_EPC }, /* Bit 2 */
945  { "<no. 59>", 0x08 }, /* Bit 3 */
946  { "<no. 60>", 0x10 }, /* Bit 4 */
947  { "<no. 61>", 0x20 }, /* Bit 5 */
948  { "<no. 62>", 0x40 }, /* Bit 6 */
949  { "<extended features>",LMP_EXT_FEAT }, /* Bit 7 */
950  { NULL }
951  },
952 };
953 
962 char *lmp_featurestostr(uint8_t *features, char *pref, int width)
963 {
964  unsigned int maxwidth = width - 1;
965  char *off, *ptr, *str;
966  int i, size = 10;
967 
968  for (i = 0; i < 8; i++) {
969  hci_map *m = lmp_features_map[i];
970 
971  while (m->str) {
972  if (m->val & features[i])
973  size += strlen(m->str) +
974  (pref ? strlen(pref) : 0) + 1;
975  m++;
976  }
977  }
978 
979  str = bt_malloc(size);
980  if (!str)
981  return NULL;
982 
983  ptr = str; *ptr = '\0';
984 
985  if (pref)
986  ptr += sprintf(ptr, "%s", pref);
987 
988  off = ptr;
989 
990  for (i = 0; i < 8; i++) {
991  hci_map *m = lmp_features_map[i];
992 
993  while (m->str) {
994  if (m->val & features[i]) {
995  if (strlen(off) + strlen(m->str) > maxwidth) {
996  ptr += sprintf(ptr, "\n%s",
997  pref ? pref : "");
998  off = ptr;
999  }
1000  ptr += sprintf(ptr, "%s ", m->str);
1001  }
1002  m++;
1003  }
1004  }
1005 
1006  return str;
1007 }
1008 
1009 /* HCI functions that do not require open device */
1010 
1019 int hci_for_each_dev(int flag, int (*func)(int dd, int dev_id, long arg),
1020  long arg)
1021 {
1022  struct hci_dev_list_req *dl;
1023  struct hci_dev_req *dr;
1024  int dev_id = -1;
1025  int i, sk, err = 0;
1026 
1027  sk = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
1028  if (sk < 0)
1029  return -1;
1030 
1031  dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
1032  if (!dl) {
1033  err = errno;
1034  goto done;
1035  }
1036 
1037  memset(dl, 0, HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
1038 
1039  dl->dev_num = HCI_MAX_DEV;
1040  dr = dl->dev_req;
1041 
1042  if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
1043  err = errno;
1044  goto free;
1045  }
1046 
1047  for (i = 0; i < dl->dev_num; i++, dr++) {
1048  if (hci_test_bit(flag, &dr->dev_opt))
1049  if (!func || func(sk, dr->dev_id, arg)) {
1050  dev_id = dr->dev_id;
1051  break;
1052  }
1053  }
1054 
1055  if (dev_id < 0)
1056  err = ENODEV;
1057 
1058 free:
1059  free(dl);
1060 
1061 done:
1062  close(sk);
1063  errno = err;
1064 
1065  return dev_id;
1066 }
1067 
1075 static int __other_bdaddr(int dd, int dev_id, long arg)
1076 {
1077  struct hci_dev_info di = { .dev_id = dev_id };
1078 
1079  if (ioctl(dd, HCIGETDEVINFO, (void *) &di))
1080  return 0;
1081 
1082  if (hci_test_bit(HCI_RAW, &di.flags))
1083  return 0;
1084 
1085  return bacmp((bdaddr_t *) arg, &di.bdaddr);
1086 }
1087 
1095 static int __same_bdaddr(int dd, int dev_id, long arg)
1096 {
1097  struct hci_dev_info di = { .dev_id = dev_id };
1098 
1099  if (ioctl(dd, HCIGETDEVINFO, (void *) &di))
1100  return 0;
1101 
1102  return !bacmp((bdaddr_t *) arg, &di.bdaddr);
1103 }
1104 
1111 int hci_get_route(bdaddr_t *bdaddr)
1112 {
1113  int dev_id;
1114 
1116  (long) (bdaddr ? bdaddr : BDADDR_ANY));
1117  if (dev_id < 0)
1119  (long) (bdaddr ? bdaddr : BDADDR_ANY));
1120 
1121  return dev_id;
1122 }
1123 
1130 int hci_devid(const char *str)
1131 {
1132  bdaddr_t ba;
1133  int id = -1;
1134 
1135  if (!strncmp(str, "hci", 3) && strlen(str) >= 4) {
1136  id = atoi(str + 3);
1137  if (hci_devba(id, &ba) < 0)
1138  return -1;
1139  } else {
1140  errno = ENODEV;
1141  str2ba(str, &ba);
1142  id = hci_for_each_dev(HCI_UP, __same_bdaddr, (long) &ba);
1143  }
1144 
1145  return id;
1146 }
1147 
1155 int hci_devinfo(int dev_id, struct hci_dev_info *di)
1156 {
1157  int dd, err, ret;
1158 
1159  dd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
1160  if (dd < 0)
1161  return dd;
1162 
1163  memset(di, 0, sizeof(struct hci_dev_info));
1164 
1165  di->dev_id = dev_id;
1166  ret = ioctl(dd, HCIGETDEVINFO, (void *) di);
1167 
1168  err = errno;
1169  close(dd);
1170  errno = err;
1171 
1172  return ret;
1173 }
1174 
1182 int hci_devba(int dev_id, bdaddr_t *bdaddr)
1183 {
1184  struct hci_dev_info di;
1185 
1186  memset(&di, 0, sizeof(di));
1187 
1188  if (hci_devinfo(dev_id, &di))
1189  return -1;
1190 
1191  if (!hci_test_bit(HCI_UP, &di.flags)) {
1192  errno = ENETDOWN;
1193  return -1;
1194  }
1195 
1196  bacpy(bdaddr, &di.bdaddr);
1197 
1198  return 0;
1199 }
1200 
1212 int hci_inquiry(int dev_id, int len, int nrsp, const uint8_t *lap,
1213  inquiry_info **ii, long flags)
1214 {
1215  struct hci_inquiry_req *ir;
1216  uint8_t num_rsp = nrsp;
1217  void *buf;
1218  int dd, size, err, ret = -1;
1219 
1220  if (nrsp <= 0) {
1221  num_rsp = 0;
1222  nrsp = 255;
1223  }
1224 
1225  if (dev_id < 0) {
1226  dev_id = hci_get_route(NULL);
1227  if (dev_id < 0) {
1228  errno = ENODEV;
1229  return -1;
1230  }
1231  }
1232 
1233  dd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
1234  if (dd < 0)
1235  return dd;
1236 
1237  buf = malloc(sizeof(*ir) + (sizeof(inquiry_info) * (nrsp)));
1238  if (!buf)
1239  goto done;
1240 
1241  ir = buf;
1242  ir->dev_id = dev_id;
1243  ir->num_rsp = num_rsp;
1244  ir->length = len;
1245  ir->flags = flags;
1246 
1247  if (lap) {
1248  memcpy(ir->lap, lap, 3);
1249  } else {
1250  ir->lap[0] = 0x33;
1251  ir->lap[1] = 0x8b;
1252  ir->lap[2] = 0x9e;
1253  }
1254 
1255  ret = ioctl(dd, HCIINQUIRY, (unsigned long) buf);
1256  if (ret < 0)
1257  goto free;
1258 
1259  size = sizeof(inquiry_info) * ir->num_rsp;
1260 
1261  if (!*ii)
1262  *ii = malloc(size);
1263 
1264  if (*ii) {
1265  memcpy((void *) *ii, buf + sizeof(*ir), size);
1266  ret = ir->num_rsp;
1267  } else
1268  ret = -1;
1269 
1270 free:
1271  free(buf);
1272 
1273 done:
1274  err = errno;
1275  close(dd);
1276  errno = err;
1277 
1278  return ret;
1279 }
1280 
1288 {
1289  struct sockaddr_hci a;
1290  int dd, err;
1291 
1292  /* Check for valid device id */
1293  if (dev_id < 0) {
1294  errno = ENODEV;
1295  return -1;
1296  }
1297 
1298  /* Create HCI socket */
1299  dd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
1300  if (dd < 0)
1301  return dd;
1302 
1303  /* Bind socket to the HCI device */
1304  memset(&a, 0, sizeof(a));
1306  a.hci_dev = dev_id;
1307  if (bind(dd, (struct sockaddr *) &a, sizeof(a)) < 0)
1308  goto failed;
1309 
1310  return dd;
1311 
1312 failed:
1313  err = errno;
1314  close(dd);
1315  errno = err;
1316 
1317  return -1;
1318 }
1319 
1326 int hci_close_dev(int dd)
1327 {
1328  return close(dd);
1329 }
1330 
1331 /* HCI functions that require open device */
1332 
1343 int hci_send_cmd(int dd, uint16_t ogf, uint16_t ocf, uint8_t plen, void *param)
1344 {
1345  uint8_t type = HCI_COMMAND_PKT;
1346  hci_command_hdr hc;
1347  struct iovec iv[3];
1348  int ivn;
1349 
1350  hc.opcode = htobs(cmd_opcode_pack(ogf, ocf));
1351  hc.plen= plen;
1352 
1353  iv[0].iov_base = &type;
1354  iv[0].iov_len = 1;
1355  iv[1].iov_base = &hc;
1356  iv[1].iov_len = HCI_COMMAND_HDR_SIZE;
1357  ivn = 2;
1358 
1359  if (plen) {
1360  iv[2].iov_base = param;
1361  iv[2].iov_len = plen;
1362  ivn = 3;
1363  }
1364 
1365  while (writev(dd, iv, ivn) < 0) {
1366  if (errno == EAGAIN || errno == EINTR)
1367  continue;
1368  return -1;
1369  }
1370  return 0;
1371 }
1372 
1381 int hci_send_req(int dd, struct hci_request *r, int to)
1382 {
1383  unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr;
1384  uint16_t opcode = htobs(cmd_opcode_pack(r->ogf, r->ocf));
1385  struct hci_filter nf, of;
1386  socklen_t olen;
1387  hci_event_hdr *hdr;
1388  int err, try;
1389 
1390  olen = sizeof(of);
1391  if (getsockopt(dd, SOL_HCI, HCI_FILTER, &of, &olen) < 0)
1392  return -1;
1393 
1394  hci_filter_clear(&nf);
1399  hci_filter_set_event(r->event, &nf);
1400  hci_filter_set_opcode(opcode, &nf);
1401  if (setsockopt(dd, SOL_HCI, HCI_FILTER, &nf, sizeof(nf)) < 0)
1402  return -1;
1403 
1404  if (hci_send_cmd(dd, r->ogf, r->ocf, r->clen, r->cparam) < 0)
1405  goto failed;
1406 
1407  try = 10;
1408  while (try--) {
1409  evt_cmd_complete *cc;
1410  evt_cmd_status *cs;
1411  evt_remote_name_req_complete *rn;
1412  evt_le_meta_event *me;
1413  remote_name_req_cp *cp;
1414  int len;
1415 
1416  if (to) {
1417  struct pollfd p;
1418  int n;
1419 
1420  p.fd = dd; p.events = POLLIN;
1421  while ((n = poll(&p, 1, to)) < 0) {
1422  if (errno == EAGAIN || errno == EINTR)
1423  continue;
1424  goto failed;
1425  }
1426 
1427  if (!n) {
1428  errno = ETIMEDOUT;
1429  goto failed;
1430  }
1431 
1432  to -= 10;
1433  if (to < 0)
1434  to = 0;
1435 
1436  }
1437 
1438  while ((len = read(dd, buf, sizeof(buf))) < 0) {
1439  if (errno == EAGAIN || errno == EINTR)
1440  continue;
1441  goto failed;
1442  }
1443 
1444  hdr = (void *) (buf + 1);
1445  ptr = buf + (1 + HCI_EVENT_HDR_SIZE);
1446  len -= (1 + HCI_EVENT_HDR_SIZE);
1447 
1448  switch (hdr->evt) {
1449  case EVT_CMD_STATUS:
1450  cs = (void *) ptr;
1451 
1452  if (cs->opcode != opcode)
1453  continue;
1454 
1455  if (r->event != EVT_CMD_STATUS) {
1456  if (cs->status) {
1457  errno = EIO;
1458  goto failed;
1459  }
1460  break;
1461  }
1462 
1463  r->rlen = MIN(len, r->rlen);
1464  memcpy(r->rparam, ptr, r->rlen);
1465  goto done;
1466 
1467  case EVT_CMD_COMPLETE:
1468  cc = (void *) ptr;
1469 
1470  if (cc->opcode != opcode)
1471  continue;
1472 
1473  ptr += EVT_CMD_COMPLETE_SIZE;
1474  len -= EVT_CMD_COMPLETE_SIZE;
1475 
1476  r->rlen = MIN(len, r->rlen);
1477  memcpy(r->rparam, ptr, r->rlen);
1478  goto done;
1479 
1481  if (hdr->evt != r->event)
1482  break;
1483 
1484  rn = (void *) ptr;
1485  cp = r->cparam;
1486 
1487  if (bacmp(&rn->bdaddr, &cp->bdaddr))
1488  continue;
1489 
1490  r->rlen = MIN(len, r->rlen);
1491  memcpy(r->rparam, ptr, r->rlen);
1492  goto done;
1493 
1494  case EVT_LE_META_EVENT:
1495  me = (void *) ptr;
1496 
1497  if (me->subevent != r->event)
1498  continue;
1499 
1500  len -= 1;
1501  r->rlen = MIN(len, r->rlen);
1502  memcpy(r->rparam, me->data, r->rlen);
1503  goto done;
1504 
1505  default:
1506  if (hdr->evt != r->event)
1507  break;
1508 
1509  r->rlen = MIN(len, r->rlen);
1510  memcpy(r->rparam, ptr, r->rlen);
1511  goto done;
1512  }
1513  }
1514  errno = ETIMEDOUT;
1515 
1516 failed:
1517  err = errno;
1518  setsockopt(dd, SOL_HCI, HCI_FILTER, &of, sizeof(of));
1519  errno = err;
1520  return -1;
1521 
1522 done:
1523  setsockopt(dd, SOL_HCI, HCI_FILTER, &of, sizeof(of));
1524  return 0;
1525 }
1526 
1539 int hci_create_connection(int dd, const bdaddr_t *bdaddr, uint16_t ptype,
1540  uint16_t clkoffset, uint8_t rswitch,
1541  uint16_t *handle, int to)
1542 {
1543  evt_conn_complete rp;
1544  create_conn_cp cp;
1545  struct hci_request rq;
1546 
1547  memset(&cp, 0, sizeof(cp));
1548  bacpy(&cp.bdaddr, bdaddr);
1549  cp.pkt_type = ptype;
1550  cp.pscan_rep_mode = 0x02;
1551  cp.clock_offset = clkoffset;
1552  cp.role_switch = rswitch;
1553 
1554  memset(&rq, 0, sizeof(rq));
1555  rq.ogf = OGF_LINK_CTL;
1556  rq.ocf = OCF_CREATE_CONN;
1557  rq.event = EVT_CONN_COMPLETE;
1558  rq.cparam = &cp;
1560  rq.rparam = &rp;
1562 
1563  if (hci_send_req(dd, &rq, to) < 0)
1564  return -1;
1565 
1566  if (rp.status) {
1567  errno = EIO;
1568  return -1;
1569  }
1570 
1571  *handle = rp.handle;
1572  return 0;
1573 }
1574 
1584 int hci_disconnect(int dd, uint16_t handle, uint8_t reason, int to)
1585 {
1586  evt_disconn_complete rp;
1587  disconnect_cp cp;
1588  struct hci_request rq;
1589 
1590  memset(&cp, 0, sizeof(cp));
1591  cp.handle = handle;
1592  cp.reason = reason;
1593 
1594  memset(&rq, 0, sizeof(rq));
1595  rq.ogf = OGF_LINK_CTL;
1596  rq.ocf = OCF_DISCONNECT;
1598  rq.cparam = &cp;
1599  rq.clen = DISCONNECT_CP_SIZE;
1600  rq.rparam = &rp;
1602 
1603  if (hci_send_req(dd, &rq, to) < 0)
1604  return -1;
1605 
1606  if (rp.status) {
1607  errno = EIO;
1608  return -1;
1609  }
1610  return 0;
1611 }
1612 
1622 int hci_le_add_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
1623 {
1624  struct hci_request rq;
1625  le_add_device_to_white_list_cp cp;
1626  uint8_t status;
1627 
1628  memset(&cp, 0, sizeof(cp));
1629  cp.bdaddr_type = type;
1630  bacpy(&cp.bdaddr, bdaddr);
1631 
1632  memset(&rq, 0, sizeof(rq));
1633  rq.ogf = OGF_LE_CTL;
1635  rq.cparam = &cp;
1637  rq.rparam = &status;
1638  rq.rlen = 1;
1639 
1640  if (hci_send_req(dd, &rq, to) < 0)
1641  return -1;
1642 
1643  if (status) {
1644  errno = EIO;
1645  return -1;
1646  }
1647 
1648  return 0;
1649 }
1650 
1660 int hci_le_rm_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
1661 {
1662  struct hci_request rq;
1663  le_remove_device_from_white_list_cp cp;
1664  uint8_t status;
1665 
1666  memset(&cp, 0, sizeof(cp));
1667  cp.bdaddr_type = type;
1668  bacpy(&cp.bdaddr, bdaddr);
1669 
1670  memset(&rq, 0, sizeof(rq));
1671  rq.ogf = OGF_LE_CTL;
1673  rq.cparam = &cp;
1675  rq.rparam = &status;
1676  rq.rlen = 1;
1677 
1678  if (hci_send_req(dd, &rq, to) < 0)
1679  return -1;
1680 
1681  if (status) {
1682  errno = EIO;
1683  return -1;
1684  }
1685 
1686  return 0;
1687 }
1688 
1697 int hci_le_read_white_list_size(int dd, uint8_t *size, int to)
1698 {
1699  struct hci_request rq;
1700  le_read_white_list_size_rp rp;
1701 
1702  memset(&rp, 0, sizeof(rp));
1703  memset(&rq, 0, sizeof(rq));
1704 
1705  rq.ogf = OGF_LE_CTL;
1707  rq.rparam = &rp;
1709 
1710  if (hci_send_req(dd, &rq, to) < 0)
1711  return -1;
1712 
1713  if (rp.status) {
1714  errno = EIO;
1715  return -1;
1716  }
1717 
1718  if (size)
1719  *size = rp.size;
1720 
1721  return 0;
1722 }
1723 
1731 int hci_le_clear_white_list(int dd, int to)
1732 {
1733  struct hci_request rq;
1734  uint8_t status;
1735 
1736  memset(&rq, 0, sizeof(rq));
1737  rq.ogf = OGF_LE_CTL;
1739  rq.rparam = &status;
1740  rq.rlen = 1;
1741 
1742  if (hci_send_req(dd, &rq, to) < 0)
1743  return -1;
1744 
1745  if (status) {
1746  errno = EIO;
1747  return -1;
1748  }
1749 
1750  return 0;
1751 }
1752 
1764 int hci_le_add_resolving_list(int dd, const bdaddr_t *bdaddr, uint8_t type,
1765  uint8_t *peer_irk, uint8_t *local_irk, int to)
1766 {
1767  struct hci_request rq;
1768  le_add_device_to_resolv_list_cp cp;
1769  uint8_t status;
1770 
1771  memset(&cp, 0, sizeof(cp));
1772  cp.bdaddr_type = type;
1773  bacpy(&cp.bdaddr, bdaddr);
1774  if (peer_irk)
1775  memcpy(cp.peer_irk, peer_irk, 16);
1776  if (local_irk)
1777  memcpy(cp.local_irk, local_irk, 16);
1778 
1779  memset(&rq, 0, sizeof(rq));
1780  rq.ogf = OGF_LE_CTL;
1782  rq.cparam = &cp;
1784  rq.rparam = &status;
1785  rq.rlen = 1;
1786 
1787  if (hci_send_req(dd, &rq, to) < 0)
1788  return -1;
1789 
1790  if (status) {
1791  errno = EIO;
1792  return -1;
1793  }
1794 
1795  return 0;
1796 }
1797 
1807 int hci_le_rm_resolving_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
1808 {
1809  struct hci_request rq;
1810  le_remove_device_from_resolv_list_cp cp;
1811  uint8_t status;
1812 
1813  memset(&cp, 0, sizeof(cp));
1814  cp.bdaddr_type = type;
1815  bacpy(&cp.bdaddr, bdaddr);
1816 
1817  memset(&rq, 0, sizeof(rq));
1818  rq.ogf = OGF_LE_CTL;
1820  rq.cparam = &cp;
1822  rq.rparam = &status;
1823  rq.rlen = 1;
1824 
1825  if (hci_send_req(dd, &rq, to) < 0)
1826  return -1;
1827 
1828  if (status) {
1829  errno = EIO;
1830  return -1;
1831  }
1832 
1833  return 0;
1834 }
1835 
1843 int hci_le_clear_resolving_list(int dd, int to)
1844 {
1845  struct hci_request rq;
1846  uint8_t status;
1847 
1848  memset(&rq, 0, sizeof(rq));
1849  rq.ogf = OGF_LE_CTL;
1851  rq.rparam = &status;
1852  rq.rlen = 1;
1853 
1854  if (hci_send_req(dd, &rq, to) < 0)
1855  return -1;
1856 
1857  if (status) {
1858  errno = EIO;
1859  return -1;
1860  }
1861 
1862  return 0;
1863 }
1864 
1873 int hci_le_read_resolving_list_size(int dd, uint8_t *size, int to)
1874 {
1875  struct hci_request rq;
1876  le_read_resolv_list_size_rp rp;
1877 
1878  memset(&rp, 0, sizeof(rp));
1879  memset(&rq, 0, sizeof(rq));
1880 
1881  rq.ogf = OGF_LE_CTL;
1883  rq.rparam = &rp;
1885 
1886  if (hci_send_req(dd, &rq, to) < 0)
1887  return -1;
1888 
1889  if (rp.status) {
1890  errno = EIO;
1891  return -1;
1892  }
1893 
1894  if (size)
1895  *size = rp.size;
1896 
1897  return 0;
1898 }
1899 
1908 int hci_le_set_address_resolution_enable(int dd, uint8_t enable, int to)
1909 {
1910  struct hci_request rq;
1911  le_set_address_resolution_enable_cp cp;
1912  uint8_t status;
1913 
1914  memset(&cp, 0, sizeof(cp));
1915  cp.enable = enable;
1916 
1917  memset(&rq, 0, sizeof(rq));
1918  rq.ogf = OGF_LE_CTL;
1920  rq.cparam = &cp;
1922  rq.rparam = &status;
1923  rq.rlen = 1;
1924 
1925  if (hci_send_req(dd, &rq, to) < 0)
1926  return -1;
1927 
1928  if (status) {
1929  errno = EIO;
1930  return -1;
1931  }
1932 
1933  return 0;
1934 }
1935 
1943 int hci_read_local_name(int dd, int len, char *name, int to)
1944 {
1945  read_local_name_rp rp;
1946  struct hci_request rq;
1947 
1948  memset(&rq, 0, sizeof(rq));
1949  rq.ogf = OGF_HOST_CTL;
1950  rq.ocf = OCF_READ_LOCAL_NAME;
1951  rq.rparam = &rp;
1953 
1954  if (hci_send_req(dd, &rq, to) < 0)
1955  return -1;
1956 
1957  if (rp.status) {
1958  errno = EIO;
1959  return -1;
1960  }
1961 
1962  rp.name[247] = '\0';
1963  strncpy(name, (char *) rp.name, len);
1964  return 0;
1965 }
1966 
1975 int hci_write_local_name(int dd, const char *name, int to)
1976 {
1977  change_local_name_cp cp;
1978  struct hci_request rq;
1979 
1980  memset(&cp, 0, sizeof(cp));
1981  strncpy((char *) cp.name, name, sizeof(cp.name));
1982 
1983  memset(&rq, 0, sizeof(rq));
1984  rq.ogf = OGF_HOST_CTL;
1986  rq.cparam = &cp;
1988 
1989  if (hci_send_req(dd, &rq, to) < 0)
1990  return -1;
1991 
1992  return 0;
1993 }
1994 
2007 int hci_read_remote_name_with_clock_offset(int dd, const bdaddr_t *bdaddr,
2008  uint8_t pscan_rep_mode,
2009  uint16_t clkoffset,
2010  int len, char *name, int to)
2011 {
2012  evt_remote_name_req_complete rn;
2013  remote_name_req_cp cp;
2014  struct hci_request rq;
2015 
2016  memset(&cp, 0, sizeof(cp));
2017  bacpy(&cp.bdaddr, bdaddr);
2018  cp.pscan_rep_mode = pscan_rep_mode;
2019  cp.clock_offset = clkoffset;
2020 
2021  memset(&rq, 0, sizeof(rq));
2022  rq.ogf = OGF_LINK_CTL;
2023  rq.ocf = OCF_REMOTE_NAME_REQ;
2024  rq.cparam = &cp;
2027  rq.rparam = &rn;
2029 
2030  if (hci_send_req(dd, &rq, to) < 0)
2031  return -1;
2032 
2033  if (rn.status) {
2034  errno = EIO;
2035  return -1;
2036  }
2037 
2038  rn.name[247] = '\0';
2039  strncpy(name, (char *) rn.name, len);
2040  return 0;
2041 }
2042 
2053 int hci_read_remote_name(int dd, const bdaddr_t *bdaddr, int len, char *name,
2054  int to)
2055 {
2056  return hci_read_remote_name_with_clock_offset(dd, bdaddr, 0x02, 0x0000,
2057  len, name, to);
2058 }
2059 
2068 int hci_read_remote_name_cancel(int dd, const bdaddr_t *bdaddr, int to)
2069 {
2070  remote_name_req_cancel_cp cp;
2071  struct hci_request rq;
2072 
2073  memset(&cp, 0, sizeof(cp));
2074  bacpy(&cp.bdaddr, bdaddr);
2075 
2076  memset(&rq, 0, sizeof(rq));
2077  rq.ogf = OGF_LINK_CTL;
2079  rq.cparam = &cp;
2081 
2082  if (hci_send_req(dd, &rq, to) < 0)
2083  return -1;
2084 
2085  return 0;
2086 }
2087 
2097 int hci_read_remote_version(int dd, uint16_t handle, struct hci_version *ver,
2098  int to)
2099 {
2100  evt_read_remote_version_complete rp;
2101  read_remote_version_cp cp;
2102  struct hci_request rq;
2103 
2104  memset(&cp, 0, sizeof(cp));
2105  cp.handle = handle;
2106 
2107  memset(&rq, 0, sizeof(rq));
2108  rq.ogf = OGF_LINK_CTL;
2111  rq.cparam = &cp;
2113  rq.rparam = &rp;
2115 
2116  if (hci_send_req(dd, &rq, to) < 0)
2117  return -1;
2118 
2119  if (rp.status) {
2120  errno = EIO;
2121  return -1;
2122  }
2123 
2124  ver->manufacturer = btohs(rp.manufacturer);
2125  ver->lmp_ver = rp.lmp_ver;
2126  ver->lmp_subver = btohs(rp.lmp_subver);
2127  return 0;
2128 }
2129 
2139 int hci_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to)
2140 {
2141  evt_read_remote_features_complete rp;
2142  read_remote_features_cp cp;
2143  struct hci_request rq;
2144 
2145  memset(&cp, 0, sizeof(cp));
2146  cp.handle = handle;
2147 
2148  memset(&rq, 0, sizeof(rq));
2149  rq.ogf = OGF_LINK_CTL;
2152  rq.cparam = &cp;
2154  rq.rparam = &rp;
2156 
2157  if (hci_send_req(dd, &rq, to) < 0)
2158  return -1;
2159 
2160  if (rp.status) {
2161  errno = EIO;
2162  return -1;
2163  }
2164 
2165  if (features)
2166  memcpy(features, rp.features, 8);
2167 
2168  return 0;
2169 }
2170 
2182 int hci_read_remote_ext_features(int dd, uint16_t handle, uint8_t page,
2183  uint8_t *max_page, uint8_t *features,
2184  int to)
2185 {
2186  evt_read_remote_ext_features_complete rp;
2187  read_remote_ext_features_cp cp;
2188  struct hci_request rq;
2189 
2190  memset(&cp, 0, sizeof(cp));
2191  cp.handle = handle;
2192  cp.page_num = page;
2193 
2194  memset(&rq, 0, sizeof(rq));
2195  rq.ogf = OGF_LINK_CTL;
2198  rq.cparam = &cp;
2200  rq.rparam = &rp;
2202 
2203  if (hci_send_req(dd, &rq, to) < 0)
2204  return -1;
2205 
2206  if (rp.status) {
2207  errno = EIO;
2208  return -1;
2209  }
2210 
2211  if (max_page)
2212  *max_page = rp.max_page_num;
2213 
2214  if (features)
2215  memcpy(features, rp.features, 8);
2216 
2217  return 0;
2218 }
2219 
2229 int hci_read_clock_offset(int dd, uint16_t handle, uint16_t *clkoffset, int to)
2230 {
2231  evt_read_clock_offset_complete rp;
2232  read_clock_offset_cp cp;
2233  struct hci_request rq;
2234 
2235  memset(&cp, 0, sizeof(cp));
2236  cp.handle = handle;
2237 
2238  memset(&rq, 0, sizeof(rq));
2239  rq.ogf = OGF_LINK_CTL;
2242  rq.cparam = &cp;
2244  rq.rparam = &rp;
2246 
2247  if (hci_send_req(dd, &rq, to) < 0)
2248  return -1;
2249 
2250  if (rp.status) {
2251  errno = EIO;
2252  return -1;
2253  }
2254 
2255  *clkoffset = rp.clock_offset;
2256  return 0;
2257 }
2258 
2267 int hci_read_local_version(int dd, struct hci_version *ver, int to)
2268 {
2269  read_local_version_rp rp;
2270  struct hci_request rq;
2271 
2272  memset(&rq, 0, sizeof(rq));
2273  rq.ogf = OGF_INFO_PARAM;
2275  rq.rparam = &rp;
2277 
2278  if (hci_send_req(dd, &rq, to) < 0)
2279  return -1;
2280 
2281  if (rp.status) {
2282  errno = EIO;
2283  return -1;
2284  }
2285 
2286  ver->manufacturer = btohs(rp.manufacturer);
2287  ver->hci_ver = rp.hci_ver;
2288  ver->hci_rev = btohs(rp.hci_rev);
2289  ver->lmp_ver = rp.lmp_ver;
2290  ver->lmp_subver = btohs(rp.lmp_subver);
2291  return 0;
2292 }
2293 
2302 int hci_read_local_commands(int dd, uint8_t *commands, int to)
2303 {
2304  read_local_commands_rp rp;
2305  struct hci_request rq;
2306 
2307  memset(&rq, 0, sizeof(rq));
2308  rq.ogf = OGF_INFO_PARAM;
2310  rq.rparam = &rp;
2312 
2313  if (hci_send_req(dd, &rq, to) < 0)
2314  return -1;
2315 
2316  if (rp.status) {
2317  errno = EIO;
2318  return -1;
2319  }
2320 
2321  if (commands)
2322  memcpy(commands, rp.commands, 64);
2323 
2324  return 0;
2325 }
2326 
2335 int hci_read_local_features(int dd, uint8_t *features, int to)
2336 {
2337  read_local_features_rp rp;
2338  struct hci_request rq;
2339 
2340  memset(&rq, 0, sizeof(rq));
2341  rq.ogf = OGF_INFO_PARAM;
2343  rq.rparam = &rp;
2345 
2346  if (hci_send_req(dd, &rq, to) < 0)
2347  return -1;
2348 
2349  if (rp.status) {
2350  errno = EIO;
2351  return -1;
2352  }
2353 
2354  if (features)
2355  memcpy(features, rp.features, 8);
2356 
2357  return 0;
2358 }
2359 
2370 int hci_read_local_ext_features(int dd, uint8_t page, uint8_t *max_page,
2371  uint8_t *features, int to)
2372 {
2373  read_local_ext_features_cp cp;
2374  read_local_ext_features_rp rp;
2375  struct hci_request rq;
2376 
2377  cp.page_num = page;
2378 
2379  memset(&rq, 0, sizeof(rq));
2380  rq.ogf = OGF_INFO_PARAM;
2382  rq.cparam = &cp;
2384  rq.rparam = &rp;
2386 
2387  if (hci_send_req(dd, &rq, to) < 0)
2388  return -1;
2389 
2390  if (rp.status) {
2391  errno = EIO;
2392  return -1;
2393  }
2394 
2395  if (max_page)
2396  *max_page = rp.max_page_num;
2397 
2398  if (features)
2399  memcpy(features, rp.features, 8);
2400 
2401  return 0;
2402 }
2403 
2412 int hci_read_bd_addr(int dd, bdaddr_t *bdaddr, int to)
2413 {
2414  read_bd_addr_rp rp;
2415  struct hci_request rq;
2416 
2417  memset(&rq, 0, sizeof(rq));
2418  rq.ogf = OGF_INFO_PARAM;
2419  rq.ocf = OCF_READ_BD_ADDR;
2420  rq.rparam = &rp;
2422 
2423  if (hci_send_req(dd, &rq, to) < 0)
2424  return -1;
2425 
2426  if (rp.status) {
2427  errno = EIO;
2428  return -1;
2429  }
2430 
2431  if (bdaddr)
2432  bacpy(bdaddr, &rp.bdaddr);
2433 
2434  return 0;
2435 }
2436 
2445 int hci_read_class_of_dev(int dd, uint8_t *cls, int to)
2446 {
2447  read_class_of_dev_rp rp;
2448  struct hci_request rq;
2449 
2450  memset(&rq, 0, sizeof(rq));
2451  rq.ogf = OGF_HOST_CTL;
2453  rq.rparam = &rp;
2455 
2456  if (hci_send_req(dd, &rq, to) < 0)
2457  return -1;
2458 
2459  if (rp.status) {
2460  errno = EIO;
2461  return -1;
2462  }
2463 
2464  memcpy(cls, rp.dev_class, 3);
2465  return 0;
2466 }
2467 
2476 int hci_write_class_of_dev(int dd, uint32_t cls, int to)
2477 {
2478  write_class_of_dev_cp cp;
2479  struct hci_request rq;
2480 
2481  memset(&rq, 0, sizeof(rq));
2482  cp.dev_class[0] = cls & 0xff;
2483  cp.dev_class[1] = (cls >> 8) & 0xff;
2484  cp.dev_class[2] = (cls >> 16) & 0xff;
2485  rq.ogf = OGF_HOST_CTL;
2487  rq.cparam = &cp;
2489  return hci_send_req(dd, &rq, to);
2490 }
2491 
2500 int hci_read_voice_setting(int dd, uint16_t *vs, int to)
2501 {
2502  read_voice_setting_rp rp;
2503  struct hci_request rq;
2504 
2505  memset(&rq, 0, sizeof(rq));
2506  rq.ogf = OGF_HOST_CTL;
2508  rq.rparam = &rp;
2510 
2511  if (hci_send_req(dd, &rq, to) < 0)
2512  return -1;
2513 
2514  if (rp.status) {
2515  errno = EIO;
2516  return -1;
2517  }
2518 
2519  *vs = rp.voice_setting;
2520  return 0;
2521 }
2522 
2531 int hci_write_voice_setting(int dd, uint16_t vs, int to)
2532 {
2533  write_voice_setting_cp cp;
2534  struct hci_request rq;
2535 
2536  memset(&rq, 0, sizeof(rq));
2537  cp.voice_setting = vs;
2538  rq.ogf = OGF_HOST_CTL;
2540  rq.cparam = &cp;
2542 
2543  return hci_send_req(dd, &rq, to);
2544 }
2545 
2555 int hci_read_current_iac_lap(int dd, uint8_t *num_iac, uint8_t *lap, int to)
2556 {
2557  read_current_iac_lap_rp rp;
2558  struct hci_request rq;
2559 
2560  memset(&rq, 0, sizeof(rq));
2561  rq.ogf = OGF_HOST_CTL;
2563  rq.rparam = &rp;
2565 
2566  if (hci_send_req(dd, &rq, to) < 0)
2567  return -1;
2568 
2569  if (rp.status) {
2570  errno = EIO;
2571  return -1;
2572  }
2573 
2574  *num_iac = rp.num_current_iac;
2575  memcpy(lap, rp.lap, rp.num_current_iac * 3);
2576  return 0;
2577 }
2578 
2588 int hci_write_current_iac_lap(int dd, uint8_t num_iac, uint8_t *lap, int to)
2589 {
2590  write_current_iac_lap_cp cp;
2591  struct hci_request rq;
2592 
2593  memset(&cp, 0, sizeof(cp));
2594  cp.num_current_iac = num_iac;
2595  memcpy(&cp.lap, lap, num_iac * 3);
2596 
2597  memset(&rq, 0, sizeof(rq));
2598  rq.ogf = OGF_HOST_CTL;
2600  rq.cparam = &cp;
2601  rq.clen = num_iac * 3 + 1;
2602 
2603  return hci_send_req(dd, &rq, to);
2604 }
2605 
2615 int hci_read_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to)
2616 {
2617  read_stored_link_key_cp cp;
2618  struct hci_request rq;
2619 
2620  memset(&cp, 0, sizeof(cp));
2621  bacpy(&cp.bdaddr, bdaddr);
2622  cp.read_all = all;
2623 
2624  memset(&rq, 0, sizeof(rq));
2625  rq.ogf = OGF_HOST_CTL;
2627  rq.cparam = &cp;
2629 
2630  return hci_send_req(dd, &rq, to);
2631 }
2632 
2642 int hci_write_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t *key, int to)
2643 {
2644  unsigned char cp[WRITE_STORED_LINK_KEY_CP_SIZE + 6 + 16];
2645  struct hci_request rq;
2646 
2647  memset(&cp, 0, sizeof(cp));
2648  cp[0] = 1;
2649  bacpy((bdaddr_t *) (cp + 1), bdaddr);
2650  memcpy(cp + 7, key, 16);
2651 
2652  memset(&rq, 0, sizeof(rq));
2653  rq.ogf = OGF_HOST_CTL;
2655  rq.cparam = &cp;
2656  rq.clen = WRITE_STORED_LINK_KEY_CP_SIZE + 6 + 16;
2657 
2658  return hci_send_req(dd, &rq, to);
2659 }
2660 
2670 int hci_delete_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to)
2671 {
2672  delete_stored_link_key_cp cp;
2673  struct hci_request rq;
2674 
2675  memset(&cp, 0, sizeof(cp));
2676  bacpy(&cp.bdaddr, bdaddr);
2677  cp.delete_all = all;
2678 
2679  memset(&rq, 0, sizeof(rq));
2680  rq.ogf = OGF_HOST_CTL;
2682  rq.cparam = &cp;
2684 
2685  return hci_send_req(dd, &rq, to);
2686 }
2687 
2696 int hci_authenticate_link(int dd, uint16_t handle, int to)
2697 {
2698  auth_requested_cp cp;
2699  evt_auth_complete rp;
2700  struct hci_request rq;
2701 
2702  cp.handle = handle;
2703 
2704  rq.ogf = OGF_LINK_CTL;
2705  rq.ocf = OCF_AUTH_REQUESTED;
2706  rq.event = EVT_AUTH_COMPLETE;
2707  rq.cparam = &cp;
2709  rq.rparam = &rp;
2711 
2712  if (hci_send_req(dd, &rq, to) < 0)
2713  return -1;
2714 
2715  if (rp.status) {
2716  errno = EIO;
2717  return -1;
2718  }
2719 
2720  return 0;
2721 }
2722 
2732 int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to)
2733 {
2734  set_conn_encrypt_cp cp;
2735  evt_encrypt_change rp;
2736  struct hci_request rq;
2737 
2738  cp.handle = handle;
2739  cp.encrypt = encrypt;
2740 
2741  rq.ogf = OGF_LINK_CTL;
2744  rq.cparam = &cp;
2746  rq.rparam = &rp;
2748 
2749  if (hci_send_req(dd, &rq, to) < 0)
2750  return -1;
2751 
2752  if (rp.status) {
2753  errno = EIO;
2754  return -1;
2755  }
2756 
2757  return 0;
2758 }
2759 
2768 int hci_change_link_key(int dd, uint16_t handle, int to)
2769 {
2770  change_conn_link_key_cp cp;
2771  evt_change_conn_link_key_complete rp;
2772  struct hci_request rq;
2773 
2774  cp.handle = handle;
2775 
2776  rq.ogf = OGF_LINK_CTL;
2779  rq.cparam = &cp;
2781  rq.rparam = &rp;
2783 
2784  if (hci_send_req(dd, &rq, to) < 0)
2785  return -1;
2786 
2787  if (rp.status) {
2788  errno = EIO;
2789  return -1;
2790  }
2791 
2792  return 0;
2793 }
2794 
2804 int hci_switch_role(int dd, bdaddr_t *bdaddr, uint8_t role, int to)
2805 {
2806  switch_role_cp cp;
2807  evt_role_change rp;
2808  struct hci_request rq;
2809 
2810  bacpy(&cp.bdaddr, bdaddr);
2811  cp.role = role;
2812  rq.ogf = OGF_LINK_POLICY;
2813  rq.ocf = OCF_SWITCH_ROLE;
2814  rq.cparam = &cp;
2816  rq.rparam = &rp;
2818  rq.event = EVT_ROLE_CHANGE;
2819 
2820  if (hci_send_req(dd, &rq, to) < 0)
2821  return -1;
2822 
2823  if (rp.status) {
2824  errno = EIO;
2825  return -1;
2826  }
2827 
2828  return 0;
2829 }
2830 
2841 int hci_park_mode(int dd, uint16_t handle, uint16_t max_interval,
2842  uint16_t min_interval, int to)
2843 {
2844  park_mode_cp cp;
2845  evt_mode_change rp;
2846  struct hci_request rq;
2847 
2848  memset(&cp, 0, sizeof (cp));
2849  cp.handle = handle;
2850  cp.max_interval = max_interval;
2851  cp.min_interval = min_interval;
2852 
2853  memset(&rq, 0, sizeof (rq));
2854  rq.ogf = OGF_LINK_POLICY;
2855  rq.ocf = OCF_PARK_MODE;
2856  rq.event = EVT_MODE_CHANGE;
2857  rq.cparam = &cp;
2858  rq.clen = PARK_MODE_CP_SIZE;
2859  rq.rparam = &rp;
2861 
2862  if (hci_send_req(dd, &rq, to) < 0)
2863  return -1;
2864 
2865  if (rp.status) {
2866  errno = EIO;
2867  return -1;
2868  }
2869 
2870  return 0;
2871 }
2872 
2881 int hci_exit_park_mode(int dd, uint16_t handle, int to)
2882 {
2883  exit_park_mode_cp cp;
2884  evt_mode_change rp;
2885  struct hci_request rq;
2886 
2887  memset(&cp, 0, sizeof (cp));
2888  cp.handle = handle;
2889 
2890  memset (&rq, 0, sizeof (rq));
2891  rq.ogf = OGF_LINK_POLICY;
2892  rq.ocf = OCF_EXIT_PARK_MODE;
2893  rq.event = EVT_MODE_CHANGE;
2894  rq.cparam = &cp;
2896  rq.rparam = &rp;
2898 
2899  if (hci_send_req(dd, &rq, to) < 0)
2900  return -1;
2901 
2902  if (rp.status) {
2903  errno = EIO;
2904  return -1;
2905  }
2906 
2907  return 0;
2908 }
2909 
2918 int hci_read_inquiry_scan_type(int dd, uint8_t *type, int to)
2919 {
2920  read_inquiry_scan_type_rp rp;
2921  struct hci_request rq;
2922 
2923  memset(&rq, 0, sizeof(rq));
2924  rq.ogf = OGF_HOST_CTL;
2926  rq.rparam = &rp;
2928 
2929  if (hci_send_req(dd, &rq, to) < 0)
2930  return -1;
2931 
2932  if (rp.status) {
2933  errno = EIO;
2934  return -1;
2935  }
2936 
2937  *type = rp.type;
2938  return 0;
2939 }
2940 
2949 int hci_write_inquiry_scan_type(int dd, uint8_t type, int to)
2950 {
2951  write_inquiry_scan_type_cp cp;
2952  write_inquiry_scan_type_rp rp;
2953  struct hci_request rq;
2954 
2955  memset(&cp, 0, sizeof(cp));
2956  cp.type = type;
2957 
2958  memset(&rq, 0, sizeof(rq));
2959  rq.ogf = OGF_HOST_CTL;
2961  rq.cparam = &cp;
2963  rq.rparam = &rp;
2965 
2966  if (hci_send_req(dd, &rq, to) < 0)
2967  return -1;
2968 
2969  if (rp.status) {
2970  errno = EIO;
2971  return -1;
2972  }
2973 
2974  return 0;
2975 }
2976 
2985 int hci_read_inquiry_mode(int dd, uint8_t *mode, int to)
2986 {
2987  read_inquiry_mode_rp rp;
2988  struct hci_request rq;
2989 
2990  memset(&rq, 0, sizeof(rq));
2991  rq.ogf = OGF_HOST_CTL;
2993  rq.rparam = &rp;
2995 
2996  if (hci_send_req(dd, &rq, to) < 0)
2997  return -1;
2998 
2999  if (rp.status) {
3000  errno = EIO;
3001  return -1;
3002  }
3003 
3004  *mode = rp.mode;
3005  return 0;
3006 }
3007 
3016 int hci_write_inquiry_mode(int dd, uint8_t mode, int to)
3017 {
3018  write_inquiry_mode_cp cp;
3019  write_inquiry_mode_rp rp;
3020  struct hci_request rq;
3021 
3022  memset(&cp, 0, sizeof(cp));
3023  cp.mode = mode;
3024 
3025  memset(&rq, 0, sizeof(rq));
3026  rq.ogf = OGF_HOST_CTL;
3028  rq.cparam = &cp;
3030  rq.rparam = &rp;
3032 
3033  if (hci_send_req(dd, &rq, to) < 0)
3034  return -1;
3035 
3036  if (rp.status) {
3037  errno = EIO;
3038  return -1;
3039  }
3040 
3041  return 0;
3042 }
3043 
3052 int hci_read_afh_mode(int dd, uint8_t *mode, int to)
3053 {
3054  read_afh_mode_rp rp;
3055  struct hci_request rq;
3056 
3057  memset(&rq, 0, sizeof(rq));
3058  rq.ogf = OGF_HOST_CTL;
3059  rq.ocf = OCF_READ_AFH_MODE;
3060  rq.rparam = &rp;
3062 
3063  if (hci_send_req(dd, &rq, to) < 0)
3064  return -1;
3065 
3066  if (rp.status) {
3067  errno = EIO;
3068  return -1;
3069  }
3070 
3071  *mode = rp.mode;
3072  return 0;
3073 }
3074 
3083 int hci_write_afh_mode(int dd, uint8_t mode, int to)
3084 {
3085  write_afh_mode_cp cp;
3086  write_afh_mode_rp rp;
3087  struct hci_request rq;
3088 
3089  memset(&cp, 0, sizeof(cp));
3090  cp.mode = mode;
3091 
3092  memset(&rq, 0, sizeof(rq));
3093  rq.ogf = OGF_HOST_CTL;
3094  rq.ocf = OCF_WRITE_AFH_MODE;
3095  rq.cparam = &cp;
3097  rq.rparam = &rp;
3099 
3100  if (hci_send_req(dd, &rq, to) < 0)
3101  return -1;
3102 
3103  if (rp.status) {
3104  errno = EIO;
3105  return -1;
3106  }
3107 
3108  return 0;
3109 }
3110 
3120 int hci_read_ext_inquiry_response(int dd, uint8_t *fec, uint8_t *data, int to)
3121 {
3122  read_ext_inquiry_response_rp rp;
3123  struct hci_request rq;
3124 
3125  memset(&rq, 0, sizeof(rq));
3126  rq.ogf = OGF_HOST_CTL;
3128  rq.rparam = &rp;
3130 
3131  if (hci_send_req(dd, &rq, to) < 0)
3132  return -1;
3133 
3134  if (rp.status) {
3135  errno = EIO;
3136  return -1;
3137  }
3138 
3139  *fec = rp.fec;
3140  memcpy(data, rp.data, HCI_MAX_EIR_LENGTH);
3141 
3142  return 0;
3143 }
3144 
3154 int hci_write_ext_inquiry_response(int dd, uint8_t fec, uint8_t *data, int to)
3155 {
3156  write_ext_inquiry_response_cp cp;
3157  write_ext_inquiry_response_rp rp;
3158  struct hci_request rq;
3159 
3160  memset(&cp, 0, sizeof(cp));
3161  cp.fec = fec;
3162  memcpy(cp.data, data, HCI_MAX_EIR_LENGTH);
3163 
3164  memset(&rq, 0, sizeof(rq));
3165  rq.ogf = OGF_HOST_CTL;
3167  rq.cparam = &cp;
3169  rq.rparam = &rp;
3171 
3172  if (hci_send_req(dd, &rq, to) < 0)
3173  return -1;
3174 
3175  if (rp.status) {
3176  errno = EIO;
3177  return -1;
3178  }
3179 
3180  return 0;
3181 }
3182 
3191 int hci_read_simple_pairing_mode(int dd, uint8_t *mode, int to)
3192 {
3193  read_simple_pairing_mode_rp rp;
3194  struct hci_request rq;
3195 
3196  memset(&rq, 0, sizeof(rq));
3197  rq.ogf = OGF_HOST_CTL;
3199  rq.rparam = &rp;
3201 
3202  if (hci_send_req(dd, &rq, to) < 0)
3203  return -1;
3204 
3205  if (rp.status) {
3206  errno = EIO;
3207  return -1;
3208  }
3209 
3210  *mode = rp.mode;
3211  return 0;
3212 }
3213 
3222 int hci_write_simple_pairing_mode(int dd, uint8_t mode, int to)
3223 {
3224  write_simple_pairing_mode_cp cp;
3225  write_simple_pairing_mode_rp rp;
3226  struct hci_request rq;
3227 
3228  memset(&cp, 0, sizeof(cp));
3229  cp.mode = mode;
3230 
3231  memset(&rq, 0, sizeof(rq));
3232  rq.ogf = OGF_HOST_CTL;
3234  rq.cparam = &cp;
3236  rq.rparam = &rp;
3238 
3239  if (hci_send_req(dd, &rq, to) < 0)
3240  return -1;
3241 
3242  if (rp.status) {
3243  errno = EIO;
3244  return -1;
3245  }
3246 
3247  return 0;
3248 }
3249 
3259 int hci_read_local_oob_data(int dd, uint8_t *hash, uint8_t *randomizer, int to)
3260 {
3261  read_local_oob_data_rp rp;
3262  struct hci_request rq;
3263 
3264  memset(&rq, 0, sizeof(rq));
3265  rq.ogf = OGF_HOST_CTL;
3267  rq.rparam = &rp;
3269 
3270  if (hci_send_req(dd, &rq, to) < 0)
3271  return -1;
3272 
3273  if (rp.status) {
3274  errno = EIO;
3275  return -1;
3276  }
3277 
3278  memcpy(hash, rp.hash, 16);
3279  memcpy(randomizer, rp.randomizer, 16);
3280  return 0;
3281 }
3282 
3291 int hci_read_inq_response_tx_power_level(int dd, int8_t *level, int to)
3292 {
3293  read_inq_response_tx_power_level_rp rp;
3294  struct hci_request rq;
3295 
3296  memset(&rq, 0, sizeof(rq));
3297  rq.ogf = OGF_HOST_CTL;
3299  rq.rparam = &rp;
3301 
3302  if (hci_send_req(dd, &rq, to) < 0)
3303  return -1;
3304 
3305  if (rp.status) {
3306  errno = EIO;
3307  return -1;
3308  }
3309 
3310  *level = rp.level;
3311  return 0;
3312 }
3313 
3322 int hci_read_inquiry_transmit_power_level(int dd, int8_t *level, int to)
3323 {
3324  return hci_read_inq_response_tx_power_level(dd, level, to);
3325 }
3326 
3335 int hci_write_inquiry_transmit_power_level(int dd, int8_t level, int to)
3336 {
3337  write_inquiry_transmit_power_level_cp cp;
3338  write_inquiry_transmit_power_level_rp rp;
3339  struct hci_request rq;
3340 
3341  memset(&cp, 0, sizeof(cp));
3342  cp.level = level;
3343 
3344  memset(&rq, 0, sizeof(rq));
3345  rq.ogf = OGF_HOST_CTL;
3347  rq.cparam = &cp;
3349  rq.rparam = &rp;
3351 
3352  if (hci_send_req(dd, &rq, to) < 0)
3353  return -1;
3354 
3355  if (rp.status) {
3356  errno = EIO;
3357  return -1;
3358  }
3359 
3360  return 0;
3361 }
3362 
3373 int hci_read_transmit_power_level(int dd, uint16_t handle, uint8_t type,
3374  int8_t *level, int to)
3375 {
3376  read_transmit_power_level_cp cp;
3377  read_transmit_power_level_rp rp;
3378  struct hci_request rq;
3379 
3380  memset(&cp, 0, sizeof(cp));
3381  cp.handle = handle;
3382  cp.type = type;
3383 
3384  memset(&rq, 0, sizeof(rq));
3385  rq.ogf = OGF_HOST_CTL;
3387  rq.cparam = &cp;
3389  rq.rparam = &rp;
3391 
3392  if (hci_send_req(dd, &rq, to) < 0)
3393  return -1;
3394 
3395  if (rp.status) {
3396  errno = EIO;
3397  return -1;
3398  }
3399 
3400  *level = rp.level;
3401  return 0;
3402 }
3403 
3413 int hci_read_link_policy(int dd, uint16_t handle, uint16_t *policy, int to)
3414 {
3415  read_link_policy_rp rp;
3416  struct hci_request rq;
3417 
3418  memset(&rq, 0, sizeof(rq));
3419  rq.ogf = OGF_LINK_POLICY;
3421  rq.cparam = &handle;
3422  rq.clen = 2;
3423  rq.rparam = &rp;
3425 
3426  if (hci_send_req(dd, &rq, to) < 0)
3427  return -1;
3428 
3429  if (rp.status) {
3430  errno = EIO;
3431  return -1;
3432  }
3433 
3434  *policy = rp.policy;
3435  return 0;
3436 }
3437 
3447 int hci_write_link_policy(int dd, uint16_t handle, uint16_t policy, int to)
3448 {
3449  write_link_policy_cp cp;
3450  write_link_policy_rp rp;
3451  struct hci_request rq;
3452 
3453  memset(&cp, 0, sizeof(cp));
3454  cp.handle = handle;
3455  cp.policy = policy;
3456 
3457  memset(&rq, 0, sizeof(rq));
3458  rq.ogf = OGF_LINK_POLICY;
3460  rq.cparam = &cp;
3462  rq.rparam = &rp;
3464 
3465  if (hci_send_req(dd, &rq, to) < 0)
3466  return -1;
3467 
3468  if (rp.status) {
3469  errno = EIO;
3470  return -1;
3471  }
3472 
3473  return 0;
3474 }
3475 
3485 int hci_read_link_supervision_timeout(int dd, uint16_t handle,
3486  uint16_t *timeout, int to)
3487 {
3488  read_link_supervision_timeout_rp rp;
3489  struct hci_request rq;
3490 
3491  memset(&rq, 0, sizeof(rq));
3492  rq.ogf = OGF_HOST_CTL;
3494  rq.cparam = &handle;
3495  rq.clen = 2;
3496  rq.rparam = &rp;
3498 
3499  if (hci_send_req(dd, &rq, to) < 0)
3500  return -1;
3501 
3502  if (rp.status) {
3503  errno = EIO;
3504  return -1;
3505  }
3506 
3507  *timeout = rp.timeout;
3508  return 0;
3509 }
3510 
3520 int hci_write_link_supervision_timeout(int dd, uint16_t handle,
3521  uint16_t timeout, int to)
3522 {
3523  write_link_supervision_timeout_cp cp;
3524  write_link_supervision_timeout_rp rp;
3525  struct hci_request rq;
3526 
3527  memset(&cp, 0, sizeof(cp));
3528  cp.handle = handle;
3529  cp.timeout = timeout;
3530 
3531  memset(&rq, 0, sizeof(rq));
3532  rq.ogf = OGF_HOST_CTL;
3534  rq.cparam = &cp;
3536  rq.rparam = &rp;
3538 
3539  if (hci_send_req(dd, &rq, to) < 0)
3540  return -1;
3541 
3542  if (rp.status) {
3543  errno = EIO;
3544  return -1;
3545  }
3546 
3547  return 0;
3548 }
3549 
3558 int hci_set_afh_classification(int dd, uint8_t *map, int to)
3559 {
3560  set_afh_classification_cp cp;
3561  set_afh_classification_rp rp;
3562  struct hci_request rq;
3563 
3564  memset(&cp, 0, sizeof(cp));
3565  memcpy(cp.map, map, 10);
3566 
3567  memset(&rq, 0, sizeof(rq));
3568  rq.ogf = OGF_HOST_CTL;
3570  rq.cparam = &cp;
3572  rq.rparam = &rp;
3574 
3575  if (hci_send_req(dd, &rq, to) < 0)
3576  return -1;
3577 
3578  if (rp.status) {
3579  errno = EIO;
3580  return -1;
3581  }
3582 
3583  return 0;
3584 }
3585 
3595 int hci_read_link_quality(int dd, uint16_t handle, uint8_t *link_quality,
3596  int to)
3597 {
3598  read_link_quality_rp rp;
3599  struct hci_request rq;
3600 
3601  memset(&rq, 0, sizeof(rq));
3602  rq.ogf = OGF_STATUS_PARAM;
3604  rq.cparam = &handle;
3605  rq.clen = 2;
3606  rq.rparam = &rp;
3608 
3609  if (hci_send_req(dd, &rq, to) < 0)
3610  return -1;
3611 
3612  if (rp.status) {
3613  errno = EIO;
3614  return -1;
3615  }
3616 
3617  *link_quality = rp.link_quality;
3618  return 0;
3619 }
3620 
3630 int hci_read_rssi(int dd, uint16_t handle, int8_t *rssi, int to)
3631 {
3632  read_rssi_rp rp;
3633  struct hci_request rq;
3634 
3635  memset(&rq, 0, sizeof(rq));
3636  rq.ogf = OGF_STATUS_PARAM;
3637  rq.ocf = OCF_READ_RSSI;
3638  rq.cparam = &handle;
3639  rq.clen = 2;
3640  rq.rparam = &rp;
3641  rq.rlen = READ_RSSI_RP_SIZE;
3642 
3643  if (hci_send_req(dd, &rq, to) < 0)
3644  return -1;
3645 
3646  if (rp.status) {
3647  errno = EIO;
3648  return -1;
3649  }
3650 
3651  *rssi = rp.rssi;
3652  return 0;
3653 }
3654 
3665 int hci_read_afh_map(int dd, uint16_t handle, uint8_t *mode, uint8_t *map,
3666  int to)
3667 {
3668  read_afh_map_rp rp;
3669  struct hci_request rq;
3670 
3671  memset(&rq, 0, sizeof(rq));
3672  rq.ogf = OGF_STATUS_PARAM;
3673  rq.ocf = OCF_READ_AFH_MAP;
3674  rq.cparam = &handle;
3675  rq.clen = 2;
3676  rq.rparam = &rp;
3678 
3679  if (hci_send_req(dd, &rq, to) < 0)
3680  return -1;
3681 
3682  if (rp.status) {
3683  errno = EIO;
3684  return -1;
3685  }
3686 
3687  *mode = rp.mode;
3688  memcpy(map, rp.map, 10);
3689  return 0;
3690 }
3691 
3703 int hci_read_clock(int dd, uint16_t handle, uint8_t which, uint32_t *clock,
3704  uint16_t *accuracy, int to)
3705 {
3706  read_clock_cp cp;
3707  read_clock_rp rp;
3708  struct hci_request rq;
3709 
3710  memset(&cp, 0, sizeof(cp));
3711  cp.handle = handle;
3712  cp.which_clock = which;
3713 
3714  memset(&rq, 0, sizeof(rq));
3715  rq.ogf = OGF_STATUS_PARAM;
3716  rq.ocf = OCF_READ_CLOCK;
3717  rq.cparam = &cp;
3718  rq.clen = READ_CLOCK_CP_SIZE;
3719  rq.rparam = &rp;
3720  rq.rlen = READ_CLOCK_RP_SIZE;
3721 
3722  if (hci_send_req(dd, &rq, to) < 0)
3723  return -1;
3724 
3725  if (rp.status) {
3726  errno = EIO;
3727  return -1;
3728  }
3729 
3730  *clock = rp.clock;
3731  *accuracy = rp.accuracy;
3732  return 0;
3733 }
3734 
3744 int hci_le_set_scan_enable(int dd, uint8_t enable, uint8_t filter_dup, int to)
3745 {
3746  struct hci_request rq;
3747  le_set_scan_enable_cp scan_cp;
3748  uint8_t status;
3749 
3750  memset(&scan_cp, 0, sizeof(scan_cp));
3751  scan_cp.enable = enable;
3752  scan_cp.filter_dup = filter_dup;
3753 
3754  memset(&rq, 0, sizeof(rq));
3755  rq.ogf = OGF_LE_CTL;
3757  rq.cparam = &scan_cp;
3759  rq.rparam = &status;
3760  rq.rlen = 1;
3761 
3762  if (hci_send_req(dd, &rq, to) < 0)
3763  return -1;
3764 
3765  if (status) {
3766  errno = EIO;
3767  return -1;
3768  }
3769 
3770  return 0;
3771 }
3772 
3785 int hci_le_set_scan_parameters(int dd, uint8_t type,
3786  uint16_t interval, uint16_t window,
3787  uint8_t own_type, uint8_t filter, int to)
3788 {
3789  struct hci_request rq;
3790  le_set_scan_parameters_cp param_cp;
3791  uint8_t status;
3792 
3793  memset(&param_cp, 0, sizeof(param_cp));
3794  param_cp.type = type;
3795  param_cp.interval = interval;
3796  param_cp.window = window;
3797  param_cp.own_bdaddr_type = own_type;
3798  param_cp.filter = filter;
3799 
3800  memset(&rq, 0, sizeof(rq));
3801  rq.ogf = OGF_LE_CTL;
3803  rq.cparam = &param_cp;
3805  rq.rparam = &status;
3806  rq.rlen = 1;
3807 
3808  if (hci_send_req(dd, &rq, to) < 0)
3809  return -1;
3810 
3811  if (status) {
3812  errno = EIO;
3813  return -1;
3814  }
3815 
3816  return 0;
3817 }
3818 
3827 int hci_le_set_advertise_enable(int dd, uint8_t enable, int to)
3828 {
3829  struct hci_request rq;
3830  le_set_advertise_enable_cp adv_cp;
3831  uint8_t status;
3832 
3833  memset(&adv_cp, 0, sizeof(adv_cp));
3834  adv_cp.enable = enable;
3835 
3836  memset(&rq, 0, sizeof(rq));
3837  rq.ogf = OGF_LE_CTL;
3839  rq.cparam = &adv_cp;
3841  rq.rparam = &status;
3842  rq.rlen = 1;
3843 
3844  if (hci_send_req(dd, &rq, to) < 0)
3845  return -1;
3846 
3847  if (status) {
3848  errno = EIO;
3849  return -1;
3850  }
3851 
3852  return 0;
3853 }
3854 
3875 int hci_le_create_conn(int dd, uint16_t interval, uint16_t window,
3876  uint8_t initiator_filter, uint8_t peer_bdaddr_type,
3877  bdaddr_t peer_bdaddr, uint8_t own_bdaddr_type,
3878  uint16_t min_interval, uint16_t max_interval,
3879  uint16_t latency, uint16_t supervision_timeout,
3880  uint16_t min_ce_length, uint16_t max_ce_length,
3881  uint16_t *handle, int to)
3882 {
3883  struct hci_request rq;
3884  le_create_connection_cp create_conn_cp;
3885  evt_le_connection_complete conn_complete_rp;
3886 
3887  memset(&create_conn_cp, 0, sizeof(create_conn_cp));
3888  create_conn_cp.interval = interval;
3889  create_conn_cp.window = window;
3890  create_conn_cp.initiator_filter = initiator_filter;
3891  create_conn_cp.peer_bdaddr_type = peer_bdaddr_type;
3892  create_conn_cp.peer_bdaddr = peer_bdaddr;
3893  create_conn_cp.own_bdaddr_type = own_bdaddr_type;
3894  create_conn_cp.min_interval = min_interval;
3895  create_conn_cp.max_interval = max_interval;
3896  create_conn_cp.latency = latency;
3897  create_conn_cp.supervision_timeout = supervision_timeout;
3898  create_conn_cp.min_ce_length = min_ce_length;
3899  create_conn_cp.max_ce_length = max_ce_length;
3900 
3901  memset(&rq, 0, sizeof(rq));
3902  rq.ogf = OGF_LE_CTL;
3903  rq.ocf = OCF_LE_CREATE_CONN;
3905  rq.cparam = &create_conn_cp;
3907  rq.rparam = &conn_complete_rp;
3909 
3910  if (hci_send_req(dd, &rq, to) < 0)
3911  return -1;
3912 
3913  if (conn_complete_rp.status) {
3914  errno = EIO;
3915  return -1;
3916  }
3917 
3918  if (handle)
3919  *handle = conn_complete_rp.handle;
3920 
3921  return 0;
3922 }
3923 
3936 int hci_le_conn_update(int dd, uint16_t handle, uint16_t min_interval,
3937  uint16_t max_interval, uint16_t latency,
3938  uint16_t supervision_timeout, int to)
3939 {
3940  evt_le_connection_update_complete evt;
3941  le_connection_update_cp cp;
3942  struct hci_request rq;
3943 
3944  memset(&cp, 0, sizeof(cp));
3945  cp.handle = handle;
3946  cp.min_interval = min_interval;
3947  cp.max_interval = max_interval;
3948  cp.latency = latency;
3949  cp.supervision_timeout = supervision_timeout;
3950  cp.min_ce_length = htobs(0x0001);
3951  cp.max_ce_length = htobs(0x0001);
3952 
3953  memset(&rq, 0, sizeof(rq));
3954  rq.ogf = OGF_LE_CTL;
3955  rq.ocf = OCF_LE_CONN_UPDATE;
3956  rq.cparam = &cp;
3959  rq.rparam = &evt;
3960  rq.rlen = sizeof(evt);
3961 
3962  if (hci_send_req(dd, &rq, to) < 0)
3963  return -1;
3964 
3965  if (evt.status) {
3966  errno = EIO;
3967  return -1;
3968  }
3969 
3970  return 0;
3971 }
3972 
3982 int hci_le_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to)
3983 {
3984  evt_le_read_remote_used_features_complete rp;
3985  le_read_remote_used_features_cp cp;
3986  struct hci_request rq;
3987 
3988  memset(&cp, 0, sizeof(cp));
3989  cp.handle = handle;
3990 
3991  memset(&rq, 0, sizeof(rq));
3992  rq.ogf = OGF_LE_CTL;
3995  rq.cparam = &cp;
3997  rq.rparam = &rp;
3999 
4000  if (hci_send_req(dd, &rq, to) < 0)
4001  return -1;
4002 
4003  if (rp.status) {
4004  errno = EIO;
4005  return -1;
4006  }
4007 
4008  if (features)
4009  memcpy(features, rp.features, 8);
4010 
4011  return 0;
4012 }
void * bt_malloc(size_t size)
Definition: bluetooth.c:185
Definition: hci.h:65
#define LMP_ENCRYPT
Definition: hci.h:219
#define OCF_READ_CLOCK_OFFSET
Definition: hci.h:471
#define READ_INQUIRY_MODE_RP_SIZE
Definition: hci.h:1060
#define OGF_INFO_PARAM
Definition: hci.h:1277
#define WRITE_VOICE_SETTING_CP_SIZE
Definition: hci.h:933
#define WRITE_AFH_MODE_RP_SIZE
Definition: hci.h:1093
#define OCF_PARK_MODE
Definition: hci.h:636
int hci_read_local_version(int dd, struct hci_version *ver, int to)
Definition: hci.c:2267
#define OCF_AUTH_REQUESTED
Definition: hci.h:412
Definition: hci.h:66
command_func_t func
#define EVT_READ_REMOTE_FEATURES_COMPLETE_SIZE
Definition: hci.h:1828
#define EVT_AUTH_COMPLETE
Definition: hci.h:1784
#define OGF_STATUS_PARAM
Definition: hci.h:1345
#define HCI_MAX_EIR_LENGTH
Definition: hci.h:1095
static int __other_bdaddr(int dd, int dev_id, long arg)
Definition: hci.c:1075
#define LMP_HOLD
Definition: hci.h:223
int hci_exit_park_mode(int dd, uint16_t handle, int to)
Definition: hci.c:2881
#define LMP_AFH_CAP_MST
Definition: hci.h:260
#define HCI_COMMAND_HDR_SIZE
Definition: hci.h:2292
#define BTPROTO_HCI
Definition: bluetooth.h:46
enum att_op_type type
Definition: att.c:141
int hci_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to)
Definition: hci.c:2139
#define HCI_EVENT_HDR_SIZE
Definition: hci.h:2298
int hci_read_link_supervision_timeout(int dd, uint16_t handle, uint16_t *timeout, int to)
Definition: hci.c:3485
int hci_read_local_name(int dd, int len, char *name, int to)
Definition: hci.c:1943
#define OCF_LE_CLEAR_RESOLV_LIST
Definition: hci.h:1725
#define LMP_LE_BREDR
Definition: hci.h:267
#define EVT_DISCONN_COMPLETE_SIZE
Definition: hci.h:1782
#define OCF_REMOTE_NAME_REQ_CANCEL
Definition: hci.h:446
#define OCF_READ_CLASS_OF_DEV
Definition: hci.h:909
int hci_devinfo(int dev_id, struct hci_dev_info *di)
Definition: hci.c:1155
#define LMP_SIMPLE_PAIR
Definition: hci.h:268
int hci_read_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to)
Definition: hci.c:2615
uint8_t num_rsp
Definition: hci.h:2441
#define EVT_MODE_CHANGE
Definition: hci.h:1891
uint16_t flags
Definition: hci.h:2438
#define READ_REMOTE_FEATURES_CP_SIZE
Definition: hci.h:456
static int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
Definition: bluetooth.h:314
#define OCF_READ_SIMPLE_PAIRING_MODE
Definition: hci.h:1126
#define OCF_DISCONNECT
Definition: hci.h:352
#define OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST
Definition: hci.h:1587
#define LMP_HV2
Definition: hci.h:230
#define OCF_READ_INQ_RESPONSE_TX_POWER_LEVEL
Definition: hci.h:1151
uint16_t hci_rev
Definition: hci_lib.h:46
int hci_strtolp(char *str, unsigned int *val)
Definition: hci.c:391
#define HCI_BREDR
Definition: hci.h:60
#define SET_AFH_CLASSIFICATION_RP_SIZE
Definition: hci.h:1036
#define OCF_EXIT_PARK_MODE
Definition: hci.h:644
int hci_read_remote_name_cancel(int dd, const bdaddr_t *bdaddr, int to)
Definition: hci.c:2068
#define HCI_DM5
Definition: hci.h:131
char * lmp_featurestostr(uint8_t *features, char *pref, int width)
Definition: hci.c:962
Definition: hci.h:71
#define OCF_CHANGE_CONN_LINK_KEY
Definition: hci.h:425
int hci_le_set_scan_enable(int dd, uint8_t enable, uint8_t filter_dup, int to)
Definition: hci.c:3744
int rlen
Definition: hci_lib.h:40
#define WRITE_INQUIRY_TRANSMIT_POWER_LEVEL_CP_SIZE
Definition: hci.h:1169
#define READ_INQUIRY_SCAN_TYPE_RP_SIZE
Definition: hci.h:1043
#define LE_SET_ADVERTISE_ENABLE_CP_SIZE
Definition: hci.h:1533
#define WRITE_LINK_POLICY_CP_SIZE
Definition: hci.h:702
static int hci_str2uint(hci_map *map, char *str, unsigned int *val)
Definition: hci.c:158
int clen
Definition: hci_lib.h:38
#define HCIGETDEVLIST
Definition: hci.h:90
#define CHANGE_LOCAL_NAME_CP_SIZE
Definition: hci.h:819
char * pal_vertostr(unsigned int ver)
Definition: hci.c:848
#define LMP_CVSD
Definition: hci.h:235
char * hci_cmdtostr(unsigned int cmd)
Definition: hci.c:722
#define OCF_WRITE_CURRENT_IAC_LAP
Definition: hci.h:1013
#define WRITE_INQUIRY_MODE_CP_SIZE
Definition: hci.h:1066
#define OCF_READ_EXT_INQUIRY_RESPONSE
Definition: hci.h:1097
void * rparam
Definition: hci_lib.h:39
#define AF_BLUETOOTH
Definition: bluetooth.h:41
#define OCF_READ_LINK_SUPERVISION_TIMEOUT
Definition: hci.h:982
int hci_write_voice_setting(int dd, uint16_t vs, int to)
Definition: hci.c:2531
#define EVT_ROLE_CHANGE_SIZE
Definition: hci.h:1882
int hci_write_inquiry_mode(int dd, uint8_t mode, int to)
Definition: hci.c:3016
#define EVT_READ_REMOTE_FEATURES_COMPLETE
Definition: hci.h:1822
#define OCF_WRITE_EXT_INQUIRY_RESPONSE
Definition: hci.h:1105
#define HCI_2DH5
Definition: hci.h:129
#define READ_TRANSMIT_POWER_LEVEL_CP_SIZE
Definition: hci.h:952
int hci_le_set_scan_parameters(int dd, uint8_t type, uint16_t interval, uint16_t window, uint8_t own_type, uint8_t filter, int to)
Definition: hci.c:3785
#define LMP_RSWITCH
Definition: hci.h:222
#define READ_REMOTE_EXT_FEATURES_CP_SIZE
Definition: hci.h:463
#define WRITE_EXT_INQUIRY_RESPONSE_CP_SIZE
Definition: hci.h:1110
#define HCI_PCI
Definition: hci.h:56
char * hci_dflagstostr(uint32_t flags)
Definition: hci.c:260
static hci_map commands_map[]
Definition: hci.c:449
int hci_set_afh_classification(int dd, uint8_t *map, int to)
Definition: hci.c:3558
int hci_get_route(bdaddr_t *bdaddr)
Definition: hci.c:1111
char * lmp_vertostr(unsigned int ver)
Definition: hci.c:820
#define OCF_READ_LINK_QUALITY
Definition: hci.h:1362
#define DISCONNECT_CP_SIZE
Definition: hci.h:357
#define BDADDR_ANY
Definition: bluetooth.h:309
#define HCI_MAX_DEV
Definition: hci.h:35
#define READ_VOICE_SETTING_RP_SIZE
Definition: hci.h:927
uint16_t dev_id
Definition: hci.h:2437
#define EVT_READ_CLOCK_OFFSET_COMPLETE
Definition: hci.h:1942
#define EVT_CONN_COMPLETE
Definition: hci.h:1758
#define LMP_HV3
Definition: hci.h:231
int hci_le_clear_resolving_list(int dd, int to)
Definition: hci.c:1843
struct hci_dev_req dev_req[0]
Definition: hci.h:2416
int hci_write_class_of_dev(int dd, uint32_t cls, int to)
Definition: hci.c:2476
int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to)
Definition: hci.c:2732
int hci_read_remote_ext_features(int dd, uint16_t handle, uint8_t page, uint8_t *max_page, uint8_t *features, int to)
Definition: hci.c:2182
#define OCF_READ_LOCAL_COMMANDS
Definition: hci.h:1290
int hci_devba(int dev_id, bdaddr_t *bdaddr)
Definition: hci.c:1182
int hci_le_read_resolving_list_size(int dd, uint8_t *size, int to)
Definition: hci.c:1873
#define LMP_RSSI_INQ
Definition: hci.h:246
uint16_t ocf
Definition: hci_lib.h:35
#define LMP_PCONTROL
Definition: hci.h:237
int hci_send_req(int dd, struct hci_request *r, int to)
Definition: hci.c:1381
#define OCF_READ_AFH_MODE
Definition: hci.h:1078
int hci_devid(const char *str)
Definition: hci.c:1130
#define LMP_EV4
Definition: hci.h:249
#define HCI_LM_RELIABLE
Definition: hci.h:295
sa_family_t hci_family
Definition: hci.h:2341
#define READ_CLOCK_RP_SIZE
Definition: hci.h:1399
#define HCI_3EV5
Definition: hci.h:144
int lmp_strtover(char *str, unsigned int *ver)
Definition: hci.c:832
#define LE_SET_ADDRESS_RESOLUTION_ENABLE_CP_SIZE
Definition: hci.h:1738
int hci_read_local_features(int dd, uint8_t *features, int to)
Definition: hci.c:2335
#define READ_EXT_INQUIRY_RESPONSE_RP_SIZE
Definition: hci.h:1103
#define OGF_LINK_POLICY
Definition: hci.h:610
uint16_t dev_id
Definition: hci.h:2378
#define WRITE_INQUIRY_SCAN_TYPE_CP_SIZE
Definition: hci.h:1049
#define LMP_LSTO
Definition: hci.h:273
#define REMOTE_NAME_REQ_CANCEL_CP_SIZE
Definition: hci.h:450
#define OCF_LE_READ_WHITE_LIST_SIZE
Definition: hci.h:1571
#define REMOTE_NAME_REQ_CP_SIZE
Definition: hci.h:444
char * hci_scoptypetostr(unsigned int ptype)
Definition: hci.c:346
#define HCI_DH1
Definition: hci.h:124
int hci_write_link_supervision_timeout(int dd, uint16_t handle, uint16_t timeout, int to)
Definition: hci.c:3520
#define OCF_READ_REMOTE_EXT_FEATURES
Definition: hci.h:458
Definition: hci.h:70
int hci_read_clock(int dd, uint16_t handle, uint8_t which, uint32_t *clock, uint16_t *accuracy, int to)
Definition: hci.c:3703
#define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE
Definition: hci.h:2183
#define READ_AFH_MODE_RP_SIZE
Definition: hci.h:1083
#define OCF_READ_TRANSMIT_POWER_LEVEL
Definition: hci.h:947
#define LMP_SNIFF_SUBR
Definition: hci.h:258
#define LMP_EV5
Definition: hci.h:250
#define HCI_EV5
Definition: hci.h:140
#define EVT_ENCRYPT_CHANGE
Definition: hci.h:1799
uint16_t lmp_subver
Definition: hci_lib.h:48
char * hci_ptypetostr(unsigned int ptype)
Definition: hci.c:323
#define EXIT_PARK_MODE_CP_SIZE
Definition: hci.h:648
#define LMP_AFH_CAP_SLV
Definition: hci.h:251
#define CREATE_CONN_CP_SIZE
Definition: hci.h:350
#define LMP_ESCO
Definition: hci.h:247
int hci_read_afh_map(int dd, uint16_t handle, uint8_t *mode, uint8_t *map, int to)
Definition: hci.c:3665
#define OCF_SET_CONN_ENCRYPT
Definition: hci.h:418
int hci_write_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t *key, int to)
Definition: hci.c:2642
#define READ_LOCAL_EXT_FEATURES_RP_SIZE
Definition: hci.h:1315
#define LMP_ERR_DAT_REP
Definition: hci.h:270
#define EVT_ROLE_CHANGE
Definition: hci.h:1876
uint16_t dev_id
Definition: hci.h:2410
#define OCF_READ_LOCAL_NAME
Definition: hci.h:821
#define HCI_HV3
Definition: hci.h:136
#define LE_READ_REMOTE_USED_FEATURES_CP_SIZE
Definition: hci.h:1628
int hci_read_link_policy(int dd, uint16_t handle, uint16_t *policy, int to)
Definition: hci.c:3413
#define WRITE_LINK_SUPERVISION_TIMEOUT_RP_SIZE
Definition: hci.h:1000
uint16_t dev_num
Definition: hci.h:2415
int hci_for_each_dev(int flag, int(*func)(int dd, int dev_id, long arg), long arg)
Definition: hci.c:1019
#define OCF_READ_VOICE_SETTING
Definition: hci.h:922
int hci_write_afh_mode(int dd, uint8_t mode, int to)
Definition: hci.c:3083
#define OCF_LE_REMOVE_DEVICE_FROM_RESOLV_LIST
Definition: hci.h:1718
#define HCI_LM_ACCEPT
Definition: hci.h:290
int hci_change_link_key(int dd, uint16_t handle, int to)
Definition: hci.c:2768
static hci_map link_mode_map[]
Definition: hci.c:397
#define READ_AFH_MAP_RP_SIZE
Definition: hci.h:1385
#define LMP_INQ_TX_PWR
Definition: hci.h:274
int hci_le_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to)
Definition: hci.c:3982
#define htobs(d)
Definition: bluetooth.h:140
static int hci_test_bit(int nr, void *addr)
Definition: hci_lib.h:183
#define OCF_WRITE_INQUIRY_SCAN_TYPE
Definition: hci.h:1045
#define LMP_ENCAPS_PDU
Definition: hci.h:269
int hci_read_inquiry_transmit_power_level(int dd, int8_t *level, int to)
Definition: hci.c:3322
uint8_t length
Definition: hci.h:2440
#define OCF_READ_LOCAL_OOB_DATA
Definition: hci.h:1143
static int __same_bdaddr(int dd, int dev_id, long arg)
Definition: hci.c:1095
#define OCF_READ_STORED_LINK_KEY
Definition: hci.h:776
#define EVT_READ_REMOTE_VERSION_COMPLETE_SIZE
Definition: hci.h:1838
#define HCI_LM_TRUSTED
Definition: hci.h:294
#define LMP_AFH_CLS_MST
Definition: hci.h:261
#define LE_REMOVE_DEVICE_FROM_RESOLV_LIST_CP_SIZE
Definition: hci.h:1723
#define HCI_2EV3
Definition: hci.h:141
int hci_write_current_iac_lap(int dd, uint8_t num_iac, uint8_t *lap, int to)
Definition: hci.c:2588
int hci_read_inq_response_tx_power_level(int dd, int8_t *level, int to)
Definition: hci.c:3291
int hci_read_ext_inquiry_response(int dd, uint8_t *fec, uint8_t *data, int to)
Definition: hci.c:3120
static void bacpy(bdaddr_t *dst, const bdaddr_t *src)
Definition: bluetooth.h:318
int hci_strtover(char *str, unsigned int *ver)
Definition: hci.c:809
int hci_delete_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to)
Definition: hci.c:2670
char * hci_commandstostr(uint8_t *commands, char *pref, int width)
Definition: hci.c:735
#define LMP_NO_BREDR
Definition: hci.h:253
int hci_read_remote_name_with_clock_offset(int dd, const bdaddr_t *bdaddr, uint8_t pscan_rep_mode, uint16_t clkoffset, int len, char *name, int to)
Definition: hci.c:2007
#define HCI_DM3
Definition: hci.h:127
static void hci_filter_set_opcode(int opcode, struct hci_filter *f)
Definition: hci_lib.h:225
#define LMP_PARK
Definition: hci.h:226
#define OCF_READ_CURRENT_IAC_LAP
Definition: hci.h:1005
#define HCI_3DH1
Definition: hci.h:122
#define LMP_EXT_INQ
Definition: hci.h:266
#define READ_LOCAL_NAME_RP_SIZE
Definition: hci.h:826
uint8_t lap[3]
Definition: hci.h:2439
int hci_strtolm(char *str, unsigned int *val)
Definition: hci.c:443
#define READ_STORED_LINK_KEY_CP_SIZE
Definition: hci.h:781
#define LE_CREATE_CONN_CP_SIZE
Definition: hci.h:1567
#define LMP_RSSI
Definition: hci.h:227
#define OCF_LE_SET_SCAN_PARAMETERS
Definition: hci.h:1535
#define HCI_3EV3
Definition: hci.h:142
int hci_read_voice_setting(int dd, uint16_t *vs, int to)
Definition: hci.c:2500
#define EVT_READ_CLOCK_OFFSET_COMPLETE_SIZE
Definition: hci.h:1948
#define READ_TRANSMIT_POWER_LEVEL_RP_SIZE
Definition: hci.h:958
#define HCI_MAX_EVENT_SIZE
Definition: hci.h:39
#define EVT_REMOTE_NAME_REQ_COMPLETE
Definition: hci.h:1791
Definition: hci.h:75
Definition: hci.c:62
int hci_read_rssi(int dd, uint16_t handle, int8_t *rssi, int to)
Definition: hci.c:3630
int hci_inquiry(int dev_id, int len, int nrsp, const uint8_t *lap, inquiry_info **ii, long flags)
Definition: hci.c:1212
char * hci_dtypetostr(int type)
Definition: hci.c:217
#define EVT_READ_REMOTE_EXT_FEATURES_COMPLETE
Definition: hci.h:2002
#define OGF_HOST_CTL
Definition: hci.h:725
int hci_create_connection(int dd, const bdaddr_t *bdaddr, uint16_t ptype, uint16_t clkoffset, uint8_t rswitch, uint16_t *handle, int to)
Definition: hci.c:1539
#define READ_RSSI_RP_SIZE
Definition: hci.h:1376
#define OCF_WRITE_CLASS_OF_DEV
Definition: hci.h:916
int hci_strtoptype(char *str, unsigned int *val)
Definition: hci.c:335
static char * hci_uint2str(hci_map *m, unsigned int val)
Definition: hci.c:130
int hci_le_rm_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
Definition: hci.c:1660
#define LMP_PSCHEME
Definition: hci.h:236
#define OCF_WRITE_LINK_SUPERVISION_TIMEOUT
Definition: hci.h:990
#define HCI_USB
Definition: hci.h:52
#define OCF_WRITE_STORED_LINK_KEY
Definition: hci.h:789
int hci_switch_role(int dd, bdaddr_t *bdaddr, uint8_t role, int to)
Definition: hci.c:2804
int hci_write_ext_inquiry_response(int dd, uint8_t fec, uint8_t *data, int to)
Definition: hci.c:3154
static hci_map sco_ptype_map[]
Definition: hci.c:303
static hci_map pal_map[]
Definition: hci.c:837
#define cmd_opcode_pack(ogf, ocf)
Definition: hci.h:2320
#define LMP_EDR_5SLOT
Definition: hci.h:257
int hci_park_mode(int dd, uint16_t handle, uint16_t max_interval, uint16_t min_interval, int to)
Definition: hci.c:2841
#define HCI_LP_SNIFF
Definition: hci.h:286
static int hci_str2bit(hci_map *map, char *str, unsigned int *val)
Definition: hci.c:99
#define LE_ADD_DEVICE_TO_RESOLV_LIST_CP_SIZE
Definition: hci.h:1716
int hci_write_inquiry_scan_type(int dd, uint8_t type, int to)
Definition: hci.c:2949
#define READ_SIMPLE_PAIRING_MODE_RP_SIZE
Definition: hci.h:1131
#define HCI_LM_AUTH
Definition: hci.h:292
#define LMP_ILACE_ISCAN
Definition: hci.h:244
#define READ_LOCAL_OOB_DATA_RP_SIZE
Definition: hci.h:1149
#define LE_SET_SCAN_PARAMETERS_CP_SIZE
Definition: hci.h:1543
int hci_le_add_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
Definition: hci.c:1622
Definition: hci.h:69
int hci_write_local_name(int dd, const char *name, int to)
Definition: hci.c:1975
#define HCI_EV4
Definition: hci.h:139
#define READ_BD_ADDR_RP_SIZE
Definition: hci.h:1334
uint16_t manufacturer
Definition: hci_lib.h:44
#define LMP_EDR_ACL_2M
Definition: hci.h:241
int hci_read_remote_version(int dd, uint16_t handle, struct hci_version *ver, int to)
Definition: hci.c:2097
#define READ_LINK_SUPERVISION_TIMEOUT_RP_SIZE
Definition: hci.h:988
#define EVT_CONN_COMPLETE_SIZE
Definition: hci.h:1766
#define OCF_WRITE_SIMPLE_PAIRING_MODE
Definition: hci.h:1133
#define LMP_EPC
Definition: hci.h:275
#define OCF_LE_CREATE_CONN
Definition: hci.h:1552
#define READ_LINK_QUALITY_RP_SIZE
Definition: hci.h:1368
char * hci_lmtostr(unsigned int lm)
Definition: hci.c:415
int event
Definition: hci_lib.h:36
int hci_send_cmd(int dd, uint16_t ogf, uint16_t ocf, uint8_t plen, void *param)
Definition: hci.c:1343
#define HCI_2EV5
Definition: hci.h:143
#define HCIINQUIRY
Definition: hci.h:109
#define OCF_LE_ADD_DEVICE_TO_WHITE_LIST
Definition: hci.h:1580
#define HCI_RS232
Definition: hci.h:55
char * hci_vertostr(unsigned int ver)
Definition: hci.c:797
#define OGF_LE_CTL
Definition: hci.h:1466
#define HCI_SDIO
Definition: hci.h:57
#define SOL_HCI
Definition: bluetooth.h:54
int hci_disconnect(int dd, uint16_t handle, uint8_t reason, int to)
Definition: hci.c:1584
int hci_le_set_advertise_enable(int dd, uint8_t enable, int to)
Definition: hci.c:3827
int hci_le_set_address_resolution_enable(int dd, uint8_t enable, int to)
Definition: hci.c:1908
uint8_t lmp_ver
Definition: hci_lib.h:47
int hci_close_dev(int dd)
Definition: hci.c:1326
#define LMP_EDR_ESCO_3M
Definition: hci.h:263
#define EVT_CHANGE_CONN_LINK_KEY_COMPLETE
Definition: hci.h:1807
#define HCI_FILTER
Definition: hci.h:2333
#define EVT_CHANGE_CONN_LINK_KEY_COMPLETE_SIZE
Definition: hci.h:1812
#define LMP_EDR_3SLOT
Definition: hci.h:255
#define OCF_LE_SET_SCAN_ENABLE
Definition: hci.h:1545
int hci_read_inquiry_scan_type(int dd, uint8_t *type, int to)
Definition: hci.c:2918
#define LMP_3SLOT
Definition: hci.h:217
#define WRITE_INQUIRY_MODE_RP_SIZE
Definition: hci.h:1070
#define LMP_SNIFF
Definition: hci.h:224
#define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE_SIZE
Definition: hci.h:2189
static void hci_filter_clear(struct hci_filter *f)
Definition: hci_lib.h:189
#define EVT_ENCRYPT_CHANGE_SIZE
Definition: hci.h:1805
#define OGF_LINK_CTL
Definition: hci.h:311
#define LMP_EDR_3S_ESCO
Definition: hci.h:264
#define LE_ADD_DEVICE_TO_WHITE_LIST_CP_SIZE
Definition: hci.h:1585
#define WRITE_INQUIRY_TRANSMIT_POWER_LEVEL_RP_SIZE
Definition: hci.h:1173
#define LMP_LE
Definition: hci.h:254
#define LMP_ILACE_PSCAN
Definition: hci.h:245
#define WRITE_LINK_SUPERVISION_TIMEOUT_CP_SIZE
Definition: hci.h:995
int hci_read_simple_pairing_mode(int dd, uint8_t *mode, int to)
Definition: hci.c:3191
#define LE_READ_WHITE_LIST_SIZE_RP_SIZE
Definition: hci.h:1576
#define WRITE_EXT_INQUIRY_RESPONSE_RP_SIZE
Definition: hci.h:1114
#define HCI_DH3
Definition: hci.h:128
#define HCI_EVENT_PKT
Definition: hci.h:117
#define CHANGE_CONN_LINK_KEY_CP_SIZE
Definition: hci.h:429
#define LMP_EXT_FEAT
Definition: hci.h:276
#define READ_INQ_RESPONSE_TX_POWER_LEVEL_RP_SIZE
Definition: hci.h:1156
#define OCF_LE_SET_ADDRESS_RESOLUTION_ENABLE
Definition: hci.h:1734
char * hci_bustostr(int bus)
Definition: hci.c:189
#define LE_CONN_UPDATE_CP_SIZE
Definition: hci.h:1604
#define WRITE_CLASS_OF_DEV_CP_SIZE
Definition: hci.h:920
#define HCI_3DH3
Definition: hci.h:126
#define READ_LINK_POLICY_RP_SIZE
Definition: hci.h:695
unsigned short hci_dev
Definition: hci.h:2342
#define OCF_READ_REMOTE_FEATURES
Definition: hci.h:452
#define OCF_READ_INQUIRY_MODE
Definition: hci.h:1055
#define WRITE_SIMPLE_PAIRING_MODE_CP_SIZE
Definition: hci.h:1137
#define MIN(x, y)
Definition: hci.c:59
int hci_write_link_policy(int dd, uint16_t handle, uint16_t policy, int to)
Definition: hci.c:3447
static hci_map dev_flags_map[]
Definition: hci.c:241
#define HCI_UART
Definition: hci.h:54
uint8_t hci_ver
Definition: hci_lib.h:45
#define READ_CLOCK_CP_SIZE
Definition: hci.h:1392
#define OCF_CREATE_CONN
Definition: hci.h:341
void bt_free(void *ptr)
Definition: bluetooth.c:190
int hci_open_dev(int dev_id)
Definition: hci.c:1287
unsigned int val
Definition: hci.c:64
#define OCF_LE_READ_REMOTE_USED_FEATURES
Definition: hci.h:1624
int hci_le_conn_update(int dd, uint16_t handle, uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t supervision_timeout, int to)
Definition: hci.c:3936
#define EVT_READ_REMOTE_EXT_FEATURES_COMPLETE_SIZE
Definition: hci.h:2010
int hci_le_read_white_list_size(int dd, uint8_t *size, int to)
Definition: hci.c:1697
#define EVT_CMD_COMPLETE_SIZE
Definition: hci.h:1854
char * str
Definition: hci.c:63
static hci_map lmp_features_map[8][9]
Definition: hci.c:866
int hci_read_bd_addr(int dd, bdaddr_t *bdaddr, int to)
Definition: hci.c:2412
#define OCF_LE_CLEAR_WHITE_LIST
Definition: hci.h:1578
uint32_t flags
Definition: hci.h:2383
int hci_read_link_quality(int dd, uint16_t handle, uint8_t *link_quality, int to)
Definition: hci.c:3595
#define LMP_EDR_ACL_3M
Definition: hci.h:242
#define HCI_LP_HOLD
Definition: hci.h:285
char * cmd
int hci_write_simple_pairing_mode(int dd, uint8_t mode, int to)
Definition: hci.c:3222
#define LMP_TACCURACY
Definition: hci.h:221
#define LMP_AFH_CLS_SLV
Definition: hci.h:252
#define LMP_NFLUSH_PKTS
Definition: hci.h:271
#define LE_SET_SCAN_ENABLE_CP_SIZE
Definition: hci.h:1550
int hci_write_inquiry_transmit_power_level(int dd, int8_t level, int to)
Definition: hci.c:3335
#define LMP_5SLOT
Definition: hci.h:218
#define OCF_WRITE_LINK_POLICY
Definition: hci.h:697
#define AUTH_REQUESTED_CP_SIZE
Definition: hci.h:416
int hci_strtoscoptype(char *str, unsigned int *val)
Definition: hci.c:358
int hci_le_create_conn(int dd, uint16_t interval, uint16_t window, uint8_t initiator_filter, uint8_t peer_bdaddr_type, bdaddr_t peer_bdaddr, uint8_t own_bdaddr_type, uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length, uint16_t *handle, int to)
Definition: hci.c:3875
char * hci_lptostr(unsigned int lp)
Definition: hci.c:379
int hci_read_local_commands(int dd, uint8_t *commands, int to)
Definition: hci.c:2302
#define HCI_2DH3
Definition: hci.h:125
#define LE_REMOVE_DEVICE_FROM_WHITE_LIST_CP_SIZE
Definition: hci.h:1592
int pal_strtover(char *str, unsigned int *ver)
Definition: hci.c:860
#define HCI_LP_PARK
Definition: hci.h:287
#define WRITE_SIMPLE_PAIRING_MODE_RP_SIZE
Definition: hci.h:1141
int hci_le_rm_resolving_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to)
Definition: hci.c:1807
char * hci_typetostr(int type)
Definition: hci.c:228
#define LMP_ENH_ISCAN
Definition: hci.h:243
#define EVT_CMD_COMPLETE
Definition: hci.h:1849
#define EVT_LE_CONN_UPDATE_COMPLETE
Definition: hci.h:2173
int str2ba(const char *str, bdaddr_t *ba)
Definition: bluetooth.c:92
#define OCF_READ_CLOCK
Definition: hci.h:1387
#define OCF_WRITE_VOICE_SETTING
Definition: hci.h:929
#define HCI_HV1
Definition: hci.h:134
#define LMP_BCAST_ENC
Definition: hci.h:239
uint16_t ogf
Definition: hci_lib.h:34
#define LMP_SCO
Definition: hci.h:229
#define WRITE_AFH_MODE_CP_SIZE
Definition: hci.h:1089
static hci_map pkt_type_map[]
Definition: hci.c:283
#define HCI_LM_SECURE
Definition: hci.h:296
#define HCIGETDEVINFO
Definition: hci.h:91
#define OCF_READ_LOCAL_FEATURES
Definition: hci.h:1297
#define HCI_2DH1
Definition: hci.h:121
int hci_read_remote_name(int dd, const bdaddr_t *bdaddr, int len, char *name, int to)
Definition: hci.c:2053
int hci_read_local_oob_data(int dd, uint8_t *hash, uint8_t *randomizer, int to)
Definition: hci.c:3259
#define READ_CLOCK_OFFSET_CP_SIZE
Definition: hci.h:475
#define WRITE_LINK_POLICY_RP_SIZE
Definition: hci.h:707
#define OCF_READ_RSSI
Definition: hci.h:1370
#define LMP_PAUSE_ENC
Definition: hci.h:259
#define LMP_EDR_ESCO_2M
Definition: hci.h:262
#define HCI_LP_RSWITCH
Definition: hci.h:284
int hci_authenticate_link(int dd, uint16_t handle, int to)
Definition: hci.c:2696
static hci_map ver_map[]
Definition: hci.c:778
#define HCI_HV2
Definition: hci.h:135
#define SET_AFH_CLASSIFICATION_CP_SIZE
Definition: hci.h:1032
#define btohs(d)
Definition: bluetooth.h:143
#define EVT_REMOTE_NAME_REQ_COMPLETE_SIZE
Definition: hci.h:1797
#define LMP_ULAW
Definition: hci.h:232
#define EVT_READ_REMOTE_VERSION_COMPLETE
Definition: hci.h:1830
#define OCF_SWITCH_ROLE
Definition: hci.h:678
#define OCF_READ_REMOTE_VERSION
Definition: hci.h:465
#define DELETE_STORED_LINK_KEY_CP_SIZE
Definition: hci.h:806
#define OCF_READ_LINK_POLICY
Definition: hci.h:685
#define HCI_COMMAND_PKT
Definition: hci.h:114
int hci_read_class_of_dev(int dd, uint8_t *cls, int to)
Definition: hci.c:2445
#define SWITCH_ROLE_CP_SIZE
Definition: hci.h:683
int hci_read_local_ext_features(int dd, uint8_t page, uint8_t *max_page, uint8_t *features, int to)
Definition: hci.c:2370
#define EVT_DISCONN_COMPLETE
Definition: hci.h:1776
#define LMP_SOFFSET
Definition: hci.h:220
#define OCF_WRITE_INQUIRY_MODE
Definition: hci.h:1062
#define HCI_EV3
Definition: hci.h:138
#define HCI_AMP
Definition: hci.h:61
#define LMP_TRSP_SCO
Definition: hci.h:238
#define READ_LOCAL_COMMANDS_RP_SIZE
Definition: hci.h:1295
int hci_read_clock_offset(int dd, uint16_t handle, uint16_t *clkoffset, int to)
Definition: hci.c:2229
#define OCF_REMOTE_NAME_REQ
Definition: hci.h:437
int hci_read_transmit_power_level(int dd, uint16_t handle, uint8_t type, int8_t *level, int to)
Definition: hci.c:3373
#define EVT_MODE_CHANGE_SIZE
Definition: hci.h:1898
#define EVT_AUTH_COMPLETE_SIZE
Definition: hci.h:1789
int hci_read_inquiry_mode(int dd, uint8_t *mode, int to)
Definition: hci.c:2985
int hci_read_afh_mode(int dd, uint8_t *mode, int to)
Definition: hci.c:3052
#define OCF_READ_LOCAL_EXT_FEATURES
Definition: hci.h:1304
#define LMP_ALAW
Definition: hci.h:233
#define HCI_LM_MASTER
Definition: hci.h:291
static char * hci_bit2str(hci_map *m, unsigned int val)
Definition: hci.c:74
#define READ_LOCAL_FEATURES_RP_SIZE
Definition: hci.h:1302
uint8_t opcode
Definition: att.c:140
#define OCF_LE_CONN_UPDATE
Definition: hci.h:1594
#define HCI_DH5
Definition: hci.h:132
static void hci_filter_set_event(int e, struct hci_filter *f)
Definition: hci_lib.h:209
#define READ_CURRENT_IAC_LAP_RP_SIZE
Definition: hci.h:1011
int hci_le_clear_white_list(int dd, int to)
Definition: hci.c:1731
#define HCI_DM1
Definition: hci.h:123
#define OCF_READ_AFH_MAP
Definition: hci.h:1378
#define READ_REMOTE_VERSION_CP_SIZE
Definition: hci.h:469
#define SET_CONN_ENCRYPT_CP_SIZE
Definition: hci.h:423
#define HCI_VIRTUAL
Definition: hci.h:51
#define LMP_QUALITY
Definition: hci.h:228
#define HCI_LM_ENCRYPT
Definition: hci.h:293
#define HCI_PCCARD
Definition: hci.h:53
#define OCF_CHANGE_LOCAL_NAME
Definition: hci.h:815
#define EVT_LE_CONN_COMPLETE
Definition: hci.h:2149
#define OCF_LE_SET_ADVERTISE_ENABLE
Definition: hci.h:1529
#define OCF_READ_INQUIRY_SCAN_TYPE
Definition: hci.h:1038
#define OCF_READ_LOCAL_VERSION
Definition: hci.h:1279
#define OCF_READ_BD_ADDR
Definition: hci.h:1329
bdaddr_t bdaddr
Definition: hci.h:2381
#define OCF_LE_READ_RESOLV_LIST_SIZE
Definition: hci.h:1727
uint32_t dev_opt
Definition: hci.h:2411
#define WRITE_STORED_LINK_KEY_CP_SIZE
Definition: hci.h:794
#define LE_READ_RESOLV_LIST_SIZE_RP_SIZE
Definition: hci.h:1732
#define READ_LOCAL_EXT_FEATURES_CP_SIZE
Definition: hci.h:1308
#define OCF_WRITE_AFH_MODE
Definition: hci.h:1085
#define OCF_DELETE_STORED_LINK_KEY
Definition: hci.h:801
#define READ_CLASS_OF_DEV_RP_SIZE
Definition: hci.h:914
#define READ_LOCAL_VERSION_RP_SIZE
Definition: hci.h:1288
static hci_map link_policy_map[]
Definition: hci.c:364
void * cparam
Definition: hci_lib.h:37
int hci_read_current_iac_lap(int dd, uint8_t *num_iac, uint8_t *lap, int to)
Definition: hci.c:2555
#define OCF_SET_AFH_CLASSIFICATION
Definition: hci.h:1028
int hci_le_add_resolving_list(int dd, const bdaddr_t *bdaddr, uint8_t type, uint8_t *peer_irk, uint8_t *local_irk, int to)
Definition: hci.c:1764
#define OCF_LE_ADD_DEVICE_TO_RESOLV_LIST
Definition: hci.h:1709
#define WRITE_INQUIRY_SCAN_TYPE_RP_SIZE
Definition: hci.h:1053
#define OCF_WRITE_INQUIRY_TRANSMIT_POWER_LEVEL
Definition: hci.h:1165
#define EVT_LE_META_EVENT
Definition: hci.h:2142
#define HCI_3DH5
Definition: hci.h:130
#define EVT_CMD_STATUS
Definition: hci.h:1856
#define PARK_MODE_CP_SIZE
Definition: hci.h:642
static void hci_filter_set_ptype(int t, struct hci_filter *f)
Definition: hci_lib.h:193