1 /* 2 * Copyright (c) 2023 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 16 #include "nfc_chip_type_parser.h" 17 18 #include <fstream> 19 #include <iostream> 20 #include <string> 21 22 using namespace std; 23 24 namespace OHOS { 25 namespace NFC { 26 int NfcChipTypeParser::nfcChipType_ = NfcChipTypeParser::NFC_CHIP_DEFAULT; 27 ParseNfcChipType()28int NfcChipTypeParser::ParseNfcChipType() 29 { 30 if (nfcChipType_ >= 0) { 31 return nfcChipType_; 32 } 33 34 ifstream ifs; 35 ifs.open(NFC_CHIP_PATH, ios::in); 36 if (!ifs.is_open()) { 37 return NFC_CHIP_DEFAULT; 38 } 39 char chipBuf[NFC_CHIP_LEN] = {0}; 40 ifs.getline(chipBuf, sizeof(chipBuf)); 41 ifs.close(); 42 43 if (NFC_CHIP_SN110U.compare(chipBuf) == 0) { 44 nfcChipType_ = NFCTYPE_SN110; 45 } else { 46 nfcChipType_ = NFCTYPE_INVALID; 47 } 48 return nfcChipType_; 49 } 50 IsSupportedChipType()51bool NfcChipTypeParser::IsSupportedChipType() 52 { 53 return (ParseNfcChipType() == NFCTYPE_SN110); 54 } 55 } // NFC 56 } // OHOS