diff options
| author | 2024-08-24 08:01:01 -0700 | |
|---|---|---|
| committer | 2024-08-27 23:54:28 +0000 | |
| commit | e4ae982d7dcd67b9cfe5d3d84ef22e3fb392a43a (patch) | |
| tree | bfd0ec6300433253fecbc2558f729676fee53838 | |
| parent | b4ddda63b4031440a0ddcefd612b351c179e48c2 (diff) | |
stack::l2cap class enum-ify tL2CAP_CFG_RESULT
Bug: 361948635
Test: m .
Flag: EXEMPT, Mechanical Refactor
Change-Id: Idc3ddcadaca7ba184b6da389bde13d2d44c0863b
| -rw-r--r-- | system/stack/eatt/eatt_impl.h | 22 | ||||
| -rw-r--r-- | system/stack/hid/hidh_conn.cc | 2 | ||||
| -rw-r--r-- | system/stack/include/l2cap_types.h | 4 | ||||
| -rw-r--r-- | system/stack/include/l2cdefs.h | 15 | ||||
| -rw-r--r-- | system/stack/l2cap/l2c_ble.cc | 26 | ||||
| -rw-r--r-- | system/stack/l2cap/l2c_csm.cc | 16 | ||||
| -rw-r--r-- | system/stack/l2cap/l2c_fcr.cc | 8 | ||||
| -rw-r--r-- | system/stack/l2cap/l2c_int.h | 24 | ||||
| -rw-r--r-- | system/stack/l2cap/l2c_main.cc | 12 | ||||
| -rw-r--r-- | system/stack/l2cap/l2c_utils.cc | 46 | ||||
| -rw-r--r-- | system/stack/rfcomm/rfc_l2cap_if.cc | 2 | ||||
| -rw-r--r-- | system/stack/rfcomm/rfc_mx_fsm.cc | 6 | ||||
| -rw-r--r-- | system/stack/test/eatt/eatt_test.cc | 30 | ||||
| -rw-r--r-- | system/stack/test/rfcomm/stack_rfcomm_test.cc | 21 | ||||
| -rw-r--r-- | system/stack/test/stack_l2cap_test.cc | 19 | ||||
| -rw-r--r-- | system/test/mock/mock_stack_l2cap_utils.cc | 2 |
16 files changed, 140 insertions, 115 deletions
diff --git a/system/stack/eatt/eatt_impl.h b/system/stack/eatt/eatt_impl.h index 08c81f2a40..b5e5aa4c2d 100644 --- a/system/stack/eatt/eatt_impl.h +++ b/system/stack/eatt/eatt_impl.h @@ -19,6 +19,8 @@ #include <com_android_bluetooth_flags.h> #include <map> +#include <memory> +#include <utility> #include <vector> #include "bind_helpers.h" @@ -157,13 +159,15 @@ struct eatt_impl { uint16_t max_mps = shim::GetController()->GetLeBufferSize().le_data_packet_length_; tL2CAP_LE_CFG_INFO local_coc_cfg = { - .result = L2CAP_LE_RESULT_CONN_OK, + .result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, .mtu = eatt_dev->rx_mtu_, .mps = eatt_dev->rx_mps_ < max_mps ? eatt_dev->rx_mps_ : max_mps, .credits = L2CA_LeCreditDefault(), }; - if (!L2CA_ConnectCreditBasedRsp(bda, identifier, lcids, L2CAP_CONN_OK, &local_coc_cfg)) { + if (!L2CA_ConnectCreditBasedRsp(bda, identifier, lcids, + tL2CAP_LE_RESULT_CODE::L2CAP_LE_RESULT_CONN_OK, + &local_coc_cfg)) { log::warn("Unable to respond L2CAP le_coc credit indication peer:{}", bda); return false; } @@ -415,8 +419,9 @@ struct eatt_impl { // regardless of success result, we have finished reconfiguration channel->EattChannelSetState(EattChannelState::EATT_CHANNEL_OPENED); - if (p_cfg->result != L2CAP_CFG_OK) { - log::info("reconfig failed lcid: 0x{:x} result: 0x{:x}", lcid, p_cfg->result); + if (p_cfg->result != tL2CAP_CFG_RESULT::L2CAP_CFG_OK) { + log::info("reconfig failed lcid: 0x{:x} result:{}", lcid, + l2cap_cfg_result_text(p_cfg->result)); return; } @@ -541,7 +546,7 @@ struct eatt_impl { } tL2CAP_LE_CFG_INFO local_coc_cfg = { - .result = L2CAP_LE_RESULT_CONN_OK, + .result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, .mtu = eatt_dev->rx_mtu_, .mps = eatt_dev->rx_mps_, .credits = L2CA_LeCreditDefault(), @@ -782,7 +787,10 @@ struct eatt_impl { std::vector<uint16_t> cids = {cid}; tL2CAP_LE_CFG_INFO cfg = { - .result = L2CAP_LE_RESULT_CONN_OK, .mtu = new_mtu, .mps = eatt_dev->rx_mps_}; + .result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, + .mtu = new_mtu, + .mps = eatt_dev->rx_mps_, + }; if (!L2CA_ReconfigCreditBasedConnsReq(eatt_dev->bda_, cids, &cfg)) { log::error("Could not start reconfig cid: 0x{:x} or device {}", cid, bd_addr); @@ -821,7 +829,7 @@ struct eatt_impl { } tL2CAP_LE_CFG_INFO cfg = { - .result = L2CAP_LE_RESULT_CONN_OK, .mtu = new_mtu, .mps = eatt_dev->rx_mps_}; + .result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, .mtu = new_mtu, .mps = eatt_dev->rx_mps_}; if (!L2CA_ReconfigCreditBasedConnsReq(eatt_dev->bda_, cids, &cfg)) { log::error("Could not start reconfig for device {}", bd_addr); diff --git a/system/stack/hid/hidh_conn.cc b/system/stack/hid/hidh_conn.cc index 159bf46cf6..e62b3131f8 100644 --- a/system/stack/hid/hidh_conn.cc +++ b/system/stack/hid/hidh_conn.cc @@ -285,7 +285,7 @@ static void hidh_on_l2cap_error(uint16_t l2cap_cid, uint16_t result) { hidh_conn_disconnect(dhandle); - if (result != L2CAP_CFG_FAILED_NO_REASON) { + if (result != static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON)) { #if (HID_HOST_MAX_CONN_RETRY > 0) if ((hh_cb.devices[dhandle].conn_tries <= HID_HOST_MAX_CONN_RETRY) && (result == HCI_ERR_CONNECTION_TOUT || result == HCI_ERR_UNSPECIFIED || diff --git a/system/stack/include/l2cap_types.h b/system/stack/include/l2cap_types.h index f2448769ea..e0927e96aa 100644 --- a/system/stack/include/l2cap_types.h +++ b/system/stack/include/l2cap_types.h @@ -116,7 +116,7 @@ typedef struct { * use to signify its presence or absence. */ typedef struct { - uint16_t result; /* Only used in confirm messages */ + tL2CAP_CFG_RESULT result; /* Only used in confirm messages */ bool mtu_present; uint16_t mtu; bool qos_present; @@ -150,7 +150,7 @@ uint16_t L2CA_LeCreditThreshold(); constexpr uint8_t L2CAP_CREDIT_BASED_MAX_CIDS = 5; struct tL2CAP_LE_CFG_INFO { - uint16_t result{L2CAP_LE_RESULT_CONN_OK}; /* Only used in confirm messages */ + tL2CAP_CFG_RESULT result{tL2CAP_CFG_RESULT::L2CAP_CFG_OK}; /* Only used in confirm messages */ uint16_t mtu{kDefaultL2capMtu}; uint16_t mps{kDefaultL2capMps}; uint16_t credits{L2CA_LeCreditDefault()}; diff --git a/system/stack/include/l2cdefs.h b/system/stack/include/l2cdefs.h index 5a9debfb84..1987287e4d 100644 --- a/system/stack/include/l2cdefs.h +++ b/system/stack/include/l2cdefs.h @@ -272,7 +272,7 @@ inline std::string l2cap_cid_fixed_text(const tL2CAP_CID_FIXED& cid) { CASE_RETURN_STRING_HEX04(L2CAP_SMP_CID); CASE_RETURN_STRING_HEX04(L2CAP_SMP_BR_CID); CASE_RETURN_STRING_HEX04(L2CAP_BASE_APPL_CID); - }; + } RETURN_UNKNOWN_TYPE_STRING(type, cid); } @@ -298,7 +298,7 @@ inline std::string l2cap_cid_fixed_text(const tL2CAP_CID_FIXED& cid) { /* Define the L2CAP configuration result codes */ -enum tL2CAP_CFG_RESULT : uint16_t { +enum class tL2CAP_CFG_RESULT : uint16_t { L2CAP_CFG_OK = 0, L2CAP_CFG_UNACCEPTABLE_PARAMS = 1, L2CAP_CFG_FAILED_NO_REASON = 2, @@ -306,6 +306,17 @@ enum tL2CAP_CFG_RESULT : uint16_t { L2CAP_CFG_PENDING = 4, }; +inline std::string l2cap_cfg_result_text(const tL2CAP_CFG_RESULT& result) { + switch (result) { + CASE_RETURN_STRING_HEX04(tL2CAP_CFG_RESULT::L2CAP_CFG_OK); + CASE_RETURN_STRING_HEX04(tL2CAP_CFG_RESULT::L2CAP_CFG_UNACCEPTABLE_PARAMS); + CASE_RETURN_STRING_HEX04(tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON); + CASE_RETURN_STRING_HEX04(tL2CAP_CFG_RESULT::L2CAP_CFG_UNKNOWN_OPTIONS); + CASE_RETURN_STRING_HEX04(tL2CAP_CFG_RESULT::L2CAP_CFG_PENDING); + } + RETURN_UNKNOWN_TYPE_STRING(type, result); +} + /* Define the L2CAP configuration option types */ #define L2CAP_CFG_TYPE_MTU 0x01 diff --git a/system/stack/l2cap/l2c_ble.cc b/system/stack/l2cap/l2c_ble.cc index d22995bbb6..203c9de0ff 100644 --- a/system/stack/l2cap/l2c_ble.cc +++ b/system/stack/l2cap/l2c_ble.cc @@ -317,9 +317,9 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { * 1.25) - 1)) ||*/ timeout < BTM_BLE_CONN_SUP_TOUT_MIN || timeout > BTM_BLE_CONN_SUP_TOUT_MAX || max_interval < min_interval) { - l2cu_send_peer_ble_par_rsp(p_lcb, L2CAP_CFG_UNACCEPTABLE_PARAMS, id); + l2cu_send_peer_ble_par_rsp(p_lcb, tL2CAP_CFG_RESULT::L2CAP_CFG_UNACCEPTABLE_PARAMS, id); } else { - l2cu_send_peer_ble_par_rsp(p_lcb, L2CAP_CFG_OK, id); + l2cu_send_peer_ble_par_rsp(p_lcb, tL2CAP_CFG_RESULT::L2CAP_CFG_OK, id); p_lcb->min_interval = min_interval; p_lcb->max_interval = max_interval; @@ -655,14 +655,16 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { } case L2CAP_CMD_CREDIT_BASED_RECONFIG_RES: { - uint16_t result; - if (p + sizeof(uint16_t) > p_pkt_end) { + uint16_t result_u16; + if (p + sizeof(tL2CAP_CFG_RESULT) > p_pkt_end) { log::error("invalid read"); return; } - STREAM_TO_UINT16(result, p); + STREAM_TO_UINT16(result_u16, p); + tL2CAP_CFG_RESULT result = static_cast<tL2CAP_CFG_RESULT>(result_u16); - log::verbose("Recv L2CAP_CMD_CREDIT_BASED_RECONFIG_RES for result = 0x{:04x}", result); + log::verbose("Recv L2CAP_CMD_CREDIT_BASED_RECONFIG_RES for result:{}", + l2cap_cfg_result_text(result)); p_lcb->pending_ecoc_reconfig_cfg.result = result; @@ -676,7 +678,7 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { &p_lcb->pending_ecoc_reconfig_cfg); temp_p_ccb->reconfig_started = false; - if (result == L2CAP_CFG_OK) { + if (result == tL2CAP_CFG_RESULT::L2CAP_CFG_OK) { temp_p_ccb->local_conn_cfg = p_lcb->pending_ecoc_reconfig_cfg; } } @@ -977,16 +979,14 @@ void l2c_ble_link_adjust_allocation(void) { if (num_lowpri_links > low_quota) { l2cb.ble_round_robin_quota = low_quota; qq = qq_remainder = 0; - } - /* If each low priority link can have at least one buffer */ - else if (num_lowpri_links > 0) { + } else if (num_lowpri_links > 0) { + /* If each low priority link can have at least one buffer */ l2cb.ble_round_robin_quota = 0; l2cb.ble_round_robin_unacked = 0; qq = low_quota / num_lowpri_links; qq_remainder = low_quota % num_lowpri_links; - } - /* If no low priority link */ - else { + } else { + /* If no low priority link */ l2cb.ble_round_robin_quota = 0; l2cb.ble_round_robin_unacked = 0; qq = qq_remainder = 0; diff --git a/system/stack/l2cap/l2c_csm.cc b/system/stack/l2cap/l2c_csm.cc index 7cfdd4fd58..4ff9c33fdb 100644 --- a/system/stack/l2cap/l2c_csm.cc +++ b/system/stack/l2cap/l2c_csm.cc @@ -81,7 +81,7 @@ static void l2c_csm_send_config_req(tL2C_CCB* p_ccb) { // Send a config response with result OK and adjust the state machine static void l2c_csm_send_config_rsp_ok(tL2C_CCB* p_ccb, bool cbit) { tL2CAP_CFG_INFO config{}; - config.result = L2CAP_CFG_OK; + config.result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK; if (cbit) { config.flags = L2CAP_CFG_FLAGS_MASK_CONT; } @@ -951,11 +951,13 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) { p_cfg->flags & L2CAP_CFG_FLAGS_MASK_CONT); l2c_csm_send_config_rsp_ok(p_ccb, p_cfg->flags & L2CAP_CFG_FLAGS_MASK_CONT); if (p_ccb->config_done & OB_CFG_DONE) { - if (p_ccb->remote_config_rsp_result == L2CAP_CFG_OK) { + if (p_ccb->remote_config_rsp_result == tL2CAP_CFG_RESULT::L2CAP_CFG_OK) { l2c_csm_indicate_connection_open(p_ccb); } else { if (p_ccb->connection_initiator == L2CAP_INITIATOR_LOCAL) { - (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid, L2CAP_CFG_FAILED_NO_REASON); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)( + p_ccb->local_cid, + static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON)); bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONFIG_REQ_FAILURE, 1); } @@ -1055,10 +1057,12 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) { /* If failure was channel mode try to renegotiate */ if (!l2c_fcr_renegotiate_chan(p_ccb, p_cfg)) { - log::debug("Calling Config_Rsp_Cb(), CID: 0x{:04x}, Failure: {}", p_ccb->local_cid, - p_cfg->result); + log::debug("Calling Config_Rsp_Cb(), CID: 0x{:04x}, cfg_result:{}", p_ccb->local_cid, + l2cap_cfg_result_text(p_cfg->result)); if (p_ccb->connection_initiator == L2CAP_INITIATOR_LOCAL) { - (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid, L2CAP_CFG_FAILED_NO_REASON); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)( + p_ccb->local_cid, + static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON)); bluetooth::shim::CountCounterMetrics( android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONFIG_RSP_NEG, 1); } diff --git a/system/stack/l2cap/l2c_fcr.cc b/system/stack/l2cap/l2c_fcr.cc index b1f931a23e..6eadd80987 100644 --- a/system/stack/l2cap/l2c_fcr.cc +++ b/system/stack/l2cap/l2c_fcr.cc @@ -1417,8 +1417,8 @@ BT_HDR* l2c_fcr_get_next_xmit_sdu_seg(tL2C_CCB* p_ccb, uint16_t max_packet_lengt log::error("L2CAP - cannot get buffer for segmentation, max_pdu: {}", max_pdu); return NULL; } - } else /* Use the original buffer if no segmentation, or the last segment */ - { + } else { + /* Use the original buffer if no segmentation, or the last segment */ p_xmit = (BT_HDR*)fixed_queue_try_dequeue(p_ccb->xmit_hold_q); if (p_xmit->event != 0) { @@ -1680,12 +1680,12 @@ bool l2c_fcr_renegotiate_chan(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { } /* Only retry if there are more channel options to try */ - if (p_cfg->result == L2CAP_CFG_UNACCEPTABLE_PARAMS) { + if (p_cfg->result == tL2CAP_CFG_RESULT::L2CAP_CFG_UNACCEPTABLE_PARAMS) { peer_mode = (p_cfg->fcr_present) ? p_cfg->fcr.mode : L2CAP_FCR_BASIC_MODE; if (p_ccb->our_cfg.fcr.mode != peer_mode) { if ((--p_ccb->fcr_cfg_tries) == 0) { - p_cfg->result = L2CAP_CFG_FAILED_NO_REASON; + p_cfg->result = tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON; log::warn("l2c_fcr_renegotiate_chan (Max retries exceeded)"); } diff --git a/system/stack/l2cap/l2c_int.h b/system/stack/l2cap/l2c_int.h index b485c28b79..6fa15fc3aa 100644 --- a/system/stack/l2cap/l2c_int.h +++ b/system/stack/l2cap/l2c_int.h @@ -30,16 +30,16 @@ #include <string> +#include "include/macros.h" #include "internal_include/bt_target.h" -#include "l2c_api.h" -#include "l2cdefs.h" -#include "macros.h" #include "osi/include/alarm.h" #include "osi/include/fixed_queue.h" #include "osi/include/list.h" #include "stack/include/bt_hdr.h" #include "stack/include/btm_sec_api_types.h" #include "stack/include/hci_error_code.h" +#include "stack/include/l2c_api.h" +#include "stack/include/l2cdefs.h" #include "types/hci_role.h" #include "types/raw_address.h" @@ -169,8 +169,7 @@ typedef enum : uint16_t { L2CEVT_ACK_TIMEOUT = 34, /* RR delay timeout */ - L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT = 35, /* Upper layer credit packet \ - */ + L2CEVT_L2CA_SEND_FLOW_CONTROL_CREDIT = 35, // Upper layer credit packet /* Peer credit based connection */ L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT = 36, /* credit packet */ L2CEVT_L2CAP_CREDIT_BASED_CONNECT_REQ = 37, /* credit based connection request */ @@ -290,7 +289,7 @@ struct tL2C_CCB { #define RECONFIG_FLAG 0x04 /* True after initial configuration */ uint8_t config_done; /* Configuration flag word */ - uint16_t remote_config_rsp_result; /* The config rsp result from remote */ + tL2CAP_CFG_RESULT remote_config_rsp_result; /* The config rsp result from remote */ uint8_t local_id; /* Transaction ID for local trans */ uint8_t remote_id; /* Transaction ID for local */ @@ -426,6 +425,7 @@ public: private: tHCI_ROLE link_role_{HCI_ROLE_CENTRAL}; /* Central or peripheral */ + public: tHCI_ROLE LinkRole() const { return link_role_; } bool IsLinkRoleCentral() const { return link_role_ == HCI_ROLE_CENTRAL; } @@ -436,8 +436,10 @@ public: uint8_t signal_id; /* Signalling channel id */ uint8_t cur_echo_id; /* Current id value for echo request */ uint16_t idle_timeout; /* Idle timeout */ + private: bool is_bonding_{false}; /* True - link active only for bonding */ + public: bool IsBonding() const { return is_bonding_; } void SetBonding() { is_bonding_ = true; } @@ -486,8 +488,8 @@ public: } tL2C_CCB* p_fixed_ccbs[L2CAP_NUM_FIXED_CHNLS]; - std::vector<uint16_t> suspended; /* List of fixed channel CIDs which are suspended but not - * removed */ + std::vector<uint16_t> suspended; // List of fixed channel CIDs which are suspended but not + // removed private: tHCI_REASON disc_reason_{HCI_ERR_UNDEFINED}; @@ -501,8 +503,8 @@ public: bool is_transport_ble() const { return transport == BT_TRANSPORT_LE; } uint16_t tx_data_len; /* tx data length used in data length extension */ - fixed_queue_t* le_sec_pending_q; /* LE coc channels waiting for security check - completion */ + fixed_queue_t* le_sec_pending_q; // LE coc channels waiting for security check + // completion uint8_t sec_act; uint8_t conn_update_mask; @@ -725,7 +727,7 @@ void l2cu_tx_complete(tL2C_TX_COMPLETE_CB_INFO* p_cbi); void l2cu_send_peer_ble_par_req(tL2C_LCB* p_lcb, uint16_t min_int, uint16_t max_int, uint16_t latency, uint16_t timeout); -void l2cu_send_peer_ble_par_rsp(tL2C_LCB* p_lcb, uint16_t reason, uint8_t rem_id); +void l2cu_send_peer_ble_par_rsp(tL2C_LCB* p_lcb, tL2CAP_CFG_RESULT reason, uint8_t rem_id); void l2cu_reject_ble_connection(tL2C_CCB* p_ccb, uint8_t rem_id, uint16_t result); void l2cu_reject_credit_based_conn_req(tL2C_LCB* p_lcb, uint8_t rem_id, uint8_t num_of_channels, uint16_t result); diff --git a/system/stack/l2cap/l2c_main.cc b/system/stack/l2cap/l2c_main.cc index c136a5c52e..8f54365279 100644 --- a/system/stack/l2cap/l2c_main.cc +++ b/system/stack/l2cap/l2c_main.cc @@ -567,9 +567,8 @@ static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { cfg_rej_len += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; cfg_rej = true; } - } - /* bad length; force loop exit */ - else { + } else { + /* bad length; force loop exit */ p = p_cfg_end; cfg_rej = true; } @@ -602,8 +601,9 @@ static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { } STREAM_TO_UINT16(lcid, p); STREAM_TO_UINT16(cfg_info.flags, p); - STREAM_TO_UINT16(cfg_info.result, p); - + uint16_t cfg_result; + STREAM_TO_UINT16(cfg_result, p); + cfg_info.result = static_cast<tL2CAP_CFG_RESULT>(cfg_result); cfg_info.flush_to_present = cfg_info.mtu_present = cfg_info.qos_present = cfg_info.fcr_present = cfg_info.fcs_present = false; @@ -695,7 +695,7 @@ static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { log::warn("cfg rsp - bad ID. Exp: {} Got: {}", p_ccb->local_id, id); break; } - if (cfg_info.result == L2CAP_CFG_OK) { + if (cfg_info.result == tL2CAP_CFG_RESULT::L2CAP_CFG_OK) { l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONFIG_RSP, &cfg_info); } else { l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONFIG_RSP_NEG, &cfg_info); diff --git a/system/stack/l2cap/l2c_utils.cc b/system/stack/l2cap/l2c_utils.cc index 169a77c463..1ef22ca2e1 100644 --- a/system/stack/l2cap/l2c_utils.cc +++ b/system/stack/l2cap/l2c_utils.cc @@ -705,7 +705,7 @@ void l2cu_send_peer_config_rsp(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { UINT16_TO_STREAM(p, p_ccb->remote_cid); UINT16_TO_STREAM(p, p_cfg->flags); /* Flags (continuation) Must match request */ - UINT16_TO_STREAM(p, p_cfg->result); + UINT16_TO_STREAM(p, static_cast<uint16_t>(p_cfg->result)); /* Now, put the options */ if (p_cfg->mtu_present) { @@ -808,7 +808,7 @@ void l2cu_send_peer_config_rej(tL2C_CCB* p_ccb, uint8_t* p_data, uint16_t data_l UINT16_TO_STREAM(p, p_ccb->remote_cid); UINT16_TO_STREAM(p, 0); /* Flags = 0 (no continuation) */ - UINT16_TO_STREAM(p, L2CAP_CFG_UNKNOWN_OPTIONS); + UINT16_TO_STREAM(p, static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_UNKNOWN_OPTIONS)); buf_space = rej_len; @@ -845,9 +845,8 @@ void l2cu_send_peer_config_rej(tL2C_CCB* p_ccb, uint8_t* p_data, uint16_t data_l } } p_data += cfg_len + L2CAP_CFG_OPTION_OVERHEAD; - } - /* bad length; force loop exit */ - else { + } else { + /* bad length; force loop exit */ p_data = p_data_end; } break; @@ -1901,9 +1900,8 @@ uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { p_cfg->mtu = required_remote_mtu; mtu_ok = false; } - } - /* Reload mtu from a previously accepted config request */ - else if (p_ccb->peer_cfg.mtu_present && !(p_ccb->config_done & IB_CFG_DONE)) { + } else if (p_ccb->peer_cfg.mtu_present && !(p_ccb->config_done & IB_CFG_DONE)) { + /* Reload mtu from a previously accepted config request */ p_cfg->mtu_present = true; p_cfg->mtu = p_ccb->peer_cfg.mtu; } @@ -1918,9 +1916,8 @@ uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { p_ccb->peer_cfg.flush_to_present = true; p_ccb->peer_cfg.flush_to = p_cfg->flush_to; } - } - /* Reload flush_to from a previously accepted config request */ - else if (p_ccb->peer_cfg.flush_to_present && !(p_ccb->config_done & IB_CFG_DONE)) { + } else if (p_ccb->peer_cfg.flush_to_present && !(p_ccb->config_done & IB_CFG_DONE)) { + /* Reload flush_to from a previously accepted config request */ p_cfg->flush_to_present = true; p_cfg->flush_to = p_ccb->peer_cfg.flush_to; } @@ -1933,14 +1930,13 @@ uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { if (p_cfg->qos.service_type <= SVC_TYPE_GUARANTEED) { p_ccb->peer_cfg.qos = p_cfg->qos; p_ccb->peer_cfg.qos_present = true; - } else /* Illegal service type value */ - { + } else { + /* Illegal service type value */ p_cfg->qos.service_type = SVC_TYPE_BEST_EFFORT; qos_type_ok = false; } - } - /* Reload QOS from a previously accepted config request */ - else if (p_ccb->peer_cfg.qos_present && !(p_ccb->config_done & IB_CFG_DONE)) { + } else if (p_ccb->peer_cfg.qos_present && !(p_ccb->config_done & IB_CFG_DONE)) { + /* Reload QOS from a previously accepted config request */ p_cfg->qos_present = true; p_cfg->qos = p_ccb->peer_cfg.qos; } @@ -1948,7 +1944,7 @@ uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { fcr_status = l2c_fcr_process_peer_cfg_req(p_ccb, p_cfg); if (fcr_status == L2CAP_PEER_CFG_DISCONNECT) { /* Notify caller to disconnect the channel (incompatible modes) */ - p_cfg->result = L2CAP_CFG_FAILED_NO_REASON; + p_cfg->result = tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON; p_cfg->mtu_present = p_cfg->qos_present = p_cfg->flush_to_present = 0; return L2CAP_PEER_CFG_DISCONNECT; @@ -1961,7 +1957,7 @@ uint8_t l2cu_process_peer_cfg_req(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) { l2cu_adjust_out_mps(p_ccb); return L2CAP_PEER_CFG_OK; } else { - p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; + p_cfg->result = tL2CAP_CFG_RESULT::L2CAP_CFG_UNACCEPTABLE_PARAMS; if (mtu_ok) { p_cfg->mtu_present = false; @@ -2254,9 +2250,8 @@ bool l2cu_lcb_disconnecting(void) { if ((!p_lcb->ccb_queue.p_first_ccb) || (p_lcb->link_state == LST_DISCONNECTING)) { status = true; break; - } - /* only one ccb left on lcb */ - else if (p_lcb->ccb_queue.p_first_ccb == p_lcb->ccb_queue.p_last_ccb) { + } else if (p_lcb->ccb_queue.p_first_ccb == p_lcb->ccb_queue.p_last_ccb) { + /* only one ccb left on lcb */ p_ccb = p_lcb->ccb_queue.p_first_ccb; if ((p_ccb->in_use) && ((p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP) || @@ -2962,7 +2957,7 @@ void l2cu_send_peer_ble_par_req(tL2C_LCB* p_lcb, uint16_t min_int, uint16_t max_ * Returns void * ******************************************************************************/ -void l2cu_send_peer_ble_par_rsp(tL2C_LCB* p_lcb, uint16_t reason, uint8_t rem_id) { +void l2cu_send_peer_ble_par_rsp(tL2C_LCB* p_lcb, tL2CAP_CFG_RESULT reason, uint8_t rem_id) { BT_HDR* p_buf; uint8_t* p; @@ -2975,7 +2970,7 @@ void l2cu_send_peer_ble_par_rsp(tL2C_LCB* p_lcb, uint16_t reason, uint8_t rem_id p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD + L2CAP_CMD_OVERHEAD; - UINT16_TO_STREAM(p, reason); + UINT16_TO_STREAM(p, static_cast<uint16_t>(reason)); l2c_link_check_send_pkts(p_lcb, 0, p_buf); } @@ -3461,9 +3456,8 @@ tL2C_CCB* l2cu_find_ccb_by_cid(tL2C_LCB* p_lcb, uint16_t local_cid) { /* make sure the CCB is in use */ if (!p_ccb->in_use) { p_ccb = NULL; - } - /* make sure it's for the same LCB */ - else if (p_lcb && p_lcb != p_ccb->p_lcb) { + } else if (p_lcb && p_lcb != p_ccb->p_lcb) { + /* make sure it's for the same LCB */ p_ccb = NULL; } } diff --git a/system/stack/rfcomm/rfc_l2cap_if.cc b/system/stack/rfcomm/rfc_l2cap_if.cc index 2527abec75..d807748cf9 100644 --- a/system/stack/rfcomm/rfc_l2cap_if.cc +++ b/system/stack/rfcomm/rfc_l2cap_if.cc @@ -221,7 +221,7 @@ void RFCOMM_ConfigCnf(uint16_t lcid, uint16_t /* initiator */, tL2CAP_CFG_INFO* log::error("RFCOMM_ConfigCnf no MCB LCID:0x{:x}", lcid); return; } - uintptr_t result_as_ptr = L2CAP_CFG_OK; + uintptr_t result_as_ptr = static_cast<unsigned>(tL2CAP_CFG_RESULT::L2CAP_CFG_OK); rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONF_CNF, (void*)result_as_ptr); } diff --git a/system/stack/rfcomm/rfc_mx_fsm.cc b/system/stack/rfcomm/rfc_mx_fsm.cc index 93db778d1b..05318ce4db 100644 --- a/system/stack/rfcomm/rfc_mx_fsm.cc +++ b/system/stack/rfcomm/rfc_mx_fsm.cc @@ -562,7 +562,7 @@ void rfc_mx_sm_state_disc_wait_ua(tRFC_MCB* p_mcb, tRFC_MX_EVENT event, void* p_ rfcomm_mx_state_text(p_mcb->state)); } -void rfc_on_l2cap_error(uint16_t lcid, uint16_t result) { +void rfc_on_l2cap_error(uint16_t lcid, uint16_t /* tL2CAP_CONN */ result) { tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); if (p_mcb == nullptr) { return; @@ -600,7 +600,7 @@ void rfc_on_l2cap_error(uint16_t lcid, uint16_t result) { if (p_mcb->pending_configure_complete) { log::info("Configuration of the pending connection was completed"); p_mcb->pending_configure_complete = false; - uintptr_t result_as_ptr = L2CAP_CFG_OK; + uintptr_t result_as_ptr = L2CAP_CONN_OK; rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONF_IND, &p_mcb->pending_cfg_info); rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONF_CNF, (void*)result_as_ptr); } @@ -609,7 +609,7 @@ void rfc_on_l2cap_error(uint16_t lcid, uint16_t result) { p_mcb->lcid = lcid; rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONN_CNF, &result); - } else if (result == L2CAP_CFG_FAILED_NO_REASON) { + } else if (result == static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON)) { log::error("failed to configure L2CAP for {}", p_mcb->bd_addr); if (p_mcb->is_initiator) { log::error("disconnect L2CAP due to config failure for {}", p_mcb->bd_addr); diff --git a/system/stack/test/eatt/eatt_test.cc b/system/stack/test/eatt/eatt_test.cc index 18c4cfa1f8..f55a13987a 100644 --- a/system/stack/test/eatt/eatt_test.cc +++ b/system/stack/test/eatt/eatt_test.cc @@ -22,18 +22,17 @@ #include <vector> -#include "bind_helpers.h" +#include "bta/test/common/fake_osi.h" #include "hci/controller_interface_mock.h" -#include "l2c_api.h" -#include "mock_btif_storage.h" -#include "mock_btm_api_layer.h" -#include "mock_eatt.h" -#include "mock_gatt_layer.h" -#include "mock_l2cap_layer.h" +#include "include/bind_helpers.h" #include "stack/include/bt_hdr.h" #include "stack/include/bt_psm_types.h" #include "stack/include/l2cdefs.h" -#include "test/common/fake_osi.h" +#include "stack/test/common/mock_btif_storage.h" +#include "stack/test/common/mock_btm_api_layer.h" +#include "stack/test/common/mock_eatt.h" +#include "stack/test/common/mock_gatt_layer.h" +#include "stack/test/common/mock_l2cap_layer.h" #include "test/mock/mock_main_shim_entry.h" #include "types/raw_address.h" @@ -447,7 +446,7 @@ TEST_F(EattTest, ReconfigAllSucceed) { ASSERT_TRUE(cids.size() == connected_cids_.size()); - tL2CAP_LE_CFG_INFO cfg = {.result = L2CAP_CFG_OK, .mtu = new_mtu}; + tL2CAP_LE_CFG_INFO cfg = {.result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, .mtu = new_mtu}; for (uint16_t cid : cids) { l2cap_app_info_.pL2CA_CreditBasedReconfigCompleted_Cb(test_address, cid, true, &cfg); @@ -472,7 +471,8 @@ TEST_F(EattTest, ReconfigAllFailed) { ASSERT_TRUE(cids.size() == connected_cids_.size()); - tL2CAP_LE_CFG_INFO cfg = {.result = L2CAP_CFG_FAILED_NO_REASON, .mtu = new_mtu}; + tL2CAP_LE_CFG_INFO cfg = {.result = tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON, + .mtu = new_mtu}; for (uint16_t cid : cids) { l2cap_app_info_.pL2CA_CreditBasedReconfigCompleted_Cb(test_address, cid, true, &cfg); @@ -497,7 +497,7 @@ TEST_F(EattTest, ReconfigSingleSucceed) { ASSERT_TRUE(cids.size() == 1); - tL2CAP_LE_CFG_INFO cfg = {.result = L2CAP_CFG_OK, .mtu = new_mtu}; + tL2CAP_LE_CFG_INFO cfg = {.result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, .mtu = new_mtu}; auto it = std::find(connected_cids_.begin(), connected_cids_.end(), cids[0]); ASSERT_TRUE(it != connected_cids_.end()); @@ -522,7 +522,8 @@ TEST_F(EattTest, ReconfigSingleFailed) { ASSERT_TRUE(cids.size() == connected_cids_.size()); - tL2CAP_LE_CFG_INFO cfg = {.result = L2CAP_CFG_FAILED_NO_REASON, .mtu = new_mtu}; + tL2CAP_LE_CFG_INFO cfg = {.result = tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON, + .mtu = new_mtu}; auto it = std::find(connected_cids_.begin(), connected_cids_.end(), cids[0]); ASSERT_TRUE(it != connected_cids_.end()); @@ -539,7 +540,7 @@ TEST_F(EattTest, ReconfigPeerSucceed) { ConnectDeviceEattSupported(3); uint16_t new_mtu = 300; - tL2CAP_LE_CFG_INFO cfg = {.result = L2CAP_CFG_OK, .mtu = new_mtu}; + tL2CAP_LE_CFG_INFO cfg = {.result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, .mtu = new_mtu}; for (uint16_t cid : connected_cids_) { l2cap_app_info_.pL2CA_CreditBasedReconfigCompleted_Cb(test_address, cid, false, &cfg); @@ -556,7 +557,8 @@ TEST_F(EattTest, ReconfigPeerFailed) { ConnectDeviceEattSupported(2); uint16_t new_mtu = 300; - tL2CAP_LE_CFG_INFO cfg = {.result = L2CAP_CFG_FAILED_NO_REASON, .mtu = new_mtu}; + tL2CAP_LE_CFG_INFO cfg = {.result = tL2CAP_CFG_RESULT::L2CAP_CFG_FAILED_NO_REASON, + .mtu = new_mtu}; for (uint16_t cid : connected_cids_) { l2cap_app_info_.pL2CA_CreditBasedReconfigCompleted_Cb(test_address, cid, false, &cfg); diff --git a/system/stack/test/rfcomm/stack_rfcomm_test.cc b/system/stack/test/rfcomm/stack_rfcomm_test.cc index 669836d362..07c21b24aa 100644 --- a/system/stack/test/rfcomm/stack_rfcomm_test.cc +++ b/system/stack/test/rfcomm/stack_rfcomm_test.cc @@ -21,18 +21,17 @@ #include <gtest/gtest.h> #include "internal_include/bt_target.h" -#include "mock_btm_layer.h" -#include "mock_l2cap_layer.h" #include "osi/include/allocator.h" #include "stack/include/bt_hdr.h" #include "stack/include/bt_psm_types.h" #include "stack/include/btm_status.h" -#include "stack/include/l2c_api.h" #include "stack/include/l2cdefs.h" #include "stack/include/port_api.h" #include "stack/include/rfcdefs.h" -#include "stack_rfcomm_test_utils.h" -#include "stack_test_packet_utils.h" +#include "stack/test/common/mock_btm_layer.h" +#include "stack/test/common/mock_l2cap_layer.h" +#include "stack/test/common/stack_test_packet_utils.h" +#include "stack/test/rfcomm/stack_rfcomm_test_utils.h" #include "types/raw_address.h" using namespace bluetooth; @@ -153,7 +152,8 @@ public: log::verbose("Step 2"); // MTU configuration is done cfg_req.mtu_present = false; - l2cap_appl_info_.pL2CA_ConfigCfm_Cb(lcid, L2CAP_CFG_OK, {}); + l2cap_appl_info_.pL2CA_ConfigCfm_Cb(lcid, + static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_OK), {}); log::verbose("Step 3"); // Remote device also ask to configure MTU size @@ -276,7 +276,8 @@ public: log::verbose("Step 2"); // Remote device confirms our configuration request cfg_req.mtu_present = false; - l2cap_appl_info_.pL2CA_ConfigCfm_Cb(lcid, L2CAP_CFG_OK, {}); + l2cap_appl_info_.pL2CA_ConfigCfm_Cb(lcid, + static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_OK), {}); log::verbose("Step 3"); // Remote device also asks to configure MTU @@ -680,14 +681,16 @@ TEST_F(StackRfcommTest, DISABLED_TestConnectionCollision) { // Remote device also ask to configure MTU size as well tL2CAP_CFG_INFO peer_cfg_req = {.mtu_present = true, .mtu = test_mtu}; // We responded by saying OK - tL2CAP_CFG_INFO our_cfg_rsp = {.result = L2CAP_CFG_OK, .mtu = peer_cfg_req.mtu}; + tL2CAP_CFG_INFO our_cfg_rsp = {.result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, + .mtu = peer_cfg_req.mtu}; EXPECT_CALL(l2cap_interface_, ConfigResponse(new_lcid, PointerMemoryEqual(&our_cfg_rsp))) .WillOnce(Return(true)); l2cap_appl_info_.pL2CA_ConfigInd_Cb(new_lcid, &peer_cfg_req); log::verbose("Step 6"); // Remote device accepted our MTU size - l2cap_appl_info_.pL2CA_ConfigCfm_Cb(new_lcid, L2CAP_CFG_OK, {}); + l2cap_appl_info_.pL2CA_ConfigCfm_Cb(new_lcid, + static_cast<uint16_t>(tL2CAP_CFG_RESULT::L2CAP_CFG_OK), {}); // L2CAP collision and connection setup done diff --git a/system/stack/test/stack_l2cap_test.cc b/system/stack/test/stack_l2cap_test.cc index f3811f881c..482863631e 100644 --- a/system/stack/test/stack_l2cap_test.cc +++ b/system/stack/test/stack_l2cap_test.cc @@ -20,10 +20,10 @@ #include <gtest/gtest.h> #include <sys/socket.h> -#include "bt_psm_types.h" #include "hci/controller_interface_mock.h" #include "osi/include/allocator.h" #include "stack/btm/btm_int_types.h" +#include "stack/include/bt_psm_types.h" #include "stack/include/l2cap_controller_interface.h" #include "stack/include/l2cap_hci_link_interface.h" #include "stack/include/l2cap_module.h" @@ -100,7 +100,7 @@ protected: .local_conn_cfg = { // tL2CAP_LE_CFG_INFO - .result = 0, + .result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, .mtu = 100, .mps = 100, .credits = L2CA_LeCreditDefault(), @@ -109,7 +109,7 @@ protected: .peer_conn_cfg = { // tL2CAP_LE_CFG_INFO - .result = 0, + .result = tL2CAP_CFG_RESULT::L2CAP_CFG_OK, .mtu = 100, .mps = 100, .credits = L2CA_LeCreditDefault(), @@ -123,12 +123,13 @@ protected: .p_lcb = nullptr, // struct t_l2c_linkcb* Link this CCB is assigned to .local_cid = 40, .remote_cid = 80, - .l2c_ccb_timer = nullptr, // alarm_t* CCB Timer Entry - .p_rcb = nullptr, // tL2C_RCB* Registration CB for this Channel - .config_done = 0, // Configuration flag word - .remote_config_rsp_result = 0, // The config rsp result from remote - .local_id = 12, // Transaction ID for local trans - .remote_id = 22, // Transaction ID for local + .l2c_ccb_timer = nullptr, // alarm_t* CCB Timer Entry + .p_rcb = nullptr, // tL2C_RCB* Registration CB for this Channel + .config_done = 0, // Configuration flag word + .remote_config_rsp_result = + tL2CAP_CFG_RESULT::L2CAP_CFG_OK, // The config rsp result from remote + .local_id = 12, // Transaction ID for local trans + .remote_id = 22, // Transaction ID for local .flags = 0, .connection_initiator = false, .our_cfg = {}, // tL2CAP_CFG_INFO Our saved configuration options diff --git a/system/test/mock/mock_stack_l2cap_utils.cc b/system/test/mock/mock_stack_l2cap_utils.cc index 56030a7c56..15ffa85e84 100644 --- a/system/test/mock/mock_stack_l2cap_utils.cc +++ b/system/test/mock/mock_stack_l2cap_utils.cc @@ -187,7 +187,7 @@ void l2cu_send_peer_ble_par_req(tL2C_LCB* /* p_lcb */, uint16_t /* min_int */, uint16_t /* timeout */) { inc_func_call_count(__func__); } -void l2cu_send_peer_ble_par_rsp(tL2C_LCB* /* p_lcb */, uint16_t /* reason */, +void l2cu_send_peer_ble_par_rsp(tL2C_LCB* /* p_lcb */, tL2CAP_CFG_RESULT /* reason */, uint8_t /* rem_id */) { inc_func_call_count(__func__); } |