aboutsummaryrefslogtreecommitdiffstats
path: root/net/nfc/hci/llc.c
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/hci/llc.c
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/hci/llc.c')
-rw-r--r--net/nfc/hci/llc.c168
1 files changed, 168 insertions, 0 deletions
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);