diff options
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r-- | net/bluetooth/mgmt.c | 518 |
1 files changed, 474 insertions, 44 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 4476d8e3c0f2..c304688252b8 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c | |||
@@ -36,7 +36,7 @@ struct pending_cmd { | |||
36 | struct list_head list; | 36 | struct list_head list; |
37 | __u16 opcode; | 37 | __u16 opcode; |
38 | int index; | 38 | int index; |
39 | void *cmd; | 39 | void *param; |
40 | struct sock *sk; | 40 | struct sock *sk; |
41 | void *user_data; | 41 | void *user_data; |
42 | }; | 42 | }; |
@@ -179,10 +179,12 @@ static int read_controller_info(struct sock *sk, u16 index) | |||
179 | 179 | ||
180 | hci_del_off_timer(hdev); | 180 | hci_del_off_timer(hdev); |
181 | 181 | ||
182 | hci_dev_lock_bh(hdev); | 182 | hci_dev_lock(hdev); |
183 | 183 | ||
184 | set_bit(HCI_MGMT, &hdev->flags); | 184 | set_bit(HCI_MGMT, &hdev->flags); |
185 | 185 | ||
186 | memset(&rp, 0, sizeof(rp)); | ||
187 | |||
186 | rp.type = hdev->dev_type; | 188 | rp.type = hdev->dev_type; |
187 | 189 | ||
188 | rp.powered = test_bit(HCI_UP, &hdev->flags); | 190 | rp.powered = test_bit(HCI_UP, &hdev->flags); |
@@ -204,7 +206,9 @@ static int read_controller_info(struct sock *sk, u16 index) | |||
204 | rp.hci_ver = hdev->hci_ver; | 206 | rp.hci_ver = hdev->hci_ver; |
205 | put_unaligned_le16(hdev->hci_rev, &rp.hci_rev); | 207 | put_unaligned_le16(hdev->hci_rev, &rp.hci_rev); |
206 | 208 | ||
207 | hci_dev_unlock_bh(hdev); | 209 | memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); |
210 | |||
211 | hci_dev_unlock(hdev); | ||
208 | hci_dev_put(hdev); | 212 | hci_dev_put(hdev); |
209 | 213 | ||
210 | return cmd_complete(sk, index, MGMT_OP_READ_INFO, &rp, sizeof(rp)); | 214 | return cmd_complete(sk, index, MGMT_OP_READ_INFO, &rp, sizeof(rp)); |
@@ -213,7 +217,7 @@ static int read_controller_info(struct sock *sk, u16 index) | |||
213 | static void mgmt_pending_free(struct pending_cmd *cmd) | 217 | static void mgmt_pending_free(struct pending_cmd *cmd) |
214 | { | 218 | { |
215 | sock_put(cmd->sk); | 219 | sock_put(cmd->sk); |
216 | kfree(cmd->cmd); | 220 | kfree(cmd->param); |
217 | kfree(cmd); | 221 | kfree(cmd); |
218 | } | 222 | } |
219 | 223 | ||
@@ -229,13 +233,14 @@ static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode, | |||
229 | cmd->opcode = opcode; | 233 | cmd->opcode = opcode; |
230 | cmd->index = index; | 234 | cmd->index = index; |
231 | 235 | ||
232 | cmd->cmd = kmalloc(len, GFP_ATOMIC); | 236 | cmd->param = kmalloc(len, GFP_ATOMIC); |
233 | if (!cmd->cmd) { | 237 | if (!cmd->param) { |
234 | kfree(cmd); | 238 | kfree(cmd); |
235 | return NULL; | 239 | return NULL; |
236 | } | 240 | } |
237 | 241 | ||
238 | memcpy(cmd->cmd, data, len); | 242 | if (data) |
243 | memcpy(cmd->param, data, len); | ||
239 | 244 | ||
240 | cmd->sk = sk; | 245 | cmd->sk = sk; |
241 | sock_hold(sk); | 246 | sock_hold(sk); |
@@ -311,7 +316,7 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
311 | if (!hdev) | 316 | if (!hdev) |
312 | return cmd_status(sk, index, MGMT_OP_SET_POWERED, ENODEV); | 317 | return cmd_status(sk, index, MGMT_OP_SET_POWERED, ENODEV); |
313 | 318 | ||
314 | hci_dev_lock_bh(hdev); | 319 | hci_dev_lock(hdev); |
315 | 320 | ||
316 | up = test_bit(HCI_UP, &hdev->flags); | 321 | up = test_bit(HCI_UP, &hdev->flags); |
317 | if ((cp->val && up) || (!cp->val && !up)) { | 322 | if ((cp->val && up) || (!cp->val && !up)) { |
@@ -338,7 +343,7 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
338 | err = 0; | 343 | err = 0; |
339 | 344 | ||
340 | failed: | 345 | failed: |
341 | hci_dev_unlock_bh(hdev); | 346 | hci_dev_unlock(hdev); |
342 | hci_dev_put(hdev); | 347 | hci_dev_put(hdev); |
343 | return err; | 348 | return err; |
344 | } | 349 | } |
@@ -363,7 +368,7 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data, | |||
363 | if (!hdev) | 368 | if (!hdev) |
364 | return cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, ENODEV); | 369 | return cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, ENODEV); |
365 | 370 | ||
366 | hci_dev_lock_bh(hdev); | 371 | hci_dev_lock(hdev); |
367 | 372 | ||
368 | if (!test_bit(HCI_UP, &hdev->flags)) { | 373 | if (!test_bit(HCI_UP, &hdev->flags)) { |
369 | err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, ENETDOWN); | 374 | err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, ENETDOWN); |
@@ -398,7 +403,7 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data, | |||
398 | mgmt_pending_remove(cmd); | 403 | mgmt_pending_remove(cmd); |
399 | 404 | ||
400 | failed: | 405 | failed: |
401 | hci_dev_unlock_bh(hdev); | 406 | hci_dev_unlock(hdev); |
402 | hci_dev_put(hdev); | 407 | hci_dev_put(hdev); |
403 | 408 | ||
404 | return err; | 409 | return err; |
@@ -424,7 +429,7 @@ static int set_connectable(struct sock *sk, u16 index, unsigned char *data, | |||
424 | if (!hdev) | 429 | if (!hdev) |
425 | return cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, ENODEV); | 430 | return cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, ENODEV); |
426 | 431 | ||
427 | hci_dev_lock_bh(hdev); | 432 | hci_dev_lock(hdev); |
428 | 433 | ||
429 | if (!test_bit(HCI_UP, &hdev->flags)) { | 434 | if (!test_bit(HCI_UP, &hdev->flags)) { |
430 | err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, ENETDOWN); | 435 | err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, ENETDOWN); |
@@ -458,7 +463,7 @@ static int set_connectable(struct sock *sk, u16 index, unsigned char *data, | |||
458 | mgmt_pending_remove(cmd); | 463 | mgmt_pending_remove(cmd); |
459 | 464 | ||
460 | failed: | 465 | failed: |
461 | hci_dev_unlock_bh(hdev); | 466 | hci_dev_unlock(hdev); |
462 | hci_dev_put(hdev); | 467 | hci_dev_put(hdev); |
463 | 468 | ||
464 | return err; | 469 | return err; |
@@ -517,7 +522,7 @@ static int set_pairable(struct sock *sk, u16 index, unsigned char *data, | |||
517 | if (!hdev) | 522 | if (!hdev) |
518 | return cmd_status(sk, index, MGMT_OP_SET_PAIRABLE, ENODEV); | 523 | return cmd_status(sk, index, MGMT_OP_SET_PAIRABLE, ENODEV); |
519 | 524 | ||
520 | hci_dev_lock_bh(hdev); | 525 | hci_dev_lock(hdev); |
521 | 526 | ||
522 | if (cp->val) | 527 | if (cp->val) |
523 | set_bit(HCI_PAIRABLE, &hdev->flags); | 528 | set_bit(HCI_PAIRABLE, &hdev->flags); |
@@ -533,12 +538,156 @@ static int set_pairable(struct sock *sk, u16 index, unsigned char *data, | |||
533 | err = mgmt_event(MGMT_EV_PAIRABLE, index, &ev, sizeof(ev), sk); | 538 | err = mgmt_event(MGMT_EV_PAIRABLE, index, &ev, sizeof(ev), sk); |
534 | 539 | ||
535 | failed: | 540 | failed: |
536 | hci_dev_unlock_bh(hdev); | 541 | hci_dev_unlock(hdev); |
537 | hci_dev_put(hdev); | 542 | hci_dev_put(hdev); |
538 | 543 | ||
539 | return err; | 544 | return err; |
540 | } | 545 | } |
541 | 546 | ||
547 | #define EIR_FLAGS 0x01 /* flags */ | ||
548 | #define EIR_UUID16_SOME 0x02 /* 16-bit UUID, more available */ | ||
549 | #define EIR_UUID16_ALL 0x03 /* 16-bit UUID, all listed */ | ||
550 | #define EIR_UUID32_SOME 0x04 /* 32-bit UUID, more available */ | ||
551 | #define EIR_UUID32_ALL 0x05 /* 32-bit UUID, all listed */ | ||
552 | #define EIR_UUID128_SOME 0x06 /* 128-bit UUID, more available */ | ||
553 | #define EIR_UUID128_ALL 0x07 /* 128-bit UUID, all listed */ | ||
554 | #define EIR_NAME_SHORT 0x08 /* shortened local name */ | ||
555 | #define EIR_NAME_COMPLETE 0x09 /* complete local name */ | ||
556 | #define EIR_TX_POWER 0x0A /* transmit power level */ | ||
557 | #define EIR_DEVICE_ID 0x10 /* device ID */ | ||
558 | |||
559 | #define PNP_INFO_SVCLASS_ID 0x1200 | ||
560 | |||
561 | static u8 bluetooth_base_uuid[] = { | ||
562 | 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, | ||
563 | 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
564 | }; | ||
565 | |||
566 | static u16 get_uuid16(u8 *uuid128) | ||
567 | { | ||
568 | u32 val; | ||
569 | int i; | ||
570 | |||
571 | for (i = 0; i < 12; i++) { | ||
572 | if (bluetooth_base_uuid[i] != uuid128[i]) | ||
573 | return 0; | ||
574 | } | ||
575 | |||
576 | memcpy(&val, &uuid128[12], 4); | ||
577 | |||
578 | val = le32_to_cpu(val); | ||
579 | if (val > 0xffff) | ||
580 | return 0; | ||
581 | |||
582 | return (u16) val; | ||
583 | } | ||
584 | |||
585 | static void create_eir(struct hci_dev *hdev, u8 *data) | ||
586 | { | ||
587 | u8 *ptr = data; | ||
588 | u16 eir_len = 0; | ||
589 | u16 uuid16_list[HCI_MAX_EIR_LENGTH / sizeof(u16)]; | ||
590 | int i, truncated = 0; | ||
591 | struct list_head *p; | ||
592 | size_t name_len; | ||
593 | |||
594 | name_len = strlen(hdev->dev_name); | ||
595 | |||
596 | if (name_len > 0) { | ||
597 | /* EIR Data type */ | ||
598 | if (name_len > 48) { | ||
599 | name_len = 48; | ||
600 | ptr[1] = EIR_NAME_SHORT; | ||
601 | } else | ||
602 | ptr[1] = EIR_NAME_COMPLETE; | ||
603 | |||
604 | /* EIR Data length */ | ||
605 | ptr[0] = name_len + 1; | ||
606 | |||
607 | memcpy(ptr + 2, hdev->dev_name, name_len); | ||
608 | |||
609 | eir_len += (name_len + 2); | ||
610 | ptr += (name_len + 2); | ||
611 | } | ||
612 | |||
613 | memset(uuid16_list, 0, sizeof(uuid16_list)); | ||
614 | |||
615 | /* Group all UUID16 types */ | ||
616 | list_for_each(p, &hdev->uuids) { | ||
617 | struct bt_uuid *uuid = list_entry(p, struct bt_uuid, list); | ||
618 | u16 uuid16; | ||
619 | |||
620 | uuid16 = get_uuid16(uuid->uuid); | ||
621 | if (uuid16 == 0) | ||
622 | return; | ||
623 | |||
624 | if (uuid16 < 0x1100) | ||
625 | continue; | ||
626 | |||
627 | if (uuid16 == PNP_INFO_SVCLASS_ID) | ||
628 | continue; | ||
629 | |||
630 | /* Stop if not enough space to put next UUID */ | ||
631 | if (eir_len + 2 + sizeof(u16) > HCI_MAX_EIR_LENGTH) { | ||
632 | truncated = 1; | ||
633 | break; | ||
634 | } | ||
635 | |||
636 | /* Check for duplicates */ | ||
637 | for (i = 0; uuid16_list[i] != 0; i++) | ||
638 | if (uuid16_list[i] == uuid16) | ||
639 | break; | ||
640 | |||
641 | if (uuid16_list[i] == 0) { | ||
642 | uuid16_list[i] = uuid16; | ||
643 | eir_len += sizeof(u16); | ||
644 | } | ||
645 | } | ||
646 | |||
647 | if (uuid16_list[0] != 0) { | ||
648 | u8 *length = ptr; | ||
649 | |||
650 | /* EIR Data type */ | ||
651 | ptr[1] = truncated ? EIR_UUID16_SOME : EIR_UUID16_ALL; | ||
652 | |||
653 | ptr += 2; | ||
654 | eir_len += 2; | ||
655 | |||
656 | for (i = 0; uuid16_list[i] != 0; i++) { | ||
657 | *ptr++ = (uuid16_list[i] & 0x00ff); | ||
658 | *ptr++ = (uuid16_list[i] & 0xff00) >> 8; | ||
659 | } | ||
660 | |||
661 | /* EIR Data length */ | ||
662 | *length = (i * sizeof(u16)) + 1; | ||
663 | } | ||
664 | } | ||
665 | |||
666 | static int update_eir(struct hci_dev *hdev) | ||
667 | { | ||
668 | struct hci_cp_write_eir cp; | ||
669 | |||
670 | if (!(hdev->features[6] & LMP_EXT_INQ)) | ||
671 | return 0; | ||
672 | |||
673 | if (hdev->ssp_mode == 0) | ||
674 | return 0; | ||
675 | |||
676 | if (test_bit(HCI_SERVICE_CACHE, &hdev->flags)) | ||
677 | return 0; | ||
678 | |||
679 | memset(&cp, 0, sizeof(cp)); | ||
680 | |||
681 | create_eir(hdev, cp.data); | ||
682 | |||
683 | if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) | ||
684 | return 0; | ||
685 | |||
686 | memcpy(hdev->eir, cp.data, sizeof(cp.data)); | ||
687 | |||
688 | return hci_send_cmd(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp); | ||
689 | } | ||
690 | |||
542 | static u8 get_service_classes(struct hci_dev *hdev) | 691 | static u8 get_service_classes(struct hci_dev *hdev) |
543 | { | 692 | { |
544 | struct list_head *p; | 693 | struct list_head *p; |
@@ -590,7 +739,7 @@ static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
590 | if (!hdev) | 739 | if (!hdev) |
591 | return cmd_status(sk, index, MGMT_OP_ADD_UUID, ENODEV); | 740 | return cmd_status(sk, index, MGMT_OP_ADD_UUID, ENODEV); |
592 | 741 | ||
593 | hci_dev_lock_bh(hdev); | 742 | hci_dev_lock(hdev); |
594 | 743 | ||
595 | uuid = kmalloc(sizeof(*uuid), GFP_ATOMIC); | 744 | uuid = kmalloc(sizeof(*uuid), GFP_ATOMIC); |
596 | if (!uuid) { | 745 | if (!uuid) { |
@@ -607,10 +756,14 @@ static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
607 | if (err < 0) | 756 | if (err < 0) |
608 | goto failed; | 757 | goto failed; |
609 | 758 | ||
759 | err = update_eir(hdev); | ||
760 | if (err < 0) | ||
761 | goto failed; | ||
762 | |||
610 | err = cmd_complete(sk, index, MGMT_OP_ADD_UUID, NULL, 0); | 763 | err = cmd_complete(sk, index, MGMT_OP_ADD_UUID, NULL, 0); |
611 | 764 | ||
612 | failed: | 765 | failed: |
613 | hci_dev_unlock_bh(hdev); | 766 | hci_dev_unlock(hdev); |
614 | hci_dev_put(hdev); | 767 | hci_dev_put(hdev); |
615 | 768 | ||
616 | return err; | 769 | return err; |
@@ -635,7 +788,7 @@ static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
635 | if (!hdev) | 788 | if (!hdev) |
636 | return cmd_status(sk, index, MGMT_OP_REMOVE_UUID, ENODEV); | 789 | return cmd_status(sk, index, MGMT_OP_REMOVE_UUID, ENODEV); |
637 | 790 | ||
638 | hci_dev_lock_bh(hdev); | 791 | hci_dev_lock(hdev); |
639 | 792 | ||
640 | if (memcmp(cp->uuid, bt_uuid_any, 16) == 0) { | 793 | if (memcmp(cp->uuid, bt_uuid_any, 16) == 0) { |
641 | err = hci_uuids_clear(hdev); | 794 | err = hci_uuids_clear(hdev); |
@@ -663,10 +816,14 @@ static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
663 | if (err < 0) | 816 | if (err < 0) |
664 | goto unlock; | 817 | goto unlock; |
665 | 818 | ||
819 | err = update_eir(hdev); | ||
820 | if (err < 0) | ||
821 | goto unlock; | ||
822 | |||
666 | err = cmd_complete(sk, index, MGMT_OP_REMOVE_UUID, NULL, 0); | 823 | err = cmd_complete(sk, index, MGMT_OP_REMOVE_UUID, NULL, 0); |
667 | 824 | ||
668 | unlock: | 825 | unlock: |
669 | hci_dev_unlock_bh(hdev); | 826 | hci_dev_unlock(hdev); |
670 | hci_dev_put(hdev); | 827 | hci_dev_put(hdev); |
671 | 828 | ||
672 | return err; | 829 | return err; |
@@ -690,7 +847,7 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data, | |||
690 | if (!hdev) | 847 | if (!hdev) |
691 | return cmd_status(sk, index, MGMT_OP_SET_DEV_CLASS, ENODEV); | 848 | return cmd_status(sk, index, MGMT_OP_SET_DEV_CLASS, ENODEV); |
692 | 849 | ||
693 | hci_dev_lock_bh(hdev); | 850 | hci_dev_lock(hdev); |
694 | 851 | ||
695 | hdev->major_class = cp->major; | 852 | hdev->major_class = cp->major; |
696 | hdev->minor_class = cp->minor; | 853 | hdev->minor_class = cp->minor; |
@@ -700,7 +857,7 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data, | |||
700 | if (err == 0) | 857 | if (err == 0) |
701 | err = cmd_complete(sk, index, MGMT_OP_SET_DEV_CLASS, NULL, 0); | 858 | err = cmd_complete(sk, index, MGMT_OP_SET_DEV_CLASS, NULL, 0); |
702 | 859 | ||
703 | hci_dev_unlock_bh(hdev); | 860 | hci_dev_unlock(hdev); |
704 | hci_dev_put(hdev); | 861 | hci_dev_put(hdev); |
705 | 862 | ||
706 | return err; | 863 | return err; |
@@ -722,7 +879,7 @@ static int set_service_cache(struct sock *sk, u16 index, unsigned char *data, | |||
722 | if (!hdev) | 879 | if (!hdev) |
723 | return cmd_status(sk, index, MGMT_OP_SET_SERVICE_CACHE, ENODEV); | 880 | return cmd_status(sk, index, MGMT_OP_SET_SERVICE_CACHE, ENODEV); |
724 | 881 | ||
725 | hci_dev_lock_bh(hdev); | 882 | hci_dev_lock(hdev); |
726 | 883 | ||
727 | BT_DBG("hci%u enable %d", index, cp->enable); | 884 | BT_DBG("hci%u enable %d", index, cp->enable); |
728 | 885 | ||
@@ -732,13 +889,15 @@ static int set_service_cache(struct sock *sk, u16 index, unsigned char *data, | |||
732 | } else { | 889 | } else { |
733 | clear_bit(HCI_SERVICE_CACHE, &hdev->flags); | 890 | clear_bit(HCI_SERVICE_CACHE, &hdev->flags); |
734 | err = update_class(hdev); | 891 | err = update_class(hdev); |
892 | if (err == 0) | ||
893 | err = update_eir(hdev); | ||
735 | } | 894 | } |
736 | 895 | ||
737 | if (err == 0) | 896 | if (err == 0) |
738 | err = cmd_complete(sk, index, MGMT_OP_SET_SERVICE_CACHE, NULL, | 897 | err = cmd_complete(sk, index, MGMT_OP_SET_SERVICE_CACHE, NULL, |
739 | 0); | 898 | 0); |
740 | 899 | ||
741 | hci_dev_unlock_bh(hdev); | 900 | hci_dev_unlock(hdev); |
742 | hci_dev_put(hdev); | 901 | hci_dev_put(hdev); |
743 | 902 | ||
744 | return err; | 903 | return err; |
@@ -772,7 +931,7 @@ static int load_keys(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
772 | BT_DBG("hci%u debug_keys %u key_count %u", index, cp->debug_keys, | 931 | BT_DBG("hci%u debug_keys %u key_count %u", index, cp->debug_keys, |
773 | key_count); | 932 | key_count); |
774 | 933 | ||
775 | hci_dev_lock_bh(hdev); | 934 | hci_dev_lock(hdev); |
776 | 935 | ||
777 | hci_link_keys_clear(hdev); | 936 | hci_link_keys_clear(hdev); |
778 | 937 | ||
@@ -790,7 +949,7 @@ static int load_keys(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
790 | key->pin_len); | 949 | key->pin_len); |
791 | } | 950 | } |
792 | 951 | ||
793 | hci_dev_unlock_bh(hdev); | 952 | hci_dev_unlock(hdev); |
794 | hci_dev_put(hdev); | 953 | hci_dev_put(hdev); |
795 | 954 | ||
796 | return 0; | 955 | return 0; |
@@ -812,7 +971,7 @@ static int remove_key(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
812 | if (!hdev) | 971 | if (!hdev) |
813 | return cmd_status(sk, index, MGMT_OP_REMOVE_KEY, ENODEV); | 972 | return cmd_status(sk, index, MGMT_OP_REMOVE_KEY, ENODEV); |
814 | 973 | ||
815 | hci_dev_lock_bh(hdev); | 974 | hci_dev_lock(hdev); |
816 | 975 | ||
817 | err = hci_remove_link_key(hdev, &cp->bdaddr); | 976 | err = hci_remove_link_key(hdev, &cp->bdaddr); |
818 | if (err < 0) { | 977 | if (err < 0) { |
@@ -835,7 +994,7 @@ static int remove_key(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
835 | } | 994 | } |
836 | 995 | ||
837 | unlock: | 996 | unlock: |
838 | hci_dev_unlock_bh(hdev); | 997 | hci_dev_unlock(hdev); |
839 | hci_dev_put(hdev); | 998 | hci_dev_put(hdev); |
840 | 999 | ||
841 | return err; | 1000 | return err; |
@@ -861,7 +1020,7 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
861 | if (!hdev) | 1020 | if (!hdev) |
862 | return cmd_status(sk, index, MGMT_OP_DISCONNECT, ENODEV); | 1021 | return cmd_status(sk, index, MGMT_OP_DISCONNECT, ENODEV); |
863 | 1022 | ||
864 | hci_dev_lock_bh(hdev); | 1023 | hci_dev_lock(hdev); |
865 | 1024 | ||
866 | if (!test_bit(HCI_UP, &hdev->flags)) { | 1025 | if (!test_bit(HCI_UP, &hdev->flags)) { |
867 | err = cmd_status(sk, index, MGMT_OP_DISCONNECT, ENETDOWN); | 1026 | err = cmd_status(sk, index, MGMT_OP_DISCONNECT, ENETDOWN); |
@@ -893,7 +1052,7 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
893 | mgmt_pending_remove(cmd); | 1052 | mgmt_pending_remove(cmd); |
894 | 1053 | ||
895 | failed: | 1054 | failed: |
896 | hci_dev_unlock_bh(hdev); | 1055 | hci_dev_unlock(hdev); |
897 | hci_dev_put(hdev); | 1056 | hci_dev_put(hdev); |
898 | 1057 | ||
899 | return err; | 1058 | return err; |
@@ -914,7 +1073,7 @@ static int get_connections(struct sock *sk, u16 index) | |||
914 | if (!hdev) | 1073 | if (!hdev) |
915 | return cmd_status(sk, index, MGMT_OP_GET_CONNECTIONS, ENODEV); | 1074 | return cmd_status(sk, index, MGMT_OP_GET_CONNECTIONS, ENODEV); |
916 | 1075 | ||
917 | hci_dev_lock_bh(hdev); | 1076 | hci_dev_lock(hdev); |
918 | 1077 | ||
919 | count = 0; | 1078 | count = 0; |
920 | list_for_each(p, &hdev->conn_hash.list) { | 1079 | list_for_each(p, &hdev->conn_hash.list) { |
@@ -945,7 +1104,7 @@ static int get_connections(struct sock *sk, u16 index) | |||
945 | 1104 | ||
946 | unlock: | 1105 | unlock: |
947 | kfree(rp); | 1106 | kfree(rp); |
948 | hci_dev_unlock_bh(hdev); | 1107 | hci_dev_unlock(hdev); |
949 | hci_dev_put(hdev); | 1108 | hci_dev_put(hdev); |
950 | return err; | 1109 | return err; |
951 | } | 1110 | } |
@@ -970,7 +1129,7 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data, | |||
970 | if (!hdev) | 1129 | if (!hdev) |
971 | return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, ENODEV); | 1130 | return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, ENODEV); |
972 | 1131 | ||
973 | hci_dev_lock_bh(hdev); | 1132 | hci_dev_lock(hdev); |
974 | 1133 | ||
975 | if (!test_bit(HCI_UP, &hdev->flags)) { | 1134 | if (!test_bit(HCI_UP, &hdev->flags)) { |
976 | err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, ENETDOWN); | 1135 | err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, ENETDOWN); |
@@ -992,7 +1151,7 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data, | |||
992 | mgmt_pending_remove(cmd); | 1151 | mgmt_pending_remove(cmd); |
993 | 1152 | ||
994 | failed: | 1153 | failed: |
995 | hci_dev_unlock_bh(hdev); | 1154 | hci_dev_unlock(hdev); |
996 | hci_dev_put(hdev); | 1155 | hci_dev_put(hdev); |
997 | 1156 | ||
998 | return err; | 1157 | return err; |
@@ -1019,7 +1178,7 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data, | |||
1019 | return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, | 1178 | return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, |
1020 | ENODEV); | 1179 | ENODEV); |
1021 | 1180 | ||
1022 | hci_dev_lock_bh(hdev); | 1181 | hci_dev_lock(hdev); |
1023 | 1182 | ||
1024 | if (!test_bit(HCI_UP, &hdev->flags)) { | 1183 | if (!test_bit(HCI_UP, &hdev->flags)) { |
1025 | err = cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, | 1184 | err = cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, |
@@ -1040,7 +1199,7 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data, | |||
1040 | mgmt_pending_remove(cmd); | 1199 | mgmt_pending_remove(cmd); |
1041 | 1200 | ||
1042 | failed: | 1201 | failed: |
1043 | hci_dev_unlock_bh(hdev); | 1202 | hci_dev_unlock(hdev); |
1044 | hci_dev_put(hdev); | 1203 | hci_dev_put(hdev); |
1045 | 1204 | ||
1046 | return err; | 1205 | return err; |
@@ -1063,14 +1222,14 @@ static int set_io_capability(struct sock *sk, u16 index, unsigned char *data, | |||
1063 | if (!hdev) | 1222 | if (!hdev) |
1064 | return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY, ENODEV); | 1223 | return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY, ENODEV); |
1065 | 1224 | ||
1066 | hci_dev_lock_bh(hdev); | 1225 | hci_dev_lock(hdev); |
1067 | 1226 | ||
1068 | hdev->io_capability = cp->io_capability; | 1227 | hdev->io_capability = cp->io_capability; |
1069 | 1228 | ||
1070 | BT_DBG("%s IO capability set to 0x%02x", hdev->name, | 1229 | BT_DBG("%s IO capability set to 0x%02x", hdev->name, |
1071 | hdev->io_capability); | 1230 | hdev->io_capability); |
1072 | 1231 | ||
1073 | hci_dev_unlock_bh(hdev); | 1232 | hci_dev_unlock(hdev); |
1074 | hci_dev_put(hdev); | 1233 | hci_dev_put(hdev); |
1075 | 1234 | ||
1076 | return cmd_complete(sk, index, MGMT_OP_SET_IO_CAPABILITY, NULL, 0); | 1235 | return cmd_complete(sk, index, MGMT_OP_SET_IO_CAPABILITY, NULL, 0); |
@@ -1156,7 +1315,7 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
1156 | if (!hdev) | 1315 | if (!hdev) |
1157 | return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE, ENODEV); | 1316 | return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE, ENODEV); |
1158 | 1317 | ||
1159 | hci_dev_lock_bh(hdev); | 1318 | hci_dev_lock(hdev); |
1160 | 1319 | ||
1161 | if (cp->io_cap == 0x03) { | 1320 | if (cp->io_cap == 0x03) { |
1162 | sec_level = BT_SECURITY_MEDIUM; | 1321 | sec_level = BT_SECURITY_MEDIUM; |
@@ -1198,7 +1357,7 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
1198 | err = 0; | 1357 | err = 0; |
1199 | 1358 | ||
1200 | unlock: | 1359 | unlock: |
1201 | hci_dev_unlock_bh(hdev); | 1360 | hci_dev_unlock(hdev); |
1202 | hci_dev_put(hdev); | 1361 | hci_dev_put(hdev); |
1203 | 1362 | ||
1204 | return err; | 1363 | return err; |
@@ -1230,7 +1389,7 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data, | |||
1230 | if (!hdev) | 1389 | if (!hdev) |
1231 | return cmd_status(sk, index, mgmt_op, ENODEV); | 1390 | return cmd_status(sk, index, mgmt_op, ENODEV); |
1232 | 1391 | ||
1233 | hci_dev_lock_bh(hdev); | 1392 | hci_dev_lock(hdev); |
1234 | 1393 | ||
1235 | if (!test_bit(HCI_UP, &hdev->flags)) { | 1394 | if (!test_bit(HCI_UP, &hdev->flags)) { |
1236 | err = cmd_status(sk, index, mgmt_op, ENETDOWN); | 1395 | err = cmd_status(sk, index, mgmt_op, ENETDOWN); |
@@ -1248,7 +1407,163 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data, | |||
1248 | mgmt_pending_remove(cmd); | 1407 | mgmt_pending_remove(cmd); |
1249 | 1408 | ||
1250 | failed: | 1409 | failed: |
1251 | hci_dev_unlock_bh(hdev); | 1410 | hci_dev_unlock(hdev); |
1411 | hci_dev_put(hdev); | ||
1412 | |||
1413 | return err; | ||
1414 | } | ||
1415 | |||
1416 | static int set_local_name(struct sock *sk, u16 index, unsigned char *data, | ||
1417 | u16 len) | ||
1418 | { | ||
1419 | struct mgmt_cp_set_local_name *mgmt_cp = (void *) data; | ||
1420 | struct hci_cp_write_local_name hci_cp; | ||
1421 | struct hci_dev *hdev; | ||
1422 | struct pending_cmd *cmd; | ||
1423 | int err; | ||
1424 | |||
1425 | BT_DBG(""); | ||
1426 | |||
1427 | if (len != sizeof(*mgmt_cp)) | ||
1428 | return cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME, EINVAL); | ||
1429 | |||
1430 | hdev = hci_dev_get(index); | ||
1431 | if (!hdev) | ||
1432 | return cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME, ENODEV); | ||
1433 | |||
1434 | hci_dev_lock(hdev); | ||
1435 | |||
1436 | cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, index, data, len); | ||
1437 | if (!cmd) { | ||
1438 | err = -ENOMEM; | ||
1439 | goto failed; | ||
1440 | } | ||
1441 | |||
1442 | memcpy(hci_cp.name, mgmt_cp->name, sizeof(hci_cp.name)); | ||
1443 | err = hci_send_cmd(hdev, HCI_OP_WRITE_LOCAL_NAME, sizeof(hci_cp), | ||
1444 | &hci_cp); | ||
1445 | if (err < 0) | ||
1446 | mgmt_pending_remove(cmd); | ||
1447 | |||
1448 | failed: | ||
1449 | hci_dev_unlock(hdev); | ||
1450 | hci_dev_put(hdev); | ||
1451 | |||
1452 | return err; | ||
1453 | } | ||
1454 | |||
1455 | static int read_local_oob_data(struct sock *sk, u16 index) | ||
1456 | { | ||
1457 | struct hci_dev *hdev; | ||
1458 | struct pending_cmd *cmd; | ||
1459 | int err; | ||
1460 | |||
1461 | BT_DBG("hci%u", index); | ||
1462 | |||
1463 | hdev = hci_dev_get(index); | ||
1464 | if (!hdev) | ||
1465 | return cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, | ||
1466 | ENODEV); | ||
1467 | |||
1468 | hci_dev_lock(hdev); | ||
1469 | |||
1470 | if (!test_bit(HCI_UP, &hdev->flags)) { | ||
1471 | err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, | ||
1472 | ENETDOWN); | ||
1473 | goto unlock; | ||
1474 | } | ||
1475 | |||
1476 | if (!(hdev->features[6] & LMP_SIMPLE_PAIR)) { | ||
1477 | err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, | ||
1478 | EOPNOTSUPP); | ||
1479 | goto unlock; | ||
1480 | } | ||
1481 | |||
1482 | if (mgmt_pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, index)) { | ||
1483 | err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, EBUSY); | ||
1484 | goto unlock; | ||
1485 | } | ||
1486 | |||
1487 | cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_DATA, index, NULL, 0); | ||
1488 | if (!cmd) { | ||
1489 | err = -ENOMEM; | ||
1490 | goto unlock; | ||
1491 | } | ||
1492 | |||
1493 | err = hci_send_cmd(hdev, HCI_OP_READ_LOCAL_OOB_DATA, 0, NULL); | ||
1494 | if (err < 0) | ||
1495 | mgmt_pending_remove(cmd); | ||
1496 | |||
1497 | unlock: | ||
1498 | hci_dev_unlock(hdev); | ||
1499 | hci_dev_put(hdev); | ||
1500 | |||
1501 | return err; | ||
1502 | } | ||
1503 | |||
1504 | static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data, | ||
1505 | u16 len) | ||
1506 | { | ||
1507 | struct hci_dev *hdev; | ||
1508 | struct mgmt_cp_add_remote_oob_data *cp = (void *) data; | ||
1509 | int err; | ||
1510 | |||
1511 | BT_DBG("hci%u ", index); | ||
1512 | |||
1513 | if (len != sizeof(*cp)) | ||
1514 | return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, | ||
1515 | EINVAL); | ||
1516 | |||
1517 | hdev = hci_dev_get(index); | ||
1518 | if (!hdev) | ||
1519 | return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, | ||
1520 | ENODEV); | ||
1521 | |||
1522 | hci_dev_lock(hdev); | ||
1523 | |||
1524 | err = hci_add_remote_oob_data(hdev, &cp->bdaddr, cp->hash, | ||
1525 | cp->randomizer); | ||
1526 | if (err < 0) | ||
1527 | err = cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, -err); | ||
1528 | else | ||
1529 | err = cmd_complete(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, NULL, | ||
1530 | 0); | ||
1531 | |||
1532 | hci_dev_unlock(hdev); | ||
1533 | hci_dev_put(hdev); | ||
1534 | |||
1535 | return err; | ||
1536 | } | ||
1537 | |||
1538 | static int remove_remote_oob_data(struct sock *sk, u16 index, | ||
1539 | unsigned char *data, u16 len) | ||
1540 | { | ||
1541 | struct hci_dev *hdev; | ||
1542 | struct mgmt_cp_remove_remote_oob_data *cp = (void *) data; | ||
1543 | int err; | ||
1544 | |||
1545 | BT_DBG("hci%u ", index); | ||
1546 | |||
1547 | if (len != sizeof(*cp)) | ||
1548 | return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA, | ||
1549 | EINVAL); | ||
1550 | |||
1551 | hdev = hci_dev_get(index); | ||
1552 | if (!hdev) | ||
1553 | return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA, | ||
1554 | ENODEV); | ||
1555 | |||
1556 | hci_dev_lock(hdev); | ||
1557 | |||
1558 | err = hci_remove_remote_oob_data(hdev, &cp->bdaddr); | ||
1559 | if (err < 0) | ||
1560 | err = cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA, | ||
1561 | -err); | ||
1562 | else | ||
1563 | err = cmd_complete(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA, | ||
1564 | NULL, 0); | ||
1565 | |||
1566 | hci_dev_unlock(hdev); | ||
1252 | hci_dev_put(hdev); | 1567 | hci_dev_put(hdev); |
1253 | 1568 | ||
1254 | return err; | 1569 | return err; |
@@ -1266,7 +1581,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) | |||
1266 | if (msglen < sizeof(*hdr)) | 1581 | if (msglen < sizeof(*hdr)) |
1267 | return -EINVAL; | 1582 | return -EINVAL; |
1268 | 1583 | ||
1269 | buf = kmalloc(msglen, GFP_ATOMIC); | 1584 | buf = kmalloc(msglen, GFP_KERNEL); |
1270 | if (!buf) | 1585 | if (!buf) |
1271 | return -ENOMEM; | 1586 | return -ENOMEM; |
1272 | 1587 | ||
@@ -1349,6 +1664,20 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) | |||
1349 | case MGMT_OP_USER_CONFIRM_NEG_REPLY: | 1664 | case MGMT_OP_USER_CONFIRM_NEG_REPLY: |
1350 | err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len, 0); | 1665 | err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len, 0); |
1351 | break; | 1666 | break; |
1667 | case MGMT_OP_SET_LOCAL_NAME: | ||
1668 | err = set_local_name(sk, index, buf + sizeof(*hdr), len); | ||
1669 | break; | ||
1670 | case MGMT_OP_READ_LOCAL_OOB_DATA: | ||
1671 | err = read_local_oob_data(sk, index); | ||
1672 | break; | ||
1673 | case MGMT_OP_ADD_REMOTE_OOB_DATA: | ||
1674 | err = add_remote_oob_data(sk, index, buf + sizeof(*hdr), len); | ||
1675 | break; | ||
1676 | case MGMT_OP_REMOVE_REMOTE_OOB_DATA: | ||
1677 | err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr), | ||
1678 | len); | ||
1679 | break; | ||
1680 | |||
1352 | default: | 1681 | default: |
1353 | BT_DBG("Unknown op %u", opcode); | 1682 | BT_DBG("Unknown op %u", opcode); |
1354 | err = cmd_status(sk, index, opcode, 0x01); | 1683 | err = cmd_status(sk, index, opcode, 0x01); |
@@ -1382,7 +1711,7 @@ struct cmd_lookup { | |||
1382 | 1711 | ||
1383 | static void mode_rsp(struct pending_cmd *cmd, void *data) | 1712 | static void mode_rsp(struct pending_cmd *cmd, void *data) |
1384 | { | 1713 | { |
1385 | struct mgmt_mode *cp = cmd->cmd; | 1714 | struct mgmt_mode *cp = cmd->param; |
1386 | struct cmd_lookup *match = data; | 1715 | struct cmd_lookup *match = data; |
1387 | 1716 | ||
1388 | if (cp->val != match->val) | 1717 | if (cp->val != match->val) |
@@ -1481,7 +1810,7 @@ int mgmt_connected(u16 index, bdaddr_t *bdaddr) | |||
1481 | 1810 | ||
1482 | static void disconnect_rsp(struct pending_cmd *cmd, void *data) | 1811 | static void disconnect_rsp(struct pending_cmd *cmd, void *data) |
1483 | { | 1812 | { |
1484 | struct mgmt_cp_disconnect *cp = cmd->cmd; | 1813 | struct mgmt_cp_disconnect *cp = cmd->param; |
1485 | struct sock **sk = data; | 1814 | struct sock **sk = data; |
1486 | struct mgmt_rp_disconnect rp; | 1815 | struct mgmt_rp_disconnect rp; |
1487 | 1816 | ||
@@ -1645,3 +1974,104 @@ int mgmt_auth_failed(u16 index, bdaddr_t *bdaddr, u8 status) | |||
1645 | 1974 | ||
1646 | return mgmt_event(MGMT_EV_AUTH_FAILED, index, &ev, sizeof(ev), NULL); | 1975 | return mgmt_event(MGMT_EV_AUTH_FAILED, index, &ev, sizeof(ev), NULL); |
1647 | } | 1976 | } |
1977 | |||
1978 | int mgmt_set_local_name_complete(u16 index, u8 *name, u8 status) | ||
1979 | { | ||
1980 | struct pending_cmd *cmd; | ||
1981 | struct hci_dev *hdev; | ||
1982 | struct mgmt_cp_set_local_name ev; | ||
1983 | int err; | ||
1984 | |||
1985 | memset(&ev, 0, sizeof(ev)); | ||
1986 | memcpy(ev.name, name, HCI_MAX_NAME_LENGTH); | ||
1987 | |||
1988 | cmd = mgmt_pending_find(MGMT_OP_SET_LOCAL_NAME, index); | ||
1989 | if (!cmd) | ||
1990 | goto send_event; | ||
1991 | |||
1992 | if (status) { | ||
1993 | err = cmd_status(cmd->sk, index, MGMT_OP_SET_LOCAL_NAME, EIO); | ||
1994 | goto failed; | ||
1995 | } | ||
1996 | |||
1997 | hdev = hci_dev_get(index); | ||
1998 | if (hdev) { | ||
1999 | hci_dev_lock_bh(hdev); | ||
2000 | update_eir(hdev); | ||
2001 | hci_dev_unlock_bh(hdev); | ||
2002 | hci_dev_put(hdev); | ||
2003 | } | ||
2004 | |||
2005 | err = cmd_complete(cmd->sk, index, MGMT_OP_SET_LOCAL_NAME, &ev, | ||
2006 | sizeof(ev)); | ||
2007 | if (err < 0) | ||
2008 | goto failed; | ||
2009 | |||
2010 | send_event: | ||
2011 | err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, index, &ev, sizeof(ev), | ||
2012 | cmd ? cmd->sk : NULL); | ||
2013 | |||
2014 | failed: | ||
2015 | if (cmd) | ||
2016 | mgmt_pending_remove(cmd); | ||
2017 | return err; | ||
2018 | } | ||
2019 | |||
2020 | int mgmt_read_local_oob_data_reply_complete(u16 index, u8 *hash, u8 *randomizer, | ||
2021 | u8 status) | ||
2022 | { | ||
2023 | struct pending_cmd *cmd; | ||
2024 | int err; | ||
2025 | |||
2026 | BT_DBG("hci%u status %u", index, status); | ||
2027 | |||
2028 | cmd = mgmt_pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, index); | ||
2029 | if (!cmd) | ||
2030 | return -ENOENT; | ||
2031 | |||
2032 | if (status) { | ||
2033 | err = cmd_status(cmd->sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, | ||
2034 | EIO); | ||
2035 | } else { | ||
2036 | struct mgmt_rp_read_local_oob_data rp; | ||
2037 | |||
2038 | memcpy(rp.hash, hash, sizeof(rp.hash)); | ||
2039 | memcpy(rp.randomizer, randomizer, sizeof(rp.randomizer)); | ||
2040 | |||
2041 | err = cmd_complete(cmd->sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, | ||
2042 | &rp, sizeof(rp)); | ||
2043 | } | ||
2044 | |||
2045 | mgmt_pending_remove(cmd); | ||
2046 | |||
2047 | return err; | ||
2048 | } | ||
2049 | |||
2050 | int mgmt_device_found(u16 index, bdaddr_t *bdaddr, u8 *dev_class, s8 rssi, | ||
2051 | u8 *eir) | ||
2052 | { | ||
2053 | struct mgmt_ev_device_found ev; | ||
2054 | |||
2055 | memset(&ev, 0, sizeof(ev)); | ||
2056 | |||
2057 | bacpy(&ev.bdaddr, bdaddr); | ||
2058 | memcpy(ev.dev_class, dev_class, sizeof(ev.dev_class)); | ||
2059 | ev.rssi = rssi; | ||
2060 | |||
2061 | if (eir) | ||
2062 | memcpy(ev.eir, eir, sizeof(ev.eir)); | ||
2063 | |||
2064 | return mgmt_event(MGMT_EV_DEVICE_FOUND, index, &ev, sizeof(ev), NULL); | ||
2065 | } | ||
2066 | |||
2067 | int mgmt_remote_name(u16 index, bdaddr_t *bdaddr, u8 *name) | ||
2068 | { | ||
2069 | struct mgmt_ev_remote_name ev; | ||
2070 | |||
2071 | memset(&ev, 0, sizeof(ev)); | ||
2072 | |||
2073 | bacpy(&ev.bdaddr, bdaddr); | ||
2074 | memcpy(ev.name, name, HCI_MAX_NAME_LENGTH); | ||
2075 | |||
2076 | return mgmt_event(MGMT_EV_REMOTE_NAME, index, &ev, sizeof(ev), NULL); | ||
2077 | } | ||