Guest User

Untitled

a guest
Apr 7th, 2026
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <errno.h>
  3. #include <sys/ioctl.h>
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <bluetooth/bluetooth.h>
  7. #include <bluetooth/hci.h>
  8.  
  9. #define HCISETACLPRIO  _IOW('H', 250, int)
  10. struct hci_acl_prio_req {
  11.     uint16_t handle;
  12.     uint8_t  high_prio;
  13. };
  14.  
  15.  
  16. int main() {
  17.     int sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
  18.     int opt = 1;
  19.     if (setsockopt(sock, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) {
  20.         fprintf(stderr, "Error setting data direction\n");
  21.         return 1;
  22.     }
  23.     struct sockaddr_hci addr;
  24.     addr.hci_family = AF_BLUETOOTH;
  25.     addr.hci_dev = 0;  // hci0
  26.     if(bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  27.         fprintf(stderr, "Can't attach to device hci0. %s(%d)\n", strerror(errno), errno);
  28.         return 1;
  29.     }
  30.  
  31.     struct hci_conn_list_req *conn_list = malloc(10 * (
  32.             sizeof(struct hci_conn_list_req) + sizeof(struct hci_conn_info)));
  33.  
  34.     conn_list->dev_id = 0;  /* hardcoded to HCI device 0 */
  35.     conn_list->conn_num = 10;
  36.  
  37.     if (ioctl(sock, HCIGETCONNLIST, (void *)conn_list)) {
  38.         fprintf(stderr, "Failed to get connection list\n");
  39.         return 1;
  40.     }
  41.  
  42.     for (int i = 0; i < conn_list->conn_num; i++) {
  43.         struct hci_conn_info *conn_info = &conn_list->conn_info[i];
  44.         if (conn_info->type == ACL_LINK) {
  45.             printf("%d %d %d\n", conn_info->handle, conn_info->state, conn_info->link_mode);
  46.             struct hci_acl_prio_req req = {
  47.                 .handle = conn_info->handle,
  48.                 .high_prio = 1,
  49.             };
  50.             if (ioctl(sock, HCISETACLPRIO, (void *)&req)) {
  51.                 fprintf(stderr, "Failed to set priority\n");
  52.                 return 1;
  53.             }
  54.         }
  55.     }
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment