mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-28 19:20:54 +00:00
use state_var to store Connection Pending task
This commit is contained in:
parent
fd48b8f79d
commit
ad67156049
@ -80,6 +80,8 @@ typedef enum {
|
||||
* @praram enabled
|
||||
*/
|
||||
void gap_set_bondable_mode(int enabled);
|
||||
gap_security_level_t gap_security_level(hci_con_handle_t con_handle);
|
||||
void gap_request_security_level(hci_con_handle_t con_handle, gap_security_level_t level);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
|
26
src/l2cap.c
26
src/l2cap.c
@ -493,6 +493,13 @@ void l2cap_run(void){
|
||||
|
||||
switch (channel->state){
|
||||
|
||||
case L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT:
|
||||
if (channel->state_var & L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND) {
|
||||
channelStateVarClearFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND);
|
||||
l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->remote_sig_id, 0, 0, 1, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case L2CAP_STATE_WILL_SEND_CREATE_CONNECTION:
|
||||
// send connection request - set state first
|
||||
channel->state = L2CAP_STATE_WAIT_CONNECTION_COMPLETE;
|
||||
@ -507,11 +514,6 @@ void l2cap_run(void){
|
||||
btstack_memory_l2cap_channel_free(channel);
|
||||
break;
|
||||
|
||||
case L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_PENDING:
|
||||
channel->state = L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT;
|
||||
l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid, 1 , 0);
|
||||
break;
|
||||
|
||||
case L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT:
|
||||
channel->state = L2CAP_STATE_CONFIG;
|
||||
channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ);
|
||||
@ -836,12 +838,20 @@ static void l2cap_handle_connection_request(hci_con_handle_t handle, uint8_t sig
|
||||
}
|
||||
|
||||
// set initial state
|
||||
channel->state = L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_PENDING;
|
||||
channel->state_var = L2CAP_CHANNEL_STATE_VAR_NONE;
|
||||
channel->state = L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT;
|
||||
channel->state_var = L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND;
|
||||
|
||||
// add to connections list
|
||||
linked_list_add(&l2cap_channels, (linked_item_t *) channel);
|
||||
|
||||
|
||||
//
|
||||
// gap_security_level_t current_level = gap_security_level(handle);
|
||||
// gap_security_level_t required_level = LEVEL_2;
|
||||
// if (current_level < required_level){
|
||||
// gap_request_security_level(handle, required_level);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// emit incoming connection request
|
||||
l2cap_emit_connection_request(channel);
|
||||
}
|
||||
|
15
src/l2cap.h
15
src/l2cap.h
@ -93,13 +93,13 @@ typedef enum {
|
||||
L2CAP_STATE_CLOSED = 1, // no baseband
|
||||
L2CAP_STATE_WILL_SEND_CREATE_CONNECTION,
|
||||
L2CAP_STATE_WAIT_CONNECTION_COMPLETE,
|
||||
L2CAP_STATE_WAIT_AUTHENTICATION_RESULT,
|
||||
L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT,
|
||||
L2CAP_STATE_WAIT_CONNECT_RSP, // from peer
|
||||
L2CAP_STATE_CONFIG,
|
||||
L2CAP_STATE_OPEN,
|
||||
L2CAP_STATE_WAIT_DISCONNECT, // from application
|
||||
L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST,
|
||||
L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_PENDING,
|
||||
L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE,
|
||||
L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_ACCEPT,
|
||||
L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST,
|
||||
@ -114,10 +114,11 @@ typedef enum {
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP = 1 << 3,
|
||||
L2CAP_CHANNEL_STATE_VAR_SENT_CONF_REQ = 1 << 4,
|
||||
L2CAP_CHANNEL_STATE_VAR_SENT_CONF_RSP = 1 << 5,
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU = 1 << 6, // in CONF RSP, add MTU field
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_CONT = 1 << 7, // in CONF RSP, set CONTINUE flag
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_INVALID = 1 << 8, // in CONF RSP, send UNKNOWN OPTIONS
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CMD_REJ_UNKNOWN = 1 << 9, // send CMD_REJ with reason unknown
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU = 1 << 6, // in CONF RSP, add MTU field
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_CONT = 1 << 7, // in CONF RSP, set CONTINUE flag
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_INVALID = 1 << 8, // in CONF RSP, send UNKNOWN OPTIONS
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CMD_REJ_UNKNOWN = 1 << 9, // send CMD_REJ with reason unknown
|
||||
L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND = 1 << 10, // send Connection Respond with pending
|
||||
} L2CAP_CHANNEL_STATE_VAR;
|
||||
|
||||
// info regarding an actual coneection
|
||||
@ -174,7 +175,9 @@ typedef struct {
|
||||
|
||||
// internal connection
|
||||
btstack_packet_handler_t packet_handler;
|
||||
|
||||
|
||||
// required security level
|
||||
gap_security_level_t security_level;
|
||||
} l2cap_service_t;
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user