Advertisement
Guest User

Untitled

a guest
Aug 28th, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. diff --git a/bluetooth-rfkill-event/bluetooth-rfkill-event.service b/bluetooth-rfkill-event/bluetooth-rfkill-event.service
  2. index 453fd36..742e1af 100644
  3. --- a/bluetooth-rfkill-event/bluetooth-rfkill-event.service
  4. +++ b/bluetooth-rfkill-event/bluetooth-rfkill-event.service
  5. @@ -6,7 +6,7 @@ Before=bluetooth.service
  6. Type=simple
  7. EnvironmentFile=-/etc/sysconfig/bluetooth-rfkill-event
  8. EnvironmentFile=-/etc/sysconfig/bluetooth-rfkill-event-hciattach
  9. -ExecStart=/usr/sbin/bluetooth_rfkill_event $DEBUG $BTMODULE $CONFIGFILE
  10. +ExecStart=/usr/sbin/bluetooth_rfkill_event $DEBUG $BTMODULE $CONFIGFILE $RFKILLNAME
  11. Restart=on-failure
  12.  
  13. [Install]
  14. diff --git a/bluetooth-rfkill-event/bluetooth-rfkill-event.sysconfig b/bluetooth-rfkill-event/bluetooth-rfkill-event.sysconfig
  15. index 64f296c..60546a9 100644
  16. --- a/bluetooth-rfkill-event/bluetooth-rfkill-event.sysconfig
  17. +++ b/bluetooth-rfkill-event/bluetooth-rfkill-event.sysconfig
  18. @@ -2,3 +2,4 @@
  19. # DEBUG -- debug options
  20. # BTMODULE -- name of bluetooth kernel module to load/unload, if any
  21. # CONFIGFILE -- name of configuration file to use
  22. +# RFKILLNAME -- name of rfkill device
  23. diff --git a/bluetooth-rfkill-event/bluetooth_rfkill_event.c b/bluetooth-rfkill-event/bluetooth_rfkill_event.c
  24. index 290c59e..201b627 100644
  25. --- a/bluetooth-rfkill-event/bluetooth_rfkill_event.c
  26. +++ b/bluetooth-rfkill-event/bluetooth_rfkill_event.c
  27. @@ -75,7 +75,7 @@ enum rfkill_switch_type {
  28.  
  29. /* list of all supported chips:
  30. name is defined in the kernel driver implementing rfkill interface for power */
  31. -#define BCM_RFKILL_NAME "bcm43xx Bluetooth\n"
  32. +#define DEFAULT_BCM_RFKILL_NAME "bcm43xx Bluetooth"
  33. #define BCM_43341_UART_DEV "/dev/ttyMFD0"
  34. #define BD_ADD_FACTORY_FILE "/factory/bluetooth_address"
  35. char factory_bd_add[18];
  36. @@ -130,8 +130,10 @@ char hciattach_options[PATH_MAX];
  37. char hci_uart_default_dev[PATH_MAX] = BCM_43341_UART_DEV;
  38.  
  39. gboolean hci_dev_registered;
  40. +gboolean patcher_started;
  41. char *bt_module = NULL;
  42. char *config_file = DEFAULT_CONFIG_FILE;
  43. +char *bcm_rfkill_name = DEFAULT_BCM_RFKILL_NAME;
  44. GHashTable *switch_hash = NULL; /* hash index to metadata about the switch */
  45.  
  46. struct main_opts {
  47. @@ -907,6 +909,7 @@ void free_hci()
  48. } else {
  49. INFO("No %s process to be found", hciattach);
  50. }
  51. + patcher_started = false;
  52. }
  53.  
  54. void attach_hci()
  55. @@ -919,8 +922,9 @@ void attach_hci()
  56. snprintf(hci_execute, sizeof(hci_execute), "%s %s", hciattach, hciattach_options);
  57.  
  58. r = system_timeout(hci_execute);
  59. + patcher_started = WIFEXITED(r) && !WEXITSTATUS(r);
  60. INFO("executing %s %s", hci_execute,
  61. - (WIFEXITED(r) && !WEXITSTATUS(r)) ? "succeeded" : "failed");
  62. + patcher_started ? "succeeded" : "failed");
  63.  
  64. if (!WIFEXITED(r) || WEXITSTATUS(r))
  65. FATAL("Failed to execute %s, exiting", hci_execute);
  66. @@ -1042,6 +1046,7 @@ static int rfkill_switch_add(struct rfkill_event *event)
  67. int fd_name = -1;
  68. int r = -1;
  69. int type;
  70. + int len;
  71.  
  72. DEBUG("");
  73.  
  74. @@ -1065,8 +1070,12 @@ static int rfkill_switch_add(struct rfkill_event *event)
  75. goto out;
  76. }
  77.  
  78. + len = strlen(sysname);
  79. + if (sysname[len-1] == '\n')
  80. + sysname[len-1] = '\0';
  81. +
  82. /* based on chip read its config file, if any, and define the hciattach utility used to dowload the patch */
  83. - if (!strncmp(BCM_RFKILL_NAME, sysname, sizeof(BCM_RFKILL_NAME))) {
  84. + if (!strncmp(bcm_rfkill_name, sysname, len-1)) {
  85. read_config(config_file);
  86. snprintf(hciattach, sizeof(hciattach), patcher_impl[main_opts.patcher].name);
  87. type = BT_PWR;
  88. @@ -1112,12 +1121,13 @@ int main(int argc, char **argv)
  89. { "btmodule", required_argument, NULL, 'b' },
  90. { "config", required_argument, NULL, 'c' },
  91. { "debug", no_argument, NULL, 'd' },
  92. + { "rfkill", required_argument, NULL, 'r' },
  93. { "stderr", no_argument, NULL, 's' },
  94. { 0, 0, 0, 0 }
  95. };
  96. int c;
  97.  
  98. - c = getopt_long(argc, argv, ":b:c:ds", opts, NULL);
  99. + c = getopt_long(argc, argv, ":b:c:dr:s", opts, NULL);
  100. if (c == -1)
  101. break;
  102.  
  103. @@ -1133,6 +1143,9 @@ int main(int argc, char **argv)
  104. case 'd':
  105. log_debug = 1;
  106. break;
  107. + case 'r':
  108. + bcm_rfkill_name = optarg;
  109. + break;
  110. case 's':
  111. log_stderr = 1;
  112. break;
  113. @@ -1148,6 +1161,9 @@ int main(int argc, char **argv)
  114. random_default_bdaddr();
  115. DEBUG("Default bdaddr: %s", default_bd_addr);
  116.  
  117. + DEBUG("Stop patcher if it's running now");
  118. + free_hci();
  119. +
  120. /* If Bluetooth kernel module is specified, try to unload and
  121. reload it before starting up. */
  122. if (bt_module) {
  123. @@ -1239,8 +1255,8 @@ int main(int argc, char **argv)
  124. {
  125. /* if unblock is for power interface: download patch and eventually register hci device */
  126. INFO("BT power driver unblocked");
  127. - free_hci();
  128. - attach_hci();
  129. + if (!patcher_started)
  130. + attach_hci();
  131. /* force to unblock also the bluetooth hci rfkill interface if hci device was registered */
  132. if (hci_dev_registered)
  133. rfkill_bluetooth_unblock();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement