Skip to content

Commit 17fa4b9

Browse files
Johan HedbergGustavo F. Padovan
authored andcommitted
Bluetooth: Add set_io_capability management command
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>
1 parent 980e1a5 commit 17fa4b9

7 files changed

Lines changed: 78 additions & 2 deletions

File tree

‎include/net/bluetooth/hci.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@ struct hci_cp_reject_sync_conn_req {
402402
__u8 reason;
403403
} __packed;
404404

405+
#define HCI_OP_IO_CAPABILITY_REPLY 0x042b
406+
struct hci_cp_io_capability_reply {
407+
bdaddr_t bdaddr;
408+
__u8 capability;
409+
__u8 oob_data;
410+
__u8 authentication;
411+
} __packed;
412+
405413
#define HCI_OP_IO_CAPABILITY_NEG_REPLY 0x0434
406414
struct hci_cp_io_capability_neg_reply {
407415
bdaddr_t bdaddr;

‎include/net/bluetooth/hci_core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct hci_dev {
106106
__u16 manufacturer;
107107
__le16 lmp_subver;
108108
__u16 voice_setting;
109+
__u8 io_capability;
109110

110111
__u16 pkt_type;
111112
__u16 esco_type;
@@ -214,6 +215,7 @@ struct hci_conn {
214215
__u8 sec_level;
215216
__u8 pending_sec_level;
216217
__u8 pin_length;
218+
__u8 io_capability;
217219
__u8 power_save;
218220
__u16 disc_timeout;
219221
unsigned long pend;

‎include/net/bluetooth/mgmt.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ struct mgmt_cp_pin_code_neg_reply {
154154
bdaddr_t bdaddr;
155155
} __packed;
156156

157+
#define MGMT_OP_SET_IO_CAPABILITY 0x0013
158+
struct mgmt_cp_set_io_capability {
159+
__le16 index;
160+
__u8 io_capability;
161+
} __packed;
162+
157163
#define MGMT_EV_CMD_COMPLETE 0x0001
158164
struct mgmt_ev_cmd_complete {
159165
__le16 opcode;

‎net/bluetooth/hci_conn.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
234234
conn->mode = HCI_CM_ACTIVE;
235235
conn->state = BT_OPEN;
236236
conn->auth_type = HCI_AT_GENERAL_BONDING;
237+
conn->io_capability = hdev->io_capability;
237238

238239
conn->power_save = 1;
239240
conn->disc_timeout = HCI_DISCONN_TIMEOUT;

‎net/bluetooth/hci_core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ int hci_register_dev(struct hci_dev *hdev)
10841084
hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1);
10851085
hdev->esco_type = (ESCO_HV1);
10861086
hdev->link_mode = (HCI_LM_ACCEPT);
1087+
hdev->io_capability = 0x03; /* No Input No Output */
10871088

10881089
hdev->idle_timeout = 0;
10891090
hdev->sniff_max_interval = 800;

‎net/bluetooth/hci_event.c‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,25 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
21982198
hci_dev_unlock(hdev);
21992199
}
22002200

2201+
static inline u8 hci_get_auth_req(struct hci_conn *conn)
2202+
{
2203+
/* If remote requests dedicated bonding follow that lead */
2204+
if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) {
2205+
/* If both remote and local IO capabilities allow MITM
2206+
* protection then require it, otherwise don't */
2207+
if (conn->remote_cap == 0x03 || conn->io_capability == 0x03)
2208+
return 0x02;
2209+
else
2210+
return 0x03;
2211+
}
2212+
2213+
/* If remote requests no-bonding follow that lead */
2214+
if (conn->remote_auth == 0x00 || conn->remote_auth == 0x01)
2215+
return 0x00;
2216+
2217+
return conn->auth_type;
2218+
}
2219+
22012220
static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
22022221
{
22032222
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
22182237

22192238
if (test_bit(HCI_PAIRABLE, &hdev->flags) ||
22202239
(conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) {
2221-
/* FIXME: Do IO capa response based on information
2222-
* provided through the management interface */
2240+
struct hci_cp_io_capability_reply cp;
2241+
2242+
bacpy(&cp.bdaddr, &ev->bdaddr);
2243+
cp.capability = conn->io_capability;
2244+
cp.oob_data = 0;
2245+
cp.authentication = hci_get_auth_req(conn);
2246+
2247+
hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
2248+
sizeof(cp), &cp);
22232249
} else {
22242250
struct hci_cp_io_capability_neg_reply cp;
22252251

‎net/bluetooth/mgmt.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,35 @@ static int pin_code_neg_reply(struct sock *sk, unsigned char *data, u16 len)
10161016
return err;
10171017
}
10181018

1019+
static int set_io_capability(struct sock *sk, unsigned char *data, u16 len)
1020+
{
1021+
struct hci_dev *hdev;
1022+
struct mgmt_cp_set_io_capability *cp;
1023+
u16 dev_id;
1024+
1025+
BT_DBG("");
1026+
1027+
cp = (void *) data;
1028+
dev_id = get_unaligned_le16(&cp->index);
1029+
1030+
hdev = hci_dev_get(dev_id);
1031+
if (!hdev)
1032+
return cmd_status(sk, MGMT_OP_SET_IO_CAPABILITY, ENODEV);
1033+
1034+
hci_dev_lock_bh(hdev);
1035+
1036+
hdev->io_capability = cp->io_capability;
1037+
1038+
BT_DBG("%s IO capability set to 0x%02x", hdev->name,
1039+
hdev->io_capability);
1040+
1041+
hci_dev_unlock_bh(hdev);
1042+
hci_dev_put(hdev);
1043+
1044+
return cmd_complete(sk, MGMT_OP_SET_IO_CAPABILITY,
1045+
&dev_id, sizeof(dev_id));
1046+
}
1047+
10191048
int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
10201049
{
10211050
unsigned char *buf;
@@ -1098,6 +1127,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
10981127
case MGMT_OP_PIN_CODE_NEG_REPLY:
10991128
err = pin_code_neg_reply(sk, buf + sizeof(*hdr), len);
11001129
break;
1130+
case MGMT_OP_SET_IO_CAPABILITY:
1131+
err = set_io_capability(sk, buf + sizeof(*hdr), len);
1132+
break;
11011133
default:
11021134
BT_DBG("Unknown op %u", opcode);
11031135
err = cmd_status(sk, opcode, 0x01);

0 commit comments

Comments
 (0)