hci: use btstack_packet_handler_t for acl and sco callbacks

This commit is contained in:
Matthias Ringwald 2016-04-21 20:47:37 +02:00
parent 827ced6014
commit 3d50b4ba50
6 changed files with 47 additions and 32 deletions

View File

@ -595,7 +595,7 @@ static void send_sco_data(void){
if ((count & SCO_REPORT_PERIOD) == 0) printf("Sent %u\n", count);
}
static void sco_packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
static void sco_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){
switch (packet_type){
case HCI_EVENT_PACKET:
if (packet[0] == HCI_EVENT_SCO_CAN_SEND_NOW){

View File

@ -215,16 +215,26 @@ static void send_sco_data(void){
hci_request_sco_can_send_now_event();
static int count = 0;
count++;
if ((count & SCO_REPORT_PERIOD) == 0) printf("Sent %u\n", count);
if ((count & SCO_REPORT_PERIOD)) return;
printf("SCO packets sent: %u\n", count);
}
static void sco_packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
return;
static void sco_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){
static int count = 0;
count++;
if ((count & SCO_REPORT_PERIOD)) return;
printf("SCO packets %u\n", count);
switch (packet_type){
case HCI_EVENT_PACKET:
if (packet[0] == HCI_EVENT_SCO_CAN_SEND_NOW){
send_sco_data();
}
break;
case HCI_SCO_DATA_PACKET:
count++;
if ((count & SCO_REPORT_PERIOD)) return;
printf("SCO packets received: %u\n", count);
break;
default:
break;
}
}
static void packet_handler(uint8_t * event, uint16_t event_size){
@ -233,9 +243,6 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
if (event[2] != HCI_STATE_WORKING) break;
show_usage();
break;
case HCI_EVENT_SCO_CAN_SEND_NOW:
send_sco_data();
break;
case HCI_EVENT_HSP_META:
switch (event[2]) {
case HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE:

View File

@ -215,16 +215,24 @@ static void send_sco_data(void){
hci_request_sco_can_send_now_event();
static int count = 0;
count++;
if ((count & 15) == 0) printf("Sent %u\n", count);
if ((count & SCO_REPORT_PERIOD)) return;
printf("SCO packets sent: %u\n", count);
}
static void sco_packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t size){
static void sco_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){
static int count = 0;
// hexdumpf(packet, size);
count++;
if ((count & SCO_REPORT_PERIOD)) return;
printf("SCO packets %u\n", count);
switch (packet_type){
case HCI_EVENT_PACKET:
if (packet[0] == HCI_EVENT_SCO_CAN_SEND_NOW){
send_sco_data();
}
break;
default:
count++;
if ((count & SCO_REPORT_PERIOD)) return;
printf("SCO packets received: %u\n", count);
break;
}
}
static void packet_handler(uint8_t * event, uint16_t event_size){

View File

@ -1816,7 +1816,7 @@ static void event_handler(uint8_t *packet, int size){
static void sco_handler(uint8_t * packet, uint16_t size){
if (!hci_stack->sco_packet_handler) return;
hci_stack->sco_packet_handler(HCI_SCO_DATA_PACKET, packet, size);
hci_stack->sco_packet_handler(HCI_SCO_DATA_PACKET, 0, packet, size);
}
static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
@ -1844,14 +1844,14 @@ void hci_add_event_handler(btstack_packet_callback_registration_t * callback_han
/** Register HCI packet handlers */
void hci_register_acl_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
void hci_register_acl_packet_handler(btstack_packet_handler_t handler){
hci_stack->acl_packet_handler = handler;
}
/**
* @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles.
*/
void hci_register_sco_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
void hci_register_sco_packet_handler(btstack_packet_handler_t handler){
hci_stack->sco_packet_handler = handler;
}
@ -2930,7 +2930,7 @@ static void hci_emit_event(uint8_t * event, uint16_t size, int dump){
static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){
if (!hci_stack->acl_packet_handler) return;
hci_stack->acl_packet_handler(HCI_ACL_DATA_PACKET, packet, size);
hci_stack->acl_packet_handler(HCI_ACL_DATA_PACKET, 0, packet, size);
}
static void hci_notify_if_sco_can_send_now(void){
@ -2940,7 +2940,7 @@ static void hci_notify_if_sco_can_send_now(void){
hci_stack->sco_waiting_for_can_send_now = 0;
uint8_t event[2] = { HCI_EVENT_SCO_CAN_SEND_NOW, 0 };
hci_dump_packet(HCI_EVENT_PACKET, 1, event, sizeof(event));
hci_stack->sco_packet_handler(HCI_EVENT_PACKET, event, sizeof(event));
hci_stack->sco_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
}

View File

@ -519,10 +519,10 @@ typedef struct {
btstack_linked_list_t connections;
/* callback to L2CAP layer */
void (*acl_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
btstack_packet_handler_t acl_packet_handler;
/* callback for SCO data */
void (*sco_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
btstack_packet_handler_t sco_packet_handler;
/* callbacks for events */
btstack_linked_list_t event_handlers;
@ -720,12 +720,12 @@ void hci_add_event_handler(btstack_packet_callback_registration_t * callback_han
/**
* @brief Registers a packet handler for ACL data. Used by L2CAP
*/
void hci_register_acl_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
void hci_register_acl_packet_handler(btstack_packet_handler_t handler);
/**
* @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles.
*/
void hci_register_sco_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
void hci_register_sco_packet_handler(btstack_packet_handler_t handler);
// Sending HCI Commands

View File

@ -82,7 +82,7 @@ static void l2cap_emit_channel_closed(l2cap_channel_t *channel);
static void l2cap_emit_connection_request(l2cap_channel_t *channel);
static int l2cap_channel_ready_for_open(l2cap_channel_t *channel);
static void l2cap_hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static void l2cap_acl_handler(uint8_t packet_type, uint8_t *packet, uint16_t size );
static void l2cap_acl_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size );
static void l2cap_notify_channel_can_send(void);
typedef struct l2cap_fixed_channel {
@ -1381,7 +1381,7 @@ static void l2cap_signaling_handler_dispatch( hci_con_handle_t handle, uint8_t *
}
}
static void l2cap_acl_handler(uint8_t packet_type, uint8_t *packet, uint16_t size ){
static void l2cap_acl_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size ){
// Get Channel ID
uint16_t channel_id = READ_L2CAP_CHANNEL_ID(packet);
@ -1487,9 +1487,9 @@ static void l2cap_acl_handler(uint8_t packet_type, uint8_t *packet, uint16_t siz
default: {
// Find channel for this channel_id and connection handle
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(channel_id);
l2cap_channel_t * l2cap_channel = l2cap_get_channel_for_local_cid(channel_id);
if (channel) {
l2cap_dispatch_to_channel(channel, L2CAP_DATA_PACKET, &packet[COMPLETE_L2CAP_HEADER], size-COMPLETE_L2CAP_HEADER);
l2cap_dispatch_to_channel(l2cap_channel, L2CAP_DATA_PACKET, &packet[COMPLETE_L2CAP_HEADER], size-COMPLETE_L2CAP_HEADER);
}
break;
}
@ -1499,7 +1499,7 @@ static void l2cap_acl_handler(uint8_t packet_type, uint8_t *packet, uint16_t siz
}
// finalize closed channel - l2cap_handle_disconnect_request & DISCONNECTION_RESPONSE
void l2cap_finialize_channel_close(l2cap_channel_t *channel){
void l2cap_finialize_channel_close(l2cap_channel_t * channel){
channel->state = L2CAP_STATE_CLOSED;
l2cap_emit_channel_closed(channel);
// discard channel