From 06b35ec0015cf46daef32b3a848db95b5ef89e2c Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Fri, 24 Jul 2009 20:17:46 +0000 Subject: [PATCH] added functions to get connectinon_t for a given connection handle or a bd_addr --- src/hci.c | 36 +++++++++++++++++++++++++++--------- src/hci.h | 40 ++++++++++++++++++++++++++++------------ src/utils.h | 2 ++ 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/hci.c b/src/hci.c index ec9168643..5d564681e 100644 --- a/src/hci.c +++ b/src/hci.c @@ -12,15 +12,36 @@ #include "hci.h" #include "hci_dump.h" -// the stack is here +// the STACK is here static hci_stack_t hci_stack; /** - * get link for given address + * get connection for given address * * @return connection OR NULL, if not found */ -static hci_connection_t *link_for_addr(bd_addr_t addr){ +static hci_connection_t *link_for_addr(bd_addr_t address){ + linked_item_t *it; + for (it = (linked_item_t *) hci_stack.connections; it ; it = it->next){ + if ( ! BD_ADDR_CMP( ((hci_connection_t *) it)->address, address) ){ + return (hci_connection_t *) it; + } + } + return NULL; +} + +/** + * get connection for a given handle + * + * @return connection OR NULL, if not found + */ +static hci_connection_t *link_for_handle(hci_con_handle_t con_handle){ + linked_item_t *it; + for (it = (linked_item_t *) hci_stack.connections; it ; it = it->next){ + if ( ((hci_connection_t *) it)->con_handle == con_handle){ + return (hci_connection_t *) it; + } + } return NULL; } @@ -160,17 +181,17 @@ int hci_power_control(HCI_POWER_MODE power_mode){ return 0; } -uint32_t hci_run(){ +void hci_run(){ uint8_t micro_packet; switch (hci_stack.state){ case HCI_STATE_INITIALIZING: if (hci_stack.substate % 2) { // odd: waiting for command completion - return 0; + return; } if (hci_stack.num_cmd_packets == 0) { // cannot send command yet - return 0; + return; } switch (hci_stack.substate/2){ case 0: @@ -200,9 +221,6 @@ uint32_t hci_run(){ default: break; } - - // don't check for timetous yet - return 0; } diff --git a/src/hci.h b/src/hci.h index a6adb6989..ed818cfd0 100644 --- a/src/hci.h +++ b/src/hci.h @@ -16,12 +16,17 @@ #include #include - +/** + * Hardware state of Bluetooth controller + */ typedef enum { HCI_POWER_OFF = 0, HCI_POWER_ON } HCI_POWER_MODE; +/** + * State of BTstack + */ typedef enum { HCI_STATE_OFF = 0, HCI_STATE_INITIALIZING, @@ -29,32 +34,44 @@ typedef enum { HCI_STATE_HALTING } HCI_STATE; +/** + * Connection State + */ typedef enum { SEND_NEGATIVE_LINK_KEY_REQUEST = 1 << 0, SEND_PIN_CODE_RESPONSE = 1 << 1 } hci_connection_flags_t; typedef struct hci_connection { - // linked list - struct hci_connection * next; + // linked list - assert: first field + linked_item_t item; // remote side bd_addr_t address; + + // module handle hci_con_handle_t con_handle; - // hci state machine + // errands hci_connection_flags_t flags; - } hci_connection_t; - +/** + * main data structure + */ typedef struct { + // transport component with configuration hci_transport_t * hci_transport; - bt_control_t * control; void * config; - uint8_t * hci_cmd_buffer; + // hardware power controller + bt_control_t * control; + + // list of existing baseband connections hci_connection_t * connections; + + // single buffer for HCI Command assembly + uint8_t * hci_cmd_buffer; /* host to controller flow control */ uint8_t num_cmd_packets; @@ -71,7 +88,6 @@ typedef struct { } hci_stack_t; - // set up HCI void hci_init(hci_transport_t *transport, void *config, bt_control_t *control); @@ -84,10 +100,8 @@ int hci_power_control(HCI_POWER_MODE mode); /** * run the hci daemon loop once - * - * @return 0 or next timeout */ -uint32_t hci_run(); +void hci_run(); // create and send hci command packets based on a template and a list of parameters int hci_send_cmd(hci_cmd_t *cmd, ...); @@ -97,3 +111,5 @@ int hci_send_cmd_packet(uint8_t *packet, int size); // send ACL packet int hci_send_acl_packet(uint8_t *packet, int size); + +// \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index 5447c4b10..3e25a5db0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -37,3 +37,5 @@ void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value); void bt_flip_addr(bd_addr_t dest, bd_addr_t src); void hexdump(void *data, int size); + +#define BD_ADDR_CMP(a,b) memcmp(a,b, BD_ADDR_LEN)