diff --git a/_b_t_d_8cpp_source.html b/_b_t_d_8cpp_source.html index 85833835..ae878380 100644 --- a/_b_t_d_8cpp_source.html +++ b/_b_t_d_8cpp_source.html @@ -127,7 +127,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
36 pollInterval(0),
37 bPollEnable(false) // Don't start polling before dongle is connected
38 {
-
39  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
+
39  for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
40  btService[i] = NULL;
41 
42  Initialize(); // Set all variables, endpoint structs etc. to default values
@@ -384,7 +384,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
293  epInfo[i].epAttribs = 0;
294  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
295  }
-
296  for(i = 0; i < BTD_NUMSERVICES; i++) {
+
296  for(i = 0; i < BTD_NUM_SERVICES; i++) {
297  if(btService[i])
298  btService[i]->Reset(); // Reset all Bluetooth services
299  }
@@ -596,9 +596,9 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
505 
506  case EV_REMOTE_NAME_COMPLETE:
507  if(!hcibuf[2]) { // Check if reading is OK
-
508  for(uint8_t i = 0; i < min(sizeof (remote_name), sizeof (hcibuf) - 9); i++) {
-
509  remote_name[i] = hcibuf[9 + i];
-
510  if(remote_name[i] == '\0') // End of string
+
508  for(uint8_t i = 0; i < min(sizeof (remote_name), sizeof (hcibuf) - 9); i++) {
+
509  remote_name[i] = hcibuf[9 + i];
+
510  if(remote_name[i] == '\0') // End of string
511  break;
512  }
513  hci_set_flag(HCI_FLAG_REMOTE_NAME_COMPLETE);
@@ -887,592 +887,589 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
796  if(hci_check_flag(HCI_FLAG_REMOTE_NAME_COMPLETE)) {
797 #ifdef DEBUG_USB_HOST
798  Notify(PSTR("\r\nRemote Name: "), 0x80);
-
799  for(uint8_t i = 0; i < 30; i++) {
-
800  if(remote_name[i] == '\0') // End of string
-
801  break;
-
802  Notifyc(remote_name[i], 0x80);
-
803  }
-
804 #endif
-
805  if(strncmp((const char*)remote_name, "Nintendo", 8) == 0) {
-
806  incomingWii = true;
-
807 #ifdef DEBUG_USB_HOST
-
808  Notify(PSTR("\r\nWiimote is connecting"), 0x80);
-
809 #endif
-
810  if(strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) {
-
811 #ifdef DEBUG_USB_HOST
-
812  Notify(PSTR(" with Motion Plus Inside"), 0x80);
-
813 #endif
-
814  motionPlusInside = true;
-
815  } else if(strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) {
-
816 #ifdef DEBUG_USB_HOST
-
817  Notify(PSTR(" - Wii U Pro Controller"), 0x80);
-
818 #endif
-
819  motionPlusInside = true;
-
820  wiiUProController = true;
-
821  } else {
-
822  motionPlusInside = false;
-
823  wiiUProController = false;
-
824  }
-
825  }
-
826  if(classOfDevice[2] == 0 && classOfDevice[1] == 0x25 && classOfDevice[0] == 0x08 && strncmp((const char*)remote_name, "Wireless Controller", 19) == 0) {
-
827 #ifdef DEBUG_USB_HOST
-
828  Notify(PSTR("\r\nPS4 controller is connecting"), 0x80);
-
829 #endif
-
830  incomingPS4 = true;
-
831  }
-
832  if(pairWithWii && motionPlusInside)
-
833  hci_state = HCI_CONNECT_DEVICE_STATE;
-
834  else {
-
835  hci_accept_connection();
-
836  hci_state = HCI_CONNECTED_STATE;
-
837  }
-
838  }
-
839  break;
-
840 
-
841  case HCI_CONNECTED_STATE:
-
842  if(hci_check_flag(HCI_FLAG_CONNECT_COMPLETE)) {
-
843 #ifdef DEBUG_USB_HOST
-
844  Notify(PSTR("\r\nConnected to Device: "), 0x80);
-
845  for(int8_t i = 5; i > 0; i--) {
-
846  D_PrintHex<uint8_t > (disc_bdaddr[i], 0x80);
-
847  Notify(PSTR(":"), 0x80);
-
848  }
-
849  D_PrintHex<uint8_t > (disc_bdaddr[0], 0x80);
-
850 #endif
-
851  if(incomingPS4)
-
852  connectToHIDDevice = true; // We should always connect to the PS4 controller
-
853 
-
854  // Clear these flags for a new connection
-
855  l2capConnectionClaimed = false;
-
856  sdpConnectionClaimed = false;
-
857  rfcommConnectionClaimed = false;
-
858 
-
859  hci_event_flag = 0;
-
860  hci_state = HCI_DONE_STATE;
-
861  }
-
862  break;
-
863 
-
864  case HCI_DONE_STATE:
-
865  hci_counter++;
-
866  if(hci_counter > 1000) { // Wait until we have looped 1000 times to make sure that the L2CAP connection has been started
-
867  hci_counter = 0;
-
868  hci_state = HCI_SCANNING_STATE;
-
869  }
-
870  break;
-
871 
-
872  case HCI_DISCONNECT_STATE:
-
873  if(hci_check_flag(HCI_FLAG_DISCONNECT_COMPLETE)) {
-
874 #ifdef DEBUG_USB_HOST
-
875  Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80);
-
876 #endif
-
877  hci_event_flag = 0; // Clear all flags
-
878 
-
879  // Reset all buffers
-
880  memset(hcibuf, 0, BULK_MAXPKTSIZE);
-
881  memset(l2capinbuf, 0, BULK_MAXPKTSIZE);
-
882 
-
883  connectToWii = incomingWii = pairWithWii = false;
-
884  connectToHIDDevice = incomingHIDDevice = pairWithHIDDevice = false;
-
885  incomingPS4 = false;
-
886 
-
887  hci_state = HCI_SCANNING_STATE;
-
888  }
-
889  break;
-
890  default:
-
891  break;
-
892  }
-
893 }
-
894 
-
895 void BTD::ACL_event_task() {
-
896  uint16_t length = BULK_MAXPKTSIZE;
-
897  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf); // Input on endpoint 2
-
898 
-
899  if(!rcode) { // Check for errors
-
900  if(length > 0) { // Check if any data was read
-
901  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
-
902  if(btService[i])
-
903  btService[i]->ACLData(l2capinbuf);
-
904  }
-
905  }
-
906  }
-
907 #ifdef EXTRADEBUG
-
908  else if(rcode != hrNAK) {
-
909  Notify(PSTR("\r\nACL data in error: "), 0x80);
-
910  D_PrintHex<uint8_t > (rcode, 0x80);
-
911  }
-
912 #endif
-
913  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
-
914  if(btService[i])
-
915  btService[i]->Run();
-
916 }
+
799  for(uint8_t i = 0; i < strlen(remote_name); i++)
+
800  Notifyc(remote_name[i], 0x80);
+
801 #endif
+
802  if(strncmp((const char*)remote_name, "Nintendo", 8) == 0) {
+
803  incomingWii = true;
+
804 #ifdef DEBUG_USB_HOST
+
805  Notify(PSTR("\r\nWiimote is connecting"), 0x80);
+
806 #endif
+
807  if(strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) {
+
808 #ifdef DEBUG_USB_HOST
+
809  Notify(PSTR(" with Motion Plus Inside"), 0x80);
+
810 #endif
+
811  motionPlusInside = true;
+
812  } else if(strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) {
+
813 #ifdef DEBUG_USB_HOST
+
814  Notify(PSTR(" - Wii U Pro Controller"), 0x80);
+
815 #endif
+
816  motionPlusInside = true;
+
817  wiiUProController = true;
+
818  } else {
+
819  motionPlusInside = false;
+
820  wiiUProController = false;
+
821  }
+
822  }
+
823  if(classOfDevice[2] == 0 && classOfDevice[1] == 0x25 && classOfDevice[0] == 0x08 && strncmp((const char*)remote_name, "Wireless Controller", 19) == 0) {
+
824 #ifdef DEBUG_USB_HOST
+
825  Notify(PSTR("\r\nPS4 controller is connecting"), 0x80);
+
826 #endif
+
827  incomingPS4 = true;
+
828  }
+
829  if(pairWithWii && motionPlusInside)
+
830  hci_state = HCI_CONNECT_DEVICE_STATE;
+
831  else {
+
832  hci_accept_connection();
+
833  hci_state = HCI_CONNECTED_STATE;
+
834  }
+
835  }
+
836  break;
+
837 
+
838  case HCI_CONNECTED_STATE:
+
839  if(hci_check_flag(HCI_FLAG_CONNECT_COMPLETE)) {
+
840 #ifdef DEBUG_USB_HOST
+
841  Notify(PSTR("\r\nConnected to Device: "), 0x80);
+
842  for(int8_t i = 5; i > 0; i--) {
+
843  D_PrintHex<uint8_t > (disc_bdaddr[i], 0x80);
+
844  Notify(PSTR(":"), 0x80);
+
845  }
+
846  D_PrintHex<uint8_t > (disc_bdaddr[0], 0x80);
+
847 #endif
+
848  if(incomingPS4)
+
849  connectToHIDDevice = true; // We should always connect to the PS4 controller
+
850 
+
851  // Clear these flags for a new connection
+
852  l2capConnectionClaimed = false;
+
853  sdpConnectionClaimed = false;
+
854  rfcommConnectionClaimed = false;
+
855 
+
856  hci_event_flag = 0;
+
857  hci_state = HCI_DONE_STATE;
+
858  }
+
859  break;
+
860 
+
861  case HCI_DONE_STATE:
+
862  hci_counter++;
+
863  if(hci_counter > 1000) { // Wait until we have looped 1000 times to make sure that the L2CAP connection has been started
+
864  hci_counter = 0;
+
865  hci_state = HCI_SCANNING_STATE;
+
866  }
+
867  break;
+
868 
+
869  case HCI_DISCONNECT_STATE:
+
870  if(hci_check_flag(HCI_FLAG_DISCONNECT_COMPLETE)) {
+
871 #ifdef DEBUG_USB_HOST
+
872  Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80);
+
873 #endif
+
874  hci_event_flag = 0; // Clear all flags
+
875 
+
876  // Reset all buffers
+
877  memset(hcibuf, 0, BULK_MAXPKTSIZE);
+
878  memset(l2capinbuf, 0, BULK_MAXPKTSIZE);
+
879 
+
880  connectToWii = incomingWii = pairWithWii = false;
+
881  connectToHIDDevice = incomingHIDDevice = pairWithHIDDevice = false;
+
882  incomingPS4 = false;
+
883 
+
884  hci_state = HCI_SCANNING_STATE;
+
885  }
+
886  break;
+
887  default:
+
888  break;
+
889  }
+
890 }
+
891 
+
892 void BTD::ACL_event_task() {
+
893  uint16_t length = BULK_MAXPKTSIZE;
+
894  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf); // Input on endpoint 2
+
895 
+
896  if(!rcode) { // Check for errors
+
897  if(length > 0) { // Check if any data was read
+
898  for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) {
+
899  if(btService[i])
+
900  btService[i]->ACLData(l2capinbuf);
+
901  }
+
902  }
+
903  }
+
904 #ifdef EXTRADEBUG
+
905  else if(rcode != hrNAK) {
+
906  Notify(PSTR("\r\nACL data in error: "), 0x80);
+
907  D_PrintHex<uint8_t > (rcode, 0x80);
+
908  }
+
909 #endif
+
910  for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
+
911  if(btService[i])
+
912  btService[i]->Run();
+
913 }
+
914 
+
915 /************************************************************/
+
916 /* HCI Commands */
917 
918 /************************************************************/
-
919 /* HCI Commands */
-
920 
-
921 /************************************************************/
-
922 void BTD::HCI_Command(uint8_t* data, uint16_t nbytes) {
-
923  hci_clear_flag(HCI_FLAG_CMD_COMPLETE);
-
924  pUsb->ctrlReq(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bmREQ_HCI_OUT, 0x00, 0x00, 0x00, 0x00, nbytes, nbytes, data, NULL);
-
925 }
-
926 
-
927 void BTD::hci_reset() {
-
928  hci_event_flag = 0; // Clear all the flags
-
929  hcibuf[0] = 0x03; // HCI OCF = 3
-
930  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
931  hcibuf[2] = 0x00;
+
919 void BTD::HCI_Command(uint8_t* data, uint16_t nbytes) {
+
920  hci_clear_flag(HCI_FLAG_CMD_COMPLETE);
+
921  pUsb->ctrlReq(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bmREQ_HCI_OUT, 0x00, 0x00, 0x00, 0x00, nbytes, nbytes, data, NULL);
+
922 }
+
923 
+
924 void BTD::hci_reset() {
+
925  hci_event_flag = 0; // Clear all the flags
+
926  hcibuf[0] = 0x03; // HCI OCF = 3
+
927  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
928  hcibuf[2] = 0x00;
+
929 
+
930  HCI_Command(hcibuf, 3);
+
931 }
932 
-
933  HCI_Command(hcibuf, 3);
-
934 }
-
935 
-
936 void BTD::hci_write_scan_enable() {
-
937  hci_clear_flag(HCI_FLAG_INCOMING_REQUEST);
-
938  hcibuf[0] = 0x1A; // HCI OCF = 1A
-
939  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
940  hcibuf[2] = 0x01; // parameter length = 1
-
941  if(btdName != NULL)
-
942  hcibuf[3] = 0x03; // Inquiry Scan enabled. Page Scan enabled.
-
943  else
-
944  hcibuf[3] = 0x02; // Inquiry Scan disabled. Page Scan enabled.
+
933 void BTD::hci_write_scan_enable() {
+
934  hci_clear_flag(HCI_FLAG_INCOMING_REQUEST);
+
935  hcibuf[0] = 0x1A; // HCI OCF = 1A
+
936  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
937  hcibuf[2] = 0x01; // parameter length = 1
+
938  if(btdName != NULL)
+
939  hcibuf[3] = 0x03; // Inquiry Scan enabled. Page Scan enabled.
+
940  else
+
941  hcibuf[3] = 0x02; // Inquiry Scan disabled. Page Scan enabled.
+
942 
+
943  HCI_Command(hcibuf, 4);
+
944 }
945 
-
946  HCI_Command(hcibuf, 4);
-
947 }
-
948 
-
949 void BTD::hci_write_scan_disable() {
-
950  hcibuf[0] = 0x1A; // HCI OCF = 1A
-
951  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
952  hcibuf[2] = 0x01; // parameter length = 1
-
953  hcibuf[3] = 0x00; // Inquiry Scan disabled. Page Scan disabled.
+
946 void BTD::hci_write_scan_disable() {
+
947  hcibuf[0] = 0x1A; // HCI OCF = 1A
+
948  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
949  hcibuf[2] = 0x01; // parameter length = 1
+
950  hcibuf[3] = 0x00; // Inquiry Scan disabled. Page Scan disabled.
+
951 
+
952  HCI_Command(hcibuf, 4);
+
953 }
954 
-
955  HCI_Command(hcibuf, 4);
-
956 }
-
957 
-
958 void BTD::hci_read_bdaddr() {
-
959  hci_clear_flag(HCI_FLAG_READ_BDADDR);
-
960  hcibuf[0] = 0x09; // HCI OCF = 9
-
961  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
-
962  hcibuf[2] = 0x00;
+
955 void BTD::hci_read_bdaddr() {
+
956  hci_clear_flag(HCI_FLAG_READ_BDADDR);
+
957  hcibuf[0] = 0x09; // HCI OCF = 9
+
958  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
+
959  hcibuf[2] = 0x00;
+
960 
+
961  HCI_Command(hcibuf, 3);
+
962 }
963 
-
964  HCI_Command(hcibuf, 3);
-
965 }
-
966 
-
967 void BTD::hci_read_local_version_information() {
-
968  hci_clear_flag(HCI_FLAG_READ_VERSION);
-
969  hcibuf[0] = 0x01; // HCI OCF = 1
-
970  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
-
971  hcibuf[2] = 0x00;
+
964 void BTD::hci_read_local_version_information() {
+
965  hci_clear_flag(HCI_FLAG_READ_VERSION);
+
966  hcibuf[0] = 0x01; // HCI OCF = 1
+
967  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
+
968  hcibuf[2] = 0x00;
+
969 
+
970  HCI_Command(hcibuf, 3);
+
971 }
972 
-
973  HCI_Command(hcibuf, 3);
-
974 }
-
975 
-
976 void BTD::hci_accept_connection() {
-
977  hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE);
-
978  hcibuf[0] = 0x09; // HCI OCF = 9
-
979  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
980  hcibuf[2] = 0x07; // parameter length 7
-
981  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
982  hcibuf[4] = disc_bdaddr[1];
-
983  hcibuf[5] = disc_bdaddr[2];
-
984  hcibuf[6] = disc_bdaddr[3];
-
985  hcibuf[7] = disc_bdaddr[4];
-
986  hcibuf[8] = disc_bdaddr[5];
-
987  hcibuf[9] = 0x00; // Switch role to master
+
973 void BTD::hci_accept_connection() {
+
974  hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE);
+
975  hcibuf[0] = 0x09; // HCI OCF = 9
+
976  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
977  hcibuf[2] = 0x07; // parameter length 7
+
978  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
979  hcibuf[4] = disc_bdaddr[1];
+
980  hcibuf[5] = disc_bdaddr[2];
+
981  hcibuf[6] = disc_bdaddr[3];
+
982  hcibuf[7] = disc_bdaddr[4];
+
983  hcibuf[8] = disc_bdaddr[5];
+
984  hcibuf[9] = 0x00; // Switch role to master
+
985 
+
986  HCI_Command(hcibuf, 10);
+
987 }
988 
-
989  HCI_Command(hcibuf, 10);
-
990 }
-
991 
-
992 void BTD::hci_remote_name() {
-
993  hci_clear_flag(HCI_FLAG_REMOTE_NAME_COMPLETE);
-
994  hcibuf[0] = 0x19; // HCI OCF = 19
-
995  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
996  hcibuf[2] = 0x0A; // parameter length = 10
-
997  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
998  hcibuf[4] = disc_bdaddr[1];
-
999  hcibuf[5] = disc_bdaddr[2];
-
1000  hcibuf[6] = disc_bdaddr[3];
-
1001  hcibuf[7] = disc_bdaddr[4];
-
1002  hcibuf[8] = disc_bdaddr[5];
-
1003  hcibuf[9] = 0x01; // Page Scan Repetition Mode
-
1004  hcibuf[10] = 0x00; // Reserved
-
1005  hcibuf[11] = 0x00; // Clock offset - low byte
-
1006  hcibuf[12] = 0x00; // Clock offset - high byte
+
989 void BTD::hci_remote_name() {
+
990  hci_clear_flag(HCI_FLAG_REMOTE_NAME_COMPLETE);
+
991  hcibuf[0] = 0x19; // HCI OCF = 19
+
992  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
993  hcibuf[2] = 0x0A; // parameter length = 10
+
994  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
995  hcibuf[4] = disc_bdaddr[1];
+
996  hcibuf[5] = disc_bdaddr[2];
+
997  hcibuf[6] = disc_bdaddr[3];
+
998  hcibuf[7] = disc_bdaddr[4];
+
999  hcibuf[8] = disc_bdaddr[5];
+
1000  hcibuf[9] = 0x01; // Page Scan Repetition Mode
+
1001  hcibuf[10] = 0x00; // Reserved
+
1002  hcibuf[11] = 0x00; // Clock offset - low byte
+
1003  hcibuf[12] = 0x00; // Clock offset - high byte
+
1004 
+
1005  HCI_Command(hcibuf, 13);
+
1006 }
1007 
-
1008  HCI_Command(hcibuf, 13);
-
1009 }
-
1010 
-
1011 void BTD::hci_set_local_name(const char* name) {
-
1012  hcibuf[0] = 0x13; // HCI OCF = 13
-
1013  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
1014  hcibuf[2] = strlen(name) + 1; // parameter length = the length of the string + end byte
-
1015  uint8_t i;
-
1016  for(i = 0; i < strlen(name); i++)
-
1017  hcibuf[i + 3] = name[i];
-
1018  hcibuf[i + 3] = 0x00; // End of string
+
1008 void BTD::hci_set_local_name(const char* name) {
+
1009  hcibuf[0] = 0x13; // HCI OCF = 13
+
1010  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
1011  hcibuf[2] = strlen(name) + 1; // parameter length = the length of the string + end byte
+
1012  uint8_t i;
+
1013  for(i = 0; i < strlen(name); i++)
+
1014  hcibuf[i + 3] = name[i];
+
1015  hcibuf[i + 3] = 0x00; // End of string
+
1016 
+
1017  HCI_Command(hcibuf, 4 + strlen(name));
+
1018 }
1019 
-
1020  HCI_Command(hcibuf, 4 + strlen(name));
-
1021 }
-
1022 
-
1023 void BTD::hci_inquiry() {
-
1024  hci_clear_flag(HCI_FLAG_DEVICE_FOUND);
-
1025  hcibuf[0] = 0x01;
-
1026  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1027  hcibuf[2] = 0x05; // Parameter Total Length = 5
-
1028  hcibuf[3] = 0x33; // LAP: Genera/Unlimited Inquiry Access Code (GIAC = 0x9E8B33) - see https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
-
1029  hcibuf[4] = 0x8B;
-
1030  hcibuf[5] = 0x9E;
-
1031  hcibuf[6] = 0x30; // Inquiry time = 61.44 sec (maximum)
-
1032  hcibuf[7] = 0x0A; // 10 number of responses
+
1020 void BTD::hci_inquiry() {
+
1021  hci_clear_flag(HCI_FLAG_DEVICE_FOUND);
+
1022  hcibuf[0] = 0x01;
+
1023  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1024  hcibuf[2] = 0x05; // Parameter Total Length = 5
+
1025  hcibuf[3] = 0x33; // LAP: Genera/Unlimited Inquiry Access Code (GIAC = 0x9E8B33) - see https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
+
1026  hcibuf[4] = 0x8B;
+
1027  hcibuf[5] = 0x9E;
+
1028  hcibuf[6] = 0x30; // Inquiry time = 61.44 sec (maximum)
+
1029  hcibuf[7] = 0x0A; // 10 number of responses
+
1030 
+
1031  HCI_Command(hcibuf, 8);
+
1032 }
1033 
-
1034  HCI_Command(hcibuf, 8);
-
1035 }
-
1036 
-
1037 void BTD::hci_inquiry_cancel() {
-
1038  hcibuf[0] = 0x02;
-
1039  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1040  hcibuf[2] = 0x00; // Parameter Total Length = 0
+
1034 void BTD::hci_inquiry_cancel() {
+
1035  hcibuf[0] = 0x02;
+
1036  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1037  hcibuf[2] = 0x00; // Parameter Total Length = 0
+
1038 
+
1039  HCI_Command(hcibuf, 3);
+
1040 }
1041 
-
1042  HCI_Command(hcibuf, 3);
-
1043 }
-
1044 
-
1045 void BTD::hci_connect() {
-
1046  hci_connect(disc_bdaddr); // Use last discovered device
-
1047 }
-
1048 
-
1049 void BTD::hci_connect(uint8_t *bdaddr) {
-
1050  hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE | HCI_FLAG_CONNECT_EVENT);
-
1051  hcibuf[0] = 0x05;
-
1052  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1053  hcibuf[2] = 0x0D; // parameter Total Length = 13
-
1054  hcibuf[3] = bdaddr[0]; // 6 octet bdaddr (LSB)
-
1055  hcibuf[4] = bdaddr[1];
-
1056  hcibuf[5] = bdaddr[2];
-
1057  hcibuf[6] = bdaddr[3];
-
1058  hcibuf[7] = bdaddr[4];
-
1059  hcibuf[8] = bdaddr[5];
-
1060  hcibuf[9] = 0x18; // DM1 or DH1 may be used
-
1061  hcibuf[10] = 0xCC; // DM3, DH3, DM5, DH5 may be used
-
1062  hcibuf[11] = 0x01; // Page repetition mode R1
-
1063  hcibuf[12] = 0x00; // Reserved
-
1064  hcibuf[13] = 0x00; // Clock offset
-
1065  hcibuf[14] = 0x00; // Invalid clock offset
-
1066  hcibuf[15] = 0x00; // Do not allow role switch
+
1042 void BTD::hci_connect() {
+
1043  hci_connect(disc_bdaddr); // Use last discovered device
+
1044 }
+
1045 
+
1046 void BTD::hci_connect(uint8_t *bdaddr) {
+
1047  hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE | HCI_FLAG_CONNECT_EVENT);
+
1048  hcibuf[0] = 0x05;
+
1049  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1050  hcibuf[2] = 0x0D; // parameter Total Length = 13
+
1051  hcibuf[3] = bdaddr[0]; // 6 octet bdaddr (LSB)
+
1052  hcibuf[4] = bdaddr[1];
+
1053  hcibuf[5] = bdaddr[2];
+
1054  hcibuf[6] = bdaddr[3];
+
1055  hcibuf[7] = bdaddr[4];
+
1056  hcibuf[8] = bdaddr[5];
+
1057  hcibuf[9] = 0x18; // DM1 or DH1 may be used
+
1058  hcibuf[10] = 0xCC; // DM3, DH3, DM5, DH5 may be used
+
1059  hcibuf[11] = 0x01; // Page repetition mode R1
+
1060  hcibuf[12] = 0x00; // Reserved
+
1061  hcibuf[13] = 0x00; // Clock offset
+
1062  hcibuf[14] = 0x00; // Invalid clock offset
+
1063  hcibuf[15] = 0x00; // Do not allow role switch
+
1064 
+
1065  HCI_Command(hcibuf, 16);
+
1066 }
1067 
-
1068  HCI_Command(hcibuf, 16);
-
1069 }
-
1070 
-
1071 void BTD::hci_pin_code_request_reply() {
-
1072  hcibuf[0] = 0x0D; // HCI OCF = 0D
-
1073  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1074  hcibuf[2] = 0x17; // parameter length 23
-
1075  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
1076  hcibuf[4] = disc_bdaddr[1];
-
1077  hcibuf[5] = disc_bdaddr[2];
-
1078  hcibuf[6] = disc_bdaddr[3];
-
1079  hcibuf[7] = disc_bdaddr[4];
-
1080  hcibuf[8] = disc_bdaddr[5];
-
1081  if(pairWithWii) {
-
1082  hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
-
1083  if(wiiUProController) {
-
1084 #ifdef DEBUG_USB_HOST
-
1085  Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80);
-
1086 #endif
-
1087  for(uint8_t i = 0; i < 6; i++)
-
1088  hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards
-
1089  } else {
-
1090  for(uint8_t i = 0; i < 6; i++)
-
1091  hcibuf[10 + i] = disc_bdaddr[i]; // The pin is the Wiimote's Bluetooth address backwards
-
1092  }
-
1093  for(uint8_t i = 16; i < 26; i++)
-
1094  hcibuf[i] = 0x00; // The rest should be 0
-
1095  } else {
-
1096  hcibuf[9] = strlen(btdPin); // Length of pin
-
1097  uint8_t i;
-
1098  for(i = 0; i < strlen(btdPin); i++) // The maximum size of the pin is 16
-
1099  hcibuf[i + 10] = btdPin[i];
-
1100  for(; i < 16; i++)
-
1101  hcibuf[i + 10] = 0x00; // The rest should be 0
-
1102  }
+
1068 void BTD::hci_pin_code_request_reply() {
+
1069  hcibuf[0] = 0x0D; // HCI OCF = 0D
+
1070  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1071  hcibuf[2] = 0x17; // parameter length 23
+
1072  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1073  hcibuf[4] = disc_bdaddr[1];
+
1074  hcibuf[5] = disc_bdaddr[2];
+
1075  hcibuf[6] = disc_bdaddr[3];
+
1076  hcibuf[7] = disc_bdaddr[4];
+
1077  hcibuf[8] = disc_bdaddr[5];
+
1078  if(pairWithWii) {
+
1079  hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
+
1080  if(wiiUProController) {
+
1081 #ifdef DEBUG_USB_HOST
+
1082  Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80);
+
1083 #endif
+
1084  for(uint8_t i = 0; i < 6; i++)
+
1085  hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards
+
1086  } else {
+
1087  for(uint8_t i = 0; i < 6; i++)
+
1088  hcibuf[10 + i] = disc_bdaddr[i]; // The pin is the Wiimote's Bluetooth address backwards
+
1089  }
+
1090  for(uint8_t i = 16; i < 26; i++)
+
1091  hcibuf[i] = 0x00; // The rest should be 0
+
1092  } else {
+
1093  hcibuf[9] = strlen(btdPin); // Length of pin
+
1094  uint8_t i;
+
1095  for(i = 0; i < strlen(btdPin); i++) // The maximum size of the pin is 16
+
1096  hcibuf[i + 10] = btdPin[i];
+
1097  for(; i < 16; i++)
+
1098  hcibuf[i + 10] = 0x00; // The rest should be 0
+
1099  }
+
1100 
+
1101  HCI_Command(hcibuf, 26);
+
1102 }
1103 
-
1104  HCI_Command(hcibuf, 26);
-
1105 }
-
1106 
-
1107 void BTD::hci_pin_code_negative_request_reply() {
-
1108  hcibuf[0] = 0x0E; // HCI OCF = 0E
-
1109  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1110  hcibuf[2] = 0x06; // parameter length 6
-
1111  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
1112  hcibuf[4] = disc_bdaddr[1];
-
1113  hcibuf[5] = disc_bdaddr[2];
-
1114  hcibuf[6] = disc_bdaddr[3];
-
1115  hcibuf[7] = disc_bdaddr[4];
-
1116  hcibuf[8] = disc_bdaddr[5];
+
1104 void BTD::hci_pin_code_negative_request_reply() {
+
1105  hcibuf[0] = 0x0E; // HCI OCF = 0E
+
1106  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1107  hcibuf[2] = 0x06; // parameter length 6
+
1108  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1109  hcibuf[4] = disc_bdaddr[1];
+
1110  hcibuf[5] = disc_bdaddr[2];
+
1111  hcibuf[6] = disc_bdaddr[3];
+
1112  hcibuf[7] = disc_bdaddr[4];
+
1113  hcibuf[8] = disc_bdaddr[5];
+
1114 
+
1115  HCI_Command(hcibuf, 9);
+
1116 }
1117 
-
1118  HCI_Command(hcibuf, 9);
-
1119 }
-
1120 
-
1121 void BTD::hci_link_key_request_negative_reply() {
-
1122  hcibuf[0] = 0x0C; // HCI OCF = 0C
-
1123  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1124  hcibuf[2] = 0x06; // parameter length 6
-
1125  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
1126  hcibuf[4] = disc_bdaddr[1];
-
1127  hcibuf[5] = disc_bdaddr[2];
-
1128  hcibuf[6] = disc_bdaddr[3];
-
1129  hcibuf[7] = disc_bdaddr[4];
-
1130  hcibuf[8] = disc_bdaddr[5];
+
1118 void BTD::hci_link_key_request_negative_reply() {
+
1119  hcibuf[0] = 0x0C; // HCI OCF = 0C
+
1120  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1121  hcibuf[2] = 0x06; // parameter length 6
+
1122  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1123  hcibuf[4] = disc_bdaddr[1];
+
1124  hcibuf[5] = disc_bdaddr[2];
+
1125  hcibuf[6] = disc_bdaddr[3];
+
1126  hcibuf[7] = disc_bdaddr[4];
+
1127  hcibuf[8] = disc_bdaddr[5];
+
1128 
+
1129  HCI_Command(hcibuf, 9);
+
1130 }
1131 
-
1132  HCI_Command(hcibuf, 9);
-
1133 }
-
1134 
-
1135 void BTD::hci_authentication_request() {
-
1136  hcibuf[0] = 0x11; // HCI OCF = 11
-
1137  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1138  hcibuf[2] = 0x02; // parameter length = 2
-
1139  hcibuf[3] = (uint8_t)(hci_handle & 0xFF); //connection handle - low byte
-
1140  hcibuf[4] = (uint8_t)((hci_handle >> 8) & 0x0F); //connection handle - high byte
+
1132 void BTD::hci_authentication_request() {
+
1133  hcibuf[0] = 0x11; // HCI OCF = 11
+
1134  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1135  hcibuf[2] = 0x02; // parameter length = 2
+
1136  hcibuf[3] = (uint8_t)(hci_handle & 0xFF); //connection handle - low byte
+
1137  hcibuf[4] = (uint8_t)((hci_handle >> 8) & 0x0F); //connection handle - high byte
+
1138 
+
1139  HCI_Command(hcibuf, 5);
+
1140 }
1141 
-
1142  HCI_Command(hcibuf, 5);
-
1143 }
-
1144 
-
1145 void BTD::hci_disconnect(uint16_t handle) { // This is called by the different services
-
1146  hci_clear_flag(HCI_FLAG_DISCONNECT_COMPLETE);
-
1147  hcibuf[0] = 0x06; // HCI OCF = 6
-
1148  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1149  hcibuf[2] = 0x03; // parameter length = 3
-
1150  hcibuf[3] = (uint8_t)(handle & 0xFF); //connection handle - low byte
-
1151  hcibuf[4] = (uint8_t)((handle >> 8) & 0x0F); //connection handle - high byte
-
1152  hcibuf[5] = 0x13; // reason
+
1142 void BTD::hci_disconnect(uint16_t handle) { // This is called by the different services
+
1143  hci_clear_flag(HCI_FLAG_DISCONNECT_COMPLETE);
+
1144  hcibuf[0] = 0x06; // HCI OCF = 6
+
1145  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1146  hcibuf[2] = 0x03; // parameter length = 3
+
1147  hcibuf[3] = (uint8_t)(handle & 0xFF); //connection handle - low byte
+
1148  hcibuf[4] = (uint8_t)((handle >> 8) & 0x0F); //connection handle - high byte
+
1149  hcibuf[5] = 0x13; // reason
+
1150 
+
1151  HCI_Command(hcibuf, 6);
+
1152 }
1153 
-
1154  HCI_Command(hcibuf, 6);
-
1155 }
-
1156 
-
1157 void BTD::hci_write_class_of_device() { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
-
1158  hcibuf[0] = 0x24; // HCI OCF = 24
-
1159  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
1160  hcibuf[2] = 0x03; // parameter length = 3
-
1161  hcibuf[3] = 0x04; // Robot
-
1162  hcibuf[4] = 0x08; // Toy
-
1163  hcibuf[5] = 0x00;
-
1164 
-
1165  HCI_Command(hcibuf, 6);
-
1166 }
-
1167 /*******************************************************************
-
1168  * *
-
1169  * HCI ACL Data Packet *
-
1170  * *
-
1171  * buf[0] buf[1] buf[2] buf[3]
-
1172  * 0 4 8 11 12 16 24 31 MSB
-
1173  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1174  * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet
-
1175  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1176  *
-
1177  * buf[4] buf[5] buf[6] buf[7]
-
1178  * 0 8 16 31 MSB
-
1179  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1180  * | Length | Channel ID | Basic L2CAP header
-
1181  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1182  *
-
1183  * buf[8] buf[9] buf[10] buf[11]
-
1184  * 0 8 16 31 MSB
-
1185  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1186  * | Code | Identifier | Length | Control frame (C-frame)
-
1187  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format)
-
1188  */
+
1154 void BTD::hci_write_class_of_device() { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
+
1155  hcibuf[0] = 0x24; // HCI OCF = 24
+
1156  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
1157  hcibuf[2] = 0x03; // parameter length = 3
+
1158  hcibuf[3] = 0x04; // Robot
+
1159  hcibuf[4] = 0x08; // Toy
+
1160  hcibuf[5] = 0x00;
+
1161 
+
1162  HCI_Command(hcibuf, 6);
+
1163 }
+
1164 /*******************************************************************
+
1165  * *
+
1166  * HCI ACL Data Packet *
+
1167  * *
+
1168  * buf[0] buf[1] buf[2] buf[3]
+
1169  * 0 4 8 11 12 16 24 31 MSB
+
1170  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1171  * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet
+
1172  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1173  *
+
1174  * buf[4] buf[5] buf[6] buf[7]
+
1175  * 0 8 16 31 MSB
+
1176  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1177  * | Length | Channel ID | Basic L2CAP header
+
1178  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1179  *
+
1180  * buf[8] buf[9] buf[10] buf[11]
+
1181  * 0 8 16 31 MSB
+
1182  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1183  * | Code | Identifier | Length | Control frame (C-frame)
+
1184  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format)
+
1185  */
+
1186 /************************************************************/
+
1187 /* L2CAP Commands */
+
1188 
1189 /************************************************************/
-
1190 /* L2CAP Commands */
-
1191 
-
1192 /************************************************************/
-
1193 void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
-
1194  uint8_t buf[8 + nbytes];
-
1195  buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
-
1196  buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
-
1197  buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
-
1198  buf[3] = (uint8_t)((4 + nbytes) >> 8);
-
1199  buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
-
1200  buf[5] = (uint8_t)(nbytes >> 8);
-
1201  buf[6] = channelLow;
-
1202  buf[7] = channelHigh;
+
1190 void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
+
1191  uint8_t buf[8 + nbytes];
+
1192  buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
+
1193  buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
+
1194  buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
+
1195  buf[3] = (uint8_t)((4 + nbytes) >> 8);
+
1196  buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
+
1197  buf[5] = (uint8_t)(nbytes >> 8);
+
1198  buf[6] = channelLow;
+
1199  buf[7] = channelHigh;
+
1200 
+
1201  for(uint16_t i = 0; i < nbytes; i++) // L2CAP C-frame
+
1202  buf[8 + i] = data[i];
1203 
-
1204  for(uint16_t i = 0; i < nbytes; i++) // L2CAP C-frame
-
1205  buf[8 + i] = data[i];
-
1206 
-
1207  uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf);
-
1208  if(rcode) {
-
1209  delay(100); // This small delay prevents it from overflowing if it fails
-
1210 #ifdef DEBUG_USB_HOST
-
1211  Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
-
1212  D_PrintHex<uint8_t > (rcode, 0x80);
-
1213  Notify(PSTR(" - Channel ID: "), 0x80);
-
1214  D_PrintHex<uint8_t > (channelHigh, 0x80);
-
1215  Notify(PSTR(" "), 0x80);
-
1216  D_PrintHex<uint8_t > (channelLow, 0x80);
-
1217 #endif
-
1218  }
-
1219 }
-
1220 
-
1221 void BTD::l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm) {
-
1222  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_REQUEST; // Code
-
1223  l2capoutbuf[1] = rxid; // Identifier
-
1224  l2capoutbuf[2] = 0x04; // Length
-
1225  l2capoutbuf[3] = 0x00;
-
1226  l2capoutbuf[4] = (uint8_t)(psm & 0xff); // PSM
-
1227  l2capoutbuf[5] = (uint8_t)(psm >> 8);
-
1228  l2capoutbuf[6] = scid[0]; // Source CID
-
1229  l2capoutbuf[7] = scid[1];
+
1204  uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf);
+
1205  if(rcode) {
+
1206  delay(100); // This small delay prevents it from overflowing if it fails
+
1207 #ifdef DEBUG_USB_HOST
+
1208  Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
+
1209  D_PrintHex<uint8_t > (rcode, 0x80);
+
1210  Notify(PSTR(" - Channel ID: "), 0x80);
+
1211  D_PrintHex<uint8_t > (channelHigh, 0x80);
+
1212  Notify(PSTR(" "), 0x80);
+
1213  D_PrintHex<uint8_t > (channelLow, 0x80);
+
1214 #endif
+
1215  }
+
1216 }
+
1217 
+
1218 void BTD::l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm) {
+
1219  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_REQUEST; // Code
+
1220  l2capoutbuf[1] = rxid; // Identifier
+
1221  l2capoutbuf[2] = 0x04; // Length
+
1222  l2capoutbuf[3] = 0x00;
+
1223  l2capoutbuf[4] = (uint8_t)(psm & 0xff); // PSM
+
1224  l2capoutbuf[5] = (uint8_t)(psm >> 8);
+
1225  l2capoutbuf[6] = scid[0]; // Source CID
+
1226  l2capoutbuf[7] = scid[1];
+
1227 
+
1228  L2CAP_Command(handle, l2capoutbuf, 8);
+
1229 }
1230 
-
1231  L2CAP_Command(handle, l2capoutbuf, 8);
-
1232 }
-
1233 
-
1234 void BTD::l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result) {
-
1235  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_RESPONSE; // Code
-
1236  l2capoutbuf[1] = rxid; // Identifier
-
1237  l2capoutbuf[2] = 0x08; // Length
-
1238  l2capoutbuf[3] = 0x00;
-
1239  l2capoutbuf[4] = dcid[0]; // Destination CID
-
1240  l2capoutbuf[5] = dcid[1];
-
1241  l2capoutbuf[6] = scid[0]; // Source CID
-
1242  l2capoutbuf[7] = scid[1];
-
1243  l2capoutbuf[8] = result; // Result: Pending or Success
-
1244  l2capoutbuf[9] = 0x00;
-
1245  l2capoutbuf[10] = 0x00; // No further information
-
1246  l2capoutbuf[11] = 0x00;
+
1231 void BTD::l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result) {
+
1232  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_RESPONSE; // Code
+
1233  l2capoutbuf[1] = rxid; // Identifier
+
1234  l2capoutbuf[2] = 0x08; // Length
+
1235  l2capoutbuf[3] = 0x00;
+
1236  l2capoutbuf[4] = dcid[0]; // Destination CID
+
1237  l2capoutbuf[5] = dcid[1];
+
1238  l2capoutbuf[6] = scid[0]; // Source CID
+
1239  l2capoutbuf[7] = scid[1];
+
1240  l2capoutbuf[8] = result; // Result: Pending or Success
+
1241  l2capoutbuf[9] = 0x00;
+
1242  l2capoutbuf[10] = 0x00; // No further information
+
1243  l2capoutbuf[11] = 0x00;
+
1244 
+
1245  L2CAP_Command(handle, l2capoutbuf, 12);
+
1246 }
1247 
-
1248  L2CAP_Command(handle, l2capoutbuf, 12);
-
1249 }
-
1250 
-
1251 void BTD::l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid) {
-
1252  l2capoutbuf[0] = L2CAP_CMD_CONFIG_REQUEST; // Code
-
1253  l2capoutbuf[1] = rxid; // Identifier
-
1254  l2capoutbuf[2] = 0x08; // Length
-
1255  l2capoutbuf[3] = 0x00;
-
1256  l2capoutbuf[4] = dcid[0]; // Destination CID
-
1257  l2capoutbuf[5] = dcid[1];
-
1258  l2capoutbuf[6] = 0x00; // Flags
-
1259  l2capoutbuf[7] = 0x00;
-
1260  l2capoutbuf[8] = 0x01; // Config Opt: type = MTU (Maximum Transmission Unit) - Hint
-
1261  l2capoutbuf[9] = 0x02; // Config Opt: length
-
1262  l2capoutbuf[10] = 0xFF; // MTU
-
1263  l2capoutbuf[11] = 0xFF;
+
1248 void BTD::l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid) {
+
1249  l2capoutbuf[0] = L2CAP_CMD_CONFIG_REQUEST; // Code
+
1250  l2capoutbuf[1] = rxid; // Identifier
+
1251  l2capoutbuf[2] = 0x08; // Length
+
1252  l2capoutbuf[3] = 0x00;
+
1253  l2capoutbuf[4] = dcid[0]; // Destination CID
+
1254  l2capoutbuf[5] = dcid[1];
+
1255  l2capoutbuf[6] = 0x00; // Flags
+
1256  l2capoutbuf[7] = 0x00;
+
1257  l2capoutbuf[8] = 0x01; // Config Opt: type = MTU (Maximum Transmission Unit) - Hint
+
1258  l2capoutbuf[9] = 0x02; // Config Opt: length
+
1259  l2capoutbuf[10] = 0xFF; // MTU
+
1260  l2capoutbuf[11] = 0xFF;
+
1261 
+
1262  L2CAP_Command(handle, l2capoutbuf, 12);
+
1263 }
1264 
-
1265  L2CAP_Command(handle, l2capoutbuf, 12);
-
1266 }
-
1267 
-
1268 void BTD::l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid) {
-
1269  l2capoutbuf[0] = L2CAP_CMD_CONFIG_RESPONSE; // Code
-
1270  l2capoutbuf[1] = rxid; // Identifier
-
1271  l2capoutbuf[2] = 0x0A; // Length
-
1272  l2capoutbuf[3] = 0x00;
-
1273  l2capoutbuf[4] = scid[0]; // Source CID
-
1274  l2capoutbuf[5] = scid[1];
-
1275  l2capoutbuf[6] = 0x00; // Flag
-
1276  l2capoutbuf[7] = 0x00;
-
1277  l2capoutbuf[8] = 0x00; // Result
-
1278  l2capoutbuf[9] = 0x00;
-
1279  l2capoutbuf[10] = 0x01; // Config
-
1280  l2capoutbuf[11] = 0x02;
-
1281  l2capoutbuf[12] = 0xA0;
-
1282  l2capoutbuf[13] = 0x02;
+
1265 void BTD::l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid) {
+
1266  l2capoutbuf[0] = L2CAP_CMD_CONFIG_RESPONSE; // Code
+
1267  l2capoutbuf[1] = rxid; // Identifier
+
1268  l2capoutbuf[2] = 0x0A; // Length
+
1269  l2capoutbuf[3] = 0x00;
+
1270  l2capoutbuf[4] = scid[0]; // Source CID
+
1271  l2capoutbuf[5] = scid[1];
+
1272  l2capoutbuf[6] = 0x00; // Flag
+
1273  l2capoutbuf[7] = 0x00;
+
1274  l2capoutbuf[8] = 0x00; // Result
+
1275  l2capoutbuf[9] = 0x00;
+
1276  l2capoutbuf[10] = 0x01; // Config
+
1277  l2capoutbuf[11] = 0x02;
+
1278  l2capoutbuf[12] = 0xA0;
+
1279  l2capoutbuf[13] = 0x02;
+
1280 
+
1281  L2CAP_Command(handle, l2capoutbuf, 14);
+
1282 }
1283 
-
1284  L2CAP_Command(handle, l2capoutbuf, 14);
-
1285 }
-
1286 
-
1287 void BTD::l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
-
1288  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_REQUEST; // Code
-
1289  l2capoutbuf[1] = rxid; // Identifier
-
1290  l2capoutbuf[2] = 0x04; // Length
-
1291  l2capoutbuf[3] = 0x00;
-
1292  l2capoutbuf[4] = dcid[0];
-
1293  l2capoutbuf[5] = dcid[1];
-
1294  l2capoutbuf[6] = scid[0];
-
1295  l2capoutbuf[7] = scid[1];
+
1284 void BTD::l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
+
1285  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_REQUEST; // Code
+
1286  l2capoutbuf[1] = rxid; // Identifier
+
1287  l2capoutbuf[2] = 0x04; // Length
+
1288  l2capoutbuf[3] = 0x00;
+
1289  l2capoutbuf[4] = dcid[0];
+
1290  l2capoutbuf[5] = dcid[1];
+
1291  l2capoutbuf[6] = scid[0];
+
1292  l2capoutbuf[7] = scid[1];
+
1293 
+
1294  L2CAP_Command(handle, l2capoutbuf, 8);
+
1295 }
1296 
-
1297  L2CAP_Command(handle, l2capoutbuf, 8);
-
1298 }
-
1299 
-
1300 void BTD::l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
-
1301  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_RESPONSE; // Code
-
1302  l2capoutbuf[1] = rxid; // Identifier
-
1303  l2capoutbuf[2] = 0x04; // Length
-
1304  l2capoutbuf[3] = 0x00;
-
1305  l2capoutbuf[4] = dcid[0];
-
1306  l2capoutbuf[5] = dcid[1];
-
1307  l2capoutbuf[6] = scid[0];
-
1308  l2capoutbuf[7] = scid[1];
+
1297 void BTD::l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
+
1298  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_RESPONSE; // Code
+
1299  l2capoutbuf[1] = rxid; // Identifier
+
1300  l2capoutbuf[2] = 0x04; // Length
+
1301  l2capoutbuf[3] = 0x00;
+
1302  l2capoutbuf[4] = dcid[0];
+
1303  l2capoutbuf[5] = dcid[1];
+
1304  l2capoutbuf[6] = scid[0];
+
1305  l2capoutbuf[7] = scid[1];
+
1306 
+
1307  L2CAP_Command(handle, l2capoutbuf, 8);
+
1308 }
1309 
-
1310  L2CAP_Command(handle, l2capoutbuf, 8);
-
1311 }
-
1312 
-
1313 void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh) {
-
1314  l2capoutbuf[0] = L2CAP_CMD_INFORMATION_RESPONSE; // Code
-
1315  l2capoutbuf[1] = rxid; // Identifier
-
1316  l2capoutbuf[2] = 0x08; // Length
-
1317  l2capoutbuf[3] = 0x00;
-
1318  l2capoutbuf[4] = infoTypeLow;
-
1319  l2capoutbuf[5] = infoTypeHigh;
-
1320  l2capoutbuf[6] = 0x00; // Result = success
-
1321  l2capoutbuf[7] = 0x00; // Result = success
-
1322  l2capoutbuf[8] = 0x00;
-
1323  l2capoutbuf[9] = 0x00;
-
1324  l2capoutbuf[10] = 0x00;
-
1325  l2capoutbuf[11] = 0x00;
+
1310 void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh) {
+
1311  l2capoutbuf[0] = L2CAP_CMD_INFORMATION_RESPONSE; // Code
+
1312  l2capoutbuf[1] = rxid; // Identifier
+
1313  l2capoutbuf[2] = 0x08; // Length
+
1314  l2capoutbuf[3] = 0x00;
+
1315  l2capoutbuf[4] = infoTypeLow;
+
1316  l2capoutbuf[5] = infoTypeHigh;
+
1317  l2capoutbuf[6] = 0x00; // Result = success
+
1318  l2capoutbuf[7] = 0x00; // Result = success
+
1319  l2capoutbuf[8] = 0x00;
+
1320  l2capoutbuf[9] = 0x00;
+
1321  l2capoutbuf[10] = 0x00;
+
1322  l2capoutbuf[11] = 0x00;
+
1323 
+
1324  L2CAP_Command(handle, l2capoutbuf, 12);
+
1325 }
1326 
-
1327  L2CAP_Command(handle, l2capoutbuf, 12);
-
1328 }
-
1329 
-
1330 /* PS3 Commands - only set Bluetooth address is implemented in this library */
-
1331 void BTD::setBdaddr(uint8_t* bdaddr) {
-
1332  /* Set the internal Bluetooth address */
-
1333  uint8_t buf[8];
-
1334  buf[0] = 0x01;
-
1335  buf[1] = 0x00;
+
1327 /* PS3 Commands - only set Bluetooth address is implemented in this library */
+
1328 void BTD::setBdaddr(uint8_t* bdaddr) {
+
1329  /* Set the internal Bluetooth address */
+
1330  uint8_t buf[8];
+
1331  buf[0] = 0x01;
+
1332  buf[1] = 0x00;
+
1333 
+
1334  for(uint8_t i = 0; i < 6; i++)
+
1335  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
1336 
-
1337  for(uint8_t i = 0; i < 6; i++)
-
1338  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
-
1339 
-
1340  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
1341  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
-
1342 }
-
1343 
-
1344 void BTD::setMoveBdaddr(uint8_t* bdaddr) {
-
1345  /* Set the internal Bluetooth address */
-
1346  uint8_t buf[11];
-
1347  buf[0] = 0x05;
-
1348  buf[7] = 0x10;
-
1349  buf[8] = 0x01;
-
1350  buf[9] = 0x02;
-
1351  buf[10] = 0x12;
+
1337  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
1338  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
+
1339 }
+
1340 
+
1341 void BTD::setMoveBdaddr(uint8_t* bdaddr) {
+
1342  /* Set the internal Bluetooth address */
+
1343  uint8_t buf[11];
+
1344  buf[0] = 0x05;
+
1345  buf[7] = 0x10;
+
1346  buf[8] = 0x01;
+
1347  buf[9] = 0x02;
+
1348  buf[10] = 0x12;
+
1349 
+
1350  for(uint8_t i = 0; i < 6; i++)
+
1351  buf[i + 1] = bdaddr[i];
1352 
-
1353  for(uint8_t i = 0; i < 6; i++)
-
1354  buf[i + 1] = bdaddr[i];
-
1355 
-
1356  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
1357  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
-
1358 }
+
1353  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
1354  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
+
1355 }
BTD::BTD_DATAOUT_PIPE
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:557
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:766
BTD::incomingWii
bool incomingWii
Definition: BTD.h:507
AddressPool
Definition: address.h:83
-
BTD::hci_connect
void hci_connect()
Definition: BTD.cpp:1045
+
BTD::hci_connect
void hci_connect()
Definition: BTD.cpp:1042
BTD::bNumEP
uint8_t bNumEP
Definition: BTD.h:546
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
BTD::btdName
const char * btdName
Definition: BTD.h:480
-
BTD::hci_reset
void hci_reset()
Definition: BTD.cpp:927
-
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1234
+
BTD::hci_reset
void hci_reset()
Definition: BTD.cpp:924
+
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1231
HCI_SCANNING_STATE
#define HCI_SCANNING_STATE
Definition: BTD.h:54
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
-
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1221
+
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1218
EV_COMMAND_STATUS
#define EV_COMMAND_STATUS
Definition: BTD.h:98
EV_REMOTE_NAME_COMPLETE
#define EV_REMOTE_NAME_COMPLETE
Definition: BTD.h:85
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
BTD::sdpConnectionClaimed
bool sdpConnectionClaimed
Definition: BTD.h:475
bmREQ_HCI_OUT
#define bmREQ_HCI_OUT
Definition: BTD.h:36
-
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1287
+
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1284
UsbDevice
Definition: address.h:75
BTD::rfcommConnectionClaimed
bool rfcommConnectionClaimed
Definition: BTD.h:477
BTD::hci_version
uint8_t hci_version
Definition: BTD.h:497
USB_DEVICE_DESCRIPTOR::idVendor
uint16_t idVendor
Definition: usb_ch9.h:106
EV_INQUIRY_COMPLETE
#define EV_INQUIRY_COMPLETE
Definition: BTD.h:79
-
BTD::hci_inquiry
void hci_inquiry()
Definition: BTD.cpp:1023
+
BTD::hci_inquiry
void hci_inquiry()
Definition: BTD.cpp:1020
BTD::BTD_EVENT_PIPE
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:553
PS3MOVE_PID
#define PS3MOVE_PID
Definition: BTD.h:27
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
@@ -1480,12 +1477,13 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:509
USB_ENDPOINT_DESCRIPTOR::bLength
uint8_t bLength
Definition: usb_ch9.h:142
USB_DEVICE_DESCRIPTOR::bMaxPacketSize0
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:105
-
BTD::hci_write_scan_disable
void hci_write_scan_disable()
Definition: BTD.cpp:949
+
BTD::hci_write_scan_disable
void hci_write_scan_disable()
Definition: BTD.cpp:946
NotifyFail
#define NotifyFail(...)
Definition: message.h:55
HCI_SET_NAME_STATE
#define HCI_SET_NAME_STATE
Definition: BTD.h:47
BTD::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: BTD.cpp:314
EV_LINK_KEY_REQUEST
#define EV_LINK_KEY_REQUEST
Definition: BTD.h:91
HCI_DONE_STATE
#define HCI_DONE_STATE
Definition: BTD.h:59
+
BTD_NUM_SERVICES
#define BTD_NUM_SERVICES
Definition: BTD.h:190
EV_DATA_BUFFER_OVERFLOW
#define EV_DATA_BUFFER_OVERFLOW
Definition: BTD.h:93
HCI_DISCONNECT_STATE
#define HCI_DISCONNECT_STATE
Definition: BTD.h:60
HCI_FLAG_CONNECT_COMPLETE
#define HCI_FLAG_CONNECT_COMPLETE
Definition: BTD.h:64
@@ -1494,8 +1492,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
BTD::btdPin
const char * btdPin
Definition: BTD.h:482
BTD::motionPlusInside
bool motionPlusInside
Definition: BTD.h:511
EV_AUTHENTICATION_COMPLETE
#define EV_AUTHENTICATION_COMPLETE
Definition: BTD.h:84
-
BTD::hci_remote_name
void hci_remote_name()
Definition: BTD.cpp:992
-
BTD::remote_name
uint8_t remote_name[30]
Definition: BTD.h:491
+
BTD::hci_remote_name
void hci_remote_name()
Definition: BTD.cpp:989
HCI_FLAG_CONNECT_EVENT
#define HCI_FLAG_CONNECT_EVENT
Definition: BTD.h:71
HCI_FLAG_DISCONNECT_COMPLETE
#define HCI_FLAG_DISCONNECT_COMPLETE
Definition: BTD.h:65
HCI_REMOTE_NAME_STATE
#define HCI_REMOTE_NAME_STATE
Definition: BTD.h:56
@@ -1504,18 +1501,19 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
PS3_VID
#define PS3_VID
Definition: BTD.h:24
NotifyFailGetDevDescr
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
BTD::BTD
BTD(USB *p)
Definition: BTD.cpp:27
+
BTD::remote_name
char remote_name[30]
Definition: BTD.h:491
hrJERR
#define hrJERR
Definition: max3421e.h:225
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
BluetoothService::Reset
virtual void Reset()
EV_MAX_SLOTS_CHANGE
#define EV_MAX_SLOTS_CHANGE
Definition: BTD.h:94
BTD::BTD_DATAIN_PIPE
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:555
-
BTD::hci_set_local_name
void hci_set_local_name(const char *name)
Definition: BTD.cpp:1011
+
BTD::hci_set_local_name
void hci_set_local_name(const char *name)
Definition: BTD.cpp:1008
EV_QOS_SETUP_COMPLETE
#define EV_QOS_SETUP_COMPLETE
Definition: BTD.h:96
-
BTD::hci_write_scan_enable
void hci_write_scan_enable()
Definition: BTD.cpp:936
+
BTD::hci_write_scan_enable
void hci_write_scan_enable()
Definition: BTD.cpp:933
BTD::Release
virtual uint8_t Release()
Definition: BTD.cpp:365
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
-
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1300
+
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1297
USB::ctrlReq
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
BTD::watingForConnection
bool watingForConnection
Definition: BTD.h:471
@@ -1547,12 +1545,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
BTD::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:122
Notifyc
#define Notifyc(...)
Definition: message.h:46
EpInfo
Definition: address.h:32
-
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1145
+
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1142
HCI_RESET_STATE
#define HCI_RESET_STATE
Definition: BTD.h:43
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
hrNAK
#define hrNAK
Definition: max3421e.h:216
-
BTD::hci_read_bdaddr
void hci_read_bdaddr()
Definition: BTD.cpp:958
-
BTD::hci_inquiry_cancel
void hci_inquiry_cancel()
Definition: BTD.cpp:1037
+
BTD::hci_read_bdaddr
void hci_read_bdaddr()
Definition: BTD.cpp:955
+
BTD::hci_inquiry_cancel
void hci_inquiry_cancel()
Definition: BTD.cpp:1034
L2CAP_CMD_INFORMATION_RESPONSE
#define L2CAP_CMD_INFORMATION_RESPONSE
Definition: BTD.h:173
USB_ENDPOINT_DESCRIPTOR::wMaxPacketSize
uint16_t wMaxPacketSize
Definition: usb_ch9.h:146
BTD::my_bdaddr
uint8_t my_bdaddr[6]
Definition: BTD.h:485
@@ -1589,16 +1587,16 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:171
EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE
#define EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE
Definition: BTD.h:95
EV_COMMAND_COMPLETE
#define EV_COMMAND_COMPLETE
Definition: BTD.h:97
-
BTD::l2cap_information_response
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1313
+
BTD::l2cap_information_response
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1310
USB_DEVICE_DESCRIPTOR::idProduct
uint16_t idProduct
Definition: usb_ch9.h:107
L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
Definition: BTD.h:167
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:169
hci_set_flag
#define hci_set_flag(flag)
Definition: BTD.h:75
-
BTD::hci_write_class_of_device
void hci_write_class_of_device()
Definition: BTD.cpp:1157
+
BTD::hci_write_class_of_device
void hci_write_class_of_device()
Definition: BTD.cpp:1154
HCI_CONNECTED_DEVICE_STATE
#define HCI_CONNECTED_DEVICE_STATE
Definition: BTD.h:52
HCI_INIT_STATE
#define HCI_INIT_STATE
Definition: BTD.h:42
bmREQ_HID_OUT
#define bmREQ_HID_OUT
Definition: BTD.h:38
-
BTD::hci_pin_code_negative_request_reply
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1107
+
BTD::hci_pin_code_negative_request_reply
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1104
EV_CHANGE_CONNECTION_LINK
#define EV_CHANGE_CONNECTION_LINK
Definition: BTD.h:87
USB_DEVICE_DESCRIPTOR::bNumConfigurations
uint8_t bNumConfigurations
Definition: usb_ch9.h:112
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
@@ -1610,14 +1608,13 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
USB
Definition: UsbCore.h:176
BluetoothService::Run
virtual void Run()
BTD::bConfNum
uint8_t bConfNum
Definition: BTD.h:544
-
BTD::hci_link_key_request_negative_reply
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1121
+
BTD::hci_link_key_request_negative_reply
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1118
EV_LOOPBACK_COMMAND
#define EV_LOOPBACK_COMMAND
Definition: BTD.h:99
-
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1193
-
BTD_NUMSERVICES
#define BTD_NUMSERVICES
Definition: BTD.h:190
+
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1190
EV_LINK_KEY_NOTIFICATION
#define EV_LINK_KEY_NOTIFICATION
Definition: BTD.h:92
-
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1268
-
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1251
-
BTD::hci_pin_code_request_reply
void hci_pin_code_request_reply()
Definition: BTD.cpp:1071
+
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1265
+
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1248
+
BTD::hci_pin_code_request_reply
void hci_pin_code_request_reply()
Definition: BTD.cpp:1068
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:166
BTD.h
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
@@ -1626,17 +1623,17 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
hci_clear_flag
#define hci_clear_flag(flag)
Definition: BTD.h:76
BTD::pUsb
USB * pUsb
Definition: BTD.h:533
NotifyStr
#define NotifyStr(...)
Definition: message.h:45
-
BTD::hci_authentication_request
void hci_authentication_request()
Definition: BTD.cpp:1135
-
BTD::hci_read_local_version_information
void hci_read_local_version_information()
Definition: BTD.cpp:967
+
BTD::hci_authentication_request
void hci_authentication_request()
Definition: BTD.cpp:1132
+
BTD::hci_read_local_version_information
void hci_read_local_version_information()
Definition: BTD.cpp:964
HCI_FLAG_REMOTE_NAME_COMPLETE
#define HCI_FLAG_REMOTE_NAME_COMPLETE
Definition: BTD.h:66
-
BTD::hci_accept_connection
void hci_accept_connection()
Definition: BTD.cpp:976
+
BTD::hci_accept_connection
void hci_accept_connection()
Definition: BTD.cpp:973
EV_PAGE_SCAN_REP_MODE
#define EV_PAGE_SCAN_REP_MODE
Definition: BTD.h:100
HCI_FLAG_DEVICE_FOUND
#define HCI_FLAG_DEVICE_FOUND
Definition: BTD.h:70
HCI_CLASS_STATE
#define HCI_CLASS_STATE
Definition: BTD.h:44
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
Definition: UsbCore.h:72
-
BTD::HCI_Command
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:922
+
BTD::HCI_Command
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:919
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
diff --git a/_b_t_d_8h.html b/_b_t_d_8h.html index 7e8ccfbd..6c40d86d 100644 --- a/_b_t_d_8h.html +++ b/_b_t_d_8h.html @@ -105,7 +105,7 @@ This graph shows which files directly or indirectly include this file:
- +

