33 control_dcid[0] = 0x70;
34 control_dcid[1] = 0x00;
35 interrupt_dcid[0] = 0x71;
36 interrupt_dcid[1] = 0x00;
43 activeConnection =
false;
59 if((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_CTRL_PSM) {
62 activeConnection =
true;
70 if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) {
73 Notify(
PSTR(
"\r\nL2CAP Command Rejected - Reason: "), 0x80);
74 D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
76 D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
78 D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
80 D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
82 D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
84 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
87 if(((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) ==
SUCCESSFUL)) {
88 if(l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) {
94 }
else if(l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) {
104 Notify(
PSTR(
"\r\nL2CAP Connection Request - PSM: "), 0x80);
105 D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
107 D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
109 D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
111 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
113 D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
115 if((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_CTRL_PSM) {
120 }
else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_INTR_PSM) {
127 if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) {
128 if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
132 }
else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
139 if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
142 }
else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
147 if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
148 #ifdef DEBUG_USB_HOST
149 Notify(
PSTR(
"\r\nDisconnect Request: Control Channel"), 0x80);
154 }
else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
155 #ifdef DEBUG_USB_HOST
156 Notify(
PSTR(
"\r\nDisconnect Request: Interrupt Channel"), 0x80);
176 Notify(
PSTR(
"\r\nL2CAP Unknown Signaling Command: "), 0x80);
177 D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
180 }
else if(l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) {
183 for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
184 D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
188 if(l2capinbuf[8] == 0xA1) {
189 uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
192 switch(l2capinbuf[9]) {
195 pRptParser[
KEYBOARD_PARSER_ID]->
Parse(reinterpret_cast<USBHID *>(
this), 0, (uint8_t)(length - 2), &l2capinbuf[10]);
200 pRptParser[
MOUSE_PARSER_ID]->
Parse(reinterpret_cast<USBHID *>(
this), 0, (uint8_t)(length - 2), &l2capinbuf[10]);
204 Notify(
PSTR(
"\r\nUnknown Report type: "), 0x80);
205 D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
210 }
else if(l2capinbuf[6] == control_dcid[0] && l2capinbuf[7] == control_dcid[1]) {
213 for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
214 D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
221 Notify(
PSTR(
"\r\nUnsupported L2CAP Data - Channel ID: "), 0x80);
222 D_PrintHex<uint8_t > (l2capinbuf[7], 0x80);
224 D_PrintHex<uint8_t > (l2capinbuf[6], 0x80);
228 for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
229 D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
238 void BTHID::L2CAP_task() {
239 switch(l2cap_state) {
243 #ifdef DEBUG_USB_HOST
244 Notify(
PSTR(
"\r\nHID Control Successfully Configured"), 0x80);
253 #ifdef DEBUG_USB_HOST
254 Notify(
PSTR(
"\r\nHID Interrupt Incoming Connection Request"), 0x80);
270 #ifdef DEBUG_USB_HOST
271 Notify(
PSTR(
"\r\nSend HID Control Config Request"), 0x80);
283 #ifdef DEBUG_USB_HOST
284 Notify(
PSTR(
"\r\nSend HID Interrupt Connection Request"), 0x80);
294 #ifdef DEBUG_USB_HOST
295 Notify(
PSTR(
"\r\nSend HID Interrupt Config Request"), 0x80);
305 #ifdef DEBUG_USB_HOST
306 Notify(
PSTR(
"\r\nHID Channels Established"), 0x80);
321 #ifdef DEBUG_USB_HOST
322 Notify(
PSTR(
"\r\nDisconnected Interrupt Channel"), 0x80);
332 #ifdef DEBUG_USB_HOST
333 Notify(
PSTR(
"\r\nDisconnected Control Channel"), 0x80);
345 switch(l2cap_state) {
349 activeConnection =
true;
350 #ifdef DEBUG_USB_HOST
351 Notify(
PSTR(
"\r\nSend HID Control Connection Request"), 0x80);
359 #ifdef DEBUG_USB_HOST
360 Notify(
PSTR(
"\r\nHID Control Incoming Connection Request"), 0x80);
378 void BTHID::setProtocol() {
379 #ifdef DEBUG_USB_HOST
380 Notify(
PSTR(
"\r\nSet protocol mode: "), 0x80);
381 D_PrintHex<uint8_t > (protocolMode, 0x80);
384 #ifdef DEBUG_USB_HOST
385 Notify(
PSTR(
"\r\nNot a valid protocol mode. Using Boot protocol instead."), 0x80);
389 uint8_t command = 0x70 | protocolMode;
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
#define L2CAP_INTERRUPT_CONFIG_REQUEST
#define L2CAP_INTERRUPT_SETUP
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
void ACLData(uint8_t *ACLData)
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
uint8_t interrupt_scid[2]
#define L2CAP_CONTROL_SUCCESS
virtual void ResetBTHID()
#define L2CAP_CONTROL_CONFIG_REQUEST
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
#define L2CAP_CONTROL_CONNECT_REQUEST
void hci_disconnect(uint16_t handle)
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
virtual void ParseBTHIDData(uint8_t len, uint8_t *buf)
#define l2cap_check_flag(flag)
#define L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_FLAG_CONTROL_CONNECTED
#define L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CONTROL_DISCONNECT
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
bool l2capConnectionClaimed
#define L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
void setLeds(struct KBDLEDS data)
#define KEYBOARD_PARSER_ID
#define USB_HID_BOOT_PROTOCOL
uint32_t l2cap_event_flag
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
#define L2CAP_FLAG_INTERRUPT_CONNECTED
#define l2cap_set_flag(flag)
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
#define L2CAP_CMD_CONNECTION_REQUEST
virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)=0
BTHID(BTD *p, bool pair=false, const char *pin="0000")
bool checkHciHandle(uint8_t *buf, uint16_t handle)
#define L2CAP_INTERRUPT_CONNECT_REQUEST
#define L2CAP_INTERRUPT_DISCONNECT
#define L2CAP_CMD_COMMAND_REJECT