Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2011 Instituto Nokia de Tecnologia
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2014 Marvell International Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    Lauro Ramos Venancio <lauro.venancio@openbossa.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *    Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #ifndef __NET_NFC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define __NET_NFC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/nfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define nfc_dbg(dev, fmt, ...) dev_dbg((dev), "NFC: " fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define nfc_info(dev, fmt, ...) dev_info((dev), "NFC: " fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define nfc_err(dev, fmt, ...) dev_err((dev), "NFC: " fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct nfc_phy_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int (*write)(void *dev_id, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	int (*enable)(void *dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	void (*disable)(void *dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct nfc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * data_exchange_cb_t - Definition of nfc_data_exchange callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * @context: nfc_data_exchange cb_context parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * @skb: response data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * @err: If an error has occurred during data exchange, it is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *	error number. Zero means no error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * When a rx or tx package is lost or corrupted or the target gets out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * of the operating field, err is -EIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) typedef void (*data_exchange_cb_t)(void *context, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 								int err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) typedef void (*se_io_cb_t)(void *context, u8 *apdu, size_t apdu_len, int err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) struct nfc_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) struct nfc_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int (*dev_up)(struct nfc_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	int (*dev_down)(struct nfc_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int (*start_poll)(struct nfc_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			  u32 im_protocols, u32 tm_protocols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	void (*stop_poll)(struct nfc_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int (*dep_link_up)(struct nfc_dev *dev, struct nfc_target *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			   u8 comm_mode, u8 *gb, size_t gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int (*dep_link_down)(struct nfc_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int (*activate_target)(struct nfc_dev *dev, struct nfc_target *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			       u32 protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	void (*deactivate_target)(struct nfc_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 				  struct nfc_target *target, u8 mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	int (*im_transceive)(struct nfc_dev *dev, struct nfc_target *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			     struct sk_buff *skb, data_exchange_cb_t cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			     void *cb_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int (*fw_download)(struct nfc_dev *dev, const char *firmware_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	/* Secure Element API */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	int (*discover_se)(struct nfc_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int (*enable_se)(struct nfc_dev *dev, u32 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int (*disable_se)(struct nfc_dev *dev, u32 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int (*se_io) (struct nfc_dev *dev, u32 se_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		      u8 *apdu, size_t apdu_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		      se_io_cb_t cb, void *cb_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define NFC_TARGET_IDX_ANY -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define NFC_MAX_GT_LEN 48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define NFC_ATR_RES_GT_OFFSET 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define NFC_ATR_REQ_GT_OFFSET 14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * struct nfc_target - NFC target descriptiom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * @sens_res: 2 bytes describing the target SENS_RES response, if the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *	is a type A one. The %sens_res most significant byte must be byte 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *	as described by the NFC Forum digital specification (i.e. the platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *	configuration one) while %sens_res least significant byte is byte 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) struct nfc_target {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u32 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	u32 supported_protocols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	u16 sens_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	u8 sel_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	u8 nfcid1_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	u8 nfcid1[NFC_NFCID1_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	u8 nfcid2_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	u8 nfcid2[NFC_NFCID2_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	u8 sensb_res_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	u8 sensb_res[NFC_SENSB_RES_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	u8 sensf_res_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	u8 sensf_res[NFC_SENSF_RES_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	u8 hci_reader_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	u8 logical_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	u8 is_iso15693;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	u8 iso15693_dsfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	u8 iso15693_uid[NFC_ISO15693_UID_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * nfc_se - A structure for NFC accessible secure elements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * @idx: The secure element index. User space will enable or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  *       disable a secure element by its index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * @type: The secure element type. It can be SE_UICC or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  *        SE_EMBEDDED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * @state: The secure element state, either enabled or disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct nfc_se {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	u32 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	u16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	u16 state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * nfc_evt_transaction - A struct for NFC secure element event transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * @aid: The application identifier triggering the event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * @aid_len: The application identifier length [5:16]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * @params: The application parameters transmitted during the transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * @params_len: The applications parameters length [0:255]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define NFC_MIN_AID_LENGTH	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #define	NFC_MAX_AID_LENGTH	16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define NFC_MAX_PARAMS_LENGTH	255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define NFC_EVT_TRANSACTION_AID_TAG	0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define NFC_EVT_TRANSACTION_PARAMS_TAG	0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct nfc_evt_transaction {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	u32 aid_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	u8 aid[NFC_MAX_AID_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	u8 params_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	u8 params[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct nfc_genl_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	u32 poll_req_portid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct mutex genl_data_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct nfc_vendor_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	__u32 vendor_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	__u32 subcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	int (*doit)(struct nfc_dev *dev, void *data, size_t data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct nfc_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	u32 target_next_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct nfc_target *targets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int n_targets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int targets_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	bool dev_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	bool fw_download_in_progress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	u8 rf_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	bool polling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct nfc_target *active_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	bool dep_link_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct nfc_genl_data genl_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	u32 supported_protocols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct list_head secure_elements;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int tx_headroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	int tx_tailroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct timer_list check_pres_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct work_struct check_pres_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	bool shutting_down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct rfkill *rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct nfc_vendor_cmd *vendor_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	int n_vendor_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct nfc_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct genl_info *cur_cmd_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define to_nfc_dev(_dev) container_of(_dev, struct nfc_dev, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) extern struct class nfc_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				    u32 supported_protocols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 				    int tx_headroom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				    int tx_tailroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * nfc_free_device - free nfc device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * @dev: The nfc device to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static inline void nfc_free_device(struct nfc_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	put_device(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int nfc_register_device(struct nfc_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) void nfc_unregister_device(struct nfc_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * nfc_set_parent_dev - set the parent device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * @nfc_dev: The nfc device whose parent is being set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * @dev: The parent device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static inline void nfc_set_parent_dev(struct nfc_dev *nfc_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				      struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	nfc_dev->dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * nfc_set_drvdata - set driver specifc data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * @dev: The nfc device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * @data: Pointer to driver specifc data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static inline void nfc_set_drvdata(struct nfc_dev *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	dev_set_drvdata(&dev->dev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * nfc_get_drvdata - get driver specifc data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * @dev: The nfc device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static inline void *nfc_get_drvdata(struct nfc_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return dev_get_drvdata(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * nfc_device_name - get the nfc device name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * @dev: The nfc device whose name to return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static inline const char *nfc_device_name(struct nfc_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return dev_name(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 				   unsigned int flags, unsigned int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 				   unsigned int *err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) int nfc_set_remote_general_bytes(struct nfc_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				 u8 *gt, u8 gt_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, size_t *gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int nfc_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			 u32 result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int nfc_targets_found(struct nfc_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		      struct nfc_target *targets, int ntargets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int nfc_target_lost(struct nfc_dev *dev, u32 target_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		       u8 comm_mode, u8 rf_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		     u8 *gb, size_t gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int nfc_tm_deactivated(struct nfc_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) void nfc_driver_failure(struct nfc_dev *dev, int err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int nfc_se_transaction(struct nfc_dev *dev, u8 se_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		       struct nfc_evt_transaction *evt_transaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int nfc_se_connectivity(struct nfc_dev *dev, u8 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) int nfc_remove_se(struct nfc_dev *dev, u32 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct nfc_se *nfc_find_se(struct nfc_dev *dev, u32 se_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) void nfc_send_to_raw_sock(struct nfc_dev *dev, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			  u8 payload_type, u8 direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline int nfc_set_vendor_cmds(struct nfc_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				      struct nfc_vendor_cmd *cmds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 				      int n_cmds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (dev->vendor_cmds || dev->n_vendor_cmds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	dev->vendor_cmds = cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	dev->n_vendor_cmds = n_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct sk_buff *__nfc_alloc_vendor_cmd_reply_skb(struct nfc_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 						 enum nfc_attrs attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 						 u32 oui, u32 subcmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 						 int approxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int nfc_vendor_cmd_reply(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * nfc_vendor_cmd_alloc_reply_skb - allocate vendor command reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * @dev: nfc device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * @oui: vendor oui
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * @approxlen: an upper bound of the length of the data that will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  *      be put into the skb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * This function allocates and pre-fills an skb for a reply to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * a vendor command. Since it is intended for a reply, calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * it outside of a vendor command's doit() operation is invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * The returned skb is pre-filled with some identifying data in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  * a way that any data that is put into the skb (with skb_put(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * nla_put() or similar) will end up being within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * %NFC_ATTR_VENDOR_DATA attribute, so all that needs to be done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * with the skb is adding data for the corresponding userspace tool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * which can then read that data out of the vendor data attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * You must not modify the skb in any other way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  * When done, call nfc_vendor_cmd_reply() with the skb and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * its error code as the result of the doit() operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  * Return: An allocated and pre-filled skb. %NULL if any errors happen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static inline struct sk_buff *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) nfc_vendor_cmd_alloc_reply_skb(struct nfc_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				u32 oui, u32 subcmd, int approxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	return __nfc_alloc_vendor_cmd_reply_skb(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 						NFC_ATTR_VENDOR_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 						oui,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 						subcmd, approxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) #endif /* __NET_NFC_H */