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 android {
25 namespace hardware {
26 namespace nfc {
27 namespace V1_2 {
28 namespace implementation {
29
30 /******************************************************************************
31 * Function getConfig
32 *
33 * Description This function can be used by HAL to inform
34 * to update vendor configuration parameters
35 *
36 * Returns void.
37 *
38 ******************************************************************************/
getConfig(android::hardware::nfc::V1_2::NfcConfig & config)39 void NfcExtns::getConfig(android::hardware::nfc::V1_2::NfcConfig& config) {
40 unsigned long num = 0;
41 std::array<uint8_t, NXP_MAX_CONFIG_STRING_LEN> buffer;
42 buffer.fill(0);
43 long retlen = 0;
44 memset(&config, 0x00, sizeof(android::hardware::nfc::V1_2::NfcConfig));
45 getConfig(config.v1_1);
46
47 if (GetNxpByteArrayValue(NAME_OFFHOST_ROUTE_UICC, (char*)buffer.data(),
48 buffer.size(), &retlen)) {
49 config.offHostRouteUicc.resize(retlen);
50 for (long i = 0; i < retlen; i++) config.offHostRouteUicc[i] = buffer[i];
51 }
52
53 if (GetNxpByteArrayValue(NAME_OFFHOST_ROUTE_ESE, (char*)buffer.data(),
54 buffer.size(), &retlen)) {
55 config.offHostRouteEse.resize(retlen);
56 for (long i = 0; i < retlen; i++) config.offHostRouteEse[i] = buffer[i];
57 }
58
59 if (GetNxpNumValue(NAME_DEFAULT_ISODEP_ROUTE, &num, sizeof(num))) {
60 config.defaultIsoDepRoute = num;
61 }
62 }
63
64 /******************************************************************************
65 * Function getConfig
66 *
67 * Description This function can be used by HAL to inform
68 * to update vendor configuration parameters
69 *
70 * Returns void.
71 *
72 ******************************************************************************/
getConfig(android::hardware::nfc::V1_1::NfcConfig & config)73 void NfcExtns::getConfig(android::hardware::nfc::V1_1::NfcConfig& config) {
74 unsigned long num = 0;
75 std::array<uint8_t, NXP_MAX_CONFIG_STRING_LEN> buffer;
76 buffer.fill(0);
77 long retlen = 0;
78 memset(&config, 0x00, sizeof(android::hardware::nfc::V1_1::NfcConfig));
79 phNxpNciHal_getExtVendorConfig();
80 if (GetNxpNumValue(NAME_NFA_POLL_BAIL_OUT_MODE, &num, sizeof(num))) {
81 config.nfaPollBailOutMode = (bool)num;
82 }
83 if (GetNxpNumValue(NAME_ISO_DEP_MAX_TRANSCEIVE, &num, sizeof(num))) {
84 config.maxIsoDepTransceiveLength = (uint32_t)num;
85 }
86 if (GetNxpNumValue(NAME_DEFAULT_OFFHOST_ROUTE, &num, sizeof(num))) {
87 config.defaultOffHostRoute = (uint8_t)num;
88 }
89 if (GetNxpNumValue(NAME_DEFAULT_NFCF_ROUTE, &num, sizeof(num))) {
90 config.defaultOffHostRouteFelica = (uint8_t)num;
91 }
92 if (GetNxpNumValue(NAME_DEFAULT_SYS_CODE_ROUTE, &num, sizeof(num))) {
93 config.defaultSystemCodeRoute = (uint8_t)num;
94 }
95 if (GetNxpNumValue(NAME_DEFAULT_SYS_CODE_PWR_STATE, &num, sizeof(num))) {
96 config.defaultSystemCodePowerState =
97 phNxpNciHal_updateAutonomousPwrState((uint8_t)num);
98 }
99 if (GetNxpNumValue(NAME_DEFAULT_ROUTE, &num, sizeof(num))) {
100 config.defaultRoute = (uint8_t)num;
101 }
102 if (GetNxpByteArrayValue(NAME_DEVICE_HOST_ALLOW_LIST, (char*)buffer.data(),
103 buffer.size(), &retlen)) {
104 config.hostWhitelist.resize(retlen);
105 for (long i = 0; i < retlen; i++) config.hostWhitelist[i] = buffer[i];
106 }
107 if (GetNxpNumValue(NAME_OFF_HOST_ESE_PIPE_ID, &num, sizeof(num))) {
108 config.offHostESEPipeId = (uint8_t)num;
109 }
110 if (GetNxpNumValue(NAME_OFF_HOST_SIM_PIPE_ID, &num, sizeof(num))) {
111 config.offHostSIMPipeId = (uint8_t)num;
112 }
113 if ((GetNxpByteArrayValue(NAME_NFA_PROPRIETARY_CFG, (char*)buffer.data(),
114 buffer.size(), &retlen)) &&
115 (retlen == 9)) {
116 config.nfaProprietaryCfg.protocol18092Active = (uint8_t)buffer[0];
117 config.nfaProprietaryCfg.protocolBPrime = (uint8_t)buffer[1];
118 config.nfaProprietaryCfg.protocolDual = (uint8_t)buffer[2];
119 config.nfaProprietaryCfg.protocol15693 = (uint8_t)buffer[3];
120 config.nfaProprietaryCfg.protocolKovio = (uint8_t)buffer[4];
121 config.nfaProprietaryCfg.protocolMifare = (uint8_t)buffer[5];
122 config.nfaProprietaryCfg.discoveryPollKovio = (uint8_t)buffer[6];
123 config.nfaProprietaryCfg.discoveryPollBPrime = (uint8_t)buffer[7];
124 config.nfaProprietaryCfg.discoveryListenBPrime = (uint8_t)buffer[8];
125 } else {
126 memset(&config.nfaProprietaryCfg, 0xFF, sizeof(ProtocolDiscoveryConfig));
127 }
128 if ((GetNxpNumValue(NAME_PRESENCE_CHECK_ALGORITHM, &num, sizeof(num))) &&
129 (num <= 2)) {
130 config.presenceCheckAlgorithm = (PresenceCheckAlgorithm)num;
131 }
132 }
133
134 } // namespace implementation
135 } // namespace V1_2
136 } // namespace nfc
137 } // namespace hardware
138 } // namespace android
139