nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2010-2014 Broadcom Corporation |
| 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 | * |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 21 | * This file contains the implementation for Type 2 tag in Reader/Writer |
| 22 | * mode. |
| 23 | * |
| 24 | ******************************************************************************/ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 25 | #include <string> |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 26 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 27 | #include <android-base/stringprintf.h> |
| 28 | #include <base/logging.h> |
| 29 | |
| 30 | #include "nfc_target.h" |
| 31 | |
| 32 | #include "bt_types.h" |
| 33 | #include "gki.h" |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 34 | #include "nci_hmsgs.h" |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 35 | #include "nfc_api.h" |
| 36 | #include "nfc_int.h" |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 37 | #include "rw_api.h" |
| 38 | #include "rw_int.h" |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 39 | |
| 40 | using android::base::StringPrintf; |
| 41 | |
| 42 | extern bool nfc_debug_enabled; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 43 | |
| 44 | /* Static local functions */ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 45 | static void rw_t2t_proc_data(uint8_t conn_id, tNFC_DATA_CEVT* p_data); |
| 46 | static tNFC_STATUS rw_t2t_send_cmd(uint8_t opcode, uint8_t* p_dat); |
| 47 | static void rw_t2t_process_error(void); |
| 48 | static void rw_t2t_process_frame_error(void); |
| 49 | static void rw_t2t_handle_presence_check_rsp(tNFC_STATUS status); |
| 50 | static void rw_t2t_resume_op(void); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 51 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 52 | static std::string rw_t2t_get_state_name(uint8_t state); |
| 53 | static std::string rw_t2t_get_substate_name(uint8_t substate); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 54 | |
| 55 | /******************************************************************************* |
| 56 | ** |
| 57 | ** Function rw_t2t_proc_data |
| 58 | ** |
| 59 | ** Description This function handles data evt received from NFC Controller. |
| 60 | ** |
| 61 | ** Returns none |
| 62 | ** |
| 63 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 64 | static void rw_t2t_proc_data(uint8_t conn_id, tNFC_DATA_CEVT* p_data) { |
| 65 | tRW_EVENT rw_event = RW_RAW_FRAME_EVT; |
| 66 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 67 | NFC_HDR* p_pkt = p_data->p_data; |
| 68 | bool b_notify = true; |
| 69 | bool b_release = true; |
| 70 | uint8_t* p; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 71 | tRW_READ_DATA evt_data = {}; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 72 | tT2T_CMD_RSP_INFO* p_cmd_rsp_info = |
| 73 | (tT2T_CMD_RSP_INFO*)rw_cb.tcb.t2t.p_cmd_rsp_info; |
| 74 | tRW_DETECT_NDEF_DATA ndef_data; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 75 | uint8_t begin_state = p_t2t->state; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 76 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 77 | if ((p_t2t->state == RW_T2T_STATE_IDLE) || (p_cmd_rsp_info == NULL)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 78 | DLOG_IF(INFO, nfc_debug_enabled) |
| 79 | << StringPrintf("RW T2T Raw Frame: Len [0x%X] Status [%s]", p_pkt->len, |
| 80 | NFC_GetStatusName(p_data->status).c_str()); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 81 | evt_data.status = p_data->status; |
| 82 | evt_data.p_data = p_pkt; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 83 | tRW_DATA rw_data; |
| 84 | rw_data.data = evt_data; |
| 85 | (*rw_cb.p_cback)(RW_T2T_RAW_FRAME_EVT, &rw_data); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 86 | return; |
| 87 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 88 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 89 | /* Update rx stats */ |
| 90 | rw_main_update_rx_stats(p_pkt->len); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 91 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 92 | /* Stop timer as response is received */ |
| 93 | nfc_stop_quick_timer(&p_t2t->t2_timer); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 94 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 95 | DLOG_IF(INFO, nfc_debug_enabled) |
| 96 | << StringPrintf("RW RECV [%s]:0x%x RSP", t2t_info_to_str(p_cmd_rsp_info), |
| 97 | p_cmd_rsp_info->opcode); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 98 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 99 | if (((p_pkt->len != p_cmd_rsp_info->rsp_len) && |
| 100 | (p_pkt->len != p_cmd_rsp_info->nack_rsp_len) && |
| 101 | (p_t2t->substate != RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR)) || |
| 102 | (p_t2t->state == RW_T2T_STATE_HALT)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 103 | LOG(ERROR) << StringPrintf("T2T Frame error. state=%s ", |
| 104 | rw_t2t_get_state_name(p_t2t->state).c_str()); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 105 | if (p_t2t->state != RW_T2T_STATE_HALT) { |
| 106 | /* Retrasmit the last sent command if retry-count < max retry */ |
| 107 | rw_t2t_process_frame_error(); |
| 108 | p_t2t->check_tag_halt = false; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 109 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 110 | GKI_freebuf(p_pkt); |
| 111 | return; |
| 112 | } |
| 113 | rw_cb.cur_retry = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 114 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 115 | /* Assume the data is just the response byte sequence */ |
| 116 | p = (uint8_t*)(p_pkt + 1) + p_pkt->offset; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 117 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 118 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 119 | "rw_t2t_proc_data State: %u conn_id: %u len: %u data[0]: 0x%02x", |
| 120 | p_t2t->state, conn_id, p_pkt->len, *p); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 121 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 122 | evt_data.p_data = NULL; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 123 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 124 | if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR_SUPPORT) { |
| 125 | /* The select process happens in two steps */ |
| 126 | if ((*p & 0x0f) == T2T_RSP_ACK) { |
| 127 | if (rw_t2t_sector_change(p_t2t->select_sector) == NFC_STATUS_OK) |
| 128 | b_notify = false; |
| 129 | else |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 130 | evt_data.status = NFC_STATUS_FAILED; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 131 | } else { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 132 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 133 | "rw_t2t_proc_data - Received NACK response(0x%x) to SEC-SELCT CMD", |
| 134 | (*p & 0x0f)); |
| 135 | evt_data.status = NFC_STATUS_REJECTED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 136 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 137 | } else if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR) { |
| 138 | evt_data.status = NFC_STATUS_FAILED; |
| 139 | } else if ((p_pkt->len != p_cmd_rsp_info->rsp_len) || |
| 140 | ((p_cmd_rsp_info->opcode == T2T_CMD_WRITE) && |
| 141 | ((*p & 0x0f) != T2T_RSP_ACK))) { |
| 142 | /* Received NACK response */ |
| 143 | evt_data.p_data = p_pkt; |
| 144 | if (p_t2t->state == RW_T2T_STATE_READ) b_release = false; |
| 145 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 146 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 147 | "rw_t2t_proc_data - Received NACK response(0x%x)", (*p & 0x0f)); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 148 | |
| 149 | if (!p_t2t->check_tag_halt) { |
| 150 | /* Just received first NACK. Retry just one time to find if tag went in to |
| 151 | * HALT State */ |
| 152 | b_notify = false; |
| 153 | rw_t2t_process_error(); |
| 154 | /* Assume Tag is in HALT State, untill we get response to retry command */ |
| 155 | p_t2t->check_tag_halt = true; |
| 156 | } else { |
| 157 | p_t2t->check_tag_halt = false; |
| 158 | /* Got consecutive NACK so tag not really halt after first NACK, but |
| 159 | * current operation failed */ |
| 160 | evt_data.status = NFC_STATUS_FAILED; |
| 161 | } |
| 162 | } else { |
| 163 | /* If the response length indicates positive response or cannot be known |
| 164 | * from length then assume success */ |
| 165 | evt_data.status = NFC_STATUS_OK; |
| 166 | p_t2t->check_tag_halt = false; |
| 167 | |
| 168 | /* The response data depends on what the current operation was */ |
| 169 | switch (p_t2t->state) { |
| 170 | case RW_T2T_STATE_CHECK_PRESENCE: |
| 171 | b_notify = false; |
| 172 | rw_t2t_handle_presence_check_rsp(NFC_STATUS_OK); |
| 173 | break; |
| 174 | |
| 175 | case RW_T2T_STATE_READ: |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 176 | evt_data.p_data = p_pkt; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 177 | b_release = false; |
| 178 | if (p_t2t->block_read == 0) { |
| 179 | p_t2t->b_read_hdr = true; |
| 180 | memcpy(p_t2t->tag_hdr, p, T2T_READ_DATA_LEN); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 181 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 182 | break; |
| 183 | |
| 184 | case RW_T2T_STATE_WRITE: |
| 185 | /* Write operation completed successfully */ |
| 186 | break; |
| 187 | |
| 188 | default: |
| 189 | /* NDEF/other Tlv Operation/Format-Tag/Config Tag as Read only */ |
| 190 | b_notify = false; |
| 191 | rw_t2t_handle_rsp(p); |
| 192 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 193 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 194 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 195 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 196 | if (b_notify) { |
| 197 | rw_event = rw_t2t_info_to_event(p_cmd_rsp_info); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 198 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 199 | if (rw_event == RW_T2T_NDEF_DETECT_EVT) { |
| 200 | ndef_data.status = evt_data.status; |
| 201 | ndef_data.protocol = NFC_PROTOCOL_T2T; |
| 202 | ndef_data.flags = RW_NDEF_FL_UNKNOWN; |
| 203 | if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_LOCKS) |
| 204 | ndef_data.flags = RW_NDEF_FL_FORMATED; |
| 205 | ndef_data.max_size = 0; |
| 206 | ndef_data.cur_size = 0; |
| 207 | /* Move back to idle state */ |
| 208 | rw_t2t_handle_op_complete(); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 209 | tRW_DATA rw_data; |
| 210 | rw_data.ndef = ndef_data; |
| 211 | (*rw_cb.p_cback)(rw_event, &rw_data); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 212 | } else { |
| 213 | /* Move back to idle state */ |
| 214 | rw_t2t_handle_op_complete(); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 215 | tRW_DATA rw_data; |
| 216 | rw_data.data = evt_data; |
| 217 | (*rw_cb.p_cback)(rw_event, &rw_data); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 218 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 219 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 220 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 221 | if (b_release) GKI_freebuf(p_pkt); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 222 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 223 | if (begin_state != p_t2t->state) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 224 | DLOG_IF(INFO, nfc_debug_enabled) |
| 225 | << StringPrintf("RW T2T state changed:<%s> -> <%s>", |
| 226 | rw_t2t_get_state_name(begin_state).c_str(), |
| 227 | rw_t2t_get_state_name(p_t2t->state).c_str()); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 228 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /******************************************************************************* |
| 232 | ** |
| 233 | ** Function rw_t2t_conn_cback |
| 234 | ** |
| 235 | ** Description This callback function receives events/data from NFCC. |
| 236 | ** |
| 237 | ** Returns none |
| 238 | ** |
| 239 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 240 | void rw_t2t_conn_cback(uint8_t conn_id, tNFC_CONN_EVT event, |
| 241 | tNFC_CONN* p_data) { |
| 242 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 243 | tRW_READ_DATA evt_data; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 244 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 245 | DLOG_IF(INFO, nfc_debug_enabled) |
| 246 | << StringPrintf("rw_t2t_conn_cback: conn_id=%i, evt=%i", conn_id, event); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 247 | /* Only handle static conn_id */ |
| 248 | if (conn_id != NFC_RF_CONN_ID) { |
| 249 | return; |
| 250 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 251 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 252 | switch (event) { |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 253 | case NFC_CONN_CREATE_CEVT: |
| 254 | case NFC_CONN_CLOSE_CEVT: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 255 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 256 | |
| 257 | case NFC_DEACTIVATE_CEVT: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 258 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 259 | /* Display stats */ |
| 260 | rw_main_log_stats(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 261 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 262 | /* Stop t2t timer (if started) */ |
| 263 | nfc_stop_quick_timer(&p_t2t->t2_timer); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 264 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 265 | /* Free cmd buf for retransmissions */ |
| 266 | if (p_t2t->p_cur_cmd_buf) { |
| 267 | GKI_freebuf(p_t2t->p_cur_cmd_buf); |
| 268 | p_t2t->p_cur_cmd_buf = NULL; |
| 269 | } |
| 270 | /* Free cmd buf used to hold command before sector change */ |
| 271 | if (p_t2t->p_sec_cmd_buf) { |
| 272 | GKI_freebuf(p_t2t->p_sec_cmd_buf); |
| 273 | p_t2t->p_sec_cmd_buf = NULL; |
| 274 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 275 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 276 | p_t2t->state = RW_T2T_STATE_NOT_ACTIVATED; |
| 277 | NFC_SetStaticRfCback(NULL); |
| 278 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 279 | |
| 280 | case NFC_DATA_CEVT: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 281 | if (p_data != NULL) { |
| 282 | if ((p_data->data.status == NFC_STATUS_OK) || |
| 283 | (p_data->data.status == NFC_STATUS_CONTINUE)) { |
| 284 | rw_t2t_proc_data(conn_id, &(p_data->data)); |
| 285 | break; |
| 286 | } else if (p_data->data.p_data != NULL) { |
| 287 | /* Free the response buffer in case of error response */ |
| 288 | GKI_freebuf((NFC_HDR*)(p_data->data.p_data)); |
| 289 | p_data->data.p_data = NULL; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 290 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 291 | } |
| 292 | /* Data event with error status...fall through to NFC_ERROR_CEVT case */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 293 | |
| 294 | case NFC_ERROR_CEVT: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 295 | if ((p_t2t->state == RW_T2T_STATE_NOT_ACTIVATED) || |
| 296 | (p_t2t->state == RW_T2T_STATE_IDLE) || |
| 297 | (p_t2t->state == RW_T2T_STATE_HALT)) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 298 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 299 | rw_main_update_trans_error_stats(); |
| 300 | #endif /* RW_STATS_INCLUDED */ |
| 301 | if (event == NFC_ERROR_CEVT) |
| 302 | evt_data.status = (tNFC_STATUS)(*(uint8_t*)p_data); |
| 303 | else if (p_data) |
| 304 | evt_data.status = p_data->status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 305 | else |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 306 | evt_data.status = NFC_STATUS_FAILED; |
| 307 | |
| 308 | evt_data.p_data = NULL; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 309 | tRW_DATA rw_data; |
| 310 | rw_data.data = evt_data; |
| 311 | (*rw_cb.p_cback)(RW_T2T_INTF_ERROR_EVT, &rw_data); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 312 | break; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 313 | } |
| 314 | nfc_stop_quick_timer(&p_t2t->t2_timer); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 315 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 316 | rw_main_update_trans_error_stats(); |
| 317 | #endif |
| 318 | if (p_t2t->state == RW_T2T_STATE_CHECK_PRESENCE) { |
| 319 | if (p_t2t->check_tag_halt) { |
| 320 | p_t2t->state = RW_T2T_STATE_HALT; |
| 321 | rw_t2t_handle_presence_check_rsp(NFC_STATUS_REJECTED); |
| 322 | } else { |
| 323 | /* Move back to idle state */ |
| 324 | rw_t2t_handle_presence_check_rsp(NFC_STATUS_FAILED); |
| 325 | } |
| 326 | } else { |
| 327 | rw_t2t_process_error(); |
| 328 | } |
| 329 | break; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 330 | |
| 331 | default: |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 332 | break; |
| 333 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /******************************************************************************* |
| 337 | ** |
| 338 | ** Function rw_t2t_send_cmd |
| 339 | ** |
| 340 | ** Description This function composes a Type 2 Tag command and send it via |
| 341 | ** NCI to NFCC. |
| 342 | ** |
| 343 | ** Returns NFC_STATUS_OK if the command is successfuly sent to NCI |
| 344 | ** otherwise, error status |
| 345 | ** |
| 346 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 347 | tNFC_STATUS rw_t2t_send_cmd(uint8_t opcode, uint8_t* p_dat) { |
| 348 | tNFC_STATUS status = NFC_STATUS_FAILED; |
| 349 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 350 | const tT2T_CMD_RSP_INFO* p_cmd_rsp_info = t2t_cmd_to_rsp_info(opcode); |
| 351 | NFC_HDR* p_data; |
| 352 | uint8_t* p; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 353 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 354 | if (p_cmd_rsp_info) { |
| 355 | /* a valid opcode for RW */ |
| 356 | p_data = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
| 357 | if (p_data) { |
| 358 | p_t2t->p_cmd_rsp_info = (tT2T_CMD_RSP_INFO*)p_cmd_rsp_info; |
| 359 | p_data->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 360 | p = (uint8_t*)(p_data + 1) + p_data->offset; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 361 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 362 | UINT8_TO_STREAM(p, opcode); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 363 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 364 | if (p_dat) { |
| 365 | ARRAY_TO_STREAM(p, p_dat, (p_cmd_rsp_info->cmd_len - 1)); |
| 366 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 367 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 368 | p_data->len = p_cmd_rsp_info->cmd_len; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 369 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 370 | /* Indicate first attempt to send command, back up cmd buffer in case |
| 371 | * needed for retransmission */ |
| 372 | rw_cb.cur_retry = 0; |
| 373 | memcpy(p_t2t->p_cur_cmd_buf, p_data, |
| 374 | sizeof(NFC_HDR) + p_data->offset + p_data->len); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 375 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 376 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 377 | /* Update stats */ |
| 378 | rw_main_update_tx_stats(p_data->len, false); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 379 | #endif |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 380 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 381 | "RW SENT [%s]:0x%x CMD", t2t_info_to_str(p_cmd_rsp_info), |
| 382 | p_cmd_rsp_info->opcode); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 383 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 384 | status = NFC_SendData(NFC_RF_CONN_ID, p_data); |
| 385 | if (status == NFC_STATUS_OK) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 386 | nfc_start_quick_timer( |
| 387 | &p_t2t->t2_timer, NFC_TTYPE_RW_T2T_RESPONSE, |
| 388 | (RW_T2T_TOUT_RESP * QUICK_TIMER_TICKS_PER_SEC) / 1000); |
| 389 | } else { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 390 | LOG(ERROR) << StringPrintf( |
| 391 | "T2T NFC Send data failed. state=%s substate=%s ", |
| 392 | rw_t2t_get_state_name(p_t2t->state).c_str(), |
| 393 | rw_t2t_get_substate_name(p_t2t->substate).c_str()); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 394 | } |
| 395 | } else { |
| 396 | status = NFC_STATUS_NO_BUFFERS; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 397 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 398 | } |
| 399 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /******************************************************************************* |
| 403 | ** |
| 404 | ** Function rw_t2t_process_timeout |
| 405 | ** |
| 406 | ** Description handles timeout event |
| 407 | ** |
| 408 | ** Returns none |
| 409 | ** |
| 410 | *******************************************************************************/ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 411 | void rw_t2t_process_timeout() { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 412 | tRW_READ_DATA evt_data; |
| 413 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 414 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 415 | if (p_t2t->state == RW_T2T_STATE_CHECK_PRESENCE) { |
| 416 | if (p_t2t->check_tag_halt) { |
| 417 | p_t2t->state = RW_T2T_STATE_HALT; |
| 418 | rw_t2t_handle_presence_check_rsp(NFC_STATUS_REJECTED); |
| 419 | } else { |
| 420 | /* Move back to idle state */ |
| 421 | rw_t2t_handle_presence_check_rsp(NFC_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 422 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 423 | return; |
| 424 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 425 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 426 | if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR) { |
| 427 | p_t2t->sector = p_t2t->select_sector; |
| 428 | /* Here timeout is an acknowledgment for successfull sector change */ |
| 429 | if (p_t2t->state == RW_T2T_STATE_SELECT_SECTOR) { |
| 430 | /* Notify that select sector op is successfull */ |
| 431 | rw_t2t_handle_op_complete(); |
| 432 | evt_data.status = NFC_STATUS_OK; |
| 433 | evt_data.p_data = NULL; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 434 | tRW_DATA rw_data; |
| 435 | rw_data.data = evt_data; |
| 436 | (*rw_cb.p_cback)(RW_T2T_SELECT_CPLT_EVT, &rw_data); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 437 | } else { |
| 438 | /* Resume operation from where we stopped before sector change */ |
| 439 | rw_t2t_resume_op(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 440 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 441 | } else if (p_t2t->state != RW_T2T_STATE_IDLE) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 442 | LOG(ERROR) << StringPrintf("T2T timeout. state=%s ", |
| 443 | rw_t2t_get_state_name(p_t2t->state).c_str()); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 444 | /* Handle timeout error as no response to the command sent */ |
| 445 | rw_t2t_process_error(); |
| 446 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /******************************************************************************* |
| 450 | ** |
| 451 | ** Function rw_t2t_process_frame_error |
| 452 | ** |
| 453 | ** Description handles frame crc error |
| 454 | ** |
| 455 | ** Returns none |
| 456 | ** |
| 457 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 458 | static void rw_t2t_process_frame_error(void) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 459 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 460 | /* Update stats */ |
| 461 | rw_main_update_crc_error_stats(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 462 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 463 | /* Process the error */ |
| 464 | rw_t2t_process_error(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /******************************************************************************* |
| 468 | ** |
| 469 | ** Function rw_t2t_process_error |
| 470 | ** |
| 471 | ** Description Process error including Timeout, Frame error. This function |
| 472 | ** will retry atleast till RW_MAX_RETRIES before give up and |
| 473 | ** sending negative notification to upper layer |
| 474 | ** |
| 475 | ** Returns none |
| 476 | ** |
| 477 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 478 | static void rw_t2t_process_error(void) { |
| 479 | tRW_READ_DATA evt_data; |
| 480 | tRW_EVENT rw_event; |
| 481 | NFC_HDR* p_cmd_buf; |
| 482 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 483 | tT2T_CMD_RSP_INFO* p_cmd_rsp_info = |
| 484 | (tT2T_CMD_RSP_INFO*)rw_cb.tcb.t2t.p_cmd_rsp_info; |
| 485 | tRW_DETECT_NDEF_DATA ndef_data; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 486 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 487 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("State: %u", p_t2t->state); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 488 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 489 | /* Retry sending command if retry-count < max */ |
| 490 | if ((!p_t2t->check_tag_halt) && (rw_cb.cur_retry < RW_MAX_RETRIES)) { |
| 491 | /* retry sending the command */ |
| 492 | rw_cb.cur_retry++; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 493 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 494 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 495 | "T2T retransmission attempt %i of %i", rw_cb.cur_retry, RW_MAX_RETRIES); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 496 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 497 | /* allocate a new buffer for message */ |
| 498 | p_cmd_buf = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
| 499 | if (p_cmd_buf != NULL) { |
| 500 | memcpy(p_cmd_buf, p_t2t->p_cur_cmd_buf, sizeof(NFC_HDR) + |
| 501 | p_t2t->p_cur_cmd_buf->offset + |
| 502 | p_t2t->p_cur_cmd_buf->len); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 503 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 504 | /* Update stats */ |
| 505 | rw_main_update_tx_stats(p_cmd_buf->len, true); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 506 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 507 | if (NFC_SendData(NFC_RF_CONN_ID, p_cmd_buf) == NFC_STATUS_OK) { |
| 508 | /* Start timer for waiting for response */ |
| 509 | nfc_start_quick_timer( |
| 510 | &p_t2t->t2_timer, NFC_TTYPE_RW_T2T_RESPONSE, |
| 511 | (RW_T2T_TOUT_RESP * QUICK_TIMER_TICKS_PER_SEC) / 1000); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 512 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 513 | return; |
| 514 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 515 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 516 | } else { |
| 517 | if (p_t2t->check_tag_halt) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 518 | DLOG_IF(INFO, nfc_debug_enabled) |
| 519 | << StringPrintf("T2T Went to HALT State!"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 520 | } else { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 521 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 522 | "T2T maximum retransmission attempts reached (%i)", RW_MAX_RETRIES); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 523 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 524 | } |
| 525 | rw_event = rw_t2t_info_to_event(p_cmd_rsp_info); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 526 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 527 | /* update failure count */ |
| 528 | rw_main_update_fail_stats(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 529 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 530 | if (p_t2t->check_tag_halt) { |
| 531 | evt_data.status = NFC_STATUS_REJECTED; |
| 532 | p_t2t->state = RW_T2T_STATE_HALT; |
| 533 | } else { |
| 534 | evt_data.status = NFC_STATUS_TIMEOUT; |
| 535 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 536 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 537 | if (rw_event == RW_T2T_NDEF_DETECT_EVT) { |
| 538 | ndef_data.status = evt_data.status; |
| 539 | ndef_data.protocol = NFC_PROTOCOL_T2T; |
| 540 | ndef_data.flags = RW_NDEF_FL_UNKNOWN; |
| 541 | if (p_t2t->substate == RW_T2T_SUBSTATE_WAIT_READ_LOCKS) |
| 542 | ndef_data.flags = RW_NDEF_FL_FORMATED; |
| 543 | ndef_data.max_size = 0; |
| 544 | ndef_data.cur_size = 0; |
| 545 | /* If not Halt move to idle state */ |
| 546 | rw_t2t_handle_op_complete(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 547 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 548 | tRW_DATA rw_data; |
| 549 | rw_data.ndef = ndef_data; |
| 550 | (*rw_cb.p_cback)(rw_event, &rw_data); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 551 | } else { |
| 552 | evt_data.p_data = NULL; |
| 553 | /* If activated and not Halt move to idle state */ |
| 554 | if (p_t2t->state != RW_T2T_STATE_NOT_ACTIVATED) rw_t2t_handle_op_complete(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 555 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 556 | p_t2t->substate = RW_T2T_SUBSTATE_NONE; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 557 | tRW_DATA rw_data; |
| 558 | rw_data.data = evt_data; |
| 559 | (*rw_cb.p_cback)(rw_event, &rw_data); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 560 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /***************************************************************************** |
| 564 | ** |
| 565 | ** Function rw_t2t_handle_presence_check_rsp |
| 566 | ** |
| 567 | ** Description Handle response to presence check |
| 568 | ** |
| 569 | ** Returns Nothing |
| 570 | ** |
| 571 | *****************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 572 | void rw_t2t_handle_presence_check_rsp(tNFC_STATUS status) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 573 | tRW_DATA rw_data; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 574 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 575 | /* Notify, Tag is present or not */ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 576 | rw_data.data.status = status; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 577 | rw_t2t_handle_op_complete(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 578 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 579 | (*rw_cb.p_cback)(RW_T2T_PRESENCE_CHECK_EVT, &rw_data); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | /******************************************************************************* |
| 583 | ** |
| 584 | ** Function rw_t2t_resume_op |
| 585 | ** |
| 586 | ** Description This function will continue operation after moving to new |
| 587 | ** sector |
| 588 | ** |
| 589 | ** Returns tNFC_STATUS |
| 590 | ** |
| 591 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 592 | static void rw_t2t_resume_op(void) { |
| 593 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 594 | tRW_READ_DATA evt_data; |
| 595 | NFC_HDR* p_cmd_buf; |
| 596 | tRW_EVENT event; |
| 597 | const tT2T_CMD_RSP_INFO* p_cmd_rsp_info = |
| 598 | (tT2T_CMD_RSP_INFO*)rw_cb.tcb.t2t.p_cmd_rsp_info; |
| 599 | uint8_t* p; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 600 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 601 | /* Move back to the substate where we were before changing sector */ |
| 602 | p_t2t->substate = p_t2t->prev_substate; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 603 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 604 | p = (uint8_t*)(p_t2t->p_sec_cmd_buf + 1) + p_t2t->p_sec_cmd_buf->offset; |
| 605 | p_cmd_rsp_info = t2t_cmd_to_rsp_info((uint8_t)*p); |
| 606 | p_t2t->p_cmd_rsp_info = (tT2T_CMD_RSP_INFO*)p_cmd_rsp_info; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 607 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 608 | /* allocate a new buffer for message */ |
| 609 | p_cmd_buf = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
| 610 | if (p_cmd_buf != NULL) { |
| 611 | memcpy(p_cmd_buf, p_t2t->p_sec_cmd_buf, sizeof(NFC_HDR) + |
| 612 | p_t2t->p_sec_cmd_buf->offset + |
| 613 | p_t2t->p_sec_cmd_buf->len); |
| 614 | memcpy(p_t2t->p_cur_cmd_buf, p_t2t->p_sec_cmd_buf, |
| 615 | sizeof(NFC_HDR) + p_t2t->p_sec_cmd_buf->offset + |
| 616 | p_t2t->p_sec_cmd_buf->len); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 617 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 618 | #if (RW_STATS_INCLUDED == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 619 | /* Update stats */ |
| 620 | rw_main_update_tx_stats(p_cmd_buf->len, true); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 621 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 622 | if (NFC_SendData(NFC_RF_CONN_ID, p_cmd_buf) == NFC_STATUS_OK) { |
| 623 | /* Start timer for waiting for response */ |
| 624 | nfc_start_quick_timer( |
| 625 | &p_t2t->t2_timer, NFC_TTYPE_RW_T2T_RESPONSE, |
| 626 | (RW_T2T_TOUT_RESP * QUICK_TIMER_TICKS_PER_SEC) / 1000); |
| 627 | } else { |
| 628 | /* failure - could not send buffer */ |
| 629 | evt_data.p_data = NULL; |
| 630 | evt_data.status = NFC_STATUS_FAILED; |
| 631 | event = rw_t2t_info_to_event(p_cmd_rsp_info); |
| 632 | rw_t2t_handle_op_complete(); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 633 | tRW_DATA rw_data; |
| 634 | rw_data.data = evt_data; |
| 635 | (*rw_cb.p_cback)(event, &rw_data); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 636 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 637 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /******************************************************************************* |
| 641 | ** |
| 642 | ** Function rw_t2t_sector_change |
| 643 | ** |
| 644 | ** Description This function issues Type 2 Tag SECTOR-SELECT command |
| 645 | ** packet 1. |
| 646 | ** |
| 647 | ** Returns tNFC_STATUS |
| 648 | ** |
| 649 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 650 | tNFC_STATUS rw_t2t_sector_change(uint8_t sector) { |
| 651 | tNFC_STATUS status; |
| 652 | NFC_HDR* p_data; |
| 653 | uint8_t* p; |
| 654 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 655 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 656 | p_data = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
| 657 | if (p_data == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 658 | LOG(ERROR) << StringPrintf("rw_t2t_sector_change - No buffer"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 659 | return (NFC_STATUS_NO_BUFFERS); |
| 660 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 661 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 662 | p_data->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 663 | p = (uint8_t*)(p_data + 1) + p_data->offset; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 664 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 665 | UINT8_TO_BE_STREAM(p, sector); |
| 666 | UINT8_TO_BE_STREAM(p, 0x00); |
| 667 | UINT8_TO_BE_STREAM(p, 0x00); |
| 668 | UINT8_TO_BE_STREAM(p, 0x00); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 669 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 670 | p_data->len = 4; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 671 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 672 | status = NFC_SendData(NFC_RF_CONN_ID, p_data); |
| 673 | if (status == NFC_STATUS_OK) { |
| 674 | /* Passive rsp command and suppose not to get response to this command */ |
| 675 | p_t2t->p_cmd_rsp_info = NULL; |
| 676 | p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 677 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 678 | DLOG_IF(INFO, nfc_debug_enabled) |
| 679 | << StringPrintf("rw_t2t_sector_change Sent Second Command"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 680 | nfc_start_quick_timer( |
| 681 | &p_t2t->t2_timer, NFC_TTYPE_RW_T2T_RESPONSE, |
| 682 | (RW_T2T_SEC_SEL_TOUT_RESP * QUICK_TIMER_TICKS_PER_SEC) / 1000); |
| 683 | } else { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 684 | LOG(ERROR) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 685 | "rw_t2t_sector_change Send failed at rw_t2t_send_cmd, error: %u", |
| 686 | status); |
| 687 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 688 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 689 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /******************************************************************************* |
| 693 | ** |
| 694 | ** Function rw_t2t_read |
| 695 | ** |
| 696 | ** Description This function issues Type 2 Tag READ command for the |
| 697 | ** specified block. If the specified block is in different |
| 698 | ** sector then it first sends command to move to new sector |
| 699 | ** and after the tag moves to new sector it issues the read |
| 700 | ** command for the block. |
| 701 | ** |
| 702 | ** Returns tNFC_STATUS |
| 703 | ** |
| 704 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 705 | tNFC_STATUS rw_t2t_read(uint16_t block) { |
| 706 | tNFC_STATUS status; |
| 707 | uint8_t* p; |
| 708 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 709 | uint8_t sector_byte2[1]; |
| 710 | uint8_t read_cmd[1]; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 711 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 712 | read_cmd[0] = block % T2T_BLOCKS_PER_SECTOR; |
| 713 | if (p_t2t->sector != block / T2T_BLOCKS_PER_SECTOR) { |
| 714 | sector_byte2[0] = 0xFF; |
| 715 | /* First Move to new sector before sending Read command */ |
| 716 | status = rw_t2t_send_cmd(T2T_CMD_SEC_SEL, sector_byte2); |
| 717 | if (status == NFC_STATUS_OK) { |
| 718 | /* Prepare command that needs to be sent after sector change op is |
| 719 | * completed */ |
| 720 | p_t2t->select_sector = (uint8_t)(block / T2T_BLOCKS_PER_SECTOR); |
| 721 | p_t2t->p_sec_cmd_buf->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 722 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 723 | p = (uint8_t*)(p_t2t->p_sec_cmd_buf + 1) + p_t2t->p_sec_cmd_buf->offset; |
| 724 | UINT8_TO_BE_STREAM(p, T2T_CMD_READ); |
| 725 | UINT8_TO_BE_STREAM(p, read_cmd[0]); |
| 726 | p_t2t->p_sec_cmd_buf->len = 2; |
| 727 | p_t2t->block_read = block; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 728 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 729 | /* Backup the current substate to move back to this substate after |
| 730 | * changing sector */ |
| 731 | p_t2t->prev_substate = p_t2t->substate; |
| 732 | p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR_SUPPORT; |
| 733 | return NFC_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 734 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 735 | return NFC_STATUS_FAILED; |
| 736 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 737 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 738 | /* Send Read command as sector change is not needed */ |
| 739 | status = rw_t2t_send_cmd(T2T_CMD_READ, (uint8_t*)read_cmd); |
| 740 | if (status == NFC_STATUS_OK) { |
| 741 | p_t2t->block_read = block; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 742 | DLOG_IF(INFO, nfc_debug_enabled) |
| 743 | << StringPrintf("rw_t2t_read Sent Command for Block: %u", block); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 744 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 745 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 746 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /******************************************************************************* |
| 750 | ** |
| 751 | ** Function rw_t2t_write |
| 752 | ** |
| 753 | ** Description This function issues Type 2 Tag WRITE command for the |
| 754 | ** specified block. If the specified block is in different |
| 755 | ** sector then it first sends command to move to new sector |
| 756 | ** and after the tag moves to new sector it issues the write |
| 757 | ** command for the block. |
| 758 | ** |
| 759 | ** Returns tNFC_STATUS |
| 760 | ** |
| 761 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 762 | tNFC_STATUS rw_t2t_write(uint16_t block, uint8_t* p_write_data) { |
| 763 | tNFC_STATUS status; |
| 764 | uint8_t* p; |
| 765 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 766 | uint8_t write_cmd[T2T_WRITE_DATA_LEN + 1]; |
| 767 | uint8_t sector_byte2[1]; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 768 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 769 | p_t2t->block_written = block; |
| 770 | write_cmd[0] = (uint8_t)(block % T2T_BLOCKS_PER_SECTOR); |
| 771 | memcpy(&write_cmd[1], p_write_data, T2T_WRITE_DATA_LEN); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 772 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 773 | if (p_t2t->sector != block / T2T_BLOCKS_PER_SECTOR) { |
| 774 | sector_byte2[0] = 0xFF; |
| 775 | /* First Move to new sector before sending Write command */ |
| 776 | status = rw_t2t_send_cmd(T2T_CMD_SEC_SEL, sector_byte2); |
| 777 | if (status == NFC_STATUS_OK) { |
| 778 | /* Prepare command that needs to be sent after sector change op is |
| 779 | * completed */ |
| 780 | p_t2t->select_sector = (uint8_t)(block / T2T_BLOCKS_PER_SECTOR); |
| 781 | p_t2t->p_sec_cmd_buf->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE; |
| 782 | p = (uint8_t*)(p_t2t->p_sec_cmd_buf + 1) + p_t2t->p_sec_cmd_buf->offset; |
| 783 | UINT8_TO_BE_STREAM(p, T2T_CMD_WRITE); |
| 784 | memcpy(p, write_cmd, T2T_WRITE_DATA_LEN + 1); |
| 785 | p_t2t->p_sec_cmd_buf->len = 2 + T2T_WRITE_DATA_LEN; |
| 786 | p_t2t->block_written = block; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 787 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 788 | /* Backup the current substate to move back to this substate after |
| 789 | * changing sector */ |
| 790 | p_t2t->prev_substate = p_t2t->substate; |
| 791 | p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR_SUPPORT; |
| 792 | return NFC_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 793 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 794 | return NFC_STATUS_FAILED; |
| 795 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 796 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 797 | /* Send Write command as sector change is not needed */ |
| 798 | status = rw_t2t_send_cmd(T2T_CMD_WRITE, write_cmd); |
| 799 | if (status == NFC_STATUS_OK) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 800 | DLOG_IF(INFO, nfc_debug_enabled) |
| 801 | << StringPrintf("rw_t2t_write Sent Command for Block: %u", block); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 802 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 803 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 804 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | /******************************************************************************* |
| 808 | ** |
| 809 | ** Function rw_t2t_select |
| 810 | ** |
| 811 | ** Description This function selects type 2 tag. |
| 812 | ** |
| 813 | ** Returns Tag selection status |
| 814 | ** |
| 815 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 816 | tNFC_STATUS rw_t2t_select(void) { |
| 817 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 818 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 819 | p_t2t->state = RW_T2T_STATE_IDLE; |
| 820 | p_t2t->ndef_status = T2T_NDEF_NOT_DETECTED; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 821 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 822 | /* Alloc cmd buf for retransmissions */ |
| 823 | if (p_t2t->p_cur_cmd_buf == NULL) { |
| 824 | p_t2t->p_cur_cmd_buf = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
| 825 | if (p_t2t->p_cur_cmd_buf == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 826 | LOG(ERROR) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 827 | "rw_t2t_select: unable to allocate buffer for retransmission"); |
| 828 | return (NFC_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 829 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 830 | } |
| 831 | /* Alloc cmd buf for holding a command untill sector changes */ |
| 832 | if (p_t2t->p_sec_cmd_buf == NULL) { |
| 833 | p_t2t->p_sec_cmd_buf = (NFC_HDR*)GKI_getpoolbuf(NFC_RW_POOL_ID); |
| 834 | if (p_t2t->p_sec_cmd_buf == NULL) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 835 | LOG(ERROR) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 836 | "rw_t2t_select: unable to allocate buffer used during sector change"); |
| 837 | return (NFC_STATUS_FAILED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 838 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 839 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 840 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 841 | NFC_SetStaticRfCback(rw_t2t_conn_cback); |
| 842 | rw_t2t_handle_op_complete(); |
| 843 | p_t2t->check_tag_halt = false; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 844 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 845 | return NFC_STATUS_OK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /***************************************************************************** |
| 849 | ** |
| 850 | ** Function rw_t2t_handle_op_complete |
| 851 | ** |
| 852 | ** Description Reset to IDLE state |
| 853 | ** |
| 854 | ** Returns Nothing |
| 855 | ** |
| 856 | *****************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 857 | void rw_t2t_handle_op_complete(void) { |
| 858 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 859 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 860 | if ((p_t2t->state == RW_T2T_STATE_READ_NDEF) || |
| 861 | (p_t2t->state == RW_T2T_STATE_WRITE_NDEF)) { |
| 862 | p_t2t->b_read_data = false; |
| 863 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 864 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 865 | if (p_t2t->state != RW_T2T_STATE_HALT) p_t2t->state = RW_T2T_STATE_IDLE; |
| 866 | p_t2t->substate = RW_T2T_SUBSTATE_NONE; |
| 867 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | /***************************************************************************** |
| 871 | ** |
| 872 | ** Function RW_T2tPresenceCheck |
| 873 | ** |
| 874 | ** Description |
| 875 | ** Check if the tag is still in the field. |
| 876 | ** |
| 877 | ** The RW_T2T_PRESENCE_CHECK_EVT w/ status is used to indicate presence |
| 878 | ** or non-presence. |
| 879 | ** |
| 880 | ** Returns |
| 881 | ** NFC_STATUS_OK, if raw data frame sent |
| 882 | ** NFC_STATUS_NO_BUFFERS: unable to allocate a buffer for this operation |
| 883 | ** NFC_STATUS_FAILED: other error |
| 884 | ** |
| 885 | *****************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 886 | tNFC_STATUS RW_T2tPresenceCheck(void) { |
| 887 | tNFC_STATUS retval = NFC_STATUS_OK; |
| 888 | tRW_DATA evt_data; |
| 889 | tRW_CB* p_rw_cb = &rw_cb; |
| 890 | uint8_t sector_blk = 0; /* block 0 of current sector */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 891 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 892 | DLOG_IF(INFO, nfc_debug_enabled) << __func__; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 893 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 894 | /* If RW_SelectTagType was not called (no conn_callback) return failure */ |
| 895 | if (!p_rw_cb->p_cback) { |
| 896 | retval = NFC_STATUS_FAILED; |
| 897 | } |
| 898 | /* If we are not activated, then RW_T2T_PRESENCE_CHECK_EVT status=FAIL */ |
| 899 | else if (p_rw_cb->tcb.t2t.state == RW_T2T_STATE_NOT_ACTIVATED) { |
| 900 | evt_data.status = NFC_STATUS_FAILED; |
| 901 | (*p_rw_cb->p_cback)(RW_T2T_PRESENCE_CHECK_EVT, &evt_data); |
| 902 | } |
| 903 | /* If command is pending, assume tag is still present */ |
| 904 | else if (p_rw_cb->tcb.t2t.state != RW_T2T_STATE_IDLE) { |
| 905 | evt_data.status = NFC_STATUS_OK; |
| 906 | (*p_rw_cb->p_cback)(RW_T2T_PRESENCE_CHECK_EVT, &evt_data); |
| 907 | } else { |
| 908 | /* IDLE state: send a READ command to block 0 of the current sector */ |
| 909 | retval = rw_t2t_send_cmd(T2T_CMD_READ, §or_blk); |
| 910 | if (retval == NFC_STATUS_OK) { |
| 911 | p_rw_cb->tcb.t2t.state = RW_T2T_STATE_CHECK_PRESENCE; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 912 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 913 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 914 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 915 | return (retval); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /******************************************************************************* |
| 919 | ** |
| 920 | ** Function RW_T2tRead |
| 921 | ** |
| 922 | ** Description This function issues the Type 2 Tag READ command. When the |
| 923 | ** operation is complete the callback function will be called |
| 924 | ** with a RW_T2T_READ_EVT. |
| 925 | ** |
| 926 | ** Returns tNFC_STATUS |
| 927 | ** |
| 928 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 929 | tNFC_STATUS RW_T2tRead(uint16_t block) { |
| 930 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 931 | tNFC_STATUS status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 932 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 933 | if (p_t2t->state != RW_T2T_STATE_IDLE) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 934 | LOG(ERROR) << StringPrintf( |
| 935 | "Error: Type 2 tag not activated or Busy - State: %u", p_t2t->state); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 936 | return (NFC_STATUS_FAILED); |
| 937 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 938 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 939 | status = rw_t2t_read(block); |
| 940 | if (status == NFC_STATUS_OK) { |
| 941 | p_t2t->state = RW_T2T_STATE_READ; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 942 | DLOG_IF(INFO, nfc_debug_enabled) |
| 943 | << StringPrintf("RW_T2tRead Sent Read command"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 944 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 945 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 946 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /******************************************************************************* |
| 950 | ** |
| 951 | ** Function RW_T2tWrite |
| 952 | ** |
| 953 | ** Description This function issues the Type 2 Tag WRITE command. When the |
| 954 | ** operation is complete the callback function will be called |
| 955 | ** with a RW_T2T_WRITE_EVT. |
| 956 | ** |
| 957 | ** p_new_bytes points to the array of 4 bytes to be written |
| 958 | ** |
| 959 | ** Returns tNFC_STATUS |
| 960 | ** |
| 961 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 962 | tNFC_STATUS RW_T2tWrite(uint16_t block, uint8_t* p_write_data) { |
| 963 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 964 | tNFC_STATUS status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 965 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 966 | if (p_t2t->state != RW_T2T_STATE_IDLE) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 967 | LOG(ERROR) << StringPrintf( |
| 968 | "Error: Type 2 tag not activated or Busy - State: %u", p_t2t->state); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 969 | return (NFC_STATUS_FAILED); |
| 970 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 971 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 972 | status = rw_t2t_write(block, p_write_data); |
| 973 | if (status == NFC_STATUS_OK) { |
| 974 | p_t2t->state = RW_T2T_STATE_WRITE; |
| 975 | if (block < T2T_FIRST_DATA_BLOCK) |
| 976 | p_t2t->b_read_hdr = false; |
| 977 | else if (block < (T2T_FIRST_DATA_BLOCK + T2T_READ_BLOCKS)) |
| 978 | p_t2t->b_read_data = false; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 979 | DLOG_IF(INFO, nfc_debug_enabled) |
| 980 | << StringPrintf("RW_T2tWrite Sent Write command"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 981 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 982 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 983 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /******************************************************************************* |
| 987 | ** |
| 988 | ** Function RW_T2tSectorSelect |
| 989 | ** |
| 990 | ** Description This function issues the Type 2 Tag SECTOR-SELECT command |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 991 | ** packet 1. If a NACK is received as the response, the |
| 992 | ** callback function will be called with a |
| 993 | ** RW_T2T_SECTOR_SELECT_EVT. If an ACK is received as the |
| 994 | ** response, the command packet 2 with the given sector number |
| 995 | ** is sent to the peer device. When the response for packet 2 |
| 996 | ** is received, the callback function will be called with a |
| 997 | ** RW_T2T_SECTOR_SELECT_EVT. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 998 | ** |
| 999 | ** A sector is 256 contiguous blocks (1024 bytes). |
| 1000 | ** |
| 1001 | ** Returns tNFC_STATUS |
| 1002 | ** |
| 1003 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1004 | tNFC_STATUS RW_T2tSectorSelect(uint8_t sector) { |
| 1005 | tNFC_STATUS status; |
| 1006 | tRW_T2T_CB* p_t2t = &rw_cb.tcb.t2t; |
| 1007 | uint8_t sector_byte2[1]; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1008 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1009 | if (p_t2t->state != RW_T2T_STATE_IDLE) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1010 | LOG(ERROR) << StringPrintf( |
| 1011 | "Error: Type 2 tag not activated or Busy - State: %u", p_t2t->state); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1012 | return (NFC_STATUS_FAILED); |
| 1013 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1014 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1015 | if (sector >= T2T_MAX_SECTOR) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1016 | LOG(ERROR) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1017 | "RW_T2tSectorSelect - Invalid sector: %u, T2 Max supported sector " |
| 1018 | "value: %u", |
| 1019 | sector, T2T_MAX_SECTOR - 1); |
| 1020 | return (NFC_STATUS_FAILED); |
| 1021 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1022 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1023 | sector_byte2[0] = 0xFF; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1024 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1025 | status = rw_t2t_send_cmd(T2T_CMD_SEC_SEL, sector_byte2); |
| 1026 | if (status == NFC_STATUS_OK) { |
| 1027 | p_t2t->state = RW_T2T_STATE_SELECT_SECTOR; |
| 1028 | p_t2t->select_sector = sector; |
| 1029 | p_t2t->substate = RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR_SUPPORT; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1030 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1031 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1032 | << StringPrintf("RW_T2tSectorSelect Sent Sector select first command"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1033 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1034 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1035 | return status; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1036 | } |
| 1037 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1038 | /******************************************************************************* |
| 1039 | ** |
| 1040 | ** Function rw_t2t_get_state_name |
| 1041 | ** |
| 1042 | ** Description This function returns the state name. |
| 1043 | ** |
| 1044 | ** NOTE conditionally compiled to save memory. |
| 1045 | ** |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1046 | ** Returns string |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1047 | ** |
| 1048 | *******************************************************************************/ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1049 | static std::string rw_t2t_get_state_name(uint8_t state) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1050 | switch (state) { |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1051 | case RW_T2T_STATE_NOT_ACTIVATED: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1052 | return "NOT_ACTIVATED"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1053 | case RW_T2T_STATE_IDLE: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1054 | return "IDLE"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1055 | case RW_T2T_STATE_READ: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1056 | return "APP_READ"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1057 | case RW_T2T_STATE_WRITE: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1058 | return "APP_WRITE"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1059 | case RW_T2T_STATE_SELECT_SECTOR: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1060 | return "SECTOR_SELECT"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1061 | case RW_T2T_STATE_DETECT_TLV: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1062 | return "TLV_DETECT"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1063 | case RW_T2T_STATE_READ_NDEF: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1064 | return "READ_NDEF"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1065 | case RW_T2T_STATE_WRITE_NDEF: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1066 | return "WRITE_NDEF"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1067 | case RW_T2T_STATE_SET_TAG_RO: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1068 | return "SET_TAG_RO"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1069 | case RW_T2T_STATE_CHECK_PRESENCE: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1070 | return "CHECK_PRESENCE"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1071 | default: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1072 | return "???? UNKNOWN STATE"; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1073 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | /******************************************************************************* |
| 1077 | ** |
| 1078 | ** Function rw_t2t_get_substate_name |
| 1079 | ** |
| 1080 | ** Description This function returns the substate name. |
| 1081 | ** |
| 1082 | ** NOTE conditionally compiled to save memory. |
| 1083 | ** |
| 1084 | ** Returns pointer to the name |
| 1085 | ** |
| 1086 | *******************************************************************************/ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1087 | static std::string rw_t2t_get_substate_name(uint8_t substate) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1088 | switch (substate) { |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1089 | case RW_T2T_SUBSTATE_NONE: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1090 | return "RW_T2T_SUBSTATE_NONE"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1091 | case RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR_SUPPORT: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1092 | return "RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR_SUPPORT"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1093 | case RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1094 | return "RW_T2T_SUBSTATE_WAIT_SELECT_SECTOR"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1095 | case RW_T2T_SUBSTATE_WAIT_READ_CC: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1096 | return "RW_T2T_SUBSTATE_WAIT_READ_CC"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1097 | case RW_T2T_SUBSTATE_WAIT_TLV_DETECT: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1098 | return "RW_T2T_SUBSTATE_WAIT_TLV_DETECT"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1099 | case RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1100 | return "RW_T2T_SUBSTATE_WAIT_FIND_LEN_FIELD_LEN"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1101 | case RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1102 | return "RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN0"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1103 | case RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN1: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1104 | return "RW_T2T_SUBSTATE_WAIT_READ_TLV_LEN1"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1105 | case RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1106 | return "RW_T2T_SUBSTATE_WAIT_READ_TLV_VALUE"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1107 | case RW_T2T_SUBSTATE_WAIT_READ_LOCKS: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1108 | return "RW_T2T_SUBSTATE_WAIT_READ_LOCKS"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1109 | case RW_T2T_SUBSTATE_WAIT_READ_NDEF_FIRST_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1110 | return "RW_T2T_SUBSTATE_WAIT_READ_NDEF_FIRST_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1111 | case RW_T2T_SUBSTATE_WAIT_READ_NDEF_LAST_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1112 | return "RW_T2T_SUBSTATE_WAIT_READ_NDEF_LAST_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1113 | case RW_T2T_SUBSTATE_WAIT_READ_TERM_TLV_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1114 | return "RW_T2T_SUBSTATE_WAIT_READ_TERM_TLV_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1115 | case RW_T2T_SUBSTATE_WAIT_READ_NDEF_NEXT_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1116 | return "RW_T2T_SUBSTATE_WAIT_READ_NDEF_NEXT_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1117 | case RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_NEXT_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1118 | return "RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_NEXT_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1119 | case RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LAST_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1120 | return "RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LAST_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1121 | case RW_T2T_SUBSTATE_WAIT_READ_NDEF_LEN_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1122 | return "RW_T2T_SUBSTATE_WAIT_READ_NDEF_LEN_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1123 | case RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1124 | return "RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1125 | case RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1126 | return "RW_T2T_SUBSTATE_WAIT_WRITE_NDEF_LEN_NEXT_BLOCK"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1127 | case RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1128 | return "RW_T2T_SUBSTATE_WAIT_WRITE_TERM_TLV_CMPLT"; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1129 | default: |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1130 | return "???? UNKNOWN SUBSTATE"; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1131 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1132 | } |