1 /* 2 3 There are two basic types of physical links that can be established 4 between a master and a slave: 5 6 Synchronous Connection Oriented ( SCO ) 7 Asynchronous Connection-Less ( ACL ) 8 9 An SCO link provides a symmetric link between the master and the slave, 10 *********** 11 with regular periodic exchange of data in the form of reserved slots. 12 Thus, the SCO link provides a circuit-switched connection 13 where data are regularly exchanged, 14 and as such it is intended for use with time-bounded information as audio. 15 16 A master can support up to three SCO links to the same or to different slaves. 17 A slave can support up to three SCO links from the same master. 18 19 Audio - Audio data is carried via SCO (Synchronous Connection Oriented) channels 20 21 An ACI link is a point-to-multipoint link between the master 22 *********** 23 and all the slaves on the piconet. It can use all of the remaining slots 24 on the channel not used for SCO links. 25 The ACL link provides a packet-switched connection 26 where data are exchanged sporadically, 27 as they become available from higher layers of the stack. 28 29 The traffic over the ACL link is completely scheduled by the master. 30 31 Each Bluetooth device has a 48 bit IEEE MAC address that 32 is used for the derivation of the access code. 33 34 The form of a MAC address - Copyright Spill & Bittau 35 NAP[15:0] : UAP[7:0] : LAP[23:0] 36 The NAP is only two bytes long and the First byte is generally zero 37 38 All packets have the same format, starting with an access code, 39 followed by a packet header and ending with the user payload 40 41 Access Code Header Payload 42 68 or 72 bits 54 bits 0 - 2745 bits 43 44 The access code is used to address the packet to a specific device. 45 The header contains all the control information associated with the packet and the link. 46 The payload contains the actual message information. 47 48 49 An HCI packet consisting of an HCI header and HCI data 50 shall be contained in one USB Transfer. 51 52 A USB transfer is defined by the USB specification as 53 one or more USB transactions that contain the data from one IO request 54 55 For example, 56 an ACL data packet containing 256 bytes (both HCI header and HCI data) 57 would be sent over the bulk endpoint in one IO request 58 59 That IO request will require four 64-byte full speed USB Transactions or 60 a single 256-byte Highspeed USB Transaction, and forms a Transfer 61 62 If the Maximum Packet Size for the endpoint on which the transfer is sent 63 is 64 bytes, then that IO request will require four 64-byte USB transactions. 64 65 USB Primary firmware interface and endpoint settings 66 67 Interface Alternate Endpoint Endpoint PacketSize 68 Number Setting Address Type 69 HCI Commands N/A N/A 0x00 Control 8/64 70 HCI Events 0 0 0x81 Interrupt<in> 16 71 ACL/AMP Data 0 0 0x82 Bulk<in> 64 72 ACL/AMP Data 0 0 0x02 Bulk<out> 64 73 74 *************** CONTROL ENDPOINT EXPECTATIONS ********************************** 75 76 Endpoint 0 is used to configure and control the USB device. 77 Endpoint 0 will also be used to allow the host to 78 send HCI-specific commands to the host controller. 79 80 All HCI Control Packets delivered to Endpoint 0 are addressed 81 in the Setup Data structure 82 83 The bmRequestType can be used to select the Device or the Interface. 84 If Interface is selected, the wIndex parameter 85 must select the Index for the targeted Bluetooth controller 86 87 For a single function Primary Controller, 88 the Host should address HCI command packets to the Device. 89 HCI command packets should be sent with the following parameters: 90 91 *** HCI command packet addressing for single-function Primary controllers : 92 93 bmRequestType 0x20 : Host-to-device class request, device as target 94 bRequest 0x00 95 wValue 0x00 96 wIndex 0x00 97 98 Note: For historical reasons, if the Primary Controller firmware receives a 99 packet over this endpoint, it should treat the packet as an HCI command 100 packet regardless of the value of bRequest, wValue and wIndex. 101 Some Host devices set bRequest to 0xE0. 102 103 *** Primary Controller Function in a Composite Device 104 105 bmRequestType 0x21 : Host-to-interface class request, interface as target 106 bRequest 0x00 107 wValue 0x00 108 wIndex IF# : This is the actual Interface # within the composite device. 109 110 If the Host system driver addresses USB requests containing HCI command packets 111 to the Device instead of to the Interface, the device implementation shall 112 recognize these HCI command packets and correctly route them to 113 the Primary Controller function, to ensure correct operation of 114 the Primary Controller function and avoid malfunctions in other functions 115 contained in the composite device. 116 117 *** HCI command packet addressing for single-function AMP Controller 118 119 bmRequestType 0x21 : Host-to-interface class request, interface as target 120 bRequest 0x2B : Arbitrary value chosen to identify requests targeted to an AMP controller function. 121 wValue 0x00 122 wIndex IF# : This is the actual Interface # within the composite device. 123 124 125 *************** BULK ENDPOINT EXPECTATIONS ************************************* 126 127 Data integrity is a critical aspect for ACL data. This, 128 in combination with bandwidth requirements, 129 is the reason for using a bulk endpoint. Multiple 64-byte packets can be shipped 130 per USB Frame (1 millisecond, full speed) or 512-byte packets per USB Microframe 131 (125 microseconds, high-speed), across the bus. 132 133 Suggested bulk max packet size is 64 bytes for full-speed, 134 or 512 bytes for high speed. 135 136 Bulk has the ability to detect errors and correct them. 137 In order to avoid starvation, a flow control model similar 138 to the shared endpoint model is recommended for the host controller. 139 140 ***************INTERRUPT ENDPOINT EXPECTATIONS ********************************* 141 142 An interrupt endpoint is necessary to ensure that events are delivered 143 in a predictable and timely manner. 144 Event packets can be sent across USB with a guaranteed latency. 145 146 The interrupt endpoint should have an interval of 1 ms (full speed). 147 For a controller using USB high-speed the interrupt interval may have 148 an interval of 125 microseconds. 149 150 The USB software and firmware requires no intimate knowledge of the events 151 passed to the host controller. 152 153 ***************ISOCHRONOUS ENDPOINT EXPECTATIONS ******************************* 154 155 These isochronous endpoints transfer synchronous data to and from the host 156 controller of the radio. 157 158 Time is the critical aspect for this type of data. 159 The USB firmware should transfer the contents of the data 160 to the host controllers' synchronous FIFOs. 161 If the FIFOs are full, the data should be overwritten with new data. 162 These endpoints have a one (1) ms interval, as required by Chapter 9 of the 163 USB Specification, Versions 1.0 and 1.1. 164 165 A suggested max packet size for this endpoint would be at least 64 bytes. 166 167 ********************** BLUETOOTH CODES ***************************************** 168 169 The following values are defined for Bluetooth Devices: 170 171 Device/Inferface : USB Codes for Primary Controllers : 172 Class bDeviceClass 0xE0 Wireless Controller 173 Subclass bDeviceSubClass 0x01 RF Controller 174 Protocol bDeviceProtocol 0x01 Bluetooth Pri Controller < bRequest : 0x00 > 175 176 Device/Inferface : USB Codes for AMP Controllers : 177 Class bDeviceClass 0xE0 Wireless Controller 178 Subclass bDeviceSubClass 0x01 RF Controller 179 Protocol bDeviceProtocol 0x04 Bluetooth AMP Controller < bRequest : 0x2B > 180 181 These values should also be used in the interface descriptors for the interfaces 182 183 Device : USB Codes for composite devices using IAD : 184 Class bDeviceClass 0xEF Miscellaneous 185 Subclass bDeviceSubClass 0x02 Common Class 186 Protocol bDeviceProtocol 0x01 Interface Association Descriptor 187 188 Interface : USB Codes for Primary Controllers : 189 Class bDeviceClass 0xE0 Wireless Controller 190 Subclass bDeviceSubClass 0x01 RF Controller 191 Protocol bDeviceProtocol 0x01 Bluetooth Pri Controller < bRequest : 0x00 > 192 193 Interface : USB Codes for AMP Controllers : 194 Class bDeviceClass 0xE0 Wireless Controller 195 Subclass bDeviceSubClass 0x01 RF Controller 196 Protocol bDeviceProtocol 0x04 Bluetooth AMP Controller < bRequest : 0x2B > 197 198 ************* BLUETOOTH COMPOSITE DEVICE IMPLEMENTATION ************************ 199 200 (IAD) : Interface Association Descriptors 201 202 Example Interface Association Descriptor used for a Primary Controller function: 203 204 Offset Field Size Value Description 205 0 bLength 1 0x08 Size of this descriptor in octets 206 1 bDescriptorType 1 0x0B INTERFACE ASSOCIATION DESCRIPTOR 207 2 bFirstInterface 1 xxxx Interface number of the first interface associated with this device 208 3 bInterfaceCount 1 0x02 Number of contiguous interfaces associated with the function 209 4 bFunctionClass 1 0xE0 Wireless Controller 210 5 bFunctionSubClass 1 0x01 RF Controller 211 6 bFunctionProtocol 1 0x01 Bluetooth Primary Controller 212 7 iFunction 1 xxxx Index Pointer to a name string for this function, if any is provide 213 214 A USB Composite contains multiple independent functions. This section 215 describes how to implement Bluetooth functions within a USB Composite 216 device. This may require the use of Interface Association Descriptors (IAD) to 217 aggregate multiple Interfaces. This also requires the host to address USB 218 requests to the specific Interface 219 220 A Primary Controller (ref) shall contain at least two interfaces: 221 HCI Events and ACL data (3 endpoints) 222 HCI SCO data (2 endpoints, multiple alternate settings) 223 224 When used in a USB Composite device, a Primary Controller function shall use 225 an IAD descriptor to associate the provided interfaces. 226 227 When used in a USB Composite device, an AMP Controller does not need IAD. 228 If the device contains the Device Firmware Upgrade option as a separate 229 Device function, an IAD is not needed. If the Device Firmware Upgrade option 230 is bundled with the AMP Controller function, then an IAD is needed to bind the 231 two interfaces. 232 233 A USB Composite device containing only a Primary Controller and an AMP Controller 234 may include a Configuration Descriptor set with the following structure: 235 236 Configuration Descriptor : 237 238 0x09, 0x02, wTotalLength, 239 0x03, 240 // bNumInterfaces 241 // IF#1 Primary events & ACL 242 // IF#2 Primary SCO or eSCO 243 // IF#3 AMP events & ACL 244 0x01, // bConfigurationValue 245 iConfiguration, 246 bmAttributes, 247 0xFA, // Max power used 500ma 248 249 Interface Association Descriptor : 250 251 0x08, 0x0B, 252 IF#1, // bFirstInterface 253 0x03, // bInterfaceCount : Number of contiguous interfaces associated with the function. 254 0xE0, 0x01, 0x01, // Wireless Controller : RF Controller : Bluetooth Primary Controller 255 iFunctionString 256 257 INTERFACE DESCRIPTOR #1 258 0x09, 0x04, IF#1, 0x00, 0x03, // bNumEndpoints : InterruptIn, BulkIn, BulkOut 259 0xE0, 0x01, 0x01, // Wireless Controller : RF Controller : Bluetooth Primary Controller 260 iInterfaceString 261 262 ENDPOINT DESCRIPTOR : Interrupt, Bulk In, Bulk Out 263 264 INTERFACE DESCRIPTOR #2 265 266 0x09, 0x04, IF#2, 0x00, 0x02, // bNumEndpoints : Isoch OUT (SCO), Isoch IN (SCO) 267 0xE0, 0x01, 0x01, // Wireless Controller : RF Controller : Bluetooth Primary Controller 268 iInterfaceString 269 270 ENDPOINT DESCRIPTOR : Iso In, Iso Out 271 272 INTERFACE DESCRIPTOR #3 273 274 0x09, 0x04, IF#3, 0x00, 0x03, // bNumEndpoints : Isoch OUT (SCO), Isoch IN (SCO) 275 0xE0, 0x01, 0x04, // Wireless Controller : RF Controller : Bluetooth AMP Controller 276 iInterfaceString 277 278 ENDPOINT DESCRIPTOR : Interrupt, Bulk In, Bulk Out 279 280 LOGICAL LINK CONTROL AND ADAPTATION PROTOCOL SPECIFICATION : L2CAP 281 282 DATA PACKET FORMAT 283 SIGNALING PACKET FORMATS 284 285 SERVICE DISCOVERY PROTOCOL SPECIFICATION : SDP 286 287 GENERIC ACCESS PROFILE 288 289 AMP MANAGER PROTOCOL SPECIFICATION 290 291 ATTRIBUTE PROTOCOL (ATT) 292 293 GENERIC ATTRIBUTE PROFILE (GATT) 294 295 SECURITY MANAGER SPECIFICATION 296 297 */