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