Skip to content

Commit d646960

Browse files
Samuel Ortizlinvjw
Samuel Ortiz
authored andcommitted
NFC: Initial LLCP support
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>
1 parent 361f3cb commit d646960

File tree

10 files changed

+2335
-3
lines changed

10 files changed

+2335
-3
lines changed

include/linux/nfc.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,22 @@ struct sockaddr_nfc {
139139
__u32 nfc_protocol;
140140
};
141141

142+
#define NFC_LLCP_MAX_SERVICE_NAME 63
143+
struct sockaddr_nfc_llcp {
144+
sa_family_t sa_family;
145+
__u32 dev_idx;
146+
__u32 target_idx;
147+
__u32 nfc_protocol;
148+
__u8 dsap; /* Destination SAP, if known */
149+
__u8 ssap; /* Source SAP to be bound to */
150+
char service_name[NFC_LLCP_MAX_SERVICE_NAME]; /* Service name URI */;
151+
size_t service_name_len;
152+
};
153+
142154
/* NFC socket protocols */
143155
#define NFC_SOCKPROTO_RAW 0
144-
#define NFC_SOCKPROTO_MAX 1
156+
#define NFC_SOCKPROTO_LLCP 1
157+
#define NFC_SOCKPROTO_MAX 2
145158

146159
#define NFC_HEADER_SIZE 1
147160

net/nfc/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ menuconfig NFC
1414
be called nfc.
1515

1616
source "net/nfc/nci/Kconfig"
17+
source "net/nfc/llcp/Kconfig"
1718

1819
source "drivers/nfc/Kconfig"

net/nfc/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ obj-$(CONFIG_NFC) += nfc.o
66
obj-$(CONFIG_NFC_NCI) += nci/
77

88
nfc-objs := core.o netlink.o af_nfc.o rawsock.o
9+
nfc-$(CONFIG_NFC_LLCP) += llcp/llcp.o llcp/commands.o llcp/sock.o

net/nfc/core.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ int nfc_dep_link_down(struct nfc_dev *dev)
240240
rc = dev->ops->dep_link_down(dev);
241241
if (!rc) {
242242
dev->dep_link_up = false;
243+
nfc_llcp_mac_is_down(dev);
243244
nfc_genl_dep_link_down_event(dev);
244245
}
245246

@@ -254,6 +255,8 @@ int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
254255
dev->dep_link_up = true;
255256
dev->dep_rf_mode = rf_mode;
256257

258+
nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode);
259+
257260
return nfc_genl_dep_link_up_event(dev, target_idx, comm_mode, rf_mode);
258261
}
259262
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)
360363
if (gb_len > NFC_MAX_GT_LEN)
361364
return -EINVAL;
362365

363-
return 0;
366+
return nfc_llcp_set_remote_gb(dev, gb, gb_len);
364367
}
365368
EXPORT_SYMBOL(nfc_set_remote_general_bytes);
366369

367370
u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, u8 *gt_len)
368371
{
369-
return NULL;
372+
return nfc_llcp_general_bytes(dev, gt_len);
370373
}
371374
EXPORT_SYMBOL(nfc_get_local_general_bytes);
372375

@@ -560,6 +563,10 @@ int nfc_register_device(struct nfc_dev *dev)
560563
if (rc < 0)
561564
return rc;
562565

566+
rc = nfc_llcp_register_device(dev);
567+
if (rc)
568+
pr_err("Could not register llcp device\n");
569+
563570
rc = nfc_genl_device_added(dev);
564571
if (rc)
565572
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)
591598

592599
mutex_unlock(&nfc_devlist_mutex);
593600

601+
nfc_llcp_unregister_device(dev);
602+
594603
rc = nfc_genl_device_removed(dev);
595604
if (rc)
596605
pr_debug("The userspace won't be notified that the device %s was removed\n",
@@ -620,13 +629,19 @@ static int __init nfc_init(void)
620629
if (rc)
621630
goto err_rawsock;
622631

632+
rc = nfc_llcp_init();
633+
if (rc)
634+
goto err_llcp_sock;
635+
623636
rc = af_nfc_init();
624637
if (rc)
625638
goto err_af_nfc;
626639

627640
return 0;
628641

629642
err_af_nfc:
643+
nfc_llcp_exit();
644+
err_llcp_sock:
630645
rawsock_exit();
631646
err_rawsock:
632647
nfc_genl_exit();
@@ -638,6 +653,7 @@ static int __init nfc_init(void)
638653
static void __exit nfc_exit(void)
639654
{
640655
af_nfc_exit();
656+
nfc_llcp_exit();
641657
rawsock_exit();
642658
nfc_genl_exit();
643659
class_unregister(&nfc_class);

net/nfc/llcp/Kconfig

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
config NFC_LLCP
2+
depends on NFC && EXPERIMENTAL
3+
bool "NFC LLCP support (EXPERIMENTAL)"
4+
default n
5+
help
6+
Say Y here if you want to build support for a kernel NFC LLCP
7+
implementation.

0 commit comments

Comments
 (0)