forked from PaulStoffregen/USBHost_t36
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetooth.cpp
1557 lines (1377 loc) · 60.9 KB
/
bluetooth.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* USB EHCI Host for Teensy 3.6
* Copyright 2017 Paul Stoffregen ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* information about the BlueTooth HCI comes from logic analyzer captures
* plus... http://affon.narod.ru/BT/bluetooth_app_c10.pdf
*/
#include <Arduino.h>
#include "USBHost_t36.h" // Read this header first for key info
#define print USBHost::print_
#define println USBHost::println_//#define DEBUG_BT
#define DEBUG_BT
//#define DEBUG_BT_VERBOSE
#ifndef DEBUG_BT
#undef DEBUG_BT_VERBOSE
void inline DBGPrintf(...) {};
#else
#define DBGPrintf USBHDBGSerial.printf
#endif
#ifndef DEBUG_BT_VERBOSE
void inline VDBGPrintf(...) {};
#else
#define VDBGPrintf USBHDBGSerial.printf
#endif
/************************************************************/
// Define HCI Commands OGF HIgh byte OCF is low byte...
// Actually shifted values...
/************************************************************/
#define HCI_INQUIRY 0x0401
#define HCI_INQUIRY_CANCEL 0x0402
#define HCI_CREATE_CONNECTION 0x0405
#define HCI_OP_ACCEPT_CONN_REQ 0x0409
#define HCI_LINK_KEY_NEG_REPLY 0x040C
#define HCI_PIN_CODE_REPLY 0x040D
#define HCI_AUTH_REQUESTED 0x0411
#define HCI_OP_REMOTE_NAME_REQ 0x0419
#define HCI_OP_REMOTE_NAME_REQ_CANCEL 0x041a
#define HCI_OP_READ_REMOTE_FEATURES 0x041b
#define HCI_OP_READ_REMOTE_VERSION_INFORMATION 0x041D
#define HCI_Write_Default_Link_Policy_Settings 0x080f
#define HCI_Set_Event_Mask 0x0c01
#define HCI_RESET 0x0c03
#define HCI_Set_Event_Filter_Clear 0x0c05
#define HCI_Read_Local_Name 0x0c14
#define HCI_Read_Stored_Link_Key 0x0c0d
#define HCI_DELETE_STORED_LINK_KEY 0x0c12
#define HCI_WRITE_LOCAL_NAME 0x0c13
#define Write_Connection_Accept_Timeout 0x0c16
#define HCI_WRITE_SCAN_ENABLE 0x0c1a
#define HCI_Read_Page_Scan_Activity 0x0c1b
#define HCI_READ_CLASS_OF_DEVICE 0x0c23
#define HCI_WRITE_CLASS_OF_DEV 0x0C24
#define HCI_Read_Voice_Setting 0x0c25
#define HCI_Read_Number_Of_Supported_IAC 0x0c38
#define HCI_Read_Current_IAC_LAP 0x0c39
#define HCI_WRITE_INQUIRY_MODE 0x0c45
#define HCI_Read_Page_Scan_Type 0x0c46
#define HCI_WRITE_EIR 0x0c52
#define HCI_WRITE_SSP_MODE 0x0c56
#define HCI_Read_Inquiry_Response_Transmit_Power_Level 0x0c58
#define HCI_WRITE_LE_HOST_SUPPORTED 0x0c6d
#define HCI_Read_Local_Supported_Features 0x1003
#define HCI_Read_Local_Extended_Features 0x1004
#define HCI_Read_Buffer_Size 0x1005
#define HCI_Read_BD_ADDR 0x1009
#define HCI_Read_Local_Version_Information 0x1001
#define HCI_Read_Local_Supported_Commands 0x1002
#define HCI_LE_SET_EVENT_MASK 0x2001
#define HCI_LE_Read_Buffer_Size 0x2002
#define HCI_LE_Read_Local_supported_Features 0x2003
#define HCI_LE_READ_ADV_TX_POWER 0x2007
#define HCI_LE_SET_ADV_DATA 0x2008
#define HCI_LE_SET_SCAN_RSP_DATA 0x2009
#define HCI_LE_READ_WHITE_LIST_SIZE 0x200f
#define HCI_LE_CLEAR_WHITE_LIST 0x2010
#define HCI_LE_Supported_States 0x201c
/* Bluetooth L2CAP PSM - see http://www.bluetooth.org/Technical/AssignedNumbers/logical_link.htm */
#define HID_CTRL_PSM 0x11 // HID_Control PSM Value
#define HID_INTR_PSM 0x13 // HID_Interrupt PSM Value
// Used For Connection Response
#define PENDING 0x01
#define SUCCESSFUL 0x00
/* L2CAP signaling commands */
#define L2CAP_CMD_COMMAND_REJECT 0x01
#define L2CAP_CMD_CONNECTION_REQUEST 0x02
#define L2CAP_CMD_CONNECTION_RESPONSE 0x03
#define L2CAP_CMD_CONFIG_REQUEST 0x04
#define L2CAP_CMD_CONFIG_RESPONSE 0x05
#define L2CAP_CMD_DISCONNECT_REQUEST 0x06
#define L2CAP_CMD_DISCONNECT_RESPONSE 0x07
#define L2CAP_CMD_INFORMATION_REQUEST 0x0A
#define L2CAP_CMD_INFORMATION_RESPONSE 0x0B
#define HID_THDR_DATA_INPUT 0xa1
// HID stuff
#define HID_BOOT_PROTOCOL 0x00
#define HID_RPT_PROTOCOL 0x01
/* HCI Events */
enum {EV_INQUIRY_COMPLETE= 0x01,EV_INQUIRY_RESULT= 0x02,EV_CONNECT_COMPLETE= 0x03,EV_INCOMING_CONNECT= 0x04,EV_DISCONNECT_COMPLETE= 0x05
,EV_AUTHENTICATION_COMPLETE= 0x06,EV_REMOTE_NAME_COMPLETE= 0x07,EV_ENCRYPTION_CHANGE= 0x08,EV_CHANGE_CONNECTION_LINK= 0x09,EV_ROLE_CHANGED= 0x12
,EV_NUM_COMPLETE_PKT= 0x13,EV_PIN_CODE_REQUEST= 0x16,EV_LINK_KEY_REQUEST= 0x17,EV_LINK_KEY_NOTIFICATION= 0x18,EV_DATA_BUFFER_OVERFLOW= 0x1A
,EV_MAX_SLOTS_CHANGE= 0x1B,EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE= 0x0C,EV_QOS_SETUP_COMPLETE= 0x0D,EV_COMMAND_COMPLETE= 0x0E,EV_COMMAND_STATUS= 0x0F
,EV_LOOPBACK_COMMAND= 0x19,EV_PAGE_SCAN_REP_MODE= 0x20, EV_INQUIRY_RESULTS_WITH_RSSI=0x22, EV_EXTENDED_INQUIRY_RESULT=0x2F };
// different modes
enum {PC_RESET = 1, PC_WRITE_CLASS_DEVICE, PC_READ_BDADDR, PC_READ_LOCAL_VERSION,
PC_SEND_WRITE_INQUIRE_MODE, PC_SEND_SET_EVENT_MASK, PC_SEND_INQUIRE,
PC_INQUIRE_CANCEL=100, PC_AUTHENTICATION_REQUESTED=110, PC_LINK_KEY_NEGATIVE=120, PC_PIN_CODE_REPLY=130,
PC_WRITE_SCAN_PAGE=200};
//////////////
//////////////
// Setup some states for the TX pipe where we need to chain messages
enum {STATE_TX_SEND_CONNECT_INT=200, STATE_TX_SEND_CONECT_RSP_SUCCESS, STATE_TX_SEND_CONFIG_REQ, STATE_TX_SEND_CONECT_ISR_RSP_SUCCESS, STATE_TX_SEND_CONFIG_ISR_REQ};
// This is a list of all the drivers inherited from the BTHIDInput class.
// Unlike the list of USBDriver (managed in enumeration.cpp), drivers stay
// on this list even when they have claimed a top level collection.
BTHIDInput * BluetoothController::available_bthid_drivers_list = NULL;
void BluetoothController::driver_ready_for_bluetooth(BTHIDInput *driver)
{
driver->next = NULL;
if (available_bthid_drivers_list == NULL) {
available_bthid_drivers_list = driver;
} else {
BTHIDInput *last = available_bthid_drivers_list;
while (last->next) last = last->next;
last->next = driver;
}
}
// When a new top level collection is found, this function asks drivers
// if they wish to claim it. The driver taking ownership of the
// collection is returned, or NULL if no driver wants it.
BTHIDInput * BluetoothController::find_driver(uint32_t device_type, uint8_t *remoteName)
{
USBHDBGSerial.printf("BluetoothController::find_driver");
BTHIDInput *driver = available_bthid_drivers_list;
while (driver) {
USBHDBGSerial.printf(" driver %x\n", (uint32_t)driver);
if (driver->claim_bluetooth(this, device_type, remoteName)) {
USBHDBGSerial.printf(" *** Claimed ***\n");
return driver;
}
driver = driver->next;
}
return NULL;
}
//12 01 00 02 FF 01 01 40 5C 0A E8 21 12 01 01 02 03 01
//VendorID = 0A5C, ProductID = 21E8, Version = 0112
//Class/Subclass/Protocol = 255 / 1 / 1
BluetoothController::product_vendor_mapping_t BluetoothController::pid_vid_mapping[] = {
{ 0xA5C, 0x21E8 }};
/************************************************************/
// Initialization and claiming of devices & interfaces
/************************************************************/
void BluetoothController::init()
{
contribute_Pipes(mypipes, sizeof(mypipes)/sizeof(Pipe_t));
contribute_Transfers(mytransfers, sizeof(mytransfers)/sizeof(Transfer_t));
contribute_String_Buffers(mystring_bufs, sizeof(mystring_bufs)/sizeof(strbuf_t));
driver_ready_for_device(this);
}
bool BluetoothController::claim(Device_t *dev, int type, const uint8_t *descriptors, uint32_t len)
{
// only claim at device level
println("BluetoothController claim this=", (uint32_t)this, HEX);
if (type != 0) return false; // claim at the device level
// Lets try to support the main USB Bluetooth class...
// http://www.usb.org/developers/defined_class/#BaseClassE0h
if (dev->bDeviceClass != 0xe0) {
bool special_case_device = false;
for (uint8_t i=0; i < (sizeof(pid_vid_mapping)/sizeof(pid_vid_mapping[0])); i++) {
if ((pid_vid_mapping[i].idVendor == dev->idVendor) && (pid_vid_mapping[i].idProduct == dev->idProduct)) {
special_case_device = true;
break;
}
}
if (!special_case_device) return false;
}
if ((dev->bDeviceSubClass != 1) || (dev->bDeviceProtocol != 1)) return false; // Bluetooth Programming Interface
DBGPrintf("BluetoothController claim this=%x vid:pid=%x:%x\n ", (uint32_t)this, dev->idVendor, dev->idProduct);
if (len > 512) {
DBGPrintf(" Descriptor length %d only showing first 512\n ");
len = 512;
}
for (uint16_t i=0; i < len; i++) {
DBGPrintf("%x ", descriptors[i]);
if ((i & 0x3f) == 0x3f) DBGPrintf("\n ");
}
DBGPrintf("\n ");
// Lets try to process the first Interface and get the end points...
// Some common stuff for both XBoxs
uint32_t count_end_points = descriptors[4];
if (count_end_points < 2) return false;
uint32_t rxep = 0;
uint32_t rx2ep = 0;
uint32_t txep = 0;
uint8_t rx_interval = 0;
uint8_t rx2_interval = 0;
uint8_t tx_interval = 0;
rx_size_ = 0;
rx2_size_ = 0;
tx_size_ = 0;
uint32_t descriptor_index = 9;
while (count_end_points-- /*&& ((rxep == 0) || txep == 0) */) {
if (descriptors[descriptor_index] != 7) return false; // length 7
if (descriptors[descriptor_index+1] != 5) return false; // ep desc
if ((descriptors[descriptor_index+4] <= 64)
&& (descriptors[descriptor_index+5] == 0)) {
// have a bulk EP size
if (descriptors[descriptor_index+2] & 0x80 ) {
if (descriptors[descriptor_index+3] == 3) { // Interrupt
rxep = descriptors[descriptor_index+2];
rx_size_ = descriptors[descriptor_index+4];
rx_interval = descriptors[descriptor_index+6];
} else if (descriptors[descriptor_index+3] == 2) { // bulk
rx2ep = descriptors[descriptor_index+2];
rx2_size_ = descriptors[descriptor_index+4];
rx2_interval = descriptors[descriptor_index+6];
}
} else {
txep = descriptors[descriptor_index+2];
tx_size_ = descriptors[descriptor_index+4];
tx_interval = descriptors[descriptor_index+6];
}
}
descriptor_index += 7; // setup to look at next one...
}
if ((rxep == 0) || (txep == 0)) {
USBHDBGSerial.printf("Bluetooth end points not found: %d %d\n", rxep, txep);
return false; // did not find two end points.
}
DBGPrintf(" rxep=%d(%d) txep=%d(%d) rx2ep=%d(%d)\n", rxep&15, rx_size_, txep, tx_size_,
rx2ep&15, rx2_size_);
print("BluetoothController, rxep=", rxep & 15);
print("(", rx_size_);
print("), txep=", txep);
print("(", tx_size_);
println(")");
rxpipe_ = new_Pipe(dev, 3, rxep & 15, 1, rx_size_, rx_interval);
if (!rxpipe_) return false;
txpipe_ = new_Pipe(dev, 3, txep, 0, tx_size_, tx_interval);
if (!txpipe_) {
//free_Pipe(rxpipe_);
return false;
}
rx2pipe_ = new_Pipe(dev, 2, rx2ep & 15, 1, rx2_size_, rx2_interval);
if (!rx2pipe_) {
// Free other pipes...
return false;
}
rxpipe_->callback_function = rx_callback;
queue_Data_Transfer(rxpipe_, rxbuf_, rx_size_, this);
rx2pipe_->callback_function = rx2_callback;
queue_Data_Transfer(rx2pipe_, rx2buf_, rx2_size_, this);
txpipe_->callback_function = tx_callback;
// Send out the reset
device = dev; // yes this is normally done on return from this but should not hurt if we do it here.
sendResetHCI();
pending_control_ = PC_RESET;
pending_control_tx_ = 0; //
return true;
}
void BluetoothController::disconnect()
{
USBHDBGSerial.printf("Bluetooth Disconnect");
if (connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_->release_bluetooth();
connections_[current_connection_].device_driver_->remote_name_[0] = 0;
connections_[current_connection_].device_driver_ = nullptr;
}
connections_[current_connection_].connection_complete_ = false;
}
void BluetoothController::timer_event(USBDriverTimer *whichTimer)
{
}
void BluetoothController::control(const Transfer_t *transfer)
{
println(" control callback (bluetooth) ", pending_control_, HEX);
#ifdef DEBUG_BT_VERBOSE
DBGPrintf(" Control callback (bluetooth): %d : ", pending_control_);
uint8_t *buffer = (uint8_t*)transfer->buffer;
for (uint8_t i=0; i < transfer->length; i++) DBGPrintf("%x ", buffer[i]);
DBGPrintf("\n");
#endif
}
/************************************************************/
// Interrupt-based Data Movement
/************************************************************/
void BluetoothController::rx_callback(const Transfer_t *transfer)
{
if (!transfer->driver) return;
((BluetoothController *)(transfer->driver))->rx_data(transfer);
}
void BluetoothController::rx2_callback(const Transfer_t *transfer)
{
if (!transfer->driver) return;
((BluetoothController *)(transfer->driver))->rx2_data(transfer);
}
void BluetoothController::tx_callback(const Transfer_t *transfer)
{
if (!transfer->driver) return;
((BluetoothController *)(transfer->driver))->tx_data(transfer);
}
void BluetoothController::rx_data(const Transfer_t *transfer)
{
uint32_t len = transfer->length - ((transfer->qtd.token >> 16) & 0x7FFF);
print_hexbytes((uint8_t*)transfer->buffer, len);
DBGPrintf("BT rx_data(%d): ", len);
uint8_t *buffer = (uint8_t*)transfer->buffer;
for (uint8_t i=0; i < len; i++) DBGPrintf("%x ", buffer[i]);
DBGPrintf("\n");
// Note the logical packets returned from the device may be larger
// than can fit in one of our packets, so we will detect this and
// the next read will be continue in or rx_buf_ in the next logical
// location. We will only go into process the next logical state
// when we have the full response read in...
if (rx_packet_data_remaining == 0) { // Previous command was fully handled
rx_packet_data_remaining = rxbuf_[1] + 2; // length of data plus the two bytes at start...
}
// Now see if the data
rx_packet_data_remaining -= len; // remove the length of this packet from length
if (rx_packet_data_remaining == 0) { // read started at beginning of packet so get the total length of packet
switch(rxbuf_[0]) { // Switch on event type
case EV_COMMAND_COMPLETE: //0x0e
handle_hci_command_complete();// Check if command succeeded
break;
case EV_COMMAND_STATUS: //0x0f
handle_hci_command_status();
break;
case EV_INQUIRY_COMPLETE: // 0x01
handle_hci_inquiry_complete();
break;
case EV_INQUIRY_RESULT: // 0x02
handle_hci_inquiry_result(false);
break;
case EV_CONNECT_COMPLETE: // 0x03
handle_hci_connection_complete();
break;
case EV_INCOMING_CONNECT: // 0x04
handle_hci_incoming_connect();
break;
case EV_DISCONNECT_COMPLETE: // 0x05
handle_hci_disconnect_complete();
break;
case EV_AUTHENTICATION_COMPLETE:// 0x06
handle_hci_authentication_complete();
break;
case EV_REMOTE_NAME_COMPLETE: // 0x07
handle_hci_remote_name_complete();
break;
case EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE:
handle_hci_remote_version_information_complete();
break;
case EV_PIN_CODE_REQUEST: // 0x16
handle_hci_pin_code_request();
break;
case EV_LINK_KEY_REQUEST: // 0x17
handle_hci_link_key_request();
break;
case EV_LINK_KEY_NOTIFICATION: // 0x18
handle_hci_link_key_notification();
break;
case EV_INQUIRY_RESULTS_WITH_RSSI:
handle_hci_inquiry_result(true);
break;
case EV_EXTENDED_INQUIRY_RESULT:
handle_hci_extended_inquiry_result();
break;
default:
break;
}
// Start read at start of buffer.
queue_Data_Transfer(rxpipe_, rxbuf_, rx_size_, this);
} else {
// Continue the read - Todo - maybe verify len == rx_size_
queue_Data_Transfer(rxpipe_, buffer + rx_size_, rx_size_, this);
return; // Don't process the message yet as we still have data to receive.
}
}
//===================================================================
// Called when an HCI command completes.
void BluetoothController::handle_hci_command_complete()
{
uint16_t hci_command = rxbuf_[3] + (rxbuf_[4] << 8);
uint8_t buffer_index;
if(!rxbuf_[5]) {
VDBGPrintf(" Command Completed! \n");
} else {
VDBGPrintf(" Command(%x) Completed - Error: %d! \n", hci_command, rxbuf_[5]);
// BUGBUG:: probably need to queue something?
}
switch (hci_command) {
case HCI_OP_REMOTE_NAME_REQ:
break;
case HCI_RESET: //0x0c03
if (!rxbuf_[5]) pending_control_ = PC_WRITE_CLASS_DEVICE;
// If it fails, will retry. maybe should have repeat max...
break;
case HCI_Set_Event_Filter_Clear: //0x0c05
break;
case HCI_Read_Local_Name: //0x0c14
// received name back...
{
//BUGBUG:: probably want to grab string object and copy to
USBHDBGSerial.printf(" Local name: %s\n", &rxbuf_[6]);
/*
uint8_t len = rxbuf_[1]+2; // Length field +2 for total bytes read
for (uint8_t i=6; i < len; i++) {
if (rxbuf_[i] == 0) {
break;
}
USBHDBGSerial.printf("%c", rxbuf_[i]);
}
USBHDBGSerial.printf("\n"); */
}
break;
case Write_Connection_Accept_Timeout: //0x0c16
break;
case HCI_READ_CLASS_OF_DEVICE: // 0x0c23
break;
case HCI_Read_Voice_Setting: //0x0c25
break;
case HCI_Read_Number_Of_Supported_IAC: //0x0c38
break;
case HCI_Read_Current_IAC_LAP: //0x0c39
break;
case HCI_WRITE_INQUIRY_MODE: //0x0c45
break;
case HCI_Read_Inquiry_Response_Transmit_Power_Level: //0x0c58
break;
case HCI_Read_Local_Supported_Features: //0x1003
// Remember the features supported by local...
for (buffer_index = 0; buffer_index < 8; buffer_index++) {
features[buffer_index] = rxbuf_[buffer_index+6];
}
break;
case HCI_Read_Buffer_Size: // 0x1005
break;
case HCI_Read_BD_ADDR: //0x1009
{
for(uint8_t i = 0; i < 6; i++) my_bdaddr_[i] = rxbuf_[6 + i];
DBGPrintf(" BD Addr %x:%x:%x:%x:%x:%x\n", my_bdaddr_[5], my_bdaddr_[4], my_bdaddr_[3], my_bdaddr_[2], my_bdaddr_[1], my_bdaddr_[0]);
}
break;
case HCI_Read_Local_Version_Information: //0x1001
hciVersion = rxbuf_[6]; // Should do error checking above...
DBGPrintf(" Local Version: %x\n", hciVersion);
pending_control_ = (do_pair_device_)? PC_SEND_WRITE_INQUIRE_MODE : PC_WRITE_SCAN_PAGE;
break;
case HCI_Read_Local_Supported_Commands: //0x1002
break;
case HCI_LE_Read_Buffer_Size: //0x2002
break;
case HCI_LE_Read_Local_supported_Features: //0x2003
break;
case HCI_LE_Supported_States: //0x201c
break;
case HCI_Read_Local_Extended_Features: //0x1004
break;
case HCI_Set_Event_Mask: //0x0c01
break;
case HCI_Read_Stored_Link_Key: //0x0c0d
break;
case HCI_Write_Default_Link_Policy_Settings: //0x080f
break;
case HCI_Read_Page_Scan_Activity: //0x0c1b
break;
case HCI_Read_Page_Scan_Type: //0x0c46
break;
case HCI_LE_SET_EVENT_MASK: //0x2001
break;
case HCI_LE_READ_ADV_TX_POWER: //0x2007
break;
case HCI_LE_READ_WHITE_LIST_SIZE: //0x200f
break;
case HCI_LE_CLEAR_WHITE_LIST: //0x2010
break;
case HCI_DELETE_STORED_LINK_KEY: //0x0c12
break;
case HCI_WRITE_LOCAL_NAME: //0x0c13
break;
case HCI_WRITE_SCAN_ENABLE: //0x0c1a
DBGPrintf("Write_Scan_enable Completed\n");
// See if we have driver and a remote
if (connections_[current_connection_].device_driver_ && connections_[current_connection_].connection_complete_) { // We have a driver call their
connections_[current_connection_].device_driver_->connectionComplete();
connections_[current_connection_].connection_complete_ = false; // only call once
}
break;
case HCI_WRITE_SSP_MODE: //0x0c56
break;
case HCI_WRITE_EIR: //0x0c52
break;
case HCI_WRITE_LE_HOST_SUPPORTED: //0x0c6d
break;
case HCI_LE_SET_SCAN_RSP_DATA: //0x2009
break;
}
// And queue up the next command
queue_next_hci_command();
}
void BluetoothController::queue_next_hci_command()
{
// Ok We completed a command now see if we need to queue another command
// Still probably need to reorganize...
switch (pending_control_) {
// Initial setup states.
case PC_RESET:
sendResetHCI();
break;
case PC_WRITE_CLASS_DEVICE:
sendHDCWriteClassOfDev();
pending_control_++;
break;
case PC_READ_BDADDR:
sendHCIReadBDAddr();
pending_control_++;
break;
case PC_READ_LOCAL_VERSION:
sendHCIReadLocalVersionInfo();
//pending_control_++;
break;
// These are used when we are pairing.
case PC_SEND_WRITE_INQUIRE_MODE:
sendHCIHCIWriteInquiryMode(2); // lets set into extended inquire mode
pending_control_++;
break;
case PC_SEND_SET_EVENT_MASK:
sendHCISetEventMask(); // Set the event mask to include extend inquire event
pending_control_++;
break;
case PC_SEND_INQUIRE:
sendHCI_INQUIRY();
pending_control_++;
break;
case PC_INQUIRE_CANCEL:
// lets try to create a connection...
sendHCICreateConnection();
pending_control_++;
break;
case PC_AUTHENTICATION_REQUESTED:
break;
case PC_LINK_KEY_NEGATIVE:
break;
case PC_PIN_CODE_REPLY:
break;
// None Pair mode
case PC_WRITE_SCAN_PAGE:
sendHCIWriteScanEnable(2);
pending_control_ = 0; //
break;
default:
break;
}
}
void BluetoothController::handle_hci_command_status()
{
// <event type><param count><status><num packets allowed to be sent><CMD><CMD>
uint16_t hci_command = rxbuf_[4] + (rxbuf_[5] << 8);
if (rxbuf_[2]) {
#ifdef DEBUG_BT
DBGPrintf(" Command %x Status %x - ", hci_command, rxbuf_[2]);
switch (rxbuf_[2]) {
case 0x01: DBGPrintf("Unknown HCI Command\n"); break;
case 0x02: DBGPrintf("Unknown Connection Identifier\n"); break;
case 0x03: DBGPrintf("Hardware Failure\n"); break;
case 0x04: DBGPrintf("Page Timeout\n"); break;
case 0x05: DBGPrintf("Authentication Failure\n"); break;
case 0x06: DBGPrintf("PIN or Key Missing\n"); break;
case 0x07: DBGPrintf("Memory Capacity Exceeded\n"); break;
case 0x08: DBGPrintf("Connection Timeout\n"); break;
case 0x09: DBGPrintf("Connection Limit Exceeded\n"); break;
case 0x0A: DBGPrintf("Synchronous Connection Limit To A Device Exceeded\n"); break;
case 0x0B: DBGPrintf("Connection Already Exists\n"); break;
case 0x0C: DBGPrintf("Command Disallowed\n"); break;
case 0x0D: DBGPrintf("Connection Rejected due to Limited Resources\n"); break;
case 0x0E: DBGPrintf("Connection Rejected Due To Security Reasons\n"); break;
case 0x0F: DBGPrintf("Connection Rejected due to Unacceptable BD_ADDR\n"); break;
default: DBGPrintf("???\n"); break;
}
#endif
// lets try recovering from some errors...
switch (hci_command) {
case HCI_OP_ACCEPT_CONN_REQ:
// We assume that the connection failed...
DBGPrintf("### Connection Failed ###");
if (count_connections_) count_connections_--;
break;
default:
break;
}
} else {
#ifdef DEBUG_BT
VDBGPrintf(" Command %x Status %x\n", hci_command, rxbuf_[2]);
#endif
}
}
void BluetoothController::handle_hci_inquiry_result(bool fRSSI)
{
// result - versus result with RSSI
// | Diverge here...
// 2 f 1 79 22 23 a c5 cc 1 2 0 40 25 0 3b 2
// 22 f 1 79 22 23 a c5 cc 1 2 40 25 0 3e 31 d2
// Wondered if multiple items if all of the BDADDR are first then next field...
// looks like it is that way...
// Section 7.7.2
if (fRSSI) DBGPrintf(" Inquiry Result with RSSI - Count: %d\n", rxbuf_[2]);
else DBGPrintf(" Inquiry Result - Count: %d\n", rxbuf_[2]);
for (uint8_t i=0; i < rxbuf_[2]; i++) {
uint8_t index_bd = 3 + (i*6);
uint8_t index_ps = 3 + (6*rxbuf_[2]) + i;
uint8_t index_class = 3 + (9*rxbuf_[2]) + i;
uint8_t index_clock_offset = 3 + (12*rxbuf_[2]) + i;
if (fRSSI) {
// Handle the differences in offsets here...
index_class = 3 + (8*rxbuf_[2]) + i;
index_clock_offset = 3 + (11*rxbuf_[2]) + i;
}
uint32_t bluetooth_class = rxbuf_[index_class] + ((uint32_t)rxbuf_[index_class+1] << 8) + ((uint32_t)rxbuf_[index_class+2] << 16);
DBGPrintf(" BD:%x:%x:%x:%x:%x:%x, PS:%d, class: %x\n",
rxbuf_[index_bd],rxbuf_[index_bd+1],rxbuf_[index_bd+2],rxbuf_[index_bd+3],rxbuf_[index_bd+4],rxbuf_[index_bd+5],
rxbuf_[index_ps], bluetooth_class);
// See if we know the class
if (((bluetooth_class & 0xff00) == 0x2500) || ((bluetooth_class & 0xff00) == 0x500)) {
DBGPrintf(" Peripheral device\n");
if (bluetooth_class & 0x80) DBGPrintf(" Mouse\n");
if (bluetooth_class & 0x40) DBGPrintf(" Keyboard\n");
switch(bluetooth_class & 0x3c) {
case 4: DBGPrintf(" Joystick\n"); break;
case 8: DBGPrintf(" Gamepad\n"); break;
case 0xc: DBGPrintf(" Remote Control\n"); break;
}
// BUGBUG, lets hard code to go to new state...
for (uint8_t i = 0; i < 6; i++) connections_[current_connection_].device_bdaddr_[i] = rxbuf_[index_bd+i];
connections_[current_connection_].device_class_ = bluetooth_class;
connections_[current_connection_].device_driver_ = find_driver(connections_[current_connection_].device_class_);
connections_[current_connection_].device_ps_repetion_mode_ = rxbuf_[index_ps]; // mode
connections_[current_connection_].device_clock_offset_[0] = rxbuf_[index_clock_offset];
connections_[current_connection_].device_clock_offset_[1] = rxbuf_[index_clock_offset+1];
// Now we need to bail from inquiry and setup to try to connect...
sendHCIInquiryCancel();
pending_control_ = PC_INQUIRE_CANCEL;
break;
}
}
}
void BluetoothController::handle_hci_extended_inquiry_result()
{
DBGPrintf(" Extended Inquiry Result - Count: %d\n", rxbuf_[2]);
// Should always be only one result here.
uint8_t index_bd = 3;
uint8_t index_ps = 9;
uint8_t index_class = 11;
uint8_t index_clock_offset = 14;
//uint8_t index_rssi = 16;
uint8_t index_eir_data = 17;
uint8_t index_local_name = 0;
uint8_t size_local_name = 0;
uint32_t bluetooth_class = rxbuf_[index_class] + ((uint32_t)rxbuf_[index_class+1] << 8) + ((uint32_t)rxbuf_[index_class+2] << 16);
DBGPrintf(" BD:%x:%x:%x:%x:%x:%x, PS:%d, class: %x\n",
rxbuf_[index_bd],rxbuf_[index_bd+1],rxbuf_[index_bd+2],rxbuf_[index_bd+3],rxbuf_[index_bd+4],rxbuf_[index_bd+5],
rxbuf_[index_ps], bluetooth_class);
// Lets see if we can find a name
while (index_eir_data < 256) {
if (rxbuf_[index_eir_data] == 0) break; // no more data
switch (rxbuf_[index_eir_data+1]) {
case 0x08: // Shortened local name
case 0x09: // complete local name
index_local_name = index_eir_data+2;
size_local_name = rxbuf_[index_eir_data]-1;
break;
}
index_eir_data += rxbuf_[index_eir_data] + 1; // point to the next item
}
if (index_local_name && size_local_name) {
// Hack lets null teminate the string
rxbuf_[index_local_name+size_local_name] = 0;
DBGPrintf(" Local Name: %s\n", &rxbuf_[index_local_name]);
}
// See if we know the class
if (((bluetooth_class & 0xff00) == 0x2500) || ((bluetooth_class & 0xff00) == 0x500)) {
DBGPrintf(" Peripheral device\n");
if (bluetooth_class & 0x80) DBGPrintf(" Mouse\n");
if (bluetooth_class & 0x40) DBGPrintf(" Keyboard\n");
switch(bluetooth_class & 0x3c) {
case 4: DBGPrintf(" Joystick\n"); break;
case 8: DBGPrintf(" Gamepad\n"); break;
case 0xc: DBGPrintf(" Remote Control\n"); break;
}
// BUGBUG, lets hard code to go to new state...
for (uint8_t i = 0; i < 6; i++) connections_[current_connection_].device_bdaddr_[i] = rxbuf_[index_bd+i];
connections_[current_connection_].device_class_ = bluetooth_class;
connections_[current_connection_].device_driver_ = find_driver(connections_[current_connection_].device_class_, index_local_name? &rxbuf_[index_local_name] : nullptr);
connections_[current_connection_].device_ps_repetion_mode_ = rxbuf_[index_ps]; // mode
connections_[current_connection_].device_clock_offset_[0] = rxbuf_[index_clock_offset];
connections_[current_connection_].device_clock_offset_[1] = rxbuf_[index_clock_offset+1];
// and if we found a driver, save away the name
if (connections_[current_connection_].device_driver_ && index_local_name && size_local_name) {
uint8_t buffer_index;
for (buffer_index = 0; size_local_name && (buffer_index < BTHIDInput::REMOTE_NAME_SIZE-1); buffer_index++) {
connections_[current_connection_].device_driver_->remote_name_[buffer_index] = rxbuf_[index_local_name+buffer_index];
size_local_name--;
}
connections_[current_connection_].device_driver_->remote_name_[buffer_index] = 0; // make sure null terminated
}
// Now we need to bail from inquiry and setup to try to connect...
sendHCIInquiryCancel();
pending_control_ = PC_INQUIRE_CANCEL;
}
}
void BluetoothController::handle_hci_inquiry_complete() {
VDBGPrintf(" Inquiry Complete - status: %d\n", rxbuf_[2]);
}
void BluetoothController::handle_hci_connection_complete() {
// 0 1 2 3 4 5 6 7 8 9 10 11 12
// ST CH CH BD BD BD BD BD BD LT EN
// 03 0b 04 00 00 40 25 00 58 4b 00 01 00
connections_[current_connection_].device_connection_handle_ = rxbuf_[3]+ (uint16_t)(rxbuf_[4]<<8);
DBGPrintf(" Connection Complete - ST:%x LH:%x\n", rxbuf_[2], connections_[current_connection_].device_connection_handle_);
if (do_pair_device_ && !(connections_[current_connection_].device_driver_ && (connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_DONT_NEED_CONNECT))) {
sendHCIAuthenticationRequested();
pending_control_ = PC_AUTHENTICATION_REQUESTED;
} else if (connections_[current_connection_].device_driver_ && (connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_NEED_CONNECT)) {
DBGPrintf(" Needs connect to device(PS4?)\n");
// The PS4 requires a connection request to it.
delay(1);
sendl2cap_ConnectionRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].control_dcid_, HID_CTRL_PSM);
#if 0
delay(1);
uint8_t packet[2];
memset(packet, 0, sizeof(packet));
packet[0] = 0x43;
packet[1] = 0x02; // Report ID
USBHDBGSerial.printf("SixAxis Command Issued!\r\n");
sendL2CapCommand(packet, sizeof(packet), 0x40);
#endif
}
}
void BluetoothController::handle_hci_incoming_connect() {
// BD BD BD BD BD BD CL CL CL LT
// 0x04 0x0A 0x79 0x22 0x23 0x0A 0xC5 0xCC 0x40 0x05 0x00 0x01
uint32_t class_of_device = rxbuf_[8] + (uint16_t)(rxbuf_[9]<<8) + (uint32_t)(rxbuf_[10]<<16);
DBGPrintf(" Event: Incoming Connect - %x:%x:%x:%x:%x:%x CL:%x LT:%x\n",
rxbuf_[2], rxbuf_[3], rxbuf_[4], rxbuf_[5], rxbuf_[6], rxbuf_[7], class_of_device, rxbuf_[11]);
if (((class_of_device & 0xff00) == 0x2500) || ((class_of_device & 0xff00) == 0x500)) {
DBGPrintf(" Peripheral device\n");
if (class_of_device & 0x80) DBGPrintf(" Mouse\n");
if (class_of_device & 0x40) DBGPrintf(" Keyboard\n");
switch(class_of_device & 0x3c) {
case 4: DBGPrintf(" Joystick\n"); break;
case 8: DBGPrintf(" Gamepad\n"); break;
case 0xc: DBGPrintf(" Remote Control\n"); break;
}
if (count_connections_ < MAX_CONNECTIONS) current_connection_ = count_connections_++;
connections_[current_connection_].device_driver_ = find_driver(class_of_device);
// We need to save away the BDADDR and class link type?
for(uint8_t i=0; i<6; i++) connections_[current_connection_].device_bdaddr_[i] = rxbuf_[i+2];
connections_[current_connection_].device_class_ = class_of_device;
sendHCIRemoteNameRequest();
}
// sendHCIAuthenticationRequested();
// pending_control_ = PC_AUTHENTICATION_REQUESTED;
}
void BluetoothController::handle_hci_pin_code_request() {
// 0x16 0x06 0x79 0x22 0x23 0x0A 0xC5 0xCC
DBGPrintf(" Event: Pin Code Request %x:%x:%x:%x:%x:%x\n",
rxbuf_[2], rxbuf_[3], rxbuf_[4], rxbuf_[5], rxbuf_[6], rxbuf_[7]);
sendHCIPinCodeReply();
pending_control_ = PC_PIN_CODE_REPLY;
}
void BluetoothController::handle_hci_link_key_request() {
// 17 6 79 22 23 a c5 cc
DBGPrintf(" Event: Link Key Request %x:%x:%x:%x:%x:%x\n",
rxbuf_[2], rxbuf_[3], rxbuf_[4], rxbuf_[5], rxbuf_[6], rxbuf_[7]);
// Now here is where we need to decide to say we have key or tell them to
// cancel key... right now hard code to cancel...
sendHCILinkKeyNegativeReply();
pending_control_ = PC_LINK_KEY_NEGATIVE;
}
void BluetoothController::handle_hci_link_key_notification() {
// 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2 3 4
// 18 17 79 22 23 a c5 cc 5e 98 d4 5e bb 15 66 da 67 fe 4f 87 2b 61 46 b4 0
DBGPrintf(" Event: Link Key Notificaton %x:%x:%x:%x:%x:%x Type:%x\n key:",
rxbuf_[2], rxbuf_[3], rxbuf_[4], rxbuf_[5], rxbuf_[6], rxbuf_[7], rxbuf_[24]);
for (uint8_t i = 8; i < 24; i++) DBGPrintf("%02x ", rxbuf_[i]);
DBGPrintf("\n");
// Now here is where we need to decide to say we have key or tell them to
// cancel key... right now hard code to cancel...
}
void BluetoothController::handle_hci_disconnect_complete()
{
//5 4 0 48 0 13
DBGPrintf(" Event: HCI Disconnect complete(%d): handle: %x, reason:%x\n", rxbuf_[2],
rxbuf_[3]+(rxbuf_[4]<<8), rxbuf_[5]);
if (connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_->release_bluetooth();
connections_[current_connection_].device_driver_->remote_name_[0] = 0;
connections_[current_connection_].device_driver_ = nullptr;
// Restore to normal...
connections_[current_connection_].control_dcid_ = 0x70;
connections_[current_connection_].interrupt_dcid_ = 0x71;
}
// Probably should clear out connection data.
#if 0
connections_[current_connection_].device_connection_handle_ = 0;
connections_[current_connection_].device_class_ = 0;
memset(connections_[current_connection_].device_bdaddr_, 0, sizeof(connections_[current_connection_].device_bdaddr_));
#endif
// Now we need to remove that item from our list of connections.
count_connections_--;
if (count_connections_ == 0) {
// reset the next connection counts back to initial states.
next_dcid_ = 0x70; // Lets try not hard coding control and interrupt dcid
}
for (uint8_t i = current_connection_; i < count_connections_; i++) connections_[i] = connections_[i+1];
current_connection_ = 0;
}
void BluetoothController::handle_hci_authentication_complete()
{
// 6 3 13 48 0
DBGPrintf(" Event: HCI Authentication complete(%d): handle: %x\n", rxbuf_[2],
rxbuf_[3]+(rxbuf_[4]<<8));
// Start up lcap connection...
connections_[current_connection_].connection_rxid_ = 0;
sendl2cap_ConnectionRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].control_dcid_, HID_CTRL_PSM);
}
void BluetoothController::handle_hci_remote_name_complete() {
// STAT bd bd bd bd bd bd
// 0x07 0xFF 0x00 0x79 0x22 0x23 0x0A 0xC5 0xCC 0x42 0x6C 0x75 0x65 0x74 0x6F 0x6F ...
DBGPrintf(" Event: handle_hci_remote_name_complete(%d)\n", rxbuf_[2]);
if (rxbuf_[2] == 0) {
DBGPrintf(" Remote Name: ");
for (uint8_t *psz = &rxbuf_[9]; *psz; psz++) DBGPrintf("%c", *psz);
DBGPrintf("\n");
}
if (connections_[current_connection_].device_driver_) {
if (!connections_[current_connection_].device_driver_->remoteNameComplete(&rxbuf_[9])) {
connections_[current_connection_].device_driver_->release_bluetooth();
connections_[current_connection_].device_driver_ = nullptr;
}
}
if (!connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_ = find_driver(connections_[current_connection_].device_class_, &rxbuf_[9]);
// not sure I should call remote name again, but they already process...
if (connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_->remoteNameComplete(&rxbuf_[9]);
}
}
if (connections_[current_connection_].device_driver_) {
// lets save away the string.
uint8_t buffer_index;
for (buffer_index = 0; buffer_index < BTHIDInput::REMOTE_NAME_SIZE-1; buffer_index++) {
connections_[current_connection_].device_driver_->remote_name_[buffer_index] = rxbuf_[9+buffer_index];
if (!connections_[current_connection_].device_driver_->remote_name_[buffer_index]) break;
}
connections_[current_connection_].device_driver_->remote_name_[buffer_index] = 0; // make sure null terminated
if (connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_PS3_IDS) {
// Real hack see if PS3...
connections_[current_connection_].control_dcid_ = 0x40;
connections_[current_connection_].interrupt_dcid_ = 0x41;
} else {
connections_[current_connection_].control_dcid_ = next_dcid_++;
connections_[current_connection_].interrupt_dcid_ = next_dcid_++;
}
}
// If we are in the connection complete mode, then this is a pairing state and needed to call
// get remote name later.
if (connections_[current_connection_].connection_complete_) {
if (connections_[current_connection_].device_driver_) { // We have a driver call their
connections_[current_connection_].device_driver_->connectionComplete();
connections_[current_connection_].connection_complete_ = false; // only call once
}
} else {
sendHCIAcceptConnectionRequest();
}
}
void BluetoothController::handle_hci_remote_version_information_complete() {
// STAT bd bd bd bd bd bd