hcieventmask.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #include <stdio.h>
  14. #include <errno.h>
  15. #include <stdlib.h>
  16. #include <getopt.h>
  17. #include <sys/socket.h>
  18. #include "lib/bluetooth.h"
  19. #include "lib/hci.h"
  20. #include "lib/hci_lib.h"
  21. static struct option main_options[] = {
  22. { "device", 1, 0, 'i' },
  23. { 0, 0, 0, 0 }
  24. };
  25. int main(int argc, char *argv[])
  26. {
  27. uint8_t events[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00 };
  28. struct hci_dev_info di;
  29. struct hci_version ver;
  30. int dd, opt, dev = 0;
  31. while ((opt=getopt_long(argc, argv, "+i:", main_options, NULL)) != -1) {
  32. switch (opt) {
  33. case 'i':
  34. dev = hci_devid(optarg);
  35. if (dev < 0) {
  36. perror("Invalid device");
  37. exit(1);
  38. }
  39. break;
  40. }
  41. }
  42. dd = hci_open_dev(dev);
  43. if (dd < 0) {
  44. fprintf(stderr, "Can't open device hci%d: %s (%d)\n",
  45. dev, strerror(errno), errno);
  46. exit(1);
  47. }
  48. if (hci_devinfo(dev, &di) < 0) {
  49. fprintf(stderr, "Can't get device info for hci%d: %s (%d)\n",
  50. dev, strerror(errno), errno);
  51. hci_close_dev(dd);
  52. exit(1);
  53. }
  54. if (hci_read_local_version(dd, &ver, 1000) < 0) {
  55. fprintf(stderr, "Can't read version info for hci%d: %s (%d)\n",
  56. dev, strerror(errno), errno);
  57. hci_close_dev(dd);
  58. exit(1);
  59. }
  60. hci_close_dev(dd);
  61. if (ver.hci_ver > 1) {
  62. if (di.features[5] & LMP_SNIFF_SUBR)
  63. events[5] |= 0x20;
  64. if (di.features[5] & LMP_PAUSE_ENC)
  65. events[5] |= 0x80;
  66. if (di.features[6] & LMP_EXT_INQ)
  67. events[5] |= 0x40;
  68. if (di.features[6] & LMP_NFLUSH_PKTS)
  69. events[7] |= 0x01;
  70. if (di.features[7] & LMP_LSTO)
  71. events[6] |= 0x80;
  72. if (di.features[6] & LMP_SIMPLE_PAIR) {
  73. events[6] |= 0x01; /* IO Capability Request */
  74. events[6] |= 0x02; /* IO Capability Response */
  75. events[6] |= 0x04; /* User Confirmation Request */
  76. events[6] |= 0x08; /* User Passkey Request */
  77. events[6] |= 0x10; /* Remote OOB Data Request */
  78. events[6] |= 0x20; /* Simple Pairing Complete */
  79. events[7] |= 0x04; /* User Passkey Notification */
  80. events[7] |= 0x08; /* Keypress Notification */
  81. events[7] |= 0x10; /* Remote Host Supported
  82. * Features Notification */
  83. }
  84. if (di.features[4] & LMP_LE)
  85. events[7] |= 0x20;
  86. if (di.features[6] & LMP_LE_BREDR)
  87. events[7] |= 0x20;
  88. }
  89. printf("Setting event mask:\n");
  90. printf("\thcitool cmd 0x%02x 0x%04x "
  91. "0x%02x 0x%02x 0x%02x 0x%02x "
  92. "0x%02x 0x%02x 0x%02x 0x%02x\n",
  93. OGF_HOST_CTL, OCF_SET_EVENT_MASK,
  94. events[0], events[1], events[2], events[3],
  95. events[4], events[5], events[6], events[7]);
  96. return 0;
  97. }