USB Host Shield 2.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BTD Class Reference

#include <BTD.h>

Inheritance diagram for BTD:
Inheritance graph
[legend]
Collaboration diagram for BTD:
Collaboration graph
[legend]

Public Member Functions

 BTD (USB *p)
 
void disconnect ()
 
int8_t registerBluetoothService (BluetoothService *pService)
 
void pairWithWiimote ()
 
void pairWithHID ()
 
uint8_t readPollInterval ()
 
USBDeviceConfig implementation
uint8_t ConfigureDevice (uint8_t parent, uint8_t port, bool lowspeed)
 
uint8_t Init (uint8_t parent, uint8_t port, bool lowspeed)
 
uint8_t Release ()
 
uint8_t Poll ()
 
virtual uint8_t GetAddress ()
 
virtual bool isReady ()
 
virtual bool DEVCLASSOK (uint8_t klass)
 
virtual bool VIDPIDOK (uint16_t vid, uint16_t pid)
 
UsbConfigXtracter implementation
void EndpointXtract (uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
 
HCI Commands
void HCI_Command (uint8_t *data, uint16_t nbytes)
 
void hci_reset ()
 
void hci_read_bdaddr ()
 
void hci_read_local_version_information ()
 
void hci_read_local_extended_features (uint8_t page_number)
 
void hci_write_local_name (const char *name)
 
void hci_write_simple_pairing_mode (bool enable)
 
void hci_set_event_mask ()
 
void hci_write_scan_enable ()
 
void hci_write_scan_disable ()
 
void hci_remote_name ()
 
void hci_accept_connection ()
 
void hci_disconnect (uint16_t handle)
 
void hci_pin_code_request_reply ()
 
void hci_pin_code_negative_request_reply ()
 
void hci_link_key_request_negative_reply ()
 
void hci_user_confirmation_request_reply ()
 
void hci_authentication_request ()
 
void hci_inquiry ()
 
void hci_inquiry_cancel ()
 
void hci_connect ()
 
void hci_io_capability_request_reply ()
 
void hci_connect (uint8_t *bdaddr)
 
void hci_write_class_of_device ()
 
L2CAP Commands
void L2CAP_Command (uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
 
void l2cap_connection_request (uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
 
void l2cap_connection_response (uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
 
void l2cap_config_request (uint16_t handle, uint8_t rxid, uint8_t *dcid)
 
void l2cap_config_response (uint16_t handle, uint8_t rxid, uint8_t *scid)
 
void l2cap_disconnection_request (uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
 
void l2cap_disconnection_response (uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
 
void l2cap_information_response (uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
 
- Public Member Functions inherited from USBDeviceConfig
virtual void ResetHubPort (uint8_t port)
 
virtual bool DEVSUBCLASSOK (uint8_t subklass)
 

Public Attributes

bool waitingForConnection
 
bool l2capConnectionClaimed
 
bool sdpConnectionClaimed
 
bool rfcommConnectionClaimed
 
const char * btdName
 
const char * btdPin
 
uint8_t my_bdaddr [6]
 
uint16_t hci_handle
 
uint8_t disc_bdaddr [6]
 
char remote_name [30]
 
uint8_t hci_version
 
bool connectToWii
 
bool incomingWii
 
bool pairWithWii
 
bool motionPlusInside
 
bool wiiUProController
 
bool connectToHIDDevice
 
bool incomingHIDDevice
 
bool pairWithHIDDevice
 
bool useSimplePairing
 

Protected Member Functions

void PrintEndpointDescriptor (const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
 

Protected Attributes

USBpUsb
 
uint8_t bAddress
 
EpInfo epInfo [BTD_MAX_ENDPOINTS]
 
uint8_t bConfNum
 
uint8_t bNumEP
 
uint32_t qNextPollTime
 

Static Protected Attributes

static const uint8_t BTD_CONTROL_PIPE = 0
 
static const uint8_t BTD_EVENT_PIPE = 1
 
static const uint8_t BTD_DATAIN_PIPE = 2
 
static const uint8_t BTD_DATAOUT_PIPE = 3
 

Detailed Description

The Bluetooth Dongle class will take care of all the USB communication and then pass the data to the BluetoothService classes.

Definition at line 222 of file BTD.h.

Constructor & Destructor Documentation

◆ BTD()

BTD::BTD ( USB p)

Constructor for the BTD class.

Parameters
pPointer to USB class instance.

Definition at line 27 of file BTD.cpp.

Member Function Documentation

◆ ConfigureDevice()

uint8_t BTD::ConfigureDevice ( uint8_t  parent,
uint8_t  port,
bool  lowspeed 
)
virtual

Address assignment and basic initialization is done here.

Parameters
parentHub number.
portPort number on the hub.
lowspeedSpeed of the device.
Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 50 of file BTD.cpp.

◆ Init()

uint8_t BTD::Init ( uint8_t  parent,
uint8_t  port,
bool  lowspeed 
)
virtual

Initialize the Bluetooth dongle.

Parameters
parentHub number.
portPort number on the hub.
lowspeedSpeed of the device.
Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 136 of file BTD.cpp.

◆ Release()

uint8_t BTD::Release ( )
virtual

Release the USB device.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 379 of file BTD.cpp.

◆ Poll()

uint8_t BTD::Poll ( )
virtual

Poll the USB Input endpoints and run the state machines.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 385 of file BTD.cpp.

◆ GetAddress()

virtual uint8_t BTD::GetAddress ( )
inlinevirtual

Get the device address.

Returns
The device address.

Reimplemented from USBDeviceConfig.

Definition at line 262 of file BTD.h.

◆ isReady()

virtual bool BTD::isReady ( )
inlinevirtual

Used to check if the dongle has been initialized.

Returns
True if it's ready.

Definition at line 270 of file BTD.h.

◆ DEVCLASSOK()

virtual bool BTD::DEVCLASSOK ( uint8_t  klass)
inlinevirtual

Used by the USB core to check what this driver support.

Parameters
klassThe device's USB class.
Returns
Returns true if the device's USB class matches this driver.

Reimplemented from USBDeviceConfig.

Definition at line 279 of file BTD.h.

◆ VIDPIDOK()

virtual bool BTD::VIDPIDOK ( uint16_t  vid,
uint16_t  pid 
)
inlinevirtual

Used by the USB core to check what this driver support. Used to set the Bluetooth address into the PS3 controllers.

Parameters
vidThe device's VID.
pidThe device's PID.
Returns
Returns true if the device's VID and PID matches this driver.

Reimplemented from USBDeviceConfig.

Definition at line 290 of file BTD.h.

◆ EndpointXtract()

void BTD::EndpointXtract ( uint8_t  conf,
uint8_t  iface,
uint8_t  alt,
uint8_t  proto,
const USB_ENDPOINT_DESCRIPTOR ep 
)
virtual

UsbConfigXtracter implementation, used to extract endpoint information.

Parameters
confConfiguration value.
ifaceInterface number.
altAlternate setting.
protoInterface Protocol.
epEndpoint Descriptor.

Reimplemented from UsbConfigXtracter.

Definition at line 330 of file BTD.cpp.

◆ disconnect()

void BTD::disconnect ( )

Disconnects both the L2CAP Channel and the HCI Connection for all Bluetooth services.

Definition at line 397 of file BTD.cpp.

◆ registerBluetoothService()

int8_t BTD::registerBluetoothService ( BluetoothService pService)
inline

Register Bluetooth dongle members/services.

Parameters
pServicePointer to BluetoothService class instance.
Returns
The service ID on success or -1 on fail.

Definition at line 321 of file BTD.h.

◆ HCI_Command()

void BTD::HCI_Command ( uint8_t *  data,
uint16_t  nbytes 
)

Used to send a HCI Command.

Parameters
dataData to send.
nbytesNumber of bytes to send.

Definition at line 1113 of file BTD.cpp.

◆ hci_reset()

void BTD::hci_reset ( )

Reset the Bluetooth dongle.

Definition at line 1118 of file BTD.cpp.

◆ hci_read_bdaddr()

void BTD::hci_read_bdaddr ( )

Read the Bluetooth address of the dongle.

Definition at line 1149 of file BTD.cpp.

◆ hci_read_local_version_information()

void BTD::hci_read_local_version_information ( )

Read the HCI Version of the Bluetooth dongle.

Definition at line 1158 of file BTD.cpp.

◆ hci_read_local_extended_features()

void BTD::hci_read_local_extended_features ( uint8_t  page_number)

Used to check if the dongle supports simple paring

Definition at line 1167 of file BTD.cpp.

◆ hci_write_local_name()

void BTD::hci_write_local_name ( const char *  name)

Set the local name of the Bluetooth dongle.

Parameters
nameDesired name.

Definition at line 1212 of file BTD.cpp.

◆ hci_write_simple_pairing_mode()

void BTD::hci_write_simple_pairing_mode ( bool  enable)

Used to enable simply paring if the dongle supports it

Definition at line 1242 of file BTD.cpp.

◆ hci_set_event_mask()

void BTD::hci_set_event_mask ( )

Used to enable events related to simple paring

Definition at line 1224 of file BTD.cpp.

◆ hci_write_scan_enable()

void BTD::hci_write_scan_enable ( )

Enable visibility to other Bluetooth devices.

Definition at line 1127 of file BTD.cpp.

◆ hci_write_scan_disable()

void BTD::hci_write_scan_disable ( )

Disable visibility to other Bluetooth devices.

Definition at line 1140 of file BTD.cpp.

◆ hci_remote_name()

void BTD::hci_remote_name ( )

Read the remote devices name.

Definition at line 1193 of file BTD.cpp.

◆ hci_accept_connection()

void BTD::hci_accept_connection ( )

Accept the connection with the Bluetooth device.

Definition at line 1177 of file BTD.cpp.

◆ hci_disconnect()

void BTD::hci_disconnect ( uint16_t  handle)

Disconnect the HCI connection.

Parameters
handleThe HCI Handle for the connection.

Definition at line 1404 of file BTD.cpp.

◆ hci_pin_code_request_reply()

void BTD::hci_pin_code_request_reply ( )

Respond with the pin for the connection. The pin is automatically set for the Wii library, but can be customized for the SPP library.

Definition at line 1299 of file BTD.cpp.

◆ hci_pin_code_negative_request_reply()

void BTD::hci_pin_code_negative_request_reply ( )

Respons when no pin was set.

Definition at line 1335 of file BTD.cpp.

◆ hci_link_key_request_negative_reply()

void BTD::hci_link_key_request_negative_reply ( )

Command is used to reply to a Link Key Request event from the BR/EDR Controller if the Host does not have a stored Link Key for the connection.

Definition at line 1349 of file BTD.cpp.

◆ hci_user_confirmation_request_reply()

void BTD::hci_user_confirmation_request_reply ( )

Used to during simple paring to confirm that the we want to connect

Definition at line 1380 of file BTD.cpp.

◆ hci_authentication_request()

void BTD::hci_authentication_request ( )

Used to try to authenticate with the remote device.

Definition at line 1394 of file BTD.cpp.

◆ hci_inquiry()

void BTD::hci_inquiry ( )

Start a HCI inquiry.

Definition at line 1251 of file BTD.cpp.

◆ hci_inquiry_cancel()

void BTD::hci_inquiry_cancel ( )

Cancel a HCI inquiry.

Definition at line 1265 of file BTD.cpp.

◆ hci_connect() [1/2]

void BTD::hci_connect ( )

Connect to last device communicated with.

Definition at line 1273 of file BTD.cpp.

◆ hci_io_capability_request_reply()

void BTD::hci_io_capability_request_reply ( )

Used during simple paring to reply to a IO capability request

Definition at line 1363 of file BTD.cpp.

◆ hci_connect() [2/2]

void BTD::hci_connect ( uint8_t *  bdaddr)

Connect to device.

Parameters
bdaddrBluetooth address of the device.

Definition at line 1277 of file BTD.cpp.

◆ hci_write_class_of_device()

void BTD::hci_write_class_of_device ( )

Used to a set the class of the device.

Definition at line 1416 of file BTD.cpp.

◆ L2CAP_Command()

void BTD::L2CAP_Command ( uint16_t  handle,
uint8_t *  data,
uint8_t  nbytes,
uint8_t  channelLow = 0x01,
uint8_t  channelHigh = 0x00 
)

Used to send L2CAP Commands.

Parameters
handleHCI Handle.
dataData to send.
nbytesNumber of bytes to send.
channelLow,channelHighLow and high byte of channel to send to. If argument is omitted then the Standard L2CAP header: Channel ID (0x01) for ACL-U will be used.

Definition at line 1452 of file BTD.cpp.

◆ l2cap_connection_request()

void BTD::l2cap_connection_request ( uint16_t  handle,
uint8_t  rxid,
uint8_t *  scid,
uint16_t  psm 
)

L2CAP Connection Request.

Parameters
handleHCI handle.
rxidIdentifier.
scidSource Channel Identifier.
psmProtocol/Service Multiplexer - see: https://www.bluetooth.org/Technical/AssignedNumbers/logical_link.htm.

Definition at line 1480 of file BTD.cpp.

◆ l2cap_connection_response()

void BTD::l2cap_connection_response ( uint16_t  handle,
uint8_t  rxid,
uint8_t *  dcid,
uint8_t *  scid,
uint8_t  result 
)

L2CAP Connection Response.

Parameters
handleHCI handle.
rxidIdentifier.
dcidDestination Channel Identifier.
scidSource Channel Identifier.
resultResult - First send PENDING and then SUCCESSFUL.

Definition at line 1493 of file BTD.cpp.

◆ l2cap_config_request()

void BTD::l2cap_config_request ( uint16_t  handle,
uint8_t  rxid,
uint8_t *  dcid 
)

L2CAP Config Request.

Parameters
handleHCI Handle.
rxidIdentifier.
dcidDestination Channel Identifier.

Definition at line 1510 of file BTD.cpp.

◆ l2cap_config_response()

void BTD::l2cap_config_response ( uint16_t  handle,
uint8_t  rxid,
uint8_t *  scid 
)

L2CAP Config Response.

Parameters
handleHCI Handle.
rxidIdentifier.
scidSource Channel Identifier.

Definition at line 1527 of file BTD.cpp.

◆ l2cap_disconnection_request()

void BTD::l2cap_disconnection_request ( uint16_t  handle,
uint8_t  rxid,
uint8_t *  dcid,
uint8_t *  scid 
)

L2CAP Disconnection Request.

Parameters
handleHCI Handle.
rxidIdentifier.
dcidDevice Channel Identifier.
scidSource Channel Identifier.

Definition at line 1546 of file BTD.cpp.

◆ l2cap_disconnection_response()

void BTD::l2cap_disconnection_response ( uint16_t  handle,
uint8_t  rxid,
uint8_t *  dcid,
uint8_t *  scid 
)

L2CAP Disconnection Response.

Parameters
handleHCI Handle.
rxidIdentifier.
dcidDevice Channel Identifier.
scidSource Channel Identifier.

Definition at line 1559 of file BTD.cpp.

◆ l2cap_information_response()

void BTD::l2cap_information_response ( uint16_t  handle,
uint8_t  rxid,
uint8_t  infoTypeLow,
uint8_t  infoTypeHigh 
)

L2CAP Information Response.

Parameters
handleHCI Handle.
rxidIdentifier.
infoTypeLow,infoTypeHighInfotype.

Definition at line 1572 of file BTD.cpp.

◆ pairWithWiimote()

void BTD::pairWithWiimote ( )
inline

Call this function to pair with a Wiimote

Definition at line 498 of file BTD.h.

◆ pairWithHID()

void BTD::pairWithHID ( )
inline

Call this function to pair with a HID device

Definition at line 514 of file BTD.h.

◆ readPollInterval()

uint8_t BTD::readPollInterval ( )
inline

Read the poll interval taken from the endpoint descriptors.

Returns
The poll interval in ms.

Definition at line 530 of file BTD.h.

◆ PrintEndpointDescriptor()

void BTD::PrintEndpointDescriptor ( const USB_ENDPOINT_DESCRIPTOR ep_ptr)
protected

Used to print the USB Endpoint Descriptor.

Parameters
ep_ptrPointer to USB Endpoint Descriptor.

Definition at line 360 of file BTD.cpp.

Member Data Documentation

◆ waitingForConnection

bool BTD::waitingForConnection

Use this to see if it is waiting for a incoming connection.

Definition at line 469 of file BTD.h.

◆ l2capConnectionClaimed

bool BTD::l2capConnectionClaimed

This is used by the service to know when to store the device information.

Definition at line 471 of file BTD.h.

◆ sdpConnectionClaimed

bool BTD::sdpConnectionClaimed

This is used by the SPP library to claim the current SDP incoming request.

Definition at line 473 of file BTD.h.

◆ rfcommConnectionClaimed

bool BTD::rfcommConnectionClaimed

This is used by the SPP library to claim the current RFCOMM incoming request.

Definition at line 475 of file BTD.h.

◆ btdName

const char* BTD::btdName

The name you wish to make the dongle show up as. It is set automatically by the SPP library.

Definition at line 478 of file BTD.h.

◆ btdPin

const char* BTD::btdPin

The pin you wish to make the dongle use for authentication. It is set automatically by the SPP and BTHID library.

Definition at line 480 of file BTD.h.

◆ my_bdaddr

uint8_t BTD::my_bdaddr[6]

The bluetooth dongles Bluetooth address.

Definition at line 483 of file BTD.h.

◆ hci_handle

uint16_t BTD::hci_handle

HCI handle for the last connection.

Definition at line 485 of file BTD.h.

◆ disc_bdaddr

uint8_t BTD::disc_bdaddr[6]

Last incoming devices Bluetooth address.

Definition at line 487 of file BTD.h.

◆ remote_name

char BTD::remote_name[30]

First 30 chars of last remote name.

Definition at line 489 of file BTD.h.

◆ hci_version

uint8_t BTD::hci_version

The supported HCI Version read from the Bluetooth dongle. Used by the PS3BT library to check the HCI Version of the Bluetooth dongle, it should be at least 3 to work properly with the library.

Definition at line 495 of file BTD.h.

◆ connectToWii

bool BTD::connectToWii

Used to only send the ACL data to the Wiimote.

Definition at line 501 of file BTD.h.

◆ incomingWii

bool BTD::incomingWii

True if a Wiimote is connecting.

Definition at line 505 of file BTD.h.

◆ pairWithWii

bool BTD::pairWithWii

True when it should pair with a Wiimote.

Definition at line 507 of file BTD.h.

◆ motionPlusInside

bool BTD::motionPlusInside

True if it's the new Wiimote with the Motion Plus Inside or a Wii U Pro Controller.

Definition at line 509 of file BTD.h.

◆ wiiUProController

bool BTD::wiiUProController

True if it's a Wii U Pro Controller.

Definition at line 511 of file BTD.h.

◆ connectToHIDDevice

bool BTD::connectToHIDDevice

Used to only send the ACL data to the HID device.

Definition at line 518 of file BTD.h.

◆ incomingHIDDevice

bool BTD::incomingHIDDevice

True if a HID device is connecting.

Definition at line 522 of file BTD.h.

◆ pairWithHIDDevice

bool BTD::pairWithHIDDevice

True when it should pair with a device like a mouse or keyboard.

Definition at line 524 of file BTD.h.

◆ useSimplePairing

bool BTD::useSimplePairing

Used by the drivers to enable simple pairing

Definition at line 532 of file BTD.h.

◆ pUsb

USB* BTD::pUsb
protected

Pointer to USB class instance.

Definition at line 539 of file BTD.h.

◆ bAddress

uint8_t BTD::bAddress
protected

Device address.

Definition at line 541 of file BTD.h.

◆ epInfo

EpInfo BTD::epInfo[BTD_MAX_ENDPOINTS]
protected

Endpoint info structure.

Definition at line 543 of file BTD.h.

◆ bConfNum

uint8_t BTD::bConfNum
protected

Configuration number.

Definition at line 546 of file BTD.h.

◆ bNumEP

uint8_t BTD::bNumEP
protected

Total number of endpoints in the configuration.

Definition at line 548 of file BTD.h.

◆ qNextPollTime

uint32_t BTD::qNextPollTime
protected

Next poll time based on poll interval taken from the USB descriptor.

Definition at line 550 of file BTD.h.

◆ BTD_CONTROL_PIPE

const uint8_t BTD::BTD_CONTROL_PIPE = 0
staticprotected

Bluetooth dongle control endpoint.

Definition at line 553 of file BTD.h.

◆ BTD_EVENT_PIPE

const uint8_t BTD::BTD_EVENT_PIPE = 1
staticprotected

HCI event endpoint index.

Definition at line 555 of file BTD.h.

◆ BTD_DATAIN_PIPE

const uint8_t BTD::BTD_DATAIN_PIPE = 2
staticprotected

ACL In endpoint index.

Definition at line 557 of file BTD.h.

◆ BTD_DATAOUT_PIPE

const uint8_t BTD::BTD_DATAOUT_PIPE = 3
staticprotected

ACL Out endpoint index.

Definition at line 559 of file BTD.h.


The documentation for this class was generated from the following files: