Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <linux/rfkill.h>
- struct rfkill_event event = {0};
- int main(void) {
- int rfkill_fd;
- if((rfkill_fd = open("/dev/rfkill", O_RDWR)) < 0){
- perror("open");
- exit(1);
- }
- printf("Starting condition\n");
- if (read(rfkill_fd, &event, sizeof(event)) > 0)
- {
- if(event.type == RFKILL_TYPE_BLUETOOTH)
- printf("1. Bluetooth chip switches: soft(%d), hard(%d).\n", event.soft, event.hard);
- }
- printf("Going to block the bt chip\n");
- event.type = RFKILL_TYPE_BLUETOOTH; // Targetting Bluetooth switches
- event.op = RFKILL_OP_CHANGE_ALL; // Change all switches
- event.soft = 1; // Set to block
- if(write(rfkill_fd, &event, sizeof(event)) < 0){
- perror("write");
- exit(1);
- }
- if (read(rfkill_fd, &event, sizeof(event)) > 0)
- {
- if(event.type == RFKILL_TYPE_BLUETOOTH)
- printf("2. Bluetooth chip switches: soft(%d), hard(%d).\n", event.soft, event.hard);
- }
- printf("Going to unblock the bt chip\n");
- event.type = RFKILL_TYPE_BLUETOOTH; // Targetting Bluetooth switches
- event.op = RFKILL_OP_CHANGE_ALL; // Change all switches
- //event.action = 0; // Set to unblock
- event.soft = 0;
- if(write(rfkill_fd, &event, sizeof(event)) < 0){
- perror("write");
- exit(1);
- }
- if (read(rfkill_fd, &event, sizeof(event)) > 0)
- {
- if(event.type == RFKILL_TYPE_BLUETOOTH)
- printf("3. Bluetooth chip switches: soft(%d), hard(%d).\n", event.soft, event.hard);
- }
- close(rfkill_fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement