From 6399eca8e47503e1df53dab4672205773c001291 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Mon, 25 Nov 2013 00:46:52 +0100 Subject: [PATCH] Updated documentation BTHID library was added and some other changes --- .gitignore | 3 +- _b_t_d_8cpp_source.html | 2648 +++++++++-------- _b_t_d_8h.html | 58 +- _b_t_d_8h__dep__incl.map | 14 +- _b_t_d_8h__dep__incl.md5 | 2 +- _b_t_d_8h__dep__incl.png | Bin 13981 -> 17011 bytes _b_t_d_8h_source.html | 487 +-- _b_t_h_i_d_8cpp.html | 110 + _b_t_h_i_d_8cpp__incl.map | 9 + _b_t_h_i_d_8cpp__incl.md5 | 1 + _b_t_h_i_d_8cpp__incl.png | Bin 0 -> 21107 bytes _b_t_h_i_d_8cpp_source.html | 552 ++++ _b_t_h_i_d_8h.html | 596 ++++ _b_t_h_i_d_8h__dep__incl.map | 3 + _b_t_h_i_d_8h__dep__incl.md5 | 1 + _b_t_h_i_d_8h__dep__incl.png | Bin 0 -> 2839 bytes _b_t_h_i_d_8h__incl.map | 8 + _b_t_h_i_d_8h__incl.md5 | 1 + _b_t_h_i_d_8h__incl.png | Bin 0 -> 18797 bytes _b_t_h_i_d_8h_source.html | 253 ++ _p_s3_b_t_8cpp_source.html | 1303 ++++---- _p_s3_b_t_8h_source.html | 165 +- _p_s3_u_s_b_8cpp_source.html | 602 ++-- _p_s3_u_s_b_8h.html | 36 +- _p_s3_u_s_b_8h_source.html | 267 +- _r_e_a_d_m_e_8md_source.html | 188 +- _s_p_p_8cpp_source.html | 1126 +++---- _s_p_p_8h_source.html | 31 +- _usb_8cpp_source.html | 477 +-- _usb_8h.html | 2 +- _usb_8h__dep__incl.map | 78 +- _usb_8h__dep__incl.md5 | 2 +- _usb_8h__dep__incl.png | Bin 102036 -> 114991 bytes _usb_core_8h_source.html | 23 +- _wii_8cpp_source.html | 188 +- _wii_8h.html | 18 +- _wii_8h_source.html | 123 +- _wii_camera_readme_8md_source.html | 19 +- _x_b_o_x_o_l_d_8cpp_source.html | 93 +- _x_b_o_x_o_l_d_8h_source.html | 6 +- _x_b_o_x_r_e_c_v_8cpp_source.html | 1061 +++---- _x_b_o_x_r_e_c_v_8h_source.html | 207 +- _x_b_o_x_u_s_b_8cpp_source.html | 12 +- adk_8cpp_source.html | 681 ++--- adk_8h.html | 40 +- adk_8h_source.html | 254 +- annotated.html | 139 +- cdcacm_8cpp_source.html | 8 +- cdcftdi_8cpp_source.html | 8 +- cdcprolific_8cpp_source.html | 8 +- class_a_c_m__coll__graph.png | Bin 21760 -> 21773 bytes class_a_d_k.html | 40 +- class_a_d_k__coll__graph.png | Bin 16893 -> 16884 bytes class_b_t_d-members.html | 87 +- class_b_t_d.html | 244 +- class_b_t_d__coll__graph.png | Bin 16749 -> 16739 bytes class_b_t_h_i_d-members.html | 112 + class_b_t_h_i_d.html | 484 +++ class_b_t_h_i_d__coll__graph.map | 3 + class_b_t_h_i_d__coll__graph.md5 | 1 + class_b_t_h_i_d__coll__graph.png | Bin 0 -> 3640 bytes class_b_t_h_i_d__inherit__graph.map | 3 + class_b_t_h_i_d__inherit__graph.md5 | 1 + class_b_t_h_i_d__inherit__graph.png | Bin 0 -> 3640 bytes class_bluetooth_service.html | 12 +- class_bluetooth_service__inherit__graph.map | 7 +- class_bluetooth_service__inherit__graph.md5 | 2 +- class_bluetooth_service__inherit__graph.png | Bin 6592 -> 9603 bytes class_bulk_only.html | 52 +- class_bulk_only__coll__graph.png | Bin 17232 -> 17208 bytes class_h_i_d__coll__graph.png | Bin 13271 -> 13251 bytes class_h_i_d_boot__coll__graph.png | Bin 17259 -> 17231 bytes class_h_i_d_universal__coll__graph.png | Bin 16053 -> 16032 bytes class_keyboard_report_parser__coll__graph.png | Bin 12245 -> 12205 bytes class_m_a_x3421e.html | 32 +- class_mouse_report_parser__coll__graph.png | Bin 9281 -> 9285 bytes class_p_l2303__coll__graph.png | Bin 24756 -> 24763 bytes class_p_s3_b_t-members.html | 15 +- class_p_s3_b_t.html | 80 +- class_p_s3_u_s_b-members.html | 46 +- class_p_s3_u_s_b.html | 197 +- class_p_s3_u_s_b__coll__graph.png | Bin 12709 -> 12682 bytes class_report_desc_parser2__coll__graph.png | Bin 21914 -> 21865 bytes class_report_desc_parser__coll__graph.png | Bin 21788 -> 21737 bytes ...s_report_desc_parser_base__coll__graph.png | Bin 18063 -> 18022 bytes class_s_p_p.html | 16 +- class_s_pi.html | 4 +- class_u_s_b.html | 16 +- class_u_s_b_device_config.html | 12 +- class_w_i_i-members.html | 27 +- class_w_i_i.html | 44 +- class_x_b_o_x_o_l_d.html | 6 +- class_x_b_o_x_o_l_d__coll__graph.png | Bin 12869 -> 12840 bytes class_x_b_o_x_r_e_c_v-members.html | 51 +- class_x_b_o_x_r_e_c_v.html | 135 +- class_x_b_o_x_r_e_c_v__coll__graph.png | Bin 13154 -> 13126 bytes class_x_b_o_x_u_s_b__coll__graph.png | Bin 12855 -> 12828 bytes classes.html | 58 +- controller_enums_8h.html | 2 +- controller_enums_8h__dep__incl.map | 30 +- controller_enums_8h__dep__incl.md5 | 2 +- controller_enums_8h__dep__incl.png | Bin 34041 -> 37038 bytes dir_397a095372f04465e811d0ee219bbf8f.html | 4 + files.html | 110 +- functions.html | 30 +- functions_0x62.html | 5 +- functions_0x63.html | 13 +- functions_0x64.html | 8 +- functions_0x67.html | 14 +- functions_0x69.html | 38 +- functions_0x70.html | 47 +- functions_0x72.html | 19 +- functions_0x73.html | 39 +- functions_0x77.html | 6 +- functions_func.html | 8 +- functions_func_0x62.html | 3 + functions_func_0x63.html | 7 +- functions_func_0x64.html | 6 +- functions_func_0x67.html | 14 +- functions_func_0x70.html | 20 +- functions_func_0x72.html | 20 +- functions_func_0x73.html | 49 +- functions_func_0x77.html | 4 +- functions_vars_0x63.html | 12 +- functions_vars_0x69.html | 3 + functions_vars_0x70.html | 13 +- globals_0x62.html | 7 +- globals_0x65.html | 3 +- globals_0x68.html | 31 +- globals_0x6b.html | 3 + globals_0x6c.html | 76 +- globals_0x6d.html | 3 + globals_0x70.html | 2 +- globals_0x75.html | 8 +- globals_0x78.html | 15 +- globals_defs_0x62.html | 7 +- globals_defs_0x65.html | 3 +- globals_defs_0x68.html | 29 +- globals_defs_0x6b.html | 3 + globals_defs_0x6c.html | 74 +- globals_defs_0x6d.html | 3 + globals_defs_0x70.html | 2 +- globals_defs_0x75.html | 6 + globals_defs_0x78.html | 7 +- graph_legend.png | Bin 25396 -> 25377 bytes hid_8h.html | 2 +- hid_8h__dep__incl.map | 16 +- hid_8h__dep__incl.md5 | 2 +- hid_8h__dep__incl.png | Bin 17195 -> 23345 bytes hidboot_8h.html | 2 +- hidboot_8h__dep__incl.map | 4 +- hidboot_8h__dep__incl.md5 | 2 +- hidboot_8h__dep__incl.png | Bin 3495 -> 7930 bytes hiduniversal_8cpp_source.html | 8 +- hidusagestr_8h.html | 2 +- hidusagestr_8h__dep__incl.map | 20 +- hidusagestr_8h__dep__incl.md5 | 2 +- hidusagestr_8h__dep__incl.png | Bin 23325 -> 30170 bytes hierarchy.html | 159 +- index.html | 12 +- inherit_graph_38.map | 9 +- inherit_graph_38.md5 | 2 +- inherit_graph_38.png | Bin 8035 -> 11705 bytes inherit_graph_47.png | Bin 60706 -> 60732 bytes inherits.html | 2 +- masstorage_8cpp_source.html | 58 +- masstorage_8h_source.html | 398 +-- ..._host__shield_2_80__wii_camera_readme.html | 3 +- search/all_61.js | 4 +- search/all_62.js | 4 + search/all_63.js | 5 +- search/all_64.js | 2 +- search/all_65.js | 2 +- search/all_67.js | 5 +- search/all_68.js | 14 +- search/all_69.js | 1 + search/all_6b.js | 1 + search/all_6c.js | 52 +- search/all_6d.js | 1 + search/all_70.js | 4 +- search/all_72.js | 6 +- search/all_73.js | 9 +- search/all_75.js | 4 +- search/all_77.js | 2 +- search/all_78.js | 3 +- search/classes_62.js | 1 + search/defines_62.js | 1 + search/defines_65.js | 2 +- search/defines_68.js | 12 +- search/defines_6b.js | 1 + search/defines_6c.js | 52 +- search/defines_6d.js | 1 + search/defines_70.js | 2 +- search/defines_75.js | 4 +- search/defines_78.js | 3 +- search/files_62.js | 4 +- search/functions_61.js | 4 +- search/functions_62.js | 1 + search/functions_63.js | 2 +- search/functions_64.js | 2 +- search/functions_67.js | 5 +- search/functions_68.js | 2 +- search/functions_70.js | 3 +- search/functions_72.js | 6 +- search/functions_73.js | 9 +- search/functions_77.js | 2 +- search/variables_63.js | 3 +- search/variables_69.js | 1 + search/variables_70.js | 1 + settings_8h.html | 36 +- settings_8h_source.html | 68 +- struct_command_block_wrapper.html | 4 +- struct_command_status_wrapper.html | 10 +- struct_request_sense_responce.html | 30 +- struct_usb_device__coll__graph.png | Bin 3868 -> 3864 bytes usbhost_8h.html | 2 +- usbhost_8h_source.html | 772 ++--- usbhub_8cpp_source.html | 12 +- 218 files changed, 9725 insertions(+), 6661 deletions(-) create mode 100644 _b_t_h_i_d_8cpp.html create mode 100644 _b_t_h_i_d_8cpp__incl.map create mode 100644 _b_t_h_i_d_8cpp__incl.md5 create mode 100644 _b_t_h_i_d_8cpp__incl.png create mode 100644 _b_t_h_i_d_8cpp_source.html create mode 100644 _b_t_h_i_d_8h.html create mode 100644 _b_t_h_i_d_8h__dep__incl.map create mode 100644 _b_t_h_i_d_8h__dep__incl.md5 create mode 100644 _b_t_h_i_d_8h__dep__incl.png create mode 100644 _b_t_h_i_d_8h__incl.map create mode 100644 _b_t_h_i_d_8h__incl.md5 create mode 100644 _b_t_h_i_d_8h__incl.png create mode 100644 _b_t_h_i_d_8h_source.html create mode 100644 class_b_t_h_i_d-members.html create mode 100644 class_b_t_h_i_d.html create mode 100644 class_b_t_h_i_d__coll__graph.map create mode 100644 class_b_t_h_i_d__coll__graph.md5 create mode 100644 class_b_t_h_i_d__coll__graph.png create mode 100644 class_b_t_h_i_d__inherit__graph.map create mode 100644 class_b_t_h_i_d__inherit__graph.md5 create mode 100644 class_b_t_h_i_d__inherit__graph.png diff --git a/.gitignore b/.gitignore index d5b665b9..7e69f457 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.bak *.zip -*.rar \ No newline at end of file +*.rar +build/ \ No newline at end of file diff --git a/_b_t_d_8cpp_source.html b/_b_t_d_8cpp_source.html index 16d89881..b83d281a 100644 --- a/_b_t_d_8cpp_source.html +++ b/_b_t_d_8cpp_source.html @@ -107,7 +107,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
16  */
17 
18 #include "BTD.h"
-
19 // To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
+
19 // To enable serial debugging see "settings.h"
20 //#define EXTRADEBUG // Uncomment to get even more debugging data
21 
22 const uint8_t BTD::BTD_CONTROL_PIPE = 0;
@@ -118,1310 +118,1373 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
27 BTD::BTD(USB *p) :
28 connectToWii(false),
29 pairWithWii(false),
-
30 pUsb(p), // Pointer to USB class instance - mandatory
-
31 bAddress(0), // Device address - mandatory
-
32 bNumEP(1), // If config descriptor needs to be parsed
-
33 qNextPollTime(0), // Reset NextPollTime
-
34 pollInterval(0),
-
35 bPollEnable(false) // Don't start polling before dongle is connected
-
36 {
-
37  for (uint8_t i = 0; i < BTD_NUMSERVICES; i++)
-
38  btService[i] = NULL;
-
39 
-
40  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
+
30 connectToHIDDevice(false),
+
31 pairWithHIDDevice(false),
+
32 pUsb(p), // Pointer to USB class instance - mandatory
+
33 bAddress(0), // Device address - mandatory
+
34 bNumEP(1), // If config descriptor needs to be parsed
+
35 qNextPollTime(0), // Reset NextPollTime
+
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++)
+
40  btService[i] = NULL;
41 
-
42  if (pUsb) // Register in USB subsystem
-
43  pUsb->RegisterDeviceClass(this); // Set devConfig[] entry
-
44 }
-
45 
-
46 uint8_t BTD::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
-
47  const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
-
48  uint8_t buf[constBufSize];
-
49  uint8_t rcode;
-
50  UsbDevice *p = NULL;
-
51  EpInfo *oldep_ptr = NULL;
-
52 
-
53  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
+
42  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
+
43 
+
44  if (pUsb) // Register in USB subsystem
+
45  pUsb->RegisterDeviceClass(this); // Set devConfig[] entry
+
46 }
+
47 
+
48 uint8_t BTD::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
+
49  const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
+
50  uint8_t buf[constBufSize];
+
51  uint8_t rcode;
+
52  UsbDevice *p = NULL;
+
53  EpInfo *oldep_ptr = NULL;
54 
-
55  AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool
-
56 #ifdef EXTRADEBUG
-
57  Notify(PSTR("\r\nBTD ConfigureDevice"), 0x80);
-
58 #endif
-
59 
-
60  if (bAddress) { // Check if address has already been assigned to an instance
-
61 #ifdef DEBUG_USB_HOST
-
62  Notify(PSTR("\r\nAddress in use"), 0x80);
-
63 #endif
-
64  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
65  }
-
66 
-
67  p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned
-
68  if (!p) {
-
69 #ifdef DEBUG_USB_HOST
-
70  Notify(PSTR("\r\nAddress not found"), 0x80);
-
71 #endif
-
72  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
73  }
-
74 
-
75  if (!p->epinfo) {
-
76 #ifdef DEBUG_USB_HOST
-
77  Notify(PSTR("\r\nepinfo is null"), 0x80);
-
78 #endif
-
79  return USB_ERROR_EPINFO_IS_NULL;
-
80  }
-
81 
-
82  oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0
-
83  p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
84  p->lowspeed = lowspeed;
-
85  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
-
86 
-
87  p->epinfo = oldep_ptr; // Restore p->epinfo
+
55  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
+
56 
+
57  AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool
+
58 #ifdef EXTRADEBUG
+
59  Notify(PSTR("\r\nBTD ConfigureDevice"), 0x80);
+
60 #endif
+
61 
+
62  if (bAddress) { // Check if address has already been assigned to an instance
+
63 #ifdef DEBUG_USB_HOST
+
64  Notify(PSTR("\r\nAddress in use"), 0x80);
+
65 #endif
+
66  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
67  }
+
68 
+
69  p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned
+
70  if (!p) {
+
71 #ifdef DEBUG_USB_HOST
+
72  Notify(PSTR("\r\nAddress not found"), 0x80);
+
73 #endif
+
74  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
75  }
+
76 
+
77  if (!p->epinfo) {
+
78 #ifdef DEBUG_USB_HOST
+
79  Notify(PSTR("\r\nepinfo is null"), 0x80);
+
80 #endif
+
81  return USB_ERROR_EPINFO_IS_NULL;
+
82  }
+
83 
+
84  oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0
+
85  p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
86  p->lowspeed = lowspeed;
+
87  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
88 
-
89  if (rcode)
-
90  goto FailGetDevDescr;
-
91 
-
92  bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class
+
89  p->epinfo = oldep_ptr; // Restore p->epinfo
+
90 
+
91  if (rcode)
+
92  goto FailGetDevDescr;
93 
-
94  if (!bAddress) {
-
95 #ifdef DEBUG_USB_HOST
-
96  Notify(PSTR("\r\nOut of address space"), 0x80);
-
97 #endif
-
98  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
99  }
-
100 
-
101  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
-
102  epInfo[1].epAddr = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Steal and abuse from epInfo structure to save memory
-
103 
-
104  VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
-
105  PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
-
106 
-
107  return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
+
94  bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class
+
95 
+
96  if (!bAddress) {
+
97 #ifdef DEBUG_USB_HOST
+
98  Notify(PSTR("\r\nOut of address space"), 0x80);
+
99 #endif
+
100  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
101  }
+
102 
+
103  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
+
104  epInfo[1].epAddr = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Steal and abuse from epInfo structure to save memory
+
105 
+
106  VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
+
107  PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
108 
-
109 FailGetDevDescr:
-
110 #ifdef DEBUG_USB_HOST
-
111  NotifyFailGetDevDescr(rcode);
-
112 #endif
-
113  if (rcode != hrJERR)
-
114  rcode = USB_ERROR_FailGetDevDescr;
-
115  Release();
-
116  return rcode;
-
117 };
-
118 
-
119 uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
-
120  uint8_t rcode;
-
121  uint8_t num_of_conf = epInfo[1].epAddr; // Number of configurations
-
122  epInfo[1].epAddr = 0;
-
123 
-
124  AddressPool &addrPool = pUsb->GetAddressPool();
-
125 #ifdef EXTRADEBUG
-
126  Notify(PSTR("\r\nBTD Init"), 0x80);
-
127 #endif
-
128  UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
-
129 
-
130  if (!p) {
-
131 #ifdef DEBUG_USB_HOST
-
132  Notify(PSTR("\r\nAddress not found"), 0x80);
-
133 #endif
-
134  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
135  }
-
136 
-
137  delay(300); // Assign new address to the device
+
109  return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
+
110 
+
111 FailGetDevDescr:
+
112 #ifdef DEBUG_USB_HOST
+
113  NotifyFailGetDevDescr(rcode);
+
114 #endif
+
115  if (rcode != hrJERR)
+
116  rcode = USB_ERROR_FailGetDevDescr;
+
117  Release();
+
118  return rcode;
+
119 };
+
120 
+
121 uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
+
122  uint8_t rcode;
+
123  uint8_t num_of_conf = epInfo[1].epAddr; // Number of configurations
+
124  epInfo[1].epAddr = 0;
+
125 
+
126  AddressPool &addrPool = pUsb->GetAddressPool();
+
127 #ifdef EXTRADEBUG
+
128  Notify(PSTR("\r\nBTD Init"), 0x80);
+
129 #endif
+
130  UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
+
131 
+
132  if (!p) {
+
133 #ifdef DEBUG_USB_HOST
+
134  Notify(PSTR("\r\nAddress not found"), 0x80);
+
135 #endif
+
136  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
137  }
138 
-
139  rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device
-
140  if (rcode) {
-
141 #ifdef DEBUG_USB_HOST
-
142  Notify(PSTR("\r\nsetAddr: "), 0x80);
-
143  D_PrintHex<uint8_t > (rcode, 0x80);
-
144 #endif
-
145  p->lowspeed = false;
-
146  goto Fail;
-
147  }
-
148 #ifdef EXTRADEBUG
-
149  Notify(PSTR("\r\nAddr: "), 0x80);
-
150  D_PrintHex<uint8_t > (bAddress, 0x80);
-
151 #endif
-
152 
-
153  p->lowspeed = false;
-
154 
-
155  p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
-
156  if (!p) {
-
157 #ifdef DEBUG_USB_HOST
-
158  Notify(PSTR("\r\nAddress not found"), 0x80);
-
159 #endif
-
160  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
161  }
-
162 
-
163  p->lowspeed = lowspeed;
+
139  delay(300); // Assign new address to the device
+
140 
+
141  rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device
+
142  if (rcode) {
+
143 #ifdef DEBUG_USB_HOST
+
144  Notify(PSTR("\r\nsetAddr: "), 0x80);
+
145  D_PrintHex<uint8_t > (rcode, 0x80);
+
146 #endif
+
147  p->lowspeed = false;
+
148  goto Fail;
+
149  }
+
150 #ifdef EXTRADEBUG
+
151  Notify(PSTR("\r\nAddr: "), 0x80);
+
152  D_PrintHex<uint8_t > (bAddress, 0x80);
+
153 #endif
+
154 
+
155  p->lowspeed = false;
+
156 
+
157  p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
+
158  if (!p) {
+
159 #ifdef DEBUG_USB_HOST
+
160  Notify(PSTR("\r\nAddress not found"), 0x80);
+
161 #endif
+
162  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
163  }
164 
-
165  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known
-
166  if (rcode)
-
167  goto FailSetDevTblEntry;
-
168 
-
169  if (VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) {
-
170  delay(100);
-
171  rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); // We only need the Control endpoint, so we don't have to initialize the other endpoints of device
-
172  if (rcode)
-
173  goto FailSetConfDescr;
-
174 
-
175 #ifdef DEBUG_USB_HOST
-
176  if (PID == PS3_PID || PID == PS3NAVIGATION_PID) {
-
177  if (PID == PS3_PID)
-
178  Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
-
179  else // It must be a navigation controller
-
180  Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
-
181  } else // It must be a Motion controller
-
182  Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
-
183 #endif
-
184 
-
185  if (my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) {
-
186 #ifdef DEBUG_USB_HOST
-
187  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);
-
188 #endif
-
189  } else {
-
190  if (PID == PS3_PID || PID == PS3NAVIGATION_PID)
-
191  setBdaddr(my_bdaddr); // Set internal Bluetooth address
-
192  else
-
193  setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
-
194 #ifdef DEBUG_USB_HOST
-
195  Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
-
196  for (int8_t i = 5; i > 0; i--) {
-
197  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
-
198  Notify(PSTR(":"), 0x80);
-
199  }
-
200  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
-
201 #endif
-
202  }
-
203 
-
204  pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 0); // Reset configuration value
-
205  pUsb->setAddr(bAddress, 0, 0); // Reset address
-
206  Release(); // Release device
-
207  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Return
-
208  } else {
-
209  // Check if attached device is a Bluetooth dongle and fill endpoint data structure
-
210  // First interface in the configuration must have Bluetooth assigned Class/Subclass/Protocol
-
211  // And 3 endpoints - interrupt-IN, bulk-IN, bulk-OUT, not necessarily in this order
-
212  for (uint8_t i = 0; i < num_of_conf; i++) {
-
213  if (VID == IOGEAR_GBU521_VID && PID == IOGEAR_GBU521_PID) {
-
214  ConfigDescParser<USB_CLASS_VENDOR_SPECIFIC, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this); // Needed for the IOGEAR GBU521
-
215  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
-
216  } else {
-
217  ConfigDescParser<USB_CLASS_WIRELESS_CTRL, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this);
-
218  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
-
219  }
-
220  if (rcode) // Check error code
-
221  goto FailGetConfDescr;
-
222  if (bNumEP >= BTD_MAX_ENDPOINTS) // All endpoints extracted
-
223  break;
-
224  }
-
225 
-
226  if (bNumEP < BTD_MAX_ENDPOINTS)
-
227  goto FailUnknownDevice;
-
228 
-
229  // Assign epInfo to epinfo pointer - this time all 3 endpoins
-
230  rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
-
231  if (rcode)
-
232  goto FailSetDevTblEntry;
-
233 
-
234  // Set Configuration Value
-
235  rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bConfNum);
-
236  if (rcode)
-
237  goto FailSetConfDescr;
-
238 
-
239  hci_num_reset_loops = 100; // only loop 100 times before trying to send the hci reset command
-
240  hci_counter = 0;
-
241  hci_state = HCI_INIT_STATE;
-
242  watingForConnection = false;
-
243  bPollEnable = true;
-
244 
-
245 #ifdef DEBUG_USB_HOST
-
246  Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80);
-
247 #endif
-
248  }
-
249  return 0; // Successful configuration
-
250 
-
251  /* diagnostic messages */
-
252 FailGetDevDescr:
-
253 #ifdef DEBUG_USB_HOST
-
254  NotifyFailGetDevDescr();
-
255  goto Fail;
-
256 #endif
-
257 
-
258 FailSetDevTblEntry:
-
259 #ifdef DEBUG_USB_HOST
-
260  NotifyFailSetDevTblEntry();
-
261  goto Fail;
-
262 #endif
-
263 
-
264 FailGetConfDescr:
-
265 #ifdef DEBUG_USB_HOST
-
266  NotifyFailGetConfDescr();
-
267  goto Fail;
-
268 #endif
-
269 
-
270 FailSetConfDescr:
-
271 #ifdef DEBUG_USB_HOST
-
272  NotifyFailSetConfDescr();
-
273 #endif
-
274  goto Fail;
-
275 
-
276 FailUnknownDevice:
-
277 #ifdef DEBUG_USB_HOST
-
278  NotifyFailUnknownDevice(VID, PID);
-
279 #endif
-
280  pUsb->setAddr(bAddress, 0, 0); // Reset address
-
281  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
-
282 Fail:
-
283 #ifdef DEBUG_USB_HOST
-
284  Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80);
-
285  NotifyFail(rcode);
-
286 #endif
-
287  Release();
-
288  return rcode;
-
289 }
-
290 
-
291 void BTD::clearAllVariables() {
-
292  uint8_t i;
-
293  for (i = 0; i < BTD_MAX_ENDPOINTS; i++) {
-
294  epInfo[i].epAddr = 0;
-
295  epInfo[i].maxPktSize = (i) ? 0 : 8;
-
296  epInfo[i].epAttribs = 0;
-
297  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
-
298  }
-
299  for (i = 0; i < BTD_NUMSERVICES; i++) {
-
300  if (btService[i])
-
301  btService[i]->Reset(); // Reset all Bluetooth services
-
302  }
-
303 
-
304  connectToWii = false;
-
305  incomingWii = false;
-
306  bAddress = 0; // Clear device address
-
307  bNumEP = 1; // Must have to be reset to 1
-
308  qNextPollTime = 0; // Reset next poll time
-
309  pollInterval = 0;
-
310  bPollEnable = false; // Don't start polling before dongle is connected
-
311 }
-
312 
-
313 /* Extracts interrupt-IN, bulk-IN, bulk-OUT endpoint information from config descriptor */
-
314 void BTD::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
-
315  //ErrorMessage<uint8_t>(PSTR("Conf.Val"),conf);
-
316  //ErrorMessage<uint8_t>(PSTR("Iface Num"),iface);
-
317  //ErrorMessage<uint8_t>(PSTR("Alt.Set"),alt);
-
318 
-
319  if (alt) // Wrong interface - by BT spec, no alt setting
-
320  return;
-
321 
-
322  bConfNum = conf;
-
323  uint8_t index;
-
324 
-
325  if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) { // Interrupt In endpoint found
-
326  index = BTD_EVENT_PIPE;
-
327  epInfo[index].bmNakPower = USB_NAK_NOWAIT;
-
328  } else {
-
329  if ((pep->bmAttributes & 0x02) == 2) // Bulk endpoint found
-
330  index = ((pep->bEndpointAddress & 0x80) == 0x80) ? BTD_DATAIN_PIPE : BTD_DATAOUT_PIPE;
-
331  else
-
332  return;
-
333  }
-
334 
-
335  // Fill the rest of endpoint data structure
-
336  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
-
337  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
-
338 #ifdef EXTRADEBUG
-
339  PrintEndpointDescriptor(pep);
-
340 #endif
-
341  if (pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
-
342  pollInterval = pep->bInterval;
-
343  bNumEP++;
-
344 }
-
345 
-
346 void BTD::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
-
347 #ifdef EXTRADEBUG
-
348  Notify(PSTR("\r\nEndpoint descriptor:"), 0x80);
-
349  Notify(PSTR("\r\nLength:\t\t"), 0x80);
-
350  D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
-
351  Notify(PSTR("\r\nType:\t\t"), 0x80);
-
352  D_PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
-
353  Notify(PSTR("\r\nAddress:\t"), 0x80);
-
354  D_PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
-
355  Notify(PSTR("\r\nAttributes:\t"), 0x80);
-
356  D_PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
-
357  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
-
358  D_PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
-
359  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
-
360  D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
-
361 #endif
-
362 }
-
363 
-
364 /* Performs a cleanup after failed Init() attempt */
-
365 uint8_t BTD::Release() {
-
366  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
-
367  pUsb->GetAddressPool().FreeAddress(bAddress);
-
368  return 0;
-
369 }
-
370 
-
371 uint8_t BTD::Poll() {
-
372  if (!bPollEnable)
-
373  return 0;
-
374  if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
-
375  qNextPollTime = millis() + pollInterval; // Set new poll time
-
376  HCI_event_task(); // poll the HCI event pipe
-
377  ACL_event_task(); // start polling the ACL input pipe too, though discard data until connected
-
378  }
-
379  return 0;
-
380 }
-
381 
-
382 void BTD::HCI_event_task() {
-
383  /* check the event pipe*/
-
384  uint16_t MAX_BUFFER_SIZE = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this
-
385  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &MAX_BUFFER_SIZE, hcibuf); // input on endpoint 1
-
386  if (!rcode || rcode == hrNAK) // Check for errors
-
387  {
-
388  switch (hcibuf[0]) //switch on event type
-
389  {
-
390  case EV_COMMAND_COMPLETE:
-
391  if (!hcibuf[5]) { // Check if command succeeded
-
392  hci_event_flag |= HCI_FLAG_CMD_COMPLETE; // set command complete flag
-
393  if ((hcibuf[3] == 0x01) && (hcibuf[4] == 0x10)) { // parameters from read local version information
-
394  hci_version = hcibuf[6]; // Used to check if it supports 2.0+EDR - see http://www.bluetooth.org/Technical/AssignedNumbers/hci.htm
-
395  hci_event_flag |= HCI_FLAG_READ_VERSION;
-
396  } else if ((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) { // parameters from read local bluetooth address
-
397  for (uint8_t i = 0; i < 6; i++)
-
398  my_bdaddr[i] = hcibuf[6 + i];
-
399  hci_event_flag |= HCI_FLAG_READ_BDADDR;
-
400  }
-
401  }
-
402  break;
-
403 
-
404  case EV_COMMAND_STATUS:
-
405  if (hcibuf[2]) { // show status on serial if not OK
-
406 #ifdef DEBUG_USB_HOST
-
407  Notify(PSTR("\r\nHCI Command Failed: "), 0x80);
-
408  D_PrintHex<uint8_t > (hcibuf[2], 0x80);
-
409  Notify(PSTR(" "), 0x80);
-
410  D_PrintHex<uint8_t > (hcibuf[4], 0x80);
-
411  Notify(PSTR(" "), 0x80);
-
412  D_PrintHex<uint8_t > (hcibuf[5], 0x80);
+
165  p->lowspeed = lowspeed;
+
166 
+
167  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known
+
168  if (rcode)
+
169  goto FailSetDevTblEntry;
+
170 
+
171  if (VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) {
+
172  delay(100);
+
173  rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); // We only need the Control endpoint, so we don't have to initialize the other endpoints of device
+
174  if (rcode)
+
175  goto FailSetConfDescr;
+
176 
+
177 #ifdef DEBUG_USB_HOST
+
178  if (PID == PS3_PID || PID == PS3NAVIGATION_PID) {
+
179  if (PID == PS3_PID)
+
180  Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
+
181  else // It must be a navigation controller
+
182  Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
+
183  } else // It must be a Motion controller
+
184  Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
+
185 #endif
+
186 
+
187  if (my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) {
+
188 #ifdef DEBUG_USB_HOST
+
189  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);
+
190 #endif
+
191  } else {
+
192  if (PID == PS3_PID || PID == PS3NAVIGATION_PID)
+
193  setBdaddr(my_bdaddr); // Set internal Bluetooth address
+
194  else
+
195  setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
+
196 #ifdef DEBUG_USB_HOST
+
197  Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
+
198  for (int8_t i = 5; i > 0; i--) {
+
199  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
+
200  Notify(PSTR(":"), 0x80);
+
201  }
+
202  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
+
203 #endif
+
204  }
+
205 
+
206  pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 0); // Reset configuration value
+
207  pUsb->setAddr(bAddress, 0, 0); // Reset address
+
208  Release(); // Release device
+
209  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Return
+
210  } else {
+
211  // Check if attached device is a Bluetooth dongle and fill endpoint data structure
+
212  // First interface in the configuration must have Bluetooth assigned Class/Subclass/Protocol
+
213  // And 3 endpoints - interrupt-IN, bulk-IN, bulk-OUT, not necessarily in this order
+
214  for (uint8_t i = 0; i < num_of_conf; i++) {
+
215  if (VID == IOGEAR_GBU521_VID && PID == IOGEAR_GBU521_PID) {
+
216  ConfigDescParser<USB_CLASS_VENDOR_SPECIFIC, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this); // Needed for the IOGEAR GBU521
+
217  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
+
218  } else {
+
219  ConfigDescParser<USB_CLASS_WIRELESS_CTRL, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this);
+
220  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
+
221  }
+
222  if (rcode) // Check error code
+
223  goto FailGetConfDescr;
+
224  if (bNumEP >= BTD_MAX_ENDPOINTS) // All endpoints extracted
+
225  break;
+
226  }
+
227 
+
228  if (bNumEP < BTD_MAX_ENDPOINTS)
+
229  goto FailUnknownDevice;
+
230 
+
231  // Assign epInfo to epinfo pointer - this time all 3 endpoins
+
232  rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
+
233  if (rcode)
+
234  goto FailSetDevTblEntry;
+
235 
+
236  // Set Configuration Value
+
237  rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bConfNum);
+
238  if (rcode)
+
239  goto FailSetConfDescr;
+
240 
+
241  hci_num_reset_loops = 100; // only loop 100 times before trying to send the hci reset command
+
242  hci_counter = 0;
+
243  hci_state = HCI_INIT_STATE;
+
244  watingForConnection = false;
+
245  bPollEnable = true;
+
246 
+
247 #ifdef DEBUG_USB_HOST
+
248  Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80);
+
249 #endif
+
250  }
+
251  return 0; // Successful configuration
+
252 
+
253  /* diagnostic messages */
+
254 FailGetDevDescr:
+
255 #ifdef DEBUG_USB_HOST
+
256  NotifyFailGetDevDescr();
+
257  goto Fail;
+
258 #endif
+
259 
+
260 FailSetDevTblEntry:
+
261 #ifdef DEBUG_USB_HOST
+
262  NotifyFailSetDevTblEntry();
+
263  goto Fail;
+
264 #endif
+
265 
+
266 FailGetConfDescr:
+
267 #ifdef DEBUG_USB_HOST
+
268  NotifyFailGetConfDescr();
+
269  goto Fail;
+
270 #endif
+
271 
+
272 FailSetConfDescr:
+
273 #ifdef DEBUG_USB_HOST
+
274  NotifyFailSetConfDescr();
+
275 #endif
+
276  goto Fail;
+
277 
+
278 FailUnknownDevice:
+
279 #ifdef DEBUG_USB_HOST
+
280  NotifyFailUnknownDevice(VID, PID);
+
281 #endif
+
282  pUsb->setAddr(bAddress, 0, 0); // Reset address
+
283  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
+
284 Fail:
+
285 #ifdef DEBUG_USB_HOST
+
286  Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80);
+
287  NotifyFail(rcode);
+
288 #endif
+
289  Release();
+
290  return rcode;
+
291 }
+
292 
+
293 void BTD::clearAllVariables() {
+
294  uint8_t i;
+
295  for (i = 0; i < BTD_MAX_ENDPOINTS; i++) {
+
296  epInfo[i].epAddr = 0;
+
297  epInfo[i].maxPktSize = (i) ? 0 : 8;
+
298  epInfo[i].epAttribs = 0;
+
299  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
+
300  }
+
301  for (i = 0; i < BTD_NUMSERVICES; i++) {
+
302  if (btService[i])
+
303  btService[i]->Reset(); // Reset all Bluetooth services
+
304  }
+
305 
+
306  connectToWii = false;
+
307  incomingWii = false;
+
308  connectToHIDDevice = false;
+
309  incomingHIDDevice = false;
+
310  bAddress = 0; // Clear device address
+
311  bNumEP = 1; // Must have to be reset to 1
+
312  qNextPollTime = 0; // Reset next poll time
+
313  pollInterval = 0;
+
314  bPollEnable = false; // Don't start polling before dongle is connected
+
315 }
+
316 
+
317 /* Extracts interrupt-IN, bulk-IN, bulk-OUT endpoint information from config descriptor */
+
318 void BTD::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
+
319  //ErrorMessage<uint8_t>(PSTR("Conf.Val"),conf);
+
320  //ErrorMessage<uint8_t>(PSTR("Iface Num"),iface);
+
321  //ErrorMessage<uint8_t>(PSTR("Alt.Set"),alt);
+
322 
+
323  if (alt) // Wrong interface - by BT spec, no alt setting
+
324  return;
+
325 
+
326  bConfNum = conf;
+
327  uint8_t index;
+
328 
+
329  if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) { // Interrupt In endpoint found
+
330  index = BTD_EVENT_PIPE;
+
331  epInfo[index].bmNakPower = USB_NAK_NOWAIT;
+
332  } else {
+
333  if ((pep->bmAttributes & 0x02) == 2) // Bulk endpoint found
+
334  index = ((pep->bEndpointAddress & 0x80) == 0x80) ? BTD_DATAIN_PIPE : BTD_DATAOUT_PIPE;
+
335  else
+
336  return;
+
337  }
+
338 
+
339  // Fill the rest of endpoint data structure
+
340  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
+
341  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
+
342 #ifdef EXTRADEBUG
+
343  PrintEndpointDescriptor(pep);
+
344 #endif
+
345  if (pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
+
346  pollInterval = pep->bInterval;
+
347  bNumEP++;
+
348 }
+
349 
+
350 void BTD::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
+
351 #ifdef EXTRADEBUG
+
352  Notify(PSTR("\r\nEndpoint descriptor:"), 0x80);
+
353  Notify(PSTR("\r\nLength:\t\t"), 0x80);
+
354  D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
+
355  Notify(PSTR("\r\nType:\t\t"), 0x80);
+
356  D_PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
+
357  Notify(PSTR("\r\nAddress:\t"), 0x80);
+
358  D_PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
+
359  Notify(PSTR("\r\nAttributes:\t"), 0x80);
+
360  D_PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
+
361  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
+
362  D_PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
+
363  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
+
364  D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
+
365 #endif
+
366 }
+
367 
+
368 /* Performs a cleanup after failed Init() attempt */
+
369 uint8_t BTD::Release() {
+
370  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
+
371  pUsb->GetAddressPool().FreeAddress(bAddress);
+
372  return 0;
+
373 }
+
374 
+
375 uint8_t BTD::Poll() {
+
376  if (!bPollEnable)
+
377  return 0;
+
378  if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
+
379  qNextPollTime = millis() + pollInterval; // Set new poll time
+
380  HCI_event_task(); // poll the HCI event pipe
+
381  ACL_event_task(); // start polling the ACL input pipe too, though discard data until connected
+
382  }
+
383  return 0;
+
384 }
+
385 
+
386 void BTD::HCI_event_task() {
+
387  /* check the event pipe*/
+
388  uint16_t MAX_BUFFER_SIZE = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this
+
389  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &MAX_BUFFER_SIZE, hcibuf); // input on endpoint 1
+
390  if (!rcode || rcode == hrNAK) // Check for errors
+
391  {
+
392  switch (hcibuf[0]) //switch on event type
+
393  {
+
394  case EV_COMMAND_COMPLETE:
+
395  if (!hcibuf[5]) { // Check if command succeeded
+
396  hci_event_flag |= HCI_FLAG_CMD_COMPLETE; // set command complete flag
+
397  if ((hcibuf[3] == 0x01) && (hcibuf[4] == 0x10)) { // parameters from read local version information
+
398  hci_version = hcibuf[6]; // Used to check if it supports 2.0+EDR - see http://www.bluetooth.org/Technical/AssignedNumbers/hci.htm
+
399  hci_event_flag |= HCI_FLAG_READ_VERSION;
+
400  } else if ((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) { // parameters from read local bluetooth address
+
401  for (uint8_t i = 0; i < 6; i++)
+
402  my_bdaddr[i] = hcibuf[6 + i];
+
403  hci_event_flag |= HCI_FLAG_READ_BDADDR;
+
404  }
+
405  }
+
406  break;
+
407 
+
408  case EV_COMMAND_STATUS:
+
409  if (hcibuf[2]) { // Show status on serial if not OK
+
410 #ifdef DEBUG_USB_HOST
+
411  Notify(PSTR("\r\nHCI Command Failed: "), 0x80);
+
412  D_PrintHex<uint8_t > (hcibuf[2], 0x80);
413 #endif
414  }
415  break;
416 
417  case EV_INQUIRY_COMPLETE:
-
418  if (inquiry_counter >= 5 && pairWithWii) {
+
418  if (inquiry_counter >= 5 && (pairWithWii || pairWithHIDDevice)) {
419  inquiry_counter = 0;
420 #ifdef DEBUG_USB_HOST
-
421  Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80);
-
422 #endif
-
423  connectToWii = false;
-
424  pairWithWii = false;
-
425  hci_state = HCI_SCANNING_STATE;
-
426  }
-
427  inquiry_counter++;
-
428  break;
-
429 
-
430  case EV_INQUIRY_RESULT:
-
431  if (hcibuf[2]) { // Check that there is more than zero responses
-
432 #ifdef EXTRADEBUG
-
433  Notify(PSTR("\r\nNumber of responses: "), 0x80);
-
434  Notify(hcibuf[2], 0x80);
-
435 #endif
-
436  for (uint8_t i = 0; i < hcibuf[2]; i++) {
-
437  if ((hcibuf[4 + 8 * hcibuf[2] + 3 * i] == 0x04 && hcibuf[5 + 8 * hcibuf[2] + 3 * i] == 0x25 && hcibuf[6 + 8 * hcibuf[2] + 3 * i] == 0x00) || (hcibuf[4 + 8 * hcibuf[2] + 3 * i] == 0x08 && hcibuf[5 + 8 * hcibuf[2] + 3 * i] == 0x05 && hcibuf[6 + 8 * hcibuf[2] + 3 * i] == 0x00)) { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html and http://wiibrew.org/wiki/Wiimote#SDP_information
-
438  if (hcibuf[4 + 8 * hcibuf[2] + 3 * i] == 0x08) // Check if it's the new Wiimote with motion plus inside that was detected
-
439  motionPlusInside = true;
-
440  else
-
441  motionPlusInside = false;
-
442  disc_bdaddr[0] = hcibuf[3 + 6 * i];
-
443  disc_bdaddr[1] = hcibuf[4 + 6 * i];
-
444  disc_bdaddr[2] = hcibuf[5 + 6 * i];
-
445  disc_bdaddr[3] = hcibuf[6 + 6 * i];
-
446  disc_bdaddr[4] = hcibuf[7 + 6 * i];
-
447  disc_bdaddr[5] = hcibuf[8 + 6 * i];
-
448  hci_event_flag |= HCI_FLAG_WII_FOUND;
-
449  break;
-
450  }
-
451 #ifdef EXTRADEBUG
-
452  else {
-
453  Notify(PSTR("\r\nClass of device: "), 0x80);
-
454  D_PrintHex<uint8_t > (hcibuf[6 + 8 * hcibuf[2] + 3 * i], 0x80);
-
455  Notify(PSTR(" "), 0x80);
-
456  D_PrintHex<uint8_t > (hcibuf[5 + 8 * hcibuf[2] + 3 * i], 0x80);
-
457  Notify(PSTR(" "), 0x80);
-
458  D_PrintHex<uint8_t > (hcibuf[4 + 8 * hcibuf[2] + 3 * i], 0x80);
-
459  }
-
460 #endif
-
461  }
-
462  }
-
463  break;
-
464 
-
465  case EV_CONNECT_COMPLETE:
-
466  hci_event_flag |= HCI_FLAG_CONNECT_EVENT;
-
467  if (!hcibuf[2]) { // check if connected OK
-
468  hci_handle = hcibuf[3] | ((hcibuf[4] & 0x0F) << 8); // store the handle for the ACL connection
-
469  hci_event_flag |= HCI_FLAG_CONN_COMPLETE; // set connection complete flag
-
470  }
-
471 #ifdef DEBUG_USB_HOST
-
472  else {
-
473  Notify(PSTR("\r\nConnection Failed"), 0x80);
-
474  hci_state = HCI_CHECK_WII_SERVICE;
-
475  }
-
476 #endif
-
477  break;
-
478 
-
479  case EV_DISCONNECT_COMPLETE:
-
480  if (!hcibuf[2]) { // check if disconnected OK
-
481  hci_event_flag |= HCI_FLAG_DISCONN_COMPLETE; // set disconnect command complete flag
-
482  hci_event_flag &= ~HCI_FLAG_CONN_COMPLETE; // clear connection complete flag
+
421  if (pairWithWii)
+
422  Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80);
+
423  else
+
424  Notify(PSTR("\r\nCouldn't find HID device"), 0x80);
+
425 #endif
+
426  connectToWii = false;
+
427  pairWithWii = false;
+
428  connectToHIDDevice = false;
+
429  pairWithHIDDevice = false;
+
430  hci_state = HCI_SCANNING_STATE;
+
431  }
+
432  inquiry_counter++;
+
433  break;
+
434 
+
435  case EV_INQUIRY_RESULT:
+
436  if (hcibuf[2]) { // Check that there is more than zero responses
+
437 #ifdef EXTRADEBUG
+
438  Notify(PSTR("\r\nNumber of responses: "), 0x80);
+
439  Notify(hcibuf[2], 0x80);
+
440 #endif
+
441  for (uint8_t i = 0; i < hcibuf[2]; i++) {
+
442  uint8_t offset = 8 * hcibuf[2] + 3 * i;
+
443  uint8_t classOfDevice[3];
+
444 
+
445  for (uint8_t j = 0; j < 3; j++)
+
446  classOfDevice[j] = hcibuf[j + 4 + offset];
+
447 
+
448  if (pairWithWii && classOfDevice[2] == 0x00 && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0x0C)) { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html and http://wiibrew.org/wiki/Wiimote#SDP_information
+
449  if (classOfDevice[0] & 0x08) // Check if it's the new Wiimote with motion plus inside that was detected
+
450  motionPlusInside = true;
+
451  else
+
452  motionPlusInside = false;
+
453 
+
454  for (uint8_t j = 0; j < 6; j++)
+
455  disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
+
456 
+
457  hci_event_flag |= HCI_FLAG_DEVICE_FOUND;
+
458  break;
+
459  } else if (pairWithHIDDevice && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0xC0)) { // Check if it is a mouse or keyboard
+
460 #ifdef DEBUG_USB_HOST
+
461  if (classOfDevice[0] & 0x80)
+
462  Notify(PSTR("\r\nMouse found"), 0x80);
+
463  if (classOfDevice[0] & 0x40)
+
464  Notify(PSTR("\r\nKeyboard found"), 0x80);
+
465 #endif
+
466 
+
467  for (uint8_t j = 0; j < 6; j++)
+
468  disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
+
469 
+
470  hci_event_flag |= HCI_FLAG_DEVICE_FOUND;
+
471  }
+
472 #ifdef EXTRADEBUG
+
473  else {
+
474  Notify(PSTR("\r\nClass of device: "), 0x80);
+
475  D_PrintHex<uint8_t > (classOfDevice[2], 0x80);
+
476  Notify(PSTR(" "), 0x80);
+
477  D_PrintHex<uint8_t > (classOfDevice[1], 0x80);
+
478  Notify(PSTR(" "), 0x80);
+
479  D_PrintHex<uint8_t > (classOfDevice[0], 0x80);
+
480  }
+
481 #endif
+
482  }
483  }
484  break;
485 
-
486  case EV_REMOTE_NAME_COMPLETE:
-
487  if (!hcibuf[2]) { // check if reading is OK
-
488  for (uint8_t i = 0; i < min(sizeof (remote_name), sizeof (hcibuf) - 9); i++)
-
489  remote_name[i] = hcibuf[9 + i];
-
490  hci_event_flag |= HCI_FLAG_REMOTE_NAME_COMPLETE;
-
491  }
-
492  break;
-
493 
-
494  case EV_INCOMING_CONNECT:
-
495  disc_bdaddr[0] = hcibuf[2];
-
496  disc_bdaddr[1] = hcibuf[3];
-
497  disc_bdaddr[2] = hcibuf[4];
-
498  disc_bdaddr[3] = hcibuf[5];
-
499  disc_bdaddr[4] = hcibuf[6];
-
500  disc_bdaddr[5] = hcibuf[7];
-
501 #ifdef EXTRADEBUG
-
502  Notify(PSTR("\r\nClass of device: "), 0x80);
-
503  D_PrintHex<uint8_t > (hcibuf[10], 0x80);
-
504  Notify(PSTR(" "), 0x80);
-
505  D_PrintHex<uint8_t > (hcibuf[9], 0x80);
-
506  Notify(PSTR(" "), 0x80);
-
507  D_PrintHex<uint8_t > (hcibuf[8], 0x80);
-
508 #endif
-
509  hci_event_flag |= HCI_FLAG_INCOMING_REQUEST;
-
510  break;
-
511 
-
512  case EV_PIN_CODE_REQUEST:
-
513  if (pairWithWii) {
-
514 #ifdef DEBUG_USB_HOST
-
515  Notify(PSTR("\r\nPairing with wiimote"), 0x80);
-
516 #endif
-
517  hci_pin_code_request_reply();
-
518  } else if (btdPin != NULL) {
-
519 #ifdef DEBUG_USB_HOST
-
520  Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80);
-
521  NotifyStr(btdPin, 0x80);
-
522 #endif
-
523  hci_pin_code_request_reply();
-
524  } else {
-
525 #ifdef DEBUG_USB_HOST
-
526  Notify(PSTR("\r\nNo pin was set"), 0x80);
-
527 #endif
-
528  hci_pin_code_negative_request_reply();
-
529  }
-
530  break;
+
486  case EV_CONNECT_COMPLETE:
+
487  hci_event_flag |= HCI_FLAG_CONNECT_EVENT;
+
488  if (!hcibuf[2]) { // check if connected OK
+
489 #ifdef EXTRADEBUG
+
490  Notify(PSTR("\r\nConnection established"), 0x80);
+
491 #endif
+
492  hci_handle = hcibuf[3] | ((hcibuf[4] & 0x0F) << 8); // store the handle for the ACL connection
+
493  hci_event_flag |= HCI_FLAG_CONN_COMPLETE; // set connection complete flag
+
494  } else {
+
495  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
496 #ifdef DEBUG_USB_HOST
+
497  Notify(PSTR("\r\nConnection Failed: "), 0x80);
+
498  D_PrintHex<uint8_t > (hcibuf[2], 0x80);
+
499 #endif
+
500  }
+
501  break;
+
502 
+
503  case EV_DISCONNECT_COMPLETE:
+
504  if (!hcibuf[2]) { // check if disconnected OK
+
505  hci_event_flag |= HCI_FLAG_DISCONN_COMPLETE; // set disconnect command complete flag
+
506  hci_event_flag &= ~HCI_FLAG_CONN_COMPLETE; // clear connection complete flag
+
507  }
+
508  break;
+
509 
+
510  case EV_REMOTE_NAME_COMPLETE:
+
511  if (!hcibuf[2]) { // check if reading is OK
+
512  for (uint8_t i = 0; i < min(sizeof (remote_name), sizeof (hcibuf) - 9); i++)
+
513  remote_name[i] = hcibuf[9 + i];
+
514  hci_event_flag |= HCI_FLAG_REMOTE_NAME_COMPLETE;
+
515  }
+
516  break;
+
517 
+
518  case EV_INCOMING_CONNECT:
+
519  for (uint8_t i = 0; i < 6; i++)
+
520  disc_bdaddr[i] = hcibuf[i + 2];
+
521 
+
522  if ((hcibuf[9] & 0x05) && (hcibuf[8] & 0xC0)) { // Check if it is a mouse or keyboard
+
523 #ifdef DEBUG_USB_HOST
+
524  if (hcibuf[8] & 0x80)
+
525  Notify(PSTR("\r\nMouse is connecting"), 0x80);
+
526  if (hcibuf[8] & 0x40)
+
527  Notify(PSTR("\r\nKeyboard is connecting"), 0x80);
+
528 #endif
+
529  incomingHIDDevice = true;
+
530  }
531 
-
532  case EV_LINK_KEY_REQUEST:
-
533 #ifdef DEBUG_USB_HOST
-
534  Notify(PSTR("\r\nReceived Key Request"), 0x80);
-
535 #endif
-
536  hci_link_key_request_negative_reply();
-
537  break;
-
538 
-
539  case EV_AUTHENTICATION_COMPLETE:
-
540  if (pairWithWii && !connectToWii) {
-
541 #ifdef DEBUG_USB_HOST
-
542  Notify(PSTR("\r\nPairing successful"), 0x80);
-
543 #endif
-
544  connectToWii = true; // Only send the ACL data to the Wii service
-
545  }
-
546  break;
-
547  /* We will just ignore the following events */
-
548  case EV_NUM_COMPLETE_PKT:
-
549  case EV_ROLE_CHANGED:
-
550  case EV_PAGE_SCAN_REP_MODE:
-
551  case EV_LOOPBACK_COMMAND:
-
552  case EV_DATA_BUFFER_OVERFLOW:
-
553  case EV_CHANGE_CONNECTION_LINK:
-
554  case EV_MAX_SLOTS_CHANGE:
-
555  case EV_QOS_SETUP_COMPLETE:
-
556  case EV_LINK_KEY_NOTIFICATION:
-
557  case EV_ENCRYPTION_CHANGE:
-
558  case EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE:
-
559  break;
-
560 #ifdef EXTRADEBUG
-
561  default:
-
562  if (hcibuf[0] != 0x00) {
-
563  Notify(PSTR("\r\nUnmanaged HCI Event: "), 0x80);
-
564  D_PrintHex<uint8_t > (hcibuf[0], 0x80);
-
565  }
-
566  break;
-
567 #endif
-
568  } // switch
-
569  }
-
570 #ifdef EXTRADEBUG
-
571  else {
-
572  Notify(PSTR("\r\nHCI event error: "), 0x80);
-
573  D_PrintHex<uint8_t > (rcode, 0x80);
-
574  }
-
575 #endif
-
576  HCI_task();
-
577 }
-
578 
-
579 /* Poll Bluetooth and print result */
-
580 void BTD::HCI_task() {
-
581  switch (hci_state) {
-
582  case HCI_INIT_STATE:
-
583  hci_counter++;
-
584  if (hci_counter > hci_num_reset_loops) { // wait until we have looped x times to clear any old events
-
585  hci_reset();
-
586  hci_state = HCI_RESET_STATE;
-
587  hci_counter = 0;
-
588  }
-
589  break;
-
590 
-
591  case HCI_RESET_STATE:
-
592  hci_counter++;
-
593  if (hci_cmd_complete) {
-
594  hci_counter = 0;
-
595 #ifdef DEBUG_USB_HOST
-
596  Notify(PSTR("\r\nHCI Reset complete"), 0x80);
-
597 #endif
-
598  hci_state = HCI_CLASS_STATE;
-
599  hci_write_class_of_device();
-
600  } else if (hci_counter > hci_num_reset_loops) {
-
601  hci_num_reset_loops *= 10;
-
602  if (hci_num_reset_loops > 2000)
-
603  hci_num_reset_loops = 2000;
-
604 #ifdef DEBUG_USB_HOST
-
605  Notify(PSTR("\r\nNo response to HCI Reset"), 0x80);
-
606 #endif
-
607  hci_state = HCI_INIT_STATE;
-
608  hci_counter = 0;
-
609  }
-
610  break;
-
611 
-
612  case HCI_CLASS_STATE:
-
613  if (hci_cmd_complete) {
-
614 #ifdef DEBUG_USB_HOST
-
615  Notify(PSTR("\r\nWrite class of device"), 0x80);
-
616 #endif
-
617  hci_state = HCI_BDADDR_STATE;
-
618  hci_read_bdaddr();
-
619  }
-
620  break;
-
621 
-
622  case HCI_BDADDR_STATE:
-
623  if (hci_read_bdaddr_complete) {
-
624 #ifdef DEBUG_USB_HOST
-
625  Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80);
-
626  for (int8_t i = 5; i > 0; i--) {
-
627  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
-
628  Notify(PSTR(":"), 0x80);
-
629  }
-
630  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
-
631 #endif
-
632  hci_read_local_version_information();
-
633  hci_state = HCI_LOCAL_VERSION_STATE;
-
634  }
-
635  break;
-
636 
-
637  case HCI_LOCAL_VERSION_STATE: // The local version is used by the PS3BT class
-
638  if (hci_read_version_complete) {
-
639  if (btdName != NULL) {
-
640  hci_set_local_name(btdName);
-
641  hci_state = HCI_SET_NAME_STATE;
-
642  } else
-
643  hci_state = HCI_CHECK_WII_SERVICE;
-
644  }
-
645  break;
-
646 
-
647  case HCI_SET_NAME_STATE:
-
648  if (hci_cmd_complete) {
-
649 #ifdef DEBUG_USB_HOST
-
650  Notify(PSTR("\r\nThe name is set to: "), 0x80);
-
651  NotifyStr(btdName, 0x80);
+
532 #ifdef EXTRADEBUG
+
533  Notify(PSTR("\r\nClass of device: "), 0x80);
+
534  D_PrintHex<uint8_t > (hcibuf[10], 0x80);
+
535  Notify(PSTR(" "), 0x80);
+
536  D_PrintHex<uint8_t > (hcibuf[9], 0x80);
+
537  Notify(PSTR(" "), 0x80);
+
538  D_PrintHex<uint8_t > (hcibuf[8], 0x80);
+
539 #endif
+
540  hci_event_flag |= HCI_FLAG_INCOMING_REQUEST;
+
541  break;
+
542 
+
543  case EV_PIN_CODE_REQUEST:
+
544  if (pairWithWii) {
+
545 #ifdef DEBUG_USB_HOST
+
546  Notify(PSTR("\r\nPairing with wiimote"), 0x80);
+
547 #endif
+
548  hci_pin_code_request_reply();
+
549  } else if (btdPin != NULL) {
+
550 #ifdef DEBUG_USB_HOST
+
551  Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80);
+
552  NotifyStr(btdPin, 0x80);
+
553 #endif
+
554  hci_pin_code_request_reply();
+
555  } else {
+
556 #ifdef DEBUG_USB_HOST
+
557  Notify(PSTR("\r\nNo pin was set"), 0x80);
+
558 #endif
+
559  hci_pin_code_negative_request_reply();
+
560  }
+
561  break;
+
562 
+
563  case EV_LINK_KEY_REQUEST:
+
564 #ifdef DEBUG_USB_HOST
+
565  Notify(PSTR("\r\nReceived Key Request"), 0x80);
+
566 #endif
+
567  hci_link_key_request_negative_reply();
+
568  break;
+
569 
+
570  case EV_AUTHENTICATION_COMPLETE:
+
571  if (pairWithWii && !connectToWii) {
+
572 #ifdef DEBUG_USB_HOST
+
573  Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80);
+
574 #endif
+
575  connectToWii = true; // Only send the ACL data to the Wii service
+
576  } else if (pairWithHIDDevice && !connectToHIDDevice) {
+
577 #ifdef DEBUG_USB_HOST
+
578  Notify(PSTR("\r\nPairing successful with HID device"), 0x80);
+
579 #endif
+
580  connectToHIDDevice = true; // Only send the ACL data to the Wii service
+
581  }
+
582  break;
+
583  /* We will just ignore the following events */
+
584  case EV_NUM_COMPLETE_PKT:
+
585  case EV_ROLE_CHANGED:
+
586  case EV_PAGE_SCAN_REP_MODE:
+
587  case EV_LOOPBACK_COMMAND:
+
588  case EV_DATA_BUFFER_OVERFLOW:
+
589  case EV_CHANGE_CONNECTION_LINK:
+
590  case EV_MAX_SLOTS_CHANGE:
+
591  case EV_QOS_SETUP_COMPLETE:
+
592  case EV_LINK_KEY_NOTIFICATION:
+
593  case EV_ENCRYPTION_CHANGE:
+
594  case EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE:
+
595  break;
+
596 #ifdef EXTRADEBUG
+
597  default:
+
598  if (hcibuf[0] != 0x00) {
+
599  Notify(PSTR("\r\nUnmanaged HCI Event: "), 0x80);
+
600  D_PrintHex<uint8_t > (hcibuf[0], 0x80);
+
601  }
+
602  break;
+
603 #endif
+
604  } // switch
+
605  }
+
606 #ifdef EXTRADEBUG
+
607  else {
+
608  Notify(PSTR("\r\nHCI event error: "), 0x80);
+
609  D_PrintHex<uint8_t > (rcode, 0x80);
+
610  }
+
611 #endif
+
612  HCI_task();
+
613 }
+
614 
+
615 /* Poll Bluetooth and print result */
+
616 void BTD::HCI_task() {
+
617  switch (hci_state) {
+
618  case HCI_INIT_STATE:
+
619  hci_counter++;
+
620  if (hci_counter > hci_num_reset_loops) { // wait until we have looped x times to clear any old events
+
621  hci_reset();
+
622  hci_state = HCI_RESET_STATE;
+
623  hci_counter = 0;
+
624  }
+
625  break;
+
626 
+
627  case HCI_RESET_STATE:
+
628  hci_counter++;
+
629  if (hci_cmd_complete) {
+
630  hci_counter = 0;
+
631 #ifdef DEBUG_USB_HOST
+
632  Notify(PSTR("\r\nHCI Reset complete"), 0x80);
+
633 #endif
+
634  hci_state = HCI_CLASS_STATE;
+
635  hci_write_class_of_device();
+
636  } else if (hci_counter > hci_num_reset_loops) {
+
637  hci_num_reset_loops *= 10;
+
638  if (hci_num_reset_loops > 2000)
+
639  hci_num_reset_loops = 2000;
+
640 #ifdef DEBUG_USB_HOST
+
641  Notify(PSTR("\r\nNo response to HCI Reset"), 0x80);
+
642 #endif
+
643  hci_state = HCI_INIT_STATE;
+
644  hci_counter = 0;
+
645  }
+
646  break;
+
647 
+
648  case HCI_CLASS_STATE:
+
649  if (hci_cmd_complete) {
+
650 #ifdef DEBUG_USB_HOST
+
651  Notify(PSTR("\r\nWrite class of device"), 0x80);
652 #endif
-
653  hci_state = HCI_CHECK_WII_SERVICE;
-
654  }
-
655  break;
-
656 
-
657  case HCI_CHECK_WII_SERVICE:
-
658  if (pairWithWii) { // Check if it should try to connect to a wiimote
-
659 #ifdef DEBUG_USB_HOST
-
660  Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80);
-
661 #endif
-
662  hci_inquiry();
-
663  hci_state = HCI_INQUIRY_STATE;
-
664  } else
-
665  hci_state = HCI_SCANNING_STATE; // Don't try to connect to a Wiimote
-
666  break;
-
667 
-
668  case HCI_INQUIRY_STATE:
-
669  if (hci_wii_found) {
-
670  hci_inquiry_cancel(); // Stop inquiry
-
671 #ifdef DEBUG_USB_HOST
-
672  Notify(PSTR("\r\nWiimote found"), 0x80);
-
673  Notify(PSTR("\r\nNow just create the instance like so:"), 0x80);
-
674  Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
-
675  Notify(PSTR("\r\nAnd then press any button on the Wiimote"), 0x80);
-
676 #endif
-
677  if (motionPlusInside) {
-
678  hci_remote_name(); // We need to know the name to distinguish between a Wiimote and a Wii U Pro Controller
-
679  hci_state = HCI_REMOTE_NAME_STATE;
-
680  } else
-
681  hci_state = HCI_CONNECT_WII_STATE;
-
682  }
-
683  break;
-
684 
-
685  case HCI_CONNECT_WII_STATE:
-
686  if (hci_cmd_complete) {
-
687 #ifdef DEBUG_USB_HOST
-
688  Notify(PSTR("\r\nConnecting to Wiimote"), 0x80);
-
689 #endif
-
690  hci_connect();
-
691  hci_state = HCI_CONNECTED_WII_STATE;
-
692  }
-
693  break;
-
694 
-
695  case HCI_CONNECTED_WII_STATE:
-
696  if (hci_connect_event) {
-
697  if (hci_connect_complete) {
-
698 #ifdef DEBUG_USB_HOST
-
699  Notify(PSTR("\r\nConnected to Wiimote"), 0x80);
+
653  hci_state = HCI_BDADDR_STATE;
+
654  hci_read_bdaddr();
+
655  }
+
656  break;
+
657 
+
658  case HCI_BDADDR_STATE:
+
659  if (hci_read_bdaddr_complete) {
+
660 #ifdef DEBUG_USB_HOST
+
661  Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80);
+
662  for (int8_t i = 5; i > 0; i--) {
+
663  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
+
664  Notify(PSTR(":"), 0x80);
+
665  }
+
666  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
+
667 #endif
+
668  hci_read_local_version_information();
+
669  hci_state = HCI_LOCAL_VERSION_STATE;
+
670  }
+
671  break;
+
672 
+
673  case HCI_LOCAL_VERSION_STATE: // The local version is used by the PS3BT class
+
674  if (hci_read_version_complete) {
+
675  if (btdName != NULL) {
+
676  hci_set_local_name(btdName);
+
677  hci_state = HCI_SET_NAME_STATE;
+
678  } else
+
679  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
680  }
+
681  break;
+
682 
+
683  case HCI_SET_NAME_STATE:
+
684  if (hci_cmd_complete) {
+
685 #ifdef DEBUG_USB_HOST
+
686  Notify(PSTR("\r\nThe name is set to: "), 0x80);
+
687  NotifyStr(btdName, 0x80);
+
688 #endif
+
689  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
690  }
+
691  break;
+
692 
+
693  case HCI_CHECK_DEVICE_SERVICE:
+
694  if (pairWithHIDDevice || pairWithWii) { // Check if it should try to connect to a wiimote
+
695 #ifdef DEBUG_USB_HOST
+
696  if (pairWithWii)
+
697  Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80);
+
698  else
+
699  Notify(PSTR("\r\nPlease enable discovery of your device"), 0x80);
700 #endif
-
701  hci_authentication_request(); // This will start the pairing with the wiimote
-
702  hci_state = HCI_SCANNING_STATE;
-
703  } else {
-
704 #ifdef DEBUG_USB_HOST
-
705  Notify(PSTR("\r\nTrying to connect one more time..."), 0x80);
-
706 #endif
-
707  hci_connect(); // Try to connect one more time
-
708  }
-
709  }
-
710  break;
-
711 
-
712  case HCI_SCANNING_STATE:
-
713  if (!connectToWii && !pairWithWii) {
-
714 #ifdef DEBUG_USB_HOST
-
715  Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80);
-
716 #endif
-
717  hci_write_scan_enable();
-
718  watingForConnection = true;
-
719  hci_state = HCI_CONNECT_IN_STATE;
-
720  }
-
721  break;
-
722 
-
723  case HCI_CONNECT_IN_STATE:
-
724  if (hci_incoming_connect_request) {
-
725  watingForConnection = false;
-
726 #ifdef DEBUG_USB_HOST
-
727  Notify(PSTR("\r\nIncoming Connection Request"), 0x80);
-
728 #endif
-
729  hci_remote_name();
-
730  hci_state = HCI_REMOTE_NAME_STATE;
-
731  } else if (hci_disconnect_complete)
-
732  hci_state = HCI_DISCONNECT_STATE;
-
733  break;
-
734 
-
735  case HCI_REMOTE_NAME_STATE:
-
736  if (hci_remote_name_complete) {
-
737 #ifdef DEBUG_USB_HOST
-
738  Notify(PSTR("\r\nRemote Name: "), 0x80);
-
739  for (uint8_t i = 0; i < 30; i++) {
-
740  if (remote_name[i] == NULL)
-
741  break;
-
742  Notifyc(remote_name[i], 0x80);
-
743  }
-
744 #endif
-
745  if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) {
-
746  incomingWii = true;
-
747 #ifdef DEBUG_USB_HOST
-
748  Notify(PSTR("\r\nWiimote is connecting"), 0x80);
-
749 #endif
-
750  if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) {
-
751 #ifdef DEBUG_USB_HOST
-
752  Notify(PSTR(" with Motion Plus Inside"), 0x80);
-
753 #endif
-
754  motionPlusInside = true;
-
755  } else if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) {
-
756 #ifdef DEBUG_USB_HOST
-
757  Notify(PSTR(" - Wii U Pro Controller"), 0x80);
-
758 #endif
-
759  motionPlusInside = true;
-
760  wiiUProController = true;
-
761  } else {
-
762  motionPlusInside = false;
-
763  wiiUProController = false;
-
764  }
+
701  hci_inquiry();
+
702  hci_state = HCI_INQUIRY_STATE;
+
703  } else
+
704  hci_state = HCI_SCANNING_STATE; // Don't try to connect to a Wiimote
+
705  break;
+
706 
+
707  case HCI_INQUIRY_STATE:
+
708  if (hci_device_found) {
+
709  hci_inquiry_cancel(); // Stop inquiry
+
710 #ifdef DEBUG_USB_HOST
+
711  if (pairWithWii)
+
712  Notify(PSTR("\r\nWiimote found"), 0x80);
+
713  else
+
714  Notify(PSTR("\r\nHID device found"), 0x80);
+
715 
+
716  Notify(PSTR("\r\nNow just create the instance like so:"), 0x80);
+
717  if (pairWithWii)
+
718  Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
+
719  else
+
720  Notify(PSTR("\r\nBTHID hid(&Btd);"), 0x80);
+
721 
+
722  Notify(PSTR("\r\nAnd then press any button on the "), 0x80);
+
723  if (pairWithWii)
+
724  Notify(PSTR("Wiimote"), 0x80);
+
725  else
+
726  Notify(PSTR("device"), 0x80);
+
727 #endif
+
728  if (motionPlusInside) {
+
729  hci_remote_name(); // We need to know the name to distinguish between a Wiimote and a Wii U Pro Controller
+
730  hci_state = HCI_REMOTE_NAME_STATE;
+
731  } else
+
732  hci_state = HCI_CONNECT_DEVICE_STATE;
+
733  }
+
734  break;
+
735 
+
736  case HCI_CONNECT_DEVICE_STATE:
+
737  if (hci_cmd_complete) {
+
738 #ifdef DEBUG_USB_HOST
+
739  if (pairWithWii)
+
740  Notify(PSTR("\r\nConnecting to Wiimote"), 0x80);
+
741  else
+
742  Notify(PSTR("\r\nConnecting to HID device"), 0x80);
+
743 #endif
+
744  hci_connect();
+
745  hci_state = HCI_CONNECTED_DEVICE_STATE;
+
746  }
+
747  break;
+
748 
+
749  case HCI_CONNECTED_DEVICE_STATE:
+
750  if (hci_connect_event) {
+
751  if (hci_connect_complete) {
+
752 #ifdef DEBUG_USB_HOST
+
753  if (pairWithWii)
+
754  Notify(PSTR("\r\nConnected to Wiimote"), 0x80);
+
755  else
+
756  Notify(PSTR("\r\nConnected to HID device"), 0x80);
+
757 #endif
+
758  hci_authentication_request(); // This will start the pairing with the wiimote
+
759  hci_state = HCI_SCANNING_STATE;
+
760  } else {
+
761 #ifdef DEBUG_USB_HOST
+
762  Notify(PSTR("\r\nTrying to connect one more time..."), 0x80);
+
763 #endif
+
764  hci_connect(); // Try to connect one more time
765  }
-
766  if (pairWithWii && motionPlusInside)
-
767  hci_state = HCI_CONNECT_WII_STATE;
-
768  else {
-
769  hci_accept_connection();
-
770  hci_state = HCI_CONNECTED_STATE;
-
771  }
-
772  }
-
773  break;
-
774 
-
775  case HCI_CONNECTED_STATE:
-
776  if (hci_connect_complete) {
-
777 #ifdef DEBUG_USB_HOST
-
778  Notify(PSTR("\r\nConnected to Device: "), 0x80);
-
779  for (int8_t i = 5; i > 0; i--) {
-
780  D_PrintHex<uint8_t > (disc_bdaddr[i], 0x80);
-
781  Notify(PSTR(":"), 0x80);
-
782  }
-
783  D_PrintHex<uint8_t > (disc_bdaddr[0], 0x80);
-
784 #endif
-
785  // Clear these flags for a new connection
-
786  l2capConnectionClaimed = false;
-
787  sdpConnectionClaimed = false;
-
788  rfcommConnectionClaimed = false;
-
789 
-
790  hci_event_flag = 0;
-
791  hci_state = HCI_DONE_STATE;
-
792  }
-
793  break;
-
794 
-
795  case HCI_DONE_STATE:
-
796  hci_counter++;
-
797  if (hci_counter > 1000) { // Wait until we have looped 1000 times to make sure that the L2CAP connection has been started
-
798  hci_counter = 0;
-
799  hci_state = HCI_SCANNING_STATE;
-
800  }
-
801  break;
-
802 
-
803  case HCI_DISCONNECT_STATE:
-
804  if (hci_disconnect_complete) {
-
805 #ifdef DEBUG_USB_HOST
-
806  Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80);
-
807 #endif
-
808  hci_event_flag = 0; // Clear all flags
-
809 
-
810  // Reset all buffers
-
811  for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++)
-
812  hcibuf[i] = 0;
-
813  for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++)
-
814  l2capinbuf[i] = 0;
-
815 
-
816  connectToWii = false;
-
817  incomingWii = false;
-
818  pairWithWii = false;
-
819 
-
820  hci_state = HCI_SCANNING_STATE;
-
821  }
-
822  break;
-
823  default:
-
824  break;
-
825  }
-
826 }
-
827 
-
828 void BTD::ACL_event_task() {
-
829  uint16_t MAX_BUFFER_SIZE = BULK_MAXPKTSIZE;
-
830  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &MAX_BUFFER_SIZE, l2capinbuf); // input on endpoint 2
-
831  if (!rcode) { // Check for errors
-
832  for (uint8_t i = 0; i < BTD_NUMSERVICES; i++)
-
833  if (btService[i])
-
834  btService[i]->ACLData(l2capinbuf);
-
835  }
-
836 #ifdef EXTRADEBUG
-
837  else if (rcode != hrNAK) {
-
838  Notify(PSTR("\r\nACL data in error: "), 0x80);
-
839  D_PrintHex<uint8_t > (rcode, 0x80);
-
840  }
+
766  }
+
767  break;
+
768 
+
769  case HCI_SCANNING_STATE:
+
770  if (!connectToWii && !pairWithWii && !connectToHIDDevice && !pairWithHIDDevice) {
+
771 #ifdef DEBUG_USB_HOST
+
772  Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80);
+
773 #endif
+
774  hci_write_scan_enable();
+
775  watingForConnection = true;
+
776  hci_state = HCI_CONNECT_IN_STATE;
+
777  }
+
778  break;
+
779 
+
780  case HCI_CONNECT_IN_STATE:
+
781  if (hci_incoming_connect_request) {
+
782  watingForConnection = false;
+
783 #ifdef DEBUG_USB_HOST
+
784  Notify(PSTR("\r\nIncoming Connection Request"), 0x80);
+
785 #endif
+
786  hci_remote_name();
+
787  hci_state = HCI_REMOTE_NAME_STATE;
+
788  } else if (hci_disconnect_complete)
+
789  hci_state = HCI_DISCONNECT_STATE;
+
790  break;
+
791 
+
792  case HCI_REMOTE_NAME_STATE:
+
793  if (hci_remote_name_complete) {
+
794 #ifdef DEBUG_USB_HOST
+
795  Notify(PSTR("\r\nRemote Name: "), 0x80);
+
796  for (uint8_t i = 0; i < 30; i++) {
+
797  if (remote_name[i] == NULL)
+
798  break;
+
799  Notifyc(remote_name[i], 0x80);
+
800  }
+
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 (pairWithWii && motionPlusInside)
+
824  hci_state = HCI_CONNECT_DEVICE_STATE;
+
825  else {
+
826  hci_accept_connection();
+
827  hci_state = HCI_CONNECTED_STATE;
+
828  }
+
829  }
+
830  break;
+
831 
+
832  case HCI_CONNECTED_STATE:
+
833  if (hci_connect_complete) {
+
834 #ifdef DEBUG_USB_HOST
+
835  Notify(PSTR("\r\nConnected to Device: "), 0x80);
+
836  for (int8_t i = 5; i > 0; i--) {
+
837  D_PrintHex<uint8_t > (disc_bdaddr[i], 0x80);
+
838  Notify(PSTR(":"), 0x80);
+
839  }
+
840  D_PrintHex<uint8_t > (disc_bdaddr[0], 0x80);
841 #endif
-
842  for (uint8_t i = 0; i < BTD_NUMSERVICES; i++)
-
843  if (btService[i])
-
844  btService[i]->Run();
-
845 }
+
842  // Clear these flags for a new connection
+
843  l2capConnectionClaimed = false;
+
844  sdpConnectionClaimed = false;
+
845  rfcommConnectionClaimed = false;
846 
-
847 /************************************************************/
-
848 /* HCI Commands */
-
849 
-
850 /************************************************************/
-
851 void BTD::HCI_Command(uint8_t* data, uint16_t nbytes) {
-
852  hci_event_flag &= ~HCI_FLAG_CMD_COMPLETE;
-
853  pUsb->ctrlReq(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bmREQ_HCI_OUT, 0x00, 0x00, 0x00, 0x00, nbytes, nbytes, data, NULL);
-
854 }
-
855 
-
856 void BTD::hci_reset() {
-
857  hci_event_flag = 0; // Clear all the flags
-
858  hcibuf[0] = 0x03; // HCI OCF = 3
-
859  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
860  hcibuf[2] = 0x00;
-
861 
-
862  HCI_Command(hcibuf, 3);
-
863 }
-
864 
-
865 void BTD::hci_write_scan_enable() {
-
866  hci_event_flag &= ~HCI_FLAG_INCOMING_REQUEST;
-
867  hcibuf[0] = 0x1A; // HCI OCF = 1A
-
868  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
869  hcibuf[2] = 0x01; // parameter length = 1
-
870  if (btdName != NULL)
-
871  hcibuf[3] = 0x03; // Inquiry Scan enabled. Page Scan enabled.
-
872  else
-
873  hcibuf[3] = 0x02; // Inquiry Scan disabled. Page Scan enabled.
-
874 
-
875  HCI_Command(hcibuf, 4);
-
876 }
-
877 
-
878 void BTD::hci_write_scan_disable() {
-
879  hcibuf[0] = 0x1A; // HCI OCF = 1A
-
880  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
881  hcibuf[2] = 0x01; // parameter length = 1
-
882  hcibuf[3] = 0x00; // Inquiry Scan disabled. Page Scan disabled.
-
883 
-
884  HCI_Command(hcibuf, 4);
-
885 }
-
886 
-
887 void BTD::hci_read_bdaddr() {
-
888  hcibuf[0] = 0x09; // HCI OCF = 9
-
889  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
-
890  hcibuf[2] = 0x00;
-
891 
-
892  HCI_Command(hcibuf, 3);
-
893 }
-
894 
-
895 void BTD::hci_read_local_version_information() {
-
896  hcibuf[0] = 0x01; // HCI OCF = 1
-
897  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
-
898  hcibuf[2] = 0x00;
-
899 
-
900  HCI_Command(hcibuf, 3);
-
901 }
-
902 
-
903 void BTD::hci_accept_connection() {
-
904  hci_event_flag &= ~HCI_FLAG_CONN_COMPLETE;
-
905  hcibuf[0] = 0x09; // HCI OCF = 9
-
906  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
907  hcibuf[2] = 0x07; // parameter length 7
-
908  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
909  hcibuf[4] = disc_bdaddr[1];
-
910  hcibuf[5] = disc_bdaddr[2];
-
911  hcibuf[6] = disc_bdaddr[3];
-
912  hcibuf[7] = disc_bdaddr[4];
-
913  hcibuf[8] = disc_bdaddr[5];
-
914  hcibuf[9] = 0x00; //switch role to master
-
915 
-
916  HCI_Command(hcibuf, 10);
-
917 }
-
918 
-
919 void BTD::hci_remote_name() {
-
920  hci_event_flag &= ~HCI_FLAG_REMOTE_NAME_COMPLETE;
-
921  hcibuf[0] = 0x19; // HCI OCF = 19
-
922  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
923  hcibuf[2] = 0x0A; // parameter length = 10
-
924  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
925  hcibuf[4] = disc_bdaddr[1];
-
926  hcibuf[5] = disc_bdaddr[2];
-
927  hcibuf[6] = disc_bdaddr[3];
-
928  hcibuf[7] = disc_bdaddr[4];
-
929  hcibuf[8] = disc_bdaddr[5];
-
930  hcibuf[9] = 0x01; //Page Scan Repetition Mode
-
931  hcibuf[10] = 0x00; //Reserved
-
932  hcibuf[11] = 0x00; //Clock offset - low byte
-
933  hcibuf[12] = 0x00; //Clock offset - high byte
-
934 
-
935  HCI_Command(hcibuf, 13);
-
936 }
-
937 
-
938 void BTD::hci_set_local_name(const char* name) {
-
939  hcibuf[0] = 0x13; // HCI OCF = 13
-
940  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
941  hcibuf[2] = strlen(name) + 1; // parameter length = the length of the string + end byte
-
942  uint8_t i;
-
943  for (i = 0; i < strlen(name); i++)
-
944  hcibuf[i + 3] = name[i];
-
945  hcibuf[i + 3] = 0x00; // End of string
-
946 
-
947  HCI_Command(hcibuf, 4 + strlen(name));
-
948 }
-
949 
-
950 void BTD::hci_inquiry() {
-
951  hci_event_flag &= ~HCI_FLAG_WII_FOUND;
-
952  hcibuf[0] = 0x01;
-
953  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
954  hcibuf[2] = 0x05; // Parameter Total Length = 5
-
955  hcibuf[3] = 0x33; // LAP: Genera/Unlimited Inquiry Access Code (GIAC = 0x9E8B33) - see https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
-
956  hcibuf[4] = 0x8B;
-
957  hcibuf[5] = 0x9E;
-
958  hcibuf[6] = 0x30; // Inquiry time = 61.44 sec (maximum)
-
959  hcibuf[7] = 0x0A; // 10 number of responses
+
847  hci_event_flag = 0;
+
848  hci_state = HCI_DONE_STATE;
+
849  }
+
850  break;
+
851 
+
852  case HCI_DONE_STATE:
+
853  hci_counter++;
+
854  if (hci_counter > 1000) { // Wait until we have looped 1000 times to make sure that the L2CAP connection has been started
+
855  hci_counter = 0;
+
856  hci_state = HCI_SCANNING_STATE;
+
857  }
+
858  break;
+
859 
+
860  case HCI_DISCONNECT_STATE:
+
861  if (hci_disconnect_complete) {
+
862 #ifdef DEBUG_USB_HOST
+
863  Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80);
+
864 #endif
+
865  hci_event_flag = 0; // Clear all flags
+
866 
+
867  // Reset all buffers
+
868  for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++)
+
869  hcibuf[i] = 0;
+
870  for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++)
+
871  l2capinbuf[i] = 0;
+
872 
+
873  connectToWii = false;
+
874  incomingWii = false;
+
875  pairWithWii = false;
+
876 
+
877  connectToHIDDevice = false;
+
878  incomingHIDDevice = false;
+
879  pairWithHIDDevice = false;
+
880 
+
881  hci_state = HCI_SCANNING_STATE;
+
882  }
+
883  break;
+
884  default:
+
885  break;
+
886  }
+
887 }
+
888 
+
889 void BTD::ACL_event_task() {
+
890  uint16_t MAX_BUFFER_SIZE = BULK_MAXPKTSIZE;
+
891  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &MAX_BUFFER_SIZE, l2capinbuf); // input on endpoint 2
+
892  if (!rcode) { // Check for errors
+
893  for (uint8_t i = 0; i < BTD_NUMSERVICES; i++)
+
894  if (btService[i])
+
895  btService[i]->ACLData(l2capinbuf);
+
896  }
+
897 #ifdef EXTRADEBUG
+
898  else if (rcode != hrNAK) {
+
899  Notify(PSTR("\r\nACL data in error: "), 0x80);
+
900  D_PrintHex<uint8_t > (rcode, 0x80);
+
901  }
+
902 #endif
+
903  for (uint8_t i = 0; i < BTD_NUMSERVICES; i++)
+
904  if (btService[i])
+
905  btService[i]->Run();
+
906 }
+
907 
+
908 /************************************************************/
+
909 /* HCI Commands */
+
910 
+
911 /************************************************************/
+
912 void BTD::HCI_Command(uint8_t* data, uint16_t nbytes) {
+
913  hci_event_flag &= ~HCI_FLAG_CMD_COMPLETE;
+
914  pUsb->ctrlReq(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bmREQ_HCI_OUT, 0x00, 0x00, 0x00, 0x00, nbytes, nbytes, data, NULL);
+
915 }
+
916 
+
917 void BTD::hci_reset() {
+
918  hci_event_flag = 0; // Clear all the flags
+
919  hcibuf[0] = 0x03; // HCI OCF = 3
+
920  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
921  hcibuf[2] = 0x00;
+
922 
+
923  HCI_Command(hcibuf, 3);
+
924 }
+
925 
+
926 void BTD::hci_write_scan_enable() {
+
927  hci_event_flag &= ~HCI_FLAG_INCOMING_REQUEST;
+
928  hcibuf[0] = 0x1A; // HCI OCF = 1A
+
929  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
930  hcibuf[2] = 0x01; // parameter length = 1
+
931  if (btdName != NULL)
+
932  hcibuf[3] = 0x03; // Inquiry Scan enabled. Page Scan enabled.
+
933  else
+
934  hcibuf[3] = 0x02; // Inquiry Scan disabled. Page Scan enabled.
+
935 
+
936  HCI_Command(hcibuf, 4);
+
937 }
+
938 
+
939 void BTD::hci_write_scan_disable() {
+
940  hcibuf[0] = 0x1A; // HCI OCF = 1A
+
941  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
942  hcibuf[2] = 0x01; // parameter length = 1
+
943  hcibuf[3] = 0x00; // Inquiry Scan disabled. Page Scan disabled.
+
944 
+
945  HCI_Command(hcibuf, 4);
+
946 }
+
947 
+
948 void BTD::hci_read_bdaddr() {
+
949  hcibuf[0] = 0x09; // HCI OCF = 9
+
950  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
+
951  hcibuf[2] = 0x00;
+
952 
+
953  HCI_Command(hcibuf, 3);
+
954 }
+
955 
+
956 void BTD::hci_read_local_version_information() {
+
957  hcibuf[0] = 0x01; // HCI OCF = 1
+
958  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
+
959  hcibuf[2] = 0x00;
960 
-
961  HCI_Command(hcibuf, 8);
+
961  HCI_Command(hcibuf, 3);
962 }
963 
-
964 void BTD::hci_inquiry_cancel() {
-
965  hcibuf[0] = 0x02;
-
966  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
967  hcibuf[2] = 0x00; // Parameter Total Length = 0
-
968 
-
969  HCI_Command(hcibuf, 3);
-
970 }
-
971 
-
972 void BTD::hci_connect() {
-
973  hci_event_flag &= ~(HCI_FLAG_CONN_COMPLETE | HCI_FLAG_CONNECT_EVENT);
-
974  hcibuf[0] = 0x05;
-
975  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
976  hcibuf[2] = 0x0D; // parameter Total Length = 13
-
977  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
978  hcibuf[4] = disc_bdaddr[1];
-
979  hcibuf[5] = disc_bdaddr[2];
-
980  hcibuf[6] = disc_bdaddr[3];
-
981  hcibuf[7] = disc_bdaddr[4];
-
982  hcibuf[8] = disc_bdaddr[5];
-
983  hcibuf[9] = 0x18; // DM1 or DH1 may be used
-
984  hcibuf[10] = 0xCC; // DM3, DH3, DM5, DH5 may be used
-
985  hcibuf[11] = 0x01; // Page repetition mode R1
-
986  hcibuf[12] = 0x00; // Reserved
-
987  hcibuf[13] = 0x00; // Clock offset
-
988  hcibuf[14] = 0x00; // Invalid clock offset
-
989  hcibuf[15] = 0x00; // Do not allow role switch
-
990 
-
991  HCI_Command(hcibuf, 16);
-
992 }
-
993 
-
994 void BTD::hci_pin_code_request_reply() {
-
995  hcibuf[0] = 0x0D; // HCI OCF = 0D
-
996  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
997  hcibuf[2] = 0x17; // parameter length 23
-
998  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
999  hcibuf[4] = disc_bdaddr[1];
-
1000  hcibuf[5] = disc_bdaddr[2];
-
1001  hcibuf[6] = disc_bdaddr[3];
-
1002  hcibuf[7] = disc_bdaddr[4];
-
1003  hcibuf[8] = disc_bdaddr[5];
-
1004  if (pairWithWii) {
-
1005  hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
-
1006  if (wiiUProController) {
-
1007 #ifdef DEBUG_USB_HOST
-
1008  Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80);
-
1009 #endif
-
1010  for (uint8_t i = 0; i < 6; i++)
-
1011  hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards
-
1012  } else {
-
1013  for (uint8_t i = 0; i < 6; i++)
-
1014  hcibuf[10 + i] = disc_bdaddr[i]; // The pin is the Wiimote's Bluetooth address backwards
-
1015  }
-
1016  for (uint8_t i = 16; i < 26; i++)
-
1017  hcibuf[i] = 0x00; // The rest should be 0
-
1018  } else {
-
1019  hcibuf[9] = strlen(btdPin); // Length of pin
-
1020  uint8_t i;
-
1021  for (i = 0; i < strlen(btdPin); i++) // The maximum size of the pin is 16
-
1022  hcibuf[i + 10] = btdPin[i];
-
1023  for (; i < 16; i++)
-
1024  hcibuf[i + 10] = 0x00; // The rest should be 0
-
1025  }
-
1026 
-
1027  HCI_Command(hcibuf, 26);
-
1028 }
+
964 void BTD::hci_accept_connection() {
+
965  hci_event_flag &= ~HCI_FLAG_CONN_COMPLETE;
+
966  hcibuf[0] = 0x09; // HCI OCF = 9
+
967  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
968  hcibuf[2] = 0x07; // parameter length 7
+
969  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
970  hcibuf[4] = disc_bdaddr[1];
+
971  hcibuf[5] = disc_bdaddr[2];
+
972  hcibuf[6] = disc_bdaddr[3];
+
973  hcibuf[7] = disc_bdaddr[4];
+
974  hcibuf[8] = disc_bdaddr[5];
+
975  hcibuf[9] = 0x00; //switch role to master
+
976 
+
977  HCI_Command(hcibuf, 10);
+
978 }
+
979 
+
980 void BTD::hci_remote_name() {
+
981  hci_event_flag &= ~HCI_FLAG_REMOTE_NAME_COMPLETE;
+
982  hcibuf[0] = 0x19; // HCI OCF = 19
+
983  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
984  hcibuf[2] = 0x0A; // parameter length = 10
+
985  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
986  hcibuf[4] = disc_bdaddr[1];
+
987  hcibuf[5] = disc_bdaddr[2];
+
988  hcibuf[6] = disc_bdaddr[3];
+
989  hcibuf[7] = disc_bdaddr[4];
+
990  hcibuf[8] = disc_bdaddr[5];
+
991  hcibuf[9] = 0x01; //Page Scan Repetition Mode
+
992  hcibuf[10] = 0x00; //Reserved
+
993  hcibuf[11] = 0x00; //Clock offset - low byte
+
994  hcibuf[12] = 0x00; //Clock offset - high byte
+
995 
+
996  HCI_Command(hcibuf, 13);
+
997 }
+
998 
+
999 void BTD::hci_set_local_name(const char* name) {
+
1000  hcibuf[0] = 0x13; // HCI OCF = 13
+
1001  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
1002  hcibuf[2] = strlen(name) + 1; // parameter length = the length of the string + end byte
+
1003  uint8_t i;
+
1004  for (i = 0; i < strlen(name); i++)
+
1005  hcibuf[i + 3] = name[i];
+
1006  hcibuf[i + 3] = 0x00; // End of string
+
1007 
+
1008  HCI_Command(hcibuf, 4 + strlen(name));
+
1009 }
+
1010 
+
1011 void BTD::hci_inquiry() {
+
1012  hci_event_flag &= ~HCI_FLAG_DEVICE_FOUND;
+
1013  hcibuf[0] = 0x01;
+
1014  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1015  hcibuf[2] = 0x05; // Parameter Total Length = 5
+
1016  hcibuf[3] = 0x33; // LAP: Genera/Unlimited Inquiry Access Code (GIAC = 0x9E8B33) - see https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
+
1017  hcibuf[4] = 0x8B;
+
1018  hcibuf[5] = 0x9E;
+
1019  hcibuf[6] = 0x30; // Inquiry time = 61.44 sec (maximum)
+
1020  hcibuf[7] = 0x0A; // 10 number of responses
+
1021 
+
1022  HCI_Command(hcibuf, 8);
+
1023 }
+
1024 
+
1025 void BTD::hci_inquiry_cancel() {
+
1026  hcibuf[0] = 0x02;
+
1027  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1028  hcibuf[2] = 0x00; // Parameter Total Length = 0
1029 
-
1030 void BTD::hci_pin_code_negative_request_reply() {
-
1031  hcibuf[0] = 0x0E; // HCI OCF = 0E
-
1032  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1033  hcibuf[2] = 0x06; // parameter length 6
-
1034  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
1035  hcibuf[4] = disc_bdaddr[1];
-
1036  hcibuf[5] = disc_bdaddr[2];
-
1037  hcibuf[6] = disc_bdaddr[3];
-
1038  hcibuf[7] = disc_bdaddr[4];
-
1039  hcibuf[8] = disc_bdaddr[5];
-
1040 
-
1041  HCI_Command(hcibuf, 9);
-
1042 }
-
1043 
-
1044 void BTD::hci_link_key_request_negative_reply() {
-
1045  hcibuf[0] = 0x0C; // HCI OCF = 0C
-
1046  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1047  hcibuf[2] = 0x06; // parameter length 6
-
1048  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
1049  hcibuf[4] = disc_bdaddr[1];
-
1050  hcibuf[5] = disc_bdaddr[2];
-
1051  hcibuf[6] = disc_bdaddr[3];
-
1052  hcibuf[7] = disc_bdaddr[4];
-
1053  hcibuf[8] = disc_bdaddr[5];
-
1054 
-
1055  HCI_Command(hcibuf, 9);
-
1056 }
-
1057 
-
1058 void BTD::hci_authentication_request() {
-
1059  hcibuf[0] = 0x11; // HCI OCF = 11
-
1060  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1061  hcibuf[2] = 0x02; // parameter length = 2
-
1062  hcibuf[3] = (uint8_t)(hci_handle & 0xFF); //connection handle - low byte
-
1063  hcibuf[4] = (uint8_t)((hci_handle >> 8) & 0x0F); //connection handle - high byte
-
1064 
-
1065  HCI_Command(hcibuf, 5);
-
1066 }
-
1067 
-
1068 void BTD::hci_disconnect(uint16_t handle) { // This is called by the different services
-
1069  hci_event_flag &= ~HCI_FLAG_DISCONN_COMPLETE;
-
1070  hcibuf[0] = 0x06; // HCI OCF = 6
-
1071  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1072  hcibuf[2] = 0x03; // parameter length = 3
-
1073  hcibuf[3] = (uint8_t)(handle & 0xFF); //connection handle - low byte
-
1074  hcibuf[4] = (uint8_t)((handle >> 8) & 0x0F); //connection handle - high byte
-
1075  hcibuf[5] = 0x13; // reason
-
1076 
-
1077  HCI_Command(hcibuf, 6);
-
1078 }
-
1079 
-
1080 void BTD::hci_write_class_of_device() { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
-
1081  hcibuf[0] = 0x24; // HCI OCF = 3
-
1082  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
1083  hcibuf[2] = 0x03; // parameter length = 3
-
1084  hcibuf[3] = 0x04; // Robot
-
1085  hcibuf[4] = 0x08; // Toy
-
1086  hcibuf[5] = 0x00;
-
1087 
-
1088  HCI_Command(hcibuf, 6);
-
1089 }
-
1090 /*******************************************************************
-
1091  * *
-
1092  * HCI ACL Data Packet *
-
1093  * *
-
1094  * buf[0] buf[1] buf[2] buf[3]
-
1095  * 0 4 8 11 12 16 24 31 MSB
-
1096  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1097  * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet
-
1098  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1099  *
-
1100  * buf[4] buf[5] buf[6] buf[7]
-
1101  * 0 8 16 31 MSB
-
1102  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1103  * | Length | Channel ID | Basic L2CAP header
-
1104  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1105  *
-
1106  * buf[8] buf[9] buf[10] buf[11]
-
1107  * 0 8 16 31 MSB
-
1108  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1109  * | Code | Identifier | Length | Control frame (C-frame)
-
1110  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format)
-
1111  */
-
1112 /************************************************************/
-
1113 /* L2CAP Commands */
-
1114 
-
1115 /************************************************************/
-
1116 void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
-
1117  uint8_t buf[8 + nbytes];
-
1118  buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
-
1119  buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
-
1120  buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
-
1121  buf[3] = (uint8_t)((4 + nbytes) >> 8);
-
1122  buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
-
1123  buf[5] = (uint8_t)(nbytes >> 8);
-
1124  buf[6] = channelLow;
-
1125  buf[7] = channelHigh;
-
1126 
-
1127  for (uint16_t i = 0; i < nbytes; i++) // L2CAP C-frame
-
1128  buf[8 + i] = data[i];
+
1030  HCI_Command(hcibuf, 3);
+
1031 }
+
1032 
+
1033 void BTD::hci_connect() {
+
1034  hci_connect(disc_bdaddr); // Use last discovered device
+
1035 }
+
1036 
+
1037 void BTD::hci_connect(uint8_t *bdaddr) {
+
1038  hci_event_flag &= ~(HCI_FLAG_CONN_COMPLETE | HCI_FLAG_CONNECT_EVENT);
+
1039  hcibuf[0] = 0x05;
+
1040  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1041  hcibuf[2] = 0x0D; // parameter Total Length = 13
+
1042  hcibuf[3] = bdaddr[0]; // 6 octet bdaddr (LSB)
+
1043  hcibuf[4] = bdaddr[1];
+
1044  hcibuf[5] = bdaddr[2];
+
1045  hcibuf[6] = bdaddr[3];
+
1046  hcibuf[7] = bdaddr[4];
+
1047  hcibuf[8] = bdaddr[5];
+
1048  hcibuf[9] = 0x18; // DM1 or DH1 may be used
+
1049  hcibuf[10] = 0xCC; // DM3, DH3, DM5, DH5 may be used
+
1050  hcibuf[11] = 0x01; // Page repetition mode R1
+
1051  hcibuf[12] = 0x00; // Reserved
+
1052  hcibuf[13] = 0x00; // Clock offset
+
1053  hcibuf[14] = 0x00; // Invalid clock offset
+
1054  hcibuf[15] = 0x00; // Do not allow role switch
+
1055 
+
1056  HCI_Command(hcibuf, 16);
+
1057 }
+
1058 
+
1059 void BTD::hci_pin_code_request_reply() {
+
1060  hcibuf[0] = 0x0D; // HCI OCF = 0D
+
1061  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1062  hcibuf[2] = 0x17; // parameter length 23
+
1063  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1064  hcibuf[4] = disc_bdaddr[1];
+
1065  hcibuf[5] = disc_bdaddr[2];
+
1066  hcibuf[6] = disc_bdaddr[3];
+
1067  hcibuf[7] = disc_bdaddr[4];
+
1068  hcibuf[8] = disc_bdaddr[5];
+
1069  if (pairWithWii) {
+
1070  hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
+
1071  if (wiiUProController) {
+
1072 #ifdef DEBUG_USB_HOST
+
1073  Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80);
+
1074 #endif
+
1075  for (uint8_t i = 0; i < 6; i++)
+
1076  hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards
+
1077  } else {
+
1078  for (uint8_t i = 0; i < 6; i++)
+
1079  hcibuf[10 + i] = disc_bdaddr[i]; // The pin is the Wiimote's Bluetooth address backwards
+
1080  }
+
1081  for (uint8_t i = 16; i < 26; i++)
+
1082  hcibuf[i] = 0x00; // The rest should be 0
+
1083  } else {
+
1084  hcibuf[9] = strlen(btdPin); // Length of pin
+
1085  uint8_t i;
+
1086  for (i = 0; i < strlen(btdPin); i++) // The maximum size of the pin is 16
+
1087  hcibuf[i + 10] = btdPin[i];
+
1088  for (; i < 16; i++)
+
1089  hcibuf[i + 10] = 0x00; // The rest should be 0
+
1090  }
+
1091 
+
1092  HCI_Command(hcibuf, 26);
+
1093 }
+
1094 
+
1095 void BTD::hci_pin_code_negative_request_reply() {
+
1096  hcibuf[0] = 0x0E; // HCI OCF = 0E
+
1097  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1098  hcibuf[2] = 0x06; // parameter length 6
+
1099  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1100  hcibuf[4] = disc_bdaddr[1];
+
1101  hcibuf[5] = disc_bdaddr[2];
+
1102  hcibuf[6] = disc_bdaddr[3];
+
1103  hcibuf[7] = disc_bdaddr[4];
+
1104  hcibuf[8] = disc_bdaddr[5];
+
1105 
+
1106  HCI_Command(hcibuf, 9);
+
1107 }
+
1108 
+
1109 void BTD::hci_link_key_request_negative_reply() {
+
1110  hcibuf[0] = 0x0C; // HCI OCF = 0C
+
1111  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1112  hcibuf[2] = 0x06; // parameter length 6
+
1113  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1114  hcibuf[4] = disc_bdaddr[1];
+
1115  hcibuf[5] = disc_bdaddr[2];
+
1116  hcibuf[6] = disc_bdaddr[3];
+
1117  hcibuf[7] = disc_bdaddr[4];
+
1118  hcibuf[8] = disc_bdaddr[5];
+
1119 
+
1120  HCI_Command(hcibuf, 9);
+
1121 }
+
1122 
+
1123 void BTD::hci_authentication_request() {
+
1124  hcibuf[0] = 0x11; // HCI OCF = 11
+
1125  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1126  hcibuf[2] = 0x02; // parameter length = 2
+
1127  hcibuf[3] = (uint8_t)(hci_handle & 0xFF); //connection handle - low byte
+
1128  hcibuf[4] = (uint8_t)((hci_handle >> 8) & 0x0F); //connection handle - high byte
1129 
-
1130  uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf);
-
1131  if (rcode) {
-
1132  delay(100); // This small delay prevents it from overflowing if it fails
-
1133 #ifdef DEBUG_USB_HOST
-
1134  Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
-
1135  D_PrintHex<uint8_t > (rcode, 0x80);
-
1136  Notify(PSTR(" - Channel ID: "), 0x80);
-
1137  D_PrintHex<uint8_t > (channelHigh, 0x80);
-
1138  Notify(PSTR(" "), 0x80);
-
1139  D_PrintHex<uint8_t > (channelLow, 0x80);
-
1140 #endif
-
1141  }
-
1142 }
-
1143 
-
1144 void BTD::l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm) {
-
1145  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_REQUEST; // Code
-
1146  l2capoutbuf[1] = rxid; // Identifier
-
1147  l2capoutbuf[2] = 0x04; // Length
-
1148  l2capoutbuf[3] = 0x00;
-
1149  l2capoutbuf[4] = (uint8_t)(psm & 0xff); // PSM
-
1150  l2capoutbuf[5] = (uint8_t)(psm >> 8);
-
1151  l2capoutbuf[6] = scid[0]; // Source CID
-
1152  l2capoutbuf[7] = scid[1];
-
1153 
-
1154  L2CAP_Command(handle, l2capoutbuf, 8);
-
1155 }
-
1156 
-
1157 void BTD::l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result) {
-
1158  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_RESPONSE; // Code
-
1159  l2capoutbuf[1] = rxid; // Identifier
-
1160  l2capoutbuf[2] = 0x08; // Length
-
1161  l2capoutbuf[3] = 0x00;
-
1162  l2capoutbuf[4] = dcid[0]; // Destination CID
-
1163  l2capoutbuf[5] = dcid[1];
-
1164  l2capoutbuf[6] = scid[0]; // Source CID
-
1165  l2capoutbuf[7] = scid[1];
-
1166  l2capoutbuf[8] = result; // Result: Pending or Success
-
1167  l2capoutbuf[9] = 0x00;
-
1168  l2capoutbuf[10] = 0x00; // No further information
-
1169  l2capoutbuf[11] = 0x00;
-
1170 
-
1171  L2CAP_Command(handle, l2capoutbuf, 12);
-
1172 }
-
1173 
-
1174 void BTD::l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid) {
-
1175  l2capoutbuf[0] = L2CAP_CMD_CONFIG_REQUEST; // Code
-
1176  l2capoutbuf[1] = rxid; // Identifier
-
1177  l2capoutbuf[2] = 0x08; // Length
-
1178  l2capoutbuf[3] = 0x00;
-
1179  l2capoutbuf[4] = dcid[0]; // Destination CID
-
1180  l2capoutbuf[5] = dcid[1];
-
1181  l2capoutbuf[6] = 0x00; // Flags
-
1182  l2capoutbuf[7] = 0x00;
-
1183  l2capoutbuf[8] = 0x01; // Config Opt: type = MTU (Maximum Transmission Unit) - Hint
-
1184  l2capoutbuf[9] = 0x02; // Config Opt: length
-
1185  l2capoutbuf[10] = 0xFF; // MTU
-
1186  l2capoutbuf[11] = 0xFF;
-
1187 
-
1188  L2CAP_Command(handle, l2capoutbuf, 12);
-
1189 }
-
1190 
-
1191 void BTD::l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid) {
-
1192  l2capoutbuf[0] = L2CAP_CMD_CONFIG_RESPONSE; // Code
-
1193  l2capoutbuf[1] = rxid; // Identifier
-
1194  l2capoutbuf[2] = 0x0A; // Length
-
1195  l2capoutbuf[3] = 0x00;
-
1196  l2capoutbuf[4] = scid[0]; // Source CID
-
1197  l2capoutbuf[5] = scid[1];
-
1198  l2capoutbuf[6] = 0x00; // Flag
-
1199  l2capoutbuf[7] = 0x00;
-
1200  l2capoutbuf[8] = 0x00; // Result
-
1201  l2capoutbuf[9] = 0x00;
-
1202  l2capoutbuf[10] = 0x01; // Config
-
1203  l2capoutbuf[11] = 0x02;
-
1204  l2capoutbuf[12] = 0xA0;
-
1205  l2capoutbuf[13] = 0x02;
-
1206 
-
1207  L2CAP_Command(handle, l2capoutbuf, 14);
-
1208 }
-
1209 
-
1210 void BTD::l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
-
1211  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_REQUEST; // Code
-
1212  l2capoutbuf[1] = rxid; // Identifier
-
1213  l2capoutbuf[2] = 0x04; // Length
-
1214  l2capoutbuf[3] = 0x00;
-
1215  l2capoutbuf[4] = dcid[0];
-
1216  l2capoutbuf[5] = dcid[1];
-
1217  l2capoutbuf[6] = scid[0];
-
1218  l2capoutbuf[7] = scid[1];
-
1219 
-
1220  L2CAP_Command(handle, l2capoutbuf, 8);
-
1221 }
-
1222 
-
1223 void BTD::l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
-
1224  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_RESPONSE; // Code
-
1225  l2capoutbuf[1] = rxid; // Identifier
-
1226  l2capoutbuf[2] = 0x04; // Length
-
1227  l2capoutbuf[3] = 0x00;
-
1228  l2capoutbuf[4] = dcid[0];
-
1229  l2capoutbuf[5] = dcid[1];
-
1230  l2capoutbuf[6] = scid[0];
-
1231  l2capoutbuf[7] = scid[1];
-
1232 
-
1233  L2CAP_Command(handle, l2capoutbuf, 8);
-
1234 }
+
1130  HCI_Command(hcibuf, 5);
+
1131 }
+
1132 
+
1133 void BTD::hci_disconnect(uint16_t handle) { // This is called by the different services
+
1134  hci_event_flag &= ~HCI_FLAG_DISCONN_COMPLETE;
+
1135  hcibuf[0] = 0x06; // HCI OCF = 6
+
1136  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1137  hcibuf[2] = 0x03; // parameter length = 3
+
1138  hcibuf[3] = (uint8_t)(handle & 0xFF); //connection handle - low byte
+
1139  hcibuf[4] = (uint8_t)((handle >> 8) & 0x0F); //connection handle - high byte
+
1140  hcibuf[5] = 0x13; // reason
+
1141 
+
1142  HCI_Command(hcibuf, 6);
+
1143 }
+
1144 
+
1145 void BTD::hci_write_class_of_device() { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
+
1146  hcibuf[0] = 0x24; // HCI OCF = 24
+
1147  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
1148  hcibuf[2] = 0x03; // parameter length = 3
+
1149  hcibuf[3] = 0x04; // Robot
+
1150  hcibuf[4] = 0x08; // Toy
+
1151  hcibuf[5] = 0x00;
+
1152 
+
1153  HCI_Command(hcibuf, 6);
+
1154 }
+
1155 /*******************************************************************
+
1156  * *
+
1157  * HCI ACL Data Packet *
+
1158  * *
+
1159  * buf[0] buf[1] buf[2] buf[3]
+
1160  * 0 4 8 11 12 16 24 31 MSB
+
1161  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1162  * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet
+
1163  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1164  *
+
1165  * buf[4] buf[5] buf[6] buf[7]
+
1166  * 0 8 16 31 MSB
+
1167  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1168  * | Length | Channel ID | Basic L2CAP header
+
1169  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1170  *
+
1171  * buf[8] buf[9] buf[10] buf[11]
+
1172  * 0 8 16 31 MSB
+
1173  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1174  * | Code | Identifier | Length | Control frame (C-frame)
+
1175  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format)
+
1176  */
+
1177 /************************************************************/
+
1178 /* L2CAP Commands */
+
1179 
+
1180 /************************************************************/
+
1181 void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
+
1182  uint8_t buf[8 + nbytes];
+
1183  buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
+
1184  buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
+
1185  buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
+
1186  buf[3] = (uint8_t)((4 + nbytes) >> 8);
+
1187  buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
+
1188  buf[5] = (uint8_t)(nbytes >> 8);
+
1189  buf[6] = channelLow;
+
1190  buf[7] = channelHigh;
+
1191 
+
1192  for (uint16_t i = 0; i < nbytes; i++) // L2CAP C-frame
+
1193  buf[8 + i] = data[i];
+
1194 
+
1195  uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf);
+
1196  if (rcode) {
+
1197  delay(100); // This small delay prevents it from overflowing if it fails
+
1198 #ifdef DEBUG_USB_HOST
+
1199  Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
+
1200  D_PrintHex<uint8_t > (rcode, 0x80);
+
1201  Notify(PSTR(" - Channel ID: "), 0x80);
+
1202  D_PrintHex<uint8_t > (channelHigh, 0x80);
+
1203  Notify(PSTR(" "), 0x80);
+
1204  D_PrintHex<uint8_t > (channelLow, 0x80);
+
1205 #endif
+
1206  }
+
1207 }
+
1208 
+
1209 void BTD::l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm) {
+
1210  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_REQUEST; // Code
+
1211  l2capoutbuf[1] = rxid; // Identifier
+
1212  l2capoutbuf[2] = 0x04; // Length
+
1213  l2capoutbuf[3] = 0x00;
+
1214  l2capoutbuf[4] = (uint8_t)(psm & 0xff); // PSM
+
1215  l2capoutbuf[5] = (uint8_t)(psm >> 8);
+
1216  l2capoutbuf[6] = scid[0]; // Source CID
+
1217  l2capoutbuf[7] = scid[1];
+
1218 
+
1219  L2CAP_Command(handle, l2capoutbuf, 8);
+
1220 }
+
1221 
+
1222 void BTD::l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result) {
+
1223  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_RESPONSE; // Code
+
1224  l2capoutbuf[1] = rxid; // Identifier
+
1225  l2capoutbuf[2] = 0x08; // Length
+
1226  l2capoutbuf[3] = 0x00;
+
1227  l2capoutbuf[4] = dcid[0]; // Destination CID
+
1228  l2capoutbuf[5] = dcid[1];
+
1229  l2capoutbuf[6] = scid[0]; // Source CID
+
1230  l2capoutbuf[7] = scid[1];
+
1231  l2capoutbuf[8] = result; // Result: Pending or Success
+
1232  l2capoutbuf[9] = 0x00;
+
1233  l2capoutbuf[10] = 0x00; // No further information
+
1234  l2capoutbuf[11] = 0x00;
1235 
-
1236 void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh) {
-
1237  l2capoutbuf[0] = L2CAP_CMD_INFORMATION_RESPONSE; // Code
-
1238  l2capoutbuf[1] = rxid; // Identifier
-
1239  l2capoutbuf[2] = 0x08; // Length
-
1240  l2capoutbuf[3] = 0x00;
-
1241  l2capoutbuf[4] = infoTypeLow;
-
1242  l2capoutbuf[5] = infoTypeHigh;
-
1243  l2capoutbuf[6] = 0x00; // Result = success
-
1244  l2capoutbuf[7] = 0x00; // Result = success
-
1245  l2capoutbuf[8] = 0x00;
-
1246  l2capoutbuf[9] = 0x00;
-
1247  l2capoutbuf[10] = 0x00;
-
1248  l2capoutbuf[11] = 0x00;
-
1249 
-
1250  L2CAP_Command(handle, l2capoutbuf, 12);
-
1251 }
+
1236  L2CAP_Command(handle, l2capoutbuf, 12);
+
1237 }
+
1238 
+
1239 void BTD::l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid) {
+
1240  l2capoutbuf[0] = L2CAP_CMD_CONFIG_REQUEST; // Code
+
1241  l2capoutbuf[1] = rxid; // Identifier
+
1242  l2capoutbuf[2] = 0x08; // Length
+
1243  l2capoutbuf[3] = 0x00;
+
1244  l2capoutbuf[4] = dcid[0]; // Destination CID
+
1245  l2capoutbuf[5] = dcid[1];
+
1246  l2capoutbuf[6] = 0x00; // Flags
+
1247  l2capoutbuf[7] = 0x00;
+
1248  l2capoutbuf[8] = 0x01; // Config Opt: type = MTU (Maximum Transmission Unit) - Hint
+
1249  l2capoutbuf[9] = 0x02; // Config Opt: length
+
1250  l2capoutbuf[10] = 0xFF; // MTU
+
1251  l2capoutbuf[11] = 0xFF;
1252 
-
1253 /* PS3 Commands - only set Bluetooth address is implemented in this library */
-
1254 void BTD::setBdaddr(uint8_t* bdaddr) {
-
1255  /* Set the internal Bluetooth address */
-
1256  uint8_t buf[8];
-
1257  buf[0] = 0x01;
-
1258  buf[1] = 0x00;
-
1259 
-
1260  for (uint8_t i = 0; i < 6; i++)
-
1261  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed
-
1262 
-
1263  // 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)
-
1264  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
-
1265 }
-
1266 
-
1267 void BTD::setMoveBdaddr(uint8_t* bdaddr) {
-
1268  /* Set the internal Bluetooth address */
-
1269  uint8_t buf[11];
-
1270  buf[0] = 0x05;
-
1271  buf[7] = 0x10;
-
1272  buf[8] = 0x01;
-
1273  buf[9] = 0x02;
-
1274  buf[10] = 0x12;
-
1275 
-
1276  for (uint8_t i = 0; i < 6; i++)
-
1277  buf[i + 1] = bdaddr[i];
-
1278 
-
1279  // 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)
-
1280  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
-
1281 }
-
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:457
-
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:761
-
bool incomingWii
Definition: BTD.h:419
+
1253  L2CAP_Command(handle, l2capoutbuf, 12);
+
1254 }
+
1255 
+
1256 void BTD::l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid) {
+
1257  l2capoutbuf[0] = L2CAP_CMD_CONFIG_RESPONSE; // Code
+
1258  l2capoutbuf[1] = rxid; // Identifier
+
1259  l2capoutbuf[2] = 0x0A; // Length
+
1260  l2capoutbuf[3] = 0x00;
+
1261  l2capoutbuf[4] = scid[0]; // Source CID
+
1262  l2capoutbuf[5] = scid[1];
+
1263  l2capoutbuf[6] = 0x00; // Flag
+
1264  l2capoutbuf[7] = 0x00;
+
1265  l2capoutbuf[8] = 0x00; // Result
+
1266  l2capoutbuf[9] = 0x00;
+
1267  l2capoutbuf[10] = 0x01; // Config
+
1268  l2capoutbuf[11] = 0x02;
+
1269  l2capoutbuf[12] = 0xA0;
+
1270  l2capoutbuf[13] = 0x02;
+
1271 
+
1272  L2CAP_Command(handle, l2capoutbuf, 14);
+
1273 }
+
1274 
+
1275 void BTD::l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
+
1276  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_REQUEST; // Code
+
1277  l2capoutbuf[1] = rxid; // Identifier
+
1278  l2capoutbuf[2] = 0x04; // Length
+
1279  l2capoutbuf[3] = 0x00;
+
1280  l2capoutbuf[4] = dcid[0];
+
1281  l2capoutbuf[5] = dcid[1];
+
1282  l2capoutbuf[6] = scid[0];
+
1283  l2capoutbuf[7] = scid[1];
+
1284 
+
1285  L2CAP_Command(handle, l2capoutbuf, 8);
+
1286 }
+
1287 
+
1288 void BTD::l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
+
1289  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_RESPONSE; // Code
+
1290  l2capoutbuf[1] = rxid; // Identifier
+
1291  l2capoutbuf[2] = 0x04; // Length
+
1292  l2capoutbuf[3] = 0x00;
+
1293  l2capoutbuf[4] = dcid[0];
+
1294  l2capoutbuf[5] = dcid[1];
+
1295  l2capoutbuf[6] = scid[0];
+
1296  l2capoutbuf[7] = scid[1];
+
1297 
+
1298  L2CAP_Command(handle, l2capoutbuf, 8);
+
1299 }
+
1300 
+
1301 void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh) {
+
1302  l2capoutbuf[0] = L2CAP_CMD_INFORMATION_RESPONSE; // Code
+
1303  l2capoutbuf[1] = rxid; // Identifier
+
1304  l2capoutbuf[2] = 0x08; // Length
+
1305  l2capoutbuf[3] = 0x00;
+
1306  l2capoutbuf[4] = infoTypeLow;
+
1307  l2capoutbuf[5] = infoTypeHigh;
+
1308  l2capoutbuf[6] = 0x00; // Result = success
+
1309  l2capoutbuf[7] = 0x00; // Result = success
+
1310  l2capoutbuf[8] = 0x00;
+
1311  l2capoutbuf[9] = 0x00;
+
1312  l2capoutbuf[10] = 0x00;
+
1313  l2capoutbuf[11] = 0x00;
+
1314 
+
1315  L2CAP_Command(handle, l2capoutbuf, 12);
+
1316 }
+
1317 
+
1318 /* PS3 Commands - only set Bluetooth address is implemented in this library */
+
1319 void BTD::setBdaddr(uint8_t* bdaddr) {
+
1320  /* Set the internal Bluetooth address */
+
1321  uint8_t buf[8];
+
1322  buf[0] = 0x01;
+
1323  buf[1] = 0x00;
+
1324 
+
1325  for (uint8_t i = 0; i < 6; i++)
+
1326  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
+
1327 
+
1328  // 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
+
1329  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
+
1330 }
+
1331 
+
1332 void BTD::setMoveBdaddr(uint8_t* bdaddr) {
+
1333  /* Set the internal Bluetooth address */
+
1334  uint8_t buf[11];
+
1335  buf[0] = 0x05;
+
1336  buf[7] = 0x10;
+
1337  buf[8] = 0x01;
+
1338  buf[9] = 0x02;
+
1339  buf[10] = 0x12;
+
1340 
+
1341  for (uint8_t i = 0; i < 6; i++)
+
1342  buf[i + 1] = bdaddr[i];
+
1343 
+
1344  // 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
+
1345  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
+
1346 }
+
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:482
+
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:764
+
bool incomingWii
Definition: BTD.h:432
Definition: address.h:83
-
void hci_connect()
Definition: BTD.cpp:972
-
uint8_t bNumEP
Definition: BTD.h:446
+
void hci_connect()
Definition: BTD.cpp:1033
+
uint8_t bNumEP
Definition: BTD.h:471
EpInfo * epinfo
Definition: address.h:76
-
const char * btdName
Definition: BTD.h:392
-
void hci_reset()
Definition: BTD.cpp:856
-
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1157
+
const char * btdName
Definition: BTD.h:405
+
void hci_reset()
Definition: BTD.cpp:917
+
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1222
#define HCI_SCANNING_STATE
Definition: BTD.h:54
bool lowspeed
Definition: address.h:79
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
-
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1144
+
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1209
#define EV_COMMAND_STATUS
Definition: BTD.h:104
-
#define hci_wii_found
Definition: BTD.h:81
#define EV_REMOTE_NAME_COMPLETE
Definition: BTD.h:91
uint8_t bmNakPower
Definition: address.h:42
-
bool sdpConnectionClaimed
Definition: BTD.h:387
-
#define HCI_CHECK_WII_SERVICE
Definition: BTD.h:48
+
bool sdpConnectionClaimed
Definition: BTD.h:400
#define bmREQ_HCI_OUT
Definition: BTD.h:36
-
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1210
+
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1275
Definition: address.h:75
-
bool rfcommConnectionClaimed
Definition: BTD.h:389
-
uint8_t hci_version
Definition: BTD.h:409
+
bool rfcommConnectionClaimed
Definition: BTD.h:402
+
uint8_t hci_version
Definition: BTD.h:422
#define EV_INQUIRY_COMPLETE
Definition: BTD.h:85
#define hci_read_bdaddr_complete
Definition: BTD.h:79
-
void hci_inquiry()
Definition: BTD.cpp:950
-
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:453
-
#define HCI_CONNECTED_WII_STATE
Definition: BTD.h:52
+
void hci_inquiry()
Definition: BTD.cpp:1011
+
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:478
#define PS3MOVE_PID
Definition: BTD.h:27
Definition: usb_ch9.h:141
uint8_t bInterval
Definition: usb_ch9.h:147
-
bool pairWithWii
Definition: BTD.h:421
+
bool pairWithWii
Definition: BTD.h:434
uint8_t bLength
Definition: usb_ch9.h:142
-
void hci_write_scan_disable()
Definition: BTD.cpp:878
+
void hci_write_scan_disable()
Definition: BTD.cpp:939
#define NotifyFail(...)
Definition: message.h:55
#define HCI_SET_NAME_STATE
Definition: BTD.h:47
-
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 void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: BTD.cpp:318
#define HCI_FLAG_CONN_COMPLETE
Definition: BTD.h:64
#define EV_LINK_KEY_REQUEST
Definition: BTD.h:97
#define HCI_DONE_STATE
Definition: BTD.h:59
#define hci_incoming_connect_request
Definition: BTD.h:78
#define EV_DATA_BUFFER_OVERFLOW
Definition: BTD.h:99
#define HCI_DISCONNECT_STATE
Definition: BTD.h:60
+
#define hci_device_found
Definition: BTD.h:81
#define EV_PIN_CODE_REQUEST
Definition: BTD.h:96
-
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:795
-
const char * btdPin
Definition: BTD.h:394
-
bool motionPlusInside
Definition: BTD.h:423
+
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
+
const char * btdPin
Definition: BTD.h:407
+
bool motionPlusInside
Definition: BTD.h:436
#define EV_AUTHENTICATION_COMPLETE
Definition: BTD.h:90
-
void hci_remote_name()
Definition: BTD.cpp:919
-
uint8_t remote_name[30]
Definition: BTD.h:403
+
void hci_remote_name()
Definition: BTD.cpp:980
+
uint8_t remote_name[30]
Definition: BTD.h:416
#define HCI_FLAG_DISCONN_COMPLETE
Definition: BTD.h:65
#define HCI_FLAG_CONNECT_EVENT
Definition: BTD.h:71
#define HCI_REMOTE_NAME_STATE
Definition: BTD.h:56
@@ -1434,53 +1497,56 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
virtual void Reset()
#define EV_MAX_SLOTS_CHANGE
Definition: BTD.h:100
-
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:455
-
void hci_set_local_name(const char *name)
Definition: BTD.cpp:938
+
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:480
+
void hci_set_local_name(const char *name)
Definition: BTD.cpp:999
#define EV_QOS_SETUP_COMPLETE
Definition: BTD.h:102
-
void hci_write_scan_enable()
Definition: BTD.cpp:865
-
virtual uint8_t Release()
Definition: BTD.cpp:365
+
void hci_write_scan_enable()
Definition: BTD.cpp:926
+
virtual uint8_t Release()
Definition: BTD.cpp:369
virtual void FreeAddress(uint8_t addr)=0
uint8_t epAttribs
Definition: address.h:37
-
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1223
+
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1288
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
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
-
bool watingForConnection
Definition: BTD.h:383
+
bool watingForConnection
Definition: BTD.h:396
#define HCI_BDADDR_STATE
Definition: BTD.h:45
+
#define HCI_CONNECT_DEVICE_STATE
Definition: BTD.h:51
#define Notify(...)
Definition: message.h:44
+
bool connectToHIDDevice
Definition: BTD.h:444
uint8_t bmAttributes
Definition: usb_ch9.h:145
-
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:790
-
uint8_t bAddress
Definition: BTD.h:439
+
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
uint8_t bAddress
Definition: BTD.h:464
#define NotifyFailGetConfDescr(...)
Definition: message.h:52
uint8_t epAddr
Definition: address.h:33
+
bool incomingHIDDevice
Definition: BTD.h:448
#define NotifyFailUnknownDevice(...)
Definition: message.h:54
+
bool pairWithHIDDevice
Definition: BTD.h:450
#define hci_remote_name_complete
Definition: BTD.h:77
-
uint32_t qNextPollTime
Definition: BTD.h:448
+
uint32_t qNextPollTime
Definition: BTD.h:473
#define USB_NAK_MAX_POWER
Definition: address.h:27
#define EV_CONNECT_COMPLETE
Definition: BTD.h:87
-
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:346
+
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:350
#define EV_DISCONNECT_COMPLETE
Definition: BTD.h:89
#define HCI_FLAG_READ_BDADDR
Definition: BTD.h:68
#define hci_read_version_complete
Definition: BTD.h:80
#define IOGEAR_GBU521_PID
Definition: BTD.h:30
-
bool connectToWii
Definition: BTD.h:415
-
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:46
+
bool connectToWii
Definition: BTD.h:428
+
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:48
#define HCI_LOCAL_VERSION_STATE
Definition: BTD.h:46
-
#define HCI_CONNECT_WII_STATE
Definition: BTD.h:51
-
bool wiiUProController
Definition: BTD.h:425
-
uint16_t hci_handle
Definition: BTD.h:399
-
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:119
+
bool wiiUProController
Definition: BTD.h:438
+
uint16_t hci_handle
Definition: BTD.h:412
+
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:121
#define Notifyc(...)
Definition: message.h:46
Definition: address.h:32
-
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1068
+
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1133
#define HCI_RESET_STATE
Definition: BTD.h:43
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
#define hrNAK
Definition: max3421e.h:216
-
void hci_read_bdaddr()
Definition: BTD.cpp:887
-
void hci_inquiry_cancel()
Definition: BTD.cpp:964
+
void hci_read_bdaddr()
Definition: BTD.cpp:948
+
void hci_inquiry_cancel()
Definition: BTD.cpp:1025
#define L2CAP_CMD_INFORMATION_RESPONSE
Definition: BTD.h:117
uint16_t wMaxPacketSize
Definition: usb_ch9.h:146
-
uint8_t my_bdaddr[6]
Definition: BTD.h:397
+
uint8_t my_bdaddr[6]
Definition: BTD.h:410
#define HID_REQUEST_SET_REPORT
Definition: BTD.h:39
#define EV_INCOMING_CONNECT
Definition: BTD.h:88
#define HCI_CONNECT_IN_STATE
Definition: BTD.h:55
@@ -1491,20 +1557,20 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
#define EV_INQUIRY_RESULT
Definition: BTD.h:86
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:112
-
virtual uint8_t Poll()
Definition: BTD.cpp:371
+
virtual uint8_t Poll()
Definition: BTD.cpp:375
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:114
-
static const uint8_t BTD_CONTROL_PIPE
Definition: BTD.h:451
+
static const uint8_t BTD_CONTROL_PIPE
Definition: BTD.h:476
uint8_t bDescriptorType
Definition: usb_ch9.h:143
#define hci_cmd_complete
Definition: BTD.h:74
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
#define HCI_FLAG_READ_VERSION
Definition: BTD.h:69
-
uint8_t disc_bdaddr[6]
Definition: BTD.h:401
-
bool l2capConnectionClaimed
Definition: BTD.h:385
+
uint8_t disc_bdaddr[6]
Definition: BTD.h:414
+
bool l2capConnectionClaimed
Definition: BTD.h:398
#define USB_NAK_NOWAIT
Definition: address.h:29
#define HCI_FLAG_INCOMING_REQUEST
Definition: BTD.h:67
#define EV_NUM_COMPLETE_PKT
Definition: BTD.h:95
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
-
EpInfo epInfo[BTD_MAX_ENDPOINTS]
Definition: BTD.h:441
+
EpInfo epInfo[BTD_MAX_ENDPOINTS]
Definition: BTD.h:466
#define IOGEAR_GBU521_VID
Definition: BTD.h:29
virtual void ACLData(uint8_t *ACLData)
#define PS3_PID
Definition: BTD.h:25
@@ -1516,49 +1582,51 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
#define EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE
Definition: BTD.h:101
#define EV_COMMAND_COMPLETE
Definition: BTD.h:103
#define hci_connect_event
Definition: BTD.h:82
-
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1236
+
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1301
#define L2CAP_CMD_CONNECTION_RESPONSE
Definition: BTD.h:111
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:113
-
void hci_write_class_of_device()
Definition: BTD.cpp:1080
+
void hci_write_class_of_device()
Definition: BTD.cpp:1145
+
#define HCI_CONNECTED_DEVICE_STATE
Definition: BTD.h:52
#define HCI_INIT_STATE
Definition: BTD.h:42
#define bmREQ_HID_OUT
Definition: BTD.h:38
-
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1030
+
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1095
#define EV_CHANGE_CONNECTION_LINK
Definition: BTD.h:93
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
#define EV_ROLE_CHANGED
Definition: BTD.h:94
uint8_t maxPktSize
Definition: address.h:34
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
+
#define HCI_CHECK_DEVICE_SERVICE
Definition: BTD.h:48
Definition: UsbCore.h:152
virtual void Run()
-
uint8_t bConfNum
Definition: BTD.h:444
-
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1044
+
uint8_t bConfNum
Definition: BTD.h:469
+
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1109
#define hci_connect_complete
Definition: BTD.h:75
#define EV_LOOPBACK_COMMAND
Definition: BTD.h:105
-
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1116
+
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1181
#define BTD_NUMSERVICES
Definition: BTD.h:134
#define EV_LINK_KEY_NOTIFICATION
Definition: BTD.h:98
-
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1191
-
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1174
-
void hci_pin_code_request_reply()
Definition: BTD.cpp:994
+
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1256
+
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1239
+
void hci_pin_code_request_reply()
Definition: BTD.cpp:1059
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:110
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
#define EV_ENCRYPTION_CHANGE
Definition: BTD.h:92
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
-
USB * pUsb
Definition: BTD.h:433
+
USB * pUsb
Definition: BTD.h:458
#define NotifyStr(...)
Definition: message.h:45
-
void hci_authentication_request()
Definition: BTD.cpp:1058
-
#define HCI_FLAG_WII_FOUND
Definition: BTD.h:70
-
void hci_read_local_version_information()
Definition: BTD.cpp:895
+
void hci_authentication_request()
Definition: BTD.cpp:1123
+
void hci_read_local_version_information()
Definition: BTD.cpp:956
#define HCI_FLAG_REMOTE_NAME_COMPLETE
Definition: BTD.h:66
-
void hci_accept_connection()
Definition: BTD.cpp:903
+
void hci_accept_connection()
Definition: BTD.cpp:964
#define EV_PAGE_SCAN_REP_MODE
Definition: BTD.h:106
#define hci_disconnect_complete
Definition: BTD.h:76
+
#define HCI_FLAG_DEVICE_FOUND
Definition: BTD.h:70
#define HCI_CLASS_STATE
Definition: BTD.h:44
-
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:756
+
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
Definition: UsbCore.h:72
-
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:851
+
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:912
Definition: usb_ch9.h:98
diff --git a/_b_t_d_8h.html b/_b_t_d_8h.html index 1e9f6bff..a3726579 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.

@@ -151,14 +151,14 @@ Macros   #define HCI_SET_NAME_STATE   5   -#define HCI_CHECK_WII_SERVICE   6 -  +#define HCI_CHECK_DEVICE_SERVICE   6 +  #define HCI_INQUIRY_STATE   7   -#define HCI_CONNECT_WII_STATE   8 -  -#define HCI_CONNECTED_WII_STATE   9 -  +#define HCI_CONNECT_DEVICE_STATE   8 +  +#define HCI_CONNECTED_DEVICE_STATE   9 +  #define HCI_SCANNING_STATE   10   #define HCI_CONNECT_IN_STATE   11 @@ -187,8 +187,8 @@ Macros   #define HCI_FLAG_READ_VERSION   0x40   -#define HCI_FLAG_WII_FOUND   0x80 -  +#define HCI_FLAG_DEVICE_FOUND   0x80 +  #define HCI_FLAG_CONNECT_EVENT   0x100   #define hci_cmd_complete   (hci_event_flag & HCI_FLAG_CMD_COMPLETE) @@ -205,8 +205,8 @@ Macros   #define hci_read_version_complete   (hci_event_flag & HCI_FLAG_READ_VERSION)   -#define hci_wii_found   (hci_event_flag & HCI_FLAG_WII_FOUND) -  +#define hci_device_found   (hci_event_flag & HCI_FLAG_DEVICE_FOUND) +  #define hci_connect_event   (hci_event_flag & HCI_FLAG_CONNECT_EVENT)   #define EV_INQUIRY_COMPLETE   0x01 @@ -291,6 +291,8 @@ Macros   #define BTD_NUMSERVICES   4   +#define PAIR   1 + 

Macro Definition Documentation

@@ -517,12 +519,12 @@ Macros - +
- +
#define HCI_CHECK_WII_SERVICE   6#define HCI_CHECK_DEVICE_SERVICE   6
@@ -545,12 +547,12 @@ Macros
- +
- +
#define HCI_CONNECT_WII_STATE   8#define HCI_CONNECT_DEVICE_STATE   8
@@ -559,12 +561,12 @@ Macros
- +
- +
#define HCI_CONNECTED_WII_STATE   9#define HCI_CONNECTED_DEVICE_STATE   9
@@ -769,12 +771,12 @@ Macros
- +
- +
#define HCI_FLAG_WII_FOUND   0x80#define HCI_FLAG_DEVICE_FOUND   0x80
@@ -895,12 +897,12 @@ Macros
- +
- +
#define hci_wii_found   (hci_event_flag & HCI_FLAG_WII_FOUND)#define hci_device_found   (hci_event_flag & HCI_FLAG_DEVICE_FOUND)
@@ -1495,6 +1497,20 @@ Macros

Definition at line 134 of file BTD.h.

+
+
+ +
+
+ + + + +
#define PAIR   1
+
+ +

Definition at line 136 of file BTD.h.

+
diff --git a/_b_t_d_8h__dep__incl.map b/_b_t_d_8h__dep__incl.map index 826104fd..4800756d 100644 --- a/_b_t_d_8h__dep__incl.map +++ b/_b_t_d_8h__dep__incl.map @@ -1,9 +1,11 @@ - - - - - - + + + + + + + + diff --git a/_b_t_d_8h__dep__incl.md5 b/_b_t_d_8h__dep__incl.md5 index f4584293..9aa56dc0 100644 --- a/_b_t_d_8h__dep__incl.md5 +++ b/_b_t_d_8h__dep__incl.md5 @@ -1 +1 @@ -5aff5061ed5b75641b5314699a5d7713 \ No newline at end of file +733ffa9984cd5bf95cd4137ba4b743af \ 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 fc29c166a08fb3a60ca658a393b8c082e6e004cc..816ed24085899d43e12f379304cc20a998adc7e8 100644 GIT binary patch literal 17011 zcmZX+Wmp|c*9C~Xy9Sp8cY?cXfP=fcdkF3pf&>We?(XjH?!kh)1eoUD`+mbtq3Z+#69SVK6IS&A zKh=dz!|I=@q*!wdkerbEPODjiCnP2;1pjF}oOJ&N>SnuFQA|k=4~*gy0<|g>x)M~v z!_ei>4=QuY!ri6H*WlWdGuz~LWUgB6m*@3UImJQWTRB&Cbu}7p?(Z<-LO=y9aNq-u zz~4srUrs_y6xA3(f=s+%zWzN}=}S`;YHmkBGS<{ZsP&B1KFn z#e&*@*5-c=2%!YOHy$9mb+O$$SE|m$<9?>&fNz`1^YLSN2r{7rGy+zYC2HMrgwP(E zloIC8A^%dUL28KWgUP}_m7N&`99Cim%+*B9${I}$WaGcMVhOnHh(>kiJ3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wN&Z)*+Hj+Am&(o=t@8%&q8T}Hh#Wn(7@qWPq6`>6%AE9@;lG@f|=>}BPcLr7WmS=$O`{$|6tz&#J%_j z+HUU)8+FHj#iobm7Fq*BDj5eeU@=14Fm#q2`{LKM8r*cv<$yU<_JPwUJ=^d*7lOtr zwL`73^6&XQZ3Qs%0wcT}67_^%3w^ zfTBiJGX-(@^GiM&8pgV!&ZlbpajK%!Kb`%8RfM;)Gg3P*pc@K3TmXtP2*?m3B74mh z!h}QgO<-^`k09?lM%PFuZTQE{{Cq_Ids70i{r|6dB8AB7tN~vGUX@wDG_@3Rii0Kr zt1q@ec_ry~ERCUu=pHch(^Om^xNu;s8Y46*eiu)v<5Pk_@Q-AuAZmBsgig`QEA#=Y znZxfZMqw!#T>KOnNn6u_c`X8_d8)Wfb)HUDgR;2UH;S8KR%in8sk>L&OmEZ_DaPV| z; k!n;?f`?oA!&?}#OpgqFK=dC{AwKFgYksrcUf_i@c2YO2$qyPW_ diff --git a/_b_t_d_8h_source.html b/_b_t_d_8h_source.html index 044b5825..325ef5f2 100644 --- a/_b_t_d_8h_source.html +++ b/_b_t_d_8h_source.html @@ -130,25 +130,25 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
39 #define HID_REQUEST_SET_REPORT 0x09
40 
41 /* Bluetooth HCI states for hci_task() */
-
42 #define HCI_INIT_STATE 0
-
43 #define HCI_RESET_STATE 1
-
44 #define HCI_CLASS_STATE 2
-
45 #define HCI_BDADDR_STATE 3
-
46 #define HCI_LOCAL_VERSION_STATE 4
-
47 #define HCI_SET_NAME_STATE 5
-
48 #define HCI_CHECK_WII_SERVICE 6
+
42 #define HCI_INIT_STATE 0
+
43 #define HCI_RESET_STATE 1
+
44 #define HCI_CLASS_STATE 2
+
45 #define HCI_BDADDR_STATE 3
+
46 #define HCI_LOCAL_VERSION_STATE 4
+
47 #define HCI_SET_NAME_STATE 5
+
48 #define HCI_CHECK_DEVICE_SERVICE 6
49 
-
50 #define HCI_INQUIRY_STATE 7 // These three states are only used if it should pair and connect to a Wii controller
-
51 #define HCI_CONNECT_WII_STATE 8
-
52 #define HCI_CONNECTED_WII_STATE 9
+
50 #define HCI_INQUIRY_STATE 7 // These three states are only used if it should pair and connect to a Wii controller
+
51 #define HCI_CONNECT_DEVICE_STATE 8
+
52 #define HCI_CONNECTED_DEVICE_STATE 9
53 
-
54 #define HCI_SCANNING_STATE 10
-
55 #define HCI_CONNECT_IN_STATE 11
-
56 #define HCI_REMOTE_NAME_STATE 12
-
57 #define HCI_CONNECTED_STATE 13
-
58 #define HCI_DISABLE_SCAN_STATE 14
-
59 #define HCI_DONE_STATE 15
-
60 #define HCI_DISCONNECT_STATE 16
+
54 #define HCI_SCANNING_STATE 10
+
55 #define HCI_CONNECT_IN_STATE 11
+
56 #define HCI_REMOTE_NAME_STATE 12
+
57 #define HCI_CONNECTED_STATE 13
+
58 #define HCI_DISABLE_SCAN_STATE 14
+
59 #define HCI_DONE_STATE 15
+
60 #define HCI_DISCONNECT_STATE 16
61 
62 /* HCI event flags*/
63 #define HCI_FLAG_CMD_COMPLETE 0x01
@@ -158,7 +158,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
67 #define HCI_FLAG_INCOMING_REQUEST 0x10
68 #define HCI_FLAG_READ_BDADDR 0x20
69 #define HCI_FLAG_READ_VERSION 0x40
-
70 #define HCI_FLAG_WII_FOUND 0x80
+
70 #define HCI_FLAG_DEVICE_FOUND 0x80
71 #define HCI_FLAG_CONNECT_EVENT 0x100
72 
73 /*Macros for HCI event flag tests */
@@ -169,7 +169,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
78 #define hci_incoming_connect_request (hci_event_flag & HCI_FLAG_INCOMING_REQUEST)
79 #define hci_read_bdaddr_complete (hci_event_flag & HCI_FLAG_READ_BDADDR)
80 #define hci_read_version_complete (hci_event_flag & HCI_FLAG_READ_VERSION)
-
81 #define hci_wii_found (hci_event_flag & HCI_FLAG_WII_FOUND)
+
81 #define hci_device_found (hci_event_flag & HCI_FLAG_DEVICE_FOUND)
82 #define hci_connect_event (hci_event_flag & HCI_FLAG_CONNECT_EVENT)
83 
84 /* HCI Events managed */
@@ -224,242 +224,263 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
133 #define BTD_MAX_ENDPOINTS 4
134 #define BTD_NUMSERVICES 4 // Max number of Bluetooth services - if you need more than four simply increase this number
135 
- -
138 public:
-
143  virtual void ACLData(uint8_t* ACLData);
-
145  virtual void Run();
-
147  virtual void Reset();
-
149  virtual void disconnect();
-
150 };
-
151 
-
156 class BTD : public USBDeviceConfig, public UsbConfigXtracter {
-
157 public:
-
162  BTD(USB *p);
-
163 
-
172  virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed);
-
180  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
-
185  virtual uint8_t Release();
-
190  virtual uint8_t Poll();
-
191 
-
196  virtual uint8_t GetAddress() {
-
197  return bAddress;
-
198  };
-
199 
-
204  virtual bool isReady() {
-
205  return bPollEnable;
-
206  };
-
212  virtual boolean DEVCLASSOK(uint8_t klass) { return (klass == USB_CLASS_WIRELESS_CTRL); }
-
213 
-
221  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
-
222  return ((vid == PS3_VID || vid == IOGEAR_GBU521_VID) && (pid == PS3_PID || pid == PS3NAVIGATION_PID || pid == PS3MOVE_PID || pid == IOGEAR_GBU521_PID));
-
223  };
-
235  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
-
239  void disconnect() {
-
240  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
-
241  if(btService[i])
-
242  btService[i]->disconnect();
-
243  };
-
244 
- -
251  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
-
252  if(!btService[i]) {
-
253  btService[i] = pService;
-
254  return i; // Return ID
-
255  }
-
256  }
-
257  return -1; // ErrorregisterServiceClass
-
258  };
-
259 
-
266  void HCI_Command(uint8_t* data, uint16_t nbytes);
-
268  void hci_reset();
-
270  void hci_read_bdaddr();
- -
277  void hci_set_local_name(const char* name);
-
279  void hci_write_scan_enable();
-
281  void hci_write_scan_disable();
-
283  void hci_remote_name();
-
285  void hci_accept_connection();
-
290  void hci_disconnect(uint16_t handle);
- - - - -
307  void hci_inquiry();
-
309  void hci_inquiry_cancel();
-
311  void hci_connect();
- -
325  void L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow = 0x01, uint8_t channelHigh = 0x00);
-
333  void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm);
-
342  void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result);
-
349  void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid);
-
356  void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid);
-
364  void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid);
-
372  void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid);
-
379  void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh);
- - - - -
390 
-
392  const char* btdName;
-
394  const char* btdPin;
-
395 
-
397  uint8_t my_bdaddr[6];
-
399  uint16_t hci_handle;
-
401  uint8_t disc_bdaddr[6];
-
403  uint8_t remote_name[30];
-
409  uint8_t hci_version;
-
410 
- -
413  pairWithWii = true;
-
414  hci_state = HCI_CHECK_WII_SERVICE;
-
415  };
-
417  bool connectToWii;
- - - - -
426 
-
431  uint8_t readPollInterval() {
-
432  return pollInterval;
-
433  };
-
434 
-
435 protected:
-
437  USB *pUsb;
-
439  uint8_t bAddress;
- -
442 
-
444  uint8_t bConfNum;
-
446  uint8_t bNumEP;
-
448  uint32_t qNextPollTime;
-
449 
-
451  static const uint8_t BTD_CONTROL_PIPE;
-
453  static const uint8_t BTD_EVENT_PIPE;
-
455  static const uint8_t BTD_DATAIN_PIPE;
-
457  static const uint8_t BTD_DATAOUT_PIPE;
-
458 
- -
464 
-
465 private:
-
466  void clearAllVariables(); // Set all variables, endpoint structs etc. to default values
-
467  BluetoothService* btService[BTD_NUMSERVICES];
-
468 
-
469  uint16_t PID, VID; // PID and VID of device connected
-
470 
-
471  bool bPollEnable;
-
472  uint8_t pollInterval;
-
473 
-
474  /* Variables used by high level HCI task */
-
475  uint8_t hci_state; //current state of bluetooth hci connection
-
476  uint16_t hci_counter; // counter used for bluetooth hci reset loops
-
477  uint8_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset
-
478  uint16_t hci_event_flag; // hci flags of received bluetooth events
-
479  uint8_t inquiry_counter;
-
480 
-
481  uint8_t hcibuf[BULK_MAXPKTSIZE]; //General purpose buffer for hci data
-
482  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; //General purpose buffer for l2cap in data
-
483  uint8_t l2capoutbuf[14]; //General purpose buffer for l2cap out data
-
484 
-
485  /* State machines */
-
486  void HCI_event_task(); // Poll the HCI event pipe
-
487  void HCI_task(); // HCI state machine
-
488  void ACL_event_task(); // ACL input pipe
+
136 #define PAIR 1
+
137 
+ +
140 public:
+
145  virtual void ACLData(uint8_t* ACLData);
+
147  virtual void Run();
+
149  virtual void Reset();
+
151  virtual void disconnect();
+
152 };
+
153 
+
158 class BTD : public USBDeviceConfig, public UsbConfigXtracter {
+
159 public:
+
164  BTD(USB *p);
+
165 
+
174  virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed);
+
182  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
+
187  virtual uint8_t Release();
+
192  virtual uint8_t Poll();
+
193 
+
198  virtual uint8_t GetAddress() {
+
199  return bAddress;
+
200  };
+
201 
+
206  virtual bool isReady() {
+
207  return bPollEnable;
+
208  };
+
214  virtual boolean DEVCLASSOK(uint8_t klass) { return (klass == USB_CLASS_WIRELESS_CTRL); }
+
215 
+
223  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
+
224  if (vid == IOGEAR_GBU521_VID && pid == IOGEAR_GBU521_PID)
+
225  return true;
+
226  if (my_bdaddr[0] != 0x00 || my_bdaddr[1] != 0x00 || my_bdaddr[2] != 0x00 || my_bdaddr[3] != 0x00 || my_bdaddr[4] != 0x00 || my_bdaddr[5] != 0x00) { // Check if Bluetooth address is set
+
227  if (vid == PS3_VID && (pid == PS3_PID || pid == PS3NAVIGATION_PID || pid == PS3MOVE_PID))
+
228  return true;
+
229  }
+
230  return false;
+
231  };
+
243  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
+
247  void disconnect() {
+
248  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
+
249  if(btService[i])
+
250  btService[i]->disconnect();
+
251  };
+
252 
+ +
259  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
+
260  if(!btService[i]) {
+
261  btService[i] = pService;
+
262  return i; // Return ID
+
263  }
+
264  }
+
265  return -1; // ErrorregisterServiceClass
+
266  };
+
267 
+
274  void HCI_Command(uint8_t* data, uint16_t nbytes);
+
276  void hci_reset();
+
278  void hci_read_bdaddr();
+ +
285  void hci_set_local_name(const char* name);
+
287  void hci_write_scan_enable();
+
289  void hci_write_scan_disable();
+
291  void hci_remote_name();
+
293  void hci_accept_connection();
+
298  void hci_disconnect(uint16_t handle);
+ + + + +
315  void hci_inquiry();
+
317  void hci_inquiry_cancel();
+
319  void hci_connect();
+
324  void hci_connect(uint8_t *bdaddr);
+ +
338  void L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow = 0x01, uint8_t channelHigh = 0x00);
+
346  void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm);
+
355  void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result);
+
362  void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid);
+
369  void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid);
+
377  void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid);
+
385  void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid);
+
392  void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh);
+ + + + +
403 
+
405  const char* btdName;
+
407  const char* btdPin;
+
408 
+
410  uint8_t my_bdaddr[6];
+
412  uint16_t hci_handle;
+
414  uint8_t disc_bdaddr[6];
+
416  uint8_t remote_name[30];
+
422  uint8_t hci_version;
+
423 
+ +
426  pairWithWii = true;
+
427  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
428  };
+
430  bool connectToWii;
+ + + + +
439 
+
441  void pairWithHID() {
+
442  pairWithHIDDevice = true;
+
443  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
444  };
+
446  bool connectToHIDDevice;
+ + +
451 
+
456  uint8_t readPollInterval() {
+
457  return pollInterval;
+
458  };
+
459 
+
460 protected:
+
462  USB *pUsb;
+
464  uint8_t bAddress;
+ +
467 
+
469  uint8_t bConfNum;
+
471  uint8_t bNumEP;
+
473  uint32_t qNextPollTime;
+
474 
+
476  static const uint8_t BTD_CONTROL_PIPE;
+
478  static const uint8_t BTD_EVENT_PIPE;
+
480  static const uint8_t BTD_DATAIN_PIPE;
+
482  static const uint8_t BTD_DATAOUT_PIPE;
+
483 
+
489 
-
490  /* Used to set the Bluetooth Address internally to the PS3 Controllers */
-
491  void setBdaddr(uint8_t* BDADDR);
-
492  void setMoveBdaddr(uint8_t* BDADDR);
-
493 };
-
494 #endif
-
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:457
-
bool incomingWii
Definition: BTD.h:419
-
void hci_connect()
Definition: BTD.cpp:972
-
uint8_t bNumEP
Definition: BTD.h:446
-
const char * btdName
Definition: BTD.h:392
-
void hci_reset()
Definition: BTD.cpp:856
-
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1157
-
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1144
-
bool sdpConnectionClaimed
Definition: BTD.h:387
-
#define HCI_CHECK_WII_SERVICE
Definition: BTD.h:48
-
Definition: BTD.h:156
-
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: BTD.h:212
-
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1210
-
bool rfcommConnectionClaimed
Definition: BTD.h:389
-
uint8_t hci_version
Definition: BTD.h:409
-
void hci_inquiry()
Definition: BTD.cpp:950
-
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:453
+
490 private:
+
491  void clearAllVariables(); // Set all variables, endpoint structs etc. to default values
+
492  BluetoothService* btService[BTD_NUMSERVICES];
+
493 
+
494  uint16_t PID, VID; // PID and VID of device connected
+
495 
+
496  bool bPollEnable;
+
497  uint8_t pollInterval;
+
498 
+
499  /* Variables used by high level HCI task */
+
500  uint8_t hci_state; //current state of bluetooth hci connection
+
501  uint16_t hci_counter; // counter used for bluetooth hci reset loops
+
502  uint8_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset
+
503  uint16_t hci_event_flag; // hci flags of received bluetooth events
+
504  uint8_t inquiry_counter;
+
505 
+
506  uint8_t hcibuf[BULK_MAXPKTSIZE]; //General purpose buffer for hci data
+
507  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; //General purpose buffer for l2cap in data
+
508  uint8_t l2capoutbuf[14]; //General purpose buffer for l2cap out data
+
509 
+
510  /* State machines */
+
511  void HCI_event_task(); // Poll the HCI event pipe
+
512  void HCI_task(); // HCI state machine
+
513  void ACL_event_task(); // ACL input pipe
+
514 
+
515  /* Used to set the Bluetooth Address internally to the PS3 Controllers */
+
516  void setBdaddr(uint8_t* BDADDR);
+
517  void setMoveBdaddr(uint8_t* BDADDR);
+
518 };
+
519 #endif
+
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:482
+
bool incomingWii
Definition: BTD.h:432
+
void hci_connect()
Definition: BTD.cpp:1033
+
uint8_t bNumEP
Definition: BTD.h:471
+
const char * btdName
Definition: BTD.h:405
+
void hci_reset()
Definition: BTD.cpp:917
+
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1222
+
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1209
+
bool sdpConnectionClaimed
Definition: BTD.h:400
+
Definition: BTD.h:158
+
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: BTD.h:214
+
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1275
+
bool rfcommConnectionClaimed
Definition: BTD.h:402
+
uint8_t hci_version
Definition: BTD.h:422
+
void hci_inquiry()
Definition: BTD.cpp:1011
+
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:478
#define PS3MOVE_PID
Definition: BTD.h:27
-
bool pairWithWii
Definition: BTD.h:421
-
void hci_write_scan_disable()
Definition: BTD.cpp:878
-
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:196
-
const char * btdPin
Definition: BTD.h:394
-
bool motionPlusInside
Definition: BTD.h:423
-
void hci_remote_name()
Definition: BTD.cpp:919
-
uint8_t remote_name[30]
Definition: BTD.h:403
+
bool pairWithWii
Definition: BTD.h:434
+
void hci_write_scan_disable()
Definition: BTD.cpp:939
+
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: BTD.cpp:318
+
virtual uint8_t GetAddress()
Definition: BTD.h:198
+
const char * btdPin
Definition: BTD.h:407
+
bool motionPlusInside
Definition: BTD.h:436
+
void hci_remote_name()
Definition: BTD.cpp:980
+
uint8_t remote_name[30]
Definition: BTD.h:416
#define PS3_VID
Definition: BTD.h:24
BTD(USB *p)
Definition: BTD.cpp:27
-
uint8_t readPollInterval()
Definition: BTD.h:431
+
uint8_t readPollInterval()
Definition: BTD.h:456
virtual void Reset()
-
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:455
-
void hci_set_local_name(const char *name)
Definition: BTD.cpp:938
-
void hci_write_scan_enable()
Definition: BTD.cpp:865
-
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:1223
+
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:480
+
void hci_set_local_name(const char *name)
Definition: BTD.cpp:999
+
void hci_write_scan_enable()
Definition: BTD.cpp:926
+
virtual uint8_t Release()
Definition: BTD.cpp:369
+
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1288
#define USB_CLASS_WIRELESS_CTRL
Definition: UsbCore.h:55
-
bool watingForConnection
Definition: BTD.h:383
-
uint8_t bAddress
Definition: BTD.h:439
-
uint32_t qNextPollTime
Definition: BTD.h:448
-
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:346
+
bool watingForConnection
Definition: BTD.h:396
+
bool connectToHIDDevice
Definition: BTD.h:444
+
uint8_t bAddress
Definition: BTD.h:464
+
bool incomingHIDDevice
Definition: BTD.h:448
+
bool pairWithHIDDevice
Definition: BTD.h:450
+
uint32_t qNextPollTime
Definition: BTD.h:473
+
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:350
#define IOGEAR_GBU521_PID
Definition: BTD.h:30
-
bool connectToWii
Definition: BTD.h:415
-
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:46
-
bool wiiUProController
Definition: BTD.h:425
-
uint16_t hci_handle
Definition: BTD.h:399
-
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:119
+
bool connectToWii
Definition: BTD.h:428
+
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:48
+
bool wiiUProController
Definition: BTD.h:438
+
uint16_t hci_handle
Definition: BTD.h:412
+
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:121
Definition: address.h:32
-
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1068
- -
void hci_read_bdaddr()
Definition: BTD.cpp:887
-
void hci_inquiry_cancel()
Definition: BTD.cpp:964
-
uint8_t my_bdaddr[6]
Definition: BTD.h:397
-
virtual uint8_t Poll()
Definition: BTD.cpp:371
-
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: BTD.h:221
-
static const uint8_t BTD_CONTROL_PIPE
Definition: BTD.h:451
+
void pairWithHID()
Definition: BTD.h:441
+
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1133
+ +
void hci_read_bdaddr()
Definition: BTD.cpp:948
+
void hci_inquiry_cancel()
Definition: BTD.cpp:1025
+
uint8_t my_bdaddr[6]
Definition: BTD.h:410
+
virtual uint8_t Poll()
Definition: BTD.cpp:375
+
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: BTD.h:223
+
static const uint8_t BTD_CONTROL_PIPE
Definition: BTD.h:476
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
-
void disconnect()
Definition: BTD.h:239
-
uint8_t disc_bdaddr[6]
Definition: BTD.h:401
-
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:250
-
bool l2capConnectionClaimed
Definition: BTD.h:385
-
EpInfo epInfo[BTD_MAX_ENDPOINTS]
Definition: BTD.h:441
+
void disconnect()
Definition: BTD.h:247
+
uint8_t disc_bdaddr[6]
Definition: BTD.h:414
+
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:258
+
bool l2capConnectionClaimed
Definition: BTD.h:398
+
EpInfo epInfo[BTD_MAX_ENDPOINTS]
Definition: BTD.h:466
#define IOGEAR_GBU521_VID
Definition: BTD.h:29
virtual void ACLData(uint8_t *ACLData)
#define PS3_PID
Definition: BTD.h:25
#define BTD_MAX_ENDPOINTS
Definition: BTD.h:133
#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:1236
-
void hci_write_class_of_device()
Definition: BTD.cpp:1080
-
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1030
+
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1301
+
void hci_write_class_of_device()
Definition: BTD.cpp:1145
+
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1095
+
#define HCI_CHECK_DEVICE_SERVICE
Definition: BTD.h:48
Definition: UsbCore.h:152
virtual void Run()
-
uint8_t bConfNum
Definition: BTD.h:444
-
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1044
-
void pairWithWiimote()
Definition: BTD.h:412
-
virtual bool isReady()
Definition: BTD.h:204
-
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1116
+
uint8_t bConfNum
Definition: BTD.h:469
+
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1109
+
void pairWithWiimote()
Definition: BTD.h:425
+
virtual bool isReady()
Definition: BTD.h:206
+
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1181
#define BTD_NUMSERVICES
Definition: BTD.h:134
-
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1191
-
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1174
-
void hci_pin_code_request_reply()
Definition: BTD.cpp:994
+
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1256
+
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1239
+
void hci_pin_code_request_reply()
Definition: BTD.cpp:1059
virtual void disconnect()
-
USB * pUsb
Definition: BTD.h:433
-
void hci_authentication_request()
Definition: BTD.cpp:1058
-
void hci_read_local_version_information()
Definition: BTD.cpp:895
-
void hci_accept_connection()
Definition: BTD.cpp:903
-
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:851
+
USB * pUsb
Definition: BTD.h:458
+
void hci_authentication_request()
Definition: BTD.cpp:1123
+
void hci_read_local_version_information()
Definition: BTD.cpp:956
+
void hci_accept_connection()
Definition: BTD.cpp:964
+
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:912