Handling ULPDET API with Proprietary NCI command & Response am: 4014036227
Original change: https://android-review.googlesource.com/c/platform/hardware/nxp/nfc/+/2817056
Change-Id: If5af2a16340bc074bcab03d74971ac61b981b6c5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/snxxx/halimpl/hal/phNxpNciHal.cc b/snxxx/halimpl/hal/phNxpNciHal.cc
index c4eb0cf..bb8bb8f 100644
--- a/snxxx/halimpl/hal/phNxpNciHal.cc
+++ b/snxxx/halimpl/hal/phNxpNciHal.cc
@@ -1079,8 +1079,11 @@
*
******************************************************************************/
int phNxpNciHal_write(uint16_t data_len, const uint8_t* p_data) {
- if (bDisableLegacyMfcExtns && bEnableMfcExtns && p_data[0] == 0x00) {
+ if (bDisableLegacyMfcExtns && bEnableMfcExtns &&
+ p_data[NCI_GID_INDEX] == 0x00) {
return NxpMfcReaderInstance.Write(data_len, p_data);
+ } else if (phNxpNciHal_isVendorSpecificCommand(data_len, p_data)) {
+ return phNxpNciHal_handleVendorSpecificCommand(data_len, p_data);
}
return phNxpNciHal_write_internal(data_len, p_data);
}
diff --git a/snxxx/halimpl/hal/phNxpNciHal_ULPDet.cc b/snxxx/halimpl/hal/phNxpNciHal_ULPDet.cc
index 2f8e137..7225a34 100644
--- a/snxxx/halimpl/hal/phNxpNciHal_ULPDet.cc
+++ b/snxxx/halimpl/hal/phNxpNciHal_ULPDet.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 NXP
+ * Copyright 2022-2023 NXP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
#include "phNfcCommon.h"
#include "phNxpNciHal_IoctlOperations.h"
#include "phNxpNciHal_PowerTrackerIface.h"
+#include "phNxpNciHal_extOperations.h"
extern phNxpNciHal_Control_t nxpncihal_ctrl;
extern NFCSTATUS phNxpNciHal_ext_send_sram_config_to_flash();
@@ -153,3 +154,26 @@
return status;
}
+
+/*******************************************************************************
+**
+** Function phNxpNciHal_handleULPDetCommand()
+**
+** Description This handles the ULPDET command and sets the ULPDET flag
+**
+** Returns It returns number of bytes received.
+*******************************************************************************/
+int phNxpNciHal_handleULPDetCommand(uint16_t data_len, const uint8_t* p_data) {
+ if (data_len <= 4) {
+ return 0;
+ }
+ uint8_t status = NCI_RSP_FAIL;
+ if (phNxpNciHal_isULPDetSupported()) {
+ phNxpNciHal_setULPDetFlag(p_data[NCI_MSG_INDEX_FEATURE_VALUE]);
+ status = NCI_RSP_OK;
+ }
+
+ phNxpNciHal_vendorSpecificCallback(p_data[NCI_OID_INDEX], status);
+
+ return p_data[NCI_MSG_LEN_INDEX];
+}
diff --git a/snxxx/halimpl/hal/phNxpNciHal_ULPDet.h b/snxxx/halimpl/hal/phNxpNciHal_ULPDet.h
index eb1e862..d96876a 100644
--- a/snxxx/halimpl/hal/phNxpNciHal_ULPDet.h
+++ b/snxxx/halimpl/hal/phNxpNciHal_ULPDet.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 NXP
+ * Copyright 2022-2023 NXP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,4 +61,14 @@
**
** Returns NFCSTATUS_FAILED or NFCSTATUS_SUCCESS
*******************************************************************************/
-NFCSTATUS phNxpNciHal_propConfULPDetMode(bool bEnable);
\ No newline at end of file
+NFCSTATUS phNxpNciHal_propConfULPDetMode(bool bEnable);
+
+/*******************************************************************************
+**
+** Function phNxpNciHal_handleULPDetCommand()
+**
+** Description This handles the ULPDET command and sets the ULPDET flag
+**
+** Returns It returns number of bytes received.
+*******************************************************************************/
+int phNxpNciHal_handleULPDetCommand(uint16_t data_len, const uint8_t* p_data);
diff --git a/snxxx/halimpl/hal/phNxpNciHal_ext.h b/snxxx/halimpl/hal/phNxpNciHal_ext.h
index dcf6d45..5f4129f 100644
--- a/snxxx/halimpl/hal/phNxpNciHal_ext.h
+++ b/snxxx/halimpl/hal/phNxpNciHal_ext.h
@@ -30,6 +30,33 @@
#define NXP_NFC_PARAM_ID_SWP2 0xD4
#define NXP_NFC_PARAM_ID_SWPUICC3 0xDC
+/* NCI GID index*/
+#define NCI_GID_INDEX 0
+/* NCI OID index*/
+#define NCI_OID_INDEX 1
+/* NCI message length index*/
+#define NCI_MSG_LEN_INDEX 2
+/* NCI message index for feature*/
+#define NCI_MSG_INDEX_FOR_FEATURE 3
+/* NCI message index feature value*/
+#define NCI_MSG_INDEX_FEATURE_VALUE 4
+#define NCI_GID_PROP 0x0F
+
+/* Android Power Saving Opcode */
+#define NCI_MSG_PROP_ANDROID_OID 0x0C
+
+/* Android Parameters */
+#define NCI_ANDROID_POWER_SAVING 0x01
+
+/* Android Power Saving Params */
+#define NCI_ANDROID_POWER_SAVING_PARAM_SIZE 2
+#define NCI_ANDROID_POWER_SAVING_PARAM_DISABLE 0
+#define NCI_ANDROID_POWER_SAVING_PARAM_ENABLE 1
+
+#define NCI_RSP_SIZE 1
+#define NCI_RSP_OK 0
+#define NCI_RSP_FAIL 1
+
void printNfcMwVersion();
void phNxpNciHal_ext_init(void);
NFCSTATUS phNxpNciHal_process_ext_rsp(uint8_t* p_ntf, uint16_t* p_len);
diff --git a/snxxx/halimpl/hal/phNxpNciHal_extOperations.cc b/snxxx/halimpl/hal/phNxpNciHal_extOperations.cc
index 0abc410..00cc48f 100755
--- a/snxxx/halimpl/hal/phNxpNciHal_extOperations.cc
+++ b/snxxx/halimpl/hal/phNxpNciHal_extOperations.cc
@@ -21,6 +21,7 @@
#include "phNfcCommon.h"
#include "phNxpNciHal_IoctlOperations.h"
+#include "phNxpNciHal_ULPDet.h"
#define NCI_HEADER_SIZE 3
#define NCI_SE_CMD_LEN 4
@@ -29,6 +30,7 @@
static vector<uint8_t> uicc2HciParams(0);
static vector<uint8_t> uiccHciCeParams(0);
extern phNxpNciHal_Control_t nxpncihal_ctrl;
+extern phTmlNfc_Context_t* gpphTmlNfc_Context;
extern NFCSTATUS phNxpNciHal_ext_send_sram_config_to_flash();
/*******************************************************************************
@@ -653,3 +655,62 @@
gpios_data.platform_gpios_status.fw_dwl);
}
}
+
+/*******************************************************************************
+**
+** Function phNxpNciHal_isVendorSpecificCommand()
+**
+** Description this function checks vendor specific command or not
+**
+** Returns true if the command is vendor specific otherwise false
+*******************************************************************************/
+bool phNxpNciHal_isVendorSpecificCommand(uint16_t data_len,
+ const uint8_t* p_data) {
+ if (data_len > 3 && p_data[NCI_GID_INDEX] == (NCI_MT_CMD | NCI_GID_PROP) &&
+ p_data[NCI_OID_INDEX] == NCI_MSG_PROP_ANDROID_OID) {
+ return true;
+ }
+ return false;
+}
+
+/*******************************************************************************
+**
+** Function phNxpNciHal_handleVendorSpecificCommand()
+**
+** Description This handles the vendor specific command
+**
+** Returns It returns number of bytes received.
+*******************************************************************************/
+int phNxpNciHal_handleVendorSpecificCommand(uint16_t data_len,
+ const uint8_t* p_data) {
+ if (data_len > 4 &&
+ p_data[NCI_MSG_INDEX_FOR_FEATURE] == NCI_ANDROID_POWER_SAVING) {
+ return phNxpNciHal_handleULPDetCommand(data_len, p_data);
+ }
+
+ return 0;
+}
+
+/*******************************************************************************
+**
+** Function phNxpNciHal_vendorSpecificCallback()
+**
+** Params oid, status
+**
+** Description This function sends response to Vendor Specific commands
+**
+*******************************************************************************/
+void phNxpNciHal_vendorSpecificCallback(int oid, int status) {
+ static phLibNfc_Message_t msg;
+ nxpncihal_ctrl.p_rsp_data[0] = (uint8_t)(NCI_GID_PROP | NCI_MT_RSP);
+ nxpncihal_ctrl.p_rsp_data[1] = oid;
+ nxpncihal_ctrl.p_rsp_data[2] = NCI_RSP_SIZE;
+ nxpncihal_ctrl.p_rsp_data[3] = status;
+ nxpncihal_ctrl.rsp_len = 4;
+
+ msg.eMsgType = NCI_HAL_RX_MSG;
+ msg.pMsgData = NULL;
+ msg.Size = 0;
+ phTmlNfc_DeferredCall(gpphTmlNfc_Context->dwCallbackThreadId,
+ (phLibNfc_Message_t*)&msg);
+}
diff --git a/snxxx/halimpl/hal/phNxpNciHal_extOperations.h b/snxxx/halimpl/hal/phNxpNciHal_extOperations.h
index 2db1d4e..e8c89d9 100755
--- a/snxxx/halimpl/hal/phNxpNciHal_extOperations.h
+++ b/snxxx/halimpl/hal/phNxpNciHal_extOperations.h
@@ -193,3 +193,35 @@
**
*******************************************************************************/
void phNxpNciHal_decodeGpioStatus(void);
+
+/*******************************************************************************
+**
+** Function phNxpNciHal_isVendorSpecificCommand()
+**
+** Description this function checks vendor specific command or not
+**
+** Returns true if the command is vendor specific otherwise false
+*******************************************************************************/
+bool phNxpNciHal_isVendorSpecificCommand(uint16_t data_len,
+ const uint8_t* p_data);
+
+/*******************************************************************************
+**
+** Function phNxpNciHal_handleVendorSpecificCommand()
+**
+** Description This handles the vendor specific command
+**
+** Returns It returns number of bytes received.
+*******************************************************************************/
+int phNxpNciHal_handleVendorSpecificCommand(uint16_t data_len,
+ const uint8_t* p_data);
+
+/*******************************************************************************
+**
+** Function phNxpNciHal_vendorSpecificCallback()
+**
+** Params oid, status
+** Description This function sends response to Vendor Specific commands
+**
+*******************************************************************************/
+void phNxpNciHal_vendorSpecificCallback(int oid, int status);