1 /****************************************************************************** 2 * 3 * Copyright (C) 2024 The Android Open Source Project. 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 #pragma once 19 #include "nfa_ee_int.h" 20 #include "nfa_sys.h" 21 using namespace std; 22 23 #define CC_FILE_ID 0xE103 24 #define NDEF_FILE_ID 0xE104 25 26 #define T4TNFCEE_SIZEOF_LEN_BYTES 0x02 27 #define T4TNFCEE_SIZEOF_STATUS_BYTES 0x02 28 29 /*CLA + INS + P1 + P2 + LC*/ 30 #define CAPDU_TL 0x05 31 #define RW_T4TNFCEE_DATA_PER_WRITE (T4T_MAX_LENGTH_LC - CAPDU_TL) 32 33 /* 34 POWER_STATE: 35 bit pos 0 = Switch On 36 bit pos 1 = Switch Off 37 bit pos 2 = Battery Off 38 bit pos 3 = Screen On lock 39 bit pos 4 = Screen off unlock 40 bit pos 5 = Screen Off lock 41 */ 42 #define T4TNFCEE_AID_POWER_STATE 0x3B 43 44 /* Event to notify T4T NFCEE Detection complete*/ 45 #define NFA_T4TNFCEE_EVT 40 46 /* Event to notify NDEF T4TNFCEE READ complete*/ 47 #define NFA_T4TNFCEE_READ_CPLT_EVT 41 48 /* Event to notify NDEF T4TNFCEE WRITE complete*/ 49 #define NFA_T4TNFCEE_WRITE_CPLT_EVT 42 50 /* Event to notify NDEF T4TNFCEE CLEAR complete*/ 51 #define NFA_T4TNFCEE_CLEAR_CPLT_EVT 43 52 /* Event to notify NDEF T4TNFCEE READ CC DATA complete*/ 53 #define NFA_T4TNFCEE_READ_CC_DATA_CPLT_EVT 44 54 55 #define T4T_NFCEE_READ_ALLOWED 0x00 56 #define T4T_NFCEE_WRITE_NOT_ALLOWED 0xFF 57 58 /*Status codes*/ 59 #define NFA_T4T_STATUS_INVALID_FILE_ID 0x05 60 61 typedef struct { 62 uint16_t capacity; 63 uint8_t read_access; 64 uint8_t write_access; 65 } tNFA_T4TNFCEE_FILE_INFO; 66 67 enum { 68 NFA_T4TNFCEE_OP_OPEN_CONNECTION, 69 NFA_T4TNFCEE_OP_READ, 70 NFA_T4TNFCEE_OP_WRITE, 71 NFA_T4TNFCEE_OP_CLOSE_CONNECTION, 72 NFA_T4TNFCEE_OP_CLEAR, 73 NFA_T4TNFCEE_OP_READ_CC_FILE, 74 NFA_T4TNFCEE_OP_MAX 75 }; 76 typedef uint8_t tNFA_T4TNFCEE_OP; 77 78 typedef struct { 79 uint32_t len; 80 uint8_t* p_data; 81 } tNFA_T4TNFCEE_OP_PARAMS_WRITE; 82 83 /* NDEF EE events */ 84 enum { 85 NFA_T4TNFCEE_OP_REQUEST_EVT = NFA_SYS_EVT_START(NFA_ID_T4TNFCEE), 86 NFA_T4TNFCEE_MAX_EVT 87 }; 88 89 /* data type for NFA_T4TNFCEE_op_req_EVT */ 90 typedef struct { 91 NFC_HDR hdr; 92 tNFA_T4TNFCEE_OP op; /* NFA T4TNFCEE operation */ 93 uint8_t* p_fileId; 94 tNFA_T4TNFCEE_OP_PARAMS_WRITE write; 95 } tNFA_T4TNFCEE_OPERATION; 96 97 /* union of all data types */ 98 typedef union { 99 /* GKI event buffer header */ 100 NFC_HDR hdr; 101 tNFA_T4TNFCEE_OPERATION op_req; 102 } tNFA_T4TNFCEE_MSG; 103 104 typedef enum { 105 /* NFA T4TNFCEE states */ 106 NFA_T4TNFCEE_STATE_DISABLED = 0x00, /* T4TNFCEE is disabled */ 107 NFA_T4TNFCEE_STATE_TRY_ENABLE, 108 NFA_T4TNFCEE_STATE_INITIALIZED, /* T4TNFCEE is waiting to handle api commands 109 */ 110 NFA_T4TNFCEE_STATE_CONNECTED, /* T4TNFCEE is in open sequence */ 111 NFA_T4TNFCEE_STATE_DISCONNECTED, /* T4TNFCEE is in closing sequence */ 112 NFA_T4TNFCEE_STATE_OPEN_FAILED /* T4TNFCEE OPEN Failed */ 113 } tNFA_T4TNFCEE_STATE; 114 115 typedef enum { 116 PROP_DISABLED = 0x00, 117 WAIT_SELECT_APPLICATION, 118 WAIT_SELECT_CC, 119 WAIT_READ_CC_DATA_LEN, 120 WAIT_READ_CC_FILE, 121 WAIT_SELECT_FILE, 122 WAIT_READ_DATA_LEN, 123 WAIT_READ_FILE, 124 WAIT_RESET_NLEN, 125 WAIT_WRITE, 126 WAIT_WRITE_COMPLETE, 127 WAIT_UPDATE_NLEN, 128 WAIT_CLEAR_NDEF_DATA, 129 OP_COMPLETE = 0x00 130 } tNFA_T4TNFCEE_RW_STATE; 131 /* NFA T4TNFCEE control block */ 132 typedef struct { 133 tNFA_STATUS status; 134 tNFA_T4TNFCEE_STATE t4tnfcee_state; /* T4T NFCEE state */ 135 tNFA_T4TNFCEE_OP cur_op; /* Current operation */ 136 tNFA_T4TNFCEE_RW_STATE rw_state; /* Read Write state */ 137 tNFA_T4TNFCEE_MSG* p_pending_msg; /* Pending command */ 138 uint8_t* p_dataBuf; /* Data buffer */ 139 uint16_t cur_fileId; /* Current FileId */ 140 uint16_t rd_offset; /* current read-offset of incoming NDEF data */ 141 uint32_t dataLen; /*length of the data*/ 142 bool ndefEmulationSupport; /* NDEF emulation support */ 143 uint8_t connId; /* NDEF NFCEE CONN ID */ 144 } tNFA_T4TNFCEE_CB; 145 extern tNFA_T4TNFCEE_CB nfa_t4tnfcee_cb; 146 147 /* type definition for action functions */ 148 typedef bool (*tNFA_T4TNFCEE_ACTION)(tNFA_T4TNFCEE_MSG* p_data); 149 150 bool nfa_t4tnfcee_handle_op_req(tNFA_T4TNFCEE_MSG* p_data); 151 bool nfa_t4tnfcee_handle_event(NFC_HDR* p_msg); 152 void nfa_t4tnfcee_free_rx_buf(void); 153 bool nfa_t4tnfcee_is_enabled(void); 154 bool NFA_T4tNfcEeIsProcessing(void); 155 bool NFA_T4tNfcEeIsEmulationSupported(void); 156 void nfa_t4tnfcee_set_ee_cback(tNFA_EE_ECB* p_ecb); 157 void nfa_t4tnfcee_init(); 158 void nfa_t4tnfcee_deinit(void); 159 tNFC_STATUS nfa_t4tnfcee_proc_disc_evt(tNFA_T4TNFCEE_OP event); 160