From 7f1690cf27ca04545945f16bd57a2ec52ce35927 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 7 Jan 2019 20:55:28 +0100 Subject: [PATCH] l2cap: provide channel mode (basic/ertm) and fcs option in L2CAP_EVENT_CHANNEL_OPENED --- CHANGELOG.md | 5 +++++ src/btstack_defines.h | 4 +++- src/btstack_event.h | 18 ++++++++++++++++++ src/l2cap.c | 14 ++++++++++---- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a28aeb184..221956cb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed +- L2CAP: provide channel mode (basic/ertm) and fcs option in L2CAP_EVENT_CHANNEL_OPENED + +## Changes December 2018 + ### Added - SM: generate and store ER / IR keys in TLV, unless manually set by application - hci_dump: support PacketLogger or BlueZ format output via SEGGER RTT Channel 1 Up diff --git a/src/btstack_defines.h b/src/btstack_defines.h index acadc98ee..d38849172 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -435,7 +435,7 @@ typedef uint8_t sm_key_t[16]; // L2CAP EVENTS /** - * @format 1BH2222221 + * @format 1BH222222111 * @param status * @param address * @param handle @@ -446,6 +446,8 @@ typedef uint8_t sm_key_t[16]; * @param remote_mtu * @param flush_timeout * @param incoming + * @param mode + * @param fcs */ #define L2CAP_EVENT_CHANNEL_OPENED 0x70 diff --git a/src/btstack_event.h b/src/btstack_event.h index 09af10f11..9f1c11d4b 100644 --- a/src/btstack_event.h +++ b/src/btstack_event.h @@ -1127,6 +1127,24 @@ static inline uint16_t l2cap_event_channel_opened_get_flush_timeout(const uint8_ static inline uint8_t l2cap_event_channel_opened_get_incoming(const uint8_t * event){ return event[23]; } +/** + * @brief Get field mode from event L2CAP_EVENT_CHANNEL_OPENED + * @param event packet + * @return mode + * @note: btstack_type 1 + */ +static inline uint8_t l2cap_event_channel_opened_get_mode(const uint8_t * event){ + return event[24]; +} +/** + * @brief Get field fcs from event L2CAP_EVENT_CHANNEL_OPENED + * @param event packet + * @return fcs + * @note: btstack_type 1 + */ +static inline uint8_t l2cap_event_channel_opened_get_fcs(const uint8_t * event){ + return event[25]; +} /** * @brief Get field local_cid from event L2CAP_EVENT_CHANNEL_CLOSED diff --git a/src/l2cap.c b/src/l2cap.c index c0b6db967..43e90402f 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -904,10 +904,7 @@ void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) { log_info("L2CAP_EVENT_CHANNEL_OPENED status 0x%x addr %s handle 0x%x psm 0x%x local_cid 0x%x remote_cid 0x%x local_mtu %u, remote_mtu %u, flush_timeout %u", status, bd_addr_to_str(channel->address), channel->con_handle, channel->psm, channel->local_cid, channel->remote_cid, channel->local_mtu, channel->remote_mtu, channel->flush_timeout); -#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE - log_info("ERTM mode %u, fcs enabled %u", channel->mode, channel->fcs_option); -#endif - uint8_t event[24]; + uint8_t event[26]; event[0] = L2CAP_EVENT_CHANNEL_OPENED; event[1] = sizeof(event) - 2; event[2] = status; @@ -920,6 +917,15 @@ void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) { little_endian_store_16(event, 19, channel->remote_mtu); little_endian_store_16(event, 21, channel->flush_timeout); event[23] = channel->state_var & L2CAP_CHANNEL_STATE_VAR_INCOMING ? 1 : 0; +#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE + log_info("ERTM mode %u, fcs enabled %u", channel->mode, channel->fcs_option); + event[24] = channel->mode; + event[25] = channel->fcs_option; + +#else + event[24] = L2CAP_CHANNEL_MODE_BASIC; + event[25] = 0; +#endif hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); l2cap_dispatch_to_channel(channel, HCI_EVENT_PACKET, event, sizeof(event)); }