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