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