Home | History | Annotate | Download | only in int
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2003-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 is the private interface file for NFA_RW
     23  *
     24  ******************************************************************************/
     25 #ifndef NFA_RW_INT_H
     26 #define NFA_RW_INT_H
     27 
     28 #include "nfa_sys.h"
     29 #include "nfa_api.h"
     30 #include "nfa_rw_api.h"
     31 #include "nfc_api.h"
     32 #include "rw_api.h"
     33 
     34 /*****************************************************************************
     35 **  Constants and data types
     36 *****************************************************************************/
     37 
     38 /* Interval for performing presence check (in ms) */
     39 #ifndef NFA_RW_PRESENCE_CHECK_INTERVAL
     40 #define NFA_RW_PRESENCE_CHECK_INTERVAL  750
     41 #endif
     42 
     43 /* TLV detection status */
     44 #define NFA_RW_TLV_DETECT_ST_OP_NOT_STARTED         0x00 /* No Tlv detected */
     45 #define NFA_RW_TLV_DETECT_ST_LOCK_TLV_OP_COMPLETE   0x01 /* Lock control tlv detected */
     46 #define NFA_RW_TLV_DETECT_ST_MEM_TLV_OP_COMPLETE    0x02 /* Memory control tlv detected */
     47 #define NFA_RW_TLV_DETECT_ST_COMPLETE               0x03 /* Both Lock and Memory control Tlvs are detected */
     48 
     49 typedef UINT8 tNFA_RW_TLV_ST;
     50 
     51 
     52 /* RW events */
     53 enum
     54 {
     55     NFA_RW_OP_REQUEST_EVT = NFA_SYS_EVT_START (NFA_ID_RW),
     56     NFA_RW_ACTIVATE_NTF_EVT,
     57     NFA_RW_DEACTIVATE_NTF_EVT,
     58     NFA_RW_PRESENCE_CHECK_TICK_EVT,
     59     NFA_RW_MAX_EVT
     60 };
     61 
     62 
     63 
     64 /* BTA_RW operations */
     65 enum
     66 {
     67     NFA_RW_OP_DETECT_NDEF,
     68     NFA_RW_OP_READ_NDEF,
     69     NFA_RW_OP_WRITE_NDEF,
     70     NFA_RW_OP_PRESENCE_CHECK,
     71     NFA_RW_OP_FORMAT_TAG,
     72     NFA_RW_OP_SEND_RAW_FRAME,
     73 
     74     /* Exclusive Type-1,Type-2 tag operations */
     75     NFA_RW_OP_DETECT_LOCK_TLV,
     76     NFA_RW_OP_DETECT_MEM_TLV,
     77     NFA_RW_OP_SET_TAG_RO,
     78 
     79     /* Exclusive Type-1 tag operations */
     80     NFA_RW_OP_T1T_RID,
     81     NFA_RW_OP_T1T_RALL,
     82     NFA_RW_OP_T1T_READ,
     83     NFA_RW_OP_T1T_WRITE,
     84     NFA_RW_OP_T1T_RSEG,
     85     NFA_RW_OP_T1T_READ8,
     86     NFA_RW_OP_T1T_WRITE8,
     87 
     88     /* Exclusive Type-2 tag operations */
     89     NFA_RW_OP_T2T_READ,
     90     NFA_RW_OP_T2T_WRITE,
     91     NFA_RW_OP_T2T_SECTOR_SELECT,
     92 
     93     /* Exclusive Type-3 tag operations */
     94     NFA_RW_OP_T3T_READ,
     95     NFA_RW_OP_T3T_WRITE,
     96     NFA_RW_OP_T3T_GET_SYSTEM_CODES,
     97 
     98     /* Exclusive ISO 15693 tag operations */
     99     NFA_RW_OP_I93_INVENTORY,
    100     NFA_RW_OP_I93_STAY_QUIET,
    101     NFA_RW_OP_I93_READ_SINGLE_BLOCK,
    102     NFA_RW_OP_I93_WRITE_SINGLE_BLOCK,
    103     NFA_RW_OP_I93_LOCK_BLOCK,
    104     NFA_RW_OP_I93_READ_MULTI_BLOCK,
    105     NFA_RW_OP_I93_WRITE_MULTI_BLOCK,
    106     NFA_RW_OP_I93_SELECT,
    107     NFA_RW_OP_I93_RESET_TO_READY,
    108     NFA_RW_OP_I93_WRITE_AFI,
    109     NFA_RW_OP_I93_LOCK_AFI,
    110     NFA_RW_OP_I93_WRITE_DSFID,
    111     NFA_RW_OP_I93_LOCK_DSFID,
    112     NFA_RW_OP_I93_GET_SYS_INFO,
    113     NFA_RW_OP_I93_GET_MULTI_BLOCK_STATUS,
    114 
    115     NFA_RW_OP_MAX
    116 };
    117 typedef UINT8 tNFA_RW_OP;
    118 
    119 /* Enumeration of parameter structios for nfa_rw operations */
    120 
    121 /* NFA_RW_OP_WRITE_NDEF params */
    122 typedef struct
    123 {
    124     UINT32          len;
    125     UINT8           *p_data;
    126 } tNFA_RW_OP_PARAMS_WRITE_NDEF;
    127 
    128 /* NFA_RW_OP_SEND_RAW_FRAME params */
    129 typedef struct
    130 {
    131     BT_HDR          *p_data;
    132 } tNFA_RW_OP_PARAMS_SEND_RAW_FRAME;
    133 
    134 /* NFA_RW_OP_SET_TAG_RO params */
    135 typedef struct
    136 {
    137     BOOLEAN         b_hard_lock;
    138 } tNFA_RW_OP_PARAMS_CONFIG_READ_ONLY;
    139 
    140 /* NFA_RW_OP_T1T_READ params */
    141 typedef struct
    142 {
    143     UINT8           segment_number;
    144     UINT8           block_number;
    145     UINT8           index;
    146 } tNFA_RW_OP_PARAMS_T1T_READ;
    147 
    148 /* NFA_RW_OP_T1T_WRITE_E8,NFA_RW_OP_T1T_WRITE_NE8
    149    NFA_RW_OP_T1T_WRITE_E, NFA_RW_OP_T1T_WRITE_NE params  */
    150 typedef struct
    151 {
    152     BOOLEAN         b_erase;
    153     UINT8           block_number;
    154     UINT8           index;
    155     UINT8           p_block_data[8];
    156 } tNFA_RW_OP_PARAMS_T1T_WRITE;
    157 
    158 /* NFA_RW_OP_T2T_READ params */
    159 typedef struct
    160 {
    161     UINT8           block_number;
    162 } tNFA_RW_OP_PARAMS_T2T_READ;
    163 
    164 /* NFA_RW_OP_T2T_WRITE params */
    165 typedef struct
    166 {
    167     UINT8           block_number;
    168     UINT8           p_block_data[4];
    169 } tNFA_RW_OP_PARAMS_T2T_WRITE;
    170 
    171 /* NFA_RW_OP_T2T_SECTOR_SELECT params */
    172 typedef struct
    173 {
    174     UINT8           sector_number;
    175 } tNFA_RW_OP_PARAMS_T2T_SECTOR_SELECT;
    176 
    177 /* NFA_RW_OP_T3T_READ params */
    178 typedef struct
    179 {
    180     UINT8              num_blocks;
    181     tNFA_T3T_BLOCK_DESC *p_block_desc;
    182 } tNFA_RW_OP_PARAMS_T3T_READ;
    183 
    184 /* NFA_RW_OP_T3T_WRITE params */
    185 typedef struct
    186 {
    187     UINT8               num_blocks;
    188     tNFA_T3T_BLOCK_DESC *p_block_desc;
    189     UINT8               *p_block_data;
    190 } tNFA_RW_OP_PARAMS_T3T_WRITE;
    191 
    192 /* NFA_RW_OP_I93_XXX params */
    193 typedef struct
    194 {
    195     BOOLEAN             uid_present;
    196     UINT8               uid[I93_UID_BYTE_LEN];
    197     BOOLEAN             afi_present;
    198     UINT8               afi;
    199     UINT8               dsfid;
    200     UINT16              first_block_number;
    201     UINT16              number_blocks;
    202     UINT8              *p_data;
    203 } tNFA_RW_OP_PARAMS_I93_CMD;
    204 
    205 /* Union of params for all reader/writer operations */
    206 typedef union
    207 {
    208     /* params for NFA_RW_OP_WRITE_NDEF */
    209     tNFA_RW_OP_PARAMS_WRITE_NDEF        write_ndef;
    210 
    211     /* params for NFA_RW_OP_SEND_RAW_FRAME */
    212     tNFA_RW_OP_PARAMS_SEND_RAW_FRAME    send_raw_frame;
    213 
    214     /* params for NFA_RW_OP_SET_TAG_RO */
    215     tNFA_RW_OP_PARAMS_CONFIG_READ_ONLY  set_readonly;
    216 
    217     /* params for NFA_RW_OP_T2T_READ and NFA_RW_OP_T1T_WRITE */
    218     tNFA_RW_OP_PARAMS_T1T_READ          t1t_read;
    219     tNFA_RW_OP_PARAMS_T1T_WRITE         t1t_write;
    220 
    221     /* params for NFA_RW_OP_T2T_READ,NFA_RW_OP_T2T_WRITE and NFA_RW_OP_T2T_SECTOR_SELECT */
    222     tNFA_RW_OP_PARAMS_T2T_READ          t2t_read;
    223     tNFA_RW_OP_PARAMS_T2T_WRITE         t2t_write;
    224     tNFA_RW_OP_PARAMS_T2T_SECTOR_SELECT t2t_sector_select;
    225 
    226     /* params for NFA_RW_OP_T3T_READ and NFA_RW_OP_T3T_WRITE */
    227     tNFA_RW_OP_PARAMS_T3T_READ          t3t_read;
    228     tNFA_RW_OP_PARAMS_T3T_WRITE         t3t_write;
    229 
    230     /* params for ISO 15693 */
    231     tNFA_RW_OP_PARAMS_I93_CMD           i93_cmd;
    232 
    233 } tNFA_RW_OP_PARAMS;
    234 
    235 /* data type for NFA_RW_op_req_EVT */
    236 typedef struct
    237 {
    238     BT_HDR              hdr;
    239     tNFA_RW_OP          op;     /* NFA RW operation */
    240     tNFA_RW_OP_PARAMS   params;
    241 } tNFA_RW_OPERATION;
    242 
    243 /* data type for NFA_RW_ACTIVATE_NTF */
    244 typedef struct
    245 {
    246     BT_HDR              hdr;
    247     tNFC_ACTIVATE_DEVT  *p_activate_params; /* Data from NFC_ACTIVATE_DEVT      */
    248     BOOLEAN             excl_rf_not_active; /* TRUE if not in exclusive RF mode */
    249 } tNFA_RW_ACTIVATE_NTF;
    250 
    251 /* union of all data types */
    252 typedef union
    253 {
    254     /* GKI event buffer header */
    255     BT_HDR                  hdr;
    256     tNFA_RW_OPERATION       op_req;
    257     tNFA_RW_ACTIVATE_NTF    activate_ntf;
    258 } tNFA_RW_MSG;
    259 
    260 /* NDEF detection status */
    261 enum
    262 {
    263     NFA_RW_NDEF_ST_UNKNOWN =0,      /* NDEF detection not performed yet */
    264     NFA_RW_NDEF_ST_TRUE,            /* Tag is NDEF */
    265     NFA_RW_NDEF_ST_FALSE            /* Tag is not NDEF */
    266 };
    267 typedef UINT8 tNFA_RW_NDEF_ST;
    268 
    269 /* flags for RW control block */
    270 #define NFA_RW_FL_NOT_EXCL_RF_MODE              0x01    /* Activation while not in exclusive RF mode                                */
    271 #define NFA_RW_FL_AUTO_PRESENCE_CHECK_BUSY      0x02    /* Waiting for response from tag for auto-presence check                    */
    272 #define NFA_RW_FL_TAG_IS_READONLY               0x04    /* Read only tag                                                            */
    273 #define NFA_RW_FL_ACTIVATION_NTF_PENDING        0x08    /* Busy retrieving additional tag information                               */
    274 #define NFA_RW_FL_API_BUSY                      0x10    /* Tag operation is in progress                                             */
    275 #define NFA_RW_FL_ACTIVATED                     0x20    /* Tag is been activated                                                    */
    276 
    277 /* NFA RW control block */
    278 typedef struct
    279 {
    280     tNFA_RW_OP      cur_op;         /* Current operation */
    281 
    282     TIMER_LIST_ENT  tle;            /* list entry for nfa_rw timer */
    283     tNFA_RW_MSG     *p_pending_msg; /* Pending API (if busy performing presence check) */
    284 
    285     /* Tag info */
    286     tNFC_PROTOCOL   protocol;
    287     UINT8           pa_sel_res;
    288     BOOLEAN         b_hard_lock;
    289 
    290     tNFA_RW_MSG     *p_buffer_rw_msg; /* Buffer to hold incoming cmd while reading tag id */
    291 
    292     /* TLV info */
    293     tNFA_RW_TLV_ST  tlv_st;         /* TLV detection status */
    294 
    295     /* NDEF info */
    296     tNFA_RW_NDEF_ST ndef_st;        /* NDEF detection status */
    297     UINT32          ndef_max_size;  /* max number of bytes available for NDEF data */
    298     UINT32          ndef_cur_size;  /* current size of stored NDEF data (in bytes) */
    299     UINT8           *p_ndef_buf;
    300     UINT32          ndef_rd_offset; /* current read-offset of incoming NDEF data */
    301 
    302     /* Current NDEF Write info */
    303     UINT8           *p_ndef_wr_buf; /* Pointer to NDEF data being written */
    304     UINT32          ndef_wr_len;    /* Length of NDEF data being written */
    305 
    306     /* Flags (see defintions for NFA_RW_FL_* ) */
    307     UINT8           flags;
    308 
    309     /* ISO 15693 tag memory information */
    310     UINT16          i93_afi_location;
    311     UINT8           i93_dsfid;
    312     UINT8           i93_block_size;
    313     UINT16          i93_num_block;
    314     UINT8           i93_uid[I93_UID_BYTE_LEN];
    315 } tNFA_RW_CB;
    316 extern tNFA_RW_CB nfa_rw_cb;
    317 
    318 
    319 
    320 /* type definition for action functions */
    321 typedef BOOLEAN (*tNFA_RW_ACTION) (tNFA_RW_MSG *p_data);
    322 
    323 /* Internal nfa_rw function prototypes */
    324 extern void    nfa_rw_stop_presence_check_timer (void);
    325 
    326 /* Action function prototypes */
    327 extern BOOLEAN nfa_rw_handle_op_req (tNFA_RW_MSG *p_data);
    328 extern BOOLEAN nfa_rw_activate_ntf (tNFA_RW_MSG *p_data);
    329 extern BOOLEAN nfa_rw_deactivate_ntf (tNFA_RW_MSG *p_data);
    330 extern BOOLEAN nfa_rw_presence_check_tick (tNFA_RW_MSG *p_data);
    331 extern void    nfa_rw_handle_presence_check_rsp (tNFC_STATUS status);
    332 extern void    nfa_rw_command_complete (void);
    333 extern BOOLEAN nfa_rw_handle_event (BT_HDR *p_msg);
    334 
    335 extern void    nfa_rw_free_ndef_rx_buf (void);
    336 extern void    nfa_rw_sys_disable (void);
    337 
    338 #endif /* NFA_DM_INT_H */
    339 
    340