mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-07 16:20:19 +00:00
connection failure for RFCOMM L2CAP channel now results in rfcomm channel open errors and removal of prepared channels and multiplexer
This commit is contained in:
parent
d4d72cf99a
commit
aac3545b0e
53
src/rfcomm.c
53
src/rfcomm.c
@ -347,7 +347,7 @@ static void rfcomm_channel_initialize(rfcomm_channel_t *channel, rfcomm_multiple
|
|||||||
static rfcomm_channel_t * rfcomm_channel_create(rfcomm_multiplexer_t * multiplexer,
|
static rfcomm_channel_t * rfcomm_channel_create(rfcomm_multiplexer_t * multiplexer,
|
||||||
rfcomm_service_t * service, uint8_t server_channel){
|
rfcomm_service_t * service, uint8_t server_channel){
|
||||||
|
|
||||||
log_info("rfcomm_channel_create for service %p, channel %u --- begin\n", service, server_channel);
|
log_info("rfcomm_channel_create for service %p, channel %u --- list of channels:\n", service, server_channel);
|
||||||
rfcomm_dump_channels();
|
rfcomm_dump_channels();
|
||||||
|
|
||||||
// alloc structure
|
// alloc structure
|
||||||
@ -580,14 +580,21 @@ static void rfcomm_send_uih_credits(rfcomm_multiplexer_t *multiplexer, uint8_t d
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: RFCOMM MULTIPLEXER
|
// MARK: RFCOMM MULTIPLEXER
|
||||||
|
static void rfcomm_multiplexer_stop_timer(rfcomm_multiplexer_t * multiplexer){
|
||||||
static void rfcomm_multiplexer_finalize(rfcomm_multiplexer_t * multiplexer){
|
|
||||||
|
|
||||||
// remove (potential) timer
|
|
||||||
if (multiplexer->timer_active) {
|
if (multiplexer->timer_active) {
|
||||||
run_loop_remove_timer(&multiplexer->timer);
|
run_loop_remove_timer(&multiplexer->timer);
|
||||||
multiplexer->timer_active = 0;
|
multiplexer->timer_active = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
static void rfcomm_multiplexer_free(rfcomm_multiplexer_t * multiplexer){
|
||||||
|
linked_list_remove( &rfcomm_multiplexers, (linked_item_t *) multiplexer);
|
||||||
|
btstack_memory_rfcomm_multiplexer_free(multiplexer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rfcomm_multiplexer_finalize(rfcomm_multiplexer_t * multiplexer){
|
||||||
|
|
||||||
|
// remove (potential) timer
|
||||||
|
rfcomm_multiplexer_stop_timer(multiplexer);
|
||||||
|
|
||||||
// close and remove all channels
|
// close and remove all channels
|
||||||
linked_item_t *it = (linked_item_t *) &rfcomm_channels;
|
linked_item_t *it = (linked_item_t *) &rfcomm_channels;
|
||||||
@ -613,8 +620,7 @@ static void rfcomm_multiplexer_finalize(rfcomm_multiplexer_t * multiplexer){
|
|||||||
uint16_t l2cap_cid = multiplexer->l2cap_cid;
|
uint16_t l2cap_cid = multiplexer->l2cap_cid;
|
||||||
|
|
||||||
// remove mutliplexer
|
// remove mutliplexer
|
||||||
linked_list_remove( &rfcomm_multiplexers, (linked_item_t *) multiplexer);
|
rfcomm_multiplexer_free(multiplexer);
|
||||||
btstack_memory_rfcomm_multiplexer_free(multiplexer);
|
|
||||||
|
|
||||||
// close l2cap multiplexer channel, too
|
// close l2cap multiplexer channel, too
|
||||||
l2cap_disconnect_internal(l2cap_cid, 0x13);
|
l2cap_disconnect_internal(l2cap_cid, 0x13);
|
||||||
@ -671,6 +677,8 @@ static int rfcomm_multiplexer_hci_event_handler(uint8_t *packet, uint16_t size){
|
|||||||
uint16_t l2cap_cid;
|
uint16_t l2cap_cid;
|
||||||
hci_con_handle_t con_handle;
|
hci_con_handle_t con_handle;
|
||||||
rfcomm_multiplexer_t *multiplexer = NULL;
|
rfcomm_multiplexer_t *multiplexer = NULL;
|
||||||
|
uint8_t status;
|
||||||
|
|
||||||
switch (packet[0]) {
|
switch (packet[0]) {
|
||||||
|
|
||||||
// accept incoming PSM_RFCOMM connection if no multiplexer exists yet
|
// accept incoming PSM_RFCOMM connection if no multiplexer exists yet
|
||||||
@ -709,8 +717,12 @@ static int rfcomm_multiplexer_hci_event_handler(uint8_t *packet, uint16_t size){
|
|||||||
|
|
||||||
// l2cap connection opened -> store l2cap_cid, remote_addr
|
// l2cap connection opened -> store l2cap_cid, remote_addr
|
||||||
case L2CAP_EVENT_CHANNEL_OPENED:
|
case L2CAP_EVENT_CHANNEL_OPENED:
|
||||||
|
|
||||||
if (READ_BT_16(packet, 11) != PSM_RFCOMM) break;
|
if (READ_BT_16(packet, 11) != PSM_RFCOMM) break;
|
||||||
log_info("L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM\n");
|
|
||||||
|
status = packet[2];
|
||||||
|
log_info("L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM, status %u\n", status);
|
||||||
|
|
||||||
// get multiplexer for remote addr
|
// get multiplexer for remote addr
|
||||||
con_handle = READ_BT_16(packet, 9);
|
con_handle = READ_BT_16(packet, 9);
|
||||||
l2cap_cid = READ_BT_16(packet, 13);
|
l2cap_cid = READ_BT_16(packet, 13);
|
||||||
@ -720,6 +732,31 @@ static int rfcomm_multiplexer_hci_event_handler(uint8_t *packet, uint16_t size){
|
|||||||
log_error("L2CAP_EVENT_CHANNEL_OPENED but no multiplexer prepared\n");
|
log_error("L2CAP_EVENT_CHANNEL_OPENED but no multiplexer prepared\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// on l2cap open error discard everything
|
||||||
|
if (status){
|
||||||
|
|
||||||
|
// remove (potential) timer
|
||||||
|
rfcomm_multiplexer_stop_timer(multiplexer);
|
||||||
|
|
||||||
|
// emit rfcomm_channel_opened with status and free channel
|
||||||
|
linked_item_t * it = (linked_item_t *) &rfcomm_channels;
|
||||||
|
while (it->next) {
|
||||||
|
rfcomm_channel_t * channel = (rfcomm_channel_t *) it->next;
|
||||||
|
if (channel->multiplexer == multiplexer){
|
||||||
|
rfcomm_emit_channel_opened(channel, status);
|
||||||
|
it->next = it->next->next;
|
||||||
|
btstack_memory_rfcomm_channel_free(channel);
|
||||||
|
} else {
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// free multiplexer
|
||||||
|
rfcomm_multiplexer_free(multiplexer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (multiplexer->state == RFCOMM_MULTIPLEXER_W4_CONNECT) {
|
if (multiplexer->state == RFCOMM_MULTIPLEXER_W4_CONNECT) {
|
||||||
log_info("L2CAP_EVENT_CHANNEL_OPENED: outgoing connection\n");
|
log_info("L2CAP_EVENT_CHANNEL_OPENED: outgoing connection\n");
|
||||||
// wrong remote addr
|
// wrong remote addr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user