aboutsummaryrefslogtreecommitdiffstats
path: root/net/nfc
diff options
context:
space:
mode:
authorEric Lapuyade <eric.lapuyade@linux.intel.com>2012-09-13 11:10:00 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2012-09-24 18:17:25 -0400
commit67cccfe17d1b3da1ed6c79e643c9be95ebde9642 (patch)
treeec08617b50bbb6dce81fd3436b582e3cf55b231a /net/nfc
parentf3e8fb552789f4845e60b11c47b676d14b9488e5 (diff)
NFC: Add an LLC Core layer to HCI
The LLC layer manages modules that control the link layer protocol (such as shdlc) between HCI and an HCI driver. The driver must simply specify the required llc when it registers with HCI. Signed-off-by: Eric Lapuyade <eric.lapuyade@intel.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'net/nfc')
-rw-r--r--net/nfc/hci/Makefile2
-rw-r--r--net/nfc/hci/core.c14
-rw-r--r--net/nfc/hci/llc.c168
-rw-r--r--net/nfc/hci/llc.h58
4 files changed, 241 insertions, 1 deletions
diff --git a/net/nfc/hci/Makefile b/net/nfc/hci/Makefile
index f9c44b2fb065..b44686b581af 100644
--- a/net/nfc/hci/Makefile
+++ b/net/nfc/hci/Makefile
@@ -4,5 +4,5 @@
4 4
5obj-$(CONFIG_NFC_HCI) += hci.o 5obj-$(CONFIG_NFC_HCI) += hci.o
6 6
7hci-y := core.o hcp.o command.o 7hci-y := core.o hcp.o command.o llc.o
8hci-$(CONFIG_NFC_SHDLC) += shdlc.o 8hci-$(CONFIG_NFC_SHDLC) += shdlc.o
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index dc57e3dc15a4..069e2d6056e5 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -26,6 +26,7 @@
26 26
27#include <net/nfc/nfc.h> 27#include <net/nfc/nfc.h>
28#include <net/nfc/hci.h> 28#include <net/nfc/hci.h>
29#include <net/nfc/llc.h>
29 30
30#include "hci.h" 31#include "hci.h"
31 32
@@ -821,4 +822,17 @@ void nfc_hci_recv_frame(struct nfc_hci_dev *hdev, struct sk_buff *skb)
821} 822}
822EXPORT_SYMBOL(nfc_hci_recv_frame); 823EXPORT_SYMBOL(nfc_hci_recv_frame);
823 824
825static int __init nfc_hci_init(void)
826{
827 return nfc_llc_init();
828}
829
830static void __exit nfc_hci_exit(void)
831{
832 nfc_llc_exit();
833}
834
835module_init(nfc_hci_init);
836module_exit(nfc_hci_exit);
837
824MODULE_LICENSE("GPL"); 838MODULE_LICENSE("GPL");
diff --git a/net/nfc/hci/llc.c b/net/nfc/hci/llc.c
new file mode 100644
index 000000000000..73c42785ce84
--- /dev/null
+++ b/net/nfc/hci/llc.c
@@ -0,0 +1,168 @@
1/*
2 * Link Layer Control manager
3 *
4 * Copyright (C) 2012 Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/export.h>
22#include <net/nfc/llc.h>
23#include "llc.h"
24
25static struct list_head llc_engines;
26
27int nfc_llc_init(void)
28{
29 INIT_LIST_HEAD(&llc_engines);
30
31 return 0;
32}
33EXPORT_SYMBOL(nfc_llc_init);
34
35void nfc_llc_exit(void)
36{
37 struct nfc_llc_engine *llc_engine, *n;
38
39 list_for_each_entry_safe(llc_engine, n, &llc_engines, entry) {
40 list_del(&llc_engine->entry);
41 kfree(llc_engine->name);
42 kfree(llc_engine);
43 }
44}
45EXPORT_SYMBOL(nfc_llc_exit);
46
47int nfc_llc_register(const char *name, struct nfc_llc_ops *ops)
48{
49 struct nfc_llc_engine *llc_engine;
50
51 llc_engine = kzalloc(sizeof(struct nfc_llc_engine), GFP_KERNEL);
52 if (llc_engine == NULL)
53 return -ENOMEM;
54
55 llc_engine->name = kstrdup(name, GFP_KERNEL);
56 if (llc_engine->name == NULL) {
57 kfree(llc_engine);
58 return -ENOMEM;
59 }
60 llc_engine->ops = ops;
61
62 INIT_LIST_HEAD(&llc_engine->entry);
63 list_add_tail (&llc_engine->entry, &llc_engines);
64
65 return 0;
66}
67EXPORT_SYMBOL(nfc_llc_register);
68
69static struct nfc_llc_engine *nfc_llc_name_to_engine(const char *name)
70{
71 struct nfc_llc_engine *llc_engine;
72
73 list_for_each_entry(llc_engine, &llc_engines, entry) {
74 if (strcmp(llc_engine->name, name) == 0)
75 return llc_engine;
76 }
77
78 return NULL;
79}
80
81void nfc_llc_unregister(const char *name)
82{
83 struct nfc_llc_engine *llc_engine;
84
85 llc_engine = nfc_llc_name_to_engine(name);
86 if (llc_engine == NULL)
87 return;
88
89 list_del(&llc_engine->entry);
90 kfree(llc_engine->name);
91 kfree(llc_engine);
92}
93EXPORT_SYMBOL(nfc_llc_unregister);
94
95struct nfc_llc *nfc_llc_allocate(const char *name, struct nfc_hci_dev *hdev,
96 xmit_to_drv_t xmit_to_drv,
97 rcv_to_hci_t rcv_to_hci, int tx_headroom,
98 int tx_tailroom, llc_failure_t llc_failure)
99{
100 struct nfc_llc_engine *llc_engine;
101 struct nfc_llc *llc;
102
103 llc_engine = nfc_llc_name_to_engine(name);
104 if (llc_engine == NULL)
105 return NULL;
106
107 llc = kzalloc(sizeof(struct nfc_llc), GFP_KERNEL);
108 if (llc == NULL)
109 return NULL;
110
111 llc->data = llc_engine->ops->init(hdev, xmit_to_drv, rcv_to_hci,
112 tx_headroom, tx_tailroom,
113 &llc->rx_headroom, &llc->rx_tailroom,
114 llc_failure);
115 if (llc->data == NULL) {
116 kfree(llc);
117 return NULL;
118 }
119 llc->ops = llc_engine->ops;
120
121 return llc;
122}
123EXPORT_SYMBOL(nfc_llc_allocate);
124
125void nfc_llc_free(struct nfc_llc *llc)
126{
127 llc->ops->deinit(llc);
128 kfree(llc);
129}
130EXPORT_SYMBOL(nfc_llc_free);
131
132inline void nfc_llc_get_rx_head_tail_room(struct nfc_llc *llc, int *rx_headroom,
133 int *rx_tailroom)
134{
135 *rx_headroom = llc->rx_headroom;
136 *rx_tailroom = llc->rx_tailroom;
137}
138EXPORT_SYMBOL(nfc_llc_get_rx_head_tail_room);
139
140inline int nfc_llc_start(struct nfc_llc *llc)
141{
142 return llc->ops->start(llc);
143}
144EXPORT_SYMBOL(nfc_llc_start);
145
146inline int nfc_llc_stop(struct nfc_llc *llc)
147{
148 return llc->ops->stop(llc);
149}
150EXPORT_SYMBOL(nfc_llc_stop);
151
152inline void nfc_llc_rcv_from_drv(struct nfc_llc *llc, struct sk_buff *skb)
153{
154 llc->ops->rcv_from_drv(llc, skb);
155}
156EXPORT_SYMBOL(nfc_llc_rcv_from_drv);
157
158inline int nfc_llc_xmit_from_hci(struct nfc_llc *llc, struct sk_buff *skb)
159{
160 return llc->ops->xmit_from_hci(llc, skb);
161}
162EXPORT_SYMBOL(nfc_llc_xmit_from_hci);
163
164inline void *nfc_llc_get_data(struct nfc_llc *llc)
165{
166 return llc->data;
167}
168EXPORT_SYMBOL(nfc_llc_get_data);
diff --git a/net/nfc/hci/llc.h b/net/nfc/hci/llc.h
new file mode 100644
index 000000000000..b2c7285b0309
--- /dev/null
+++ b/net/nfc/hci/llc.h
@@ -0,0 +1,58 @@
1/*
2 * Link Layer Control manager
3 *
4 * Copyright (C) 2012 Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#ifndef __LOCAL_LLC_H_
22#define __LOCAL_LLC_H_
23
24#include <net/nfc/hci.h>
25#include <net/nfc/llc.h>
26#include <linux/skbuff.h>
27
28struct nfc_llc_ops {
29 void *(*init) (struct nfc_hci_dev *hdev, xmit_to_drv_t xmit_to_drv,
30 rcv_to_hci_t rcv_to_hci, int tx_headroom,
31 int tx_tailroom, int *rx_headroom, int *rx_tailroom,
32 llc_failure_t llc_failure);
33 void (*deinit) (struct nfc_llc *llc);
34 int (*start) (struct nfc_llc *llc);
35 int (*stop) (struct nfc_llc *llc);
36 void (*rcv_from_drv) (struct nfc_llc *llc, struct sk_buff *skb);
37 int (*xmit_from_hci) (struct nfc_llc *llc, struct sk_buff *skb);
38};
39
40struct nfc_llc_engine {
41 const char *name;
42 struct nfc_llc_ops *ops;
43 struct list_head entry;
44};
45
46struct nfc_llc {
47 void *data;
48 struct nfc_llc_ops *ops;
49 int rx_headroom;
50 int rx_tailroom;
51};
52
53void *nfc_llc_get_data(struct nfc_llc *llc);
54
55int nfc_llc_register(const char *name, struct nfc_llc_ops *ops);
56void nfc_llc_unregister(const char *name);
57
58#endif /* __LOCAL_LLC_H_ */