From 49ade831a72df40646f693fe4046fb5158729a6b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 14 Mar 2013 23:40:52 +0100 Subject: [PATCH] Write class of device This is needed in order for some devices to see the dongle --- BTD.cpp | 23 +++++++++++++++++++++-- BTD.h | 31 +++++++++++++++++-------------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 14091899..e30be250 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -529,8 +529,8 @@ void BTD::HCI_task() { #ifdef DEBUG Notify(PSTR("\r\nHCI Reset complete")); #endif - hci_state = HCI_BDADDR_STATE; - hci_read_bdaddr(); + hci_state = HCI_CLASS_STATE; + hci_write_class_of_device(); } else if (hci_counter > hci_num_reset_loops) { hci_num_reset_loops *= 10; @@ -543,6 +543,16 @@ void BTD::HCI_task() { hci_counter = 0; } break; + + case HCI_CLASS_STATE: + if(hci_cmd_complete) { +#ifdef DEBUG + Notify(PSTR("\r\nWrite class of device")); +#endif + hci_state = HCI_BDADDR_STATE; + hci_read_bdaddr(); + } + break; case HCI_BDADDR_STATE: if (hci_read_bdaddr_complete) { @@ -986,6 +996,15 @@ void BTD::hci_disconnect(uint16_t handle) { // This is called by the different s HCI_Command(hcibuf, 6); } +void BTD::hci_write_class_of_device() { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html + hcibuf[0] = 0x24; // HCI OCF = 3 + hcibuf[1] = 0x03 << 2; // HCI OGF = 3 + hcibuf[2] = 0x03; // parameter length = 3 + hcibuf[3] = 0x04; // Robot + hcibuf[4] = 0x08; // Toy + hcibuf[5] = 0x00; + HCI_Command(hcibuf, 6); +} /******************************************************************* * * * HCI ACL Data Packet * diff --git a/BTD.h b/BTD.h index 6a8e4188..238b8959 100755 --- a/BTD.h +++ b/BTD.h @@ -39,22 +39,23 @@ /* Bluetooth HCI states for hci_task() */ #define HCI_INIT_STATE 0 #define HCI_RESET_STATE 1 -#define HCI_BDADDR_STATE 2 -#define HCI_LOCAL_VERSION_STATE 3 -#define HCI_SET_NAME_STATE 4 -#define HCI_CHECK_WII_SERVICE 5 +#define HCI_CLASS_STATE 2 +#define HCI_BDADDR_STATE 3 +#define HCI_LOCAL_VERSION_STATE 4 +#define HCI_SET_NAME_STATE 5 +#define HCI_CHECK_WII_SERVICE 6 -#define HCI_INQUIRY_STATE 6 // These three states are only used if it should pair and connect to a Wii controller -#define HCI_CONNECT_WII_STATE 7 -#define HCI_CONNECTED_WII_STATE 8 +#define HCI_INQUIRY_STATE 7 // These three states are only used if it should pair and connect to a Wii controller +#define HCI_CONNECT_WII_STATE 8 +#define HCI_CONNECTED_WII_STATE 9 -#define HCI_SCANNING_STATE 9 -#define HCI_CONNECT_IN_STATE 10 -#define HCI_REMOTE_NAME_STATE 11 -#define HCI_CONNECTED_STATE 12 -#define HCI_DISABLE_SCAN_STATE 13 -#define HCI_DONE_STATE 14 -#define HCI_DISCONNECT_STATE 15 +#define HCI_SCANNING_STATE 10 +#define HCI_CONNECT_IN_STATE 11 +#define HCI_REMOTE_NAME_STATE 12 +#define HCI_CONNECTED_STATE 13 +#define HCI_DISABLE_SCAN_STATE 14 +#define HCI_DONE_STATE 15 +#define HCI_DISCONNECT_STATE 16 /* HCI event flags*/ #define HCI_FLAG_CMD_COMPLETE 0x01 @@ -274,6 +275,8 @@ public: void hci_inquiry_cancel(); /** Connect to a device. */ void hci_connect(); + /** Used to a set the class of the device. */ + void hci_write_class_of_device(); /**@}*/ /** @name L2CAP Commands */