staging: rtl8192e: Fix FSF_MAILING_ADDRESS warnings
[firefly-linux-kernel-4.4.55.git] / drivers / staging / rtl8192e / rtllib_module.c
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
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>
44 #include <linux/wireless.h>
45 #include <linux/etherdevice.h>
46 #include <linux/uaccess.h>
47 #include <net/arp.h>
48
49 #include "rtllib.h"
50
51
52 u32 rt_global_debug_component = COMP_ERR;
53 EXPORT_SYMBOL(rt_global_debug_component);
54
55
56
57 static inline int rtllib_networks_allocate(struct rtllib_device *ieee)
58 {
59         if (ieee->networks)
60                 return 0;
61
62         ieee->networks = kzalloc(
63                 MAX_NETWORK_COUNT * sizeof(struct rtllib_network),
64                 GFP_KERNEL);
65         if (!ieee->networks)
66                 return -ENOMEM;
67
68         return 0;
69 }
70
71 static inline void rtllib_networks_free(struct rtllib_device *ieee)
72 {
73         if (!ieee->networks)
74                 return;
75         kfree(ieee->networks);
76         ieee->networks = NULL;
77 }
78
79 static inline void rtllib_networks_initialize(struct rtllib_device *ieee)
80 {
81         int i;
82
83         INIT_LIST_HEAD(&ieee->network_free_list);
84         INIT_LIST_HEAD(&ieee->network_list);
85         for (i = 0; i < MAX_NETWORK_COUNT; i++)
86                 list_add_tail(&ieee->networks[i].list,
87                               &ieee->network_free_list);
88 }
89
90 struct net_device *alloc_rtllib(int sizeof_priv)
91 {
92         struct rtllib_device *ieee = NULL;
93         struct net_device *dev;
94         int i, err;
95
96         pr_debug("rtllib: Initializing...\n");
97
98         dev = alloc_etherdev(sizeof(struct rtllib_device) + sizeof_priv);
99         if (!dev) {
100                 pr_err("Unable to allocate net_device.\n");
101                 return NULL;
102         }
103         ieee = (struct rtllib_device *)netdev_priv_rsl(dev);
104         memset(ieee, 0, sizeof(struct rtllib_device)+sizeof_priv);
105         ieee->dev = dev;
106
107         err = rtllib_networks_allocate(ieee);
108         if (err) {
109                 pr_err("Unable to allocate beacon storage: %d\n", err);
110                 goto failed;
111         }
112         rtllib_networks_initialize(ieee);
113
114
115         /* Default fragmentation threshold is maximum payload size */
116         ieee->fts = DEFAULT_FTS;
117         ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
118         ieee->open_wep = 1;
119
120         /* Default to enabling full open WEP with host based encrypt/decrypt */
121         ieee->host_encrypt = 1;
122         ieee->host_decrypt = 1;
123         ieee->ieee802_1x = 1; /* Default to supporting 802.1x */
124
125         ieee->rtllib_ap_sec_type = rtllib_ap_sec_type;
126
127         spin_lock_init(&ieee->lock);
128         spin_lock_init(&ieee->wpax_suitlist_lock);
129         spin_lock_init(&ieee->reorder_spinlock);
130         atomic_set(&(ieee->atm_swbw), 0);
131
132         /* SAM FIXME */
133         lib80211_crypt_info_init(&ieee->crypt_info, "RTLLIB", &ieee->lock);
134
135         ieee->wpa_enabled = 0;
136         ieee->tkip_countermeasures = 0;
137         ieee->drop_unencrypted = 0;
138         ieee->privacy_invoked = 0;
139         ieee->ieee802_1x = 1;
140         ieee->raw_tx = 0;
141         ieee->hwsec_active = 0;
142
143         memset(ieee->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
144         rtllib_softmac_init(ieee);
145
146         ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL);
147         if (ieee->pHTInfo == NULL)
148                 return NULL;
149
150         HTUpdateDefaultSetting(ieee);
151         HTInitializeHTInfo(ieee);
152         TSInitialize(ieee);
153         for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++)
154                 INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]);
155
156         for (i = 0; i < 17; i++) {
157                 ieee->last_rxseq_num[i] = -1;
158                 ieee->last_rxfrag_num[i] = -1;
159                 ieee->last_packet_time[i] = 0;
160         }
161
162         return dev;
163
164  failed:
165         free_netdev(dev);
166         return NULL;
167 }
168 EXPORT_SYMBOL(alloc_rtllib);
169
170 void free_rtllib(struct net_device *dev)
171 {
172         struct rtllib_device *ieee = (struct rtllib_device *)
173                                       netdev_priv_rsl(dev);
174
175         kfree(ieee->pHTInfo);
176         ieee->pHTInfo = NULL;
177         rtllib_softmac_free(ieee);
178
179         lib80211_crypt_info_free(&ieee->crypt_info);
180
181         rtllib_networks_free(ieee);
182         free_netdev(dev);
183 }
184 EXPORT_SYMBOL(free_rtllib);
185
186 static int __init rtllib_init(void)
187 {
188         return 0;
189 }
190
191 static void __exit rtllib_exit(void)
192 {
193 }
194
195 module_init(rtllib_init);
196 module_exit(rtllib_exit);
197
198 MODULE_LICENSE("GPL");