aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2011-04-27 10:29:56 -0400
committerGustavo F. Padovan <padovan@profusion.mobi>2011-04-28 00:10:03 -0400
commit14a53664138a8407382745bb470045d1817b7801 (patch)
tree9a731741ee34c1d7ea5abdd290bc27cd45277753 /net
parentcf2f90f59bbf2c2a539d171cde6e1dfe72048555 (diff)
Bluetooth: Add basic discovery commands to the management interface
This patch adds start_discovery and stop_discovery commands to the management interface. Right now their implementation is fairly simplistic and the parameters are fixed to what user space has defaulted to so far. This is the very initial phase for discovery implementation into the kernel. Next steps include name resolution, LE scanning and bdaddr type handling. Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com> Signed-off-by: Anderson Briglia <anderson.briglia@openbossa.org> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/mgmt.c76
1 files changed, 75 insertions, 1 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c304688252b8..dbc248f27b1b 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1569,6 +1569,75 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
1569 return err; 1569 return err;
1570} 1570}
1571 1571
1572static int start_discovery(struct sock *sk, u16 index)
1573{
1574 u8 lap[3] = { 0x33, 0x8b, 0x9e };
1575 struct hci_cp_inquiry cp;
1576 struct pending_cmd *cmd;
1577 struct hci_dev *hdev;
1578 int err;
1579
1580 BT_DBG("hci%u", index);
1581
1582 hdev = hci_dev_get(index);
1583 if (!hdev)
1584 return cmd_status(sk, index, MGMT_OP_START_DISCOVERY, ENODEV);
1585
1586 hci_dev_lock_bh(hdev);
1587
1588 cmd = mgmt_pending_add(sk, MGMT_OP_START_DISCOVERY, index, NULL, 0);
1589 if (!cmd) {
1590 err = -ENOMEM;
1591 goto failed;
1592 }
1593
1594 memset(&cp, 0, sizeof(cp));
1595 memcpy(&cp.lap, lap, 3);
1596 cp.length = 0x08;
1597 cp.num_rsp = 0x00;
1598
1599 err = hci_send_cmd(hdev, HCI_OP_INQUIRY, sizeof(cp), &cp);
1600 if (err < 0)
1601 mgmt_pending_remove(cmd);
1602
1603failed:
1604 hci_dev_unlock_bh(hdev);
1605 hci_dev_put(hdev);
1606
1607 return err;
1608}
1609
1610static int stop_discovery(struct sock *sk, u16 index)
1611{
1612 struct hci_dev *hdev;
1613 struct pending_cmd *cmd;
1614 int err;
1615
1616 BT_DBG("hci%u", index);
1617
1618 hdev = hci_dev_get(index);
1619 if (!hdev)
1620 return cmd_status(sk, index, MGMT_OP_STOP_DISCOVERY, ENODEV);
1621
1622 hci_dev_lock_bh(hdev);
1623
1624 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, index, NULL, 0);
1625 if (!cmd) {
1626 err = -ENOMEM;
1627 goto failed;
1628 }
1629
1630 err = hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
1631 if (err < 0)
1632 mgmt_pending_remove(cmd);
1633
1634failed:
1635 hci_dev_unlock_bh(hdev);
1636 hci_dev_put(hdev);
1637
1638 return err;
1639}
1640
1572int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) 1641int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
1573{ 1642{
1574 unsigned char *buf; 1643 unsigned char *buf;
@@ -1677,7 +1746,12 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
1677 err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr), 1746 err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr),
1678 len); 1747 len);
1679 break; 1748 break;
1680 1749 case MGMT_OP_START_DISCOVERY:
1750 err = start_discovery(sk, index);
1751 break;
1752 case MGMT_OP_STOP_DISCOVERY:
1753 err = stop_discovery(sk, index);
1754 break;
1681 default: 1755 default:
1682 BT_DBG("Unknown op %u", opcode); 1756 BT_DBG("Unknown op %u", opcode);
1683 err = cmd_status(sk, index, opcode, 0x01); 1757 err = cmd_status(sk, index, opcode, 0x01);