aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-10-20 07:33:56 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-22 05:59:40 -0400
commita9de9248064bfc8eb0a183a6a951a4e7b5ca10a4 (patch)
tree4934b99543a9ae0f0282a7f366a8b765c6fb1a08 /net
parent55b70a0300b873c0ec7ea6e33752af56f41250ce (diff)
[Bluetooth] Switch from OGF+OCF to using only opcodes
The Bluetooth HCI commands are divided into logical OGF groups for easier identification of their purposes. While this still makes sense for the written specification, its makes the code only more complex and harder to read. So instead of using separate OGF and OCF values to identify the commands, use a common 16-bit opcode that combines both values. As a side effect this also reduces the complexity of OGF and OCF calculations during command header parsing. Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/hci_conn.c43
-rw-r--r--net/bluetooth/hci_core.c48
-rw-r--r--net/bluetooth/hci_event.c1598
-rw-r--r--net/bluetooth/hci_sock.c2
-rw-r--r--net/bluetooth/hci_sysfs.c37
5 files changed, 954 insertions, 774 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 5fdfc9a67d39..797a30bec6fd 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -82,7 +82,7 @@ void hci_acl_connect(struct hci_conn *conn)
82 else 82 else
83 cp.role_switch = 0x00; 83 cp.role_switch = 0x00;
84 84
85 hci_send_cmd(hdev, OGF_LINK_CTL, OCF_CREATE_CONN, sizeof(cp), &cp); 85 hci_send_cmd(hdev, HCI_OP_CREATE_CONN, sizeof(cp), &cp);
86} 86}
87 87
88static void hci_acl_connect_cancel(struct hci_conn *conn) 88static void hci_acl_connect_cancel(struct hci_conn *conn)
@@ -95,8 +95,7 @@ static void hci_acl_connect_cancel(struct hci_conn *conn)
95 return; 95 return;
96 96
97 bacpy(&cp.bdaddr, &conn->dst); 97 bacpy(&cp.bdaddr, &conn->dst);
98 hci_send_cmd(conn->hdev, OGF_LINK_CTL, 98 hci_send_cmd(conn->hdev, HCI_OP_CREATE_CONN_CANCEL, sizeof(cp), &cp);
99 OCF_CREATE_CONN_CANCEL, sizeof(cp), &cp);
100} 99}
101 100
102void hci_acl_disconn(struct hci_conn *conn, __u8 reason) 101void hci_acl_disconn(struct hci_conn *conn, __u8 reason)
@@ -109,8 +108,7 @@ void hci_acl_disconn(struct hci_conn *conn, __u8 reason)
109 108
110 cp.handle = cpu_to_le16(conn->handle); 109 cp.handle = cpu_to_le16(conn->handle);
111 cp.reason = reason; 110 cp.reason = reason;
112 hci_send_cmd(conn->hdev, OGF_LINK_CTL, 111 hci_send_cmd(conn->hdev, HCI_OP_DISCONNECT, sizeof(cp), &cp);
113 OCF_DISCONNECT, sizeof(cp), &cp);
114} 112}
115 113
116void hci_add_sco(struct hci_conn *conn, __u16 handle) 114void hci_add_sco(struct hci_conn *conn, __u16 handle)
@@ -126,7 +124,7 @@ void hci_add_sco(struct hci_conn *conn, __u16 handle)
126 cp.handle = cpu_to_le16(handle); 124 cp.handle = cpu_to_le16(handle);
127 cp.pkt_type = cpu_to_le16(hdev->pkt_type & SCO_PTYPE_MASK); 125 cp.pkt_type = cpu_to_le16(hdev->pkt_type & SCO_PTYPE_MASK);
128 126
129 hci_send_cmd(hdev, OGF_LINK_CTL, OCF_ADD_SCO, sizeof(cp), &cp); 127 hci_send_cmd(hdev, HCI_OP_ADD_SCO, sizeof(cp), &cp);
130} 128}
131 129
132static void hci_conn_timeout(unsigned long arg) 130static void hci_conn_timeout(unsigned long arg)
@@ -348,7 +346,7 @@ int hci_conn_auth(struct hci_conn *conn)
348 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->pend)) { 346 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->pend)) {
349 struct hci_cp_auth_requested cp; 347 struct hci_cp_auth_requested cp;
350 cp.handle = cpu_to_le16(conn->handle); 348 cp.handle = cpu_to_le16(conn->handle);
351 hci_send_cmd(conn->hdev, OGF_LINK_CTL, OCF_AUTH_REQUESTED, sizeof(cp), &cp); 349 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
352 } 350 }
353 return 0; 351 return 0;
354} 352}
@@ -369,7 +367,7 @@ int hci_conn_encrypt(struct hci_conn *conn)
369 struct hci_cp_set_conn_encrypt cp; 367 struct hci_cp_set_conn_encrypt cp;
370 cp.handle = cpu_to_le16(conn->handle); 368 cp.handle = cpu_to_le16(conn->handle);
371 cp.encrypt = 1; 369 cp.encrypt = 1;
372 hci_send_cmd(conn->hdev, OGF_LINK_CTL, OCF_SET_CONN_ENCRYPT, sizeof(cp), &cp); 370 hci_send_cmd(conn->hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), &cp);
373 } 371 }
374 return 0; 372 return 0;
375} 373}
@@ -383,7 +381,7 @@ int hci_conn_change_link_key(struct hci_conn *conn)
383 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->pend)) { 381 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->pend)) {
384 struct hci_cp_change_conn_link_key cp; 382 struct hci_cp_change_conn_link_key cp;
385 cp.handle = cpu_to_le16(conn->handle); 383 cp.handle = cpu_to_le16(conn->handle);
386 hci_send_cmd(conn->hdev, OGF_LINK_CTL, OCF_CHANGE_CONN_LINK_KEY, sizeof(cp), &cp); 384 hci_send_cmd(conn->hdev, HCI_OP_CHANGE_CONN_LINK_KEY, sizeof(cp), &cp);
387 } 385 }
388 return 0; 386 return 0;
389} 387}
@@ -401,7 +399,7 @@ int hci_conn_switch_role(struct hci_conn *conn, uint8_t role)
401 struct hci_cp_switch_role cp; 399 struct hci_cp_switch_role cp;
402 bacpy(&cp.bdaddr, &conn->dst); 400 bacpy(&cp.bdaddr, &conn->dst);
403 cp.role = role; 401 cp.role = role;
404 hci_send_cmd(conn->hdev, OGF_LINK_POLICY, OCF_SWITCH_ROLE, sizeof(cp), &cp); 402 hci_send_cmd(conn->hdev, HCI_OP_SWITCH_ROLE, sizeof(cp), &cp);
405 } 403 }
406 return 0; 404 return 0;
407} 405}
@@ -423,8 +421,7 @@ void hci_conn_enter_active_mode(struct hci_conn *conn)
423 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) { 421 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) {
424 struct hci_cp_exit_sniff_mode cp; 422 struct hci_cp_exit_sniff_mode cp;
425 cp.handle = cpu_to_le16(conn->handle); 423 cp.handle = cpu_to_le16(conn->handle);
426 hci_send_cmd(hdev, OGF_LINK_POLICY, 424 hci_send_cmd(hdev, HCI_OP_EXIT_SNIFF_MODE, sizeof(cp), &cp);
427 OCF_EXIT_SNIFF_MODE, sizeof(cp), &cp);
428 } 425 }
429 426
430timer: 427timer:
@@ -455,8 +452,7 @@ void hci_conn_enter_sniff_mode(struct hci_conn *conn)
455 cp.max_latency = cpu_to_le16(0); 452 cp.max_latency = cpu_to_le16(0);
456 cp.min_remote_timeout = cpu_to_le16(0); 453 cp.min_remote_timeout = cpu_to_le16(0);
457 cp.min_local_timeout = cpu_to_le16(0); 454 cp.min_local_timeout = cpu_to_le16(0);
458 hci_send_cmd(hdev, OGF_LINK_POLICY, 455 hci_send_cmd(hdev, HCI_OP_SNIFF_SUBRATE, sizeof(cp), &cp);
459 OCF_SNIFF_SUBRATE, sizeof(cp), &cp);
460 } 456 }
461 457
462 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) { 458 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) {
@@ -466,8 +462,7 @@ void hci_conn_enter_sniff_mode(struct hci_conn *conn)
466 cp.min_interval = cpu_to_le16(hdev->sniff_min_interval); 462 cp.min_interval = cpu_to_le16(hdev->sniff_min_interval);
467 cp.attempt = cpu_to_le16(4); 463 cp.attempt = cpu_to_le16(4);
468 cp.timeout = cpu_to_le16(1); 464 cp.timeout = cpu_to_le16(1);
469 hci_send_cmd(hdev, OGF_LINK_POLICY, 465 hci_send_cmd(hdev, HCI_OP_SNIFF_MODE, sizeof(cp), &cp);
470 OCF_SNIFF_MODE, sizeof(cp), &cp);
471 } 466 }
472} 467}
473 468
@@ -493,6 +488,22 @@ void hci_conn_hash_flush(struct hci_dev *hdev)
493 } 488 }
494} 489}
495 490
491/* Check pending connect attempts */
492void hci_conn_check_pending(struct hci_dev *hdev)
493{
494 struct hci_conn *conn;
495
496 BT_DBG("hdev %s", hdev->name);
497
498 hci_dev_lock(hdev);
499
500 conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2);
501 if (conn)
502 hci_acl_connect(conn);
503
504 hci_dev_unlock(hdev);
505}
506
496int hci_get_conn_list(void __user *arg) 507int hci_get_conn_list(void __user *arg)
497{ 508{
498 struct hci_conn_list_req req, *cl; 509 struct hci_conn_list_req req, *cl;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 18e3afc964df..2894382dd26d 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -176,7 +176,7 @@ static void hci_reset_req(struct hci_dev *hdev, unsigned long opt)
176 BT_DBG("%s %ld", hdev->name, opt); 176 BT_DBG("%s %ld", hdev->name, opt);
177 177
178 /* Reset device */ 178 /* Reset device */
179 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_RESET, 0, NULL); 179 hci_send_cmd(hdev, HCI_OP_RESET, 0, NULL);
180} 180}
181 181
182static void hci_init_req(struct hci_dev *hdev, unsigned long opt) 182static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
@@ -202,16 +202,16 @@ static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
202 202
203 /* Reset */ 203 /* Reset */
204 if (test_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks)) 204 if (test_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks))
205 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_RESET, 0, NULL); 205 hci_send_cmd(hdev, HCI_OP_RESET, 0, NULL);
206 206
207 /* Read Local Supported Features */ 207 /* Read Local Supported Features */
208 hci_send_cmd(hdev, OGF_INFO_PARAM, OCF_READ_LOCAL_FEATURES, 0, NULL); 208 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_FEATURES, 0, NULL);
209 209
210 /* Read Local Version */ 210 /* Read Local Version */
211 hci_send_cmd(hdev, OGF_INFO_PARAM, OCF_READ_LOCAL_VERSION, 0, NULL); 211 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL);
212 212
213 /* Read Buffer Size (ACL mtu, max pkt, etc.) */ 213 /* Read Buffer Size (ACL mtu, max pkt, etc.) */
214 hci_send_cmd(hdev, OGF_INFO_PARAM, OCF_READ_BUFFER_SIZE, 0, NULL); 214 hci_send_cmd(hdev, HCI_OP_READ_BUFFER_SIZE, 0, NULL);
215 215
216#if 0 216#if 0
217 /* Host buffer size */ 217 /* Host buffer size */
@@ -221,29 +221,35 @@ static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
221 cp.sco_mtu = HCI_MAX_SCO_SIZE; 221 cp.sco_mtu = HCI_MAX_SCO_SIZE;
222 cp.acl_max_pkt = cpu_to_le16(0xffff); 222 cp.acl_max_pkt = cpu_to_le16(0xffff);
223 cp.sco_max_pkt = cpu_to_le16(0xffff); 223 cp.sco_max_pkt = cpu_to_le16(0xffff);
224 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_HOST_BUFFER_SIZE, sizeof(cp), &cp); 224 hci_send_cmd(hdev, HCI_OP_HOST_BUFFER_SIZE, sizeof(cp), &cp);
225 } 225 }
226#endif 226#endif
227 227
228 /* Read BD Address */ 228 /* Read BD Address */
229 hci_send_cmd(hdev, OGF_INFO_PARAM, OCF_READ_BD_ADDR, 0, NULL); 229 hci_send_cmd(hdev, HCI_OP_READ_BD_ADDR, 0, NULL);
230
231 /* Read Class of Device */
232 hci_send_cmd(hdev, HCI_OP_READ_CLASS_OF_DEV, 0, NULL);
233
234 /* Read Local Name */
235 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL);
230 236
231 /* Read Voice Setting */ 237 /* Read Voice Setting */
232 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_READ_VOICE_SETTING, 0, NULL); 238 hci_send_cmd(hdev, HCI_OP_READ_VOICE_SETTING, 0, NULL);
233 239
234 /* Optional initialization */ 240 /* Optional initialization */
235 241
236 /* Clear Event Filters */ 242 /* Clear Event Filters */
237 flt_type = HCI_FLT_CLEAR_ALL; 243 flt_type = HCI_FLT_CLEAR_ALL;
238 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_SET_EVENT_FLT, 1, &flt_type); 244 hci_send_cmd(hdev, HCI_OP_SET_EVENT_FLT, 1, &flt_type);
239 245
240 /* Page timeout ~20 secs */ 246 /* Page timeout ~20 secs */
241 param = cpu_to_le16(0x8000); 247 param = cpu_to_le16(0x8000);
242 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_WRITE_PG_TIMEOUT, 2, &param); 248 hci_send_cmd(hdev, HCI_OP_WRITE_PG_TIMEOUT, 2, &param);
243 249
244 /* Connection accept timeout ~20 secs */ 250 /* Connection accept timeout ~20 secs */
245 param = cpu_to_le16(0x7d00); 251 param = cpu_to_le16(0x7d00);
246 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_WRITE_CA_TIMEOUT, 2, &param); 252 hci_send_cmd(hdev, HCI_OP_WRITE_CA_TIMEOUT, 2, &param);
247} 253}
248 254
249static void hci_scan_req(struct hci_dev *hdev, unsigned long opt) 255static void hci_scan_req(struct hci_dev *hdev, unsigned long opt)
@@ -253,7 +259,7 @@ static void hci_scan_req(struct hci_dev *hdev, unsigned long opt)
253 BT_DBG("%s %x", hdev->name, scan); 259 BT_DBG("%s %x", hdev->name, scan);
254 260
255 /* Inquiry and Page scans */ 261 /* Inquiry and Page scans */
256 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE, 1, &scan); 262 hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
257} 263}
258 264
259static void hci_auth_req(struct hci_dev *hdev, unsigned long opt) 265static void hci_auth_req(struct hci_dev *hdev, unsigned long opt)
@@ -263,7 +269,7 @@ static void hci_auth_req(struct hci_dev *hdev, unsigned long opt)
263 BT_DBG("%s %x", hdev->name, auth); 269 BT_DBG("%s %x", hdev->name, auth);
264 270
265 /* Authentication */ 271 /* Authentication */
266 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_WRITE_AUTH_ENABLE, 1, &auth); 272 hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, 1, &auth);
267} 273}
268 274
269static void hci_encrypt_req(struct hci_dev *hdev, unsigned long opt) 275static void hci_encrypt_req(struct hci_dev *hdev, unsigned long opt)
@@ -273,7 +279,7 @@ static void hci_encrypt_req(struct hci_dev *hdev, unsigned long opt)
273 BT_DBG("%s %x", hdev->name, encrypt); 279 BT_DBG("%s %x", hdev->name, encrypt);
274 280
275 /* Authentication */ 281 /* Authentication */
276 hci_send_cmd(hdev, OGF_HOST_CTL, OCF_WRITE_ENCRYPT_MODE, 1, &encrypt); 282 hci_send_cmd(hdev, HCI_OP_WRITE_ENCRYPT_MODE, 1, &encrypt);
277} 283}
278 284
279/* Get HCI device by index. 285/* Get HCI device by index.
@@ -384,7 +390,7 @@ static void hci_inq_req(struct hci_dev *hdev, unsigned long opt)
384 memcpy(&cp.lap, &ir->lap, 3); 390 memcpy(&cp.lap, &ir->lap, 3);
385 cp.length = ir->length; 391 cp.length = ir->length;
386 cp.num_rsp = ir->num_rsp; 392 cp.num_rsp = ir->num_rsp;
387 hci_send_cmd(hdev, OGF_LINK_CTL, OCF_INQUIRY, sizeof(cp), &cp); 393 hci_send_cmd(hdev, HCI_OP_INQUIRY, sizeof(cp), &cp);
388} 394}
389 395
390int hci_inquiry(void __user *arg) 396int hci_inquiry(void __user *arg)
@@ -1111,13 +1117,13 @@ static int hci_send_frame(struct sk_buff *skb)
1111} 1117}
1112 1118
1113/* Send HCI command */ 1119/* Send HCI command */
1114int hci_send_cmd(struct hci_dev *hdev, __u16 ogf, __u16 ocf, __u32 plen, void *param) 1120int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param)
1115{ 1121{
1116 int len = HCI_COMMAND_HDR_SIZE + plen; 1122 int len = HCI_COMMAND_HDR_SIZE + plen;
1117 struct hci_command_hdr *hdr; 1123 struct hci_command_hdr *hdr;
1118 struct sk_buff *skb; 1124 struct sk_buff *skb;
1119 1125
1120 BT_DBG("%s ogf 0x%x ocf 0x%x plen %d", hdev->name, ogf, ocf, plen); 1126 BT_DBG("%s opcode 0x%x plen %d", hdev->name, opcode, plen);
1121 1127
1122 skb = bt_skb_alloc(len, GFP_ATOMIC); 1128 skb = bt_skb_alloc(len, GFP_ATOMIC);
1123 if (!skb) { 1129 if (!skb) {
@@ -1126,7 +1132,7 @@ int hci_send_cmd(struct hci_dev *hdev, __u16 ogf, __u16 ocf, __u32 plen, void *p
1126 } 1132 }
1127 1133
1128 hdr = (struct hci_command_hdr *) skb_put(skb, HCI_COMMAND_HDR_SIZE); 1134 hdr = (struct hci_command_hdr *) skb_put(skb, HCI_COMMAND_HDR_SIZE);
1129 hdr->opcode = cpu_to_le16(hci_opcode_pack(ogf, ocf)); 1135 hdr->opcode = cpu_to_le16(opcode);
1130 hdr->plen = plen; 1136 hdr->plen = plen;
1131 1137
1132 if (plen) 1138 if (plen)
@@ -1143,7 +1149,7 @@ int hci_send_cmd(struct hci_dev *hdev, __u16 ogf, __u16 ocf, __u32 plen, void *p
1143} 1149}
1144 1150
1145/* Get data from the previously sent command */ 1151/* Get data from the previously sent command */
1146void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 ogf, __u16 ocf) 1152void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode)
1147{ 1153{
1148 struct hci_command_hdr *hdr; 1154 struct hci_command_hdr *hdr;
1149 1155
@@ -1152,10 +1158,10 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 ogf, __u16 ocf)
1152 1158
1153 hdr = (void *) hdev->sent_cmd->data; 1159 hdr = (void *) hdev->sent_cmd->data;
1154 1160
1155 if (hdr->opcode != cpu_to_le16(hci_opcode_pack(ogf, ocf))) 1161 if (hdr->opcode != cpu_to_le16(opcode))
1156 return NULL; 1162 return NULL;
1157 1163
1158 BT_DBG("%s ogf 0x%x ocf 0x%x", hdev->name, ogf, ocf); 1164 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
1159 1165
1160 return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE; 1166 return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE;
1161} 1167}
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 4baea1e38652..e2cfeea5ee72 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -52,234 +52,273 @@
52 52
53/* Handle HCI Event packets */ 53/* Handle HCI Event packets */
54 54
55/* Command Complete OGF LINK_CTL */ 55static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
56static void hci_cc_link_ctl(struct hci_dev *hdev, __u16 ocf, struct sk_buff *skb)
57{ 56{
58 __u8 status; 57 __u8 status = *((__u8 *) skb->data);
59 struct hci_conn *pend;
60 58
61 BT_DBG("%s ocf 0x%x", hdev->name, ocf); 59 BT_DBG("%s status 0x%x", hdev->name, status);
62 60
63 switch (ocf) { 61 if (status)
64 case OCF_INQUIRY_CANCEL: 62 return;
65 case OCF_EXIT_PERIODIC_INQ:
66 status = *((__u8 *) skb->data);
67 63
68 if (status) { 64 clear_bit(HCI_INQUIRY, &hdev->flags);
69 BT_DBG("%s Inquiry cancel error: status 0x%x", hdev->name, status);
70 } else {
71 clear_bit(HCI_INQUIRY, &hdev->flags);
72 hci_req_complete(hdev, status);
73 }
74 65
75 hci_dev_lock(hdev); 66 hci_req_complete(hdev, status);
76 67
77 pend = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); 68 hci_conn_check_pending(hdev);
78 if (pend) 69}
79 hci_acl_connect(pend);
80 70
81 hci_dev_unlock(hdev); 71static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
72{
73 __u8 status = *((__u8 *) skb->data);
82 74
83 break; 75 BT_DBG("%s status 0x%x", hdev->name, status);
84 76
85 default: 77 if (status)
86 BT_DBG("%s Command complete: ogf LINK_CTL ocf %x", hdev->name, ocf); 78 return;
87 break; 79
80 clear_bit(HCI_INQUIRY, &hdev->flags);
81
82 hci_conn_check_pending(hdev);
83}
84
85static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, struct sk_buff *skb)
86{
87 BT_DBG("%s", hdev->name);
88}
89
90static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
91{
92 struct hci_rp_role_discovery *rp = (void *) skb->data;
93 struct hci_conn *conn;
94
95 BT_DBG("%s status 0x%x", hdev->name, rp->status);
96
97 if (rp->status)
98 return;
99
100 hci_dev_lock(hdev);
101
102 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
103 if (conn) {
104 if (rp->role)
105 conn->link_mode &= ~HCI_LM_MASTER;
106 else
107 conn->link_mode |= HCI_LM_MASTER;
88 } 108 }
109
110 hci_dev_unlock(hdev);
89} 111}
90 112
91/* Command Complete OGF LINK_POLICY */ 113static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
92static void hci_cc_link_policy(struct hci_dev *hdev, __u16 ocf, struct sk_buff *skb)
93{ 114{
115 struct hci_rp_write_link_policy *rp = (void *) skb->data;
94 struct hci_conn *conn; 116 struct hci_conn *conn;
95 struct hci_rp_role_discovery *rd;
96 struct hci_rp_write_link_policy *lp;
97 void *sent; 117 void *sent;
98 118
99 BT_DBG("%s ocf 0x%x", hdev->name, ocf); 119 BT_DBG("%s status 0x%x", hdev->name, rp->status);
100 120
101 switch (ocf) { 121 if (rp->status)
102 case OCF_ROLE_DISCOVERY: 122 return;
103 rd = (void *) skb->data;
104 123
105 if (rd->status) 124 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
106 break; 125 if (!sent)
126 return;
107 127
108 hci_dev_lock(hdev); 128 hci_dev_lock(hdev);
109 129
110 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rd->handle)); 130 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
111 if (conn) { 131 if (conn) {
112 if (rd->role) 132 __le16 policy = get_unaligned((__le16 *) (sent + 2));
113 conn->link_mode &= ~HCI_LM_MASTER; 133 conn->link_policy = __le16_to_cpu(policy);
114 else 134 }
115 conn->link_mode |= HCI_LM_MASTER;
116 }
117 135
118 hci_dev_unlock(hdev); 136 hci_dev_unlock(hdev);
119 break; 137}
138
139static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
140{
141 __u8 status = *((__u8 *) skb->data);
142
143 BT_DBG("%s status 0x%x", hdev->name, status);
120 144
121 case OCF_WRITE_LINK_POLICY: 145 hci_req_complete(hdev, status);
122 sent = hci_sent_cmd_data(hdev, OGF_LINK_POLICY, OCF_WRITE_LINK_POLICY); 146}
123 if (!sent)
124 break;
125 147
126 lp = (struct hci_rp_write_link_policy *) skb->data; 148static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
149{
150 __u8 status = *((__u8 *) skb->data);
151 void *sent;
127 152
128 if (lp->status) 153 BT_DBG("%s status 0x%x", hdev->name, status);
129 break;
130 154
131 hci_dev_lock(hdev); 155 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
156 if (!sent)
157 return;
132 158
133 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(lp->handle)); 159 if (!status)
134 if (conn) { 160 memcpy(hdev->dev_name, sent, 248);
135 __le16 policy = get_unaligned((__le16 *) (sent + 2)); 161}
136 conn->link_policy = __le16_to_cpu(policy);
137 }
138 162
139 hci_dev_unlock(hdev); 163static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
140 break; 164{
165 struct hci_rp_read_local_name *rp = (void *) skb->data;
141 166
142 default: 167 BT_DBG("%s status 0x%x", hdev->name, rp->status);
143 BT_DBG("%s: Command complete: ogf LINK_POLICY ocf %x", 168
144 hdev->name, ocf); 169 if (rp->status)
145 break; 170 return;
171
172 memcpy(hdev->dev_name, rp->name, 248);
173}
174
175static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
176{
177 __u8 status = *((__u8 *) skb->data);
178 void *sent;
179
180 BT_DBG("%s status 0x%x", hdev->name, status);
181
182 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
183 if (!sent)
184 return;
185
186 if (!status) {
187 __u8 param = *((__u8 *) sent);
188
189 if (param == AUTH_ENABLED)
190 set_bit(HCI_AUTH, &hdev->flags);
191 else
192 clear_bit(HCI_AUTH, &hdev->flags);
146 } 193 }
194
195 hci_req_complete(hdev, status);
147} 196}
148 197
149/* Command Complete OGF HOST_CTL */ 198static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
150static void hci_cc_host_ctl(struct hci_dev *hdev, __u16 ocf, struct sk_buff *skb)
151{ 199{
152 __u8 status, param; 200 __u8 status = *((__u8 *) skb->data);
153 __u16 setting;
154 struct hci_rp_read_voice_setting *vs;
155 void *sent; 201 void *sent;
156 202
157 BT_DBG("%s ocf 0x%x", hdev->name, ocf); 203 BT_DBG("%s status 0x%x", hdev->name, status);
158 204
159 switch (ocf) { 205 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
160 case OCF_RESET: 206 if (!sent)
161 status = *((__u8 *) skb->data); 207 return;
162 hci_req_complete(hdev, status);
163 break;
164 208
165 case OCF_SET_EVENT_FLT: 209 if (!status) {
166 status = *((__u8 *) skb->data); 210 __u8 param = *((__u8 *) sent);
167 if (status) {
168 BT_DBG("%s SET_EVENT_FLT failed %d", hdev->name, status);
169 } else {
170 BT_DBG("%s SET_EVENT_FLT succeseful", hdev->name);
171 }
172 break;
173 211
174 case OCF_WRITE_AUTH_ENABLE: 212 if (param)
175 sent = hci_sent_cmd_data(hdev, OGF_HOST_CTL, OCF_WRITE_AUTH_ENABLE); 213 set_bit(HCI_ENCRYPT, &hdev->flags);
176 if (!sent) 214 else
177 break; 215 clear_bit(HCI_ENCRYPT, &hdev->flags);
216 }
178 217
179 status = *((__u8 *) skb->data); 218 hci_req_complete(hdev, status);
180 param = *((__u8 *) sent); 219}
181 220
182 if (!status) { 221static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
183 if (param == AUTH_ENABLED) 222{
184 set_bit(HCI_AUTH, &hdev->flags); 223 __u8 status = *((__u8 *) skb->data);
185 else 224 void *sent;
186 clear_bit(HCI_AUTH, &hdev->flags);
187 }
188 hci_req_complete(hdev, status);
189 break;
190 225
191 case OCF_WRITE_ENCRYPT_MODE: 226 BT_DBG("%s status 0x%x", hdev->name, status);
192 sent = hci_sent_cmd_data(hdev, OGF_HOST_CTL, OCF_WRITE_ENCRYPT_MODE);
193 if (!sent)
194 break;
195 227
196 status = *((__u8 *) skb->data); 228 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
197 param = *((__u8 *) sent); 229 if (!sent)
230 return;
198 231
199 if (!status) { 232 if (!status) {
200 if (param) 233 __u8 param = *((__u8 *) sent);
201 set_bit(HCI_ENCRYPT, &hdev->flags);
202 else
203 clear_bit(HCI_ENCRYPT, &hdev->flags);
204 }
205 hci_req_complete(hdev, status);
206 break;
207 234
208 case OCF_WRITE_CA_TIMEOUT: 235 clear_bit(HCI_PSCAN, &hdev->flags);
209 status = *((__u8 *) skb->data); 236 clear_bit(HCI_ISCAN, &hdev->flags);
210 if (status) {
211 BT_DBG("%s OCF_WRITE_CA_TIMEOUT failed %d", hdev->name, status);
212 } else {
213 BT_DBG("%s OCF_WRITE_CA_TIMEOUT succeseful", hdev->name);
214 }
215 break;
216 237
217 case OCF_WRITE_PG_TIMEOUT: 238 if (param & SCAN_INQUIRY)
218 status = *((__u8 *) skb->data); 239 set_bit(HCI_ISCAN, &hdev->flags);
219 if (status) {
220 BT_DBG("%s OCF_WRITE_PG_TIMEOUT failed %d", hdev->name, status);
221 } else {
222 BT_DBG("%s: OCF_WRITE_PG_TIMEOUT succeseful", hdev->name);
223 }
224 break;
225 240
226 case OCF_WRITE_SCAN_ENABLE: 241 if (param & SCAN_PAGE)
227 sent = hci_sent_cmd_data(hdev, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE); 242 set_bit(HCI_PSCAN, &hdev->flags);
228 if (!sent) 243 }
229 break;
230 244
231 status = *((__u8 *) skb->data); 245 hci_req_complete(hdev, status);
232 param = *((__u8 *) sent); 246}
233 247
234 BT_DBG("param 0x%x", param); 248static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
249{
250 struct hci_rp_read_class_of_dev *rp = (void *) skb->data;
235 251
236 if (!status) { 252 BT_DBG("%s status 0x%x", hdev->name, rp->status);
237 clear_bit(HCI_PSCAN, &hdev->flags);
238 clear_bit(HCI_ISCAN, &hdev->flags);
239 if (param & SCAN_INQUIRY)
240 set_bit(HCI_ISCAN, &hdev->flags);
241 253
242 if (param & SCAN_PAGE) 254 if (rp->status)
243 set_bit(HCI_PSCAN, &hdev->flags); 255 return;
244 }
245 hci_req_complete(hdev, status);
246 break;
247 256
248 case OCF_READ_VOICE_SETTING: 257 memcpy(hdev->dev_class, rp->dev_class, 3);
249 vs = (struct hci_rp_read_voice_setting *) skb->data;
250 258
251 if (vs->status) { 259 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
252 BT_DBG("%s READ_VOICE_SETTING failed %d", hdev->name, vs->status); 260 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
253 break; 261}
254 }
255 262
256 setting = __le16_to_cpu(vs->voice_setting); 263static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
264{
265 __u8 status = *((__u8 *) skb->data);
266 void *sent;
257 267
258 if (hdev->voice_setting != setting ) { 268 BT_DBG("%s status 0x%x", hdev->name, status);
259 hdev->voice_setting = setting;
260 269
261 BT_DBG("%s: voice setting 0x%04x", hdev->name, setting); 270 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
271 if (!sent)
272 return;
262 273
263 if (hdev->notify) { 274 if (!status)
264 tasklet_disable(&hdev->tx_task); 275 memcpy(hdev->dev_class, sent, 3);
265 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); 276}
266 tasklet_enable(&hdev->tx_task); 277
267 } 278static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
268 } 279{
269 break; 280 struct hci_rp_read_voice_setting *rp = (void *) skb->data;
281 __u16 setting;
282
283 BT_DBG("%s status 0x%x", hdev->name, rp->status);
284
285 if (rp->status)
286 return;
270 287
271 case OCF_WRITE_VOICE_SETTING: 288 setting = __le16_to_cpu(rp->voice_setting);
272 sent = hci_sent_cmd_data(hdev, OGF_HOST_CTL, OCF_WRITE_VOICE_SETTING);
273 if (!sent)
274 break;
275 289
276 status = *((__u8 *) skb->data); 290 if (hdev->voice_setting == setting )
277 setting = __le16_to_cpu(get_unaligned((__le16 *) sent)); 291 return;
292
293 hdev->voice_setting = setting;
278 294
279 if (!status && hdev->voice_setting != setting) { 295 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
296
297 if (hdev->notify) {
298 tasklet_disable(&hdev->tx_task);
299 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
300 tasklet_enable(&hdev->tx_task);
301 }
302}
303
304static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
305{
306 __u8 status = *((__u8 *) skb->data);
307 void *sent;
308
309 BT_DBG("%s status 0x%x", hdev->name, status);
310
311 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
312 if (!sent)
313 return;
314
315 if (!status) {
316 __u16 setting = __le16_to_cpu(get_unaligned((__le16 *) sent));
317
318 if (hdev->voice_setting != setting) {
280 hdev->voice_setting = setting; 319 hdev->voice_setting = setting;
281 320
282 BT_DBG("%s: voice setting 0x%04x", hdev->name, setting); 321 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
283 322
284 if (hdev->notify) { 323 if (hdev->notify) {
285 tasklet_disable(&hdev->tx_task); 324 tasklet_disable(&hdev->tx_task);
@@ -287,143 +326,153 @@ static void hci_cc_host_ctl(struct hci_dev *hdev, __u16 ocf, struct sk_buff *skb
287 tasklet_enable(&hdev->tx_task); 326 tasklet_enable(&hdev->tx_task);
288 } 327 }
289 } 328 }
290 hci_req_complete(hdev, status);
291 break;
292
293 case OCF_HOST_BUFFER_SIZE:
294 status = *((__u8 *) skb->data);
295 if (status) {
296 BT_DBG("%s OCF_BUFFER_SIZE failed %d", hdev->name, status);
297 hci_req_complete(hdev, status);
298 }
299 break;
300
301 default:
302 BT_DBG("%s Command complete: ogf HOST_CTL ocf %x", hdev->name, ocf);
303 break;
304 } 329 }
305} 330}
306 331
307/* Command Complete OGF INFO_PARAM */ 332static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
308static void hci_cc_info_param(struct hci_dev *hdev, __u16 ocf, struct sk_buff *skb)
309{ 333{
310 struct hci_rp_read_loc_version *lv; 334 __u8 status = *((__u8 *) skb->data);
311 struct hci_rp_read_local_features *lf;
312 struct hci_rp_read_buffer_size *bs;
313 struct hci_rp_read_bd_addr *ba;
314 335
315 BT_DBG("%s ocf 0x%x", hdev->name, ocf); 336 BT_DBG("%s status 0x%x", hdev->name, status);
316 337
317 switch (ocf) { 338 hci_req_complete(hdev, status);
318 case OCF_READ_LOCAL_VERSION: 339}
319 lv = (struct hci_rp_read_loc_version *) skb->data;
320 340
321 if (lv->status) { 341static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
322 BT_DBG("%s READ_LOCAL_VERSION failed %d", hdev->name, lf->status); 342{
323 break; 343 struct hci_rp_read_local_version *rp = (void *) skb->data;
324 }
325 344
326 hdev->hci_ver = lv->hci_ver; 345 BT_DBG("%s status 0x%x", hdev->name, rp->status);
327 hdev->hci_rev = btohs(lv->hci_rev);
328 hdev->manufacturer = btohs(lv->manufacturer);
329 346
330 BT_DBG("%s: manufacturer %d hci_ver %d hci_rev %d", hdev->name, 347 if (rp->status)
331 hdev->manufacturer, hdev->hci_ver, hdev->hci_rev); 348 return;
332 349
333 break; 350 hdev->hci_ver = rp->hci_ver;
351 hdev->hci_rev = btohs(rp->hci_rev);
352 hdev->manufacturer = btohs(rp->manufacturer);
334 353
335 case OCF_READ_LOCAL_FEATURES: 354 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name,
336 lf = (struct hci_rp_read_local_features *) skb->data; 355 hdev->manufacturer,
356 hdev->hci_ver, hdev->hci_rev);
357}
337 358
338 if (lf->status) { 359static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb)
339 BT_DBG("%s READ_LOCAL_FEATURES failed %d", hdev->name, lf->status); 360{
340 break; 361 struct hci_rp_read_local_commands *rp = (void *) skb->data;
341 }
342 362
343 memcpy(hdev->features, lf->features, sizeof(hdev->features)); 363 BT_DBG("%s status 0x%x", hdev->name, rp->status);
344 364
345 /* Adjust default settings according to features 365 if (rp->status)
346 * supported by device. */ 366 return;
347 if (hdev->features[0] & LMP_3SLOT)
348 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
349 367
350 if (hdev->features[0] & LMP_5SLOT) 368 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
351 hdev->pkt_type |= (HCI_DM5 | HCI_DH5); 369}
352 370
353 if (hdev->features[1] & LMP_HV2) { 371static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb)
354 hdev->pkt_type |= (HCI_HV2); 372{
355 hdev->esco_type |= (ESCO_HV2); 373 struct hci_rp_read_local_features *rp = (void *) skb->data;
356 }
357 374
358 if (hdev->features[1] & LMP_HV3) { 375 BT_DBG("%s status 0x%x", hdev->name, rp->status);
359 hdev->pkt_type |= (HCI_HV3);
360 hdev->esco_type |= (ESCO_HV3);
361 }
362 376
363 if (hdev->features[3] & LMP_ESCO) 377 if (rp->status)
364 hdev->esco_type |= (ESCO_EV3); 378 return;
365 379
366 if (hdev->features[4] & LMP_EV4) 380 memcpy(hdev->features, rp->features, 8);
367 hdev->esco_type |= (ESCO_EV4);
368 381
369 if (hdev->features[4] & LMP_EV5) 382 /* Adjust default settings according to features
370 hdev->esco_type |= (ESCO_EV5); 383 * supported by device. */
371 384
372 BT_DBG("%s: features 0x%x 0x%x 0x%x", hdev->name, 385 if (hdev->features[0] & LMP_3SLOT)
373 lf->features[0], lf->features[1], lf->features[2]); 386 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
374 387
375 break; 388 if (hdev->features[0] & LMP_5SLOT)
389 hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
376 390
377 case OCF_READ_BUFFER_SIZE: 391 if (hdev->features[1] & LMP_HV2) {
378 bs = (struct hci_rp_read_buffer_size *) skb->data; 392 hdev->pkt_type |= (HCI_HV2);
393 hdev->esco_type |= (ESCO_HV2);
394 }
379 395
380 if (bs->status) { 396 if (hdev->features[1] & LMP_HV3) {
381 BT_DBG("%s READ_BUFFER_SIZE failed %d", hdev->name, bs->status); 397 hdev->pkt_type |= (HCI_HV3);
382 hci_req_complete(hdev, bs->status); 398 hdev->esco_type |= (ESCO_HV3);
383 break; 399 }
384 }
385 400
386 hdev->acl_mtu = __le16_to_cpu(bs->acl_mtu); 401 if (hdev->features[3] & LMP_ESCO)
387 hdev->sco_mtu = bs->sco_mtu; 402 hdev->esco_type |= (ESCO_EV3);
388 hdev->acl_pkts = __le16_to_cpu(bs->acl_max_pkt);
389 hdev->sco_pkts = __le16_to_cpu(bs->sco_max_pkt);
390 403
391 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) { 404 if (hdev->features[4] & LMP_EV4)
392 hdev->sco_mtu = 64; 405 hdev->esco_type |= (ESCO_EV4);
393 hdev->sco_pkts = 8;
394 }
395 406
396 hdev->acl_cnt = hdev->acl_pkts; 407 if (hdev->features[4] & LMP_EV5)
397 hdev->sco_cnt = hdev->sco_pkts; 408 hdev->esco_type |= (ESCO_EV5);
398 409
399 BT_DBG("%s mtu: acl %d, sco %d max_pkt: acl %d, sco %d", hdev->name, 410 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name,
400 hdev->acl_mtu, hdev->sco_mtu, hdev->acl_pkts, hdev->sco_pkts); 411 hdev->features[0], hdev->features[1],
401 break; 412 hdev->features[2], hdev->features[3],
413 hdev->features[4], hdev->features[5],
414 hdev->features[6], hdev->features[7]);
415}
402 416
403 case OCF_READ_BD_ADDR: 417static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
404 ba = (struct hci_rp_read_bd_addr *) skb->data; 418{
419 struct hci_rp_read_buffer_size *rp = (void *) skb->data;
405 420
406 if (!ba->status) { 421 BT_DBG("%s status 0x%x", hdev->name, rp->status);
407 bacpy(&hdev->bdaddr, &ba->bdaddr);
408 } else {
409 BT_DBG("%s: READ_BD_ADDR failed %d", hdev->name, ba->status);
410 }
411 422
412 hci_req_complete(hdev, ba->status); 423 if (rp->status)
413 break; 424 return;
414 425
415 default: 426 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
416 BT_DBG("%s Command complete: ogf INFO_PARAM ocf %x", hdev->name, ocf); 427 hdev->sco_mtu = rp->sco_mtu;
417 break; 428 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
429 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
430
431 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
432 hdev->sco_mtu = 64;
433 hdev->sco_pkts = 8;
418 } 434 }
435
436 hdev->acl_cnt = hdev->acl_pkts;
437 hdev->sco_cnt = hdev->sco_pkts;
438
439 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name,
440 hdev->acl_mtu, hdev->acl_pkts,
441 hdev->sco_mtu, hdev->sco_pkts);
442}
443
444static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
445{
446 struct hci_rp_read_bd_addr *rp = (void *) skb->data;
447
448 BT_DBG("%s status 0x%x", hdev->name, rp->status);
449
450 if (!rp->status)
451 bacpy(&hdev->bdaddr, &rp->bdaddr);
452
453 hci_req_complete(hdev, rp->status);
454}
455
456static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
457{
458 BT_DBG("%s status 0x%x", hdev->name, status);
459
460 if (status) {
461 hci_req_complete(hdev, status);
462
463 hci_conn_check_pending(hdev);
464 } else
465 set_bit(HCI_INQUIRY, &hdev->flags);
419} 466}
420 467
421/* Command Status OGF LINK_CTL */
422static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) 468static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
423{ 469{
470 struct hci_cp_create_conn *cp;
424 struct hci_conn *conn; 471 struct hci_conn *conn;
425 struct hci_cp_create_conn *cp = hci_sent_cmd_data(hdev, OGF_LINK_CTL, OCF_CREATE_CONN);
426 472
473 BT_DBG("%s status 0x%x", hdev->name, status);
474
475 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
427 if (!cp) 476 if (!cp)
428 return; 477 return;
429 478
@@ -431,8 +480,7 @@ static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
431 480
432 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); 481 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
433 482
434 BT_DBG("%s status 0x%x bdaddr %s conn %p", hdev->name, 483 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->bdaddr), conn);
435 status, batostr(&cp->bdaddr), conn);
436 484
437 if (status) { 485 if (status) {
438 if (conn && conn->state == BT_CONNECT) { 486 if (conn && conn->state == BT_CONNECT) {
@@ -457,234 +505,111 @@ static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
457 hci_dev_unlock(hdev); 505 hci_dev_unlock(hdev);
458} 506}
459 507
460static void hci_cs_link_ctl(struct hci_dev *hdev, __u16 ocf, __u8 status) 508static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
461{ 509{
462 BT_DBG("%s ocf 0x%x", hdev->name, ocf); 510 struct hci_cp_add_sco *cp;
463 511 struct hci_conn *acl, *sco;
464 switch (ocf) { 512 __u16 handle;
465 case OCF_CREATE_CONN:
466 hci_cs_create_conn(hdev, status);
467 break;
468
469 case OCF_ADD_SCO:
470 if (status) {
471 struct hci_conn *acl, *sco;
472 struct hci_cp_add_sco *cp = hci_sent_cmd_data(hdev, OGF_LINK_CTL, OCF_ADD_SCO);
473 __u16 handle;
474
475 if (!cp)
476 break;
477 513
478 handle = __le16_to_cpu(cp->handle); 514 if (!status)
515 return;
479 516
480 BT_DBG("%s Add SCO error: handle %d status 0x%x", hdev->name, handle, status); 517 BT_DBG("%s status 0x%x", hdev->name, status);
481 518
482 hci_dev_lock(hdev); 519 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
520 if (!cp)
521 return;
483 522
484 acl = hci_conn_hash_lookup_handle(hdev, handle); 523 handle = __le16_to_cpu(cp->handle);
485 if (acl && (sco = acl->link)) {
486 sco->state = BT_CLOSED;
487 524
488 hci_proto_connect_cfm(sco, status); 525 BT_DBG("%s handle %d", hdev->name, handle);
489 hci_conn_del(sco);
490 }
491 526
492 hci_dev_unlock(hdev); 527 hci_dev_lock(hdev);
493 }
494 break;
495 528
496 case OCF_INQUIRY: 529 acl = hci_conn_hash_lookup_handle(hdev, handle);
497 if (status) { 530 if (acl && (sco = acl->link)) {
498 BT_DBG("%s Inquiry error: status 0x%x", hdev->name, status); 531 sco->state = BT_CLOSED;
499 hci_req_complete(hdev, status);
500 } else {
501 set_bit(HCI_INQUIRY, &hdev->flags);
502 }
503 break;
504 532
505 default: 533 hci_proto_connect_cfm(sco, status);
506 BT_DBG("%s Command status: ogf LINK_CTL ocf %x status %d", 534 hci_conn_del(sco);
507 hdev->name, ocf, status);
508 break;
509 } 535 }
510}
511
512/* Command Status OGF LINK_POLICY */
513static void hci_cs_link_policy(struct hci_dev *hdev, __u16 ocf, __u8 status)
514{
515 BT_DBG("%s ocf 0x%x", hdev->name, ocf);
516
517 switch (ocf) {
518 case OCF_SNIFF_MODE:
519 if (status) {
520 struct hci_conn *conn;
521 struct hci_cp_sniff_mode *cp = hci_sent_cmd_data(hdev, OGF_LINK_POLICY, OCF_SNIFF_MODE);
522
523 if (!cp)
524 break;
525
526 hci_dev_lock(hdev);
527
528 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
529 if (conn) {
530 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
531 }
532
533 hci_dev_unlock(hdev);
534 }
535 break;
536
537 case OCF_EXIT_SNIFF_MODE:
538 if (status) {
539 struct hci_conn *conn;
540 struct hci_cp_exit_sniff_mode *cp = hci_sent_cmd_data(hdev, OGF_LINK_POLICY, OCF_EXIT_SNIFF_MODE);
541
542 if (!cp)
543 break;
544
545 hci_dev_lock(hdev);
546 536
547 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); 537 hci_dev_unlock(hdev);
548 if (conn) {
549 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
550 }
551
552 hci_dev_unlock(hdev);
553 }
554 break;
555
556 default:
557 BT_DBG("%s Command status: ogf LINK_POLICY ocf %x", hdev->name, ocf);
558 break;
559 }
560} 538}
561 539
562/* Command Status OGF HOST_CTL */ 540static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
563static void hci_cs_host_ctl(struct hci_dev *hdev, __u16 ocf, __u8 status)
564{ 541{
565 BT_DBG("%s ocf 0x%x", hdev->name, ocf); 542 BT_DBG("%s status 0x%x", hdev->name, status);
566
567 switch (ocf) {
568 default:
569 BT_DBG("%s Command status: ogf HOST_CTL ocf %x", hdev->name, ocf);
570 break;
571 }
572} 543}
573 544
574/* Command Status OGF INFO_PARAM */ 545static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
575static void hci_cs_info_param(struct hci_dev *hdev, __u16 ocf, __u8 status)
576{ 546{
577 BT_DBG("%s: hci_cs_info_param: ocf 0x%x", hdev->name, ocf); 547 BT_DBG("%s status 0x%x", hdev->name, status);
578
579 switch (ocf) {
580 default:
581 BT_DBG("%s Command status: ogf INFO_PARAM ocf %x", hdev->name, ocf);
582 break;
583 }
584} 548}
585 549
586/* Inquiry Complete */ 550static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
587static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
588{ 551{
589 __u8 status = *((__u8 *) skb->data); 552 struct hci_cp_sniff_mode *cp;
590 struct hci_conn *pend; 553 struct hci_conn *conn;
591 554
592 BT_DBG("%s status %d", hdev->name, status); 555 BT_DBG("%s status 0x%x", hdev->name, status);
593 556
594 clear_bit(HCI_INQUIRY, &hdev->flags); 557 if (!status)
595 hci_req_complete(hdev, status); 558 return;
559
560 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
561 if (!cp)
562 return;
596 563
597 hci_dev_lock(hdev); 564 hci_dev_lock(hdev);
598 565
599 pend = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); 566 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
600 if (pend) 567 if (conn)
601 hci_acl_connect(pend); 568 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
602 569
603 hci_dev_unlock(hdev); 570 hci_dev_unlock(hdev);
604} 571}
605 572
606/* Inquiry Result */ 573static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
607static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
608{ 574{
609 struct inquiry_data data; 575 struct hci_cp_exit_sniff_mode *cp;
610 struct inquiry_info *info = (struct inquiry_info *) (skb->data + 1); 576 struct hci_conn *conn;
611 int num_rsp = *((__u8 *) skb->data);
612 577
613 BT_DBG("%s num_rsp %d", hdev->name, num_rsp); 578 BT_DBG("%s status 0x%x", hdev->name, status);
614 579
615 if (!num_rsp) 580 if (!status)
581 return;
582
583 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
584 if (!cp)
616 return; 585 return;
617 586
618 hci_dev_lock(hdev); 587 hci_dev_lock(hdev);
619 588
620 for (; num_rsp; num_rsp--) { 589 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
621 bacpy(&data.bdaddr, &info->bdaddr); 590 if (conn)
622 data.pscan_rep_mode = info->pscan_rep_mode; 591 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
623 data.pscan_period_mode = info->pscan_period_mode;
624 data.pscan_mode = info->pscan_mode;
625 memcpy(data.dev_class, info->dev_class, 3);
626 data.clock_offset = info->clock_offset;
627 data.rssi = 0x00;
628 info++;
629 hci_inquiry_cache_update(hdev, &data);
630 }
631 592
632 hci_dev_unlock(hdev); 593 hci_dev_unlock(hdev);
633} 594}
634 595
635/* Inquiry Result With RSSI */ 596static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
636static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct sk_buff *skb)
637{ 597{
638 struct inquiry_data data; 598 __u8 status = *((__u8 *) skb->data);
639 int num_rsp = *((__u8 *) skb->data);
640
641 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
642
643 if (!num_rsp)
644 return;
645
646 hci_dev_lock(hdev);
647 599
648 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { 600 BT_DBG("%s status %d", hdev->name, status);
649 struct inquiry_info_with_rssi_and_pscan_mode *info =
650 (struct inquiry_info_with_rssi_and_pscan_mode *) (skb->data + 1);
651 601
652 for (; num_rsp; num_rsp--) { 602 clear_bit(HCI_INQUIRY, &hdev->flags);
653 bacpy(&data.bdaddr, &info->bdaddr);
654 data.pscan_rep_mode = info->pscan_rep_mode;
655 data.pscan_period_mode = info->pscan_period_mode;
656 data.pscan_mode = info->pscan_mode;
657 memcpy(data.dev_class, info->dev_class, 3);
658 data.clock_offset = info->clock_offset;
659 data.rssi = info->rssi;
660 info++;
661 hci_inquiry_cache_update(hdev, &data);
662 }
663 } else {
664 struct inquiry_info_with_rssi *info =
665 (struct inquiry_info_with_rssi *) (skb->data + 1);
666 603
667 for (; num_rsp; num_rsp--) { 604 hci_req_complete(hdev, status);
668 bacpy(&data.bdaddr, &info->bdaddr);
669 data.pscan_rep_mode = info->pscan_rep_mode;
670 data.pscan_period_mode = info->pscan_period_mode;
671 data.pscan_mode = 0x00;
672 memcpy(data.dev_class, info->dev_class, 3);
673 data.clock_offset = info->clock_offset;
674 data.rssi = info->rssi;
675 info++;
676 hci_inquiry_cache_update(hdev, &data);
677 }
678 }
679 605
680 hci_dev_unlock(hdev); 606 hci_conn_check_pending(hdev);
681} 607}
682 608
683/* Extended Inquiry Result */ 609static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
684static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
685{ 610{
686 struct inquiry_data data; 611 struct inquiry_data data;
687 struct extended_inquiry_info *info = (struct extended_inquiry_info *) (skb->data + 1); 612 struct inquiry_info *info = (void *) (skb->data + 1);
688 int num_rsp = *((__u8 *) skb->data); 613 int num_rsp = *((__u8 *) skb->data);
689 614
690 BT_DBG("%s num_rsp %d", hdev->name, num_rsp); 615 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
@@ -696,12 +621,12 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
696 621
697 for (; num_rsp; num_rsp--) { 622 for (; num_rsp; num_rsp--) {
698 bacpy(&data.bdaddr, &info->bdaddr); 623 bacpy(&data.bdaddr, &info->bdaddr);
699 data.pscan_rep_mode = info->pscan_rep_mode; 624 data.pscan_rep_mode = info->pscan_rep_mode;
700 data.pscan_period_mode = info->pscan_period_mode; 625 data.pscan_period_mode = info->pscan_period_mode;
701 data.pscan_mode = 0x00; 626 data.pscan_mode = info->pscan_mode;
702 memcpy(data.dev_class, info->dev_class, 3); 627 memcpy(data.dev_class, info->dev_class, 3);
703 data.clock_offset = info->clock_offset; 628 data.clock_offset = info->clock_offset;
704 data.rssi = info->rssi; 629 data.rssi = 0x00;
705 info++; 630 info++;
706 hci_inquiry_cache_update(hdev, &data); 631 hci_inquiry_cache_update(hdev, &data);
707 } 632 }
@@ -709,70 +634,18 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
709 hci_dev_unlock(hdev); 634 hci_dev_unlock(hdev);
710} 635}
711 636
712/* Connect Request */
713static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
714{
715 struct hci_ev_conn_request *ev = (struct hci_ev_conn_request *) skb->data;
716 int mask = hdev->link_mode;
717
718 BT_DBG("%s Connection request: %s type 0x%x", hdev->name,
719 batostr(&ev->bdaddr), ev->link_type);
720
721 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
722
723 if (mask & HCI_LM_ACCEPT) {
724 /* Connection accepted */
725 struct hci_conn *conn;
726 struct hci_cp_accept_conn_req cp;
727
728 hci_dev_lock(hdev);
729 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
730 if (!conn) {
731 if (!(conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr))) {
732 BT_ERR("No memmory for new connection");
733 hci_dev_unlock(hdev);
734 return;
735 }
736 }
737 memcpy(conn->dev_class, ev->dev_class, 3);
738 conn->state = BT_CONNECT;
739 hci_dev_unlock(hdev);
740
741 bacpy(&cp.bdaddr, &ev->bdaddr);
742
743 if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
744 cp.role = 0x00; /* Become master */
745 else
746 cp.role = 0x01; /* Remain slave */
747
748 hci_send_cmd(hdev, OGF_LINK_CTL,
749 OCF_ACCEPT_CONN_REQ, sizeof(cp), &cp);
750 } else {
751 /* Connection rejected */
752 struct hci_cp_reject_conn_req cp;
753
754 bacpy(&cp.bdaddr, &ev->bdaddr);
755 cp.reason = 0x0f;
756 hci_send_cmd(hdev, OGF_LINK_CTL,
757 OCF_REJECT_CONN_REQ, sizeof(cp), &cp);
758 }
759}
760
761/* Connect Complete */
762static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 637static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
763{ 638{
764 struct hci_ev_conn_complete *ev = (struct hci_ev_conn_complete *) skb->data; 639 struct hci_ev_conn_complete *ev = (void *) skb->data;
765 struct hci_conn *conn, *pend; 640 struct hci_conn *conn;
766 641
767 BT_DBG("%s", hdev->name); 642 BT_DBG("%s", hdev->name);
768 643
769 hci_dev_lock(hdev); 644 hci_dev_lock(hdev);
770 645
771 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); 646 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
772 if (!conn) { 647 if (!conn)
773 hci_dev_unlock(hdev); 648 goto unlock;
774 return;
775 }
776 649
777 if (!ev->status) { 650 if (!ev->status) {
778 conn->handle = __le16_to_cpu(ev->handle); 651 conn->handle = __le16_to_cpu(ev->handle);
@@ -788,8 +661,7 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
788 if (conn->type == ACL_LINK) { 661 if (conn->type == ACL_LINK) {
789 struct hci_cp_read_remote_features cp; 662 struct hci_cp_read_remote_features cp;
790 cp.handle = ev->handle; 663 cp.handle = ev->handle;
791 hci_send_cmd(hdev, OGF_LINK_CTL, 664 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, sizeof(cp), &cp);
792 OCF_READ_REMOTE_FEATURES, sizeof(cp), &cp);
793 } 665 }
794 666
795 /* Set link policy */ 667 /* Set link policy */
@@ -797,8 +669,7 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
797 struct hci_cp_write_link_policy cp; 669 struct hci_cp_write_link_policy cp;
798 cp.handle = ev->handle; 670 cp.handle = ev->handle;
799 cp.policy = cpu_to_le16(hdev->link_policy); 671 cp.policy = cpu_to_le16(hdev->link_policy);
800 hci_send_cmd(hdev, OGF_LINK_POLICY, 672 hci_send_cmd(hdev, HCI_OP_WRITE_LINK_POLICY, sizeof(cp), &cp);
801 OCF_WRITE_LINK_POLICY, sizeof(cp), &cp);
802 } 673 }
803 674
804 /* Set packet type for incoming connection */ 675 /* Set packet type for incoming connection */
@@ -809,8 +680,7 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
809 cpu_to_le16(hdev->pkt_type & ACL_PTYPE_MASK): 680 cpu_to_le16(hdev->pkt_type & ACL_PTYPE_MASK):
810 cpu_to_le16(hdev->pkt_type & SCO_PTYPE_MASK); 681 cpu_to_le16(hdev->pkt_type & SCO_PTYPE_MASK);
811 682
812 hci_send_cmd(hdev, OGF_LINK_CTL, 683 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp), &cp);
813 OCF_CHANGE_CONN_PTYPE, sizeof(cp), &cp);
814 } else { 684 } else {
815 /* Update disconnect timer */ 685 /* Update disconnect timer */
816 hci_conn_hold(conn); 686 hci_conn_hold(conn);
@@ -835,136 +705,83 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
835 if (ev->status) 705 if (ev->status)
836 hci_conn_del(conn); 706 hci_conn_del(conn);
837 707
838 pend = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); 708unlock:
839 if (pend)
840 hci_acl_connect(pend);
841
842 hci_dev_unlock(hdev); 709 hci_dev_unlock(hdev);
843}
844
845/* Disconnect Complete */
846static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
847{
848 struct hci_ev_disconn_complete *ev = (struct hci_ev_disconn_complete *) skb->data;
849 struct hci_conn *conn;
850
851 BT_DBG("%s status %d", hdev->name, ev->status);
852
853 if (ev->status)
854 return;
855
856 hci_dev_lock(hdev);
857
858 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
859 if (conn) {
860 conn->state = BT_CLOSED;
861 hci_proto_disconn_ind(conn, ev->reason);
862 hci_conn_del(conn);
863 }
864 710
865 hci_dev_unlock(hdev); 711 hci_conn_check_pending(hdev);
866} 712}
867 713
868/* Number of completed packets */ 714static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
869static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
870{ 715{
871 struct hci_ev_num_comp_pkts *ev = (struct hci_ev_num_comp_pkts *) skb->data; 716 struct hci_ev_conn_request *ev = (void *) skb->data;
872 __le16 *ptr; 717 int mask = hdev->link_mode;
873 int i;
874 718
875 skb_pull(skb, sizeof(*ev)); 719 BT_DBG("%s bdaddr %s type 0x%x", hdev->name,
720 batostr(&ev->bdaddr), ev->link_type);
876 721
877 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl); 722 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
878
879 if (skb->len < ev->num_hndl * 4) {
880 BT_DBG("%s bad parameters", hdev->name);
881 return;
882 }
883
884 tasklet_disable(&hdev->tx_task);
885 723
886 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) { 724 if (mask & HCI_LM_ACCEPT) {
725 /* Connection accepted */
887 struct hci_conn *conn; 726 struct hci_conn *conn;
888 __u16 handle, count; 727 struct hci_cp_accept_conn_req cp;
889
890 handle = __le16_to_cpu(get_unaligned(ptr++));
891 count = __le16_to_cpu(get_unaligned(ptr++));
892
893 conn = hci_conn_hash_lookup_handle(hdev, handle);
894 if (conn) {
895 conn->sent -= count;
896 728
897 if (conn->type == ACL_LINK) { 729 hci_dev_lock(hdev);
898 if ((hdev->acl_cnt += count) > hdev->acl_pkts) 730 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
899 hdev->acl_cnt = hdev->acl_pkts; 731 if (!conn) {
900 } else { 732 if (!(conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr))) {
901 if ((hdev->sco_cnt += count) > hdev->sco_pkts) 733 BT_ERR("No memmory for new connection");
902 hdev->sco_cnt = hdev->sco_pkts; 734 hci_dev_unlock(hdev);
735 return;
903 } 736 }
904 } 737 }
905 } 738 memcpy(conn->dev_class, ev->dev_class, 3);
906 hci_sched_tx(hdev); 739 conn->state = BT_CONNECT;
907 740 hci_dev_unlock(hdev);
908 tasklet_enable(&hdev->tx_task);
909}
910
911/* Role Change */
912static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
913{
914 struct hci_ev_role_change *ev = (struct hci_ev_role_change *) skb->data;
915 struct hci_conn *conn;
916
917 BT_DBG("%s status %d", hdev->name, ev->status);
918 741
919 hci_dev_lock(hdev); 742 bacpy(&cp.bdaddr, &ev->bdaddr);
920 743
921 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); 744 if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
922 if (conn) { 745 cp.role = 0x00; /* Become master */
923 if (!ev->status) { 746 else
924 if (ev->role) 747 cp.role = 0x01; /* Remain slave */
925 conn->link_mode &= ~HCI_LM_MASTER;
926 else
927 conn->link_mode |= HCI_LM_MASTER;
928 }
929 748
930 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->pend); 749 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
750 } else {
751 /* Connection rejected */
752 struct hci_cp_reject_conn_req cp;
931 753
932 hci_role_switch_cfm(conn, ev->status, ev->role); 754 bacpy(&cp.bdaddr, &ev->bdaddr);
755 cp.reason = 0x0f;
756 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
933 } 757 }
934
935 hci_dev_unlock(hdev);
936} 758}
937 759
938/* Mode Change */ 760static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
939static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
940{ 761{
941 struct hci_ev_mode_change *ev = (struct hci_ev_mode_change *) skb->data; 762 struct hci_ev_disconn_complete *ev = (void *) skb->data;
942 struct hci_conn *conn; 763 struct hci_conn *conn;
943 764
944 BT_DBG("%s status %d", hdev->name, ev->status); 765 BT_DBG("%s status %d", hdev->name, ev->status);
945 766
767 if (ev->status)
768 return;
769
946 hci_dev_lock(hdev); 770 hci_dev_lock(hdev);
947 771
948 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); 772 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
949 if (conn) { 773 if (conn) {
950 conn->mode = ev->mode; 774 conn->state = BT_CLOSED;
951 conn->interval = __le16_to_cpu(ev->interval); 775 hci_proto_disconn_ind(conn, ev->reason);
952 776 hci_conn_del(conn);
953 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) {
954 if (conn->mode == HCI_CM_ACTIVE)
955 conn->power_save = 1;
956 else
957 conn->power_save = 0;
958 }
959 } 777 }
960 778
961 hci_dev_unlock(hdev); 779 hci_dev_unlock(hdev);
962} 780}
963 781
964/* Authentication Complete */
965static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 782static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
966{ 783{
967 struct hci_ev_auth_complete *ev = (struct hci_ev_auth_complete *) skb->data; 784 struct hci_ev_auth_complete *ev = (void *) skb->data;
968 struct hci_conn *conn; 785 struct hci_conn *conn;
969 786
970 BT_DBG("%s status %d", hdev->name, ev->status); 787 BT_DBG("%s status %d", hdev->name, ev->status);
@@ -985,8 +802,8 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
985 struct hci_cp_set_conn_encrypt cp; 802 struct hci_cp_set_conn_encrypt cp;
986 cp.handle = cpu_to_le16(conn->handle); 803 cp.handle = cpu_to_le16(conn->handle);
987 cp.encrypt = 1; 804 cp.encrypt = 1;
988 hci_send_cmd(conn->hdev, OGF_LINK_CTL, 805 hci_send_cmd(conn->hdev,
989 OCF_SET_CONN_ENCRYPT, sizeof(cp), &cp); 806 HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), &cp);
990 } else { 807 } else {
991 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); 808 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
992 hci_encrypt_cfm(conn, ev->status, 0x00); 809 hci_encrypt_cfm(conn, ev->status, 0x00);
@@ -997,10 +814,16 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
997 hci_dev_unlock(hdev); 814 hci_dev_unlock(hdev);
998} 815}
999 816
1000/* Encryption Change */ 817static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
818{
819 BT_DBG("%s", hdev->name);
820
821 hci_conn_check_pending(hdev);
822}
823
1001static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) 824static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
1002{ 825{
1003 struct hci_ev_encrypt_change *ev = (struct hci_ev_encrypt_change *) skb->data; 826 struct hci_ev_encrypt_change *ev = (void *) skb->data;
1004 struct hci_conn *conn; 827 struct hci_conn *conn;
1005 828
1006 BT_DBG("%s status %d", hdev->name, ev->status); 829 BT_DBG("%s status %d", hdev->name, ev->status);
@@ -1024,10 +847,9 @@ static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *
1024 hci_dev_unlock(hdev); 847 hci_dev_unlock(hdev);
1025} 848}
1026 849
1027/* Change Connection Link Key Complete */ 850static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1028static inline void hci_change_conn_link_key_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1029{ 851{
1030 struct hci_ev_change_conn_link_key_complete *ev = (struct hci_ev_change_conn_link_key_complete *) skb->data; 852 struct hci_ev_change_link_key_complete *ev = (void *) skb->data;
1031 struct hci_conn *conn; 853 struct hci_conn *conn;
1032 854
1033 BT_DBG("%s status %d", hdev->name, ev->status); 855 BT_DBG("%s status %d", hdev->name, ev->status);
@@ -1047,25 +869,263 @@ static inline void hci_change_conn_link_key_complete_evt(struct hci_dev *hdev, s
1047 hci_dev_unlock(hdev); 869 hci_dev_unlock(hdev);
1048} 870}
1049 871
1050/* Pin Code Request*/ 872static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
1051static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1052{ 873{
874 struct hci_ev_remote_features *ev = (void *) skb->data;
875 struct hci_conn *conn;
876
877 BT_DBG("%s status %d", hdev->name, ev->status);
878
879 if (ev->status)
880 return;
881
882 hci_dev_lock(hdev);
883
884 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
885 if (conn)
886 memcpy(conn->features, ev->features, 8);
887
888 hci_dev_unlock(hdev);
1053} 889}
1054 890
1055/* Link Key Request */ 891static inline void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb)
1056static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1057{ 892{
893 BT_DBG("%s", hdev->name);
1058} 894}
1059 895
1060/* Link Key Notification */ 896static inline void hci_qos_setup_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1061static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
1062{ 897{
898 BT_DBG("%s", hdev->name);
1063} 899}
1064 900
1065/* Remote Features */ 901static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1066static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
1067{ 902{
1068 struct hci_ev_remote_features *ev = (struct hci_ev_remote_features *) skb->data; 903 struct hci_ev_cmd_complete *ev = (void *) skb->data;
904 __u16 opcode;
905
906 skb_pull(skb, sizeof(*ev));
907
908 opcode = __le16_to_cpu(ev->opcode);
909
910 switch (opcode) {
911 case HCI_OP_INQUIRY_CANCEL:
912 hci_cc_inquiry_cancel(hdev, skb);
913 break;
914
915 case HCI_OP_EXIT_PERIODIC_INQ:
916 hci_cc_exit_periodic_inq(hdev, skb);
917 break;
918
919 case HCI_OP_REMOTE_NAME_REQ_CANCEL:
920 hci_cc_remote_name_req_cancel(hdev, skb);
921 break;
922
923 case HCI_OP_ROLE_DISCOVERY:
924 hci_cc_role_discovery(hdev, skb);
925 break;
926
927 case HCI_OP_WRITE_LINK_POLICY:
928 hci_cc_write_link_policy(hdev, skb);
929 break;
930
931 case HCI_OP_RESET:
932 hci_cc_reset(hdev, skb);
933 break;
934
935 case HCI_OP_WRITE_LOCAL_NAME:
936 hci_cc_write_local_name(hdev, skb);
937 break;
938
939 case HCI_OP_READ_LOCAL_NAME:
940 hci_cc_read_local_name(hdev, skb);
941 break;
942
943 case HCI_OP_WRITE_AUTH_ENABLE:
944 hci_cc_write_auth_enable(hdev, skb);
945 break;
946
947 case HCI_OP_WRITE_ENCRYPT_MODE:
948 hci_cc_write_encrypt_mode(hdev, skb);
949 break;
950
951 case HCI_OP_WRITE_SCAN_ENABLE:
952 hci_cc_write_scan_enable(hdev, skb);
953 break;
954
955 case HCI_OP_READ_CLASS_OF_DEV:
956 hci_cc_read_class_of_dev(hdev, skb);
957 break;
958
959 case HCI_OP_WRITE_CLASS_OF_DEV:
960 hci_cc_write_class_of_dev(hdev, skb);
961 break;
962
963 case HCI_OP_READ_VOICE_SETTING:
964 hci_cc_read_voice_setting(hdev, skb);
965 break;
966
967 case HCI_OP_WRITE_VOICE_SETTING:
968 hci_cc_write_voice_setting(hdev, skb);
969 break;
970
971 case HCI_OP_HOST_BUFFER_SIZE:
972 hci_cc_host_buffer_size(hdev, skb);
973 break;
974
975 case HCI_OP_READ_LOCAL_VERSION:
976 hci_cc_read_local_version(hdev, skb);
977 break;
978
979 case HCI_OP_READ_LOCAL_COMMANDS:
980 hci_cc_read_local_commands(hdev, skb);
981 break;
982
983 case HCI_OP_READ_LOCAL_FEATURES:
984 hci_cc_read_local_features(hdev, skb);
985 break;
986
987 case HCI_OP_READ_BUFFER_SIZE:
988 hci_cc_read_buffer_size(hdev, skb);
989 break;
990
991 case HCI_OP_READ_BD_ADDR:
992 hci_cc_read_bd_addr(hdev, skb);
993 break;
994
995 default:
996 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
997 break;
998 }
999
1000 if (ev->ncmd) {
1001 atomic_set(&hdev->cmd_cnt, 1);
1002 if (!skb_queue_empty(&hdev->cmd_q))
1003 hci_sched_cmd(hdev);
1004 }
1005}
1006
1007static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
1008{
1009 struct hci_ev_cmd_status *ev = (void *) skb->data;
1010 __u16 opcode;
1011
1012 skb_pull(skb, sizeof(*ev));
1013
1014 opcode = __le16_to_cpu(ev->opcode);
1015
1016 switch (opcode) {
1017 case HCI_OP_INQUIRY:
1018 hci_cs_inquiry(hdev, ev->status);
1019 break;
1020
1021 case HCI_OP_CREATE_CONN:
1022 hci_cs_create_conn(hdev, ev->status);
1023 break;
1024
1025 case HCI_OP_ADD_SCO:
1026 hci_cs_add_sco(hdev, ev->status);
1027 break;
1028
1029 case HCI_OP_REMOTE_NAME_REQ:
1030 hci_cs_remote_name_req(hdev, ev->status);
1031 break;
1032
1033 case HCI_OP_SETUP_SYNC_CONN:
1034 hci_cs_setup_sync_conn(hdev, ev->status);
1035 break;
1036
1037 case HCI_OP_SNIFF_MODE:
1038 hci_cs_sniff_mode(hdev, ev->status);
1039 break;
1040
1041 case HCI_OP_EXIT_SNIFF_MODE:
1042 hci_cs_exit_sniff_mode(hdev, ev->status);
1043 break;
1044
1045 default:
1046 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
1047 break;
1048 }
1049
1050 if (ev->ncmd) {
1051 atomic_set(&hdev->cmd_cnt, 1);
1052 if (!skb_queue_empty(&hdev->cmd_q))
1053 hci_sched_cmd(hdev);
1054 }
1055}
1056
1057static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
1058{
1059 struct hci_ev_role_change *ev = (void *) skb->data;
1060 struct hci_conn *conn;
1061
1062 BT_DBG("%s status %d", hdev->name, ev->status);
1063
1064 hci_dev_lock(hdev);
1065
1066 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
1067 if (conn) {
1068 if (!ev->status) {
1069 if (ev->role)
1070 conn->link_mode &= ~HCI_LM_MASTER;
1071 else
1072 conn->link_mode |= HCI_LM_MASTER;
1073 }
1074
1075 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->pend);
1076
1077 hci_role_switch_cfm(conn, ev->status, ev->role);
1078 }
1079
1080 hci_dev_unlock(hdev);
1081}
1082
1083static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
1084{
1085 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
1086 __le16 *ptr;
1087 int i;
1088
1089 skb_pull(skb, sizeof(*ev));
1090
1091 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
1092
1093 if (skb->len < ev->num_hndl * 4) {
1094 BT_DBG("%s bad parameters", hdev->name);
1095 return;
1096 }
1097
1098 tasklet_disable(&hdev->tx_task);
1099
1100 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) {
1101 struct hci_conn *conn;
1102 __u16 handle, count;
1103
1104 handle = __le16_to_cpu(get_unaligned(ptr++));
1105 count = __le16_to_cpu(get_unaligned(ptr++));
1106
1107 conn = hci_conn_hash_lookup_handle(hdev, handle);
1108 if (conn) {
1109 conn->sent -= count;
1110
1111 if (conn->type == ACL_LINK) {
1112 if ((hdev->acl_cnt += count) > hdev->acl_pkts)
1113 hdev->acl_cnt = hdev->acl_pkts;
1114 } else {
1115 if ((hdev->sco_cnt += count) > hdev->sco_pkts)
1116 hdev->sco_cnt = hdev->sco_pkts;
1117 }
1118 }
1119 }
1120
1121 hci_sched_tx(hdev);
1122
1123 tasklet_enable(&hdev->tx_task);
1124}
1125
1126static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
1127{
1128 struct hci_ev_mode_change *ev = (void *) skb->data;
1069 struct hci_conn *conn; 1129 struct hci_conn *conn;
1070 1130
1071 BT_DBG("%s status %d", hdev->name, ev->status); 1131 BT_DBG("%s status %d", hdev->name, ev->status);
@@ -1073,17 +1133,39 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff
1073 hci_dev_lock(hdev); 1133 hci_dev_lock(hdev);
1074 1134
1075 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); 1135 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1076 if (conn && !ev->status) { 1136 if (conn) {
1077 memcpy(conn->features, ev->features, sizeof(conn->features)); 1137 conn->mode = ev->mode;
1138 conn->interval = __le16_to_cpu(ev->interval);
1139
1140 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) {
1141 if (conn->mode == HCI_CM_ACTIVE)
1142 conn->power_save = 1;
1143 else
1144 conn->power_save = 0;
1145 }
1078 } 1146 }
1079 1147
1080 hci_dev_unlock(hdev); 1148 hci_dev_unlock(hdev);
1081} 1149}
1082 1150
1083/* Clock Offset */ 1151static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1152{
1153 BT_DBG("%s", hdev->name);
1154}
1155
1156static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1157{
1158 BT_DBG("%s", hdev->name);
1159}
1160
1161static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
1162{
1163 BT_DBG("%s", hdev->name);
1164}
1165
1084static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb) 1166static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb)
1085{ 1167{
1086 struct hci_ev_clock_offset *ev = (struct hci_ev_clock_offset *) skb->data; 1168 struct hci_ev_clock_offset *ev = (void *) skb->data;
1087 struct hci_conn *conn; 1169 struct hci_conn *conn;
1088 1170
1089 BT_DBG("%s status %d", hdev->name, ev->status); 1171 BT_DBG("%s status %d", hdev->name, ev->status);
@@ -1103,10 +1185,9 @@ static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *sk
1103 hci_dev_unlock(hdev); 1185 hci_dev_unlock(hdev);
1104} 1186}
1105 1187
1106/* Page Scan Repetition Mode */
1107static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) 1188static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
1108{ 1189{
1109 struct hci_ev_pscan_rep_mode *ev = (struct hci_ev_pscan_rep_mode *) skb->data; 1190 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
1110 struct inquiry_entry *ie; 1191 struct inquiry_entry *ie;
1111 1192
1112 BT_DBG("%s", hdev->name); 1193 BT_DBG("%s", hdev->name);
@@ -1121,10 +1202,69 @@ static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *
1121 hci_dev_unlock(hdev); 1202 hci_dev_unlock(hdev);
1122} 1203}
1123 1204
1124/* Sniff Subrate */ 1205static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct sk_buff *skb)
1206{
1207 struct inquiry_data data;
1208 int num_rsp = *((__u8 *) skb->data);
1209
1210 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
1211
1212 if (!num_rsp)
1213 return;
1214
1215 hci_dev_lock(hdev);
1216
1217 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {
1218 struct inquiry_info_with_rssi_and_pscan_mode *info = (void *) (skb->data + 1);
1219
1220 for (; num_rsp; num_rsp--) {
1221 bacpy(&data.bdaddr, &info->bdaddr);
1222 data.pscan_rep_mode = info->pscan_rep_mode;
1223 data.pscan_period_mode = info->pscan_period_mode;
1224 data.pscan_mode = info->pscan_mode;
1225 memcpy(data.dev_class, info->dev_class, 3);
1226 data.clock_offset = info->clock_offset;
1227 data.rssi = info->rssi;
1228 info++;
1229 hci_inquiry_cache_update(hdev, &data);
1230 }
1231 } else {
1232 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
1233
1234 for (; num_rsp; num_rsp--) {
1235 bacpy(&data.bdaddr, &info->bdaddr);
1236 data.pscan_rep_mode = info->pscan_rep_mode;
1237 data.pscan_period_mode = info->pscan_period_mode;
1238 data.pscan_mode = 0x00;
1239 memcpy(data.dev_class, info->dev_class, 3);
1240 data.clock_offset = info->clock_offset;
1241 data.rssi = info->rssi;
1242 info++;
1243 hci_inquiry_cache_update(hdev, &data);
1244 }
1245 }
1246
1247 hci_dev_unlock(hdev);
1248}
1249
1250static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
1251{
1252 BT_DBG("%s", hdev->name);
1253}
1254
1255static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1256{
1257 BT_DBG("%s", hdev->name);
1258}
1259
1260static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb)
1261{
1262 BT_DBG("%s", hdev->name);
1263}
1264
1125static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb) 1265static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb)
1126{ 1266{
1127 struct hci_ev_sniff_subrate *ev = (struct hci_ev_sniff_subrate *) skb->data; 1267 struct hci_ev_sniff_subrate *ev = (void *) skb->data;
1128 struct hci_conn *conn; 1268 struct hci_conn *conn;
1129 1269
1130 BT_DBG("%s status %d", hdev->name, ev->status); 1270 BT_DBG("%s status %d", hdev->name, ev->status);
@@ -1138,22 +1278,42 @@ static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *s
1138 hci_dev_unlock(hdev); 1278 hci_dev_unlock(hdev);
1139} 1279}
1140 1280
1141void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) 1281static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
1142{ 1282{
1143 struct hci_event_hdr *hdr = (struct hci_event_hdr *) skb->data; 1283 struct inquiry_data data;
1144 struct hci_ev_cmd_complete *ec; 1284 struct extended_inquiry_info *info = (void *) (skb->data + 1);
1145 struct hci_ev_cmd_status *cs; 1285 int num_rsp = *((__u8 *) skb->data);
1146 u16 opcode, ocf, ogf;
1147 1286
1148 skb_pull(skb, HCI_EVENT_HDR_SIZE); 1287 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
1149 1288
1150 BT_DBG("%s evt 0x%x", hdev->name, hdr->evt); 1289 if (!num_rsp)
1290 return;
1151 1291
1152 switch (hdr->evt) { 1292 hci_dev_lock(hdev);
1153 case HCI_EV_NUM_COMP_PKTS: 1293
1154 hci_num_comp_pkts_evt(hdev, skb); 1294 for (; num_rsp; num_rsp--) {
1155 break; 1295 bacpy(&data.bdaddr, &info->bdaddr);
1296 data.pscan_rep_mode = info->pscan_rep_mode;
1297 data.pscan_period_mode = info->pscan_period_mode;
1298 data.pscan_mode = 0x00;
1299 memcpy(data.dev_class, info->dev_class, 3);
1300 data.clock_offset = info->clock_offset;
1301 data.rssi = info->rssi;
1302 info++;
1303 hci_inquiry_cache_update(hdev, &data);
1304 }
1305
1306 hci_dev_unlock(hdev);
1307}
1308
1309void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
1310{
1311 struct hci_event_hdr *hdr = (void *) skb->data;
1312 __u8 event = hdr->evt;
1313
1314 skb_pull(skb, HCI_EVENT_HDR_SIZE);
1156 1315
1316 switch (event) {
1157 case HCI_EV_INQUIRY_COMPLETE: 1317 case HCI_EV_INQUIRY_COMPLETE:
1158 hci_inquiry_complete_evt(hdev, skb); 1318 hci_inquiry_complete_evt(hdev, skb);
1159 break; 1319 break;
@@ -1162,44 +1322,64 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
1162 hci_inquiry_result_evt(hdev, skb); 1322 hci_inquiry_result_evt(hdev, skb);
1163 break; 1323 break;
1164 1324
1165 case HCI_EV_INQUIRY_RESULT_WITH_RSSI: 1325 case HCI_EV_CONN_COMPLETE:
1166 hci_inquiry_result_with_rssi_evt(hdev, skb); 1326 hci_conn_complete_evt(hdev, skb);
1167 break;
1168
1169 case HCI_EV_EXTENDED_INQUIRY_RESULT:
1170 hci_extended_inquiry_result_evt(hdev, skb);
1171 break; 1327 break;
1172 1328
1173 case HCI_EV_CONN_REQUEST: 1329 case HCI_EV_CONN_REQUEST:
1174 hci_conn_request_evt(hdev, skb); 1330 hci_conn_request_evt(hdev, skb);
1175 break; 1331 break;
1176 1332
1177 case HCI_EV_CONN_COMPLETE:
1178 hci_conn_complete_evt(hdev, skb);
1179 break;
1180
1181 case HCI_EV_DISCONN_COMPLETE: 1333 case HCI_EV_DISCONN_COMPLETE:
1182 hci_disconn_complete_evt(hdev, skb); 1334 hci_disconn_complete_evt(hdev, skb);
1183 break; 1335 break;
1184 1336
1185 case HCI_EV_ROLE_CHANGE:
1186 hci_role_change_evt(hdev, skb);
1187 break;
1188
1189 case HCI_EV_MODE_CHANGE:
1190 hci_mode_change_evt(hdev, skb);
1191 break;
1192
1193 case HCI_EV_AUTH_COMPLETE: 1337 case HCI_EV_AUTH_COMPLETE:
1194 hci_auth_complete_evt(hdev, skb); 1338 hci_auth_complete_evt(hdev, skb);
1195 break; 1339 break;
1196 1340
1341 case HCI_EV_REMOTE_NAME:
1342 hci_remote_name_evt(hdev, skb);
1343 break;
1344
1197 case HCI_EV_ENCRYPT_CHANGE: 1345 case HCI_EV_ENCRYPT_CHANGE:
1198 hci_encrypt_change_evt(hdev, skb); 1346 hci_encrypt_change_evt(hdev, skb);
1199 break; 1347 break;
1200 1348
1201 case HCI_EV_CHANGE_CONN_LINK_KEY_COMPLETE: 1349 case HCI_EV_CHANGE_LINK_KEY_COMPLETE:
1202 hci_change_conn_link_key_complete_evt(hdev, skb); 1350 hci_change_link_key_complete_evt(hdev, skb);
1351 break;
1352
1353 case HCI_EV_REMOTE_FEATURES:
1354 hci_remote_features_evt(hdev, skb);
1355 break;
1356
1357 case HCI_EV_REMOTE_VERSION:
1358 hci_remote_version_evt(hdev, skb);
1359 break;
1360
1361 case HCI_EV_QOS_SETUP_COMPLETE:
1362 hci_qos_setup_complete_evt(hdev, skb);
1363 break;
1364
1365 case HCI_EV_CMD_COMPLETE:
1366 hci_cmd_complete_evt(hdev, skb);
1367 break;
1368
1369 case HCI_EV_CMD_STATUS:
1370 hci_cmd_status_evt(hdev, skb);
1371 break;
1372
1373 case HCI_EV_ROLE_CHANGE:
1374 hci_role_change_evt(hdev, skb);
1375 break;
1376
1377 case HCI_EV_NUM_COMP_PKTS:
1378 hci_num_comp_pkts_evt(hdev, skb);
1379 break;
1380
1381 case HCI_EV_MODE_CHANGE:
1382 hci_mode_change_evt(hdev, skb);
1203 break; 1383 break;
1204 1384
1205 case HCI_EV_PIN_CODE_REQ: 1385 case HCI_EV_PIN_CODE_REQ:
@@ -1214,10 +1394,6 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
1214 hci_link_key_notify_evt(hdev, skb); 1394 hci_link_key_notify_evt(hdev, skb);
1215 break; 1395 break;
1216 1396
1217 case HCI_EV_REMOTE_FEATURES:
1218 hci_remote_features_evt(hdev, skb);
1219 break;
1220
1221 case HCI_EV_CLOCK_OFFSET: 1397 case HCI_EV_CLOCK_OFFSET:
1222 hci_clock_offset_evt(hdev, skb); 1398 hci_clock_offset_evt(hdev, skb);
1223 break; 1399 break;
@@ -1226,82 +1402,32 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
1226 hci_pscan_rep_mode_evt(hdev, skb); 1402 hci_pscan_rep_mode_evt(hdev, skb);
1227 break; 1403 break;
1228 1404
1229 case HCI_EV_SNIFF_SUBRATE: 1405 case HCI_EV_INQUIRY_RESULT_WITH_RSSI:
1230 hci_sniff_subrate_evt(hdev, skb); 1406 hci_inquiry_result_with_rssi_evt(hdev, skb);
1231 break; 1407 break;
1232 1408
1233 case HCI_EV_CMD_STATUS: 1409 case HCI_EV_REMOTE_EXT_FEATURES:
1234 cs = (struct hci_ev_cmd_status *) skb->data; 1410 hci_remote_ext_features_evt(hdev, skb);
1235 skb_pull(skb, sizeof(cs));
1236
1237 opcode = __le16_to_cpu(cs->opcode);
1238 ogf = hci_opcode_ogf(opcode);
1239 ocf = hci_opcode_ocf(opcode);
1240
1241 switch (ogf) {
1242 case OGF_INFO_PARAM:
1243 hci_cs_info_param(hdev, ocf, cs->status);
1244 break;
1245
1246 case OGF_HOST_CTL:
1247 hci_cs_host_ctl(hdev, ocf, cs->status);
1248 break;
1249
1250 case OGF_LINK_CTL:
1251 hci_cs_link_ctl(hdev, ocf, cs->status);
1252 break;
1253
1254 case OGF_LINK_POLICY:
1255 hci_cs_link_policy(hdev, ocf, cs->status);
1256 break;
1257
1258 default:
1259 BT_DBG("%s Command Status OGF %x", hdev->name, ogf);
1260 break;
1261 }
1262
1263 if (cs->ncmd) {
1264 atomic_set(&hdev->cmd_cnt, 1);
1265 if (!skb_queue_empty(&hdev->cmd_q))
1266 hci_sched_cmd(hdev);
1267 }
1268 break; 1411 break;
1269 1412
1270 case HCI_EV_CMD_COMPLETE: 1413 case HCI_EV_SYNC_CONN_COMPLETE:
1271 ec = (struct hci_ev_cmd_complete *) skb->data; 1414 hci_sync_conn_complete_evt(hdev, skb);
1272 skb_pull(skb, sizeof(*ec)); 1415 break;
1273
1274 opcode = __le16_to_cpu(ec->opcode);
1275 ogf = hci_opcode_ogf(opcode);
1276 ocf = hci_opcode_ocf(opcode);
1277
1278 switch (ogf) {
1279 case OGF_INFO_PARAM:
1280 hci_cc_info_param(hdev, ocf, skb);
1281 break;
1282
1283 case OGF_HOST_CTL:
1284 hci_cc_host_ctl(hdev, ocf, skb);
1285 break;
1286 1416
1287 case OGF_LINK_CTL: 1417 case HCI_EV_SYNC_CONN_CHANGED:
1288 hci_cc_link_ctl(hdev, ocf, skb); 1418 hci_sync_conn_changed_evt(hdev, skb);
1289 break; 1419 break;
1290 1420
1291 case OGF_LINK_POLICY: 1421 case HCI_EV_SNIFF_SUBRATE:
1292 hci_cc_link_policy(hdev, ocf, skb); 1422 hci_sniff_subrate_evt(hdev, skb);
1293 break; 1423 break;
1294 1424
1295 default: 1425 case HCI_EV_EXTENDED_INQUIRY_RESULT:
1296 BT_DBG("%s Command Completed OGF %x", hdev->name, ogf); 1426 hci_extended_inquiry_result_evt(hdev, skb);
1297 break; 1427 break;
1298 }
1299 1428
1300 if (ec->ncmd) { 1429 default:
1301 atomic_set(&hdev->cmd_cnt, 1); 1430 BT_DBG("%s event 0x%x", hdev->name, event);
1302 if (!skb_queue_empty(&hdev->cmd_q))
1303 hci_sched_cmd(hdev);
1304 }
1305 break; 1431 break;
1306 } 1432 }
1307 1433
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 43dd6373bff9..8825102c517c 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -451,7 +451,7 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
451 goto drop; 451 goto drop;
452 } 452 }
453 453
454 if (test_bit(HCI_RAW, &hdev->flags) || (ogf == OGF_VENDOR_CMD)) { 454 if (test_bit(HCI_RAW, &hdev->flags) || (ogf == 0x3f)) {
455 skb_queue_tail(&hdev->raw_q, skb); 455 skb_queue_tail(&hdev->raw_q, skb);
456 hci_sched_tx(hdev); 456 hci_sched_tx(hdev);
457 } else { 457 } else {
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 25835403d659..cef1e3e1881c 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -41,6 +41,26 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, char
41 return sprintf(buf, "%s\n", typetostr(hdev->type)); 41 return sprintf(buf, "%s\n", typetostr(hdev->type));
42} 42}
43 43
44static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
45{
46 struct hci_dev *hdev = dev_get_drvdata(dev);
47 char name[249];
48 int i;
49
50 for (i = 0; i < 248; i++)
51 name[i] = hdev->dev_name[i];
52
53 name[248] = '\0';
54 return sprintf(buf, "%s\n", name);
55}
56
57static ssize_t show_class(struct device *dev, struct device_attribute *attr, char *buf)
58{
59 struct hci_dev *hdev = dev_get_drvdata(dev);
60 return sprintf(buf, "0x%.2x%.2x%.2x\n",
61 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
62}
63
44static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf) 64static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf)
45{ 65{
46 struct hci_dev *hdev = dev_get_drvdata(dev); 66 struct hci_dev *hdev = dev_get_drvdata(dev);
@@ -49,6 +69,17 @@ static ssize_t show_address(struct device *dev, struct device_attribute *attr, c
49 return sprintf(buf, "%s\n", batostr(&bdaddr)); 69 return sprintf(buf, "%s\n", batostr(&bdaddr));
50} 70}
51 71
72static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf)
73{
74 struct hci_dev *hdev = dev_get_drvdata(dev);
75
76 return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
77 hdev->features[0], hdev->features[1],
78 hdev->features[2], hdev->features[3],
79 hdev->features[4], hdev->features[5],
80 hdev->features[6], hdev->features[7]);
81}
82
52static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf) 83static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf)
53{ 84{
54 struct hci_dev *hdev = dev_get_drvdata(dev); 85 struct hci_dev *hdev = dev_get_drvdata(dev);
@@ -170,7 +201,10 @@ static ssize_t store_sniff_min_interval(struct device *dev, struct device_attrib
170} 201}
171 202
172static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); 203static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
204static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
205static DEVICE_ATTR(class, S_IRUGO, show_class, NULL);
173static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); 206static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
207static DEVICE_ATTR(features, S_IRUGO, show_features, NULL);
174static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL); 208static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL);
175static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL); 209static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
176static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL); 210static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
@@ -185,7 +219,10 @@ static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
185 219
186static struct device_attribute *bt_attrs[] = { 220static struct device_attribute *bt_attrs[] = {
187 &dev_attr_type, 221 &dev_attr_type,
222 &dev_attr_name,
223 &dev_attr_class,
188 &dev_attr_address, 224 &dev_attr_address,
225 &dev_attr_features,
189 &dev_attr_manufacturer, 226 &dev_attr_manufacturer,
190 &dev_attr_hci_version, 227 &dev_attr_hci_version,
191 &dev_attr_hci_revision, 228 &dev_attr_hci_revision,