aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/bluetooth/hci_bcsp.c3
-rw-r--r--include/net/bluetooth/hci.h604
-rw-r--r--include/net/bluetooth/hci_core.h12
-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
8 files changed, 1315 insertions, 1032 deletions
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index d66064ccb31c..696f7528f022 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -237,7 +237,8 @@ static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data,
237 if (hciextn && chan == 5) { 237 if (hciextn && chan == 5) {
238 struct hci_command_hdr *hdr = (struct hci_command_hdr *) data; 238 struct hci_command_hdr *hdr = (struct hci_command_hdr *) data;
239 239
240 if (hci_opcode_ogf(__le16_to_cpu(hdr->opcode)) == OGF_VENDOR_CMD) { 240 /* Vendor specific commands */
241 if (hci_opcode_ogf(__le16_to_cpu(hdr->opcode)) == 0x3f) {
241 u8 desc = *(data + HCI_COMMAND_HDR_SIZE); 242 u8 desc = *(data + HCI_COMMAND_HDR_SIZE);
242 if ((desc & 0xf0) == 0xc0) { 243 if ((desc & 0xf0) == 0xc0) {
243 data += HCI_COMMAND_HDR_SIZE + 1; 244 data += HCI_COMMAND_HDR_SIZE + 1;
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ebfb96b41106..a8a9eb6af966 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -200,119 +200,18 @@ enum {
200#define HCI_LM_SECURE 0x0020 200#define HCI_LM_SECURE 0x0020
201 201
202/* ----- HCI Commands ---- */ 202/* ----- HCI Commands ---- */
203/* OGF & OCF values */ 203#define HCI_OP_INQUIRY 0x0401
204 204struct hci_cp_inquiry {
205/* Informational Parameters */ 205 __u8 lap[3];
206#define OGF_INFO_PARAM 0x04 206 __u8 length;
207 207 __u8 num_rsp;
208#define OCF_READ_LOCAL_VERSION 0x0001
209struct hci_rp_read_loc_version {
210 __u8 status;
211 __u8 hci_ver;
212 __le16 hci_rev;
213 __u8 lmp_ver;
214 __le16 manufacturer;
215 __le16 lmp_subver;
216} __attribute__ ((packed));
217
218#define OCF_READ_LOCAL_FEATURES 0x0003
219struct hci_rp_read_local_features {
220 __u8 status;
221 __u8 features[8];
222} __attribute__ ((packed));
223
224#define OCF_READ_BUFFER_SIZE 0x0005
225struct hci_rp_read_buffer_size {
226 __u8 status;
227 __le16 acl_mtu;
228 __u8 sco_mtu;
229 __le16 acl_max_pkt;
230 __le16 sco_max_pkt;
231} __attribute__ ((packed));
232
233#define OCF_READ_BD_ADDR 0x0009
234struct hci_rp_read_bd_addr {
235 __u8 status;
236 bdaddr_t bdaddr;
237} __attribute__ ((packed));
238
239/* Host Controller and Baseband */
240#define OGF_HOST_CTL 0x03
241#define OCF_RESET 0x0003
242#define OCF_READ_AUTH_ENABLE 0x001F
243#define OCF_WRITE_AUTH_ENABLE 0x0020
244 #define AUTH_DISABLED 0x00
245 #define AUTH_ENABLED 0x01
246
247#define OCF_READ_ENCRYPT_MODE 0x0021
248#define OCF_WRITE_ENCRYPT_MODE 0x0022
249 #define ENCRYPT_DISABLED 0x00
250 #define ENCRYPT_P2P 0x01
251 #define ENCRYPT_BOTH 0x02
252
253#define OCF_WRITE_CA_TIMEOUT 0x0016
254#define OCF_WRITE_PG_TIMEOUT 0x0018
255
256#define OCF_WRITE_SCAN_ENABLE 0x001A
257 #define SCAN_DISABLED 0x00
258 #define SCAN_INQUIRY 0x01
259 #define SCAN_PAGE 0x02
260
261#define OCF_SET_EVENT_FLT 0x0005
262struct hci_cp_set_event_flt {
263 __u8 flt_type;
264 __u8 cond_type;
265 __u8 condition[0];
266} __attribute__ ((packed));
267
268/* Filter types */
269#define HCI_FLT_CLEAR_ALL 0x00
270#define HCI_FLT_INQ_RESULT 0x01
271#define HCI_FLT_CONN_SETUP 0x02
272
273/* CONN_SETUP Condition types */
274#define HCI_CONN_SETUP_ALLOW_ALL 0x00
275#define HCI_CONN_SETUP_ALLOW_CLASS 0x01
276#define HCI_CONN_SETUP_ALLOW_BDADDR 0x02
277
278/* CONN_SETUP Conditions */
279#define HCI_CONN_SETUP_AUTO_OFF 0x01
280#define HCI_CONN_SETUP_AUTO_ON 0x02
281
282#define OCF_READ_CLASS_OF_DEV 0x0023
283struct hci_rp_read_dev_class {
284 __u8 status;
285 __u8 dev_class[3];
286} __attribute__ ((packed));
287
288#define OCF_WRITE_CLASS_OF_DEV 0x0024
289struct hci_cp_write_dev_class {
290 __u8 dev_class[3];
291} __attribute__ ((packed));
292
293#define OCF_READ_VOICE_SETTING 0x0025
294struct hci_rp_read_voice_setting {
295 __u8 status;
296 __le16 voice_setting;
297} __attribute__ ((packed)); 208} __attribute__ ((packed));
298 209
299#define OCF_WRITE_VOICE_SETTING 0x0026 210#define HCI_OP_INQUIRY_CANCEL 0x0402
300struct hci_cp_write_voice_setting {
301 __le16 voice_setting;
302} __attribute__ ((packed));
303 211
304#define OCF_HOST_BUFFER_SIZE 0x0033 212#define HCI_OP_EXIT_PERIODIC_INQ 0x0404
305struct hci_cp_host_buffer_size {
306 __le16 acl_mtu;
307 __u8 sco_mtu;
308 __le16 acl_max_pkt;
309 __le16 sco_max_pkt;
310} __attribute__ ((packed));
311
312/* Link Control */
313#define OGF_LINK_CTL 0x01
314 213
315#define OCF_CREATE_CONN 0x0005 214#define HCI_OP_CREATE_CONN 0x0405
316struct hci_cp_create_conn { 215struct hci_cp_create_conn {
317 bdaddr_t bdaddr; 216 bdaddr_t bdaddr;
318 __le16 pkt_type; 217 __le16 pkt_type;
@@ -322,105 +221,138 @@ struct hci_cp_create_conn {
322 __u8 role_switch; 221 __u8 role_switch;
323} __attribute__ ((packed)); 222} __attribute__ ((packed));
324 223
325#define OCF_CREATE_CONN_CANCEL 0x0008 224#define HCI_OP_DISCONNECT 0x0406
326struct hci_cp_create_conn_cancel {
327 bdaddr_t bdaddr;
328} __attribute__ ((packed));
329
330#define OCF_ACCEPT_CONN_REQ 0x0009
331struct hci_cp_accept_conn_req {
332 bdaddr_t bdaddr;
333 __u8 role;
334} __attribute__ ((packed));
335
336#define OCF_REJECT_CONN_REQ 0x000a
337struct hci_cp_reject_conn_req {
338 bdaddr_t bdaddr;
339 __u8 reason;
340} __attribute__ ((packed));
341
342#define OCF_DISCONNECT 0x0006
343struct hci_cp_disconnect { 225struct hci_cp_disconnect {
344 __le16 handle; 226 __le16 handle;
345 __u8 reason; 227 __u8 reason;
346} __attribute__ ((packed)); 228} __attribute__ ((packed));
347 229
348#define OCF_ADD_SCO 0x0007 230#define HCI_OP_ADD_SCO 0x0407
349struct hci_cp_add_sco { 231struct hci_cp_add_sco {
350 __le16 handle; 232 __le16 handle;
351 __le16 pkt_type; 233 __le16 pkt_type;
352} __attribute__ ((packed)); 234} __attribute__ ((packed));
353 235
354#define OCF_INQUIRY 0x0001 236#define HCI_OP_CREATE_CONN_CANCEL 0x0408
355struct hci_cp_inquiry { 237struct hci_cp_create_conn_cancel {
356 __u8 lap[3]; 238 bdaddr_t bdaddr;
357 __u8 length;
358 __u8 num_rsp;
359} __attribute__ ((packed)); 239} __attribute__ ((packed));
360 240
361#define OCF_INQUIRY_CANCEL 0x0002 241#define HCI_OP_ACCEPT_CONN_REQ 0x0409
242struct hci_cp_accept_conn_req {
243 bdaddr_t bdaddr;
244 __u8 role;
245} __attribute__ ((packed));
362 246
363#define OCF_EXIT_PERIODIC_INQ 0x0004 247#define HCI_OP_REJECT_CONN_REQ 0x040a
248struct hci_cp_reject_conn_req {
249 bdaddr_t bdaddr;
250 __u8 reason;
251} __attribute__ ((packed));
364 252
365#define OCF_LINK_KEY_REPLY 0x000B 253#define HCI_OP_LINK_KEY_REPLY 0x040b
366struct hci_cp_link_key_reply { 254struct hci_cp_link_key_reply {
367 bdaddr_t bdaddr; 255 bdaddr_t bdaddr;
368 __u8 link_key[16]; 256 __u8 link_key[16];
369} __attribute__ ((packed)); 257} __attribute__ ((packed));
370 258
371#define OCF_LINK_KEY_NEG_REPLY 0x000C 259#define HCI_OP_LINK_KEY_NEG_REPLY 0x040c
372struct hci_cp_link_key_neg_reply { 260struct hci_cp_link_key_neg_reply {
373 bdaddr_t bdaddr; 261 bdaddr_t bdaddr;
374} __attribute__ ((packed)); 262} __attribute__ ((packed));
375 263
376#define OCF_PIN_CODE_REPLY 0x000D 264#define HCI_OP_PIN_CODE_REPLY 0x040d
377struct hci_cp_pin_code_reply { 265struct hci_cp_pin_code_reply {
378 bdaddr_t bdaddr; 266 bdaddr_t bdaddr;
379 __u8 pin_len; 267 __u8 pin_len;
380 __u8 pin_code[16]; 268 __u8 pin_code[16];
381} __attribute__ ((packed)); 269} __attribute__ ((packed));
382 270
383#define OCF_PIN_CODE_NEG_REPLY 0x000E 271#define HCI_OP_PIN_CODE_NEG_REPLY 0x040e
384struct hci_cp_pin_code_neg_reply { 272struct hci_cp_pin_code_neg_reply {
385 bdaddr_t bdaddr; 273 bdaddr_t bdaddr;
386} __attribute__ ((packed)); 274} __attribute__ ((packed));
387 275
388#define OCF_CHANGE_CONN_PTYPE 0x000F 276#define HCI_OP_CHANGE_CONN_PTYPE 0x040f
389struct hci_cp_change_conn_ptype { 277struct hci_cp_change_conn_ptype {
390 __le16 handle; 278 __le16 handle;
391 __le16 pkt_type; 279 __le16 pkt_type;
392} __attribute__ ((packed)); 280} __attribute__ ((packed));
393 281
394#define OCF_AUTH_REQUESTED 0x0011 282#define HCI_OP_AUTH_REQUESTED 0x0411
395struct hci_cp_auth_requested { 283struct hci_cp_auth_requested {
396 __le16 handle; 284 __le16 handle;
397} __attribute__ ((packed)); 285} __attribute__ ((packed));
398 286
399#define OCF_SET_CONN_ENCRYPT 0x0013 287#define HCI_OP_SET_CONN_ENCRYPT 0x0413
400struct hci_cp_set_conn_encrypt { 288struct hci_cp_set_conn_encrypt {
401 __le16 handle; 289 __le16 handle;
402 __u8 encrypt; 290 __u8 encrypt;
403} __attribute__ ((packed)); 291} __attribute__ ((packed));
404 292
405#define OCF_CHANGE_CONN_LINK_KEY 0x0015 293#define HCI_OP_CHANGE_CONN_LINK_KEY 0x0415
406struct hci_cp_change_conn_link_key { 294struct hci_cp_change_conn_link_key {
407 __le16 handle; 295 __le16 handle;
408} __attribute__ ((packed)); 296} __attribute__ ((packed));
409 297
410#define OCF_READ_REMOTE_FEATURES 0x001B 298#define HCI_OP_REMOTE_NAME_REQ 0x0419
299struct hci_cp_remote_name_req {
300 bdaddr_t bdaddr;
301 __u8 pscan_rep_mode;
302 __u8 pscan_mode;
303 __le16 clock_offset;
304} __attribute__ ((packed));
305
306#define HCI_OP_REMOTE_NAME_REQ_CANCEL 0x041a
307struct hci_cp_remote_name_req_cancel {
308 bdaddr_t bdaddr;
309} __attribute__ ((packed));
310
311#define HCI_OP_READ_REMOTE_FEATURES 0x041b
411struct hci_cp_read_remote_features { 312struct hci_cp_read_remote_features {
412 __le16 handle; 313 __le16 handle;
413} __attribute__ ((packed)); 314} __attribute__ ((packed));
414 315
415#define OCF_READ_REMOTE_VERSION 0x001D 316#define HCI_OP_READ_REMOTE_EXT_FEATURES 0x041c
317struct hci_cp_read_remote_ext_features {
318 __le16 handle;
319 __u8 page;
320} __attribute__ ((packed));
321
322#define HCI_OP_READ_REMOTE_VERSION 0x041d
416struct hci_cp_read_remote_version { 323struct hci_cp_read_remote_version {
417 __le16 handle; 324 __le16 handle;
418} __attribute__ ((packed)); 325} __attribute__ ((packed));
419 326
420/* Link Policy */ 327#define HCI_OP_SETUP_SYNC_CONN 0x0428
421#define OGF_LINK_POLICY 0x02 328struct hci_cp_setup_sync_conn {
329 __le16 handle;
330 __le32 tx_bandwidth;
331 __le32 rx_bandwidth;
332 __le16 max_latency;
333 __le16 voice_setting;
334 __u8 retrans_effort;
335 __le16 pkt_type;
336} __attribute__ ((packed));
422 337
423#define OCF_SNIFF_MODE 0x0003 338#define HCI_OP_ACCEPT_SYNC_CONN_REQ 0x0429
339struct hci_cp_accept_sync_conn_req {
340 bdaddr_t bdaddr;
341 __le32 tx_bandwidth;
342 __le32 rx_bandwidth;
343 __le16 max_latency;
344 __le16 content_format;
345 __u8 retrans_effort;
346 __le16 pkt_type;
347} __attribute__ ((packed));
348
349#define HCI_OP_REJECT_SYNC_CONN_REQ 0x042a
350struct hci_cp_reject_sync_conn_req {
351 bdaddr_t bdaddr;
352 __u8 reason;
353} __attribute__ ((packed));
354
355#define HCI_OP_SNIFF_MODE 0x0803
424struct hci_cp_sniff_mode { 356struct hci_cp_sniff_mode {
425 __le16 handle; 357 __le16 handle;
426 __le16 max_interval; 358 __le16 max_interval;
@@ -429,12 +361,12 @@ struct hci_cp_sniff_mode {
429 __le16 timeout; 361 __le16 timeout;
430} __attribute__ ((packed)); 362} __attribute__ ((packed));
431 363
432#define OCF_EXIT_SNIFF_MODE 0x0004 364#define HCI_OP_EXIT_SNIFF_MODE 0x0804
433struct hci_cp_exit_sniff_mode { 365struct hci_cp_exit_sniff_mode {
434 __le16 handle; 366 __le16 handle;
435} __attribute__ ((packed)); 367} __attribute__ ((packed));
436 368
437#define OCF_ROLE_DISCOVERY 0x0009 369#define HCI_OP_ROLE_DISCOVERY 0x0809
438struct hci_cp_role_discovery { 370struct hci_cp_role_discovery {
439 __le16 handle; 371 __le16 handle;
440} __attribute__ ((packed)); 372} __attribute__ ((packed));
@@ -444,7 +376,13 @@ struct hci_rp_role_discovery {
444 __u8 role; 376 __u8 role;
445} __attribute__ ((packed)); 377} __attribute__ ((packed));
446 378
447#define OCF_READ_LINK_POLICY 0x000C 379#define HCI_OP_SWITCH_ROLE 0x080b
380struct hci_cp_switch_role {
381 bdaddr_t bdaddr;
382 __u8 role;
383} __attribute__ ((packed));
384
385#define HCI_OP_READ_LINK_POLICY 0x080c
448struct hci_cp_read_link_policy { 386struct hci_cp_read_link_policy {
449 __le16 handle; 387 __le16 handle;
450} __attribute__ ((packed)); 388} __attribute__ ((packed));
@@ -454,13 +392,7 @@ struct hci_rp_read_link_policy {
454 __le16 policy; 392 __le16 policy;
455} __attribute__ ((packed)); 393} __attribute__ ((packed));
456 394
457#define OCF_SWITCH_ROLE 0x000B 395#define HCI_OP_WRITE_LINK_POLICY 0x080d
458struct hci_cp_switch_role {
459 bdaddr_t bdaddr;
460 __u8 role;
461} __attribute__ ((packed));
462
463#define OCF_WRITE_LINK_POLICY 0x000D
464struct hci_cp_write_link_policy { 396struct hci_cp_write_link_policy {
465 __le16 handle; 397 __le16 handle;
466 __le16 policy; 398 __le16 policy;
@@ -470,7 +402,7 @@ struct hci_rp_write_link_policy {
470 __le16 handle; 402 __le16 handle;
471} __attribute__ ((packed)); 403} __attribute__ ((packed));
472 404
473#define OCF_SNIFF_SUBRATE 0x0011 405#define HCI_OP_SNIFF_SUBRATE 0x0811
474struct hci_cp_sniff_subrate { 406struct hci_cp_sniff_subrate {
475 __le16 handle; 407 __le16 handle;
476 __le16 max_latency; 408 __le16 max_latency;
@@ -478,59 +410,156 @@ struct hci_cp_sniff_subrate {
478 __le16 min_local_timeout; 410 __le16 min_local_timeout;
479} __attribute__ ((packed)); 411} __attribute__ ((packed));
480 412
481/* Status params */ 413#define HCI_OP_SET_EVENT_MASK 0x0c01
482#define OGF_STATUS_PARAM 0x05 414struct hci_cp_set_event_mask {
415 __u8 mask[8];
416} __attribute__ ((packed));
483 417
484/* Testing commands */ 418#define HCI_OP_RESET 0x0c03
485#define OGF_TESTING_CMD 0x3E
486 419
487/* Vendor specific commands */ 420#define HCI_OP_SET_EVENT_FLT 0x0c05
488#define OGF_VENDOR_CMD 0x3F 421struct hci_cp_set_event_flt {
422 __u8 flt_type;
423 __u8 cond_type;
424 __u8 condition[0];
425} __attribute__ ((packed));
489 426
490/* ---- HCI Events ---- */ 427/* Filter types */
491#define HCI_EV_INQUIRY_COMPLETE 0x01 428#define HCI_FLT_CLEAR_ALL 0x00
429#define HCI_FLT_INQ_RESULT 0x01
430#define HCI_FLT_CONN_SETUP 0x02
492 431
493#define HCI_EV_INQUIRY_RESULT 0x02 432/* CONN_SETUP Condition types */
494struct inquiry_info { 433#define HCI_CONN_SETUP_ALLOW_ALL 0x00
495 bdaddr_t bdaddr; 434#define HCI_CONN_SETUP_ALLOW_CLASS 0x01
496 __u8 pscan_rep_mode; 435#define HCI_CONN_SETUP_ALLOW_BDADDR 0x02
497 __u8 pscan_period_mode; 436
498 __u8 pscan_mode; 437/* CONN_SETUP Conditions */
438#define HCI_CONN_SETUP_AUTO_OFF 0x01
439#define HCI_CONN_SETUP_AUTO_ON 0x02
440
441#define HCI_OP_WRITE_LOCAL_NAME 0x0c13
442struct hci_cp_write_local_name {
443 __u8 name[248];
444} __attribute__ ((packed));
445
446#define HCI_OP_READ_LOCAL_NAME 0x0c14
447struct hci_rp_read_local_name {
448 __u8 status;
449 __u8 name[248];
450} __attribute__ ((packed));
451
452#define HCI_OP_WRITE_CA_TIMEOUT 0x0c16
453
454#define HCI_OP_WRITE_PG_TIMEOUT 0x0c18
455
456#define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a
457 #define SCAN_DISABLED 0x00
458 #define SCAN_INQUIRY 0x01
459 #define SCAN_PAGE 0x02
460
461#define HCI_OP_READ_AUTH_ENABLE 0x0c1f
462
463#define HCI_OP_WRITE_AUTH_ENABLE 0x0c20
464 #define AUTH_DISABLED 0x00
465 #define AUTH_ENABLED 0x01
466
467#define HCI_OP_READ_ENCRYPT_MODE 0x0c21
468
469#define HCI_OP_WRITE_ENCRYPT_MODE 0x0c22
470 #define ENCRYPT_DISABLED 0x00
471 #define ENCRYPT_P2P 0x01
472 #define ENCRYPT_BOTH 0x02
473
474#define HCI_OP_READ_CLASS_OF_DEV 0x0c23
475struct hci_rp_read_class_of_dev {
476 __u8 status;
499 __u8 dev_class[3]; 477 __u8 dev_class[3];
500 __le16 clock_offset;
501} __attribute__ ((packed)); 478} __attribute__ ((packed));
502 479
503#define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x22 480#define HCI_OP_WRITE_CLASS_OF_DEV 0x0c24
504struct inquiry_info_with_rssi { 481struct hci_cp_write_class_of_dev {
505 bdaddr_t bdaddr;
506 __u8 pscan_rep_mode;
507 __u8 pscan_period_mode;
508 __u8 dev_class[3]; 482 __u8 dev_class[3];
509 __le16 clock_offset;
510 __s8 rssi;
511} __attribute__ ((packed)); 483} __attribute__ ((packed));
512struct inquiry_info_with_rssi_and_pscan_mode { 484
485#define HCI_OP_READ_VOICE_SETTING 0x0c25
486struct hci_rp_read_voice_setting {
487 __u8 status;
488 __le16 voice_setting;
489} __attribute__ ((packed));
490
491#define HCI_OP_WRITE_VOICE_SETTING 0x0c26
492struct hci_cp_write_voice_setting {
493 __le16 voice_setting;
494} __attribute__ ((packed));
495
496#define HCI_OP_HOST_BUFFER_SIZE 0x0c33
497struct hci_cp_host_buffer_size {
498 __le16 acl_mtu;
499 __u8 sco_mtu;
500 __le16 acl_max_pkt;
501 __le16 sco_max_pkt;
502} __attribute__ ((packed));
503
504#define HCI_OP_READ_LOCAL_VERSION 0x1001
505struct hci_rp_read_local_version {
506 __u8 status;
507 __u8 hci_ver;
508 __le16 hci_rev;
509 __u8 lmp_ver;
510 __le16 manufacturer;
511 __le16 lmp_subver;
512} __attribute__ ((packed));
513
514#define HCI_OP_READ_LOCAL_COMMANDS 0x1002
515struct hci_rp_read_local_commands {
516 __u8 status;
517 __u8 commands[64];
518} __attribute__ ((packed));
519
520#define HCI_OP_READ_LOCAL_FEATURES 0x1003
521struct hci_rp_read_local_features {
522 __u8 status;
523 __u8 features[8];
524} __attribute__ ((packed));
525
526#define HCI_OP_READ_LOCAL_EXT_FEATURES 0x1004
527struct hci_rp_read_local_ext_features {
528 __u8 status;
529 __u8 page;
530 __u8 max_page;
531 __u8 features[8];
532} __attribute__ ((packed));
533
534#define HCI_OP_READ_BUFFER_SIZE 0x1005
535struct hci_rp_read_buffer_size {
536 __u8 status;
537 __le16 acl_mtu;
538 __u8 sco_mtu;
539 __le16 acl_max_pkt;
540 __le16 sco_max_pkt;
541} __attribute__ ((packed));
542
543#define HCI_OP_READ_BD_ADDR 0x1009
544struct hci_rp_read_bd_addr {
545 __u8 status;
513 bdaddr_t bdaddr; 546 bdaddr_t bdaddr;
514 __u8 pscan_rep_mode;
515 __u8 pscan_period_mode;
516 __u8 pscan_mode;
517 __u8 dev_class[3];
518 __le16 clock_offset;
519 __s8 rssi;
520} __attribute__ ((packed)); 547} __attribute__ ((packed));
521 548
522#define HCI_EV_EXTENDED_INQUIRY_RESULT 0x2F 549/* ---- HCI Events ---- */
523struct extended_inquiry_info { 550#define HCI_EV_INQUIRY_COMPLETE 0x01
551
552#define HCI_EV_INQUIRY_RESULT 0x02
553struct inquiry_info {
524 bdaddr_t bdaddr; 554 bdaddr_t bdaddr;
525 __u8 pscan_rep_mode; 555 __u8 pscan_rep_mode;
526 __u8 pscan_period_mode; 556 __u8 pscan_period_mode;
557 __u8 pscan_mode;
527 __u8 dev_class[3]; 558 __u8 dev_class[3];
528 __le16 clock_offset; 559 __le16 clock_offset;
529 __s8 rssi;
530 __u8 data[240];
531} __attribute__ ((packed)); 560} __attribute__ ((packed));
532 561
533#define HCI_EV_CONN_COMPLETE 0x03 562#define HCI_EV_CONN_COMPLETE 0x03
534struct hci_ev_conn_complete { 563struct hci_ev_conn_complete {
535 __u8 status; 564 __u8 status;
536 __le16 handle; 565 __le16 handle;
@@ -539,40 +568,63 @@ struct hci_ev_conn_complete {
539 __u8 encr_mode; 568 __u8 encr_mode;
540} __attribute__ ((packed)); 569} __attribute__ ((packed));
541 570
542#define HCI_EV_CONN_REQUEST 0x04 571#define HCI_EV_CONN_REQUEST 0x04
543struct hci_ev_conn_request { 572struct hci_ev_conn_request {
544 bdaddr_t bdaddr; 573 bdaddr_t bdaddr;
545 __u8 dev_class[3]; 574 __u8 dev_class[3];
546 __u8 link_type; 575 __u8 link_type;
547} __attribute__ ((packed)); 576} __attribute__ ((packed));
548 577
549#define HCI_EV_DISCONN_COMPLETE 0x05 578#define HCI_EV_DISCONN_COMPLETE 0x05
550struct hci_ev_disconn_complete { 579struct hci_ev_disconn_complete {
551 __u8 status; 580 __u8 status;
552 __le16 handle; 581 __le16 handle;
553 __u8 reason; 582 __u8 reason;
554} __attribute__ ((packed)); 583} __attribute__ ((packed));
555 584
556#define HCI_EV_AUTH_COMPLETE 0x06 585#define HCI_EV_AUTH_COMPLETE 0x06
557struct hci_ev_auth_complete { 586struct hci_ev_auth_complete {
558 __u8 status; 587 __u8 status;
559 __le16 handle; 588 __le16 handle;
560} __attribute__ ((packed)); 589} __attribute__ ((packed));
561 590
562#define HCI_EV_ENCRYPT_CHANGE 0x08 591#define HCI_EV_REMOTE_NAME 0x07
592struct hci_ev_remote_name {
593 __u8 status;
594 bdaddr_t bdaddr;
595 __u8 name[248];
596} __attribute__ ((packed));
597
598#define HCI_EV_ENCRYPT_CHANGE 0x08
563struct hci_ev_encrypt_change { 599struct hci_ev_encrypt_change {
564 __u8 status; 600 __u8 status;
565 __le16 handle; 601 __le16 handle;
566 __u8 encrypt; 602 __u8 encrypt;
567} __attribute__ ((packed)); 603} __attribute__ ((packed));
568 604
569#define HCI_EV_CHANGE_CONN_LINK_KEY_COMPLETE 0x09 605#define HCI_EV_CHANGE_LINK_KEY_COMPLETE 0x09
570struct hci_ev_change_conn_link_key_complete { 606struct hci_ev_change_link_key_complete {
607 __u8 status;
608 __le16 handle;
609} __attribute__ ((packed));
610
611#define HCI_EV_REMOTE_FEATURES 0x0b
612struct hci_ev_remote_features {
613 __u8 status;
614 __le16 handle;
615 __u8 features[8];
616} __attribute__ ((packed));
617
618#define HCI_EV_REMOTE_VERSION 0x0c
619struct hci_ev_remote_version {
571 __u8 status; 620 __u8 status;
572 __le16 handle; 621 __le16 handle;
622 __u8 lmp_ver;
623 __le16 manufacturer;
624 __le16 lmp_subver;
573} __attribute__ ((packed)); 625} __attribute__ ((packed));
574 626
575#define HCI_EV_QOS_SETUP_COMPLETE 0x0D 627#define HCI_EV_QOS_SETUP_COMPLETE 0x0d
576struct hci_qos { 628struct hci_qos {
577 __u8 service_type; 629 __u8 service_type;
578 __u32 token_rate; 630 __u32 token_rate;
@@ -586,33 +638,33 @@ struct hci_ev_qos_setup_complete {
586 struct hci_qos qos; 638 struct hci_qos qos;
587} __attribute__ ((packed)); 639} __attribute__ ((packed));
588 640
589#define HCI_EV_CMD_COMPLETE 0x0E 641#define HCI_EV_CMD_COMPLETE 0x0e
590struct hci_ev_cmd_complete { 642struct hci_ev_cmd_complete {
591 __u8 ncmd; 643 __u8 ncmd;
592 __le16 opcode; 644 __le16 opcode;
593} __attribute__ ((packed)); 645} __attribute__ ((packed));
594 646
595#define HCI_EV_CMD_STATUS 0x0F 647#define HCI_EV_CMD_STATUS 0x0f
596struct hci_ev_cmd_status { 648struct hci_ev_cmd_status {
597 __u8 status; 649 __u8 status;
598 __u8 ncmd; 650 __u8 ncmd;
599 __le16 opcode; 651 __le16 opcode;
600} __attribute__ ((packed)); 652} __attribute__ ((packed));
601 653
602#define HCI_EV_NUM_COMP_PKTS 0x13 654#define HCI_EV_ROLE_CHANGE 0x12
603struct hci_ev_num_comp_pkts {
604 __u8 num_hndl;
605 /* variable length part */
606} __attribute__ ((packed));
607
608#define HCI_EV_ROLE_CHANGE 0x12
609struct hci_ev_role_change { 655struct hci_ev_role_change {
610 __u8 status; 656 __u8 status;
611 bdaddr_t bdaddr; 657 bdaddr_t bdaddr;
612 __u8 role; 658 __u8 role;
613} __attribute__ ((packed)); 659} __attribute__ ((packed));
614 660
615#define HCI_EV_MODE_CHANGE 0x14 661#define HCI_EV_NUM_COMP_PKTS 0x13
662struct hci_ev_num_comp_pkts {
663 __u8 num_hndl;
664 /* variable length part */
665} __attribute__ ((packed));
666
667#define HCI_EV_MODE_CHANGE 0x14
616struct hci_ev_mode_change { 668struct hci_ev_mode_change {
617 __u8 status; 669 __u8 status;
618 __le16 handle; 670 __le16 handle;
@@ -620,53 +672,88 @@ struct hci_ev_mode_change {
620 __le16 interval; 672 __le16 interval;
621} __attribute__ ((packed)); 673} __attribute__ ((packed));
622 674
623#define HCI_EV_PIN_CODE_REQ 0x16 675#define HCI_EV_PIN_CODE_REQ 0x16
624struct hci_ev_pin_code_req { 676struct hci_ev_pin_code_req {
625 bdaddr_t bdaddr; 677 bdaddr_t bdaddr;
626} __attribute__ ((packed)); 678} __attribute__ ((packed));
627 679
628#define HCI_EV_LINK_KEY_REQ 0x17 680#define HCI_EV_LINK_KEY_REQ 0x17
629struct hci_ev_link_key_req { 681struct hci_ev_link_key_req {
630 bdaddr_t bdaddr; 682 bdaddr_t bdaddr;
631} __attribute__ ((packed)); 683} __attribute__ ((packed));
632 684
633#define HCI_EV_LINK_KEY_NOTIFY 0x18 685#define HCI_EV_LINK_KEY_NOTIFY 0x18
634struct hci_ev_link_key_notify { 686struct hci_ev_link_key_notify {
635 bdaddr_t bdaddr; 687 bdaddr_t bdaddr;
636 __u8 link_key[16]; 688 __u8 link_key[16];
637 __u8 key_type; 689 __u8 key_type;
638} __attribute__ ((packed)); 690} __attribute__ ((packed));
639 691
640#define HCI_EV_REMOTE_FEATURES 0x0B 692#define HCI_EV_CLOCK_OFFSET 0x1c
641struct hci_ev_remote_features { 693struct hci_ev_clock_offset {
642 __u8 status; 694 __u8 status;
643 __le16 handle; 695 __le16 handle;
644 __u8 features[8]; 696 __le16 clock_offset;
645} __attribute__ ((packed)); 697} __attribute__ ((packed));
646 698
647#define HCI_EV_REMOTE_VERSION 0x0C 699#define HCI_EV_PSCAN_REP_MODE 0x20
648struct hci_ev_remote_version { 700struct hci_ev_pscan_rep_mode {
701 bdaddr_t bdaddr;
702 __u8 pscan_rep_mode;
703} __attribute__ ((packed));
704
705#define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x22
706struct inquiry_info_with_rssi {
707 bdaddr_t bdaddr;
708 __u8 pscan_rep_mode;
709 __u8 pscan_period_mode;
710 __u8 dev_class[3];
711 __le16 clock_offset;
712 __s8 rssi;
713} __attribute__ ((packed));
714struct inquiry_info_with_rssi_and_pscan_mode {
715 bdaddr_t bdaddr;
716 __u8 pscan_rep_mode;
717 __u8 pscan_period_mode;
718 __u8 pscan_mode;
719 __u8 dev_class[3];
720 __le16 clock_offset;
721 __s8 rssi;
722} __attribute__ ((packed));
723
724#define HCI_EV_REMOTE_EXT_FEATURES 0x23
725struct hci_ev_remote_ext_features {
649 __u8 status; 726 __u8 status;
650 __le16 handle; 727 __le16 handle;
651 __u8 lmp_ver; 728 __u8 page;
652 __le16 manufacturer; 729 __u8 max_page;
653 __le16 lmp_subver; 730 __u8 features[8];
654} __attribute__ ((packed)); 731} __attribute__ ((packed));
655 732
656#define HCI_EV_CLOCK_OFFSET 0x01C 733#define HCI_EV_SYNC_CONN_COMPLETE 0x2c
657struct hci_ev_clock_offset { 734struct hci_ev_sync_conn_complete {
658 __u8 status; 735 __u8 status;
659 __le16 handle; 736 __le16 handle;
660 __le16 clock_offset; 737 bdaddr_t bdaddr;
738 __u8 link_type;
739 __u8 tx_interval;
740 __u8 retrans_window;
741 __le16 rx_pkt_len;
742 __le16 tx_pkt_len;
743 __u8 air_mode;
661} __attribute__ ((packed)); 744} __attribute__ ((packed));
662 745
663#define HCI_EV_PSCAN_REP_MODE 0x20 746#define HCI_EV_SYNC_CONN_CHANGED 0x2d
664struct hci_ev_pscan_rep_mode { 747struct hci_ev_sync_conn_changed {
665 bdaddr_t bdaddr; 748 __u8 status;
666 __u8 pscan_rep_mode; 749 __le16 handle;
750 __u8 tx_interval;
751 __u8 retrans_window;
752 __le16 rx_pkt_len;
753 __le16 tx_pkt_len;
667} __attribute__ ((packed)); 754} __attribute__ ((packed));
668 755
669#define HCI_EV_SNIFF_SUBRATE 0x2E 756#define HCI_EV_SNIFF_SUBRATE 0x2e
670struct hci_ev_sniff_subrate { 757struct hci_ev_sniff_subrate {
671 __u8 status; 758 __u8 status;
672 __le16 handle; 759 __le16 handle;
@@ -676,14 +763,25 @@ struct hci_ev_sniff_subrate {
676 __le16 max_local_timeout; 763 __le16 max_local_timeout;
677} __attribute__ ((packed)); 764} __attribute__ ((packed));
678 765
766#define HCI_EV_EXTENDED_INQUIRY_RESULT 0x2f
767struct extended_inquiry_info {
768 bdaddr_t bdaddr;
769 __u8 pscan_rep_mode;
770 __u8 pscan_period_mode;
771 __u8 dev_class[3];
772 __le16 clock_offset;
773 __s8 rssi;
774 __u8 data[240];
775} __attribute__ ((packed));
776
679/* Internal events generated by Bluetooth stack */ 777/* Internal events generated by Bluetooth stack */
680#define HCI_EV_STACK_INTERNAL 0xFD 778#define HCI_EV_STACK_INTERNAL 0xfd
681struct hci_ev_stack_internal { 779struct hci_ev_stack_internal {
682 __u16 type; 780 __u16 type;
683 __u8 data[0]; 781 __u8 data[0];
684} __attribute__ ((packed)); 782} __attribute__ ((packed));
685 783
686#define HCI_EV_SI_DEVICE 0x01 784#define HCI_EV_SI_DEVICE 0x01
687struct hci_ev_si_device { 785struct hci_ev_si_device {
688 __u16 event; 786 __u16 event;
689 __u16 dev_id; 787 __u16 dev_id;
@@ -704,40 +802,40 @@ struct hci_ev_si_security {
704#define HCI_SCO_HDR_SIZE 3 802#define HCI_SCO_HDR_SIZE 3
705 803
706struct hci_command_hdr { 804struct hci_command_hdr {
707 __le16 opcode; /* OCF & OGF */ 805 __le16 opcode; /* OCF & OGF */
708 __u8 plen; 806 __u8 plen;
709} __attribute__ ((packed)); 807} __attribute__ ((packed));
710 808
711struct hci_event_hdr { 809struct hci_event_hdr {
712 __u8 evt; 810 __u8 evt;
713 __u8 plen; 811 __u8 plen;
714} __attribute__ ((packed)); 812} __attribute__ ((packed));
715 813
716struct hci_acl_hdr { 814struct hci_acl_hdr {
717 __le16 handle; /* Handle & Flags(PB, BC) */ 815 __le16 handle; /* Handle & Flags(PB, BC) */
718 __le16 dlen; 816 __le16 dlen;
719} __attribute__ ((packed)); 817} __attribute__ ((packed));
720 818
721struct hci_sco_hdr { 819struct hci_sco_hdr {
722 __le16 handle; 820 __le16 handle;
723 __u8 dlen; 821 __u8 dlen;
724} __attribute__ ((packed)); 822} __attribute__ ((packed));
725 823
726#ifdef __KERNEL__ 824#ifdef __KERNEL__
727#include <linux/skbuff.h> 825#include <linux/skbuff.h>
728static inline struct hci_event_hdr *hci_event_hdr(const struct sk_buff *skb) 826static inline struct hci_event_hdr *hci_event_hdr(const struct sk_buff *skb)
729{ 827{
730 return (struct hci_event_hdr *)skb->data; 828 return (struct hci_event_hdr *) skb->data;
731} 829}
732 830
733static inline struct hci_acl_hdr *hci_acl_hdr(const struct sk_buff *skb) 831static inline struct hci_acl_hdr *hci_acl_hdr(const struct sk_buff *skb)
734{ 832{
735 return (struct hci_acl_hdr *)skb->data; 833 return (struct hci_acl_hdr *) skb->data;
736} 834}
737 835
738static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb) 836static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb)
739{ 837{
740 return (struct hci_sco_hdr *)skb->data; 838 return (struct hci_sco_hdr *) skb->data;
741} 839}
742#endif 840#endif
743 841
@@ -771,13 +869,13 @@ struct sockaddr_hci {
771struct hci_filter { 869struct hci_filter {
772 unsigned long type_mask; 870 unsigned long type_mask;
773 unsigned long event_mask[2]; 871 unsigned long event_mask[2];
774 __le16 opcode; 872 __le16 opcode;
775}; 873};
776 874
777struct hci_ufilter { 875struct hci_ufilter {
778 __u32 type_mask; 876 __u32 type_mask;
779 __u32 event_mask[2]; 877 __u32 event_mask[2];
780 __le16 opcode; 878 __le16 opcode;
781}; 879};
782 880
783#define HCI_FLT_TYPE_BITS 31 881#define HCI_FLT_TYPE_BITS 31
@@ -825,15 +923,15 @@ struct hci_dev_info {
825struct hci_conn_info { 923struct hci_conn_info {
826 __u16 handle; 924 __u16 handle;
827 bdaddr_t bdaddr; 925 bdaddr_t bdaddr;
828 __u8 type; 926 __u8 type;
829 __u8 out; 927 __u8 out;
830 __u16 state; 928 __u16 state;
831 __u32 link_mode; 929 __u32 link_mode;
832}; 930};
833 931
834struct hci_dev_req { 932struct hci_dev_req {
835 __u16 dev_id; 933 __u16 dev_id;
836 __u32 dev_opt; 934 __u32 dev_opt;
837}; 935};
838 936
839struct hci_dev_list_req { 937struct hci_dev_list_req {
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 8f67c8a7169b..0db89ed6b00c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -71,7 +71,10 @@ struct hci_dev {
71 __u16 id; 71 __u16 id;
72 __u8 type; 72 __u8 type;
73 bdaddr_t bdaddr; 73 bdaddr_t bdaddr;
74 __u8 dev_name[248];
75 __u8 dev_class[3];
74 __u8 features[8]; 76 __u8 features[8];
77 __u8 commands[64];
75 __u8 hci_ver; 78 __u8 hci_ver;
76 __u16 hci_rev; 79 __u16 hci_rev;
77 __u16 manufacturer; 80 __u16 manufacturer;
@@ -312,8 +315,9 @@ void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
312void hci_add_sco(struct hci_conn *conn, __u16 handle); 315void hci_add_sco(struct hci_conn *conn, __u16 handle);
313 316
314struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst); 317struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
315int hci_conn_del(struct hci_conn *conn); 318int hci_conn_del(struct hci_conn *conn);
316void hci_conn_hash_flush(struct hci_dev *hdev); 319void hci_conn_hash_flush(struct hci_dev *hdev);
320void hci_conn_check_pending(struct hci_dev *hdev);
317 321
318struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *src); 322struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *src);
319int hci_conn_auth(struct hci_conn *conn); 323int hci_conn_auth(struct hci_conn *conn);
@@ -617,11 +621,11 @@ int hci_unregister_cb(struct hci_cb *hcb);
617int hci_register_notifier(struct notifier_block *nb); 621int hci_register_notifier(struct notifier_block *nb);
618int hci_unregister_notifier(struct notifier_block *nb); 622int hci_unregister_notifier(struct notifier_block *nb);
619 623
620int hci_send_cmd(struct hci_dev *hdev, __u16 ogf, __u16 ocf, __u32 plen, void *param); 624int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
621int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags); 625int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
622int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); 626int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
623 627
624void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 ogf, __u16 ocf); 628void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
625 629
626void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data); 630void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data);
627 631
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,