mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-19 08:42:55 +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.h"
|
||||||
#include "hci_dump.h"
|
#include "hci_dump.h"
|
||||||
|
|
||||||
// the stack is here
|
// the STACK is here
|
||||||
static hci_stack_t hci_stack;
|
static hci_stack_t hci_stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get link for given address
|
* get connection for given address
|
||||||
*
|
*
|
||||||
* @return connection OR NULL, if not found
|
* @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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,17 +181,17 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t hci_run(){
|
void hci_run(){
|
||||||
uint8_t micro_packet;
|
uint8_t micro_packet;
|
||||||
switch (hci_stack.state){
|
switch (hci_stack.state){
|
||||||
case HCI_STATE_INITIALIZING:
|
case HCI_STATE_INITIALIZING:
|
||||||
if (hci_stack.substate % 2) {
|
if (hci_stack.substate % 2) {
|
||||||
// odd: waiting for command completion
|
// odd: waiting for command completion
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
if (hci_stack.num_cmd_packets == 0) {
|
if (hci_stack.num_cmd_packets == 0) {
|
||||||
// cannot send command yet
|
// cannot send command yet
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
switch (hci_stack.substate/2){
|
switch (hci_stack.substate/2){
|
||||||
case 0:
|
case 0:
|
||||||
@ -200,9 +221,6 @@ uint32_t hci_run(){
|
|||||||
default:
|
default:
|
||||||
break;
|
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 <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hardware state of Bluetooth controller
|
||||||
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HCI_POWER_OFF = 0,
|
HCI_POWER_OFF = 0,
|
||||||
HCI_POWER_ON
|
HCI_POWER_ON
|
||||||
} HCI_POWER_MODE;
|
} HCI_POWER_MODE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State of BTstack
|
||||||
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HCI_STATE_OFF = 0,
|
HCI_STATE_OFF = 0,
|
||||||
HCI_STATE_INITIALIZING,
|
HCI_STATE_INITIALIZING,
|
||||||
@ -29,33 +34,45 @@ typedef enum {
|
|||||||
HCI_STATE_HALTING
|
HCI_STATE_HALTING
|
||||||
} HCI_STATE;
|
} HCI_STATE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection State
|
||||||
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SEND_NEGATIVE_LINK_KEY_REQUEST = 1 << 0,
|
SEND_NEGATIVE_LINK_KEY_REQUEST = 1 << 0,
|
||||||
SEND_PIN_CODE_RESPONSE = 1 << 1
|
SEND_PIN_CODE_RESPONSE = 1 << 1
|
||||||
} hci_connection_flags_t;
|
} hci_connection_flags_t;
|
||||||
|
|
||||||
typedef struct hci_connection {
|
typedef struct hci_connection {
|
||||||
// linked list
|
// linked list - assert: first field
|
||||||
struct hci_connection * next;
|
linked_item_t item;
|
||||||
|
|
||||||
// remote side
|
// remote side
|
||||||
bd_addr_t address;
|
bd_addr_t address;
|
||||||
|
|
||||||
|
// module handle
|
||||||
hci_con_handle_t con_handle;
|
hci_con_handle_t con_handle;
|
||||||
|
|
||||||
// hci state machine
|
// errands
|
||||||
hci_connection_flags_t flags;
|
hci_connection_flags_t flags;
|
||||||
|
|
||||||
} hci_connection_t;
|
} hci_connection_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main data structure
|
||||||
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// transport component with configuration
|
||||||
hci_transport_t * hci_transport;
|
hci_transport_t * hci_transport;
|
||||||
bt_control_t * control;
|
|
||||||
void * config;
|
void * config;
|
||||||
|
|
||||||
uint8_t * hci_cmd_buffer;
|
// hardware power controller
|
||||||
|
bt_control_t * control;
|
||||||
|
|
||||||
|
// list of existing baseband connections
|
||||||
hci_connection_t * connections;
|
hci_connection_t * connections;
|
||||||
|
|
||||||
|
// single buffer for HCI Command assembly
|
||||||
|
uint8_t * hci_cmd_buffer;
|
||||||
|
|
||||||
/* host to controller flow control */
|
/* host to controller flow control */
|
||||||
uint8_t num_cmd_packets;
|
uint8_t num_cmd_packets;
|
||||||
uint8_t num_acl_packets;
|
uint8_t num_acl_packets;
|
||||||
@ -71,7 +88,6 @@ typedef struct {
|
|||||||
|
|
||||||
} hci_stack_t;
|
} hci_stack_t;
|
||||||
|
|
||||||
|
|
||||||
// set up HCI
|
// set up HCI
|
||||||
void hci_init(hci_transport_t *transport, void *config, bt_control_t *control);
|
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
|
* 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
|
// create and send hci command packets based on a template and a list of parameters
|
||||||
int hci_send_cmd(hci_cmd_t *cmd, ...);
|
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
|
// send ACL packet
|
||||||
int hci_send_acl_packet(uint8_t *packet, int size);
|
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 bt_flip_addr(bd_addr_t dest, bd_addr_t src);
|
||||||
|
|
||||||
void hexdump(void *data, int size);
|
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