aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2011-01-26 06:11:03 -0500
committerGustavo F. Padovan <padovan@profusion.mobi>2011-02-07 22:40:05 -0500
commitc542a06c29acbf4ea0024884a198065a10613147 (patch)
tree0e680582a90e9384364a9c6f4dc2c475339a472e /net/bluetooth/mgmt.c
parent053f0211d3b1a991f06a7b4aec5b762e42d7c6a4 (diff)
Bluetooth: Implement set_pairable managment command
This patch implements a new set_pairable management command to control the pairable state of local adapters. The state is represented using a new HCI_PAIRABLE flag in the hci_dev struct. For backwards compatibility with older user space versions the HCI_PAIRABLE flag gets automatically set when the existence of an adapter is reported to user space through legacy methods and the HCI_MGMT flag is not set. Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r--net/bluetooth/mgmt.c88
1 files changed, 65 insertions, 23 deletions
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;