DO NOT MERGE - Mark RQ3A.210410.001 as merged
Bug: 190855093
Merged-In: I382911dc3243e2364a81a4c7ac2a2e23056da2ff
Change-Id: I489725b9da3f9e3eb47012073f9a72b2fbce50ba
diff --git a/1.0/Android.bp b/1.0/Android.bp
index bfe1da2..3946c8d 100644
--- a/1.0/Android.bp
+++ b/1.0/Android.bp
@@ -12,6 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+package {
+ // http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // the below license kinds from "hardware_st_nfc_license":
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["hardware_st_nfc_license"],
+}
+
cc_library_shared {
name: "nfc_nci.st21nfc",
proprietary: true,
diff --git a/1.1/Android.bp b/1.1/Android.bp
index 7afc354..568dd84 100644
--- a/1.1/Android.bp
+++ b/1.1/Android.bp
@@ -12,6 +12,14 @@
// 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.
+package {
+ // http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // the below license kinds from "hardware_st_nfc_license":
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["hardware_st_nfc_license"],
+}
+
cc_binary {
name: "android.hardware.nfc@1.1-service.st",
defaults: ["hidl_defaults"],
@@ -35,4 +43,8 @@
"android.hardware.nfc@1.1",
"libhidlbase",
],
+
+ sanitize: {
+ memtag_heap: true,
+ },
}
diff --git a/1.1/hal_st21nfc.cc b/1.1/hal_st21nfc.cc
index 7c5c8c8..c88ea8b 100644
--- a/1.1/hal_st21nfc.cc
+++ b/1.1/hal_st21nfc.cc
@@ -370,6 +370,8 @@
hal_dta_state = 0;
+ deInitializeHalLog();
+
if (async_callback_thread_end() != 0) {
STLOG_HAL_E("HAL st21nfc: %s async_callback_thread_end failed", __func__);
return -1; // We are doomed, stop it here, NOW !
diff --git a/1.2/Android.bp b/1.2/Android.bp
index f09d9ed..78c7d4d 100644
--- a/1.2/Android.bp
+++ b/1.2/Android.bp
@@ -13,6 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+package {
+ // http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // the below license kinds from "hardware_st_nfc_license":
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["hardware_st_nfc_license"],
+}
+
cc_binary {
name: "android.hardware.nfc@1.2-service.st",
defaults: ["hidl_defaults"],
@@ -34,7 +42,11 @@
"libutils",
"android.hardware.nfc@1.0",
"android.hardware.nfc@1.1",
- "android.hardware.nfc@1.2",
+ "android.hardware.nfc@1.2",
"libhidlbase",
],
+
+ sanitize: {
+ memtag_heap: true,
+ },
}
diff --git a/1.2/hal_st21nfc.cc b/1.2/hal_st21nfc.cc
index 8397fe5..fb4f3c9 100644
--- a/1.2/hal_st21nfc.cc
+++ b/1.2/hal_st21nfc.cc
@@ -49,7 +49,7 @@
nfc_stack_callback_t* p_cback_unwrap;
} st21nfc_dev_t;
-const char* halVersion = "ST21NFC HAL1.2 Version 3.2.52";
+const char* halVersion = "ST21NFC HAL1.2 Version 3.2.53";
uint8_t cmd_set_nfc_mode_enable[] = {0x2f, 0x02, 0x02, 0x02, 0x01};
uint8_t hal_is_closed = 1;
@@ -377,6 +377,8 @@
hal_dta_state = 0;
+ deInitializeHalLog();
+
if (async_callback_thread_end() != 0) {
STLOG_HAL_E("HAL st21nfc: %s async_callback_thread_end failed", __func__);
return -1; // We are doomed, stop it here, NOW !
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..74373ca
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,31 @@
+//
+// Copyright (C) 2021 The Android Open Source Project
+//
+// 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.
+
+package {
+ default_applicable_licenses: ["hardware_st_nfc_license"],
+}
+
+// Added automatically by a large-scale-change
+// http://go/android-license-faq
+license {
+ name: "hardware_st_nfc_license",
+ visibility: [":__subpackages__"],
+ license_kinds: [
+ "SPDX-license-identifier-Apache-2.0",
+ ],
+ license_text: [
+ "LICENSE",
+ ],
+}
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..d97975c
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,3 @@
+third_party {
+ license_type: NOTICE
+}
diff --git a/st21nfc/Android.bp b/st21nfc/Android.bp
index 3ff2260..6358c4a 100644
--- a/st21nfc/Android.bp
+++ b/st21nfc/Android.bp
@@ -12,6 +12,14 @@
// 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.
+package {
+ // http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // the below license kinds from "hardware_st_nfc_license":
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["hardware_st_nfc_license"],
+}
+
cc_library_shared {
name: "nfc_nci.st21nfc.default",
defaults: ["hidl_defaults"],
diff --git a/st21nfc/adaptation/android_logmsg.cpp b/st21nfc/adaptation/android_logmsg.cpp
index f377d00..341309a 100644
--- a/st21nfc/adaptation/android_logmsg.cpp
+++ b/st21nfc/adaptation/android_logmsg.cpp
@@ -17,10 +17,13 @@
*
******************************************************************************/
#include "android_logmsg.h"
+#include <pthread.h>
#include <stdio.h>
void DispHal(const char* title, const void* data, size_t length);
unsigned char hal_trace_level = STNFC_TRACE_LEVEL_DEBUG;
+uint16_t hal_log_cnt = 0;
+pthread_mutex_t halLogMutex;
/*******************************************************************************
**
@@ -43,12 +46,22 @@
*******************************************************************************/
unsigned char InitializeSTLogLevel() {
unsigned long num = 0;
+ int ret;
num = 1;
if (GetNumValue(NAME_STNFC_HAL_LOGLEVEL, &num, sizeof(num)))
hal_trace_level = (unsigned char)num;
- STLOG_HAL_D("%s: level=%u", __func__, hal_trace_level);
+ STLOG_HAL_D("%s: HAL log level=%u, hal_log_cnt (before reset): #%04X",
+ __func__, hal_trace_level, hal_log_cnt);
+
+ hal_log_cnt = 0x00;
+
+ ret = pthread_mutex_init(&halLogMutex, NULL);
+ if (ret != 0) {
+ STLOG_HAL_E("HAL: %s pthread_mutex_init failed", __func__);
+ }
+
return hal_trace_level;
}
@@ -58,6 +71,16 @@
size_t i, k;
bool first_line = true;
bool privacy = false;
+ uint16_t frame_nb;
+
+ pthread_mutex_lock(&halLogMutex);
+ frame_nb = hal_log_cnt;
+
+ if (hal_log_cnt == 0xFFFF) {
+ hal_log_cnt = 0;
+ } else {
+ hal_log_cnt++;
+ }
if (hal_trace_level & STNFC_TRACE_FLAG_PRIVACY) {
if ((length > 3) &&
@@ -75,6 +98,7 @@
line[0] = 0;
if (length == 0) {
STLOG_HAL_D("%s", title);
+ pthread_mutex_unlock(&halLogMutex);
return;
}
for (i = 0, k = 0; i < (privacy ? 3 : length); i++, k++) {
@@ -83,14 +107,21 @@
if (first_line == true) {
first_line = false;
if (title[0] == 'R') {
- STLOG_HAL_D("Rx %s\n", line);
+ STLOG_HAL_D("(#0%04X) Rx %s\n", frame_nb, line);
} else if (title[0] == 'T') {
- STLOG_HAL_D("Tx %s\n", line);
+ STLOG_HAL_D("(#0%04X) Tx %s\n", frame_nb, line);
} else {
STLOG_HAL_D("%s\n", line);
}
+ pthread_mutex_unlock(&halLogMutex);
} else {
- STLOG_HAL_D("%s\n", line);
+ if (title[0] == 'R') {
+ STLOG_HAL_D("(#0%04X) rx %s\n", frame_nb, line);
+ } else if (title[0] == 'T') {
+ STLOG_HAL_D("(#0%04X) tx %s\n", frame_nb, line);
+ } else {
+ STLOG_HAL_D("%s\n", line);
+ }
}
line[k] = 0;
}
@@ -103,13 +134,22 @@
if (first_line == true) {
if (title[0] == 'R') {
- STLOG_HAL_D("Rx %s\n", line);
+ STLOG_HAL_D("(#0%04X) Rx %s\n", frame_nb, line);
} else if (title[0] == 'T') {
- STLOG_HAL_D("Tx %s\n", line);
+ STLOG_HAL_D("(#0%04X) Tx %s\n", frame_nb, line);
} else {
STLOG_HAL_D("%s\n", line);
}
+ pthread_mutex_unlock(&halLogMutex);
} else {
- STLOG_HAL_D("%s\n", line);
+ if (title[0] == 'R') {
+ STLOG_HAL_D("(#0%04X) rx %s\n", frame_nb, line);
+ } else if (title[0] == 'T') {
+ STLOG_HAL_D("(#0%04X) tx %s\n", frame_nb, line);
+ } else {
+ STLOG_HAL_D("%s\n", line);
+ }
}
}
+
+void deInitializeHalLog() { pthread_mutex_destroy(&halLogMutex); }
diff --git a/st21nfc/adaptation/i2clayer.cc b/st21nfc/adaptation/i2clayer.cc
index 049ef08..c7b1300 100644
--- a/st21nfc/adaptation/i2clayer.cc
+++ b/st21nfc/adaptation/i2clayer.cc
@@ -34,6 +34,7 @@
#include "android_logmsg.h"
#include "halcore.h"
#include "halcore_private.h"
+#include "hal_config.h"
#define ST21NFC_MAGIC 0xEA
@@ -43,16 +44,22 @@
#define ST21NFC_SET_POLARITY_FALLING _IOR(ST21NFC_MAGIC, 0x04, unsigned int)
#define ST21NFC_SET_POLARITY_HIGH _IOR(ST21NFC_MAGIC, 0x05, unsigned int)
#define ST21NFC_SET_POLARITY_LOW _IOR(ST21NFC_MAGIC, 0x06, unsigned int)
+#define ST21NFC_CLK_ENABLE _IOR(ST21NFC_MAGIC, 0x11, unsigned int)
+#define ST21NFC_CLK_DISABLE _IOR(ST21NFC_MAGIC, 0x12, unsigned int)
+#define ST21NFC_CLK_STATE _IOR(ST21NFC_MAGIC, 0x13, unsigned int)
#define LINUX_DBGBUFFER_SIZE 300
static int fidI2c = 0;
static int cmdPipe[2] = {0, 0};
+static int notifyResetRequest = 0;
-static struct pollfd event_table[2];
+static struct pollfd event_table[3];
static pthread_t threadHandle = (pthread_t)NULL;
pthread_mutex_t i2ctransport_mtx = PTHREAD_MUTEX_INITIALIZER;
+unsigned long hal_ctrl_clk = 0;
+
/**************************************************************************************************
*
* Private API Declaration
@@ -81,6 +88,8 @@
HALHANDLE hHAL = (HALHANDLE)arg;
STLOG_HAL_D("echo thread started...\n");
bool readOk = false;
+ int eventNum = (notifyResetRequest < 0) ? 2 : 3;
+ bool reseting = false;
do {
event_table[0].fd = fidI2c;
@@ -91,9 +100,13 @@
event_table[1].events = POLLIN;
event_table[1].revents = 0;
+ event_table[2].fd = notifyResetRequest;
+ event_table[2].events = POLLPRI;
+ event_table[2].revents = 0;
+
STLOG_HAL_V("echo thread go to sleep...\n");
- int poll_status = poll(event_table, 2, -1);
+ int poll_status = poll(event_table, eventNum, -1);
if (-1 == poll_status) {
STLOG_HAL_E("error in poll call\n");
@@ -199,11 +212,28 @@
}
}
+ if (event_table[2].revents & POLLPRI && eventNum > 2) {
+ STLOG_HAL_W("thread received reset request command.. \n");
+ char reset[10];
+ int byte;
+ reset[9] = '\0';
+ lseek(notifyResetRequest, 0, SEEK_SET);
+ byte = read(notifyResetRequest, &reset, sizeof(reset));
+ if (byte < 10) {
+ reset[byte] = '\0';
+ }
+ if (byte > 0 && reset[0] =='1' && reseting == false) {
+ STLOG_HAL_E("trigger NFCC reset.. \n");
+ reseting = true;
+ i2cResetPulse(fidI2c);
+ }
+ }
} while (!closeThread);
close(fidI2c);
close(cmdPipe[0]);
close(cmdPipe[1]);
+ close(notifyResetRequest);
HalDestroy(hHAL);
STLOG_HAL_D("thread exit\n");
@@ -229,15 +259,43 @@
*/
bool I2cOpenLayer(void* dev, HAL_CALLBACK callb, HALHANDLE* pHandle) {
uint32_t NoDbgFlag = HAL_FLAG_DEBUG;
+ char nfc_dev_node[64];
+ char nfc_reset_req_node[128];
+
+ /*Read device node path*/
+ if (!GetStrValue(NAME_ST_NFC_DEV_NODE, (char *)nfc_dev_node,
+ sizeof(nfc_dev_node))) {
+ STLOG_HAL_D("Open /dev/st21nfc\n");
+ strcpy(nfc_dev_node, "/dev/st21nfc");
+ }
+ /*Read nfcc reset request sysfs*/
+ if (GetStrValue(NAME_ST_NFC_RESET_REQ_SYSFS, (char *)nfc_reset_req_node,
+ sizeof(nfc_reset_req_node))) {
+ STLOG_HAL_D("Open %s\n", nfc_reset_req_node);
+ notifyResetRequest = open(nfc_reset_req_node, O_RDONLY);
+ if (notifyResetRequest < 0) {
+ STLOG_HAL_E("unable to open %s (%s) \n", nfc_reset_req_node, strerror(errno));
+ }
+ }
(void)pthread_mutex_lock(&i2ctransport_mtx);
- fidI2c = open("/dev/st21nfc", O_RDWR);
+
+ fidI2c = open(nfc_dev_node, O_RDWR);
if (fidI2c < 0) {
- STLOG_HAL_W("unable to open /dev/st21nfc (%s) \n", strerror(errno));
+ STLOG_HAL_W("unable to open %s (%s) \n", nfc_dev_node, strerror(errno));
(void)pthread_mutex_unlock(&i2ctransport_mtx);
return false;
}
+ GetNumValue(NAME_STNFC_CONTROL_CLK, &hal_ctrl_clk, sizeof(hal_ctrl_clk));
+
+ if (hal_ctrl_clk) {
+ if (ioctl(fidI2c, ST21NFC_CLK_DISABLE, NULL) < 0) {
+ char msg[LINUX_DBGBUFFER_SIZE];
+ strerror_r(errno, msg, LINUX_DBGBUFFER_SIZE);
+ STLOG_HAL_E("ST21NFC_CLK_DISABLE failed errno %d(%s)", errno, msg);
+ }
+ }
i2cSetPolarity(fidI2c, false, false);
i2cResetPulse(fidI2c);
@@ -360,13 +418,51 @@
int retries = 0;
int result = 0;
int halfsecs = 0;
+ int clk_state = -1;
+ char msg[LINUX_DBGBUFFER_SIZE];
+
+ if (hal_ctrl_clk && length >= 4 && pvBuffer[0] == 0x20 &&
+ pvBuffer[1] == 0x09) {
+ if (0 > (clk_state = ioctl(fid, ST21NFC_CLK_STATE, NULL))) {
+ strerror_r(errno, msg, LINUX_DBGBUFFER_SIZE);
+ STLOG_HAL_E("ST21NFC_CLK_STATE failed errno %d(%s)", errno, msg);
+ clk_state = -1;
+ }
+ STLOG_HAL_D("ST21NFC_CLK_STATE = %d", clk_state);
+ if (clk_state == 1 && (pvBuffer[3] == 0x01 || pvBuffer[3] == 0x03)) {
+ // screen off cases
+ if (ioctl(fid, ST21NFC_CLK_DISABLE, NULL) < 0) {
+ strerror_r(errno, msg, LINUX_DBGBUFFER_SIZE);
+ STLOG_HAL_E("ST21NFC_CLK_DISABLE failed errno %d(%s)", errno, msg);
+ } else if (0 > (clk_state = ioctl(fid, ST21NFC_CLK_STATE, NULL))) {
+ strerror_r(errno, msg, LINUX_DBGBUFFER_SIZE);
+ STLOG_HAL_E("ST21NFC_CLK_STATE failed errno %d(%s)", errno, msg);
+ clk_state = -1;
+ }
+ if (clk_state != 0) {
+ STLOG_HAL_E("CLK_DISABLE STATE ERROR clk_state = %d", clk_state);
+ }
+ } else if (clk_state == 0 && (pvBuffer[3] == 0x02 || pvBuffer[3] == 0x00)) {
+ // screen on cases
+ if (ioctl(fid, ST21NFC_CLK_ENABLE, NULL) < 0) {
+ strerror_r(errno, msg, LINUX_DBGBUFFER_SIZE);
+ STLOG_HAL_E("ST21NFC_CLK_ENABLE failed errno %d(%s)", errno, msg);
+ } else if (0 > (clk_state = ioctl(fid, ST21NFC_CLK_STATE, NULL))) {
+ strerror_r(errno, msg, LINUX_DBGBUFFER_SIZE);
+ STLOG_HAL_E("ST21NFC_CLK_STATE failed errno %d(%s)", errno, msg);
+ clk_state = -1;
+ }
+ if (clk_state != 1) {
+ STLOG_HAL_E("CLK_ENABLE STATE ERROR clk_state = %d", clk_state);
+ }
+ }
+ }
redo:
while (retries < 3) {
result = write(fid, pvBuffer, length);
if (result < 0) {
- char msg[LINUX_DBGBUFFER_SIZE];
strerror_r(errno, msg, LINUX_DBGBUFFER_SIZE);
STLOG_HAL_W("! i2cWrite!!, errno is '%s'", msg);
diff --git a/st21nfc/hal_wrapper.cc b/st21nfc/hal_wrapper.cc
index f687189..d92b477 100644
--- a/st21nfc/hal_wrapper.cc
+++ b/st21nfc/hal_wrapper.cc
@@ -66,6 +66,8 @@
static uint8_t nciPropEnableFwDbgTraces[256];
static uint8_t nciPropGetFwDbgTracesConfig[] = {0x2F, 0x02, 0x05, 0x03,
0x00, 0x14, 0x01, 0x00};
+static bool isDebuggable;
+
bool mReadFwConfigDone = false;
bool mHciCreditLent = false;
@@ -117,6 +119,7 @@
return -1; // We are doomed, stop it here, NOW !
}
+ isDebuggable = property_get_int32("ro.debuggable", 0);
mHalHandle = *pHandle;
return 1;
@@ -314,6 +317,11 @@
else if ((p_data[0] == 0x60) && (p_data[1] == 0x00)) {
// Stop timer
HalSendDownstreamStopTimer(mHalHandle);
+ if (forceRecover == true) {
+ forceRecover = false;
+ mHalWrapperDataCallback(data_len, p_data);
+ break;
+ }
// Send CORE_INIT_CMD
STLOG_HAL_V("%s - Sending CORE_INIT_CMD", __func__);
@@ -370,9 +378,12 @@
// NFC_STATUS_OK
if (p_data[3] == 0x00) {
bool confNeeded = false;
+ bool firmware_debug_enabled =
+ property_get_int32("persist.vendor.nfc.firmware_debug_enabled", 0);
// Check if FW DBG shall be set
if (GetNumValue(NAME_STNFC_FW_DEBUG_ENABLED, &num, sizeof(num))) {
+ if (firmware_debug_enabled && isDebuggable) num = 1;
// 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__);
@@ -472,9 +483,6 @@
}
}
mHalWrapperDataCallback(data_len, p_data);
- } else if (forceRecover == true) {
- forceRecover = false;
- mHalWrapperDataCallback(data_len, p_data);
} else {
STLOG_HAL_V("%s - Core reset notification - Nfc mode ", __func__);
}
@@ -512,9 +520,8 @@
}
}
-static void halWrapperCallback(uint8_t event, uint8_t event_status) {
+static void halWrapperCallback(uint8_t event, __attribute__((unused))uint8_t event_status) {
uint8_t coreInitCmd[] = {0x20, 0x01, 0x02, 0x00, 0x00};
- uint8_t propNfcModeSetCmdOn[] = {0x2f, 0x02, 0x02, 0x02, 0x01};
switch (mHalWrapperState) {
case HAL_WRAPPER_STATE_CLOSING:
@@ -574,10 +581,10 @@
HalSendDownstreamStopTimer(mHalHandle);
mTimerStarted = false;
forceRecover = true;
- if (!HalSendDownstream(mHalHandle, propNfcModeSetCmdOn,
- sizeof(propNfcModeSetCmdOn))) {
- STLOG_HAL_E("NFC-NCI HAL: %s SendDownstream failed", __func__);
- }
+ resetHandlerState();
+ I2cResetPulse();
+ mHalWrapperState = HAL_WRAPPER_STATE_OPEN;
+
}
return;
}
diff --git a/st21nfc/include/android_logmsg.h b/st21nfc/include/android_logmsg.h
index 1392d4c..e6fbbc5 100644
--- a/st21nfc/include/android_logmsg.h
+++ b/st21nfc/include/android_logmsg.h
@@ -49,6 +49,7 @@
#define NAME_STNFC_FW_BIN_NAME "STNFC_FW_BIN_NAME"
#define NAME_STNFC_FW_DEBUG_ENABLED "STNFC_FW_DEBUG_ENABLED"
#define NAME_CORE_CONF_PROP "CORE_CONF_PROP"
+#define NAME_STNFC_CONTROL_CLK "STNFC_CONTROL_CLK"
/* #######################
* Set the logging level
@@ -104,6 +105,8 @@
void DispHal(const char* title, const void* data, size_t length);
+void deInitializeHalLog();
+
#ifdef __cplusplus
};
#endif
diff --git a/st21nfc/include/hal_config.h b/st21nfc/include/hal_config.h
index 8bc2932..ad99983 100644
--- a/st21nfc/include/hal_config.h
+++ b/st21nfc/include/hal_config.h
@@ -42,5 +42,7 @@
#define NAME_DEFAULT_ISODEP_ROUTE "DEFAULT_ISODEP_ROUTE"
#define NAME_STNFC_USB_CHARGING_MODE "STNFC_USB_CHARGING_MODE"
#define NAME_CORE_CONF_PROP "CORE_CONF_PROP"
+#define NAME_ST_NFC_DEV_NODE "ST_NFC_DEV_NODE"
+#define NAME_ST_NFC_RESET_REQ_SYSFS "ST_NFC_RESET_REQ_SYSFS"
#endif