From c61d85f6278a2a82b3aedbc333ae045c019c877b Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sat, 30 Apr 2011 20:33:19 +0000 Subject: [PATCH] revert accidental commit --- example/l2cap-server.c | 149 +++++++---------------------------------- example/test.c | 22 ++++-- 2 files changed, 39 insertions(+), 132 deletions(-) diff --git a/example/l2cap-server.c b/example/l2cap-server.c index ec7dc0221..4e44a07f6 100644 --- a/example/l2cap-server.c +++ b/example/l2cap-server.c @@ -49,83 +49,6 @@ hci_con_handle_t con_handle; uint16_t hid_control = 0; uint16_t hid_interrupt = 0; -uint8_t sdp_response_0100[] = { - 0x07, 0x00, 0x00, 0x00, 0x7B, 0x00, 0x76, 0x36, 0x01, 0xD7, - 0x36, 0x01, 0x7F, 0x09, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, - 0x00, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, 0x11, 0x24, 0x09, - 0x00, 0x04, 0x35, 0x0D, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, - 0x00, 0x11, 0x35, 0x03, 0x19, 0x00, 0x11, 0x09, 0x00, 0x05, - 0x35, 0x03, 0x19, 0x10, 0x02, 0x09, 0x00, 0x06, 0x35, 0x09, - 0x09, 0x65, 0x6E, 0x09, 0x00, 0x6A, 0x09, 0x01, 0x00, 0x09, - 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, 0x24, 0x09, - 0x01, 0x00, 0x09, 0x00, 0x0D, 0x35, 0x0F, 0x35, 0x0D, 0x35, - 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x13, 0x35, 0x03, 0x19, - 0x00, 0x11, 0x09, 0x01, 0x00, 0x25, 0x20, 0x42, 0x72, 0x6F, - 0x61, 0x64, 0x63, 0x6F, 0x6D, 0x20, 0x42, 0x6C, 0x75, 0x65, - 0x74, 0x6F, 0x6F, 0x74, 0x68, 0x02, 0x00, 0x76 -}; -uint8_t sdp_response_0100_0076[] = { - 0x07, 0x00, 0x01, 0x00, 0x7B, 0x00, 0x76, 0x20, 0x44, 0x65, - 0x6D, 0x6F, 0x20, 0x4B, 0x65, 0x79, 0x62, 0x6F, 0x61, 0x72, - 0x64, 0x09, 0x01, 0x01, 0x25, 0x08, 0x4B, 0x65, 0x79, 0x62, - 0x6F, 0x61, 0x72, 0x64, 0x09, 0x01, 0x02, 0x25, 0x0E, 0x42, - 0x72, 0x6F, 0x61, 0x64, 0x63, 0x6F, 0x6D, 0x20, 0x43, 0x6F, - 0x72, 0x70, 0x2E, 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, - 0x02, 0x01, 0x09, 0x01, 0x11, 0x09, 0x02, 0x02, 0x08, 0x40, - 0x09, 0x02, 0x03, 0x08, 0x33, 0x09, 0x02, 0x04, 0x28, 0x01, - 0x09, 0x02, 0x05, 0x28, 0x01, 0x09, 0x02, 0x06, 0x35, 0x9F, - 0x35, 0x9D, 0x08, 0x22, 0x25, 0x99, 0x05, 0x01, 0x09, 0x06, - 0xA1, 0x01, 0x85, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29, 0xE7, - 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, - 0x95, 0x01, 0x75, 0x08, 0x81, 0x02, 0x00, 0xEC -}; -uint8_t sdp_response_0100_00EC[] = { - 0x07, 0x00, 0x02, 0x00, 0x7B, 0x00, 0x76, 0x01, 0x95, 0x05, - 0x75, 0x01, 0x05, 0x08, 0x19, 0x01, 0x29, 0x05, 0x91, 0x02, - 0x95, 0x01, 0x75, 0x03, 0x91, 0x01, 0x95, 0x06, 0x75, 0x08, - 0x15, 0x00, 0x25, 0x65, 0x05, 0x07, 0x19, 0x00, 0x29, 0x65, - 0x81, 0x00, 0xC0, 0x05, 0x0C, 0x09, 0x01, 0xA1, 0x01, 0x85, - 0x02, 0x19, 0x00, 0x29, 0xFF, 0x15, 0x00, 0x25, 0xFF, 0x75, - 0x08, 0x95, 0x01, 0x81, 0x00, 0xC0, 0x05, 0x0C, 0x09, 0x01, - 0xA1, 0x01, 0x85, 0x05, 0x05, 0x01, 0x09, 0x06, 0xA1, 0x02, - 0x05, 0x06, 0x09, 0x20, 0x15, 0x00, 0x25, 0xFF, 0x75, 0x08, - 0x95, 0x08, 0x81, 0x00, 0x09, 0x20, 0x15, 0x00, 0x25, 0xFF, - 0x75, 0x08, 0x95, 0x08, 0xB1, 0x00, 0xC0, 0x05, 0x0C, 0x09, - 0x01, 0xA1, 0x01, 0x85, 0x06, 0x19, 0x00, 0x29, 0xFE, 0x15, - 0x00, 0x25, 0xFF, 0x75, 0x08, 0x02, 0x01, 0x62 -}; -uint8_t sdp_response_0100_0162[] = { - 0x07, 0x00, 0x03, 0x00, 0x7B, 0x00, 0x76, 0x95, 0x02, 0x81, - 0x00, 0xC0, 0xC0, 0x09, 0x02, 0x07, 0x35, 0x08, 0x35, 0x06, - 0x09, 0x03, 0x09, 0x09, 0x01, 0x00, 0x09, 0x02, 0x0B, 0x09, - 0x01, 0x00, 0x09, 0x02, 0x0D, 0x28, 0x00, 0x09, 0x02, 0x0E, - 0x28, 0x01, 0x36, 0x00, 0x52, 0x09, 0x00, 0x00, 0x0A, 0x00, - 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, 0x12, - 0x00, 0x09, 0x00, 0x04, 0x35, 0x0D, 0x35, 0x06, 0x19, 0x01, - 0x00, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, 0x00, 0x01, 0x09, - 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x12, 0x00, 0x09, - 0x01, 0x00, 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, 0x02, - 0x01, 0x09, 0x0A, 0x5C, 0x09, 0x02, 0x02, 0x09, 0x20, 0x01, - 0x09, 0x02, 0x03, 0x09, 0x01, 0x07, 0x09, 0x02, 0x04, 0x28, - 0x01, 0x09, 0x02, 0x05, 0x09, 0x02, 0x01, 0xD8 -}; -uint8_t sdp_response_0100_01D8[] = { - 0x07, 0x00, 0x04, 0x00, 0x05, 0x00, 0x02, 0x00, 0x02, 0x00 -}; - -uint8_t sdp_response_1200[] = { - 0x07, 0x00, 0x01, 0x00, 0x5B, 0x00, 0x58, 0x36, 0x00, 0x55, - 0x36, 0x00, 0x52, 0x09, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, - 0x01, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, 0x12, 0x00, 0x09, - 0x00, 0x04, 0x35, 0x0D, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, - 0x00, 0x01, 0x35, 0x03, 0x19, 0x00, 0x01, 0x09, 0x00, 0x09, - 0x35, 0x08, 0x35, 0x06, 0x19, 0x12, 0x00, 0x09, 0x01, 0x00, - 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, 0x02, 0x01, 0x09, - 0x0A, 0x5C, 0x09, 0x02, 0x02, 0x09, 0x20, 0x01, 0x09, 0x02, - 0x03, 0x09, 0x01, 0x07, 0x09, 0x02, 0x04, 0x28, 0x01, 0x09, - 0x02, 0x05, 0x09, 0x00, 0x02, 0x00 -}; - void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ bd_addr_t event_addr; @@ -135,53 +58,13 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint uint16_t remote_cid; char pin[20]; int i; - uint16_t UUID; - uint16_t cont = 0; - uint8_t * response; - uint16_t len; + switch (packet_type) { case L2CAP_DATA_PACKET: - // - if (packet[0] != 0x06) return; // no sdp request - UUID = packet[8] << 8 | packet [9]; - switch (UUID) { - case 0x0100: - if (packet[19]){ - cont = packet[20] << 8 | packet [21]; - } - switch (cont) { - case 0: - response = sdp_response_0100; - len = sizeof(sdp_response_0100); - break; - case 0x0076: - response = sdp_response_0100_0076; - len = sizeof(sdp_response_0100_0076); - break; - case 0x00EC: - response = sdp_response_0100_00EC; - len = sizeof(sdp_response_0100_00EC); - break; - case 0x0162: - response = sdp_response_0100_0162; - len = sizeof(sdp_response_0100_0162); - break; - case 0x01d8: - response = sdp_response_0100_01D8; - len = sizeof(sdp_response_0100_01D8); - break; - } - memcpy(response+1, &packet[1], 2); - bt_send_l2cap( channel, response, len); - printf("answering 0100 request, cont %u\n", cont); - break; - case 0x1200: - memcpy(sdp_response_1200+1, &packet[1], 2); - bt_send_l2cap( channel, sdp_response_1200, sizeof(sdp_response_1200)); - printf("answering 1200 request\n"); - break; - } + // just dump data for now + printf("source cid %x -- ", channel); + hexdump( packet, size ); break; case HCI_EVENT_PACKET: @@ -223,7 +106,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint break; case HCI_EVENT_PIN_CODE_REQUEST: -/* // inform about pin code request + // inform about pin code request printf("Please enter PIN here: "); fgets(pin, 20, stdin); i = strlen(pin)-1; @@ -231,8 +114,6 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint pin[i] = '\0'; } printf("PIN = '%s'\n", pin); - */ - strcpy(pin, "0000"); bt_flip_addr(event_addr, &packet[2]); bt_send_cmd(&hci_pin_code_request_reply, &event_addr, strlen(pin), pin); break; @@ -248,6 +129,16 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint print_bd_addr(event_addr); printf(", handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n", handle, psm, local_cid, READ_BT_16(packet, 15)); + + if (psm == PSM_HID_CONTROL){ + hid_control = local_cid; + } + if (psm == PSM_HID_INTERRUPT){ + hid_interrupt = local_cid; + } + if (hid_control && hid_interrupt){ + bt_send_cmd(&hci_switch_role_command, &event_addr, 0); + } } else { printf("L2CAP connection to device "); print_bd_addr(event_addr); @@ -255,7 +146,14 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint exit(1); } break; - + + case HCI_EVENT_ROLE_CHANGE: { + //HID Control: 0x06 bytes - SET_FEATURE_REPORT [ 53 F4 42 03 00 00 ] + uint8_t set_feature_report[] = { 0x53, 0xf4, 0x42, 0x03, 0x00, 0x00}; + bt_send_l2cap(hid_control, (uint8_t*) &set_feature_report, sizeof(set_feature_report)); + break; + } + case HCI_EVENT_DISCONNECTION_COMPLETE: // connection closed -> quit tes app printf("Basebank connection closed\n"); @@ -287,7 +185,6 @@ int main (int argc, const char * argv[]){ return err; } bt_register_packet_handler(packet_handler); - bt_send_cmd(&l2cap_register_service, PSM_SDP, 250); bt_send_cmd(&l2cap_register_service, PSM_HID_CONTROL, 250); bt_send_cmd(&l2cap_register_service, PSM_HID_INTERRUPT, 250); diff --git a/example/test.c b/example/test.c index 5dfd36c75..3b6ec2bdd 100644 --- a/example/test.c +++ b/example/test.c @@ -45,8 +45,7 @@ // bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard // bd_addr_t addr = {0x00, 0x19, 0x1d, 0x90, 0x44, 0x68 }; // WiiMote -// bd_addr_t addr = {0x76, 0x6d, 0x62, 0xdb, 0xca, 0x73 }; // iPad -bd_addr_t addr = {0x00, 0x06, 0x66, 0x42, 0x16, 0xf5 }; // iControlPad-16f5 +bd_addr_t addr = {0x76, 0x6d, 0x62, 0xdb, 0xca, 0x73 }; // iPad hci_con_handle_t con_handle; uint16_t source_cid_interrupt; @@ -62,6 +61,16 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint // just dump data for now printf("source cid %x -- ", channel); hexdump( packet, size ); + + // HOME => disconnect + if (packet[0] == 0xA1) { // Status report + if (packet[1] == 0x30 || packet[1] == 0x31) { // type 0x30 or 0x31 + if (packet[3] & 0x080) { // homne button pressed + printf("Disconnect baseband\n"); + bt_send_cmd(&hci_disconnect, con_handle, 0x13); // remote closed connection + } + } + } break; case HCI_EVENT_PACKET: @@ -76,7 +85,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint case BTSTACK_EVENT_STATE: // bt stack activated, get started - disable pairing if (packet[2] == HCI_STATE_WORKING) { - bt_send_cmd(&hci_write_authentication_enable, 1); + bt_send_cmd(&hci_write_authentication_enable, 0); } break; @@ -91,7 +100,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint // inform about pin code request printf("Please enter PIN 0000 on remote device\n"); bt_flip_addr(event_addr, &packet[2]); - bt_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "1234"); + bt_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000"); break; case L2CAP_EVENT_CHANNEL_OPENED: @@ -109,6 +118,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint if (psm == 0x13) { source_cid_interrupt = source_cid; + // interupt channel openedn succesfully, now open control channel, too. + bt_send_cmd(&l2cap_create_channel, event_addr, 0x11); } else { source_cid_control = source_cid; // request acceleration data.. @@ -117,7 +128,6 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint // stop blinking // uint8_t setLEDs[] = { 0x52, 0x11, 0x10 }; // bt_send_l2cap( source_cid, setLEDs, sizeof(setLEDs)); - bt_send_cmd(&l2cap_create_channel, event_addr, 0x13); } } else { printf("L2CAP connection to device "); @@ -136,7 +146,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint case HCI_EVENT_COMMAND_COMPLETE: // connect to HID device (PSM 0x13) at addr if ( COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable) ) { - bt_send_cmd(&l2cap_create_channel, addr, 0x11); + bt_send_cmd(&l2cap_create_channel, addr, 0x13); printf("Press 1+2 on WiiMote to make it discoverable - Press HOME to disconnect later :)\n"); } break;