use single packet handler per protocol layer: hci

This commit is contained in:
matthias.ringwald 2010-07-18 16:30:16 +00:00
parent 10e830c982
commit 2718e2e7a1
4 changed files with 32 additions and 30 deletions

View File

@ -139,7 +139,7 @@ static int nr_hci_connections(){
/** /**
* Dummy handler called by HCI * Dummy handler called by HCI
*/ */
static void dummy_handler(uint8_t *packet, uint16_t size){ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
} }
/** /**
@ -208,7 +208,7 @@ static void acl_handler(uint8_t *packet, int size){
// forward complete L2CAP packet if complete. // forward complete L2CAP packet if complete.
if (conn->acl_recombination_pos >= conn->acl_recombination_length + 4 + 4){ // pos already incl. ACL header if (conn->acl_recombination_pos >= conn->acl_recombination_length + 4 + 4){ // pos already incl. ACL header
hci_stack.acl_packet_handler(conn->acl_recombination_buffer, conn->acl_recombination_pos); hci_stack.packet_handler(HCI_ACL_DATA_PACKET, conn->acl_recombination_buffer, conn->acl_recombination_pos);
// reset recombination buffer // reset recombination buffer
conn->acl_recombination_length = 0; conn->acl_recombination_length = 0;
conn->acl_recombination_pos = 0; conn->acl_recombination_pos = 0;
@ -230,7 +230,7 @@ static void acl_handler(uint8_t *packet, int size){
if (acl_length >= l2cap_length + 4){ if (acl_length >= l2cap_length + 4){
// forward fragment as L2CAP packet // forward fragment as L2CAP packet
hci_stack.acl_packet_handler(packet, acl_length + 4); hci_stack.packet_handler(HCI_ACL_DATA_PACKET, packet, acl_length + 4);
} else { } else {
// store first fragment and tweak acl length for complete package // store first fragment and tweak acl length for complete package
@ -346,7 +346,7 @@ static void event_handler(uint8_t *packet, int size){
} }
} }
hci_stack.event_packet_handler(packet, size); hci_stack.packet_handler(HCI_EVENT_PACKET, packet, size);
// execute main loop // execute main loop
hci_run(); hci_run();
@ -366,11 +366,8 @@ void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
} }
/** Register HCI packet handlers */ /** Register HCI packet handlers */
void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, uint16_t size)){ void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
hci_stack.event_packet_handler = handler; hci_stack.packet_handler = handler;
}
void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, uint16_t size)){
hci_stack.acl_packet_handler = handler;
} }
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){
@ -395,8 +392,7 @@ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){
hci_stack.hci_cmd_buffer = malloc(3+255); hci_stack.hci_cmd_buffer = malloc(3+255);
// higher level handler // higher level handler
hci_stack.event_packet_handler = dummy_handler; hci_stack.packet_handler = dummy_handler;
hci_stack.acl_packet_handler = dummy_handler;
// register packet handlers with transport // register packet handlers with transport
transport->register_packet_handler(&packet_handler); transport->register_packet_handler(&packet_handler);
@ -549,7 +545,7 @@ void hci_emit_state(){
event[1] = len - 3; event[1] = len - 3;
event[2] = hci_stack.state; event[2] = hci_stack.state;
hci_dump_packet( HCI_EVENT_PACKET, 0, event, len); hci_dump_packet( HCI_EVENT_PACKET, 0, event, len);
hci_stack.event_packet_handler(event, len); hci_stack.packet_handler(HCI_EVENT_PACKET, event, len);
} }
void hci_emit_connection_complete(hci_connection_t *conn){ void hci_emit_connection_complete(hci_connection_t *conn){
@ -563,7 +559,7 @@ void hci_emit_connection_complete(hci_connection_t *conn){
event[11] = 1; // ACL connection event[11] = 1; // ACL connection
event[12] = 0; // encryption disabled event[12] = 0; // encryption disabled
hci_dump_packet( HCI_EVENT_PACKET, 0, event, len); hci_dump_packet( HCI_EVENT_PACKET, 0, event, len);
hci_stack.event_packet_handler(event, len); hci_stack.packet_handler(HCI_EVENT_PACKET, event, len);
} }
void hci_emit_l2cap_check_timeout(hci_connection_t *conn){ void hci_emit_l2cap_check_timeout(hci_connection_t *conn){
@ -573,7 +569,7 @@ void hci_emit_l2cap_check_timeout(hci_connection_t *conn){
event[1] = len - 2; event[1] = len - 2;
bt_store_16(event, 2, conn->con_handle); bt_store_16(event, 2, conn->con_handle);
hci_dump_packet( HCI_EVENT_PACKET, 0, event, len); hci_dump_packet( HCI_EVENT_PACKET, 0, event, len);
hci_stack.event_packet_handler(event, len); hci_stack.packet_handler(HCI_EVENT_PACKET, event, len);
} }
void hci_emit_nr_connections_changed(){ void hci_emit_nr_connections_changed(){
@ -583,7 +579,7 @@ void hci_emit_nr_connections_changed(){
event[1] = len - 2; event[1] = len - 2;
event[2] = nr_hci_connections(); event[2] = nr_hci_connections();
hci_dump_packet( HCI_EVENT_PACKET, 0, event, len); hci_dump_packet( HCI_EVENT_PACKET, 0, event, len);
hci_stack.event_packet_handler(event, len); hci_stack.packet_handler(HCI_EVENT_PACKET, event, len);
} }
void hci_emit_hci_open_failed(){ void hci_emit_hci_open_failed(){
@ -592,7 +588,7 @@ void hci_emit_hci_open_failed(){
event[0] = BTSTACK_EVENT_POWERON_FAILED; event[0] = BTSTACK_EVENT_POWERON_FAILED;
event[1] = len - 2; event[1] = len - 2;
hci_dump_packet( HCI_EVENT_PACKET, 0, event, len); hci_dump_packet( HCI_EVENT_PACKET, 0, event, len);
hci_stack.event_packet_handler(event, len); hci_stack.packet_handler(HCI_EVENT_PACKET, event, len);
} }
@ -605,7 +601,7 @@ void hci_emit_btstack_version() {
event[len++] = BTSTACK_MINOR; event[len++] = BTSTACK_MINOR;
bt_store_16(event, len, BTSTACK_REVISION); bt_store_16(event, len, BTSTACK_REVISION);
hci_dump_packet( HCI_EVENT_PACKET, 0, event, len); hci_dump_packet( HCI_EVENT_PACKET, 0, event, len);
hci_stack.event_packet_handler(event, len); hci_stack.packet_handler(HCI_EVENT_PACKET, event, len);
} }
void hci_emit_system_bluetooth_enabled(uint8_t enabled){ void hci_emit_system_bluetooth_enabled(uint8_t enabled){
@ -615,5 +611,5 @@ void hci_emit_system_bluetooth_enabled(uint8_t enabled){
event[1] = len - 2; event[1] = len - 2;
event[2] = enabled; event[2] = enabled;
hci_dump_packet( HCI_EVENT_PACKET, 0, event, len); hci_dump_packet( HCI_EVENT_PACKET, 0, event, len);
hci_stack.event_packet_handler(event, len); hci_stack.packet_handler(HCI_EVENT_PACKET, event, len);
} }

View File

@ -188,8 +188,7 @@ typedef struct {
uint8_t num_acl_packets; uint8_t num_acl_packets;
/* callback to L2CAP layer */ /* callback to L2CAP layer */
void (*event_packet_handler)(uint8_t *packet, uint16_t size); void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
void (*acl_packet_handler) (uint8_t *packet, uint16_t size);
/* hci state machine */ /* hci state machine */
HCI_STATE state; HCI_STATE state;
@ -204,10 +203,7 @@ uint16_t hci_create_cmd_internal(uint8_t *hci_cmd_buffer, hci_cmd_t *cmd, va_lis
// 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);
void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, uint16_t size));
void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, uint16_t size));
// power control // power control
int hci_power_control(HCI_POWER_MODE mode); int hci_power_control(HCI_POWER_MODE mode);

View File

@ -61,6 +61,7 @@
static void null_event_handler(connection_t * connection, uint8_t *packet, uint16_t size); static void null_event_handler(connection_t * connection, uint8_t *packet, uint16_t size);
static void null_data_handler(connection_t * connection, uint16_t local_cid, uint8_t *packet, uint16_t size); static void null_data_handler(connection_t * connection, uint16_t local_cid, uint8_t *packet, uint16_t size);
static void l2cap_packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size );
static uint8_t * sig_buffer = NULL; static uint8_t * sig_buffer = NULL;
static linked_list_t l2cap_channels = NULL; static linked_list_t l2cap_channels = NULL;
@ -78,10 +79,9 @@ void l2cap_init(){
acl_buffer = malloc( 400 + 8 ); acl_buffer = malloc( 400 + 8 );
// //
// register callbacks with HCI // register callback with HCI
// //
hci_register_event_packet_handler(&l2cap_event_handler); hci_register_packet_handler(&l2cap_packet_handler);
hci_register_acl_packet_handler(&l2cap_acl_handler);
} }
@ -678,6 +678,18 @@ void l2cap_acl_handler( uint8_t *packet, uint16_t size ){
} }
} }
static void l2cap_packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
switch (packet_type) {
case HCI_EVENT_PACKET:
l2cap_event_handler(packet, size);
break;
case HCI_ACL_DATA_PACKET:
l2cap_acl_handler(packet, size);
break;
default:
break;
}
}
// finalize closed channel // finalize closed channel
void l2cap_finialize_channel_close(l2cap_channel_t *channel){ void l2cap_finialize_channel_close(l2cap_channel_t *channel){

View File

@ -112,8 +112,6 @@ void l2cap_register_data_packet_handler(void (*handler)(connection_t * connectio
void l2cap_create_channel_internal(connection_t * connection, bd_addr_t address, uint16_t psm); void l2cap_create_channel_internal(connection_t * connection, bd_addr_t address, uint16_t psm);
void l2cap_disconnect_internal(uint16_t local_cid, uint8_t reason); void l2cap_disconnect_internal(uint16_t local_cid, uint8_t reason);
void l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len); void l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len);
void l2cap_acl_handler( uint8_t *packet, uint16_t size );
void l2cap_event_handler( uint8_t *packet, uint16_t size );
uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid); uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid);
void l2cap_set_capture_connection(connection_t * connection); void l2cap_set_capture_connection(connection_t * connection);