1 // SPDX-License-Identifier: GPL-2.0-only
3 * Link Layer Control manager
5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
8 #include <net/nfc/llc.h>
12 static LIST_HEAD(llc_engines);
14 int __init nfc_llc_init(void)
18 r = nfc_llc_nop_register();
22 r = nfc_llc_shdlc_register();
33 void nfc_llc_exit(void)
35 struct nfc_llc_engine *llc_engine, *n;
37 list_for_each_entry_safe(llc_engine, n, &llc_engines, entry) {
38 list_del(&llc_engine->entry);
39 kfree(llc_engine->name);
44 int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops)
46 struct nfc_llc_engine *llc_engine;
48 llc_engine = kzalloc(sizeof(struct nfc_llc_engine), GFP_KERNEL);
49 if (llc_engine == NULL)
52 llc_engine->name = kstrdup(name, GFP_KERNEL);
53 if (llc_engine->name == NULL) {
57 llc_engine->ops = ops;
59 INIT_LIST_HEAD(&llc_engine->entry);
60 list_add_tail(&llc_engine->entry, &llc_engines);
65 static struct nfc_llc_engine *nfc_llc_name_to_engine(const char *name)
67 struct nfc_llc_engine *llc_engine;
69 list_for_each_entry(llc_engine, &llc_engines, entry) {
70 if (strcmp(llc_engine->name, name) == 0)
77 void nfc_llc_unregister(const char *name)
79 struct nfc_llc_engine *llc_engine;
81 llc_engine = nfc_llc_name_to_engine(name);
82 if (llc_engine == NULL)
85 list_del(&llc_engine->entry);
86 kfree(llc_engine->name);
90 struct nfc_llc *nfc_llc_allocate(const char *name, struct nfc_hci_dev *hdev,
91 xmit_to_drv_t xmit_to_drv,
92 rcv_to_hci_t rcv_to_hci, int tx_headroom,
93 int tx_tailroom, llc_failure_t llc_failure)
95 struct nfc_llc_engine *llc_engine;
98 llc_engine = nfc_llc_name_to_engine(name);
99 if (llc_engine == NULL)
102 llc = kzalloc(sizeof(struct nfc_llc), GFP_KERNEL);
106 llc->data = llc_engine->ops->init(hdev, xmit_to_drv, rcv_to_hci,
107 tx_headroom, tx_tailroom,
108 &llc->rx_headroom, &llc->rx_tailroom,
110 if (llc->data == NULL) {
114 llc->ops = llc_engine->ops;
119 void nfc_llc_free(struct nfc_llc *llc)
121 llc->ops->deinit(llc);
125 int nfc_llc_start(struct nfc_llc *llc)
127 return llc->ops->start(llc);
129 EXPORT_SYMBOL(nfc_llc_start);
131 int nfc_llc_stop(struct nfc_llc *llc)
133 return llc->ops->stop(llc);
135 EXPORT_SYMBOL(nfc_llc_stop);
137 void nfc_llc_rcv_from_drv(struct nfc_llc *llc, struct sk_buff *skb)
139 llc->ops->rcv_from_drv(llc, skb);
142 int nfc_llc_xmit_from_hci(struct nfc_llc *llc, struct sk_buff *skb)
144 return llc->ops->xmit_from_hci(llc, skb);
147 void *nfc_llc_get_data(struct nfc_llc *llc)