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