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