30connectToHIDDevice(
false),
31pairWithHIDDevice(
false),
32useSimplePairing(
false),
38simple_pairing_supported(
false),
89 p->lowspeed = lowspeed;
101 Notify(
PSTR(
"\r\nOut of address space"), 0x80);
106 if (
udd->bDeviceClass == 0x09)
113 PID =
udd->idProduct;
119 Notify(
PSTR(
"\r\nPlease create a hub instance in your code: \"USBHub Hub1(&Usb);\""), 0x80);
180 p->lowspeed = lowspeed;
195 Notify(
PSTR(
"\r\nDualshock 3 Controller Connected"), 0x80);
197 Notify(
PSTR(
"\r\nNavigation Controller Connected"), 0x80);
199 Notify(
PSTR(
"\r\nMotion Controller Connected"), 0x80);
204 Notify(
PSTR(
"\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\r\nor set the Bluetooth address in the constructor of the PS3BT class"), 0x80);
212 Notify(
PSTR(
"\r\nBluetooth Address was set to: "), 0x80);
256 hci_num_reset_loops = 100;
263 Notify(
PSTR(
"\r\nBluetooth Dongle Initialized"), 0x80);
295 Notify(
PSTR(
"\r\nBTD Init Failed, error code: "), 0x80);
302void BTD::Initialize() {
320 incomingPSController =
false;
326 simple_pairing_supported =
false;
356 pollInterval =
pep->bInterval;
362 Notify(
PSTR(
"\r\nEndpoint descriptor:"), 0x80);
403void BTD::HCI_event_task() {
412 if((hcibuf[3] == 0x01) && (hcibuf[4] == 0x10)) {
421 }
else if((hcibuf[3] == 0x04) && (hcibuf[4] == 0x10)) {
426 Notify(
PSTR(
"\r\nMaximum page number: "), 0x80);
428 Notify(
PSTR(
"\r\nExtended LMP features:"), 0x80);
438 if(hcibuf[8 + 6] & (1U << 3)) {
439 simple_pairing_supported =
true;
444 simple_pairing_supported =
false;
450 Notify(
PSTR(
" secure simple pairing (controller support)"), 0x80);
452 }
else if(hcibuf[6] == 1) {
455 if(hcibuf[8 + 0] & (1U << 0))
459 Notify(
PSTR(
" secure simple pairing (host support)"), 0x80);
465 }
else if((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) {
476 Notify(
PSTR(
"\r\nHCI Command Failed: "), 0x80);
478 Notify(
PSTR(
"\r\nNum HCI Command Packets: "), 0x80);
493 Notify(
PSTR(
"\r\nCouldn't find Wiimote"), 0x80);
495 Notify(
PSTR(
"\r\nCouldn't find HID device"), 0x80);
510 Notify(
PSTR(
"\r\nNumber of responses: "), 0x80);
532 if(
pairWithWii && (classOfDevice[2] == 0x00) && ((classOfDevice[1] & 0x0F) == 0x05) && (classOfDevice[0] & 0x0C)) {
533 checkRemoteName =
true;
540 }
else if(
pairWithHIDDevice && ((classOfDevice[1] & 0x0F) == 0x05) && (classOfDevice[0] & 0xC8)) {
542 checkRemoteName =
true;
544 if(classOfDevice[0] & 0x80)
546 if(classOfDevice[0] & 0x40)
548 if(classOfDevice[0] & 0x08)
565 Notify(
PSTR(
"\r\nConnection established"), 0x80);
567 hci_handle = hcibuf[3] | ((hcibuf[4] & 0x0F) << 8);
572 Notify(
PSTR(
"\r\nConnection Failed: "), 0x80);
602 classOfDevice[
i] = hcibuf[
i + 8];
604 if(((classOfDevice[1] & 0x0F) == 0x05) && (classOfDevice[0] & 0xC8)) {
606 if(classOfDevice[0] & 0x80)
607 Notify(
PSTR(
"\r\nMouse is connecting"), 0x80);
608 if(classOfDevice[0] & 0x40)
609 Notify(
PSTR(
"\r\nKeyboard is connecting"), 0x80);
610 if(classOfDevice[0] & 0x08)
611 Notify(
PSTR(
"\r\nGamepad is connecting"), 0x80);
630 Notify(
PSTR(
"\r\nPairing with Wiimote"), 0x80);
635 Notify(
PSTR(
"\r\nBluetooth pin is set too: "), 0x80);
649 Notify(
PSTR(
"\r\nReceived Key Request"), 0x80);
658 Notify(
PSTR(
"\r\nPairing successful with Wiimote"), 0x80);
663 Notify(
PSTR(
"\r\nPairing successful with HID device"), 0x80);
668 Notify(
PSTR(
"\r\nPairing was successful"), 0x80);
683 Notify(
PSTR(
"\r\nReceived IO Capability Request"), 0x80);
690 Notify(
PSTR(
"\r\nReceived IO Capability Response: "), 0x80);
695 Notify(
PSTR(
"\r\nAuthentication request: "), 0x80);
702 Notify(
PSTR(
"\r\nUser confirmation Request"), 0x80);
718 Notify(
PSTR(
"\r\nSimple Pairing succeeded"), 0x80);
720 Notify(
PSTR(
"\r\nSimple Pairing failed: "), 0x80);
740 if(hcibuf[0] != 0x00) {
748 if(hcibuf[0] != 0x00) {
749 Notify(
PSTR(
"\r\nUnmanaged HCI Event: "), 0x80);
770void BTD::HCI_task() {
774 if(hci_counter > hci_num_reset_loops) {
790 }
else if(hci_counter > hci_num_reset_loops) {
791 hci_num_reset_loops *= 10;
792 if(hci_num_reset_loops > 2000)
793 hci_num_reset_loops = 2000;
795 Notify(
PSTR(
"\r\nNo response to HCI Reset"), 0x80);
805 Notify(
PSTR(
"\r\nWrite class of device"), 0x80);
815 Notify(
PSTR(
"\r\nLocal Bluetooth Address: "), 0x80);
844 Notify(
PSTR(
"\r\nThe name was set to: "), 0x80);
858 if(simple_pairing_supported) {
869 Notify(
PSTR(
"\r\nSimple pairing was enabled"), 0x80);
879 Notify(
PSTR(
"\r\nSet event mask completed"), 0x80);
889 Notify(
PSTR(
"\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press the SYNC button if you are using a Wii U Pro Controller or a Wii Balance Board"), 0x80);
891 Notify(
PSTR(
"\r\nPlease enable discovery of your device"), 0x80);
908 Notify(
PSTR(
"\r\nNow just create the instance like so:"), 0x80);
914 Notify(
PSTR(
"\r\nAnd then press any button on the "), 0x80);
920 if(checkRemoteName) {
932 Notify(
PSTR(
"\r\nConnecting to Wiimote"), 0x80);
934 Notify(
PSTR(
"\r\nConnecting to HID device"), 0x80);
936 checkRemoteName =
false;
947 Notify(
PSTR(
"\r\nConnected to Wiimote"), 0x80);
949 Notify(
PSTR(
"\r\nConnected to HID device"), 0x80);
955 Notify(
PSTR(
"\r\nTrying to connect one more time..."), 0x80);
965 Notify(
PSTR(
"\r\nWait For Incoming Connection Request"), 0x80);
977 Notify(
PSTR(
"\r\nIncoming Connection Request"), 0x80);
996 pairWiiUsingSync =
false;
998 Notify(
PSTR(
"\r\nWiimote is connecting"), 0x80);
1001#ifdef DEBUG_USB_HOST
1002 Notify(
PSTR(
" with Motion Plus Inside"), 0x80);
1006#ifdef DEBUG_USB_HOST
1007 Notify(
PSTR(
" - Wii U Pro Controller"), 0x80);
1011#ifdef DEBUG_USB_HOST
1014 pairWiiUsingSync =
true;
1017 if(classOfDevice[2] == 0 && classOfDevice[1] == 0x25 && classOfDevice[0] == 0x08 &&
strncmp((
const char*)
remote_name,
"Wireless Controller", 19) == 0) {
1018#ifdef DEBUG_USB_HOST
1019 Notify(
PSTR(
"\r\nPS4/PS5 controller is connecting"), 0x80);
1021 incomingPSController =
true;
1034#ifdef DEBUG_USB_HOST
1035 Notify(
PSTR(
"\r\nConnected to Device: "), 0x80);
1042 if(incomingPSController)
1057 if(hci_counter > 1000) {
1065#ifdef DEBUG_USB_HOST
1066 Notify(
PSTR(
"\r\nHCI Disconnected from Device"), 0x80);
1076 incomingPSController =
false;
1086void BTD::ACL_event_task() {
1100 Notify(
PSTR(
"\r\nACL data in error: "), 0x80);
1106 btService[
i]->
Run();
1115 pUsb->
ctrlReq(
bAddress,
epInfo[
BTD_CONTROL_PIPE ].epAddr,
bmREQ_HCI_OUT, 0x00, 0x00, 0x00, 0x00,
nbytes,
nbytes, data,
NULL);
1121 hcibuf[1] = 0x03 << 2;
1130 hcibuf[1] = 0x03 << 2;
1142 hcibuf[1] = 0x03 << 2;
1152 hcibuf[1] = 0x04 << 2;
1161 hcibuf[1] = 0x04 << 2;
1170 hcibuf[1] = 0x04 << 2;
1180 hcibuf[1] = 0x01 << 2;
1196 hcibuf[1] = 0x01 << 2;
1214 hcibuf[1] = 0x03 << 2;
1219 hcibuf[
i + 3] = 0x00;
1226 hcibuf[1] = 0x03 << 2;
1244 hcibuf[1] = 0x03 << 2;
1246 hcibuf[3] =
enable ? 1 : 0;
1254 hcibuf[1] = 0x01 << 2;
1267 hcibuf[1] = 0x01 << 2;
1280 hcibuf[1] = 0x01 << 2;
1301 hcibuf[1] = 0x01 << 2;
1311 if(pairWiiUsingSync) {
1312#ifdef DEBUG_USB_HOST
1313 Notify(
PSTR(
"\r\nPairing with Wii controller via SYNC"), 0x80);
1329 hcibuf[
i + 10] = 0x00;
1337 hcibuf[1] = 0x01 << 2;
1351 hcibuf[1] = 0x01 << 2;
1365 hcibuf[1] = 0x01 << 2;
1382 hcibuf[1] = 0x01 << 2;
1396 hcibuf[1] = 0x01 << 2;
1407 hcibuf[1] = 0x01 << 2;
1418 hcibuf[1] = 0x03 << 2;
1464 buf[8 +
i] = data[
i];
1469#ifdef DEBUG_USB_HOST
1470 Notify(
PSTR(
"\r\nError sending L2CAP message: 0x"), 0x80);
1482 l2capoutbuf[1] =
rxid;
1483 l2capoutbuf[2] = 0x04;
1484 l2capoutbuf[3] = 0x00;
1487 l2capoutbuf[6] =
scid[0];
1488 l2capoutbuf[7] =
scid[1];
1495 l2capoutbuf[1] =
rxid;
1496 l2capoutbuf[2] = 0x08;
1497 l2capoutbuf[3] = 0x00;
1498 l2capoutbuf[4] =
dcid[0];
1499 l2capoutbuf[5] =
dcid[1];
1500 l2capoutbuf[6] =
scid[0];
1501 l2capoutbuf[7] =
scid[1];
1503 l2capoutbuf[9] = 0x00;
1504 l2capoutbuf[10] = 0x00;
1505 l2capoutbuf[11] = 0x00;
1512 l2capoutbuf[1] =
rxid;
1513 l2capoutbuf[2] = 0x08;
1514 l2capoutbuf[3] = 0x00;
1515 l2capoutbuf[4] =
dcid[0];
1516 l2capoutbuf[5] =
dcid[1];
1517 l2capoutbuf[6] = 0x00;
1518 l2capoutbuf[7] = 0x00;
1519 l2capoutbuf[8] = 0x01;
1520 l2capoutbuf[9] = 0x02;
1521 l2capoutbuf[10] = 0xFF;
1522 l2capoutbuf[11] = 0xFF;
1529 l2capoutbuf[1] =
rxid;
1530 l2capoutbuf[2] = 0x0A;
1531 l2capoutbuf[3] = 0x00;
1532 l2capoutbuf[4] =
scid[0];
1533 l2capoutbuf[5] =
scid[1];
1534 l2capoutbuf[6] = 0x00;
1535 l2capoutbuf[7] = 0x00;
1536 l2capoutbuf[8] = 0x00;
1537 l2capoutbuf[9] = 0x00;
1538 l2capoutbuf[10] = 0x01;
1539 l2capoutbuf[11] = 0x02;
1540 l2capoutbuf[12] = 0xA0;
1541 l2capoutbuf[13] = 0x02;
1548 l2capoutbuf[1] =
rxid;
1549 l2capoutbuf[2] = 0x04;
1550 l2capoutbuf[3] = 0x00;
1551 l2capoutbuf[4] =
dcid[0];
1552 l2capoutbuf[5] =
dcid[1];
1553 l2capoutbuf[6] =
scid[0];
1554 l2capoutbuf[7] =
scid[1];
1561 l2capoutbuf[1] =
rxid;
1562 l2capoutbuf[2] = 0x04;
1563 l2capoutbuf[3] = 0x00;
1564 l2capoutbuf[4] =
dcid[0];
1565 l2capoutbuf[5] =
dcid[1];
1566 l2capoutbuf[6] =
scid[0];
1567 l2capoutbuf[7] =
scid[1];
1574 l2capoutbuf[1] =
rxid;
1575 l2capoutbuf[2] = 0x08;
1576 l2capoutbuf[3] = 0x00;
1579 l2capoutbuf[6] = 0x00;
1580 l2capoutbuf[7] = 0x00;
1581 l2capoutbuf[8] = 0x00;
1582 l2capoutbuf[9] = 0x00;
1583 l2capoutbuf[10] = 0x00;
1584 l2capoutbuf[11] = 0x00;
1600 pUsb->
ctrlReq(
bAddress,
epInfo[
BTD_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8,
buf,
NULL);
1616 pUsb->
ctrlReq(
bAddress,
epInfo[
BTD_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11,
buf,
NULL);
#define EV_COMMAND_STATUS
#define HCI_FLAG_DISCONNECT_COMPLETE
#define EV_NUM_COMPLETE_PKT
#define HCI_INQUIRY_STATE
#define HCI_FLAG_INCOMING_REQUEST
#define EV_EXTENDED_INQUIRY_RESULT
#define HCI_FLAG_CMD_COMPLETE
#define HCI_CONNECT_DEVICE_STATE
#define EV_QOS_SETUP_COMPLETE
#define EV_DISCONNECT_COMPLETE
#define HCI_FLAG_LOCAL_EXTENDED_FEATURES
#define EV_REMOTE_NAME_COMPLETE
#define EV_MAX_SLOTS_CHANGE
#define HCI_CHECK_DEVICE_SERVICE
#define EV_IO_CAPABILITY_RESPONSE
#define HCI_DISCONNECT_STATE
#define EV_INQUIRY_RESULT
#define L2CAP_CMD_DISCONNECT_REQUEST
#define EV_CHANGE_CONNECTION_LINK
#define HCI_FLAG_REMOTE_NAME_COMPLETE
#define HCI_FLAG_CONNECT_COMPLETE
#define L2CAP_CMD_CONFIG_REQUEST
#define HCI_WRITE_NAME_STATE
#define HCI_REMOTE_NAME_STATE
#define L2CAP_CMD_DISCONNECT_RESPONSE
#define EV_INQUIRY_COMPLETE
#define HCI_LOCAL_EXTENDED_FEATURES_STATE
#define PS3NAVIGATION_PID
#define BELKIN_F8T065BF_VID
#define hci_check_flag(flag)
#define HCI_FLAG_DEVICE_FOUND
#define EV_AUTHENTICATION_COMPLETE
#define IOGEAR_GBU521_VID
#define EV_DATA_BUFFER_OVERFLOW
#define hci_clear_flag(flag)
#define L2CAP_CMD_CONFIG_RESPONSE
#define EV_COMMAND_COMPLETE
#define EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE
#define EV_IO_CAPABILITY_REQUEST
#define HCI_CONNECT_IN_STATE
#define EV_LINK_KEY_NOTIFICATION
#define EV_LINK_KEY_REQUEST
#define HCI_LOCAL_VERSION_STATE
#define EV_PIN_CODE_REQUEST
#define EV_ENCRYPTION_CHANGE
#define HCI_FLAG_READ_BDADDR
#define HCI_FLAG_READ_VERSION
#define HCI_SET_EVENT_MASK_STATE
#define HCI_CONNECTED_DEVICE_STATE
#define L2CAP_CMD_CONNECTION_REQUEST
#define HCI_WRITE_SIMPLE_PAIRING_STATE
#define HCI_SCANNING_STATE
#define EV_LOOPBACK_COMMAND
#define BELKIN_F8T065BF_PID
#define HCI_FLAG_CONNECT_EVENT
#define EV_CONNECT_COMPLETE
#define EV_PAGE_SCAN_REP_MODE
#define hci_set_flag(flag)
#define EV_SIMPLE_PAIRING_COMPLETE
#define HCI_CONNECTED_STATE
#define EV_USER_CONFIRMATION_REQUEST
#define IOGEAR_GBU521_PID
#define BTD_MAX_ENDPOINTS
#define L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_INFORMATION_RESPONSE
#define EV_INCOMING_CONNECT
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
#define USB_ERROR_FailGetDevDescr
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_NAK_MAX_POWER
virtual void FreeAddress(uint8_t addr)=0
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
void hci_user_confirmation_request_reply()
static const uint8_t BTD_DATAOUT_PIPE
bool l2capConnectionClaimed
void hci_disconnect(uint16_t handle)
void hci_accept_connection()
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
static const uint8_t BTD_EVENT_PIPE
void hci_read_local_extended_features(uint8_t page_number)
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
void hci_io_capability_request_reply()
void hci_write_simple_pairing_mode(bool enable)
void hci_inquiry_cancel()
static const uint8_t BTD_DATAIN_PIPE
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
static const uint8_t BTD_CONTROL_PIPE
uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
void hci_pin_code_request_reply()
void hci_pin_code_negative_request_reply()
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
void hci_write_scan_enable()
EpInfo epInfo[BTD_MAX_ENDPOINTS]
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
bool waitingForConnection
void hci_write_class_of_device()
bool rfcommConnectionClaimed
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
void hci_write_local_name(const char *name)
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
void hci_set_event_mask()
void hci_authentication_request()
void hci_read_local_version_information()
void HCI_Command(uint8_t *data, uint16_t nbytes)
void hci_link_key_request_negative_reply()
bool sdpConnectionClaimed
void hci_write_scan_disable()
virtual void disconnect()=0
virtual void ACLData(uint8_t *ACLData)=0
AddressPool & GetAddressPool()
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
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)
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
#define NotifyFailSetConfDescr(...)
#define NotifyFailUnknownDevice(...)
#define NotifyFailGetConfDescr(...)
#define NotifyFailSetDevTblEntry(...)
#define NotifyFailGetDevDescr(...)
#define USB_TRANSFER_TYPE_BULK
#define bmUSB_TRANSFER_TYPE
#define USB_TRANSFER_TYPE_INTERRUPT
#define HID_REQUEST_SET_REPORT