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