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