Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <errno.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <bluetooth/bluetooth.h>
- #include <bluetooth/hci.h>
- #define HCISETACLPRIO _IOW('H', 250, int)
- struct hci_acl_prio_req {
- uint16_t handle;
- uint8_t high_prio;
- };
- int main() {
- int sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
- int opt = 1;
- if (setsockopt(sock, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) {
- fprintf(stderr, "Error setting data direction\n");
- return 1;
- }
- struct sockaddr_hci addr;
- addr.hci_family = AF_BLUETOOTH;
- addr.hci_dev = 0; // hci0
- if(bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- fprintf(stderr, "Can't attach to device hci0. %s(%d)\n", strerror(errno), errno);
- return 1;
- }
- struct hci_conn_list_req *conn_list = malloc(10 * (
- sizeof(struct hci_conn_list_req) + sizeof(struct hci_conn_info)));
- conn_list->dev_id = 0; /* hardcoded to HCI device 0 */
- conn_list->conn_num = 10;
- if (ioctl(sock, HCIGETCONNLIST, (void *)conn_list)) {
- fprintf(stderr, "Failed to get connection list\n");
- return 1;
- }
- for (int i = 0; i < conn_list->conn_num; i++) {
- struct hci_conn_info *conn_info = &conn_list->conn_info[i];
- if (conn_info->type == ACL_LINK) {
- printf("%d %d %d\n", conn_info->handle, conn_info->state, conn_info->link_mode);
- struct hci_acl_prio_req req = {
- .handle = conn_info->handle,
- .high_prio = 1,
- };
- if (ioctl(sock, HCISETACLPRIO, (void *)&req)) {
- fprintf(stderr, "Failed to set priority\n");
- return 1;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment