Home | History | Annotate | Download | only in int
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-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 is the private interface file for the NFA EE.
     22  *
     23  ******************************************************************************/
     24 #ifndef NFA_EE_INT_H
     25 #define NFA_EE_INT_H
     26 #include "nfc_api.h"
     27 #include "nfa_ee_api.h"
     28 #include "nfa_sys.h"
     29 
     30 /*****************************************************************************
     31 **  Constants and data types
     32 *****************************************************************************/
     33 #define NFA_EE_DEBUG            BT_TRACE_VERBOSE
     34 #define NFA_EE_NUM_ECBS         (NFA_EE_MAX_EE_SUPPORTED+1) /* the number of tNFA_EE_ECBs (for NFCEEs and DH) */
     35 #define NFA_EE_CB_4_DH          NFA_EE_MAX_EE_SUPPORTED     /* The index for DH in nfa_ee_cb.ee_cb[] */
     36 #define NFA_EE_INVALID          0xFF
     37 #define NFA_EE_MAX_TECH_ROUTE   4 /* only A, B, F, Bprime are supported by UICC now */
     38 
     39 #ifndef NFA_EE_AID_CFG_TAG_NAME
     40 #define NFA_EE_AID_CFG_TAG_NAME         0x4F /* AID                             */
     41 #endif
     42 
     43 /* NFA EE events */
     44 enum
     45 {
     46     NFA_EE_API_DISCOVER_EVT  = NFA_SYS_EVT_START(NFA_ID_EE),
     47     NFA_EE_API_REGISTER_EVT,
     48     NFA_EE_API_DEREGISTER_EVT,
     49     NFA_EE_API_MODE_SET_EVT,
     50     NFA_EE_API_SET_TECH_CFG_EVT,
     51     NFA_EE_API_SET_PROTO_CFG_EVT,
     52     NFA_EE_API_ADD_AID_EVT,
     53     NFA_EE_API_REMOVE_AID_EVT,
     54     NFA_EE_API_UPDATE_NOW_EVT,
     55     NFA_EE_API_CONNECT_EVT,
     56     NFA_EE_API_SEND_DATA_EVT,
     57     NFA_EE_API_DISCONNECT_EVT,
     58 
     59     NFA_EE_NCI_DISC_RSP_EVT,
     60     NFA_EE_NCI_DISC_NTF_EVT,
     61     NFA_EE_NCI_MODE_SET_RSP_EVT,
     62     NFA_EE_NCI_CONN_EVT,
     63     NFA_EE_NCI_DATA_EVT,
     64     NFA_EE_NCI_ACTION_NTF_EVT,
     65     NFA_EE_NCI_DISC_REQ_NTF_EVT,
     66 
     67     NFA_EE_ROUT_TIMEOUT_EVT,
     68     NFA_EE_DISCV_TIMEOUT_EVT,
     69     NFA_EE_CFG_TO_NFCC_EVT,
     70     NFA_EE_MAX_EVT
     71 
     72 };
     73 
     74 
     75 typedef UINT16 tNFA_EE_INT_EVT;
     76 #define NFA_EE_AE_ROUTE             0x80        /* for listen mode routing table*/
     77 #define NFA_EE_AE_VS                0x40
     78 
     79 
     80 /* NFA EE Management state */
     81 enum
     82 {
     83     NFA_EE_EM_STATE_INIT = 0,
     84     NFA_EE_EM_STATE_INIT_DONE,
     85     NFA_EE_EM_STATE_RESTORING,
     86     NFA_EE_EM_STATE_DISABLING,
     87     NFA_EE_EM_STATE_DISABLED,
     88 
     89     NFA_EE_EM_STATE_MAX
     90 };
     91 typedef UINT8 tNFA_EE_EM_STATE;
     92 
     93 /* NFA EE connection status */
     94 enum
     95 {
     96     NFA_EE_CONN_ST_NONE,    /* not connected */
     97     NFA_EE_CONN_ST_WAIT,    /* connection is initiated; waiting for ack */
     98     NFA_EE_CONN_ST_CONN,    /* connected; can send/receive data */
     99     NFA_EE_CONN_ST_DISC,    /* disconnecting; waiting for ack */
    100     NFA_EE_CONN_ST_MAX
    101 };
    102 typedef UINT8 tNFA_EE_CONN_ST;
    103 
    104 #define NFA_EE_MAX_AID_CFG_LEN  (510)
    105 #define NFA_EE_7816_STATUS_LEN  (2)
    106 
    107 /* NFA EE control block flags:
    108  * use to indicate an API function has changed the configuration of the associated NFCEE
    109  * The flags are cleared when the routing table/VS is updated */
    110 #define NFA_EE_ECB_FLAGS_TECH       0x02      /* technology routing changed         */
    111 #define NFA_EE_ECB_FLAGS_PROTO      0x04      /* protocol routing changed           */
    112 #define NFA_EE_ECB_FLAGS_AID        0x08      /* AID routing changed                */
    113 #define NFA_EE_ECB_FLAGS_VS         0x10      /* VS changed                         */
    114 #define NFA_EE_ECB_FLAGS_RESTORE    0x20      /* Restore related                    */
    115 #define NFA_EE_ECB_FLAGS_ROUTING    0x0E      /* routing flags changed              */
    116 #define NFA_EE_ECB_FLAGS_DISC_REQ   0x40      /* NFCEE Discover Request NTF is set  */
    117 #define NFA_EE_ECB_FLAGS_ORDER      0x80      /* DISC_REQ N reported before DISC N  */
    118 typedef UINT8 tNFA_EE_ECB_FLAGS;
    119 
    120 /* part of tNFA_EE_STATUS; for internal use only  */
    121 #define NFA_EE_STATUS_RESTORING 0x20      /* waiting for restore to full power mode to complete */
    122 #define NFA_EE_STATUS_INT_MASK  0x20      /* this bit is in ee_status for internal use only */
    123 
    124 /* NFA-EE information for a particular NFCEE Entity (including DH) */
    125 typedef struct
    126 {
    127     tNFA_TECHNOLOGY_MASK    tech_switch_on;     /* default routing - technologies switch_on  */
    128     tNFA_TECHNOLOGY_MASK    tech_switch_off;    /* default routing - technologies switch_off */
    129     tNFA_TECHNOLOGY_MASK    tech_battery_off;   /* default routing - technologies battery_off*/
    130     tNFA_PROTOCOL_MASK      proto_switch_on;    /* default routing - protocols switch_on     */
    131     tNFA_PROTOCOL_MASK      proto_switch_off;   /* default routing - protocols switch_off    */
    132     tNFA_PROTOCOL_MASK      proto_battery_off;  /* default routing - protocols battery_off   */
    133     tNFA_EE_CONN_ST         conn_st;            /* connection status */
    134     UINT8                   conn_id;            /* connection id */
    135     tNFA_EE_CBACK           *p_ee_cback;        /* the callback function */
    136 
    137     /* Each AID entry has an ssociated aid_len, aid_pwr_cfg, aid_rt_info.
    138      * aid_cfg[] contains AID and maybe some other VS information in TLV format
    139      * The first T is always NFA_EE_AID_CFG_TAG_NAME, the L is the actual AID length
    140      * the aid_len is the total length of all the TLVs associated with this AID entry
    141      */
    142     UINT8                   aid_len[NFA_EE_MAX_AID_ENTRIES];/* the actual lengths in aid_cfg */
    143     UINT8                   aid_pwr_cfg[NFA_EE_MAX_AID_ENTRIES];/* power configuration of this AID entry */
    144     UINT8                   aid_rt_info[NFA_EE_MAX_AID_ENTRIES];/* route/vs info for this AID entry */
    145     UINT8                   aid_cfg[NFA_EE_MAX_AID_CFG_LEN];/* routing entries based on AID */
    146     UINT8                   aid_entries;        /* The number of AID entries in aid_cfg */
    147     UINT8                   nfcee_id;           /* ID for this NFCEE */
    148     UINT8                   ee_status;          /* The NFCEE status */
    149     UINT8                   ee_old_status;      /* The NFCEE status before going to low power mode */
    150     tNFA_EE_INTERFACE       ee_interface[NFC_MAX_EE_INTERFACE];/* NFCEE supported interface */
    151     tNFA_EE_TLV             ee_tlv[NFC_MAX_EE_TLVS];/* the TLV */
    152     UINT8                   num_interface;      /* number of Target interface */
    153     UINT8                   num_tlvs;           /* number of TLVs */
    154     tNFA_EE_ECB_FLAGS       ecb_flags;          /* the flags of this control block */
    155     tNFA_EE_INTERFACE       use_interface;      /* NFCEE interface used for the connection */
    156     tNFA_NFC_PROTOCOL       la_protocol;        /* Listen A protocol    */
    157     tNFA_NFC_PROTOCOL       lb_protocol;        /* Listen B protocol    */
    158     tNFA_NFC_PROTOCOL       lf_protocol;        /* Listen F protocol    */
    159     tNFA_NFC_PROTOCOL       lbp_protocol;       /* Listen B' protocol   */
    160 } tNFA_EE_ECB;
    161 
    162 /* data type for NFA_EE_API_DISCOVER_EVT */
    163 typedef struct
    164 {
    165     BT_HDR              hdr;
    166     tNFA_EE_CBACK       *p_cback;
    167 } tNFA_EE_API_DISCOVER;
    168 
    169 /* data type for NFA_EE_API_REGISTER_EVT */
    170 typedef struct
    171 {
    172     BT_HDR              hdr;
    173     tNFA_EE_CBACK       *p_cback;
    174 } tNFA_EE_API_REGISTER;
    175 
    176 /* data type for NFA_EE_API_DEREGISTER_EVT */
    177 typedef struct
    178 {
    179     BT_HDR              hdr;
    180     int                 index;
    181 } tNFA_EE_API_DEREGISTER;
    182 
    183 /* data type for NFA_EE_API_MODE_SET_EVT */
    184 typedef struct
    185 {
    186     BT_HDR              hdr;
    187     tNFA_EE_ECB        *p_cb;
    188     UINT8               nfcee_id;
    189     UINT8               mode;
    190 } tNFA_EE_API_MODE_SET;
    191 
    192 /* data type for NFA_EE_API_SET_TECH_CFG_EVT */
    193 typedef struct
    194 {
    195     BT_HDR                  hdr;
    196     tNFA_EE_ECB            *p_cb;
    197     UINT8                   nfcee_id;
    198     tNFA_TECHNOLOGY_MASK    technologies_switch_on;
    199     tNFA_TECHNOLOGY_MASK    technologies_switch_off;
    200     tNFA_TECHNOLOGY_MASK    technologies_battery_off;
    201 } tNFA_EE_API_SET_TECH_CFG;
    202 
    203 /* data type for NFA_EE_API_SET_PROTO_CFG_EVT */
    204 typedef struct
    205 {
    206     BT_HDR              hdr;
    207     tNFA_EE_ECB        *p_cb;
    208     UINT8               nfcee_id;
    209     tNFA_PROTOCOL_MASK  protocols_switch_on;
    210     tNFA_PROTOCOL_MASK  protocols_switch_off;
    211     tNFA_PROTOCOL_MASK  protocols_battery_off;
    212 } tNFA_EE_API_SET_PROTO_CFG;
    213 
    214 /* data type for NFA_EE_API_ADD_AID_EVT */
    215 typedef struct
    216 {
    217     BT_HDR              hdr;
    218     tNFA_EE_ECB        *p_cb;
    219     UINT8               nfcee_id;
    220     UINT8               aid_len;
    221     UINT8               *p_aid;
    222     tNFA_EE_PWR_STATE   power_state;
    223 } tNFA_EE_API_ADD_AID;
    224 
    225 /* data type for NFA_EE_API_REMOVE_AID_EVT */
    226 typedef struct
    227 {
    228     BT_HDR              hdr;
    229     UINT8               aid_len;
    230     UINT8               *p_aid;
    231 } tNFA_EE_API_REMOVE_AID;
    232 
    233 /* data type for NFA_EE_API_CONNECT_EVT */
    234 typedef struct
    235 {
    236     BT_HDR              hdr;
    237     tNFA_EE_ECB        *p_cb;
    238     UINT8               nfcee_id;
    239     UINT8               ee_interface;
    240     tNFA_EE_CBACK       *p_cback;
    241 } tNFA_EE_API_CONNECT;
    242 
    243 /* data type for NFA_EE_API_SEND_DATA_EVT */
    244 typedef struct
    245 {
    246     BT_HDR              hdr;
    247     tNFA_EE_ECB        *p_cb;
    248     UINT8               nfcee_id;
    249     UINT16              data_len;
    250     UINT8               *p_data;
    251 } tNFA_EE_API_SEND_DATA;
    252 
    253 /* data type for NFA_EE_API_DISCONNECT_EVT */
    254 typedef struct
    255 {
    256     BT_HDR              hdr;
    257     tNFA_EE_ECB        *p_cb;
    258     UINT8               nfcee_id;
    259 } tNFA_EE_API_DISCONNECT;
    260 
    261 
    262 typedef struct
    263 {
    264     BT_HDR              hdr;
    265     tNFC_STATUS         status;                 /* The event status. */
    266 } tNFA_EE_MSG_STATUS;
    267 
    268 /* common data type for internal events with nfa_ee_use_cfg_cb[] as TRUE */
    269 typedef struct
    270 {
    271     BT_HDR              hdr;
    272     tNFA_EE_ECB        *p_cb;
    273     UINT8               nfcee_id;
    274 } tNFA_EE_CFG_HDR;
    275 
    276 /* data type for tNFC_RESPONSE_EVT */
    277 typedef struct
    278 {
    279     BT_HDR                      hdr;
    280     void                        *p_data;
    281 } tNFA_EE_NCI_RESPONSE;
    282 
    283 /* data type for NFA_EE_NCI_DISC_RSP_EVT */
    284 typedef struct
    285 {
    286     BT_HDR                      hdr;
    287     tNFC_NFCEE_DISCOVER_REVT    *p_data;
    288 } tNFA_EE_NCI_DISC_RSP;
    289 
    290 /* data type for NFA_EE_NCI_DISC_NTF_EVT */
    291 typedef struct
    292 {
    293     BT_HDR                      hdr;
    294     tNFC_NFCEE_INFO_REVT        *p_data;
    295 } tNFA_EE_NCI_DISC_NTF;
    296 
    297 /* data type for NFA_EE_NCI_MODE_SET_RSP_EVT */
    298 typedef struct
    299 {
    300     BT_HDR                      hdr;
    301     tNFC_NFCEE_MODE_SET_REVT    *p_data;
    302 } tNFA_EE_NCI_MODE_SET;
    303 
    304 /* data type for NFA_EE_NCI_CONN_EVT and NFA_EE_NCI_DATA_EVT */
    305 typedef struct
    306 {
    307     BT_HDR                      hdr;
    308     UINT8                       conn_id;
    309     tNFC_CONN_EVT               event;
    310     tNFC_CONN                   *p_data;
    311 } tNFA_EE_NCI_CONN;
    312 
    313 /* data type for NFA_EE_NCI_ACTION_NTF_EVT */
    314 typedef struct
    315 {
    316     BT_HDR                      hdr;
    317     tNFC_EE_ACTION_REVT         *p_data;
    318 } tNFA_EE_NCI_ACTION;
    319 
    320 /* data type for NFA_EE_NCI_DISC_REQ_NTF_EVT */
    321 typedef struct
    322 {
    323     BT_HDR                      hdr;
    324     tNFC_EE_DISCOVER_REQ_REVT   *p_data;
    325 } tNFA_EE_NCI_DISC_REQ;
    326 
    327 /* union of all event data types */
    328 typedef union
    329 {
    330     BT_HDR                      hdr;
    331     tNFA_EE_CFG_HDR             cfg_hdr;
    332     tNFA_EE_API_DISCOVER        ee_discover;
    333     tNFA_EE_API_REGISTER        ee_register;
    334     tNFA_EE_API_DEREGISTER      deregister;
    335     tNFA_EE_API_MODE_SET        mode_set;
    336     tNFA_EE_API_SET_TECH_CFG    set_tech;
    337     tNFA_EE_API_SET_PROTO_CFG   set_proto;
    338     tNFA_EE_API_ADD_AID         add_aid;
    339     tNFA_EE_API_REMOVE_AID      rm_aid;
    340     tNFA_EE_API_CONNECT         connect;
    341     tNFA_EE_API_SEND_DATA       send_data;
    342     tNFA_EE_API_DISCONNECT      disconnect;
    343     tNFA_EE_NCI_DISC_RSP        disc_rsp;
    344     tNFA_EE_NCI_DISC_NTF        disc_ntf;
    345     tNFA_EE_NCI_MODE_SET        mode_set_rsp;
    346     tNFA_EE_NCI_CONN            conn;
    347     tNFA_EE_NCI_ACTION          act;
    348     tNFA_EE_NCI_DISC_REQ        disc_req;
    349 } tNFA_EE_MSG;
    350 
    351 /* type for State Machine (SM) action functions */
    352 typedef void (*tNFA_EE_SM_ACT)(tNFA_EE_MSG *p_data);
    353 
    354 /*****************************************************************************
    355 **  control block
    356 *****************************************************************************/
    357 #define NFA_EE_CFGED_UPDATE_NOW         0x80
    358 #define NFA_EE_CFGED_OFF_ROUTING        0x40    /* either switch off or battery off is configured */
    359 
    360 /* the following status are the definition used in ee_cfg_sts */
    361 #define NFA_EE_STS_CHANGED_ROUTING      0x01
    362 #define NFA_EE_STS_CHANGED_VS           0x02
    363 #define NFA_EE_STS_CHANGED              0x0f
    364 #define NFA_EE_STS_PREV                 0xf0
    365 #define NFA_EE_STS_PREV_ROUTING         0x10
    366 
    367 #define NFA_EE_FLAG_WAIT_HCI            0x01    /* set this bit when waiting for HCI to finish the initialization process in NFA_EE_EM_STATE_RESTORING */
    368 #define NFA_EE_FLAG_NOTIFY_HCI          0x02    /* set this bit when EE needs to notify the p_enable_cback at the end of NFCEE discover process in NFA_EE_EM_STATE_RESTORING */
    369 typedef UINT8 tNFA_EE_FLAGS;
    370 
    371 typedef void (tNFA_EE_ENABLE_DONE_CBACK)(BOOLEAN disable_discover);
    372 
    373 /* NFA EE Management control block */
    374 typedef struct
    375 {
    376     tNFA_EE_ECB          ecb[NFA_EE_NUM_ECBS];   /* control block for DH and NFCEEs  */
    377     TIMER_LIST_ENT       timer;                  /* timer to send info to NFCC       */
    378     TIMER_LIST_ENT       discv_timer;            /* timer to end NFCEE discovery     */
    379     tNFA_EE_CBACK        *p_ee_cback[NFA_EE_MAX_CBACKS];/* to report EE events       */
    380     tNFA_EE_CBACK        *p_ee_disc_cback;       /* to report EE discovery result    */
    381     tNFA_EE_ENABLE_DONE_CBACK *p_enable_cback;   /* callback to notify on enable done*/
    382     tNFA_EE_EM_STATE     em_state;               /* NFA-EE state initialized or not  */
    383     UINT8                num_ee_expecting;       /* number of ee_info still expecting*/
    384     UINT8                cur_ee;                 /* the number of ee_info in cb      */
    385     UINT8                ee_cfged;               /* the bit mask of configured ECBs  */
    386     UINT8                ee_cfg_sts;             /* configuration status             */
    387     tNFA_EE_FLAGS        ee_flags;               /* flags                           */
    388 } tNFA_EE_CB;
    389 
    390 /*****************************************************************************
    391 **  External variables
    392 *****************************************************************************/
    393 
    394 /* NFA EE control block */
    395 #if NFA_DYNAMIC_MEMORY == FALSE
    396 extern tNFA_EE_CB nfa_ee_cb;
    397 #else
    398 extern tNFA_EE_CB *nfa_ee_cb_ptr;
    399 #define nfa_ee_cb (*nfa_ee_cb_ptr)
    400 #endif
    401 
    402 /*****************************************************************************
    403 **  External functions
    404 *****************************************************************************/
    405 /* function prototypes - exported from nfa_ee_main.c */
    406 void nfa_ee_sys_enable (void);
    407 void nfa_ee_sys_disable (void);
    408 
    409 /* event handler function type */
    410 BOOLEAN nfa_ee_evt_hdlr (BT_HDR *p_msg);
    411 void nfa_ee_proc_nfcc_power_mode (UINT8 nfcc_power_mode);
    412 #if (NFC_NFCEE_INCLUDED == TRUE)
    413 void nfa_ee_get_tech_route (UINT8 power_state, UINT8 *p_handles);
    414 #endif
    415 void nfa_ee_proc_evt(tNFC_RESPONSE_EVT event, void *p_data);
    416 tNFA_EE_ECB * nfa_ee_find_ecb (UINT8 nfcee_id);
    417 tNFA_EE_ECB * nfa_ee_find_ecb_by_conn_id (UINT8 conn_id);
    418 UINT8 nfa_ee_ecb_to_mask (tNFA_EE_ECB *p_cb);
    419 void nfa_ee_restore_one_ecb (tNFA_EE_ECB *p_cb);
    420 BOOLEAN nfa_ee_is_active (tNFA_HANDLE nfcee_id);
    421 
    422 /* Action function prototypes - nfa_ee_act.c */
    423 void nfa_ee_api_discover(tNFA_EE_MSG *p_data);
    424 void nfa_ee_api_register(tNFA_EE_MSG *p_data);
    425 void nfa_ee_api_deregister(tNFA_EE_MSG *p_data);
    426 void nfa_ee_api_mode_set(tNFA_EE_MSG *p_data);
    427 void nfa_ee_api_set_tech_cfg(tNFA_EE_MSG *p_data);
    428 void nfa_ee_api_set_proto_cfg(tNFA_EE_MSG *p_data);
    429 void nfa_ee_api_add_aid(tNFA_EE_MSG *p_data);
    430 void nfa_ee_api_remove_aid(tNFA_EE_MSG *p_data);
    431 void nfa_ee_api_update_now(tNFA_EE_MSG *p_data);
    432 void nfa_ee_api_connect(tNFA_EE_MSG *p_data);
    433 void nfa_ee_api_send_data(tNFA_EE_MSG *p_data);
    434 void nfa_ee_api_disconnect(tNFA_EE_MSG *p_data);
    435 void nfa_ee_report_disc_done(BOOLEAN notify_sys);
    436 void nfa_ee_nci_disc_rsp(tNFA_EE_MSG *p_data);
    437 void nfa_ee_nci_disc_ntf(tNFA_EE_MSG *p_data);
    438 void nfa_ee_nci_mode_set_rsp(tNFA_EE_MSG *p_data);
    439 void nfa_ee_nci_conn(tNFA_EE_MSG *p_data);
    440 void nfa_ee_nci_action_ntf(tNFA_EE_MSG *p_data);
    441 void nfa_ee_nci_disc_req_ntf(tNFA_EE_MSG *p_data);
    442 void nfa_ee_rout_timeout(tNFA_EE_MSG *p_data);
    443 void nfa_ee_discv_timeout(tNFA_EE_MSG *p_data);
    444 void nfa_ee_lmrt_to_nfcc(tNFA_EE_MSG *p_data);
    445 void nfa_ee_update_rout(void);
    446 void nfa_ee_report_event(tNFA_EE_CBACK *p_cback, tNFA_EE_EVT event, tNFA_EE_CBACK_DATA *p_data);
    447 tNFA_EE_ECB * nfa_ee_find_aid_offset(UINT8 aid_len, UINT8 *p_aid, int *p_offset, int *p_entry);
    448 void nfa_ee_remove_labels(void);
    449 int nfa_ee_find_total_aid_len(tNFA_EE_ECB *p_cb, int start_entry);
    450 void nfa_ee_start_timer(void);
    451 void nfa_ee_reg_cback_enable_done (tNFA_EE_ENABLE_DONE_CBACK *p_cback);
    452 
    453 extern void nfa_ee_proc_hci_info_cback (void);
    454 
    455 
    456 #endif /* NFA_P2P_INT_H */
    457