xref: /openbmc/linux/net/nfc/nfc.h (revision d646960f7986fefb460a2b062d5ccc8ccfeacc3a)
13e256b8fSLauro Ramos Venancio /*
23e256b8fSLauro Ramos Venancio  * Copyright (C) 2011 Instituto Nokia de Tecnologia
33e256b8fSLauro Ramos Venancio  *
43e256b8fSLauro Ramos Venancio  * Authors:
53e256b8fSLauro Ramos Venancio  *    Lauro Ramos Venancio <lauro.venancio@openbossa.org>
63e256b8fSLauro Ramos Venancio  *    Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
73e256b8fSLauro Ramos Venancio  *
83e256b8fSLauro Ramos Venancio  * This program is free software; you can redistribute it and/or modify
93e256b8fSLauro Ramos Venancio  * it under the terms of the GNU General Public License as published by
103e256b8fSLauro Ramos Venancio  * the Free Software Foundation; either version 2 of the License, or
113e256b8fSLauro Ramos Venancio  * (at your option) any later version.
123e256b8fSLauro Ramos Venancio  *
133e256b8fSLauro Ramos Venancio  * This program is distributed in the hope that it will be useful,
143e256b8fSLauro Ramos Venancio  * but WITHOUT ANY WARRANTY; without even the implied warranty of
153e256b8fSLauro Ramos Venancio  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
163e256b8fSLauro Ramos Venancio  * GNU General Public License for more details.
173e256b8fSLauro Ramos Venancio  *
183e256b8fSLauro Ramos Venancio  * You should have received a copy of the GNU General Public License
193e256b8fSLauro Ramos Venancio  * along with this program; if not, write to the
203e256b8fSLauro Ramos Venancio  * Free Software Foundation, Inc.,
213e256b8fSLauro Ramos Venancio  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
223e256b8fSLauro Ramos Venancio  */
233e256b8fSLauro Ramos Venancio 
243e256b8fSLauro Ramos Venancio #ifndef __LOCAL_NFC_H
253e256b8fSLauro Ramos Venancio #define __LOCAL_NFC_H
263e256b8fSLauro Ramos Venancio 
2755eb94f9SIlan Elias #include <net/nfc/nfc.h>
28c7fe3b52SAloisio Almeida Jr #include <net/sock.h>
293e256b8fSLauro Ramos Venancio 
30c7fe3b52SAloisio Almeida Jr struct nfc_protocol {
31c7fe3b52SAloisio Almeida Jr 	int id;
32c7fe3b52SAloisio Almeida Jr 	struct proto *proto;
33c7fe3b52SAloisio Almeida Jr 	struct module *owner;
34c7fe3b52SAloisio Almeida Jr 	int (*create)(struct net *net, struct socket *sock,
35c7fe3b52SAloisio Almeida Jr 			const struct nfc_protocol *nfc_proto);
36c7fe3b52SAloisio Almeida Jr };
37c7fe3b52SAloisio Almeida Jr 
3823b7869cSLauro Ramos Venancio struct nfc_rawsock {
3923b7869cSLauro Ramos Venancio 	struct sock sk;
4023b7869cSLauro Ramos Venancio 	struct nfc_dev *dev;
4123b7869cSLauro Ramos Venancio 	u32 target_idx;
4223b7869cSLauro Ramos Venancio 	struct work_struct tx_work;
4323b7869cSLauro Ramos Venancio 	bool tx_work_scheduled;
4423b7869cSLauro Ramos Venancio };
4523b7869cSLauro Ramos Venancio #define nfc_rawsock(sk) ((struct nfc_rawsock *) sk)
4623b7869cSLauro Ramos Venancio #define to_rawsock_sk(_tx_work) \
4723b7869cSLauro Ramos Venancio 	((struct sock *) container_of(_tx_work, struct nfc_rawsock, tx_work))
4823b7869cSLauro Ramos Venancio 
49*d646960fSSamuel Ortiz #ifdef CONFIG_NFC_LLCP
50*d646960fSSamuel Ortiz 
51*d646960fSSamuel Ortiz void nfc_llcp_mac_is_down(struct nfc_dev *dev);
52*d646960fSSamuel Ortiz void nfc_llcp_mac_is_up(struct nfc_dev *dev, u32 target_idx,
53*d646960fSSamuel Ortiz 			u8 comm_mode, u8 rf_mode);
54*d646960fSSamuel Ortiz int nfc_llcp_register_device(struct nfc_dev *dev);
55*d646960fSSamuel Ortiz void nfc_llcp_unregister_device(struct nfc_dev *dev);
56*d646960fSSamuel Ortiz int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len);
57*d646960fSSamuel Ortiz u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, u8 *general_bytes_len);
58*d646960fSSamuel Ortiz int __init nfc_llcp_init(void);
59*d646960fSSamuel Ortiz void nfc_llcp_exit(void);
60*d646960fSSamuel Ortiz 
61*d646960fSSamuel Ortiz #else
62*d646960fSSamuel Ortiz 
63*d646960fSSamuel Ortiz void nfc_llcp_mac_is_down(struct nfc_dev *dev)
64*d646960fSSamuel Ortiz {
65*d646960fSSamuel Ortiz }
66*d646960fSSamuel Ortiz 
67*d646960fSSamuel Ortiz void nfc_llcp_mac_is_up(struct nfc_dev *dev, u32 target_idx,
68*d646960fSSamuel Ortiz 			u8 comm_mode, u8 rf_mode)
69*d646960fSSamuel Ortiz {
70*d646960fSSamuel Ortiz }
71*d646960fSSamuel Ortiz 
72*d646960fSSamuel Ortiz static inline int nfc_llcp_register_device(struct nfc_dev *dev)
73*d646960fSSamuel Ortiz {
74*d646960fSSamuel Ortiz 	return 0;
75*d646960fSSamuel Ortiz }
76*d646960fSSamuel Ortiz 
77*d646960fSSamuel Ortiz static inline void nfc_llcp_unregister_device(struct nfc_dev *dev)
78*d646960fSSamuel Ortiz {
79*d646960fSSamuel Ortiz }
80*d646960fSSamuel Ortiz 
81*d646960fSSamuel Ortiz static inline int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len)
82*d646960fSSamuel Ortiz {
83*d646960fSSamuel Ortiz 	return 0;
84*d646960fSSamuel Ortiz }
85*d646960fSSamuel Ortiz 
86*d646960fSSamuel Ortiz static inline u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, u8 *gb_len)
87*d646960fSSamuel Ortiz {
88*d646960fSSamuel Ortiz 	*gb_len = 0;
89*d646960fSSamuel Ortiz 	return NULL;
90*d646960fSSamuel Ortiz }
91*d646960fSSamuel Ortiz 
92*d646960fSSamuel Ortiz static inline int nfc_llcp_init(void)
93*d646960fSSamuel Ortiz {
94*d646960fSSamuel Ortiz 	return 0;
95*d646960fSSamuel Ortiz }
96*d646960fSSamuel Ortiz 
97*d646960fSSamuel Ortiz static inline void nfc_llcp_exit(void)
98*d646960fSSamuel Ortiz {
99*d646960fSSamuel Ortiz }
100*d646960fSSamuel Ortiz 
101*d646960fSSamuel Ortiz #endif
102*d646960fSSamuel Ortiz 
10323b7869cSLauro Ramos Venancio int __init rawsock_init(void);
10423b7869cSLauro Ramos Venancio void rawsock_exit(void);
10523b7869cSLauro Ramos Venancio 
106c7fe3b52SAloisio Almeida Jr int __init af_nfc_init(void);
107c7fe3b52SAloisio Almeida Jr void af_nfc_exit(void);
108c7fe3b52SAloisio Almeida Jr int nfc_proto_register(const struct nfc_protocol *nfc_proto);
109c7fe3b52SAloisio Almeida Jr void nfc_proto_unregister(const struct nfc_protocol *nfc_proto);
110c7fe3b52SAloisio Almeida Jr 
1113e256b8fSLauro Ramos Venancio extern int nfc_devlist_generation;
1123e256b8fSLauro Ramos Venancio extern struct mutex nfc_devlist_mutex;
1133e256b8fSLauro Ramos Venancio 
1144d12b8b1SLauro Ramos Venancio int __init nfc_genl_init(void);
1154d12b8b1SLauro Ramos Venancio void nfc_genl_exit(void);
1164d12b8b1SLauro Ramos Venancio 
1174d12b8b1SLauro Ramos Venancio void nfc_genl_data_init(struct nfc_genl_data *genl_data);
1184d12b8b1SLauro Ramos Venancio void nfc_genl_data_exit(struct nfc_genl_data *genl_data);
1194d12b8b1SLauro Ramos Venancio 
1204d12b8b1SLauro Ramos Venancio int nfc_genl_targets_found(struct nfc_dev *dev);
1214d12b8b1SLauro Ramos Venancio 
1224d12b8b1SLauro Ramos Venancio int nfc_genl_device_added(struct nfc_dev *dev);
1234d12b8b1SLauro Ramos Venancio int nfc_genl_device_removed(struct nfc_dev *dev);
1244d12b8b1SLauro Ramos Venancio 
1251ed28f61SSamuel Ortiz int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
1261ed28f61SSamuel Ortiz 			       u8 comm_mode, u8 rf_mode);
1271ed28f61SSamuel Ortiz int nfc_genl_dep_link_down_event(struct nfc_dev *dev);
1281ed28f61SSamuel Ortiz 
1293e256b8fSLauro Ramos Venancio struct nfc_dev *nfc_get_device(unsigned idx);
1303e256b8fSLauro Ramos Venancio 
1313e256b8fSLauro Ramos Venancio static inline void nfc_put_device(struct nfc_dev *dev)
1323e256b8fSLauro Ramos Venancio {
1333e256b8fSLauro Ramos Venancio 	put_device(&dev->dev);
1343e256b8fSLauro Ramos Venancio }
1353e256b8fSLauro Ramos Venancio 
1363e256b8fSLauro Ramos Venancio static inline void nfc_device_iter_init(struct class_dev_iter *iter)
1373e256b8fSLauro Ramos Venancio {
1383e256b8fSLauro Ramos Venancio 	class_dev_iter_init(iter, &nfc_class, NULL, NULL);
1393e256b8fSLauro Ramos Venancio }
1403e256b8fSLauro Ramos Venancio 
1413e256b8fSLauro Ramos Venancio static inline struct nfc_dev *nfc_device_iter_next(struct class_dev_iter *iter)
1423e256b8fSLauro Ramos Venancio {
1433e256b8fSLauro Ramos Venancio 	struct device *d = class_dev_iter_next(iter);
1443e256b8fSLauro Ramos Venancio 	if (!d)
1453e256b8fSLauro Ramos Venancio 		return NULL;
1463e256b8fSLauro Ramos Venancio 
1473e256b8fSLauro Ramos Venancio 	return to_nfc_dev(d);
1483e256b8fSLauro Ramos Venancio }
1493e256b8fSLauro Ramos Venancio 
1503e256b8fSLauro Ramos Venancio static inline void nfc_device_iter_exit(struct class_dev_iter *iter)
1513e256b8fSLauro Ramos Venancio {
1523e256b8fSLauro Ramos Venancio 	class_dev_iter_exit(iter);
1533e256b8fSLauro Ramos Venancio }
1543e256b8fSLauro Ramos Venancio 
1558b3fe7b5SIlan Elias int nfc_dev_up(struct nfc_dev *dev);
1568b3fe7b5SIlan Elias 
1578b3fe7b5SIlan Elias int nfc_dev_down(struct nfc_dev *dev);
1588b3fe7b5SIlan Elias 
1593e256b8fSLauro Ramos Venancio int nfc_start_poll(struct nfc_dev *dev, u32 protocols);
1603e256b8fSLauro Ramos Venancio 
1613e256b8fSLauro Ramos Venancio int nfc_stop_poll(struct nfc_dev *dev);
1623e256b8fSLauro Ramos Venancio 
1631ed28f61SSamuel Ortiz int nfc_dep_link_up(struct nfc_dev *dev, int target_idx,
1641ed28f61SSamuel Ortiz 				u8 comm_mode, u8 rf_mode);
1651ed28f61SSamuel Ortiz 
1661ed28f61SSamuel Ortiz int nfc_dep_link_down(struct nfc_dev *dev);
1671ed28f61SSamuel Ortiz 
1683e256b8fSLauro Ramos Venancio int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol);
1693e256b8fSLauro Ramos Venancio 
1703e256b8fSLauro Ramos Venancio int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx);
1713e256b8fSLauro Ramos Venancio 
1723e256b8fSLauro Ramos Venancio int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx,
1733e256b8fSLauro Ramos Venancio 					struct sk_buff *skb,
1743e256b8fSLauro Ramos Venancio 					data_exchange_cb_t cb,
1753e256b8fSLauro Ramos Venancio 					void *cb_context);
1763e256b8fSLauro Ramos Venancio 
1773e256b8fSLauro Ramos Venancio #endif /* __LOCAL_NFC_H */
178