Skip to content

Commit

Permalink
NFC: Initial LLCP support
Browse files Browse the repository at this point in the history
This 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.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Samuel Ortiz authored and linvjw committed Dec 14, 2011
1 parent 361f3cb commit d646960
Show file tree
Hide file tree
Showing 10 changed files with 2,335 additions and 3 deletions.
15 changes: 14 additions & 1 deletion include/linux/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions net/nfc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ menuconfig NFC
be called nfc.

source "net/nfc/nci/Kconfig"
source "net/nfc/llcp/Kconfig"

source "drivers/nfc/Kconfig"
1 change: 1 addition & 0 deletions net/nfc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 18 additions & 2 deletions net/nfc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand 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);

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -620,13 +629,19 @@ 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;

return 0;

err_af_nfc:
nfc_llcp_exit();
err_llcp_sock:
rawsock_exit();
err_rawsock:
nfc_genl_exit();
Expand All @@ -638,6 +653,7 @@ static int __init nfc_init(void)
static void __exit nfc_exit(void)
{
af_nfc_exit();
nfc_llcp_exit();
rawsock_exit();
nfc_genl_exit();
class_unregister(&nfc_class);
Expand Down
7 changes: 7 additions & 0 deletions net/nfc/llcp/Kconfig
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit d646960

Please sign in to comment.