diff --git a/src/btstack_defines.h b/src/btstack_defines.h index 6af8e7ccb..cb073674e 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -138,12 +138,12 @@ typedef uint8_t sm_key_t[16]; #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_PSM 0x65 #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_SECURITY 0x66 #define L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_RESOURCES 0x67 -#define L2CAP_CONNECTION_RESPONSE_RESULT_RTX_TIMEOUT 0x68 - -#define L2CAP_SERVICE_ALREADY_REGISTERED 0x69 -#define L2CAP_DATA_LEN_EXCEEDS_REMOTE_MTU 0x6A -#define L2CAP_SERVICE_DOES_NOT_EXIST 0x6B -#define L2CAP_LOCAL_CID_DOES_NOT_EXIST 0x6C +#define L2CAP_CONNECTION_RESPONSE_RESULT_ERTM_NOT_SUPPORTD 0x68 +#define L2CAP_CONNECTION_RESPONSE_RESULT_RTX_TIMEOUT 0x69 +#define L2CAP_SERVICE_ALREADY_REGISTERED 0x6A +#define L2CAP_DATA_LEN_EXCEEDS_REMOTE_MTU 0x6B +#define L2CAP_SERVICE_DOES_NOT_EXIST 0x6C +#define L2CAP_LOCAL_CID_DOES_NOT_EXIST 0x6D #define RFCOMM_MULTIPLEXER_STOPPED 0x70 #define RFCOMM_CHANNEL_ALREADY_REGISTERED 0x71 diff --git a/src/l2cap.c b/src/l2cap.c index 2ebc2a214..2e260a68c 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -1707,14 +1707,27 @@ static void l2cap_signaling_handler_dispatch( hci_con_handle_t handle, uint8_t * uint16_t info_type = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET); uint16_t result = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+2); if (result != 0) return; - if (info_type != 0x04) return; + if (info_type != 0x02) return; connection->l2cap_state.information_state = L2CAP_INFORMATION_STATE_DONE; connection->l2cap_state.extended_feature_mask = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4); - log_info("extneded features mask 0x%02x", connection->l2cap_state.extended_feature_mask); + log_info("extended features mask 0x%02x", connection->l2cap_state.extended_feature_mask); // trigger connection request btstack_linked_list_iterator_init(&it, &l2cap_channels); while (btstack_linked_list_iterator_has_next(&it)){ l2cap_channel_t * channel = (l2cap_channel_t *) btstack_linked_list_iterator_next(&it); + if (channel->con_handle != handle) continue; + // bail if ERTM was requested but is not supported + if ((channel->mode == L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION) && ((connection->l2cap_state.extended_feature_mask & 0x08) == 0)){ + // channel closed + channel->state = L2CAP_STATE_CLOSED; + // map l2cap connection response result to BTstack status enumeration + l2cap_emit_channel_opened(channel, L2CAP_CONNECTION_RESPONSE_RESULT_ERTM_NOT_SUPPORTD); + // discard channel + btstack_linked_list_remove(&l2cap_channels, (btstack_linked_item_t *) channel); + btstack_memory_l2cap_channel_free(channel); + continue; + } + // start connecting if (channel->state == L2CAP_STATE_WAIT_OUTGOING_EXTENDED_FEATURES){ channel->state = L2CAP_STATE_WILL_SEND_CONNECTION_REQUEST; }