Go to the source code of this file.

@@ -353,8 +353,8 @@ Macros   #define BTD_MAX_ENDPOINTS   4   -#define BTD_NUMSERVICES   4 -  +#define BTD_NUM_SERVICES   4 +  #define PAIR   1   #define UHS_ACL_HANDLE_OK(x, y)   ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20))) @@ -2023,12 +2023,12 @@ Macros - +
- +
#define BTD_NUMSERVICES   4#define BTD_NUM_SERVICES   4
diff --git a/_b_t_d_8h__dep__incl.map b/_b_t_d_8h__dep__incl.map index 792f0e4d..23dd3813 100644 --- a/_b_t_d_8h__dep__incl.map +++ b/_b_t_d_8h__dep__incl.map @@ -1,13 +1,12 @@ - - - + + + - - - - + + + diff --git a/_b_t_d_8h__dep__incl.md5 b/_b_t_d_8h__dep__incl.md5 index 01d32675..c136623d 100644 --- a/_b_t_d_8h__dep__incl.md5 +++ b/_b_t_d_8h__dep__incl.md5 @@ -1 +1 @@ -359d0fb9802ea91c25ab343278928ac0 \ No newline at end of file +a586d33041837831328e4bd5a24cb1bb \ No newline at end of file diff --git a/_b_t_d_8h__dep__incl.png b/_b_t_d_8h__dep__incl.png index 7b28b330..8d7511ce 100644 Binary files a/_b_t_d_8h__dep__incl.png and b/_b_t_d_8h__dep__incl.png differ diff --git a/_b_t_d_8h_source.html b/_b_t_d_8h_source.html index c6e00629..d3242b15 100644 --- a/_b_t_d_8h_source.html +++ b/_b_t_d_8h_source.html @@ -278,7 +278,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
187 #define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface
188 
189 #define BTD_MAX_ENDPOINTS 4
-
190 #define BTD_NUMSERVICES 4 // Max number of Bluetooth services - if you need more than 4 simply increase this number
+
190 #define BTD_NUM_SERVICES 4 // Max number of Bluetooth services - if you need more than 4 simply increase this number
191 
192 #define PAIR 1
193 
@@ -338,13 +338,13 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
306  };
318  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
322  void disconnect() {
-
323  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
+
323  for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
324  if(btService[i])
325  btService[i]->disconnect();
326  };
327 
-
334  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
+
334  for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) {
335  if(!btService[i]) {
336  btService[i] = pService;
337  return i; // Return ID
@@ -391,7 +391,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
485  uint8_t my_bdaddr[6];
487  uint16_t hci_handle;
489  uint8_t disc_bdaddr[6];
-
491  uint8_t remote_name[30];
+
491  char remote_name[30];
497  uint8_t hci_version;
498 
@@ -434,7 +434,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
564 
565 private:
566  void Initialize(); // Set all variables, endpoint structs etc. to default values
-
567  BluetoothService* btService[BTD_NUMSERVICES];
+
568 
569  uint16_t PID, VID; // PID and VID of device connected
570 
@@ -445,15 +445,15 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
575  uint8_t classOfDevice[3]; // Class of device of last device
576 
577  /* Variables used by high level HCI task */
-
578  uint8_t hci_state; //current state of bluetooth hci connection
-
579  uint16_t hci_counter; // counter used for bluetooth hci reset loops
-
580  uint16_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset
-
581  uint16_t hci_event_flag; // hci flags of received bluetooth events
+
578  uint8_t hci_state; // Current state of Bluetooth HCI connection
+
579  uint16_t hci_counter; // Counter used for Bluetooth HCI reset loops
+
580  uint16_t hci_num_reset_loops; // This value indicate how many times it should read before trying to reset
+
581  uint16_t hci_event_flag; // HCI flags of received Bluetooth events
582  uint8_t inquiry_counter;
583 
-
584  uint8_t hcibuf[BULK_MAXPKTSIZE]; //General purpose buffer for hci data
-
585  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; //General purpose buffer for l2cap in data
-
586  uint8_t l2capoutbuf[14]; //General purpose buffer for l2cap out data
+
584  uint8_t hcibuf[BULK_MAXPKTSIZE]; // General purpose buffer for HCI data
+
585  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data
+
586  uint8_t l2capoutbuf[14]; // General purpose buffer for L2CAP out data
587 
588  /* State machines */
589  void HCI_event_task(); // Poll the HCI event pipe
@@ -467,41 +467,42 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
597 #endif
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:557
bool incomingWii
Definition: BTD.h:507
-
void hci_connect()
Definition: BTD.cpp:1045
+
void hci_connect()
Definition: BTD.cpp:1042
uint8_t bNumEP
Definition: BTD.h:546
const char * btdName
Definition: BTD.h:480
-
void hci_reset()
Definition: BTD.cpp:927
-
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1234
-
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1221
+
void hci_reset()
Definition: BTD.cpp:924
+
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1231
+
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1218
bool sdpConnectionClaimed
Definition: BTD.h:475
Definition: BTD.h:230
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: BTD.h:287
-
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1287
+
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1284
bool rfcommConnectionClaimed
Definition: BTD.h:477
uint8_t hci_version
Definition: BTD.h:497
-
void hci_inquiry()
Definition: BTD.cpp:1023
+
void hci_inquiry()
Definition: BTD.cpp:1020
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:553
#define PS3MOVE_PID
Definition: BTD.h:27
bool pairWithWii
Definition: BTD.h:509
-
void hci_write_scan_disable()
Definition: BTD.cpp:949
+
void hci_write_scan_disable()
Definition: BTD.cpp:946
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: BTD.cpp:314
virtual uint8_t GetAddress()
Definition: BTD.h:270
+
#define BTD_NUM_SERVICES
Definition: BTD.h:190
const char * btdPin
Definition: BTD.h:482
bool motionPlusInside
Definition: BTD.h:511
-
void hci_remote_name()
Definition: BTD.cpp:992
-
uint8_t remote_name[30]
Definition: BTD.h:491
+
void hci_remote_name()
Definition: BTD.cpp:989
#define PS3_VID
Definition: BTD.h:24
BTD(USB *p)
Definition: BTD.cpp:27
+
char remote_name[30]
Definition: BTD.h:491
uint8_t readPollInterval()
Definition: BTD.h:531
virtual void Reset()
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:555
-
void hci_set_local_name(const char *name)
Definition: BTD.cpp:1011
-
void hci_write_scan_enable()
Definition: BTD.cpp:936
+
void hci_set_local_name(const char *name)
Definition: BTD.cpp:1008
+
void hci_write_scan_enable()
Definition: BTD.cpp:933
virtual uint8_t Release()
Definition: BTD.cpp:365
-
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1300
+
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1297
#define USB_CLASS_WIRELESS_CTRL
Definition: UsbCore.h:55
bool watingForConnection
Definition: BTD.h:471
bool connectToHIDDevice
Definition: BTD.h:519
@@ -518,10 +519,10 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:122
Definition: address.h:32
void pairWithHID()
Definition: BTD.h:516
-
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1145
+
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1142
-
void hci_read_bdaddr()
Definition: BTD.cpp:958
-
void hci_inquiry_cancel()
Definition: BTD.cpp:1037
+
void hci_read_bdaddr()
Definition: BTD.cpp:955
+
void hci_inquiry_cancel()
Definition: BTD.cpp:1034
uint8_t my_bdaddr[6]
Definition: BTD.h:485
virtual uint8_t Poll()
Definition: BTD.cpp:371
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: BTD.h:298
@@ -538,27 +539,26 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
#define PS3_PID
Definition: BTD.h:25
#define BTD_MAX_ENDPOINTS
Definition: BTD.h:189
#define PS3NAVIGATION_PID
Definition: BTD.h:26
-
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1313
-
void hci_write_class_of_device()
Definition: BTD.cpp:1157
-
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1107
+
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1310
+
void hci_write_class_of_device()
Definition: BTD.cpp:1154
+
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1104
#define HCI_CHECK_DEVICE_SERVICE
Definition: BTD.h:48
Definition: UsbCore.h:176
virtual void Run()
uint8_t bConfNum
Definition: BTD.h:544
-
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1121
+
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1118
void pairWithWiimote()
Definition: BTD.h:500
virtual bool isReady()
Definition: BTD.h:278
-
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1193
-
#define BTD_NUMSERVICES
Definition: BTD.h:190
-
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1268
-
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1251
-
void hci_pin_code_request_reply()
Definition: BTD.cpp:1071
+
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1190
+
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1265
+
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1248
+
void hci_pin_code_request_reply()
Definition: BTD.cpp:1068
virtual void disconnect()
USB * pUsb
Definition: BTD.h:533
-
void hci_authentication_request()
Definition: BTD.cpp:1135
-
void hci_read_local_version_information()
Definition: BTD.cpp:967
-
void hci_accept_connection()
Definition: BTD.cpp:976
-
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:922
+
void hci_authentication_request()
Definition: BTD.cpp:1132
+
void hci_read_local_version_information()
Definition: BTD.cpp:964
+
void hci_accept_connection()
Definition: BTD.cpp:973
+
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:919