Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 237312
b: refs/heads/master
c: c542a06
h: refs/heads/master
v: v3
  • Loading branch information
Johan Hedberg authored and Gustavo F. Padovan committed Feb 8, 2011
1 parent c9406ba commit 6022525
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 24 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 053f0211d3b1a991f06a7b4aec5b762e42d7c6a4
refs/heads/master: c542a06c29acbf4ea0024884a198065a10613147
1 change: 1 addition & 0 deletions trunk/include/net/bluetooth/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum {
HCI_SETUP,
HCI_AUTO_OFF,
HCI_MGMT,
HCI_PAIRABLE,
};

/* HCI ioctl defines */
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/net/bluetooth/mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct mgmt_mode {

#define MGMT_OP_SET_CONNECTABLE 0x0007

#define MGMT_OP_SET_PAIRABLE 0x0008

#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
Expand Down Expand Up @@ -103,3 +105,5 @@ struct mgmt_ev_index_removed {
#define MGMT_EV_DISCOVERABLE 0x0007

#define MGMT_EV_CONNECTABLE 0x0008

#define MGMT_EV_PAIRABLE 0x0009
10 changes: 10 additions & 0 deletions trunk/net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,10 +799,17 @@ int hci_get_dev_list(void __user *arg)
read_lock_bh(&hci_dev_list_lock);
list_for_each(p, &hci_dev_list) {
struct hci_dev *hdev;

hdev = list_entry(p, struct hci_dev, list);

hci_del_off_timer(hdev);

if (!test_bit(HCI_MGMT, &hdev->flags))
set_bit(HCI_PAIRABLE, &hdev->flags);

(dr + n)->dev_id = hdev->id;
(dr + n)->dev_opt = hdev->flags;

if (++n >= dev_num)
break;
}
Expand Down Expand Up @@ -832,6 +839,9 @@ int hci_get_dev_info(void __user *arg)

hci_del_off_timer(hdev);

if (!test_bit(HCI_MGMT, &hdev->flags))
set_bit(HCI_PAIRABLE, &hdev->flags);

strcpy(di.name, hdev->name);
di.bdaddr = hdev->bdaddr;
di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4);
Expand Down
88 changes: 65 additions & 23 deletions trunk/net/bluetooth/mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,29 @@ static int set_connectable(struct sock *sk, unsigned char *data, u16 len)
return err;
}

static int mgmt_event(u16 event, void *data, u16 data_len, struct sock *skip_sk)
{
struct sk_buff *skb;
struct mgmt_hdr *hdr;

skb = alloc_skb(sizeof(*hdr) + data_len, GFP_ATOMIC);
if (!skb)
return -ENOMEM;

bt_cb(skb)->channel = HCI_CHANNEL_CONTROL;

hdr = (void *) skb_put(skb, sizeof(*hdr));
hdr->opcode = cpu_to_le16(event);
hdr->len = cpu_to_le16(data_len);

memcpy(skb_put(skb, data_len), data, data_len);

hci_send_to_sock(NULL, skb, skip_sk);
kfree_skb(skb);

return 0;
}

static int send_mode_rsp(struct sock *sk, u16 opcode, u16 index, u8 val)
{
struct mgmt_hdr *hdr;
Expand Down Expand Up @@ -509,6 +532,45 @@ static int send_mode_rsp(struct sock *sk, u16 opcode, u16 index, u8 val)
return 0;
}

static int set_pairable(struct sock *sk, unsigned char *data, u16 len)
{
struct mgmt_mode *cp, ev;
struct hci_dev *hdev;
u16 dev_id;
int err;

cp = (void *) data;
dev_id = get_unaligned_le16(&cp->index);

BT_DBG("request for hci%u", dev_id);

hdev = hci_dev_get(dev_id);
if (!hdev)
return cmd_status(sk, MGMT_OP_SET_PAIRABLE, ENODEV);

hci_dev_lock_bh(hdev);

if (cp->val)
set_bit(HCI_PAIRABLE, &hdev->flags);
else
clear_bit(HCI_PAIRABLE, &hdev->flags);

err = send_mode_rsp(sk, MGMT_OP_SET_PAIRABLE, dev_id, cp->val);
if (err < 0)
goto failed;

put_unaligned_le16(dev_id, &ev.index);
ev.val = cp->val;

err = mgmt_event(MGMT_EV_PAIRABLE, &ev, sizeof(ev), sk);

failed:
hci_dev_unlock_bh(hdev);
hci_dev_put(hdev);

return err;
}

int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
{
unsigned char *buf;
Expand Down Expand Up @@ -558,6 +620,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
case MGMT_OP_SET_CONNECTABLE:
err = set_connectable(sk, buf + sizeof(*hdr), len);
break;
case MGMT_OP_SET_PAIRABLE:
err = set_pairable(sk, buf + sizeof(*hdr), len);
break;
default:
BT_DBG("Unknown op %u", opcode);
err = cmd_status(sk, opcode, 0x01);
Expand All @@ -574,29 +639,6 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
return err;
}

static int mgmt_event(u16 event, void *data, u16 data_len, struct sock *skip_sk)
{
struct sk_buff *skb;
struct mgmt_hdr *hdr;

skb = alloc_skb(sizeof(*hdr) + data_len, GFP_ATOMIC);
if (!skb)
return -ENOMEM;

bt_cb(skb)->channel = HCI_CHANNEL_CONTROL;

hdr = (void *) skb_put(skb, sizeof(*hdr));
hdr->opcode = cpu_to_le16(event);
hdr->len = cpu_to_le16(data_len);

memcpy(skb_put(skb, data_len), data, data_len);

hci_send_to_sock(NULL, skb, skip_sk);
kfree_skb(skb);

return 0;
}

int mgmt_index_added(u16 index)
{
struct mgmt_ev_index_added ev;
Expand Down

0 comments on commit 6022525

Please sign in to comment.