extracted rfcomm_channel_packet_handler

This commit is contained in:
matthias.ringwald 2011-07-06 11:09:43 +00:00
parent d7bd042c27
commit 48b8951948

View File

@ -1199,46 +1199,13 @@ static void rfcomm_channel_state_machine(rfcomm_channel_t *channel, rfcomm_chann
} }
} }
void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ void rfcomm_channel_packet_handler(rfcomm_multiplexer_t * multiplexer, uint8_t *packet, uint16_t size){
// multiplexer handler
int handled = 0;
switch (packet_type) {
case HCI_EVENT_PACKET:
handled = rfcomm_multiplexer_hci_event_handler(packet, size);
break;
case L2CAP_DATA_PACKET:
handled = rfcomm_multiplexer_l2cap_packet_handler(channel, packet, size);
break;
default:
break;
}
if (handled) return;
// we only handle l2cap packet over open multiplexer channel now
if (packet_type != L2CAP_DATA_PACKET) {
(*app_packet_handler)(NULL, packet_type, channel, packet, size);
return;
}
rfcomm_multiplexer_t * multiplexer = rfcomm_multiplexer_for_l2cap_cid(channel);
if (!multiplexer || multiplexer->state != RFCOMM_MULTIPLEXER_OPEN) {
(*app_packet_handler)(NULL, packet_type, channel, packet, size);
return;
}
// rfcomm: (0) addr [76543 server channel] [2 direction: initiator uses 1] [1 C/R: CMD by initiator = 1] [0 EA=1] // rfcomm: (0) addr [76543 server channel] [2 direction: initiator uses 1] [1 C/R: CMD by initiator = 1] [0 EA=1]
const uint8_t frame_dlci = packet[0] >> 2; const uint8_t frame_dlci = packet[0] >> 2;
uint8_t message_dlci; // used by commands in UIH(_PF) packets uint8_t message_dlci; // used by commands in UIH(_PF) packets
uint8_t message_len; // " uint8_t message_len; // "
// channel data
if (frame_dlci && (packet[1] == BT_RFCOMM_UIH || packet[1] == BT_RFCOMM_UIH_PF)) {
rfcomm_channel_packet_handler_uih(multiplexer, packet, size);
return;
}
// rfcomm: (1) command/control // rfcomm: (1) command/control
// -- credits_offset = 1 if command == BT_RFCOMM_UIH_PF // -- credits_offset = 1 if command == BT_RFCOMM_UIH_PF
const uint8_t credit_offset = ((packet[1] & BT_RFCOMM_UIH_PF) == BT_RFCOMM_UIH_PF) ? 1 : 0; // credits for uih_pf frames const uint8_t credit_offset = ((packet[1] & BT_RFCOMM_UIH_PF) == BT_RFCOMM_UIH_PF) ? 1 : 0; // credits for uih_pf frames
@ -1258,7 +1225,7 @@ void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
case BT_RFCOMM_SABM: case BT_RFCOMM_SABM:
rfService = rfcomm_service_for_channel(frame_dlci >> 1); rfService = rfcomm_service_for_channel(frame_dlci >> 1);
if (rfService) { if (rfService) {
log_dbg("Received SABM #%u\n", frame_dlci); log_dbg("Received SABM #%u\n", frame_dlci);
// get or create channel // get or create channel
rfChannel = rfcomm_channel_for_multiplexer_and_dlci(multiplexer, frame_dlci); rfChannel = rfcomm_channel_for_multiplexer_and_dlci(multiplexer, frame_dlci);
@ -1429,6 +1396,45 @@ void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
} }
} }
void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
// multiplexer handler
int handled = 0;
switch (packet_type) {
case HCI_EVENT_PACKET:
handled = rfcomm_multiplexer_hci_event_handler(packet, size);
break;
case L2CAP_DATA_PACKET:
handled = rfcomm_multiplexer_l2cap_packet_handler(channel, packet, size);
break;
default:
break;
}
if (handled) return;
// we only handle l2cap packet over open multiplexer channel now
if (packet_type != L2CAP_DATA_PACKET) {
(*app_packet_handler)(NULL, packet_type, channel, packet, size);
return;
}
rfcomm_multiplexer_t * multiplexer = rfcomm_multiplexer_for_l2cap_cid(channel);
if (!multiplexer || multiplexer->state != RFCOMM_MULTIPLEXER_OPEN) {
(*app_packet_handler)(NULL, packet_type, channel, packet, size);
return;
}
// channel data ?
// rfcomm: (0) addr [76543 server channel] [2 direction: initiator uses 1] [1 C/R: CMD by initiator = 1] [0 EA=1]
const uint8_t frame_dlci = packet[0] >> 2;
if (frame_dlci && (packet[1] == BT_RFCOMM_UIH || packet[1] == BT_RFCOMM_UIH_PF)) {
rfcomm_channel_packet_handler_uih(multiplexer, packet, size);
return;
}
rfcomm_channel_packet_handler(multiplexer, packet, size);
}
// //
void rfcomm_close_connection(void *connection){ void rfcomm_close_connection(void *connection){
linked_item_t *it; linked_item_t *it;