Bluetooth: Add set_io_capability management command
authorJohan Hedberg <johan.hedberg@nokia.com>
Tue, 25 Jan 2011 11:28:33 +0000 (13:28 +0200)
committerGustavo F. Padovan <padovan@profusion.mobi>
Tue, 8 Feb 2011 03:40:08 +0000 (01:40 -0200)
This patch adds a new set_io_capability management command which is used
to set the IO capability for Secure Simple Pairing (SSP) as well as the
Security Manager Protocol (SMP). The value is per hci_dev and each
hci_conn object inherits it upon creation.

Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
include/net/bluetooth/hci.h
include/net/bluetooth/hci_core.h
include/net/bluetooth/mgmt.h
net/bluetooth/hci_conn.c
net/bluetooth/hci_core.c
net/bluetooth/hci_event.c
net/bluetooth/mgmt.c

index e8e52da2b26b3610303fd67c956b166667ed472a..4bee030e4b52a29498fadb8865a550bd32593574 100644 (file)
@@ -402,6 +402,14 @@ struct hci_cp_reject_sync_conn_req {
        __u8     reason;
 } __packed;
 
+#define HCI_OP_IO_CAPABILITY_REPLY     0x042b
+struct hci_cp_io_capability_reply {
+       bdaddr_t bdaddr;
+       __u8     capability;
+       __u8     oob_data;
+       __u8     authentication;
+} __packed;
+
 #define HCI_OP_IO_CAPABILITY_NEG_REPLY 0x0434
 struct hci_cp_io_capability_neg_reply {
        bdaddr_t bdaddr;
index 9ac3da6e4a9a8feac7a8c27e0ad17bbad5702441..6163bff6fa910eb5b5eb9bdd70fbcfc391391e06 100644 (file)
@@ -106,6 +106,7 @@ struct hci_dev {
        __u16           manufacturer;
        __le16          lmp_subver;
        __u16           voice_setting;
+       __u8            io_capability;
 
        __u16           pkt_type;
        __u16           esco_type;
@@ -214,6 +215,7 @@ struct hci_conn {
        __u8             sec_level;
        __u8             pending_sec_level;
        __u8             pin_length;
+       __u8             io_capability;
        __u8             power_save;
        __u16            disc_timeout;
        unsigned long    pend;
index 46fb56d21b59106deefeb520710318e4584eef3b..44ac55c850794ec971b7a820e1186f6052f9bc25 100644 (file)
@@ -154,6 +154,12 @@ struct mgmt_cp_pin_code_neg_reply {
        bdaddr_t bdaddr;
 } __packed;
 
+#define MGMT_OP_SET_IO_CAPABILITY      0x0013
+struct mgmt_cp_set_io_capability {
+       __le16 index;
+       __u8 io_capability;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE           0x0001
 struct mgmt_ev_cmd_complete {
        __le16 opcode;
index 99cd8d9d891b475c57925be6ae54a88240f7adc8..42dc39f25b724c749a838dc514b84650f7f49687 100644 (file)
@@ -234,6 +234,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
        conn->mode  = HCI_CM_ACTIVE;
        conn->state = BT_OPEN;
        conn->auth_type = HCI_AT_GENERAL_BONDING;
+       conn->io_capability = hdev->io_capability;
 
        conn->power_save = 1;
        conn->disc_timeout = HCI_DISCONN_TIMEOUT;
index 8ca8cf147058913acea2187223fe21d653ce9f32..bf6729a53378347b68208b269aa63846b07141f4 100644 (file)
@@ -1084,6 +1084,7 @@ int hci_register_dev(struct hci_dev *hdev)
        hdev->pkt_type  = (HCI_DM1 | HCI_DH1 | HCI_HV1);
        hdev->esco_type = (ESCO_HV1);
        hdev->link_mode = (HCI_LM_ACCEPT);
+       hdev->io_capability = 0x03; /* No Input No Output */
 
        hdev->idle_timeout = 0;
        hdev->sniff_max_interval = 800;
index 98bcf78f2021efdd578dd7dc8dcb76c965b0c9ac..617f58363dbc06a281d168c9ed2501def58f61c5 100644 (file)
@@ -2198,6 +2198,25 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
        hci_dev_unlock(hdev);
 }
 
+static inline u8 hci_get_auth_req(struct hci_conn *conn)
+{
+       /* If remote requests dedicated bonding follow that lead */
+       if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) {
+               /* If both remote and local IO capabilities allow MITM
+                * protection then require it, otherwise don't */
+               if (conn->remote_cap == 0x03 || conn->io_capability == 0x03)
+                       return 0x02;
+               else
+                       return 0x03;
+       }
+
+       /* If remote requests no-bonding follow that lead */
+       if (conn->remote_auth == 0x00 || conn->remote_auth == 0x01)
+               return 0x00;
+
+       return conn->auth_type;
+}
+
 static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
        struct hci_ev_io_capa_request *ev = (void *) skb->data;
@@ -2218,8 +2237,15 @@ static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff
 
        if (test_bit(HCI_PAIRABLE, &hdev->flags) ||
                        (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) {
-               /* FIXME: Do IO capa response based on information
-                * provided through the management interface */
+               struct hci_cp_io_capability_reply cp;
+
+               bacpy(&cp.bdaddr, &ev->bdaddr);
+               cp.capability = conn->io_capability;
+               cp.oob_data = 0;
+               cp.authentication = hci_get_auth_req(conn);
+
+               hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
+                                                       sizeof(cp), &cp);
        } else {
                struct hci_cp_io_capability_neg_reply cp;
 
index 3800aaf5792d8797770dc2d9bd62ca44c2c95e10..b2bda83050a490e71eb9e1d6f893fdcd1ff2a8a7 100644 (file)
@@ -1016,6 +1016,35 @@ failed:
        return err;
 }
 
+static int set_io_capability(struct sock *sk, unsigned char *data, u16 len)
+{
+       struct hci_dev *hdev;
+       struct mgmt_cp_set_io_capability *cp;
+       u16 dev_id;
+
+       BT_DBG("");
+
+       cp = (void *) data;
+       dev_id = get_unaligned_le16(&cp->index);
+
+       hdev = hci_dev_get(dev_id);
+       if (!hdev)
+               return cmd_status(sk, MGMT_OP_SET_IO_CAPABILITY, ENODEV);
+
+       hci_dev_lock_bh(hdev);
+
+       hdev->io_capability = cp->io_capability;
+
+       BT_DBG("%s IO capability set to 0x%02x", hdev->name,
+                                               hdev->io_capability);
+
+       hci_dev_unlock_bh(hdev);
+       hci_dev_put(hdev);
+
+       return cmd_complete(sk, MGMT_OP_SET_IO_CAPABILITY,
+                                               &dev_id, sizeof(dev_id));
+}
+
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 {
        unsigned char *buf;
@@ -1098,6 +1127,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
        case MGMT_OP_PIN_CODE_NEG_REPLY:
                err = pin_code_neg_reply(sk, buf + sizeof(*hdr), len);
                break;
+       case MGMT_OP_SET_IO_CAPABILITY:
+               err = set_io_capability(sk, buf + sizeof(*hdr), len);
+               break;
        default:
                BT_DBG("Unknown op %u", opcode);
                err = cmd_status(sk, opcode, 0x01);