1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef NFC_VENDOR_ADAPTIONS_H 16 #define NFC_VENDOR_ADAPTIONS_H 17 18 #include <cstdint> 19 #include <string> 20 #include "infc_vendor.h" 21 22 namespace OHOS { 23 namespace HDI { 24 namespace Nfc { 25 const std::string NFC_HAL_SO_DEFAULT_NAME = "libnfc_hdiimpl.z.so"; 26 const std::string VENDOR_NFC_EXT_SERVICE_LIB = "libvendor_ext_nfc_service.z.so"; 27 28 const std::string EXT_GET_CHIP_TYPE_FUNC_NAME = "GetChipType"; 29 const std::string EXT_GET_SUFFIX_FUNC_NAME = "GetNfcHalFuncNameSuffix"; 30 const std::string EXT_SET_FW_UPDATE_CONFIG_FUNC_NAME = "CheckFirmwareUpdate"; 31 32 const std::string HAL_OPEN_FUNC_NAME = "phNxpNciHal_open"; 33 const std::string HAL_WRITE_FUNC_NAME = "phNxpNciHal_write"; 34 const std::string HAL_CORE_INIT_FUNC_NAME = "phNxpNciHal_core_initialized"; 35 const std::string HAL_PRE_DISC_FUNC_NAME = "phNxpNciHal_pre_discover"; 36 const std::string HAL_CLOSE_FUNC_NAME = "phNxpNciHal_close"; 37 const std::string HAL_CTRL_GRANTED_FUNC_NAME = "phNxpNciHal_control_granted"; 38 const std::string HAL_POWER_CYCLE_FUNC_NAME = "phNxpNciHal_power_cycle"; 39 const std::string HAL_IOCTL_FUNC_NAME = "phNxpNciHal_ioctl"; 40 const std::string HAL_GET_CONFIG_FUNC_NAME = "phNxpNciHal_getVendorConfig_1_2"; 41 const std::string HAL_FACTORY_RESET_FUNC_NAME = "phNxpNciHal_do_factory_reset"; 42 const std::string HAL_SHUTDOWN_CASE_FUNC_NAME = "phNxpNciHal_configDiscShutdown"; 43 const std::string DEFAULT_FUNC_NAME_SUFFIX = ""; 44 45 const std::string NFC_HAL_SO_PREFIX = "libnfc_hal_impl_"; 46 const std::string NFC_HAL_SO_SUFFIX = ".z.so"; 47 const unsigned int VENDOR_IOCTL_TOTAL_LEN = 256; 48 const unsigned int VENDOR_IOCTL_INOUT_DATA_LEN = 128; 49 const unsigned int VENDOR_IOCTL_OUTPUT_LEN_INDEX = 128; 50 const unsigned int VENDOR_IOCTL_OUTPUT_START_INDEX = 129; 51 const unsigned int VENDOR_IOCTL_INPUT_LEN_INDEX = 0; 52 const unsigned int VENDOR_IOCTL_INPUT_START_INDEX = 1; 53 const unsigned int VENDOR_IOCTL_INPUT_MIN_LEN = 128; 54 55 const unsigned int VENDOR_IOCTL_INPUT_DATA_LEN = 288; 56 const unsigned int VENDOR_IOCTL_OUTPUT_DATA_START_INDEX = 288; 57 const unsigned int VENDOR_IOCTL_OUTPUT_DATA_LEN = 4128; 58 const unsigned int VENDOR_IOCTL_TOTAL_LENGTH = VENDOR_IOCTL_INPUT_DATA_LEN + VENDOR_IOCTL_OUTPUT_DATA_LEN; 59 const long VENDOR_GET_HISTORY_NCI_CMD = 112; 60 61 struct NfcHalInterface { 62 int (*nfcHalOpen)(NfcStackCallbackT *pCback, NfcStackDataCallbackT *pDataCback); 63 int (*nfcHalWrite)(uint16_t dataLen, const uint8_t *pData); 64 int (*nfcHalCoreInitialized)(uint16_t coreInitRspLen, uint8_t *pCoreInitRspParams); 65 int (*nfcHalPrediscover)(void); 66 int (*nfcHalClose)(bool bShutdown); 67 int (*nfcHalControlGranted)(void); 68 int (*nfcHalPowerCycle)(void); 69 int (*nfcHalIoctl)(long arg, void *pData); 70 void (*nfcHalGetConfig)(V1_1::NfcVendorConfig &config); 71 void (*nfcHalFactoryReset)(void); 72 int (*nfcHalShutdownCase)(void); 73 }; 74 75 struct NfcExtInterface { 76 const char* (*getNfcChipType)(void); 77 const char* (*getNfcHalFuncNameSuffix)(const char* chipType); 78 void (*checkFirmwareUpdate)(void); 79 }; 80 81 class NfcVendorAdaptions : public INfcVendor { 82 public: 83 NfcVendorAdaptions(); 84 ~NfcVendorAdaptions() override; 85 86 int VendorOpen(NfcStackCallbackT *pCback, NfcStackDataCallbackT *pDataCback) override; 87 int VendorWrite(uint16_t dataLen, const uint8_t *pData) override; 88 int VendorCoreInitialized(uint16_t coreInitRspLen, uint8_t *pCoreInitRspParams) override; 89 int VendorPrediscover(void) override; 90 int VendorClose(bool bShutdown) override; 91 int VendorControlGranted(void) override; 92 int VendorPowerCycle(void) override; 93 int VendorIoctl(long arg, void *pData) override; 94 int VendorIoctlWithResponse(long arg, void *pData, uint16_t dataLen, std::vector<uint8_t> &pRetVal) override; 95 int VendorGetConfig(V1_1::NfcVendorConfig &config) override; 96 int VendorFactoryReset(void) override; 97 int VendorShutdownCase(void) override; 98 99 private: 100 std::string GetChipType(void); 101 std::string GetNfcHalFuncNameSuffix(const std::string &chipType); 102 void ResetNfcInterface(void); 103 int8_t InitNfcHalInterfaces(std::string nfcHalSoName, std::string suffix); 104 void CheckFirmwareUpdate(void); 105 int VendorGetHistoryNci(void *pData, uint16_t dataLen, std::vector<uint8_t> &pRetVal); 106 107 void *nfcHalHandle; // handle of nfc hal so 108 NfcHalInterface nfcHalInf; 109 110 void *nfcExtHandle; // handle of nfc ext service 111 NfcExtInterface nfcExtInf; 112 }; 113 } // Nfc 114 } // HDI 115 } // OHOS 116 117 #endif // NFC_VENDOR_ADAPTIONS_H 118