From e2edc0c3988319f94f2d3706299f4e9ebe388b1d Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 25 Jul 2010 15:11:33 +0000 Subject: [PATCH] read buffer size on hci init --- include/btstack/hci_cmds.h | 1 + src/hci.c | 27 +++++++++++++++++++++------ src/hci.h | 4 +++- src/hci_cmds.c | 11 ++++++++--- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/btstack/hci_cmds.h b/include/btstack/hci_cmds.h index 0437c607d..852562b64 100644 --- a/include/btstack/hci_cmds.h +++ b/include/btstack/hci_cmds.h @@ -209,6 +209,7 @@ extern hci_cmd_t hci_pin_code_request_reply; extern hci_cmd_t hci_pin_code_request_negative_reply; extern hci_cmd_t hci_qos_setup; extern hci_cmd_t hci_read_bd_addr; +extern hci_cmd_t hci_read_buffer_size; extern hci_cmd_t hci_read_link_policy_settings; extern hci_cmd_t hci_read_link_supervision_timeout; extern hci_cmd_t hci_remote_name_request; diff --git a/src/hci.c b/src/hci.c index 6f72e29d6..5b2d234a7 100644 --- a/src/hci.c +++ b/src/hci.c @@ -257,12 +257,24 @@ static void event_handler(uint8_t *packet, int size){ hci_con_handle_t handle; hci_connection_t * conn; + // get num_cmd_packets + if (packet[0] == HCI_EVENT_COMMAND_COMPLETE || packet[0] == HCI_EVENT_COMMAND_STATUS){ + // Get Num_HCI_Command_Packets + hci_stack.num_cmd_packets = packet[2]; + } + switch (packet[0]) { case HCI_EVENT_COMMAND_COMPLETE: - case HCI_EVENT_COMMAND_STATUS: - // Get Num_HCI_Command_Packets - hci_stack.num_cmd_packets = packet[2]; + if (COMMAND_COMPLETE_EVENT(packet, hci_read_buffer_size)){ + // from offset 5 + // status + hci_stack.acl_data_packet_length = READ_BT_16(packet, 6); + // SCO data packet len (8) + hci_stack.total_num_acl_packets = packet[9]; + // total num SCO packets + log_dbg("hci_read_buffer_size: size %u, count %u\n", hci_stack.acl_data_packet_length, hci_stack.total_num_acl_packets); + } break; case HCI_EVENT_CONNECTION_REQUEST: @@ -462,14 +474,17 @@ void hci_run(){ case 1: hci_send_cmd(&hci_read_bd_addr); break; - case 2: + case 2: + hci_send_cmd(&hci_read_buffer_size); + break; + case 3: // ca. 15 sec hci_send_cmd(&hci_write_page_timeout, 0x6000); break; - case 3: + case 4: hci_send_cmd(&hci_write_scan_enable, 3); // 3 inq scan + page scan break; - case 4: + case 5: // done. hci_stack.state = HCI_STATE_WORKING; hci_emit_state(); diff --git a/src/hci.h b/src/hci.h index e6b09e180..1eaf80b67 100644 --- a/src/hci.h +++ b/src/hci.h @@ -189,7 +189,9 @@ typedef struct { /* host to controller flow control */ uint8_t num_cmd_packets; - uint8_t num_acl_packets; + // uint8_t total_num_cmd_packets; + uint8_t total_num_acl_packets; + uint16_t acl_data_packet_length; /* callback to L2CAP layer */ void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size); diff --git a/src/hci_cmds.c b/src/hci_cmds.c index b85108c20..3e4316fb6 100644 --- a/src/hci_cmds.c +++ b/src/hci_cmds.c @@ -238,7 +238,7 @@ OPCODE(OGF_LINK_POLICY, 0x0c), "H" }; hci_cmd_t hci_write_link_policy_settings = { OPCODE(OGF_LINK_POLICY, 0x0d), "H2" -// handlee, settings +// handle, settings }; /** @@ -296,19 +296,24 @@ hci_cmd_t hci_write_extended_inquiry_response = { OPCODE(OGF_CONTROLLER_BASEBAND, 0x52), "1E" // FEC_Required, Exstended Inquiry Response }; - hci_cmd_t hci_write_simple_pairing_mode = { OPCODE(OGF_CONTROLLER_BASEBAND, 0x56), "1" // mode: 0 = off, 1 = on }; +/** + * Informational Parameters + */ +hci_cmd_t hci_read_buffer_size = { +OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x05), "" +// no params +}; hci_cmd_t hci_read_bd_addr = { OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x09), "" // no params }; // BTstack commands - hci_cmd_t btstack_get_state = { OPCODE(OGF_BTSTACK, BTSTACK_GET_STATE), "" // no params ->