bnep: handle l2cap open for incoming connections properly

This commit is contained in:
Matthias Ringwald 2015-08-03 10:39:10 +02:00
parent 9eeb95b810
commit 72956c7420

View File

@ -1251,22 +1251,29 @@ static int bnep_hci_event_handler(uint8_t *packet, uint16_t size)
return 1; return 1;
} }
if (channel->state == BNEP_CHANNEL_STATE_CLOSED) { switch (channel->state){
log_info("L2CAP_EVENT_CHANNEL_OPENED: outgoing connection"); case BNEP_CHANNEL_STATE_CLOSED:
log_info("L2CAP_EVENT_CHANNEL_OPENED: outgoing connection");
bnep_channel_start_timer(channel, BNEP_CONNECTION_TIMEOUT_MS); bnep_channel_start_timer(channel, BNEP_CONNECTION_TIMEOUT_MS);
/* Assign connection handle and l2cap cid */ /* Assign connection handle and l2cap cid */
channel->l2cap_cid = l2cap_cid; channel->l2cap_cid = l2cap_cid;
channel->con_handle = con_handle; channel->con_handle = con_handle;
/* Initiate the connection request */ /* Initiate the connection request */
channel->state = BNEP_CHANNEL_STATE_WAIT_FOR_CONNECTION_RESPONSE; channel->state = BNEP_CHANNEL_STATE_WAIT_FOR_CONNECTION_RESPONSE;
bnep_channel_state_add(channel, BNEP_CHANNEL_STATE_VAR_SND_CONNECTION_REQUEST); bnep_channel_state_add(channel, BNEP_CHANNEL_STATE_VAR_SND_CONNECTION_REQUEST);
channel->max_frame_size = bnep_max_frame_size_for_l2cap_mtu(READ_BT_16(packet, 17)); channel->max_frame_size = bnep_max_frame_size_for_l2cap_mtu(READ_BT_16(packet, 17));
bnep_run(); bnep_run();
} else { break;
log_error("L2CAP_EVENT_CHANNEL_OPENED: Invalid state: %d", channel->state); case BNEP_CHANNEL_STATE_WAIT_FOR_CONNECTION_REQUEST:
/* New information: channel mtu */
channel->max_frame_size = bnep_max_frame_size_for_l2cap_mtu(READ_BT_16(packet, 17));
break;
default:
log_error("L2CAP_EVENT_CHANNEL_OPENED: Invalid state: %d", channel->state);
break;
} }
return 1; return 1;