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