1 /*
2 * Copyright (C) 2012-2014 NXP Semiconductors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <log/log.h>
17
18 #include <phNxpConfig.h>
19 #include <phNxpLog.h>
20 #include <phNxpNciHal.h>
21 #include <phNxpNciHal_dta.h>
22
23 /****** Global Variables*********/
24 static phNxpDta_Control_t nxpdta_ctrl = {0, 0, 0};
25 extern bool nfc_debug_enabled;
26 /*******************************************************************************
27 **
28 ** Function phNxpEnable_DtaMode
29 **
30 ** Description This function configures
31 ** HAL in DTA mode
32 **
33 *******************************************************************************/
phNxpEnable_DtaMode(uint16_t pattern_no)34 void phNxpEnable_DtaMode(uint16_t pattern_no) {
35 nxpdta_ctrl.dta_ctrl_flag = false;
36 nxpdta_ctrl.dta_t1t_flag = false;
37 nxpdta_ctrl.dta_pattern_no = pattern_no;
38 NXPLOG_NCIHAL_D(">>>>DTA - Mode is enabled");
39 nxpdta_ctrl.dta_ctrl_flag = true;
40 }
41
42 /*******************************************************************************
43 **
44 ** Function phNxpDisable_DtaMode
45 **
46 ** Description This function disable DTA mode
47 **
48 *******************************************************************************/
phNxpDisable_DtaMode(void)49 void phNxpDisable_DtaMode(void) {
50 nxpdta_ctrl.dta_ctrl_flag = false;
51 nxpdta_ctrl.dta_t1t_flag = false;
52 NXPLOG_NCIHAL_D(">>>>DTA - Mode is Disabled");
53 }
54
55 /******************************************************************************
56 * Function phNxpDta_IsEnable
57 *
58 * Description This function checks the DTA mode is enable or not.
59 *
60 * Returns It returns TRUE if DTA enabled otherwise FALSE
61 *
62 ******************************************************************************/
phNxpDta_IsEnable(void)63 NFCSTATUS phNxpDta_IsEnable(void) { return nxpdta_ctrl.dta_ctrl_flag; }
64
65 /******************************************************************************
66 * Function phNxpDta_T1TEnable
67 *
68 * Description This function enables DTA mode for T1T tag.
69 *
70 *
71 ******************************************************************************/
phNxpDta_T1TEnable(void)72 void phNxpDta_T1TEnable(void) { nxpdta_ctrl.dta_t1t_flag = true; }
73 /******************************************************************************
74 * Function phNxpNHal_DtaUpdate
75 *
76 * Description This function changes the command and responses specific
77 * to make DTA application success
78 *
79 * Returns It return NFCSTATUS_SUCCESS then continue with send else
80 * sends NFCSTATUS_FAILED direct response is prepared and
81 * do not send anything to NFCC.
82 *
83 ******************************************************************************/
84
phNxpNHal_DtaUpdate(uint16_t * cmd_len,uint8_t * p_cmd_data,uint16_t * rsp_len,uint8_t * p_rsp_data)85 NFCSTATUS phNxpNHal_DtaUpdate(uint16_t* cmd_len, uint8_t* p_cmd_data,
86 uint16_t* rsp_len, uint8_t* p_rsp_data) {
87 NFCSTATUS status = NFCSTATUS_SUCCESS;
88
89 if (nxpdta_ctrl.dta_ctrl_flag == true) {
90 // Workaround for DTA, block the set config command with general bytes */
91 if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
92 p_cmd_data[2] == 0x17 && p_cmd_data[3] == 0x01 &&
93 p_cmd_data[4] == 0x29 && p_cmd_data[5] == 0x14) {
94 *rsp_len = 5;
95 NXPLOG_NCIHAL_D(">>>>DTA - Block set config command");
96 phNxpNciHal_print_packet("DTASEND", p_cmd_data, *cmd_len);
97
98 p_rsp_data[0] = 0x40;
99 p_rsp_data[1] = 0x02;
100 p_rsp_data[2] = 0x02;
101 p_rsp_data[3] = 0x00;
102 p_rsp_data[4] = 0x00;
103
104 phNxpNciHal_print_packet("DTARECV", p_rsp_data, 5);
105
106 status = NFCSTATUS_FAILED;
107 NXPLOG_NCIHAL_D(
108 "Going through DTA workaround - Block set config command END");
109
110 } else if (p_cmd_data[0] == 0x21 && p_cmd_data[1] == 0x08 &&
111 p_cmd_data[2] == 0x04 && p_cmd_data[3] == 0xFF &&
112 p_cmd_data[4] == 0xFF) {
113 NXPLOG_NCIHAL_D(">>>>DTA Change Felica system code");
114 *rsp_len = 4;
115 p_rsp_data[0] = 0x41;
116 p_rsp_data[1] = 0x08;
117 p_rsp_data[2] = 0x01;
118 p_rsp_data[3] = 0x00;
119 status = NFCSTATUS_FAILED;
120
121 phNxpNciHal_print_packet("DTARECV", p_rsp_data, 4);
122 } else if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
123 p_cmd_data[2] == 0x10 && p_cmd_data[3] == 0x05 &&
124 p_cmd_data[10] == 0x32 && p_cmd_data[12] == 0x00) {
125 NXPLOG_NCIHAL_D(">>>>DTA Update LA_SEL_INFO param");
126
127 p_cmd_data[12] = 0x40;
128 p_cmd_data[18] = 0x02;
129 status = NFCSTATUS_SUCCESS;
130 } else if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
131 p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04 &&
132 p_cmd_data[10] == 0x32 && p_cmd_data[12] == 0x00) {
133 NXPLOG_NCIHAL_D(">>>>DTA Blocking dirty set config");
134 *rsp_len = 5;
135 p_rsp_data[0] = 0x40;
136 p_rsp_data[1] = 0x02;
137 p_rsp_data[2] = 0x02;
138 p_rsp_data[3] = 0x00;
139 p_rsp_data[4] = 0x00;
140 status = NFCSTATUS_FAILED;
141 phNxpNciHal_print_packet("DTARECV", p_rsp_data, 5);
142 } else if (p_cmd_data[0] == 0x21 && p_cmd_data[1] == 0x03) {
143 if (*cmd_len > (NCI_MAX_DATA_LEN - 6)) {
144 android_errorWriteLog(0x534e4554, "183487770");
145 return NFCSTATUS_FAILED;
146 }
147 NXPLOG_NCIHAL_D(">>>>DTA Add NFC-F listen tech params");
148 p_cmd_data[2] += 6;
149 p_cmd_data[3] += 3;
150 p_cmd_data[*cmd_len] = 0x80;
151 p_cmd_data[*cmd_len + 1] = 0x01;
152 p_cmd_data[*cmd_len + 2] = 0x82;
153 p_cmd_data[*cmd_len + 3] = 0x01;
154 p_cmd_data[*cmd_len + 4] = 0x85;
155 p_cmd_data[*cmd_len + 5] = 0x01;
156
157 *cmd_len += 6;
158 status = NFCSTATUS_SUCCESS;
159 } else if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
160 p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04 &&
161 p_cmd_data[10] == 0x32 && p_cmd_data[12] == 0x20 &&
162 nxpdta_ctrl.dta_pattern_no == 0x1000) {
163 NXPLOG_NCIHAL_D(">>>>DTA Blocking dirty set config for analog testing");
164 *rsp_len = 5;
165 p_rsp_data[0] = 0x40;
166 p_rsp_data[1] = 0x02;
167 p_rsp_data[2] = 0x02;
168 p_rsp_data[3] = 0x00;
169 p_rsp_data[4] = 0x00;
170 status = NFCSTATUS_FAILED;
171 phNxpNciHal_print_packet("DTARECV", p_rsp_data, 5);
172 } else if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
173 p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04 &&
174 p_cmd_data[4] == 0x32 && p_cmd_data[5] == 0x01 &&
175 p_cmd_data[6] == 0x00) {
176 NXPLOG_NCIHAL_D(">>>>DTA Blocking dirty set config");
177 *rsp_len = 5;
178 p_rsp_data[0] = 0x40;
179 p_rsp_data[1] = 0x02;
180 p_rsp_data[2] = 0x02;
181 p_rsp_data[3] = 0x00;
182 p_rsp_data[4] = 0x00;
183 status = NFCSTATUS_FAILED;
184 phNxpNciHal_print_packet("DTARECV", p_rsp_data, 5);
185 } else if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
186 p_cmd_data[2] == 0x04 && p_cmd_data[3] == 0x01 &&
187 p_cmd_data[4] == 0x50 && p_cmd_data[5] == 0x01 &&
188 p_cmd_data[6] == 0x00 && nxpdta_ctrl.dta_pattern_no == 0x1000) {
189 NXPLOG_NCIHAL_D(">>>>DTA Blocking dirty set config for analog testing");
190 *rsp_len = 5;
191 p_rsp_data[0] = 0x40;
192 p_rsp_data[1] = 0x02;
193 p_rsp_data[2] = 0x02;
194 p_rsp_data[3] = 0x00;
195 p_rsp_data[4] = 0x00;
196 status = NFCSTATUS_FAILED;
197 phNxpNciHal_print_packet("DTARECV", p_rsp_data, 5);
198 } else {
199 }
200 if (nxpdta_ctrl.dta_t1t_flag == true) {
201 if (p_cmd_data[2] == 0x07 && p_cmd_data[3] == 0x78 &&
202 p_cmd_data[4] == 0x00 && p_cmd_data[5] == 0x00) {
203 /*if (nxpdta_ctrl.dta_pattern_no == 0)
204 {
205 NXPLOG_NCIHAL_D(">>>>DTA - T1T modification block RID command Custom
206 Response (pattern 0)");
207 phNxpNciHal_print_packet("DTASEND", p_cmd_data, *cmd_len);
208 *rsp_len = 10;
209 p_rsp_data[0] = 0x00;
210 p_rsp_data[1] = 0x00;
211 p_rsp_data[2] = 0x07;
212 p_rsp_data[3] = 0x12;
213 p_rsp_data[4] = 0x49;
214 p_rsp_data[5] = 0x00;
215 p_rsp_data[6] = 0x00;
216 p_rsp_data[7] = 0x00;
217 p_rsp_data[8] = 0x00;
218 p_rsp_data[9] = 0x00;
219
220 status = NFCSTATUS_FAILED;
221
222 phNxpNciHal_print_packet("DTARECV", p_rsp_data, *rsp_len);
223 }
224 else
225 {*/
226 NXPLOG_NCIHAL_D("Change RID command's UID echo bytes to 0");
227
228 nxpdta_ctrl.dta_t1t_flag = false;
229 p_cmd_data[6] = 0x00;
230 p_cmd_data[7] = 0x00;
231 p_cmd_data[8] = 0x00;
232 p_cmd_data[9] = 0x00;
233 status = NFCSTATUS_SUCCESS;
234 /*}*/
235 }
236 }
237 }
238 return status;
239 }
240