aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/bluetooth/hci.h1
-rw-r--r--include/net/bluetooth/mgmt.h4
-rw-r--r--net/bluetooth/hci_core.c10
-rw-r--r--net/bluetooth/mgmt.c88
4 files changed, 80 insertions, 23 deletions
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 469f8fdb2f5d..f0c25b5ba4b2 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -80,6 +80,7 @@ enum {
80 HCI_SETUP, 80 HCI_SETUP,
81 HCI_AUTO_OFF, 81 HCI_AUTO_OFF,
82 HCI_MGMT, 82 HCI_MGMT,
83 HCI_PAIRABLE,
83}; 84};
84 85
85/* HCI ioctl defines */ 86/* HCI ioctl defines */
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index f61fd6779ee5..a554802291ed 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -70,6 +70,8 @@ struct mgmt_mode {
70 70
71#define MGMT_OP_SET_CONNECTABLE 0x0007 71#define MGMT_OP_SET_CONNECTABLE 0x0007
72 72
73#define MGMT_OP_SET_PAIRABLE 0x0008
74
73#define MGMT_EV_CMD_COMPLETE 0x0001 75#define MGMT_EV_CMD_COMPLETE 0x0001
74struct mgmt_ev_cmd_complete { 76struct mgmt_ev_cmd_complete {
75 __le16 opcode; 77 __le16 opcode;
@@ -103,3 +105,5 @@ struct mgmt_ev_index_removed {
103#define MGMT_EV_DISCOVERABLE 0x0007 105#define MGMT_EV_DISCOVERABLE 0x0007
104 106
105#define MGMT_EV_CONNECTABLE 0x0008 107#define MGMT_EV_CONNECTABLE 0x0008
108
109#define MGMT_EV_PAIRABLE 0x0009
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index dfc4ef90deca..13eb5a8beb84 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -799,10 +799,17 @@ int hci_get_dev_list(void __user *arg)
799 read_lock_bh(&hci_dev_list_lock); 799 read_lock_bh(&hci_dev_list_lock);
800 list_for_each(p, &hci_dev_list) { 800 list_for_each(p, &hci_dev_list) {
801 struct hci_dev *hdev; 801 struct hci_dev *hdev;
802
802 hdev = list_entry(p, struct hci_dev, list); 803 hdev = list_entry(p, struct hci_dev, list);
804
803 hci_del_off_timer(hdev); 805 hci_del_off_timer(hdev);
806
807 if (!test_bit(HCI_MGMT, &hdev->flags))
808 set_bit(HCI_PAIRABLE, &hdev->flags);
809
804 (dr + n)->dev_id = hdev->id; 810 (dr + n)->dev_id = hdev->id;
805 (dr + n)->dev_opt = hdev->flags; 811 (dr + n)->dev_opt = hdev->flags;
812
806 if (++n >= dev_num) 813 if (++n >= dev_num)
807 break; 814 break;
808 } 815 }
@@ -832,6 +839,9 @@ int hci_get_dev_info(void __user *arg)
832 839
833 hci_del_off_timer(hdev); 840 hci_del_off_timer(hdev);
834 841
842 if (!test_bit(HCI_MGMT, &hdev->flags))
843 set_bit(HCI_PAIRABLE, &hdev->flags);
844
835 strcpy(di.name, hdev->name); 845 strcpy(di.name, hdev->name);
836 di.bdaddr = hdev->bdaddr; 846 di.bdaddr = hdev->bdaddr;
837 di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4); 847 di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 13872ae219c9..d10735076a25 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -481,6 +481,29 @@ failed:
481 return err; 481 return err;
482} 482}
483 483
484static int mgmt_event(u16 event, void *data, u16 data_len, struct sock *skip_sk)
485{
486 struct sk_buff *skb;
487 struct mgmt_hdr *hdr;
488
489 skb = alloc_skb(sizeof(*hdr) + data_len, GFP_ATOMIC);
490 if (!skb)
491 return -ENOMEM;
492
493 bt_cb(skb)->channel = HCI_CHANNEL_CONTROL;
494
495 hdr = (void *) skb_put(skb, sizeof(*hdr));
496 hdr->opcode = cpu_to_le16(event);
497 hdr->len = cpu_to_le16(data_len);
498
499 memcpy(skb_put(skb, data_len), data, data_len);
500
501 hci_send_to_sock(NULL, skb, skip_sk);
502 kfree_skb(skb);
503
504 return 0;
505}
506
484static int send_mode_rsp(struct sock *sk, u16 opcode, u16 index, u8 val) 507static int send_mode_rsp(struct sock *sk, u16 opcode, u16 index, u8 val)
485{ 508{
486 struct mgmt_hdr *hdr; 509 struct mgmt_hdr *hdr;
@@ -509,6 +532,45 @@ static int send_mode_rsp(struct sock *sk, u16 opcode, u16 index, u8 val)
509 return 0; 532 return 0;
510} 533}
511 534
535static int set_pairable(struct sock *sk, unsigned char *data, u16 len)
536{
537 struct mgmt_mode *cp, ev;
538 struct hci_dev *hdev;
539 u16 dev_id;
540 int err;
541
542 cp = (void *) data;
543 dev_id = get_unaligned_le16(&cp->index);
544
545 BT_DBG("request for hci%u", dev_id);
546
547 hdev = hci_dev_get(dev_id);
548 if (!hdev)
549 return cmd_status(sk, MGMT_OP_SET_PAIRABLE, ENODEV);
550
551 hci_dev_lock_bh(hdev);
552
553 if (cp->val)
554 set_bit(HCI_PAIRABLE, &hdev->flags);
555 else
556 clear_bit(HCI_PAIRABLE, &hdev->flags);
557
558 err = send_mode_rsp(sk, MGMT_OP_SET_PAIRABLE, dev_id, cp->val);
559 if (err < 0)
560 goto failed;
561
562 put_unaligned_le16(dev_id, &ev.index);
563 ev.val = cp->val;
564
565 err = mgmt_event(MGMT_EV_PAIRABLE, &ev, sizeof(ev), sk);
566
567failed:
568 hci_dev_unlock_bh(hdev);
569 hci_dev_put(hdev);
570
571 return err;
572}
573
512int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) 574int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
513{ 575{
514 unsigned char *buf; 576 unsigned char *buf;
@@ -558,6 +620,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
558 case MGMT_OP_SET_CONNECTABLE: 620 case MGMT_OP_SET_CONNECTABLE:
559 err = set_connectable(sk, buf + sizeof(*hdr), len); 621 err = set_connectable(sk, buf + sizeof(*hdr), len);
560 break; 622 break;
623 case MGMT_OP_SET_PAIRABLE:
624 err = set_pairable(sk, buf + sizeof(*hdr), len);
625 break;
561 default: 626 default:
562 BT_DBG("Unknown op %u", opcode); 627 BT_DBG("Unknown op %u", opcode);
563 err = cmd_status(sk, opcode, 0x01); 628 err = cmd_status(sk, opcode, 0x01);
@@ -574,29 +639,6 @@ done:
574 return err; 639 return err;
575} 640}
576 641
577static int mgmt_event(u16 event, void *data, u16 data_len, struct sock *skip_sk)
578{
579 struct sk_buff *skb;
580 struct mgmt_hdr *hdr;
581
582 skb = alloc_skb(sizeof(*hdr) + data_len, GFP_ATOMIC);
583 if (!skb)
584 return -ENOMEM;
585
586 bt_cb(skb)->channel = HCI_CHANNEL_CONTROL;
587
588 hdr = (void *) skb_put(skb, sizeof(*hdr));
589 hdr->opcode = cpu_to_le16(event);
590 hdr->len = cpu_to_le16(data_len);
591
592 memcpy(skb_put(skb, data_len), data, data_len);
593
594 hci_send_to_sock(NULL, skb, skip_sk);
595 kfree_skb(skb);
596
597 return 0;
598}
599
600int mgmt_index_added(u16 index) 642int mgmt_index_added(u16 index)
601{ 643{
602 struct mgmt_ev_index_added ev; 644 struct mgmt_ev_index_added ev;