NFC update
Subsystems (2)
cover NFC update
Hi John,
This NFC update includes adding function names to the NFC pr_fmt(), new skb allocation routines, a locking fix and an atomic allocation one. Patches 5,6 and 7 are preparation for the LLCP implementation. The last one is the actual LLCP (a.k.a. NFC peer to peer mode) implementation.
Samuel Ortiz (8):
NFC: Add function name to the NFC pr_fmt() routine
NFC: Add tx skb allocation routine
NFC: Do not take the genl mutex from the netlink release notifier
NFC: Atomic socket allocation
NFC: Add a DEP link control netlink command
NFC: Set and get DEP general bytes
NFC: DEP link hook implementation for pn533
NFC: Initial LLCP support
drivers/nfc/pn533.c | 168 ++++++++- include/linux/nfc.h | 29 ++- include/net/nfc/nfc.h | 21 +- net/nfc/Kconfig | 1 + net/nfc/Makefile | 1 + net/nfc/core.c | 143 +++++++- net/nfc/llcp/Kconfig | 7 + net/nfc/llcp/commands.c | 399 +++++++++++++++++++ net/nfc/llcp/llcp.c | 973 +++++++++++++++++++++++++++++++++++++++++++++++ net/nfc/llcp/llcp.h | 193 ++++++++++ net/nfc/llcp/sock.c | 675 ++++++++++++++++++++++++++++++++ net/nfc/nci/core.c | 2 +- net/nfc/nci/data.c | 2 +- net/nfc/nci/ntf.c | 2 +- net/nfc/nci/rsp.c | 2 +- net/nfc/netlink.c | 148 +++++++- net/nfc/nfc.h | 63 +++ net/nfc/rawsock.c | 11 +- 18 files changed, 2818 insertions(+), 22 deletions(-) create mode 100644 net/nfc/llcp/Kconfig create mode 100644 net/nfc/llcp/commands.c create mode 100644 net/nfc/llcp/llcp.c create mode 100644 net/nfc/llcp/llcp.h create mode 100644 net/nfc/llcp/sock.c
Signature · 1 line
1.7.7.3
PATCH 1/8 NFC: Add function name to the NFC pr_fmt() routine
--- net/nfc/core.c | 2 +- net/nfc/nci/core.c | 2 +- net/nfc/nci/data.c | 2 +- net/nfc/nci/ntf.c | 2 +- net/nfc/nci/rsp.c | 2 +- net/nfc/netlink.c | 2 +- net/nfc/rawsock.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-)
net/nfc/core.c +1 -1
@@ -21,7 +21,7 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt (fmt) KBUILD_MODNAME ": %s: " fmt, __func__#include <linux/init.h> #include <linux/kernel.h>
net/nfc/nci/core.c +1 -1
@@ -25,7 +25,7 @@* */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt (fmt) KBUILD_MODNAME ": %s: " fmt, __func__#include <linux/types.h> #include <linux/workqueue.h>
net/nfc/nci/data.c +1 -1
@@ -21,7 +21,7 @@* */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt (fmt) KBUILD_MODNAME ": %s: " fmt, __func__#include <linux/types.h> #include <linux/interrupt.h>
net/nfc/nci/ntf.c +1 -1
@@ -25,7 +25,7 @@* */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt (fmt) KBUILD_MODNAME ": %s: " fmt, __func__#include <linux/types.h> #include <linux/interrupt.h>
net/nfc/nci/rsp.c +1 -1
@@ -25,7 +25,7 @@* */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt (fmt) KBUILD_MODNAME ": %s: " fmt, __func__#include <linux/types.h> #include <linux/interrupt.h>
net/nfc/netlink.c +1 -1
@@ -21,7 +21,7 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt (fmt) KBUILD_MODNAME ": %s: " fmt, __func__#include <net/genetlink.h> #include <linux/nfc.h>
net/nfc/rawsock.c +1 -1
@@ -21,7 +21,7 @@* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt (fmt) KBUILD_MODNAME ": %s: " fmt, __func__#include <net/tcp_states.h> #include <linux/nfc.h>
Signature · 1 line
1.7.7.3
PATCH 2/8 NFC: Add tx skb allocation routine
In reply to Samuel OrtizThis is a factorization of the current rawsock tx skb allocation routine, as it will be used by the LLCP code.
We also rename nfc_alloc_skb to nfc_alloc_recv_skb for consistency sake.
--- drivers/nfc/pn533.c | 2 +- include/net/nfc/nfc.h | 5 ++++- net/nfc/core.c | 30 +++++++++++++++++++++++++++--- net/nfc/rawsock.c | 7 ++----- 4 files changed, 34 insertions(+), 10 deletions(-)
drivers/nfc/pn533.c +1 -1
@@ -1368,7 +1368,7 @@ static int pn533_data_exchange(struct nfc_dev *nfc_dev, u32 target_idx,PN533_CMD_DATAEXCH_DATA_MAXLEN +PN533_FRAME_TAIL_SIZE ; - skb_resp =nfc_alloc_skb (skb_resp_len,GFP_KERNEL ); + skb_resp =nfc_alloc_recv_skb (skb_resp_len,GFP_KERNEL );if (!skb_resp) { rc = -ENOMEM ; goto error;
include/net/nfc/nfc.h +4 -1
@@ -157,7 +157,10 @@ static inline const char *nfc_device_name(struct nfc_dev *dev)return dev_name (&dev->dev); } -struct sk_buff *nfc_alloc_skb (unsigned int size,gfp_t gfp); +struct sk_buff *nfc_alloc_send_skb (struct nfc_dev *dev,struct sock *sk, +unsigned int flags,unsigned int size, +unsigned int *err); +struct sk_buff *nfc_alloc_recv_skb (unsigned int size,gfp_t gfp);int nfc_targets_found (struct nfc_dev *dev,struct nfc_target *targets,int ntargets);
net/nfc/core.c +27 -3
@@ -27,6 +27,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/nfc.h> #include "nfc.h"
@@ -275,12 +276,35 @@ error: }/** -* nfc_alloc_skb - allocate a skb for data exchange responses +* nfc_alloc_send_skb - allocate a skb for data exchange responses * * @size: size to allocate * @gfp: gfp flags */ -struct sk_buff *nfc_alloc_skb (unsigned int size,gfp_t gfp) +struct sk_buff *nfc_alloc_send_skb (struct nfc_dev *dev,struct sock *sk, +unsigned int flags,unsigned int size, +unsigned int *err) +{ +struct sk_buff *skb; +unsigned int total_size; + + total_size = size + + dev->tx_headroom + dev->tx_tailroom +NFC_HEADER_SIZE ; + + skb =sock_alloc_send_skb (sk, total_size, flags &MSG_DONTWAIT , err); +if (skb) +skb_reserve (skb, dev->tx_headroom +NFC_HEADER_SIZE ); + +return skb; +} + +/** +* nfc_alloc_recv_skb - allocate a skb for data exchange responses +* +* @size: size to allocate +* @gfp: gfp flags +*/ +struct sk_buff *nfc_alloc_recv_skb (unsigned int size,gfp_t gfp) {struct sk_buff *skb;unsigned int total_size;
@@ -293,7 +317,7 @@ struct sk_buff *nfc_alloc_skb(unsigned int size, gfp_t gfp)return skb; } -EXPORT_SYMBOL (nfc_alloc_skb); +EXPORT_SYMBOL (nfc_alloc_recv_skb);/** * nfc_targets_found - inform that targets were found
net/nfc/rawsock.c +2 -5
@@ -208,13 +208,10 @@ static int rawsock_sendmsg(struct kiocb *iocb, struct socket *sock,if (sock->state !=SS_CONNECTED )return -ENOTCONN ; - skb =sock_alloc_send_skb (sk, len + dev->tx_headroom + dev->tx_tailroom +NFC_HEADER_SIZE , - msg->msg_flags &MSG_DONTWAIT , &rc); -if (!skb) + skb =nfc_alloc_send_skb (dev, sk, msg->msg_flags, len, &rc); +if (skb ==NULL )return rc; -skb_reserve (skb, dev->tx_headroom +NFC_HEADER_SIZE ); - rc =memcpy_fromiovec (skb_put (skb, len), msg->msg_iov, len);if (rc <0 ) {kfree_skb (skb);
Signature · 1 line
1.7.7.3
PATCH 3/8 NFC: Do not take the genl mutex from the netlink release notifier
In reply to Samuel OrtizThe netlink notifier is atomic so we must not sleep in that context. Also we know that Any netlink packets arriving to us will be purged when the notifier is called, so we don't need to take the mutex.
--- net/nfc/netlink.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
net/nfc/netlink.c +0 -2
@@ -504,12 +504,10 @@ static int nfc_genl_rcv_nl_event(struct notifier_block *this, dev =nfc_device_iter_next (&iter);while (dev) { -mutex_lock (&dev->genl_data.genl_data_mutex);if (dev->genl_data.poll_req_pid == n->pid) {nfc_stop_poll (dev); dev->genl_data.poll_req_pid =0 ; } -mutex_unlock (&dev->genl_data.genl_data_mutex); dev =nfc_device_iter_next (&iter); }
Signature · 1 line
1.7.7.3
PATCH 4/8 NFC: Atomic socket allocation
In reply to Samuel Ortizrawsock_create() is called with preemption disabled, so we should not sleep.
--- net/nfc/rawsock.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/nfc/rawsock.c +1 -1
@@ -310,7 +310,7 @@ static int rawsock_create(struct net *net, struct socket *sock, sock->ops = &rawsock_ops; - sk =sk_alloc (net,PF_NFC ,GFP_KERNEL , nfc_proto->proto); + sk =sk_alloc (net,PF_NFC ,GFP_ATOMIC , nfc_proto->proto);if (!sk)return -ENOMEM ;
Signature · 1 line
1.7.7.3
PATCH 5/8 NFC: Add a DEP link control netlink command
In reply to Samuel OrtizNFC-DEP (Data Exchange Protocol) is an NFC MAC layer.
This command allows to enable and disable the DEP link on to which e.g. LLCP can run.
--- include/linux/nfc.h | 14 +++++ include/net/nfc/nfc.h | 11 ++++ net/nfc/core.c | 77 ++++++++++++++++++++++++++ net/nfc/netlink.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ net/nfc/nfc.h | 9 +++ 5 files changed, 255 insertions(+), 0 deletions(-)
include/linux/nfc.h +14 -0
@@ -62,6 +62,8 @@ enum nfc_commands {NFC_CMD_GET_DEVICE ,NFC_CMD_DEV_UP ,NFC_CMD_DEV_DOWN , +NFC_CMD_DEP_LINK_UP , +NFC_CMD_DEP_LINK_DOWN ,NFC_CMD_START_POLL ,NFC_CMD_STOP_POLL , NFC_CMD_GET_TARGET,
@@ -86,6 +88,8 @@ enum nfc_commands {* @NFC_ATTR_TARGET_SENS_RES: NFC-A targets extra information such as NFCID * @NFC_ATTR_TARGET_SEL_RES: NFC-A targets extra information (useful if the * target is not NFC-Forum compliant) +* @NFC_ATTR_COMM_MODE: Passive or active mode +* @NFC_ATTR_RF_MODE: Initiator or target */ enum nfc_attrs {NFC_ATTR_UNSPEC ,
@@ -95,6 +99,8 @@ enum nfc_attrs {NFC_ATTR_TARGET_INDEX ,NFC_ATTR_TARGET_SENS_RES ,NFC_ATTR_TARGET_SEL_RES , +NFC_ATTR_COMM_MODE , +NFC_ATTR_RF_MODE ,/* private: internal use only */ __NFC_ATTR_AFTER_LAST };
@@ -111,6 +117,14 @@ enum nfc_attrs {#define NFC_PROTO_MAX 6 +/* NFC communication modes */ +#define NFC_COMM_ACTIVE 0 +#define NFC_COMM_PASSIVE 1 + +/* NFC RF modes */ +#define NFC_RF_INITIATOR 0 +#define NFC_RF_TARGET 1 +/* NFC protocols masks used in bitsets */ #define NFC_PROTO_JEWEL_MASK (1 << NFC_PROTO_JEWEL)#define NFC_PROTO_MIFARE_MASK (1 << NFC_PROTO_MIFARE)
include/net/nfc/nfc.h +11 -0
@@ -52,6 +52,9 @@ struct nfc_ops {int (*dev_down)(struct nfc_dev *dev);int (*start_poll)(struct nfc_dev *dev,u32 protocols);void (*stop_poll)(struct nfc_dev *dev); +int (*dep_link_up)(struct nfc_dev *dev,int target_idx, +u8 comm_mode,u8 rf_mode); +int (*dep_link_down)(struct nfc_dev *dev);int (*activate_target)(struct nfc_dev *dev,u32 target_idx,u32 protocol);void (*deactivate_target)(struct nfc_dev *dev,u32 target_idx);
@@ -60,6 +63,9 @@ struct nfc_ops { void *cb_context); }; +#define NFC_TARGET_IDX_ANY -1 +#define NFC_MAX_GT_LEN 48 +struct nfc_target {u32 idx;u32 supported_protocols;
@@ -83,6 +89,8 @@ struct nfc_dev {bool dev_up;bool polling;bool remote_activated; +bool dep_link_up; +u32 dep_rf_mode;struct nfc_genl_data genl_data;u32 supported_protocols;
@@ -165,4 +173,7 @@ struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp);int nfc_targets_found (struct nfc_dev *dev,struct nfc_target *targets,int ntargets); +int nfc_dep_link_is_up (struct nfc_dev *dev,u32 target_idx, +u8 comm_mode,u8 rf_mode); +#endif /* __NET_NFC_H */
net/nfc/core.c +77 -0
83 lines not on this page · raw message
net/nfc/netlink.c +144 -0
174 lines not on this page · raw message
net/nfc/nfc.h +9 -0
@@ -68,6 +68,10 @@ int nfc_genl_targets_found(struct nfc_dev *dev);int nfc_genl_device_added (struct nfc_dev *dev);int nfc_genl_device_removed (struct nfc_dev *dev); +int nfc_genl_dep_link_up_event (struct nfc_dev *dev,u32 target_idx, +u8 comm_mode,u8 rf_mode); +int nfc_genl_dep_link_down_event (struct nfc_dev *dev); +struct nfc_dev *nfc_get_device (unsigned idx);static inline void nfc_put_device (struct nfc_dev *dev)
@@ -102,6 +106,11 @@ int nfc_start_poll(struct nfc_dev *dev, u32 protocols);int nfc_stop_poll (struct nfc_dev *dev); +int nfc_dep_link_up (struct nfc_dev *dev,int target_idx, +u8 comm_mode,u8 rf_mode); + +int nfc_dep_link_down (struct nfc_dev *dev); +int nfc_activate_target (struct nfc_dev *dev,u32 target_idx,u32 protocol);int nfc_deactivate_target (struct nfc_dev *dev,u32 target_idx);
Signature · 1 line
1.7.7.3
PATCH 6/8 NFC: Set and get DEP general bytes
In reply to Samuel OrtizWithout an API for setting and getting the local and remote general bytes, drivers won't be able to properly establish a DEP link.
This API also allows them to propagate the remote general bytes they get from the DEP link establishment up to the LLCP layer.
--- drivers/nfc/pn533.c | 7 ++++++- include/net/nfc/nfc.h | 5 +++++ net/nfc/core.c | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletions(-)
drivers/nfc/pn533.c +6 -1
@@ -1121,6 +1121,7 @@ static int pn533_activate_target_nfcdep(struct pn533 *dev) {struct pn533_cmd_activate_param param;struct pn533_cmd_activate_response *resp; +u16 gt_len;int rc;nfc_dev_dbg (&dev->interface->dev,"%s" , __func__);
@@ -1146,7 +1147,11 @@ static int pn533_activate_target_nfcdep(struct pn533 *dev)if (rc !=PN533_CMD_RET_SUCCESS )return -EIO ; -return 0 ; +/* ATR_RES general bytes are located at offset 16 */ + gt_len =PN533_FRAME_CMD_PARAMS_LEN (dev->in_frame) -16 ; + rc =nfc_set_remote_general_bytes (dev->nfc_dev, resp->gt, gt_len); + +return rc; } static int pn533_activate_target(struct nfc_dev *nfc_dev, u32 target_idx,
include/net/nfc/nfc.h +5 -0
@@ -170,6 +170,11 @@ struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk, unsigned int *err);struct sk_buff *nfc_alloc_recv_skb (unsigned int size,gfp_t gfp); +int nfc_set_remote_general_bytes (struct nfc_dev *dev, +u8 *gt,u8 gt_len); + +u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,u8 *gt_len); +int nfc_targets_found (struct nfc_dev *dev,struct nfc_target *targets,int ntargets);
net/nfc/core.c +18 -0
@@ -352,6 +352,24 @@ error:return rc; } +int nfc_set_remote_general_bytes (struct nfc_dev *dev,u8 *gb,u8 gb_len) +{ +pr_debug ("dev_name=%s gb_len=%d\n" , +dev_name (&dev->dev), gb_len); + +if (gb_len >NFC_MAX_GT_LEN ) +return -EINVAL ; + +return 0 ; +} +EXPORT_SYMBOL (nfc_set_remote_general_bytes); + +u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,u8 *gt_len) +{ +return NULL ; +} +EXPORT_SYMBOL (nfc_get_local_general_bytes); +/** * nfc_alloc_send_skb - allocate a skb for data exchange responses *
Signature · 1 line
1.7.7.3
PATCH 7/8 NFC: DEP link hook implementation for pn533
In reply to Samuel Ortiz--- drivers/nfc/pn533.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 159 insertions(+), 0 deletions(-)
drivers/nfc/pn533.c +159 -0
@@ -72,6 +72,7 @@ MODULE_DEVICE_TABLE(usb, pn533_table);#define PN533_CMD_IN_LIST_PASSIVE_TARGET 0x4A#define PN533_CMD_IN_ATR 0x50#define PN533_CMD_IN_RELEASE 0x52 +#define PN533_CMD_IN_JUMP_FOR_DEP 0x56#define PN533_CMD_RESPONSE (cmd) (cmd + 1)
@@ -231,6 +232,26 @@ struct pn533_cmd_activate_response {u8 gt[]; } __packed; +/* PN533_CMD_IN_JUMP_FOR_DEP */ +struct pn533_cmd_jump_dep { +u8 active; +u8 baud; +u8 next; +u8 gt[]; +} __packed; + +struct pn533_cmd_jump_dep_response { +u8 status; +u8 tg; +u8 nfcid3t[10 ]; +u8 didt; +u8 bst; +u8 brt; +u8 to; +u8 ppt; +/* optional */ +u8 gt[]; +} __packed;struct pn533 {struct usb_device *udev;
@@ -1244,6 +1265,142 @@ static void pn533_deactivate_target(struct nfc_dev *nfc_dev, u32 target_idx)return ; } + +static int pn533_in_dep_link_up_complete (struct pn533 *dev,void *arg, +u8 *params,int params_len) +{ +struct pn533_cmd_jump_dep *cmd; +struct pn533_cmd_jump_dep_response *resp; +struct nfc_target nfc_target; +u8 target_gt_len; +int rc; + +if (params_len == -ENOENT ) { +nfc_dev_dbg (&dev->interface->dev,"" ); +return 0 ; + } + +if (params_len <0 ) { +nfc_dev_err (&dev->interface->dev, +"Error %d when bringing DEP link up" , + params_len); +return 0 ; + } + +if (dev->tgt_available_prots && + !(dev->tgt_available_prots & (1 <<NFC_PROTO_NFC_DEP ))) { +nfc_dev_err (&dev->interface->dev, +"The target does not support DEP" ); +return -EINVAL ; + } + + resp = (struct pn533_cmd_jump_dep_response *) params; + cmd = (struct pn533_cmd_jump_dep *) arg; + rc = resp->status &PN533_CMD_RET_MASK ; +if (rc !=PN533_CMD_RET_SUCCESS ) { +nfc_dev_err (&dev->interface->dev, +"Bringing DEP link up failed %d" , rc); +return 0 ; + } + +if (!dev->tgt_available_prots) { +nfc_dev_dbg (&dev->interface->dev,"Creating new target" ); + + nfc_target.supported_protocols =NFC_PROTO_NFC_DEP_MASK ; + rc =nfc_targets_found (dev->nfc_dev, &nfc_target,1 ); +if (rc) +return 0 ; + + dev->tgt_available_prots =0 ; + } + + dev->tgt_active_prot =NFC_PROTO_NFC_DEP ; + +/* ATR_RES general bytes are located at offset 17 */ + target_gt_len =PN533_FRAME_CMD_PARAMS_LEN (dev->in_frame) -17 ; + rc =nfc_set_remote_general_bytes (dev->nfc_dev, + resp->gt, target_gt_len); +if (rc ==0 ) + rc =nfc_dep_link_is_up (dev->nfc_dev, + dev->nfc_dev->targets[0 ].idx, + !cmd->active,NFC_RF_INITIATOR ); + +return 0 ; +} + +static int pn533_dep_link_up (struct nfc_dev *nfc_dev,int target_idx, +u8 comm_mode,u8 rf_mode) +{ +struct pn533 *dev =nfc_get_drvdata (nfc_dev); +struct pn533_cmd_jump_dep *cmd; +u8 cmd_len, local_gt_len, *local_gt; +int rc; + +nfc_dev_dbg (&dev->interface->dev,"%s" , __func__); + +if (rf_mode ==NFC_RF_TARGET ) { +nfc_dev_err (&dev->interface->dev,"Target mode not supported" ); +return -EOPNOTSUPP ; + } + + +if (dev->poll_mod_count) { +nfc_dev_err (&dev->interface->dev, +"Cannot bring the DEP link up while polling" ); +return -EBUSY ; + } + +if (dev->tgt_active_prot) { +nfc_dev_err (&dev->interface->dev, +"There is already an active target" ); +return -EBUSY ; + } + + local_gt =nfc_get_local_general_bytes (dev->nfc_dev, &local_gt_len); +if (local_gt_len >NFC_MAX_GT_LEN ) +return -EINVAL ; + + cmd_len =sizeof (struct pn533_cmd_jump_dep ) + local_gt_len; + cmd =kzalloc (cmd_len,GFP_KERNEL ); +if (cmd ==NULL ) +return -ENOMEM ; + +pn533_tx_frame_init (dev->out_frame,PN533_CMD_IN_JUMP_FOR_DEP ); + + cmd->active = !comm_mode; + cmd->baud =0 ; +if (local_gt !=NULL ) { + cmd->next =4 ;/* We have some Gi */ +memcpy (cmd->gt, local_gt, local_gt_len); + }else { + cmd->next =0 ; + } + +memcpy (PN533_FRAME_CMD_PARAMS_PTR (dev->out_frame), cmd, cmd_len); + dev->out_frame->datalen += cmd_len; + +pn533_tx_frame_finish (dev->out_frame); + + rc =pn533_send_cmd_frame_async (dev, dev->out_frame, dev->in_frame, + dev->in_maxlen, pn533_in_dep_link_up_complete, + cmd,GFP_KERNEL ); +if (rc) + goto out; + + +out: +kfree (cmd); + +return rc; +} + +static int pn533_dep_link_down (struct nfc_dev *nfc_dev) +{ +pn533_deactivate_target (nfc_dev,0 ); + +return 0 ; +} +#define PN533_CMD_DATAEXCH_HEAD_LEN (sizeof(struct pn533_frame) + 3)#define PN533_CMD_DATAEXCH_DATA_MAXLEN 262
@@ -1439,6 +1596,8 @@ static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata,struct nfc_ops pn533_nfc_ops = { .dev_up =NULL , .dev_down =NULL , + .dep_link_up = pn533_dep_link_up, + .dep_link_down = pn533_dep_link_down, .start_poll = pn533_start_poll, .stop_poll = pn533_stop_poll, .activate_target = pn533_activate_target,
Signature · 1 line
1.7.7.3
PATCH 8/8 NFC: Initial LLCP support
In reply to Samuel OrtizThis patch is an initial implementation for the NFC Logical Link Control protocol. It's also known as NFC peer to peer mode.
This is a basic implementation as it lacks SDP (services Discovery Protocol), frames aggregation support, and frame rejecion parsing. Follow up patches will implement those missing features. This code has been tested against a Nexus S phone implementing LLCP 1.0.
--- include/linux/nfc.h | 15 +- net/nfc/Kconfig | 1 + net/nfc/Makefile | 1 + net/nfc/core.c | 20 +- net/nfc/llcp/Kconfig | 7 + net/nfc/llcp/commands.c | 399 +++++++++++++++++++ net/nfc/llcp/llcp.c | 973 +++++++++++++++++++++++++++++++++++++++++++++++ net/nfc/llcp/llcp.h | 193 ++++++++++ net/nfc/llcp/sock.c | 675 ++++++++++++++++++++++++++++++++ net/nfc/nfc.h | 54 +++ 10 files changed, 2335 insertions(+), 3 deletions(-) create mode 100644 net/nfc/llcp/Kconfig create mode 100644 net/nfc/llcp/commands.c create mode 100644 net/nfc/llcp/llcp.c create mode 100644 net/nfc/llcp/llcp.h create mode 100644 net/nfc/llcp/sock.c
include/linux/nfc.h +14 -1
@@ -139,9 +139,22 @@ struct sockaddr_nfc {__u32 nfc_protocol; }; +#define NFC_LLCP_MAX_SERVICE_NAME 63 +struct sockaddr_nfc_llcp { +sa_family_t sa_family; +__u32 dev_idx; +__u32 target_idx; +__u32 nfc_protocol; +__u8 dsap;/* Destination SAP, if known */ +__u8 ssap;/* Source SAP to be bound to */ + char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */; +size_t service_name_len; +}; +/* NFC socket protocols */ #define NFC_SOCKPROTO_RAW 0 -#define NFC_SOCKPROTO_MAX 1 +#define NFC_SOCKPROTO_LLCP 1 +#define NFC_SOCKPROTO_MAX 2#define NFC_HEADER_SIZE 1
net/nfc/Kconfig +1 -0
@@ -14,5 +14,6 @@ menuconfig NFC be called nfc. source "net/nfc/nci/Kconfig" +source "net/nfc/llcp/Kconfig" source "drivers/nfc/Kconfig"
net/nfc/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_NFC) += nfc.o obj-$(CONFIG_NFC_NCI) += nci/ nfc-objs := core.o netlink.o af_nfc.o rawsock.o +nfc-$(CONFIG_NFC_LLCP) += llcp/llcp.o llcp/commands.o llcp/sock.o
net/nfc/core.c +18 -2
@@ -240,6 +240,7 @@ int nfc_dep_link_down(struct nfc_dev *dev) rc = dev->ops->dep_link_down (dev);if (!rc) { dev->dep_link_up = false; +nfc_llcp_mac_is_down (dev);nfc_genl_dep_link_down_event (dev); }
@@ -254,6 +255,8 @@ int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx, dev->dep_link_up = true; dev->dep_rf_mode = rf_mode; +nfc_llcp_mac_is_up (dev, target_idx, comm_mode, rf_mode); +return nfc_genl_dep_link_up_event (dev, target_idx, comm_mode, rf_mode); }EXPORT_SYMBOL (nfc_dep_link_is_up);
@@ -360,13 +363,13 @@ int nfc_set_remote_general_bytes(struct nfc_dev *dev, u8 *gb, u8 gb_len)if (gb_len >NFC_MAX_GT_LEN )return -EINVAL ; -return 0 ; +return nfc_llcp_set_remote_gb (dev, gb, gb_len); }EXPORT_SYMBOL (nfc_set_remote_general_bytes);u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,u8 *gt_len) { -return NULL ; +return nfc_llcp_general_bytes (dev, gt_len); }EXPORT_SYMBOL (nfc_get_local_general_bytes);
@@ -560,6 +563,10 @@ int nfc_register_device(struct nfc_dev *dev)if (rc <0 )return rc; + rc =nfc_llcp_register_device (dev); +if (rc) +pr_err ("Could not register llcp device\n" ); + rc =nfc_genl_device_added (dev);if (rc) pr_debug("The userspace won't be notified that the device %s was added\n",
@@ -591,6 +598,8 @@ void nfc_unregister_device(struct nfc_dev *dev)mutex_unlock (&nfc_devlist_mutex); +nfc_llcp_unregister_device (dev); + rc =nfc_genl_device_removed (dev);if (rc) pr_debug("The userspace won't be notified that the device %s was removed\n",
@@ -620,6 +629,10 @@ static int __init nfc_init(void)if (rc) goto err_rawsock; + rc =nfc_llcp_init (); +if (rc) + goto err_llcp_sock; + rc =af_nfc_init ();if (rc) goto err_af_nfc;
@@ -627,6 +640,8 @@ static int __init nfc_init(void)return 0 ; err_af_nfc: +nfc_llcp_exit (); +err_llcp_sock:rawsock_exit (); err_rawsock:nfc_genl_exit ();
@@ -638,6 +653,7 @@ err_genl: static void __exit nfc_exit(void) {af_nfc_exit (); +nfc_llcp_exit ();rawsock_exit ();nfc_genl_exit ();class_unregister (&nfc_class);
net/nfc/llcp/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config NFC_LLCP + depends on NFC && EXPERIMENTAL + bool "NFC LLCP support (EXPERIMENTAL)" + default n + help + Say Y here if you want to build support for a kernel NFC LLCP + implementation.
net/nfc/llcp/commands.c new file +399 -0
399 lines not on this page · raw message
net/nfc/llcp/llcp.c new file +973 -0
973 lines not on this page · raw message
net/nfc/llcp/llcp.h new file +193 -0
193 lines not on this page · raw message
net/nfc/llcp/sock.c new file +675 -0
675 lines not on this page · raw message
net/nfc/nfc.h +54 -0
60 lines not on this page · raw message
Signature · 1 line
1.7.7.3
RE: [PATCH 3/8] NFC: Do not take the genl mutex from the netlink release notifier
In reply to Samuel OrtizHi Samuel,
net/nfc/netlink.c static int nfc_genl_rcv_nl_event(struct · line 513
Quoted 13 lines
net/nfc/netlink.c +0
-2@@ -504,12 +504,10 @@ static int nfc_genl_rcv_nl_event(structnotifier_block *this, dev =nfc_device_iter_next (&iter);while (dev) { -mutex_lock (&dev->genl_data.genl_data_mutex);if (dev->genl_data.poll_req_pid == n->pid) {nfc_stop_poll (dev); dev->genl_data.poll_req_pid =0 ; } -mutex_unlock (&dev->genl_data.genl_data_mutex); dev =nfc_device_iter_next (&iter); }
Please note that the function nfc_stop_poll might also sleep, since mutex_lock is also called inside:nfc_genl_rcv_nl_event -> nfc_stop_poll -> device_lock -> mutex_lock.
BR,
Ilan