honor the layer abstratctions

This commit is contained in:
matthias.ringwald 2009-05-17 20:32:14 +00:00
parent 319eaf1a7d
commit 16833f0a4e
4 changed files with 85 additions and 15 deletions

View File

@ -55,8 +55,9 @@ hci_cmd_t hci_host_buffer_size = {
};
static hci_transport_t * hci_transport;
static uint8_t * hci_cmd_buffer;
// the stack is here
static hci_stack_t hci_stack;
void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value){
buffer[pos] = value & 0xff;
@ -79,13 +80,45 @@ static void *hci_daemon_thread(void *arg){
}
#endif
/**
* Handler called by HCI transport
*/
static void dummy_handler(uint8_t *packet, int size){
}
static void acl_handler(uint8_t *packet, int size){
hci_stack.acl_packet_handler(packet, size);
}
static void event_handler(uint8_t *packet, int size){
hci_stack.event_packet_handler(packet, size);
}
/** Register L2CAP handlers */
void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, int size)){
hci_stack.event_packet_handler = handler;
}
void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, int size)){
hci_stack.acl_packet_handler = handler;
}
void hci_init(hci_transport_t *transport, void *config){
// reference to use transport layer implementation
hci_transport = transport;
hci_stack.hci_transport = transport;
// empty cmd buffer
hci_cmd_buffer = malloc(3+255);
hci_stack.hci_cmd_buffer = malloc(3+255);
// higher level handler
hci_stack.event_packet_handler = dummy_handler;
hci_stack.acl_packet_handler = dummy_handler;
// register packet handlers with transport
transport->register_event_packet_handler( event_handler);
transport->register_acl_packet_handler( acl_handler);
// open low-level device
transport->open(&config);
// open unix socket
@ -110,11 +143,16 @@ void hci_run(){
}
}
int hci_send_acl_packet(uint8_t *packet, int size){
return hci_transport->send_acl_packet(packet, size);
return hci_stack.hci_transport->send_acl_packet(packet, size);
}
int hci_send_cmd(hci_cmd_t *cmd, ...){
uint8_t * hci_cmd_buffer = hci_stack.hci_cmd_buffer;
hci_cmd_buffer[0] = cmd->opcode & 0xff;
hci_cmd_buffer[1] = cmd->opcode >> 8;
int pos = 3;
@ -171,5 +209,5 @@ int hci_send_cmd(hci_cmd_t *cmd, ...){
va_end(argptr);
hci_cmd_buffer[2] = pos - 3;
// send packet
return hci_transport->send_cmd_packet(hci_cmd_buffer, pos);
return hci_stack.hci_transport->send_cmd_packet(hci_cmd_buffer, pos);
}

View File

@ -53,10 +53,36 @@ typedef struct {
const char *format;
} hci_cmd_t;
typedef struct hci_connection {
struct hci_connection * next;
bd_addr_t address;
hci_con_handle_t con_handle;
} hci_connection_t;
typedef struct {
hci_transport_t * hci_transport;
uint8_t * hci_cmd_buffer;
hci_connection_t *connections;
/* host to controller flow control */
uint8_t num_cmd_packets;
uint8_t num_acl_packets;
/* callback to L2CAP layer */
void (*event_packet_handler)(uint8_t *packet, int size);
void (*acl_packet_handler) (uint8_t *packet, int size);
} hci_stack_t;
// set up HCI
void hci_init(hci_transport_t *transport, void *config);
void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, int size));
void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, int size));
// power control
int hci_power_control(HCI_POWER_MODE mode);
@ -72,6 +98,8 @@ int hci_send_cmd(hci_cmd_t *cmd, ...);
// send ACL packet
int hci_send_acl_packet(uint8_t *packet, int size);
// helper
extern void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value);

View File

@ -22,6 +22,14 @@ typedef enum {
INFORMATIONAL_RESPONSE
} L2CAP_SIGNALING_COMMANDS;
typedef struct {
} l2cap_channel_t;
typedef struct {
} l2cap_service_t;
void l2cap_init();
int l2cap_send_signaling_packet(hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, ...);

View File

@ -118,27 +118,23 @@ int main (int argc, const char * argv[]) {
// H4 UART
transport = &hci_h4_transport;
// Ancient Ericsson ROK 101 007 (ca. 2001)
config.device_name = argv[1];
config.baudrate = 57600;
config.flowcontrol = 1;
// open low-level device
transport->open(&config);
// init HCI
hci_init(transport, &config);
hci_power_control(HCI_POWER_ON);
// init L2CAP
l2cap_init();
//
// register callbacks
//
transport->register_event_packet_handler(&event_handler);
transport->register_acl_packet_handler(&acl_handler);
hci_register_event_packet_handler(&event_handler);
hci_register_acl_packet_handler(&acl_handler);
// init L2CAP
l2cap_init();
// get fd for select call
int transport_fd = transport->get_fd();