Merge "Define 2 new entries for libnfc-hal-st.conf" am: 2789b16708

Original change: https://android-review.googlesource.com/c/platform/hardware/st/nfc/+/2036446

Change-Id: Ie5fc3bb3d1cf6b79011b1c2cbf55be0f085bdaa6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/st21nfc/hal_wrapper.cc b/st21nfc/hal_wrapper.cc
index aa2aad2..5c97179 100644
--- a/st21nfc/hal_wrapper.cc
+++ b/st21nfc/hal_wrapper.cc
@@ -200,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) {
@@ -389,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__);
@@ -399,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)
@@ -415,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