mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-27 06:35:20 +00:00
all states covered, needs double-check of state machine
This commit is contained in:
parent
ae280e7320
commit
552d92a164
46
src/l2cap.c
46
src/l2cap.c
@ -260,6 +260,11 @@ void l2cap_run(void){
|
|||||||
free (channel);
|
free (channel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT:
|
||||||
|
l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->sig_id, channel->local_cid, channel->remote_cid, 0, 0);
|
||||||
|
channel->state = L2CAP_STATE_WAIT_CONFIG_REQ_OR_SEND_CONFIG_REQ;
|
||||||
|
break;
|
||||||
|
|
||||||
case L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST:
|
case L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST:
|
||||||
// success, start l2cap handshake
|
// success, start l2cap handshake
|
||||||
channel->sig_id = l2cap_next_sig_id();
|
channel->sig_id = l2cap_next_sig_id();
|
||||||
@ -277,7 +282,24 @@ void l2cap_run(void){
|
|||||||
channel->state = L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_CONFIG_REQ;
|
channel->state = L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_CONFIG_REQ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_WILL_SEND_CONFIG_REQ_RSP:
|
||||||
|
l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->sig_id, channel->remote_cid, 0, 0, 0, NULL);
|
||||||
|
channel->state = L2CAP_STATE_WAIT_CONFIG_REQ_RSP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case L2CAP_STATE_WILL_SEND_CONFIG_REQ_RSP:
|
||||||
|
l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->sig_id, channel->remote_cid, 0, 0, 0, NULL);
|
||||||
|
channel->state = L2CAP_STATE_OPEN;
|
||||||
|
l2cap_emit_channel_opened(channel, 0); // success
|
||||||
|
l2cap_emit_credits(channel, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
case L2CAP_STATE_WILL_SEND_CONFIG_REQ_AND_CONFIG_REQ_RSP:
|
case L2CAP_STATE_WILL_SEND_CONFIG_REQ_AND_CONFIG_REQ_RSP:
|
||||||
|
l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->sig_id, channel->remote_cid, 0, 0, 0, NULL);
|
||||||
|
channel->state = L2CAP_STATE_WILL_SEND_CONFIG_REQ;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case L2CAP_STATE_WILL_SEND_CONFIG_REQ:
|
||||||
channel->sig_id = l2cap_next_sig_id();
|
channel->sig_id = l2cap_next_sig_id();
|
||||||
config_options[0] = 1; // MTU
|
config_options[0] = 1; // MTU
|
||||||
config_options[1] = 2; // len param
|
config_options[1] = 2; // len param
|
||||||
@ -526,19 +548,10 @@ void l2cap_accept_connection_internal(uint16_t local_cid){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// accept connection
|
channel->state = L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT;
|
||||||
l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->sig_id, channel->local_cid, channel->remote_cid, 0, 0);
|
|
||||||
|
|
||||||
// set real sig and state and start config
|
// process
|
||||||
channel->sig_id = l2cap_next_sig_id();
|
l2cap_run();
|
||||||
channel->state = L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_CONFIG_REQ;
|
|
||||||
uint8_t config_options[4];
|
|
||||||
config_options[0] = 1; // MTU
|
|
||||||
config_options[1] = 2; // len param
|
|
||||||
bt_store_16( (uint8_t*)&config_options, 2, channel->local_mtu);
|
|
||||||
l2cap_send_signaling_packet(channel->handle, CONFIGURE_REQUEST, channel->sig_id, channel->remote_cid, 0, 4, &config_options);
|
|
||||||
|
|
||||||
// log_dbg("new state %u\n", channel->state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason){
|
void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason){
|
||||||
@ -567,8 +580,7 @@ void l2cap_signaling_handle_configure_request(l2cap_channel_t *channel, uint8_t
|
|||||||
pos += length;
|
pos += length;
|
||||||
}
|
}
|
||||||
uint8_t identifier = command[L2CAP_SIGNALING_COMMAND_SIGID_OFFSET];
|
uint8_t identifier = command[L2CAP_SIGNALING_COMMAND_SIGID_OFFSET];
|
||||||
// send back OK
|
channel->sig_id = command[L2CAP_SIGNALING_COMMAND_SIGID_OFFSET];
|
||||||
l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, identifier, channel->remote_cid, 0, 0, 0, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *command){
|
void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *command){
|
||||||
@ -650,7 +662,7 @@ void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *command)
|
|||||||
break;
|
break;
|
||||||
case CONFIGURE_REQUEST:
|
case CONFIGURE_REQUEST:
|
||||||
l2cap_signaling_handle_configure_request(channel, command);
|
l2cap_signaling_handle_configure_request(channel, command);
|
||||||
channel->state = L2CAP_STATE_WAIT_CONFIG_REQ_RSP;
|
channel->state = L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_WILL_SEND_CONFIG_REQ_RSP;
|
||||||
break;
|
break;
|
||||||
case DISCONNECTION_REQUEST:
|
case DISCONNECTION_REQUEST:
|
||||||
l2cap_handle_disconnect_request(channel, identifier);
|
l2cap_handle_disconnect_request(channel, identifier);
|
||||||
@ -665,9 +677,7 @@ void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *command)
|
|||||||
switch (code) {
|
switch (code) {
|
||||||
case CONFIGURE_REQUEST:
|
case CONFIGURE_REQUEST:
|
||||||
l2cap_signaling_handle_configure_request(channel, command);
|
l2cap_signaling_handle_configure_request(channel, command);
|
||||||
channel->state = L2CAP_STATE_OPEN;
|
channel->state = L2CAP_STATE_WILL_SEND_CONFIG_REQ_RSP;
|
||||||
l2cap_emit_channel_opened(channel, 0); // success
|
|
||||||
l2cap_emit_credits(channel, 1);
|
|
||||||
break;
|
break;
|
||||||
case DISCONNECTION_REQUEST:
|
case DISCONNECTION_REQUEST:
|
||||||
l2cap_handle_disconnect_request(channel, identifier);
|
l2cap_handle_disconnect_request(channel, identifier);
|
||||||
|
@ -56,16 +56,19 @@ typedef enum {
|
|||||||
L2CAP_STATE_WAIT_CONNECT_RSP, // from peer
|
L2CAP_STATE_WAIT_CONNECT_RSP, // from peer
|
||||||
L2CAP_STATE_WAIT_CONFIG_REQ_OR_SEND_CONFIG_REQ,
|
L2CAP_STATE_WAIT_CONFIG_REQ_OR_SEND_CONFIG_REQ,
|
||||||
L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_CONFIG_REQ,
|
L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_CONFIG_REQ,
|
||||||
|
L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_WILL_SEND_CONFIG_REQ_RSP,
|
||||||
L2CAP_STATE_WAIT_CONFIG_REQ_RSP,
|
L2CAP_STATE_WAIT_CONFIG_REQ_RSP,
|
||||||
L2CAP_STATE_WAIT_CONFIG_REQ,
|
L2CAP_STATE_WAIT_CONFIG_REQ,
|
||||||
L2CAP_STATE_OPEN,
|
L2CAP_STATE_OPEN,
|
||||||
L2CAP_STATE_WAIT_DISCONNECT, // from application
|
L2CAP_STATE_WAIT_DISCONNECT, // from application
|
||||||
L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST,
|
L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST,
|
||||||
|
L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE,
|
||||||
|
L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT,
|
||||||
|
L2CAP_STATE_WILL_SEND_CONFIG_REQ,
|
||||||
|
L2CAP_STATE_WILL_SEND_CONFIG_REQ_RSP,
|
||||||
L2CAP_STATE_WILL_SEND_CONFIG_REQ_AND_CONFIG_REQ_RSP,
|
L2CAP_STATE_WILL_SEND_CONFIG_REQ_AND_CONFIG_REQ_RSP,
|
||||||
L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST,
|
L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST,
|
||||||
L2CAP_STATE_WILL_SEND_DISCONNECT_RESPONSE,
|
L2CAP_STATE_WILL_SEND_DISCONNECT_RESPONSE,
|
||||||
L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE,
|
|
||||||
|
|
||||||
} L2CAP_STATE;
|
} L2CAP_STATE;
|
||||||
|
|
||||||
// info regarding an actual coneection
|
// info regarding an actual coneection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user