diff options
| -rw-r--r-- | include/net/nfc/llc.h | 51 | ||||
| -rw-r--r-- | net/nfc/hci/Makefile | 2 | ||||
| -rw-r--r-- | net/nfc/hci/core.c | 14 | ||||
| -rw-r--r-- | net/nfc/hci/llc.c | 168 | ||||
| -rw-r--r-- | net/nfc/hci/llc.h | 58 |
5 files changed, 292 insertions, 1 deletions
diff --git a/include/net/nfc/llc.h b/include/net/nfc/llc.h new file mode 100644 index 000000000000..98df903f8b7d --- /dev/null +++ b/include/net/nfc/llc.h | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | /* | ||
| 2 | * Link Layer Control manager public interface | ||
| 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 __NFC_LLC_H_ | ||
| 22 | #define __NFC_LLC_H_ | ||
| 23 | |||
| 24 | #include <net/nfc/hci.h> | ||
| 25 | #include <linux/skbuff.h> | ||
| 26 | |||
| 27 | typedef void (*rcv_to_hci_t) (struct nfc_hci_dev *hdev, struct sk_buff *skb); | ||
| 28 | typedef int (*xmit_to_drv_t) (struct nfc_hci_dev *hdev, struct sk_buff *skb); | ||
| 29 | typedef void (*llc_failure_t) (struct nfc_hci_dev *hdev, int err); | ||
| 30 | |||
| 31 | struct nfc_llc; | ||
| 32 | |||
| 33 | struct nfc_llc *nfc_llc_allocate(const char *name, struct nfc_hci_dev *hdev, | ||
| 34 | xmit_to_drv_t xmit_to_drv, | ||
| 35 | rcv_to_hci_t rcv_to_hci, int tx_headroom, | ||
| 36 | int tx_tailroom, llc_failure_t llc_failure); | ||
| 37 | void nfc_llc_free(struct nfc_llc *llc); | ||
| 38 | |||
| 39 | void nfc_llc_get_rx_head_tail_room(struct nfc_llc *llc, int *rx_headroom, | ||
| 40 | int *rx_tailroom); | ||
| 41 | |||
| 42 | |||
| 43 | int nfc_llc_start(struct nfc_llc *llc); | ||
| 44 | int nfc_llc_stop(struct nfc_llc *llc); | ||
| 45 | void nfc_llc_rcv_from_drv(struct nfc_llc *llc, struct sk_buff *skb); | ||
| 46 | int nfc_llc_xmit_from_hci(struct nfc_llc *llc, struct sk_buff *skb); | ||
| 47 | |||
| 48 | int nfc_llc_init(void); | ||
| 49 | void nfc_llc_exit(void); | ||
| 50 | |||
| 51 | #endif /* __NFC_LLC_H_ */ | ||
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 | ||
| 5 | obj-$(CONFIG_NFC_HCI) += hci.o | 5 | obj-$(CONFIG_NFC_HCI) += hci.o |
| 6 | 6 | ||
| 7 | hci-y := core.o hcp.o command.o | 7 | hci-y := core.o hcp.o command.o llc.o |
| 8 | hci-$(CONFIG_NFC_SHDLC) += shdlc.o | 8 | hci-$(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 | } |
| 822 | EXPORT_SYMBOL(nfc_hci_recv_frame); | 823 | EXPORT_SYMBOL(nfc_hci_recv_frame); |
| 823 | 824 | ||
| 825 | static int __init nfc_hci_init(void) | ||
| 826 | { | ||
| 827 | return nfc_llc_init(); | ||
| 828 | } | ||
| 829 | |||
| 830 | static void __exit nfc_hci_exit(void) | ||
| 831 | { | ||
| 832 | nfc_llc_exit(); | ||
| 833 | } | ||
| 834 | |||
| 835 | module_init(nfc_hci_init); | ||
| 836 | module_exit(nfc_hci_exit); | ||
| 837 | |||
| 824 | MODULE_LICENSE("GPL"); | 838 | MODULE_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 | |||
| 25 | static struct list_head llc_engines; | ||
| 26 | |||
| 27 | int nfc_llc_init(void) | ||
| 28 | { | ||
| 29 | INIT_LIST_HEAD(&llc_engines); | ||
| 30 | |||
| 31 | return 0; | ||
| 32 | } | ||
| 33 | EXPORT_SYMBOL(nfc_llc_init); | ||
| 34 | |||
| 35 | void 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 | } | ||
| 45 | EXPORT_SYMBOL(nfc_llc_exit); | ||
| 46 | |||
| 47 | int 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 | } | ||
| 67 | EXPORT_SYMBOL(nfc_llc_register); | ||
| 68 | |||
| 69 | static 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 | |||
| 81 | void 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 | } | ||
| 93 | EXPORT_SYMBOL(nfc_llc_unregister); | ||
| 94 | |||
| 95 | struct 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 | |||
