mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-15 23:42:52 +00:00
added functions to get connectinon_t for a given connection handle or a bd_addr
This commit is contained in:
parent
397b7985a6
commit
06b35ec001
36
src/hci.c
36
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;
|
||||
}
|
||||
|
||||
|
||||
|
40
src/hci.h
40
src/hci.h
@ -16,12 +16,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
//
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user