1 /******************************************************************************
2  *
3  *  Copyright 2022-2023 NXP
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #include "NxpNfc.h"
20 
21 #include <log/log.h>
22 
23 #include "phNxpNciHal.h"
24 #include "phNxpNciHal_Adaptation.h"
25 
26 extern bool nfc_debug_enabled;
27 
28 namespace aidl {
29 namespace vendor {
30 namespace nxp {
31 namespace nxpnfc_aidl {
32 
getVendorParam(const std::string & key,std::string * _aidl_return)33 ::ndk::ScopedAStatus NxpNfc::getVendorParam(const std::string& key,
34                                             std::string* _aidl_return) {
35   LOG(INFO) << "NxpNfc AIDL - getVendorParam";
36   *_aidl_return = phNxpNciHal_getSystemProperty(key);
37   return ndk::ScopedAStatus::ok();
38 }
39 
setVendorParam(const std::string & key,const std::string & value,bool * _aidl_return)40 ::ndk::ScopedAStatus NxpNfc::setVendorParam(const std::string& key,
41                                             const std::string& value,
42                                             bool* _aidl_return) {
43   LOG(INFO) << "NxpNfc AIDL - setVendorParam";
44   *_aidl_return = phNxpNciHal_setSystemProperty(key, value);
45   return ndk::ScopedAStatus::ok();
46 }
47 
resetEse(int64_t resetType,bool * _aidl_return)48 ::ndk::ScopedAStatus NxpNfc::resetEse(int64_t resetType, bool* _aidl_return) {
49   LOG(INFO) << "NxpNfc AIDL - resetEse";
50   NFCSTATUS status = NFCSTATUS_FAILED;
51   *_aidl_return = false;
52   ALOGD("NxpNfc::resetEse Entry");
53 
54   status = phNxpNciHal_resetEse(resetType);
55   if (NFCSTATUS_SUCCESS == status) {
56     *_aidl_return = true;
57     status = NFCSTATUS_SUCCESS;
58     ALOGD("Reset request (%02x) completed", (uint8_t)resetType);
59   } else {
60     ALOGE("Reset request (%02x) failed", (uint8_t)resetType);
61   }
62 
63   ALOGD("NxpNfc::resetEse Exit");
64   return status == NFCSTATUS_SUCCESS
65              ? ndk::ScopedAStatus::ok()
66              : ndk::ScopedAStatus::fromServiceSpecificError(
67                    static_cast<int64_t>(status));
68 }
69 
setNxpTransitConfig(const std::string & strVal,bool * _aidl_return)70 ::ndk::ScopedAStatus NxpNfc::setNxpTransitConfig(const std::string& strVal,
71                                                  bool* _aidl_return) {
72   *_aidl_return = false;
73   ALOGD("NxpNfc::setNxpTransitConfig Entry");
74 
75   *_aidl_return = phNxpNciHal_setNxpTransitConfig((char*)strVal.c_str());
76 
77   ALOGD("NxpNfc::setNxpTransitConfig Exit");
78   return *_aidl_return == true ? ndk::ScopedAStatus::ok()
79                                : ndk::ScopedAStatus::fromServiceSpecificError(
80                                      static_cast<bool>(*_aidl_return));
81 }
82 
83 }  // namespace nxpnfc_aidl
84 }  // namespace nxp
85 }  // namespace vendor
86 }  // namespace aidl
87