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 static void nfc_llc_del_engine(struct nfc_llc_engine
*llc_engine
)
35 list_del(&llc_engine
->entry
);
36 kfree_const(llc_engine
->name
);
40 void nfc_llc_exit(void)
42 struct nfc_llc_engine
*llc_engine
, *n
;
44 list_for_each_entry_safe(llc_engine
, n
, &llc_engines
, entry
)
45 nfc_llc_del_engine(llc_engine
);
48 int nfc_llc_register(const char *name
, const struct nfc_llc_ops
*ops
)
50 struct nfc_llc_engine
*llc_engine
;
52 llc_engine
= kzalloc(sizeof(struct nfc_llc_engine
), GFP_KERNEL
);
53 if (llc_engine
== NULL
)
56 llc_engine
->name
= kstrdup_const(name
, GFP_KERNEL
);
57 if (llc_engine
->name
== NULL
) {
61 llc_engine
->ops
= ops
;
63 INIT_LIST_HEAD(&llc_engine
->entry
);
64 list_add_tail(&llc_engine
->entry
, &llc_engines
);
69 static struct nfc_llc_engine
*nfc_llc_name_to_engine(const char *name
)
71 struct nfc_llc_engine
*llc_engine
;
73 list_for_each_entry(llc_engine
, &llc_engines
, entry
) {
74 if (strcmp(llc_engine
->name
, name
) == 0)
81 void nfc_llc_unregister(const char *name
)
83 struct nfc_llc_engine
*llc_engine
;
85 llc_engine
= nfc_llc_name_to_engine(name
);
86 if (llc_engine
== NULL
)
89 nfc_llc_del_engine(llc_engine
);
92 struct nfc_llc
*nfc_llc_allocate(const char *name
, struct nfc_hci_dev
*hdev
,
93 xmit_to_drv_t xmit_to_drv
,
94 rcv_to_hci_t rcv_to_hci
, int tx_headroom
,
95 int tx_tailroom
, llc_failure_t llc_failure
)
97 struct nfc_llc_engine
*llc_engine
;
100 llc_engine
= nfc_llc_name_to_engine(name
);
101 if (llc_engine
== NULL
)
104 llc
= kzalloc(sizeof(struct nfc_llc
), GFP_KERNEL
);
108 llc
->data
= llc_engine
->ops
->init(hdev
, xmit_to_drv
, rcv_to_hci
,
109 tx_headroom
, tx_tailroom
,
110 &llc
->rx_headroom
, &llc
->rx_tailroom
,
112 if (llc
->data
== NULL
) {
116 llc
->ops
= llc_engine
->ops
;
121 void nfc_llc_free(struct nfc_llc
*llc
)
123 llc
->ops
->deinit(llc
);
127 int nfc_llc_start(struct nfc_llc
*llc
)
129 return llc
->ops
->start(llc
);
131 EXPORT_SYMBOL(nfc_llc_start
);
133 int nfc_llc_stop(struct nfc_llc
*llc
)
135 return llc
->ops
->stop(llc
);
137 EXPORT_SYMBOL(nfc_llc_stop
);
139 void nfc_llc_rcv_from_drv(struct nfc_llc
*llc
, struct sk_buff
*skb
)
141 llc
->ops
->rcv_from_drv(llc
, skb
);
144 int nfc_llc_xmit_from_hci(struct nfc_llc
*llc
, struct sk_buff
*skb
)
146 return llc
->ops
->xmit_from_hci(llc
, skb
);
149 void *nfc_llc_get_data(struct nfc_llc
*llc
)