Go to the documentation of this file.
25 #define PS3_VID 0x054C // Sony Corporation
26 #define PS3_PID 0x0268 // PS3 Controller DualShock 3
27 #define PS3NAVIGATION_PID 0x042F // Navigation controller
28 #define PS3MOVE_PID 0x03D5 // Motion controller
31 #define IOGEAR_GBU521_VID 0x0A5C
32 #define IOGEAR_GBU521_PID 0x21E8
33 #define BELKIN_F8T065BF_VID 0x050D
34 #define BELKIN_F8T065BF_PID 0x065A
37 #define BULK_MAXPKTSIZE 64 // Max size for ACL data
40 #define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
43 #define HCI_INIT_STATE 0
44 #define HCI_RESET_STATE 1
45 #define HCI_CLASS_STATE 2
46 #define HCI_BDADDR_STATE 3
47 #define HCI_LOCAL_VERSION_STATE 4
48 #define HCI_WRITE_NAME_STATE 5
49 #define HCI_CHECK_DEVICE_SERVICE 6
51 #define HCI_INQUIRY_STATE 7 // These three states are only used if it should pair and connect to a device
52 #define HCI_CONNECT_DEVICE_STATE 8
53 #define HCI_CONNECTED_DEVICE_STATE 9
55 #define HCI_SCANNING_STATE 10
56 #define HCI_CONNECT_IN_STATE 11
57 #define HCI_REMOTE_NAME_STATE 12
58 #define HCI_CONNECTED_STATE 13
59 #define HCI_DISABLE_SCAN_STATE 14
60 #define HCI_DONE_STATE 15
61 #define HCI_DISCONNECT_STATE 16
62 #define HCI_LOCAL_EXTENDED_FEATURES_STATE 17
63 #define HCI_WRITE_SIMPLE_PAIRING_STATE 18
64 #define HCI_SET_EVENT_MASK_STATE 19
67 #define HCI_FLAG_CMD_COMPLETE (1UL << 0)
68 #define HCI_FLAG_CONNECT_COMPLETE (1UL << 1)
69 #define HCI_FLAG_DISCONNECT_COMPLETE (1UL << 2)
70 #define HCI_FLAG_REMOTE_NAME_COMPLETE (1UL << 3)
71 #define HCI_FLAG_INCOMING_REQUEST (1UL << 4)
72 #define HCI_FLAG_READ_BDADDR (1UL << 5)
73 #define HCI_FLAG_READ_VERSION (1UL << 6)
74 #define HCI_FLAG_DEVICE_FOUND (1UL << 7)
75 #define HCI_FLAG_CONNECT_EVENT (1UL << 8)
76 #define HCI_FLAG_LOCAL_EXTENDED_FEATURES (1UL << 9)
79 #define hci_check_flag(flag) (hci_event_flag & (flag))
80 #define hci_set_flag(flag) (hci_event_flag |= (flag))
81 #define hci_clear_flag(flag) (hci_event_flag &= ~(flag))
84 #define EV_INQUIRY_COMPLETE 0x01
85 #define EV_INQUIRY_RESULT 0x02
86 #define EV_CONNECT_COMPLETE 0x03
87 #define EV_INCOMING_CONNECT 0x04
88 #define EV_DISCONNECT_COMPLETE 0x05
89 #define EV_AUTHENTICATION_COMPLETE 0x06
90 #define EV_REMOTE_NAME_COMPLETE 0x07
91 #define EV_ENCRYPTION_CHANGE 0x08
92 #define EV_CHANGE_CONNECTION_LINK 0x09
93 #define EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE 0x0C
94 #define EV_QOS_SETUP_COMPLETE 0x0D
95 #define EV_COMMAND_COMPLETE 0x0E
96 #define EV_COMMAND_STATUS 0x0F
97 #define EV_ROLE_CHANGED 0x12
98 #define EV_NUM_COMPLETE_PKT 0x13
99 #define EV_PIN_CODE_REQUEST 0x16
100 #define EV_LINK_KEY_REQUEST 0x17
101 #define EV_LINK_KEY_NOTIFICATION 0x18
102 #define EV_DATA_BUFFER_OVERFLOW 0x1A
103 #define EV_MAX_SLOTS_CHANGE 0x1B
104 #define EV_LOOPBACK_COMMAND 0x19
105 #define EV_PAGE_SCAN_REP_MODE 0x20
106 #define EV_READ_REMOTE_EXTENDED_FEATURES_COMPLETE 0x23
107 #define EV_IO_CAPABILITY_REQUEST 0x31
108 #define EV_IO_CAPABILITY_RESPONSE 0x32
109 #define EV_USER_CONFIRMATION_REQUEST 0x33
110 #define EV_SIMPLE_PAIRING_COMPLETE 0x36
117 #define L2CAP_CONTROL_CONNECT_REQUEST 2
118 #define L2CAP_CONTROL_CONFIG_REQUEST 3
119 #define L2CAP_CONTROL_SUCCESS 4
120 #define L2CAP_CONTROL_DISCONNECT 5
123 #define L2CAP_INTERRUPT_SETUP 6
124 #define L2CAP_INTERRUPT_CONNECT_REQUEST 7
125 #define L2CAP_INTERRUPT_CONFIG_REQUEST 8
126 #define L2CAP_INTERRUPT_DISCONNECT 9
129 #define L2CAP_SDP_WAIT 10
130 #define L2CAP_SDP_SUCCESS 11
133 #define L2CAP_RFCOMM_WAIT 12
134 #define L2CAP_RFCOMM_SUCCESS 13
136 #define L2CAP_DISCONNECT_RESPONSE 14 // Used for both SDP and RFCOMM channel
139 #define TURN_ON_LED 17
140 #define PS3_ENABLE_SIXAXIS 18
141 #define WII_CHECK_MOTION_PLUS_STATE 19
142 #define WII_CHECK_EXTENSION_STATE 20
143 #define WII_INIT_MOTION_PLUS_STATE 21
146 #define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST (1UL << 0)
147 #define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS (1UL << 1)
148 #define L2CAP_FLAG_CONTROL_CONNECTED (1UL << 2)
149 #define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE (1UL << 3)
152 #define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST (1UL << 4)
153 #define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS (1UL << 5)
154 #define L2CAP_FLAG_INTERRUPT_CONNECTED (1UL << 6)
155 #define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE (1UL << 7)
158 #define L2CAP_FLAG_CONNECTION_SDP_REQUEST (1UL << 8)
159 #define L2CAP_FLAG_CONFIG_SDP_SUCCESS (1UL << 9)
160 #define L2CAP_FLAG_DISCONNECT_SDP_REQUEST (1UL << 10)
163 #define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST (1UL << 11)
164 #define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS (1UL << 12)
165 #define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST (1UL << 13)
167 #define L2CAP_FLAG_DISCONNECT_RESPONSE (1UL << 14)
170 #define l2cap_check_flag(flag) (l2cap_event_flag & (flag))
171 #define l2cap_set_flag(flag) (l2cap_event_flag |= (flag))
172 #define l2cap_clear_flag(flag) (l2cap_event_flag &= ~(flag))
175 #define L2CAP_CMD_COMMAND_REJECT 0x01
176 #define L2CAP_CMD_CONNECTION_REQUEST 0x02
177 #define L2CAP_CMD_CONNECTION_RESPONSE 0x03
178 #define L2CAP_CMD_CONFIG_REQUEST 0x04
179 #define L2CAP_CMD_CONFIG_RESPONSE 0x05
180 #define L2CAP_CMD_DISCONNECT_REQUEST 0x06
181 #define L2CAP_CMD_DISCONNECT_RESPONSE 0x07
182 #define L2CAP_CMD_INFORMATION_REQUEST 0x0A
183 #define L2CAP_CMD_INFORMATION_RESPONSE 0x0B
187 #define SUCCESSFUL 0x00
190 #define SDP_PSM 0x01 // Service Discovery Protocol PSM Value
191 #define RFCOMM_PSM 0x03 // RFCOMM PSM Value
192 #define HID_CTRL_PSM 0x11 // HID_Control PSM Value
193 #define HID_INTR_PSM 0x13 // HID_Interrupt PSM Value
196 #define SDP_SERVICE_SEARCH_REQUEST 0x02
197 #define SDP_SERVICE_SEARCH_RESPONSE 0x03
198 #define SDP_SERVICE_ATTRIBUTE_REQUEST 0x04
199 #define SDP_SERVICE_ATTRIBUTE_RESPONSE 0x05
200 #define SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST 0x06 // See the RFCOMM specs
201 #define SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE 0x07 // See the RFCOMM specs
202 #define PNP_INFORMATION_UUID 0x1200
203 #define SERIALPORT_UUID 0x1101 // See http://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm
204 #define L2CAP_UUID 0x0100
207 #define WI_SUBCLASS_RF 0x01 // RF Controller
208 #define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface
210 #define BTD_MAX_ENDPOINTS 4
211 #define BTD_NUM_SERVICES 4 // Max number of Bluetooth services - if you need more than 4 simply increase this number
245 uint8_t
Init(uint8_t parent, uint8_t port,
bool lowspeed);
289 virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) {
323 btService[i] = pService;
410 void L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow = 0x01, uint8_t channelHigh = 0x00);
572 uint8_t pollInterval;
573 bool simple_pairing_supported;
576 bool pairWiiUsingSync;
577 bool checkRemoteName;
578 bool incomingPSController;
579 uint8_t classOfDevice[3];
583 uint16_t hci_counter;
584 uint16_t hci_num_reset_loops;
585 uint16_t hci_event_flag;
586 uint8_t inquiry_counter;
590 uint8_t l2capoutbuf[14];
593 void HCI_event_task();
595 void ACL_event_task();
598 void setBdaddr(uint8_t* BDADDR);
599 void setMoveBdaddr(uint8_t* BDADDR);
615 virtual void Run() = 0;
617 virtual void Reset() = 0;
635 virtual void onInit() = 0;
639 return (buf[0] == (handle & 0xFF)) && (buf[1] == ((handle >> 8) | 0x20));
void hci_disconnect(uint16_t handle)
void hci_write_scan_disable()
static const uint8_t BTD_CONTROL_PIPE
void hci_write_local_name(const char *name)
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
void hci_accept_connection()
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
#define HCI_CHECK_DEVICE_SERVICE
void hci_read_local_version_information()
EpInfo epInfo[BTD_MAX_ENDPOINTS]
virtual bool DEVCLASSOK(uint8_t klass)
virtual void ACLData(uint8_t *ACLData)=0
int8_t registerBluetoothService(BluetoothService *pService)
#define IOGEAR_GBU521_PID
void hci_write_class_of_device()
virtual void disconnect()=0
void hci_read_local_extended_features(uint8_t page_number)
virtual uint8_t GetAddress()
#define USB_CLASS_WIRELESS_CTRL
void hci_user_confirmation_request_reply()
void HCI_Command(uint8_t *data, uint16_t nbytes)
#define BELKIN_F8T065BF_PID
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
void hci_pin_code_request_reply()
uint32_t l2cap_event_flag
static const uint8_t BTD_DATAIN_PIPE
void hci_write_scan_enable()
static const uint8_t BTD_DATAOUT_PIPE
uint8_t readPollInterval()
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
bool sdpConnectionClaimed
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
bool rfcommConnectionClaimed
void hci_pin_code_negative_request_reply()
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
#define PS3NAVIGATION_PID
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
#define BTD_MAX_ENDPOINTS
void attachOnInit(void(*funcOnInit)(void))
bool waitingForConnection
void hci_link_key_request_negative_reply()
void hci_inquiry_cancel()
void(* pFuncOnInit)(void)
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
bool checkHciHandle(uint8_t *buf, uint16_t handle)
static const uint8_t BTD_EVENT_PIPE
#define IOGEAR_GBU521_VID
void hci_set_event_mask()
void hci_authentication_request()
void hci_write_simple_pairing_mode(bool enable)
void hci_io_capability_request_reply()
bool l2capConnectionClaimed
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
#define BELKIN_F8T065BF_VID
uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)