Skip to content

Commit 23b7869

Browse files
Lauro Ramos Venanciolinvjw
authored andcommitted
NFC: add the NFC socket raw protocol
This socket protocol is used to perform data exchange with NFC targets. Signed-off-by: Lauro Ramos Venancio <[email protected]> Signed-off-by: Aloisio Almeida Jr <[email protected]> Signed-off-by: Samuel Ortiz <[email protected]> Signed-off-by: John W. Linville <[email protected]>
1 parent c7fe3b5 commit 23b7869

File tree

5 files changed

+388
-2
lines changed

5 files changed

+388
-2
lines changed

include/linux/nfc.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#ifndef __LINUX_NFC_H
2525
#define __LINUX_NFC_H
2626

27+
#include <linux/types.h>
28+
#include <linux/socket.h>
29+
2730
#define NFC_GENL_NAME "nfc"
2831
#define NFC_GENL_VERSION 1
2932

@@ -109,7 +112,15 @@ enum nfc_attrs {
109112
#define NFC_PROTO_ISO14443_MASK (1 << NFC_PROTO_ISO14443)
110113
#define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP)
111114

115+
struct sockaddr_nfc {
116+
sa_family_t sa_family;
117+
__u32 dev_idx;
118+
__u32 target_idx;
119+
__u32 nfc_protocol;
120+
};
121+
112122
/* NFC socket protocols */
113-
#define NFC_SOCKPROTO_MAX 0
123+
#define NFC_SOCKPROTO_RAW 0
124+
#define NFC_SOCKPROTO_MAX 1
114125

115126
#endif /*__LINUX_NFC_H */

net/nfc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
obj-$(CONFIG_NFC) += nfc.o
66

7-
nfc-objs := core.o netlink.o af_nfc.o
7+
nfc-objs := core.o netlink.o af_nfc.o rawsock.o

net/nfc/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,19 @@ static int __init nfc_init(void)
432432
/* the first generation must not be 0 */
433433
nfc_devlist_generation = 1;
434434

435+
rc = rawsock_init();
436+
if (rc)
437+
goto err_rawsock;
438+
435439
rc = af_nfc_init();
436440
if (rc)
437441
goto err_af_nfc;
438442

439443
return 0;
440444

441445
err_af_nfc:
446+
rawsock_exit();
447+
err_rawsock:
442448
nfc_genl_exit();
443449
err_genl:
444450
class_unregister(&nfc_class);
@@ -448,6 +454,7 @@ static int __init nfc_init(void)
448454
static void __exit nfc_exit(void)
449455
{
450456
af_nfc_exit();
457+
rawsock_exit();
451458
nfc_genl_exit();
452459
class_unregister(&nfc_class);
453460
}

net/nfc/nfc.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ struct nfc_protocol {
4242
const struct nfc_protocol *nfc_proto);
4343
};
4444

45+
struct nfc_rawsock {
46+
struct sock sk;
47+
struct nfc_dev *dev;
48+
u32 target_idx;
49+
struct work_struct tx_work;
50+
bool tx_work_scheduled;
51+
};
52+
#define nfc_rawsock(sk) ((struct nfc_rawsock *) sk)
53+
#define to_rawsock_sk(_tx_work) \
54+
((struct sock *) container_of(_tx_work, struct nfc_rawsock, tx_work))
55+
56+
int __init rawsock_init(void);
57+
void rawsock_exit(void);
58+
4559
int __init af_nfc_init(void);
4660
void af_nfc_exit(void);
4761
int nfc_proto_register(const struct nfc_protocol *nfc_proto);

0 commit comments

Comments
 (0)