Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <linux/rfkill.h>
  5.  
  6. struct rfkill_event event = {0};
  7.  
  8. int main(void) {
  9. int rfkill_fd;
  10. if((rfkill_fd = open("/dev/rfkill", O_RDWR)) < 0){
  11. perror("open");
  12. exit(1);
  13. }
  14.  
  15. printf("Starting condition\n");
  16. if (read(rfkill_fd, &event, sizeof(event)) > 0)
  17. {
  18. if(event.type == RFKILL_TYPE_BLUETOOTH)
  19. printf("1. Bluetooth chip switches: soft(%d), hard(%d).\n", event.soft, event.hard);
  20. }
  21.  
  22.  
  23. printf("Going to block the bt chip\n");
  24. event.type = RFKILL_TYPE_BLUETOOTH; // Targetting Bluetooth switches
  25. event.op = RFKILL_OP_CHANGE_ALL; // Change all switches
  26. event.soft = 1; // Set to block
  27.  
  28. if(write(rfkill_fd, &event, sizeof(event)) < 0){
  29. perror("write");
  30. exit(1);
  31. }
  32.  
  33. if (read(rfkill_fd, &event, sizeof(event)) > 0)
  34. {
  35. if(event.type == RFKILL_TYPE_BLUETOOTH)
  36. printf("2. Bluetooth chip switches: soft(%d), hard(%d).\n", event.soft, event.hard);
  37. }
  38.  
  39. printf("Going to unblock the bt chip\n");
  40. event.type = RFKILL_TYPE_BLUETOOTH; // Targetting Bluetooth switches
  41. event.op = RFKILL_OP_CHANGE_ALL; // Change all switches
  42. //event.action = 0; // Set to unblock
  43. event.soft = 0;
  44.  
  45. if(write(rfkill_fd, &event, sizeof(event)) < 0){
  46. perror("write");
  47. exit(1);
  48. }
  49.  
  50. if (read(rfkill_fd, &event, sizeof(event)) > 0)
  51. {
  52. if(event.type == RFKILL_TYPE_BLUETOOTH)
  53. printf("3. Bluetooth chip switches: soft(%d), hard(%d).\n", event.soft, event.hard);
  54. }
  55.  
  56. close(rfkill_fd);
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement