Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Copyright(c) 2004 Intel Corporation. All rights reserved. |
| 4 | |
| 5 | Portions of this file are based on the WEP enablement code provided by the |
| 6 | Host AP project hostap-drivers v0.1.3 |
| 7 | Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen |
| 8 | <jkmaline@cc.hut.fi> |
| 9 | Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> |
| 10 | |
| 11 | This program is free software; you can redistribute it and/or modify it |
| 12 | under the terms of version 2 of the GNU General Public License as |
| 13 | published by the Free Software Foundation. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 18 | more details. |
| 19 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 20 | The full GNU General Public License is included in this distribution in the |
| 21 | file called LICENSE. |
| 22 | |
| 23 | Contact Information: |
| 24 | James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include <linux/compiler.h> |
| 30 | #include <linux/errno.h> |
| 31 | #include <linux/if_arp.h> |
| 32 | #include <linux/in6.h> |
| 33 | #include <linux/in.h> |
| 34 | #include <linux/ip.h> |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/module.h> |
| 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/pci.h> |
| 39 | #include <linux/proc_fs.h> |
| 40 | #include <linux/skbuff.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/tcp.h> |
| 43 | #include <linux/types.h> |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 44 | #include <linux/wireless.h> |
| 45 | #include <linux/etherdevice.h> |
Larry Finger | 8567829 | 2011-08-25 11:48:24 -0500 | [diff] [blame] | 46 | #include <linux/uaccess.h> |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 47 | #include <net/arp.h> |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 48 | #include "rtllib.h" |
| 49 | |
Sean MacLennan | d37e020 | 2011-11-28 20:21:27 -0500 | [diff] [blame] | 50 | u32 rt_global_debug_component = COMP_ERR; |
| 51 | EXPORT_SYMBOL(rt_global_debug_component); |
| 52 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 53 | static inline int rtllib_networks_allocate(struct rtllib_device *ieee) |
| 54 | { |
| 55 | if (ieee->networks) |
| 56 | return 0; |
| 57 | |
Shraddha Barke | 749f3c0 | 2015-10-09 21:03:29 +0530 | [diff] [blame] | 58 | ieee->networks = kcalloc(MAX_NETWORK_COUNT, |
| 59 | sizeof(struct rtllib_network), GFP_KERNEL); |
Quentin Lambert | b6b0012 | 2015-03-05 14:12:15 +0100 | [diff] [blame] | 60 | if (!ieee->networks) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 61 | return -ENOMEM; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 62 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static inline void rtllib_networks_free(struct rtllib_device *ieee) |
| 67 | { |
| 68 | if (!ieee->networks) |
| 69 | return; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 70 | kfree(ieee->networks); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 71 | ieee->networks = NULL; |
| 72 | } |
| 73 | |
| 74 | static inline void rtllib_networks_initialize(struct rtllib_device *ieee) |
| 75 | { |
| 76 | int i; |
| 77 | |
| 78 | INIT_LIST_HEAD(&ieee->network_free_list); |
| 79 | INIT_LIST_HEAD(&ieee->network_list); |
| 80 | for (i = 0; i < MAX_NETWORK_COUNT; i++) |
Larry Finger | 8567829 | 2011-08-25 11:48:24 -0500 | [diff] [blame] | 81 | list_add_tail(&ieee->networks[i].list, |
| 82 | &ieee->network_free_list); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 85 | struct net_device *alloc_rtllib(int sizeof_priv) |
| 86 | { |
| 87 | struct rtllib_device *ieee = NULL; |
| 88 | struct net_device *dev; |
Larry Finger | 8567829 | 2011-08-25 11:48:24 -0500 | [diff] [blame] | 89 | int i, err; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 90 | |
Mateusz Kulikowski | def16d2 | 2015-05-31 20:19:34 +0200 | [diff] [blame] | 91 | pr_debug("rtllib: Initializing...\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 92 | |
| 93 | dev = alloc_etherdev(sizeof(struct rtllib_device) + sizeof_priv); |
| 94 | if (!dev) { |
Mateusz Kulikowski | f0dddb1 | 2015-05-31 20:19:27 +0200 | [diff] [blame] | 95 | pr_err("Unable to allocate net_device.\n"); |
Himangi Saraogi | 49d74d7 | 2014-06-21 20:39:51 +0530 | [diff] [blame] | 96 | return NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 97 | } |
| 98 | ieee = (struct rtllib_device *)netdev_priv_rsl(dev); |
| 99 | memset(ieee, 0, sizeof(struct rtllib_device)+sizeof_priv); |
| 100 | ieee->dev = dev; |
| 101 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 102 | err = rtllib_networks_allocate(ieee); |
| 103 | if (err) { |
Mateusz Kulikowski | f0dddb1 | 2015-05-31 20:19:27 +0200 | [diff] [blame] | 104 | pr_err("Unable to allocate beacon storage: %d\n", err); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 105 | goto failed; |
| 106 | } |
| 107 | rtllib_networks_initialize(ieee); |
| 108 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 109 | /* Default fragmentation threshold is maximum payload size */ |
| 110 | ieee->fts = DEFAULT_FTS; |
| 111 | ieee->scan_age = DEFAULT_MAX_SCAN_AGE; |
| 112 | ieee->open_wep = 1; |
| 113 | |
| 114 | /* Default to enabling full open WEP with host based encrypt/decrypt */ |
| 115 | ieee->host_encrypt = 1; |
| 116 | ieee->host_decrypt = 1; |
| 117 | ieee->ieee802_1x = 1; /* Default to supporting 802.1x */ |
| 118 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 119 | ieee->rtllib_ap_sec_type = rtllib_ap_sec_type; |
| 120 | |
| 121 | spin_lock_init(&ieee->lock); |
| 122 | spin_lock_init(&ieee->wpax_suitlist_lock); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 123 | spin_lock_init(&ieee->reorder_spinlock); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 124 | atomic_set(&(ieee->atm_swbw), 0); |
| 125 | |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 126 | /* SAM FIXME */ |
| 127 | lib80211_crypt_info_init(&ieee->crypt_info, "RTLLIB", &ieee->lock); |
| 128 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 129 | ieee->wpa_enabled = 0; |
| 130 | ieee->tkip_countermeasures = 0; |
| 131 | ieee->drop_unencrypted = 0; |
| 132 | ieee->privacy_invoked = 0; |
| 133 | ieee->ieee802_1x = 1; |
| 134 | ieee->raw_tx = 0; |
| 135 | ieee->hwsec_active = 0; |
| 136 | |
Larry Finger | 8567829 | 2011-08-25 11:48:24 -0500 | [diff] [blame] | 137 | memset(ieee->swcamtable, 0, sizeof(struct sw_cam_table) * 32); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 138 | rtllib_softmac_init(ieee); |
| 139 | |
Larry Finger | 8567829 | 2011-08-25 11:48:24 -0500 | [diff] [blame] | 140 | ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL); |
Sandhya Bankar | 6869a11 | 2016-09-18 04:18:22 +0530 | [diff] [blame] | 141 | if (!ieee->pHTInfo) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 142 | return NULL; |
Quentin Lambert | b6b0012 | 2015-03-05 14:12:15 +0100 | [diff] [blame] | 143 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 144 | HTUpdateDefaultSetting(ieee); |
| 145 | HTInitializeHTInfo(ieee); |
| 146 | TSInitialize(ieee); |
| 147 | for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++) |
| 148 | INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]); |
| 149 | |
| 150 | for (i = 0; i < 17; i++) { |
| 151 | ieee->last_rxseq_num[i] = -1; |
| 152 | ieee->last_rxfrag_num[i] = -1; |
| 153 | ieee->last_packet_time[i] = 0; |
| 154 | } |
| 155 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 156 | return dev; |
| 157 | |
| 158 | failed: |
Himangi Saraogi | 49d74d7 | 2014-06-21 20:39:51 +0530 | [diff] [blame] | 159 | free_netdev(dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 160 | return NULL; |
| 161 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 162 | EXPORT_SYMBOL(alloc_rtllib); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 163 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 164 | void free_rtllib(struct net_device *dev) |
| 165 | { |
Larry Finger | 8567829 | 2011-08-25 11:48:24 -0500 | [diff] [blame] | 166 | struct rtllib_device *ieee = (struct rtllib_device *) |
| 167 | netdev_priv_rsl(dev); |
Larry Finger | d7613e5 | 2011-09-01 12:23:21 -0500 | [diff] [blame] | 168 | |
| 169 | kfree(ieee->pHTInfo); |
| 170 | ieee->pHTInfo = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 171 | rtllib_softmac_free(ieee); |
Sean MacLennan | 0ddcf5f | 2011-12-19 23:21:41 -0500 | [diff] [blame] | 172 | |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 173 | lib80211_crypt_info_free(&ieee->crypt_info); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 174 | |
| 175 | rtllib_networks_free(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 176 | free_netdev(dev); |
| 177 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 178 | EXPORT_SYMBOL(free_rtllib); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 179 | |
Rashika Kheria | cf8ab8c | 2013-11-02 23:38:00 +0530 | [diff] [blame] | 180 | static int __init rtllib_init(void) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 181 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
Rashika Kheria | cf8ab8c | 2013-11-02 23:38:00 +0530 | [diff] [blame] | 185 | static void __exit rtllib_exit(void) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 186 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 187 | } |
Sean MacLennan | d37e020 | 2011-11-28 20:21:27 -0500 | [diff] [blame] | 188 | |
| 189 | module_init(rtllib_init); |
| 190 | module_exit(rtllib_exit); |
| 191 | |
| 192 | MODULE_LICENSE("GPL"); |