Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * NCI based Driver for STMicroelectronics NFC Chip
0004  *
0005  * Copyright (C) 2014  STMicroelectronics SAS. All rights reserved.
0006  */
0007 
0008 #ifndef __LOCAL_ST_NCI_H_
0009 #define __LOCAL_ST_NCI_H_
0010 
0011 #include "ndlc.h"
0012 
0013 /* Define private flags: */
0014 #define ST_NCI_RUNNING          1
0015 
0016 #define ST_NCI_CORE_PROP                0x01
0017 #define ST_NCI_SET_NFC_MODE             0x02
0018 
0019 /*
0020  * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
0021  * sequence of at most 32 characters.
0022  */
0023 #define ST_NCI_ESE_MAX_LENGTH  33
0024 
0025 #define ST_NCI_DEVICE_MGNT_GATE     0x01
0026 
0027 #define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */
0028 #define ST_NCI_FACTORY_MODE 2
0029 
0030 struct nci_mode_set_cmd {
0031     u8 cmd_type;
0032     u8 mode;
0033 } __packed;
0034 
0035 struct nci_mode_set_rsp {
0036     u8 status;
0037 } __packed;
0038 
0039 struct st_nci_se_status {
0040     bool is_ese_present;
0041     bool is_uicc_present;
0042 };
0043 
0044 struct st_nci_se_info {
0045     struct st_nci_se_status *se_status;
0046     u8 atr[ST_NCI_ESE_MAX_LENGTH];
0047     struct completion req_completion;
0048 
0049     struct timer_list bwi_timer;
0050     int wt_timeout; /* in msecs */
0051     bool bwi_active;
0052 
0053     struct timer_list se_active_timer;
0054     bool se_active;
0055 
0056     bool xch_error;
0057 
0058     se_io_cb_t cb;
0059     void *cb_context;
0060 };
0061 
0062 /**
0063  * enum nfc_vendor_cmds - supported nfc vendor commands
0064  *
0065  * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
0066  *  are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
0067  * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
0068  *  It does not consider any NFC_ATTR_VENDOR_DATA.
0069  * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
0070  *  RF trimmings or low level drivers configurations (I2C, SPI, SWP).
0071  * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
0072  *  table following RF technology, CLF mode or protocol.
0073  * @HCI_DM_GET_INFO: Allow to retrieve CLF information.
0074  * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
0075  *  level drivers configurations or RF trimmings.
0076  * @HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
0077  *  packet can be more than 8KB.
0078  * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
0079  *  configuration changes without CLF power off.
0080  * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
0081  *  white list).
0082  * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
0083  *  technology. When using this command to anti-collision is done.
0084  * @LOOPBACK: Allow to echo a command and test the Dh to CLF connectivity.
0085  * @HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
0086  *  CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
0087  * @HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
0088  *  specific CLF command as there is no GPIO for this.
0089  * @HCI_DM_FWUPD_END:  Allow to complete firmware update.
0090  * @HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
0091  *  CLF antenna to a reference value.
0092  * @MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
0093  *  received during a NCI_CORE_INIT_CMD.
0094  */
0095 enum nfc_vendor_cmds {
0096     FACTORY_MODE,
0097     HCI_CLEAR_ALL_PIPES,
0098     HCI_DM_PUT_DATA,
0099     HCI_DM_UPDATE_AID,
0100     HCI_DM_GET_INFO,
0101     HCI_DM_GET_DATA,
0102     HCI_DM_DIRECT_LOAD,
0103     HCI_DM_RESET,
0104     HCI_GET_PARAM,
0105     HCI_DM_FIELD_GENERATOR,
0106     LOOPBACK,
0107     HCI_DM_FWUPD_START,
0108     HCI_DM_FWUPD_END,
0109     HCI_DM_VDC_MEASUREMENT_VALUE,
0110     HCI_DM_VDC_VALUE_COMPARISON,
0111     MANUFACTURER_SPECIFIC,
0112 };
0113 
0114 struct st_nci_info {
0115     struct llt_ndlc *ndlc;
0116     unsigned long flags;
0117 
0118     struct st_nci_se_info se_info;
0119 };
0120 
0121 void st_nci_remove(struct nci_dev *ndev);
0122 int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
0123          int phy_tailroom, struct st_nci_se_status *se_status);
0124 
0125 int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status);
0126 void st_nci_se_deinit(struct nci_dev *ndev);
0127 
0128 int st_nci_discover_se(struct nci_dev *ndev);
0129 int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
0130 int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
0131 int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
0132                 u8 *apdu, size_t apdu_length,
0133                 se_io_cb_t cb, void *cb_context);
0134 int st_nci_hci_load_session(struct nci_dev *ndev);
0135 void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
0136                     u8 event, struct sk_buff *skb);
0137 void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
0138                         struct sk_buff *skb);
0139 
0140 int st_nci_vendor_cmds_init(struct nci_dev *ndev);
0141 
0142 #endif /* __LOCAL_ST_NCI_H_ */