Snap for 8603585 from 278f5cc84f614da56abeab4fa7273b769dbde153 to mainline-conscrypt-release Change-Id: Ib32bf415b211d5a2162aaaff911531bcc775ae47
diff --git a/1.2/hal_st21nfc.cc b/1.2/hal_st21nfc.cc index 5efc6b1..71cb7aa 100644 --- a/1.2/hal_st21nfc.cc +++ b/1.2/hal_st21nfc.cc
@@ -30,6 +30,7 @@ #include "android_logmsg.h" #include "hal_config.h" #include "halcore.h" +#include "st21nfc_dev.h" #define VENDOR_LIB_PATH "/vendor/lib64/" #define VENDOR_LIB_EXT ".so" @@ -40,15 +41,6 @@ typedef int (*STEseReset)(void); -typedef struct { - struct nfc_nci_device nci_device; // nci_device must be first struct member - // below declarations are private variables within HAL - nfc_stack_callback_t* p_cback; - nfc_stack_data_callback_t* p_data_cback; - HALHANDLE hHAL; - nfc_stack_callback_t* p_cback_unwrap; -} st21nfc_dev_t; - const char* halVersion = "ST21NFC HAL1.2 Version 3.2.54"; uint8_t cmd_set_nfc_mode_enable[] = {0x2f, 0x02, 0x02, 0x02, 0x01};
diff --git a/aidl/Nfc.cpp b/aidl/Nfc.cpp index dc8ee62..bcadc16 100644 --- a/aidl/Nfc.cpp +++ b/aidl/Nfc.cpp
@@ -25,22 +25,28 @@ namespace hardware { namespace nfc { +typedef struct { + uint64_t mOpenCount; + Nfc* nfc; +} stHalCookie; + std::shared_ptr<INfcClientCallback> Nfc::mCallback = nullptr; AIBinder_DeathRecipient* clientDeathRecipient = nullptr; pthread_mutex_t mLockOpenClose = PTHREAD_MUTEX_INITIALIZER; uint64_t mOpenCount = 0; +stHalCookie mHalCookie; void OnDeath(void* cookie) { pthread_mutex_lock(&mLockOpenClose); - LOG(INFO) << __func__ << "cookie : " << (*(uint64_t*)cookie) << " mOpenCount " - << (unsigned long long)mOpenCount; - if (*(uint64_t*)cookie == mOpenCount) { + stHalCookie* mCookie = static_cast<stHalCookie*>(cookie); + LOG(INFO) << __func__ << "cookie : " << mCookie->mOpenCount + << " mOpenCount : " << mOpenCount; + if (mCookie->mOpenCount == mOpenCount) { if (Nfc::mCallback != nullptr && !AIBinder_isAlive(Nfc::mCallback->asBinder().get())) { LOG(INFO) << __func__ << " Nfc service has died"; pthread_mutex_unlock(&mLockOpenClose); - Nfc* nfc = static_cast<Nfc*>(cookie); - nfc->close(NfcCloseType::DISABLE); + mCookie->nfc->close(NfcCloseType::DISABLE); } } pthread_mutex_unlock(&mLockOpenClose); @@ -57,18 +63,20 @@ pthread_mutex_lock(&mLockOpenClose); mOpenCount++; Nfc::mCallback = clientCallback; + mHalCookie.mOpenCount = mOpenCount; + mHalCookie.nfc = this; clientDeathRecipient = AIBinder_DeathRecipient_new(OnDeath); auto linkRet = AIBinder_linkToDeath(clientCallback->asBinder().get(), - clientDeathRecipient, &mOpenCount /* cookie */); + clientDeathRecipient, &mHalCookie /* cookie */); if (linkRet != STATUS_OK) { LOG(ERROR) << __func__ << ": linkToDeath failed: " << linkRet; // Just ignore the error. } int ret = StNfc_hal_open(eventCallback, dataCallback); - LOG(INFO) << "Nfc::open Exit count " << (unsigned long long)mOpenCount; + LOG(INFO) << "Nfc::open Exit count " << mOpenCount; pthread_mutex_unlock(&mLockOpenClose); return ret == 0 ? ndk::ScopedAStatus::ok() : ndk::ScopedAStatus::fromServiceSpecificError(
diff --git a/aidl/hal_st21nfc.cc b/aidl/hal_st21nfc.cc index 2ae28c8..755ece1 100644 --- a/aidl/hal_st21nfc.cc +++ b/aidl/hal_st21nfc.cc
@@ -29,6 +29,7 @@ #include "android_logmsg.h" #include "hal_config.h" #include "halcore.h" +#include "st21nfc_dev.h" #define VENDOR_LIB_PATH "/vendor/lib64/" #define VENDOR_LIB_EXT ".so" @@ -41,14 +42,6 @@ typedef int (*STEseReset)(void); -typedef struct { - // below declarations are private variables within HAL - nfc_stack_callback_t* p_cback; - nfc_stack_data_callback_t* p_data_cback; - HALHANDLE hHAL; - nfc_stack_callback_t* p_cback_unwrap; -} st21nfc_dev_t; - const char* halVersion = "ST21NFC AIDL Version 1.0.0"; uint8_t cmd_set_nfc_mode_enable[] = {0x2f, 0x02, 0x02, 0x02, 0x01};
diff --git a/st21nfc/hal/halcore.cc b/st21nfc/hal/halcore.cc index e7bb319..67ecbf9 100644 --- a/st21nfc/hal/halcore.cc +++ b/st21nfc/hal/halcore.cc
@@ -25,8 +25,10 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> + #include "android_logmsg.h" #include "halcore_private.h" +#include "st21nfc_dev.h" extern int I2cWriteCmd(const uint8_t* x, size_t len); extern void DispHal(const char* title, const void* data, size_t length); @@ -38,14 +40,6 @@ static bool rf_deactivate_delay; struct timespec start_tx_data; -typedef struct { - struct nfc_nci_device nci_device; // nci_device must be first struct member - // below declarations are private variables within HAL - nfc_stack_callback_t* p_cback; - nfc_stack_data_callback_t* p_data_cback; - HALHANDLE hHAL; -} st21nfc_dev_t; // beware, is a duplication of structure in nfc_nci_st21nfc.c - /************************************************************************************************** * * Private API Declaration
diff --git a/st21nfc/hal_wrapper.cc b/st21nfc/hal_wrapper.cc index 65cfc1a..5c97179 100644 --- a/st21nfc/hal_wrapper.cc +++ b/st21nfc/hal_wrapper.cc
@@ -23,9 +23,11 @@ #include <log/log.h> #include <string.h> #include <unistd.h> + #include "android_logmsg.h" #include "hal_fd.h" #include "halcore.h" +#include "st21nfc_dev.h" extern void HalCoreCallback(void* context, uint32_t event, const void* d, size_t length); @@ -33,14 +35,6 @@ extern void I2cCloseLayer(); extern void I2cRecovery(); -typedef struct { - struct nfc_nci_device nci_device; // nci_device must be first struct member - // below declarations are private variables within HAL - nfc_stack_callback_t* p_cback; - nfc_stack_data_callback_t* p_data_cback; - HALHANDLE hHAL; -} st21nfc_dev_t; - static void halWrapperDataCallback(uint16_t data_len, uint8_t* p_data); static void halWrapperCallback(uint8_t event, uint8_t event_status); @@ -206,6 +200,8 @@ uint8_t coreInitCmd[] = {0x20, 0x01, 0x02, 0x00, 0x00}; uint8_t coreResetCmd[] = {0x20, 0x00, 0x01, 0x01}; unsigned long num = 0; + unsigned long swp_log = 0; + unsigned long rf_log = 0; int nciPropEnableFwDbgTraces_size = sizeof(nciPropEnableFwDbgTraces); switch (mHalWrapperState) { @@ -395,6 +391,30 @@ if (GetNumValue(NAME_STNFC_FW_DEBUG_ENABLED, &num, sizeof(num)) || isDebuggable) { if (firmware_debug_enabled) num = 1; + + if (num == 1) { + GetNumValue(NAME_STNFC_FW_SWP_LOG_SIZE, &swp_log, + sizeof(swp_log)); + GetNumValue(NAME_STNFC_FW_RF_LOG_SIZE, &rf_log, sizeof(rf_log)); + } + // limit swp and rf payload length between 4 and 30. + if (swp_log > 30) + swp_log = 30; + else if (swp_log < 4) + swp_log = 4; + + if (rf_log > 30) + rf_log = 30; + else if (rf_log < 4) + rf_log = 4; + + if ((rf_log || swp_log) && + ((p_data[15] != rf_log) || (p_data[17] != swp_log))) { + STLOG_HAL_D("%s - FW DBG payload traces changes needed", + __func__); + confNeeded = true; + } + // If conf file indicate set needed and not yet enabled if ((num == 1) && (p_data[7] == 0x00)) { STLOG_HAL_D("%s - FW DBG traces enabling needed", __func__); @@ -405,8 +425,9 @@ nciPropEnableFwDbgTraces[9] = 0x00; confNeeded = true; } else { - STLOG_HAL_D("%s - No changes in FW DBG traces config needed", - __func__); + STLOG_HAL_D( + "%s - No FW DBG traces enable/disable change needed", + __func__); } if (data_len < 9 || p_data[6] == 0 || p_data[6] < (data_len - 7) @@ -421,6 +442,11 @@ memcpy(nciPropEnableFwDbgTraces, nciHeaderPropSetConfig, 9); memcpy(&nciPropEnableFwDbgTraces[10], &p_data[8], p_data[6] - 1); + if (rf_log || swp_log) { + nciPropEnableFwDbgTraces[9] = (uint8_t)num; + nciPropEnableFwDbgTraces[17] = (uint8_t)rf_log; + nciPropEnableFwDbgTraces[19] = (uint8_t)swp_log; + } if ((9 + p_data[6]) < sizeof(nciPropEnableFwDbgTraces)) { nciPropEnableFwDbgTraces_size = 9 + p_data[6]; }
diff --git a/st21nfc/include/android_logmsg.h b/st21nfc/include/android_logmsg.h index fcb0462..66c05b7 100644 --- a/st21nfc/include/android_logmsg.h +++ b/st21nfc/include/android_logmsg.h
@@ -52,6 +52,8 @@ #define NAME_STNFC_CONTROL_CLK "STNFC_CONTROL_CLK" #define NAME_STNFC_UWB_LIB_NAME "STNFC_UWB_LIB_NAME" #define NAME_STNFC_ACTIVERW_TIMER "STNFC_ACTIVERW_TIMER" +#define NAME_STNFC_FW_SWP_LOG_SIZE "STNFC_FW_SWP_LOG_SIZE" +#define NAME_STNFC_FW_RF_LOG_SIZE "STNFC_FW_RF_LOG_SIZE" /* ####################### * Set the logging level
diff --git a/st21nfc/include/st21nfc_dev.h b/st21nfc/include/st21nfc_dev.h new file mode 100644 index 0000000..de48e70 --- /dev/null +++ b/st21nfc/include/st21nfc_dev.h
@@ -0,0 +1,29 @@ +/** ---------------------------------------------------------------------- + * + * Copyright (C) 2022 ST Microelectronics S.A. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + ----------------------------------------------------------------------*/ +#ifndef __ST21NFC_DEV__ +#define __ST21NFC_DEV__ + +typedef struct { + nfc_stack_callback_t* p_cback; + nfc_stack_data_callback_t* p_data_cback; + HALHANDLE hHAL; + nfc_stack_callback_t* p_cback_unwrap; +} st21nfc_dev_t; + +#endif