1bc2ed2b3Sopenharmony_ci/* 2bc2ed2b3Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License. 5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at 6bc2ed2b3Sopenharmony_ci * 7bc2ed2b3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc2ed2b3Sopenharmony_ci * 9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and 13bc2ed2b3Sopenharmony_ci * limitations under the License. 14bc2ed2b3Sopenharmony_ci */ 15bc2ed2b3Sopenharmony_ci#ifndef NFC_SDK_COMMON_H 16bc2ed2b3Sopenharmony_ci#define NFC_SDK_COMMON_H 17bc2ed2b3Sopenharmony_ci#include <string> 18bc2ed2b3Sopenharmony_ci#include <vector> 19bc2ed2b3Sopenharmony_ci 20bc2ed2b3Sopenharmony_cinamespace OHOS { 21bc2ed2b3Sopenharmony_cinamespace NFC { 22bc2ed2b3Sopenharmony_cinamespace KITS { 23bc2ed2b3Sopenharmony_ciconst static uint32_t HEX_BYTE_LEN = 2; 24bc2ed2b3Sopenharmony_ciconst static uint32_t HEX_VALUE = 16; 25bc2ed2b3Sopenharmony_ciconst static uint32_t HALF_BYTE_BITS = 4; 26bc2ed2b3Sopenharmony_cistatic const uint32_t NFC_MANAGER_SYS_ABILITY_ID = 1140; 27bc2ed2b3Sopenharmony_cistatic const std::string NFC_MANAGER_SYS_ABILITY_NAME = "nfc_service"; 28bc2ed2b3Sopenharmony_ci 29bc2ed2b3Sopenharmony_cienum ErrorCode : const int { 30bc2ed2b3Sopenharmony_ci ERR_NONE = 0, 31bc2ed2b3Sopenharmony_ci 32bc2ed2b3Sopenharmony_ci ERR_NO_PERMISSION = 201, 33bc2ed2b3Sopenharmony_ci ERR_NOT_SYSTEM_APP = 202, 34bc2ed2b3Sopenharmony_ci 35bc2ed2b3Sopenharmony_ci // error for nfc state operations 36bc2ed2b3Sopenharmony_ci ERR_NFC_BASE = 3100100, 37bc2ed2b3Sopenharmony_ci ERR_NFC_PARAMETERS, 38bc2ed2b3Sopenharmony_ci ERR_NFC_STATE_UNBIND, 39bc2ed2b3Sopenharmony_ci ERR_NFC_STATE_INVALID, 40bc2ed2b3Sopenharmony_ci 41bc2ed2b3Sopenharmony_ci // error for tag I/O operations 42bc2ed2b3Sopenharmony_ci ERR_TAG_BASE = 3100200, 43bc2ed2b3Sopenharmony_ci ERR_TAG_STATE_IO_FAILED, 44bc2ed2b3Sopenharmony_ci ERR_TAG_PARAMETERS, 45bc2ed2b3Sopenharmony_ci ERR_TAG_STATE_NFC_CLOSED, 46bc2ed2b3Sopenharmony_ci ERR_TAG_STATE_LOST, 47bc2ed2b3Sopenharmony_ci ERR_TAG_STATE_DISCONNECTED, 48bc2ed2b3Sopenharmony_ci ERR_TAG_STATE_UNBIND, 49bc2ed2b3Sopenharmony_ci ERR_TAG_APP_NOT_FOREGROUND, 50bc2ed2b3Sopenharmony_ci ERR_TAG_APP_NOT_REGISTERED, 51bc2ed2b3Sopenharmony_ci 52bc2ed2b3Sopenharmony_ci // error for card emulation operations 53bc2ed2b3Sopenharmony_ci ERR_CE_BASE = 3100300, 54bc2ed2b3Sopenharmony_ci ERR_HCE_PARAMETERS, 55bc2ed2b3Sopenharmony_ci ERR_HCE_STATE_NFC_CLOSED, 56bc2ed2b3Sopenharmony_ci ERR_HCE_STATE_LOST, 57bc2ed2b3Sopenharmony_ci ERR_HCE_STATE_DISCONNECTED, 58bc2ed2b3Sopenharmony_ci ERR_HCE_STATE_IO_FAILED, 59bc2ed2b3Sopenharmony_ci ERR_HCE_STATE_UNBIND, 60bc2ed2b3Sopenharmony_ci ERR_HCE_NOT_GET_PAYMENT_SERVICES, 61bc2ed2b3Sopenharmony_ci 62bc2ed2b3Sopenharmony_ci // error for nfc database operations 63bc2ed2b3Sopenharmony_ci ERR_NFC_DATABASE_RW = 3100400, 64bc2ed2b3Sopenharmony_ci}; 65bc2ed2b3Sopenharmony_ci 66bc2ed2b3Sopenharmony_cienum NfcState { STATE_OFF = 1, STATE_TURNING_ON = 2, STATE_ON = 3, STATE_TURNING_OFF = 4 }; 67bc2ed2b3Sopenharmony_ci 68bc2ed2b3Sopenharmony_cienum NfcTask { TASK_TURN_ON = 101, TASK_TURN_OFF, TASK_INITIALIZE }; 69bc2ed2b3Sopenharmony_ci 70bc2ed2b3Sopenharmony_cienum FeatureType { HCE = 0, UICC = 1, ESE = 2 }; 71bc2ed2b3Sopenharmony_ci 72bc2ed2b3Sopenharmony_ci/** NFC state changed for common event notification */ 73bc2ed2b3Sopenharmony_ciconst std::string COMMON_EVENT_NFC_ACTION_STATE_CHANGED = "usual.event.nfc.action.ADAPTER_STATE_CHANGED"; 74bc2ed2b3Sopenharmony_ciconst std::string NFC_EXTRA_STATE = "ohos.nfc.extra.ADAPTER_STATE"; 75bc2ed2b3Sopenharmony_ci 76bc2ed2b3Sopenharmony_ci/** Payment type of card emulation */ 77bc2ed2b3Sopenharmony_cistatic const std::string TYPE_PAYMENT = "payment"; 78bc2ed2b3Sopenharmony_ci 79bc2ed2b3Sopenharmony_ci/** Other type of card emulation */ 80bc2ed2b3Sopenharmony_cistatic const std::string TYPE_OHTER = "other"; 81bc2ed2b3Sopenharmony_ci 82bc2ed2b3Sopenharmony_ci/** Payment type of card emulation metadata name */ 83bc2ed2b3Sopenharmony_ciconst std::string KEY_PAYMENT_AID = "payment-aid"; 84bc2ed2b3Sopenharmony_ci 85bc2ed2b3Sopenharmony_ci/** Other type of card emulation metadata name */ 86bc2ed2b3Sopenharmony_ciconst std::string KEY_OHTER_AID = "other-aid"; 87bc2ed2b3Sopenharmony_ci 88bc2ed2b3Sopenharmony_ci/** Action for tag application declared */ 89bc2ed2b3Sopenharmony_ciconst std::string ACTION_TAG_FOUND = "ohos.nfc.tag.action.TAG_FOUND"; 90bc2ed2b3Sopenharmony_ci 91bc2ed2b3Sopenharmony_ci/** Action for HCE application declared */ 92bc2ed2b3Sopenharmony_ciconst std::string ACTION_HOST_APDU_SERVICE = "ohos.nfc.cardemulation.action.HOST_APDU_SERVICE"; 93bc2ed2b3Sopenharmony_ci 94bc2ed2b3Sopenharmony_ci/** Action for off host*/ 95bc2ed2b3Sopenharmony_ciconst std::string ACTION_OFF_HOST_APDU_SERVICE = "ohos.nfc.cardemulation.action.OFF_HOST_APDU_SERVICE"; 96bc2ed2b3Sopenharmony_ci 97bc2ed2b3Sopenharmony_ci/** Database key for nfc state. */ 98bc2ed2b3Sopenharmony_ciconst std::string NFC_DATA_URI_ID = 99bc2ed2b3Sopenharmony_ci "/com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=data_key_nfc_state"; 100bc2ed2b3Sopenharmony_ciconst std::string NFC_DATA_ABILITY_PREFIX = "datashare://"; 101bc2ed2b3Sopenharmony_ciconst std::string NFC_DATA_URI = NFC_DATA_ABILITY_PREFIX + NFC_DATA_URI_ID; 102bc2ed2b3Sopenharmony_ciconst std::string DATA_SHARE_KEY_STATE = "data_key_nfc_state"; 103bc2ed2b3Sopenharmony_ciconst std::string NFC_DATA_COLUMN_KEYWORD = "KEYWORD"; 104bc2ed2b3Sopenharmony_ciconst std::string NFC_DATA_COLUMN_VALUE = "VALUE"; 105bc2ed2b3Sopenharmony_ci 106bc2ed2b3Sopenharmony_ci/** Database key for payment default app. */ 107bc2ed2b3Sopenharmony_ciconst std::string NFC_PAYMENT_DEFAULT_APP = 108bc2ed2b3Sopenharmony_ci "/com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=nfc_payment_default_app"; 109bc2ed2b3Sopenharmony_ciconst std::string NFC_DATA_URI_PAYMENT_DEFAULT_APP = NFC_DATA_ABILITY_PREFIX + NFC_PAYMENT_DEFAULT_APP; 110bc2ed2b3Sopenharmony_ciconst std::string DATA_SHARE_KEY_NFC_PAYMENT_DEFAULT_APP = "nfc_payment_default_app"; 111bc2ed2b3Sopenharmony_ci 112bc2ed2b3Sopenharmony_ci/** NFC field on/off common event */ 113bc2ed2b3Sopenharmony_ciconst std::string COMMON_EVENT_NFC_ACTION_RF_FIELD_ON_DETECTED = "usual.event.nfc.action.RF_FIELD_ON_DETECTED"; 114bc2ed2b3Sopenharmony_ciconst std::string COMMON_EVENT_NFC_ACTION_RF_FIELD_OFF_DETECTED = "usual.event.nfc.action.RF_FIELD_OFF_DETECTED"; 115bc2ed2b3Sopenharmony_ci 116bc2ed2b3Sopenharmony_ciconst int DATA_SHARE_INVALID_VALUE = -1; 117bc2ed2b3Sopenharmony_ci 118bc2ed2b3Sopenharmony_ci/** type const of hce napi on */ 119bc2ed2b3Sopenharmony_ciconst std::string EVENT_HCE_CMD = "hceCmd"; 120bc2ed2b3Sopenharmony_ci 121bc2ed2b3Sopenharmony_ci/** type const of max apdu length */ 122bc2ed2b3Sopenharmony_ciconst uint32_t MAX_APDU_DATA_BYTE = 1024; 123bc2ed2b3Sopenharmony_ciconst uint32_t MAX_APDU_DATA_HEX_STR = MAX_APDU_DATA_BYTE * 2; 124bc2ed2b3Sopenharmony_ciconst uint32_t MAX_AID_LIST_NUM_PER_APP = 100; 125bc2ed2b3Sopenharmony_ci 126bc2ed2b3Sopenharmony_ci#ifdef VENDOR_APPLICATIONS_ENABLED 127bc2ed2b3Sopenharmony_ciconst int VENDOR_APP_INIT_DONE = 1; 128bc2ed2b3Sopenharmony_ciconst int VENDOR_APP_CHANGE = 2; 129bc2ed2b3Sopenharmony_ci#endif 130bc2ed2b3Sopenharmony_ci 131bc2ed2b3Sopenharmony_cienum class DefaultPaymentType { 132bc2ed2b3Sopenharmony_ci TYPE_HCE = 0, 133bc2ed2b3Sopenharmony_ci TYPE_UICC = 1, 134bc2ed2b3Sopenharmony_ci TYPE_ESE = 2, 135bc2ed2b3Sopenharmony_ci TYPE_EMPTY = 3, 136bc2ed2b3Sopenharmony_ci TYPE_UNINSTALLED = 4, 137bc2ed2b3Sopenharmony_ci TYPE_UNKNOWN = 0xFF, 138bc2ed2b3Sopenharmony_ci}; 139bc2ed2b3Sopenharmony_ci 140bc2ed2b3Sopenharmony_cienum class TagTechnology { 141bc2ed2b3Sopenharmony_ci NFC_INVALID_TECH = 0, 142bc2ed2b3Sopenharmony_ci NFC_A_TECH = 1, 143bc2ed2b3Sopenharmony_ci NFC_B_TECH = 2, 144bc2ed2b3Sopenharmony_ci NFC_ISODEP_TECH = 3, 145bc2ed2b3Sopenharmony_ci NFC_F_TECH = 4, // Felica 146bc2ed2b3Sopenharmony_ci NFC_V_TECH = 5, // ISO15693 147bc2ed2b3Sopenharmony_ci NFC_NDEF_TECH = 6, 148bc2ed2b3Sopenharmony_ci NFC_NDEF_FORMATABLE_TECH = 7, 149bc2ed2b3Sopenharmony_ci NFC_MIFARE_CLASSIC_TECH = 8, 150bc2ed2b3Sopenharmony_ci NFC_MIFARE_ULTRALIGHT_TECH = 9 151bc2ed2b3Sopenharmony_ci}; 152bc2ed2b3Sopenharmony_ci 153bc2ed2b3Sopenharmony_cienum EmNfcForumType { 154bc2ed2b3Sopenharmony_ci NFC_FORUM_TYPE_UNKNOWN = 0, 155bc2ed2b3Sopenharmony_ci NFC_FORUM_TYPE_1 = 1, 156bc2ed2b3Sopenharmony_ci NFC_FORUM_TYPE_2 = 2, 157bc2ed2b3Sopenharmony_ci NFC_FORUM_TYPE_3 = 3, 158bc2ed2b3Sopenharmony_ci NFC_FORUM_TYPE_4 = 4, 159bc2ed2b3Sopenharmony_ci MIFARE_CLASSIC = 101, 160bc2ed2b3Sopenharmony_ci ICODE_SLI = 102 161bc2ed2b3Sopenharmony_ci}; 162bc2ed2b3Sopenharmony_ci 163bc2ed2b3Sopenharmony_ciclass NfcSdkCommon final { 164bc2ed2b3Sopenharmony_cipublic: 165bc2ed2b3Sopenharmony_ci static const int SHIFT_SIZE = 8; 166bc2ed2b3Sopenharmony_ci static const int SHIFT_TIME = 4; 167bc2ed2b3Sopenharmony_ci 168bc2ed2b3Sopenharmony_cipublic: 169bc2ed2b3Sopenharmony_ci static bool IsLittleEndian(); 170bc2ed2b3Sopenharmony_ci static std::string BytesVecToHexString(const unsigned char* src, uint32_t length); 171bc2ed2b3Sopenharmony_ci static std::string UnsignedCharToHexString(const unsigned char src); 172bc2ed2b3Sopenharmony_ci static void HexStringToBytes(const std::string &src, std::vector<unsigned char> &bytes); 173bc2ed2b3Sopenharmony_ci static unsigned char GetByteFromHexStr(const std::string src, uint32_t index); 174bc2ed2b3Sopenharmony_ci static uint32_t GetHexStrBytesLen(const std::string src); 175bc2ed2b3Sopenharmony_ci static uint32_t StringToInt(std::string src, bool bLittleEndian = true); 176bc2ed2b3Sopenharmony_ci static std::string IntToHexString(uint32_t num); 177bc2ed2b3Sopenharmony_ci static void StringToAsciiBytes(const std::string &src, std::vector<unsigned char> &bytes); 178bc2ed2b3Sopenharmony_ci static std::string StringToHexString(const std::string &src); 179bc2ed2b3Sopenharmony_ci static std::string HexStringToAsciiString(const std::string &src); 180bc2ed2b3Sopenharmony_ci static std::string HexArrayToStringWithoutChecking(const std::string &src); 181bc2ed2b3Sopenharmony_ci static uint64_t GetCurrentTime(); 182bc2ed2b3Sopenharmony_ci static uint64_t GetRelativeTime(); 183bc2ed2b3Sopenharmony_ci static std::string CodeMiddlePart(const std::string &src); 184bc2ed2b3Sopenharmony_ci}; 185bc2ed2b3Sopenharmony_ci} // namespace KITS 186bc2ed2b3Sopenharmony_ci} // namespace NFC 187bc2ed2b3Sopenharmony_ci} // namespace OHOS 188bc2ed2b3Sopenharmony_ci#endif // NFC_SDK_COMMON_H 189