The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Evan Chu | e9629ba | 2014-01-31 11:18:47 -0500 | [diff] [blame] | 3 | * Copyright (C) 2011-2014 Broadcom Corporation |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 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 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This file contains the implementation for ISO 15693 in Reader/Writer |
| 22 | * mode. |
| 23 | * |
| 24 | ******************************************************************************/ |
Ruchi Kandoi | 6e267b3 | 2019-01-24 13:39:18 -0800 | [diff] [blame] | 25 | #include <log/log.h> |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 26 | #include <string.h> |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 27 | |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 28 | #include <android-base/stringprintf.h> |
| 29 | #include <base/logging.h> |
| 30 | |
| 31 | #include "nfc_target.h" |
| 32 | |
| 33 | #include "bt_types.h" |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 34 | #include "nfc_api.h" |
| 35 | #include "nfc_int.h" |
| 36 | #include "rw_api.h" |
| 37 | #include "rw_int.h" |
Andre Eisenbach | 8a4edf6 | 2017-11-20 14:51:11 -0800 | [diff] [blame] | 38 | #include "trace_api.h" |
| 39 | |
| 40 | using android::base::StringPrintf; |
| 41 | |
| 42 | extern bool nfc_debug_enabled; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 43 | |
Ruchi Kandoi | 46e6e28 | 2017-01-30 14:26:10 -0800 | [diff] [blame] | 44 | /* Response timeout */ |
| 45 | #define RW_I93_TOUT_RESP 1000 |
| 46 | /* stay quiet timeout */ |
| 47 | #define RW_I93_TOUT_STAY_QUIET 200 |
| 48 | /* max reading data if read multi block is supported */ |
| 49 | #define RW_I93_READ_MULTI_BLOCK_SIZE 128 |
| 50 | /* CC, zero length NDEF, Terminator TLV */ |
| 51 | #define RW_I93_FORMAT_DATA_LEN 8 |
| 52 | /* max getting lock status if get multi block sec is supported */ |
| 53 | #define RW_I93_GET_MULTI_BLOCK_SEC_SIZE 253 |
George Chang | ec0e233 | 2019-08-16 20:37:23 +0800 | [diff] [blame] | 54 | /*Capability Container CC Size */ |
| 55 | #define RW_I93_CC_SIZE 4 |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 56 | |
| 57 | /* main state */ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 58 | enum { |
| 59 | RW_I93_STATE_NOT_ACTIVATED, /* ISO15693 is not activated */ |
| 60 | RW_I93_STATE_IDLE, /* waiting for upper layer API */ |
| 61 | RW_I93_STATE_BUSY, /* waiting for response from tag */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 62 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 63 | RW_I93_STATE_DETECT_NDEF, /* performing NDEF detection precedure */ |
| 64 | RW_I93_STATE_READ_NDEF, /* performing read NDEF procedure */ |
| 65 | RW_I93_STATE_UPDATE_NDEF, /* performing update NDEF procedure */ |
| 66 | RW_I93_STATE_FORMAT, /* performing format procedure */ |
| 67 | RW_I93_STATE_SET_READ_ONLY, /* performing set read-only procedure */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 68 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 69 | RW_I93_STATE_PRESENCE_CHECK /* checking presence of tag */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* sub state */ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 73 | enum { |
| 74 | RW_I93_SUBSTATE_WAIT_UID, /* waiting for response of inventory */ |
| 75 | RW_I93_SUBSTATE_WAIT_SYS_INFO, /* waiting for response of get sys info */ |
| 76 | RW_I93_SUBSTATE_WAIT_CC, /* waiting for reading CC */ |
| 77 | RW_I93_SUBSTATE_SEARCH_NDEF_TLV, /* searching NDEF TLV */ |
| 78 | RW_I93_SUBSTATE_CHECK_LOCK_STATUS, /* check if any NDEF TLV is locked */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 79 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 80 | RW_I93_SUBSTATE_RESET_LEN, /* set length to 0 to update NDEF TLV */ |
| 81 | RW_I93_SUBSTATE_WRITE_NDEF, /* writing NDEF and Terminator TLV */ |
| 82 | RW_I93_SUBSTATE_UPDATE_LEN, /* set length into NDEF TLV */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 83 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 84 | RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI, /* reset DSFID and AFI */ |
| 85 | RW_I93_SUBSTATE_CHECK_READ_ONLY, /* check if any block is locked */ |
| 86 | RW_I93_SUBSTATE_WRITE_CC_NDEF_TLV, /* write CC and empty NDEF/Terminator TLV |
| 87 | */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 88 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 89 | RW_I93_SUBSTATE_WAIT_UPDATE_CC, /* updating CC as read-only */ |
| 90 | RW_I93_SUBSTATE_LOCK_NDEF_TLV, /* lock blocks of NDEF TLV */ |
| 91 | RW_I93_SUBSTATE_WAIT_LOCK_CC /* lock block of CC */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 94 | static std::string rw_i93_get_state_name(uint8_t state); |
| 95 | static std::string rw_i93_get_sub_state_name(uint8_t sub_state); |
| 96 | static std::string rw_i93_get_tag_name(uint8_t product_version); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 97 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 98 | static void rw_i93_data_cback(uint8_t conn_id, tNFC_CONN_EVT event, |
| 99 | tNFC_CONN* p_data); |
| 100 | void rw_i93_handle_error(tNFC_STATUS status); |
| 101 | tNFC_STATUS rw_i93_send_cmd_get_sys_info(uint8_t* p_uid, uint8_t extra_flag); |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 102 | tNFC_STATUS rw_i93_send_cmd_get_ext_sys_info(uint8_t* p_uid); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 103 | |
| 104 | /******************************************************************************* |
| 105 | ** |
| 106 | ** Function rw_i93_get_product_version |
| 107 | ** |
| 108 | ** Description Get product version from UID |
| 109 | ** |
| 110 | ** Returns void |
| 111 | ** |
| 112 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 113 | void rw_i93_get_product_version(uint8_t* p_uid) { |
| 114 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 115 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 116 | if (!memcmp(p_i93->uid, p_uid, I93_UID_BYTE_LEN)) { |
| 117 | return; |
| 118 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 119 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 120 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 121 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 122 | memcpy(p_i93->uid, p_uid, I93_UID_BYTE_LEN); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 123 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 124 | if (p_uid[1] == I93_UID_IC_MFG_CODE_NXP) { |
| 125 | if (p_uid[2] == I93_UID_ICODE_SLI) |
| 126 | p_i93->product_version = RW_I93_ICODE_SLI; |
| 127 | else if (p_uid[2] == I93_UID_ICODE_SLI_S) |
| 128 | p_i93->product_version = RW_I93_ICODE_SLI_S; |
| 129 | else if (p_uid[2] == I93_UID_ICODE_SLI_L) |
| 130 | p_i93->product_version = RW_I93_ICODE_SLI_L; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 131 | else |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 132 | p_i93->product_version = RW_I93_UNKNOWN_PRODUCT; |
| 133 | } else if (p_uid[1] == I93_UID_IC_MFG_CODE_TI) { |
| 134 | if ((p_uid[2] & I93_UID_TAG_IT_HF_I_PRODUCT_ID_MASK) == |
| 135 | I93_UID_TAG_IT_HF_I_PLUS_INLAY) |
| 136 | p_i93->product_version = RW_I93_TAG_IT_HF_I_PLUS_INLAY; |
| 137 | else if ((p_uid[2] & I93_UID_TAG_IT_HF_I_PRODUCT_ID_MASK) == |
| 138 | I93_UID_TAG_IT_HF_I_PLUS_CHIP) |
| 139 | p_i93->product_version = RW_I93_TAG_IT_HF_I_PLUS_CHIP; |
| 140 | else if ((p_uid[2] & I93_UID_TAG_IT_HF_I_PRODUCT_ID_MASK) == |
| 141 | I93_UID_TAG_IT_HF_I_STD_CHIP_INLAY) |
| 142 | p_i93->product_version = RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY; |
| 143 | else if ((p_uid[2] & I93_UID_TAG_IT_HF_I_PRODUCT_ID_MASK) == |
| 144 | I93_UID_TAG_IT_HF_I_PRO_CHIP_INLAY) |
| 145 | p_i93->product_version = RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY; |
| 146 | else |
| 147 | p_i93->product_version = RW_I93_UNKNOWN_PRODUCT; |
| 148 | } else if ((p_uid[1] == I93_UID_IC_MFG_CODE_STM) && |
| 149 | (p_i93->info_flags & I93_INFO_FLAG_IC_REF)) { |
| 150 | if (p_i93->ic_reference == I93_IC_REF_STM_M24LR04E_R) |
| 151 | p_i93->product_version = RW_I93_STM_M24LR04E_R; |
| 152 | else if (p_i93->ic_reference == I93_IC_REF_STM_M24LR16E_R) |
| 153 | p_i93->product_version = RW_I93_STM_M24LR16E_R; |
| 154 | else if (p_i93->ic_reference == I93_IC_REF_STM_M24LR64E_R) |
| 155 | p_i93->product_version = RW_I93_STM_M24LR64E_R; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 156 | else if (p_i93->ic_reference == I93_IC_REF_STM_ST25DVHIK) |
| 157 | p_i93->product_version = RW_I93_STM_ST25DVHIK; |
| 158 | else if (p_i93->ic_reference == I93_IC_REF_STM_ST25DV04K) |
| 159 | p_i93->product_version = RW_I93_STM_ST25DV04K; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 160 | else { |
| 161 | switch (p_i93->ic_reference & I93_IC_REF_STM_MASK) { |
| 162 | case I93_IC_REF_STM_LRI1K: |
| 163 | p_i93->product_version = RW_I93_STM_LRI1K; |
| 164 | break; |
| 165 | case I93_IC_REF_STM_LRI2K: |
| 166 | p_i93->product_version = RW_I93_STM_LRI2K; |
| 167 | break; |
| 168 | case I93_IC_REF_STM_LRIS2K: |
| 169 | p_i93->product_version = RW_I93_STM_LRIS2K; |
| 170 | break; |
| 171 | case I93_IC_REF_STM_LRIS64K: |
| 172 | p_i93->product_version = RW_I93_STM_LRIS64K; |
| 173 | break; |
| 174 | case I93_IC_REF_STM_M24LR64_R: |
| 175 | p_i93->product_version = RW_I93_STM_M24LR64_R; |
| 176 | break; |
| 177 | default: |
| 178 | p_i93->product_version = RW_I93_UNKNOWN_PRODUCT; |
| 179 | break; |
| 180 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 181 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 182 | } else { |
| 183 | p_i93->product_version = RW_I93_UNKNOWN_PRODUCT; |
| 184 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 185 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 186 | DLOG_IF(INFO, nfc_debug_enabled) |
| 187 | << StringPrintf("product_version = <%s>", |
| 188 | rw_i93_get_tag_name(p_i93->product_version).c_str()); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 189 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 190 | switch (p_i93->product_version) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 191 | case RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY: |
| 192 | case RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 193 | /* these don't support Get System Information Command */ |
| 194 | /* these support only Inventory, Stay Quiet, Read Single Block, Write |
| 195 | * Single Block, Lock Block */ |
| 196 | p_i93->block_size = I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_BLK_SIZE; |
| 197 | p_i93->num_block = I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_NUM_USER_BLK; |
| 198 | break; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 199 | default: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 200 | break; |
| 201 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /******************************************************************************* |
| 205 | ** |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 206 | ** Function rw_i93_process_ext_sys_info |
| 207 | ** |
| 208 | ** Description Store extended system information of tag |
| 209 | ** |
| 210 | ** Returns FALSE if retrying with protocol extension flag |
| 211 | ** |
| 212 | *******************************************************************************/ |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 213 | bool rw_i93_process_ext_sys_info(uint8_t* p_data, uint16_t length) { |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 214 | uint8_t* p = p_data; |
| 215 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 216 | uint8_t uid[I93_UID_BYTE_LEN], *p_uid; |
| 217 | |
| 218 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
| 219 | |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 220 | if (length < (I93_UID_BYTE_LEN + 1)) { |
| 221 | android_errorWriteLog(0x534e4554, "122316913"); |
| 222 | return false; |
| 223 | } |
| 224 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 225 | STREAM_TO_UINT8(p_i93->info_flags, p); |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 226 | length--; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 227 | |
| 228 | p_uid = uid; |
| 229 | STREAM_TO_ARRAY8(p_uid, p); |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 230 | length -= I93_UID_BYTE_LEN; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 231 | |
| 232 | if (p_i93->info_flags & I93_INFO_FLAG_DSFID) { |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 233 | if (length < 1) { |
| 234 | android_errorWriteLog(0x534e4554, "122316913"); |
| 235 | return false; |
| 236 | } |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 237 | STREAM_TO_UINT8(p_i93->dsfid, p); |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 238 | length--; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 239 | } |
| 240 | if (p_i93->info_flags & I93_INFO_FLAG_AFI) { |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 241 | if (length < 1) { |
| 242 | android_errorWriteLog(0x534e4554, "122316913"); |
| 243 | return false; |
| 244 | } |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 245 | STREAM_TO_UINT8(p_i93->afi, p); |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 246 | length--; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 247 | } |
| 248 | if (p_i93->info_flags & I93_INFO_FLAG_MEM_SIZE) { |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 249 | if (length < 3) { |
| 250 | android_errorWriteLog(0x534e4554, "122316913"); |
| 251 | return false; |
| 252 | } |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 253 | STREAM_TO_UINT16(p_i93->num_block, p); |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 254 | length -= I93_INFO_16BIT_NUM_BLOCK_LEN; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 255 | |
| 256 | /* it is one less than actual number of bytes */ |
| 257 | p_i93->num_block += 1; |
| 258 | |
| 259 | STREAM_TO_UINT8(p_i93->block_size, p); |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 260 | length--; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 261 | /* it is one less than actual number of blocks */ |
| 262 | p_i93->block_size = (p_i93->block_size & 0x1F) + 1; |
| 263 | } |
| 264 | if (p_i93->info_flags & I93_INFO_FLAG_IC_REF) { |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 265 | if (length < 1) { |
| 266 | android_errorWriteLog(0x534e4554, "122316913"); |
| 267 | return false; |
| 268 | } |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 269 | STREAM_TO_UINT8(p_i93->ic_reference, p); |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 270 | length--; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 271 | |
| 272 | /* clear existing UID to set product version */ |
| 273 | p_i93->uid[0] = 0x00; |
| 274 | |
| 275 | /* store UID and get product version */ |
| 276 | rw_i93_get_product_version(p_uid); |
| 277 | |
| 278 | if (p_i93->uid[0] == I93_UID_FIRST_BYTE) { |
| 279 | if (p_i93->uid[1] == I93_UID_IC_MFG_CODE_STM) { |
| 280 | /* STM supports more than 2040 bytes */ |
| 281 | p_i93->intl_flags |= RW_I93_FLAG_EXT_COMMANDS; |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | /******************************************************************************* |
| 289 | ** |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 290 | ** Function rw_i93_process_sys_info |
| 291 | ** |
| 292 | ** Description Store system information of tag |
| 293 | ** |
| 294 | ** Returns FALSE if retrying with protocol extension flag |
| 295 | ** |
| 296 | *******************************************************************************/ |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 297 | bool rw_i93_process_sys_info(uint8_t* p_data, uint16_t length) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 298 | uint8_t* p = p_data; |
| 299 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 300 | uint8_t uid[I93_UID_BYTE_LEN], *p_uid; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 301 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 302 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 303 | |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 304 | if (length < (I93_UID_BYTE_LEN + 1)) { |
| 305 | android_errorWriteLog(0x534e4554, "121259048"); |
| 306 | return false; |
| 307 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 308 | STREAM_TO_UINT8(p_i93->info_flags, p); |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 309 | length--; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 310 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 311 | p_uid = uid; |
| 312 | STREAM_TO_ARRAY8(p_uid, p); |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 313 | length -= I93_UID_BYTE_LEN; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 314 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 315 | if (p_i93->info_flags & I93_INFO_FLAG_DSFID) { |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 316 | if (length == 0) { |
| 317 | android_errorWriteLog(0x534e4554, "121259048"); |
| 318 | return false; |
| 319 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 320 | STREAM_TO_UINT8(p_i93->dsfid, p); |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 321 | length--; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 322 | } |
| 323 | if (p_i93->info_flags & I93_INFO_FLAG_AFI) { |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 324 | if (length == 0) { |
| 325 | android_errorWriteLog(0x534e4554, "121259048"); |
| 326 | return false; |
| 327 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 328 | STREAM_TO_UINT8(p_i93->afi, p); |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 329 | length--; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 330 | } |
| 331 | if (p_i93->info_flags & I93_INFO_FLAG_MEM_SIZE) { |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 332 | bool block_16_bit = p_i93->intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK; |
| 333 | if (block_16_bit && length > 2) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 334 | STREAM_TO_UINT16(p_i93->num_block, p); |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 335 | length -= 2; |
| 336 | } else if (!block_16_bit && length > 1) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 337 | STREAM_TO_UINT8(p_i93->num_block, p); |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 338 | length--; |
| 339 | } else { |
| 340 | android_errorWriteLog(0x534e4554, "121259048"); |
| 341 | return false; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 342 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 343 | /* it is one less than actual number of bytes */ |
| 344 | p_i93->num_block += 1; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 345 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 346 | STREAM_TO_UINT8(p_i93->block_size, p); |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 347 | length--; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 348 | /* it is one less than actual number of blocks */ |
| 349 | p_i93->block_size = (p_i93->block_size & 0x1F) + 1; |
| 350 | } |
| 351 | if (p_i93->info_flags & I93_INFO_FLAG_IC_REF) { |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 352 | if (length == 0) { |
| 353 | android_errorWriteLog(0x534e4554, "121259048"); |
| 354 | return false; |
| 355 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 356 | STREAM_TO_UINT8(p_i93->ic_reference, p); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 357 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 358 | /* clear existing UID to set product version */ |
| 359 | p_i93->uid[0] = 0x00; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 360 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 361 | /* store UID and get product version */ |
| 362 | rw_i93_get_product_version(p_uid); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 363 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 364 | if (p_i93->uid[0] == I93_UID_FIRST_BYTE) { |
| 365 | if ((p_i93->uid[1] == I93_UID_IC_MFG_CODE_NXP) && |
| 366 | (p_i93->ic_reference == I93_IC_REF_ICODE_SLI_L)) { |
| 367 | p_i93->num_block = 8; |
| 368 | p_i93->block_size = 4; |
| 369 | } else if (p_i93->uid[1] == I93_UID_IC_MFG_CODE_STM) { |
| 370 | /* |
| 371 | ** LRI1K: 010000xx(b), blockSize: 4, numberBlocks: 0x20 |
| 372 | ** LRI2K: 001000xx(b), blockSize: 4, numberBlocks: 0x40 |
| 373 | ** LRIS2K: 001010xx(b), blockSize: 4, numberBlocks: 0x40 |
| 374 | ** LRIS64K: 010001xx(b), blockSize: 4, numberBlocks: 0x800 |
| 375 | ** M24LR64-R: 001011xx(b), blockSize: 4, numberBlocks: 0x800 |
| 376 | ** M24LR04E-R: 01011010(b), blockSize: 4, numberBlocks: 0x80 |
| 377 | ** M24LR16E-R: 01001110(b), blockSize: 4, numberBlocks: 0x200 |
| 378 | ** M24LR64E-R: 01011110(b), blockSize: 4, numberBlocks: 0x800 |
| 379 | */ |
| 380 | if ((p_i93->product_version == RW_I93_STM_M24LR16E_R) || |
| 381 | (p_i93->product_version == RW_I93_STM_M24LR64E_R)) { |
| 382 | /* |
| 383 | ** M24LR16E-R or M24LR64E-R returns system information |
| 384 | ** without memory size, if option flag is not set. |
| 385 | ** LRIS64K and M24LR64-R return error if option flag is not |
| 386 | ** set. |
| 387 | */ |
| 388 | if (!(p_i93->intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK)) { |
| 389 | /* get memory size with protocol extension flag */ |
| 390 | if (rw_i93_send_cmd_get_sys_info(NULL, I93_FLAG_PROT_EXT_YES) == |
| 391 | NFC_STATUS_OK) { |
| 392 | /* STM supports more than 2040 bytes */ |
| 393 | p_i93->intl_flags |= RW_I93_FLAG_16BIT_NUM_BLOCK; |
| 394 | |
| 395 | return false; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 396 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 397 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 398 | } else if ((p_i93->product_version == RW_I93_STM_LRI2K) && |
| 399 | (p_i93->ic_reference == 0x21)) { |
| 400 | /* workaround of byte order in memory size information */ |
| 401 | p_i93->num_block = 64; |
| 402 | p_i93->block_size = 4; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 403 | } else if (!(p_i93->info_flags & I93_INFO_FLAG_MEM_SIZE)) { |
| 404 | if (!(p_i93->intl_flags & RW_I93_FLAG_EXT_COMMANDS)) { |
| 405 | if (rw_i93_send_cmd_get_ext_sys_info(NULL) == NFC_STATUS_OK) { |
| 406 | /* STM supports more than 2040 bytes */ |
| 407 | p_i93->intl_flags |= RW_I93_FLAG_EXT_COMMANDS; |
| 408 | |
| 409 | return false; |
| 410 | } |
| 411 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 412 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 413 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 414 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 415 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 416 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 417 | return true; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /******************************************************************************* |
| 421 | ** |
| 422 | ** Function rw_i93_check_sys_info_prot_ext |
| 423 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 424 | ** Description Check if need to set protocol extension flag to get system |
| 425 | ** info |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 426 | ** |
| 427 | ** Returns TRUE if sent Get System Info with protocol extension flag |
| 428 | ** |
| 429 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 430 | bool rw_i93_check_sys_info_prot_ext(uint8_t error_code) { |
| 431 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 432 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 433 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 434 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 435 | if ((p_i93->uid[1] == I93_UID_IC_MFG_CODE_STM) && |
| 436 | (p_i93->sent_cmd == I93_CMD_GET_SYS_INFO) && |
| 437 | (error_code == I93_ERROR_CODE_OPTION_NOT_SUPPORTED) && |
| 438 | (rw_i93_send_cmd_get_sys_info(NULL, I93_FLAG_PROT_EXT_YES) == |
| 439 | NFC_STATUS_OK)) { |
| 440 | return true; |
| 441 | } else { |
| 442 | return false; |
| 443 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /******************************************************************************* |
| 447 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 448 | ** Function rw_i93_send_to_upper |
| 449 | ** |
| 450 | ** Description Send response to upper layer |
| 451 | ** |
| 452 | ** Returns void |
| 453 | ** |
| 454 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 455 | void rw_i93_send_to_upper(NFC_HDR* p_resp) { |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 456 | uint8_t *p = (uint8_t*)(p_resp + 1) + p_resp->offset, *p_uid; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 457 | uint16_t length = p_resp->len; |
| 458 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 459 | tRW_DATA rw_data; |
| 460 | uint8_t event = RW_I93_MAX_EVT; |
| 461 | uint8_t flags; |
| 462 | NFC_HDR* p_buff; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 463 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 464 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 465 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 466 | STREAM_TO_UINT8(flags, p); |
| 467 | length--; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 468 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 469 | if (flags & I93_FLAG_ERROR_DETECTED) { |
| 470 | if ((length) && (rw_i93_check_sys_info_prot_ext(*p))) { |
| 471 | /* getting system info with protocol extension flag */ |
| 472 | /* This STM tag supports more than 2040 bytes */ |
| 473 | p_i93->intl_flags |= RW_I93_FLAG_16BIT_NUM_BLOCK; |
| 474 | p_i93->state = RW_I93_STATE_BUSY; |
| 475 | } else { |
| 476 | /* notify error to upper layer */ |
| 477 | rw_data.i93_cmd_cmpl.status = NFC_STATUS_FAILED; |
| 478 | rw_data.i93_cmd_cmpl.command = p_i93->sent_cmd; |
| 479 | STREAM_TO_UINT8(rw_data.i93_cmd_cmpl.error_code, p); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 480 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 481 | rw_cb.tcb.i93.sent_cmd = 0; |
| 482 | (*(rw_cb.p_cback))(RW_I93_CMD_CMPL_EVT, &rw_data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 483 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 484 | return; |
| 485 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 486 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 487 | switch (p_i93->sent_cmd) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 488 | case I93_CMD_INVENTORY: |
| 489 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 490 | /* forward inventory response */ |
| 491 | rw_data.i93_inventory.status = NFC_STATUS_OK; |
| 492 | STREAM_TO_UINT8(rw_data.i93_inventory.dsfid, p); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 493 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 494 | p_uid = rw_data.i93_inventory.uid; |
| 495 | STREAM_TO_ARRAY8(p_uid, p); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 496 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 497 | /* store UID and get product version */ |
| 498 | rw_i93_get_product_version(p_uid); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 499 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 500 | event = RW_I93_INVENTORY_EVT; |
| 501 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 502 | |
| 503 | case I93_CMD_READ_SINGLE_BLOCK: |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 504 | case I93_CMD_EXT_READ_SINGLE_BLOCK: |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 505 | case I93_CMD_READ_MULTI_BLOCK: |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 506 | case I93_CMD_EXT_READ_MULTI_BLOCK: |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 507 | case I93_CMD_GET_MULTI_BLK_SEC: |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 508 | case I93_CMD_EXT_GET_MULTI_BLK_SEC: |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 509 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 510 | /* forward tag data or security status */ |
| 511 | p_buff = (NFC_HDR*)GKI_getbuf((uint16_t)(length + NFC_HDR_SIZE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 512 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 513 | if (p_buff) { |
| 514 | p_buff->offset = 0; |
| 515 | p_buff->len = length; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 516 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 517 | memcpy((p_buff + 1), p, length); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 518 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 519 | rw_data.i93_data.status = NFC_STATUS_OK; |
| 520 | rw_data.i93_data.command = p_i93->sent_cmd; |
| 521 | rw_data.i93_data.p_data = p_buff; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 522 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 523 | event = RW_I93_DATA_EVT; |
| 524 | } else { |
| 525 | rw_data.i93_cmd_cmpl.status = NFC_STATUS_NO_BUFFERS; |
| 526 | rw_data.i93_cmd_cmpl.command = p_i93->sent_cmd; |
| 527 | rw_data.i93_cmd_cmpl.error_code = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 528 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 529 | event = RW_I93_CMD_CMPL_EVT; |
| 530 | } |
| 531 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 532 | |
| 533 | case I93_CMD_WRITE_SINGLE_BLOCK: |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 534 | case I93_CMD_EXT_WRITE_SINGLE_BLOCK: |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 535 | case I93_CMD_LOCK_BLOCK: |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 536 | case I93_CMD_EXT_LOCK_BLOCK: |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 537 | case I93_CMD_WRITE_MULTI_BLOCK: |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 538 | case I93_CMD_EXT_WRITE_MULTI_BLOCK: |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 539 | case I93_CMD_SELECT: |
| 540 | case I93_CMD_RESET_TO_READY: |
| 541 | case I93_CMD_WRITE_AFI: |
| 542 | case I93_CMD_LOCK_AFI: |
| 543 | case I93_CMD_WRITE_DSFID: |
| 544 | case I93_CMD_LOCK_DSFID: |
| 545 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 546 | /* notify the complete of command */ |
| 547 | rw_data.i93_cmd_cmpl.status = NFC_STATUS_OK; |
| 548 | rw_data.i93_cmd_cmpl.command = p_i93->sent_cmd; |
| 549 | rw_data.i93_cmd_cmpl.error_code = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 550 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 551 | event = RW_I93_CMD_CMPL_EVT; |
| 552 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 553 | |
| 554 | case I93_CMD_GET_SYS_INFO: |
| 555 | |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 556 | if (rw_i93_process_sys_info(p, length)) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 557 | rw_data.i93_sys_info.status = NFC_STATUS_OK; |
| 558 | rw_data.i93_sys_info.info_flags = p_i93->info_flags; |
| 559 | rw_data.i93_sys_info.dsfid = p_i93->dsfid; |
| 560 | rw_data.i93_sys_info.afi = p_i93->afi; |
| 561 | rw_data.i93_sys_info.num_block = p_i93->num_block; |
| 562 | rw_data.i93_sys_info.block_size = p_i93->block_size; |
| 563 | rw_data.i93_sys_info.IC_reference = p_i93->ic_reference; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 564 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 565 | memcpy(rw_data.i93_sys_info.uid, p_i93->uid, I93_UID_BYTE_LEN); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 566 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 567 | event = RW_I93_SYS_INFO_EVT; |
| 568 | } else { |
| 569 | /* retrying with protocol extension flag */ |
| 570 | p_i93->state = RW_I93_STATE_BUSY; |
| 571 | return; |
| 572 | } |
| 573 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 574 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 575 | case I93_CMD_EXT_GET_SYS_INFO: |
| 576 | |
Jack Yu | 8a86b1f | 2019-01-30 16:21:45 +0800 | [diff] [blame] | 577 | if (rw_i93_process_ext_sys_info(p, length)) { |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 578 | rw_data.i93_sys_info.status = NFC_STATUS_OK; |
| 579 | rw_data.i93_sys_info.info_flags = p_i93->info_flags; |
| 580 | rw_data.i93_sys_info.dsfid = p_i93->dsfid; |
| 581 | rw_data.i93_sys_info.afi = p_i93->afi; |
| 582 | rw_data.i93_sys_info.num_block = p_i93->num_block; |
| 583 | rw_data.i93_sys_info.block_size = p_i93->block_size; |
| 584 | rw_data.i93_sys_info.IC_reference = p_i93->ic_reference; |
| 585 | |
| 586 | memcpy(rw_data.i93_sys_info.uid, p_i93->uid, I93_UID_BYTE_LEN); |
| 587 | |
| 588 | event = RW_I93_SYS_INFO_EVT; |
| 589 | } else { |
| 590 | /* retrying with protocol extension flag or with extended sys info |
| 591 | * command */ |
| 592 | p_i93->state = RW_I93_STATE_BUSY; |
| 593 | return; |
| 594 | } |
| 595 | break; |
| 596 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 597 | default: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 598 | break; |
| 599 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 600 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 601 | rw_cb.tcb.i93.sent_cmd = 0; |
| 602 | if (event != RW_I93_MAX_EVT) { |
| 603 | (*(rw_cb.p_cback))(event, &rw_data); |
| 604 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 605 | LOG(ERROR) << StringPrintf("Invalid response"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 606 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /******************************************************************************* |
| 610 | ** |
| 611 | ** Function rw_i93_send_to_lower |
| 612 | ** |
| 613 | ** Description Send Request frame to lower layer |
| 614 | ** |
| 615 | ** Returns TRUE if success |
| 616 | ** |
| 617 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 618 | bool rw_i93_send_to_lower(NFC_HDR* p_msg) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 619 | /* store command for retransmitting */ |
| 620 | if (rw_cb.tcb.i93.p_retry_cmd) { |
| 621 | GKI_freebuf(rw_cb.tcb.i93.p_retry_cmd); |
| 622 | rw_cb.tcb.i93.p_retry_cmd = NULL; |
| 623 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 624 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 625 | rw_cb.tcb.i93.p_retry_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 626 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 627 | if (rw_cb.tcb.i93.p_retry_cmd) { |
| 628 | memcpy(rw_cb.tcb.i93.p_retry_cmd, p_msg, |
| 629 | sizeof(NFC_HDR) + p_msg->offset + p_msg->len); |
| 630 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 631 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 632 | if (NFC_SendData(NFC_RF_CONN_ID, p_msg) != NFC_STATUS_OK) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 633 | LOG(ERROR) << StringPrintf("failed"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 634 | return false; |
| 635 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 636 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 637 | nfc_start_quick_timer(&rw_cb.tcb.i93.timer, NFC_TTYPE_RW_I93_RESPONSE, |
| 638 | (RW_I93_TOUT_RESP * QUICK_TIMER_TICKS_PER_SEC) / 1000); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 639 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 640 | return true; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /******************************************************************************* |
| 644 | ** |
| 645 | ** Function rw_i93_send_cmd_inventory |
| 646 | ** |
| 647 | ** Description Send Inventory Request to VICC |
| 648 | ** |
| 649 | ** Returns tNFC_STATUS |
| 650 | ** |
| 651 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 652 | tNFC_STATUS rw_i93_send_cmd_inventory(uint8_t* p_uid, bool including_afi, |
| 653 | uint8_t afi) { |
| 654 | NFC_HDR* p_cmd; |
| 655 | uint8_t *p, flags; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 656 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 657 | DLOG_IF(INFO, nfc_debug_enabled) |
| 658 | << StringPrintf("including_afi:%d, AFI:0x%02X", including_afi, afi); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 659 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 660 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 661 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 662 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 663 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 664 | return NFC_STATUS_NO_BUFFERS; |
| 665 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 666 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 667 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 668 | p_cmd->len = 3; |
| 669 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 670 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 671 | /* Flags */ |
| 672 | flags = (I93_FLAG_SLOT_ONE | I93_FLAG_INVENTORY_SET | |
| 673 | RW_I93_FLAG_SUB_CARRIER | RW_I93_FLAG_DATA_RATE); |
| 674 | if (including_afi) { |
| 675 | flags |= I93_FLAG_AFI_PRESENT; |
| 676 | } |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 677 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 678 | UINT8_TO_STREAM(p, flags); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 679 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 680 | /* Command Code */ |
| 681 | UINT8_TO_STREAM(p, I93_CMD_INVENTORY); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 682 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 683 | if (including_afi) { |
| 684 | /* Parameters */ |
| 685 | UINT8_TO_STREAM(p, afi); /* Optional AFI */ |
| 686 | p_cmd->len++; |
| 687 | } |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 688 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 689 | if (p_uid) { |
| 690 | UINT8_TO_STREAM(p, I93_UID_BYTE_LEN * 8); /* Mask Length */ |
| 691 | ARRAY8_TO_STREAM(p, p_uid); /* UID */ |
| 692 | p_cmd->len += I93_UID_BYTE_LEN; |
| 693 | } else { |
| 694 | UINT8_TO_STREAM(p, 0x00); /* Mask Length */ |
| 695 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 696 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 697 | if (rw_i93_send_to_lower(p_cmd)) { |
| 698 | rw_cb.tcb.i93.sent_cmd = I93_CMD_INVENTORY; |
| 699 | return NFC_STATUS_OK; |
| 700 | } else { |
| 701 | return NFC_STATUS_FAILED; |
| 702 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | /******************************************************************************* |
| 706 | ** |
| 707 | ** Function rw_i93_send_cmd_stay_quiet |
| 708 | ** |
| 709 | ** Description Send Stay Quiet Request to VICC |
| 710 | ** |
| 711 | ** Returns tNFC_STATUS |
| 712 | ** |
| 713 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 714 | tNFC_STATUS rw_i93_send_cmd_stay_quiet(void) { |
| 715 | NFC_HDR* p_cmd; |
| 716 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 717 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 718 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 719 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 720 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 721 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 722 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 723 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 724 | return NFC_STATUS_NO_BUFFERS; |
| 725 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 726 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 727 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 728 | p_cmd->len = 10; |
| 729 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 730 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 731 | /* Flags */ |
| 732 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 733 | RW_I93_FLAG_DATA_RATE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 734 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 735 | /* Command Code */ |
| 736 | UINT8_TO_STREAM(p, I93_CMD_STAY_QUIET); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 737 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 738 | /* Parameters */ |
| 739 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 740 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 741 | if (rw_i93_send_to_lower(p_cmd)) { |
| 742 | rw_cb.tcb.i93.sent_cmd = I93_CMD_STAY_QUIET; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 743 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 744 | /* restart timer for stay quiet */ |
| 745 | nfc_start_quick_timer( |
| 746 | &rw_cb.tcb.i93.timer, NFC_TTYPE_RW_I93_RESPONSE, |
| 747 | (RW_I93_TOUT_STAY_QUIET * QUICK_TIMER_TICKS_PER_SEC) / 1000); |
| 748 | return NFC_STATUS_OK; |
| 749 | } else { |
| 750 | return NFC_STATUS_FAILED; |
| 751 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /******************************************************************************* |
| 755 | ** |
| 756 | ** Function rw_i93_send_cmd_read_single_block |
| 757 | ** |
| 758 | ** Description Send Read Single Block Request to VICC |
| 759 | ** |
| 760 | ** Returns tNFC_STATUS |
| 761 | ** |
| 762 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 763 | tNFC_STATUS rw_i93_send_cmd_read_single_block(uint16_t block_number, |
| 764 | bool read_security) { |
| 765 | NFC_HDR* p_cmd; |
| 766 | uint8_t *p, flags; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 767 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 768 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 769 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 770 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 771 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 772 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 773 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 774 | return NFC_STATUS_NO_BUFFERS; |
| 775 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 776 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 777 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 778 | p_cmd->len = 11; |
| 779 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 780 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 781 | /* Flags */ |
| 782 | flags = |
| 783 | (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | RW_I93_FLAG_DATA_RATE); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 784 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 785 | if (read_security) flags |= I93_FLAG_OPTION_SET; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 786 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 787 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK) |
| 788 | flags |= I93_FLAG_PROT_EXT_YES; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 789 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 790 | UINT8_TO_STREAM(p, flags); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 791 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 792 | /* Command Code */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 793 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 794 | UINT8_TO_STREAM(p, I93_CMD_EXT_READ_SINGLE_BLOCK); |
| 795 | } else { |
| 796 | UINT8_TO_STREAM(p, I93_CMD_READ_SINGLE_BLOCK); |
| 797 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 798 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 799 | /* Parameters */ |
| 800 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 801 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 802 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK || |
| 803 | rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 804 | UINT16_TO_STREAM(p, block_number); /* Block number */ |
| 805 | p_cmd->len++; |
| 806 | } else { |
| 807 | UINT8_TO_STREAM(p, block_number); /* Block number */ |
| 808 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 809 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 810 | if (rw_i93_send_to_lower(p_cmd)) { |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 811 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) |
| 812 | rw_cb.tcb.i93.sent_cmd = I93_CMD_EXT_READ_SINGLE_BLOCK; |
| 813 | else |
| 814 | rw_cb.tcb.i93.sent_cmd = I93_CMD_READ_SINGLE_BLOCK; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 815 | return NFC_STATUS_OK; |
| 816 | } else { |
| 817 | return NFC_STATUS_FAILED; |
| 818 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /******************************************************************************* |
| 822 | ** |
| 823 | ** Function rw_i93_send_cmd_write_single_block |
| 824 | ** |
| 825 | ** Description Send Write Single Block Request to VICC |
| 826 | ** |
| 827 | ** Returns tNFC_STATUS |
| 828 | ** |
| 829 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 830 | tNFC_STATUS rw_i93_send_cmd_write_single_block(uint16_t block_number, |
| 831 | uint8_t* p_data) { |
| 832 | NFC_HDR* p_cmd; |
| 833 | uint8_t *p, flags; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 834 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 835 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 836 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 837 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 838 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 839 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 840 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 841 | return NFC_STATUS_NO_BUFFERS; |
| 842 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 843 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 844 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 845 | p_cmd->len = 11 + rw_cb.tcb.i93.block_size; |
| 846 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 847 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 848 | /* Flags */ |
| 849 | if ((rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_PLUS_INLAY) || |
| 850 | (rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_PLUS_CHIP) || |
| 851 | (rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 852 | (rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY)) { |
| 853 | /* Option must be set for TI tag */ |
| 854 | flags = (I93_FLAG_ADDRESS_SET | I93_FLAG_OPTION_SET | |
| 855 | RW_I93_FLAG_SUB_CARRIER | RW_I93_FLAG_DATA_RATE); |
| 856 | } else { |
| 857 | flags = (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 858 | RW_I93_FLAG_DATA_RATE); |
| 859 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 860 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 861 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK) |
| 862 | flags |= I93_FLAG_PROT_EXT_YES; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 863 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 864 | UINT8_TO_STREAM(p, flags); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 865 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 866 | /* Command Code */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 867 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 868 | UINT8_TO_STREAM(p, I93_CMD_EXT_WRITE_SINGLE_BLOCK); |
| 869 | } else { |
| 870 | UINT8_TO_STREAM(p, I93_CMD_WRITE_SINGLE_BLOCK); |
| 871 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 872 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 873 | /* Parameters */ |
| 874 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 875 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 876 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK || |
| 877 | rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 878 | UINT16_TO_STREAM(p, block_number); /* Block number */ |
| 879 | p_cmd->len++; |
| 880 | } else { |
| 881 | UINT8_TO_STREAM(p, block_number); /* Block number */ |
| 882 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 883 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 884 | /* Data */ |
| 885 | ARRAY_TO_STREAM(p, p_data, rw_cb.tcb.i93.block_size); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 886 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 887 | if (rw_i93_send_to_lower(p_cmd)) { |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 888 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) |
| 889 | rw_cb.tcb.i93.sent_cmd = I93_CMD_EXT_WRITE_SINGLE_BLOCK; |
| 890 | else |
| 891 | rw_cb.tcb.i93.sent_cmd = I93_CMD_WRITE_SINGLE_BLOCK; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 892 | return NFC_STATUS_OK; |
| 893 | } else { |
| 894 | return NFC_STATUS_FAILED; |
| 895 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /******************************************************************************* |
| 899 | ** |
| 900 | ** Function rw_i93_send_cmd_lock_block |
| 901 | ** |
| 902 | ** Description Send Lock Block Request to VICC |
| 903 | ** |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 904 | ** STM LRIS64K, M24LR64-R, M24LR04E-R, M24LR16E-R, M24LR64E-R |
| 905 | ** do not support. |
| 906 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 907 | ** Returns tNFC_STATUS |
| 908 | ** |
| 909 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 910 | tNFC_STATUS rw_i93_send_cmd_lock_block(uint8_t block_number) { |
| 911 | NFC_HDR* p_cmd; |
| 912 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 913 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 914 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 915 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 916 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 917 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 918 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 919 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 920 | return NFC_STATUS_NO_BUFFERS; |
| 921 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 922 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 923 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 924 | p_cmd->len = 11; |
| 925 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 926 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 927 | /* Flags */ |
| 928 | if ((rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_PLUS_INLAY) || |
| 929 | (rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_PLUS_CHIP) || |
| 930 | (rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 931 | (rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY)) { |
| 932 | /* Option must be set for TI tag */ |
| 933 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | I93_FLAG_OPTION_SET | |
| 934 | RW_I93_FLAG_SUB_CARRIER | RW_I93_FLAG_DATA_RATE)); |
| 935 | } else { |
| 936 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 937 | RW_I93_FLAG_DATA_RATE)); |
| 938 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 939 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 940 | /* Command Code */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 941 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 942 | UINT8_TO_STREAM(p, I93_CMD_EXT_LOCK_BLOCK); |
| 943 | } else { |
| 944 | UINT8_TO_STREAM(p, I93_CMD_LOCK_BLOCK); |
| 945 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 946 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 947 | /* Parameters */ |
| 948 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 949 | |
| 950 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 951 | UINT16_TO_STREAM(p, block_number); /* Block number */ |
| 952 | p_cmd->len++; |
| 953 | } else { |
| 954 | UINT8_TO_STREAM(p, block_number); /* Block number */ |
| 955 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 956 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 957 | if (rw_i93_send_to_lower(p_cmd)) { |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 958 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) |
| 959 | rw_cb.tcb.i93.sent_cmd = I93_CMD_EXT_LOCK_BLOCK; |
| 960 | else |
| 961 | rw_cb.tcb.i93.sent_cmd = I93_CMD_LOCK_BLOCK; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 962 | return NFC_STATUS_OK; |
| 963 | } else { |
| 964 | return NFC_STATUS_FAILED; |
| 965 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /******************************************************************************* |
| 969 | ** |
| 970 | ** Function rw_i93_send_cmd_read_multi_blocks |
| 971 | ** |
| 972 | ** Description Send Read Multiple Blocks Request to VICC |
| 973 | ** |
| 974 | ** Returns tNFC_STATUS |
| 975 | ** |
| 976 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 977 | tNFC_STATUS rw_i93_send_cmd_read_multi_blocks(uint16_t first_block_number, |
| 978 | uint16_t number_blocks) { |
| 979 | NFC_HDR* p_cmd; |
| 980 | uint8_t *p, flags; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 981 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 982 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 983 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 984 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 985 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 986 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 987 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 988 | return NFC_STATUS_NO_BUFFERS; |
| 989 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 990 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 991 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 992 | p_cmd->len = 12; |
| 993 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 994 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 995 | /* Flags */ |
| 996 | flags = |
| 997 | (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | RW_I93_FLAG_DATA_RATE); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 998 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 999 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1000 | flags |= I93_FLAG_PROT_EXT_YES; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1001 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1002 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1003 | UINT8_TO_STREAM(p, flags); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1004 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1005 | /* Command Code */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1006 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 1007 | UINT8_TO_STREAM(p, I93_CMD_EXT_READ_MULTI_BLOCK); |
| 1008 | } else { |
| 1009 | UINT8_TO_STREAM(p, I93_CMD_READ_MULTI_BLOCK); |
| 1010 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1011 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1012 | /* Parameters */ |
| 1013 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1014 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1015 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK || |
| 1016 | rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1017 | UINT16_TO_STREAM(p, first_block_number); /* First block number */ |
| 1018 | p_cmd->len++; |
| 1019 | } else { |
| 1020 | UINT8_TO_STREAM(p, first_block_number); /* First block number */ |
| 1021 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1022 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1023 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 1024 | UINT16_TO_STREAM( |
| 1025 | p, number_blocks - 1); /* Number of blocks, 0x00 to read one block */ |
| 1026 | p_cmd->len++; |
| 1027 | } else { |
| 1028 | UINT8_TO_STREAM( |
| 1029 | p, number_blocks - 1); /* Number of blocks, 0x00 to read one block */ |
| 1030 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1031 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1032 | if (rw_i93_send_to_lower(p_cmd)) { |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1033 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) |
| 1034 | rw_cb.tcb.i93.sent_cmd = I93_CMD_EXT_READ_MULTI_BLOCK; |
| 1035 | else |
| 1036 | rw_cb.tcb.i93.sent_cmd = I93_CMD_READ_MULTI_BLOCK; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1037 | return NFC_STATUS_OK; |
| 1038 | } else { |
| 1039 | return NFC_STATUS_FAILED; |
| 1040 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /******************************************************************************* |
| 1044 | ** |
| 1045 | ** Function rw_i93_send_cmd_write_multi_blocks |
| 1046 | ** |
| 1047 | ** Description Send Write Multiple Blocks Request to VICC |
| 1048 | ** |
| 1049 | ** Returns tNFC_STATUS |
| 1050 | ** |
| 1051 | *******************************************************************************/ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1052 | tNFC_STATUS rw_i93_send_cmd_write_multi_blocks(uint16_t first_block_number, |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1053 | uint16_t number_blocks, |
| 1054 | uint8_t* p_data) { |
| 1055 | NFC_HDR* p_cmd; |
| 1056 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1057 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1058 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1059 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1060 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1061 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1062 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1063 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1064 | return NFC_STATUS_NO_BUFFERS; |
| 1065 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1066 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1067 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1068 | p_cmd->len = 12 + number_blocks * rw_cb.tcb.i93.block_size; |
| 1069 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1070 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1071 | /* Flags */ |
| 1072 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1073 | RW_I93_FLAG_DATA_RATE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1074 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1075 | /* Command Code */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1076 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 1077 | INT8_TO_STREAM(p, I93_CMD_EXT_WRITE_MULTI_BLOCK); |
| 1078 | } else { |
| 1079 | UINT8_TO_STREAM(p, I93_CMD_WRITE_MULTI_BLOCK); |
| 1080 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1081 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1082 | /* Parameters */ |
| 1083 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1084 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 1085 | UINT16_TO_STREAM(p, first_block_number); /* Block number */ |
| 1086 | UINT16_TO_STREAM( |
| 1087 | p, number_blocks - 1); /* Number of blocks, 0x00 to read one block */ |
| 1088 | p_cmd->len += 2; |
| 1089 | } else { |
| 1090 | UINT8_TO_STREAM(p, first_block_number); /* Block number */ |
| 1091 | UINT8_TO_STREAM( |
| 1092 | p, number_blocks - 1); /* Number of blocks, 0x00 to read one block */ |
| 1093 | } |
| 1094 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1095 | UINT8_TO_STREAM( |
| 1096 | p, number_blocks - 1); /* Number of blocks, 0x00 to read one block */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1097 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1098 | /* Data */ |
| 1099 | ARRAY_TO_STREAM(p, p_data, number_blocks * rw_cb.tcb.i93.block_size); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1100 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1101 | if (rw_i93_send_to_lower(p_cmd)) { |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1102 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) |
| 1103 | rw_cb.tcb.i93.sent_cmd = I93_CMD_EXT_WRITE_MULTI_BLOCK; |
| 1104 | else |
| 1105 | rw_cb.tcb.i93.sent_cmd = I93_CMD_WRITE_MULTI_BLOCK; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1106 | return NFC_STATUS_OK; |
| 1107 | } else { |
| 1108 | return NFC_STATUS_FAILED; |
| 1109 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | /******************************************************************************* |
| 1113 | ** |
| 1114 | ** Function rw_i93_send_cmd_select |
| 1115 | ** |
| 1116 | ** Description Send Select Request to VICC |
| 1117 | ** |
| 1118 | ** Returns tNFC_STATUS |
| 1119 | ** |
| 1120 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1121 | tNFC_STATUS rw_i93_send_cmd_select(uint8_t* p_uid) { |
| 1122 | NFC_HDR* p_cmd; |
| 1123 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1124 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1125 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1126 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1127 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1128 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1129 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1130 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1131 | return NFC_STATUS_NO_BUFFERS; |
| 1132 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1133 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1134 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1135 | p_cmd->len = 10; |
| 1136 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1137 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1138 | /* Flags */ |
| 1139 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1140 | RW_I93_FLAG_DATA_RATE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1141 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1142 | /* Command Code */ |
| 1143 | UINT8_TO_STREAM(p, I93_CMD_SELECT); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1144 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1145 | /* Parameters */ |
| 1146 | ARRAY8_TO_STREAM(p, p_uid); /* UID */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1147 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1148 | if (rw_i93_send_to_lower(p_cmd)) { |
| 1149 | rw_cb.tcb.i93.sent_cmd = I93_CMD_SELECT; |
| 1150 | return NFC_STATUS_OK; |
| 1151 | } else { |
| 1152 | return NFC_STATUS_FAILED; |
| 1153 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /******************************************************************************* |
| 1157 | ** |
| 1158 | ** Function rw_i93_send_cmd_reset_to_ready |
| 1159 | ** |
| 1160 | ** Description Send Reset to Ready Request to VICC |
| 1161 | ** |
| 1162 | ** Returns tNFC_STATUS |
| 1163 | ** |
| 1164 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1165 | tNFC_STATUS rw_i93_send_cmd_reset_to_ready(void) { |
| 1166 | NFC_HDR* p_cmd; |
| 1167 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1168 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1169 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1170 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1171 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1172 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1173 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1174 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1175 | return NFC_STATUS_NO_BUFFERS; |
| 1176 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1177 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1178 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1179 | p_cmd->len = 10; |
| 1180 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1181 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1182 | /* Flags */ |
| 1183 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1184 | RW_I93_FLAG_DATA_RATE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1185 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1186 | /* Command Code */ |
| 1187 | UINT8_TO_STREAM(p, I93_CMD_RESET_TO_READY); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1188 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1189 | /* Parameters */ |
| 1190 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1191 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1192 | if (rw_i93_send_to_lower(p_cmd)) { |
| 1193 | rw_cb.tcb.i93.sent_cmd = I93_CMD_RESET_TO_READY; |
| 1194 | return NFC_STATUS_OK; |
| 1195 | } else { |
| 1196 | return NFC_STATUS_FAILED; |
| 1197 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | /******************************************************************************* |
| 1201 | ** |
| 1202 | ** Function rw_i93_send_cmd_write_afi |
| 1203 | ** |
| 1204 | ** Description Send Write AFI Request to VICC |
| 1205 | ** |
| 1206 | ** Returns tNFC_STATUS |
| 1207 | ** |
| 1208 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1209 | tNFC_STATUS rw_i93_send_cmd_write_afi(uint8_t afi) { |
| 1210 | NFC_HDR* p_cmd; |
| 1211 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1212 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1213 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1214 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1215 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1216 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1217 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1218 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1219 | return NFC_STATUS_NO_BUFFERS; |
| 1220 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1221 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1222 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1223 | p_cmd->len = 11; |
| 1224 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1225 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1226 | /* Flags */ |
| 1227 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1228 | RW_I93_FLAG_DATA_RATE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1229 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1230 | /* Command Code */ |
| 1231 | UINT8_TO_STREAM(p, I93_CMD_WRITE_AFI); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1232 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1233 | /* Parameters */ |
| 1234 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
| 1235 | UINT8_TO_STREAM(p, afi); /* AFI */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1236 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1237 | if (rw_i93_send_to_lower(p_cmd)) { |
| 1238 | rw_cb.tcb.i93.sent_cmd = I93_CMD_WRITE_AFI; |
| 1239 | return NFC_STATUS_OK; |
| 1240 | } else { |
| 1241 | return NFC_STATUS_FAILED; |
| 1242 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | /******************************************************************************* |
| 1246 | ** |
| 1247 | ** Function rw_i93_send_cmd_lock_afi |
| 1248 | ** |
| 1249 | ** Description Send Lock AFI Request to VICC |
| 1250 | ** |
| 1251 | ** Returns tNFC_STATUS |
| 1252 | ** |
| 1253 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1254 | tNFC_STATUS rw_i93_send_cmd_lock_afi(void) { |
| 1255 | NFC_HDR* p_cmd; |
| 1256 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1257 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1258 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1259 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1260 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1261 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1262 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1263 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1264 | return NFC_STATUS_NO_BUFFERS; |
| 1265 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1266 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1267 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1268 | p_cmd->len = 10; |
| 1269 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1270 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1271 | /* Flags */ |
| 1272 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1273 | RW_I93_FLAG_DATA_RATE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1274 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1275 | /* Command Code */ |
| 1276 | UINT8_TO_STREAM(p, I93_CMD_LOCK_AFI); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1277 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1278 | /* Parameters */ |
| 1279 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1280 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1281 | if (rw_i93_send_to_lower(p_cmd)) { |
| 1282 | rw_cb.tcb.i93.sent_cmd = I93_CMD_LOCK_AFI; |
| 1283 | return NFC_STATUS_OK; |
| 1284 | } else { |
| 1285 | return NFC_STATUS_FAILED; |
| 1286 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | /******************************************************************************* |
| 1290 | ** |
| 1291 | ** Function rw_i93_send_cmd_write_dsfid |
| 1292 | ** |
| 1293 | ** Description Send Write DSFID Request to VICC |
| 1294 | ** |
| 1295 | ** Returns tNFC_STATUS |
| 1296 | ** |
| 1297 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1298 | tNFC_STATUS rw_i93_send_cmd_write_dsfid(uint8_t dsfid) { |
| 1299 | NFC_HDR* p_cmd; |
| 1300 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1301 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1302 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1303 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1304 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1305 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1306 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1307 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1308 | return NFC_STATUS_NO_BUFFERS; |
| 1309 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1310 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1311 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1312 | p_cmd->len = 11; |
| 1313 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1314 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1315 | /* Flags */ |
| 1316 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1317 | RW_I93_FLAG_DATA_RATE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1318 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1319 | /* Command Code */ |
| 1320 | UINT8_TO_STREAM(p, I93_CMD_WRITE_DSFID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1321 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1322 | /* Parameters */ |
| 1323 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
| 1324 | UINT8_TO_STREAM(p, dsfid); /* DSFID */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1325 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1326 | if (rw_i93_send_to_lower(p_cmd)) { |
| 1327 | rw_cb.tcb.i93.sent_cmd = I93_CMD_WRITE_DSFID; |
| 1328 | return NFC_STATUS_OK; |
| 1329 | } else { |
| 1330 | return NFC_STATUS_FAILED; |
| 1331 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | /******************************************************************************* |
| 1335 | ** |
| 1336 | ** Function rw_i93_send_cmd_lock_dsfid |
| 1337 | ** |
| 1338 | ** Description Send Lock DSFID Request to VICC |
| 1339 | ** |
| 1340 | ** Returns tNFC_STATUS |
| 1341 | ** |
| 1342 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1343 | tNFC_STATUS rw_i93_send_cmd_lock_dsfid(void) { |
| 1344 | NFC_HDR* p_cmd; |
| 1345 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1346 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1347 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1348 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1349 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1350 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1351 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1352 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1353 | return NFC_STATUS_NO_BUFFERS; |
| 1354 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1355 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1356 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1357 | p_cmd->len = 10; |
| 1358 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1359 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1360 | /* Flags */ |
| 1361 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1362 | RW_I93_FLAG_DATA_RATE)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1363 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1364 | /* Command Code */ |
| 1365 | UINT8_TO_STREAM(p, I93_CMD_LOCK_DSFID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1366 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1367 | /* Parameters */ |
| 1368 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1369 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1370 | if (rw_i93_send_to_lower(p_cmd)) { |
| 1371 | rw_cb.tcb.i93.sent_cmd = I93_CMD_LOCK_DSFID; |
| 1372 | return NFC_STATUS_OK; |
| 1373 | } else { |
| 1374 | return NFC_STATUS_FAILED; |
| 1375 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /******************************************************************************* |
| 1379 | ** |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1380 | ** Function rw_i93_send_cmd_get_ext_sys_info |
| 1381 | ** |
| 1382 | ** Description Send Get Extended System Information Request to VICC |
| 1383 | ** |
| 1384 | ** Returns tNFC_STATUS |
| 1385 | ** |
| 1386 | *******************************************************************************/ |
| 1387 | tNFC_STATUS rw_i93_send_cmd_get_ext_sys_info(uint8_t* p_uid) { |
| 1388 | NFC_HDR* p_cmd; |
| 1389 | uint8_t* p; |
| 1390 | |
| 1391 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
| 1392 | |
| 1393 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
| 1394 | |
| 1395 | if (!p_cmd) { |
| 1396 | DLOG_IF(INFO, nfc_debug_enabled) << __func__ << "Cannot allocate buffer"; |
| 1397 | return NFC_STATUS_NO_BUFFERS; |
| 1398 | } |
| 1399 | |
| 1400 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1401 | p_cmd->len = 11; |
| 1402 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
| 1403 | |
| 1404 | /* Flags */ |
| 1405 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1406 | RW_I93_FLAG_DATA_RATE)); |
| 1407 | |
| 1408 | /* Command Code */ |
| 1409 | UINT8_TO_STREAM(p, I93_CMD_EXT_GET_SYS_INFO); |
| 1410 | |
| 1411 | /* Parameters request field */ |
| 1412 | UINT8_TO_STREAM(p, |
| 1413 | (I93_INFO_FLAG_MOI | I93_INFO_FLAG_DSFID | I93_INFO_FLAG_AFI | |
| 1414 | I93_INFO_FLAG_MEM_SIZE | I93_INFO_FLAG_IC_REF)); |
| 1415 | |
| 1416 | /* Parameters */ |
| 1417 | if (p_uid) { |
| 1418 | ARRAY8_TO_STREAM(p, p_uid); /* UID */ |
| 1419 | } else { |
| 1420 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
| 1421 | } |
| 1422 | |
| 1423 | if (rw_i93_send_to_lower(p_cmd)) { |
| 1424 | rw_cb.tcb.i93.sent_cmd = I93_CMD_EXT_GET_SYS_INFO; |
| 1425 | return NFC_STATUS_OK; |
| 1426 | } else { |
| 1427 | return NFC_STATUS_FAILED; |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | /******************************************************************************* |
| 1432 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1433 | ** Function rw_i93_send_cmd_get_sys_info |
| 1434 | ** |
| 1435 | ** Description Send Get System Information Request to VICC |
| 1436 | ** |
| 1437 | ** Returns tNFC_STATUS |
| 1438 | ** |
| 1439 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1440 | tNFC_STATUS rw_i93_send_cmd_get_sys_info(uint8_t* p_uid, uint8_t extra_flags) { |
| 1441 | NFC_HDR* p_cmd; |
| 1442 | uint8_t* p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1443 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1444 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1445 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1446 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1447 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1448 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1449 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1450 | return NFC_STATUS_NO_BUFFERS; |
| 1451 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1452 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1453 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1454 | p_cmd->len = 10; |
| 1455 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1456 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1457 | /* Flags */ |
| 1458 | UINT8_TO_STREAM(p, (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | |
| 1459 | RW_I93_FLAG_DATA_RATE | extra_flags)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1460 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1461 | /* Command Code */ |
| 1462 | UINT8_TO_STREAM(p, I93_CMD_GET_SYS_INFO); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1463 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1464 | /* Parameters */ |
| 1465 | if (p_uid) { |
| 1466 | ARRAY8_TO_STREAM(p, p_uid); /* UID */ |
| 1467 | } else { |
| 1468 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
| 1469 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1470 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1471 | if (rw_i93_send_to_lower(p_cmd)) { |
| 1472 | rw_cb.tcb.i93.sent_cmd = I93_CMD_GET_SYS_INFO; |
| 1473 | return NFC_STATUS_OK; |
| 1474 | } else { |
| 1475 | return NFC_STATUS_FAILED; |
| 1476 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /******************************************************************************* |
| 1480 | ** |
| 1481 | ** Function rw_i93_send_cmd_get_multi_block_sec |
| 1482 | ** |
| 1483 | ** Description Send Get Multiple Block Security Status Request to VICC |
| 1484 | ** |
| 1485 | ** Returns tNFC_STATUS |
| 1486 | ** |
| 1487 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1488 | tNFC_STATUS rw_i93_send_cmd_get_multi_block_sec(uint16_t first_block_number, |
| 1489 | uint16_t number_blocks) { |
| 1490 | NFC_HDR* p_cmd; |
| 1491 | uint8_t *p, flags; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1492 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1493 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1494 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1495 | p_cmd = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1496 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1497 | if (!p_cmd) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1498 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1499 | return NFC_STATUS_NO_BUFFERS; |
| 1500 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1501 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1502 | p_cmd->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 1503 | p_cmd->len = 12; |
| 1504 | p = (uint8_t*)(p_cmd + 1) + p_cmd->offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1505 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1506 | /* Flags */ |
| 1507 | flags = |
| 1508 | (I93_FLAG_ADDRESS_SET | RW_I93_FLAG_SUB_CARRIER | RW_I93_FLAG_DATA_RATE); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1509 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1510 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK) |
| 1511 | flags |= I93_FLAG_PROT_EXT_YES; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1512 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1513 | UINT8_TO_STREAM(p, flags); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1514 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1515 | /* Command Code */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1516 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
| 1517 | UINT8_TO_STREAM(p, I93_CMD_EXT_GET_MULTI_BLK_SEC); |
| 1518 | } else { |
| 1519 | UINT8_TO_STREAM(p, I93_CMD_GET_MULTI_BLK_SEC); |
| 1520 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1521 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1522 | /* Parameters */ |
| 1523 | ARRAY8_TO_STREAM(p, rw_cb.tcb.i93.uid); /* UID */ |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1524 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1525 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_16BIT_NUM_BLOCK || |
| 1526 | rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1527 | UINT16_TO_STREAM(p, first_block_number); /* First block number */ |
| 1528 | UINT16_TO_STREAM( |
| 1529 | p, number_blocks - 1); /* Number of blocks, 0x00 to read one block */ |
| 1530 | p_cmd->len += 2; |
| 1531 | } else { |
| 1532 | UINT8_TO_STREAM(p, first_block_number); /* First block number */ |
| 1533 | UINT8_TO_STREAM( |
| 1534 | p, number_blocks - 1); /* Number of blocks, 0x00 to read one block */ |
| 1535 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1536 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1537 | if (rw_i93_send_to_lower(p_cmd)) { |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1538 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_EXT_COMMANDS) |
| 1539 | rw_cb.tcb.i93.sent_cmd = I93_CMD_EXT_GET_MULTI_BLK_SEC; |
| 1540 | else |
| 1541 | rw_cb.tcb.i93.sent_cmd = I93_CMD_GET_MULTI_BLK_SEC; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1542 | return NFC_STATUS_OK; |
| 1543 | } else { |
| 1544 | return NFC_STATUS_FAILED; |
| 1545 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /******************************************************************************* |
| 1549 | ** |
| 1550 | ** Function rw_i93_get_next_blocks |
| 1551 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 1552 | ** Description Read as many blocks as possible (up to |
| 1553 | ** RW_I93_READ_MULTI_BLOCK_SIZE) |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1554 | ** |
| 1555 | ** Returns tNFC_STATUS |
| 1556 | ** |
| 1557 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1558 | tNFC_STATUS rw_i93_get_next_blocks(uint16_t offset) { |
| 1559 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 1560 | uint16_t first_block; |
| 1561 | uint16_t num_block; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1562 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1563 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1564 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1565 | first_block = offset / p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1566 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1567 | /* more blocks, more efficent but more error rate */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1568 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1569 | if (p_i93->intl_flags & RW_I93_FLAG_READ_MULTI_BLOCK) { |
| 1570 | num_block = RW_I93_READ_MULTI_BLOCK_SIZE / p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1571 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1572 | if (num_block + first_block > p_i93->num_block) |
| 1573 | num_block = p_i93->num_block - first_block; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1574 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1575 | if (p_i93->uid[1] == I93_UID_IC_MFG_CODE_STM) { |
| 1576 | /* LRIS64K, M24LR64-R, M24LR04E-R, M24LR16E-R, M24LR64E-R requires |
| 1577 | ** - The max number of blocks is 32 and they are all located in the |
| 1578 | ** same sector. |
| 1579 | ** - The sector is 32 blocks of 4 bytes. |
| 1580 | */ |
| 1581 | if ((p_i93->product_version == RW_I93_STM_LRIS64K) || |
| 1582 | (p_i93->product_version == RW_I93_STM_M24LR64_R) || |
| 1583 | (p_i93->product_version == RW_I93_STM_M24LR04E_R) || |
| 1584 | (p_i93->product_version == RW_I93_STM_M24LR16E_R) || |
| 1585 | (p_i93->product_version == RW_I93_STM_M24LR64E_R)) { |
| 1586 | if (num_block > I93_STM_MAX_BLOCKS_PER_READ) |
| 1587 | num_block = I93_STM_MAX_BLOCKS_PER_READ; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1588 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1589 | if ((first_block / I93_STM_BLOCKS_PER_SECTOR) != |
| 1590 | ((first_block + num_block - 1) / I93_STM_BLOCKS_PER_SECTOR)) { |
| 1591 | num_block = I93_STM_BLOCKS_PER_SECTOR - |
| 1592 | (first_block % I93_STM_BLOCKS_PER_SECTOR); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1593 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1594 | } |
| 1595 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1596 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1597 | return rw_i93_send_cmd_read_multi_blocks(first_block, num_block); |
| 1598 | } else { |
| 1599 | return rw_i93_send_cmd_read_single_block(first_block, false); |
| 1600 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | /******************************************************************************* |
| 1604 | ** |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1605 | ** Function rw_i93_get_next_block_sec |
| 1606 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 1607 | ** Description Get as many security of blocks as possible from |
| 1608 | ** p_i93->rw_offset (up to RW_I93_GET_MULTI_BLOCK_SEC_SIZE) |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1609 | ** |
| 1610 | ** Returns tNFC_STATUS |
| 1611 | ** |
| 1612 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1613 | tNFC_STATUS rw_i93_get_next_block_sec(void) { |
| 1614 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 1615 | uint16_t num_blocks; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1616 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1617 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1618 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1619 | if (p_i93->num_block <= p_i93->rw_offset) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1620 | LOG(ERROR) << StringPrintf( |
| 1621 | "rw_offset(0x%x) must be less than num_block(0x%x)", p_i93->rw_offset, |
| 1622 | p_i93->num_block); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1623 | return NFC_STATUS_FAILED; |
| 1624 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1625 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1626 | num_blocks = p_i93->num_block - p_i93->rw_offset; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1627 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1628 | if (num_blocks > RW_I93_GET_MULTI_BLOCK_SEC_SIZE) |
| 1629 | num_blocks = RW_I93_GET_MULTI_BLOCK_SEC_SIZE; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1630 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1631 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1632 | << __func__ << std::hex << rw_cb.tcb.i93.intl_flags; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1633 | return rw_i93_send_cmd_get_multi_block_sec(p_i93->rw_offset, num_blocks); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | /******************************************************************************* |
| 1637 | ** |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1638 | ** Function rw_i93_sm_detect_ndef |
| 1639 | ** |
| 1640 | ** Description Process NDEF detection procedure |
| 1641 | ** |
| 1642 | ** 1. Get UID if not having yet |
| 1643 | ** 2. Get System Info if not having yet |
| 1644 | ** 3. Read first block for CC |
| 1645 | ** 4. Search NDEF Type and length |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 1646 | ** 5. Get block status to get max NDEF size and read-only |
| 1647 | ** status |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1648 | ** |
| 1649 | ** Returns void |
| 1650 | ** |
| 1651 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1652 | void rw_i93_sm_detect_ndef(NFC_HDR* p_resp) { |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 1653 | uint8_t *p = (uint8_t*)(p_resp + 1) + p_resp->offset, *p_uid; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1654 | uint8_t flags, u8 = 0, cc[4]; |
| 1655 | uint16_t length = p_resp->len, xx, block, first_block, last_block, num_blocks; |
| 1656 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 1657 | tRW_DATA rw_data; |
| 1658 | tNFC_STATUS status = NFC_STATUS_FAILED; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1659 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1660 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1661 | "sub_state:%s (0x%x)", |
| 1662 | rw_i93_get_sub_state_name(p_i93->sub_state).c_str(), p_i93->sub_state); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1663 | |
Ruchi Kandoi | 6e267b3 | 2019-01-24 13:39:18 -0800 | [diff] [blame] | 1664 | if (length == 0) { |
| 1665 | android_errorWriteLog(0x534e4554, "121260197"); |
| 1666 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1667 | return; |
| 1668 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1669 | STREAM_TO_UINT8(flags, p); |
| 1670 | length--; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1671 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1672 | if (flags & I93_FLAG_ERROR_DETECTED) { |
| 1673 | if ((length) && (rw_i93_check_sys_info_prot_ext(*p))) { |
| 1674 | /* getting system info with protocol extension flag */ |
| 1675 | /* This STM tag supports more than 2040 bytes */ |
| 1676 | p_i93->intl_flags |= RW_I93_FLAG_16BIT_NUM_BLOCK; |
| 1677 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1678 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1679 | << StringPrintf("Got error flags (0x%02x)", flags); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1680 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1681 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1682 | return; |
| 1683 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1684 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1685 | switch (p_i93->sub_state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1686 | case RW_I93_SUBSTATE_WAIT_UID: |
| 1687 | |
Ruchi Kandoi | 6e267b3 | 2019-01-24 13:39:18 -0800 | [diff] [blame] | 1688 | if (length < (I93_UID_BYTE_LEN + 1)) { |
| 1689 | android_errorWriteLog(0x534e4554, "121260197"); |
| 1690 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1691 | return; |
| 1692 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1693 | STREAM_TO_UINT8(u8, p); /* DSFID */ |
| 1694 | p_uid = p_i93->uid; |
| 1695 | STREAM_TO_ARRAY8(p_uid, p); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1696 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1697 | if (u8 != I93_DFS_UNSUPPORTED) { |
| 1698 | /* if Data Storage Format is unknown */ |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1699 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1700 | << StringPrintf("Got unknown DSFID (0x%02x)", u8); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1701 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1702 | } else { |
| 1703 | /* get system information to get memory size */ |
| 1704 | if (rw_i93_send_cmd_get_sys_info(NULL, I93_FLAG_PROT_EXT_NO) == |
| 1705 | NFC_STATUS_OK) { |
| 1706 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_SYS_INFO; |
| 1707 | } else { |
| 1708 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1709 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1710 | } |
| 1711 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1712 | |
| 1713 | case RW_I93_SUBSTATE_WAIT_SYS_INFO: |
| 1714 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1715 | p_i93->block_size = 0; |
| 1716 | p_i93->num_block = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1717 | |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 1718 | if (!rw_i93_process_sys_info(p, length)) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1719 | /* retrying with protocol extension flag */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1720 | break; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | if ((p_i93->block_size == 0) || (p_i93->num_block == 0)) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1724 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1725 | << StringPrintf("Unable to get tag memory size"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1726 | rw_i93_handle_error(status); |
| 1727 | } else { |
| 1728 | /* read CC in the first block */ |
| 1729 | if (rw_i93_send_cmd_read_single_block(0x0000, false) == NFC_STATUS_OK) { |
| 1730 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_CC; |
| 1731 | } else { |
| 1732 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1733 | } |
| 1734 | } |
| 1735 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1736 | |
| 1737 | case RW_I93_SUBSTATE_WAIT_CC: |
| 1738 | |
George Chang | ec0e233 | 2019-08-16 20:37:23 +0800 | [diff] [blame] | 1739 | if (length < RW_I93_CC_SIZE) { |
| 1740 | android_errorWriteLog(0x534e4554, "139188579"); |
| 1741 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1742 | return; |
| 1743 | } |
| 1744 | |
| 1745 | /* assume block size is more than RW_I93_CC_SIZE 4 */ |
| 1746 | STREAM_TO_ARRAY(cc, p, RW_I93_CC_SIZE); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1747 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1748 | status = NFC_STATUS_FAILED; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1749 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1750 | /* |
| 1751 | ** Capability Container (CC) |
| 1752 | ** |
| 1753 | ** CC[0] : magic number (0xE1) |
| 1754 | ** CC[1] : Bit 7-6:Major version number |
| 1755 | ** : Bit 5-4:Minor version number |
| 1756 | ** : Bit 3-2:Read access condition (00b: read access granted |
| 1757 | ** without any security) |
| 1758 | ** : Bit 1-0:Write access condition (00b: write access granted |
| 1759 | ** without any security) |
| 1760 | ** CC[2] : Memory size in 8 bytes (Ex. 0x04 is 32 bytes) [STM, set to |
| 1761 | ** 0xFF if more than 2040bytes] |
| 1762 | ** CC[3] : Bit 0:Read multiple blocks is supported [NXP, STM] |
| 1763 | ** : Bit 1:Inventory page read is supported [NXP] |
| 1764 | ** : Bit 2:More than 2040 bytes are supported [STM] |
| 1765 | */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1766 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1767 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 1768 | "cc: 0x%02X 0x%02X 0x%02X 0x%02X", cc[0], cc[1], cc[2], cc[3]); |
| 1769 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1770 | << StringPrintf("Total blocks:0x%04X, Block size:0x%02X", |
| 1771 | p_i93->num_block, p_i93->block_size); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1772 | |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1773 | if ((cc[0] == I93_ICODE_CC_MAGIC_NUMER_E1) || |
| 1774 | (cc[0] == I93_ICODE_CC_MAGIC_NUMER_E2)) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1775 | if ((cc[1] & I93_ICODE_CC_READ_ACCESS_MASK) == |
| 1776 | I93_ICODE_CC_READ_ACCESS_GRANTED) { |
| 1777 | if ((cc[1] & I93_ICODE_CC_WRITE_ACCESS_MASK) != |
| 1778 | I93_ICODE_CC_WRITE_ACCESS_GRANTED) { |
| 1779 | /* read-only or password required to write */ |
| 1780 | p_i93->intl_flags |= RW_I93_FLAG_READ_ONLY; |
| 1781 | } |
| 1782 | if (cc[3] & I93_ICODE_CC_MBREAD_MASK) { |
| 1783 | /* tag supports read multi blocks command */ |
| 1784 | p_i93->intl_flags |= RW_I93_FLAG_READ_MULTI_BLOCK; |
| 1785 | } |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 1786 | if (cc[0] == I93_ICODE_CC_MAGIC_NUMER_E2) { |
| 1787 | p_i93->intl_flags |= RW_I93_FLAG_EXT_COMMANDS; |
| 1788 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1789 | status = NFC_STATUS_OK; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1790 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1791 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1792 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1793 | if (status == NFC_STATUS_OK) { |
| 1794 | /* seach NDEF TLV from offset 4 when CC file coded on 4 bytes NFC Forum |
| 1795 | */ |
| 1796 | if (cc[2] != 0) |
| 1797 | p_i93->rw_offset = 4; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1798 | else |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1799 | p_i93->rw_offset = 8; |
| 1800 | |
| 1801 | if (rw_i93_get_next_blocks(p_i93->rw_offset) == NFC_STATUS_OK) { |
| 1802 | p_i93->sub_state = RW_I93_SUBSTATE_SEARCH_NDEF_TLV; |
| 1803 | p_i93->tlv_detect_state = RW_I93_TLV_DETECT_STATE_TYPE; |
| 1804 | } else { |
| 1805 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1806 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1807 | } else { |
| 1808 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1809 | } |
| 1810 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1811 | |
| 1812 | case RW_I93_SUBSTATE_SEARCH_NDEF_TLV: |
| 1813 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1814 | /* search TLV within read blocks */ |
| 1815 | for (xx = 0; xx < length; xx++) { |
| 1816 | /* if looking for type */ |
| 1817 | if (p_i93->tlv_detect_state == RW_I93_TLV_DETECT_STATE_TYPE) { |
| 1818 | if (*(p + xx) == I93_ICODE_TLV_TYPE_NULL) { |
| 1819 | continue; |
| 1820 | } else if ((*(p + xx) == I93_ICODE_TLV_TYPE_NDEF) || |
| 1821 | (*(p + xx) == I93_ICODE_TLV_TYPE_PROP)) { |
| 1822 | /* store found type and get length field */ |
| 1823 | p_i93->tlv_type = *(p + xx); |
| 1824 | p_i93->ndef_tlv_start_offset = p_i93->rw_offset + xx; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1825 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1826 | p_i93->tlv_detect_state = RW_I93_TLV_DETECT_STATE_LENGTH_1; |
| 1827 | } else if (*(p + xx) == I93_ICODE_TLV_TYPE_TERM) { |
| 1828 | /* no NDEF TLV found */ |
| 1829 | p_i93->tlv_type = I93_ICODE_TLV_TYPE_TERM; |
| 1830 | break; |
| 1831 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 1832 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1833 | << StringPrintf("Invalid type: 0x%02x", *(p + xx)); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1834 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1835 | return; |
| 1836 | } |
| 1837 | } else if (p_i93->tlv_detect_state == |
| 1838 | RW_I93_TLV_DETECT_STATE_LENGTH_1) { |
| 1839 | /* if 3 bytes length field */ |
| 1840 | if (*(p + xx) == 0xFF) { |
| 1841 | /* need 2 more bytes for length field */ |
| 1842 | p_i93->tlv_detect_state = RW_I93_TLV_DETECT_STATE_LENGTH_2; |
| 1843 | } else { |
| 1844 | p_i93->tlv_length = *(p + xx); |
| 1845 | p_i93->tlv_detect_state = RW_I93_TLV_DETECT_STATE_VALUE; |
| 1846 | |
| 1847 | if (p_i93->tlv_type == I93_ICODE_TLV_TYPE_NDEF) { |
| 1848 | p_i93->ndef_tlv_last_offset = |
| 1849 | p_i93->ndef_tlv_start_offset + 1 + p_i93->tlv_length; |
| 1850 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1851 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1852 | } |
| 1853 | } else if (p_i93->tlv_detect_state == |
| 1854 | RW_I93_TLV_DETECT_STATE_LENGTH_2) { |
| 1855 | /* the second byte of 3 bytes length field */ |
| 1856 | p_i93->tlv_length = *(p + xx); |
| 1857 | p_i93->tlv_detect_state = RW_I93_TLV_DETECT_STATE_LENGTH_3; |
| 1858 | } else if (p_i93->tlv_detect_state == |
| 1859 | RW_I93_TLV_DETECT_STATE_LENGTH_3) { |
| 1860 | /* the last byte of 3 bytes length field */ |
| 1861 | p_i93->tlv_length = (p_i93->tlv_length << 8) + *(p + xx); |
| 1862 | p_i93->tlv_detect_state = RW_I93_TLV_DETECT_STATE_VALUE; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1863 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1864 | if (p_i93->tlv_type == I93_ICODE_TLV_TYPE_NDEF) { |
| 1865 | p_i93->ndef_tlv_last_offset = |
| 1866 | p_i93->ndef_tlv_start_offset + 3 + p_i93->tlv_length; |
| 1867 | break; |
| 1868 | } |
| 1869 | } else if (p_i93->tlv_detect_state == RW_I93_TLV_DETECT_STATE_VALUE) { |
| 1870 | /* this is other than NDEF TLV */ |
| 1871 | if (p_i93->tlv_length <= length - xx) { |
| 1872 | /* skip value field */ |
| 1873 | xx += (uint8_t)p_i93->tlv_length; |
| 1874 | p_i93->tlv_detect_state = RW_I93_TLV_DETECT_STATE_TYPE; |
| 1875 | } else { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1876 | /* read more data */ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1877 | p_i93->tlv_length -= (length - xx); |
| 1878 | break; |
| 1879 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1880 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | /* found NDEF TLV and read length field */ |
| 1884 | if ((p_i93->tlv_type == I93_ICODE_TLV_TYPE_NDEF) && |
| 1885 | (p_i93->tlv_detect_state == RW_I93_TLV_DETECT_STATE_VALUE)) { |
| 1886 | p_i93->ndef_length = p_i93->tlv_length; |
| 1887 | |
| 1888 | /* get lock status to see if read-only */ |
| 1889 | if ((p_i93->product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 1890 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY) || |
| 1891 | ((p_i93->uid[1] == I93_UID_IC_MFG_CODE_NXP) && |
| 1892 | (p_i93->ic_reference & I93_ICODE_IC_REF_MBREAD_MASK))) { |
| 1893 | /* these doesn't support GetMultiBlockSecurityStatus */ |
| 1894 | |
| 1895 | p_i93->rw_offset = p_i93->ndef_tlv_start_offset; |
| 1896 | first_block = p_i93->ndef_tlv_start_offset / p_i93->block_size; |
| 1897 | |
| 1898 | /* read block to get lock status */ |
| 1899 | rw_i93_send_cmd_read_single_block(first_block, true); |
| 1900 | p_i93->sub_state = RW_I93_SUBSTATE_CHECK_LOCK_STATUS; |
| 1901 | } else { |
| 1902 | /* block offset for read-only check */ |
| 1903 | p_i93->rw_offset = 0; |
| 1904 | |
| 1905 | if (rw_i93_get_next_block_sec() == NFC_STATUS_OK) { |
| 1906 | p_i93->sub_state = RW_I93_SUBSTATE_CHECK_LOCK_STATUS; |
| 1907 | } else { |
| 1908 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1909 | } |
| 1910 | } |
| 1911 | } else { |
| 1912 | /* read more data */ |
| 1913 | p_i93->rw_offset += length; |
| 1914 | |
| 1915 | if (p_i93->rw_offset >= p_i93->block_size * p_i93->num_block) { |
| 1916 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1917 | } else if (rw_i93_get_next_blocks(p_i93->rw_offset) == NFC_STATUS_OK) { |
| 1918 | p_i93->sub_state = RW_I93_SUBSTATE_SEARCH_NDEF_TLV; |
| 1919 | } else { |
| 1920 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1921 | } |
| 1922 | } |
| 1923 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1924 | |
| 1925 | case RW_I93_SUBSTATE_CHECK_LOCK_STATUS: |
| 1926 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1927 | if ((p_i93->product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 1928 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY) || |
| 1929 | ((p_i93->uid[1] == I93_UID_IC_MFG_CODE_NXP) && |
| 1930 | (p_i93->ic_reference & I93_ICODE_IC_REF_MBREAD_MASK))) { |
| 1931 | /* these doesn't support GetMultiBlockSecurityStatus */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1932 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1933 | block = (p_i93->rw_offset / p_i93->block_size); |
| 1934 | last_block = (p_i93->ndef_tlv_last_offset / p_i93->block_size); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1935 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1936 | if ((*p) & I93_BLOCK_LOCKED) { |
| 1937 | if (block <= last_block) { |
| 1938 | p_i93->intl_flags |= RW_I93_FLAG_READ_ONLY; |
| 1939 | } |
| 1940 | } else { |
| 1941 | /* if we need to check more user blocks */ |
| 1942 | if (block + 1 < p_i93->num_block) { |
| 1943 | p_i93->rw_offset += p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1944 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1945 | /* read block to get lock status */ |
| 1946 | rw_i93_send_cmd_read_single_block( |
| 1947 | (uint16_t)(p_i93->rw_offset / p_i93->block_size), true); |
| 1948 | break; |
| 1949 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 1950 | } |
| 1951 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1952 | p_i93->max_ndef_length = |
| 1953 | p_i93->ndef_length |
| 1954 | /* add available bytes including the last block of NDEF TLV */ |
| 1955 | + (p_i93->block_size * (block - last_block) + 1) - |
| 1956 | (p_i93->ndef_tlv_last_offset % p_i93->block_size) - 1; |
| 1957 | } else { |
| 1958 | if (p_i93->rw_offset == 0) { |
| 1959 | p_i93->max_ndef_length = |
| 1960 | p_i93->ndef_length |
| 1961 | /* add available bytes in the last block of NDEF TLV */ |
| 1962 | + p_i93->block_size - |
| 1963 | (p_i93->ndef_tlv_last_offset % p_i93->block_size) - 1; |
| 1964 | |
| 1965 | first_block = (p_i93->ndef_tlv_start_offset / p_i93->block_size); |
| 1966 | } else { |
| 1967 | first_block = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1968 | } |
| 1969 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1970 | last_block = (p_i93->ndef_tlv_last_offset / p_i93->block_size); |
| 1971 | num_blocks = length; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1972 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1973 | for (block = first_block; block < num_blocks; block++) { |
| 1974 | /* if any block of NDEF TLV is locked */ |
| 1975 | if ((block + p_i93->rw_offset) <= last_block) { |
| 1976 | if (*(p + block) & I93_BLOCK_LOCKED) { |
| 1977 | p_i93->intl_flags |= RW_I93_FLAG_READ_ONLY; |
| 1978 | break; |
| 1979 | } |
| 1980 | } else { |
| 1981 | if (*(p + block) & I93_BLOCK_LOCKED) { |
| 1982 | /* no more consecutive unlocked block */ |
| 1983 | break; |
| 1984 | } else { |
| 1985 | /* add block size if not locked */ |
| 1986 | p_i93->max_ndef_length += p_i93->block_size; |
| 1987 | } |
| 1988 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1989 | } |
| 1990 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1991 | /* update next security of block to check */ |
| 1992 | p_i93->rw_offset += num_blocks; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 1993 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 1994 | /* if need to check more */ |
| 1995 | if (p_i93->num_block > p_i93->rw_offset) { |
| 1996 | if (rw_i93_get_next_block_sec() != NFC_STATUS_OK) { |
| 1997 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 1998 | } |
| 1999 | break; |
| 2000 | } |
| 2001 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2002 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2003 | /* check if need to adjust max NDEF length */ |
| 2004 | if ((p_i93->ndef_length < 0xFF) && (p_i93->max_ndef_length >= 0xFF)) { |
| 2005 | /* 3 bytes length field must be used */ |
| 2006 | p_i93->max_ndef_length -= 2; |
| 2007 | } |
| 2008 | |
| 2009 | rw_data.ndef.status = NFC_STATUS_OK; |
Love Khanna | 57a3dfa | 2017-03-28 20:03:38 +0530 | [diff] [blame] | 2010 | rw_data.ndef.protocol = NFC_PROTOCOL_T5T; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2011 | rw_data.ndef.flags = 0; |
| 2012 | rw_data.ndef.flags |= RW_NDEF_FL_SUPPORTED; |
| 2013 | rw_data.ndef.flags |= RW_NDEF_FL_FORMATED; |
| 2014 | rw_data.ndef.flags |= RW_NDEF_FL_FORMATABLE; |
| 2015 | rw_data.ndef.cur_size = p_i93->ndef_length; |
| 2016 | |
| 2017 | if (p_i93->intl_flags & RW_I93_FLAG_READ_ONLY) { |
| 2018 | rw_data.ndef.flags |= RW_NDEF_FL_READ_ONLY; |
| 2019 | rw_data.ndef.max_size = p_i93->ndef_length; |
| 2020 | } else { |
| 2021 | rw_data.ndef.flags |= RW_NDEF_FL_HARD_LOCKABLE; |
| 2022 | rw_data.ndef.max_size = p_i93->max_ndef_length; |
| 2023 | } |
| 2024 | |
| 2025 | p_i93->state = RW_I93_STATE_IDLE; |
| 2026 | p_i93->sent_cmd = 0; |
| 2027 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2028 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 2029 | "NDEF cur_size(%d),max_size (%d), flags (0x%x)", |
| 2030 | rw_data.ndef.cur_size, rw_data.ndef.max_size, rw_data.ndef.flags); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2031 | |
| 2032 | (*(rw_cb.p_cback))(RW_I93_NDEF_DETECT_EVT, &rw_data); |
| 2033 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2034 | |
| 2035 | default: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2036 | break; |
| 2037 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /******************************************************************************* |
| 2041 | ** |
| 2042 | ** Function rw_i93_sm_read_ndef |
| 2043 | ** |
| 2044 | ** Description Process NDEF read procedure |
| 2045 | ** |
| 2046 | ** Returns void |
| 2047 | ** |
| 2048 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2049 | void rw_i93_sm_read_ndef(NFC_HDR* p_resp) { |
| 2050 | uint8_t* p = (uint8_t*)(p_resp + 1) + p_resp->offset; |
| 2051 | uint8_t flags; |
| 2052 | uint16_t offset, length = p_resp->len; |
| 2053 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 2054 | tRW_DATA rw_data; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2055 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2056 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2057 | |
Jack Yu | 46defd3 | 2019-01-30 14:59:09 +0800 | [diff] [blame] | 2058 | if (length == 0) { |
| 2059 | android_errorWriteLog(0x534e4554, "122035770"); |
| 2060 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2061 | return; |
| 2062 | } |
| 2063 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2064 | STREAM_TO_UINT8(flags, p); |
| 2065 | length--; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2066 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2067 | if (flags & I93_FLAG_ERROR_DETECTED) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2068 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2069 | << StringPrintf("Got error flags (0x%02x)", flags); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2070 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2071 | return; |
| 2072 | } |
| 2073 | |
| 2074 | /* if this is the first block */ |
| 2075 | if (p_i93->rw_length == 0) { |
| 2076 | /* get start of NDEF in the first block */ |
| 2077 | offset = p_i93->ndef_tlv_start_offset % p_i93->block_size; |
| 2078 | |
| 2079 | if (p_i93->ndef_length < 0xFF) { |
| 2080 | offset += 2; |
| 2081 | } else { |
| 2082 | offset += 4; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2083 | } |
| 2084 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2085 | /* adjust offset if read more blocks because the first block doesn't have |
| 2086 | * NDEF */ |
| 2087 | offset -= (p_i93->rw_offset - p_i93->ndef_tlv_start_offset); |
| 2088 | } else { |
| 2089 | offset = 0; |
| 2090 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2091 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2092 | /* if read enough data to skip type and length field for the beginning */ |
| 2093 | if (offset < length) { |
| 2094 | offset++; /* flags */ |
| 2095 | p_resp->offset += offset; |
| 2096 | p_resp->len -= offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2097 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2098 | rw_data.data.status = NFC_STATUS_OK; |
| 2099 | rw_data.data.p_data = p_resp; |
| 2100 | |
| 2101 | p_i93->rw_length += p_resp->len; |
| 2102 | } else { |
| 2103 | /* in case of no Ndef data included */ |
| 2104 | p_resp->len = 0; |
| 2105 | } |
| 2106 | |
| 2107 | /* if read all of NDEF data */ |
| 2108 | if (p_i93->rw_length >= p_i93->ndef_length) { |
| 2109 | /* remove extra btyes in the last block */ |
| 2110 | p_resp->len -= (p_i93->rw_length - p_i93->ndef_length); |
| 2111 | |
| 2112 | p_i93->state = RW_I93_STATE_IDLE; |
| 2113 | p_i93->sent_cmd = 0; |
| 2114 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2115 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2116 | << StringPrintf("NDEF read complete read (%d)/total (%d)", p_resp->len, |
| 2117 | p_i93->ndef_length); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2118 | |
| 2119 | (*(rw_cb.p_cback))(RW_I93_NDEF_READ_CPLT_EVT, &rw_data); |
| 2120 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2121 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2122 | << StringPrintf("NDEF read segment read (%d)/total (%d)", p_resp->len, |
| 2123 | p_i93->ndef_length); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2124 | |
| 2125 | if (p_resp->len > 0) { |
| 2126 | (*(rw_cb.p_cback))(RW_I93_NDEF_READ_EVT, &rw_data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2127 | } |
| 2128 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2129 | /* this will make read data from next block */ |
| 2130 | p_i93->rw_offset += length; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2131 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2132 | if (rw_i93_get_next_blocks(p_i93->rw_offset) != NFC_STATUS_OK) { |
| 2133 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2134 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2135 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | /******************************************************************************* |
| 2139 | ** |
| 2140 | ** Function rw_i93_sm_update_ndef |
| 2141 | ** |
| 2142 | ** Description Process NDEF update procedure |
| 2143 | ** |
| 2144 | ** 1. Set length field to zero |
| 2145 | ** 2. Write NDEF and Terminator TLV |
| 2146 | ** 3. Set length field to NDEF length |
| 2147 | ** |
| 2148 | ** Returns void |
| 2149 | ** |
| 2150 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2151 | void rw_i93_sm_update_ndef(NFC_HDR* p_resp) { |
| 2152 | uint8_t* p = (uint8_t*)(p_resp + 1) + p_resp->offset; |
| 2153 | uint8_t flags, xx, length_offset, buff[I93_MAX_BLOCK_LENGH]; |
| 2154 | uint16_t length = p_resp->len, block_number; |
| 2155 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 2156 | tRW_DATA rw_data; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2157 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2158 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 2159 | "sub_state:%s (0x%x)", |
| 2160 | rw_i93_get_sub_state_name(p_i93->sub_state).c_str(), p_i93->sub_state); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2161 | |
Jack Yu | 9b406b6 | 2019-01-30 15:10:07 +0800 | [diff] [blame] | 2162 | if (length == 0 || p_i93->block_size > I93_MAX_BLOCK_LENGH) { |
| 2163 | android_errorWriteLog(0x534e4554, "122320256"); |
| 2164 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2165 | return; |
| 2166 | } |
| 2167 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2168 | STREAM_TO_UINT8(flags, p); |
| 2169 | length--; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2170 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2171 | if (flags & I93_FLAG_ERROR_DETECTED) { |
| 2172 | if (((p_i93->product_version == RW_I93_TAG_IT_HF_I_PLUS_INLAY) || |
| 2173 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PLUS_CHIP) || |
| 2174 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 2175 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY)) && |
| 2176 | (*p == I93_ERROR_CODE_BLOCK_FAIL_TO_WRITE)) { |
| 2177 | /* ignore error */ |
| 2178 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2179 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2180 | << StringPrintf("Got error flags (0x%02x)", flags); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2181 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2182 | return; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2183 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2184 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2185 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2186 | switch (p_i93->sub_state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2187 | case RW_I93_SUBSTATE_RESET_LEN: |
| 2188 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2189 | /* get offset of length field */ |
| 2190 | length_offset = (p_i93->ndef_tlv_start_offset + 1) % p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2191 | |
Jack Yu | 9b406b6 | 2019-01-30 15:10:07 +0800 | [diff] [blame] | 2192 | if (length < length_offset) { |
| 2193 | android_errorWriteLog(0x534e4554, "122320256"); |
| 2194 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2195 | return; |
| 2196 | } |
| 2197 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2198 | /* set length to zero */ |
| 2199 | *(p + length_offset) = 0x00; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2200 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2201 | if (p_i93->ndef_length > 0) { |
| 2202 | /* if 3 bytes length field is needed */ |
| 2203 | if (p_i93->ndef_length >= 0xFF) { |
| 2204 | xx = length_offset + 3; |
| 2205 | } else { |
| 2206 | xx = length_offset + 1; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2207 | } |
| 2208 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2209 | /* write the first part of NDEF in the same block */ |
| 2210 | for (; xx < p_i93->block_size; xx++) { |
Jack Yu | 9b406b6 | 2019-01-30 15:10:07 +0800 | [diff] [blame] | 2211 | if (xx > length || p_i93->rw_length > p_i93->ndef_length) { |
| 2212 | android_errorWriteLog(0x534e4554, "122320256"); |
| 2213 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2214 | return; |
| 2215 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2216 | if (p_i93->rw_length < p_i93->ndef_length) { |
| 2217 | *(p + xx) = *(p_i93->p_update_data + p_i93->rw_length++); |
| 2218 | } else { |
| 2219 | *(p + xx) = I93_ICODE_TLV_TYPE_NULL; |
| 2220 | } |
| 2221 | } |
| 2222 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2223 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2224 | block_number = (p_i93->ndef_tlv_start_offset + 1) / p_i93->block_size; |
| 2225 | |
George Chang | 82fd825 | 2020-01-03 20:46:24 +0800 | [diff] [blame] | 2226 | if (length < p_i93->block_size) { |
| 2227 | android_errorWriteLog(0x534e4554, "143109193"); |
| 2228 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2229 | } else if (rw_i93_send_cmd_write_single_block(block_number, p) == |
| 2230 | NFC_STATUS_OK) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2231 | /* update next writing offset */ |
| 2232 | p_i93->rw_offset = (block_number + 1) * p_i93->block_size; |
| 2233 | p_i93->sub_state = RW_I93_SUBSTATE_WRITE_NDEF; |
| 2234 | } else { |
| 2235 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2236 | } |
| 2237 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2238 | |
| 2239 | case RW_I93_SUBSTATE_WRITE_NDEF: |
| 2240 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2241 | /* if it's not the end of tag memory */ |
| 2242 | if (p_i93->rw_offset < p_i93->block_size * p_i93->num_block) { |
| 2243 | block_number = p_i93->rw_offset / p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2244 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2245 | /* if we have more data to write */ |
| 2246 | if (p_i93->rw_length < p_i93->ndef_length) { |
| 2247 | p = p_i93->p_update_data + p_i93->rw_length; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2248 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2249 | p_i93->rw_offset += p_i93->block_size; |
| 2250 | p_i93->rw_length += p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2251 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2252 | /* if this is the last block of NDEF TLV */ |
| 2253 | if (p_i93->rw_length > p_i93->ndef_length) { |
| 2254 | /* length of NDEF TLV in the block */ |
| 2255 | xx = (uint8_t)(p_i93->block_size - |
| 2256 | (p_i93->rw_length - p_i93->ndef_length)); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2257 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2258 | /* set NULL TLV in the unused part of block */ |
| 2259 | memset(buff, I93_ICODE_TLV_TYPE_NULL, p_i93->block_size); |
| 2260 | memcpy(buff, p, xx); |
| 2261 | p = buff; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2262 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2263 | /* if it's the end of tag memory */ |
| 2264 | if ((p_i93->rw_offset >= p_i93->block_size * p_i93->num_block) && |
| 2265 | (xx < p_i93->block_size)) { |
| 2266 | buff[xx] = I93_ICODE_TLV_TYPE_TERM; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2267 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2268 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2269 | p_i93->ndef_tlv_last_offset = |
| 2270 | p_i93->rw_offset - p_i93->block_size + xx - 1; |
| 2271 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2272 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2273 | if (rw_i93_send_cmd_write_single_block(block_number, p) != |
| 2274 | NFC_STATUS_OK) { |
| 2275 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2276 | } |
| 2277 | } else { |
| 2278 | /* if this is the very next block of NDEF TLV */ |
| 2279 | if (block_number == |
| 2280 | (p_i93->ndef_tlv_last_offset / p_i93->block_size) + 1) { |
| 2281 | p_i93->rw_offset += p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2282 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2283 | /* write Terminator TLV and NULL TLV */ |
| 2284 | memset(buff, I93_ICODE_TLV_TYPE_NULL, p_i93->block_size); |
| 2285 | buff[0] = I93_ICODE_TLV_TYPE_TERM; |
| 2286 | p = buff; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2287 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2288 | if (rw_i93_send_cmd_write_single_block(block_number, p) != |
| 2289 | NFC_STATUS_OK) { |
| 2290 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2291 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2292 | } else { |
| 2293 | /* finished writing NDEF and Terminator TLV */ |
| 2294 | /* read length field to update length */ |
| 2295 | block_number = |
| 2296 | (p_i93->ndef_tlv_start_offset + 1) / p_i93->block_size; |
| 2297 | |
| 2298 | if (rw_i93_send_cmd_read_single_block(block_number, false) == |
| 2299 | NFC_STATUS_OK) { |
| 2300 | /* set offset to length field */ |
| 2301 | p_i93->rw_offset = p_i93->ndef_tlv_start_offset + 1; |
| 2302 | |
| 2303 | /* get size of length field */ |
| 2304 | if (p_i93->ndef_length >= 0xFF) { |
| 2305 | p_i93->rw_length = 3; |
| 2306 | } else if (p_i93->ndef_length > 0) { |
| 2307 | p_i93->rw_length = 1; |
| 2308 | } else { |
| 2309 | p_i93->rw_length = 0; |
| 2310 | } |
| 2311 | |
| 2312 | p_i93->sub_state = RW_I93_SUBSTATE_UPDATE_LEN; |
| 2313 | } else { |
| 2314 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2315 | } |
| 2316 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2317 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2318 | } else { |
| 2319 | /* if we have no more data to write */ |
| 2320 | if (p_i93->rw_length >= p_i93->ndef_length) { |
| 2321 | /* finished writing NDEF and Terminator TLV */ |
| 2322 | /* read length field to update length */ |
| 2323 | block_number = (p_i93->ndef_tlv_start_offset + 1) / p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2324 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2325 | if (rw_i93_send_cmd_read_single_block(block_number, false) == |
| 2326 | NFC_STATUS_OK) { |
| 2327 | /* set offset to length field */ |
| 2328 | p_i93->rw_offset = p_i93->ndef_tlv_start_offset + 1; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2329 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2330 | /* get size of length field */ |
| 2331 | if (p_i93->ndef_length >= 0xFF) { |
| 2332 | p_i93->rw_length = 3; |
| 2333 | } else if (p_i93->ndef_length > 0) { |
| 2334 | p_i93->rw_length = 1; |
| 2335 | } else { |
| 2336 | p_i93->rw_length = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2337 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2338 | |
| 2339 | p_i93->sub_state = RW_I93_SUBSTATE_UPDATE_LEN; |
| 2340 | break; |
| 2341 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2342 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2343 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2344 | } |
| 2345 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2346 | |
| 2347 | case RW_I93_SUBSTATE_UPDATE_LEN: |
| 2348 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2349 | /* if we have more length field to write */ |
| 2350 | if (p_i93->rw_length > 0) { |
| 2351 | /* if we got ack for writing, read next block to update rest of length |
| 2352 | * field */ |
| 2353 | if (length == 0) { |
| 2354 | block_number = p_i93->rw_offset / p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2355 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2356 | if (rw_i93_send_cmd_read_single_block(block_number, false) != |
| 2357 | NFC_STATUS_OK) { |
| 2358 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2359 | } |
| 2360 | } else { |
| 2361 | length_offset = p_i93->rw_offset % p_i93->block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2362 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2363 | /* update length field within the read block */ |
| 2364 | for (xx = length_offset; xx < p_i93->block_size; xx++) { |
Jack Yu | 9b406b6 | 2019-01-30 15:10:07 +0800 | [diff] [blame] | 2365 | if (xx > length) { |
| 2366 | android_errorWriteLog(0x534e4554, "122320256"); |
| 2367 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2368 | return; |
| 2369 | } |
| 2370 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2371 | if (p_i93->rw_length == 3) |
| 2372 | *(p + xx) = 0xFF; |
| 2373 | else if (p_i93->rw_length == 2) |
| 2374 | *(p + xx) = (uint8_t)((p_i93->ndef_length >> 8) & 0xFF); |
| 2375 | else if (p_i93->rw_length == 1) |
| 2376 | *(p + xx) = (uint8_t)(p_i93->ndef_length & 0xFF); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2377 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2378 | p_i93->rw_length--; |
| 2379 | if (p_i93->rw_length == 0) break; |
| 2380 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2381 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2382 | block_number = (p_i93->rw_offset / p_i93->block_size); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2383 | |
George Chang | 82fd825 | 2020-01-03 20:46:24 +0800 | [diff] [blame] | 2384 | if (length < p_i93->block_size) { |
| 2385 | android_errorWriteLog(0x534e4554, "143155861"); |
| 2386 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2387 | } else if (rw_i93_send_cmd_write_single_block(block_number, p) == |
| 2388 | NFC_STATUS_OK) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2389 | /* set offset to the beginning of next block */ |
| 2390 | p_i93->rw_offset += |
| 2391 | p_i93->block_size - (p_i93->rw_offset % p_i93->block_size); |
| 2392 | } else { |
| 2393 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2394 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2395 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2396 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2397 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 2398 | "NDEF update complete, %d bytes, (%d-%d)", p_i93->ndef_length, |
| 2399 | p_i93->ndef_tlv_start_offset, p_i93->ndef_tlv_last_offset); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2400 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2401 | p_i93->state = RW_I93_STATE_IDLE; |
| 2402 | p_i93->sent_cmd = 0; |
| 2403 | p_i93->p_update_data = NULL; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2404 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2405 | rw_data.status = NFC_STATUS_OK; |
| 2406 | (*(rw_cb.p_cback))(RW_I93_NDEF_UPDATE_CPLT_EVT, &rw_data); |
| 2407 | } |
| 2408 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2409 | |
| 2410 | default: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2411 | break; |
| 2412 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | /******************************************************************************* |
| 2416 | ** |
| 2417 | ** Function rw_i93_sm_format |
| 2418 | ** |
| 2419 | ** Description Process format procedure |
| 2420 | ** |
| 2421 | ** 1. Get UID |
| 2422 | ** 2. Get sys info for memory size (reset AFI/DSFID) |
| 2423 | ** 3. Get block status to get read-only status |
| 2424 | ** 4. Write CC and empty NDEF |
| 2425 | ** |
| 2426 | ** Returns void |
| 2427 | ** |
| 2428 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2429 | void rw_i93_sm_format(NFC_HDR* p_resp) { |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 2430 | uint8_t *p = (uint8_t*)(p_resp + 1) + p_resp->offset, *p_uid; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2431 | uint8_t flags; |
| 2432 | uint16_t length = p_resp->len, xx, block_number; |
| 2433 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 2434 | tRW_DATA rw_data; |
| 2435 | tNFC_STATUS status = NFC_STATUS_FAILED; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2436 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2437 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 2438 | "sub_state:%s (0x%x)", |
| 2439 | rw_i93_get_sub_state_name(p_i93->sub_state).c_str(), p_i93->sub_state); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2440 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2441 | STREAM_TO_UINT8(flags, p); |
| 2442 | length--; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2443 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2444 | if (flags & I93_FLAG_ERROR_DETECTED) { |
| 2445 | if (((p_i93->product_version == RW_I93_TAG_IT_HF_I_PLUS_INLAY) || |
| 2446 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PLUS_CHIP) || |
| 2447 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 2448 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY)) && |
| 2449 | (*p == I93_ERROR_CODE_BLOCK_FAIL_TO_WRITE)) { |
| 2450 | /* ignore error */ |
| 2451 | } else if ((length) && (rw_i93_check_sys_info_prot_ext(*p))) { |
| 2452 | /* getting system info with protocol extension flag */ |
| 2453 | /* This STM tag supports more than 2040 bytes */ |
| 2454 | p_i93->intl_flags |= RW_I93_FLAG_16BIT_NUM_BLOCK; |
| 2455 | return; |
| 2456 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2457 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2458 | << StringPrintf("Got error flags (0x%02x)", flags); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2459 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2460 | return; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2461 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2462 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2463 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2464 | switch (p_i93->sub_state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2465 | case RW_I93_SUBSTATE_WAIT_UID: |
| 2466 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2467 | p++; /* skip DSFID */ |
| 2468 | p_uid = p_i93->uid; |
| 2469 | STREAM_TO_ARRAY8(p_uid, p); /* store UID */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2470 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2471 | /* get system information to get memory size */ |
| 2472 | if (rw_i93_send_cmd_get_sys_info(NULL, I93_FLAG_PROT_EXT_NO) == |
| 2473 | NFC_STATUS_OK) { |
| 2474 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_SYS_INFO; |
| 2475 | } else { |
| 2476 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2477 | } |
| 2478 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2479 | |
| 2480 | case RW_I93_SUBSTATE_WAIT_SYS_INFO: |
| 2481 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2482 | p_i93->block_size = 0; |
| 2483 | p_i93->num_block = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2484 | |
Ruchi Kandoi | ba95bb1 | 2019-01-24 14:45:55 -0800 | [diff] [blame] | 2485 | if (!rw_i93_process_sys_info(p, length)) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2486 | /* retrying with protocol extension flag */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2487 | break; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | if (p_i93->info_flags & I93_INFO_FLAG_DSFID) { |
| 2491 | /* DSFID, if any DSFID then reset */ |
| 2492 | if (p_i93->dsfid != I93_DFS_UNSUPPORTED) { |
| 2493 | p_i93->intl_flags |= RW_I93_FLAG_RESET_DSFID; |
| 2494 | } |
| 2495 | } |
| 2496 | if (p_i93->info_flags & I93_INFO_FLAG_AFI) { |
| 2497 | /* AFI, reset to 0 */ |
| 2498 | if (p_i93->afi != 0x00) { |
| 2499 | p_i93->intl_flags |= RW_I93_FLAG_RESET_AFI; |
| 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | if ((p_i93->block_size == 0) || (p_i93->num_block == 0)) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2504 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2505 | << StringPrintf("Unable to get tag memory size"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2506 | rw_i93_handle_error(status); |
| 2507 | } else if (p_i93->intl_flags & RW_I93_FLAG_RESET_DSFID) { |
| 2508 | if (rw_i93_send_cmd_write_dsfid(I93_DFS_UNSUPPORTED) == NFC_STATUS_OK) { |
| 2509 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI; |
| 2510 | } else { |
| 2511 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2512 | } |
| 2513 | } else if (p_i93->intl_flags & RW_I93_FLAG_RESET_AFI) { |
| 2514 | if (rw_i93_send_cmd_write_afi(0x00) == NFC_STATUS_OK) { |
| 2515 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI; |
| 2516 | } else { |
| 2517 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2518 | } |
| 2519 | } else { |
| 2520 | /* get lock status to see if read-only */ |
| 2521 | if ((p_i93->uid[1] == I93_UID_IC_MFG_CODE_NXP) && |
| 2522 | (p_i93->ic_reference & I93_ICODE_IC_REF_MBREAD_MASK)) { |
| 2523 | /* these doesn't support GetMultiBlockSecurityStatus */ |
| 2524 | |
| 2525 | rw_cb.tcb.i93.rw_offset = 0; |
| 2526 | |
| 2527 | /* read blocks with option flag to get block security status */ |
| 2528 | if (rw_i93_send_cmd_read_single_block(0x0000, true) == |
| 2529 | NFC_STATUS_OK) { |
| 2530 | p_i93->sub_state = RW_I93_SUBSTATE_CHECK_READ_ONLY; |
| 2531 | } else { |
| 2532 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2533 | } |
| 2534 | } else { |
| 2535 | /* block offset for read-only check */ |
| 2536 | p_i93->rw_offset = 0; |
| 2537 | |
| 2538 | if (rw_i93_get_next_block_sec() == NFC_STATUS_OK) { |
| 2539 | p_i93->sub_state = RW_I93_SUBSTATE_CHECK_READ_ONLY; |
| 2540 | } else { |
| 2541 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2542 | } |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2547 | |
| 2548 | case RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI: |
| 2549 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2550 | if (p_i93->sent_cmd == I93_CMD_WRITE_DSFID) { |
| 2551 | p_i93->intl_flags &= ~RW_I93_FLAG_RESET_DSFID; |
| 2552 | } else if (p_i93->sent_cmd == I93_CMD_WRITE_AFI) { |
| 2553 | p_i93->intl_flags &= ~RW_I93_FLAG_RESET_AFI; |
| 2554 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2555 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2556 | if (p_i93->intl_flags & RW_I93_FLAG_RESET_DSFID) { |
| 2557 | if (rw_i93_send_cmd_write_dsfid(I93_DFS_UNSUPPORTED) == NFC_STATUS_OK) { |
| 2558 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI; |
| 2559 | } else { |
| 2560 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2561 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2562 | } else if (p_i93->intl_flags & RW_I93_FLAG_RESET_AFI) { |
| 2563 | if (rw_i93_send_cmd_write_afi(0x00) == NFC_STATUS_OK) { |
| 2564 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI; |
| 2565 | } else { |
| 2566 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2567 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2568 | } else { |
| 2569 | /* get lock status to see if read-only */ |
| 2570 | if ((p_i93->uid[1] == I93_UID_IC_MFG_CODE_NXP) && |
| 2571 | (p_i93->ic_reference & I93_ICODE_IC_REF_MBREAD_MASK)) { |
| 2572 | /* these doesn't support GetMultiBlockSecurityStatus */ |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2573 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2574 | rw_cb.tcb.i93.rw_offset = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2575 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2576 | /* read blocks with option flag to get block security status */ |
| 2577 | if (rw_i93_send_cmd_read_single_block(0x0000, true) == |
| 2578 | NFC_STATUS_OK) { |
| 2579 | p_i93->sub_state = RW_I93_SUBSTATE_CHECK_READ_ONLY; |
| 2580 | } else { |
| 2581 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2582 | } |
| 2583 | } else { |
| 2584 | /* block offset for read-only check */ |
| 2585 | p_i93->rw_offset = 0; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 2586 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2587 | if (rw_i93_get_next_block_sec() == NFC_STATUS_OK) { |
| 2588 | p_i93->sub_state = RW_I93_SUBSTATE_CHECK_READ_ONLY; |
| 2589 | } else { |
| 2590 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2591 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2592 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2593 | } |
| 2594 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2595 | |
| 2596 | case RW_I93_SUBSTATE_CHECK_READ_ONLY: |
| 2597 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2598 | if ((p_i93->product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 2599 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY) || |
| 2600 | ((p_i93->uid[1] == I93_UID_IC_MFG_CODE_NXP) && |
| 2601 | (p_i93->ic_reference & I93_ICODE_IC_REF_MBREAD_MASK))) { |
| 2602 | if ((*p) & I93_BLOCK_LOCKED) { |
| 2603 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2604 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2605 | } |
| 2606 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2607 | /* if we checked all of user blocks */ |
| 2608 | if ((p_i93->rw_offset / p_i93->block_size) + 1 == p_i93->num_block) { |
| 2609 | if ((p_i93->product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 2610 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY)) { |
| 2611 | /* read the block which has AFI */ |
| 2612 | p_i93->rw_offset = I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_AFI_LOCATION; |
| 2613 | rw_i93_send_cmd_read_single_block( |
| 2614 | (uint16_t)(p_i93->rw_offset / p_i93->block_size), true); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2615 | break; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2616 | } |
| 2617 | } else if (p_i93->rw_offset == |
| 2618 | I93_TAG_IT_HF_I_STD_PRO_CHIP_INLAY_AFI_LOCATION) { |
| 2619 | /* no block is locked */ |
| 2620 | } else { |
| 2621 | p_i93->rw_offset += p_i93->block_size; |
| 2622 | rw_i93_send_cmd_read_single_block( |
| 2623 | (uint16_t)(p_i93->rw_offset / p_i93->block_size), true); |
| 2624 | break; |
| 2625 | } |
| 2626 | } else { |
| 2627 | /* if any block is locked, we cannot format it */ |
| 2628 | for (xx = 0; xx < length; xx++) { |
| 2629 | if (*(p + xx) & I93_BLOCK_LOCKED) { |
| 2630 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2631 | break; |
| 2632 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2633 | } |
| 2634 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2635 | /* update block offset for read-only check */ |
| 2636 | p_i93->rw_offset += length; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2637 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2638 | /* if need to get more lock status of blocks */ |
| 2639 | if (p_i93->num_block > p_i93->rw_offset) { |
| 2640 | if (rw_i93_get_next_block_sec() != NFC_STATUS_OK) { |
| 2641 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2642 | } |
| 2643 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2644 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2645 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 2646 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2647 | /* get buffer to store CC, zero length NDEF TLV and Terminator TLV */ |
George Chang | 3785414 | 2019-10-05 10:59:26 +0800 | [diff] [blame] | 2648 | /* Block size could be either 4 or 8 or 16 or 32 bytes */ |
| 2649 | /* Get buffer for the largest block size I93_MAX_BLOCK_LENGH */ |
| 2650 | p_i93->p_update_data = (uint8_t*)GKI_getbuf(I93_MAX_BLOCK_LENGH); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2651 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2652 | if (!p_i93->p_update_data) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2653 | LOG(ERROR) << StringPrintf("Cannot allocate buffer"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2654 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2655 | break; |
Alisher Alikhodjaev | 27013fe | 2020-07-23 14:38:34 -0700 | [diff] [blame^] | 2656 | } else { |
| 2657 | switch (p_i93->block_size) { |
| 2658 | case 4: |
| 2659 | case 8: |
| 2660 | break; |
| 2661 | case 16: |
| 2662 | case 32: /* initialize unpopulated buffer b/139738828 */ |
| 2663 | memset(p_i93->p_update_data, I93_ICODE_TLV_TYPE_NULL, |
| 2664 | I93_MAX_BLOCK_LENGH); |
| 2665 | break; |
| 2666 | default: |
| 2667 | android_errorWriteLog(0x534e4554, "157650336"); |
| 2668 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2669 | return; |
| 2670 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | p = p_i93->p_update_data; |
| 2674 | |
| 2675 | /* Capability Container */ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 2676 | *(p++) = I93_ICODE_CC_MAGIC_NUMER_E1; /* magic number */ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2677 | *(p++) = 0x40; /* version 1.0, read/write */ |
| 2678 | |
| 2679 | /* if memory size is less than 2048 bytes */ |
| 2680 | if (((p_i93->num_block * p_i93->block_size) / 8) < 0x100) |
| 2681 | *(p++) = (uint8_t)((p_i93->num_block * p_i93->block_size) / |
| 2682 | 8); /* memory size */ |
| 2683 | else |
| 2684 | *(p++) = 0xFF; |
| 2685 | |
| 2686 | if ((p_i93->product_version == RW_I93_ICODE_SLI) || |
| 2687 | (p_i93->product_version == RW_I93_ICODE_SLI_S) || |
| 2688 | (p_i93->product_version == RW_I93_ICODE_SLI_L)) { |
| 2689 | if (p_i93->ic_reference & I93_ICODE_IC_REF_MBREAD_MASK) |
| 2690 | *(p++) = I93_ICODE_CC_IPREAD_MASK; /* IPREAD */ |
| 2691 | else |
| 2692 | *(p++) = I93_ICODE_CC_MBREAD_MASK; /* MBREAD, read multi block command |
| 2693 | supported */ |
| 2694 | } else if ((p_i93->product_version == RW_I93_TAG_IT_HF_I_PLUS_INLAY) || |
| 2695 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PLUS_CHIP)) { |
| 2696 | *(p++) = I93_ICODE_CC_MBREAD_MASK; /* MBREAD, read multi block command |
| 2697 | supported */ |
| 2698 | } else if ((p_i93->product_version == |
| 2699 | RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 2700 | (p_i93->product_version == |
| 2701 | RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY)) { |
| 2702 | *(p++) = 0; |
| 2703 | } else { |
| 2704 | /* STM except LRIS2K, Broadcom supports read multi block command */ |
| 2705 | |
| 2706 | /* if memory size is more than 2040 bytes (which is not LRIS2K) */ |
| 2707 | if (((p_i93->num_block * p_i93->block_size) / 8) > 0xFF) |
| 2708 | *(p++) = (I93_ICODE_CC_MBREAD_MASK | I93_STM_CC_OVERFLOW_MASK); |
| 2709 | else if (p_i93->product_version == RW_I93_STM_LRIS2K) |
| 2710 | *(p++) = 0x00; |
| 2711 | else |
| 2712 | *(p++) = I93_ICODE_CC_MBREAD_MASK; |
| 2713 | } |
| 2714 | |
| 2715 | /* zero length NDEF and Terminator TLV */ |
| 2716 | *(p++) = I93_ICODE_TLV_TYPE_NDEF; |
| 2717 | *(p++) = 0x00; |
| 2718 | *(p++) = I93_ICODE_TLV_TYPE_TERM; |
| 2719 | *(p++) = I93_ICODE_TLV_TYPE_NULL; |
| 2720 | |
| 2721 | /* start from block 0 */ |
| 2722 | p_i93->rw_offset = 0; |
| 2723 | |
| 2724 | if (rw_i93_send_cmd_write_single_block(0, p_i93->p_update_data) == |
| 2725 | NFC_STATUS_OK) { |
| 2726 | p_i93->sub_state = RW_I93_SUBSTATE_WRITE_CC_NDEF_TLV; |
| 2727 | p_i93->rw_offset += p_i93->block_size; |
| 2728 | } else { |
| 2729 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2730 | } |
| 2731 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2732 | |
| 2733 | case RW_I93_SUBSTATE_WRITE_CC_NDEF_TLV: |
| 2734 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2735 | /* if we have more data to write */ |
| 2736 | if (p_i93->rw_offset < RW_I93_FORMAT_DATA_LEN) { |
| 2737 | block_number = (p_i93->rw_offset / p_i93->block_size); |
| 2738 | p = p_i93->p_update_data + p_i93->rw_offset; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2739 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2740 | if (rw_i93_send_cmd_write_single_block(block_number, p) == |
| 2741 | NFC_STATUS_OK) { |
| 2742 | p_i93->sub_state = RW_I93_SUBSTATE_WRITE_CC_NDEF_TLV; |
| 2743 | p_i93->rw_offset += p_i93->block_size; |
| 2744 | } else { |
| 2745 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2746 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2747 | } else { |
| 2748 | GKI_freebuf(p_i93->p_update_data); |
| 2749 | p_i93->p_update_data = NULL; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2750 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2751 | p_i93->state = RW_I93_STATE_IDLE; |
| 2752 | p_i93->sent_cmd = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2753 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2754 | rw_data.status = NFC_STATUS_OK; |
| 2755 | (*(rw_cb.p_cback))(RW_I93_FORMAT_CPLT_EVT, &rw_data); |
| 2756 | } |
| 2757 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2758 | |
| 2759 | default: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2760 | break; |
| 2761 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | /******************************************************************************* |
| 2765 | ** |
| 2766 | ** Function rw_i93_sm_set_read_only |
| 2767 | ** |
| 2768 | ** Description Process read-only procedure |
| 2769 | ** |
| 2770 | ** 1. Update CC as read-only |
| 2771 | ** 2. Lock all block of NDEF TLV |
| 2772 | ** 3. Lock block of CC |
| 2773 | ** |
| 2774 | ** Returns void |
| 2775 | ** |
| 2776 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2777 | void rw_i93_sm_set_read_only(NFC_HDR* p_resp) { |
| 2778 | uint8_t* p = (uint8_t*)(p_resp + 1) + p_resp->offset; |
| 2779 | uint8_t flags, block_number; |
| 2780 | uint16_t length = p_resp->len; |
| 2781 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 2782 | tRW_DATA rw_data; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2783 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2784 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 2785 | "sub_state:%s (0x%x)", |
| 2786 | rw_i93_get_sub_state_name(p_i93->sub_state).c_str(), p_i93->sub_state); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2787 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2788 | STREAM_TO_UINT8(flags, p); |
| 2789 | length--; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2790 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2791 | if (flags & I93_FLAG_ERROR_DETECTED) { |
| 2792 | if (((p_i93->product_version == RW_I93_TAG_IT_HF_I_PLUS_INLAY) || |
| 2793 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PLUS_CHIP) || |
| 2794 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 2795 | (p_i93->product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY)) && |
| 2796 | (*p == I93_ERROR_CODE_BLOCK_FAIL_TO_WRITE)) { |
| 2797 | /* ignore error */ |
| 2798 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2799 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2800 | << StringPrintf("Got error flags (0x%02x)", flags); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2801 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2802 | return; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2803 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2804 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2805 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2806 | switch (p_i93->sub_state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2807 | case RW_I93_SUBSTATE_WAIT_CC: |
| 2808 | |
George Chang | ec0e233 | 2019-08-16 20:37:23 +0800 | [diff] [blame] | 2809 | if (length < RW_I93_CC_SIZE) { |
| 2810 | android_errorWriteLog(0x534e4554, "139188579"); |
| 2811 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2812 | return; |
| 2813 | } |
| 2814 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2815 | /* mark CC as read-only */ |
| 2816 | *(p + 1) |= I93_ICODE_CC_READ_ONLY; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2817 | |
George Chang | 82fd825 | 2020-01-03 20:46:24 +0800 | [diff] [blame] | 2818 | if (length < p_i93->block_size) { |
| 2819 | android_errorWriteLog(0x534e4554, "143106535"); |
| 2820 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2821 | } else if (rw_i93_send_cmd_write_single_block(0, p) == NFC_STATUS_OK) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2822 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_UPDATE_CC; |
| 2823 | } else { |
| 2824 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2825 | } |
| 2826 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2827 | |
| 2828 | case RW_I93_SUBSTATE_WAIT_UPDATE_CC: |
| 2829 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2830 | /* successfully write CC then lock all blocks of NDEF TLV */ |
| 2831 | p_i93->rw_offset = p_i93->ndef_tlv_start_offset; |
| 2832 | block_number = (uint8_t)(p_i93->rw_offset / p_i93->block_size); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2833 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2834 | if (rw_i93_send_cmd_lock_block(block_number) == NFC_STATUS_OK) { |
| 2835 | p_i93->rw_offset += p_i93->block_size; |
| 2836 | p_i93->sub_state = RW_I93_SUBSTATE_LOCK_NDEF_TLV; |
| 2837 | } else { |
| 2838 | rw_i93_handle_error(NFC_STATUS_FAILED); |
| 2839 | } |
| 2840 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2841 | |
| 2842 | case RW_I93_SUBSTATE_LOCK_NDEF_TLV: |
| 2843 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2844 | /* if we need to lock more blocks */ |
| 2845 | if (p_i93->rw_offset < p_i93->ndef_tlv_last_offset) { |
| 2846 | /* get the next block of NDEF TLV */ |
| 2847 | block_number = (uint8_t)(p_i93->rw_offset / p_i93->block_size); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2848 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2849 | if (rw_i93_send_cmd_lock_block(block_number) == NFC_STATUS_OK) { |
| 2850 | p_i93->rw_offset += p_i93->block_size; |
| 2851 | } else { |
| 2852 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2853 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2854 | } |
| 2855 | /* if the first block of NDEF TLV is different from block of CC */ |
| 2856 | else if (p_i93->ndef_tlv_start_offset / p_i93->block_size != 0) { |
| 2857 | /* lock block of CC */ |
| 2858 | if (rw_i93_send_cmd_lock_block(0) == NFC_STATUS_OK) { |
| 2859 | p_i93->sub_state = RW_I93_SUBSTATE_WAIT_LOCK_CC; |
| 2860 | } else { |
| 2861 | rw_i93_handle_error(NFC_STATUS_FAILED); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2862 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2863 | } else { |
| 2864 | p_i93->intl_flags |= RW_I93_FLAG_READ_ONLY; |
| 2865 | p_i93->state = RW_I93_STATE_IDLE; |
| 2866 | p_i93->sent_cmd = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2867 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2868 | rw_data.status = NFC_STATUS_OK; |
| 2869 | (*(rw_cb.p_cback))(RW_I93_SET_TAG_RO_EVT, &rw_data); |
| 2870 | } |
| 2871 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2872 | |
| 2873 | case RW_I93_SUBSTATE_WAIT_LOCK_CC: |
| 2874 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2875 | p_i93->intl_flags |= RW_I93_FLAG_READ_ONLY; |
| 2876 | p_i93->state = RW_I93_STATE_IDLE; |
| 2877 | p_i93->sent_cmd = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2878 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2879 | rw_data.status = NFC_STATUS_OK; |
| 2880 | (*(rw_cb.p_cback))(RW_I93_SET_TAG_RO_EVT, &rw_data); |
| 2881 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2882 | |
| 2883 | default: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2884 | break; |
| 2885 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | /******************************************************************************* |
| 2889 | ** |
| 2890 | ** Function rw_i93_handle_error |
| 2891 | ** |
| 2892 | ** Description notify error to application and clean up |
| 2893 | ** |
| 2894 | ** Returns none |
| 2895 | ** |
| 2896 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2897 | void rw_i93_handle_error(tNFC_STATUS status) { |
| 2898 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 2899 | tRW_DATA rw_data; |
| 2900 | tRW_EVENT event; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2901 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2902 | DLOG_IF(INFO, nfc_debug_enabled) |
| 2903 | << StringPrintf("status:0x%02X, state:0x%X", status, p_i93->state); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2904 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2905 | nfc_stop_quick_timer(&p_i93->timer); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2906 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2907 | if (rw_cb.p_cback) { |
| 2908 | rw_data.status = status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2909 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2910 | switch (p_i93->state) { |
| 2911 | case RW_I93_STATE_IDLE: /* in case of RawFrame */ |
| 2912 | event = RW_I93_INTF_ERROR_EVT; |
| 2913 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2914 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2915 | case RW_I93_STATE_BUSY: |
| 2916 | if (p_i93->sent_cmd == I93_CMD_STAY_QUIET) { |
| 2917 | /* There is no response to Stay Quiet command */ |
| 2918 | rw_data.i93_cmd_cmpl.status = NFC_STATUS_OK; |
| 2919 | rw_data.i93_cmd_cmpl.command = I93_CMD_STAY_QUIET; |
| 2920 | rw_data.i93_cmd_cmpl.error_code = 0; |
| 2921 | event = RW_I93_CMD_CMPL_EVT; |
| 2922 | } else { |
| 2923 | event = RW_I93_INTF_ERROR_EVT; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2924 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2925 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2926 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2927 | case RW_I93_STATE_DETECT_NDEF: |
Love Khanna | 57a3dfa | 2017-03-28 20:03:38 +0530 | [diff] [blame] | 2928 | rw_data.ndef.protocol = NFC_PROTOCOL_T5T; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2929 | rw_data.ndef.cur_size = 0; |
| 2930 | rw_data.ndef.max_size = 0; |
| 2931 | rw_data.ndef.flags = 0; |
| 2932 | rw_data.ndef.flags |= RW_NDEF_FL_FORMATABLE; |
| 2933 | rw_data.ndef.flags |= RW_NDEF_FL_UNKNOWN; |
| 2934 | event = RW_I93_NDEF_DETECT_EVT; |
| 2935 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2936 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2937 | case RW_I93_STATE_READ_NDEF: |
| 2938 | event = RW_I93_NDEF_READ_FAIL_EVT; |
| 2939 | break; |
| 2940 | |
| 2941 | case RW_I93_STATE_UPDATE_NDEF: |
| 2942 | p_i93->p_update_data = NULL; |
| 2943 | event = RW_I93_NDEF_UPDATE_FAIL_EVT; |
| 2944 | break; |
| 2945 | |
| 2946 | case RW_I93_STATE_FORMAT: |
| 2947 | if (p_i93->p_update_data) { |
| 2948 | GKI_freebuf(p_i93->p_update_data); |
| 2949 | p_i93->p_update_data = NULL; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2950 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2951 | event = RW_I93_FORMAT_CPLT_EVT; |
| 2952 | break; |
| 2953 | |
| 2954 | case RW_I93_STATE_SET_READ_ONLY: |
| 2955 | event = RW_I93_SET_TAG_RO_EVT; |
| 2956 | break; |
| 2957 | |
| 2958 | case RW_I93_STATE_PRESENCE_CHECK: |
| 2959 | event = RW_I93_PRESENCE_CHECK_EVT; |
| 2960 | break; |
| 2961 | |
| 2962 | default: |
| 2963 | event = RW_I93_MAX_EVT; |
| 2964 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2965 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2966 | |
| 2967 | p_i93->state = RW_I93_STATE_IDLE; |
| 2968 | p_i93->sent_cmd = 0; |
| 2969 | |
| 2970 | if (event != RW_I93_MAX_EVT) { |
| 2971 | (*(rw_cb.p_cback))(event, &rw_data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2972 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2973 | } else { |
| 2974 | p_i93->state = RW_I93_STATE_IDLE; |
| 2975 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | /******************************************************************************* |
| 2979 | ** |
| 2980 | ** Function rw_i93_process_timeout |
| 2981 | ** |
| 2982 | ** Description process timeout event |
| 2983 | ** |
| 2984 | ** Returns none |
| 2985 | ** |
| 2986 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2987 | void rw_i93_process_timeout(TIMER_LIST_ENT* p_tle) { |
| 2988 | NFC_HDR* p_buf; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 2989 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2990 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("event=%d", p_tle->event); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 2991 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2992 | if (p_tle->event == NFC_TTYPE_RW_I93_RESPONSE) { |
| 2993 | if ((rw_cb.tcb.i93.retry_count < RW_MAX_RETRIES) && |
| 2994 | (rw_cb.tcb.i93.p_retry_cmd) && |
| 2995 | (rw_cb.tcb.i93.sent_cmd != I93_CMD_STAY_QUIET)) { |
| 2996 | rw_cb.tcb.i93.retry_count++; |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 2997 | LOG(ERROR) << StringPrintf("retry_count = %d", rw_cb.tcb.i93.retry_count); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 2998 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 2999 | p_buf = rw_cb.tcb.i93.p_retry_cmd; |
| 3000 | rw_cb.tcb.i93.p_retry_cmd = NULL; |
Evan Chu | 7c69b27 | 2013-05-14 12:48:36 -0400 | [diff] [blame] | 3001 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3002 | if (rw_i93_send_to_lower(p_buf)) { |
| 3003 | return; |
| 3004 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3005 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3006 | |
| 3007 | /* all retrial is done or failed to send command to lower layer */ |
| 3008 | if (rw_cb.tcb.i93.p_retry_cmd) { |
| 3009 | GKI_freebuf(rw_cb.tcb.i93.p_retry_cmd); |
| 3010 | rw_cb.tcb.i93.p_retry_cmd = NULL; |
| 3011 | rw_cb.tcb.i93.retry_count = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3012 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3013 | rw_i93_handle_error(NFC_STATUS_TIMEOUT); |
| 3014 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3015 | LOG(ERROR) << StringPrintf("unknown event=%d", p_tle->event); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3016 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | /******************************************************************************* |
| 3020 | ** |
| 3021 | ** Function rw_i93_data_cback |
| 3022 | ** |
| 3023 | ** Description This callback function receives the data from NFCC. |
| 3024 | ** |
| 3025 | ** Returns none |
| 3026 | ** |
| 3027 | *******************************************************************************/ |
Ruchi Kandoi | 9ba6d24 | 2017-10-13 16:07:01 -0700 | [diff] [blame] | 3028 | static void rw_i93_data_cback(__attribute__((unused)) uint8_t conn_id, |
| 3029 | tNFC_CONN_EVT event, tNFC_CONN* p_data) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3030 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 3031 | NFC_HDR* p_resp; |
| 3032 | tRW_DATA rw_data; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3033 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3034 | uint8_t begin_state = p_i93->state; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3035 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3036 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("event = 0x%X", event); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3037 | |
Love Khanna | 57a3dfa | 2017-03-28 20:03:38 +0530 | [diff] [blame] | 3038 | if ((event == NFC_DEACTIVATE_CEVT) || (event == NFC_ERROR_CEVT) || |
| 3039 | ((event == NFC_DATA_CEVT) && (p_data->status != NFC_STATUS_OK))) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3040 | nfc_stop_quick_timer(&p_i93->timer); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3041 | |
Jizhou Liao | 499be10 | 2017-08-11 12:57:12 -0700 | [diff] [blame] | 3042 | if (event == NFC_ERROR_CEVT || (p_data->status != NFC_STATUS_OK)) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3043 | if ((p_i93->retry_count < RW_MAX_RETRIES) && (p_i93->p_retry_cmd)) { |
| 3044 | p_i93->retry_count++; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3045 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3046 | LOG(ERROR) << StringPrintf("retry_count = %d", p_i93->retry_count); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3047 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3048 | p_resp = p_i93->p_retry_cmd; |
| 3049 | p_i93->p_retry_cmd = NULL; |
| 3050 | if (rw_i93_send_to_lower(p_resp)) { |
| 3051 | return; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3052 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3053 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3054 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3055 | /* all retrial is done or failed to send command to lower layer */ |
| 3056 | if (p_i93->p_retry_cmd) { |
| 3057 | GKI_freebuf(p_i93->p_retry_cmd); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3058 | p_i93->p_retry_cmd = NULL; |
| 3059 | p_i93->retry_count = 0; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | rw_i93_handle_error((tNFC_STATUS)(*(uint8_t*)p_data)); |
| 3063 | } else { |
| 3064 | /* free retry buffer */ |
| 3065 | if (p_i93->p_retry_cmd) { |
| 3066 | GKI_freebuf(p_i93->p_retry_cmd); |
| 3067 | p_i93->p_retry_cmd = NULL; |
| 3068 | p_i93->retry_count = 0; |
| 3069 | } |
| 3070 | NFC_SetStaticRfCback(NULL); |
| 3071 | p_i93->state = RW_I93_STATE_NOT_ACTIVATED; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3072 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3073 | return; |
| 3074 | } |
| 3075 | |
| 3076 | if (event != NFC_DATA_CEVT) { |
| 3077 | return; |
| 3078 | } |
| 3079 | |
| 3080 | p_resp = (NFC_HDR*)p_data->data.p_data; |
| 3081 | |
| 3082 | nfc_stop_quick_timer(&p_i93->timer); |
| 3083 | |
| 3084 | /* free retry buffer */ |
| 3085 | if (p_i93->p_retry_cmd) { |
| 3086 | GKI_freebuf(p_i93->p_retry_cmd); |
| 3087 | p_i93->p_retry_cmd = NULL; |
| 3088 | p_i93->retry_count = 0; |
| 3089 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3090 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3091 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 3092 | "RW I93 state: <%s (%d)>", rw_i93_get_state_name(p_i93->state).c_str(), |
| 3093 | p_i93->state); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3094 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3095 | switch (p_i93->state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3096 | case RW_I93_STATE_IDLE: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3097 | /* Unexpected Response from VICC, it should be raw frame response */ |
| 3098 | /* forward to upper layer without parsing */ |
| 3099 | p_i93->sent_cmd = 0; |
| 3100 | if (rw_cb.p_cback) { |
| 3101 | rw_data.raw_frame.status = p_data->data.status; |
| 3102 | rw_data.raw_frame.p_data = p_resp; |
| 3103 | (*(rw_cb.p_cback))(RW_I93_RAW_FRAME_EVT, &rw_data); |
| 3104 | p_resp = NULL; |
| 3105 | } else { |
| 3106 | GKI_freebuf(p_resp); |
| 3107 | } |
| 3108 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3109 | case RW_I93_STATE_BUSY: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3110 | p_i93->state = RW_I93_STATE_IDLE; |
| 3111 | rw_i93_send_to_upper(p_resp); |
| 3112 | GKI_freebuf(p_resp); |
| 3113 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3114 | |
| 3115 | case RW_I93_STATE_DETECT_NDEF: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3116 | rw_i93_sm_detect_ndef(p_resp); |
| 3117 | GKI_freebuf(p_resp); |
| 3118 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3119 | |
| 3120 | case RW_I93_STATE_READ_NDEF: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3121 | rw_i93_sm_read_ndef(p_resp); |
| 3122 | /* p_resp may send upper lyaer */ |
| 3123 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3124 | |
| 3125 | case RW_I93_STATE_UPDATE_NDEF: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3126 | rw_i93_sm_update_ndef(p_resp); |
| 3127 | GKI_freebuf(p_resp); |
| 3128 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3129 | |
| 3130 | case RW_I93_STATE_FORMAT: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3131 | rw_i93_sm_format(p_resp); |
| 3132 | GKI_freebuf(p_resp); |
| 3133 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3134 | |
| 3135 | case RW_I93_STATE_SET_READ_ONLY: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3136 | rw_i93_sm_set_read_only(p_resp); |
| 3137 | GKI_freebuf(p_resp); |
| 3138 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3139 | |
| 3140 | case RW_I93_STATE_PRESENCE_CHECK: |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3141 | p_i93->state = RW_I93_STATE_IDLE; |
| 3142 | p_i93->sent_cmd = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3143 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3144 | /* if any response, send presence check with ok */ |
| 3145 | rw_data.status = NFC_STATUS_OK; |
| 3146 | (*(rw_cb.p_cback))(RW_I93_PRESENCE_CHECK_EVT, &rw_data); |
| 3147 | GKI_freebuf(p_resp); |
| 3148 | break; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3149 | |
| 3150 | default: |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3151 | LOG(ERROR) << StringPrintf("invalid state=%d", p_i93->state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3152 | GKI_freebuf(p_resp); |
| 3153 | break; |
| 3154 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3155 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3156 | if (begin_state != p_i93->state) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3157 | DLOG_IF(INFO, nfc_debug_enabled) |
| 3158 | << StringPrintf("RW I93 state changed:<%s> -> <%s>", |
| 3159 | rw_i93_get_state_name(begin_state).c_str(), |
| 3160 | rw_i93_get_state_name(p_i93->state).c_str()); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3161 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | /******************************************************************************* |
| 3165 | ** |
| 3166 | ** Function rw_i93_select |
| 3167 | ** |
Love Khanna | 57a3dfa | 2017-03-28 20:03:38 +0530 | [diff] [blame] | 3168 | ** Description Initialise ISO 15693 / T5T RW |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3169 | ** |
| 3170 | ** Returns NFC_STATUS_OK if success |
| 3171 | ** |
| 3172 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3173 | tNFC_STATUS rw_i93_select(uint8_t* p_uid) { |
| 3174 | tRW_I93_CB* p_i93 = &rw_cb.tcb.i93; |
| 3175 | uint8_t uid[I93_UID_BYTE_LEN], *p; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3176 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3177 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3178 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3179 | NFC_SetStaticRfCback(rw_i93_data_cback); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3180 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3181 | p_i93->state = RW_I93_STATE_IDLE; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3182 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3183 | /* convert UID to big endian format - MSB(0xE0) in first byte */ |
| 3184 | p = uid; |
| 3185 | STREAM_TO_ARRAY8(p, p_uid); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3186 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3187 | rw_i93_get_product_version(uid); |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3188 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3189 | return NFC_STATUS_OK; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | /******************************************************************************* |
| 3193 | ** |
| 3194 | ** Function RW_I93Inventory |
| 3195 | ** |
Martijn Coenen | 5c65c3a | 2013-03-27 13:23:36 -0700 | [diff] [blame] | 3196 | ** Description This function send Inventory command with/without AFI |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3197 | ** If UID is provided then set UID[0]:MSB, ... UID[7]:LSB |
| 3198 | ** |
| 3199 | ** RW_I93_RESPONSE_EVT will be returned |
| 3200 | ** |
| 3201 | ** Returns NFC_STATUS_OK if success |
| 3202 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3203 | ** NFC_STATUS_BUSY if busy |
| 3204 | ** NFC_STATUS_FAILED if other error |
| 3205 | ** |
| 3206 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3207 | tNFC_STATUS RW_I93Inventory(bool including_afi, uint8_t afi, uint8_t* p_uid) { |
| 3208 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3209 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3210 | DLOG_IF(INFO, nfc_debug_enabled) |
| 3211 | << StringPrintf(", including_afi:%d, AFI:0x%02X", including_afi, afi); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3212 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3213 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3214 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3215 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3216 | return NFC_STATUS_BUSY; |
| 3217 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3218 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3219 | status = rw_i93_send_cmd_inventory(p_uid, including_afi, afi); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3220 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3221 | if (status == NFC_STATUS_OK) { |
| 3222 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3223 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3224 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3225 | return (status); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | /******************************************************************************* |
| 3229 | ** |
| 3230 | ** Function RW_I93StayQuiet |
| 3231 | ** |
| 3232 | ** Description This function send Inventory command |
| 3233 | ** |
| 3234 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3235 | ** |
| 3236 | ** Returns NFC_STATUS_OK if success |
| 3237 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3238 | ** NFC_STATUS_BUSY if busy |
| 3239 | ** NFC_STATUS_FAILED if other error |
| 3240 | ** |
| 3241 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3242 | tNFC_STATUS RW_I93StayQuiet(void) { |
| 3243 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3244 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3245 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3246 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3247 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3248 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3249 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3250 | return NFC_STATUS_BUSY; |
| 3251 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3252 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3253 | status = rw_i93_send_cmd_stay_quiet(); |
| 3254 | if (status == NFC_STATUS_OK) { |
| 3255 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3256 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3257 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3258 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | /******************************************************************************* |
| 3262 | ** |
| 3263 | ** Function RW_I93ReadSingleBlock |
| 3264 | ** |
| 3265 | ** Description This function send Read Single Block command |
| 3266 | ** |
| 3267 | ** RW_I93_RESPONSE_EVT will be returned |
| 3268 | ** |
| 3269 | ** Returns NFC_STATUS_OK if success |
| 3270 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3271 | ** NFC_STATUS_BUSY if busy |
| 3272 | ** NFC_STATUS_FAILED if other error |
| 3273 | ** |
| 3274 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3275 | tNFC_STATUS RW_I93ReadSingleBlock(uint16_t block_number) { |
| 3276 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3277 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3278 | DLOG_IF(INFO, nfc_debug_enabled) |
| 3279 | << StringPrintf("block_number:0x%02X", block_number); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3280 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3281 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3282 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3283 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3284 | return NFC_STATUS_BUSY; |
| 3285 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3286 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3287 | status = rw_i93_send_cmd_read_single_block(block_number, false); |
| 3288 | if (status == NFC_STATUS_OK) { |
| 3289 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3290 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3291 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3292 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | /******************************************************************************* |
| 3296 | ** |
| 3297 | ** Function RW_I93WriteSingleBlock |
| 3298 | ** |
| 3299 | ** Description This function send Write Single Block command |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 3300 | ** Application must get block size first by calling |
| 3301 | ** RW_I93GetSysInfo(). |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3302 | ** |
| 3303 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3304 | ** |
| 3305 | ** Returns NFC_STATUS_OK if success |
| 3306 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3307 | ** NFC_STATUS_BUSY if busy |
| 3308 | ** NFC_STATUS_FAILED if other error |
| 3309 | ** |
| 3310 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3311 | tNFC_STATUS RW_I93WriteSingleBlock(uint16_t block_number, uint8_t* p_data) { |
| 3312 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3313 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3314 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3315 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3316 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3317 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3318 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3319 | return NFC_STATUS_BUSY; |
| 3320 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3321 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3322 | if (rw_cb.tcb.i93.block_size == 0) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3323 | LOG(ERROR) << StringPrintf("Block size is unknown"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3324 | return NFC_STATUS_FAILED; |
| 3325 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3326 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3327 | status = rw_i93_send_cmd_write_single_block(block_number, p_data); |
| 3328 | if (status == NFC_STATUS_OK) { |
| 3329 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3330 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3331 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3332 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | /******************************************************************************* |
| 3336 | ** |
| 3337 | ** Function RW_I93LockBlock |
| 3338 | ** |
| 3339 | ** Description This function send Lock Block command |
| 3340 | ** |
| 3341 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3342 | ** |
| 3343 | ** Returns NFC_STATUS_OK if success |
| 3344 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3345 | ** NFC_STATUS_BUSY if busy |
| 3346 | ** NFC_STATUS_FAILED if other error |
| 3347 | ** |
| 3348 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3349 | tNFC_STATUS RW_I93LockBlock(uint8_t block_number) { |
| 3350 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3351 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3352 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3353 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3354 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3355 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3356 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3357 | return NFC_STATUS_BUSY; |
| 3358 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3359 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3360 | status = rw_i93_send_cmd_lock_block(block_number); |
| 3361 | if (status == NFC_STATUS_OK) { |
| 3362 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3363 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3364 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3365 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | /******************************************************************************* |
| 3369 | ** |
| 3370 | ** Function RW_I93ReadMultipleBlocks |
| 3371 | ** |
| 3372 | ** Description This function send Read Multiple Blocks command |
| 3373 | ** |
| 3374 | ** RW_I93_RESPONSE_EVT will be returned |
| 3375 | ** |
| 3376 | ** Returns NFC_STATUS_OK if success |
| 3377 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3378 | ** NFC_STATUS_BUSY if busy |
| 3379 | ** NFC_STATUS_FAILED if other error |
| 3380 | ** |
| 3381 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3382 | tNFC_STATUS RW_I93ReadMultipleBlocks(uint16_t first_block_number, |
| 3383 | uint16_t number_blocks) { |
| 3384 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3385 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3386 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3387 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3388 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3389 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3390 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3391 | return NFC_STATUS_BUSY; |
| 3392 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3393 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3394 | status = rw_i93_send_cmd_read_multi_blocks(first_block_number, number_blocks); |
| 3395 | if (status == NFC_STATUS_OK) { |
| 3396 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3397 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3398 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3399 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | /******************************************************************************* |
| 3403 | ** |
| 3404 | ** Function RW_I93WriteMultipleBlocks |
| 3405 | ** |
| 3406 | ** Description This function send Write Multiple Blocks command |
| 3407 | ** |
| 3408 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3409 | ** |
| 3410 | ** Returns NFC_STATUS_OK if success |
| 3411 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3412 | ** NFC_STATUS_BUSY if busy |
| 3413 | ** NFC_STATUS_FAILED if other error |
| 3414 | ** |
| 3415 | *******************************************************************************/ |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 3416 | tNFC_STATUS RW_I93WriteMultipleBlocks(uint16_t first_block_number, |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3417 | uint16_t number_blocks, uint8_t* p_data) { |
| 3418 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3419 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3420 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3421 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3422 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3423 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3424 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3425 | return NFC_STATUS_BUSY; |
| 3426 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3427 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3428 | if (rw_cb.tcb.i93.block_size == 0) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3429 | LOG(ERROR) << StringPrintf("Block size is unknown"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3430 | return NFC_STATUS_FAILED; |
| 3431 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3432 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3433 | status = rw_i93_send_cmd_write_multi_blocks(first_block_number, number_blocks, |
| 3434 | p_data); |
| 3435 | if (status == NFC_STATUS_OK) { |
| 3436 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3437 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3438 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3439 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | /******************************************************************************* |
| 3443 | ** |
| 3444 | ** Function RW_I93Select |
| 3445 | ** |
| 3446 | ** Description This function send Select command |
| 3447 | ** |
| 3448 | ** UID[0]: 0xE0, MSB |
| 3449 | ** UID[1]: IC Mfg Code |
| 3450 | ** ... |
| 3451 | ** UID[7]: LSB |
| 3452 | ** |
| 3453 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3454 | ** |
| 3455 | ** Returns NFC_STATUS_OK if success |
| 3456 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3457 | ** NFC_STATUS_BUSY if busy |
| 3458 | ** NFC_STATUS_FAILED if other error |
| 3459 | ** |
| 3460 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3461 | tNFC_STATUS RW_I93Select(uint8_t* p_uid) { |
| 3462 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3463 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3464 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3465 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3466 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3467 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3468 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3469 | return NFC_STATUS_BUSY; |
| 3470 | } |
| 3471 | |
| 3472 | if (p_uid) { |
| 3473 | status = rw_i93_send_cmd_select(p_uid); |
| 3474 | if (status == NFC_STATUS_OK) { |
| 3475 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3476 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3477 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3478 | LOG(ERROR) << StringPrintf("UID shall be provided"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3479 | status = NFC_STATUS_FAILED; |
| 3480 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3481 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3482 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | /******************************************************************************* |
| 3486 | ** |
| 3487 | ** Function RW_I93ResetToReady |
| 3488 | ** |
| 3489 | ** Description This function send Reset To Ready command |
| 3490 | ** |
| 3491 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3492 | ** |
| 3493 | ** Returns NFC_STATUS_OK if success |
| 3494 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3495 | ** NFC_STATUS_BUSY if busy |
| 3496 | ** NFC_STATUS_FAILED if other error |
| 3497 | ** |
| 3498 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3499 | tNFC_STATUS RW_I93ResetToReady(void) { |
| 3500 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3501 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3502 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3503 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3504 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3505 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3506 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3507 | return NFC_STATUS_BUSY; |
| 3508 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3509 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3510 | status = rw_i93_send_cmd_reset_to_ready(); |
| 3511 | if (status == NFC_STATUS_OK) { |
| 3512 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3513 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3514 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3515 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | /******************************************************************************* |
| 3519 | ** |
| 3520 | ** Function RW_I93WriteAFI |
| 3521 | ** |
| 3522 | ** Description This function send Write AFI command |
| 3523 | ** |
| 3524 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3525 | ** |
| 3526 | ** Returns NFC_STATUS_OK if success |
| 3527 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3528 | ** NFC_STATUS_BUSY if busy |
| 3529 | ** NFC_STATUS_FAILED if other error |
| 3530 | ** |
| 3531 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3532 | tNFC_STATUS RW_I93WriteAFI(uint8_t afi) { |
| 3533 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3534 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3535 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3536 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3537 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3538 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3539 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3540 | return NFC_STATUS_BUSY; |
| 3541 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3542 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3543 | status = rw_i93_send_cmd_write_afi(afi); |
| 3544 | if (status == NFC_STATUS_OK) { |
| 3545 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3546 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3547 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3548 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | /******************************************************************************* |
| 3552 | ** |
| 3553 | ** Function RW_I93LockAFI |
| 3554 | ** |
| 3555 | ** Description This function send Lock AFI command |
| 3556 | ** |
| 3557 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3558 | ** |
| 3559 | ** Returns NFC_STATUS_OK if success |
| 3560 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3561 | ** NFC_STATUS_BUSY if busy |
| 3562 | ** NFC_STATUS_FAILED if other error |
| 3563 | ** |
| 3564 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3565 | tNFC_STATUS RW_I93LockAFI(void) { |
| 3566 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3567 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3568 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3569 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3570 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3571 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3572 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3573 | return NFC_STATUS_BUSY; |
| 3574 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3575 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3576 | status = rw_i93_send_cmd_lock_afi(); |
| 3577 | if (status == NFC_STATUS_OK) { |
| 3578 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3579 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3580 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3581 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | /******************************************************************************* |
| 3585 | ** |
| 3586 | ** Function RW_I93WriteDSFID |
| 3587 | ** |
| 3588 | ** Description This function send Write DSFID command |
| 3589 | ** |
| 3590 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3591 | ** |
| 3592 | ** Returns NFC_STATUS_OK if success |
| 3593 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3594 | ** NFC_STATUS_BUSY if busy |
| 3595 | ** NFC_STATUS_FAILED if other error |
| 3596 | ** |
| 3597 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3598 | tNFC_STATUS RW_I93WriteDSFID(uint8_t dsfid) { |
| 3599 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3600 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3601 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3602 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3603 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3604 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3605 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3606 | return NFC_STATUS_BUSY; |
| 3607 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3608 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3609 | status = rw_i93_send_cmd_write_dsfid(dsfid); |
| 3610 | if (status == NFC_STATUS_OK) { |
| 3611 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3612 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3613 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3614 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | /******************************************************************************* |
| 3618 | ** |
| 3619 | ** Function RW_I93LockDSFID |
| 3620 | ** |
| 3621 | ** Description This function send Lock DSFID command |
| 3622 | ** |
| 3623 | ** RW_I93_CMD_CMPL_EVT will be returned |
| 3624 | ** |
| 3625 | ** Returns NFC_STATUS_OK if success |
| 3626 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3627 | ** NFC_STATUS_BUSY if busy |
| 3628 | ** NFC_STATUS_FAILED if other error |
| 3629 | ** |
| 3630 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3631 | tNFC_STATUS RW_I93LockDSFID(void) { |
| 3632 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3633 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3634 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3635 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3636 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3637 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3638 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3639 | return NFC_STATUS_BUSY; |
| 3640 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3641 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3642 | status = rw_i93_send_cmd_lock_dsfid(); |
| 3643 | if (status == NFC_STATUS_OK) { |
| 3644 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3645 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3646 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3647 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | /******************************************************************************* |
| 3651 | ** |
| 3652 | ** Function RW_I93GetSysInfo |
| 3653 | ** |
| 3654 | ** Description This function send Get System Information command |
| 3655 | ** |
| 3656 | ** RW_I93_RESPONSE_EVT will be returned |
| 3657 | ** |
| 3658 | ** Returns NFC_STATUS_OK if success |
| 3659 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3660 | ** NFC_STATUS_BUSY if busy |
| 3661 | ** NFC_STATUS_FAILED if other error |
| 3662 | ** |
| 3663 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3664 | tNFC_STATUS RW_I93GetSysInfo(uint8_t* p_uid) { |
| 3665 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3666 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3667 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3668 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3669 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3670 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3671 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3672 | return NFC_STATUS_BUSY; |
| 3673 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3674 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3675 | if (p_uid) { |
| 3676 | status = rw_i93_send_cmd_get_sys_info(p_uid, I93_FLAG_PROT_EXT_NO); |
| 3677 | } else { |
| 3678 | status = rw_i93_send_cmd_get_sys_info(NULL, I93_FLAG_PROT_EXT_NO); |
| 3679 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3680 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3681 | if (status == NFC_STATUS_OK) { |
| 3682 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3683 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3684 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3685 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | /******************************************************************************* |
| 3689 | ** |
| 3690 | ** Function RW_I93GetMultiBlockSecurityStatus |
| 3691 | ** |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 3692 | ** Description This function send Get Multiple Block Security Status |
| 3693 | ** command |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3694 | ** |
| 3695 | ** RW_I93_RESPONSE_EVT will be returned |
| 3696 | ** |
| 3697 | ** Returns NFC_STATUS_OK if success |
| 3698 | ** NFC_STATUS_NO_BUFFERS if out of buffer |
| 3699 | ** NFC_STATUS_BUSY if busy |
| 3700 | ** NFC_STATUS_FAILED if other error |
| 3701 | ** |
| 3702 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3703 | tNFC_STATUS RW_I93GetMultiBlockSecurityStatus(uint16_t first_block_number, |
| 3704 | uint16_t number_blocks) { |
| 3705 | tNFC_STATUS status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3706 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3707 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3708 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3709 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3710 | LOG(ERROR) << StringPrintf( |
| 3711 | "Unable to start command at state " |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3712 | "(0x%X)", |
| 3713 | rw_cb.tcb.i93.state); |
| 3714 | return NFC_STATUS_BUSY; |
| 3715 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3716 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3717 | status = |
| 3718 | rw_i93_send_cmd_get_multi_block_sec(first_block_number, number_blocks); |
| 3719 | if (status == NFC_STATUS_OK) { |
| 3720 | rw_cb.tcb.i93.state = RW_I93_STATE_BUSY; |
| 3721 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3722 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3723 | return status; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | /******************************************************************************* |
| 3727 | ** |
| 3728 | ** Function RW_I93DetectNDef |
| 3729 | ** |
| 3730 | ** Description This function performs NDEF detection procedure |
| 3731 | ** |
| 3732 | ** RW_I93_NDEF_DETECT_EVT will be returned |
| 3733 | ** |
| 3734 | ** Returns NFC_STATUS_OK if success |
| 3735 | ** NFC_STATUS_FAILED if busy or other error |
| 3736 | ** |
| 3737 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3738 | tNFC_STATUS RW_I93DetectNDef(void) { |
| 3739 | tNFC_STATUS status; |
| 3740 | tRW_I93_RW_SUBSTATE sub_state; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3741 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3742 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3743 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3744 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3745 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3746 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3747 | return NFC_STATUS_FAILED; |
| 3748 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3749 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3750 | if (rw_cb.tcb.i93.uid[0] != I93_UID_FIRST_BYTE) { |
| 3751 | status = rw_i93_send_cmd_inventory(NULL, false, 0x00); |
| 3752 | sub_state = RW_I93_SUBSTATE_WAIT_UID; |
| 3753 | } else if ((rw_cb.tcb.i93.num_block == 0) || |
| 3754 | (rw_cb.tcb.i93.block_size == 0)) { |
| 3755 | status = |
| 3756 | rw_i93_send_cmd_get_sys_info(rw_cb.tcb.i93.uid, I93_FLAG_PROT_EXT_NO); |
| 3757 | sub_state = RW_I93_SUBSTATE_WAIT_SYS_INFO; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3758 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3759 | /* clear all flags */ |
| 3760 | rw_cb.tcb.i93.intl_flags = 0; |
| 3761 | } else { |
| 3762 | /* read CC in the first block */ |
| 3763 | status = rw_i93_send_cmd_read_single_block(0x0000, false); |
| 3764 | sub_state = RW_I93_SUBSTATE_WAIT_CC; |
| 3765 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3766 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3767 | if (status == NFC_STATUS_OK) { |
| 3768 | rw_cb.tcb.i93.state = RW_I93_STATE_DETECT_NDEF; |
| 3769 | rw_cb.tcb.i93.sub_state = sub_state; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 3770 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3771 | /* clear flags except flag for 2 bytes of number of blocks */ |
| 3772 | rw_cb.tcb.i93.intl_flags &= RW_I93_FLAG_16BIT_NUM_BLOCK; |
| 3773 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3774 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3775 | return (status); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | /******************************************************************************* |
| 3779 | ** |
| 3780 | ** Function RW_I93ReadNDef |
| 3781 | ** |
| 3782 | ** Description This function performs NDEF read procedure |
| 3783 | ** Note: RW_I93DetectNDef () must be called before using this |
| 3784 | ** |
| 3785 | ** The following event will be returned |
| 3786 | ** RW_I93_NDEF_READ_EVT for each segmented NDEF message |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 3787 | ** RW_I93_NDEF_READ_CPLT_EVT for the last segment or |
| 3788 | ** complete NDEF |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3789 | ** RW_I93_NDEF_READ_FAIL_EVT for failure |
| 3790 | ** |
| 3791 | ** Returns NFC_STATUS_OK if success |
| 3792 | ** NFC_STATUS_FAILED if I93 is busy or other error |
| 3793 | ** |
| 3794 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3795 | tNFC_STATUS RW_I93ReadNDef(void) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3796 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3797 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3798 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3799 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3800 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3801 | return NFC_STATUS_FAILED; |
| 3802 | } |
| 3803 | |
| 3804 | if ((rw_cb.tcb.i93.tlv_type == I93_ICODE_TLV_TYPE_NDEF) && |
| 3805 | (rw_cb.tcb.i93.ndef_length > 0)) { |
| 3806 | rw_cb.tcb.i93.rw_offset = rw_cb.tcb.i93.ndef_tlv_start_offset; |
| 3807 | rw_cb.tcb.i93.rw_length = 0; |
| 3808 | |
| 3809 | if (rw_i93_get_next_blocks(rw_cb.tcb.i93.rw_offset) == NFC_STATUS_OK) { |
| 3810 | rw_cb.tcb.i93.state = RW_I93_STATE_READ_NDEF; |
| 3811 | } else { |
| 3812 | return NFC_STATUS_FAILED; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3813 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3814 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3815 | LOG(ERROR) << StringPrintf("No NDEF detected"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3816 | return NFC_STATUS_FAILED; |
| 3817 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3818 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3819 | return NFC_STATUS_OK; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | /******************************************************************************* |
| 3823 | ** |
| 3824 | ** Function RW_I93UpdateNDef |
| 3825 | ** |
| 3826 | ** Description This function performs NDEF update procedure |
| 3827 | ** Note: RW_I93DetectNDef () must be called before using this |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 3828 | ** Updating data must not be removed until returning |
| 3829 | ** event |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3830 | ** |
| 3831 | ** The following event will be returned |
| 3832 | ** RW_I93_NDEF_UPDATE_CPLT_EVT for complete |
| 3833 | ** RW_I93_NDEF_UPDATE_FAIL_EVT for failure |
| 3834 | ** |
| 3835 | ** Returns NFC_STATUS_OK if success |
| 3836 | ** NFC_STATUS_FAILED if I93 is busy or other error |
| 3837 | ** |
| 3838 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3839 | tNFC_STATUS RW_I93UpdateNDef(uint16_t length, uint8_t* p_data) { |
| 3840 | uint16_t block_number; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3841 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3842 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("length:%d", length); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3843 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3844 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3845 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3846 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3847 | return NFC_STATUS_FAILED; |
| 3848 | } |
| 3849 | |
| 3850 | if (rw_cb.tcb.i93.tlv_type == I93_ICODE_TLV_TYPE_NDEF) { |
| 3851 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_READ_ONLY) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3852 | LOG(ERROR) << StringPrintf("NDEF is read-only"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3853 | return NFC_STATUS_FAILED; |
| 3854 | } |
| 3855 | if (rw_cb.tcb.i93.max_ndef_length < length) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3856 | LOG(ERROR) << StringPrintf( |
| 3857 | "data (%d bytes) is more than max NDEF length " |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3858 | "(%d)", |
| 3859 | length, rw_cb.tcb.i93.max_ndef_length); |
| 3860 | return NFC_STATUS_FAILED; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3861 | } |
| 3862 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3863 | rw_cb.tcb.i93.ndef_length = length; |
| 3864 | rw_cb.tcb.i93.p_update_data = p_data; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3865 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3866 | /* read length field */ |
| 3867 | rw_cb.tcb.i93.rw_offset = rw_cb.tcb.i93.ndef_tlv_start_offset + 1; |
| 3868 | rw_cb.tcb.i93.rw_length = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3869 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3870 | block_number = rw_cb.tcb.i93.rw_offset / rw_cb.tcb.i93.block_size; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3871 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3872 | if (rw_i93_send_cmd_read_single_block(block_number, false) == |
| 3873 | NFC_STATUS_OK) { |
| 3874 | rw_cb.tcb.i93.state = RW_I93_STATE_UPDATE_NDEF; |
| 3875 | rw_cb.tcb.i93.sub_state = RW_I93_SUBSTATE_RESET_LEN; |
| 3876 | } else { |
| 3877 | return NFC_STATUS_FAILED; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3878 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3879 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3880 | LOG(ERROR) << StringPrintf("No NDEF detected"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3881 | return NFC_STATUS_FAILED; |
| 3882 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3883 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3884 | return NFC_STATUS_OK; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | /******************************************************************************* |
| 3888 | ** |
| 3889 | ** Function RW_I93FormatNDef |
| 3890 | ** |
| 3891 | ** Description This function performs formatting procedure |
| 3892 | ** |
| 3893 | ** RW_I93_FORMAT_CPLT_EVT will be returned |
| 3894 | ** |
| 3895 | ** Returns NFC_STATUS_OK if success |
| 3896 | ** NFC_STATUS_FAILED if busy or other error |
| 3897 | ** |
| 3898 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3899 | tNFC_STATUS RW_I93FormatNDef(void) { |
| 3900 | tNFC_STATUS status; |
| 3901 | tRW_I93_RW_SUBSTATE sub_state; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3902 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3903 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3904 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3905 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3906 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3907 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3908 | return NFC_STATUS_FAILED; |
| 3909 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3910 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3911 | if ((rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY) || |
| 3912 | (rw_cb.tcb.i93.product_version == RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY)) { |
| 3913 | /* These don't support GetSystemInformation and GetMultiBlockSecurityStatus |
| 3914 | */ |
| 3915 | rw_cb.tcb.i93.rw_offset = 0; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3916 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3917 | /* read blocks with option flag to get block security status */ |
| 3918 | status = rw_i93_send_cmd_read_single_block(0x0000, true); |
| 3919 | sub_state = RW_I93_SUBSTATE_CHECK_READ_ONLY; |
| 3920 | } else { |
| 3921 | status = rw_i93_send_cmd_inventory(rw_cb.tcb.i93.uid, false, 0x00); |
| 3922 | sub_state = RW_I93_SUBSTATE_WAIT_UID; |
| 3923 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3924 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3925 | if (status == NFC_STATUS_OK) { |
| 3926 | rw_cb.tcb.i93.state = RW_I93_STATE_FORMAT; |
| 3927 | rw_cb.tcb.i93.sub_state = sub_state; |
| 3928 | rw_cb.tcb.i93.intl_flags = 0; |
| 3929 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3930 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3931 | return (status); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | /******************************************************************************* |
| 3935 | ** |
| 3936 | ** Function RW_I93SetTagReadOnly |
| 3937 | ** |
| 3938 | ** Description This function performs NDEF read-only procedure |
| 3939 | ** Note: RW_I93DetectNDef () must be called before using this |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 3940 | ** Updating data must not be removed until returning |
| 3941 | ** event |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3942 | ** |
| 3943 | ** The RW_I93_SET_TAG_RO_EVT event will be returned. |
| 3944 | ** |
| 3945 | ** Returns NFC_STATUS_OK if success |
| 3946 | ** NFC_STATUS_FAILED if I93 is busy or other error |
| 3947 | ** |
| 3948 | *******************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3949 | tNFC_STATUS RW_I93SetTagReadOnly(void) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3950 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3951 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3952 | if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3953 | LOG(ERROR) << StringPrintf("Unable to start command at state (0x%X)", |
| 3954 | rw_cb.tcb.i93.state); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3955 | return NFC_STATUS_FAILED; |
| 3956 | } |
| 3957 | |
| 3958 | if (rw_cb.tcb.i93.tlv_type == I93_ICODE_TLV_TYPE_NDEF) { |
| 3959 | if (rw_cb.tcb.i93.intl_flags & RW_I93_FLAG_READ_ONLY) { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3960 | LOG(ERROR) << StringPrintf("NDEF is already read-only"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3961 | return NFC_STATUS_FAILED; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3962 | } |
| 3963 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3964 | /* get CC in the first block */ |
| 3965 | if (rw_i93_send_cmd_read_single_block(0, false) == NFC_STATUS_OK) { |
| 3966 | rw_cb.tcb.i93.state = RW_I93_STATE_SET_READ_ONLY; |
| 3967 | rw_cb.tcb.i93.sub_state = RW_I93_SUBSTATE_WAIT_CC; |
| 3968 | } else { |
| 3969 | return NFC_STATUS_FAILED; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3970 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3971 | } else { |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3972 | LOG(ERROR) << StringPrintf("No NDEF detected"); |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3973 | return NFC_STATUS_FAILED; |
| 3974 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3975 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3976 | return NFC_STATUS_OK; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | /***************************************************************************** |
| 3980 | ** |
| 3981 | ** Function RW_I93PresenceCheck |
| 3982 | ** |
| 3983 | ** Description Check if the tag is still in the field. |
| 3984 | ** |
| 3985 | ** The RW_I93_PRESENCE_CHECK_EVT w/ status is used to indicate |
| 3986 | ** presence or non-presence. |
| 3987 | ** |
| 3988 | ** Returns NFC_STATUS_OK, if raw data frame sent |
Ruchi Kandoi | 552f2b7 | 2017-01-28 16:22:55 -0800 | [diff] [blame] | 3989 | ** NFC_STATUS_NO_BUFFERS: unable to allocate a buffer for this |
| 3990 | ** operation |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3991 | ** NFC_STATUS_FAILED: other error |
| 3992 | ** |
| 3993 | *****************************************************************************/ |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 3994 | tNFC_STATUS RW_I93PresenceCheck(void) { |
| 3995 | tNFC_STATUS status; |
| 3996 | tRW_DATA evt_data; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3997 | |
Ruchi Kandoi | 6767aec | 2017-09-26 09:46:26 -0700 | [diff] [blame] | 3998 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 3999 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4000 | if (!rw_cb.p_cback) { |
| 4001 | return NFC_STATUS_FAILED; |
| 4002 | } else if (rw_cb.tcb.i93.state == RW_I93_STATE_NOT_ACTIVATED) { |
| 4003 | evt_data.status = NFC_STATUS_FAILED; |
| 4004 | (*rw_cb.p_cback)(RW_T4T_PRESENCE_CHECK_EVT, &evt_data); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4005 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4006 | return NFC_STATUS_OK; |
| 4007 | } else if (rw_cb.tcb.i93.state != RW_I93_STATE_IDLE) { |
| 4008 | return NFC_STATUS_BUSY; |
| 4009 | } else { |
| 4010 | /* The support of AFI by the VICC is optional, so do not include AFI */ |
| 4011 | status = rw_i93_send_cmd_inventory(rw_cb.tcb.i93.uid, false, 0x00); |
| 4012 | |
| 4013 | if (status == NFC_STATUS_OK) { |
| 4014 | /* do not retry during presence check */ |
| 4015 | rw_cb.tcb.i93.retry_count = RW_MAX_RETRIES; |
| 4016 | rw_cb.tcb.i93.state = RW_I93_STATE_PRESENCE_CHECK; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4017 | } |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4018 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4019 | |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4020 | return (status); |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4021 | } |
| 4022 | |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4023 | /******************************************************************************* |
| 4024 | ** |
| 4025 | ** Function rw_i93_get_state_name |
| 4026 | ** |
| 4027 | ** Description This function returns the state name. |
| 4028 | ** |
| 4029 | ** NOTE conditionally compiled to save memory. |
| 4030 | ** |
| 4031 | ** Returns pointer to the name |
| 4032 | ** |
| 4033 | *******************************************************************************/ |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4034 | static std::string rw_i93_get_state_name(uint8_t state) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4035 | switch (state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4036 | case RW_I93_STATE_NOT_ACTIVATED: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4037 | return "NOT_ACTIVATED"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4038 | case RW_I93_STATE_IDLE: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4039 | return "IDLE"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4040 | case RW_I93_STATE_BUSY: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4041 | return "BUSY"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4042 | case RW_I93_STATE_DETECT_NDEF: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4043 | return "NDEF_DETECTION"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4044 | case RW_I93_STATE_READ_NDEF: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4045 | return "READ_NDEF"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4046 | case RW_I93_STATE_UPDATE_NDEF: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4047 | return "UPDATE_NDEF"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4048 | case RW_I93_STATE_FORMAT: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4049 | return "FORMAT"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4050 | case RW_I93_STATE_SET_READ_ONLY: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4051 | return "SET_READ_ONLY"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4052 | case RW_I93_STATE_PRESENCE_CHECK: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4053 | return "PRESENCE_CHECK"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4054 | default: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4055 | return "???? UNKNOWN STATE"; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4056 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | /******************************************************************************* |
| 4060 | ** |
| 4061 | ** Function rw_i93_get_sub_state_name |
| 4062 | ** |
| 4063 | ** Description This function returns the sub_state name. |
| 4064 | ** |
| 4065 | ** NOTE conditionally compiled to save memory. |
| 4066 | ** |
| 4067 | ** Returns pointer to the name |
| 4068 | ** |
| 4069 | *******************************************************************************/ |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4070 | static std::string rw_i93_get_sub_state_name(uint8_t sub_state) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4071 | switch (sub_state) { |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4072 | case RW_I93_SUBSTATE_WAIT_UID: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4073 | return "WAIT_UID"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4074 | case RW_I93_SUBSTATE_WAIT_SYS_INFO: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4075 | return "WAIT_SYS_INFO"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4076 | case RW_I93_SUBSTATE_WAIT_CC: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4077 | return "WAIT_CC"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4078 | case RW_I93_SUBSTATE_SEARCH_NDEF_TLV: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4079 | return "SEARCH_NDEF_TLV"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4080 | case RW_I93_SUBSTATE_CHECK_LOCK_STATUS: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4081 | return "CHECK_LOCK_STATUS"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4082 | case RW_I93_SUBSTATE_RESET_LEN: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4083 | return "RESET_LEN"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4084 | case RW_I93_SUBSTATE_WRITE_NDEF: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4085 | return "WRITE_NDEF"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4086 | case RW_I93_SUBSTATE_UPDATE_LEN: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4087 | return "UPDATE_LEN"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4088 | case RW_I93_SUBSTATE_WAIT_RESET_DSFID_AFI: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4089 | return "WAIT_RESET_DSFID_AFI"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4090 | case RW_I93_SUBSTATE_CHECK_READ_ONLY: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4091 | return "CHECK_READ_ONLY"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4092 | case RW_I93_SUBSTATE_WRITE_CC_NDEF_TLV: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4093 | return "WRITE_CC_NDEF_TLV"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4094 | case RW_I93_SUBSTATE_WAIT_UPDATE_CC: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4095 | return "WAIT_UPDATE_CC"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4096 | case RW_I93_SUBSTATE_LOCK_NDEF_TLV: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4097 | return "LOCK_NDEF_TLV"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4098 | case RW_I93_SUBSTATE_WAIT_LOCK_CC: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4099 | return "WAIT_LOCK_CC"; |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4100 | default: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4101 | return "???? UNKNOWN SUBSTATE"; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4102 | } |
The Android Open Source Project | e9df6ba | 2012-12-13 14:55:37 -0800 | [diff] [blame] | 4103 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4104 | |
| 4105 | /******************************************************************************* |
| 4106 | ** |
| 4107 | ** Function rw_i93_get_tag_name |
| 4108 | ** |
| 4109 | ** Description This function returns the tag name. |
| 4110 | ** |
| 4111 | ** NOTE conditionally compiled to save memory. |
| 4112 | ** |
| 4113 | ** Returns pointer to the name |
| 4114 | ** |
| 4115 | *******************************************************************************/ |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4116 | static std::string rw_i93_get_tag_name(uint8_t product_version) { |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4117 | switch (product_version) { |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4118 | case RW_I93_ICODE_SLI: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4119 | return "SLI/SLIX"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4120 | case RW_I93_ICODE_SLI_S: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4121 | return "SLI-S/SLIX-S"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4122 | case RW_I93_ICODE_SLI_L: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4123 | return "SLI-L/SLIX-L"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4124 | case RW_I93_TAG_IT_HF_I_PLUS_INLAY: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4125 | return "Tag-it HF-I Plus Inlay"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4126 | case RW_I93_TAG_IT_HF_I_PLUS_CHIP: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4127 | return "Tag-it HF-I Plus Chip"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4128 | case RW_I93_TAG_IT_HF_I_STD_CHIP_INLAY: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4129 | return "Tag-it HF-I Standard Chip/Inlyas"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4130 | case RW_I93_TAG_IT_HF_I_PRO_CHIP_INLAY: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4131 | return "Tag-it HF-I Pro Chip/Inlays"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4132 | case RW_I93_STM_LRI1K: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4133 | return "LRi1K"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4134 | case RW_I93_STM_LRI2K: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4135 | return "LRi2K"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4136 | case RW_I93_STM_LRIS2K: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4137 | return "LRiS2K"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4138 | case RW_I93_STM_LRIS64K: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4139 | return "LRiS64K"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4140 | case RW_I93_STM_M24LR64_R: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4141 | return "M24LR64"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4142 | case RW_I93_STM_M24LR04E_R: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4143 | return "M24LR04E"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4144 | case RW_I93_STM_M24LR16E_R: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4145 | return "M24LR16E"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4146 | case RW_I93_STM_M24LR64E_R: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4147 | return "M24LR64E"; |
Raphael Collado | 867d5c3 | 2017-03-27 12:49:40 +0200 | [diff] [blame] | 4148 | case RW_I93_STM_ST25DV04K: |
| 4149 | return "ST25DV04"; |
| 4150 | case RW_I93_STM_ST25DVHIK: |
| 4151 | return "ST25DV"; |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4152 | case RW_I93_UNKNOWN_PRODUCT: |
| 4153 | default: |
Ruchi Kandoi | 7dab0e5 | 2017-08-03 13:09:49 -0700 | [diff] [blame] | 4154 | return "UNKNOWN"; |
Ruchi Kandoi | 6fca02d | 2017-01-30 14:28:16 -0800 | [diff] [blame] | 4155 | } |
Evan Chu | 85b7e84 | 2013-01-18 11:02:50 -0500 | [diff] [blame] | 4156 | } |