-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathbluetooth.cpp
2606 lines (2336 loc) · 109 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
*/
//=============================================================================
// Bluetooth Main controller code
//=============================================================================
#include <Arduino.h>
#include "USBHost_t36.h" // Read this header first for key info
#include "utility/bt_defines.h"
#include <EEPROM.h>
#define print USBHost::print_
#define println USBHost::println_
//#define DEBUG_BT
//#define DEBUG_BT_VERBOSE
#ifndef DEBUG_BT
#undef DEBUG_BT_VERBOSE
void inline DBGPrintf(...) {};
void inline DBGFlush() {};
#else
#define DBGPrintf USBHDBGSerial.printf
#define DBGFlush USBHDBGSerial.flush
#endif
elapsedMillis em_rx_tx2 = 0;
elapsedMillis em_rx_tx = 0;
#ifndef DEBUG_BT_VERBOSE
void inline VDBGPrintf(...) {};
#else
#define VDBGPrintf USBHDBGSerial.printf
#endif
// Lets use a boolean to determine if we have SSP available_bthid_drivers_list
bool has_key = false;
// 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;
// default forward.
hidclaim_t BTHIDInput::claim_bluetooth(BluetoothConnection *btconnection, uint32_t bluetooth_class, uint8_t *remoteName, int type)
{
return claim_bluetooth(btconnection->btController_, bluetooth_class, remoteName) ? CLAIM_INTERFACE : CLAIM_NO;
}
const uint8_t *BTHIDInput::manufacturer()
{
return nullptr; // so far don't have one
}
const uint8_t *BTHIDInput::product()
{
if (btconnect == nullptr) return nullptr;
return btconnect->remote_name_;
}
const uint8_t *BTHIDInput::serialNumber()
{
return nullptr;
}
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;
}
}
bool BluetoothController::queue_Data_Transfer_Debug(Pipe_t *pipe, void *buffer,
uint32_t len, USBDriver *driver, uint32_t line)
{
if ((pipe == nullptr) || (driver == nullptr) || ((len > 0) && (buffer == nullptr))) {
// something wrong:
USBHDBGSerial.printf("\n !!!!!!!!!!! BluetoothController::queue_Data_Transfer called with bad data line: %u\n", line);
USBHDBGSerial.printf("\t pipe:%p buffer:%p len:%u driver:%p\n", pipe, buffer, len, driver);
return false;
}
return queue_Data_Transfer(pipe, buffer, len, driver);
}
//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("%02x ", 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_Debug(rxpipe_, rxbuf_, rx_size_, this, __LINE__);
rx2pipe_->callback_function = rx2_callback;
queue_Data_Transfer_Debug(rx2pipe_, rx2buf_, rx2_size_, this, __LINE__);
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");
// lets clear out any active connecitons
current_connection_ = BluetoothConnection::s_first_;
while (current_connection_) {
// see if this one is in use
if (current_connection_->btController_ == this) {
if (current_connection_->device_driver_) {
current_connection_->device_driver_->release_bluetooth();
current_connection_->remote_name_[0] = 0;
current_connection_->device_driver_ = nullptr;
}
current_connection_->btController_ = nullptr;
}
current_connection_ = current_connection_->next_;
}
// Maybe leave it pointing to first one just in case.
count_connections_ = 0;
timer_connection_ = nullptr;
current_connection_ = BluetoothConnection::s_first_;
USBHDBGSerial.printf("Bluetooth Disconnect complete"); USBHDBGSerial.flush();
}
void BluetoothController::timer_event(USBDriverTimer *whichTimer)
{
DBGPrintf("BT::Timer_event(%p)->%p\n", whichTimer, whichTimer->pointer);DBGFlush();
if (whichTimer == &timer_) {
if (timer_connection_) timer_connection_->timer_event(whichTimer);
} else if (whichTimer->pointer) {
BluetoothConnection* btc = (BluetoothConnection*)(whichTimer->pointer);
btc->timer_event(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("%02x ", buffer[i]);
DBGPrintf("\n");
#endif
}
bool BluetoothController::setTimer(BluetoothConnection *connection, uint32_t us) // set to NULL ptr will clear:
{
static uint32_t millis_last = 0;
DBGPrintf("BluetoothController::setTimer(%p, %u) TO:%u, dt:%u\n", connection, us,
millis(), millis()-millis_last);
millis_last = millis();
if (connection == nullptr) {
timer_connection_ = nullptr;
timer_.stop();
return true;
} else if ((timer_connection_ == nullptr) || (connection == timer_connection_)) {
timer_connection_ = connection;
timer_.start(us);
return true;
}
return false;
}
/************************************************************/
// Try starting a pairing operation after sketch starts
/************************************************************/
bool BluetoothController::startDevicePairing(const char *pin, bool pair_ssp)
{
// What should we verify before starting this mode?
if (pending_control_ != 0) {
DBGPrintf("Pending control not zero.");
return false;
}
// BUGBUG:: probably should make copy of pin...
pair_pincode_ = pin;
do_pair_ssp_ = pair_ssp;
// Try simple approach first to see if I can simply start it
do_pair_device_ = !do_pair_ssp_;
pending_control_ = PC_SEND_WRITE_INQUIRE_MODE;
queue_next_hci_command();
return true;
}
#ifdef DEBUG_BT
void print_error_codes(uint8_t error_code) {
switch (error_code) {
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;
case 0x10: DBGPrintf(" ( Connection Accept Timeout Exceeded)\n"); break;
case 0x11: DBGPrintf(" ( Unsupported Feature or Parameter Value)\n"); break;
case 0x12: DBGPrintf(" ( Invalid HCI Command Parameters)\n"); break;
case 0x13: DBGPrintf(" ( Remote User Terminated Connection)\n"); break;
case 0x14: DBGPrintf(" ( Remote Device Terminated Connection due to Low Resources)\n"); break;
case 0x15: DBGPrintf(" ( Remote Device Terminated Connection due to Power Off)\n"); break;
case 0x16: DBGPrintf(" ( Connection Terminated By Local Host)\n"); break;
case 0x17: DBGPrintf(" ( Repeated Attempts)\n"); break;
case 0x18: DBGPrintf(" ( Pairing Not Allowed)\n"); break;
case 0x19: DBGPrintf(" ( Unknown LMP PDU)\n"); break;
case 0x1A: DBGPrintf(" ( Unsupported Remote Feature)\n"); break;
case 0x1B: DBGPrintf(" ( SCO Offset Rejected)\n"); break;
case 0x1C: DBGPrintf(" ( SCO Interval Rejected)\n"); break;
case 0x1D: DBGPrintf(" ( SCO Air Mode Rejected)\n"); break;
case 0x1E: DBGPrintf(" ( Invalid LMP Parameters / Invalid LL Parameters)\n"); break;
case 0x1F: DBGPrintf(" ( Unspecified Error)\n"); break;
case 0x20: DBGPrintf(" ( Unsupported LMP Parameter Value / Unsupported LL Parameter Value)\n"); break;
case 0x21: DBGPrintf(" ( Role Change Not Allowed)\n"); break;
case 0x22: DBGPrintf(" ( LMP Response Timeout / LL Response Timeout)\n"); break;
case 0x23: DBGPrintf(" ( LMP Error Transaction Collision / LL Procedure Collision)\n"); break;
case 0x24: DBGPrintf(" ( LMP PDU Not Allowed)\n"); break;
case 0x25: DBGPrintf(" ( Encryption Mode Not Acceptable)\n"); break;
case 0x26: DBGPrintf(" ( Link Key cannot be Changed)\n"); break;
case 0x27: DBGPrintf(" ( Requested QoS Not Supported)\n"); break;
case 0x28: DBGPrintf(" ( Instant Passed)\n"); break;
case 0x29: DBGPrintf(" ( Pairing With Unit Key Not Supported)\n"); break;
case 0x2A: DBGPrintf(" ( Different Transaction Collision)\n"); break;
case 0x2B: DBGPrintf(" ( Reserved for future use)\n"); break;
case 0x2C: DBGPrintf(" ( QoS Unacceptable Parameter)\n"); break;
case 0x2D: DBGPrintf(" ( QoS Rejected)\n"); break;
case 0x2E: DBGPrintf(" ( Channel Classification Not Supported)\n"); break;
case 0x2F: DBGPrintf(" ( Insufficient Security)\n"); break;
case 0x30: DBGPrintf(" ( Parameter Out Of Mandatory Range)\n"); break;
case 0x31: DBGPrintf(" ( Reserved for future use)\n"); break;
case 0x32: DBGPrintf(" ( Role Switch Pending)\n"); break;
case 0x33: DBGPrintf(" ( Reserved for future use)\n"); break;
case 0x34: DBGPrintf(" ( Reserved Slot Violation)\n"); break;
case 0x35: DBGPrintf(" ( Role Switch Failed)\n"); break;
case 0x36: DBGPrintf(" ( Extended Inquiry Response Too Large)\n"); break;
case 0x37: DBGPrintf(" ( Secure Simple Pairing Not Supported By Host)\n"); break;
case 0x38: DBGPrintf(" ( Host Busy - Pairing)\n"); break;
case 0x39: DBGPrintf(" ( Connection Rejected due to No Suitable Channel Found)\n"); break;
case 0x3A: DBGPrintf(" ( Controller Busy)\n"); break;
case 0x3B: DBGPrintf(" ( Unacceptable Connection Parameters)\n"); break;
case 0x3C: DBGPrintf(" ( Advertising Timeout)\n"); break;
case 0x3D: DBGPrintf(" ( Connection Terminated due to MIC Failure)\n"); break;
case 0x3E: DBGPrintf(" ( Connection Failed to be Established / Synchronization Timeout)\n"); break;
case 0x3F: DBGPrintf(" ( Previously used)\n"); break;
case 0x40: DBGPrintf(" ( Coarse Clock Adjustment Rejected but Will Try to Adjust Using Clock Dragging)\n"); break;
case 0x41: DBGPrintf(" ( Type0 Submap Not Defined)\n"); break;
case 0x42: DBGPrintf(" ( Unknown Advertising Identifier)\n"); break;
case 0x43: DBGPrintf(" ( Limit Reached)\n"); break;
case 0x44: DBGPrintf(" ( Operation Cancelled by Host)\n"); break;
case 0x45: DBGPrintf(" ( Packet Too Long)\n"); break;
default: 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)
{
uint32_t len = transfer->length - ((transfer->qtd.token >> 16) & 0x7FFF);
print_hexbytes((uint8_t*)transfer->buffer, len);
// DBGPrintf("<<(00 : %d): ", len);
// DBGPrintf("<<(02 %u %p %u):", (uint32_t)em_rx_tx2, transfer->driver, len);
// em_rx_tx2 = 0;
// uint8_t *buffer = (uint8_t*)transfer->buffer;
// for (uint8_t i = 0; i < len; i++) DBGPrintf("%02X ", buffer[i]);
// DBGPrintf("\n");
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("<<(00 : %d): ", len);
DBGPrintf(rx_packet_data_remaining_? "<<C(01, %u):":"<<(01, %u):", (uint32_t)em_rx_tx);
em_rx_tx = 0;
uint8_t *buffer = (uint8_t*)transfer->buffer;
for (uint8_t i = 0; i < len; i++) DBGPrintf("%02X ", 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
if (len == 0) {
DBGPrintf("<< Empty Packet >>\n");
// probably could combine with below.
queue_Data_Transfer_Debug(rxpipe_, rxbuf_, rx_size_, this, __LINE__);
return;
}
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;
//use simple pairing
case EV_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE: //0x0B
USBHDBGSerial.printf(" Remote read features complete: status:%x ", rxbuf_[2]);
#if defined(DEBUG_BT_VERBOSE)
print_error_codes(rxbuf_[2]);
#endif
USBHDBGSerial.printf(" Requested to use SSP Pairing: %d\n", do_pair_ssp_);
if ( (rxbuf_[11]) & (0x01 << 3)) {
if (current_connection_) {
current_connection_->supports_SSP_ = true;
USBHDBGSerial.printf("%d\n", current_connection_->supports_SSP_);
}
//sendHCIRemoteNameRequest();
} else {
USBHDBGSerial.printf("No Support for SPP\n");
//USBHDBGSerial.printf("Try just say yes\n");
//current_connection_->supports_SSP_ = true;
}
#if 1
// Try bypass role discovery did not help much anyway
// Note We may need to check for PS4 or the like and
// start connection. Let me try by setting timer like
// Set a timeout
setTimer(current_connection_, BluetoothConnection::CONNECTION_TIMEOUT_US);
#else
sendHCIRoleDiscoveryRequest();
#endif
break;
case EV_READ_REMOTE_EXTENDED_FEATURES_COMPLETE: //0x23
USBHDBGSerial.printf(" Extended features read complete: status:%x ", rxbuf_[2]);
#if defined(DEBUG_BT_VERBOSE)
print_error_codes(rxbuf_[2]);
#endif
USBHDBGSerial.printf(" Requested to use SSP Pairing: %d\n", do_pair_ssp_);
if ( ((rxbuf_[7] >> 0) & 0x01) == 1) {
if (current_connection_) {
current_connection_->supports_SSP_ = true;
USBHDBGSerial.printf("%d\n", current_connection_->supports_SSP_);
}
//sendHCIRemoteNameRequest();
} else {
USBHDBGSerial.printf("No Support for SPP\n");
}
sendHCIRoleDiscoveryRequest();
break;
case EV_ENCRYPTION_CHANGE:// < UseSimplePairing
if(has_key == true ) {
USBHDBGSerial.printf(" Change to Link Encryption: ");
sendHCISetConnectionEncryption(); // use simple pairing hangs the link
has_key = false;
}
//handle_hci_encryption_change_complete();
break;
case EV_RETURN_LINK_KEYS:
handle_hci_return_link_keys();
break;
case EV_SIMPLE_PAIRING_COMPLETE:
if(!rxbuf_[2]) { // Check if pairing was Complete
USBHDBGSerial.printf("\r\nSimple Pairing Complete\n");
} else {
USBHDBGSerial.printf("\r\nPairing Failed: \n");
}
break;
case EV_MAX_SLOTS_CHANGE:
USBHDBGSerial.printf("Received Max Slot change Msg\n");
break;
case EV_USER_CONFIRMATION_REQUEST:
handle_hci_user_confirmation_request_reply();
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:
#if 0
handle_hci_extended_inquiry_result();
#else
DBGPrintf("$$$ EV_EXTENDED_INQUIRY_RESULT Disabled\n");
#endif
break;
case EV_IO_CAPABILITY_RESPONSE:
handle_HCI_IO_CAPABILITY_REQUEST_REPLY();
break;
case EV_IO_CAPABILITY_REQUEST:
handle_hci_io_capability_request();
break;
case EV_ROLE_CHANGED:
// 12 08 00 16 AC B3 26 3F C8 00
VDBGPrintf(" EV_ROLE_CHANGED: st:%u bdaddr: %02x:%02x:%02x:%02x:%02x:%02x role:%u(%s)\n",
rxbuf_[2], rxbuf_[3], rxbuf_[4], rxbuf_[5], rxbuf_[6], rxbuf_[7], rxbuf_[8],
rxbuf_[9], rxbuf_[9]? "Peripheral" : "Central" );
break;
case EV_NUM_COMPLETE_PKT: //13 05 01 47 00 01 00
VDBGPrintf(" NUM_COMPLETE_PKT: ch:%u fh:%04x comp:%u\n",
rxbuf_[2], rxbuf_[3] + (rxbuf_[4] << 8), rxbuf_[rxbuf_[1]] + (rxbuf_[rxbuf_[1] + 1] << 8) );
break;
case EV_LE_META_EVENT:
handle_ev_meta_event(); // 0x3e
break;
default:
break;
}
// Start read at start of buffer.
queue_Data_Transfer_Debug(rxpipe_, rxbuf_, rx_size_, this, __LINE__);
} else {
// Continue the read - Todo - maybe verify len == rx_size_
queue_Data_Transfer_Debug(rxpipe_, buffer + rx_size_, rx_size_, this, __LINE__);
return; // Don't process the message yet as we still have data to receive.
}
}
#ifdef DEBUG_BT_VERBOSE
void print_supported_commands(uint8_t *cmd_data) {
typedef struct {
uint8_t octet;
uint8_t bit;
const char *name;
} pss_data_t;
static const pss_data_t pssd[] = {
{ 0, 0, /*0x0401*/ "HCI_INQUIRY"},
{ 0, 1, /*0x0402*/ "HCI_INQUIRY_CANCEL"},
{ 0, 4, /*0x0405*/ "HCI_CREATE_CONNECTION"},
{ 1, 0, /*0x0409*/ "HCI_OP_ACCEPT_CONN_REQ"},
{ 1, 1, /*0x040A*/ "HCI_OP_REJECT_CONN_REQ"},
{ 1, 2, /*0x040B*/ "HCI_LINK_KEY_REQUEST_REPLY"},
{ 1, 3, /*0x040C*/ "HCI_LINK_KEY_NEG_REPLY"},
{ 1, 4, /*0x040D*/ "HCI_PIN_CODE_REPLY"},
{ 1, 7, /*0x0411*/ "HCI_AUTH_REQUESTED"},
{ 2, 0, /*0x0413*/ "HCI_SET_CONN_ENCRYPTION"},
{ 2, 3, /*0x0419*/ "HCI_OP_REMOTE_NAME_REQ"},
{ 2, 4, /*0x041a*/ "HCI_OP_REMOTE_NAME_REQ_CANCEL"},
{ 2, 5, /*0x041b*/ "HCI_OP_READ_REMOTE_FEATURES"},
{ 2, 6, /*0x041c*/ "HCI_OP_READ_REMOTE_EXTENDED_FEATURE"},
{ 2, 7, /*0x041D*/ "HCI_OP_READ_REMOTE_VERSION_INFORMATION"},
{ 18, 7, /*0x042B*/ "HCI_IO_CAPABILITY_REQUEST_REPLY"},
{ 19, 0, /*0x042C*/ "HCI_USER_CONFIRMATION_REQUEST"},
{ 4, 7, /*0x0809*/ "HCI_OP_ROLE_DISCOVERY"},
{ 5, 4, /*0x080f*/ "HCI_Write_Default_Link_Policy_Settings"},
{ 5, 6, /*0x0c01*/ "HCI_Set_Event_Mask"},
{ 5, 7, /*0x0c03*/ "HCI_RESET"},
{ 6, 0, /*0x0c05*/ "HCI_SET_EVENT_FILTER"},
{ 6, 5, /*0x0c0d*/ "HCI_READ_STORED_LINK_KEY"},
{ 6, 7, /*0x0c12*/ "HCI_DELETE_STORED_LINK_KEY"},
{ 7, 0, /*0x0c13*/ "HCI_WRITE_LOCAL_NAME"},
{ 7, 1, /*0x0c14*/ "HCI_Read_Local_Name"},
{ 7, 3, /*0x0c16*/ "HCI_Write_Connection_Accept_Timeout"},
{ 7, 6, /*0x0c1a*/ "HCI_WRITE_SCAN_ENABLE"},
{ 8, 0, /*0x0c1b*/ "HCI_Read_Page_Scan_Activity"},
{ 9, 0, /*0x0c23*/ "HCI_READ_CLASS_OF_DEVICE"},
{ 9, 1, /*0x0C24*/ "HCI_WRITE_CLASS_OF_DEV"},
{ 9, 2, /*0x0c25*/ "HCI_Read_Voice_Setting"},
{ 11, 2, /*0x0c38*/ "HCI_Read_Number_Of_Supported_IAC"},
{ 11, 3, /*0x0c39*/ "HCI_Read_Current_IAC_LAP"},
{ 12, 6, /*0x0c45*/ "HCI_WRITE_INQUIRY_MODE"},
{ 13, 1, /*0x0c46*/ "HCI_Read_Page_Scan_Type"},
{ 17, 1, /*0x0c52*/ "HCI_WRITE_EXTENDED_INQUIRY_RESPONSE"},
{ 17, 5, /*0x0c55*/ "HCI_READ_SIMPLE_PAIRING_MODE"},
{ 17, 6, /*0x0c56*/ "HCI_WRITE_SIMPLE_PAIRING_MODE"},
{ 18, 0, /*0x0c58*/ "HCI_Read_Inquiry_Response_Transmit_Power_Level"},
{ 24, 5, /*???? */ "HCI_READ_LE_HOST_SUPPORTED"},
{ 24, 6, /*0x0c6d*/ "HCI_WRITE_LE_HOST_SUPPORTED"},
#if 0
{ 0, 0, /*0x1001*/ "HCI_Read_Local_Version_Information"},
{ 0, 0, /*0x1002*/ "HCI_Read_Local_Supported_Commands"},
{ 25, 2, /*0x1003*/ "HCI_Read_Local_Supported_Features"},
{ 0, 0, /*0x1004*/ "HCI_Read_Local_Extended_Features"},
{ 25, 1, /*0x1005*/ "HCI_Read_Buffer_Size"},
{ 0, 0, /*0x1009*/ "HCI_Read_BD_ADDR"},
{ 0, 0, /*0x1408*/ "HCI_READ_ENCRYPTION_KEY_SIZE"},
{ 0, 0, /*0x2001*/ "HCI_LE_SET_EVENT_MASK"},
{ 0, 0, /*0x2002*/ "HCI_LE_Read_Buffer_Size"},
{ 0, 0, /*0x2003*/ "HCI_LE_Read_Local_supported_Features"},
{ 0, 0, /*0x2007*/ "HCI_LE_READ_ADV_TX_POWER"},
{ 0, 0, /*0x2008*/ "HCI_LE_SET_ADV_DATA"},
{ 0, 0, /*0x2009*/ "HCI_LE_SET_SCAN_RSP_DATA"},
{ 0, 0, /*0x200f*/ "HCI_LE_READ_WHITE_LIST_SIZE"},
{ 0, 0, /*0x2010*/ "HCI_LE_CLEAR_WHITE_LIST"},
{ 0, 0, /*0x201c*/ "HCI_LE_Supported_States"},
#endif
};
USBHDBGSerial.printf("\n### Local Supported Commands ###\n");
for (uint16_t i = 0; i < (sizeof(pssd) / sizeof(pssd[0])); i++) {
uint8_t mask = 1 << pssd[i].bit;
USBHDBGSerial.printf("\t%s - ", pssd[i].name);
if (cmd_data[pssd[i].octet] & mask) USBHDBGSerial.printf("yes\n");
else USBHDBGSerial.printf("** NO ***\n");
}
}
#endif
#ifdef DEBUG_BT_VERBOSE
void print_supported_features(uint8_t *cmd_data) {
typedef struct {
uint8_t octet;
uint8_t bit;
const char *name;
} pss_data_t;
static const pss_data_t pssd[] = {
{0, 0, "3 slot packets"},
{0, 1, "5 slot packets"},
{0, 2, "Encryption"},
{0, 3, "Slot offset"},
{0, 4, "Timing accuracy"},
{0, 5, "Role switch"},
{0, 6, "Hold mode"},
{0, 7, "Sniff mode"},
{1, 0, "Reserved"},
{1, 1, "Power control requests"},
{1, 2, "Channel quality driven data rate (CQDDR)"},
{1, 3, "SCO link"},
{1, 4, "HV2 packets"},
{1, 5, "HV3 packets"},
{1, 6, "μ-law log synchronous data"},
{1, 7, "A-law log synchronous data"},
{2, 0, "CVSD synchronous data"},
{2, 1, "Paging parameter negotiation"},
{2, 2, "Power control"},
{2, 3, "Transparent synchronous data"},
{2, 4, "Flow control lag (least significant bit)"},
{2, 5, "Flow control lag (middle bit)"},
{2, 6, "Flow control lag (most significant bit)"},
{2, 7, "Broadcast Encryption"},
{3, 1, "Enhanced Data Rate ACL 2 Mb/s mode"},
{3, 2, "Enhanced Data Rate ACL 3 Mb/s mode"},
{3, 3, "Enhanced inquiry scan"},
{3, 4, "Interlaced inquiry scan"},
{3, 5, "Interlaced page scan"},
{3, 6, "RSSI with inquiry results"},
{3, 7, "Extended SCO link (EV3 packets)"},
{4, 0, "EV4 packets"},
{4, 1, "EV5 packets"},
{4, 3, "AFH capable slave"},
{4, 4, "AFH classification slave"},
{4, 5, "BR/EDR Not Supported"},
{4, 6, "LE Supported (Controller)"},
{4, 7, "3-slot Enhanced Data Rate ACL packets"},
{5, 0, "5-slot Enhanced Data Rate ACL packets"},
{5, 1, "Sniff subrating"},
{5, 2, "Pause encryption"},
{5, 3, "AFH capable master"},
{5, 4, "AFH classification master"},
{5, 5, "Enhanced Data Rate eSCO 2 Mb/s mode"},
{5, 6, "Enhanced Data Rate eSCO 3 Mb/s mode"},
{5, 7, "3-slot Enhanced Data Rate eSCO packets"},
{6, 0, "Extended Inquiry Response"},
{6, 1, "Simultaneous LE and BR/EDR to Same Device Capable(Controller)"},
{6, 3, "Secure Simple Pairing"},
{6, 4, "Encapsulated PDU"},
{6, 5, "Erroneous Data Reporting"},
{6, 6, "Non-flushable Packet Boundary Flag"},
{7, 0, "Link Supervision Timeout Changed Event"},
{7, 1, "Inquiry TX Power Level"},
{7, 2, "Enhanced Power Control"},
{7, 7, "Extended features"}
};
USBHDBGSerial.printf("\n### Local Supported Features ###\n");
for (uint16_t i = 0; i < (sizeof(pssd) / sizeof(pssd[0])); i++) {
uint8_t mask = 1 << pssd[i].bit;
USBHDBGSerial.printf("\t%s - ", pssd[i].name);
if (cmd_data[pssd[i].octet] & mask) USBHDBGSerial.printf("yes\n");
else USBHDBGSerial.printf("** NO ***\n");
}
}
#endif
//===================================================================
// 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;
#ifdef DEBUG_BT_VERBOSE
if (!rxbuf_[5]) {
VDBGPrintf(" Command Completed! \n");
} else {
VDBGPrintf(" Command(%x) Completed - Error: 0x%x!", hci_command, rxbuf_[5], rxbuf_[5]);
// BUGBUG:: probably need to queue something?
print_error_codes(rxbuf_[5]);
}
#endif
switch (hci_command) {
case HCI_OP_REMOTE_NAME_REQ:
break;
case HCI_RESET: //0x0c03
if (!rxbuf_[5]) pending_control_++;
// If it fails, will retry. maybe should have repeat max...
break;
case HCI_SET_EVENT_FILTER: //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_Commands: //0x1002
DBGPrintf(" HCI_Read_Local_Supported_Commands\n");
#ifdef DEBUG_BT_VERBOSE
print_supported_commands(&rxbuf_[6]);
#endif
break;
case HCI_Read_Local_Supported_Features: //0x1003
DBGPrintf(" HCI_Read_Local_Supported_Features\n");
#ifdef DEBUG_BT_VERBOSE
print_supported_features(&rxbuf_[6]);
#endif
// 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);
if( do_pair_ssp_ ) {
pending_control_ = PC_SEND_WRITE_INQUIRE_MODE;
} else {
pending_control_ = (do_pair_device_) ? PC_SEND_WRITE_INQUIRE_MODE : PC_WRITE_SCAN_PAGE;
}
break;
case HCI_LE_Read_Buffer_Size: //0x2002
{
DBGPrintf("LE Buffer Size: Size:%u, cnt:%u\n",
rxbuf_[6] + (rxbuf_[7] << 8), rxbuf_[8]);
}
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
DBGPrintf(" HCI_READ_STORED_LINK_KEY keys total:%u read:%u\n",
rxbuf_[6] + (rxbuf_[7] << 8), rxbuf_[8]);
break;
case HCI_WRITE_STORED_LINK_KEY: //0xc011
DBGPrintf(" HCI_WRITE_STORED_LINK_KEY keys written:%u\n", rxbuf_[6]);
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
current_connection_->handle_HCI_WRITE_SCAN_ENABLE_complete(rxbuf_);
break;
case HCI_READ_SIMPLE_PAIRING_MODE: //0x0c55
break;
case HCI_WRITE_SIMPLE_PAIRING_MODE: //0x0c56
//sendHCIReadSimplePairingMode();
break;
case HCI_WRITE_EXTENDED_INQUIRY_RESPONSE: //0x0c52
break;
case HCI_WRITE_LE_HOST_SUPPORTED: //0x0c6d
break;
case HCI_LE_SET_SCAN_RSP_DATA: //0x2009
break;
case HCI_LINK_KEY_NEG_REPLY:
//if (current_connection_->device_class_ == 0x2508) {
// DBGPrintf("Hack see if we can catch the Terios here");
// pending_control_ = PC_CONNECT_AFTER_SDP_DISCONNECT;
//}
break;
case HCI_OP_ROLE_DISCOVERY: // 0x0809
current_connection_->handle_HCI_OP_ROLE_DISCOVERY_complete(rxbuf_);
break;
case HCI_INQUIRY_CANCEL: // 0x0402
// Question should I setup up PC for this or do inline
sendHCIRemoteNameRequest();
break;
case HCI_OP_READ_REMOTE_FEATURES:
break; //0x041b
case HCI_OP_READ_REMOTE_EXTENDED_FEATURE:
break; //0x041c
case HCI_SET_CONN_ENCRYPTION:
break;
case HCI_READ_ENCRYPTION_KEY_SIZE:
break;
case HCI_LINK_KEY_REQUEST_REPLY:
DBGPrintf("\tHCI_LINK_KEY_REQUEST_REPLY\n");
break;
case HCI_USER_CONFIRMATION_REQUEST: //0x042C
DBGPrintf("User Confirmation Request Reply\n");
break;
case HCI_IO_CAPABILITY_REQUEST_REPLY: //0x042B
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_READ_LOCAL_SUPPORTED_COMMANDS:
sendHCIReadLocalSupportedCommands();
pending_control_++;
break;
case PC_READ_LOCAL_SUPPORTED_FEATURES:
sendHCIReadLocalSupportedFeatures();
pending_control_++;
break;
case PC_SEND_SET_EVENT_MASK:
sendHCISetEventMask(); // Set the event mask to include extend inquire event
pending_control_++;
break;
// ----------------------
// Added some LE setup as experiment
case PC_SET_LE_EVENT_MASK:
{
DBGPrintf("HCI_LE_SET_EVENT_MASK\n");