1 /******************************************************************************
2 *
3 * Copyright 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 #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 (GetNxpNumValue(NAME_OFF_HOST_SIM_PIPE_ID, &num, sizeof(num))) {
69 config.offHostSIMPipeId = (uint8_t)num;
70 }
71 if (GetNxpNumValue(NAME_DEFAULT_ISODEP_ROUTE, &num, sizeof(num))) {
72 config.defaultIsoDepRoute = (uint8_t)num;
73 }
74 if (GetNxpByteArrayValue(NAME_OFFHOST_ROUTE_UICC, (char*)buffer.data(),
75 buffer.size(), &retlen)) {
76 config.offHostRouteUicc.resize(retlen);
77 for (long i = 0; i < retlen; i++) config.offHostRouteUicc[i] = buffer[i];
78 }
79
80 if (GetNxpByteArrayValue(NAME_OFFHOST_ROUTE_ESE, (char*)buffer.data(),
81 buffer.size(), &retlen)) {
82 config.offHostRouteEse.resize(retlen);
83 for (long i = 0; i < retlen; i++) config.offHostRouteEse[i] = buffer[i];
84 }
85 if ((GetNxpByteArrayValue(NAME_NFA_PROPRIETARY_CFG, (char*)buffer.data(),
86 buffer.size(), &retlen)) &&
87 (retlen == 9)) {
88 config.nfaProprietaryCfg.protocol18092Active = (uint8_t)buffer[0];
89 config.nfaProprietaryCfg.protocolBPrime = (uint8_t)buffer[1];
90 config.nfaProprietaryCfg.protocolDual = (uint8_t)buffer[2];
91 config.nfaProprietaryCfg.protocol15693 = (uint8_t)buffer[3];
92 config.nfaProprietaryCfg.protocolKovio = (uint8_t)buffer[4];
93 config.nfaProprietaryCfg.protocolMifare = (uint8_t)buffer[5];
94 config.nfaProprietaryCfg.discoveryPollKovio = (uint8_t)buffer[6];
95 config.nfaProprietaryCfg.discoveryPollBPrime = (uint8_t)buffer[7];
96 config.nfaProprietaryCfg.discoveryListenBPrime = (uint8_t)buffer[8];
97 } else {
98 memset(&config.nfaProprietaryCfg, 0xFF, sizeof(ProtocolDiscoveryConfig));
99 }
100 if ((GetNxpNumValue(NAME_PRESENCE_CHECK_ALGORITHM, &num, sizeof(num))) &&
101 (num <= 2)) {
102 config.presenceCheckAlgorithm = (PresenceCheckAlgorithm)num;
103 }
104 }
105
106 } // namespace nfc
107 } // namespace hardware
108 } // namespace android
109 } // namespace aidl