1 /****************************************************************************** 2 * 3 * Copyright (C) 2009-2013 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 /****************************************************************************** 21 * 22 * This file contains the Near Field Communication (NFC) Card Emulation 23 * mode related internal function / definitions. 24 * 25 ******************************************************************************/ 26 27 #ifndef CE_INT_H_ 28 #define CE_INT_H_ 29 30 #include "ce_api.h" 31 32 #if (CE_TEST_INCLUDED == FALSE) 33 #define CE_MIN_SUP_PROTO NCI_PROTOCOL_FELICA 34 #define CE_MAX_SUP_PROTO NCI_PROTOCOL_ISO4 35 #else 36 #define CE_MIN_SUP_PROTO NCI_PROTOCOL_TYPE1 37 #define CE_MAX_SUP_PROTO NCI_PROTOCOL_MIFARE 38 #endif 39 40 #define CE_MAX_BYTE_PER_PAGE 7 /* 2^8=256. CB use UINT8 for BytesPerPage, so max is 7 */ 41 42 /* CE Type 3 Tag structures */ 43 44 /* Type 3 Tag NDEF card-emulation */ 45 typedef struct { 46 BOOLEAN initialized; 47 UINT8 version; /* Ver: peer version */ 48 UINT8 nbr; /* NBr: number of blocks that can be read using one Check command */ 49 UINT8 nbw; /* Nbw: number of blocks that can be written using one Update command */ 50 UINT16 nmaxb; /* Nmaxb: maximum number of blocks available for NDEF data */ 51 UINT8 writef; /* WriteFlag: 00h if writing data finished; 0Fh if writing data in progress */ 52 UINT8 rwflag; /* RWFlag: 00h NDEF is read-only; 01h if read/write available */ 53 UINT32 ln; 54 UINT8 *p_buf; /* Current contents for READs */ 55 56 /* Scratch NDEF buffer (for update NDEF commands) */ 57 UINT8 scratch_writef; 58 UINT32 scratch_ln; 59 UINT8 *p_scratch_buf; /* Scratch buffer for WRITE/readback */ 60 } tCE_T3T_NDEF_INFO; 61 62 /* Type 3 Tag current command processing */ 63 typedef struct { 64 UINT16 service_code_list[T3T_MSG_SERVICE_LIST_MAX]; 65 UINT8 *p_block_list_start; 66 UINT8 *p_block_data_start; 67 UINT8 num_services; 68 UINT8 num_blocks; 69 } tCE_T3T_CUR_CMD; 70 71 /* Type 3 Tag control blcok */ 72 typedef struct 73 { 74 UINT8 state; 75 UINT16 system_code; 76 UINT8 local_nfcid2[NCI_RF_F_UID_LEN]; 77 UINT8 local_pmm[NCI_T3T_PMM_LEN]; 78 tCE_T3T_NDEF_INFO ndef_info; 79 tCE_T3T_CUR_CMD cur_cmd; 80 } tCE_T3T_MEM; 81 82 /* CE Type 4 Tag control blocks */ 83 typedef struct 84 { 85 UINT8 aid_len; 86 UINT8 aid[NFC_MAX_AID_LEN]; 87 tCE_CBACK *p_cback; 88 } tCE_T4T_REG_AID; /* registered AID table */ 89 90 typedef struct 91 { 92 TIMER_LIST_ENT timer; /* timeout for update file */ 93 UINT8 cc_file[T4T_FC_TLV_OFFSET_IN_CC + T4T_FILE_CONTROL_TLV_SIZE]; 94 UINT8 *p_ndef_msg; /* storage of NDEF message */ 95 UINT16 nlen; /* current size of NDEF message */ 96 UINT16 max_file_size; /* size of storage + 2 bytes for NLEN */ 97 UINT8 *p_scratch_buf; /* temp storage of NDEF message for update */ 98 99 #define CE_T4T_STATUS_T4T_APP_SELECTED 0x01 /* T4T CE App is selected */ 100 #define CE_T4T_STATUS_REG_AID_SELECTED 0x02 /* Registered AID is selected */ 101 #define CE_T4T_STATUS_CC_FILE_SELECTED 0x04 /* CC file is selected */ 102 #define CE_T4T_STATUS_NDEF_SELECTED 0x08 /* NDEF file is selected */ 103 #define CE_T4T_STATUS_NDEF_FILE_READ_ONLY 0x10 /* NDEF is read-only */ 104 #define CE_T4T_STATUS_NDEF_FILE_UPDATING 0x20 /* NDEF is updating */ 105 #define CE_T4T_STATUS_WILDCARD_AID_SELECTED 0x40 /* Wildcard AID selected */ 106 107 UINT8 status; 108 109 tCE_CBACK *p_wildcard_aid_cback; /* registered wildcard AID callback */ 110 tCE_T4T_REG_AID reg_aid[CE_T4T_MAX_REG_AID]; /* registered AID table */ 111 UINT8 selected_aid_idx; 112 } tCE_T4T_MEM; 113 114 #define CE_T4T_WILDCARD_AID_HANDLE (CE_T4T_MAX_REG_AID) /* reserved handle for wildcard aid */ 115 116 /* CE memory control blocks */ 117 typedef struct 118 { 119 tCE_T3T_MEM t3t; 120 tCE_T4T_MEM t4t; 121 } tCE_MEM; 122 123 /* CE control blocks */ 124 typedef struct 125 { 126 tCE_MEM mem; 127 tCE_CBACK *p_cback; 128 UINT8 *p_ndef; /* the memory starting from NDEF */ 129 UINT16 ndef_max; /* max size of p_ndef */ 130 UINT16 ndef_cur; /* current size of p_ndef */ 131 tNFC_RF_TECH tech; 132 UINT8 trace_level; 133 134 } tCE_CB; 135 136 /* 137 ** CE Type 4 Tag Definition 138 */ 139 140 /* Max data size using a single ReadBinary. 2 bytes are for status bytes */ 141 #define CE_T4T_MAX_LE (NFC_CE_POOL_BUF_SIZE - BT_HDR_SIZE - NCI_MSG_OFFSET_SIZE - NCI_DATA_HDR_SIZE - T4T_RSP_STATUS_WORDS_SIZE) 142 143 /* Max data size using a single UpdateBinary. 6 bytes are for CLA, INS, P1, P2, Lc */ 144 #define CE_T4T_MAX_LC (NFC_CE_POOL_BUF_SIZE - BT_HDR_SIZE - NCI_DATA_HDR_SIZE - T4T_CMD_MAX_HDR_SIZE) 145 146 /***************************************************************************** 147 ** EXTERNAL FUNCTION DECLARATIONS 148 *****************************************************************************/ 149 #ifdef __cplusplus 150 extern "C" { 151 #endif 152 153 /* Global NFC data */ 154 #if NFC_DYNAMIC_MEMORY == FALSE 155 NFC_API extern tCE_CB ce_cb; 156 #else 157 NFC_API extern tCE_CB *ce_cb_ptr; 158 #define ce_cb (*ce_cb_ptr) 159 #endif 160 161 extern void ce_init (void); 162 163 /* ce_t3t internal functions */ 164 void ce_t3t_init (void); 165 tNFC_STATUS ce_select_t3t (UINT16 system_code, UINT8 nfcid2[NCI_RF_F_UID_LEN]); 166 167 /* ce_t4t internal functions */ 168 extern tNFC_STATUS ce_select_t4t (void); 169 extern void ce_t4t_process_timeout (TIMER_LIST_ENT *p_tle); 170 171 #ifdef __cplusplus 172 } 173 #endif 174 175 #endif /* CE_INT_H_ */ 176