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 31 const std::string HAL_OPEN_FUNC_NAME = "phNxpNciHal_open"; 32 const std::string HAL_WRITE_FUNC_NAME = "phNxpNciHal_write"; 33 const std::string HAL_CORE_INIT_FUNC_NAME = "phNxpNciHal_core_initialized"; 34 const std::string HAL_PRE_DISC_FUNC_NAME = "phNxpNciHal_pre_discover"; 35 const std::string HAL_CLOSE_FUNC_NAME = "phNxpNciHal_close"; 36 const std::string HAL_CTRL_GRANTED_FUNC_NAME = "phNxpNciHal_control_granted"; 37 const std::string HAL_POWER_CYCLE_FUNC_NAME = "phNxpNciHal_power_cycle"; 38 const std::string HAL_IOCTL_FUNC_NAME = "phNxpNciHal_ioctl"; 39 const std::string HAL_GET_CONFIG_FUNC_NAME = "phNxpNciHal_getVendorConfig_1_2"; 40 const std::string HAL_FACTORY_RESET_FUNC_NAME = "phNxpNciHal_do_factory_reset"; 41 const std::string HAL_SHUTDOWN_CASE_FUNC_NAME = "phNxpNciHal_configDiscShutdown"; 42 const std::string DEFAULT_FUNC_NAME_SUFFIX = ""; 43 44 const std::string NFC_HAL_SO_PREFIX = "libnfc_hal_impl_"; 45 const std::string NFC_HAL_SO_SUFFIX = ".z.so"; 46 const unsigned int VENDOR_IOCTL_TOTAL_LEN = 256; 47 const unsigned int VENDOR_IOCTL_INOUT_DATA_LEN = 128; 48 const unsigned int VENDOR_IOCTL_OUTPUT_LEN_INDEX = 128; 49 const unsigned int VENDOR_IOCTL_OUTPUT_START_INDEX = 129; 50 const unsigned int VENDOR_IOCTL_INPUT_LEN_INDEX = 0; 51 const unsigned int VENDOR_IOCTL_INPUT_START_INDEX = 1; 52 const unsigned int VENDOR_IOCTL_INPUT_MAX_LEN = 128; 53 54 struct NfcHalInterface { 55 int (*nfcHalOpen)(NfcStackCallbackT *pCback, NfcStackDataCallbackT *pDataCback); 56 int (*nfcHalWrite)(uint16_t dataLen, const uint8_t *pData); 57 int (*nfcHalCoreInitialized)(uint16_t coreInitRspLen, uint8_t *pCoreInitRspParams); 58 int (*nfcHalPrediscover)(void); 59 int (*nfcHalClose)(bool bShutdown); 60 int (*nfcHalControlGranted)(void); 61 int (*nfcHalPowerCycle)(void); 62 int (*nfcHalIoctl)(long arg, void *pData); 63 void (*nfcHalGetConfig)(V1_1::NfcVendorConfig &config); 64 void (*nfcHalFactoryReset)(void); 65 int (*nfcHalShutdownCase)(void); 66 }; 67 68 struct NfcExtInterface { 69 const char* (*getNfcChipType)(void); 70 const char* (*getNfcHalFuncNameSuffix)(const char* chipType); 71 }; 72 73 class NfcVendorAdaptions : public INfcVendor { 74 public: 75 NfcVendorAdaptions(); 76 ~NfcVendorAdaptions() override; 77 78 int VendorOpen(NfcStackCallbackT *pCback, NfcStackDataCallbackT *pDataCback) override; 79 int VendorWrite(uint16_t dataLen, const uint8_t *pData) override; 80 int VendorCoreInitialized(uint16_t coreInitRspLen, uint8_t *pCoreInitRspParams) override; 81 int VendorPrediscover(void) override; 82 int VendorClose(bool bShutdown) override; 83 int VendorControlGranted(void) override; 84 int VendorPowerCycle(void) override; 85 int VendorIoctl(long arg, void *pData) override; 86 int VendorIoctlWithResponse(long arg, void *pData, std::vector<uint8_t> &pRetVal) override; 87 int VendorGetConfig(V1_1::NfcVendorConfig &config) override; 88 int VendorFactoryReset(void) override; 89 int VendorShutdownCase(void) override; 90 91 private: 92 std::string GetChipType(void); 93 std::string GetNfcHalFuncNameSuffix(const std::string &chipType); 94 void ResetNfcInterface(void); 95 int8_t InitNfcHalInterfaces(std::string nfcHalSoName, std::string suffix); 96 97 void *nfcHalHandle; // handle of nfc hal so 98 NfcHalInterface nfcHalInf; 99 100 void *nfcExtHandle; // handle of nfc ext service 101 NfcExtInterface nfcExtInf; 102 }; 103 } // Nfc 104 } // HDI 105 } // OHOS 106 107 #endif // NFC_VENDOR_ADAPTIONS_H 108