^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * NCI based Driver for STMicroelectronics NFC Chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef __LOCAL_ST_NCI_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define __LOCAL_ST_NCI_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "ndlc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /* Define private flags: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define ST_NCI_RUNNING 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define ST_NCI_CORE_PROP 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ST_NCI_SET_NFC_MODE 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * sequence of at most 32 characters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define ST_NCI_ESE_MAX_LENGTH 33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define ST_NCI_DEVICE_MGNT_GATE 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define ST_NCI_FACTORY_MODE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct nci_mode_set_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u8 cmd_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct nci_mode_set_rsp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct st_nci_se_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) bool is_ese_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) bool is_uicc_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct st_nci_se_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct st_nci_se_status *se_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u8 atr[ST_NCI_ESE_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct completion req_completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct timer_list bwi_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int wt_timeout; /* in msecs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) bool bwi_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct timer_list se_active_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) bool se_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) bool xch_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) se_io_cb_t cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void *cb_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * enum nfc_vendor_cmds - supported nfc vendor commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * It does not consider any NFC_ATTR_VENDOR_DATA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * RF trimmings or low level drivers configurations (I2C, SPI, SWP).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * table following RF technology, CLF mode or protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @HCI_DM_GET_INFO: Allow to retrieve CLF information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * level drivers configurations or RF trimmings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * packet can be more than 8KB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * configuration changes without CLF power off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * white list).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * technology. When using this command to anti-collision is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @LOOPBACK: Allow to echo a command and test the Dh to CLF connectivity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * @HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * specific CLF command as there is no GPIO for this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * @HCI_DM_FWUPD_END: Allow to complete firmware update.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * @HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * CLF antenna to a reference value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * received during a NCI_CORE_INIT_CMD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) enum nfc_vendor_cmds {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) FACTORY_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) HCI_CLEAR_ALL_PIPES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) HCI_DM_PUT_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) HCI_DM_UPDATE_AID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) HCI_DM_GET_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) HCI_DM_GET_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) HCI_DM_DIRECT_LOAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) HCI_DM_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) HCI_GET_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) HCI_DM_FIELD_GENERATOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) LOOPBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) HCI_DM_FWUPD_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) HCI_DM_FWUPD_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) HCI_DM_VDC_MEASUREMENT_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) HCI_DM_VDC_VALUE_COMPARISON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) MANUFACTURER_SPECIFIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct st_nci_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct llt_ndlc *ndlc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct st_nci_se_info se_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void st_nci_remove(struct nci_dev *ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int phy_tailroom, struct st_nci_se_status *se_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void st_nci_se_deinit(struct nci_dev *ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int st_nci_discover_se(struct nci_dev *ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u8 *apdu, size_t apdu_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) se_io_cb_t cb, void *cb_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int st_nci_hci_load_session(struct nci_dev *ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u8 event, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int st_nci_vendor_cmds_init(struct nci_dev *ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #endif /* __LOCAL_ST_NCI_H_ */