11ccea77eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
23e256b8fSLauro Ramos Venancio /*
33e256b8fSLauro Ramos Venancio * Copyright (C) 2011 Instituto Nokia de Tecnologia
43e256b8fSLauro Ramos Venancio *
53e256b8fSLauro Ramos Venancio * Authors:
63e256b8fSLauro Ramos Venancio * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
73e256b8fSLauro Ramos Venancio * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
83e256b8fSLauro Ramos Venancio */
93e256b8fSLauro Ramos Venancio
103e256b8fSLauro Ramos Venancio #ifndef __LOCAL_NFC_H
113e256b8fSLauro Ramos Venancio #define __LOCAL_NFC_H
123e256b8fSLauro Ramos Venancio
1355eb94f9SIlan Elias #include <net/nfc/nfc.h>
14c7fe3b52SAloisio Almeida Jr #include <net/sock.h>
153e256b8fSLauro Ramos Venancio
1696d4581fSChristophe Ricard #define NFC_TARGET_MODE_IDLE 0
1796d4581fSChristophe Ricard #define NFC_TARGET_MODE_SLEEP 1
1896d4581fSChristophe Ricard
19c7fe3b52SAloisio Almeida Jr struct nfc_protocol {
20c7fe3b52SAloisio Almeida Jr int id;
21c7fe3b52SAloisio Almeida Jr struct proto *proto;
22c7fe3b52SAloisio Almeida Jr struct module *owner;
23c7fe3b52SAloisio Almeida Jr int (*create)(struct net *net, struct socket *sock,
2411aa9c28SEric W. Biederman const struct nfc_protocol *nfc_proto, int kern);
25c7fe3b52SAloisio Almeida Jr };
26c7fe3b52SAloisio Almeida Jr
2723b7869cSLauro Ramos Venancio struct nfc_rawsock {
2823b7869cSLauro Ramos Venancio struct sock sk;
2923b7869cSLauro Ramos Venancio struct nfc_dev *dev;
3023b7869cSLauro Ramos Venancio u32 target_idx;
3123b7869cSLauro Ramos Venancio struct work_struct tx_work;
3223b7869cSLauro Ramos Venancio bool tx_work_scheduled;
3323b7869cSLauro Ramos Venancio };
3457be1f3fSHiren Tandel
3557be1f3fSHiren Tandel struct nfc_sock_list {
3657be1f3fSHiren Tandel struct hlist_head head;
3757be1f3fSHiren Tandel rwlock_t lock;
3857be1f3fSHiren Tandel };
3957be1f3fSHiren Tandel
4023b7869cSLauro Ramos Venancio #define nfc_rawsock(sk) ((struct nfc_rawsock *) sk)
4123b7869cSLauro Ramos Venancio #define to_rawsock_sk(_tx_work) \
4223b7869cSLauro Ramos Venancio ((struct sock *) container_of(_tx_work, struct nfc_rawsock, tx_work))
4323b7869cSLauro Ramos Venancio
44d9b8d8e1SThierry Escande struct nfc_llcp_sdp_tlv;
45d9b8d8e1SThierry Escande
46d646960fSSamuel Ortiz void nfc_llcp_mac_is_down(struct nfc_dev *dev);
47d646960fSSamuel Ortiz void nfc_llcp_mac_is_up(struct nfc_dev *dev, u32 target_idx,
48d646960fSSamuel Ortiz u8 comm_mode, u8 rf_mode);
49d646960fSSamuel Ortiz int nfc_llcp_register_device(struct nfc_dev *dev);
50d646960fSSamuel Ortiz void nfc_llcp_unregister_device(struct nfc_dev *dev);
513df40eb3SKrzysztof Kozlowski int nfc_llcp_set_remote_gb(struct nfc_dev *dev, const u8 *gb, u8 gb_len);
5247807d3dSSamuel Ortiz u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *general_bytes_len);
5373167cedSSamuel Ortiz int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb);
5452feb444SThierry Escande struct nfc_llcp_local *nfc_llcp_find_local(struct nfc_dev *dev);
55*6709d4b7SLin Ma int nfc_llcp_local_put(struct nfc_llcp_local *local);
56d646960fSSamuel Ortiz int __init nfc_llcp_init(void);
57d646960fSSamuel Ortiz void nfc_llcp_exit(void);
58d9b8d8e1SThierry Escande void nfc_llcp_free_sdp_tlv(struct nfc_llcp_sdp_tlv *sdp);
59d9b8d8e1SThierry Escande void nfc_llcp_free_sdp_tlv_list(struct hlist_head *head);
60d646960fSSamuel Ortiz
6123b7869cSLauro Ramos Venancio int __init rawsock_init(void);
6223b7869cSLauro Ramos Venancio void rawsock_exit(void);
6323b7869cSLauro Ramos Venancio
64c7fe3b52SAloisio Almeida Jr int __init af_nfc_init(void);
65c7fe3b52SAloisio Almeida Jr void af_nfc_exit(void);
66c7fe3b52SAloisio Almeida Jr int nfc_proto_register(const struct nfc_protocol *nfc_proto);
67c7fe3b52SAloisio Almeida Jr void nfc_proto_unregister(const struct nfc_protocol *nfc_proto);
68c7fe3b52SAloisio Almeida Jr
693e256b8fSLauro Ramos Venancio extern int nfc_devlist_generation;
703e256b8fSLauro Ramos Venancio extern struct mutex nfc_devlist_mutex;
713e256b8fSLauro Ramos Venancio
724d12b8b1SLauro Ramos Venancio int __init nfc_genl_init(void);
734d12b8b1SLauro Ramos Venancio void nfc_genl_exit(void);
744d12b8b1SLauro Ramos Venancio
754d12b8b1SLauro Ramos Venancio void nfc_genl_data_init(struct nfc_genl_data *genl_data);
764d12b8b1SLauro Ramos Venancio void nfc_genl_data_exit(struct nfc_genl_data *genl_data);
774d12b8b1SLauro Ramos Venancio
784d12b8b1SLauro Ramos Venancio int nfc_genl_targets_found(struct nfc_dev *dev);
798112a5c9SSamuel Ortiz int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx);
804d12b8b1SLauro Ramos Venancio
814d12b8b1SLauro Ramos Venancio int nfc_genl_device_added(struct nfc_dev *dev);
824d12b8b1SLauro Ramos Venancio int nfc_genl_device_removed(struct nfc_dev *dev);
834d12b8b1SLauro Ramos Venancio
841ed28f61SSamuel Ortiz int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
851ed28f61SSamuel Ortiz u8 comm_mode, u8 rf_mode);
861ed28f61SSamuel Ortiz int nfc_genl_dep_link_down_event(struct nfc_dev *dev);
871ed28f61SSamuel Ortiz
88fc40a8c1SSamuel Ortiz int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol);
89fc40a8c1SSamuel Ortiz int nfc_genl_tm_deactivated(struct nfc_dev *dev);
90fc40a8c1SSamuel Ortiz
91d9b8d8e1SThierry Escande int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list);
92d9b8d8e1SThierry Escande
932757c372SSamuel Ortiz int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type);
942757c372SSamuel Ortiz int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx);
95447b27c4SChristophe Ricard int nfc_genl_se_transaction(struct nfc_dev *dev, u8 se_idx,
96447b27c4SChristophe Ricard struct nfc_evt_transaction *evt_transaction);
979afec6d3SChristophe Ricard int nfc_genl_se_connectivity(struct nfc_dev *dev, u8 se_idx);
982757c372SSamuel Ortiz
9995c96174SEric Dumazet struct nfc_dev *nfc_get_device(unsigned int idx);
1003e256b8fSLauro Ramos Venancio
nfc_put_device(struct nfc_dev * dev)1013e256b8fSLauro Ramos Venancio static inline void nfc_put_device(struct nfc_dev *dev)
1023e256b8fSLauro Ramos Venancio {
1033e256b8fSLauro Ramos Venancio put_device(&dev->dev);
1043e256b8fSLauro Ramos Venancio }
1053e256b8fSLauro Ramos Venancio
nfc_device_iter_init(struct class_dev_iter * iter)1063e256b8fSLauro Ramos Venancio static inline void nfc_device_iter_init(struct class_dev_iter *iter)
1073e256b8fSLauro Ramos Venancio {
1083e256b8fSLauro Ramos Venancio class_dev_iter_init(iter, &nfc_class, NULL, NULL);
1093e256b8fSLauro Ramos Venancio }
1103e256b8fSLauro Ramos Venancio
nfc_device_iter_next(struct class_dev_iter * iter)1113e256b8fSLauro Ramos Venancio static inline struct nfc_dev *nfc_device_iter_next(struct class_dev_iter *iter)
1123e256b8fSLauro Ramos Venancio {
1133e256b8fSLauro Ramos Venancio struct device *d = class_dev_iter_next(iter);
1143e256b8fSLauro Ramos Venancio if (!d)
1153e256b8fSLauro Ramos Venancio return NULL;
1163e256b8fSLauro Ramos Venancio
1173e256b8fSLauro Ramos Venancio return to_nfc_dev(d);
1183e256b8fSLauro Ramos Venancio }
1193e256b8fSLauro Ramos Venancio
nfc_device_iter_exit(struct class_dev_iter * iter)1203e256b8fSLauro Ramos Venancio static inline void nfc_device_iter_exit(struct class_dev_iter *iter)
1213e256b8fSLauro Ramos Venancio {
1223e256b8fSLauro Ramos Venancio class_dev_iter_exit(iter);
1233e256b8fSLauro Ramos Venancio }
1243e256b8fSLauro Ramos Venancio
1259ea7187cSSamuel Ortiz int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name);
126352a5f5fSEric Lapuyade int nfc_genl_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
127352a5f5fSEric Lapuyade u32 result);
1289674da87SEric Lapuyade
1298b3fe7b5SIlan Elias int nfc_dev_up(struct nfc_dev *dev);
1308b3fe7b5SIlan Elias
1318b3fe7b5SIlan Elias int nfc_dev_down(struct nfc_dev *dev);
1328b3fe7b5SIlan Elias
133fe7c5800SSamuel Ortiz int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols);
1343e256b8fSLauro Ramos Venancio
1353e256b8fSLauro Ramos Venancio int nfc_stop_poll(struct nfc_dev *dev);
1363e256b8fSLauro Ramos Venancio
13747807d3dSSamuel Ortiz int nfc_dep_link_up(struct nfc_dev *dev, int target_idx, u8 comm_mode);
1381ed28f61SSamuel Ortiz
1391ed28f61SSamuel Ortiz int nfc_dep_link_down(struct nfc_dev *dev);
1401ed28f61SSamuel Ortiz
1413e256b8fSLauro Ramos Venancio int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol);
1423e256b8fSLauro Ramos Venancio
14396d4581fSChristophe Ricard int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx, u8 mode);
1443e256b8fSLauro Ramos Venancio
1450a40acb2SSamuel Ortiz int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
1460a40acb2SSamuel Ortiz data_exchange_cb_t cb, void *cb_context);
1473e256b8fSLauro Ramos Venancio
148c531c9ecSSamuel Ortiz int nfc_enable_se(struct nfc_dev *dev, u32 se_idx);
149c531c9ecSSamuel Ortiz int nfc_disable_se(struct nfc_dev *dev, u32 se_idx);
150c531c9ecSSamuel Ortiz
1513e256b8fSLauro Ramos Venancio #endif /* __LOCAL_NFC_H */
152