diff options
66 files changed, 11781 insertions, 192 deletions
diff --git a/Android.bp b/Android.bp index 0c7eec3..957b8b3 100755..100644 --- a/Android.bp +++ b/Android.bp @@ -1,7 +1,108 @@ +cc_library_headers { + name: "libese_client_headers", + export_include_dirs: [ + "inc", + "jcos_client/inc", + "ls_client/inc", + ], + vendor_available: true, +} + +cc_library_shared { + + name: "se_nq_extn_client", + defaults: ["hidl_defaults"], + vendor: true, + + srcs: [ + "utils/phNxpConfig.cc", + "utils/sparse_crc32.cc", + "src/eSEClientIntf.cc", + "src/phNxpLog.cc" + ], + + local_include_dirs: [ + "inc", + "utils", + "jcos_client/inc", + "ls_client/inc", + ], + shared_libs: [ + "libbase", + "libcutils", + "libdl", + "libhidlbase", + "liblog", + "libutils", + "libchrome", + "libdl", + "libhidlbase", + ], +} + cc_library_shared { - name: "nfc_nci_nxp", + + name: "jcos_nq_client", defaults: ["hidl_defaults"], - proprietary: true, + vendor: true, + + srcs: [ + "jcos_client/src/JcDnld.cpp", + "jcos_client/src/JcopOsDownload.cpp", + ], + + local_include_dirs: [ + "inc", + "utils", + "jcos_client/inc", + ], + shared_libs: [ + "libbase", + "libcutils", + "libdl", + "libhidlbase", + "liblog", + "libutils", + "libchrome", + "libdl", + "libhidlbase", + ], +} + +cc_library_shared { + + name: "ls_nq_client", + defaults: ["hidl_defaults"], + vendor: true, + + srcs: [ + "ls_client/src/LsClient.cpp", + "ls_client/src/LsLib.cpp", + ], + + local_include_dirs: [ + "inc", + "utils", + "ls_client/inc", + ], + shared_libs: [ + "libbase", + "libcutils", + "libdl", + "libhidlbase", + "liblog", + "libutils", + "libchrome", + "libdl", + "libhidlbase", + "se_nq_extn_client" + ], +} + +cc_library_shared { + name: "nfc_nci.nqx.default.hw", + defaults: ["hidl_defaults"], + vendor: true, srcs: [ "halimpl/common/*.cc", @@ -27,18 +128,14 @@ cc_library_shared { "libhardware", "libhardware_legacy", "libhidlbase", - "liblog", "libutils", "android.hardware.nfc@1.0", "android.hardware.nfc@1.1", "android.hardware.nfc@1.2", + "vendor.nxp.hardware.nfc@1.0", + "vendor.nxp.hardware.nfc@1.1", "android.hardware.secure_element@1.0", - "ese_spi_nxp", - "vendor.nxp.nxpese@1.0", - "vendor.nxp.eventprocessor@1.0", - "vendor.nxp.nxpnfc@2.0", "vendor.nxp.nxpnfclegacy@1.0", - "ese_client", "hal_libnfc" ], local_include_dirs: [ @@ -49,12 +146,7 @@ cc_library_shared { "halimpl/tml", "halimpl/src/include", "halimpl/configs", - ], - include_dirs: [ - "hardware/nxp/nfc/extns/impl/", - "hardware/nxp/nfc/extns/impl/nxpnfc/2.0", - "hardware/nxp/secure_element_extns/inc", - "hardware/nxp/secure_element/libese-spi/src/include", + "jcos_client/inc", ], export_include_dirs: [ "extns/impl", @@ -80,49 +172,3 @@ cc_library_shared { "-DNXP_HW_SELF_TEST" ], } - -cc_binary { - name: "android.hardware.nfc@1.2-service", - defaults: ["hidl_defaults"], - proprietary: true, - init_rc: ["1.2/android.hardware.nfc@1.2-service.rc"], - relative_install_path: "hw", - srcs: [ - "1.2/NxpNfcService.cpp", - "1.2/Nfc.cpp", - "extns/impl/nxpnfc/2.0/NxpNfc.cpp", - "extns/impl/nxpnfclegacy/1.0/NxpNfcLegacy.cpp" - ], - - shared_libs: [ - "nfc_nci_nxp", - "libbase", - "libcutils", - "libhardware", - "liblog", - "libutils", - "android.hardware.nfc@1.0", - "android.hardware.nfc@1.1", - "android.hardware.nfc@1.2", - "ese_spi_nxp", - "libhidlbase", - "vendor.nxp.nxpnfc@2.0", - "vendor.nxp.nxpese@1.0", - "vendor.nxp.nxpnfclegacy@1.0", - "android.hardware.secure_element@1.0", - "ese_client", - "hal_libnfc", - ], - local_include_dirs: [ - "halimpl/inc", - "halimpl/hal", - "halimpl/inc", - "halimpl/tml", - "halimpl/utils", - "halimpl/configs", - ], - include_dirs: [ - "hardware/nxp/nfc/extns/impl/nxpnfc/2.0", - "hardware/nxp/nfc/halimpl/src/include", - ], -} diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/MODULE_LICENSE_APACHE2 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. @@ -1,9 +1,32 @@ -# nfcandroid_nfc_hidlimpl +# nfcandroid_nxp_ese_clients + +This Repo contains any additional information/files required to support the release #### Git Repository | DESCRIPTION | CHECKOUT COMMAND | | :-------------: |:-------------:| +| nfcandroid_nxp_ese_clients | git clone https://github.com/NXPNFCProject/nfcandroid_nxp_ese_clients.git | + +####Supported Versions on "master" Branch + +| Android Version | NXP Release | NXP Tag | +| :-------------: |:-------------:| :-----:| +| android-p-preview 2 | 9.00.08 (SN100x) | NFC_NCIHALx_AR2000.09.00.08_OpnSrc | +| android-p-preview 2 | 9.00.0A (SN100x) | NFC_NCIHALx_AR2000.09.00.0A_OpnSrc | +| android-p-preview 2 | 9.00.0C (SN100x) | NFC_NCIHALx_AR2000.09.00.0C_OpnSrc | +| android-p-preview 2 | 9.00.0D (SN100x) | NFC_NCIHALx_AR2000.09.00.0D_OpnSrc | +| android-p-preview 2 | 9.00.0F (SN100x) | NFC_NCIHALx_AR2000.09.00.0F_OpnSrc | +| android-p-preview 2 | 9.00.11 (SN100x) | NFC_NCIHALx_AR2000.09.00.11_OpnSrc | +| android-p-preview 2 | 9.00.13 (SN100x) | NFC_NCIHALx_AR2000.09.00.13_OpnSrc | +| android-p-preview 2 | 9.00.15 (SN100x) | NFC_NCIHALx_AR2000.09.00.15_OpnSrc | + +# nfcandroid_nfc_hidlimpl + +####Git Repository + +| DESCRIPTION | CHECKOUT COMMAND | +| :-------------: |:-------------:| | nfcandroid_nfc_hidlimpl | git clone https://github.com/NXPNFCProject/nfcandroid_nfc_hidlimpl.git | #### Supported Version on "br_android_ncihalx_row_q" branch diff --git a/README.md~ b/README.md~ new file mode 100644 index 0000000..ffa039d --- /dev/null +++ b/README.md~ @@ -0,0 +1,29 @@ +#NFC_NCIHAL_libnfc-nci + +####Git Repository + +| DESCRIPTION | CHECKOUT COMMAND | +|:-------------:|:-------------:| +| NFC_NCIHAL_libnfc-nci | git clone https://github.com/NXPNFCProject/NFC_NCIHAL_libnfc-nci.git | + +####Supported Versions on "master" Branch + +| Android Version | NXP Release | NXP Tag | +| :-------------: |:-------------:| :-----:| +| android-5.0.0_r1/android5.1.0_r1 | 3.5.0_L (PN547C2/PN548C2) | NFC_NCIHALx_AR0F.3.5.0_L_OpnSrc | + +####Supported Versions on "br_android_ncihalx_m" Branch + +| Android Version | NXP Release | NXP Tag | +| :-------------: |:-------------:| :-----:| +| android-6.0.0_r1 | 4.2.0_M (PN547C2/PN548C2) | NFC_NCIHALx_AR0F.4.2.0_M_OpnSrc | +| android-6.0.0_r1 | 4.3.0_M (PN547C2/PN548C2) | NFC_NCIHALx_AR0F.4.3.0_M_OpnSrc | +| android-6.0.1_r17 | 4.5.0_M (PN551/PN548C2) | NFC_NCIHALx_AR3C.4.5.0_M_OpnSrc | +| android-6.0.1_r17 | 4.7.0_M (PN553) | NFC_NCIHALx_ARC0.4.7.0_M_OpnSrc | + +####Supported Versions on "br_android_ncihalx_n" Branch + +| Android Version | NXP Release | NXP Tag | +| :-------------: |:-------------:| :-----:| +| android-7.0.0_r1 | 7.0.3_N (PN548C2/PN551) | NFC_NCIHALx_AR3C.7.0.3_N_OpnSrc | +| android-7.0.0_r4 | 7.0.4_N (PN553) | NFC_NCIHALx_AR3C.7.0.4_N_OpnSrc | diff --git a/extns/impl/nxpnfc/2.0/Nxp_Features.h b/extns/impl/nxpnfc/2.0/Nxp_Features.h index c1ca798..8a276d9 100755..100644 --- a/extns/impl/nxpnfc/2.0/Nxp_Features.h +++ b/extns/impl/nxpnfc/2.0/Nxp_Features.h @@ -24,15 +24,7 @@ #define STRMAX_1 40 #define STRMAX_2 100 - -#ifndef FW_DLL_ROOT_DIR -#ifdef __LP64__ -#define FW_DLL_ROOT_DIR "/system/vendor/lib64/" -#else #define FW_DLL_ROOT_DIR "/system/vendor/lib/" -#endif -#endif - #define FW_DLL_EXTENSION ".so" #define FW_MOBILE_MAJOR_NUMBER_PN553 0x01 diff --git a/extns/intf/nxpnfc/Android.bp b/extns/intf/nxpnfc/Android.bp deleted file mode 100755 index 97eb19e..0000000 --- a/extns/intf/nxpnfc/Android.bp +++ /dev/null @@ -1,4 +0,0 @@ -hidl_package_root {
- name: "vendor.nxp.nxpnfc",
- path: "hardware/nxp/nfc/extns/intf/nxpnfc",
-}
diff --git a/halimpl/common/phNfcCommon.h b/halimpl/common/phNfcCommon.h index 37a9414..37a9414 100755..100644 --- a/halimpl/common/phNfcCommon.h +++ b/halimpl/common/phNfcCommon.h diff --git a/halimpl/common/phNfcTypes.h b/halimpl/common/phNfcTypes.h index ada0a9d..ada0a9d 100755..100644 --- a/halimpl/common/phNfcTypes.h +++ b/halimpl/common/phNfcTypes.h diff --git a/halimpl/configs/NxpNfcCapability.cpp b/halimpl/configs/NxpNfcCapability.cpp index 3069a16..3069a16 100755..100644 --- a/halimpl/configs/NxpNfcCapability.cpp +++ b/halimpl/configs/NxpNfcCapability.cpp diff --git a/halimpl/configs/NxpNfcCapability.h b/halimpl/configs/NxpNfcCapability.h index b5fb982..b5fb982 100755..100644 --- a/halimpl/configs/NxpNfcCapability.h +++ b/halimpl/configs/NxpNfcCapability.h diff --git a/halimpl/dnld/phDnldNfc.cc b/halimpl/dnld/phDnldNfc.cc index 5ee9036..f6576ab 100755..100644 --- a/halimpl/dnld/phDnldNfc.cc +++ b/halimpl/dnld/phDnldNfc.cc @@ -744,8 +744,8 @@ NFCSTATUS phDnldNfc_InitImgInfo(void) { /*Read Firmware file name from config file*/ if (GetNxpStrValue(NAME_NXP_FW_NAME, (char*)fwFileName, sizeof(fwFileName)) == true) { - strncpy(fwpathName, FW_DLL_ROOT_DIR, strlen(FW_DLL_ROOT_DIR) + 1); - strncat(fwpathName, fwFileName, strlen(fwFileName)); + strlcpy(fwpathName, FW_DLL_ROOT_DIR, sizeof(fwpathName)); + strlcat(fwpathName, fwFileName, sizeof(fwpathName)); pathName = fwpathName; } @@ -962,15 +962,15 @@ NFCSTATUS phDnldNfc_LoadFW(const char* pathName, uint8_t** pImgInfo, void* pImageInfoLen = NULL; if (pathName == NULL) { if(nfcFL.chipType == pn548C2) { - pathName = "/system/vendor/lib/libpn548ad_fw.so"; + pathName = "/vendor/lib/libpn548ad_fw.so"; } else if(nfcFL.chipType == pn551) { - pathName = "/system/vendor/lib/libpn551_fw.so"; + pathName = "/vendor/lib/libpn551_fw.so"; } else if(nfcFL.chipType == pn553) { - pathName = "/system/vendor/lib/libpn553_fw.so"; + pathName = "/vendor/lib/libpn553_fw.so"; } else if(nfcFL.chipType == pn557) { - pathName = "/system/vendor/lib/libpn557_fw.so"; + pathName = "/vendor/lib/libpn557_fw.so"; } else { - pathName = "/system/vendor/lib/libpn547_fw.so"; + pathName = "/vendor/lib/libpn547_fw.so"; } } @@ -1036,15 +1036,15 @@ NFCSTATUS phDnldNfc_LoadRecoveryFW(const char* pathName, uint8_t** pImgInfo, /* check for path name */ if (pathName == NULL) { if(nfcFL.chipType == pn548C2) { - pathName = "/system/vendor/lib/libpn548ad_fw.so"; + pathName = "/vendor/lib/libpn548ad_fw.so"; } else if(nfcFL.chipType == pn551) { - pathName = "/system/vendor/lib/libpn551_fw.so"; + pathName = "/vendor/lib/libpn551_fw.so"; } else if(nfcFL.chipType == pn553) { - pathName = "/system/vendor/lib/libpn553_fw.so"; + pathName = "/vendor/lib/libpn553_fw.so"; }else if(nfcFL.chipType == pn557) { - pathName = "/system/vendor/lib/libpn557_fw.so"; + pathName = "/vendor/lib/libpn557_fw.so"; } else { - pathName = "/system/vendor/lib/libpn547_fw.so"; + pathName = "/vendor/lib/libpn547_fw.so"; } } /* check if the handle is not NULL then free the library */ diff --git a/halimpl/hal/phNxpNciHal.cc b/halimpl/hal/phNxpNciHal.cc index 5c4a0c9..b7e9be6 100644 --- a/halimpl/hal/phNxpNciHal.cc +++ b/halimpl/hal/phNxpNciHal.cc @@ -31,7 +31,7 @@ #include "phNxpNciHal_nciParser.h" #include <EseAdaptation.h> #include "spi_spm.h" -#include <vendor/nxp/nxpnfc/2.0/types.h> +#include <vendor/nxp/hardware/nfc/2.0/types.h> #include "Nxp_Features.h" #include "NxpNfc.h" @@ -109,12 +109,16 @@ uint32_t gSvddSyncOff_Delay = 10; bool_t force_fw_download_req = false; bool_t gParserCreated = FALSE; bool nfc_debug_enabled = true; +#ifdef ENABLE_ESE_CLIENT ESE_UPDATE_STATE eseUpdateSpi = ESE_UPDATE_COMPLETED; ESE_UPDATE_STATE eseUpdateDwp = ESE_UPDATE_COMPLETED; +#endif nfc_stack_callback_t* p_nfc_stack_cback_backup; /* global variable to get FW version from NCI response*/ uint32_t wFwVerRsp; +#ifdef ENABLE_ESE_CLIENT EseAdaptation *gpEseAdapt = NULL; +#endif /* External global variable to get FW version */ extern uint16_t wFwVer; @@ -804,8 +808,8 @@ int phNxpNciHal_MinInit(nfc_stack_callback_t* p_cback, max_len * sizeof(uint8_t))) { NXPLOG_NCIHAL_E( "Invalid nfc device node name keeping the default device node " - "/dev/pn54x"); - strncpy(nfc_dev_node, "/dev/pn54x", strlen("/dev/pn54x") + 1); + "/dev/nq-nci"); + strlcpy(nfc_dev_node, "/dev/nq-nci", max_len); } tTmlConfig.pDevName = (int8_t*)nfc_dev_node; @@ -941,10 +945,10 @@ int phNxpNciHal_MinOpen() { nxpncihal_ctrl.halStatus = HAL_STATUS_OPEN; nxpncihal_ctrl.is_wait_for_ce_ntf = false; nxpncihal_ctrl.hal_boot_mode = boot_mode; - - gpEseAdapt = &EseAdaptation::GetInstance(); - gpEseAdapt->Initialize(); - +#ifdef ENABLE_ESE_CLIENT + gpEseAdapt = &EseAdaptation::GetInstance(); + gpEseAdapt->Initialize(); +#endif /*nci version NCI_VERSION_UNKNOWN version by default*/ nxpncihal_ctrl.nci_info.nci_version = NCI_VERSION_UNKNOWN; @@ -965,8 +969,8 @@ int phNxpNciHal_MinOpen() { max_len * sizeof(char))) { NXPLOG_NCIHAL_D( "Invalid nfc device node name keeping the default device node " - "/dev/pn54x"); - strncpy(nfc_dev_node, "/dev/pn54x", strlen("/dev/pn54x") + 1); + "/dev/nq-nci"); + strlcpy(nfc_dev_node, "/dev/nq-nci", max_len); } /* Configure hardware link */ @@ -1130,7 +1134,7 @@ int phNxpNciHal_open(nfc_stack_callback_t* p_cback, nfc_stack_data_callback_t* p_data_cback) { AutoThreadMutex a(gsHalOpenCloseLock); NFCSTATUS wConfigStatus = NFCSTATUS_SUCCESS; - +#ifdef ENABLE_ESE_CLIENT if((eseUpdateSpi != ESE_UPDATE_COMPLETED) || (eseUpdateDwp != ESE_UPDATE_COMPLETED)) { ALOGD("%s BLOCK NFC HAL OPEN", __func__); @@ -1141,7 +1145,7 @@ int phNxpNciHal_open(nfc_stack_callback_t* p_cback, } return NFCSTATUS_FAILED; } - +#endif if (nxpncihal_ctrl.hal_boot_mode == NFC_FAST_BOOT_MODE ) { NXPLOG_NCIHAL_E(" HAL NFC fast init mode calling min_open %d", nxpncihal_ctrl.hal_boot_mode); @@ -2114,9 +2118,17 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) { uint8_t swp_info_buff[2]; uint8_t swp_intf_status = 0x00; uint8_t swp1A_intf_status = 0x00; + char nq_chipid[PROPERTY_VALUE_MAX] = {0}; + int rc = 0; NFCSTATUS status = NFCSTATUS_FAILED; phNxpNci_EEPROM_info_t swp_intf_info; - + rc = __system_property_get("vendor.qti.nfc.chipid", nq_chipid); + if (rc <= 0) { + NXPLOG_NCIHAL_E("get vendor.qti.nfc.chipid fail, rc = %d\n", rc); + } + else { + NXPLOG_NCIHAL_D("vendor.qti.nfc.chipid = %s\n", nq_chipid); + } memset(swp_info_buff, 0, sizeof(swp_info_buff)); /*Read SWP1 data*/ memset(&swp_intf_info, 0, sizeof(swp_intf_info)); @@ -2132,19 +2144,21 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) { NXP_NCI_HAL_CORE_INIT_RECOVER(retry_core_init_cnt, retry_core_init); } if (nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_WO_EXT_SWITCH) { - /*Read SWP1A data*/ - memset(&swp_intf_info, 0, sizeof(swp_intf_info)); - swp_intf_info.request_mode = GET_EEPROM_DATA; - swp_intf_info.request_type = EEPROM_SWP1A_INTF; - swp_intf_info.buffer = &swp1A_intf_status; - swp_intf_info.bufflen = sizeof(uint8_t); - status = request_EEPROM(&swp_intf_info); - if (status == NFCSTATUS_OK) - swp_info_buff[1] = swp1A_intf_status; - else { - NXPLOG_NCIHAL_E("request_EEPROM error occured %d", status); - NXP_NCI_HAL_CORE_INIT_RECOVER(retry_core_init_cnt, retry_core_init); - } + if ((rc > 0) && (strncmp(nq_chipid, NQ220, PROPERTY_VALUE_MAX) != 0) && (strncmp(nq_chipid, NQ210, PROPERTY_VALUE_MAX) != 0)) { + /*Read SWP1A data*/ + memset(&swp_intf_info, 0, sizeof(swp_intf_info)); + swp_intf_info.request_mode = GET_EEPROM_DATA; + swp_intf_info.request_type = EEPROM_SWP1A_INTF; + swp_intf_info.buffer = &swp1A_intf_status; + swp_intf_info.bufflen = sizeof(uint8_t); + status = request_EEPROM(&swp_intf_info); + if (status == NFCSTATUS_OK) + swp_info_buff[1] = swp1A_intf_status; + else { + NXPLOG_NCIHAL_E("request_EEPROM error occured %d", status); + NXP_NCI_HAL_CORE_INIT_RECOVER(retry_core_init_cnt, retry_core_init); + } + } } phNxpNci_EEPROM_info_t mEEPROM_info = { .request_mode = 0 }; mEEPROM_info.buffer = swp_info_buff; @@ -3658,6 +3672,60 @@ int phNxpNciHal_check_ncicmd_write_window(uint16_t cmd_len, uint8_t* p_cmd) { } /****************************************************************************** + * Function phNxpNciHal_getNfcChipId + * + * Description This function is called to get the NFC HW chip id. + * On successful property retrieval, chip-id is returned + * to HIDL. + * + * Returns return chip-id on success, and NULL on failure. + * + ******************************************************************************/ +std::string phNxpNciHal_getNfcChipId() { + NXPLOG_NCIHAL_D("%s : enter", __func__); + + char nq_chipid[PROPERTY_VALUE_MAX] = {0}; + int ret = 0; + + ret = __system_property_get("vendor.qti.nfc.chipid", nq_chipid); + if(ret <= 0) { + NXPLOG_NCIHAL_E("%s: Failure in getting chip-id.", __func__); + return NQ_330_440_CHIPID; + } + else { + NXPLOG_NCIHAL_D("%s: Got vendor.qti.nfc.chipid: %s ", __func__, nq_chipid); + return nq_chipid; + } +} + +/****************************************************************************** + * Function phNxpNciHal_getNfcFirmwareVersion + * + * Description This function is called to get the NFC FW version. + * On successful property retrieval, firmware version + * is returned to HIDL. + * + * Returns return fw version on success, and NULL on failure. + * + ******************************************************************************/ +std::string phNxpNciHal_getNfcFirmwareVersion() { + NXPLOG_NCIHAL_D("%s : enter", __func__); + + char nq_fw_ver[PROPERTY_VALUE_MAX] = {0}; + int ret = 0; + + ret = __system_property_get("vendor.qti.nfc.fwver", nq_fw_ver); + if(ret <= 0) { + NXPLOG_NCIHAL_E("%s: Failure in getting firmware version.", __func__); + return NULL; + } + else { + NXPLOG_NCIHAL_D("%s: Got vendor.qti.nfc.fwver: %s ", __func__, nq_fw_ver); + return nq_fw_ver; + } +} + +/****************************************************************************** * Function phNxpNciHal_ioctl * * Description This function is called by jni when wired mode is diff --git a/halimpl/hal/phNxpNciHal.h b/halimpl/hal/phNxpNciHal.h index dc5468f..1cea407 100644 --- a/halimpl/hal/phNxpNciHal.h +++ b/halimpl/hal/phNxpNciHal.h @@ -20,7 +20,7 @@ #include <hardware/nfc.h> #include <phNxpNciHal_utils.h> #include "NxpNfcCapability.h" -#include <vendor/nxp/nxpnfc/2.0/types.h> +#include <vendor/nxp/hardware/nfc/2.0/types.h> #include "DwpEseUpdater.h" #include "EseUpdateChecker.h" @@ -43,6 +43,11 @@ using namespace std; #define NCI_VERSION_1_1 0x11 #define NCI_VERSION_1_0 0x10 #define NCI_VERSION_UNKNOWN 0x00 +#define NQ_330_440_CHIPID "0x51" + +/* Uncomment define ENABLE_ESE_CLIENT to +enable eSE client */ +//#define ENABLE_ESE_CLIENT TRUE /*Mem alloc with 8 byte alignment*/ #define size_align(sz) ((((sz)-1) | 7) + 1) @@ -109,8 +114,10 @@ typedef struct phNxpNciGpioInfo { uint8_t values[2]; } phNxpNciGpioInfo_t; +#ifdef ENABLE_ESE_CLIENT extern ESE_UPDATE_STATE eseUpdateSpi; extern ESE_UPDATE_STATE eseUpdateDwp; +#endif /* Macros to enable and disable extensions */ #define HAL_ENABLE_EXT() (nxpncihal_ctrl.hal_ext_enabled = 1) diff --git a/halimpl/hal/phNxpNciHal_Kovio.h b/halimpl/hal/phNxpNciHal_Kovio.h new file mode 100644 index 0000000..c8b516b --- /dev/null +++ b/halimpl/hal/phNxpNciHal_Kovio.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 NXP Semiconductors + * + * 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 _PHNXPNCIHAL_KOVIO_H_ +#define _PHNXPNCIHAL_KOVIO_H_ + +#include <phNxpNciHal.h> +#include <phTmlNfc.h> +#include <string.h> + +extern NFCSTATUS phNxpNciHal_kovio_rsp_ext(uint8_t* p_ntf, uint16_t* p_len); +extern void phNxpNciHal_clean_Kovio_Ext(); + +#endif /* _PHNXPNCIHAL_KOVIO_H_ */ diff --git a/halimpl/inc/Nxp_Features.h b/halimpl/inc/Nxp_Features.h new file mode 100644 index 0000000..28f8301 --- /dev/null +++ b/halimpl/inc/Nxp_Features.h @@ -0,0 +1,519 @@ +/* + * Copyright (C) 2012-2016 NXP Semiconductors + * + * 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. + */ + +/* + * NXP features declarations + */ +#include <unistd.h> +#include <string.h> +#ifndef NXP_FEATURES_H +#define NXP_FEATURES_H + +#define STRMAX_1 40 +#define STRMAX_2 100 +#define FW_DLL_ROOT_DIR "/vendor/lib/" +#define FW_DLL_EXTENSION ".so" + +#define FW_MOBILE_MAJOR_NUMBER_PN553 0x01 +#define FW_MOBILE_MAJOR_NUMBER_PN551 0x05 +#define FW_MOBILE_MAJOR_NUMBER_PN48AD 0x01 + +#define NFA_EE_MAX_EE_SUPPORTED 4 + +#define JCOP_VER_3_1 1 +#define JCOP_VER_3_2 2 +#define JCOP_VER_3_3 3 +#define JCOP_VER_4_0 4 + +typedef enum { + pn547C2 = 0x01, + pn65T, + pn548C2, + pn66T, + pn551, + pn67T, + pn553, + pn80T, + pn557, + pn81T +}tNFC_chipType; + +/* + * TODO renaming + * */ +typedef struct { + /*Flags common to all chip types*/ + uint8_t _NXP_NFCC_EMPTY_DATA_PACKET : 1; + uint8_t _GEMALTO_SE_SUPPORT : 1; + uint8_t _NFCC_I2C_READ_WRITE_IMPROVEMENT : 1; + uint8_t _NFCC_MIFARE_TIANJIN : 1; + uint8_t _NFCC_MW_RCVRY_BLK_FW_DNLD : 1; + uint8_t _NFCC_DYNAMIC_DUAL_UICC : 1; + uint8_t _NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH : 1; + uint8_t _NFC_NXP_STAT_DUAL_UICC_WO_EXT_SWITCH : 1; + uint8_t _NFCC_FW_WA : 1; + uint8_t _NFCC_FORCE_NCI1_0_INIT : 1; + uint8_t _NFCC_ROUTING_BLOCK_BIT : 1; + uint8_t _NFCC_SPI_FW_DOWNLOAD_SYNC : 1; + uint8_t _HW_ANTENNA_LOOP4_SELF_TEST : 1; + uint8_t _NFCEE_REMOVED_NTF_RECOVERY : 1; + uint8_t _NFCC_FORCE_FW_DOWNLOAD : 1; + uint8_t _UICC_CREATE_CONNECTIVITY_PIPE : 1; + uint8_t _NFCC_AID_MATCHING_PLATFORM_CONFIG : 1; + uint8_t _NFCC_ROUTING_BLOCK_BIT_PROP : 1; + uint8_t _NXP_NFC_UICC_ETSI12 : 1; + uint8_t _NFA_EE_MAX_EE_SUPPORTED : 3; +}tNfc_nfccFeatureList; +/* + * TODO renaming + * */ +typedef struct { + uint8_t _ESE_EXCLUSIVE_WIRED_MODE : 2; + uint8_t _ESE_WIRED_MODE_RESUME : 2; + uint8_t _ESE_WIRED_MODE_TIMEOUT : 2; + uint8_t _ESE_PN67T_RESET : 2; + uint8_t _ESE_APDU_GATE_RESET : 2; + uint8_t _ESE_WIRED_MODE_DISABLE_DISCOVERY : 1; + uint8_t _LEGACY_APDU_GATE : 1; + uint8_t _TRIPLE_MODE_PROTECTION : 1; + uint8_t _ESE_FELICA_CLT : 1; + uint8_t _WIRED_MODE_STANDBY_PROP : 1; + uint8_t _WIRED_MODE_STANDBY : 1; + uint8_t _ESE_DUAL_MODE_PRIO_SCHEME : 2; + uint8_t _ESE_FORCE_ENABLE : 1; + uint8_t _ESE_RESET_METHOD : 1; + uint8_t _EXCLUDE_NV_MEM_DEPENDENCY : 1; + uint8_t _ESE_ETSI_READER_ENABLE : 1; + uint8_t _ESE_SVDD_SYNC : 1; + uint8_t _NFCC_ESE_UICC_CONCURRENT_ACCESS_PROTECTION : 1; + uint8_t _ESE_JCOP_DWNLD_PROTECTION : 1; + uint8_t _UICC_HANDLE_CLEAR_ALL_PIPES : 1; + uint8_t _GP_CONTINOUS_PROCESSING : 1; + uint8_t _ESE_DWP_SPI_SYNC_ENABLE : 1; + uint8_t _ESE_ETSI12_PROP_INIT : 1; + uint8_t _ESE_WIRED_MODE_PRIO : 1; + uint8_t _ESE_UICC_EXCLUSIVE_WIRED_MODE : 1; + uint8_t _ESE_POWER_MODE : 1; + uint8_t _ESE_P73_ISO_RST : 1; + uint8_t _BLOCK_PROPRIETARY_APDU_GATE : 1; + uint8_t _JCOP_WA_ENABLE : 1; + uint8_t _NXP_LDR_SVC_VER_2 : 1; + uint8_t _NXP_ESE_VER : 3; +}tNfc_eseFeatureList; +/* + * TODO renaming + * */ +typedef struct { + uint8_t _NFCC_RESET_RSP_LEN; +}tNfc_platformFeatureList; + +typedef struct { + uint8_t _NCI_INTERFACE_UICC_DIRECT; + uint8_t _NCI_INTERFACE_ESE_DIRECT; + uint8_t _NCI_PWR_LINK_PARAM_CMD_SIZE; + uint8_t _NCI_EE_PWR_LINK_ALWAYS_ON; + uint8_t _NFA_EE_MAX_AID_ENTRIES; + uint8_t _NFC_NXP_AID_MAX_SIZE_DYN : 1; + uint8_t _FW_LIB_PATH[STRMAX_2]; + uint8_t _PLATFORM_LIB_PATH[STRMAX_2]; + uint8_t _PKU_LIB_PATH[STRMAX_2]; + uint16_t _PHDNLDNFC_USERDATA_EEPROM_OFFSET; + uint16_t _PHDNLDNFC_USERDATA_EEPROM_LEN; + uint8_t _FW_MOBILE_MAJOR_NUMBER; +}tNfc_nfcMwFeatureList; +/* + * TODO renaming + * */ +typedef struct { + uint8_t nfcNxpEse : 1; + tNFC_chipType chipType; + tNfc_nfccFeatureList nfccFL; + tNfc_eseFeatureList eseFL; + tNfc_platformFeatureList platformFL; + tNfc_nfcMwFeatureList nfcMwFL; +}tNfc_featureList; + +extern tNfc_featureList nfcFL; + +#define CONFIGURE_FEATURELIST(chipType) { \ + nfcFL.chipType = chipType; \ + nfcFL.nfcMwFL._NFC_NXP_AID_MAX_SIZE_DYN = true; \ + if(chipType == pn81T) { \ + nfcFL.chipType = pn557; \ + } \ + else if(chipType == pn80T) { \ + nfcFL.chipType = pn553; \ + } \ + else if(chipType == pn67T) { \ + nfcFL.chipType = pn551; \ + } \ + else if(chipType == pn66T) { \ + nfcFL.chipType = pn548C2; \ + } \ + else if(chipType == pn65T) { \ + nfcFL.chipType = pn547C2; \ + } \ + if ((chipType == pn65T) || (chipType == pn66T) || \ + (chipType == pn67T) || (chipType == pn80T) || \ + (chipType == pn81T)) { \ + nfcFL.nfcNxpEse = true; \ + CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) \ + } \ + else { \ + nfcFL.nfcNxpEse = false; \ + CONFIGURE_FEATURELIST_NFCC(chipType) \ + } \ + \ + \ +} + +#define CONFIGURE_FEATURELIST_NFCC_WITH_ESE(chipType) { \ + nfcFL.nfccFL._NXP_NFCC_EMPTY_DATA_PACKET = true; \ + nfcFL.nfccFL._GEMALTO_SE_SUPPORT = true; \ + \ + \ + nfcFL.eseFL._ESE_EXCLUSIVE_WIRED_MODE = 1; \ + nfcFL.eseFL._ESE_WIRED_MODE_RESUME = 2; \ + nfcFL.eseFL._ESE_PN67T_RESET = 1; \ + nfcFL.eseFL._ESE_APDU_GATE_RESET = 2; \ + nfcFL.eseFL._NXP_ESE_VER = JCOP_VER_4_0; \ + nfcFL.eseFL._NXP_LDR_SVC_VER_2 = true; \ + \ + \ + if (chipType == pn81T) { \ + CONFIGURE_FEATURELIST_NFCC(pn557) \ + nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = true; \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 4; \ + \ + \ + nfcFL.eseFL._ESE_FELICA_CLT = true; \ + nfcFL.eseFL._ESE_DUAL_MODE_PRIO_SCHEME = \ + nfcFL.eseFL._ESE_WIRED_MODE_RESUME; \ + nfcFL.eseFL._ESE_RESET_METHOD = true; \ + nfcFL.eseFL._ESE_POWER_MODE = true; \ + nfcFL.eseFL._ESE_P73_ISO_RST = true; \ + nfcFL.eseFL._WIRED_MODE_STANDBY = true; \ + nfcFL.eseFL._ESE_ETSI_READER_ENABLE = true; \ + nfcFL.eseFL._ESE_SVDD_SYNC = true; \ + nfcFL.eseFL._ESE_JCOP_DWNLD_PROTECTION = true; \ + nfcFL.eseFL._UICC_HANDLE_CLEAR_ALL_PIPES = true; \ + nfcFL.eseFL._GP_CONTINOUS_PROCESSING = false; \ + nfcFL.eseFL._ESE_DWP_SPI_SYNC_ENABLE = true; \ + nfcFL.eseFL._ESE_ETSI12_PROP_INIT = true; \ + } \ + if (chipType == pn80T) { \ + CONFIGURE_FEATURELIST_NFCC(pn553) \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 4; \ + \ + \ + nfcFL.eseFL._ESE_FELICA_CLT = true; \ + nfcFL.eseFL._WIRED_MODE_STANDBY = true; \ + nfcFL.eseFL._ESE_DUAL_MODE_PRIO_SCHEME = \ + nfcFL.eseFL._ESE_WIRED_MODE_RESUME; \ + nfcFL.eseFL._ESE_RESET_METHOD = true; \ + nfcFL.eseFL._ESE_ETSI_READER_ENABLE = true; \ + nfcFL.eseFL._ESE_SVDD_SYNC = true; \ + nfcFL.eseFL._ESE_JCOP_DWNLD_PROTECTION = true; \ + nfcFL.eseFL._UICC_HANDLE_CLEAR_ALL_PIPES = true; \ + nfcFL.eseFL._ESE_DWP_SPI_SYNC_ENABLE = true; \ + nfcFL.eseFL._ESE_POWER_MODE = true; \ + nfcFL.eseFL._ESE_P73_ISO_RST = true; \ + \ + \ + nfcFL.nfcMwFL._NCI_PWR_LINK_PARAM_CMD_SIZE = 0x02; \ + nfcFL.nfcMwFL._NCI_EE_PWR_LINK_ALWAYS_ON = 0x01; \ + } \ + else if (chipType == pn67T) \ + { \ + CONFIGURE_FEATURELIST_NFCC(pn551) \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 3; \ + \ + \ + nfcFL.eseFL._TRIPLE_MODE_PROTECTION = true; \ + nfcFL.eseFL._WIRED_MODE_STANDBY_PROP = true; \ + nfcFL.eseFL._ESE_FORCE_ENABLE = true; \ + nfcFL.eseFL._ESE_ETSI_READER_ENABLE = true; \ + nfcFL.eseFL._ESE_SVDD_SYNC = true; \ + nfcFL.eseFL._LEGACY_APDU_GATE = true; \ + nfcFL.eseFL._NFCC_ESE_UICC_CONCURRENT_ACCESS_PROTECTION = true; \ + nfcFL.eseFL._ESE_DWP_SPI_SYNC_ENABLE = true; \ + } \ + else if (chipType == pn66T) \ + { \ + CONFIGURE_FEATURELIST_NFCC(pn548C2) \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 3; \ + \ + \ + nfcFL.eseFL._TRIPLE_MODE_PROTECTION = true; \ + nfcFL.eseFL._WIRED_MODE_STANDBY_PROP = true; \ + nfcFL.eseFL._WIRED_MODE_STANDBY = true; \ + nfcFL.eseFL._ESE_FORCE_ENABLE = true; \ + nfcFL.eseFL._ESE_ETSI_READER_ENABLE = true; \ + nfcFL.eseFL._ESE_SVDD_SYNC = true; \ + nfcFL.eseFL._LEGACY_APDU_GATE = true; \ + nfcFL.eseFL._NFCC_ESE_UICC_CONCURRENT_ACCESS_PROTECTION = true; \ + nfcFL.eseFL._ESE_DWP_SPI_SYNC_ENABLE = true; \ + } \ + else if (chipType == pn65T) \ + { \ + CONFIGURE_FEATURELIST_NFCC(pn547C2) \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 3; \ + nfcFL.eseFL._ESE_WIRED_MODE_DISABLE_DISCOVERY = true; \ + nfcFL.eseFL._LEGACY_APDU_GATE = true; \ + } \ +} + + +#define CONFIGURE_FEATURELIST_NFCC(chipType) { \ + nfcFL.eseFL._ESE_WIRED_MODE_TIMEOUT = 3; \ + nfcFL.eseFL._ESE_WIRED_MODE_DISABLE_DISCOVERY = false; \ + nfcFL.eseFL._LEGACY_APDU_GATE = false; \ + nfcFL.eseFL._TRIPLE_MODE_PROTECTION = false; \ + nfcFL.eseFL._ESE_FELICA_CLT = false; \ + nfcFL.eseFL._WIRED_MODE_STANDBY_PROP = false; \ + nfcFL.eseFL._WIRED_MODE_STANDBY = false; \ + nfcFL.eseFL._ESE_DUAL_MODE_PRIO_SCHEME = \ + nfcFL.eseFL._ESE_WIRED_MODE_TIMEOUT; \ + nfcFL.eseFL._ESE_FORCE_ENABLE = false; \ + nfcFL.eseFL._ESE_RESET_METHOD = false; \ + nfcFL.eseFL._ESE_ETSI_READER_ENABLE = false; \ + nfcFL.eseFL._ESE_SVDD_SYNC = false; \ + nfcFL.eseFL._NFCC_ESE_UICC_CONCURRENT_ACCESS_PROTECTION = false; \ + nfcFL.eseFL._ESE_JCOP_DWNLD_PROTECTION = false; \ + nfcFL.eseFL._UICC_HANDLE_CLEAR_ALL_PIPES = false; \ + nfcFL.eseFL._GP_CONTINOUS_PROCESSING = false; \ + nfcFL.eseFL._ESE_DWP_SPI_SYNC_ENABLE = false; \ + nfcFL.eseFL._ESE_ETSI12_PROP_INIT = false; \ + nfcFL.eseFL._ESE_WIRED_MODE_PRIO = false; \ + nfcFL.eseFL._ESE_UICC_EXCLUSIVE_WIRED_MODE = false; \ + nfcFL.eseFL._ESE_POWER_MODE = false; \ + nfcFL.eseFL._ESE_P73_ISO_RST = false; \ + nfcFL.eseFL._BLOCK_PROPRIETARY_APDU_GATE = false; \ + nfcFL.eseFL._JCOP_WA_ENABLE = true; \ + nfcFL.eseFL._EXCLUDE_NV_MEM_DEPENDENCY = false; \ + nfcFL.nfccFL._NXP_NFC_UICC_ETSI12 = false; \ + nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = false; \ + \ + \ + nfcFL.platformFL._NFCC_RESET_RSP_LEN = 0; \ + \ + \ + nfcFL.nfcMwFL._NCI_INTERFACE_UICC_DIRECT = 0x00; \ + nfcFL.nfcMwFL._NCI_INTERFACE_ESE_DIRECT = 0x00; \ + nfcFL.nfcMwFL._NCI_PWR_LINK_PARAM_CMD_SIZE = 0x02; \ + nfcFL.nfcMwFL._NCI_EE_PWR_LINK_ALWAYS_ON = 0x01; \ + nfcFL.nfcMwFL._PHDNLDNFC_USERDATA_EEPROM_OFFSET = 0x023CU; \ + nfcFL.nfcMwFL._PHDNLDNFC_USERDATA_EEPROM_LEN = 0x0C80U; \ + nfcFL.nfcMwFL._FW_MOBILE_MAJOR_NUMBER = \ + FW_MOBILE_MAJOR_NUMBER_PN48AD; \ + \ + \ + if (chipType == pn557) \ + { \ + nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ + nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = false; \ + nfcFL.nfccFL._NFCC_MW_RCVRY_BLK_FW_DNLD = true; \ + nfcFL.nfccFL._NFCC_DYNAMIC_DUAL_UICC = true; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH = false; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_WO_EXT_SWITCH = true; \ + nfcFL.nfccFL._NFCC_FW_WA = true; \ + nfcFL.nfccFL._NFCC_FORCE_NCI1_0_INIT = false; \ + nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = true; \ + nfcFL.nfccFL._HW_ANTENNA_LOOP4_SELF_TEST = false; \ + nfcFL.nfccFL._NFCEE_REMOVED_NTF_RECOVERY = true; \ + nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = true; \ + nfcFL.nfccFL._UICC_CREATE_CONNECTIVITY_PIPE = true; \ + nfcFL.nfccFL._NXP_NFC_UICC_ETSI12 = false; \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 3; \ + \ + \ + nfcFL.eseFL._ESE_ETSI12_PROP_INIT = true; \ + nfcFL.eseFL._EXCLUDE_NV_MEM_DEPENDENCY = true; \ + \ + \ + nfcFL.platformFL._NFCC_RESET_RSP_LEN = 0x10U; \ + \ + \ + nfcFL.nfcMwFL._NCI_INTERFACE_UICC_DIRECT = 0x82; \ + nfcFL.nfcMwFL._NCI_INTERFACE_ESE_DIRECT = 0x83; \ + \ + \ + } \ + else if (chipType == pn553) \ + { \ + nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ + nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = false; \ + nfcFL.nfccFL._NFCC_MW_RCVRY_BLK_FW_DNLD = true; \ + nfcFL.nfccFL._NFCC_DYNAMIC_DUAL_UICC = true; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH = false; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_WO_EXT_SWITCH = true; \ + nfcFL.nfccFL._NFCC_FW_WA = true; \ + nfcFL.nfccFL._NFCC_FORCE_NCI1_0_INIT = true; \ + nfcFL.nfccFL._NFCC_ROUTING_BLOCK_BIT = true; \ + nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = true; \ + nfcFL.nfccFL._HW_ANTENNA_LOOP4_SELF_TEST = false; \ + nfcFL.nfccFL._NFCEE_REMOVED_NTF_RECOVERY = true; \ + nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = true; \ + nfcFL.nfccFL._UICC_CREATE_CONNECTIVITY_PIPE = true; \ + nfcFL.nfccFL._NFCC_AID_MATCHING_PLATFORM_CONFIG = false; \ + nfcFL.nfccFL._NFCC_ROUTING_BLOCK_BIT_PROP = false; \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 3; \ + \ + \ + nfcFL.eseFL._ESE_ETSI12_PROP_INIT = true; \ + nfcFL.eseFL._JCOP_WA_ENABLE = false; \ + nfcFL.eseFL._EXCLUDE_NV_MEM_DEPENDENCY = true; \ + \ + \ + nfcFL.platformFL._NFCC_RESET_RSP_LEN = 0x10U; \ + \ + \ + nfcFL.nfcMwFL._NCI_INTERFACE_UICC_DIRECT = 0x82; \ + nfcFL.nfcMwFL._NCI_INTERFACE_ESE_DIRECT = 0x83; \ + \ + \ + SRTCPY_FW("libpn553tc_fw", "libpn553tc_fw_platform", \ + "libpn553tc_fw_pku") \ + \ + \ + nfcFL.nfcMwFL._FW_MOBILE_MAJOR_NUMBER = \ + FW_MOBILE_MAJOR_NUMBER_PN553; \ + \ + \ + } \ + else if (chipType == pn551) \ + { \ + nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ + nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = true; \ + nfcFL.nfccFL._NFCC_MW_RCVRY_BLK_FW_DNLD = false; \ + nfcFL.nfccFL._NFCC_DYNAMIC_DUAL_UICC = false; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH = true; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_WO_EXT_SWITCH = false; \ + nfcFL.nfccFL._NFCC_FW_WA = false; \ + nfcFL.nfccFL._NFCC_FORCE_NCI1_0_INIT = false; \ + nfcFL.nfccFL._NFCC_ROUTING_BLOCK_BIT = false; \ + nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = false; \ + nfcFL.nfccFL._HW_ANTENNA_LOOP4_SELF_TEST = true; \ + nfcFL.nfccFL._NFCEE_REMOVED_NTF_RECOVERY = true; \ + nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = false; \ + nfcFL.nfccFL._UICC_CREATE_CONNECTIVITY_PIPE = false; \ + nfcFL.nfccFL._NFCC_AID_MATCHING_PLATFORM_CONFIG = true; \ + nfcFL.nfccFL._NFCC_ROUTING_BLOCK_BIT_PROP = true; \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 2; \ + \ + \ + nfcFL.eseFL._ESE_FORCE_ENABLE = true; \ + \ + \ + nfcFL.platformFL._NFCC_RESET_RSP_LEN = 0x11U; \ + \ + \ + nfcFL.nfcMwFL._NCI_INTERFACE_UICC_DIRECT = 0x82; \ + nfcFL.nfcMwFL._NCI_INTERFACE_ESE_DIRECT = 0x83; \ + \ + \ + SRTCPY_FW("libpn551_fw", "libpn551_fw_platform", \ + "libpn551_fw_pku") \ + \ + \ + nfcFL.nfcMwFL._PHDNLDNFC_USERDATA_EEPROM_OFFSET = 0x02BCU; \ + nfcFL.nfcMwFL._PHDNLDNFC_USERDATA_EEPROM_LEN = 0x0C00U; \ + nfcFL.nfcMwFL._FW_MOBILE_MAJOR_NUMBER = \ + FW_MOBILE_MAJOR_NUMBER_PN551; \ + \ + \ + } \ + else if (chipType == pn548C2) \ + { \ + nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = true; \ + nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = true; \ + nfcFL.nfccFL._NFCC_MW_RCVRY_BLK_FW_DNLD = false; \ + nfcFL.nfccFL._NFCC_DYNAMIC_DUAL_UICC = false; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH = true; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_WO_EXT_SWITCH = false; \ + nfcFL.nfccFL._NFCC_FW_WA = false; \ + nfcFL.nfccFL._NFCC_FORCE_NCI1_0_INIT = false; \ + nfcFL.nfccFL._NFCC_ROUTING_BLOCK_BIT = false; \ + nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = false; \ + nfcFL.nfccFL._HW_ANTENNA_LOOP4_SELF_TEST = true; \ + nfcFL.nfccFL._NFCEE_REMOVED_NTF_RECOVERY = true; \ + nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = false; \ + nfcFL.nfccFL._UICC_CREATE_CONNECTIVITY_PIPE = false; \ + nfcFL.nfccFL._NFCC_AID_MATCHING_PLATFORM_CONFIG = true; \ + nfcFL.nfccFL._NFCC_ROUTING_BLOCK_BIT_PROP = true; \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 2; \ + \ + \ + nfcFL.eseFL._ESE_FORCE_ENABLE = true; \ + nfcFL.eseFL._ESE_ETSI12_PROP_INIT = true; \ + \ + \ + nfcFL.nfcMwFL._NCI_INTERFACE_UICC_DIRECT = 0x82; \ + nfcFL.nfcMwFL._NCI_INTERFACE_ESE_DIRECT = 0x83; \ + \ + \ + SRTCPY_FW("libpn548ad_fw", "libpn548ad_fw_platform", \ + "libpn548ad_fw_pku") \ + \ + \ + nfcFL.nfcMwFL._PHDNLDNFC_USERDATA_EEPROM_OFFSET = 0x02BCU; \ + nfcFL.nfcMwFL._PHDNLDNFC_USERDATA_EEPROM_LEN = 0x0C00U; \ + \ + \ + } \ + else if(chipType == pn547C2) \ + { \ + nfcFL.nfccFL._NFCC_I2C_READ_WRITE_IMPROVEMENT = false; \ + nfcFL.nfccFL._NFCC_MIFARE_TIANJIN = true; \ + nfcFL.nfccFL._NFCC_MW_RCVRY_BLK_FW_DNLD = false; \ + nfcFL.nfccFL._NFCC_DYNAMIC_DUAL_UICC = false; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH = false; \ + nfcFL.nfccFL._NFC_NXP_STAT_DUAL_UICC_WO_EXT_SWITCH = false; \ + nfcFL.nfccFL._NFCC_FW_WA = false; \ + nfcFL.nfccFL._NFCC_FORCE_NCI1_0_INIT = false; \ + nfcFL.nfccFL._NFCC_ROUTING_BLOCK_BIT = false; \ + nfcFL.nfccFL._NFCC_SPI_FW_DOWNLOAD_SYNC = false; \ + nfcFL.nfccFL._HW_ANTENNA_LOOP4_SELF_TEST = true; \ + nfcFL.nfccFL._NFCEE_REMOVED_NTF_RECOVERY = true; \ + nfcFL.nfccFL._NFCC_FORCE_FW_DOWNLOAD = false; \ + nfcFL.nfccFL._UICC_CREATE_CONNECTIVITY_PIPE = false; \ + nfcFL.nfccFL._NFCC_AID_MATCHING_PLATFORM_CONFIG = true; \ + nfcFL.nfccFL._NFCC_ROUTING_BLOCK_BIT_PROP = false; \ + nfcFL.nfccFL._NFA_EE_MAX_EE_SUPPORTED = 2; \ + \ + \ + nfcFL.nfcMwFL._NCI_INTERFACE_UICC_DIRECT = 0x81; \ + nfcFL.nfcMwFL._NCI_INTERFACE_ESE_DIRECT = 0x82; \ + \ + \ + SRTCPY_FW("libpn547_fw", "libpn547_fw_platform", \ + "libpn547_fw_pku") \ + \ + \ + } \ +} +#ifdef __cplusplus +#define SRTCPY_FW(str1,str2,str3) +#else +#define SRTCPY_FW(str1, str2,str3) \ + snprintf(nfcFL.nfcMwFL._FW_LIB_PATH, STRMAX_2, "%s%s%s", \ + FW_DLL_ROOT_DIR, str1, FW_DLL_EXTENSION); \ + snprintf(nfcFL.nfcMwFL._PLATFORM_LIB_PATH, STRMAX_2, "%s%s%s", \ + FW_DLL_ROOT_DIR, str2, FW_DLL_EXTENSION); \ + snprintf(nfcFL.nfcMwFL._PKU_LIB_PATH, STRMAX_2, "%s%s%s", \ + FW_DLL_ROOT_DIR, str3, FW_DLL_EXTENSION); +#endif +#endif diff --git a/halimpl/inc/phNxpNciHal_Adaptation.h b/halimpl/inc/phNxpNciHal_Adaptation.h index 6f592a6..913787b 100755..100644 --- a/halimpl/inc/phNxpNciHal_Adaptation.h +++ b/halimpl/inc/phNxpNciHal_Adaptation.h @@ -17,16 +17,32 @@ #ifndef _PHNXPNCIHAL_ADAPTATION_H_ #define _PHNXPNCIHAL_ADAPTATION_H_ +#ifdef ENABLE_ESE_CLIENT #include "EseUpdateChecker.h" +#endif #include <android/hardware/nfc/1.2/INfc.h> #include <android/hardware/nfc/1.2/types.h> #include <hardware/hardware.h> #include <hardware/nfc.h> +using namespace std; using ::android::hardware::nfc::V1_2::NfcConfig; +#define NFC_NCI_NXP_PN54X_HARDWARE_MODULE_ID "nfc_nci.nqx" + +typedef struct +{ + struct nfc_nci_device nci_device; + + /* Local definitions */ + int (*ioctl)(const struct nfc_nci_device *p_dev, long arg, void *p_data); + int(*check_fw_dwnld_flag)(const struct nfc_nci_device *p_dev, uint8_t* param1); +} pn547_dev_t; + +#ifdef ENABLE_ESE_CLIENT extern ESE_UPDATE_STATE eseUpdateSpi; extern ESE_UPDATE_STATE eseUpdateDwp; +#endif /* NXP HAL functions */ @@ -41,6 +57,8 @@ int phNxpNciHal_close(bool); int phNxpNciHal_configDiscShutdown(void); int phNxpNciHal_control_granted(void); int phNxpNciHal_power_cycle(void); +string phNxpNciHal_getNfcChipId(); +string phNxpNciHal_getNfcFirmwareVersion(); void phNxpNciHal_getVendorConfig( android::hardware::nfc::V1_1::NfcConfig &config); void phNxpNciHal_getVendorConfig_1_2(NfcConfig &config); diff --git a/halimpl/libnfc-nxp-PN547C2_example.conf b/halimpl/libnfc-nxp-PN547C2_example.conf new file mode 100644 index 0000000..a3d727c --- /dev/null +++ b/halimpl/libnfc-nxp-PN547C2_example.conf @@ -0,0 +1,188 @@ +## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn547) +## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn547) +############################################################################### +# Application options +# Logging Levels +# NXPLOG_DEFAULT_LOGLEVEL 0x01 +# ANDROID_LOG_DEBUG 0x03 +# ANDROID_LOG_WARN 0x02 +# ANDROID_LOG_ERROR 0x01 +# ANDROID_LOG_SILENT 0x00 +NXPLOG_EXTNS_LOGLEVEL=0x03 +NXPLOG_NCIHAL_LOGLEVEL=0x03 +NXPLOG_NCIX_LOGLEVEL=0x03 +NXPLOG_NCIR_LOGLEVEL=0x03 +NXPLOG_FWDNLD_LOGLEVEL=0x03 +NXPLOG_TML_LOGLEVEL=0x03 + +############################################################################### +# Nfc Device Node name +NXP_NFC_DEV_NODE="/dev/nq-nci" + +############################################################################### +# Extension for Mifare reader enable +MIFARE_READER_ENABLE=0x01 + +############################################################################### +# Vzw Feature enable +VZW_FEATURE_ENABLE=0x01 + +############################################################################### +# File name for Firmware +NXP_FW_NAME="libpn547_fw.so" + +############################################################################### +# System clock source selection configuration +#define CLK_SRC_XTAL 1 +#define CLK_SRC_PLL 2 +NXP_SYS_CLK_SRC_SEL=0x01 + +############################################################################### +# System clock frequency selection configuration +#define CLK_FREQ_13MHZ 1 +#define CLK_FREQ_19_2MHZ 2 +#define CLK_FREQ_24MHZ 3 +#define CLK_FREQ_26MHZ 4 +#define CLK_FREQ_32MHZ 5 +#define CLK_FREQ_38_4MHZ 6 +#define CLK_FREQ_52MHZ 7 +NXP_SYS_CLK_FREQ_SEL=0x00 + +############################################################################### +# The timeout value to be used for clock request acknowledgment +# min value = 0x01 to max = 0x06 +NXP_SYS_CLOCK_TO_CFG=0x01 + +############################################################################### +# NXP proprietary settings +NXP_ACT_PROP_EXTN={2F, 02, 00} + +############################################################################### +# NFC forum profile settings +NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} + +############################################################################### +# Standby enable settings +#NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### +#Atonomous Mode +#Enable 0x01 +#Disable 0x00 +NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE=0x00 + + +############################################################################### +## Set configuration optimization decision setting +## Enable = 0x01 +## Disable = 0x00 +NXP_SET_CONFIG_ALWAYS=0x01 + +############################################################################### +# Core configuration rf field filter settings to enable set to 01 to disable set to 00 last bit +NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01 + } + +############################################################################### +# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set to 0x00 +NXP_I2C_FRAGMENTATION_ENABLED=0x00 + +############################################################################### +# Mifare Classic Key settings +#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, +# A0, 52, 06, D3, F7, D3, F7, D3, F7, +# A0, 53, 06, FF, FF, FF, FF, FF, FF, +# A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 +NXP_DEFAULT_SE=0x02 + +############################################################################### +NXP_DEFAULT_NFCEE_TIMEOUT=20 + +############################################################################### +#Enable SWP full power mode when phone is power off +NXP_SWP_FULL_PWR_ON=0x01 + +############################################################################### +#Set the default AID route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_AID_ROUTE=0x00 + +############################################################################### +#Set the Mifare Desfire route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_DESFIRE_ROUTE=0x02 + +############################################################################### +#Set the Mifare CLT route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_MIFARE_CLT_ROUTE=0x02 + +############################################################################## +#### Select the CHIP #### +#PN547C2 0x01 +#PN65T 0x02 +#PN548AD 0x03 +#PN66T 0x04 +NXP_NFC_CHIP=0x01 + +############################################################################### +#Timeout in secs +NXP_SWP_RD_START_TIMEOUT=0x0A + +############################################################################### +#Timeout in secs +NXP_SWP_RD_TAG_OP_TIMEOUT=0x01 + +############################################################################### +# CE when Screen state is locked +# This setting is for DEFAULT_AID_ROUTE, +# DEFAULT_DESFIRE_ROUTE and DEFAULT_MIFARE_CLT_ROUTE +# Disable 0x00 +# Enable 0x01 +NXP_CE_ROUTE_STRICT_DISABLE=0x01 + +############################################################################### +# AID Matching platform options +# AID_MATCHING_L 0x01 +# AID_MATCHING_K 0x02 +AID_MATCHING_PLATFORM=0x01 + +################################################################################ +#Used to Restrict Type A UICC baud rate +#0 = default supported +#1 = 212 maximum supported +#2 = 424 maximum supported +#3 = 848 maximum supported +NXP_TYPEA_UICC_BAUD_RATE=0x00 + +################################################################################ +#Used to Restrict Type B UICC baud rate +#0 = default supported +#1 = 212 maximum supported +#2 = 424 maximum supported +#3 = 848 maximum supported +NXP_TYPEB_UICC_BAUD_RATE=0x00 + +################################################################################ +#Config to allow adding aids +#NFC on/off is required after this config +#1 = enabling adding aid to NFCC routing table. +#0 = disabling adding aid to NFCC routing table. +NXP_ENABLE_ADD_AID=0x01 + +################################################################################ diff --git a/halimpl/libnfc-nxp-PN548AD_example.conf b/halimpl/libnfc-nxp-PN548AD_example.conf new file mode 100644 index 0000000..49cb58a --- /dev/null +++ b/halimpl/libnfc-nxp-PN548AD_example.conf @@ -0,0 +1,265 @@ +## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn54x) +## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn54x) + +############################################################################### +# Application options +# Logging Levels +# NXPLOG_DEFAULT_LOGLEVEL 0x01 +# ANDROID_LOG_DEBUG 0x03 +# ANDROID_LOG_WARN 0x02 +# ANDROID_LOG_ERROR 0x01 +# ANDROID_LOG_SILENT 0x00 +# +NXPLOG_EXTNS_LOGLEVEL=0x03 +NXPLOG_NCIHAL_LOGLEVEL=0x03 +NXPLOG_NCIX_LOGLEVEL=0x03 +NXPLOG_NCIR_LOGLEVEL=0x03 +NXPLOG_FWDNLD_LOGLEVEL=0x03 +NXPLOG_TML_LOGLEVEL=0x03 + +############################################################################### +# Extension for Mifare reader enable +MIFARE_READER_ENABLE=0x01 + +############################################################################### +# Vzw Feature enable +VZW_FEATURE_ENABLE=0x01 + +############################################################################### +# File location for Firmware +#FW_STORAGE="/vendor/firmware/libpn548_fw.so" + +############################################################################### +# System clock source selection configuration +#define CLK_SRC_XTAL 1 +#define CLK_SRC_PLL 2 + +NXP_SYS_CLK_SRC_SEL=0x02 + +############################################################################### +# System clock frequency selection configuration +#define CLK_FREQ_13MHZ 1 +#define CLK_FREQ_19_2MHZ 2 +#define CLK_FREQ_24MHZ 3 +#define CLK_FREQ_26MHZ 4 +#define CLK_FREQ_38_4MHZ 5 +#define CLK_FREQ_52MHZ 6 + +NXP_SYS_CLK_FREQ_SEL=0x02 + +############################################################################### +# The timeout value to be used for clock request acknowledgment +# min value = 0x01 to max = 0x1A + +NXP_SYS_CLOCK_TO_CFG=0x01 + +############################################################################### +# NXP proprietary settings +NXP_ACT_PROP_EXTN={2F, 02, 00} + +############################################################################### +# NFC forum profile settings +NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} + +############################################################################### +# NFCC Configuration Control +# Allow NFCC to manage RF Config 0x01 +# Don't allow NFCC to manage RF Config 0x00 +NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01} + +############################################################################### +# Standby enable settings +#NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### +# NXP TVDD configurations settings +# Allow NFCC to configure External TVDD, There are currently three +#configurations (1, 2 and 3) are supported, out of them only one can be +#supported. + +NXP_EXT_TVDD_CFG=0x01 + +############################################################################### +#config1:SLALM, 3.3V for both RM and CM +NXP_EXT_TVDD_CFG_1={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 02, 09, 00} + +############################################################################### +#config2: use DCDC in CE, use Tx_Pwr_Req, set CFG2 mode, SLALM, +#monitoring 5V from DCDC, 4.7V for both RM and CM, DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_2={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 56, 64, 0A} + +############################################################################### +#config3: use DCDC in CE, use Tx_Pwr_Req, SLALM, monitoring 5V from DCDC, +#DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_3={20, 02, 0B, 02, A0, 66, 01, 01, A0, 0E, 03, 52, 64, 0A} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +NXP_CORE_CONF_EXTN={20, 02, 15, 05, + A0, EC, 01, 01, + A0, ED, 01, 00, + A0, 5E, 01, 01, + A0, 40, 01, 01, + A0, DD, 01, 2D + } + +############################################################################### +# Core configuration rf field filter settings to enable set 01 ,to disable set to 00 last bit +NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01 + } + +############################################################################### +# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set to 0x00 +NXP_I2C_FRAGMENTATION_ENABLED=0x00 + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2B, 0D, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 60, 01, 0E, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### +# Mifare Classic Key settings +#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, +# A0, 52, 06, D3, F7, D3, F7, D3, F7, +# A0, 53, 06, FF, FF, FF, FF, FF, FF, +# A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 + +NXP_DEFAULT_SE=0x07 + +############################################################################### +#Enable SWP full power mode when phone is power off +NXP_SWP_FULL_PWR_ON=0x00 + +############################################################################### +#### Select the CHIP #### +#PN547C2 0x01 +#PN65T 0x02 +#PN548AD 0x03 +#PN66T 0x04 + +NXP_NFC_CHIP=0x03 + +############################################################################### +# CE when Screen state is locked +# Disable 0x00 +# Enable 0x01 +NXP_CE_ROUTE_STRICT_DISABLE=0x01 + +############################################################################### +#Timeout in secs to get NFCEE Discover notification +NXP_DEFAULT_NFCEE_DISC_TIMEOUT=20 + +NXP_DEFAULT_NFCEE_TIMEOUT=0x06 + +############################################################################### +#Timeout in secs +NXP_SWP_RD_START_TIMEOUT=0x0A + +############################################################################### +#Timeout in secs +NXP_SWP_RD_TAG_OP_TIMEOUT=0x01 + +############################################################################### +#Set the default AID route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_AID_ROUTE=0x00 + +############################################################################### +#Set the Mifare Desfire route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_DESFIRE_ROUTE=0x02 + +############################################################################### +#Set the Mifare CLT route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_MIFARE_CLT_ROUTE=0x02 + +############################################################################### +# AID Matching platform options +# AID_MATCHING_L 0x01 +# AID_MATCHING_K 0x02 +AID_MATCHING_PLATFORM=0x01 + +############################################################################### +#CHINA_TIANJIN_RF_SETTING +#Enable 0x01 +#Disable 0x00 +NXP_CHINA_TIANJIN_RF_ENABLED=0x01 + +############################################################################### +#SWP_SWITCH_TIMEOUT_SETTING +# Allowed range of swp timeout setting is 0x00 to 0x3C [0 - 60]. +# Timeout in milliseconds, for example +# No Timeout 0x00 +# 10 millisecond timeout 0x0A +NXP_SWP_SWITCH_TIMEOUT=0x0A diff --git a/halimpl/libnfc-nxp-PN548C2_example.conf b/halimpl/libnfc-nxp-PN548C2_example.conf new file mode 100644 index 0000000..5a5fd07 --- /dev/null +++ b/halimpl/libnfc-nxp-PN548C2_example.conf @@ -0,0 +1,337 @@ +## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn547) +## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn547) +############################################################################### +# Application options +# Logging Levels +# NXPLOG_DEFAULT_LOGLEVEL 0x01 +# ANDROID_LOG_DEBUG 0x03 +# ANDROID_LOG_WARN 0x02 +# ANDROID_LOG_ERROR 0x01 +# ANDROID_LOG_SILENT 0x00 +NXPLOG_EXTNS_LOGLEVEL=0x03 +NXPLOG_NCIHAL_LOGLEVEL=0x03 +NXPLOG_NCIX_LOGLEVEL=0x03 +NXPLOG_NCIR_LOGLEVEL=0x03 +NXPLOG_FWDNLD_LOGLEVEL=0x03 +NXPLOG_TML_LOGLEVEL=0x03 + +############################################################################### +# Nfc Device Node name +NXP_NFC_DEV_NODE="/dev/nq-nci" + +############################################################################### +# Extension for Mifare reader enable +MIFARE_READER_ENABLE=0x01 + +############################################################################### +# Vzw Feature enable +VZW_FEATURE_ENABLE=0x01 + +############################################################################### +# File name for Firmware +NXP_FW_NAME="libpn548ad_fw.so" + +############################################################################### +# System clock source selection configuration +#define CLK_SRC_XTAL 1 +#define CLK_SRC_PLL 2 +NXP_SYS_CLK_SRC_SEL=0x02 + +############################################################################### +# System clock frequency selection configuration +#define CLK_FREQ_13MHZ 1 +#define CLK_FREQ_19_2MHZ 2 +#define CLK_FREQ_24MHZ 3 +#define CLK_FREQ_26MHZ 4 +#define CLK_FREQ_32MHZ 5 +#define CLK_FREQ_38_4MHZ 6 +#define CLK_FREQ_52MHZ 7 +NXP_SYS_CLK_FREQ_SEL=0x02 + +############################################################################### +# The timeout value to be used for clock request acknowledgment +# min value = 0x01 to max = 0x06 +NXP_SYS_CLOCK_TO_CFG=0x06 + +############################################################################### +# NXP proprietary settings +NXP_ACT_PROP_EXTN={2F, 02, 00} + +############################################################################### +# NFC forum profile settings +NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} + +############################################################################### +# NFCC Configuration Control +# Allow NFCC to manage RF Config 0x01 +# Don't allow NFCC to manage RF Config 0x00 +NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01} + +############################################################################### +# Standby enable settings +#NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### +# NXP TVDD configurations settings +# Allow NFCC to configure External TVDD, There are currently three +#configurations (1, 2 and 3) are supported, out of them only one can be +#supported. +NXP_EXT_TVDD_CFG=0x01 + +################################################################################ +#config1:SLALM, 3.3V for both RM and CM +NXP_EXT_TVDD_CFG_1={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 02, 09, 00} + +################################################################################ +#config2: use DCDC in CE, use Tx_Pwr_Req, set CFG2 mode, SLALM, +#monitoring 5V from DCDC, 4.7V for both RM and CM, DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_2={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 56, 64, 0A} + +################################################################################ +#config3: use DCDC in CE, use Tx_Pwr_Req, SLALM, monitoring 5V from DCDC, +#DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_3={20, 02, 0B, 02, A0, 66, 01, 01, A0, 0E, 03, 52, 64, 0A} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +## Set configuration optimization decision setting +## Enable = 0x01 +## Disable = 0x00 +NXP_SET_CONFIG_ALWAYS=0x01 + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +NXP_CORE_CONF_EXTN={20, 02, 19, 06, + A0, EC, 01, 01, + A0, ED, 01, 00, + A0, 5E, 01, 01, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, 96, 01, 01 + } +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration rf field filter settings to enable set to 01 to disable set to 00 last bit +NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01 + } + +############################################################################### +# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set to 0x00 +NXP_I2C_FRAGMENTATION_ENABLED=0x00 + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### +# Mifare Classic Key settings +#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, +# A0, 52, 06, D3, F7, D3, F7, D3, F7, +# A0, 53, 06, FF, FF, FF, FF, FF, FF, +# A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 +NXP_DEFAULT_SE=0x03 + +############################################################################### +#Enable SWP full power mode when phone is power off +NXP_SWP_FULL_PWR_ON=0x00 + +############################################################################### +#### Select the CHIP #### +#PN547C2 0x01 +#PN65T 0x02 +#PN548AD 0x03 +#PN66T 0x04 +NXP_NFC_CHIP=0x03 + +############################################################################### +# CE when Screen state is locked +# This setting is for DEFAULT_AID_ROUTE, +# DEFAULT_DESFIRE_ROUTE and DEFAULT_MIFARE_CLT_ROUTE +# Disable 0x00 +# Enable 0x01 +NXP_CE_ROUTE_STRICT_DISABLE=0x01 + +############################################################################### +#Timeout in secs to get NFCEE Discover notification +NXP_DEFAULT_NFCEE_DISC_TIMEOUT=20 + +############################################################################### +NXP_DEFAULT_NFCEE_TIMEOUT=20 + +############################################################################### +#Timeout in secs +NXP_SWP_RD_START_TIMEOUT=0x0A + +############################################################################### +#Timeout in secs +NXP_SWP_RD_TAG_OP_TIMEOUT=0x01 + +############################################################################### +#Set the default AID route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_AID_ROUTE=0x00 + +############################################################################### +#Set the Mifare Desfire route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_DESFIRE_ROUTE=0x02 + +############################################################################### +#Set the Mifare CLT route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_MIFARE_CLT_ROUTE=0x02 + +############################################################################### +#Set the default AID Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_AID_PWR_STATE=0x19 + +############################################################################### +#Set the Mifare Desfire Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_DESFIRE_PWR_STATE=0x1B + +############################################################################### +#Set the Mifare CLT Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_MIFARE_CLT_PWR_STATE=0x1B + +############################################################################### +# AID Matching platform options +# AID_MATCHING_L 0x01 +# AID_MATCHING_K 0x02 +AID_MATCHING_PLATFORM=0x01 + +############################################################################### +#CHINA_TIANJIN_RF_SETTING +#Enable 0x01 +#Disable 0x00 +NXP_CHINA_TIANJIN_RF_ENABLED=0x01 + +############################################################################### +#SWP_SWITCH_TIMEOUT_SETTING +# Allowed range of swp timeout setting is 0x00 to 0x3C [0 - 60]. +# Timeout in milliseconds, for example +# No Timeout 0x00 +# 10 millisecond timeout 0x0A +NXP_SWP_SWITCH_TIMEOUT=0x0A + +############################################################################### +#Dynamic RSSI feature enable +# Disable 0x00 +# Enable 0x01 +NXP_AGC_DEBUG_ENABLE=0x00 + +############################################################################### +# UICC mode supported +# Disable 0x00 +# Enable 0x01 +NXP_DUAL_UICC_ENABLE=0x00 + +############################################################################### +#Config to allow adding aids +#NFC on/off is required after this config +#1 = enabling adding aid to NFCC routing table. +#0 = disabling adding aid to NFCC routing table. +NXP_ENABLE_ADD_AID=0x01 + +############################################################################### +# Enable/Disable checking default proto SE Id +# Disable 0x00 +# Enable 0x01 +NXP_CHECK_DEFAULT_PROTO_SE_ID=0x01 + +############################################################################### diff --git a/halimpl/libnfc-nxp-PN551_example.conf b/halimpl/libnfc-nxp-PN551_example.conf new file mode 100644 index 0000000..990824f --- /dev/null +++ b/halimpl/libnfc-nxp-PN551_example.conf @@ -0,0 +1,344 @@ +## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn551) +## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn551) +############################################################################### +# Application options +# Logging Levels +# NXPLOG_DEFAULT_LOGLEVEL 0x01 +# ANDROID_LOG_DEBUG 0x03 +# ANDROID_LOG_WARN 0x02 +# ANDROID_LOG_ERROR 0x01 +# ANDROID_LOG_SILENT 0x00 +NXPLOG_EXTNS_LOGLEVEL=0x03 +NXPLOG_NCIHAL_LOGLEVEL=0x03 +NXPLOG_NCIX_LOGLEVEL=0x03 +NXPLOG_NCIR_LOGLEVEL=0x03 +NXPLOG_FWDNLD_LOGLEVEL=0x03 +NXPLOG_TML_LOGLEVEL=0x03 + +############################################################################### +# Nfc Device Node name +NXP_NFC_DEV_NODE="/dev/nq-nci" + +############################################################################### +# Extension for Mifare reader enable +MIFARE_READER_ENABLE=0x01 + +############################################################################### +# Vzw Feature enable +VZW_FEATURE_ENABLE=0x01 + +############################################################################### +# File name for Firmware +NXP_FW_NAME="libpn551_fw.so" + +############################################################################### +# System clock source selection configuration +#define CLK_SRC_XTAL 1 +#define CLK_SRC_PLL 2 +NXP_SYS_CLK_SRC_SEL=0x01 + +############################################################################### +# System clock frequency selection configuration +#define CLK_FREQ_13MHZ 1 +#define CLK_FREQ_19_2MHZ 2 +#define CLK_FREQ_24MHZ 3 +#define CLK_FREQ_26MHZ 4 +#define CLK_FREQ_32MHZ 5 +#define CLK_FREQ_38_4MHZ 6 +#define CLK_FREQ_52MHZ 7 +NXP_SYS_CLK_FREQ_SEL=0x01 + +############################################################################### +# The timeout value to be used for clock request acknowledgment +# min value = 0x01 to max = 0x06 +NXP_SYS_CLOCK_TO_CFG=0x06 + +############################################################################### +# NXP proprietary settings +NXP_ACT_PROP_EXTN={2F, 02, 00} + +############################################################################### +# NFC forum profile settings +NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} + +############################################################################### +# NFCC Configuration Control +# Allow NFCC to manage RF Config 0x01 +# Don't allow NFCC to manage RF Config 0x00 +NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01} + +############################################################################### +# Standby enable settings +#NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### +# NXP TVDD configurations settings +# Allow NFCC to configure External TVDD, There are currently three +#configurations (1, 2 and 3) are supported, out of them only one can be +#supported. +NXP_EXT_TVDD_CFG=0x01 + +############################################################################### +#config1:SLALM, 3.3V for both RM and CM +NXP_EXT_TVDD_CFG_1={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 02, 09, 00} + +############################################################################### +#config2: use DCDC in CE, use Tx_Pwr_Req, set CFG2 mode, SLALM, +#monitoring 5V from DCDC, 3.3V for both RM and CM, DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_2={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 56, 24, 08 } + +############################################################################### +#config3: use DCDC in CE, use Tx_Pwr_Req, SLALM, monitoring 5V from DCDC, +#DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_3={20, 02, 0B, 02, A0, 66, 01, 01, A0, 0E, 03, 52, 40, 0A} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +## Set configuration optimization decision setting +## Enable = 0x01 +## Disable = 0x00 +NXP_SET_CONFIG_ALWAYS=0x00 + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +NXP_CORE_CONF_EXTN={20, 02, 19, 06, + A0, EC, 01, 01, + A0, ED, 01, 00, + A0, 5E, 01, 01, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, 96, 01, 01 + } +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration rf field filter settings to enable set to 01 to disable set to 00 last bit +NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01 } + +############################################################################### +# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set to 0x00 +NXP_I2C_FRAGMENTATION_ENABLED=0x00 + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### +# Mifare Classic Key settings +#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, +# A0, 52, 06, D3, F7, D3, F7, D3, F7, +# A0, 53, 06, FF, FF, FF, FF, FF, FF, +# A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 +NXP_DEFAULT_SE=0x03 + +############################################################################### +#Enable SWP full power mode when phone is power off +NXP_SWP_FULL_PWR_ON=0x00 + +############################################################################### +#### Select the CHIP #### +#PN547C2 0x01 +#PN65T 0x02 +#PN548AD 0x03 +#PN66T 0x04 +#PN551 0x05 +#PN67T 0x06 +NXP_NFC_CHIP=0x05 + +############################################################################### +# CE when Screen state is locked +# This setting is for DEFAULT_AID_ROUTE, +# DEFAULT_DESFIRE_ROUTE and DEFAULT_MIFARE_CLT_ROUTE +# Disable 0x00 +# Enable 0x01 +NXP_CE_ROUTE_STRICT_DISABLE=0x01 + +############################################################################### +#Timeout in secs to get NFCEE Discover notification +NXP_DEFAULT_NFCEE_DISC_TIMEOUT=20 + +############################################################################### +NXP_DEFAULT_NFCEE_TIMEOUT=20 + +############################################################################### +#Timeout in secs +NXP_SWP_RD_START_TIMEOUT=0x0A + +############################################################################### +#Timeout in secs +NXP_SWP_RD_TAG_OP_TIMEOUT=0x01 + +############################################################################### +#Set the default AID route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_AID_ROUTE=0x00 + +############################################################################### +#Set the Mifare Desfire route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_DESFIRE_ROUTE=0x02 + +############################################################################### +#Set the Mifare CLT route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_MIFARE_CLT_ROUTE=0x02 + +############################################################################### +#Set the default AID Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_AID_PWR_STATE=0x19 + +############################################################################### +#Set the Mifare Desfire Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_DESFIRE_PWR_STATE=0x1B + +############################################################################### +#Set the Mifare CLT Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_MIFARE_CLT_PWR_STATE=0x1B + +############################################################################### +# AID Matching platform options +# AID_MATCHING_L 0x01 +# AID_MATCHING_K 0x02 +AID_MATCHING_PLATFORM=0x01 + +############################################################################### +#CHINA_TIANJIN_RF_SETTING +#Enable 0x01 +#Disable 0x00 +NXP_CHINA_TIANJIN_RF_ENABLED=0x01 + +############################################################################### +#SWP_SWITCH_TIMEOUT_SETTING +# Allowed range of swp timeout setting is 0x00 to 0x3C [0 - 60]. +# Timeout in milliseconds, for example +# No Timeout 0x00 +# 10 millisecond timeout 0x0A +NXP_SWP_SWITCH_TIMEOUT=0x0A + +############################################################################### +#Dynamic RSSI feature enable +# Disable 0x00 +# Enable 0x01 +NXP_AGC_DEBUG_ENABLE=0x00 + +############################################################################### +# UICC mode supported +# Disable 0x00 +# Enable 0x01 +NXP_DUAL_UICC_ENABLE=0x00 + +############################################################################### +#Config to allow adding aids +#NFC on/off is required after this config +#1 = enabling adding aid to NFCC routing table. +#0 = disabling adding aid to NFCC routing table. +NXP_ENABLE_ADD_AID=0x01 + +############################################################################### +# Enable/Disable checking default proto SE Id +# Disable 0x00 +# Enable 0x01 +NXP_CHECK_DEFAULT_PROTO_SE_ID=0x01 + +############################################################################### +# Restrict routing to first matched rule only. +# Blacklist enable 0x01 +# Blacklist disable 0x00 +NXP_PROP_BLACKLIST_ROUTING=0x00 + +############################################################################### diff --git a/halimpl/libnfc-nxp-PN553_example.conf b/halimpl/libnfc-nxp-PN553_example.conf index 8be520b..b07e5e9 100644 --- a/halimpl/libnfc-nxp-PN553_example.conf +++ b/halimpl/libnfc-nxp-PN553_example.conf @@ -17,7 +17,7 @@ NXPLOG_TML_LOGLEVEL=0x03 ############################################################################### # Nfc Device Node name -NXP_NFC_DEV_NODE="/dev/pn553" +NXP_NFC_DEV_NODE="/dev/nq-nci" ############################################################################### # Extension for Mifare reader enable @@ -62,6 +62,16 @@ NXP_ACT_PROP_EXTN={2F, 02, 00} NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} ############################################################################### +# NFCC Configuration Control +# Allow NFCC to manage RF Config 0x01 +# Don't allow NFCC to manage RF Config 0x00 +NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01} + +############################################################################### +# Standby enable settings +#NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### # NXP TVDD configurations settings # Allow NFCC to configure External TVDD, two configurations (1 and 2) supported, # out of them only one can be configured at a time. @@ -77,12 +87,101 @@ NXP_EXT_TVDD_CFG_1={20, 02, 0F, 01, A0, 0E, 0B, 31, 01, 01, 31, 00, 00, 00, 01, NXP_EXT_TVDD_CFG_2={20, 02, 0F, 01, A0, 0E, 0B, 11, 01, C2, B2, 00, B2, 1E, 1F, 00, D0, 0C} ############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +# DPC deactivated +NXP_RF_CONF_BLK_1={ +20, 02, 5C, 01, A0, 0B, 58, 10, 90, 90, 78, 0F, 4E, 32, 00, 3D, 9F, 00, 00, 3D, +9F, 00, 00, 50, 9F, 00, 00, 59, 9F, 00, 00, 5A, 9F, 00, 00, 64, 9F, 00, 00, 65, +9F, 00, 00, 6E, 9F, 00, 00, 72, 9F, 00, 00, 79, 9F, 00, 00, 7B, 9F, 00, 00, 84, +9F, 00, 00, 86, 9F, 00, 00, 8F, 9F, 00, 00, 91, 9F, 00, 00, 9A, 9F, 00, 00, A1, +9F, 00, 00, A7, 1F, 00, 00, B0, 1F, 00, 00, B9, 1F, 00, 00 +} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +# DLMA Deactivated +NXP_RF_CONF_BLK_2={ +20, 02, D6, 01, A0, 34, D2, 23, 04, 18, 07, 40, 00, 20, 40, 00, BE, 23, 60, 00, +2B, 13, 40, 00, B8, 21, 60, 00, 38, 35, 00, 00, 18, 46, 08, 00, DE, 54, 08, 02, +00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, +00, 00, 08, 02, 00, 00, 48, 01, 00, 00, 08, 03, 00, 00, 08, 01, 00, 00, C8, 02, +00, 00, C8, 00, 00, 00, 88, 02, 00, 00, 48, 02, 00, 00, B8, 00, 00, 00, 68, 00, +00, 00, 18, 00, 00, 00, 08, 02, 00, 00, 00, 00, 00, 00, 00, 00, 07, 00, 20, 40, +00, BE, 23, 60, 00, 2B, 13, 40, 00, B8, 21, 60, 00, 38, 35, 00, 00, 18, 46, 08, +00, DE, 54, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, +02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 48, 01, 00, 00, 08, 03, 00, 00, 08, +01, 00, 00, C8, 02, 00, 00, C8, 00, 00, 00, 88, 02, 00, 00, 48, 02, 00, 00, B8, +00, 00, 00, 68, 00, 00, 00, 18, 00, 00, 00, 08, 02, 00, 00, 00, 00 +} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### # Set configuration optimization decision setting # Enable = 0x01 # Disable = 0x00 NXP_SET_CONFIG_ALWAYS=0x00 ############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +# Clock timeout settings A004 +# eSE (SVDD) PWR REQ settings A0F2 +# How eSE connected to PN553 A012 +# UICC2 bit rate A0D1 +# SWP1A interface A0D4 +# DWP intf behavior config, SVDD Load activated by default if set to 0x31 - A037 +NXP_CORE_CONF_EXTN={20, 02, 25, 09, + A0, EC, 01, 01, + A0, ED, 01, 01, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, D1, 01, 02, + A0, D4, 01, 01, + A0, 37, 01, 35 + } +# A0, F2, 01, 01, +# A0, 40, 01, 01, +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### # Core configuration rf field filter settings to enable set to 01 to disable set # to 00 last bit NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 00 } @@ -93,12 +192,41 @@ NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 00 } NXP_I2C_FRAGMENTATION_ENABLED=0x00 ############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### # Mifare Classic Key settings #NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, # A0, 52, 06, D3, F7, D3, F7, D3, F7, # A0, 53, 06, FF, FF, FF, FF, FF, FF, # A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 +# UICC2 0x04 + +NXP_DEFAULT_SE=0x07 + ############################################################################### #Enable SWP full power mode when phone is power off NXP_SWP_FULL_PWR_ON=0x00 @@ -229,7 +357,7 @@ DEFAULT_TECH_ABF_PWR_STATE=0x1B # bit pos 2 = Battery Off # bit pos 3 = Screen Off # bit pos 4 = Screen Lock -DEFAULT_SYS_CODE_PWR_STATE=0x00 +DEFAULT_SYS_CODE_PWR_STATE=0x1B ############################################################################### # Configure the NFC Extras to open and use a static pipe. If the value is diff --git a/halimpl/libnfc-nxp-PN557_example.conf b/halimpl/libnfc-nxp-PN557_example.conf index 31d09b9..1319612 100644 --- a/halimpl/libnfc-nxp-PN557_example.conf +++ b/halimpl/libnfc-nxp-PN557_example.conf @@ -61,6 +61,16 @@ NXP_ACT_PROP_EXTN={2F, 02, 00} NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} ############################################################################### +# NFCC Configuration Control +# Allow NFCC to manage RF Config 0x01 +# Don't allow NFCC to manage RF Config 0x00 +NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01} + +############################################################################### +# Standby enable settings +#NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### # NXP TVDD configurations settings # Allow NFCC to configure External TVDD, two configurations (1 and 2) supported, # out of them only one can be configured at a time. @@ -74,6 +84,43 @@ NXP_EXT_TVDD_CFG_1={20, 02, 0F, 01, A0, 0E, 0B, 31, 01, 01, 31, 00, 00, 00, 01, #config2: use DCDC in CE, use Tx_Pwr_Req, set CFG2 mode, SLALM, #monitoring 5V from DCDC, 3.3V for both RM and CM, DCDCWaitTime=4.2ms NXP_EXT_TVDD_CFG_2={20, 02, 0F, 01, A0, 0E, 0B, 11, 01, C2, B2, 00, B2, 1E, 1F, 00, D0, 0C} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + ############################################################################### # Set configuration optimization decision setting # Enable = 0x01 @@ -81,6 +128,41 @@ NXP_EXT_TVDD_CFG_2={20, 02, 0F, 01, A0, 0E, 0B, 11, 01, C2, B2, 00, B2, 1E, 1F, NXP_SET_CONFIG_ALWAYS=0x01 ############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +# Clock timeout settings A004 +# eSE (SVDD) PWR REQ settings A0F2 +# How eSE connected to PN553 A012 +# UICC2 bit rate A0D1 +# SWP1A interface A0D4 +# DWP intf behavior config, SVDD Load activated by default if set to 0x31 - A037 +NXP_CORE_CONF_EXTN={20, 02, 25, 09, + A0, EC, 01, 01, + A0, ED, 01, 00, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, D1, 01, 02, + A0, D4, 01, 01, + A0, 37, 01, 35 + } +# A0, F2, 01, 01, +# A0, 40, 01, 01, +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### # Core configuration rf field filter settings to enable set to 01 to disable set # to 00 last bit NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 00 } @@ -91,12 +173,43 @@ NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 00 } NXP_I2C_FRAGMENTATION_ENABLED=0x00 ############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 34, 10, + 85, 01, 01, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01, + 68, 01, 00 + } + +############################################################################### # Mifare Classic Key settings #NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, # A0, 52, 06, D3, F7, D3, F7, D3, F7, # A0, 53, 06, FF, FF, FF, FF, FF, FF, # A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 +# UICC2 0x04 + +NXP_DEFAULT_SE=0x07 + ############################################################################### #Enable SWP full power mode when phone is power off NXP_SWP_FULL_PWR_ON=0x00 @@ -234,9 +347,10 @@ DEFAULT_TECH_ABF_PWR_STATE=0x3B # bit pos 3 = Switched On Sub-State 1 : Screen is off and device is unlocked # bit pos 4 = Switched On Sub-State 2 : Screen is on and device is locked # bit pos 5 = Switched On Sub-State 3 : Screen is off and device is locked -DEFAULT_SYS_CODE_PWR_STATE=0x00 +DEFAULT_SYS_CODE_PWR_STATE=0x3B ############################################################################### +############################################################################### # Configure the NFC Extras to open and use a static pipe. If the value is # not set or set to 0, then the default is use a dynamic pipe based on a # destination gate (see NFA_HCI_DEFAULT_DEST_GATE). Note there is a value @@ -256,6 +370,18 @@ NFA_POLL_BAIL_OUT_MODE=0x01 AID_MATCHING_PLATFORM=0x01 ############################################################################### +# P61 interface options +# NFC 0x01 +# SPI 0x02 +NXP_P61_LS_DEFAULT_INTERFACE=0x01 + +############################################################################### +# P61 LTSM interface options +# NFC 0x01 +# SPI 0x02 +NXP_P61_LTSM_DEFAULT_INTERFACE=0x01 + +############################################################################### #CHINA_TIANJIN_RF_SETTING #Enable 0x01 #Disable 0x00 @@ -270,6 +396,27 @@ NXP_CHINA_TIANJIN_RF_ENABLED=0x01 NXP_SWP_SWITCH_TIMEOUT=0x0A ############################################################################### +# P61 interface options for JCOP Download +# NFC 0x01 +# SPI 0x02 +NXP_P61_JCOP_DEFAULT_INTERFACE=0x01 + +############################################################################### +# P61 JCOP OS download options +# FRAMEWORK API BY APPLICATION 0x00 +# AT BOOT_TIME 0x01 +NXP_JCOPDL_AT_BOOT_ENABLE=0x00 + +############################################################################### +# Loader service version +# NFC service checks for LS version 2.0 or 2.1 +# LS2.0 0x20 +# LS2.1 0x21 +# LS2.2 0x22 +# AT NFC service intialization +NXP_LOADER_SERVICE_VERSION=0x22 + +############################################################################### #Timeout value in milliseconds for NFCC standby mode.The range is between 5000 #msec to 20000 msec and zero is to disable. NXP_NFCC_STANDBY_TIMEOUT=20000 @@ -281,6 +428,29 @@ NXP_NFCC_STANDBY_TIMEOUT=20000 NXP_AGC_DEBUG_ENABLE=0x00 ############################################################################### +#Virtual Mode ESE and Wired Mode ongoing delay Wired Mode +# For Technology routing to ESE Technology Mask = 4 +# For ISO-DEP Protocol routing to ESE Mask = 2 +# It can also take TECH|PROTO = 6 +# To ignore the delay set mask to = 0 +NXP_ESE_WIRED_PRT_MASK=0x00 + +############################################################################### +#Virtual Mode UICC and Wired Mode ongoing delay Wired Mode +#For Technology routing to UICC Technology Mask = 4 +#For ISO-DEP Protocol routing to UICC set Mask = 2 +#For Select AID Routing to UICC set Mask = 1 +#It can also take values TECH|PROTO|SELECT_AID = 7 , 6 , 5 ,3 .To ignore delay +#set mask = 0 +NXP_UICC_WIRED_PRT_MASK=0x00 + +############################################################################### +#RF field true delay Wired Mode +# delay wired mode = 1 +# allow wired mode = 0 +NXP_WIRED_MODE_RF_FIELD_ENABLE=0x00 + +############################################################################### #Config to allow adding aids #NFC on/off is required after this config #1 = enabling adding aid to NFCC routing table. @@ -288,6 +458,11 @@ NXP_AGC_DEBUG_ENABLE=0x00 NXP_ENABLE_ADD_AID=0x01 ############################################################################### +# JCOP-3.3 continuous process timeout in msec and value should be in Hexadecimal +# JCOP CP TIMEOUT +NXP_CP_TIMEOUT={00, 77} + +############################################################################### # Enable/Disable checking default proto SE Id # Disable 0x00 # Enable 0x01 diff --git a/halimpl/libnfc-nxp-PN65T_example.conf b/halimpl/libnfc-nxp-PN65T_example.conf new file mode 100644 index 0000000..3a9a807 --- /dev/null +++ b/halimpl/libnfc-nxp-PN65T_example.conf @@ -0,0 +1,313 @@ +## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn547) +## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn547) +############################################################################### +# Application options +# Logging Levels +# NXPLOG_DEFAULT_LOGLEVEL 0x01 +# ANDROID_LOG_DEBUG 0x03 +# ANDROID_LOG_WARN 0x02 +# ANDROID_LOG_ERROR 0x01 +# ANDROID_LOG_SILENT 0x00 +NXPLOG_EXTNS_LOGLEVEL=0x03 +NXPLOG_NCIHAL_LOGLEVEL=0x03 +NXPLOG_NCIX_LOGLEVEL=0x03 +NXPLOG_NCIR_LOGLEVEL=0x03 +NXPLOG_FWDNLD_LOGLEVEL=0x03 +NXPLOG_TML_LOGLEVEL=0x03 + +############################################################################### +# Nfc Device Node name +NXP_NFC_DEV_NODE="/dev/nq-nci" + +############################################################################### +# Extension for Mifare reader enable +MIFARE_READER_ENABLE=0x01 + +############################################################################### +# Vzw Feature enable +VZW_FEATURE_ENABLE=0x01 + +############################################################################### +# File name for Firmware +NXP_FW_NAME="libpn547_fw.so" + +############################################################################### +# System clock source selection configuration +#define CLK_SRC_XTAL 1 +#define CLK_SRC_PLL 2 +NXP_SYS_CLK_SRC_SEL=0x01 + +############################################################################### +# System clock frequency selection configuration +#define CLK_FREQ_13MHZ 1 +#define CLK_FREQ_19_2MHZ 2 +#define CLK_FREQ_24MHZ 3 +#define CLK_FREQ_26MHZ 4 +#define CLK_FREQ_32MHZ 5 +#define CLK_FREQ_38_4MHZ 6 +#define CLK_FREQ_52MHZ 7 +NXP_SYS_CLK_FREQ_SEL=0x00 + +############################################################################### +# The timeout value to be used for clock request acknowledgment +# min value = 0x01 to max = 0x06 +NXP_SYS_CLOCK_TO_CFG=0x01 + +############################################################################### +# NXP proprietary settings +NXP_ACT_PROP_EXTN={2F, 02, 00} + +############################################################################### +# NFC forum profile settings +NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} + +############################################################################### +# Standby enable settings +#NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### +#Atonomous Mode +#Enable 0x01 +#Disable 0x00 +NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE=0x00 + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +# NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +## Set configuration optimization decision setting +## Enable = 0x01 +## Disable = 0x00 +NXP_SET_CONFIG_ALWAYS=0x01 + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +NXP_CORE_CONF_EXTN={20, 02, 1A, 05, + A0, EC, 01, 01, + A0, ED, 01, 01, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 0D, 06, 3E, 2D, 15, 88, 15, 00 + } +# A0, 40, 01, 01, +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration rf field filter settings to enable set to 01 to disable set +# to 00 last bit +NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01 + } +############################################################################### +# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set +# to 0x00 +NXP_I2C_FRAGMENTATION_ENABLED=0x00 + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2B, 0D, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 60, 01, 0E, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### +# Mifare Classic Key settings +#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, +# A0, 52, 06, D3, F7, D3, F7, D3, F7, +# A0, 53, 06, FF, FF, FF, FF, FF, FF, +# A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 +NXP_DEFAULT_SE=0x02 + +############################################################################### +NXP_DEFAULT_NFCEE_TIMEOUT=20 + +############################################################################### +#Enable SWP full power mode when phone is power off +NXP_SWP_FULL_PWR_ON=0x01 + +############################################################################### +#Set the default AID route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_AID_ROUTE=0x00 + +############################################################################### +#Set the Mifare Desfire route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_DESFIRE_ROUTE=0x02 + +############################################################################### +#Set the Mifare CLT route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_MIFARE_CLT_ROUTE=0x02 + +############################################################################## +#### Select the CHIP #### +#PN547C2 0x01 +#PN65T 0x02 +#PN548AD 0x03 +#PN66T 0x04 +NXP_NFC_CHIP=0x02 + +############################################################################### +#Timeout in secs +NXP_SWP_RD_START_TIMEOUT=0x0A + +############################################################################### +#Timeout in secs +NXP_SWP_RD_TAG_OP_TIMEOUT=0x01 + +############################################################################### +# CE when Screen state is locked +# This setting is for DEFAULT_AID_ROUTE, +# DEFAULT_DESFIRE_ROUTE and DEFAULT_MIFARE_CLT_ROUTE +# Disable 0x00 +# Enable 0x01 +NXP_CE_ROUTE_STRICT_DISABLE=0x01 + +############################################################################### +# AID Matching platform options +# AID_MATCHING_L 0x01 +# AID_MATCHING_K 0x02 +AID_MATCHING_PLATFORM=0x01 + +############################################################################### +# P61 interface options +# NFC 0x01 +# SPI 0x02 +NXP_P61_LS_DEFAULT_INTERFACE=0x01 + +############################################################################### +# P61 LTSM interface options +# NFC 0x01 +# SPI 0x02 +NXP_P61_LTSM_DEFAULT_INTERFACE=0x01 + +############################################################################### +#CHINA_TIANJIN_RF_SETTING +#Enable 0x01 +#Disable 0x00 +NXP_CHINA_TIANJIN_RF_ENABLED=0x01 + +############################################################################### +#SWP_SWITCH_TIMEOUT_SETTING +# Allowed range of swp timeout setting is 0x00 to 0x3C [0 - 60]. +# Timeout in milliseconds, for example +# No Timeout 0x00 +# 10 millisecond timeout 0x0A +NXP_SWP_SWITCH_TIMEOUT=0x0A + +############################################################################### +# P61 interface options for JCOP Download +# NFC 0x01 +# SPI 0x02 +NXP_P61_JCOP_DEFAULT_INTERFACE=0x01 + +############################################################################### +# P61 JCOP OS download options +# FRAMEWORK API BY APPLICATION 0x00 +# AT BOOT_TIME 0x01 +NXP_JCOPDL_AT_BOOT_ENABLE=0x00 + +############################################################################### +# Loader service version +# NFC service checks for LS version 2.0 or 2.1 +# LS2.0 0x20 +# LS2.1 0x21 +# LS2.2 0x22 +# AT NFC service intialization +NXP_LOADER_SERVICE_VERSION=0x21 + +################################################################################ +#Used to Restrict Type A UICC baud rate +#0 = default supported +#1 = 212 maximum supported +#2 = 424 maximum supported +#3 = 848 maximum supported +NXP_TYPEA_UICC_BAUD_RATE=0x00 + +################################################################################ +#Used to Restrict Type B UICC baud rate +#0 = default supported +#1 = 212 maximum supported +#2 = 424 maximum supported +#3 = 848 maximum supported +NXP_TYPEB_UICC_BAUD_RATE=0x00 + +############################################################################### +#Config to allow adding aids +#NFC on/off is required after this config +#1 = enabling adding aid to NFCC routing table. +#0 = disabling adding aid to NFCC routing table. +NXP_ENABLE_ADD_AID=0x01 + +############################################################################### diff --git a/halimpl/libnfc-nxp-PN66T_example.conf b/halimpl/libnfc-nxp-PN66T_example.conf new file mode 100644 index 0000000..1af8100 --- /dev/null +++ b/halimpl/libnfc-nxp-PN66T_example.conf @@ -0,0 +1,423 @@ +## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn547) +## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn547) +############################################################################### +# Application options +# Logging Levels +# NXPLOG_DEFAULT_LOGLEVEL 0x01 +# ANDROID_LOG_DEBUG 0x03 +# ANDROID_LOG_WARN 0x02 +# ANDROID_LOG_ERROR 0x01 +# ANDROID_LOG_SILENT 0x00 +NXPLOG_EXTNS_LOGLEVEL=0x03 +NXPLOG_NCIHAL_LOGLEVEL=0x03 +NXPLOG_NCIX_LOGLEVEL=0x03 +NXPLOG_NCIR_LOGLEVEL=0x03 +NXPLOG_FWDNLD_LOGLEVEL=0x03 +NXPLOG_TML_LOGLEVEL=0x03 + +############################################################################### +# Nfc Device Node name +NXP_NFC_DEV_NODE="/dev/nq-nci" + +############################################################################### +# Extension for Mifare reader enable +MIFARE_READER_ENABLE=0x01 + +############################################################################### +# Vzw Feature enable +VZW_FEATURE_ENABLE=0x01 + +############################################################################### +# File name for Firmware +NXP_FW_NAME="libpn548ad_fw.so" + +############################################################################### +# System clock source selection configuration +#define CLK_SRC_XTAL 1 +#define CLK_SRC_PLL 2 +NXP_SYS_CLK_SRC_SEL=0x02 + +############################################################################### +# System clock frequency selection configuration +#define CLK_FREQ_13MHZ 1 +#define CLK_FREQ_19_2MHZ 2 +#define CLK_FREQ_24MHZ 3 +#define CLK_FREQ_26MHZ 4 +#define CLK_FREQ_32MHZ 5 +#define CLK_FREQ_38_4MHZ 6 +#define CLK_FREQ_52MHZ 7 +NXP_SYS_CLK_FREQ_SEL=0x02 + +############################################################################### +# The timeout value to be used for clock request acknowledgment +# min value = 0x01 to max = 0x06 +NXP_SYS_CLOCK_TO_CFG=0x06 + +############################################################################### +# NXP proprietary settings +NXP_ACT_PROP_EXTN={2F, 02, 00} + +############################################################################### +# NFC forum profile settings +NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} + +############################################################################### +# NFCC Configuration Control +# Allow NFCC to manage RF Config 0x01 +# Don't allow NFCC to manage RF Config 0x00 +NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01} + +############################################################################### +# Standby enable settings +# NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### +# NXP TVDD configurations settings +# Allow NFCC to configure External TVDD, There are currently three +#configurations (1, 2 and 3) are supported, out of them only one can be +#supported. +NXP_EXT_TVDD_CFG=0x01 + +############################################################################### +#config1:SLALM, 3.3V for both RM and CM +NXP_EXT_TVDD_CFG_1={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 02, 09, 00} + +############################################################################### +#config2: use DCDC in CE, use Tx_Pwr_Req, set CFG2 mode, SLALM, +#monitoring 5V from DCDC, 4.7V for both RM and CM, DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_2={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 56, 64, 0A} + +############################################################################### +#config3: use DCDC in CE, use Tx_Pwr_Req, SLALM, monitoring 5V from DCDC, +#DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_3={20, 02, 0B, 02, A0, 66, 01, 01, A0, 0E, 03, 52, 64, 0A} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Set configuration optimization decision setting +# Enable = 0x01 +# Disable = 0x00 +NXP_SET_CONFIG_ALWAYS=0x01 + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +# Clock timeout settings A004 +# A0 9F 02 <svdd ON guard time (msec)> <svdd off guard time(msec)> +NXP_CORE_CONF_EXTN={20, 02, 26, 09, + A0, EC, 01, 01, + A0, ED, 01, 03, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, F2, 01, 01, + A0, 96, 01, 01, + A0, 9F, 02, 08, 08 + } +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration rf field filter settings to enable set to 01 to disable set +# to 00 last bit +NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01 } + +############################################################################### +# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set +# to 0x00 +NXP_I2C_FRAGMENTATION_ENABLED=0x00 + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### +# Mifare Classic Key settings +#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, +# A0, 52, 06, D3, F7, D3, F7, D3, F7, +# A0, 53, 06, FF, FF, FF, FF, FF, FF, +# A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 +NXP_DEFAULT_SE=0x03 + +############################################################################### +#Enable SWP full power mode when phone is power off +NXP_SWP_FULL_PWR_ON=0x00 + +############################################################################### +#### Select the CHIP #### +#PN547C2 0x01 +#PN65T 0x02 +#PN548AD 0x03 +#PN66T 0x04 +#PN551 0x05 +#PN67T 0x06 +NXP_NFC_CHIP=0x04 + +############################################################################### +# CE when Screen state is locked +# This setting is for DEFAULT_AID_ROUTE, +# DEFAULT_DESFIRE_ROUTE and DEFAULT_MIFARE_CLT_ROUTE +# Disable 0x00 +# Enable 0x01 +NXP_CE_ROUTE_STRICT_DISABLE=0x01 + +############################################################################### +#Timeout in secs to get NFCEE Discover notification +NXP_DEFAULT_NFCEE_DISC_TIMEOUT=20 + +############################################################################### +NXP_DEFAULT_NFCEE_TIMEOUT=20 + +############################################################################### +#Timeout in secs +NXP_SWP_RD_START_TIMEOUT=0x0A + +############################################################################### +#Timeout in secs +NXP_SWP_RD_TAG_OP_TIMEOUT=0x01 + +############################################################################### +#Set the default AID route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_AID_ROUTE=0x00 + +############################################################################### +#Set the Mifare Desfire route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_DESFIRE_ROUTE=0x02 + +############################################################################### +#Set the Mifare CLT route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_MIFARE_CLT_ROUTE=0x02 + +############################################################################### +#Set the default AID Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_AID_PWR_STATE=0x19 + +############################################################################### +#Set the Mifare Desfire Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_DESFIRE_PWR_STATE=0x1B + +############################################################################### +#Set the Mifare CLT Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_MIFARE_CLT_PWR_STATE=0x1B + +############################################################################### +# AID Matching platform options +# AID_MATCHING_L 0x01 +# AID_MATCHING_K 0x02 +AID_MATCHING_PLATFORM=0x01 + +############################################################################### +# P61 interface options +# NFC 0x01 +# SPI 0x02 +NXP_P61_LS_DEFAULT_INTERFACE=0x01 + +############################################################################### +# P61 LTSM interface options +# NFC 0x01 +# SPI 0x02 +NXP_P61_LTSM_DEFAULT_INTERFACE=0x01 + +############################################################################### +#CHINA_TIANJIN_RF_SETTING +#Enable 0x01 +#Disable 0x00 +NXP_CHINA_TIANJIN_RF_ENABLED=0x01 + +############################################################################### +#SWP_SWITCH_TIMEOUT_SETTING +# Allowed range of swp timeout setting is 0x00 to 0x3C [0 - 60]. +# Timeout in milliseconds, for example +# No Timeout 0x00 +# 10 millisecond timeout 0x0A +NXP_SWP_SWITCH_TIMEOUT=0x0A + +############################################################################### +# P61 interface options for JCOP Download +# NFC 0x01 +# SPI 0x02 +NXP_P61_JCOP_DEFAULT_INTERFACE=0x01 + +############################################################################### +# P61 JCOP OS download options +# FRAMEWORK API BY APPLICATION 0x00 +# AT BOOT_TIME 0x01 +NXP_JCOPDL_AT_BOOT_ENABLE=0x00 + +############################################################################### +# Loader service version +# NFC service checks for LS version 2.0 or 2.1 +# LS2.0 0x20 +# LS2.1 0x21 +# LS2.2 0x22 +# AT NFC service intialization +NXP_LOADER_SERVICE_VERSION=0x21 + +############################################################################### +#Timeout value in milliseconds for NFCC standby mode.The range is between 5000 +#msec to 20000 msec and zero is to disable. +NXP_NFCC_STANDBY_TIMEOUT=20000 + +############################################################################### +#Dynamic RSSI feature enable +# Disable 0x00 +# Enable 0x01 +NXP_AGC_DEBUG_ENABLE=0x00 + +############################################################################### +#Virtual Mode ESE and Wired Mode ongoing delay Wired Mode +# For Technology routing to ESE Technology Mask = 4 +# For ISO-DEP Protocol routing to ESE Mask = 2 +# It can also take TECH|PROTO = 6 +# To ignore the delay set mask to = 0 +NXP_ESE_WIRED_PRT_MASK=0x00 + +############################################################################### +#Virtual Mode UICC and Wired Mode ongoing delay Wired Mode +#For Technology routing to UICC Technology Mask = 4 +#For ISO-DEP Protocol routing to UICC set Mask = 2 +#For Select AID Routing to UICC set Mask = 1 +#It can also take values TECH|PROTO|SELECT_AID = 7 , 6 , 5 ,3 .To ignore delay +#set mask = 0 +NXP_UICC_WIRED_PRT_MASK=0x00 + +################################################################################ +#RF field true delay Wired Mode +# delay wired mode = 1 +# allow wired mode = 0 +NXP_WIRED_MODE_RF_FIELD_ENABLE=0x00 + +############################################################################### +#Config to allow adding aids +#NFC on/off is required after this config +#1 = enabling adding aid to NFCC routing table. +#0 = disabling adding aid to NFCC routing table. +NXP_ENABLE_ADD_AID=0x01 + +############################################################################### +# UICC mode supported +# Disable 0x00 +# Enable 0x01 +NXP_DUAL_UICC_ENABLE=0x00 + +############################################################################### +# JCOP-3.3 continuous process timeout in msec and value should be in Hexadecimal +# JCOP CP TIMEOUT +# NXP_CP_TIMEOUT={00, 77} + +############################################################################### +# Enable/Disable checking default proto SE Id +# Disable 0x00 +# Enable 0x01 +NXP_CHECK_DEFAULT_PROTO_SE_ID=0x01 + +############################################################################### +# SVDD sync off Delay in ms it can be max 20 ms +# If out of range timeout used, default delay of 10ms will be set +NXP_SVDD_SYNC_OFF_DELAY=10 + +############################################################################### +#NXP_CN_TRANSIT_BLK_NUM_CHECK_ENABLE +#Enable/Disable block number checks for china transit use case +#Enable 0x01 +#Disable 0x00 +NXP_CN_TRANSIT_BLK_NUM_CHECK_ENABLE=0x01 + +############################################################################### diff --git a/halimpl/libnfc-nxp-PN67T_example.conf b/halimpl/libnfc-nxp-PN67T_example.conf new file mode 100644 index 0000000..25f7a5f --- /dev/null +++ b/halimpl/libnfc-nxp-PN67T_example.conf @@ -0,0 +1,434 @@ +## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn547) +## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn547) +############################################################################### +# Application options +# Logging Levels +# NXPLOG_DEFAULT_LOGLEVEL 0x01 +# ANDROID_LOG_DEBUG 0x03 +# ANDROID_LOG_WARN 0x02 +# ANDROID_LOG_ERROR 0x01 +# ANDROID_LOG_SILENT 0x00 +NXPLOG_EXTNS_LOGLEVEL=0x03 +NXPLOG_NCIHAL_LOGLEVEL=0x03 +NXPLOG_NCIX_LOGLEVEL=0x03 +NXPLOG_NCIR_LOGLEVEL=0x03 +NXPLOG_FWDNLD_LOGLEVEL=0x03 +NXPLOG_TML_LOGLEVEL=0x03 + +############################################################################### +# Nfc Device Node name +NXP_NFC_DEV_NODE="/dev/nq-nci" + +############################################################################### +# Extension for Mifare reader enable +MIFARE_READER_ENABLE=0x01 + +############################################################################### +# Vzw Feature enable +VZW_FEATURE_ENABLE=0x01 + +############################################################################### +# File name for Firmware +NXP_FW_NAME="libpn551_fw.so" + +############################################################################### +# System clock source selection configuration +#define CLK_SRC_XTAL 1 +#define CLK_SRC_PLL 2 +NXP_SYS_CLK_SRC_SEL=0x02 + +############################################################################### +# System clock frequency selection configuration +#define CLK_FREQ_13MHZ 1 +#define CLK_FREQ_19_2MHZ 2 +#define CLK_FREQ_24MHZ 3 +#define CLK_FREQ_26MHZ 4 +#define CLK_FREQ_32MHZ 5 +#define CLK_FREQ_38_4MHZ 6 +#define CLK_FREQ_52MHZ 7 +NXP_SYS_CLK_FREQ_SEL=0x02 + +############################################################################### +# The timeout value to be used for clock request acknowledgment +# min value = 0x01 to max = 0x06 +NXP_SYS_CLOCK_TO_CFG=0x06 + +############################################################################### +# NXP proprietary settings +NXP_ACT_PROP_EXTN={2F, 02, 00} + +############################################################################### +# NFC forum profile settings +NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} + +############################################################################### +# NFCC Configuration Control +# Allow NFCC to manage RF Config 0x01 +# Don't allow NFCC to manage RF Config 0x00 +NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01} + +############################################################################### +# Standby enable settings +# NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### +# NXP TVDD configurations settings +# Allow NFCC to configure External TVDD, There are currently three +#configurations (1, 2 and 3) are supported, out of them only one can be +#supported. +NXP_EXT_TVDD_CFG=0x01 + +############################################################################### +#config1:SLALM, 3.3V for both RM and CM +NXP_EXT_TVDD_CFG_1={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 02, 09, 00} + +############################################################################### +#config2: use DCDC in CE, use Tx_Pwr_Req, set CFG2 mode, SLALM, +#monitoring 5V from DCDC, 4.7V for both RM and CM, DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_2={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 56, 64, 0A} + +############################################################################### +#config3: use DCDC in CE, use Tx_Pwr_Req, SLALM, monitoring 5V from DCDC, +#DCDCWaitTime=4.2ms +NXP_EXT_TVDD_CFG_3={20, 02, 0B, 02, A0, 66, 01, 01, A0, 0E, 03, 52, 64, 0A} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Set configuration optimization decision setting +# Enable = 0x01 +# Disable = 0x00 +NXP_SET_CONFIG_ALWAYS=0x00 + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +# Clock timeout settings A004 +# A0 9F 02 <svdd ON guard time (msec)> <svdd off guard time(msec)> +NXP_CORE_CONF_EXTN={20, 02, 26, 09, + A0, EC, 01, 01, + A0, ED, 01, 03, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, F2, 01, 01, + A0, 96, 01, 01, + A0, 9F, 02, 08, 08 + } +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration rf field filter settings to enable set to 01 to disable set +# to 00 last bit +NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01 } + +############################################################################### +# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set +# to 0x00 +NXP_I2C_FRAGMENTATION_ENABLED=0x00 + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### +# Mifare Classic Key settings +#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, +# A0, 52, 06, D3, F7, D3, F7, D3, F7, +# A0, 53, 06, FF, FF, FF, FF, FF, FF, +# A0, 54, 06, 00, 00, 00, 00, 00, 00} + +############################################################################### +# Default SE Options +# No secure element 0x00 +# eSE 0x01 +# UICC 0x02 +NXP_DEFAULT_SE=0x03 + +############################################################################### +#Enable SWP full power mode when phone is power off +NXP_SWP_FULL_PWR_ON=0x00 + +############################################################################### +#### Select the CHIP #### +#PN547C2 0x01 +#PN65T 0x02 +#PN548AD 0x03 +#PN66T 0x04 +#PN551 0x05 +#PN67T 0x06 +NXP_NFC_CHIP=0x06 + +############################################################################### +# CE when Screen state is locked +# This setting is for DEFAULT_AID_ROUTE, +# DEFAULT_DESFIRE_ROUTE and DEFAULT_MIFARE_CLT_ROUTE +# Disable 0x00 +# Enable 0x01 +NXP_CE_ROUTE_STRICT_DISABLE=0x01 + +############################################################################### +#Timeout in secs to get NFCEE Discover notification +NXP_DEFAULT_NFCEE_DISC_TIMEOUT=20 + +############################################################################### +NXP_DEFAULT_NFCEE_TIMEOUT=20 + +############################################################################### +#Timeout in secs +NXP_SWP_RD_START_TIMEOUT=0x0A + +############################################################################### +#Timeout in secs +NXP_SWP_RD_TAG_OP_TIMEOUT=0x01 + +############################################################################### +#Set the default AID route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_AID_ROUTE=0x00 + +############################################################################### +#Set the Mifare Desfire route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_DESFIRE_ROUTE=0x02 + +############################################################################### +#Set the Mifare CLT route Location : +#This settings will be used when application does not set this parameter +# host 0x00 +# eSE 0x01 +# UICC 0x02 +DEFAULT_MIFARE_CLT_ROUTE=0x02 + +############################################################################### +#Set the default AID Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_AID_PWR_STATE=0x19 + +############################################################################### +#Set the Mifare Desfire Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_DESFIRE_PWR_STATE=0x1B + +############################################################################### +#Set the Mifare CLT Power state : +#This settings will be used when application does not set this parameter +# bit pos 0 = Switch On +# bit pos 1 = Switch Off +# bit pos 2 = Battery Off +# bit pos 3 = Screen Lock +# bit pos 4 = Screen Off +DEFAULT_MIFARE_CLT_PWR_STATE=0x1B + +############################################################################### +# AID Matching platform options +# AID_MATCHING_L 0x01 +# AID_MATCHING_K 0x02 +AID_MATCHING_PLATFORM=0x01 + +############################################################################### +# P61 interface options +# NFC 0x01 +# SPI 0x02 +NXP_P61_LS_DEFAULT_INTERFACE=0x01 + +############################################################################### +# P61 LTSM interface options +# NFC 0x01 +# SPI 0x02 +NXP_P61_LTSM_DEFAULT_INTERFACE=0x01 + +############################################################################### +#CHINA_TIANJIN_RF_SETTING +#Enable 0x01 +#Disable 0x00 +NXP_CHINA_TIANJIN_RF_ENABLED=0x01 + +############################################################################### +#SWP_SWITCH_TIMEOUT_SETTING +# Allowed range of swp timeout setting is 0x00 to 0x3C [0 - 60]. +# Timeout in milliseconds, for example +# No Timeout 0x00 +# 10 millisecond timeout 0x0A +NXP_SWP_SWITCH_TIMEOUT=0x0A + +############################################################################### +# P61 interface options for JCOP Download +# NFC 0x01 +# SPI 0x02 +NXP_P61_JCOP_DEFAULT_INTERFACE=0x01 + +############################################################################### +# P61 JCOP OS download options +# FRAMEWORK API BY APPLICATION 0x00 +# AT BOOT_TIME 0x01 +NXP_JCOPDL_AT_BOOT_ENABLE=0x00 + +############################################################################### +# Loader service version +# NFC service checks for LS version 2.0 or 2.1 +# LS2.0 0x20 +# LS2.1 0x21 +# LS2.2 0x22 +# AT NFC service intialization +NXP_LOADER_SERVICE_VERSION=0x22 + +############################################################################### +#Timeout value in milliseconds for NFCC standby mode.The range is between 5000 +#msec to 20000 msec and zero is to disable. +NXP_NFCC_STANDBY_TIMEOUT=20000 + +############################################################################### +#Dynamic RSSI feature enable +# Disable 0x00 +# Enable 0x01 +NXP_AGC_DEBUG_ENABLE=0x00 + +############################################################################### +#Virtual Mode ESE and Wired Mode ongoing delay Wired Mode +# For Technology routing to ESE Technology Mask = 4 +# For ISO-DEP Protocol routing to ESE Mask = 2 +# It can also take TECH|PROTO = 6 +# To ignore the delay set mask to = 0 +NXP_ESE_WIRED_PRT_MASK=0x00 + +############################################################################### +#Virtual Mode UICC and Wired Mode ongoing delay Wired Mode +#For Technology routing to UICC Technology Mask = 4 +#For ISO-DEP Protocol routing to UICC set Mask = 2 +#For Select AID Routing to UICC set Mask = 1 +#It can also take values TECH|PROTO|SELECT_AID = 7 , 6 , 5 ,3 .To ignore delay +#set mask = 0 +NXP_UICC_WIRED_PRT_MASK=0x00 + +############################################################################### +#RF field true delay Wired Mode +# delay wired mode = 1 +# allow wired mode = 0 +NXP_WIRED_MODE_RF_FIELD_ENABLE=0x00 + +############################################################################### +#Config to allow adding aids +#NFC on/off is required after this config +#1 = enabling adding aid to NFCC routing table. +#0 = disabling adding aid to NFCC routing table. +NXP_ENABLE_ADD_AID=0x01 + +############################################################################### +# UICC mode supported +# Disable 0x00 +# Enable 0x01 +NXP_DUAL_UICC_ENABLE=0x00 + +############################################################################### +# JCOP-3.3 continuous process timeout in msec and value should be in Hexadecimal +# JCOP CP TIMEOUT +# NXP_CP_TIMEOUT={00, 77} + +############################################################################### +# Enable/Disable checking default proto SE Id +# Disable 0x00 +# Enable 0x01 +NXP_CHECK_DEFAULT_PROTO_SE_ID=0x01 + +############################################################################### +# SVDD sync off Delay in ms it can be max 20 ms +# If out of range timeout used, default delay of 10ms will be set +NXP_SVDD_SYNC_OFF_DELAY=10 + +############################################################################### +#NXP_CN_TRANSIT_BLK_NUM_CHECK_ENABLE +#Enable/Disable block number checks for china transit use case +#Enable 0x01 +#Disable 0x00 +NXP_CN_TRANSIT_BLK_NUM_CHECK_ENABLE=0x01 + +############################################################################### +#Enable Passive Listen Timeout +# Maximum retry three times, Timeout in millisec +NXP_NFCC_PASSIVE_LISTEN_TIMEOUT=5000 + +############################################################################### +# Restrict routing to first matched rule only. +# Blacklist enable 0x01 +# Blacklist disable 0x00 +NXP_PROP_BLACKLIST_ROUTING=0x00 + +############################################################################### diff --git a/halimpl/libnfc-nxp-PN80T_example.conf b/halimpl/libnfc-nxp-PN80T_example.conf index c41a290..725183a 100644 --- a/halimpl/libnfc-nxp-PN80T_example.conf +++ b/halimpl/libnfc-nxp-PN80T_example.conf @@ -18,7 +18,7 @@ NFC_DEBUG_ENABLED=0x01 ############################################################################### # Nfc Device Node name -NXP_NFC_DEV_NODE="/dev/pn553" +NXP_NFC_DEV_NODE="/dev/nq-nci" ############################################################################### # Extension for Mifare reader enable @@ -69,6 +69,16 @@ NXP_ACT_PROP_EXTN={2F, 02, 00} NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00} ############################################################################### +# NFCC Configuration Control +# Allow NFCC to manage RF Config 0x01 +# Don't allow NFCC to manage RF Config 0x00 +NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01} + +############################################################################### +# Standby enable settings +#NXP_CORE_STANDBY={2F, 00, 01, 01} + +############################################################################### # NXP TVDD configurations settings # Allow NFCC to configure External TVDD, two configurations (1 and 2) supported, # out of them only one can be configured at a time. @@ -84,12 +94,104 @@ NXP_EXT_TVDD_CFG_1={20, 02, 0F, 01, A0, 0E, 0B, 31, 01, 01, 31, 00, 00, 00, 01, NXP_EXT_TVDD_CFG_2={20, 02, 0F, 01, A0, 0E, 0B, 11, 01, C2, B2, 00, B2, 1E, 1F, 00, D0, 0C} ############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +# DPC deactivated +NXP_RF_CONF_BLK_1={ +20, 02, 5C, 01, A0, 0B, 58, 10, 90, 90, 78, 0F, 4E, 32, 00, 3D, 9F, 00, 00, 3D, +9F, 00, 00, 50, 9F, 00, 00, 59, 9F, 00, 00, 5A, 9F, 00, 00, 64, 9F, 00, 00, 65, +9F, 00, 00, 6E, 9F, 00, 00, 72, 9F, 00, 00, 79, 9F, 00, 00, 7B, 9F, 00, 00, 84, +9F, 00, 00, 86, 9F, 00, 00, 8F, 9F, 00, 00, 91, 9F, 00, 00, 9A, 9F, 00, 00, A1, +9F, 00, 00, A7, 1F, 00, 00, B0, 1F, 00, 00, B9, 1F, 00, 00 +} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +# DLMA Deactivated +NXP_RF_CONF_BLK_2={ +20, 02, D6, 01, A0, 34, D2, 23, 04, 18, 07, 40, 00, 20, 40, 00, BE, 23, 60, 00, +2B, 13, 40, 00, B8, 21, 60, 00, 38, 35, 00, 00, 18, 46, 08, 00, DE, 54, 08, 02, +00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, +00, 00, 08, 02, 00, 00, 48, 01, 00, 00, 08, 03, 00, 00, 08, 01, 00, 00, C8, 02, +00, 00, C8, 00, 00, 00, 88, 02, 00, 00, 48, 02, 00, 00, B8, 00, 00, 00, 68, 00, +00, 00, 18, 00, 00, 00, 08, 02, 00, 00, 00, 00, 00, 00, 00, 00, 07, 00, 20, 40, +00, BE, 23, 60, 00, 2B, 13, 40, 00, B8, 21, 60, 00, 38, 35, 00, 00, 18, 46, 08, +00, DE, 54, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 08, +02, 00, 00, 08, 02, 00, 00, 08, 02, 00, 00, 48, 01, 00, 00, 08, 03, 00, 00, 08, +01, 00, 00, C8, 02, 00, 00, C8, 00, 00, 00, 88, 02, 00, 00, 48, 02, 00, 00, B8, +00, 00, 00, 68, 00, 00, 00, 18, 00, 00, 00, 08, 02, 00, 00, 00, 00 +} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### # Set configuration optimization decision setting # Enable = 0x01 # Disable = 0x00 NXP_SET_CONFIG_ALWAYS=0x00 ############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +# Clock timeout settings A004 +# eSE (SVDD) PWR REQ settings A0F2 +# Window size A0D8 +# DWP Speed A0D5 +# How eSE connected to PN553 A012 +# UICC2 bit rate A0D1 +# SWP1A interface A0D4 +# DWP intf behavior config, SVDD Load activated by default if set to 0x31 A037 +NXP_CORE_CONF_EXTN={20, 02, 29, 0A, + A0, EC, 01, 01, + A0, ED, 01, 01, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 40, 01, 01, + A0, D1, 01, 02, + A0, D4, 01, 01, + A0, 37, 01, 35, + A0, D8, 01, 02, + A0, D5, 01, 0A + } +# A0, F2, 01, 01, +# A0, 40, 01, 01, +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### # Core configuration rf field filter settings to enable set to 01 to disable set # to 00 last bit NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 00 } @@ -100,6 +202,25 @@ NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 00 } NXP_I2C_FRAGMENTATION_ENABLED=0x00 ############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### # Mifare Classic Key settings #NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, # A0, 52, 06, D3, F7, D3, F7, D3, F7, @@ -159,6 +280,7 @@ NXP_SWP_RD_TAG_OP_TIMEOUT=0x20 # host 0x00 # eSE 0x01 # UICC 0x02 +# UICC2 0x03 DEFAULT_AID_ROUTE=0x00 ############################################################################### @@ -244,7 +366,7 @@ DEFAULT_TECH_ABF_PWR_STATE=0x1B # bit pos 2 = Battery Off # bit pos 3 = Screen Off # bit pos 4 = Screen Lock -DEFAULT_SYS_CODE_PWR_STATE=0x00 +DEFAULT_SYS_CODE_PWR_STATE=0x1B ############################################################################### # Configure the NFC Extras to open and use a static pipe. If the value is @@ -342,6 +464,12 @@ NXP_ENABLE_ADD_AID=0x01 NXP_CP_TIMEOUT={00, 77} ############################################################################### +# Enable/Disable checking default proto SE Id +# Disable 0x00 +# Enable 0x01 +NXP_CHECK_DEFAULT_PROTO_SE_ID=0x01 + +############################################################################### # SVDD sync off Delay in ms it can be max 20 ms # If out of range timeout used, default delay of 10ms will be set NXP_SVDD_SYNC_OFF_DELAY=10 @@ -504,5 +632,3 @@ NXP_PROP_RESET_EMVCO_CMD={20, 02, 05, 01, A0, 44, 01, 00} # 5 -> EMVCO Cert Polling, DISC_IDLE = Removal process , DISC DEACTIVATE = POWER_OFF # 7 -> EMVCO Polling, DISC_IDLE = POWER_OFF, DISC DEACTIVATE = POWER_OFF NFA_CONFIG_FORMAT=1 - -###############################################################################
\ No newline at end of file diff --git a/halimpl/libnfc-nxp_RF-PN547C2_example b/halimpl/libnfc-nxp_RF-PN547C2_example new file mode 100644 index 0000000..df28264 --- /dev/null +++ b/halimpl/libnfc-nxp_RF-PN547C2_example @@ -0,0 +1,78 @@ +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +# NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +NXP_CORE_CONF_EXTN={20, 02, 16, 04, + A0, EC, 01, 01, + A0, ED, 01, 00, + A0, 5E, 01, 01, + A0, 0D, 06, 3E, 2D, 15, 88, 15, 00 + } +# A0, 40, 01, 01, +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2B, 0D, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 60, 01, 0E, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } +############################################################################### + diff --git a/halimpl/libnfc-nxp_RF-PN548C2_example b/halimpl/libnfc-nxp_RF-PN548C2_example new file mode 100644 index 0000000..c65a94c --- /dev/null +++ b/halimpl/libnfc-nxp_RF-PN548C2_example @@ -0,0 +1,80 @@ +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +NXP_CORE_CONF_EXTN={20, 02, 19, 06, + A0, EC, 01, 01, + A0, ED, 01, 00, + A0, 5E, 01, 01, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, 96, 01, 01 + } +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } +############################################################################### + diff --git a/halimpl/libnfc-nxp_RF-PN551_example b/halimpl/libnfc-nxp_RF-PN551_example new file mode 100644 index 0000000..e42920f --- /dev/null +++ b/halimpl/libnfc-nxp_RF-PN551_example @@ -0,0 +1,80 @@ +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +NXP_CORE_CONF_EXTN={20, 02, 19, 06, + A0, EC, 01, 01, + A0, ED, 01, 00, + A0, 5E, 01, 01, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, 96, 01, 01 + } +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } +############################################################################### + diff --git a/halimpl/libnfc-nxp_RF-PN553_example b/halimpl/libnfc-nxp_RF-PN553_example new file mode 100644 index 0000000..724f217 --- /dev/null +++ b/halimpl/libnfc-nxp_RF-PN553_example @@ -0,0 +1,91 @@ +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +# Clock timeout settings A004 +# eSE (SVDD) PWR REQ settings A0F2 +# How eSE connected to PN553 A012 +# UICC2 bit rate A0D1 +# SWP1A interface A0D4 +# DWP intf behavior config, SVDD Load activated by default if set to 0x31 - A037 +NXP_CORE_CONF_EXTN={20, 02, 25, 09, + A0, EC, 01, 01, + A0, ED, 01, 00, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, D1, 01, 02, + A0, D4, 01, 01, + A0, 37, 01, 35 + } +# A0, F2, 01, 01, +# A0, 40, 01, 01, +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } +############################################################################### + diff --git a/halimpl/libnfc-nxp_RF-PN66T_example.conf b/halimpl/libnfc-nxp_RF-PN66T_example.conf new file mode 100644 index 0000000..4697eed --- /dev/null +++ b/halimpl/libnfc-nxp_RF-PN66T_example.conf @@ -0,0 +1,86 @@ +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +# Clock timeout settings A004 +# A0 9F 02 <svdd ON guard time (msec)> <svdd off guard time(msec)> +NXP_CORE_CONF_EXTN={20, 02, 26, 09, + A0, EC, 01, 01, + A0, ED, 01, 03, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, F2, 01, 01, + A0, 96, 01, 01, + A0, 9F, 02, 08, 08 + } +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### + diff --git a/halimpl/libnfc-nxp_RF-PN67T_example.conf b/halimpl/libnfc-nxp_RF-PN67T_example.conf new file mode 100644 index 0000000..4697eed --- /dev/null +++ b/halimpl/libnfc-nxp_RF-PN67T_example.conf @@ -0,0 +1,86 @@ +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_1={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_2={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_3={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_4={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_5={ +#} + +############################################################################### +# NXP RF configuration ALM/PLM settings +# This section needs to be updated with the correct values based on the platform +#NXP_RF_CONF_BLK_6={ +#} + +############################################################################### +# Core configuration extensions +# It includes +# Wired mode settings A0ED, A0EE +# Tag Detector A040, A041, A043 +# Low Power mode A007 +# Clock settings A002, A003 +# PbF settings A008 +# Clock timeout settings A004 +# A0 9F 02 <svdd ON guard time (msec)> <svdd off guard time(msec)> +NXP_CORE_CONF_EXTN={20, 02, 26, 09, + A0, EC, 01, 01, + A0, ED, 01, 03, + A0, 5E, 01, 01, + A0, 12, 01, 02, + A0, 40, 01, 01, + A0, DD, 01, 2D, + A0, F2, 01, 01, + A0, 96, 01, 01, + A0, 9F, 02, 08, 08 + } +# A0, 41, 01, 02, +# A0, 43, 01, 04, +# A0, 02, 01, 01, +# A0, 03, 01, 11, +# A0, 07, 01, 03, +# A0, 08, 01, 01 +# } + +############################################################################### +# Core configuration settings +NXP_CORE_CONF={ 20, 02, 2E, 0E, + 28, 01, 00, + 21, 01, 00, + 30, 01, 08, + 31, 01, 03, + 32, 01, 60, + 38, 01, 01, + 33, 04, 01, 02, 03, 04, + 54, 01, 06, + 50, 01, 02, + 5B, 01, 00, + 80, 01, 01, + 81, 01, 01, + 82, 01, 0E, + 18, 01, 01 + } + +############################################################################### + diff --git a/halimpl/log/phNxpLog.h b/halimpl/log/phNxpLog.h index 75432b5..75432b5 100755..100644 --- a/halimpl/log/phNxpLog.h +++ b/halimpl/log/phNxpLog.h diff --git a/halimpl/self-test/phNxpNciHal_SelfTest.cc b/halimpl/self-test/phNxpNciHal_SelfTest.cc index 1992ef1..86a2042 100755..100644 --- a/halimpl/self-test/phNxpNciHal_SelfTest.cc +++ b/halimpl/self-test/phNxpNciHal_SelfTest.cc @@ -1068,8 +1068,8 @@ NFCSTATUS phNxpNciHal_TestMode_open(void) { max_len)) { NXPLOG_NCIHAL_D( "Invalid nfc device node name keeping the default device node " - "/dev/pn54x"); - strcpy((char*)nfc_dev_node, "/dev/pn54x"); + "/dev/nq-nci"); + strlcpy((char*)nfc_dev_node, "/dev/nq-nci", max_len); } gDrvCfg.nClientId = phDal4Nfc_msgget(0, 0600); diff --git a/halimpl/src/adaptation/EseAdaptation.cpp b/halimpl/src/adaptation/EseAdaptation.cpp index 597e5e9..bde2f8b 100755 --- a/halimpl/src/adaptation/EseAdaptation.cpp +++ b/halimpl/src/adaptation/EseAdaptation.cpp @@ -32,8 +32,10 @@ using android::hardware::secure_element::V1_0::ISecureElementHalCallback; using android::hardware::hidl_vec; using android::sp; +#ifdef ENABLE_ESE_CLIENT using vendor::nxp::nxpese::V1_0::INxpEse; using vendor::nxp::eventprocessor::V1_0::INxpEseEvtProcessor; +#endif using ::android::hardware::hidl_death_recipient; using ::android::wp; using ::android::hidl::base::V1_0::IBase; @@ -49,8 +51,10 @@ extern "C" void delete_stack_non_volatile_store(bool forceDelete); EseAdaptation* EseAdaptation::mpInstance = NULL; ThreadMutex EseAdaptation::sLock; ThreadMutex EseAdaptation::sIoctlLock; +#ifdef ENABLE_ESE_CLIENT sp<INxpEse> EseAdaptation::mHalNxpEse; sp<INxpEseEvtProcessor> EseAdaptation::mHalNxpEseEvtProcessor; +#endif sp<ISecureElement> EseAdaptation::mHal; tHAL_ESE_CBACK* EseAdaptation::mHalCallback = NULL; tHAL_ESE_DATA_CBACK* EseAdaptation::mHalDataCallback = NULL; @@ -67,6 +71,7 @@ ThreadCondVar EseAdaptation::mHalInitCompletedEvent; //static uint8_t evt_status; #endif +#ifdef ENABLE_ESE_CLIENT class NxpEseDeathRecipient : public hidl_death_recipient { public: sp<INxpEse> mHalNxpEseDeathRsp; @@ -87,6 +92,7 @@ class NxpEseDeathRecipient : public hidl_death_recipient { EseAdaptation::GetInstance().InitializeHalDeviceContext(); } }; +#endif /******************************************************************************* ** @@ -98,7 +104,9 @@ class NxpEseDeathRecipient : public hidl_death_recipient { ** *******************************************************************************/ EseAdaptation::EseAdaptation() { +#ifdef ENABLE_ESE_CLIENT mCurrentIoctlData = NULL; +#endif memset(&mSpiHalEntryFuncs, 0, sizeof(mSpiHalEntryFuncs)); } @@ -207,6 +215,7 @@ tHAL_ESE_ENTRY* EseAdaptation::GetHalEntryFuncs() { void EseAdaptation::InitializeHalDeviceContext() { const char* func = "EseAdaptation::InitializeHalDeviceContext"; ALOGD_IF(nfc_debug_enabled, "%s: enter", func); +#ifdef ENABLE_ESE_CLIENT ALOGD_IF(nfc_debug_enabled, "%s: INxpEse::tryGetService()", func); for (int cnt = 0; ((mHalNxpEse == nullptr) && (cnt < 3)); cnt++) { mHalNxpEse = INxpEse::tryGetService(); @@ -235,6 +244,7 @@ void EseAdaptation::InitializeHalDeviceContext() { mHalNxpEseEvtProcessor.get(), (mHalNxpEseEvtProcessor->isRemote() ? "remote" : "local")); } +#endif /*Transceive NCI_INIT_CMD*/ ALOGD_IF(nfc_debug_enabled, "%s: exit", func); } @@ -265,7 +275,8 @@ void EseAdaptation::HalDeviceContextDataCallback(uint16_t data_len, ** Returns: None. ** *******************************************************************************/ -void IoctlCallback(hidl_vec<uint8_t> outputData) { +void IoctlCallback(hidl_vec<uint8_t> /* outputData */) { +#ifdef ENABLE_ESE_CLIENT const char* func = "IoctlCallback"; ese_nxp_ExtnOutputData_t* pOutData = (ese_nxp_ExtnOutputData_t*)&outputData[0]; @@ -276,6 +287,7 @@ void IoctlCallback(hidl_vec<uint8_t> outputData) { * This data will be sent back to libese*/ memcpy(&pAdaptation->mCurrentIoctlData->out, &outputData[0], sizeof(ese_nxp_ExtnOutputData_t)); +#endif } /******************************************************************************* ** @@ -292,7 +304,9 @@ void IoctlCallback(hidl_vec<uint8_t> outputData) { ** Returns: -1 or 0. ** *******************************************************************************/ -int EseAdaptation::HalIoctl(long arg, void* p_data) { +int EseAdaptation::HalIoctl(long /* arg */ , void* /* p_data */) { + int ret = -1; +#ifdef ENABLE_ESE_CLIENT const char* func = "EseAdaptation::HalIoctl"; hidl_vec<uint8_t> data; AutoThreadMutex a(sIoctlLock); @@ -305,6 +319,8 @@ int EseAdaptation::HalIoctl(long arg, void* p_data) { ALOGD_IF(nfc_debug_enabled, "%s Ioctl Completed for Type=%lu", func, (unsigned long)pInpOutData->out.ioctlType); return (pInpOutData->out.result); +#endif + return ret; } /******************************************************************************* @@ -317,7 +333,8 @@ int EseAdaptation::HalIoctl(long arg, void* p_data) { ** Returns: none ** *******************************************************************************/ -void EseAdaptation::HalNfccNtf(long arg, void *p_data) { +void EseAdaptation::HalNfccNtf(long /* arg */, void * /* p_data */) { +#ifdef ENABLE_ESE_CLIENT const char *func = "EseAdaptation::HalNfccNtf"; hidl_vec<uint8_t> data; AutoThreadMutex a(sIoctlLock); @@ -331,6 +348,7 @@ void EseAdaptation::HalNfccNtf(long arg, void *p_data) { ALOGD_IF(nfc_debug_enabled, "%s Ioctl Completed for Type=%lu", func, (unsigned long)pInpOutData->out.ioctlType); return; +#endif } /******************************************************************************* diff --git a/halimpl/src/halLibnfc/src/Android.bp b/halimpl/src/halLibnfc/src/Android.bp index a11a2c5..590e0f6 100755 --- a/halimpl/src/halLibnfc/src/Android.bp +++ b/halimpl/src/halLibnfc/src/Android.bp @@ -16,13 +16,11 @@ cc_library_shared { // Treble configuration "libhidlbase", - "libhidltransport", - "libhwbinder", "libutils", - "ese_client", "android.hardware.nfc@1.0", "android.hardware.nfc@1.1", - "vendor.nxp.nxpnfc@2.0", + "android.hardware.nfc@1.2", + "vendor.nxp.hardware.nfc@2.0", "vendor.nxp.nxpnfclegacy@1.0" ], cflags: [ @@ -43,8 +41,7 @@ cc_library_shared { "gki/common", ], include_dirs: [ - "hardware/nxp/nfc/extns/impl/nxpnfc/2.0", - "hardware/nxp/secure_element/extns/impl/", + "vendor/nxp/opensource/halimpl/extns/impl/", ], srcs: [ "nfa/dm/*.cc", diff --git a/halimpl/src/halLibnfc/src/adaptation/HalNfcAdaptation.cc b/halimpl/src/halLibnfc/src/adaptation/HalNfcAdaptation.cc index da5919a..e730d1c 100755 --- a/halimpl/src/halLibnfc/src/adaptation/HalNfcAdaptation.cc +++ b/halimpl/src/halLibnfc/src/adaptation/HalNfcAdaptation.cc @@ -66,7 +66,7 @@ using ::android::hardware::hidl_death_recipient; using android::hardware::hidl_vec; using android::hardware::nfc::V1_1::INfcClientCallback; using ::android::hidl::base::V1_0::IBase; -using vendor::nxp::nxpnfc::V2_0::INxpNfc; +using vendor::nxp::hardware::nfc::V2_0::INqNfc; using vendor::nxp::nxpnfclegacy::V1_0::INxpNfcLegacy; extern bool nfc_debug_enabled; @@ -76,7 +76,7 @@ extern void GKI_shutdown(); HalNfcAdaptation *HalNfcAdaptation::mpInstance = NULL; HalAdaptationThreadMutex HalNfcAdaptation::sLock; HalAdaptationThreadMutex HalNfcAdaptation::sIoctlLock; -sp<INxpNfc> HalNfcAdaptation::mHalNxpNfc; +sp<INqNfc> HalNfcAdaptation::mNqHal; sp<INxpNfcLegacy> HalNfcAdaptation::mHalNxpNfcLegacy; sp<INfc> HalNfcAdaptation::mHal; sp<INfcV1_1> HalNfcAdaptation::mHal_1_1; @@ -435,14 +435,14 @@ void HalNfcAdaptation::InitializeHalDeviceContext() { (mHal->isRemote() ? "remote" : "local")); } mHal->linkToDeath(mNfcHalDeathRecipient, 0); - LOG(INFO) << StringPrintf("%s: INxpNfc::getService()", func); - mHalNxpNfc = INxpNfc::tryGetService(); - if (mHalNxpNfc == nullptr) { - LOG(INFO) << StringPrintf("Failed to retrieve the NXPNFC HAL!"); + LOG(INFO) << StringPrintf("%s: INqNfc::getService()", func); + mNqHal = INqNfc::tryGetService(); + if (mNqHal == nullptr) { + LOG(INFO) << StringPrintf("Failed to retrieve the NQNFC HAL!"); } else { - LOG(INFO) << StringPrintf("%s: INxpNfc::getService() returned %p (%s)", - func, mHalNxpNfc.get(), - (mHalNxpNfc->isRemote() ? "remote" : "local")); + LOG(INFO) << StringPrintf("%s: INqNfc::getService() returned %p (%s)", + func, mNqHal.get(), + (mNqHal->isRemote() ? "remote" : "local")); } LOG(INFO) << StringPrintf("%s: INxpNfcLegacy::getService()", func); diff --git a/halimpl/src/halLibnfc/src/include/HalNfcAdaptation.h b/halimpl/src/halLibnfc/src/include/HalNfcAdaptation.h index 22318b8..e1d1771 100755 --- a/halimpl/src/halLibnfc/src/include/HalNfcAdaptation.h +++ b/halimpl/src/halLibnfc/src/include/HalNfcAdaptation.h @@ -46,10 +46,10 @@ #include <utils/RefBase.h> #include <vendor/nxp/nxpnfclegacy/1.0/INxpNfcLegacy.h> #include <vendor/nxp/nxpnfclegacy/1.0/types.h> -#include <vendor/nxp/nxpnfc/2.0/INxpNfc.h> +#include <vendor/nxp/hardware/nfc/2.0/INqNfc.h> using ::android::sp; -using vendor::nxp::nxpnfc::V2_0::INxpNfc; +using vendor::nxp::hardware::nfc::V2_0::INqNfc; namespace android { namespace hardware { @@ -138,7 +138,7 @@ private: static HalAdaptationThreadCondVar mHalIoctlEvent; static android::sp<android::hardware::nfc::V1_0::INfc> mHal; static android::sp<android::hardware::nfc::V1_1::INfc> mHal_1_1; - static android::sp<vendor::nxp::nxpnfc::V2_0::INxpNfc> mHalNxpNfc; + static android::sp<vendor::nxp::hardware::nfc::V2_0::INqNfc> mNqHal; static android::hardware::nfc::V1_1::INfcClientCallback *mCallback; static android::sp<vendor::nxp::nxpnfclegacy::V1_0::INxpNfcLegacy> mHalNxpNfcLegacy; sp<NfcDeathRecipient> mNfcHalDeathRecipient; diff --git a/halimpl/src/halLibnfc/src/nfa/ee/nfa_ee_act.cc b/halimpl/src/halLibnfc/src/nfa/ee/nfa_ee_act.cc index 7acdf90..fe09de4 100755 --- a/halimpl/src/halLibnfc/src/nfa/ee/nfa_ee_act.cc +++ b/halimpl/src/halLibnfc/src/nfa/ee/nfa_ee_act.cc @@ -2643,14 +2643,13 @@ static void nfa_ee_report_discover_req_evt(void) { void nfa_ee_nci_pwr_link_ctrl_rsp(tNFA_EE_MSG* p_data) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(" nfa_ee_nci_pwr_link_ctrl_rsp()"); - tNFA_EE_PWR_LNK_CTRL pwr_lnk_ctrl; + tNFA_EE_CBACK_DATA nfa_ee_cback_data; tNFC_NFCEE_EE_PWR_LNK_REVT* p_rsp = p_data->pwr_lnk_ctrl_rsp.p_data; - pwr_lnk_ctrl.status = p_rsp->status; + nfa_ee_cback_data.pwr_lnk_ctrl.status = p_rsp->status; DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(" nfa_ee_nci_pwr_link_ctrl_rsp: status = %d ", - pwr_lnk_ctrl.status); - nfa_ee_report_event(NULL, NFA_EE_PWR_LINK_CTRL_EVT, - (tNFA_EE_CBACK_DATA*)&pwr_lnk_ctrl); + nfa_ee_cback_data.pwr_lnk_ctrl.status); + nfa_ee_report_event(NULL, NFA_EE_PWR_LINK_CTRL_EVT, &nfa_ee_cback_data); } #endif /******************************************************************************* @@ -3468,4 +3467,4 @@ uint16_t nfa_ee_lmrt_size() { 2 /*route/power state*/; return len < NFA_EE_MAX_AID_CFG_LEN ? len : NFA_EE_MAX_AID_CFG_LEN; } -#endif
\ No newline at end of file +#endif diff --git a/halimpl/src/include/EseAdaptation.h b/halimpl/src/include/EseAdaptation.h index bea0eb7..de52a8e 100755 --- a/halimpl/src/include/EseAdaptation.h +++ b/halimpl/src/include/EseAdaptation.h @@ -20,17 +20,23 @@ #include <pthread.h> #include "ese_hal_api.h" +#ifdef ENABLE_ESE_CLIENT #include "hal_nxpese.h" +#endif #include <android/hardware/secure_element/1.0/ISecureElement.h> #include <android/hardware/secure_element/1.0/ISecureElementHalCallback.h> #include <android/hardware/secure_element/1.0/types.h> #include <utils/RefBase.h> +#ifdef ENABLE_ESE_CLIENT #include <vendor/nxp/eventprocessor/1.0/INxpEseEvtProcessor.h> #include <vendor/nxp/nxpese/1.0/INxpEse.h> using vendor::nxp::nxpese::V1_0::INxpEse; using vendor::nxp::eventprocessor::V1_0::INxpEseEvtProcessor; +#endif using ::android::sp; +#ifdef ENABLE_ESE_CLIENT class NxpEseDeathRecipient; +#endif class ThreadMutex { public: @@ -79,17 +85,23 @@ class EseAdaptation { static int HalIoctl(long arg, void* p_data); static void HalNfccNtf(long arg, void *p_data); tHAL_ESE_ENTRY* GetHalEntryFuncs(); +#ifdef ENABLE_ESE_CLIENT ese_nxp_IoctlInOutData_t* mCurrentIoctlData; +#endif tHAL_ESE_ENTRY mSpiHalEntryFuncs; // function pointers for HAL entry points +#ifdef ENABLE_ESE_CLIENT static android::sp<vendor::nxp::nxpese::V1_0::INxpEse> mHalNxpEse; static android::sp<vendor::nxp::eventprocessor::V1_0::INxpEseEvtProcessor> mHalNxpEseEvtProcessor; +#endif private: EseAdaptation(); void signal(); static EseAdaptation* mpInstance; +#ifdef ENABLE_ESE_CLIENT sp<NxpEseDeathRecipient> mNxpEseDeathRecipient; +#endif static ThreadMutex sLock; static ThreadMutex sIoctlLock; ThreadCondVar mCondVar; diff --git a/halimpl/tml/phOsalNfc_Timer.cc b/halimpl/tml/phOsalNfc_Timer.cc index 7e9f837..7e9f837 100755..100644 --- a/halimpl/tml/phOsalNfc_Timer.cc +++ b/halimpl/tml/phOsalNfc_Timer.cc diff --git a/halimpl/tml/phOsalNfc_Timer.h b/halimpl/tml/phOsalNfc_Timer.h index 30888db..30888db 100755..100644 --- a/halimpl/tml/phOsalNfc_Timer.h +++ b/halimpl/tml/phOsalNfc_Timer.h diff --git a/halimpl/tml/phTmlNfc.h b/halimpl/tml/phTmlNfc.h index ddbdeb9..ddbdeb9 100755..100644 --- a/halimpl/tml/phTmlNfc.h +++ b/halimpl/tml/phTmlNfc.h diff --git a/halimpl/tml/phTmlNfc_i2c.h b/halimpl/tml/phTmlNfc_i2c.h index f182844..38523b0 100755..100644 --- a/halimpl/tml/phTmlNfc_i2c.h +++ b/halimpl/tml/phTmlNfc_i2c.h @@ -39,7 +39,7 @@ extern phTmlNfc_i2cfragmentation_t fragmentation_enabled; * PN544_SET_PWR(1): power on * PN544_SET_PWR(2): reset and power on with firmware download enabled */ -#define PN544_SET_PWR _IOW(PN544_MAGIC, 0x01, long) +#define PN544_SET_PWR _IOW(PN544_MAGIC, 0x01, unsigned int) NFCSTATUS phTmlNfc_i2c_get_p61_power_state(void* pDevHandle); NFCSTATUS phTmlNfc_i2c_set_p61_power_state(void* pDevHandle, long arg); @@ -55,19 +55,19 @@ NFCSTATUS phTmlNfc_rel_dwpOnOff_wait(void *pDevHandle, long dwplinkActvStatus); * level 1 = Enable power * level 0 = Disable power */ -#define P61_SET_SPI_PWR _IOW(PN544_MAGIC, 0x02, long) +#define P61_SET_SPI_PWR _IOW(PN544_MAGIC, 0x02, unsigned int) /* SPI or DWP can call this ioctl to get the current * power state of P61 * */ -#define P61_GET_PWR_STATUS _IOR(PN544_MAGIC, 0x03, long) +#define P61_GET_PWR_STATUS _IOR(PN544_MAGIC, 0x03, unsigned int) /* DWP side this ioctl will be called * level 1 = Wired access is enabled/ongoing * level 0 = Wired access is disalbed/stopped */ -#define P61_SET_WIRED_ACCESS _IOW(PN544_MAGIC, 0x04, long) +#define P61_SET_WIRED_ACCESS _IOW(PN544_MAGIC, 0x04, unsigned int) /* NFC Init will call the ioctl to register the PID with the i2c driver diff --git a/halimpl/utils/phNxpConfig.cpp b/halimpl/utils/phNxpConfig.cpp index 58ac5b9..8c57313 100755..100644 --- a/halimpl/utils/phNxpConfig.cpp +++ b/halimpl/utils/phNxpConfig.cpp @@ -1,4 +1,6 @@ /****************************************************************************** + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * Not a Contribution. * * Copyright (C) 2011-2012 Broadcom Corporation * @@ -36,6 +38,16 @@ * ******************************************************************************/ + /** + * @file phNxpConfig.cpp + * @date 24 Aug 2016 + * @brief File containing code for dynamic selection of config files based on target. + * + * The target device has to be configured with some primary setting while booting.So a + * config file will be picked while the target is booted. Here based on the target device + * a configuration file will be selected dynamically and the device will be configured. + */ + #include <phNxpConfig.h> #include <stdio.h> #include <string> @@ -82,6 +94,60 @@ const char default_nxp_config_path[] = const char nxp_rf_config_path[] = "/system/vendor/libnfc-nxp_RF.conf"; +/** + * @brief target platform ID values. + */ + +typedef enum +{ + CONFIG_GENERIC = 0x00, + MTP_TYPE_DEFAULT = 0x01, /**< default MTP config. DC DC ON */ + QRD_TYPE_DEFAULT = 0x02, /**< default QRD config DC DC OFF */ + MTP_TYPE_1 = 0x03, /**< mtp config type1 : newer chip */ + MTP_TYPE_2 = 0x04, /**< mtp config type2 TBD */ + QRD_TYPE_1 = 0x05, /**< qrd config type1 DC DC ON*/ + QRD_TYPE_2 = 0x06, /**< qrd config type2 Newer chip */ + MTP_TYPE_NQ3XX = 0x07, /**< mtp config : for NQ3XX chip */ + QRD_TYPE_NQ3XX = 0x08, /**< qrd config : for NQ3XX chip */ + MTP_TYPE_NQ4XX = 0x09, /**< mtp config : for NQ4XX chip */ + QRD_TYPE_NQ4XX = 0x10, /**< qrd config : for NQ4XX chip */ + DEFAULT_CONFIG = QRD_TYPE_DEFAULT, /**< default is qrd default config */ + CONFIG_INVALID = 0xFF +} CONFIGIDVALUE; + +/** + * @brief Defines the soc_id values for different targets. + */ + +typedef enum +{ + TARGET_GENERIC = 0x00,/**< new targets */ + TARGET_MSM8952 = 264, /**< 8952 target */ + TARGET_MSM8976 = 278, /**< 8976 target */ + TARGET_MSM8937 = 294, /**< 8937 target */ + TARGET_MSM8953 = 293, /**< 8953 target */ + TARGET_MSM8996 = 246, /**< 8996 target*/ + TARGET_MSM8909 = 245, /**< 8909w target */ + TARGET_MSM8998 = 292, /**< 8998 target */ + TARGET_MSM8997 = 306, /**< 8997 target */ + TARGET_MSM8917 = 303, /**< 8917 target */ + TARGET_MSM8940 = 313, /**< 8940 target */ + TARGET_SDM660 = 317, /**< SDM660 target */ + TARGET_SDM670 = 336, /**< SDM670 target */ + TARGET_SDM710 = 360, /**< SDM710 target */ + TARGET_SDM712 = 393, /**< SDM712 target */ + TARGET_QCS605 = 347, /**< QCS605 target */ + TARGET_SDM630 = 318, /**< SDM630 target */ + TARGET_SDM632 = 349, /**< SDM632 target */ + TARGET_SDM439 = 353, /**< SDM439 target */ + TARGET_SDM429 = 354, /**< SDM429 target */ + TARGET_SDM450 = 338, /**< SDM450 target */ + TARGET_SDM455 = 385, /**< SDM455 target */ + TARGET_SDM845 = 321, /**< SDM845 target */ + TARGET_DEFAULT = TARGET_GENERIC, /**< new targets */ + TARGET_INVALID = 0xFF +} TARGETTYPE; + namespace { size_t readConfigFile(const char* fileName, uint8_t** p_data) { @@ -116,6 +182,7 @@ using namespace ::std; namespace nxp { +void findConfigFilePathFromTransportConfigPaths(const string& configName, string& filePath); class CNfcParam : public string { public: @@ -152,6 +219,8 @@ class CNfcConfig : public vector<const CNfcParam*> { private: CNfcConfig(); bool readConfig(const char* name, bool bResetContent); + int file_exist (const char* filename); + int getconfiguration_id (char * config_file); void moveFromList(); void moveToList(); void add(const CNfcParam* pParam); @@ -159,6 +228,7 @@ class CNfcConfig : public vector<const CNfcParam*> { bool isAllowed(const char* name); list<const CNfcParam*> m_list; bool mValidFile; + bool mDynamConfig; uint32_t config_crc32_; uint32_t config_crc32_rf_; uint32_t config_crc32_tr_; @@ -172,6 +242,282 @@ class CNfcConfig : public vector<const CNfcParam*> { inline void Reset(unsigned long f) { state &= ~f; } }; +/** + * @brief This function reads the hardware information from the given path. + * + * This function receives the path and then reads the hardware information + * from the file present in the given path. It reads the details like whether + * it is QRD or MTP. It reads the data from that file and stores in buffer. + * It also receives a count which tells the number of characters to be read + * Finally the length of the buffer is returned. + * + * @param path The path where the file containing hardware details to be read. + * @param buff The hardware details that is read from that path will be stored here. + * @param count It represents the number of characters to be read from that file. + * @return It returns the length of the buffer. + */ + +static int read_line_from_file(const char *path, char *buf, size_t count) +{ + char *fgets_ret = NULL; + FILE *fd = NULL; + int rv = 0; + + // opens the file to read the HW_PLATFORM detail of the target + fd = fopen(path, "r"); + if (fd == NULL) + return -1; + + // stores the data that is read from the given path into buf + fgets_ret = fgets(buf, (int)count, fd); + if (NULL != fgets_ret) + rv = (int)strlen(buf); + else + rv = ferror(fd); + + fclose(fd); + + return rv; +} + +/** + * @brief This function gets the source information from the file. + * + * This function receives a buffer variable to store the read information + * and also receives two different path. The hardware information may be + * present in any one of the received path. So this function checks in + * both the paths. This function internally uses read_line_from_file + * function to read the check and read the hardware details in each path. + * + * @param buf hardware details that is read will be stored. + * @param soc_node_path1 The first path where the file may be present. + * @param soc_node_path2 The second path where the file may be present. + * @return Returns the length of buffer. + */ + +static int get_soc_info(char *buf, const char *soc_node_path1, + const char *soc_node_path2) +{ + int ret = 0; + + // checks whether the hw platform detail is present in this path + ret = read_line_from_file(soc_node_path1, buf, MAX_SOC_INFO_NAME_LEN); + if (ret < 0) { + // if the hw platform detail is not present in the former path it checks here + ret = read_line_from_file(soc_node_path2, buf, MAX_SOC_INFO_NAME_LEN); + if (ret < 0) { + ALOGE("getting socinfo(%s, %d) failed.\n", soc_node_path1, ret); + return ret; + } + } + if (ret && buf[ret - 1] == '\n') + buf[ret - 1] = '\0'; + + return ret; +} + +/** + * @brief finds the cofiguration id value for the particular target. + * + * This function reads the target board platform detail and hardware + * platform detail from the target device and generate a generic + * config file name.If that config file is present then it will be + * used for configuring that target. If not then based on the target + * information a config file will be assigned. + * + * @param config_file The generic config file name will be stored. + * @return it returns the config id for the target. + */ + +int CNfcConfig::getconfiguration_id (char * config_file) +{ + int config_id = QRD_TYPE_DEFAULT; + char target_type[MAX_SOC_INFO_NAME_LEN] = {'\0'}; + char soc_info[MAX_SOC_INFO_NAME_LEN] = {'\0'}; + char nq_chipid[PROPERTY_VALUE_MAX] = {0}; + char nq_fw_ver[PROPERTY_VALUE_MAX] = {0}; + string strPath; + int rc = 0; + int idx = 0; + + rc = get_soc_info(soc_info, SYSFS_SOCID_PATH1, SYSFS_SOCID_PATH2); + if (rc < 0) { + ALOGE("get_soc_info(SOC_ID) fail!\n"); + return DEFAULT_CONFIG; + } + idx = atoi(soc_info); + + rc = get_soc_info(target_type, SYSFS_HW_PLATFORM_PATH1, SYSFS_HW_PLATFORM_PATH2); + if (rc < 0) { + ALOGE("get_soc_info(HW_PLATFORM) fail!\n"); + return DEFAULT_CONFIG; + } + + rc = __system_property_get("vendor.qti.nfc.chipid", nq_chipid); + if (rc <= 0) + ALOGE("get vendor.qti.nfc.chipid fail, rc = %d\n", rc); + else + ALOGD("vendor.qti.nfc.chipid = %s\n", nq_chipid); + + rc = __system_property_get("vendor.qti.nfc.fwver", nq_fw_ver); + if (rc <= 0) + ALOGE("get vendor.qti.nfc.fwver fail, rc = %d\n", rc); + else + ALOGD("vendor.qti.nfc.fwver = %s\n", nq_fw_ver); + + // Converting the HW_PLATFORM detail that is read from target to lowercase + for (int i=0;target_type[i];i++) + target_type[i] = tolower(target_type[i]); + + // generating a generic config file name based on the target details + snprintf(config_file, MAX_DATA_CONFIG_PATH_LEN, "libnfc-%s_%s.conf", + soc_info, target_type); + + findConfigFilePathFromTransportConfigPaths(config_file, strPath); + if (file_exist(strPath.c_str())) + idx = 0; + + if (DEBUG) + ALOGI("id:%d, config_file_name:%s\n", idx, config_file); + + // if target is QRD platform then config id is assigned here + if (0 == strncmp(target_type, QRD_HW_PLATFORM, MAX_SOC_INFO_NAME_LEN)) { + switch (idx) + { + case TARGET_GENERIC: + config_id = CONFIG_GENERIC; + break; + case TARGET_MSM8952: + case TARGET_MSM8909: + config_id = QRD_TYPE_DEFAULT; + strlcpy(config_file, config_name_qrd, MAX_DATA_CONFIG_PATH_LEN); + break; + case TARGET_MSM8953: + case TARGET_MSM8937: + case TARGET_MSM8917: + case TARGET_MSM8940: + case TARGET_SDM632: + case TARGET_SDM439: + case TARGET_SDM429: + case TARGET_SDM450: + if ((!strncmp(nq_chipid, NQ220, PROPERTY_VALUE_MAX)) || (!strncmp(nq_chipid, NQ210, PROPERTY_VALUE_MAX))) { + // NQ210 or NQ220 + config_id = QRD_TYPE_DEFAULT; + strlcpy(config_file, config_name_qrd, MAX_DATA_CONFIG_PATH_LEN); + } else if (!strncmp(nq_fw_ver, FW_MAJOR_NUM_NQ4xx, FW_MAJOR_NUM_LENGTH)) { + config_id = QRD_TYPE_NQ4XX; + strlcpy(config_file, config_name_qrd_NQ4XX, MAX_DATA_CONFIG_PATH_LEN); + } else { + config_id = QRD_TYPE_NQ3XX; + strlcpy(config_file, config_name_qrd_NQ3XX, MAX_DATA_CONFIG_PATH_LEN); + } + break; + case TARGET_MSM8976: + case TARGET_MSM8996: + strlcpy(config_file, config_name_qrd1, MAX_DATA_CONFIG_PATH_LEN); + config_id = QRD_TYPE_1; + break; + case TARGET_SDM845: + case TARGET_SDM670: + case TARGET_SDM710: + case TARGET_SDM712: + case TARGET_QCS605: + if (!strncmp(nq_fw_ver, FW_MAJOR_NUM_NQ4xx, FW_MAJOR_NUM_LENGTH)) { + config_id = QRD_TYPE_NQ4XX; + strlcpy(config_file, config_name_qrd_NQ4XX, MAX_DATA_CONFIG_PATH_LEN); + } + else { + config_id = QRD_TYPE_NQ3XX; + strlcpy(config_file, config_name_qrd_NQ3XX, MAX_DATA_CONFIG_PATH_LEN); + } + break; + case TARGET_SDM660: + case TARGET_SDM630: + case TARGET_SDM455: + case TARGET_MSM8998: + case TARGET_MSM8997: + if ((!strncmp(nq_chipid, NQ220, PROPERTY_VALUE_MAX)) || (!strncmp(nq_chipid, NQ210, PROPERTY_VALUE_MAX))) { + // NQ210 or NQ220 + config_id = QRD_TYPE_2; + strlcpy(config_file, config_name_qrd2, MAX_DATA_CONFIG_PATH_LEN); + } else { + config_id = QRD_TYPE_NQ3XX; + strlcpy(config_file, config_name_qrd_NQ3XX, MAX_DATA_CONFIG_PATH_LEN); + } + break; + default: + config_id = QRD_TYPE_DEFAULT; + strlcpy(config_file, config_name_qrd, MAX_DATA_CONFIG_PATH_LEN); + break; + } + } + // if target is not QRD platform then default config id is assigned here + else { + switch (idx) + { + case TARGET_GENERIC: + config_id = CONFIG_GENERIC; + break; + case TARGET_MSM8953: + case TARGET_MSM8937: + case TARGET_MSM8917: + case TARGET_MSM8940: + case TARGET_SDM632: + case TARGET_SDM439: + case TARGET_SDM429: + case TARGET_SDM450: + if ((!strncmp(nq_chipid, NQ220, PROPERTY_VALUE_MAX)) || (!strncmp(nq_chipid, NQ210, PROPERTY_VALUE_MAX))) { + // NQ210 or NQ220 + config_id = MTP_TYPE_DEFAULT; + strlcpy(config_file, config_name_mtp, MAX_DATA_CONFIG_PATH_LEN); + } else if (!strncmp(nq_fw_ver, FW_MAJOR_NUM_NQ4xx, FW_MAJOR_NUM_LENGTH)) { + config_id = MTP_TYPE_NQ4XX; + strlcpy(config_file, config_name_mtp_NQ4XX, MAX_DATA_CONFIG_PATH_LEN); + } else { + config_id = MTP_TYPE_NQ3XX; + strlcpy(config_file, config_name_mtp_NQ3XX, MAX_DATA_CONFIG_PATH_LEN); + } + break; + case TARGET_SDM845: + case TARGET_SDM670: + case TARGET_SDM710: + case TARGET_SDM712: + case TARGET_QCS605: + if (!strncmp(nq_fw_ver, FW_MAJOR_NUM_NQ4xx, FW_MAJOR_NUM_LENGTH)) { + config_id = MTP_TYPE_NQ4XX; + strlcpy(config_file, config_name_mtp_NQ4XX, MAX_DATA_CONFIG_PATH_LEN); + } + else { + config_id = MTP_TYPE_NQ3XX; + strlcpy(config_file, config_name_mtp_NQ3XX, MAX_DATA_CONFIG_PATH_LEN); + } + break; + case TARGET_SDM660: + case TARGET_SDM630: + case TARGET_SDM455: + case TARGET_MSM8998: + case TARGET_MSM8997: + if ((!strncmp(nq_chipid, NQ220, PROPERTY_VALUE_MAX)) || (!strncmp(nq_chipid, NQ210, PROPERTY_VALUE_MAX))) { + // NQ210 or NQ220 + config_id = MTP_TYPE_1; + strlcpy(config_file, config_name_mtp1, MAX_DATA_CONFIG_PATH_LEN); + } else { + config_id = MTP_TYPE_NQ3XX; + strlcpy(config_file, config_name_mtp_NQ3XX, MAX_DATA_CONFIG_PATH_LEN); + } + break; + default: + config_id = MTP_TYPE_DEFAULT; + strlcpy(config_file, config_name_mtp, MAX_DATA_CONFIG_PATH_LEN); + break; + } + } + if (DEBUG) + ALOGI("platform config id:%d, config_file_name:%s\n", config_id, config_file); + + return config_id; +} + /******************************************************************************* ** ** Function: isPrintable() @@ -450,9 +796,8 @@ bool CNfcConfig::readConfig(const char* name, bool bResetContent) { ** Returns: none ** *******************************************************************************/ -CNfcConfig::CNfcConfig() - : mValidFile(true), config_crc32_(0), config_crc32_rf_(0), - config_crc32_tr_(0), state(0) {} +CNfcConfig::CNfcConfig() : mValidFile(true), mDynamConfig(true), config_crc32_(0), + config_crc32_rf_(0), config_crc32_tr_(0), state(0) {} /******************************************************************************* ** @@ -465,6 +810,22 @@ CNfcConfig::CNfcConfig() *******************************************************************************/ CNfcConfig::~CNfcConfig() {} +/** + * @brief checks whether the given file exist. + * + * This function gets the file name and checks whether the given file + * exist in the particular path.Internaly it uses stat system call to + * find the existance. + * + * @param filename The name of the file whose existance has to be checked. + * @return it returns true if the given file name exist. + */ +int CNfcConfig::file_exist (const char* filename) +{ + struct stat buffer; + return (stat (filename, &buffer) == 0); +} + /******************************************************************************* ** ** Function: CNfcConfig::GetInstance() @@ -476,46 +837,49 @@ CNfcConfig::~CNfcConfig() {} *******************************************************************************/ CNfcConfig& CNfcConfig::GetInstance() { static CNfcConfig theInstance; - char valueStr[PROPERTY_VALUE_MAX] = {0}; - string config_file_name = "libnfc-nxp"; - if (theInstance.size() == 0 && theInstance.mValidFile) { - string strPath; - if (alternative_config_path[0] != '\0') { - strPath.assign(alternative_config_path); - strPath += config_name; - theInstance.readConfig(strPath.c_str(), true); - if (!theInstance.empty()) { - return theInstance; - } - } - // update config file based on system property - int len = property_get("persist.vendor.nfc.config_file_name", valueStr, ""); + int gconfigpathid=0; + char config_name_generic[MAX_DATA_CONFIG_PATH_LEN] = {'\0'}; + + if (theInstance.size() == 0 && theInstance.mValidFile) + { + string strPath; + if (alternative_config_path[0] != '\0') + { + strPath.assign(alternative_config_path); + strPath += config_name; + theInstance.readConfig(strPath.c_str(), true); + if (!theInstance.empty()) + { + return theInstance; + } + } + findConfigFilePathFromTransportConfigPaths(config_name, strPath); + //checks whether the default config file is present in th target + if (theInstance.file_exist(strPath.c_str())) { + ALOGI("default config file exists = %s, disables dynamic selection", strPath.c_str()); + theInstance.mDynamConfig = false; + theInstance.readConfig(strPath.c_str(), true); + /* + * if libnfc-nxp.conf exists then dynamic selection will + * be turned off by default we will not have this file. + */ + return theInstance; + } - if (len > 0) { - config_file_name = config_file_name + "_" + valueStr + ".conf"; - } else { - config_file_name = config_name; - } - ALOGD("nxp config referred : %s", config_file_name.c_str()); - - if (findConfigFilePathFromTransportConfigPaths( - android::base::GetProperty("persist.vendor.nfc.config_file_name", ""), - strPath)) { - NXPLOG_EXTNS_D("%s load %s\n", __func__, strPath.c_str()); - } else if (findConfigFilePathFromTransportConfigPaths( - extra_config_base + - android::base::GetProperty("ro.boot.product.hardware.sku", "") + - + extra_config_ext, strPath)) { - NXPLOG_EXTNS_D("%s load %s\n", __func__, strPath.c_str()); - } else { - findConfigFilePathFromTransportConfigPaths(config_name, strPath); - } + gconfigpathid = theInstance.getconfiguration_id(config_name_generic); + findConfigFilePathFromTransportConfigPaths(config_name_generic, strPath); + if (!(theInstance.file_exist(strPath.c_str()))) { + ALOGI("no matching file found, using default file for stability\n"); + findConfigFilePathFromTransportConfigPaths(config_name_default, strPath); + } + ALOGI("config file used = %s\n",strPath.c_str()); + theInstance.readConfig(strPath.c_str(), true); +#if(NXP_EXTNS == TRUE) - ALOGD("nxp config file : %s", strPath.c_str()); - theInstance.readConfig(strPath.c_str(), true); -#if (NXP_EXTNS == TRUE) - theInstance.readNxpTransitConfig(transit_config_path); - theInstance.readNxpRFConfig(nxp_rf_config_path); + + theInstance.readNxpTransitConfig("nxpTransit"); + theInstance.readNxpTransitConfig(transit_config_path); + theInstance.readNxpRFConfig(nxp_rf_config_path); #endif } return theInstance; diff --git a/halimpl/utils/phNxpConfig.h b/halimpl/utils/phNxpConfig.h index 691e82f..b078f1a 100644 --- a/halimpl/utils/phNxpConfig.h +++ b/halimpl/utils/phNxpConfig.h @@ -161,4 +161,78 @@ int updateNxpConfigTimestamp(); #define NAME_ETSI_READER_ENABLE "ETSI_READER_ENABLE" #define NAME_WTAG_SUPPORT "WTAG_SUPPORT" #define NAME_DEFAULT_T4TNFCEE_AID_POWER_STATE "DEFAULT_T4TNFCEE_AID_POWER_STATE" +/** + * @brief defines the different config files used. + */ + +#define config_name_mtp "libnfc-mtp_default.conf" +#define config_name_mtp1 "libnfc-mtp_rf1.conf" +#define config_name_mtp2 "libnfc-mtp_rf2.conf" +#define config_name_mtp_NQ3XX "libnfc-mtp-NQ3XX.conf" +#define config_name_mtp_NQ4XX "libnfc-mtp-NQ4XX.conf" +#define config_name_qrd "libnfc-qrd_default.conf" +#define config_name_qrd1 "libnfc-qrd_rf1.conf" +#define config_name_qrd2 "libnfc-qrd_rf2.conf" +#define config_name_qrd_NQ3XX "libnfc-qrd-NQ3XX.conf" +#define config_name_qrd_NQ4XX "libnfc-qrd-NQ4XX.conf" +#define config_name_default "libnfc-nxp_default.conf" + +/** + * @brief defines the different major number used. + */ +#define FW_MAJOR_NUM_NQ2xx "10" +#define FW_MAJOR_NUM_NQ3xx "11" +#define FW_MAJOR_NUM_NQ4xx "12" + +#define FW_MAJOR_NUM_LENGTH 2 + +/** + * @brief defines the maximum length of the target name. + */ + +#define MAX_SOC_INFO_NAME_LEN (15) + +/** + * @brief Defines the type of hardware platform. + */ + +#define QRD_HW_PLATFORM "qrd" +#define MTP_HW_PLATFORM "mtp" + +/** + * @brief Defines the path where the hardware platform details are present. + */ + +#define SYSFS_HW_PLATFORM_PATH1 "/sys/devices/soc0/hw_platform" +#define SYSFS_HW_PLATFORM_PATH2 "/sys/devices/system/soc/soc0/hw_platform" + +/** + * @brief Defines the path where the soc_id details are present. + */ + +#define SYSFS_SOCID_PATH1 "/sys/devices/soc0/soc_id" +#define SYSFS_SOCID_PATH2 "/sys/devices/system/soc/soc0/id" + +/** + * @brief Defines the maximum length of the config file name. + */ + +#define MAX_DATA_CONFIG_PATH_LEN 64 + +/** + * @brief Defines the NQ chip type. + */ + +#define NQ210 "0x48" +#define NQ220 "0x58" + +/** + * @brief Defines whether debugging is enabled or disabled. + */ + +#define DEBUG 0 + +/* default configuration */ +#define default_storage_location "/data/vendor/nfc" + #endif diff --git a/inc/IChannel.h b/inc/IChannel.h new file mode 100644 index 0000000..c41171c --- /dev/null +++ b/inc/IChannel.h @@ -0,0 +1,119 @@ + /* + * Copyright (C) 2015-2018 NXP Semiconductors + * + * 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 ICHANNEL_H_ +#define ICHANNEL_H_ + +#include "data_types.h" +typedef enum InterfaceInfo{ + INTF_NFC = 0, + INTF_SE =1, +}IntfInfo; +typedef struct IChannel +{ +/******************************************************************************* +** +** Function: Open +** +** Description: Initialize the channel. +** +** Returns: True if ok. +** +*******************************************************************************/ +int16_t (*open)(); +/******************************************************************************* +** +** Function: close +** +** Description: Close the channel. +** +** Returns: True if ok. +** +*******************************************************************************/ +bool (*close)(int16_t mHandle); + +/******************************************************************************* +** +** Function: transceive +** +** Description: Send data to the secure element; read it's response. +** xmitBuffer: Data to transmit. +** xmitBufferSize: Length of data. +** recvBuffer: Buffer to receive response. +** recvBufferMaxSize: Maximum size of buffer. +** recvBufferActualSize: Actual length of response. +** timeoutMillisec: timeout in millisecond +** +** Returns: True if ok. +** +*******************************************************************************/ +bool (*transceive) (uint8_t* xmitBuffer, int32_t xmitBufferSize, uint8_t* recvBuffer, + int32_t recvBufferMaxSize, int32_t& recvBufferActualSize, int32_t timeoutMillisec); + +/******************************************************************************* +** +** Function: transceiveRaw +** +** Description: Send native/non-gp commands to the secure element; read it's response. +** xmitBuffer: Data to transmit. +** xmitBufferSize: Length of data. +** recvBuffer: Buffer to receive response. +** recvBufferMaxSize: Maximum size of buffer. +** recvBufferActualSize: Actual length of response. +** timeoutMillisec: timeout in millisecond +** +** Returns: True if ok. +** +*******************************************************************************/ +bool (*transceiveRaw) (uint8_t* xmitBuffer, int32_t xmitBufferSize, uint8_t* recvBuffer, + int32_t recvBufferMaxSize, int32_t& recvBufferActualSize, int32_t timeoutMillisec); + +/******************************************************************************* +** +** Function: doeSE_Reset +** +** Description: Power OFF and ON to eSE +** +** Returns: None. +** +*******************************************************************************/ + +void (*doeSE_Reset)(); +/******************************************************************************* +** +** Function: doeSE_JcopDownLoadReset +** +** Description: Power OFF and ON to eSE during JCOP Update +** +** Returns: None. +** +*******************************************************************************/ + +void (*doeSE_JcopDownLoadReset)(); +/******************************************************************************* +** +** Variable: tNfc_featureList +** +** Description: NFCC and eSE feature flags +** +** Returns: None. +** +*******************************************************************************/ +uint8_t (*getInterfaceInfo)(); +}IChannel_t; + + +#endif /* ICHANNEL_H_ */ diff --git a/inc/data_types.h b/inc/data_types.h new file mode 100644 index 0000000..fa2ddba --- /dev/null +++ b/inc/data_types.h @@ -0,0 +1,59 @@ + /* + * Copyright (C) 2015-2018 NXP Semiconductors + * + * 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 DATA_TYPES_H +#define DATA_TYPES_H +#include <stdint.h> +#include <stdbool.h> +#ifndef NULL +#define NULL 0 +#endif + +/* +#ifndef false +#define false 0 +#endif +*/ + +#ifndef FALSE +#define FALSE 0 +#endif + +typedef uint32_t TIME_STAMP; + +/* +#ifndef true +#define true (!false) +#endif +*/ + +#ifndef TRUE +#define TRUE (!FALSE) +#endif + +typedef unsigned char UBYTE; + +#define STATUS_SUCCESS 0x00 +#define STATUS_OK 0x00 +#define STATUS_UPTO_DATE 0x01 +#define STATUS_FAILED 0x03 +#define STATUS_INUSE 0x04 +#define STATUS_FILE_NOT_FOUND 0x05 + +#define EE_ERROR_OPEN_FAIL -1 + +typedef uint8_t tJBL_STATUS; + +#endif diff --git a/inc/eSEClientIntf.h b/inc/eSEClientIntf.h new file mode 100644 index 0000000..9c265c8 --- /dev/null +++ b/inc/eSEClientIntf.h @@ -0,0 +1,81 @@ +/******************************************************************************* + * + * Copyright 2018 NXP + * + * 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 CLIENT_INTF_H_ +#define CLIENT_INTF_H_ +#include <pthread.h> +#include <string> + +#define SEMS_STATUS_FAILED_SW1 0x63 +#define SEMS_STATUS_FAILED_SW2 0x40 + +#define SEMS_STATUS_SUCCESS_SW1 0x90 +#define SEMS_STATUS_SUCCESS_SW2 0x00 + +#define JCOP_UPDATE_3STEP_DONE 3 + +typedef struct se_extns_entry{ + uint8_t isJcopUpdateRequired; + uint8_t isLSUpdateRequired; + unsigned long int sJcopUpdateIntferface; + unsigned long int sLsUpdateIntferface; +} se_extns_entry; + +typedef enum { + ESE_INTF_INVALID = 0, + ESE_INTF_NFC = 1, + ESE_INTF_SPI = 2 +}ESE_CLIENT_INTF; + +typedef enum { + SESTATUS_SUCCESS = (0x0000), + SESTATUS_FAILED = (0x0003), + SESTATUS_FILE_NOT_FOUND = (0x0005) +} SESTATUS; + +typedef enum { + ESE_UPDATE_COMPLETED = 0, + ESE_UPDATE_STARTED, + ESE_JCOP_UPDATE_REQUIRED, + ESE_JCOP_UPDATE_COMPLETED, + ESE_LS_UPDATE_REQUIRED, + ESE_LS_UPDATE_COMPLETED +}ese_update_state_t; + +extern bool nfc_debug_enabled; +/******************************************************************************* +** +** Function: checkeSEClientRequired +** +** Description: Read the interface and condition for ese Update(JCOP download/LS download) +** +** Returns: SUCCESS of ok +** +*******************************************************************************/ +uint8_t checkeSEClientRequired(ESE_CLIENT_INTF intf ); + +uint8_t getJcopUpdateRequired(); +uint8_t getLsUpdateRequired(); +uint8_t getJcopUpdateIntf(); +uint8_t getLsUpdateIntf(); +bool geteSETerminalId(char*); +bool geteUICCTerminalId(char*); +bool getNfcSeTerminalId(char*); +void setJcopUpdateRequired(uint8_t state); +void setLsUpdateRequired(uint8_t state); +#endif /* CLIENT_INTF_H_ */ diff --git a/inc/phNxpLog.h b/inc/phNxpLog.h new file mode 100644 index 0000000..ecbf6bb --- /dev/null +++ b/inc/phNxpLog.h @@ -0,0 +1,367 @@ +/* + * Copyright (C) 2010-2014 NXP Semiconductors + * + * 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. + */ + +#if !defined(NXPLOG__H_INCLUDED) +#define NXPLOG__H_INCLUDED +#include <log/log.h> + +typedef struct nci_log_level { + uint8_t global_log_level; + uint8_t extns_log_level; + uint8_t hal_log_level; + uint8_t dnld_log_level; + uint8_t tml_log_level; + uint8_t ncix_log_level; + uint8_t ncir_log_level; +} nci_log_level_t; + +/* global log level Ref */ +extern nci_log_level_t gLog_level; +extern bool nfc_debug_enabled; +/* define log module included when compile */ +#define ENABLE_EXTNS_TRACES TRUE +#define ENABLE_HAL_TRACES TRUE +#define ENABLE_TML_TRACES TRUE +#define ENABLE_FWDNLD_TRACES TRUE +#define ENABLE_NCIX_TRACES TRUE +#define ENABLE_NCIR_TRACES TRUE + +#define ENABLE_HCPX_TRACES FALSE +#define ENABLE_HCPR_TRACES FALSE + +/* ####################### Set the log module name in .conf file + * ########################## */ +#define NAME_NXPLOG_EXTNS_LOGLEVEL "NXPLOG_EXTNS_LOGLEVEL" +#define NAME_NXPLOG_HAL_LOGLEVEL "NXPLOG_NCIHAL_LOGLEVEL" +#define NAME_NXPLOG_NCIX_LOGLEVEL "NXPLOG_NCIX_LOGLEVEL" +#define NAME_NXPLOG_NCIR_LOGLEVEL "NXPLOG_NCIR_LOGLEVEL" +#define NAME_NXPLOG_FWDNLD_LOGLEVEL "NXPLOG_FWDNLD_LOGLEVEL" +#define NAME_NXPLOG_TML_LOGLEVEL "NXPLOG_TML_LOGLEVEL" + +/* ####################### Set the log module name by Android property + * ########################## */ +#define PROP_NAME_NXPLOG_GLOBAL_LOGLEVEL "nfc.nxp_log_level_global" +#define PROP_NAME_NXPLOG_EXTNS_LOGLEVEL "nfc.nxp_log_level_extns" +#define PROP_NAME_NXPLOG_HAL_LOGLEVEL "nfc.nxp_log_level_hal" +#define PROP_NAME_NXPLOG_NCI_LOGLEVEL "nfc.nxp_log_level_nci" +#define PROP_NAME_NXPLOG_FWDNLD_LOGLEVEL "nfc.nxp_log_level_dnld" +#define PROP_NAME_NXPLOG_TML_LOGLEVEL "nfc.nxp_log_level_tml" + +/* ####################### Set the logging level for EVERY COMPONENT here + * ######################## :START: */ +#define NXPLOG_LOG_SILENT_LOGLEVEL 0x00 +#define NXPLOG_LOG_ERROR_LOGLEVEL 0x01 +#define NXPLOG_LOG_WARN_LOGLEVEL 0x02 +#define NXPLOG_LOG_DEBUG_LOGLEVEL 0x03 +/* ####################### Set the default logging level for EVERY COMPONENT + * here ########################## :END: */ + +/* The Default log level for all the modules. */ +#define NXPLOG_DEFAULT_LOGLEVEL NXPLOG_LOG_ERROR_LOGLEVEL + +/* ################################################################################################################ + */ +/* ############################################### Component Names + * ################################################ */ +/* ################################################################################################################ + */ + +extern const char* NXPLOG_ITEM_EXTNS; /* Android logging tag for NxpExtns */ +extern const char* NXPLOG_ITEM_NCIHAL; /* Android logging tag for NxpNciHal */ +extern const char* NXPLOG_ITEM_NCIX; /* Android logging tag for NxpNciX */ +extern const char* NXPLOG_ITEM_NCIR; /* Android logging tag for NxpNciR */ +extern const char* NXPLOG_ITEM_FWDNLD; /* Android logging tag for NxpFwDnld */ +extern const char* NXPLOG_ITEM_TML; /* Android logging tag for NxpTml */ + +#ifdef NXP_HCI_REQ +extern const char* NXPLOG_ITEM_HCPX; /* Android logging tag for NxpHcpX */ +extern const char* NXPLOG_ITEM_HCPR; /* Android logging tag for NxpHcpR */ +#endif /*NXP_HCI_REQ*/ + +/* ######################################## Defines used for Logging data + * ######################################### */ +#ifdef NXP_VRBS_REQ +#define NXPLOG_FUNC_ENTRY(COMP) \ + LOG_PRI(ANDROID_LOG_VERBOSE, (COMP), "+:%s", (__func__)) +#define NXPLOG_FUNC_EXIT(COMP) \ + LOG_PRI(ANDROID_LOG_VERBOSE, (COMP), "-:%s", (__func__)) +#endif /*NXP_VRBS_REQ*/ + +/* ################################################################################################################ + */ +/* ######################################## Logging APIs of actual modules + * ######################################## */ +/* ################################################################################################################ + */ +/* Logging APIs used by NxpExtns module */ +#if (ENABLE_EXTNS_TRACES == TRUE) +#define NXPLOG_EXTNS_D(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.extns_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_EXTNS, __VA_ARGS__); \ + } +#define NXPLOG_EXTNS_W(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.extns_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_EXTNS, __VA_ARGS__); \ + } +#define NXPLOG_EXTNS_E(...) \ + { \ + if (gLog_level.extns_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL) \ + LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_EXTNS, __VA_ARGS__); \ + } +#else +#define NXPLOG_EXTNS_D(...) +#define NXPLOG_EXTNS_W(...) +#define NXPLOG_EXTNS_E(...) +#endif /* Logging APIs used by NxpExtns module */ + +/* Logging APIs used by NxpNciHal module */ +#if (ENABLE_HAL_TRACES == TRUE) +#define NXPLOG_NCIHAL_D(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.hal_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_NCIHAL, __VA_ARGS__); \ + } +#define NXPLOG_NCIHAL_W(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.hal_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_NCIHAL, __VA_ARGS__); \ + } +#define NXPLOG_NCIHAL_E(...) \ + { \ + if (gLog_level.hal_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL) \ + LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_NCIHAL, __VA_ARGS__); \ + } +#else +#define NXPLOG_NCIHAL_D(...) +#define NXPLOG_NCIHAL_W(...) +#define NXPLOG_NCIHAL_E(...) +#endif /* Logging APIs used by HAL module */ + +/* Logging APIs used by NxpNciX module */ +#if (ENABLE_NCIX_TRACES == TRUE) +#define NXPLOG_NCIX_D(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.ncix_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_NCIX, __VA_ARGS__); \ + } +#define NXPLOG_NCIX_W(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.ncix_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_NCIX, __VA_ARGS__); \ + } +#define NXPLOG_NCIX_E(...) \ + { \ + if (gLog_level.ncix_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL) \ + LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_NCIX, __VA_ARGS__); \ + } +#else +#define NXPLOG_NCIX_D(...) +#define NXPLOG_NCIX_W(...) +#define NXPLOG_NCIX_E(...) +#endif /* Logging APIs used by NCIx module */ + +/* Logging APIs used by NxpNciR module */ +#if (ENABLE_NCIR_TRACES == TRUE) +#define NXPLOG_NCIR_D(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.ncir_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_NCIR, __VA_ARGS__); \ + } +#define NXPLOG_NCIR_W(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.ncir_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_NCIR, __VA_ARGS__); \ + } +#define NXPLOG_NCIR_E(...) \ + { \ + if (gLog_level.ncir_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL) \ + LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_NCIR, __VA_ARGS__); \ + } +#else +#define NXPLOG_NCIR_D(...) +#define NXPLOG_NCIR_W(...) +#define NXPLOG_NCIR_E(...) +#endif /* Logging APIs used by NCIR module */ + +/* Logging APIs used by NxpFwDnld module */ +#if (ENABLE_FWDNLD_TRACES == TRUE) +#define NXPLOG_FWDNLD_D(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.dnld_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#define NXPLOG_FWDNLD_W(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.dnld_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#define NXPLOG_FWDNLD_E(...) \ + { \ + if (gLog_level.dnld_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL) \ + LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#else +#define NXPLOG_FWDNLD_D(...) +#define NXPLOG_FWDNLD_W(...) +#define NXPLOG_FWDNLD_E(...) +#endif /* Logging APIs used by NxpFwDnld module */ + +/* Logging APIs used by NxpTml module */ +#if (ENABLE_TML_TRACES == TRUE) +#define NXPLOG_TML_D(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.tml_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_TML, __VA_ARGS__); \ + } +#define NXPLOG_TML_W(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.tml_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_TML, __VA_ARGS__); \ + } +#define NXPLOG_TML_E(...) \ + { \ + if (gLog_level.tml_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL) \ + LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_TML, __VA_ARGS__); \ + } +#else +#define NXPLOG_TML_D(...) +#define NXPLOG_TML_W(...) +#define NXPLOG_TML_E(...) +#endif /* Logging APIs used by NxpTml module */ + +#ifdef NXP_HCI_REQ +/* Logging APIs used by NxpHcpX module */ +#if (ENABLE_HCPX_TRACES == TRUE) +#define NXPLOG_HCPX_D(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.dnld_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#define NXPLOG_HCPX_W(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.dnld_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#define NXPLOG_HCPX_E(...) \ + { \ + if (gLog_level.dnld_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL) \ + LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#else +#define NXPLOG_HCPX_D(...) +#define NXPLOG_HCPX_W(...) +#define NXPLOG_HCPX_E(...) +#endif /* Logging APIs used by NxpHcpX module */ + +/* Logging APIs used by NxpHcpR module */ +#if (ENABLE_HCPR_TRACES == TRUE) +#define NXPLOG_HCPR_D(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.dnld_log_level >= NXPLOG_LOG_DEBUG_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_DEBUG, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#define NXPLOG_HCPR_W(...) \ + { \ + if ((nfc_debug_enabled) || \ + (gLog_level.dnld_log_level >= NXPLOG_LOG_WARN_LOGLEVEL)) \ + LOG_PRI(ANDROID_LOG_WARN, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#define NXPLOG_HCPR_E(...) \ + { \ + if (gLog_level.dnld_log_level >= NXPLOG_LOG_ERROR_LOGLEVEL) \ + LOG_PRI(ANDROID_LOG_ERROR, NXPLOG_ITEM_FWDNLD, __VA_ARGS__); \ + } +#else +#define NXPLOG_HCPR_D(...) +#define NXPLOG_HCPR_W(...) +#define NXPLOG_HCPR_E(...) +#endif /* Logging APIs used by NxpHcpR module */ +#endif /* NXP_HCI_REQ */ + +#ifdef NXP_VRBS_REQ +#if (ENABLE_EXTNS_TRACES == TRUE) +#define NXPLOG_EXTNS_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_EXTNS) +#define NXPLOG_EXTNS_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_EXTNS) +#else +#define NXPLOG_EXTNS_ENTRY() +#define NXPLOG_EXTNS_EXIT() +#endif + +#if (ENABLE_HAL_TRACES == TRUE) +#define NXPLOG_NCIHAL_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_NCIHAL) +#define NXPLOG_NCIHAL_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_NCIHAL) +#else +#define NXPLOG_NCIHAL_ENTRY() +#define NXPLOG_NCIHAL_EXIT() +#endif + +#if (ENABLE_NCIX_TRACES == TRUE) +#define NXPLOG_NCIX_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_NCIX) +#define NXPLOG_NCIX_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_NCIX) +#else +#define NXPLOG_NCIX_ENTRY() +#define NXPLOG_NCIX_EXIT() +#endif + +#if (ENABLE_NCIR_TRACES == TRUE) +#define NXPLOG_NCIR_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_NCIR) +#define NXPLOG_NCIR_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_NCIR) +#else +#define NXPLOG_NCIR_ENTRY() +#define NXPLOG_NCIR_EXIT() +#endif + +#ifdef NXP_HCI_REQ + +#if (ENABLE_HCPX_TRACES == TRUE) +#define NXPLOG_HCPX_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_HCPX) +#define NXPLOG_HCPX_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_HCPX) +#else +#define NXPLOG_HCPX_ENTRY() +#define NXPLOG_HCPX_EXIT() +#endif + +#if (ENABLE_HCPR_TRACES == TRUE) +#define NXPLOG_HCPR_ENTRY() NXPLOG_FUNC_ENTRY(NXPLOG_ITEM_HCPR) +#define NXPLOG_HCPR_EXIT() NXPLOG_FUNC_EXIT(NXPLOG_ITEM_HCPR) +#else +#define NXPLOG_HCPR_ENTRY() +#define NXPLOG_HCPR_EXIT() +#endif +#endif /* NXP_HCI_REQ */ + +#endif /* NXP_VRBS_REQ */ + +void phNxpLog_InitializeLogLevel(void); + +#endif /* NXPLOG__H_INCLUDED */ diff --git a/jcos_client/inc/JcDnld.h b/jcos_client/inc/JcDnld.h new file mode 100644 index 0000000..ac27342 --- /dev/null +++ b/jcos_client/inc/JcDnld.h @@ -0,0 +1,64 @@ + /* + * Copyright (C) 2015-2018 NXP Semiconductors + * + * 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 JCDNLD_H_ +#define JCDNLD_H_ + +#include "IChannel.h" +/******************************************************************************* +** +** Function: JCDNLD_Init +** +** Description: Initializes the JCOP library and opens the DWP communication channel +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +unsigned char JCDNLD_Init(IChannel *channel); + +/******************************************************************************* +** +** Function: JCDNLD_StartDownload +** +** Description: Starts the JCOP update +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +unsigned char JCDNLD_StartDownload(); + +/******************************************************************************* +** +** Function: JCDNLD_DeInit +** +** Description: Deinitializes the JCOP Lib +** +** Returns: true if ok. +** +*******************************************************************************/ +bool JCDNLD_DeInit(); + +/******************************************************************************* +** +** Function: JCDNLD_CheckVersion +** +** Description: Check the existing JCOP OS version +** +** Returns: true if ok. +** +*******************************************************************************/ +bool JCDNLD_CheckVersion(); +#endif diff --git a/jcos_client/inc/JcopOsDownload.h b/jcos_client/inc/JcopOsDownload.h new file mode 100644 index 0000000..9afca68 --- /dev/null +++ b/jcos_client/inc/JcopOsDownload.h @@ -0,0 +1,155 @@ + /* + * Copyright (C) 2015-2018 NXP Semiconductors + * + * 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. + */ + +#include "data_types.h" +#include "IChannel.h" +#include <stdio.h> + +typedef struct JcopOs_TranscieveInfo +{ + int32_t timeout; + uint8_t sRecvData[1024]; + uint8_t *sSendData; + int32_t sSendlength; + int sRecvlength; +}JcopOs_TranscieveInfo_t; + +typedef struct JcopOs_Version_Info +{ + uint8_t osid; + uint8_t ver1; + uint8_t ver0; + uint8_t OtherValid; + uint8_t ver_status; +}JcopOs_Version_Info_t; +typedef struct JcopOs_ImageInfo +{ + FILE *fp; + int fls_size; + char fls_path[256]; + int index; + uint8_t cur_state; + JcopOs_Version_Info_t version_info; +}JcopOs_ImageInfo_t; +typedef struct JcopOs_Dwnld_Context +{ + JcopOs_Version_Info_t version_info; + JcopOs_ImageInfo_t Image_info; + JcopOs_TranscieveInfo_t pJcopOs_TransInfo; + IChannel_t *channel; +}JcopOs_Dwnld_Context_t,*pJcopOs_Dwnld_Context_t; + + +static uint8_t Trigger_APDU[] = {0x4F, 0x70, 0x80, 0x13, 0x04, 0xDE, 0xAD, 0xBE, 0xEF, 0x00}; +static uint8_t GetInfo_APDU[] = {0x00, //CLA + 0xA4, 0x04, 0x00, 0x0C, //INS, P1, P2, Lc + 0xD2, 0x76, 0x00, 0x00, 0x85, 0x41, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, //Data + 0x00 //Le + }; +static uint8_t GetInfo_Data[] = {0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x72, 0x4F, 0x53}; + +static uint8_t Uai_Trigger_APDU[] = {0x4F, 0x70, 0x80, 0x13, 0x04, 0x4A, 0x55, 0x41, 0x49, 0x00}; +static uint8_t Uai_GetInfo_APDU[] = {0x80,0xCA,0x00,0xFE,0x02,0xDF,0x43,0x00}; + +#define OSID_OFFSET 9 +#define VER1_OFFSET 10 +#define VER0_OFFSET 11 +#define JCOPOS_HEADER_LEN 5 + +#define JCOP_UPDATE_STATE0 0 +#define JCOP_UPDATE_STATE1 1 +#define JCOP_UPDATE_STATE2 2 +#define JCOP_UPDATE_STATE3 3 +#define JCOP_UPDATE_STATE_TRIGGER_APDU 4 + +#define JCOP_MAX_RETRY_CNT 3 +//#define JCOP_INFO_PATH "/data/vendor/nfc/jcop_info.txt" + +#define JCOP_MAX_BUF_SIZE 10240 + +class JcopOsDwnld +{ +public: + +/******************************************************************************* +** +** Function: getInstance +** +** Description: Get the SecureElement singleton object. +** +** Returns: SecureElement object. +** +*******************************************************************************/ +static JcopOsDwnld* getInstance (); + + +/******************************************************************************* +** +** Function: getJcopOsFileInfo +** +** Description: Verify all the updater files required for download +** are present or not +** +** Returns: True if ok. +** +*******************************************************************************/ +bool getJcopOsFileInfo(); + +/******************************************************************************* +** +** Function: initialize +** +** Description: Initialize all member variables. +** native: Native data. +** +** Returns: True if ok. +** +*******************************************************************************/ +bool initialize (IChannel_t *channel); + +/******************************************************************************* +** +** Function: finalize +** +** Description: Release all resources. +** +** Returns: None +** +*******************************************************************************/ +void finalize (); + +tJBL_STATUS JcopOs_Download(); + +tJBL_STATUS TriggerApdu(JcopOs_ImageInfo_t* pVersionInfo, tJBL_STATUS status, JcopOs_TranscieveInfo_t* pTranscv_Info); + +tJBL_STATUS UaiTriggerApdu(JcopOs_ImageInfo_t* pVersionInfo, tJBL_STATUS status, JcopOs_TranscieveInfo_t* pTranscv_Info); + +tJBL_STATUS GetInfo(JcopOs_ImageInfo_t* pVersionInfo, tJBL_STATUS status, JcopOs_TranscieveInfo_t* pTranscv_Info); + +tJBL_STATUS load_JcopOS_image(JcopOs_ImageInfo_t *Os_info, tJBL_STATUS status, JcopOs_TranscieveInfo_t *pTranscv_Info); + +tJBL_STATUS JcopOs_update_seq_handler(); + +tJBL_STATUS SendUAICmds(JcopOs_ImageInfo_t *Os_info, tJBL_STATUS status, JcopOs_TranscieveInfo_t *pTranscv_Info); + +IChannel_t *mchannel; + +private: +static JcopOsDwnld sJcopDwnld; +bool mIsInit; +tJBL_STATUS GetJcopOsState(JcopOs_ImageInfo_t *Os_info, uint8_t *counter); +tJBL_STATUS SetJcopOsState(JcopOs_ImageInfo_t *Os_info, uint8_t state); +}; diff --git a/jcos_client/src/JcDnld.cpp b/jcos_client/src/JcDnld.cpp new file mode 100644 index 0000000..b607e48 --- /dev/null +++ b/jcos_client/src/JcDnld.cpp @@ -0,0 +1,172 @@ + /* + * Copyright (C) 2015-2018 NXP Semiconductors + * + * 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. + */ +#include <android-base/stringprintf.h> +#include <base/logging.h> +#include <data_types.h> +#include "JcDnld.h" +#include "JcopOsDownload.h" + +using android::base::StringPrintf; + +JcopOsDwnld *jd; +IChannel_t *channel; +static bool inUse = false; +static int16_t jcHandle; +extern pJcopOs_Dwnld_Context_t gpJcopOs_Dwnld_Context; +/******************************************************************************* +** +** Function: JCDNLD_Init +** +** Description: Initializes the JCOP library and opens the DWP communication channel +** +** Returns: true if ok. +** +*******************************************************************************/ +tJBL_STATUS JCDNLD_Init(IChannel_t *channel) +{ + static const char fn[] = "JCDNLD_Init"; + bool stat = false; + jcHandle = EE_ERROR_OPEN_FAIL; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter", fn); + + if (inUse == true) + { + return STATUS_INUSE; + } + else if(channel == NULL) + { + return STATUS_FAILED; + } + /*TODO: inUse assignment should be with protection like using semaphore*/ + inUse = true; + jd = JcopOsDwnld::getInstance(); + stat = jd->initialize (channel); + if(stat != true) + { + LOG(ERROR) << StringPrintf("%s: failed", fn); + } + else + { + if((channel != NULL) && + (channel->open) != NULL) + { + jcHandle = channel->open(); + if(jcHandle == EE_ERROR_OPEN_FAIL) + { + LOG(ERROR) << StringPrintf("%s:Open DWP communication is failed", fn); + stat = false; + } + else + { + LOG(ERROR) << StringPrintf("%s:Open DWP communication is success", fn); + stat = true; + } + } + else + { + LOG(ERROR) << StringPrintf("%s: NULL DWP channel", fn); + stat = false; + } + } + return (stat == true)?STATUS_OK:STATUS_FAILED; +} + +/******************************************************************************* +** +** Function: JCDNLD_StartDownload +** +** Description: Starts the JCOP update +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +tJBL_STATUS JCDNLD_StartDownload() +{ + static const char fn[] = "JCDNLD_StartDownload"; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Enter", fn); + tJBL_STATUS status = STATUS_FAILED; + status = jd->JcopOs_Download(); + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Exit; status=0x0%X", fn, status); + return status; +} + +/******************************************************************************* +** +** Function: JCDNLD_DeInit +** +** Description: Deinitializes the JCOP Lib +** +** Returns: true if ok. +** +*******************************************************************************/ +bool JCDNLD_DeInit() +{ + static const char fn[] = "JCDNLD_DeInit"; + bool stat = false; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter", fn); + + if(gpJcopOs_Dwnld_Context != NULL) + { + channel = gpJcopOs_Dwnld_Context->channel; + if((channel != NULL) && (channel->doeSE_JcopDownLoadReset != NULL)) + { + channel->doeSE_JcopDownLoadReset(); + if(channel->close != NULL) + { + stat = channel->close(jcHandle); + if(stat != true) + { + LOG(ERROR) << StringPrintf("%s:closing DWP channel is failed", fn); + } + } + else + { + LOG(ERROR) << StringPrintf("%s: NULL fp DWP_close", fn); + stat = false; + } + } + } + else + { + LOG(ERROR) << StringPrintf("%s: NULL dwnld context", fn); + } + jd->finalize(); + /*TODO: inUse assignment should be with protection like using semaphore*/ + inUse = false; + return stat; +} + +/******************************************************************************* +** +** Function: JCDNLD_CheckVersion +** +** Description: Check the existing JCOP OS version +** +** Returns: true if ok. +** +*******************************************************************************/ +bool JCDNLD_CheckVersion() +{ + + /** + * Need to implement in case required + * */ + return true; +} diff --git a/jcos_client/src/JcopOsDownload.cpp b/jcos_client/src/JcopOsDownload.cpp new file mode 100644 index 0000000..ab6453e --- /dev/null +++ b/jcos_client/src/JcopOsDownload.cpp @@ -0,0 +1,1041 @@ + /* + * Copyright (C) 2015-2018 NXP Semiconductors + * + * 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. + */ +#include <android-base/stringprintf.h> +#include <base/logging.h> +#include <semaphore.h> +#include <JcopOsDownload.h> +#include <IChannel.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/stat.h> + +using android::base::StringPrintf; + +JcopOsDwnld JcopOsDwnld::sJcopDwnld; +static int32_t gTransceiveTimeout = 120000; +uint8_t isUaiEnabled = false; +uint8_t isPatchUpdate = false; + +tJBL_STATUS (JcopOsDwnld::*JcopOs_dwnld_seqhandler[])( + JcopOs_ImageInfo_t* pContext, tJBL_STATUS status, JcopOs_TranscieveInfo_t* pInfo)={ + &JcopOsDwnld::UaiTriggerApdu, + &JcopOsDwnld::SendUAICmds, + &JcopOsDwnld::TriggerApdu, + &JcopOsDwnld::GetInfo, + &JcopOsDwnld::load_JcopOS_image, + &JcopOsDwnld::GetInfo, + &JcopOsDwnld::load_JcopOS_image, + &JcopOsDwnld::GetInfo, + &JcopOsDwnld::load_JcopOS_image, + NULL + }; + +pJcopOs_Dwnld_Context_t gpJcopOs_Dwnld_Context = NULL; +static const char *path[3] = {"/vendor/etc/JcopOs_Update1.apdu", + "/vendor/etc/JcopOs_Update2.apdu", + "/vendor/etc/JcopOs_Update3.apdu"}; +static const char *JCOP_INFO_PATH[2] = {"/data/vendor/nfc/jcop_info.txt", + "/data/vendor/secure_element/jcop_info.txt"}; + +static const char *uai_path[2] = {"/vendor/etc/cci.jcsh", + "/vendor/etc/jci.jcsh"}; + +inline int FSCANF_BYTE(FILE *stream, const char *format, void* pVal) +{ + int Result = 0; + + if((NULL != stream) && (NULL != format) && (NULL != pVal)) + { + unsigned int dwVal; + unsigned char* pTmp = (unsigned char*)pVal; + Result = fscanf(stream, format, &dwVal); + + (*pTmp) = (unsigned char)(dwVal & 0x000000FF); + } + return Result; +} + +/******************************************************************************* +** +** Function: getInstance +** +** Description: Get the JcopOsDwnld singleton object. +** +** Returns: JcopOsDwnld object. +** +*******************************************************************************/ +JcopOsDwnld* JcopOsDwnld::getInstance() +{ + JcopOsDwnld *jd = new JcopOsDwnld(); + return jd; +} + +/******************************************************************************* +** +** Function: getJcopOsFileInfo +** +** Description: Verify all the updater files required for download +** are present or not +** +** Returns: True if ok. +** +*******************************************************************************/ +bool JcopOsDwnld::getJcopOsFileInfo() +{ + static const char fn [] = "JcopOsDwnld::getJcopOsFileInfo"; + bool status = true; + struct stat st; + isPatchUpdate = false; + int isFilepresent = 0; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Enter", fn); + for (int num = 0; num < 2; num++) + { + if (stat(uai_path[num], &st)) + { + status = false; + } + } + /*If UAI specific files are present*/ + if(status == true) + { + isUaiEnabled = true; + for (int num = 0; num < 3; num++) + { + if (stat(path[num], &st)) + status = false; + else + isFilepresent++; + } + if(isFilepresent == 1 && status == false && !(stat(path[0], &st))) + { + isPatchUpdate = true; + status = true; + } else if(isFilepresent == 2 && status == false) { + isPatchUpdate = false; + status = false; + } + } + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Exit Status %d", fn, status); + return status; +} + +/******************************************************************************* +** +** Function: initialize +** +** Description: Initialize all member variables. +** native: Native data. +** +** Returns: True if ok. +** +*******************************************************************************/ +bool JcopOsDwnld::initialize (IChannel_t *channel) +{ + static const char fn [] = "JcopOsDwnld::initialize"; + isUaiEnabled = false; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf ("%s: enter", fn); + + if (!getJcopOsFileInfo()) + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: insufficient resources, file not present", fn); + return (false); + } + gpJcopOs_Dwnld_Context = (pJcopOs_Dwnld_Context_t)malloc(sizeof(JcopOs_Dwnld_Context_t)); + if(gpJcopOs_Dwnld_Context != NULL) + { + memset((void *)gpJcopOs_Dwnld_Context, 0, (uint32_t)sizeof(JcopOs_Dwnld_Context_t)); + gpJcopOs_Dwnld_Context->channel = (IChannel_t*)malloc(sizeof(IChannel_t)); + if(gpJcopOs_Dwnld_Context->channel != NULL) + { + memset(gpJcopOs_Dwnld_Context->channel, 0, sizeof(IChannel_t)); + } + else + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Memory allocation for IChannel is failed", fn); + return (false); + } + gpJcopOs_Dwnld_Context->pJcopOs_TransInfo.sSendData = (uint8_t*)malloc(sizeof(uint8_t)*JCOP_MAX_BUF_SIZE); + if(gpJcopOs_Dwnld_Context->pJcopOs_TransInfo.sSendData != NULL) + { + memset(gpJcopOs_Dwnld_Context->pJcopOs_TransInfo.sSendData, 0, JCOP_MAX_BUF_SIZE); + } + else + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Memory allocation for SendBuf is failed", fn); + return (false); + } + } + else + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Memory allocation failed", fn); + return (false); + } + mIsInit = true; + memcpy(gpJcopOs_Dwnld_Context->channel, channel, sizeof(IChannel_t)); + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf ("%s: exit", fn); + return (true); +} +/******************************************************************************* +** +** Function: finalize +** +** Description: Release all resources. +** +** Returns: None +** +*******************************************************************************/ +void JcopOsDwnld::finalize () +{ + static const char fn [] = "JcopOsDwnld::finalize"; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf ("%s: enter", fn); + mIsInit = false; + if(gpJcopOs_Dwnld_Context != NULL) + { + if(gpJcopOs_Dwnld_Context->channel != NULL) + { + free(gpJcopOs_Dwnld_Context->channel); + gpJcopOs_Dwnld_Context->channel = NULL; + } + if(gpJcopOs_Dwnld_Context->pJcopOs_TransInfo.sSendData != NULL) + { + free(gpJcopOs_Dwnld_Context->pJcopOs_TransInfo.sSendData); + gpJcopOs_Dwnld_Context->pJcopOs_TransInfo.sSendData = NULL; + } + free(gpJcopOs_Dwnld_Context); + gpJcopOs_Dwnld_Context = NULL; + } + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf ("%s: exit", fn); +} + +/******************************************************************************* +** +** Function: JcopOs_Download +** +** Description: Starts the OS download sequence +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::JcopOs_Download() +{ + static const char fn [] = "JcopOsDwnld::JcopOs_Download"; + tJBL_STATUS wstatus = STATUS_FAILED; + uint8_t retry_cnt = 0x00; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Enter:", fn); + if(mIsInit == false) + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf ("%s: JcopOs Dwnld is not initialized", fn); + wstatus = STATUS_FAILED; + } + else + { + do + { + wstatus = JcopOsDwnld::JcopOs_update_seq_handler(); + if(wstatus == STATUS_FAILED) + retry_cnt++; + else + break; + }while(retry_cnt < JCOP_MAX_RETRY_CNT); + } + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Exit; status = 0x%x", fn, wstatus); + return wstatus; +} +/******************************************************************************* +** +** Function: JcopOs_update_seq_handler +** +** Description: Performs the JcopOS download sequence +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::JcopOs_update_seq_handler() +{ + static const char fn[] = "JcopOsDwnld::JcopOs_update_seq_handler"; + uint8_t seq_counter = 0; + JcopOs_ImageInfo_t update_info = (JcopOs_ImageInfo_t )gpJcopOs_Dwnld_Context->Image_info; + JcopOs_TranscieveInfo_t trans_info = (JcopOs_TranscieveInfo_t )gpJcopOs_Dwnld_Context->pJcopOs_TransInfo; + update_info.index = 0x00; + update_info.cur_state = 0x00; + tJBL_STATUS status = STATUS_FAILED; + + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter", fn); + status = GetJcopOsState(&update_info, &seq_counter); + if(status != STATUS_SUCCESS) + { + LOG(ERROR) << StringPrintf("Error in getting JcopOsState info"); + } + else + { + LOG(ERROR) << StringPrintf("seq_counter %d", seq_counter); + while((JcopOs_dwnld_seqhandler[seq_counter]) != NULL ) + { + status = STATUS_FAILED; + status = (*this.*(JcopOs_dwnld_seqhandler[seq_counter]))(&update_info, status, &trans_info ); + if(STATUS_SUCCESS != status) + { + LOG(ERROR) << StringPrintf("%s: exiting; status=0x0%X", fn, status); + break; + } + seq_counter++; + } + if(status == STATUS_SUCCESS) + { + int32_t recvBufferActualSize = 0; + uint8_t select[] = {0, 0xA4, 0x04, 0, 0}; + uint16_t handle = gpJcopOs_Dwnld_Context->channel->open(); + usleep(100*1000); + LOG(ERROR) << StringPrintf("%s: Issue First APDU", fn); + gpJcopOs_Dwnld_Context->channel->transceive(select, sizeof(select), + trans_info.sRecvData, 1024, recvBufferActualSize, trans_info.timeout); + + gpJcopOs_Dwnld_Context->channel->close(handle); + } + } + return status; +} + +/******************************************************************************* +** +** Function: TriggerApdu +** +** Description: Switch to updater OS +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::TriggerApdu(JcopOs_ImageInfo_t* pVersionInfo, tJBL_STATUS status, JcopOs_TranscieveInfo_t* pTranscv_Info) +{ + static const char fn [] = "JcopOsDwnld::TriggerApdu"; + bool stat = false; + IChannel_t *mchannel = gpJcopOs_Dwnld_Context->channel; + int32_t recvBufferActualSize = 0; + + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter;", fn); + if(pTranscv_Info == NULL || + pVersionInfo == NULL) + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Invalid parameter", fn); + status = STATUS_FAILED; + } + else + { + pTranscv_Info->timeout = gTransceiveTimeout; + pTranscv_Info->sSendlength = (int32_t)sizeof(Trigger_APDU); + pTranscv_Info->sRecvlength = 1024;//(int32_t)sizeof(int32_t); + memcpy(pTranscv_Info->sSendData, Trigger_APDU, pTranscv_Info->sSendlength); + + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Calling Secure Element Transceive", fn); + stat = mchannel->transceiveRaw (pTranscv_Info->sSendData, + pTranscv_Info->sSendlength, + pTranscv_Info->sRecvData, + pTranscv_Info->sRecvlength, + recvBufferActualSize, + pTranscv_Info->timeout); + if (stat != true) + { + status = STATUS_FAILED; + LOG(ERROR) << StringPrintf("%s: SE transceive failed status = 0x%X", fn, status);//Stop JcopOs Update + } + else if(((pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x68) && + (pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x81))|| + ((pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x90) && + (pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00))|| + ((pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x6F) && + (pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00))) + { + mchannel->doeSE_JcopDownLoadReset(); + status = STATUS_OK; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Trigger APDU Transceive status = 0x%X", fn, status); + } + else + { + /* status {90, 00} */ + status = STATUS_OK; + } + } + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: exit; status = 0x%X", fn, status); + return status; +} + +/******************************************************************************* +** +** Function: SendUAICmds +** +** Description: Perform UAI Authentication +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::SendUAICmds(JcopOs_ImageInfo_t* Os_info, tJBL_STATUS status, JcopOs_TranscieveInfo_t* pTranscv_Info) +{ + static const char fn [] = "JcopOsDwnld::SendUAICmds"; + bool stat = false; + int wResult; + int32_t wIndex,wCount=0; + int32_t wLen; + IChannel_t *mchannel = gpJcopOs_Dwnld_Context->channel; + int32_t recvBufferActualSize = 0; + int i = 0; + + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter;", fn); + + if(!isUaiEnabled) + { + goto exit; + } + if(pTranscv_Info == NULL || + Os_info == NULL) + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Invalid parameter", fn); + status = STATUS_FAILED; + } + for(i = 0; i < 2; i++) + { + Os_info->fp = fopen(uai_path[i], "r"); + if (Os_info->fp == NULL) { + LOG(ERROR) << StringPrintf("Error opening CCI file <%s> for reading: %s", + Os_info->fls_path, strerror(errno)); + return STATUS_FILE_NOT_FOUND; + } + wResult = fseek(Os_info->fp, 0L, SEEK_END); + if (wResult) { + LOG(ERROR) << StringPrintf("Error seeking end CCI file %s", strerror(errno)); + goto exit; + } + Os_info->fls_size = ftell(Os_info->fp); + if (Os_info->fls_size < 0) { + LOG(ERROR) << StringPrintf("Error ftelling file %s", strerror(errno)); + goto exit; + } + wResult = fseek(Os_info->fp, 6L, SEEK_SET); + if (wResult) { + LOG(ERROR) << StringPrintf("Error seeking start image file %s", strerror(errno)); + goto exit; + } + { + wIndex=0; + wLen=0; + wCount=0; + memset(pTranscv_Info->sSendData,0x00,JCOP_MAX_BUF_SIZE); + pTranscv_Info->sSendlength=0; + + LOG(ERROR) << StringPrintf("%s; wIndex = 0", fn); + for(wCount =0; (wCount < 5 && !feof(Os_info->fp)); wCount++, wIndex++) + { + wResult = FSCANF_BYTE(Os_info->fp,"%2X",&pTranscv_Info->sSendData[wIndex]); + } + if(wResult != 0) + { + wLen = pTranscv_Info->sSendData[4]; + LOG(ERROR) << StringPrintf("%s; Read 5byes success & len=%d", fn,wLen); + if(wLen == 0x00) + { + LOG(ERROR) << StringPrintf("%s: Extended APDU", fn); + wResult = FSCANF_BYTE(Os_info->fp,"%2X",&pTranscv_Info->sSendData[wIndex++]); + wResult = FSCANF_BYTE(Os_info->fp,"%2X",&pTranscv_Info->sSendData[wIndex++]); + wLen = ((pTranscv_Info->sSendData[5] << 8) | (pTranscv_Info->sSendData[6])); + } + for(wCount =0; (wCount < wLen && !feof(Os_info->fp)); wCount++, wIndex++) + { + wResult = FSCANF_BYTE(Os_info->fp,"%2X",&pTranscv_Info->sSendData[wIndex]); + } + } + else + { + LOG(ERROR) << StringPrintf("%s: JcopOs image Read failed", fn); + goto exit; + } + pTranscv_Info->sSendlength = wIndex; + LOG(ERROR) << StringPrintf("%s: start transceive for length %d", fn, pTranscv_Info->sSendlength); + if((pTranscv_Info->sSendlength != 0x03) && + (pTranscv_Info->sSendData[0] != 0x00) && + (pTranscv_Info->sSendData[1] != 0x00)) + { + + stat = mchannel->transceiveRaw(pTranscv_Info->sSendData, + pTranscv_Info->sSendlength, + pTranscv_Info->sRecvData, + pTranscv_Info->sRecvlength, + recvBufferActualSize, + pTranscv_Info->timeout); + } + else + { + LOG(ERROR) << StringPrintf("%s: Invalid packet", fn); + goto exit; + } + if(stat != true) + { + LOG(ERROR) << StringPrintf("%s: Transceive failed; status=0x%X", fn, stat); + status = STATUS_FAILED; + goto exit; + } + else if(recvBufferActualSize != 0 && + pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x90 && + pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00) + { + status = STATUS_SUCCESS; + } + else if(pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x6F && + pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00) + { + LOG(ERROR) << StringPrintf("%s: JcopOs is already upto date-No update required exiting", fn); + Os_info->version_info.ver_status = STATUS_UPTO_DATE; + status = STATUS_FAILED; + break; + } + else + { + status = STATUS_FAILED; + LOG(ERROR) << StringPrintf("%s: pTranscv_Info->sRecvData[recvBufferActualSize-1] = 0x%x%x recvBufferActualSize = %d", fn, + pTranscv_Info->sRecvData[recvBufferActualSize-2], pTranscv_Info->sRecvData[recvBufferActualSize-1],recvBufferActualSize); + LOG(ERROR) << StringPrintf("%s: Invalid response", fn); + goto exit; + } + } + wResult = fclose(Os_info->fp); + } +exit: + LOG(ERROR) << StringPrintf("%s close fp and exit; status= 0x%X", fn,status); + mchannel->doeSE_JcopDownLoadReset(); + if(status == STATUS_SUCCESS) + SetJcopOsState(Os_info, JCOP_UPDATE_STATE_TRIGGER_APDU); + else + wResult = fclose(Os_info->fp); + + return status; +} +/******************************************************************************* +** +** Function: UaiTriggerApdu +** +** Description: Switch to updater OS +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::UaiTriggerApdu(JcopOs_ImageInfo_t* pVersionInfo, tJBL_STATUS status, JcopOs_TranscieveInfo_t* pTranscv_Info) +{ + static const char fn [] = "JcopOsDwnld::UaiTriggerApdu"; + bool stat = false; + IChannel_t *mchannel = gpJcopOs_Dwnld_Context->channel; + int32_t recvBufferActualSize = 0; + + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter;", fn); + + if(!isUaiEnabled) + { + return true; + } + if(pTranscv_Info == NULL || + pVersionInfo == NULL) + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Invalid parameter", fn); + status = STATUS_FAILED; + } + else + { + pTranscv_Info->timeout = gTransceiveTimeout; + pTranscv_Info->sSendlength = (int32_t)sizeof(Uai_Trigger_APDU); + pTranscv_Info->sRecvlength = 1024;//(int32_t)sizeof(int32_t); + memcpy(pTranscv_Info->sSendData, Uai_Trigger_APDU, pTranscv_Info->sSendlength); + + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Calling Secure Element Transceive", fn); + stat = mchannel->transceiveRaw (pTranscv_Info->sSendData, + pTranscv_Info->sSendlength, + pTranscv_Info->sRecvData, + pTranscv_Info->sRecvlength, + recvBufferActualSize, + pTranscv_Info->timeout); + if (stat != true) + { + status = STATUS_FAILED; + LOG(ERROR) << StringPrintf("%s: SE transceive failed status = 0x%X", fn, status);//Stop JcopOs Update + } + else if(((pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x68) && + (pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x81))|| + ((pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x90) && + (pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00))|| + ((pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x6F) && + (pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00))) + { + /*mchannel->doeSE_JcopDownLoadReset();*/ + status = STATUS_OK; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Trigger APDU Transceive status = 0x%X", fn, status); + } + else + { + /* status {90, 00} */ + status = STATUS_OK; + } + } + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: exit; status = 0x%X", fn, status); + return status; +} +/******************************************************************************* +** +** Function: GetInfo +** +** Description: Get the JCOP OS info +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::GetInfo(JcopOs_ImageInfo_t* pImageInfo, tJBL_STATUS status, JcopOs_TranscieveInfo_t* pTranscv_Info) +{ + static const char fn [] = "JcopOsDwnld::GetInfo"; + + bool stat = false; + IChannel_t *mchannel = gpJcopOs_Dwnld_Context->channel; + int32_t recvBufferActualSize = 0; + + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter;", fn); + + if(pTranscv_Info == NULL || + pImageInfo == NULL) + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Invalid parameter", fn); + status = STATUS_FAILED; + } + else + { + memcpy(pImageInfo->fls_path, (char *)path[pImageInfo->index], strlen(path[pImageInfo->index])); + + memset(pTranscv_Info->sSendData, 0, JCOP_MAX_BUF_SIZE); + pTranscv_Info->timeout = gTransceiveTimeout; + if(isUaiEnabled) + { + pTranscv_Info->sSendlength = (uint32_t)sizeof(Uai_GetInfo_APDU); + memcpy(pTranscv_Info->sSendData, Uai_GetInfo_APDU, pTranscv_Info->sSendlength); + }else + { + pTranscv_Info->sSendlength = (uint32_t)sizeof(GetInfo_APDU); + memcpy(pTranscv_Info->sSendData, GetInfo_APDU, pTranscv_Info->sSendlength); + } + pTranscv_Info->sRecvlength = 1024; + + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: Calling Secure Element Transceive", fn); + stat = mchannel->transceive (pTranscv_Info->sSendData, + pTranscv_Info->sSendlength, + pTranscv_Info->sRecvData, + pTranscv_Info->sRecvlength, + recvBufferActualSize, + pTranscv_Info->timeout); + if (stat != true) + { + status = STATUS_FAILED; + pImageInfo->index =0; + LOG(ERROR) << StringPrintf("%s: SE transceive failed status = 0x%X", fn, status);//Stop JcopOs Update + } + else if((pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x90) && + (pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00)) + { + pImageInfo->version_info.osid = pTranscv_Info->sRecvData[recvBufferActualSize-6]; + pImageInfo->version_info.ver1 = pTranscv_Info->sRecvData[recvBufferActualSize-5]; + pImageInfo->version_info.ver0 = pTranscv_Info->sRecvData[recvBufferActualSize-4]; + pImageInfo->version_info.OtherValid = pTranscv_Info->sRecvData[recvBufferActualSize-3]; +#if 0 + if((pImageInfo->index != 0) && + (pImageInfo->version_info.osid == 0x01) && + (pImageInfo->version_info.OtherValid == 0x11)) + { + LOG(ERROR) << StringPrintf("3-Step update is not required"); + memset(pImageInfo->fls_path,0,sizeof(pImageInfo->fls_path)); + pImageInfo->index=0; + } + else +#endif + { + LOG(ERROR) << StringPrintf("Starting 3-Step update"); + memcpy(pImageInfo->fls_path, path[pImageInfo->index], strlen(path[pImageInfo->index])); + pImageInfo->index++; + } + status = STATUS_OK; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: GetInfo Transceive status = 0x%X", fn, status); + } + else if((pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x6A) && + (pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x82) && + pImageInfo->version_info.ver_status == STATUS_UPTO_DATE) + { + status = STATUS_UPTO_DATE; + } + else + { + status = STATUS_FAILED; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s; Invalid response for GetInfo", fn); + } + } + + if (status == STATUS_FAILED) + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s; status failed, doing reset...", fn); + mchannel->doeSE_JcopDownLoadReset(); + } + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: exit; status = 0x%X", fn, status); + return status; +} +/******************************************************************************* +** +** Function: load_JcopOS_image +** +** Description: Used to update the JCOP OS +** Get Info function has to be called before this +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::load_JcopOS_image(JcopOs_ImageInfo_t *Os_info, tJBL_STATUS status, JcopOs_TranscieveInfo_t *pTranscv_Info) +{ + static const char fn [] = "JcopOsDwnld::load_JcopOS_image"; + bool stat = false; + int wResult; + int32_t wIndex,wCount=0; + int32_t wLen; + + IChannel_t *mchannel = gpJcopOs_Dwnld_Context->channel; + int32_t recvBufferActualSize = 0; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter", fn); + if(Os_info == NULL || + pTranscv_Info == NULL) + { + LOG(ERROR) << StringPrintf("%s: invalid parameter", fn); + return status; + } + Os_info->fp = fopen(Os_info->fls_path, "r"); + + if (Os_info->fp == NULL) { + LOG(ERROR) << StringPrintf("Error opening OS image file <%s> for reading: %s", + Os_info->fls_path, strerror(errno)); + return STATUS_FILE_NOT_FOUND; + } + wResult = fseek(Os_info->fp, 0L, SEEK_END); + if (wResult) { + LOG(ERROR) << StringPrintf("Error seeking end OS image file %s", strerror(errno)); + goto exit; + } + Os_info->fls_size = ftell(Os_info->fp); + if (Os_info->fls_size < 0) { + LOG(ERROR) << StringPrintf("Error ftelling file %s", strerror(errno)); + goto exit; + } + wResult = fseek(Os_info->fp, 0L, SEEK_SET); + if (wResult) { + LOG(ERROR) << StringPrintf("Error seeking start image file %s", strerror(errno)); + goto exit; + } + while(!feof(Os_info->fp)) + { + LOG(ERROR) << StringPrintf("%s; Start of line processing", fn); + + wIndex=0; + wLen=0; + wCount=0; + memset(pTranscv_Info->sSendData,0x00,JCOP_MAX_BUF_SIZE); + pTranscv_Info->sSendlength=0; + + LOG(ERROR) << StringPrintf("%s; wIndex = 0", fn); + for(wCount =0; (wCount < 5 && !feof(Os_info->fp)); wCount++, wIndex++) + { + wResult = FSCANF_BYTE(Os_info->fp,"%2X",&pTranscv_Info->sSendData[wIndex]); + } + if(wResult != 0) + { + wLen = pTranscv_Info->sSendData[4]; + LOG(ERROR) << StringPrintf("%s; Read 5byes success & len=%d", fn,wLen); + if(wLen == 0x00) + { + LOG(ERROR) << StringPrintf("%s: Extended APDU", fn); + wResult = FSCANF_BYTE(Os_info->fp,"%2X",&pTranscv_Info->sSendData[wIndex++]); + wResult = FSCANF_BYTE(Os_info->fp,"%2X",&pTranscv_Info->sSendData[wIndex++]); + wLen = ((pTranscv_Info->sSendData[5] << 8) | (pTranscv_Info->sSendData[6])); + } + for(wCount =0; (wCount < wLen && !feof(Os_info->fp)); wCount++, wIndex++) + { + wResult = FSCANF_BYTE(Os_info->fp,"%2X",&pTranscv_Info->sSendData[wIndex]); + } + } + else + { + LOG(ERROR) << StringPrintf("%s: JcopOs image Read failed", fn); + goto exit; + } + + pTranscv_Info->sSendlength = wIndex; + LOG(ERROR) << StringPrintf("%s: start transceive for length %d", fn, pTranscv_Info->sSendlength); + if((pTranscv_Info->sSendlength != 0x03) && + (pTranscv_Info->sSendData[0] != 0x00) && + (pTranscv_Info->sSendData[1] != 0x00)) + { + + stat = mchannel->transceive(pTranscv_Info->sSendData, + pTranscv_Info->sSendlength, + pTranscv_Info->sRecvData, + pTranscv_Info->sRecvlength, + recvBufferActualSize, + pTranscv_Info->timeout); + } + else + { + LOG(ERROR) << StringPrintf("%s: Invalid packet", fn); + continue; + } + if(stat != true) + { + LOG(ERROR) << StringPrintf("%s: Transceive failed; status=0x%X", fn, stat); + status = STATUS_FAILED; + goto exit; + } + else if(recvBufferActualSize != 0 && + pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x90 && + pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00) + { + //LOG(ERROR) << StringPrintf("%s: END transceive for length %d", fn, pTranscv_Info->sSendlength); + status = STATUS_SUCCESS; + } + else if(pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x6F && + pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0x00) + { + LOG(ERROR) << StringPrintf("%s: JcopOs is already upto date-No update required exiting", fn); + Os_info->version_info.ver_status = STATUS_UPTO_DATE; + status = STATUS_FAILED; + break; + } + else if(pTranscv_Info->sRecvData[recvBufferActualSize-2] == 0x6F && + pTranscv_Info->sRecvData[recvBufferActualSize-1] == 0xA1) + { + LOG(ERROR) << StringPrintf("%s: JcopOs is already up to date-No update required exiting", fn); + Os_info->version_info.ver_status = STATUS_UPTO_DATE; + status = STATUS_UPTO_DATE; + break; + } + else + { + status = STATUS_FAILED; + LOG(ERROR) << StringPrintf("%s: Invalid response", fn); + } + LOG(ERROR) << StringPrintf("%s: Going for next line", fn); + } + + if(status == STATUS_SUCCESS) + { + Os_info->cur_state++; + /*If Patch Update is required*/ + if(isPatchUpdate) + { + /*Set the step to 3 to handle multiple + JCOP Patch update*/ + Os_info->cur_state = 3; + } + SetJcopOsState(Os_info, Os_info->cur_state); + } + +exit: + mchannel->doeSE_JcopDownLoadReset(); + LOG(ERROR) << StringPrintf("%s close fp and exit; status= 0x%X", fn,status); + wResult = fclose(Os_info->fp); + return status; +} + +/******************************************************************************* +** +** Function: GetJcopOsState +** +** Description: Used to update the JCOP OS state +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::GetJcopOsState(JcopOs_ImageInfo_t *Os_info, uint8_t *counter) +{ + static const char fn [] = "JcopOsDwnld::GetJcopOsState"; + tJBL_STATUS status = STATUS_SUCCESS; + FILE *fp; + uint8_t xx=0; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter", fn); + IChannel_t *mchannel = gpJcopOs_Dwnld_Context->channel; + if(Os_info == NULL) + { + LOG(ERROR) << StringPrintf("%s: invalid parameter", fn); + return STATUS_FAILED; + } + fp = fopen(JCOP_INFO_PATH[mchannel->getInterfaceInfo()], "r"); + + + if (fp == NULL) { + LOG(ERROR) << StringPrintf("file <%s> not exits for reading- creating new file: %s", + JCOP_INFO_PATH[mchannel->getInterfaceInfo()], strerror(errno)); + fp = fopen(JCOP_INFO_PATH[mchannel->getInterfaceInfo()], "w+"); + if (fp == NULL) + { + LOG(ERROR) << StringPrintf("Error opening OS image file <%s> for reading: %s", + JCOP_INFO_PATH[mchannel->getInterfaceInfo()], strerror(errno)); + return STATUS_FAILED; + } + fprintf(fp, "%u", xx); + fclose(fp); + } + else + { + FSCANF_BYTE(fp, "%u", &xx); + LOG(ERROR) << StringPrintf("JcopOsState %d", xx); + fclose(fp); + } + + switch(xx) + { + case JCOP_UPDATE_STATE0: + case JCOP_UPDATE_STATE3: + LOG(ERROR) << StringPrintf("Starting update from UAI Authentication"); + Os_info->index = JCOP_UPDATE_STATE0; + Os_info->cur_state = JCOP_UPDATE_STATE0; + *counter = 0; + break; + case JCOP_UPDATE_STATE1: + LOG(ERROR) << StringPrintf("Starting update from step2"); + Os_info->index = JCOP_UPDATE_STATE1; + Os_info->cur_state = JCOP_UPDATE_STATE1; + *counter = 5; + break; + case JCOP_UPDATE_STATE2: + LOG(ERROR) << StringPrintf("Starting update from step3"); + Os_info->index = JCOP_UPDATE_STATE2; + Os_info->cur_state = JCOP_UPDATE_STATE2; + *counter = 7; + break; + case JCOP_UPDATE_STATE_TRIGGER_APDU: + LOG(ERROR) << StringPrintf("Starting update from step1"); + Os_info->index = JCOP_UPDATE_STATE0; + Os_info->cur_state = JCOP_UPDATE_STATE0; + *counter = 2; + break; + default: + LOG(ERROR) << StringPrintf("invalid state"); + status = STATUS_FAILED; + break; + } + return status; +} + +/******************************************************************************* +** +** Function: SetJcopOsState +** +** Description: Used to set the JCOP OS state +** +** Returns: Success if ok. +** +*******************************************************************************/ +tJBL_STATUS JcopOsDwnld::SetJcopOsState(JcopOs_ImageInfo_t *Os_info, uint8_t state) +{ + static const char fn [] = "JcopOsDwnld::SetJcopOsState"; + tJBL_STATUS status = STATUS_FAILED; + FILE *fp; + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: enter", fn); + IChannel_t *mchannel = gpJcopOs_Dwnld_Context->channel; + if(Os_info == NULL) + { + LOG(ERROR) << StringPrintf("%s: invalid parameter", fn); + return status; + } + fp = fopen(JCOP_INFO_PATH[mchannel->getInterfaceInfo()], "w"); + + if (fp == NULL) { + LOG(ERROR) << StringPrintf("Error opening OS image file <%s> for reading: %s", + JCOP_INFO_PATH[mchannel->getInterfaceInfo()], strerror(errno)); + } + else + { + fprintf(fp, "%u", state); + fflush(fp); + LOG(ERROR) << StringPrintf("Current JcopOsState: %d", state); + status = STATUS_SUCCESS; + int fd=fileno(fp); + int ret = fdatasync(fd); + LOG(ERROR) << StringPrintf("ret value: %d", ret); + fclose(fp); + } + return status; +} + +#if 0 +void *JcopOsDwnld::GetMemory(uint32_t size) +{ + void *pMem; + static const char fn [] = "JcopOsDwnld::GetMemory"; + pMem = (void *)malloc(size); + + if(pMem != NULL) + { + memset(pMem, 0, size); + } + else + { + DLOG_IF(INFO, nfc_debug_enabled) + << StringPrintf("%s: memory allocation failed", fn); + } + return pMem; +} + +void JcopOsDwnld::FreeMemory(void *pMem) +{ + if(pMem != NULL) + { + free(pMem); + pMem = NULL; + } +} + +#endif diff --git a/ls_client/inc/LsClient.h b/ls_client/inc/LsClient.h new file mode 100644 index 0000000..552e72c --- /dev/null +++ b/ls_client/inc/LsClient.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * + * Copyright 2018 NXP + * + * 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. + * + ******************************************************************************/ + +#include "../../inc/IChannel.h" + +#ifdef __cplusplus + +extern "C" { + +#endif +#ifndef LSCLIENT_H_ +#define LSCLIENT_H_ + +#define STATUS_SUCCESS 0x00 +#define STATUS_OK 0x00 +#define STATUS_FAILED 0x03 +#define STATUS_FILE_NOT_FOUND 0x05 + +typedef uint8_t tLSC_STATUS; + +/******************************************************************************* +** +** Function: LSC_Start +** +** Description: Starts the LSC over DWP +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +unsigned char LSC_Start(const char* name, const char* dest, uint8_t* pdata, + uint16_t len, uint8_t* respSW); + +/******************************************************************************* +** +** Function: performLSDownload +** +** Description: Perform LS during hal init +** +** Returns: SUCCESS of ok +** +*******************************************************************************/ +tLSC_STATUS performLSDownload(IChannel_t* data); + +void* phLS_memset(void* buff, int val, size_t len); +void* phLS_memcpy(void* dest, const void* src, size_t len); +void* phLS_memalloc(uint32_t size); +void phLS_free(void* ptr); +void* phLS_calloc(size_t datatype, size_t size); + +#endif /* LSCLIENT_H_ */ + +#ifdef __cplusplus +} + +#endif diff --git a/ls_client/inc/LsLib.h b/ls_client/inc/LsLib.h new file mode 100644 index 0000000..b4b09a2 --- /dev/null +++ b/ls_client/inc/LsLib.h @@ -0,0 +1,555 @@ +/******************************************************************************* + * + * Copyright 2018 NXP + * + * 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 LSC_H_ +#define LSC_H_ + +#define NXP_LS_AID +#include "LsClient.h" +#include <stdio.h> +#include "../../inc/IChannel.h" +#include "phNxpConfig.h" + +typedef struct Lsc_ChannelInfo { + uint8_t channel_id; + bool isOpend; +} Lsc_ChannelInfo_t; + +typedef struct Lsc_TranscieveInfo { + int32_t timeout; + uint8_t sRecvData[1024]; + uint8_t sSendData[1024]; + int32_t sSendlength; + int sRecvlength; + uint8_t sTemp_recvbuf[1024]; +} Lsc_TranscieveInfo_t; + +typedef struct Lsc_ImageInfo { + FILE* fp; + int fls_size; + char fls_path[384]; + int bytes_read; + FILE* fResp; + int fls_RespSize; + char fls_RespPath[384]; + int bytes_wrote; + Lsc_ChannelInfo_t Channel_Info[10]; + uint8_t channel_cnt; +} Lsc_ImageInfo_t; +typedef enum { + LS_Default = 0x00, + LS_Cert = 0x7F21, + LS_Sign = 0x60, + LS_Comm = 0x40 +} Ls_TagType; + +typedef struct Lsc_lib_Context { + IChannel_t *mchannel; + Lsc_ImageInfo_t Image_info; + Lsc_TranscieveInfo_t Transcv_Info; +} Lsc_Dwnld_Context_t, *pLsc_Dwnld_Context_t; + +typedef struct phNxpLs_data { + uint32_t len; /*!< length of the buffer */ + uint8_t* p_data; /*!< pointer to a buffer */ +} phNxpLs_data; + + +static uint8_t OpenChannel[] = {0x00, 0x70, 0x00, 0x00, 0x01}; +static uint8_t GetData[] = {0x80, 0xCA, 0x00, 0x46, 0x00}; +#ifndef NXP_LS_AID +static uint8_t SelectLsc[] = {0x00, 0xA4, 0x04, 0x00, 0x0D, 0xA0, + 0x00, 0x00, 0x03, 0x96, 0x41, 0x4C, + 0x41, 0x01, 0x43, 0x4F, 0x52, 0x01}; +#else +static uint8_t SelectLsc[] = {0xA4, 0x04, 0x00, 0x0E, 0xA0, 0x00, + 0x00, 0x03, 0x96, 0x54, 0x43, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x0B, 0x00}; + +static const uint8_t SelectSEMS[] = {0xA4, 0x04, 0x00, 0x0C, 0xA0, 0x00, + 0x00, 0x01, 0x51, 0x53, 0x45, 0x4D, + 0x53, 0x00, 0x00, 0x00}; + +static const uint8_t SelectSEMSUpdater[] = {0xA4, 0x04, 0x00, 0x0C, 0xA0, 0x00, + 0x00, 0x01, 0x51, 0x53, 0x45, 0x4D, + 0x53, 0xFF, 0xFF, 0xFF}; +#endif + +/*LSC2*/ +#define NOOFAIDS 0x03 +#define LENOFAIDS 0x16 +#define NUM_LS_AIDS 0x03 +#define LEN_LS_AID 0x16 +#define LS_SELF_UPDATE_AID_IDX 2 +#ifndef NXP_LS_AID +static uint8_t ArrayOfAIDs[NUM_LS_AIDS][LEN_LS_AID] = { + {0x12, 0x00, 0xA4, 0x04, 0x00, 0x0D, 0xA0, 0x00, 0x00, 0x03, 0x96, 0x41, + 0x4C, 0x41, 0x01, 0x4C, 0x44, 0x52, 0x01, 0x00, 0x00, 0x00}, + {0x12, 0x00, 0xA4, 0x04, 0x00, 0x0D, 0xA0, 0x00, 0x00, 0x03, 0x96, 0x41, + 0x4C, 0x41, 0x01, 0x43, 0x4F, 0x52, 0x01, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +#else +static uint8_t ArrayOfAIDs[NOOFAIDS][LENOFAIDS] = { + {0x14, 0x00, 0xA4, 0x04, 0x00, 0x0F, 0xA0, 0x00, 0x00, 0x03, 0x96, 0x54, + 0x43, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x02, 0x00}, + {0x14, 0x00, 0xA4, 0x04, 0x00, 0x0F, 0xA0, 0x00, 0x00, 0x03, 0x96, 0x54, + 0x43, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x01, 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +#endif +#define TAG_CERTIFICATE 0x7F21 +#define TAG_LSES_RESP 0x4E +#define TAG_LSES_RSPLEN 0x02 +#define TAG_SERIAL_NO 0x93 +#define TAG_LSRE_ID 0x42 +#define TAG_LSRE_SIGNID 0x45 +#define TAG_CERTFHOLD_ID 0x5F20 +#define TAG_KEY_USAGE 0x95 +#define TAG_EFF_DATE 0x5F25 +#define TAG_EXP_DATE 0x5F24 +#define TAG_CCM_PERMISSION 0x53 +#define TAG_SIG_RNS_COMP 0x5F37 +#define MAX_META_STRING_SIZE 0xFF + +#define TAG_LS_VER1 0x9F +#define TAG_LS_VER2 0x08 +#define LS_DEFAULT_STATUS 0x6340 +#define LS_SUCCESS_STATUS 0x9000 +#define TAG_RE_KEYID 0x65 + +#define LS_ABORT_SW1 0x69 +#define LS_ABORT_SW2 0x87 +//#define AID_MEM_PATH "/data/vendor/secure_element/AID_MEM.txt" +//#define LS_STATUS_PATH "/data/vendor/secure_element/LS_Status.txt" +#define LS_SRC_BACKUP "/data/vendor/secure_element/LS_Src_Backup.txt" +#define LS_DST_BACKUP "/data/vendor/secure_element/LS_Dst_Backup.txt" +#define MAX_CERT_LEN (255 + 137) + +/*LSC2*/ + +#define JCOP3_WR +#define MAX_SIZE 0xFF +#define PARAM_P1_OFFSET 0x02 +#define FIRST_BLOCK 0x05 +#define LAST_BLOCK 0x84 +#define ONLY_BLOCK 0x85 +#define CLA_BYTE 0x80 +#define JSBL_HEADER_LEN 0x03 +#define LSC_CMD_HDR_LEN 0x02 + +/* Definations for TAG ID's present in the script file*/ +#define TAG_SELECT_ID 0x6F +#define TAG_LSC_ID 0x84 +#define TAG_PRO_DATA_ID 0xA5 +#define TAG_JSBL_HDR_ID 0x60 +#define TAG_JSBL_KEY_ID 0x61 +#define TAG_SIGNATURE_ID 0x41 +#define TAG_LSC_CMD_ID 0x40 +#define TAG_JSBL_CER_ID 0x44 + +/*Definitions for Install for load*/ +#define INSTAL_LOAD_ID 0xE6 +#define LOAD_CMD_ID 0xE8 +#define LOAD_MORE_BLOCKS 0x00 +#define LOAD_LAST_BLOCK 0x80 + +#define STORE_DATA_CLA 0x80 +#define STORE_DATA_INS 0xE2 +#define STORE_DATA_LEN 32 +#define STORE_DATA_TAG 0x4F +static const char *AID_MEM_PATH[2] = {"/data/vendor/nfc/AID_MEM.txt", + "/data/vendor/secure_element/AID_MEM.txt"}; +static const char *LS_STATUS_PATH[2] = {"/data/vendor/nfc/LS_Status.txt", + "/data/vendor/secure_element/LS_Status.txt"}; + +/******************************************************************************* +** +** Function: initialize +** +** Description: Initialize all member variables. +** native: Native data. +** +** Returns: True if ok. +** +*******************************************************************************/ +bool initialize (IChannel_t *channel); + +/******************************************************************************* +** +** Function: finalize +** +** Description: Release all resources. +** +** Returns: None +** +*******************************************************************************/ +void finalize(); + +/******************************************************************************* +** +** Function: Perform_LSC +** +** Description: Performs the LSC download sequence +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS Perform_LSC(const char* path, const char* dest, + const uint8_t* pdata, uint16_t len, uint8_t* respSW); + +/******************************************************************************* +** +** Function: LSC_OpenChannel +** +** Description: Creates the logical channel with lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +static tLSC_STATUS LSC_OpenChannel(Lsc_ImageInfo_t* pContext, + tLSC_STATUS status, + Lsc_TranscieveInfo_t* pInfo) + __attribute__((unused)); + +/******************************************************************************* +** +** Function: LSC_SelectLsc +** +** Description: Creates the logical channel with lsc +** Channel_id will be used for any communication with Lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +static tLSC_STATUS LSC_SelectLsc(Lsc_ImageInfo_t* pContext, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pInfo) + __attribute__((unused)); + +/******************************************************************************* +** +** Function: LSC_StoreData +** +** Description: It is used to provide the LSC with an Unique +** Identifier of the Application that has triggered the LSC +*script. +** +** Returns: Success if ok. +** +*******************************************************************************/ +static tLSC_STATUS LSC_StoreData(Lsc_ImageInfo_t* pContext, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pInfo) + __attribute__((unused)); + +/******************************************************************************* +** +** Function: LSC_loadapplet +** +** Description: Reads the script from the file and sent to Lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +static tLSC_STATUS LSC_loadapplet(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) + __attribute__((unused)); + +/******************************************************************************* +** +** Function: LSC_update_seq_handler +** +** Description: Performs the LSC update sequence handler sequence +** +** Returns: Success if ok. +** +*******************************************************************************/ +static tLSC_STATUS LSC_update_seq_handler( + tLSC_STATUS (*seq_handler[])(Lsc_ImageInfo_t* pContext, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pInfo), + const char* name, const char* dest) __attribute__((unused)); + +/******************************************************************************* +** +** Function: Write_Response_To_OutFile +** +** Description: Write the response to Out file +** with length recvlen from buffer RecvData. +** +** Returns: Success if OK +** +*******************************************************************************/ +tLSC_STATUS Write_Response_To_OutFile(Lsc_ImageInfo_t* image_info, + uint8_t* RecvData, int32_t recvlen, + Ls_TagType tType); + +/******************************************************************************* +** +** Function: Check_Certificate_Tag +** +** Description: Check certificate Tag presence in script +** by 7F21 . +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_Certificate_Tag(uint8_t* read_buf, uint16_t* offset1); + +/******************************************************************************* +** +** Function: Check_SerialNo_Tag +** +** Description: Check Serial number Tag presence in script +** by 0x93 . +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_SerialNo_Tag(uint8_t* read_buf, uint16_t* offset1); + +/******************************************************************************* +** +** Function: Check_LSRootID_Tag +** +** Description: Check LS root ID tag presence in script and compare with +** select response root ID value. +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_LSRootID_Tag(uint8_t* read_buf, uint16_t* offset1); + +/******************************************************************************* +** +** Function: Check_CertHoldID_Tag +** +** Description: Check certificate holder ID tag presence in script. +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_CertHoldID_Tag(uint8_t* read_buf, uint16_t* offset1); + +/******************************************************************************* +** +** Function: Check_Date_Tag +** +** Description: Check date tags presence in script. +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_Date_Tag(uint8_t* read_buf, uint16_t* offset1); + +/******************************************************************************* +** +** Function: Check_45_Tag +** +** Description: Check 45 tags presence in script and compare the value +** with select response tag 45 value +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_45_Tag(uint8_t* read_buf, uint16_t* offset1, + uint8_t* tag45Len); + +/******************************************************************************* +** +** Function: Certificate_Verification +** +** Description: Perform the certificate verification by forwarding it to +** LS applet. +** +** Returns: Success if certificate is verified +** +*******************************************************************************/ +tLSC_STATUS Certificate_Verification(Lsc_ImageInfo_t* Os_info, + Lsc_TranscieveInfo_t* pTranscv_Info, + uint8_t* read_buf, uint16_t* offset1, + uint8_t* tag45Len); + +/******************************************************************************* +** +** Function: Check_Complete_7F21_Tag +** +** Description: Traverses the 7F21 tag for verification of each sub tag with +** in the 7F21 tag. +** +** Returns: Success if all tags are verified +** +*******************************************************************************/ +tLSC_STATUS Check_Complete_7F21_Tag(Lsc_ImageInfo_t* Os_info, + Lsc_TranscieveInfo_t* pTranscv_Info, + uint8_t* read_buf, uint16_t* offset); + +/******************************************************************************* +** +** Function: LSC_UpdateExeStatus +** +** Description: Updates LSC status to a file +** +** Returns: true if success else false +** +*******************************************************************************/ +bool LSC_UpdateExeStatus(uint16_t status); + +/******************************************************************************* +** +** Function: Get_LsStatus +** +** Description: Interface to fetch Loader service client status to JNI, +*Services +** +** Returns: SUCCESS/FAILURE +** +*******************************************************************************/ +tLSC_STATUS Get_LsStatus(uint8_t* pVersion); + +/******************************************************************************* +** +** Function: LSC_SendtoEse +** +** Description: It is used to send the packet to p61 +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_SendtoEse(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info); + +/******************************************************************************* +** +** Function: LSC_SendtoLsc +** +** Description: It is used to forward the packet to Lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_SendtoLsc(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info, + Ls_TagType tType); + +/******************************************************************************* +** +** Function: LSC_CloseChannel +** +** Description: Closes the previously opened logical channel +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_CloseChannel(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info); + +/******************************************************************************* +** +** Function: LSC_ProcessResp +** +** Description: Process the response packet received from Lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_ProcessResp(Lsc_ImageInfo_t* image_info, int32_t recvlen, + Lsc_TranscieveInfo_t* trans_info, Ls_TagType tType); + +/******************************************************************************* +** +** Function: LSC_Check_KeyIdentifier +** +** Description: Checks and validates certificate +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_Check_KeyIdentifier(Lsc_ImageInfo_t* Os_info, + tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info, + uint8_t* temp_buf, tLSC_STATUS flag, + int32_t wNewLen); + +/******************************************************************************* +** +** Function: LSC_ReadScript +** +** Description: Reads the current line if the script +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_ReadScript(Lsc_ImageInfo_t* Os_info, uint8_t* read_buf); + +/******************************************************************************* +** +** Function: Process_EseResponse +** +** Description: It is used to process the received response packet from ESE +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS Process_EseResponse(Lsc_TranscieveInfo_t* pTranscv_Info, + int32_t recv_len, Lsc_ImageInfo_t* Os_info); + +/******************************************************************************* +** +** Function: Process_SelectRsp +** +** Description: It is used to process the received response for SELECT LSC +*cmd +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS Process_SelectRsp(uint8_t* Recv_data, int32_t Recv_len); + +/******************************************************************************* +** +** Function: Numof_lengthbytes +** +** Description: Checks the number of length bytes and assigns +** length value to wLen. +** +** Returns: Number of Length bytes +** +*******************************************************************************/ +uint8_t Numof_lengthbytes(uint8_t* read_buf, int32_t* wLen); + +#ifdef JCOP3_WR +tLSC_STATUS Send_Backall_Loadcmds(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info); + +tLSC_STATUS Bufferize_load_cmds(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info); +#endif + +inline int FSCANF_BYTE(FILE* stream, const char* format, void* pVal) { + int Result = 0; + + if ((NULL != stream) && (NULL != format) && (NULL != pVal)) { + unsigned int dwVal; + unsigned char* pTmp = (unsigned char*)pVal; + Result = fscanf(stream, format, &dwVal); + + (*pTmp) = (unsigned char)(dwVal & 0x000000FF); + } + return Result; +} + +#endif /*LSC_H*/ diff --git a/ls_client/src/LsClient.cpp b/ls_client/src/LsClient.cpp new file mode 100644 index 0000000..6792dca --- /dev/null +++ b/ls_client/src/LsClient.cpp @@ -0,0 +1,216 @@ +/****************************************************************************** + * + * Copyright 2018 NXP + * + * 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. + * + ******************************************************************************/ + +#include "LsLib.h" +#include "LsClient.h" +#include <cutils/log.h> +#include <dirent.h> +#include <stdlib.h> +#include <pthread.h> +#include <string.h> +#include <errno.h> + +/*static char gethex(const char *s, char **endptr); +char *convert(const char *s, int *length);*/ +uint8_t datahex(char c); +void updateLsAid(uint8_t intfInfo); +//extern pLsc_Dwnld_Context_t gpLsc_Dwnld_Context; +//static android::sp<ISecureElementHalCallback> cCallback; +/******************************************************************************* +** +** Function: LSC_Start +** +** Description: Starts the LSC update over DWP +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_Start(const char* name, const char* dest, uint8_t* pdata, + uint16_t len, uint8_t* respSW) { + static const char fn[] = "LSC_Start"; + tLSC_STATUS status = STATUS_FAILED; + if (name != NULL) { + ALOGE("%s: name is %s", fn, name); + ALOGE("%s: Dest is %s", fn, dest); + status = Perform_LSC(name, dest, pdata, len, respSW); + } else { + ALOGE("Invalid parameter"); + } + ALOGE("%s: Exit; status=0x0%X", fn, status); + return status; +} + +/******************************************************************************* +** +** Function: performLSDownload +** +** Description: Perform LS during hal init +** +** Returns: SUCCESS of ok +** +*******************************************************************************/ +tLSC_STATUS performLSDownload(IChannel_t* data) { + tLSC_STATUS status = STATUS_FAILED; + + const char* lsUpdateBackupPath = + "/vendor/etc/loaderservice_updater.txt"; + const char* lsUpdateBackupOutPath[2] = + {"/data/vendor/nfc/loaderservice_updater_out.txt", + "/data/vendor/secure_element/loaderservice_updater_out.txt",}; + IChannel_t* mchannel = (IChannel_t*)data; + + /*generated SHA-1 string for secureElementLS + This will remain constant as handled in secureElement HAL*/ + char sha1[] = "6d583e84f2710e6b0f06beebc1a12a1083591373"; + uint8_t hash[20] = {}; + + for (int i = 0; i < 40; i = i + 2) { + hash[i / 2] = + (((datahex(sha1[i]) & 0x0F) << 4) | (datahex(sha1[i + 1]) & 0x0F)); + } + /*Check and update if any new LS AID is available*/ + updateLsAid(mchannel->getInterfaceInfo()); + + if(!initialize ((IChannel_t*) data)) + return status; + + + uint8_t resSW[4] = {0x4e, 0x02, 0x69, 0x87}; + FILE* fIn, *fOut; + if ((fIn = fopen(lsUpdateBackupPath, "rb")) == NULL) { + ALOGE("%s Cannot open file %s\n", __func__, lsUpdateBackupPath); + ALOGE("%s Error : %s", __func__, strerror(errno)); + return status; + } else { + ALOGD("%s File opened %s\n", __func__, lsUpdateBackupPath); + fseek(fIn, 0, SEEK_END); + long fsize = ftell(fIn); + rewind(fIn); + + char* lsUpdateBuf = (char*)malloc(fsize + 1); + fread(lsUpdateBuf, fsize, 1, fIn); + fclose(fIn); + + if ((fOut = fopen(lsUpdateBackupOutPath[mchannel->getInterfaceInfo()], "wb")) == NULL) { + ALOGE("%s Failed to open file %s\n", __func__, + lsUpdateBackupOutPath[mchannel->getInterfaceInfo()]); + } else { + ALOGD("%s File opened %s\n", __func__, + lsUpdateBackupOutPath[mchannel->getInterfaceInfo()]); + + if ((long)fwrite(lsUpdateBuf, 1, fsize, fOut) != fsize) { + ALOGE("%s ERROR - Failed to write %ld bytes to file\n", __func__, fsize); + } + + fclose(fOut); + } + + status = LSC_Start(lsUpdateBackupPath, lsUpdateBackupOutPath[mchannel->getInterfaceInfo()], + (uint8_t*)hash, (uint16_t)sizeof(hash), resSW); + resSW[0]=0x4e; + ALOGD("%s LSC_Start completed\n", __func__); + if (status == STATUS_SUCCESS) { + if (remove(lsUpdateBackupPath) == 0) { + ALOGD("%s : %s file deleted successfully\n", __func__, + lsUpdateBackupPath); + } else { + ALOGD("%s : %s file deletion failed!!!\n", __func__, + lsUpdateBackupPath); + } + } + free(lsUpdateBuf); + } + ALOGD("%s pthread_exit\n", __func__); + + return status; +} + +/******************************************************************************* +** +** Function: datahex +** +** Description: Converts char to uint8_t +** +** Returns: uint8_t variable +** +*******************************************************************************/ +uint8_t datahex(char c) { + uint8_t value = 0; + if (c >= '0' && c <= '9') + value = (c - '0'); + else if (c >= 'A' && c <= 'F') + value = (10 + (c - 'A')); + else if (c >= 'a' && c <= 'f') + value = (10 + (c - 'a')); + return value; +} + +/******************************************************************************* +** +** Function: updateLsAid +** +** Description: Store AID in LS_SELF_UPDATE_AID_IDX of ArrayOfAIDs if new LS +** AID is available after LS Self Update +** +** Returns: None +** +*******************************************************************************/ +void updateLsAid(uint8_t intfInfo) { + ALOGD_IF( "%s Enter\n", __func__); + + FILE* fAID_MEM = NULL; + fAID_MEM = fopen(AID_MEM_PATH[intfInfo], "r"); + + if (fAID_MEM == NULL) { + ALOGE("%s: AID data file does not exists", __func__); + return; + } + + uint8_t aidLen = 0x00; + int32_t wStatus = 0; + + while (!(feof(fAID_MEM))) { + wStatus = FSCANF_BYTE(fAID_MEM, "%2x", + &ArrayOfAIDs[LS_SELF_UPDATE_AID_IDX][aidLen++]); + if (wStatus == 0) { + ALOGE("%s: exit: Error during read AID data", __func__); + ArrayOfAIDs[LS_SELF_UPDATE_AID_IDX][0] = 0x00; + break; + } + } + if ((wStatus > 0x00) && (aidLen > 0x00)) { + ArrayOfAIDs[LS_SELF_UPDATE_AID_IDX][0] = aidLen - 1; + } + fclose(fAID_MEM); +} + +void* phLS_memset(void* buff, int val, size_t len) { + return memset(buff, val, len); +} + +void* phLS_memcpy(void* dest, const void* src, size_t len) { + return memcpy(dest, src, len); +} + +void* phLS_memalloc(uint32_t size) { return malloc(size); } + +void phLS_free(void* ptr) { return free(ptr); } + +void* phLS_calloc(size_t datatype, size_t size) { + return calloc(datatype, size); +} diff --git a/ls_client/src/LsLib.cpp b/ls_client/src/LsLib.cpp new file mode 100644 index 0000000..592bea0 --- /dev/null +++ b/ls_client/src/LsLib.cpp @@ -0,0 +1,2137 @@ +/******************************************************************************* + * + * Copyright 2018 NXP + * + * 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. + * + ******************************************************************************/ + +#include <cutils/log.h> +#include <LsLib.h> +#include <LsClient.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +pLsc_Dwnld_Context_t gpLsc_Dwnld_Context = NULL; +static int32_t gTransceiveTimeout = 120000; +#ifdef JCOP3_WR +uint8_t Cmd_Buffer[64 * 1024]; +static int32_t cmd_count = 0; +bool islastcmdLoad; +bool SendBack_cmds = false; +uint8_t* pBuffer; +#endif +bool mIsInit; +uint8_t Select_Rsp[1024]; +uint8_t Jsbl_RefKey[256]; +uint8_t Jsbl_keylen; +uint8_t StoreData[22]; +int Select_Rsp_Len; +uint8_t lsVersionArr[2]; +uint8_t tag42Arr[17]; +uint8_t tag45Arr[9]; +uint8_t lsExecuteResp[4]; +uint8_t AID_ARRAY[22]; +int32_t resp_len = 0; +FILE* fAID_MEM = NULL; +FILE* fLS_STATUS = NULL; +uint8_t lsGetStatusArr[2]; +phNxpLs_data cmdApdu; +phNxpLs_data rspApdu; +static tLSC_STATUS LSC_Transceive(phNxpLs_data* pCmd, phNxpLs_data* pRsp); +tLSC_STATUS (*Applet_load_seqhandler[])(Lsc_ImageInfo_t* pContext, + tLSC_STATUS status, + Lsc_TranscieveInfo_t* pInfo) = { + LSC_OpenChannel, LSC_SelectLsc, LSC_StoreData, LSC_loadapplet, NULL}; + +/******************************************************************************* +** +** Function: initialize +** +** Description: Initialize all member variables. +** native: Native data. +** +** Returns: True if ok. +** +*******************************************************************************/ +bool initialize (IChannel_t* channel) +{ + static const char fn [] = "Ala_initialize"; + + ALOGD ("%s: enter", fn); + + gpLsc_Dwnld_Context = (pLsc_Dwnld_Context_t)malloc(sizeof(Lsc_Dwnld_Context_t)); + if(gpLsc_Dwnld_Context != NULL) + { + memset((void *)gpLsc_Dwnld_Context, 0, (uint32_t)sizeof(Lsc_Dwnld_Context_t)); + } + else + { + ALOGD("%s: Memory allocation failed", fn); + return (false); + } + gpLsc_Dwnld_Context->mchannel = channel; + if((channel != NULL) && + (channel->open) != NULL) + { + if(channel->open() == STATUS_FAILED) + { + ALOGD ("%s: exit : channle open failed", fn); + return false; + } + } + else + { + ALOGD ("%s: exit : channel null", fn); + return false; + } + mIsInit = true; + ALOGD ("%s: exit : success", fn); + return (true); +} + +/******************************************************************************* +** +** Function: finalize +** +** Description: Release all resources. +** +** Returns: None +** +*******************************************************************************/ +void finalize() { + static const char fn[] = "Lsc_finalize"; + ALOGD("%s: enter", fn); + mIsInit = false; + if (gpLsc_Dwnld_Context != NULL) { + free(gpLsc_Dwnld_Context); + gpLsc_Dwnld_Context = NULL; + } + ALOGD("%s: exit", fn); +} + +/******************************************************************************* +** +** Function: Perform_LSC +** +** Description: Performs the LSC download sequence +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS Perform_LSC(const char* name, const char* dest, + const uint8_t* pdata, uint16_t len, uint8_t* respSW) { + static const char fn[] = "Perform_LSC"; + tLSC_STATUS status = STATUS_FAILED; + ALOGD("%s: enter; sha-len=%d", fn, len); + //mIsInit = true; Changed here HARI + if (mIsInit == false) { + ALOGD("%s: LSC lib is not initialized", fn); + status = STATUS_FAILED; + } else if ((pdata == NULL) || (len == 0x00)) { + ALOGD("%s: Invalid SHA-data", fn); + } else { + StoreData[0] = STORE_DATA_TAG; + StoreData[1] = len; + memcpy(&StoreData[2], pdata, len); + status = LSC_update_seq_handler(Applet_load_seqhandler, name, dest); + if ((status != STATUS_OK) && (lsExecuteResp[2] == 0x90) && + (lsExecuteResp[3] == 0x00)) { + lsExecuteResp[2] = LS_ABORT_SW1; + lsExecuteResp[3] = LS_ABORT_SW2; + } + memcpy(&respSW[0], &lsExecuteResp[0], 4); + ALOGD("%s: lsExecuteScript Response SW=%2x%2x", fn, lsExecuteResp[2], + lsExecuteResp[3]); + } + + ALOGD("%s: exit; status=0x0%x", fn, status); + return status; +} +/******************************************************************************* +** +** Function: LSC_update_seq_handler +** +** Description: Performs the LSC update sequence handler sequence +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_update_seq_handler( + tLSC_STATUS (*seq_handler[])(Lsc_ImageInfo_t* pContext, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pInfo), + const char* name, const char* dest) { + static const char fn[] = "LSC_update_seq_handler"; + uint16_t seq_counter = 0; + Lsc_ImageInfo_t update_info = + (Lsc_ImageInfo_t)gpLsc_Dwnld_Context->Image_info; + Lsc_TranscieveInfo_t trans_info = + (Lsc_TranscieveInfo_t)gpLsc_Dwnld_Context->Transcv_Info; + tLSC_STATUS status = STATUS_FAILED; + ALOGD("%s: enter", fn); + + if (dest != NULL) { + strcat(update_info.fls_RespPath, dest); + ALOGD("Loader Service response data path/destination: %s", dest); + update_info.bytes_wrote = 0xAA; + } else { + update_info.bytes_wrote = 0x55; + } + if ((LSC_UpdateExeStatus(LS_DEFAULT_STATUS)) != true) { + return false; + } + // memcpy(update_info.fls_path, (char*)Lsc_path, sizeof(Lsc_path)); + strcat(update_info.fls_path, name); + ALOGD("Selected applet to install is: %s", update_info.fls_path); + + while ((seq_handler[seq_counter]) != NULL) { + status = STATUS_FAILED; + status = (*(seq_handler[seq_counter]))(&update_info, status, &trans_info); + if (STATUS_SUCCESS != status) { + ALOGE("%s: exiting; status=0x0%X", fn, status); + break; + } + seq_counter++; + } + + LSC_CloseChannel(&update_info, STATUS_FAILED, &trans_info); + ALOGE("%s: exit; status=0x%x", fn, status); + return status; +} +/******************************************************************************* +** +** Function: LSC_OpenChannel +** +** Description: Creates the logical channel with lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_OpenChannel(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) { + static const char fn[] = "LSC_OpenChannel"; + tLSC_STATUS transStat = STATUS_FAILED; + phNxpLs_data cmdApdu; + phNxpLs_data rspApdu; + Os_info->channel_cnt = 0x00; + ALOGD("%s: enter", fn); + if (Os_info == NULL || pTranscv_Info == NULL) { + ALOGD("%s: Invalid parameter", fn); + } else { + phLS_memset(&cmdApdu, 0x00, sizeof(phNxpLs_data)); + phLS_memset(&rspApdu, 0x00, sizeof(phNxpLs_data)); + + cmdApdu.len = (int32_t)sizeof(OpenChannel); + cmdApdu.p_data = (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + memcpy(cmdApdu.p_data, OpenChannel, cmdApdu.len); + + ALOGD("%s: Calling Secure Element Transceive", fn); + transStat = LSC_Transceive(&cmdApdu, &rspApdu); + + if (transStat != STATUS_SUCCESS && (rspApdu.len < 0x03)) { + if (rspApdu.len == 0x02) + memcpy(&lsExecuteResp[2], &rspApdu.p_data[rspApdu.len - 2], 2); + status = STATUS_FAILED; + ALOGE("%s: SE transceive failed status = 0x%X", fn, status); + } else if (((rspApdu.p_data[rspApdu.len - 2] != 0x90) && + (rspApdu.p_data[rspApdu.len - 1] != 0x00))) { + memcpy(&lsExecuteResp[2], &rspApdu.p_data[rspApdu.len - 2], 2); + status = STATUS_FAILED; + ALOGE("%s: invalid response = 0x%X", fn, status); + } else { + uint8_t cnt = Os_info->channel_cnt; + Os_info->Channel_Info[cnt].channel_id = rspApdu.p_data[rspApdu.len - 3]; + Os_info->Channel_Info[cnt].isOpend = true; + Os_info->channel_cnt++; + status = STATUS_OK; + } + phLS_free(cmdApdu.p_data); + } + + ALOGE("%s: exit; status=0x%x", fn, status); + return status; +} +/******************************************************************************* +** +** Function: LSC_SelectLsc +** +** Description: Creates the logical channel with lsc +** Channel_id will be used for any communication with Lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_SelectLsc(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) { + static const char fn[] = "LSC_SelectLsc"; + tLSC_STATUS transStat = STATUS_FAILED; + phNxpLs_data cmdApdu; + phNxpLs_data rspApdu; + unsigned long semsPresent = 1; + + if (Os_info == NULL || pTranscv_Info == NULL) { + ALOGD("%s: Invalid parameter", fn); + } else { + phLS_memset(&cmdApdu, 0x00, sizeof(phNxpLs_data)); + phLS_memset(&rspApdu, 0x00, sizeof(phNxpLs_data)); + + GetNxpNumValue(NAME_NXP_SEMS_SUPPORTED, &semsPresent, sizeof(semsPresent)); + + if(semsPresent) + { + cmdApdu.len = (int32_t)(sizeof(SelectSEMS) + 1); + cmdApdu.p_data = (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + cmdApdu.p_data[0] = Os_info->Channel_Info[0].channel_id; + memcpy(&(cmdApdu.p_data[1]), SelectSEMS, sizeof(SelectSEMS)); + } + else + { + /*p_data will have channel_id (1 byte) + SelectLsc APDU*/ + cmdApdu.len = (int32_t)(sizeof(SelectLsc) + 1); + cmdApdu.p_data = (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + cmdApdu.p_data[0] = Os_info->Channel_Info[0].channel_id; + memcpy(&(cmdApdu.p_data[1]), SelectLsc, sizeof(SelectLsc)); + } + ALOGD("%s: Calling Secure Element Transceive with Loader service AID", fn); + + transStat = LSC_Transceive(&cmdApdu, &rspApdu); + + if (transStat != STATUS_SUCCESS && (rspApdu.len == 0x00)) { + status = STATUS_FAILED; + ALOGE("%s: SE transceive failed status = 0x%X", fn, status); + } else if (((rspApdu.p_data[rspApdu.len - 2] == 0x90) && + (rspApdu.p_data[rspApdu.len - 1] == 0x00))) { + status = Process_SelectRsp(rspApdu.p_data, (rspApdu.len - 2)); + if (status != STATUS_OK) { + ALOGE("%s: Select Lsc Rsp doesnt have a valid key; status = 0x%X", fn, + status); + } + } else if (((rspApdu.p_data[rspApdu.len - 2] != 0x90))) { + /*Copy the response SW in failure case*/ + memcpy(&lsExecuteResp[2], &(rspApdu.p_data[rspApdu.len - 2]), 2); + } + else { + status = STATUS_FAILED; + } + if(status == STATUS_FAILED && semsPresent) + { + phLS_free(cmdApdu.p_data); + cmdApdu.len = (int32_t)(sizeof(SelectSEMSUpdater) + 1); + cmdApdu.p_data = (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + cmdApdu.p_data[0] = Os_info->Channel_Info[0].channel_id; + memcpy(&(cmdApdu.p_data[1]), SelectSEMSUpdater, sizeof(SelectSEMSUpdater)); + transStat = LSC_Transceive(&cmdApdu, &rspApdu); + + if (transStat != STATUS_SUCCESS && (rspApdu.len == 0x00)) { + status = STATUS_FAILED; + ALOGE("%s: SE transceive failed status = 0x%X", fn, status); + } else if (((rspApdu.p_data[rspApdu.len - 2] == 0x90) && + (rspApdu.p_data[rspApdu.len - 1] == 0x00))) { + status = Process_SelectRsp(rspApdu.p_data, (rspApdu.len - 2)); + if (status != STATUS_OK) { + ALOGE("%s: Select Lsc Rsp doesnt have a valid key; status = 0x%X", fn, + status); + } + } else if (((rspApdu.p_data[rspApdu.len - 2] != 0x90))) { + /*Copy the response SW in failure case*/ + memcpy(&lsExecuteResp[2], &(rspApdu.p_data[rspApdu.len - 2]), 2); + } + else { + status = STATUS_FAILED; + } + } + phLS_free(cmdApdu.p_data); + } + ALOGE("%s: exit; status=0x%x", fn, status); + return status; +} + +/******************************************************************************* +** +** Function: LSC_StoreData +** +** Description: It is used to provide the LSC with an Unique +** Identifier of the Application that has triggered the LSC +*script. +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_StoreData(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) { + static const char fn[] = "LSC_StoreData"; + tLSC_STATUS transStat = STATUS_FAILED; + phNxpLs_data cmdApdu; + phNxpLs_data rspApdu; + int32_t xx = 0, len = 0; + ALOGD("%s: enter", fn); + if (Os_info == NULL || pTranscv_Info == NULL) { + ALOGD("%s: Invalid parameter", fn); + } else { + phLS_memset(&cmdApdu, 0x00, sizeof(phNxpLs_data)); + phLS_memset(&rspApdu, 0x00, sizeof(phNxpLs_data)); + cmdApdu.len = (int32_t)(5 + sizeof(StoreData)); + cmdApdu.p_data = (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + + len = StoreData[1] + 2; //+2 offset is for tag value and length byte + cmdApdu.p_data[xx++] = + STORE_DATA_CLA | (Os_info->Channel_Info[0].channel_id); + cmdApdu.p_data[xx++] = STORE_DATA_INS; + cmdApdu.p_data[xx++] = 0x00; // P1 + cmdApdu.p_data[xx++] = 0x00; // P2 + cmdApdu.p_data[xx++] = len; + memcpy(&(cmdApdu.p_data[xx]), StoreData, len); + + ALOGD("%s: Calling Secure Element Transceive", fn); + transStat = LSC_Transceive(&cmdApdu, &rspApdu); + + if ((transStat != STATUS_SUCCESS) && (rspApdu.len == 0x00)) { + status = STATUS_FAILED; + ALOGE("%s: SE transceive failed status = 0x%X", fn, status); + } else if ((rspApdu.p_data[rspApdu.len - 2] == 0x90) && + (rspApdu.p_data[rspApdu.len - 1] == 0x00)) { + ALOGE("STORE CMD is successful"); + status = STATUS_SUCCESS; + } else { + /*Copy the response SW in failure case*/ + memcpy(&lsExecuteResp[2], &(rspApdu.p_data[rspApdu.len - 2]), 2); + status = STATUS_FAILED; + } + } + phLS_free(cmdApdu.p_data); + ALOGE("%s: exit; status=0x%x", fn, status); + return status; +} + +/******************************************************************************* +** +** Function: LSC_loadapplet +** +** Description: Reads the script from the file and sent to Lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_loadapplet(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) { + static const char fn[] = "LSC_loadapplet"; + int wResult; + int32_t wLen = 0; + uint8_t temp_buf[1024]; + uint8_t len_byte = 0, offset = 0; + Os_info->bytes_read = 0; + bool reachEOFCheck = false; + tLSC_STATUS tag40_found = STATUS_FAILED; + if (Os_info->bytes_wrote == 0xAA) { + Os_info->fResp = fopen(Os_info->fls_RespPath, "a+"); + if (Os_info->fResp == NULL) { + ALOGE("Error opening response recording file <%s> for reading: %s", + Os_info->fls_RespPath, strerror(errno)); + return status; + } + ALOGD("%s: Response OUT FILE path is successfully created", fn); + } else { + ALOGD("%s: Response Out file is optional as per input", fn); + } + ALOGD("%s: enter", fn); + if (Os_info == NULL || pTranscv_Info == NULL) { + ALOGE("%s: invalid parameter", fn); + return status; + } + Os_info->fp = fopen(Os_info->fls_path, "r"); + + if (Os_info->fp == NULL) { + ALOGE("Error opening OS image file <%s> for reading: %s", Os_info->fls_path, + strerror(errno)); + return status; + } + wResult = fseek(Os_info->fp, 0L, SEEK_END); + if (wResult) { + ALOGE("Error seeking end OS image file %s", strerror(errno)); + goto exit; + } + Os_info->fls_size = ftell(Os_info->fp); + ALOGE("fls_size=%d", Os_info->fls_size); + if (Os_info->fls_size < 0) { + ALOGE("Error ftelling file %s", strerror(errno)); + goto exit; + } + wResult = fseek(Os_info->fp, 0L, SEEK_SET); + if (wResult) { + ALOGE("Error seeking start image file %s", strerror(errno)); + goto exit; + } + status = LSC_Check_KeyIdentifier(Os_info, status, pTranscv_Info, NULL, + STATUS_FAILED, 0); + if (status != STATUS_OK) { + goto exit; + } + while (!feof(Os_info->fp) && (Os_info->bytes_read < Os_info->fls_size)) { + len_byte = 0x00; + offset = 0; + /*Check if the certificate/ is verified or not*/ + if (status != STATUS_OK) { + goto exit; + } + memset(temp_buf, 0, sizeof(temp_buf)); + ALOGE("%s; Start of line processing", fn); + status = LSC_ReadScript(Os_info, temp_buf); + if (status != STATUS_OK) { + goto exit; + } else if (status == STATUS_OK) { + /*Reset the flag in case further commands exists*/ + reachEOFCheck = false; + } + if (temp_buf[offset] == TAG_LSC_CMD_ID) { + /* + * start sending the packet to Lsc + * */ + offset = offset + 1; + len_byte = Numof_lengthbytes(&temp_buf[offset], &wLen); + /*If the len data not present or + * len is less than or equal to 32*/ + if ((len_byte == 0) || (wLen <= 32)) + + { + ALOGE("Invalid length zero"); + goto exit; + } else { + tag40_found = STATUS_OK; + offset = offset + len_byte; + pTranscv_Info->sSendlength = wLen; + memcpy(pTranscv_Info->sSendData, &temp_buf[offset], wLen); + } + status = LSC_SendtoLsc(Os_info, status, pTranscv_Info, LS_Comm); + if (status != STATUS_OK) { + /*When the switching of LS 6320 case*/ + if (status == STATUS_FILE_NOT_FOUND) { + /*When 6320 occurs close the existing channels*/ + LSC_CloseChannel(Os_info, status, pTranscv_Info); + + status = STATUS_FAILED; + status = LSC_OpenChannel(Os_info, status, pTranscv_Info); + if (status == STATUS_OK) { + ALOGD("SUCCESS:Post Switching LS open channel"); + status = STATUS_FAILED; + status = LSC_SelectLsc(Os_info, status, pTranscv_Info); + if (status == STATUS_OK) { + ALOGD("SUCCESS:Post Switching LS select"); + status = STATUS_FAILED; + status = LSC_StoreData(Os_info, status, pTranscv_Info); + if (status == STATUS_OK) { + /*Enable certificate and signature verification*/ + tag40_found = STATUS_OK; + lsExecuteResp[2] = 0x90; + lsExecuteResp[3] = 0x00; + reachEOFCheck = true; + continue; + } + ALOGE("Post Switching LS store data failure"); + } + ALOGE("Post Switching LS select failure"); + } + ALOGE("Post Switching LS failure"); + } + ALOGE("Sending packet to lsc failed"); + goto exit; + } + } else if ((temp_buf[offset] == (0x7F)) && + (temp_buf[offset + 1] == (0x21))) { + ALOGD("TAGID: Encountered again certificate tag 7F21"); + if (tag40_found == STATUS_OK) { + ALOGD("2nd Script processing starts with reselect"); + status = STATUS_FAILED; + status = LSC_SelectLsc(Os_info, status, pTranscv_Info); + if (status == STATUS_OK) { + ALOGD("2nd Script select success next store data command"); + status = STATUS_FAILED; + status = LSC_StoreData(Os_info, status, pTranscv_Info); + if (status == STATUS_OK) { + ALOGD( + "2nd Script store data success next certificate verification"); + offset = offset + 2; + len_byte = Numof_lengthbytes(&temp_buf[offset], &wLen); + status = LSC_Check_KeyIdentifier(Os_info, status, pTranscv_Info, + temp_buf, STATUS_OK, + wLen + len_byte + 2); + } + } + /*If the certificate and signature is verified*/ + if (status == STATUS_OK) { + /*If the certificate is verified for 6320 then new + * script starts*/ + tag40_found = STATUS_FAILED; + } + /*If the certificate or signature verification failed*/ + else { + goto exit; + } + } + /*Already certificate&Sginature verified previously skip 7f21& tag 60*/ + else { + memset(temp_buf, 0, sizeof(temp_buf)); + status = LSC_ReadScript(Os_info, temp_buf); + if (status != STATUS_OK) { + ALOGE("%s; Next Tag has to TAG 60 not found", fn); + goto exit; + } + if (temp_buf[offset] == TAG_JSBL_HDR_ID) + continue; + else + goto exit; + } + } else { + /* + * Invalid packet received in between stop processing packet + * return failed status + * */ + status = STATUS_FAILED; + break; + } + } + if (Os_info->bytes_wrote == 0xAA) { + fclose(Os_info->fResp); + } + LSC_UpdateExeStatus(LS_SUCCESS_STATUS); + wResult = fclose(Os_info->fp); + ALOGE("%s exit;End of Load Applet; status=0x%x", fn, status); + return status; +exit: + wResult = fclose(Os_info->fp); + if (Os_info->bytes_wrote == 0xAA) { + fclose(Os_info->fResp); + } + /*Script ends with SW 6320 and reached END OF FILE*/ + if (reachEOFCheck == true) { + status = STATUS_OK; + LSC_UpdateExeStatus(LS_SUCCESS_STATUS); + } + ALOGE("%s close fp and exit; status= 0x%X", fn, status); + return status; +} +/******************************************************************************* +** +** Function: LSC_Check_KeyIdentifier +** +** Description: Checks and validates certificate +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_Check_KeyIdentifier(Lsc_ImageInfo_t* Os_info, + tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info, + uint8_t* temp_buf, tLSC_STATUS flag, + int32_t wNewLen) { + static const char fn[] = "LSC_Check_KeyIdentifier"; + uint16_t offset = 0x00, len_byte = 0; + status = STATUS_FAILED; + uint8_t read_buf[1024]; + int32_t wLen; + uint8_t certf_found = STATUS_FAILED; + uint8_t sign_found = STATUS_FAILED; + ALOGD("%s: enter", fn); + + while (!feof(Os_info->fp) && (Os_info->bytes_read < Os_info->fls_size)) { + offset = 0x00; + wLen = 0; + if (flag == STATUS_OK) { + /*If the 7F21 TAG is already read: After TAG 40*/ + memcpy(read_buf, temp_buf, wNewLen); + status = STATUS_OK; + flag = STATUS_FAILED; + } else { + /*If the 7F21 TAG is not read: Before TAG 40*/ + status = LSC_ReadScript(Os_info, read_buf); + } + if (status != STATUS_OK) return status; + if (STATUS_OK == + Check_Complete_7F21_Tag(Os_info, pTranscv_Info, read_buf, &offset)) { + ALOGD("%s: Certificate is verified", fn); + certf_found = STATUS_OK; + break; + } + /*The Loader Service Client ignores all subsequent commands starting by tag + * �7F21� or tag �60� until the first command starting by tag �40� is + * found*/ + else if (((read_buf[offset] == TAG_LSC_CMD_ID) && + (certf_found != STATUS_OK))) { + ALOGE("%s: NOT FOUND Root entity identifier's certificate", fn); + status = STATUS_FAILED; + return status; + } + } + memset(read_buf, 0, sizeof(read_buf)); + if (certf_found == STATUS_OK) { + offset = 0x00; + wLen = 0; + status = LSC_ReadScript(Os_info, read_buf); + if (status != STATUS_OK) + return status; + else + status = STATUS_FAILED; + + if ((read_buf[offset] == TAG_JSBL_HDR_ID) && + (certf_found != STATUS_FAILED) && (sign_found != STATUS_OK)) + + { + // TODO check the SElect cmd response and return status accordingly + ALOGD("TAGID: TAG_JSBL_HDR_ID"); + offset = offset + 1; + len_byte = Numof_lengthbytes(&read_buf[offset], &wLen); + offset = offset + len_byte; + if (read_buf[offset] == TAG_SIGNATURE_ID) { + offset = offset + 1; + len_byte = Numof_lengthbytes(&read_buf[offset], &wLen); + offset = offset + len_byte; + ALOGE("TAGID: TAG_SIGNATURE_ID"); + + pTranscv_Info->sSendlength = wLen + 5; + + pTranscv_Info->sSendData[0] = 0x00; + pTranscv_Info->sSendData[1] = 0xA0; + pTranscv_Info->sSendData[2] = 0x00; + pTranscv_Info->sSendData[3] = 0x00; + pTranscv_Info->sSendData[4] = wLen; + + memcpy(&(pTranscv_Info->sSendData[5]), &read_buf[offset], wLen); + ALOGE("%s: start transceive for length %ld", fn, + (long)pTranscv_Info->sSendlength); + status = LSC_SendtoLsc(Os_info, status, pTranscv_Info, LS_Sign); + if (status != STATUS_OK) { + return status; + } else { + sign_found = STATUS_OK; + } + } + } else if (read_buf[offset] != TAG_JSBL_HDR_ID) { + status = STATUS_FAILED; + } + } else { + ALOGE("%s : Exit certificate verification failed", fn); + } + + ALOGD("%s: exit: status=0x%x", fn, status); + return status; +} +/******************************************************************************* +** +** Function: LSC_ReadScript +** +** Description: Reads the current line if the script +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_ReadScript(Lsc_ImageInfo_t* Os_info, uint8_t* read_buf) { + static const char fn[] = "LSC_ReadScript"; + int32_t wCount, wLen, wIndex = 0; + uint8_t len_byte = 0; + int wResult = 0; + tLSC_STATUS status = STATUS_FAILED; + int32_t lenOff = 1; + bool isMetaDatapresent = false; + + ALOGD("%s: enter", fn); + + for (wCount = 0; (wCount < 2 && !feof(Os_info->fp)); wCount++, wIndex++) { + wResult = FSCANF_BYTE(Os_info->fp, "%2X", (unsigned int*)&read_buf[wIndex]); + + if(wResult == 0) + { + char metaString[MAX_META_STRING_SIZE]; + char *ptr = fgets(metaString, sizeof(metaString), Os_info->fp); + if(ptr != NULL) + { + isMetaDatapresent = true; + ALOGD("MetaData = %s",ptr); + wCount = 0; + wIndex = 0; + } + else + { + break; + } + } + else + { + if(isMetaDatapresent) + { + isMetaDatapresent = false; + wCount = 0; + wIndex = 0; + read_buf[0] = read_buf[1]; + ALOGD("End of MetaData"); + } + } + } + if (wResult == 0) return STATUS_FAILED; + + Os_info->bytes_read = Os_info->bytes_read + (wCount * 2); + + if ((read_buf[0] == 0x7f) && (read_buf[1] == 0x21)) { + for (wCount = 0; (wCount < 1 && !feof(Os_info->fp)); wCount++, wIndex++) { + wResult = + FSCANF_BYTE(Os_info->fp, "%2X", (unsigned int*)&read_buf[wIndex]); + } + if (wResult == 0) { + ALOGE("%s: Exit Read Script failed in 7F21 ", fn); + return STATUS_FAILED; + } + /*Read_Script from wCount*2 to wCount*1 */ + Os_info->bytes_read = Os_info->bytes_read + (wCount * 2); + lenOff = 2; + } else if ((read_buf[0] == 0x40) || (read_buf[0] == 0x60)) { + lenOff = 1; + } + /*If TAG is neither 7F21 nor 60 nor 40 then ABORT execution*/ + else { + ALOGE("Invalid TAG 0x%X found in the script", read_buf[0]); + return STATUS_FAILED; + } + + if (read_buf[lenOff] == 0x00) { + ALOGE("Invalid length zero"); + len_byte = 0x00; + return STATUS_FAILED; + } else if ((read_buf[lenOff] & 0x80) == 0x80) { + len_byte = read_buf[lenOff] & 0x0F; + len_byte = len_byte + 1; // 1 byte added for byte 0x81 + + ALOGD("%s: Length byte Read from 0x80 is 0x%x ", fn, len_byte); + + if (len_byte == 0x02) { + for (wCount = 0; (wCount < 1 && !feof(Os_info->fp)); wCount++, wIndex++) { + wResult = + FSCANF_BYTE(Os_info->fp, "%2X", (unsigned int*)&read_buf[wIndex]); + } + if (wResult == 0) { + ALOGE("%s: Exit Read Script failed in length 0x02 ", fn); + return STATUS_FAILED; + } + + wLen = read_buf[lenOff + 1]; + Os_info->bytes_read = Os_info->bytes_read + (wCount * 2); + ALOGD("%s: Length of Read Script in len_byte= 0x02 is 0x%x ", fn, wLen); + } else if (len_byte == 0x03) { + for (wCount = 0; (wCount < 2 && !feof(Os_info->fp)); wCount++, wIndex++) { + wResult = + FSCANF_BYTE(Os_info->fp, "%2X", (unsigned int*)&read_buf[wIndex]); + } + if (wResult == 0) { + ALOGE("%s: Exit Read Script failed in length 0x03 ", fn); + return STATUS_FAILED; + } + + Os_info->bytes_read = Os_info->bytes_read + (wCount * 2); + wLen = read_buf[lenOff + 1]; // Length of the packet send to LSC + wLen = ((wLen << 8) | (read_buf[lenOff + 2])); + ALOGD("%s: Length of Read Script in len_byte= 0x03 is 0x%x ", fn, wLen); + } else { + /*Need to provide the support if length is more than 2 bytes*/ + ALOGE("Length recived is greater than 3"); + return STATUS_FAILED; + } + } else { + len_byte = 0x01; + wLen = read_buf[lenOff]; + ALOGE("%s: Length of Read Script in len_byte= 0x01 is 0x%x ", fn, wLen); + } + + for (wCount = 0; (wCount < wLen && !feof(Os_info->fp)); wCount++, wIndex++) { + wResult = FSCANF_BYTE(Os_info->fp, "%2X", (unsigned int*)&read_buf[wIndex]); + } + + if (wResult == 0) { + ALOGE("%s: Exit Read Script failed in fscanf function ", fn); + return status; + } else { + Os_info->bytes_read = + Os_info->bytes_read + (wCount * 2) + 1; // not sure why 2 added + status = STATUS_OK; + } + + ALOGD("%s: exit: status=0x%x; Num of bytes read=%d and index=%d", fn, status, + Os_info->bytes_read, wIndex); + + return status; +} + +/******************************************************************************* +** +** Function: LSC_SendtoEse +** +** Description: It is used to send the packet to p61 +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_SendtoEse(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) { + static const char fn[] = "LSC_SendtoEse"; + bool chanl_open_cmd = false; + tLSC_STATUS transStat = STATUS_FAILED; + status = STATUS_FAILED; + phNxpLs_data cmdApdu; + phNxpLs_data rspApdu; + int32_t recvBufferActualSize = 0; + ALOGD("%s: enter", fn); +#ifdef JCOP3_WR + /* + * Bufferize_load_cmds function is implemented in JCOP + * */ + status = Bufferize_load_cmds(Os_info, status, pTranscv_Info); + if (status != STATUS_FAILED) { +#endif + if (pTranscv_Info->sSendData[1] == 0x70) { + if (pTranscv_Info->sSendData[2] == 0x00) { + ALOGE("Channel open"); + chanl_open_cmd = true; + } else { + ALOGE("Channel close"); + for (uint8_t cnt = 0; cnt < Os_info->channel_cnt; cnt++) { + if (Os_info->Channel_Info[cnt].channel_id == + pTranscv_Info->sSendData[3]) { + ALOGE("Closed channel id = 0x0%x", + Os_info->Channel_Info[cnt].channel_id); + Os_info->Channel_Info[cnt].isOpend = false; + } + } + } + } + phLS_memset(&cmdApdu, 0x00, sizeof(phNxpLs_data)); + phLS_memset(&rspApdu, 0x00, sizeof(phNxpLs_data)); + + cmdApdu.len = (int32_t)(pTranscv_Info->sSendlength); + cmdApdu.p_data = (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + memcpy(cmdApdu.p_data, pTranscv_Info->sSendData, cmdApdu.len); + + transStat = LSC_Transceive(&cmdApdu, &rspApdu); + + if (transStat != STATUS_SUCCESS) { + ALOGE("%s: Transceive failed; status=0x%X", fn, transStat); + } else { + if (chanl_open_cmd == true) { + if ((rspApdu.len == 0x03) && + ((rspApdu.p_data[rspApdu.len - 2] == 0x90) && + (rspApdu.p_data[rspApdu.len - 1] == 0x00))) { + ALOGE("open channel success"); + uint8_t cnt = Os_info->channel_cnt; + Os_info->Channel_Info[cnt].channel_id = + rspApdu.p_data[rspApdu.len - 3]; + Os_info->Channel_Info[cnt].isOpend = true; + Os_info->channel_cnt++; + } else { + ALOGE("channel open faield"); + } + } + memcpy(pTranscv_Info->sRecvData, rspApdu.p_data, rspApdu.len); + status = Process_EseResponse(pTranscv_Info, rspApdu.len, Os_info); + } +#ifdef JCOP3_WR + } else if (SendBack_cmds == false) { + /* + * Workaround for issue in JCOP + * Send the fake response back + * */ + recvBufferActualSize = 0x03; + pTranscv_Info->sRecvData[0] = 0x00; + pTranscv_Info->sRecvData[1] = 0x90; + pTranscv_Info->sRecvData[2] = 0x00; + status = Process_EseResponse(pTranscv_Info, recvBufferActualSize, Os_info); + } else { + if (islastcmdLoad == true) { + status = Send_Backall_Loadcmds(Os_info, status, pTranscv_Info); + SendBack_cmds = false; + } else { + memset(Cmd_Buffer, 0, sizeof(Cmd_Buffer)); + SendBack_cmds = false; + status = STATUS_FAILED; + } + } +#endif + phLS_free(cmdApdu.p_data); + ALOGD("%s: exit: status=0x%x", fn, status); + return status; +} + +/******************************************************************************* +** +** Function: LSC_SendtoLsc +** +** Description: It is used to forward the packet to Lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_SendtoLsc(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info, + Ls_TagType tType) { + static const char fn[] = "LSC_SendtoLsc"; + tLSC_STATUS transStat = STATUS_FAILED; + status = STATUS_FAILED; + + phNxpLs_data cmdApdu; + phNxpLs_data rspApdu; + ALOGD("%s: enter", fn); + pTranscv_Info->sSendData[0] = (0x80 | Os_info->Channel_Info[0].channel_id); + pTranscv_Info->timeout = gTransceiveTimeout; + pTranscv_Info->sRecvlength = 1024; + + phLS_memset(&cmdApdu, 0x00, sizeof(phNxpLs_data)); + phLS_memset(&rspApdu, 0x00, sizeof(phNxpLs_data)); + cmdApdu.len = pTranscv_Info->sSendlength; + cmdApdu.p_data = (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + memcpy(cmdApdu.p_data, pTranscv_Info->sSendData, cmdApdu.len); + + transStat = LSC_Transceive(&cmdApdu, &rspApdu); + + if (transStat != STATUS_SUCCESS) { + ALOGE("%s: Transceive failed; status=0x%X", fn, transStat); + } else { + memcpy(pTranscv_Info->sRecvData, rspApdu.p_data, rspApdu.len); + + status = LSC_ProcessResp(Os_info, rspApdu.len, pTranscv_Info, tType); + } + phLS_free(cmdApdu.p_data); + ALOGD("%s: exit: status=0x%x", fn, status); + return status; +} +/******************************************************************************* +** +** Function: LSC_CloseChannel +** +** Description: Closes the previously opened logical channel +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_CloseChannel(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) { + static const char fn[] = "LSC_CloseChannel"; + status = STATUS_FAILED; + tLSC_STATUS transStat = STATUS_FAILED; + phNxpLs_data cmdApdu; + phNxpLs_data rspApdu; + uint8_t xx = 0; + uint8_t cnt = 0; + ALOGD("%s: enter", fn); + + if (Os_info == NULL || pTranscv_Info == NULL) { + ALOGE("Invalid parameter"); + } else { + for (cnt = 0; (cnt < Os_info->channel_cnt); cnt++) { + phLS_memset(&cmdApdu, 0x00, sizeof(phNxpLs_data)); + phLS_memset(&rspApdu, 0x00, sizeof(phNxpLs_data)); + + cmdApdu.len = 5; + cmdApdu.p_data = + (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + if (Os_info->Channel_Info[cnt].isOpend == false) continue; + xx = 0; + cmdApdu.p_data[xx++] = Os_info->Channel_Info[cnt].channel_id; + cmdApdu.p_data[xx++] = 0x70; + cmdApdu.p_data[xx++] = 0x80; + cmdApdu.p_data[xx++] = Os_info->Channel_Info[cnt].channel_id; + cmdApdu.p_data[xx++] = 0x00; + + transStat = LSC_Transceive(&cmdApdu, &rspApdu); + + if (transStat != STATUS_SUCCESS && rspApdu.len < 2) { + ALOGE("%s: Transceive failed; status=0x%X", fn, transStat); + } else if ((rspApdu.p_data[rspApdu.len - 2] == 0x90) && + (rspApdu.p_data[rspApdu.len - 1] == 0x00)) { + ALOGE("Close channel id = 0x0%x is success", + Os_info->Channel_Info[cnt].channel_id); + status = STATUS_OK; + } else { + ALOGE("Close channel id = 0x0%x is failed", + Os_info->Channel_Info[cnt].channel_id); + } + } + } + phLS_free(cmdApdu.p_data); + ALOGD("%s: exit; status=0x0%x", fn, status); + return status; +} +/******************************************************************************* +** +** Function: LSC_ProcessResp +** +** Description: Process the response packet received from Lsc +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS LSC_ProcessResp(Lsc_ImageInfo_t* image_info, int32_t recvlen, + Lsc_TranscieveInfo_t* trans_info, + Ls_TagType tType) { + static const char fn[] = "LSC_ProcessResp"; + tLSC_STATUS status = STATUS_FAILED; + static int32_t temp_len = 0; + uint8_t* RecvData = trans_info->sRecvData; + char sw[2]; + + ALOGD("%s: enter", fn); + + if (RecvData == NULL && recvlen == 0x00) { + ALOGE("%s: Invalid parameter: status=0x%x", fn, status); + return status; + } else if (recvlen >= 2) { + sw[0] = RecvData[recvlen - 2]; + sw[1] = RecvData[recvlen - 1]; + } else { + ALOGE("%s: Invalid response; status=0x%x", fn, status); + return status; + } + /*Update the Global variable for storing response length*/ + resp_len = recvlen; + if ((sw[0] != 0x63)) { + lsExecuteResp[2] = sw[0]; + lsExecuteResp[3] = sw[1]; + ALOGD("%s: Process Response SW; status = 0x%x", fn, sw[0]); + ALOGD("%s: Process Response SW; status = 0x%x", fn, sw[1]); + } + if ((recvlen == 0x02) && (sw[0] == 0x90) && (sw[1] == 0x00)) { + tLSC_STATUS wStatus = STATUS_FAILED; + ALOGE("%s: Before Write Response", fn); + wStatus = Write_Response_To_OutFile(image_info, RecvData, recvlen, tType); + if (wStatus != STATUS_FAILED) status = STATUS_OK; + } else if ((recvlen > 0x02) && (sw[0] == 0x90) && (sw[1] == 0x00)) { + tLSC_STATUS wStatus = STATUS_FAILED; + ALOGE("%s: Before Write Response", fn); + wStatus = Write_Response_To_OutFile(image_info, RecvData, recvlen, tType); + if (wStatus != STATUS_FAILED) status = STATUS_OK; + } + + else if ((recvlen > 0x02) && (sw[0] == 0x63) && (sw[1] == 0x10)) { + if (temp_len != 0) { + memcpy((trans_info->sTemp_recvbuf + temp_len), RecvData, (recvlen - 2)); + trans_info->sSendlength = temp_len + (recvlen - 2); + memcpy(trans_info->sSendData, trans_info->sTemp_recvbuf, + trans_info->sSendlength); + temp_len = 0; + } else { + memcpy(trans_info->sSendData, RecvData, (recvlen - 2)); + trans_info->sSendlength = recvlen - 2; + } + status = LSC_SendtoEse(image_info, status, trans_info); + } else if ((recvlen > 0x02) && (sw[0] == 0x63) && (sw[1] == 0x20)) { + uint8_t respLen = 0; + int32_t wStatus = 0; + + AID_ARRAY[0] = recvlen + 3; + AID_ARRAY[1] = 00; + AID_ARRAY[2] = 0xA4; + AID_ARRAY[3] = 0x04; + AID_ARRAY[4] = 0x00; + AID_ARRAY[5] = recvlen - 2; + memcpy(&AID_ARRAY[6], &RecvData[0], recvlen - 2); + //memcpy(&ArrayOfAIDs[2][0], &AID_ARRAY[0], recvlen + 4); + memcpy(&ArrayOfAIDs[LS_SELF_UPDATE_AID_IDX][0], &AID_ARRAY[0], recvlen + 4); + + fAID_MEM = fopen(AID_MEM_PATH[gpLsc_Dwnld_Context-> + mchannel->getInterfaceInfo()], "w"); + + if (fAID_MEM == NULL) { + ALOGE("Error opening AID data for writing: %s", strerror(errno)); + return status; + } + + /*Updating the AID_MEM with new value into AID file*/ + while (respLen <= (recvlen + 4)) { + wStatus = fprintf(fAID_MEM, "%2x", AID_ARRAY[respLen++]); + if (wStatus != 2) { + ALOGE("%s: Invalid Response during fprintf; status=0x%x", fn, status); + fclose(fAID_MEM); + break; + } + } + if (wStatus == 2) { + status = STATUS_FILE_NOT_FOUND; + } else { + status = STATUS_FAILED; + } + } else if ((recvlen >= 0x02) && + ((sw[0] != 0x90) && (sw[0] != 0x63) && (sw[0] != 0x61))) { + tLSC_STATUS wStatus = STATUS_FAILED; + wStatus = Write_Response_To_OutFile(image_info, RecvData, recvlen, tType); + } + ALOGD("%s: exit: status=0x%x", fn, status); + return status; +} +/******************************************************************************* +** +** Function: Process_EseResponse +** +** Description: It is used to process the received response packet from ESE +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS Process_EseResponse(Lsc_TranscieveInfo_t* pTranscv_Info, + int32_t recv_len, Lsc_ImageInfo_t* Os_info) { + static const char fn[] = "Process_EseResponse"; + tLSC_STATUS status = STATUS_OK; + uint8_t xx = 0; + ALOGD("%s: enter", fn); + + pTranscv_Info->sSendData[xx++] = + (CLA_BYTE | Os_info->Channel_Info[0].channel_id); + pTranscv_Info->sSendData[xx++] = 0xA2; + + if (recv_len <= 0xFF) { + pTranscv_Info->sSendData[xx++] = 0x80; + pTranscv_Info->sSendData[xx++] = 0x00; + pTranscv_Info->sSendData[xx++] = (uint8_t)recv_len; + memcpy(&(pTranscv_Info->sSendData[xx]), pTranscv_Info->sRecvData, recv_len); + pTranscv_Info->sSendlength = xx + recv_len; + status = LSC_SendtoLsc(Os_info, status, pTranscv_Info, LS_Comm); + } else { + while (recv_len > MAX_SIZE) { + xx = PARAM_P1_OFFSET; + pTranscv_Info->sSendData[xx++] = 0x00; + pTranscv_Info->sSendData[xx++] = 0x00; + pTranscv_Info->sSendData[xx++] = MAX_SIZE; + recv_len = recv_len - MAX_SIZE; + memcpy(&(pTranscv_Info->sSendData[xx]), pTranscv_Info->sRecvData, + MAX_SIZE); + pTranscv_Info->sSendlength = xx + MAX_SIZE; + /*Need not store Process eSE response's response in the out file so + * LS_Comm = 0*/ + status = LSC_SendtoLsc(Os_info, status, pTranscv_Info, LS_Comm); + if (status != STATUS_OK) { + ALOGE("Sending packet to Lsc failed: status=0x%x", status); + return status; + } + } + xx = PARAM_P1_OFFSET; + pTranscv_Info->sSendData[xx++] = LAST_BLOCK; + pTranscv_Info->sSendData[xx++] = 0x01; + pTranscv_Info->sSendData[xx++] = recv_len; + memcpy(&(pTranscv_Info->sSendData[xx]), pTranscv_Info->sRecvData, recv_len); + pTranscv_Info->sSendlength = xx + recv_len; + status = LSC_SendtoLsc(Os_info, status, pTranscv_Info, LS_Comm); + } + ALOGD("%s: exit: status=0x%x", fn, status); + return status; +} +/******************************************************************************* +** +** Function: Process_SelectRsp +** +** Description: It is used to process the received response for SELECT LSC +*cmd +** +** Returns: Success if ok. +** +*******************************************************************************/ +tLSC_STATUS Process_SelectRsp(uint8_t* Recv_data, int32_t Recv_len) { + (void)Recv_len; + static const char fn[] = "Process_SelectRsp"; + tLSC_STATUS status = STATUS_FAILED; + int i = 0, len = 0; + ALOGE("%s: enter", fn); + + if (Recv_data[i] == TAG_SELECT_ID) { + ALOGD("TAG: TAG_SELECT_ID"); + i = i + 1; + len = Recv_data[i]; + i = i + 1; + if (Recv_data[i] == TAG_LSC_ID) { + ALOGD("TAG: TAG_LSC_ID"); + i = i + 1; + len = Recv_data[i]; + i = i + 1 + len; // points to next tag name A5 + // points to TAG 9F08 for LS application version + if ((Recv_data[i] == TAG_LS_VER1) && (Recv_data[i + 1] == TAG_LS_VER2)) { + uint8_t lsaVersionLen = 0; + ALOGD("TAG: TAG_LS_APPLICATION_VER"); + + i = i + 2; + lsaVersionLen = Recv_data[i]; + // points to TAG 9F08 LS application version + i = i + 1; + memcpy(lsVersionArr, &Recv_data[i], lsaVersionLen); + + // points to Identifier of the Root Entity key set identifier + i = i + lsaVersionLen; + + if (Recv_data[i] == TAG_RE_KEYID) { + uint8_t rootEntityLen = 0; + i = i + 1; + rootEntityLen = Recv_data[i]; + + i = i + 1; + if (Recv_data[i] == TAG_LSRE_ID) { + uint8_t tag42Len = 0; + i = i + 1; + tag42Len = Recv_data[i]; + // copy the data including length + memcpy(tag42Arr, &Recv_data[i], tag42Len + 1); + i = i + tag42Len + 1; + ALOGD("tag42Arr %s", tag42Arr); + if (Recv_data[i] == TAG_LSRE_SIGNID) { + uint8_t tag45Len = Recv_data[i + 1]; + memcpy(tag45Arr, &Recv_data[i + 1], tag45Len + 1); + status = STATUS_OK; + } else { + ALOGE( + "Invalid Root entity for TAG 45 = 0x%x; " + "status=0x%x", + Recv_data[i], status); + return status; + } + } else { + ALOGE( + "Invalid Root entity for TAG 42 = 0x%x; " + "status=0x%x", + Recv_data[i], status); + return status; + } + } else { + ALOGE( + "Invalid Root entity key set TAG ID = 0x%x; " + "status=0x%x", + Recv_data[i], status); + return status; + } + } + } else { + ALOGE("Invalid Loader Service AID TAG ID = 0x%x; status=0x%x", + Recv_data[i], status); + return status; + } + } else { + ALOGE("Invalid FCI TAG = 0x%x; status=0x%x", Recv_data[i], status); + return status; + } + ALOGE("%s: Exiting status = 0x%x", fn, status); + return status; +} + +#ifdef JCOP3_WR +tLSC_STATUS Bufferize_load_cmds(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) { + (void)Os_info; + static const char fn[] = "Bufferize_load_cmds"; + uint8_t Param_P2; + status = STATUS_FAILED; + + if (cmd_count == 0x00) { + if ((pTranscv_Info->sSendData[1] == INSTAL_LOAD_ID) && + (pTranscv_Info->sSendData[2] == PARAM_P1_OFFSET) && + (pTranscv_Info->sSendData[3] == 0x00)) { + ALOGE("BUffer: install for load"); + pBuffer[0] = pTranscv_Info->sSendlength; + memcpy(&pBuffer[1], &(pTranscv_Info->sSendData[0]), + pTranscv_Info->sSendlength); + pBuffer = pBuffer + pTranscv_Info->sSendlength + 1; + cmd_count++; + } else { + /* + * Do not buffer this cmd + * Send this command to eSE + * */ + status = STATUS_OK; + } + + } else { + Param_P2 = cmd_count - 1; + if ((pTranscv_Info->sSendData[1] == LOAD_CMD_ID) && + (pTranscv_Info->sSendData[2] == LOAD_MORE_BLOCKS) && + (pTranscv_Info->sSendData[3] == Param_P2)) { + ALOGE("BUffer: load"); + pBuffer[0] = pTranscv_Info->sSendlength; + memcpy(&pBuffer[1], &(pTranscv_Info->sSendData[0]), + pTranscv_Info->sSendlength); + pBuffer = pBuffer + pTranscv_Info->sSendlength + 1; + cmd_count++; + } else if ((pTranscv_Info->sSendData[1] == LOAD_CMD_ID) && + (pTranscv_Info->sSendData[2] == LOAD_LAST_BLOCK) && + (pTranscv_Info->sSendData[3] == Param_P2)) { + ALOGE("BUffer: last load"); + SendBack_cmds = true; + pBuffer[0] = pTranscv_Info->sSendlength; + memcpy(&pBuffer[1], &(pTranscv_Info->sSendData[0]), + pTranscv_Info->sSendlength); + pBuffer = pBuffer + pTranscv_Info->sSendlength + 1; + cmd_count++; + islastcmdLoad = true; + } else { + ALOGE("BUffer: Not a load cmd"); + SendBack_cmds = true; + pBuffer[0] = pTranscv_Info->sSendlength; + memcpy(&pBuffer[1], &(pTranscv_Info->sSendData[0]), + pTranscv_Info->sSendlength); + pBuffer = pBuffer + pTranscv_Info->sSendlength + 1; + islastcmdLoad = false; + cmd_count++; + } + } + ALOGE("%s: exit; status=0x%x", fn, status); + return status; +} + +tLSC_STATUS Send_Backall_Loadcmds(Lsc_ImageInfo_t* Os_info, tLSC_STATUS status, + Lsc_TranscieveInfo_t* pTranscv_Info) { + static const char fn[] = "Send_Backall_Loadcmds"; + tLSC_STATUS transStat = STATUS_FAILED; + status = STATUS_FAILED; + phNxpLs_data cmdApdu; + phNxpLs_data rspApdu; + int32_t recvBufferActualSize = 0; + ALOGD("%s: enter", fn); + pBuffer = Cmd_Buffer; // Points to start of first cmd to send + if (cmd_count == 0x00) { + ALOGE("No cmds stored to send to eSE"); + } else { + while (cmd_count-- > 0) { + phLS_memset(&cmdApdu, 0x00, sizeof(phNxpLs_data)); + phLS_memset(&rspApdu, 0x00, sizeof(phNxpLs_data)); + + cmdApdu.len = (int32_t)(pBuffer[0]); + cmdApdu.p_data = + (uint8_t*)phLS_memalloc(cmdApdu.len * sizeof(uint8_t)); + pBuffer = pBuffer + 1 + cmdApdu.len; + + memcpy(cmdApdu.p_data, &pBuffer[1], cmdApdu.len); + + transStat = LSC_Transceive(&cmdApdu, &rspApdu); + + memcpy(pTranscv_Info->sRecvData, rspApdu.p_data, rspApdu.len); + recvBufferActualSize = rspApdu.len; + + if (transStat != STATUS_SUCCESS || (recvBufferActualSize < 2)) { + ALOGE("%s: Transceive failed; status=0x%X", fn, transStat); + } else if (cmd_count == 0x00) // Last command in the buffer + { + if (islastcmdLoad == false) { + status = + Process_EseResponse(pTranscv_Info, recvBufferActualSize, Os_info); + } else if ((recvBufferActualSize == 0x02) && + (pTranscv_Info->sRecvData[recvBufferActualSize - 2] == + 0x90) && + (pTranscv_Info->sRecvData[recvBufferActualSize - 1] == + 0x00)) { + recvBufferActualSize = 0x03; + pTranscv_Info->sRecvData[0] = 0x00; + pTranscv_Info->sRecvData[1] = 0x90; + pTranscv_Info->sRecvData[2] = 0x00; + status = + Process_EseResponse(pTranscv_Info, recvBufferActualSize, Os_info); + } else { + status = + Process_EseResponse(pTranscv_Info, recvBufferActualSize, Os_info); + } + } else if ((recvBufferActualSize == 0x02) && + (pTranscv_Info->sRecvData[0] == 0x90) && + (pTranscv_Info->sRecvData[1] == 0x00)) { + /*Do not do anything + * send next command in the buffer*/ + } else if ((recvBufferActualSize == 0x03) && + (pTranscv_Info->sRecvData[0] == 0x00) && + (pTranscv_Info->sRecvData[1] == 0x90) && + (pTranscv_Info->sRecvData[2] == 0x00)) { + /*Do not do anything + * Send next cmd in the buffer*/ + } else if ((pTranscv_Info->sRecvData[recvBufferActualSize - 2] != 0x90) && + (pTranscv_Info->sRecvData[recvBufferActualSize - 1] != 0x00)) { + /*Error condition hence exiting the loop*/ + status = + Process_EseResponse(pTranscv_Info, recvBufferActualSize, Os_info); + /*If the sending of Load fails reset the count*/ + cmd_count = 0; + break; + } + } + } + memset(Cmd_Buffer, 0, sizeof(Cmd_Buffer)); + pBuffer = Cmd_Buffer; // point back to start of line + cmd_count = 0x00; + phLS_free(cmdApdu.p_data); + ALOGD("%s: exit: status=0x%x", fn, status); + return status; +} +#endif +/******************************************************************************* +** +** Function: Numof_lengthbytes +** +** Description: Checks the number of length bytes and assigns +** length value to wLen. +** +** Returns: Number of Length bytes +** +*******************************************************************************/ +uint8_t Numof_lengthbytes(uint8_t* read_buf, int32_t* pLen) { + static const char fn[] = "Numof_lengthbytes"; + uint8_t len_byte = 0, i = 0; + int32_t wLen = 0; + ALOGE("%s:enter", fn); + + if (read_buf[i] == 0x00) { + ALOGE("Invalid length zero"); + len_byte = 0x00; + } else if ((read_buf[i] & 0x80) == 0x80) { + len_byte = read_buf[i] & 0x0F; + len_byte = len_byte + 1; // 1 byte added for byte 0x81 + } else { + len_byte = 0x01; + } + /* + * To get the length of the value field + * */ + switch (len_byte) { + case 0: + wLen = read_buf[0]; + break; + case 1: + /*1st byte is the length*/ + wLen = read_buf[0]; + break; + case 2: + /*2nd byte is the length*/ + wLen = read_buf[1]; + break; + case 3: + /*1st and 2nd bytes are length*/ + wLen = read_buf[1]; + wLen = ((wLen << 8) | (read_buf[2])); + break; + case 4: + /*3bytes are the length*/ + wLen = read_buf[1]; + wLen = ((wLen << 16) | (read_buf[2] << 8)); + wLen = (wLen | (read_buf[3])); + break; + default: + ALOGE("default case"); + break; + } + + *pLen = wLen; + ALOGE("%s:exit; len_bytes=0x0%x, Length=%d", fn, len_byte, *pLen); + return len_byte; +} +/******************************************************************************* +** +** Function: Write_Response_To_OutFile +** +** Description: Write the response to Out file +** with length recvlen from buffer RecvData. +** +** Returns: Success if OK +** +*******************************************************************************/ +tLSC_STATUS Write_Response_To_OutFile(Lsc_ImageInfo_t* image_info, + uint8_t* RecvData, int32_t recvlen, + Ls_TagType tType) { + int32_t respLen = 0; + tLSC_STATUS wStatus = STATUS_FAILED; + static const char fn[] = "Write_Response_to_OutFile"; + int32_t status = 0; + uint8_t tagBuffer[12] = {0x61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int32_t tag44Len = 0; + int32_t tag61Len = 0; + uint8_t tag43Len = 1; + uint8_t tag43off = 0; + uint8_t tag44off = 0; + uint8_t ucTag44[3] = {0x00, 0x00, 0x00}; + uint8_t tagLen = 0; + uint8_t tempLen = 0; + /*If the Response out file is NULL or Other than LS commands*/ + if ((image_info->bytes_wrote == 0x55) || (tType == LS_Default)) { + return STATUS_OK; + } + /*Certificate TAG occupies 2 bytes*/ + if (tType == LS_Cert) { + tag43Len = 2; + } + ALOGE("%s: Enter", fn); + + /* |TAG | LEN(BERTLV)| VAL | + * | 61 | XX | TAG | LEN | VAL | TAG | LEN(BERTLV) | VAL + *| + * | 43 | 1/2 | 7F21/60/40 | 44 | apduRespLen | + *apduResponse | + **/ + if (recvlen < 0x80) { + tag44Len = 1; + ucTag44[0] = recvlen; + tag61Len = recvlen + 4 + tag43Len; + + if (tag61Len & 0x80) { + tagBuffer[1] = 0x81; + tagBuffer[2] = tag61Len; + tag43off = 3; + tag44off = 5 + tag43Len; + tagLen = tag44off + 2; + } else { + tagBuffer[1] = tag61Len; + tag43off = 2; + tag44off = 4 + tag43Len; + tagLen = tag44off + 2; + } + } else if ((recvlen >= 0x80) && (recvlen <= 0xFF)) { + ucTag44[0] = 0x81; + ucTag44[1] = recvlen; + tag61Len = recvlen + 5 + tag43Len; + tag44Len = 2; + + if ((tag61Len & 0xFF00) != 0) { + tagBuffer[1] = 0x82; + tagBuffer[2] = (tag61Len & 0xFF00) >> 8; + tagBuffer[3] = (tag61Len & 0xFF); + tag43off = 4; + tag44off = 6 + tag43Len; + tagLen = tag44off + 3; + } else { + tagBuffer[1] = 0x81; + tagBuffer[2] = (tag61Len & 0xFF); + tag43off = 3; + tag44off = 5 + tag43Len; + tagLen = tag44off + 3; + } + } else if ((recvlen > 0xFF) && (recvlen <= 0xFFFF)) { + ucTag44[0] = 0x82; + ucTag44[1] = (recvlen & 0xFF00) >> 8; + ucTag44[2] = (recvlen & 0xFF); + tag44Len = 3; + + tag61Len = recvlen + 6 + tag43Len; + + if ((tag61Len & 0xFF00) != 0) { + tagBuffer[1] = 0x82; + tagBuffer[2] = (tag61Len & 0xFF00) >> 8; + tagBuffer[3] = (tag61Len & 0xFF); + tag43off = 4; + tag44off = 6 + tag43Len; + tagLen = tag44off + 4; + } + } + tagBuffer[tag43off] = 0x43; + tagBuffer[tag43off + 1] = tag43Len; + tagBuffer[tag44off] = 0x44; + memcpy(&tagBuffer[tag44off + 1], &ucTag44[0], tag44Len); + + if (tType == LS_Cert) { + tagBuffer[tag43off + 2] = 0x7F; + tagBuffer[tag43off + 3] = 0x21; + } else if (tType == LS_Sign) { + tagBuffer[tag43off + 2] = 0x60; + } else if (tType == LS_Comm) { + tagBuffer[tag43off + 2] = 0x40; + } else { + /*Do nothing*/ + } + while (tempLen < tagLen) { + status = fprintf(image_info->fResp, "%02X", tagBuffer[tempLen++]); + if (status != 2) { + ALOGE("%s: Invalid Response during fprintf; status=0x%x", fn, (status)); + wStatus = STATUS_FAILED; + break; + } + } + /*Updating the response data into out script*/ + while (respLen < recvlen) { + status = fprintf(image_info->fResp, "%02X", RecvData[respLen++]); + if (status != 2) { + ALOGE("%s: Invalid Response during fprintf; status=0x%x", fn, (status)); + wStatus = STATUS_FAILED; + break; + } + } + if (status == 2) { + fprintf(image_info->fResp, "%s\n", ""); + ALOGE("%s: SUCCESS Response written to script out file; status=0x%x", fn, + (status)); + wStatus = STATUS_OK; + } + fflush(image_info->fResp); + return wStatus; +} + +/******************************************************************************* +** +** Function: Check_Certificate_Tag +** +** Description: Check certificate Tag presence in script +** by 7F21 . +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_Certificate_Tag(uint8_t* read_buf, uint16_t* offset1) { + tLSC_STATUS status = STATUS_FAILED; + uint16_t len_byte = 0; + int32_t wLen /*, recvBufferActualSize=0*/; + uint16_t offset = *offset1; + + if (((read_buf[offset] << 8 | read_buf[offset + 1]) == TAG_CERTIFICATE)) { + ALOGD("TAGID: TAG_CERTIFICATE"); + offset = offset + 2; + len_byte = Numof_lengthbytes(&read_buf[offset], &wLen); + offset = offset + len_byte; + *offset1 = offset; + if (wLen <= MAX_CERT_LEN) status = STATUS_OK; + } + return status; +} + +/******************************************************************************* +** +** Function: Check_SerialNo_Tag +** +** Description: Check Serial number Tag presence in script +** by 0x93 . +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_SerialNo_Tag(uint8_t* read_buf, uint16_t* offset1) { + tLSC_STATUS status = STATUS_FAILED; + uint16_t offset = *offset1; + static const char fn[] = "Check_SerialNo_Tag"; + + if (read_buf[offset] == TAG_SERIAL_NO) { + ALOGD("TAGID: TAG_SERIAL_NO"); + uint8_t serNoLen = read_buf[offset + 1]; + offset = offset + serNoLen + 2; + *offset1 = offset; + ALOGD("%s: TAG_LSROOT_ENTITY is %x", fn, read_buf[offset]); + status = STATUS_OK; + } + return status; +} + +/******************************************************************************* +** +** Function: Check_LSRootID_Tag +** +** Description: Check LS root ID tag presence in script and compare with +** select response root ID value. +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_LSRootID_Tag(uint8_t* read_buf, uint16_t* offset1) { + tLSC_STATUS status = STATUS_FAILED; + uint16_t offset = *offset1; + + if (read_buf[offset] == TAG_LSRE_ID) { + ALOGD("TAGID: TAG_LSROOT_ENTITY"); + if (tag42Arr[0] == read_buf[offset + 1]) { + uint8_t tag42Len = read_buf[offset + 1]; + offset = offset + 2; + status = memcmp(&read_buf[offset], &tag42Arr[1], tag42Arr[0]); + ALOGD("LSC_Check_KeyIdentifier : TAG 42 verified"); + + if (status == STATUS_OK) { + ALOGD( + "LSC_Check_KeyIdentifier : Loader service root entity " + "ID is matched"); + offset = offset + tag42Len; + *offset1 = offset; + } + } + } + return status; +} + +/******************************************************************************* +** +** Function: Check_CertHoldID_Tag +** +** Description: Check certificate holder ID tag presence in script. +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_CertHoldID_Tag(uint8_t* read_buf, uint16_t* offset1) { + tLSC_STATUS status = STATUS_FAILED; + uint16_t offset = *offset1; + + if ((read_buf[offset] << 8 | read_buf[offset + 1]) == TAG_CERTFHOLD_ID) { + uint8_t certfHoldIDLen = 0; + ALOGD("TAGID: TAG_CERTFHOLD_ID"); + certfHoldIDLen = read_buf[offset + 2]; + offset = offset + certfHoldIDLen + 3; + if (read_buf[offset] == TAG_KEY_USAGE) { + uint8_t keyusgLen = 0; + ALOGD("TAGID: TAG_KEY_USAGE"); + keyusgLen = read_buf[offset + 1]; + offset = offset + keyusgLen + 2; + *offset1 = offset; + status = STATUS_OK; + } + } + return status; +} + +/******************************************************************************* +** +** Function: Check_Date_Tag +** +** Description: Check date tags presence in script. +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_Date_Tag(uint8_t* read_buf, uint16_t* offset1) { + tLSC_STATUS status = STATUS_OK; + uint16_t offset = *offset1; + + if ((read_buf[offset] << 8 | read_buf[offset + 1]) == TAG_EFF_DATE) { + uint8_t effDateLen = read_buf[offset + 2]; + offset = offset + 3 + effDateLen; + ALOGD("TAGID: TAG_EFF_DATE"); + if ((read_buf[offset] << 8 | read_buf[offset + 1]) == TAG_EXP_DATE) { + uint8_t effExpLen = read_buf[offset + 2]; + offset = offset + 3 + effExpLen; + ALOGD("TAGID: TAG_EXP_DATE"); + status = STATUS_OK; + } else if (read_buf[offset] == TAG_LSRE_SIGNID) { + status = STATUS_OK; + } + } else if ((read_buf[offset] << 8 | read_buf[offset + 1]) == TAG_EXP_DATE) { + uint8_t effExpLen = read_buf[offset + 2]; + offset = offset + 3 + effExpLen; + ALOGD("TAGID: TAG_EXP_DATE"); + status = STATUS_OK; + } else if (read_buf[offset] == TAG_LSRE_SIGNID) { + status = STATUS_OK; + } else { + /*STATUS_FAILED*/ + } + *offset1 = offset; + return status; +} + +/******************************************************************************* +** +** Function: Check_45_Tag +** +** Description: Check 45 tags presence in script and compare the value +** with select response tag 45 value +** +** Returns: Success if Tag found +** +*******************************************************************************/ +tLSC_STATUS Check_45_Tag(uint8_t* read_buf, uint16_t* offset1, + uint8_t* tag45Len) { + tLSC_STATUS status = STATUS_FAILED; + uint16_t offset = *offset1; + if (read_buf[offset] == TAG_LSRE_SIGNID) { + *tag45Len = read_buf[offset + 1]; + offset = offset + 2; + if (tag45Arr[0] == *tag45Len) { + status = memcmp(&read_buf[offset], &tag45Arr[1], tag45Arr[0]); + if (status == STATUS_OK) { + ALOGD("LSC_Check_KeyIdentifier : TAG 45 verified"); + *offset1 = offset; + } + } + } + return status; +} + +/******************************************************************************* +** +** Function: Certificate_Verification +** +** Description: Perform the certificate verification by forwarding it to +** LS applet. +** +** Returns: Success if certificate is verified +** +*******************************************************************************/ +tLSC_STATUS Certificate_Verification(Lsc_ImageInfo_t* Os_info, + Lsc_TranscieveInfo_t* pTranscv_Info, + uint8_t* read_buf, uint16_t* offset1, + uint8_t* tag45Len) { + tLSC_STATUS status = STATUS_FAILED; + uint16_t offset = *offset1; + int32_t wCertfLen = (read_buf[2] << 8 | read_buf[3]); + tLSC_STATUS certf_found = STATUS_FAILED; + static const char fn[] = "Certificate_Verification"; + uint8_t tag_len_byte = Numof_lengthbytes(&read_buf[2], &wCertfLen); + + pTranscv_Info->sSendData[0] = 0x80; + pTranscv_Info->sSendData[1] = 0xA0; + pTranscv_Info->sSendData[2] = 0x01; + pTranscv_Info->sSendData[3] = 0x00; + /*If the certificate is less than 255 bytes*/ + if (wCertfLen <= 251) { + uint8_t tag7f49Off = 0; + uint8_t u7f49Len = 0; + uint8_t tag5f37Len = 0; + ALOGD("Certificate is greater than 255"); + offset = offset + *tag45Len; + ALOGD("%s: Before TAG_CCM_PERMISSION = %x", fn, read_buf[offset]); + if (read_buf[offset] == TAG_CCM_PERMISSION) { + int32_t tag53Len = 0; + uint8_t len_byte = 0; + offset = offset + 1; + len_byte = Numof_lengthbytes(&read_buf[offset], &tag53Len); + offset = offset + tag53Len + len_byte; + ALOGD("%s: Verified TAG TAG_CCM_PERMISSION = 0x53", fn); + if ((uint16_t)(read_buf[offset] << 8 | read_buf[offset + 1]) == + TAG_SIG_RNS_COMP) { + tag7f49Off = offset; + u7f49Len = read_buf[offset + 2]; + offset = offset + 3 + u7f49Len; + if (u7f49Len != 64) { + return STATUS_FAILED; + } + if ((uint16_t)(read_buf[offset] << 8 | read_buf[offset + 1]) == + 0x7f49) { + tag5f37Len = read_buf[offset + 2]; + if (read_buf[offset + 3] != 0x86 || (read_buf[offset + 4] != 65)) { + return STATUS_FAILED; + } + } else { + return STATUS_FAILED; + } + } else { + return STATUS_FAILED; + } + } else { + return STATUS_FAILED; + } + pTranscv_Info->sSendData[4] = wCertfLen + 2 + tag_len_byte; + pTranscv_Info->sSendlength = wCertfLen + 7 + tag_len_byte; + memcpy(&(pTranscv_Info->sSendData[5]), &read_buf[0], + wCertfLen + 2 + tag_len_byte); + + ALOGD("%s: start transceive for length %d", fn, pTranscv_Info->sSendlength); + status = LSC_SendtoLsc(Os_info, status, pTranscv_Info, LS_Cert); + if (status != STATUS_OK) { + return status; + } else { + certf_found = STATUS_OK; + ALOGD("Certificate is verified"); + return status; + } + } + /*If the certificate is more than 255 bytes*/ + else { + uint8_t tag7f49Off = 0; + uint8_t u7f49Len = 0; + uint8_t tag5f37Len = 0; + ALOGD("Certificate is greater than 255"); + offset = offset + *tag45Len; + ALOGD("%s: Before TAG_CCM_PERMISSION = %x", fn, read_buf[offset]); + if (read_buf[offset] == TAG_CCM_PERMISSION) { + int32_t tag53Len = 0; + uint8_t len_byte = 0; + offset = offset + 1; + len_byte = Numof_lengthbytes(&read_buf[offset], &tag53Len); + offset = offset + tag53Len + len_byte; + ALOGD("%s: Verified TAG TAG_CCM_PERMISSION = 0x53", fn); + if ((uint16_t)(read_buf[offset] << 8 | read_buf[offset + 1]) == + TAG_SIG_RNS_COMP) { + tag7f49Off = offset; + u7f49Len = read_buf[offset + 2]; + offset = offset + 3 + u7f49Len; + if (u7f49Len != 64) { + return STATUS_FAILED; + } + if ((uint16_t)(read_buf[offset] << 8 | read_buf[offset + 1]) == + 0x7f49) { + tag5f37Len = read_buf[offset + 2]; + if (read_buf[offset + 3] != 0x86 || (read_buf[offset + 4] != 65)) { + return STATUS_FAILED; + } + } else { + return STATUS_FAILED; + } + pTranscv_Info->sSendData[4] = tag7f49Off; + memcpy(&(pTranscv_Info->sSendData[5]), &read_buf[0], tag7f49Off); + pTranscv_Info->sSendlength = tag7f49Off + 5; + ALOGD("%s: start transceive for length %d", fn, + pTranscv_Info->sSendlength); + + status = LSC_SendtoLsc(Os_info, status, pTranscv_Info, LS_Default); + if (status != STATUS_OK) { + uint8_t* RecvData = pTranscv_Info->sRecvData; + Write_Response_To_OutFile(Os_info, RecvData, resp_len, LS_Cert); + return status; + } + + pTranscv_Info->sSendData[2] = 0x00; + pTranscv_Info->sSendData[4] = u7f49Len + tag5f37Len + 6; + memcpy(&(pTranscv_Info->sSendData[5]), &read_buf[tag7f49Off], + u7f49Len + tag5f37Len + 6); + pTranscv_Info->sSendlength = u7f49Len + tag5f37Len + 11; + ALOGD("%s: start transceive for length %d", fn, + pTranscv_Info->sSendlength); + + status = LSC_SendtoLsc(Os_info, status, pTranscv_Info, LS_Cert); + if (status != STATUS_OK) { + return status; + } else { + ALOGD("Certificate is verified"); + certf_found = STATUS_OK; + return status; + } + } else { + return STATUS_FAILED; + } + } else { + return STATUS_FAILED; + } + } + return status; +} + +/******************************************************************************* +** +** Function: Check_Complete_7F21_Tag +** +** Description: Traverses the 7F21 tag for verification of each sub tag with +** in the 7F21 tag. +** +** Returns: Success if all tags are verified +** +*******************************************************************************/ +tLSC_STATUS Check_Complete_7F21_Tag(Lsc_ImageInfo_t* Os_info, + Lsc_TranscieveInfo_t* pTranscv_Info, + uint8_t* read_buf, uint16_t* offset) { + static const char fn[] = "Check_Complete_7F21_Tag"; + + if (STATUS_OK == Check_Certificate_Tag(read_buf, offset)) { + if (STATUS_OK == Check_SerialNo_Tag(read_buf, offset)) { + if (STATUS_OK == Check_LSRootID_Tag(read_buf, offset)) { + if (STATUS_OK == Check_CertHoldID_Tag(read_buf, offset)) { + if (STATUS_OK == Check_Date_Tag(read_buf, offset)) { + uint8_t tag45Len = 0; + if (STATUS_OK == Check_45_Tag(read_buf, offset, &tag45Len)) { + if (STATUS_OK == Certificate_Verification(Os_info, pTranscv_Info, + read_buf, offset, + &tag45Len)) { + return STATUS_OK; + } + } else { + ALOGE("%s: FAILED in Check_45_Tag", fn); + } + } else { + ALOGE("%s: FAILED in Check_Date_Tag", fn); + } + } else { + ALOGE("%s: FAILED in Check_CertHoldID_Tag", fn); + } + } else { + ALOGE("%s: FAILED in Check_LSRootID_Tag", fn); + } + } else { + ALOGE("%s: FAILED in Check_SerialNo_Tag", fn); + } + } else { + ALOGE("%s: FAILED in Check_Certificate_Tag", fn); + } + return STATUS_FAILED; +} + +/******************************************************************************* +** +** Function: LSC_UpdateExeStatus +** +** Description: Updates LSC status to a file +** +** Returns: true if success else false +** +*******************************************************************************/ +bool LSC_UpdateExeStatus(uint16_t status) { + fLS_STATUS = fopen(LS_STATUS_PATH[gpLsc_Dwnld_Context->mchannel + ->getInterfaceInfo()], "w+"); + ALOGD("enter: LSC_UpdateExeStatus"); + if (fLS_STATUS == NULL) { + ALOGE("Error opening LS Status file for backup: %s", strerror(errno)); + return false; + } + if ((fprintf(fLS_STATUS, "%04x", status)) != 4) { + ALOGE("Error updating LS Status backup: %s", strerror(errno)); + fclose(fLS_STATUS); + return false; + } + ALOGD("exit: LSC_UpdateExeStatus"); + fclose(fLS_STATUS); + return true; +} + +/******************************************************************************* +** +** Function: Get_LsStatus +** +** Description: Interface to fetch Loader service client status to JNI, +*Services +** +** Returns: SUCCESS/FAILURE +** +*******************************************************************************/ +tLSC_STATUS Get_LsStatus(uint8_t* pStatus) { + tLSC_STATUS status = STATUS_FAILED; + uint8_t lsStatus[2] = {0x63, 0x40}; + uint8_t loopcnt = 0; + fLS_STATUS = fopen(LS_STATUS_PATH[gpLsc_Dwnld_Context + ->mchannel->getInterfaceInfo()], "r"); + + if (fLS_STATUS == NULL) { + ALOGE("Error opening LS Status file for backup: %s", strerror(errno)); + return status; + } + for (loopcnt = 0; loopcnt < 2; loopcnt++) { + if ((FSCANF_BYTE(fLS_STATUS, "%2x", &lsStatus[loopcnt])) == 0) { + ALOGE("Error updating LS Status backup: %s", strerror(errno)); + fclose(fLS_STATUS); + return status; + } + } + ALOGD("enter: LSC_getLsStatus 0x%X 0x%X", lsStatus[0], lsStatus[1]); + memcpy(pStatus, lsStatus, 2); + fclose(fLS_STATUS); + return STATUS_OK; +} + +static tLSC_STATUS LSC_Transceive(phNxpLs_data* pCmd, phNxpLs_data* pRsp) +{ + bool stat = false; + tLSC_STATUS status = STATUS_FAILED; + int32_t recvBufferActualSize = 0; + IChannel_t *mchannel = gpLsc_Dwnld_Context->mchannel; + Lsc_TranscieveInfo_t* pTranscv_Info = &gpLsc_Dwnld_Context->Transcv_Info; + + pTranscv_Info->timeout = gTransceiveTimeout; + pTranscv_Info->sSendlength = pCmd->len; + pTranscv_Info->sRecvlength = 1024;//(int32_t)sizeof(int32_t); + + memcpy(pTranscv_Info->sSendData, pCmd->p_data, pTranscv_Info->sSendlength); + stat = mchannel->transceive (pTranscv_Info->sSendData, + pTranscv_Info->sSendlength, + pTranscv_Info->sRecvData, + pTranscv_Info->sRecvlength, + recvBufferActualSize, + pTranscv_Info->timeout); + if(stat == true) + { + pRsp->len = recvBufferActualSize; + //memcpy(pRsp->p_data, pTranscv_Info->sRecvData, recvBufferActualSize); + pRsp->p_data = pTranscv_Info->sRecvData; + status = STATUS_OK; + } + return status; + +} diff --git a/nfc_vendor_product.mk b/nfc_vendor_product.mk new file mode 100644 index 0000000..52be57d --- /dev/null +++ b/nfc_vendor_product.mk @@ -0,0 +1,20 @@ +# Enable build support for NFC open source vendor modules +ifeq ($(call is-board-platform-in-list, sdm845 sdm710 qcs605),true) +TARGET_USES_NQ_NFC := true +endif + +NQ_VENDOR_NFC += vendor.nxp.hardware.nfc@1.2-service +NQ_VENDOR_NFC += nfc_nci.nqx.default.hw + +ifeq ($(strip $(TARGET_USES_NQ_NFC)),true) +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/com.nxp.mifare.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/com.nxp.mifare.xml \ + frameworks/native/data/etc/com.android.nfc_extras.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/com.android.nfc_extras.xml \ + frameworks/native/data/etc/android.hardware.nfc.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.nfc.xml \ + frameworks/native/data/etc/android.hardware.nfc.hce.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.nfc.hce.xml \ + frameworks/native/data/etc/android.hardware.nfc.hcef.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.nfc.hcef.xml \ + vendor/nxp/opensource/halimpl/halimpl/libnfc-nci.conf:$(TARGET_COPY_OUT_VENDOR)/etc/libnfc-nci.conf + +PRODUCT_PACKAGES += $(NQ_VENDOR_NFC) +endif + diff --git a/src/eSEClientIntf.cc b/src/eSEClientIntf.cc new file mode 100644 index 0000000..aa4bef9 --- /dev/null +++ b/src/eSEClientIntf.cc @@ -0,0 +1,286 @@ +/****************************************************************************** + * + * Copyright 2018 NXP + * + * 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. + * + ******************************************************************************/ + +#include "eSEClientIntf.h" +#include <cutils/log.h> +#include <dirent.h> +#include <stdlib.h> +#include <pthread.h> +#include <IChannel.h> +#include <JcDnld.h> +#include <unistd.h> +#include <sys/stat.h> +#include <phNxpConfig.h> +#include "phNxpConfig.h" +#include <android-base/logging.h> +#include <android-base/stringprintf.h> + +#define TERMINAL_LEN 5 +bool nfc_debug_enabled; +void* performJCOS_Download_thread(void* data); +IChannel_t Ch; +static const char *path[3] = {"/vendor/etc/JcopOs_Update1.apdu", + "/vendor/etc/JcopOs_Update2.apdu", + "/vendor/etc/JcopOs_Update3.apdu"}; + +static const char *uai_path[2] = {"/vendor/etc/cci.jcsh", + "/vendor/etc/jci.jcsh"}; +static const char *isSystemImgInfo[2] = {"/data/vendor/nfc/jcop_info.txt", + "/data/vendor/secure_element/jcop_info.txt"}; +static const char *lsUpdateBackupPath = +"/vendor/etc/loaderservice_updater.txt"; +static const char *isFirstTimeLsUpdate[2] = +{"/data/vendor/nfc/LS_Status.txt", + "/data/vendor/secure_element/LS_Status.txt"}; +se_extns_entry seExtn; + +static bool scriptUpdateRequired(ESE_CLIENT_INTF intf); +static bool jcopOsUpdateRequired(ESE_CLIENT_INTF intf); +/******************************************************************************* +** +** Function: checkeSEClientUpdateRequired +** +** Description: HAL service entry criteria is verified +** Read the interface and condition for ese Update(JCOP download/LS download) +** from the config file and file path and validate. +** +** Returns: SUCCESS of ok +** +*******************************************************************************/ +uint8_t checkeSEClientRequired(ESE_CLIENT_INTF intf ) { + uint8_t status = SESTATUS_FAILED; + unsigned long int num; + bool isApduPresent = true; + bool isSystemImgUpdated = false; + bool isLsScriptPresent = true; + bool isFirstLsUpdate = false; + struct stat st; + + LOG(ERROR) <<"Check_HalStart_Entry: enter: "; + /*Check APDU files are present*/ + for (int num = 0; num < 2; num++) + { + if (stat(uai_path[num], &st)) + { + isApduPresent = false; + } + } + /*If UAI specific files are present*/ + if(isApduPresent == true) + { + for (int num = 0; num < 1; num++) + { + if (stat(path[num], &st)) + { + isApduPresent = false; + } + } + } + /*Check if OS udpate required*/ + isSystemImgUpdated = jcopOsUpdateRequired(intf); + + /*Check if LS script present*/ + if(stat(lsUpdateBackupPath, &st)) + { + isLsScriptPresent = false; + } + /*Check if LS update required*/ + isFirstLsUpdate = scriptUpdateRequired(intf); + + if(GetNxpNumValue(NAME_NXP_P61_JCOP_DEFAULT_INTERFACE, &num, sizeof(num))) { + seExtn.sJcopUpdateIntferface = num; + } + if(GetNxpNumValue(NAME_NXP_P61_LS_DEFAULT_INTERFACE, &num, sizeof(num))) { + seExtn.sLsUpdateIntferface = num; + } + if(GetNxpNumValue(NAME_NXP_LS_FORCE_UPDATE_REQUIRED, &num, sizeof(num))) { + seExtn.isLSUpdateRequired = num; + } + if(GetNxpNumValue(NAME_NXP_JCOP_FORCE_UPDATE_REQUIRED, &num, sizeof(num))) { + seExtn.isJcopUpdateRequired = num; + } + if(isApduPresent && seExtn.sJcopUpdateIntferface && + ((isSystemImgUpdated && (intf == seExtn.sJcopUpdateIntferface)) + || seExtn.isJcopUpdateRequired)) + { + LOG(ERROR) <<" Jcop update required "; + seExtn.isJcopUpdateRequired = true; + } + else + { + LOG(ERROR) <<"Jcop update not required "; + seExtn.isJcopUpdateRequired = false; + } + + if(isLsScriptPresent && seExtn.sLsUpdateIntferface && + (seExtn.isLSUpdateRequired || (isFirstLsUpdate && + (intf == seExtn.sLsUpdateIntferface)))) + { + LOG(ERROR) <<" LS update required "; + seExtn.isLSUpdateRequired = true; + } + else + { + LOG(ERROR) <<" LS update not required "; + seExtn.isLSUpdateRequired = false; + } + return status; +} + +/******************************************************************************* +** +** Function: scriptUpdateRequired +** +** Description: Get SEMS script update required +** +** Returns: TRUE/FALSE +** +*******************************************************************************/ +bool scriptUpdateRequired(ESE_CLIENT_INTF intf) +{ + bool mScriptUpdateRequired = false; + uint32_t status[2] = {SEMS_STATUS_FAILED_SW1, SEMS_STATUS_FAILED_SW2}; + FILE* fLS_STATUS = fopen(isFirstTimeLsUpdate[intf-1], "r"); + + if (fLS_STATUS == NULL) { + LOG(ERROR) <<"Error opening status file"; + mScriptUpdateRequired = true; + } + else { + if ((fscanf(fLS_STATUS, "%2x %2x", &status[0], &status[1])) == 0) { + LOG(ERROR) <<"Error reading status file:"; + status[0] = SEMS_STATUS_FAILED_SW1; + status[1] = SEMS_STATUS_FAILED_SW2; + } + if(status[0] == SEMS_STATUS_SUCCESS_SW1 && + status[1] == SEMS_STATUS_SUCCESS_SW2) { + mScriptUpdateRequired = false; + LOG(ERROR) <<"Last script execution success"; + } + else { + mScriptUpdateRequired = true; + LOG(ERROR) <<"Last script execution failed "; + } + fclose(fLS_STATUS); + } + return mScriptUpdateRequired; +} +/******************************************************************************* +** +** Function: jcopOsUpdateRequired +** +** Description: Get JCOP update required +** +** Returns: TRUE/FALSE +** +*******************************************************************************/ +bool jcopOsUpdateRequired(ESE_CLIENT_INTF intf) +{ + bool isUpdateRequired = false; + uint32_t status = 0; + FILE* fp = fopen(isSystemImgInfo[intf-1], "r"); + + if (fp == NULL) { + LOG(ERROR) <<"jcopOsUpdateRequired : file not exits for reading"; + isUpdateRequired = true; + } + else { + if (fscanf(fp, "%u", &status) == 0) { + LOG(ERROR) <<"jcop status read fail"; + isUpdateRequired = true; + } + else { + LOG(ERROR) << "JcopOsState: "<< status; + if (status == JCOP_UPDATE_3STEP_DONE) { + isUpdateRequired = false; + LOG(ERROR) <<"jcopOsUpdateRequired : Jcop update completed"; + } + else { + LOG(ERROR) << "jcopOsUpdateRequired : Jcop update required"; + isUpdateRequired = true; + } + } + fclose(fp); + } + return isUpdateRequired; +} + +uint8_t getJcopUpdateRequired() +{ + return seExtn.isJcopUpdateRequired; +} +uint8_t getLsUpdateRequired() +{ + return seExtn.isLSUpdateRequired; +} +uint8_t getJcopUpdateIntf() +{ + return seExtn.sJcopUpdateIntferface; +} +uint8_t getLsUpdateIntf() +{ + return seExtn.sLsUpdateIntferface; +} + +void setJcopUpdateRequired(uint8_t state) +{ + seExtn.isJcopUpdateRequired = state; +} + +void setLsUpdateRequired(uint8_t state) +{ + seExtn.isLSUpdateRequired = state; +} + +bool geteSETerminalId(char* val) +{ + bool ret = false; + + if(GetNxpStrValue(NAME_NXP_SPI_SE_TERMINAL_NUM, val, TERMINAL_LEN)) + { + LOG(ERROR) <<"eSETerminalId found"; + ALOGE("eSETerminalId found val = %s ", val); + + ret = true; + } + return ret; +} + +bool geteUICCTerminalId(char* val) +{ + bool ret = false; + + if(GetNxpStrValue(NAME_NXP_VISO_SE_TERMINAL_NUM, val, TERMINAL_LEN)) + { + ALOGE("eUICCTerminalId found val = %s ", val); + ret = true; + } + return ret; +} + +bool getNfcSeTerminalId(char* val) +{ + bool ret = false; + + if(GetNxpStrValue(NAME_NXP_NFC_SE_TERMINAL_NUM, val, TERMINAL_LEN)) + { + ALOGE("NfcSeTerminalId found val = %s ", val); + ret = true; + } + return ret; +} diff --git a/src/phNxpLog.cc b/src/phNxpLog.cc new file mode 100644 index 0000000..c7f211f --- /dev/null +++ b/src/phNxpLog.cc @@ -0,0 +1,260 @@ +/* + * Copyright (C) 2010-2014 NXP Semiconductors + * + * 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. + */ +#define LOG_TAG "NxpNfcHal" +#include <stdio.h> +#include <string.h> +#if !defined(NXPLOG__H_INCLUDED) +#include "phNxpConfig.h" +#include "phNxpLog.h" +#endif +#include <cutils/properties.h> +#include <log/log.h> + +const char* NXPLOG_ITEM_EXTNS = "NxpExtns"; +const char* NXPLOG_ITEM_NCIHAL = "NxpHal"; +const char* NXPLOG_ITEM_NCIX = "NxpNciX"; +const char* NXPLOG_ITEM_NCIR = "NxpNciR"; +const char* NXPLOG_ITEM_FWDNLD = "NxpFwDnld"; +const char* NXPLOG_ITEM_TML = "NxpTml"; + +#ifdef NXP_HCI_REQ +const char* NXPLOG_ITEM_HCPX = "NxpHcpX"; +const char* NXPLOG_ITEM_HCPR = "NxpHcpR"; +#endif /*NXP_HCI_REQ*/ + +/* global log level structure */ +nci_log_level_t gLog_level; + +extern bool nfc_debug_enabled; + +/******************************************************************************* + * + * Function phNxpLog_SetGlobalLogLevel + * + * Description Sets the global log level for all modules. + * This value is set by Android property + *nfc.nxp_log_level_global. + * If value can be overridden by module log level. + * + * Returns The value of global log level + * + ******************************************************************************/ +static uint8_t phNxpLog_SetGlobalLogLevel(void) { + uint8_t level = NXPLOG_DEFAULT_LOGLEVEL; + unsigned long num = 0; + char valueStr[PROPERTY_VALUE_MAX] = {0}; + + int len = property_get(PROP_NAME_NXPLOG_GLOBAL_LOGLEVEL, valueStr, ""); + if (len > 0) { + /* let Android property override .conf variable */ + sscanf(valueStr, "%lu", &num); + level = (unsigned char)num; + } + memset(&gLog_level, level, sizeof(nci_log_level_t)); + return level; +} + +/******************************************************************************* + * + * Function phNxpLog_SetHALLogLevel + * + * Description Sets the HAL layer log level. + * + * Returns void + * + ******************************************************************************/ +static void phNxpLog_SetHALLogLevel(uint8_t level) { + unsigned long num = 0; + int len; + char valueStr[PROPERTY_VALUE_MAX] = {0}; + + if (GetNxpNumValue(NAME_NXPLOG_HAL_LOGLEVEL, &num, sizeof(num))) { + gLog_level.hal_log_level = + (level > (unsigned char)num) ? level : (unsigned char)num; + ; + } + + len = property_get(PROP_NAME_NXPLOG_HAL_LOGLEVEL, valueStr, ""); + if (len > 0) { + /* let Android property override .conf variable */ + sscanf(valueStr, "%lu", &num); + gLog_level.hal_log_level = (unsigned char)num; + } +} + +/******************************************************************************* + * + * Function phNxpLog_SetExtnsLogLevel + * + * Description Sets the Extensions layer log level. + * + * Returns void + * + ******************************************************************************/ +static void phNxpLog_SetExtnsLogLevel(uint8_t level) { + unsigned long num = 0; + int len; + char valueStr[PROPERTY_VALUE_MAX] = {0}; + if (GetNxpNumValue(NAME_NXPLOG_EXTNS_LOGLEVEL, &num, sizeof(num))) { + gLog_level.extns_log_level = + (level > (unsigned char)num) ? level : (unsigned char)num; + ; + } + + len = property_get(PROP_NAME_NXPLOG_EXTNS_LOGLEVEL, valueStr, ""); + if (len > 0) { + /* let Android property override .conf variable */ + sscanf(valueStr, "%lu", &num); + gLog_level.extns_log_level = (unsigned char)num; + } +} + +/******************************************************************************* + * + * Function phNxpLog_SetTmlLogLevel + * + * Description Sets the Tml layer log level. + * + * Returns void + * + ******************************************************************************/ +static void phNxpLog_SetTmlLogLevel(uint8_t level) { + unsigned long num = 0; + int len; + char valueStr[PROPERTY_VALUE_MAX] = {0}; + if (GetNxpNumValue(NAME_NXPLOG_TML_LOGLEVEL, &num, sizeof(num))) { + gLog_level.tml_log_level = + (level > (unsigned char)num) ? level : (unsigned char)num; + ; + } + + len = property_get(PROP_NAME_NXPLOG_TML_LOGLEVEL, valueStr, ""); + if (len > 0) { + /* let Android property override .conf variable */ + sscanf(valueStr, "%lu", &num); + gLog_level.tml_log_level = (unsigned char)num; + } +} + +/******************************************************************************* + * + * Function phNxpLog_SetDnldLogLevel + * + * Description Sets the FW download layer log level. + * + * Returns void + * + ******************************************************************************/ +static void phNxpLog_SetDnldLogLevel(uint8_t level) { + unsigned long num = 0; + int len; + char valueStr[PROPERTY_VALUE_MAX] = {0}; + if (GetNxpNumValue(NAME_NXPLOG_FWDNLD_LOGLEVEL, &num, sizeof(num))) { + gLog_level.dnld_log_level = + (level > (unsigned char)num) ? level : (unsigned char)num; + ; + } + + len = property_get(PROP_NAME_NXPLOG_FWDNLD_LOGLEVEL, valueStr, ""); + if (len > 0) { + /* let Android property override .conf variable */ + sscanf(valueStr, "%lu", &num); + gLog_level.dnld_log_level = (unsigned char)num; + } +} + +/******************************************************************************* + * + * Function phNxpLog_SetNciTxLogLevel + * + * Description Sets the NCI transaction layer log level. + * + * Returns void + * + ******************************************************************************/ +static void phNxpLog_SetNciTxLogLevel(uint8_t level) { + unsigned long num = 0; + int len; + char valueStr[PROPERTY_VALUE_MAX] = {0}; + if (GetNxpNumValue(NAME_NXPLOG_NCIX_LOGLEVEL, &num, sizeof(num))) { + gLog_level.ncix_log_level = + (level > (unsigned char)num) ? level : (unsigned char)num; + } + if (GetNxpNumValue(NAME_NXPLOG_NCIR_LOGLEVEL, &num, sizeof(num))) { + gLog_level.ncir_log_level = + (level > (unsigned char)num) ? level : (unsigned char)num; + ; + } + + len = property_get(PROP_NAME_NXPLOG_NCI_LOGLEVEL, valueStr, ""); + if (len > 0) { + /* let Android property override .conf variable */ + sscanf(valueStr, "%lu", &num); + gLog_level.ncix_log_level = (unsigned char)num; + gLog_level.ncir_log_level = (unsigned char)num; + } +} + +/****************************************************************************** + * Function phNxpLog_InitializeLogLevel + * + * Description Initialize and get log level of module from libnfc-nxp.conf + *or + * Android runtime properties. + * The Android property nfc.nxp_global_log_level is to + * define log level for all modules. Modules log level will + *overwide global level. + * The Android property will overwide the level + * in libnfc-nxp.conf + * + * Android property names: + * nfc.nxp_log_level_global * defines log level for all + *modules + * nfc.nxp_log_level_extns * extensions module log + * nfc.nxp_log_level_hal * Hal module log + * nfc.nxp_log_level_dnld * firmware download module + *log + * nfc.nxp_log_level_tml * TML module log + * nfc.nxp_log_level_nci * NCI transaction log + * + * Log Level values: + * NXPLOG_LOG_SILENT_LOGLEVEL 0 * No trace to show + * NXPLOG_LOG_ERROR_LOGLEVEL 1 * Show Error trace + *only + * NXPLOG_LOG_WARN_LOGLEVEL 2 * Show Warning + *trace and Error trace + * NXPLOG_LOG_DEBUG_LOGLEVEL 3 * Show all traces + * + * Returns void + * + ******************************************************************************/ +void phNxpLog_InitializeLogLevel(void) { + uint8_t level = phNxpLog_SetGlobalLogLevel(); + phNxpLog_SetHALLogLevel(level); + phNxpLog_SetExtnsLogLevel(level); + phNxpLog_SetTmlLogLevel(level); + phNxpLog_SetDnldLogLevel(level); + phNxpLog_SetNciTxLogLevel(level); + + ALOGD_IF(nfc_debug_enabled, + "%s: global =%u, Fwdnld =%u, extns =%u, \ + hal =%u, tml =%u, ncir =%u, \ + ncix =%u", + __func__, gLog_level.global_log_level, gLog_level.dnld_log_level, + gLog_level.extns_log_level, gLog_level.hal_log_level, + gLog_level.tml_log_level, gLog_level.ncir_log_level, + gLog_level.ncix_log_level); +} diff --git a/utils/phNxpConfig.cc b/utils/phNxpConfig.cc new file mode 100644 index 0000000..5774c36 --- /dev/null +++ b/utils/phNxpConfig.cc @@ -0,0 +1,1090 @@ +/****************************************************************************** + * + * Copyright (C) 2011-2012 Broadcom Corporation + * + * 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. + * + ******************************************************************************/ + +/****************************************************************************** + * + * The original Work has been changed by NXP Semiconductors. + * + * Copyright (C) 2013-2018 NXP Semiconductors + * + * 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. + * + ******************************************************************************/ + +#include <stdio.h> +#include <sys/stat.h> +#include <list> +#include <string> +#include <vector> +#include <log/log.h> + +#include <phNxpConfig.h> +#include <phNxpLog.h> +#include "sparse_crc32.h" +#if GENERIC_TARGET +const char alternative_config_path[] = "/data/vendor/nfc/"; +#else +const char alternative_config_path[] = ""; +#endif + +#if 1 +const char* transport_config_paths[] = {"/odm/etc/", "/vendor/etc/", "/etc/"}; +#else +const char* transport_config_paths[] = {"res/"}; +#endif +const int transport_config_path_size = + (sizeof(transport_config_paths) / sizeof(transport_config_paths[0])); + +#define config_name "libnfc-nxp.conf" +#define extra_config_base "libnfc-" +#define extra_config_ext ".conf" +#define IsStringValue 0x80000000 + +const char rf_config_timestamp_path[] = + "/data/vendor/nfc/libnfc-nxpRFConfigState.bin"; +const char tr_config_timestamp_path[] = + "/data/vendor/nfc/libnfc-nxpTransitConfigState.bin"; +const char config_timestamp_path[] = + "/data/vendor/nfc/libnfc-nxpConfigState.bin"; +/*const char default_nxp_config_path[] = + "/vendor/etc/libnfc-nxp.conf";*/ +const char nxp_rf_config_path[] = + "/system/vendor/libnfc-nxp_RF.conf"; +const char transit_config_path[] = "/data/vendor/nfc/libnfc-nxpTransit.conf"; +void readOptionalConfig(const char* optional); + +namespace { + +size_t readConfigFile(const char* fileName, uint8_t** p_data) { + FILE* fd = fopen(fileName, "rb"); + if (fd == nullptr) return 0; + + fseek(fd, 0L, SEEK_END); + const size_t file_size = ftell(fd); + rewind(fd); + + uint8_t* buffer = new uint8_t[file_size]; + size_t read = fread(buffer, file_size, 1, fd); + fclose(fd); + + if (read == 1) { + *p_data = buffer; + return file_size; + } + + delete[] buffer; + return 0; +} + +} // namespace + +using namespace ::std; + +class CNfcParam : public string { + public: + CNfcParam(); + CNfcParam(const char* name, const string& value); + CNfcParam(const char* name, unsigned long value); + virtual ~CNfcParam(); + unsigned long numValue() const { return m_numValue; } + const char* str_value() const { return m_str_value.c_str(); } + size_t str_len() const { return m_str_value.length(); } + + private: + string m_str_value; + unsigned long m_numValue; +}; + +class CNfcConfig : public vector<const CNfcParam*> { + public: + virtual ~CNfcConfig(); + static CNfcConfig& GetInstance(); + friend void readOptionalConfig(const char* optional); + bool isModified(); + void resetModified(); + int updateTimestamp(); + int checkTimestamp(const char* fileName, const char* fileTimeStamp); + + bool getValue(const char* name, char* pValue, size_t len) const; + bool getValue(const char* name, unsigned long& rValue) const; + bool getValue(const char* name, unsigned short& rValue) const; + bool getValue(const char* name, char* pValue, long len, long* readlen) const; + const CNfcParam* find(const char* p_name) const; + void readNxpTransitConfig(const char* fileName) const; + void readNxpRFConfig(const char* fileName) const; + void clean(); + + private: + CNfcConfig(); + bool readConfig(const char* name, bool bResetContent); + void moveFromList(); + void moveToList(); + void add(const CNfcParam* pParam); + void dump(); + bool isAllowed(const char* name); + list<const CNfcParam*> m_list; + bool mValidFile; + uint32_t config_crc32_; + unsigned long m_timeStamp; + unsigned long m_timeStampRF; + unsigned long m_timeStampTransit; + string mCurrentFile; + + unsigned long state; + + inline bool Is(unsigned long f) { return (state & f) == f; } + inline void Set(unsigned long f) { state |= f; } + inline void Reset(unsigned long f) { state &= ~f; } +}; + +/******************************************************************************* +** +** Function: isPrintable() +** +** Description: determine if 'c' is printable +** +** Returns: 1, if printable, otherwise 0 +** +*******************************************************************************/ +inline bool isPrintable(char c) { + return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || + (c >= '0' && c <= '9') || c == '/' || c == '_' || c == '-' || c == '.'; +} + +/******************************************************************************* +** +** Function: isDigit() +** +** Description: determine if 'c' is numeral digit +** +** Returns: true, if numerical digit +** +*******************************************************************************/ +inline bool isDigit(char c, int base) { + if ('0' <= c && c <= '9') return true; + if (base == 16) { + if (('A' <= c && c <= 'F') || ('a' <= c && c <= 'f')) return true; + } + return false; +} + +/******************************************************************************* +** +** Function: getDigitValue() +** +** Description: return numerical value of a decimal or hex char +** +** Returns: numerical value if decimal or hex char, otherwise 0 +** +*******************************************************************************/ +inline int getDigitValue(char c, int base) { + if ('0' <= c && c <= '9') return c - '0'; + if (base == 16) { + if ('A' <= c && c <= 'F') + return c - 'A' + 10; + else if ('a' <= c && c <= 'f') + return c - 'a' + 10; + } + return 0; +} + +/******************************************************************************* +** +** Function: findConfigFilePathFromTransportConfigPaths() +** +** Description: find a config file path with a given config name from transport +** config paths +** +** Returns: none +** +*******************************************************************************/ +void findConfigFilePathFromTransportConfigPaths(const string& configName, + string& filePath) { + for (int i = 0; i < transport_config_path_size - 1; i++) { + filePath.assign(transport_config_paths[i]); + filePath += configName; + struct stat file_stat; + if (stat(filePath.c_str(), &file_stat) == 0 && S_ISREG(file_stat.st_mode)) { + return; + } + } + filePath.assign(transport_config_paths[transport_config_path_size - 1]); + filePath += configName; +} + +/******************************************************************************* +** +** Function: CNfcConfig::readConfig() +** +** Description: read Config settings and parse them into a linked list +** move the element from linked list to a array at the end +** +** Returns: 1, if there are any config data, 0 otherwise +** +*******************************************************************************/ +bool CNfcConfig::readConfig(const char* name, bool bResetContent) { + enum { + BEGIN_LINE = 1, + TOKEN, + STR_VALUE, + NUM_VALUE, + BEGIN_HEX, + BEGIN_QUOTE, + END_LINE + }; + + uint8_t* p_config = nullptr; + size_t config_size = readConfigFile(name, &p_config); + if (p_config == nullptr) { + ALOGE("%s Cannot open config file %s\n", __func__, name); + if (bResetContent) { + ALOGE("%s Using default value for all settings\n", __func__); + mValidFile = false; + } + return false; + } + + string token; + string strValue; + unsigned long numValue = 0; + CNfcParam* pParam = NULL; + int i = 0; + int base = 0; + char c; + int bflag = 0; + state = BEGIN_LINE; + + config_crc32_ = sparse_crc32(0, (const void*)p_config, (int)config_size); + mValidFile = true; + if (size() > 0) { + if (bResetContent) + clean(); + else + moveToList(); + } + + for (size_t offset = 0; offset != config_size; ++offset) { + c = p_config[offset]; + switch (state & 0xff) { + case BEGIN_LINE: + if (c == '#') + state = END_LINE; + else if (isPrintable(c)) { + i = 0; + token.erase(); + strValue.erase(); + state = TOKEN; + token.push_back(c); + } + break; + case TOKEN: + if (c == '=') { + token.push_back('\0'); + state = BEGIN_QUOTE; + } else if (isPrintable(c)) + token.push_back(c); + else + state = END_LINE; + break; + case BEGIN_QUOTE: + if (c == '"') { + state = STR_VALUE; + base = 0; + } else if (c == '0') + state = BEGIN_HEX; + else if (isDigit(c, 10)) { + state = NUM_VALUE; + base = 10; + numValue = getDigitValue(c, base); + i = 0; + } else if (c == '{') { + state = NUM_VALUE; + bflag = 1; + base = 16; + i = 0; + Set(IsStringValue); + } else + state = END_LINE; + break; + case BEGIN_HEX: + if (c == 'x' || c == 'X') { + state = NUM_VALUE; + base = 16; + numValue = 0; + i = 0; + break; + } else if (isDigit(c, 10)) { + state = NUM_VALUE; + base = 10; + numValue = getDigitValue(c, base); + break; + } else if (c != '\n' && c != '\r') { + state = END_LINE; + break; + } + [[fallthrough]]; + // fall through to numValue to handle numValue + + case NUM_VALUE: + if (isDigit(c, base)) { + numValue *= base; + numValue += getDigitValue(c, base); + ++i; + } else if (bflag == 1 && + (c == ' ' || c == '\r' || c == '\n' || c == '\t')) { + break; + } else if (base == 16 && + (c == ',' || c == ':' || c == '-' || c == ' ' || c == '}')) { + if (c == '}') { + bflag = 0; + } + if (i > 0) { + int n = (i + 1) / 2; + while (n-- > 0) { + numValue = numValue >> (n * 8); + unsigned char c = (numValue)&0xFF; + strValue.push_back(c); + } + } + + Set(IsStringValue); + numValue = 0; + i = 0; + } else { + if (c == '\n' || c == '\r') { + if (bflag == 0) { + state = BEGIN_LINE; + } + } else { + if (bflag == 0) { + state = END_LINE; + } + } + if (Is(IsStringValue) && base == 16 && i > 0) { + int n = (i + 1) / 2; + while (n-- > 0) strValue.push_back(((numValue >> (n * 8)) & 0xFF)); + } + if (strValue.length() > 0) + pParam = new CNfcParam(token.c_str(), strValue); + else + pParam = new CNfcParam(token.c_str(), numValue); + add(pParam); + strValue.erase(); + numValue = 0; + } + break; + case STR_VALUE: + if (c == '"') { + strValue.push_back('\0'); + state = END_LINE; + pParam = new CNfcParam(token.c_str(), strValue); + add(pParam); + } else if (isPrintable(c)) + strValue.push_back(c); + break; + case END_LINE: + if (c == '\n' || c == '\r') state = BEGIN_LINE; + break; + default: + break; + } + } + + delete[] p_config; + + moveFromList(); + return size() > 0; +} + +/******************************************************************************* +** +** Function: CNfcConfig::CNfcConfig() +** +** Description: class constructor +** +** Returns: none +** +*******************************************************************************/ +CNfcConfig::CNfcConfig() + : mValidFile(true), + m_timeStamp(0), + m_timeStampRF(0), + m_timeStampTransit(0), + state(0) {} + +/******************************************************************************* +** +** Function: CNfcConfig::~CNfcConfig() +** +** Description: class destructor +** +** Returns: none +** +*******************************************************************************/ +CNfcConfig::~CNfcConfig() {} + +/******************************************************************************* +** +** Function: CNfcConfig::GetInstance() +** +** Description: get class singleton object +** +** Returns: none +** +*******************************************************************************/ +CNfcConfig& CNfcConfig::GetInstance() { + static CNfcConfig theInstance; + + if (theInstance.size() == 0 && theInstance.mValidFile) { + string strPath; + if (alternative_config_path[0] != '\0') { + strPath.assign(alternative_config_path); + strPath += config_name; + theInstance.readConfig(strPath.c_str(), true); + if (!theInstance.empty()) { + return theInstance; + } + } + findConfigFilePathFromTransportConfigPaths(config_name, strPath); + theInstance.readConfig(strPath.c_str(), true); +#if (NXP_EXTNS == TRUE) + readOptionalConfig("brcm"); + theInstance.readNxpTransitConfig(transit_config_path); + theInstance.readNxpRFConfig(nxp_rf_config_path); +#endif + } + + return theInstance; +} + +/******************************************************************************* +** +** Function: CNfcConfig::getValue() +** +** Description: get a string value of a setting +** +** Returns: true if setting exists +** false if setting does not exist +** +*******************************************************************************/ +bool CNfcConfig::getValue(const char* name, char* pValue, size_t len) const { + const CNfcParam* pParam = find(name); + if (pParam == NULL) return false; + + if (pParam->str_len() > 0) { + memset(pValue, 0, len); + memcpy(pValue, pParam->str_value(), pParam->str_len()); + return true; + } + return false; +} + +bool CNfcConfig::getValue(const char* name, char* pValue, long len, + long* readlen) const { + const CNfcParam* pParam = find(name); + if (pParam == NULL) return false; + + if (pParam->str_len() > 0) { + if (pParam->str_len() <= (unsigned long)len) { + memset(pValue, 0, len); + memcpy(pValue, pParam->str_value(), pParam->str_len()); + *readlen = pParam->str_len(); + } else { + *readlen = -1; + } + + return true; + } + return false; +} + +/******************************************************************************* +** +** Function: CNfcConfig::getValue() +** +** Description: get a long numerical value of a setting +** +** Returns: true if setting exists +** false if setting does not exist +** +*******************************************************************************/ +bool CNfcConfig::getValue(const char* name, unsigned long& rValue) const { + const CNfcParam* pParam = find(name); + if (pParam == NULL) return false; + + if (pParam->str_len() == 0) { + rValue = static_cast<unsigned long>(pParam->numValue()); + return true; + } + return false; +} + +/******************************************************************************* +** +** Function: CNfcConfig::getValue() +** +** Description: get a short numerical value of a setting +** +** Returns: true if setting exists +** false if setting does not exist +** +*******************************************************************************/ +bool CNfcConfig::getValue(const char* name, unsigned short& rValue) const { + const CNfcParam* pParam = find(name); + if (pParam == NULL) return false; + + if (pParam->str_len() == 0) { + rValue = static_cast<unsigned short>(pParam->numValue()); + return true; + } + return false; +} + +/******************************************************************************* +** +** Function: CNfcConfig::find() +** +** Description: search if a setting exist in the setting array +** +** Returns: pointer to the setting object +** +*******************************************************************************/ +const CNfcParam* CNfcConfig::find(const char* p_name) const { + if (size() == 0) return NULL; + + for (const_iterator it = begin(), itEnd = end(); it != itEnd; ++it) { + if (**it < p_name) { + continue; + } else if (**it == p_name) { + if ((*it)->str_len() > 0) { + NXPLOG_EXTNS_D("%s found %s=%s\n", __func__, p_name, + (*it)->str_value()); + } else { + NXPLOG_EXTNS_D("%s found %s=(0x%lx)\n", __func__, p_name, + (*it)->numValue()); + } + return *it; + } else + break; + } + return NULL; +} + +/******************************************************************************* +** +** Function: CNfcConfig::readNxpTransitConfig() +** +** Description: read Config settings from transit conf file +** +** Returns: none +** +*******************************************************************************/ +void CNfcConfig::readNxpTransitConfig(const char* fileName) const { + ALOGD("readNxpTransitConfig-Enter..Reading %s", fileName); + CNfcConfig::GetInstance().readConfig(fileName, false); +} + +/******************************************************************************* +** +** Function: CNfcConfig::readNxpRFConfig() +** +** Description: read Config settings from RF conf file +** +** Returns: none +** +*******************************************************************************/ +void CNfcConfig::readNxpRFConfig(const char* fileName) const { + ALOGD("readNxpRFConfig-Enter..Reading %s", fileName); + CNfcConfig::GetInstance().readConfig(fileName, false); +} + +/******************************************************************************* +** +** Function: CNfcConfig::clean() +** +** Description: reset the setting array +** +** Returns: none +** +*******************************************************************************/ +void CNfcConfig::clean() { + if (size() == 0) return; + + for (iterator it = begin(), itEnd = end(); it != itEnd; ++it) delete *it; + clear(); +} + +/******************************************************************************* +** +** Function: CNfcConfig::Add() +** +** Description: add a setting object to the list +** +** Returns: none +** +*******************************************************************************/ +void CNfcConfig::add(const CNfcParam* pParam) { + if (m_list.size() == 0) { + m_list.push_back(pParam); + return; + } + if ((mCurrentFile.find("nxpTransit") != std::string::npos) && + !isAllowed(pParam->c_str())) { + ALOGD("%s Token restricted. Returning", __func__); + return; + } + for (list<const CNfcParam*>::iterator it = m_list.begin(), + itEnd = m_list.end(); + it != itEnd; ++it) { + if (**it < pParam->c_str()) continue; + if (**it == pParam->c_str()) + m_list.insert(m_list.erase(it), pParam); + else + m_list.insert(it, pParam); + + return; + } + m_list.push_back(pParam); +} +/******************************************************************************* +** +** Function: CNfcConfig::dump() +** +** Description: prints all elements in the list +** +** Returns: none +** +*******************************************************************************/ +void CNfcConfig::dump() { + ALOGD("%s Enter", __func__); + + for (list<const CNfcParam*>::iterator it = m_list.begin(), + itEnd = m_list.end(); + it != itEnd; ++it) { + if ((*it)->str_len() > 0) + ALOGD("%s %s \t= %s", __func__, (*it)->c_str(), (*it)->str_value()); + else + ALOGD("%s %s \t= (0x%0lX)\n", __func__, (*it)->c_str(), + (*it)->numValue()); + } +} +/******************************************************************************* +** +** Function: CNfcConfig::isAllowed() +** +** Description: checks if token update is allowed +** +** Returns: true if allowed else false +** +*******************************************************************************/ +bool CNfcConfig::isAllowed(const char* name) { + string token(name); + bool stat = false; + if ((token.find("P2P_LISTEN_TECH_MASK") != std::string::npos) || + (token.find("HOST_LISTEN_TECH_MASK") != std::string::npos) || + (token.find("UICC_LISTEN_TECH_MASK") != std::string::npos) || + (token.find("NXP_ESE_LISTEN_TECH_MASK") != std::string::npos) || + (token.find("POLLING_TECH_MASK") != std::string::npos) || + (token.find("NXP_RF_CONF_BLK") != std::string::npos) || + (token.find("NXP_CN_TRANSIT_BLK_NUM_CHECK_ENABLE") != + std::string::npos) || + (token.find("NXP_FWD_FUNCTIONALITY_ENABLE") != std::string::npos)) + + { + stat = true; + } + return stat; +} +/******************************************************************************* +** +** Function: CNfcConfig::moveFromList() +** +** Description: move the setting object from list to array +** +** Returns: none +** +*******************************************************************************/ +void CNfcConfig::moveFromList() { + if (m_list.size() == 0) return; + + for (list<const CNfcParam *>::iterator it = m_list.begin(), + itEnd = m_list.end(); + it != itEnd; ++it) + push_back(*it); + m_list.clear(); +} + +/******************************************************************************* +** +** Function: CNfcConfig::moveToList() +** +** Description: move the setting object from array to list +** +** Returns: none +** +*******************************************************************************/ +void CNfcConfig::moveToList() { + if (m_list.size() != 0) m_list.clear(); + + for (iterator it = begin(), itEnd = end(); it != itEnd; ++it) + m_list.push_back(*it); + clear(); +} +/******************************************************************************* +** +** Function: CNfcConfig::checkTimestamp(const char* fileName,const char* +*fileNameTime) +** +** Description: check if config file has modified +** +** Returns: 0 if not modified, 1 otherwise. +** +*******************************************************************************/ +int CNfcConfig::checkTimestamp(const char* fileName, const char* fileNameTime) { + FILE* fd; + struct stat st; + unsigned long value = 0, timeStamp = 0; + int ret = 0; + if (strcmp(config_timestamp_path, fileNameTime) == 0) { + timeStamp = m_timeStamp; + } else if (strcmp(rf_config_timestamp_path, fileNameTime) == 0) { + timeStamp = m_timeStampRF; + } else if (strcmp(tr_config_timestamp_path, fileNameTime) == 0) { + timeStamp = m_timeStampTransit; + } else + ALOGD("Invalid file \n"); + + if (stat(fileNameTime, &st) != 0) { + ALOGD("%s file not exist.\n", __func__); + if ((fd = fopen(fileNameTime, "w+")) != NULL) { + fwrite(&timeStamp, sizeof(unsigned long), 1, fd); + fclose(fd); + } + return 1; + } else { + fd = fopen(fileNameTime, "r+"); + if (fd == NULL) { + ALOGE("%s Cannot open file %s\n", __func__, fileName); + return 1; + } + fread(&value, sizeof(unsigned long), 1, fd); + ret = (value != timeStamp) ? 1 : 0; + if (ret) { + ALOGD("Config File Modified Update timestamp"); + fseek(fd, 0, SEEK_SET); + fwrite(&timeStamp, sizeof(unsigned long), 1, fd); + } + fclose(fd); + } + return ret; +} +/******************************************************************************* +** +** Function: CNfcConfig::updateTimestamp() +** +** Description: update if config file has modified +** +** Returns: 0 if not modified, 1 otherwise. +** +*******************************************************************************/ +int CNfcConfig::updateTimestamp() { + FILE* fd; + struct stat st; + unsigned long value = 0; + int ret = 0; + + if (stat(config_timestamp_path, &st) != 0) { + ALOGD("%s file %s not exist, creat it.\n", __func__, config_timestamp_path); + fd = fopen(config_timestamp_path, "w+"); + if (fd != NULL) { + fwrite(&m_timeStamp, sizeof(unsigned long), 1, fd); + fclose(fd); + } + return 1; + } else { + fd = fopen(config_timestamp_path, "r+"); + if (fd == NULL) { + ALOGE("%s Cannot open file %s\n", __func__, config_timestamp_path); + return 1; + } + + fread(&value, sizeof(unsigned long), 1, fd); + ret = (value != m_timeStamp); + if (ret) { + fseek(fd, 0, SEEK_SET); + fwrite(&m_timeStamp, sizeof(unsigned long), 1, fd); + } + fclose(fd); + } + return ret; +} + +bool CNfcConfig::isModified() { + FILE* fd = fopen(config_timestamp_path, "r+"); + if (fd == nullptr) { + ALOGE("%s Unable to open file '%s' - assuming modified", __func__, + config_timestamp_path); + return true; + } + + uint32_t stored_crc32 = 0; + fread(&stored_crc32, sizeof(uint32_t), 1, fd); + fclose(fd); + + return stored_crc32 != config_crc32_; +} + +void CNfcConfig::resetModified() { + FILE* fd = fopen(config_timestamp_path, "w+"); + if (fd == nullptr) { + ALOGE("%s Unable to open file '%s' for writing", __func__, + config_timestamp_path); + return; + } + + fwrite(&config_crc32_, sizeof(uint32_t), 1, fd); + fclose(fd); +} + +/******************************************************************************* +** +** Function: CNfcParam::CNfcParam() +** +** Description: class constructor +** +** Returns: none +** +*******************************************************************************/ +CNfcParam::CNfcParam() : m_numValue(0) {} + +/******************************************************************************* +** +** Function: CNfcParam::~CNfcParam() +** +** Description: class destructor +** +** Returns: none +** +*******************************************************************************/ +CNfcParam::~CNfcParam() {} + +/******************************************************************************* +** +** Function: CNfcParam::CNfcParam() +** +** Description: class copy constructor +** +** Returns: none +** +*******************************************************************************/ +CNfcParam::CNfcParam(const char* name, const string& value) + : string(name), m_str_value(value), m_numValue(0) {} + +/******************************************************************************* +** +** Function: CNfcParam::CNfcParam() +** +** Description: class copy constructor +** +** Returns: none +** +*******************************************************************************/ +CNfcParam::CNfcParam(const char* name, unsigned long value) + : string(name), m_numValue(value) {} + +/******************************************************************************* +** +** Function: readOptionalConfig() +** +** Description: read Config settings from an optional conf file +** +** Returns: none +** +*******************************************************************************/ +void readOptionalConfig(const char* extra) { + string strPath; + string configName(extra_config_base); + configName += extra; + configName += extra_config_ext; + + if (alternative_config_path[0] != '\0') { + strPath.assign(alternative_config_path); + strPath += configName; + } else { + findConfigFilePathFromTransportConfigPaths(configName, strPath); + } + + CNfcConfig::GetInstance().readConfig(strPath.c_str(), false); +} + +/******************************************************************************* +** +** Function: GetStrValue +** +** Description: API function for getting a string value of a setting +** +** Returns: True if found, otherwise False. +** +*******************************************************************************/ +extern "C" int GetNxpStrValue(const char* name, char* pValue, + unsigned long len) { + CNfcConfig& rConfig = CNfcConfig::GetInstance(); + + return rConfig.getValue(name, pValue, len); +} + +/******************************************************************************* +** +** Function: GetByteArrayValue() +** +** Description: Read byte array value from the config file. +** +** Parameters: +** name - name of the config param to read. +** pValue - pointer to input buffer. +** bufflen - input buffer length. +** len - out parameter to return the number of bytes read from +** config file, return -1 in case bufflen is not enough. +** +** Returns: TRUE[1] if config param name is found in the config file, else +** FALSE[0] +** +*******************************************************************************/ +extern "C" int GetNxpByteArrayValue(const char* name, char* pValue, + long bufflen, long* len) { + CNfcConfig& rConfig = CNfcConfig::GetInstance(); + + return rConfig.getValue(name, pValue, bufflen, len); +} + +/******************************************************************************* +** +** Function: GetNumValue +** +** Description: API function for getting a numerical value of a setting +** +** Returns: true, if successful +** +*******************************************************************************/ +extern "C" int GetNxpNumValue(const char* name, void* pValue, + unsigned long len) { + if (!pValue) return false; + + CNfcConfig& rConfig = CNfcConfig::GetInstance(); + const CNfcParam* pParam = rConfig.find(name); + + if (pParam == NULL) return false; + unsigned long v = pParam->numValue(); + if (v == 0 && pParam->str_len() > 0 && pParam->str_len() < 4) { + const unsigned char* p = (const unsigned char*)pParam->str_value(); + for (unsigned int i = 0; i < pParam->str_len(); ++i) { + v *= 256; + v += *p++; + } + } + switch (len) { + case sizeof(unsigned long): + *(static_cast<unsigned long*>(pValue)) = (unsigned long)v; + break; + case sizeof(unsigned short): + *(static_cast<unsigned short*>(pValue)) = (unsigned short)v; + break; + case sizeof(unsigned char): + *(static_cast<unsigned char*>(pValue)) = (unsigned char)v; + break; + default: + return false; + } + return true; +} + +/******************************************************************************* +** +** Function: resetConfig +** +** Description: reset settings array +** +** Returns: none +** +*******************************************************************************/ +extern "C" void resetNxpConfig() + +{ + CNfcConfig& rConfig = CNfcConfig::GetInstance(); + + rConfig.clean(); +} + +/******************************************************************************* +** +** Function: isNxpConfigModified() +** +** Description: check if config file has modified +** +** Returns: 0 if not modified, 1 otherwise. +** +*******************************************************************************/ +extern "C" int isNxpConfigModified() { + CNfcConfig& rConfig = CNfcConfig::GetInstance(); + return rConfig.isModified(); +} + +/******************************************************************************* +** +** Function: isNxpRFConfigModified() +** +** Description: check if config file has modified +** +** Returns: 0 if not modified, 1 otherwise. +** +*******************************************************************************/ +extern "C" int isNxpRFConfigModified() { + int retRF = 0, rettransit = 0, ret = 0; + CNfcConfig& rConfig = CNfcConfig::GetInstance(); + retRF = rConfig.checkTimestamp(nxp_rf_config_path, rf_config_timestamp_path); + rettransit = + rConfig.checkTimestamp(transit_config_path, tr_config_timestamp_path); + ret = retRF | rettransit; + ALOGD("ret RF or Transit value %d", ret); + return ret; +} + +/******************************************************************************* +** +** Function: updateNxpConfigTimestamp() +** +** Description: update if config file has modified +** +** Returns: 0 if not modified, 1 otherwise. +** +*******************************************************************************/ +extern "C" int updateNxpConfigTimestamp() { + CNfcConfig& rConfig = CNfcConfig::GetInstance(); + rConfig.resetModified(); + return 0; +} diff --git a/utils/phNxpConfig.h b/utils/phNxpConfig.h new file mode 100644 index 0000000..0dfae97 --- /dev/null +++ b/utils/phNxpConfig.h @@ -0,0 +1,142 @@ +/****************************************************************************** + * + * Copyright (C) 1999-2012 Broadcom Corporation + * + * 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. + * + ******************************************************************************/ + +/****************************************************************************** + * + * The original Work has been changed by NXP Semiconductors. + * + * Copyright (C) 2013-2018 NXP Semiconductors + * + * 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 __CONFIG_H +#define __CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +int GetNxpStrValue(const char* name, char* p_value, unsigned long len); +int GetNxpNumValue(const char* name, void* p_value, unsigned long len); +int GetNxpByteArrayValue(const char* name, char* pValue, long bufflen, + long* len); +void resetNxpConfig(void); +int isNxpRFConfigModified(); +int isNxpConfigModified(); +int updateNxpConfigTimestamp(); + +#ifdef __cplusplus +}; +#endif + +#define NAME_NXPLOG_EXTNS_LOGLEVEL "NXPLOG_EXTNS_LOGLEVEL" +#define NAME_NXPLOG_NCIHAL_LOGLEVEL "NXPLOG_NCIHAL_LOGLEVEL" +#define NAME_NXPLOG_NCIX_LOGLEVEL "NXPLOG_NCIX_LOGLEVEL" +#define NAME_NXPLOG_NCIR_LOGLEVEL "NXPLOG_NCIR_LOGLEVEL" +#define NAME_NXPLOG_FWDNLD_LOGLEVEL "NXPLOG_FWDNLD_LOGLEVEL" +#define NAME_NXPLOG_TML_LOGLEVEL "NXPLOG_TML_LOGLEVEL" + +#define NAME_MIFARE_READER_ENABLE "MIFARE_READER_ENABLE" +#define NAME_FW_STORAGE "FW_STORAGE" +#define NAME_NXP_NFC_DEV_NODE "NXP_NFC_DEV_NODE" +#define NAME_NXP_NFC_CHIP "NXP_NFC_CHIP" +#define NAME_NXP_FW_NAME "NXP_FW_NAME" +#define NAME_NXP_FW_TYPE "NXP_FW_TYPE" +#define NAME_NXP_FW_PROTECION_OVERRIDE "NXP_FW_PROTECION_OVERRIDE" +#define NAME_NXP_SYS_CLK_SRC_SEL "NXP_SYS_CLK_SRC_SEL" +#define NAME_NXP_SYS_CLK_FREQ_SEL "NXP_SYS_CLK_FREQ_SEL" +#define NAME_NXP_SYS_CLOCK_TO_CFG "NXP_SYS_CLOCK_TO_CFG" +#define NAME_NXP_CLOCK_REQ_DELAY "NXP_CLOCK_REQ_DELAY" +#define NAME_NXP_ACT_PROP_EXTN "NXP_ACT_PROP_EXTN" +#define NAME_NXP_EXT_TVDD_CFG "NXP_EXT_TVDD_CFG" +#define NAME_NXP_EXT_TVDD_CFG_1 "NXP_EXT_TVDD_CFG_1" +#define NAME_NXP_EXT_TVDD_CFG_2 "NXP_EXT_TVDD_CFG_2" +#define NAME_NXP_EXT_TVDD_CFG_3 "NXP_EXT_TVDD_CFG_3" +#define NAME_NXP_RF_CONF_BLK_MAX "NXP_RF_CONF_MAX_NUM" +#define NAME_NXP_CORE_CONF_EXTN "NXP_CORE_CONF_EXTN" +#define NAME_NXP_CORE_CONF "NXP_CORE_CONF" +#define NAME_NXP_NFC_PROFILE_EXTN "NXP_NFC_PROFILE_EXTN" +#define NAME_NXP_CHINA_TIANJIN_RF_ENABLED "NXP_CHINA_TIANJIN_RF_ENABLED" +#define NAME_NXP_CHINA_BLK_NUM_CHK_ENABLE "NXP_CN_TRANSIT_BLK_NUM_CHECK_ENABLE" +#define NAME_NXP_CN_TRANSIT_CMA_BYPASSMODE_ENABLE "NXP_CN_TRANSIT_CMA_BYPASSMODE_ENABLE" +#define NAME_NXP_ESE_POWER_DH_CONTROL "NXP_ESE_POWER_DH_CONTROL" +#define NAME_NXP_ESE_POWER_EXT_PMU "NXP_ESE_POWER_EXT_PMU" +#define NAME_NXP_ESE_POWER_DH_CONTROL_CFG_1 "NXP_ESE_POWER_DH_CONTROL_CFG_1" +#define NAME_NXP_SWP_SWITCH_TIMEOUT "NXP_SWP_SWITCH_TIMEOUT" +#define NAME_NXP_SWP_FULL_PWR_ON "NXP_SWP_FULL_PWR_ON" +#define NAME_NXP_CORE_RF_FIELD "NXP_CORE_RF_FIELD" +#define NAME_NXP_NFC_MERGE_RF_PARAMS "NXP_NFC_MERGE_RF_PARAMS" +#define NAME_NXP_I2C_FRAGMENTATION_ENABLED "NXP_I2C_FRAGMENTATION_ENABLED" +#define NAME_NFC_DEBUG_ENABLED "NFC_DEBUG_ENABLED" +#define NAME_AID_MATCHING_PLATFORM "AID_MATCHING_PLATFORM" +#define NAME_NXP_TYPEA_UICC_BAUD_RATE "NXP_TYPEA_UICC_BAUD_RATE" +#define NAME_NXP_TYPEB_UICC_BAUD_RATE "NXP_TYPEB_UICC_BAUD_RATE" +#define NAME_NXP_SET_CONFIG_ALWAYS "NXP_SET_CONFIG_ALWAYS" +#define NAME_NXP_PROP_BLACKLIST_ROUTING "NXP_PROP_BLACKLIST_ROUTING" +#define NAME_NXP_WIREDMODE_RESUME_TIMEOUT "NXP_WIREDMODE_RESUME_TIMEOUT" +#define NAME_NXP_UICC_LISTEN_TECH_MASK "UICC_LISTEN_TECH_MASK" +#define NAME_NXP_ESE_LISTEN_TECH_MASK "NXP_ESE_LISTEN_TECH_MASK" +#define NAME_NXP_SVDD_SYNC_OFF_DELAY "NXP_SVDD_SYNC_OFF_DELAY" +#define NAME_NXP_CORE_PROP_SYSTEM_DEBUG "NXP_CORE_PROP_SYSTEM_DEBUG" +#define NAME_NXP_NCI_PARSER_LIBRARY "NXP_NCI_PARSER_LIBRARY" +#define NAME_NXP_DEFAULT_UICC2_SELECT "NXP_DEFAULT_UICC2_SELECT" +#define NAME_NXP_ALWAYS_FW_UPDATE "NXP_ALWAYS_FW_UPDATE" +#define NAME_NXP_P61_JCOP_DEFAULT_INTERFACE "NXP_P61_JCOP_DEFAULT_INTERFACE" +#define NAME_RF_STATUS_UPDATE_ENABLE "RF_STATUS_UPDATE_ENABLE" +#define NAME_DEFAULT_ROUTE "DEFAULT_ROUTE" +#define NAME_DEFAULT_SYS_CODE_ROUTE "DEFAULT_SYS_CODE_ROUTE" +#define NAME_DEFAULT_SYS_CODE_PWR_STATE "DEFAULT_SYS_CODE_PWR_STATE" +#define NAME_OFF_HOST_ESE_PIPE_ID "OFF_HOST_ESE_PIPE_ID" +#define NAME_OFF_HOST_SIM_PIPE_ID "OFF_HOST_SIM_PIPE_ID" +#define NAME_DEFAULT_OFFHOST_ROUTE "DEFAULT_OFFHOST_ROUTE" +#define NAME_DEFAULT_NFCF_ROUTE "DEFAULT_NFCF_ROUTE" +#define NAME_ISO_DEP_MAX_TRANSCEIVE "ISO_DEP_MAX_TRANSCEIVE" +#define NAME_NFA_POLL_BAIL_OUT_MODE "NFA_POLL_BAIL_OUT_MODE" +#define NAME_ACTIVE_SE "ACTIVE_SE" +#define NAME_ACTIVE_SE_NFCF "ACTIVE_SE_NFCF" +#define NAME_DEFAULT_FELICA_SYS_CODE_ROUTE "DEFAULT_FELICA_SYS_CODE_ROUTE" +#define NAME_DEFAULT_ISODEP_ROUTE "DEFAULT_ISODEP_ROUTE" +#define NAME_DEVICE_HOST_WHITE_LIST "DEVICE_HOST_WHITE_LIST" +#define NAME_NFA_PROPRIETARY_CFG "NFA_PROPRIETARY_CFG" +#define NAME_PRESENCE_CHECK_ALGORITHM "PRESENCE_CHECK_ALGORITHM" +#define NAME_NXP_CORE_PROP_SYSTEM_DEBUG "NXP_CORE_PROP_SYSTEM_DEBUG" +#define NAME_NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE "NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE" +#define NAME_NXP_P61_LS_DEFAULT_INTERFACE "NXP_P61_LS_DEFAULT_INTERFACE" +#define NAME_NXP_LS_FORCE_UPDATE_REQUIRED "NXP_LS_FORCE_UPDATE_REQUIRED" +#define NAME_NXP_JCOP_FORCE_UPDATE_REQUIRED "NXP_JCOP_FORCE_UPDATE_REQUIRED" +#define NAME_NXP_SEMS_SUPPORTED "NXP_GP_AMD_I_SEMS_SUPPORTED" +#define NAME_NXP_SPI_SE_TERMINAL_NUM "NXP_SPI_SE_TERMINAL_NUM" +#define NAME_NXP_VISO_SE_TERMINAL_NUM "NXP_VISO_SE_TERMINAL_NUM" +#define NAME_NXP_NFC_SE_TERMINAL_NUM "NXP_NFC_SE_TERMINAL_NUM" + +/* default configuration */ +#define default_storage_location "/data/vendor/nfc" + +#endif diff --git a/utils/sparse_crc32.cc b/utils/sparse_crc32.cc new file mode 100644 index 0000000..d490daa --- /dev/null +++ b/utils/sparse_crc32.cc @@ -0,0 +1,107 @@ +/*- + * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or + * code or tables extracted from it, as desired without restriction. + */ + +/* + * First, the polynomial itself and its table of feedback terms. The + * polynomial is + * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 + * + * Note that we take it "backwards" and put the highest-order term in + * the lowest-order bit. The X^32 term is "implied"; the LSB is the + * X^31 term, etc. The X^0 term (usually shown as "+1") results in + * the MSB being 1 + * + * Note that the usual hardware shift register implementation, which + * is what we're using (we're merely optimizing it by doing eight-bit + * chunks at a time) shifts bits into the lowest-order term. In our + * implementation, that means shifting towards the right. Why do we + * do it this way? Because the calculated CRC must be transmitted in + * order from highest-order term to lowest-order term. UARTs transmit + * characters in order from LSB to MSB. By storing the CRC this way + * we hand it to the UART in the order low-byte to high-byte; the UART + * sends each low-bit to hight-bit; and the result is transmission bit + * by bit from highest- to lowest-order term without requiring any bit + * shuffling on our part. Reception works similarly + * + * The feedback terms table consists of 256, 32-bit entries. Notes + * + * The table can be generated at runtime if desired; code to do so + * is shown later. It might not be obvious, but the feedback + * terms simply represent the results of eight shift/xor opera + * tions for all combinations of data and CRC register values + * + * The values must be right-shifted by eight bits by the "updcrc + * logic; the shift must be unsigned (bring in zeroes). On some + * hardware you could probably optimize the shift in assembler by + * using byte-swap instructions + * polynomial $edb88320 + * + * + * CRC32 code derived from work by Gary S. Brown. + */ + +/* Code taken from FreeBSD 8 */ +#include <stdint.h> + +static uint32_t crc32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; + +/* + * A function that calculates the CRC-32 based on the table above is + * given below for documentation purposes. An equivalent implementation + * of this function that's actually used in the kernel can be found + * in sys/libkern.h, where it can be inlined. + */ + +uint32_t sparse_crc32(uint32_t crc_in, const void* buf, int size) { + const uint8_t* p = (const uint8_t*)buf; + uint32_t crc; + + crc = crc_in ^ ~0U; + while (size--) crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + return crc ^ ~0U; +} diff --git a/utils/sparse_crc32.h b/utils/sparse_crc32.h new file mode 100644 index 0000000..29fc9be --- /dev/null +++ b/utils/sparse_crc32.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2010 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. + */ + +#ifndef _LIBSPARSE_SPARSE_CRC32_H_ +#define _LIBSPARSE_SPARSE_CRC32_H_ + +#include <stdint.h> + +uint32_t sparse_crc32(uint32_t crc, const void* buf, int size); + +#endif |