Skip to content

Commit

Permalink
NFC: add the NFC socket raw protocol
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Lauro Ramos Venancio authored and linvjw committed Jul 5, 2011
1 parent c7fe3b5 commit 23b7869
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 2 deletions.
13 changes: 12 additions & 1 deletion include/linux/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#ifndef __LINUX_NFC_H
#define __LINUX_NFC_H

#include <linux/types.h>
#include <linux/socket.h>

#define NFC_GENL_NAME "nfc"
#define NFC_GENL_VERSION 1

Expand Down Expand Up @@ -109,7 +112,15 @@ enum nfc_attrs {
#define NFC_PROTO_ISO14443_MASK (1 << NFC_PROTO_ISO14443)
#define NFC_PROTO_NFC_DEP_MASK (1 << NFC_PROTO_NFC_DEP)

struct sockaddr_nfc {
sa_family_t sa_family;
__u32 dev_idx;
__u32 target_idx;
__u32 nfc_protocol;
};

/* NFC socket protocols */
#define NFC_SOCKPROTO_MAX 0
#define NFC_SOCKPROTO_RAW 0
#define NFC_SOCKPROTO_MAX 1

#endif /*__LINUX_NFC_H */
2 changes: 1 addition & 1 deletion net/nfc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

obj-$(CONFIG_NFC) += nfc.o

nfc-objs := core.o netlink.o af_nfc.o
nfc-objs := core.o netlink.o af_nfc.o rawsock.o
7 changes: 7 additions & 0 deletions net/nfc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,19 @@ static int __init nfc_init(void)
/* the first generation must not be 0 */
nfc_devlist_generation = 1;

rc = rawsock_init();
if (rc)
goto err_rawsock;

rc = af_nfc_init();
if (rc)
goto err_af_nfc;

return 0;

err_af_nfc:
rawsock_exit();
err_rawsock:
nfc_genl_exit();
err_genl:
class_unregister(&nfc_class);
Expand All @@ -448,6 +454,7 @@ static int __init nfc_init(void)
static void __exit nfc_exit(void)
{
af_nfc_exit();
rawsock_exit();
nfc_genl_exit();
class_unregister(&nfc_class);
}
Expand Down
14 changes: 14 additions & 0 deletions net/nfc/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ struct nfc_protocol {
const struct nfc_protocol *nfc_proto);
};

struct nfc_rawsock {
struct sock sk;
struct nfc_dev *dev;
u32 target_idx;
struct work_struct tx_work;
bool tx_work_scheduled;
};
#define nfc_rawsock(sk) ((struct nfc_rawsock *) sk)
#define to_rawsock_sk(_tx_work) \
((struct sock *) container_of(_tx_work, struct nfc_rawsock, tx_work))

int __init rawsock_init(void);
void rawsock_exit(void);

int __init af_nfc_init(void);
void af_nfc_exit(void);
int nfc_proto_register(const struct nfc_protocol *nfc_proto);
Expand Down
Loading

0 comments on commit 23b7869

Please sign in to comment.