1 /******************************************************************************
2  *
3  *  Copyright 2023-2024 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 #include "NfcExtns.h"
19 
20 #include "phNfcStatus.h"
21 #include "phNxpConfig.h"
22 #include "phNxpNciHal_extOperations.h"
23 
24 namespace aidl {
25 namespace android {
26 namespace hardware {
27 namespace nfc {
28 
getConfig(NfcConfig & config)29 void NfcExtns::getConfig(NfcConfig& config) {
30   unsigned long num = 0;
31   std::array<uint8_t, NXP_MAX_CONFIG_STRING_LEN> buffer;
32   buffer.fill(0);
33   long retlen = 0;
34   memset(&config, 0x00, sizeof(NfcConfig));
35 
36   phNxpNciHal_getExtVendorConfig();
37 
38   if (GetNxpNumValue(NAME_NFA_POLL_BAIL_OUT_MODE, &num, sizeof(num))) {
39     config.nfaPollBailOutMode = (bool)num;
40   }
41   if (GetNxpNumValue(NAME_ISO_DEP_MAX_TRANSCEIVE, &num, sizeof(num))) {
42     config.maxIsoDepTransceiveLength = (uint32_t)num;
43   }
44   if (GetNxpNumValue(NAME_DEFAULT_OFFHOST_ROUTE, &num, sizeof(num))) {
45     config.defaultOffHostRoute = (uint8_t)num;
46   }
47   if (GetNxpNumValue(NAME_DEFAULT_NFCF_ROUTE, &num, sizeof(num))) {
48     config.defaultOffHostRouteFelica = (uint8_t)num;
49   }
50   if (GetNxpNumValue(NAME_DEFAULT_SYS_CODE_ROUTE, &num, sizeof(num))) {
51     config.defaultSystemCodeRoute = (uint8_t)num;
52   }
53   if (GetNxpNumValue(NAME_DEFAULT_SYS_CODE_PWR_STATE, &num, sizeof(num))) {
54     config.defaultSystemCodePowerState =
55         phNxpNciHal_updateAutonomousPwrState((uint8_t)num);
56   }
57   if (GetNxpNumValue(NAME_DEFAULT_ROUTE, &num, sizeof(num))) {
58     config.defaultRoute = (uint8_t)num;
59   }
60   if (GetNxpByteArrayValue(NAME_DEVICE_HOST_ALLOW_LIST, (char*)buffer.data(),
61                            buffer.size(), &retlen)) {
62     config.hostAllowlist.resize(retlen);
63     for (long i = 0; i < retlen; i++) config.hostAllowlist[i] = buffer[i];
64   }
65   if (GetNxpNumValue(NAME_OFF_HOST_ESE_PIPE_ID, &num, sizeof(num))) {
66     config.offHostESEPipeId = (uint8_t)num;
67   }
68   if (GetNxpByteArrayValue(NAME_OFF_HOST_SIM_PIPE_IDS, (char*)buffer.data(),
69                            buffer.size(), &retlen)) {
70     config.offHostSimPipeIds.resize(retlen);
71     for (long i = 0; i < retlen; i++) config.offHostSimPipeIds[i] = buffer[i];
72   }
73   if (GetNxpNumValue(NAME_DEFAULT_ISODEP_ROUTE, &num, sizeof(num))) {
74     config.defaultIsoDepRoute = (uint8_t)num;
75   }
76   if (GetNxpByteArrayValue(NAME_OFFHOST_ROUTE_UICC, (char*)buffer.data(),
77                            buffer.size(), &retlen)) {
78     config.offHostRouteUicc.resize(retlen);
79     for (long i = 0; i < retlen; i++) config.offHostRouteUicc[i] = buffer[i];
80   }
81 
82   if (GetNxpByteArrayValue(NAME_OFFHOST_ROUTE_ESE, (char*)buffer.data(),
83                            buffer.size(), &retlen)) {
84     config.offHostRouteEse.resize(retlen);
85     for (long i = 0; i < retlen; i++) config.offHostRouteEse[i] = buffer[i];
86   }
87   if ((GetNxpByteArrayValue(NAME_NFA_PROPRIETARY_CFG, (char*)buffer.data(),
88                             buffer.size(), &retlen)) &&
89       (retlen == 9)) {
90     config.nfaProprietaryCfg.protocol18092Active = (uint8_t)buffer[0];
91     config.nfaProprietaryCfg.protocolBPrime = (uint8_t)buffer[1];
92     config.nfaProprietaryCfg.protocolDual = (uint8_t)buffer[2];
93     config.nfaProprietaryCfg.protocol15693 = (uint8_t)buffer[3];
94     config.nfaProprietaryCfg.protocolKovio = (uint8_t)buffer[4];
95     config.nfaProprietaryCfg.protocolMifare = (uint8_t)buffer[5];
96     config.nfaProprietaryCfg.discoveryPollKovio = (uint8_t)buffer[6];
97     config.nfaProprietaryCfg.discoveryPollBPrime = (uint8_t)buffer[7];
98     config.nfaProprietaryCfg.discoveryListenBPrime = (uint8_t)buffer[8];
99   } else {
100     memset(&config.nfaProprietaryCfg, 0xFF, sizeof(ProtocolDiscoveryConfig));
101   }
102   if ((GetNxpNumValue(NAME_PRESENCE_CHECK_ALGORITHM, &num, sizeof(num))) &&
103       (num <= 2)) {
104     config.presenceCheckAlgorithm = (PresenceCheckAlgorithm)num;
105   }
106 }
107 
108 }  // namespace nfc
109 }  // namespace hardware
110 }  // namespace android
111 }  // namespace aidl