PageRenderTime 35ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c

https://github.com/galaxyishere/samsung-kernel-latona
C | 321 lines | 219 code | 46 blank | 56 comment | 35 complexity | a198304b372eda157968289c1ac1f9c0 MD5 | raw file
  1. /*******************************************************************************
  2. Copyright(c) 2004 Intel Corporation. All rights reserved.
  3. Portions of this file are based on the WEP enablement code provided by the
  4. Host AP project hostap-drivers v0.1.3
  5. Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  6. <jkmaline@cc.hut.fi>
  7. Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
  8. This program is free software; you can redistribute it and/or modify it
  9. under the terms of version 2 of the GNU General Public License as
  10. published by the Free Software Foundation.
  11. This program is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. more details.
  15. You should have received a copy of the GNU General Public License along with
  16. this program; if not, write to the Free Software Foundation, Inc., 59
  17. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. The full GNU General Public License is included in this distribution in the
  19. file called LICENSE.
  20. Contact Information:
  21. James P. Ketrenos <ipw2100-admin@linux.intel.com>
  22. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  23. *******************************************************************************/
  24. #include <linux/compiler.h>
  25. //#include <linux/config.h>
  26. #include <linux/errno.h>
  27. #include <linux/if_arp.h>
  28. #include <linux/in6.h>
  29. #include <linux/in.h>
  30. #include <linux/ip.h>
  31. #include <linux/kernel.h>
  32. #include <linux/module.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/pci.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/slab.h>
  38. #include <linux/tcp.h>
  39. #include <linux/types.h>
  40. #include <linux/version.h>
  41. #include <linux/wireless.h>
  42. #include <linux/etherdevice.h>
  43. #include <asm/uaccess.h>
  44. #include <net/arp.h>
  45. #include "ieee80211.h"
  46. MODULE_DESCRIPTION("802.11 data/management/control stack");
  47. MODULE_AUTHOR("Copyright (C) 2004 Intel Corporation <jketreno@linux.intel.com>");
  48. MODULE_LICENSE("GPL");
  49. #define DRV_NAME "ieee80211"
  50. static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
  51. {
  52. if (ieee->networks)
  53. return 0;
  54. ieee->networks = kcalloc(
  55. MAX_NETWORK_COUNT, sizeof(struct ieee80211_network),
  56. GFP_KERNEL);
  57. if (!ieee->networks) {
  58. printk(KERN_WARNING "%s: Out of memory allocating beacons\n",
  59. ieee->dev->name);
  60. return -ENOMEM;
  61. }
  62. return 0;
  63. }
  64. static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
  65. {
  66. if (!ieee->networks)
  67. return;
  68. kfree(ieee->networks);
  69. ieee->networks = NULL;
  70. }
  71. static inline void ieee80211_networks_initialize(struct ieee80211_device *ieee)
  72. {
  73. int i;
  74. INIT_LIST_HEAD(&ieee->network_free_list);
  75. INIT_LIST_HEAD(&ieee->network_list);
  76. for (i = 0; i < MAX_NETWORK_COUNT; i++)
  77. list_add_tail(&ieee->networks[i].list, &ieee->network_free_list);
  78. }
  79. struct net_device *alloc_ieee80211(int sizeof_priv)
  80. {
  81. struct ieee80211_device *ieee;
  82. struct net_device *dev;
  83. int i,err;
  84. IEEE80211_DEBUG_INFO("Initializing...\n");
  85. dev = alloc_etherdev(sizeof(struct ieee80211_device) + sizeof_priv);
  86. if (!dev) {
  87. IEEE80211_ERROR("Unable to network device.\n");
  88. goto failed;
  89. }
  90. ieee = netdev_priv(dev);
  91. memset(ieee, 0, sizeof(struct ieee80211_device)+sizeof_priv);
  92. ieee->dev = dev;
  93. err = ieee80211_networks_allocate(ieee);
  94. if (err) {
  95. IEEE80211_ERROR("Unable to allocate beacon storage: %d\n",
  96. err);
  97. goto failed;
  98. }
  99. ieee80211_networks_initialize(ieee);
  100. /* Default fragmentation threshold is maximum payload size */
  101. ieee->fts = DEFAULT_FTS;
  102. ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
  103. ieee->open_wep = 1;
  104. /* Default to enabling full open WEP with host based encrypt/decrypt */
  105. ieee->host_encrypt = 1;
  106. ieee->host_decrypt = 1;
  107. ieee->ieee802_1x = 1; /* Default to supporting 802.1x */
  108. INIT_LIST_HEAD(&ieee->crypt_deinit_list);
  109. init_timer(&ieee->crypt_deinit_timer);
  110. ieee->crypt_deinit_timer.data = (unsigned long)ieee;
  111. ieee->crypt_deinit_timer.function = ieee80211_crypt_deinit_handler;
  112. spin_lock_init(&ieee->lock);
  113. spin_lock_init(&ieee->wpax_suitlist_lock);
  114. spin_lock_init(&ieee->bw_spinlock);
  115. spin_lock_init(&ieee->reorder_spinlock);
  116. //added by WB
  117. atomic_set(&(ieee->atm_chnlop), 0);
  118. atomic_set(&(ieee->atm_swbw), 0);
  119. ieee->wpax_type_set = 0;
  120. ieee->wpa_enabled = 0;
  121. ieee->tkip_countermeasures = 0;
  122. ieee->drop_unencrypted = 0;
  123. ieee->privacy_invoked = 0;
  124. ieee->ieee802_1x = 1;
  125. ieee->raw_tx = 0;
  126. //ieee->hwsec_support = 1; //defalt support hw security. //use module_param instead.
  127. ieee->hwsec_active = 0; //disable hwsec, switch it on when necessary.
  128. ieee80211_softmac_init(ieee);
  129. ieee->pHTInfo = kzalloc(sizeof(RT_HIGH_THROUGHPUT), GFP_KERNEL);
  130. if (ieee->pHTInfo == NULL)
  131. {
  132. IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for HTInfo\n");
  133. return NULL;
  134. }
  135. HTUpdateDefaultSetting(ieee);
  136. HTInitializeHTInfo(ieee); //may move to other place.
  137. TSInitialize(ieee);
  138. for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++)
  139. INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]);
  140. for (i = 0; i < 17; i++) {
  141. ieee->last_rxseq_num[i] = -1;
  142. ieee->last_rxfrag_num[i] = -1;
  143. ieee->last_packet_time[i] = 0;
  144. }
  145. //These function were added to load crypte module autoly
  146. ieee80211_tkip_null();
  147. ieee80211_wep_null();
  148. ieee80211_ccmp_null();
  149. return dev;
  150. failed:
  151. if (dev)
  152. free_netdev(dev);
  153. return NULL;
  154. }
  155. void free_ieee80211(struct net_device *dev)
  156. {
  157. struct ieee80211_device *ieee = netdev_priv(dev);
  158. int i;
  159. //struct list_head *p, *q;
  160. // del_timer_sync(&ieee->SwBwTimer);
  161. if (ieee->pHTInfo != NULL)
  162. {
  163. kfree(ieee->pHTInfo);
  164. ieee->pHTInfo = NULL;
  165. }
  166. RemoveAllTS(ieee);
  167. ieee80211_softmac_free(ieee);
  168. del_timer_sync(&ieee->crypt_deinit_timer);
  169. ieee80211_crypt_deinit_entries(ieee, 1);
  170. for (i = 0; i < WEP_KEYS; i++) {
  171. struct ieee80211_crypt_data *crypt = ieee->crypt[i];
  172. if (crypt) {
  173. if (crypt->ops)
  174. crypt->ops->deinit(crypt->priv);
  175. kfree(crypt);
  176. ieee->crypt[i] = NULL;
  177. }
  178. }
  179. ieee80211_networks_free(ieee);
  180. free_netdev(dev);
  181. }
  182. #ifdef CONFIG_IEEE80211_DEBUG
  183. u32 ieee80211_debug_level = 0;
  184. static int debug = \
  185. // IEEE80211_DL_INFO |
  186. // IEEE80211_DL_WX |
  187. // IEEE80211_DL_SCAN |
  188. // IEEE80211_DL_STATE |
  189. // IEEE80211_DL_MGMT |
  190. // IEEE80211_DL_FRAG |
  191. // IEEE80211_DL_EAP |
  192. // IEEE80211_DL_DROP |
  193. // IEEE80211_DL_TX |
  194. // IEEE80211_DL_RX |
  195. //IEEE80211_DL_QOS |
  196. // IEEE80211_DL_HT |
  197. // IEEE80211_DL_TS |
  198. // IEEE80211_DL_BA |
  199. // IEEE80211_DL_REORDER|
  200. // IEEE80211_DL_TRACE |
  201. //IEEE80211_DL_DATA |
  202. IEEE80211_DL_ERR //awayls open this flags to show error out
  203. ;
  204. struct proc_dir_entry *ieee80211_proc = NULL;
  205. static int show_debug_level(char *page, char **start, off_t offset,
  206. int count, int *eof, void *data)
  207. {
  208. return snprintf(page, count, "0x%08X\n", ieee80211_debug_level);
  209. }
  210. static int store_debug_level(struct file *file, const char *buffer,
  211. unsigned long count, void *data)
  212. {
  213. char buf[] = "0x00000000";
  214. unsigned long len = min_t(unsigned long, sizeof(buf) - 1, count);
  215. char *p = (char *)buf;
  216. unsigned long val;
  217. if (copy_from_user(buf, buffer, len))
  218. return count;
  219. buf[len] = 0;
  220. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  221. p++;
  222. if (p[0] == 'x' || p[0] == 'X')
  223. p++;
  224. val = simple_strtoul(p, &p, 16);
  225. } else
  226. val = simple_strtoul(p, &p, 10);
  227. if (p == buf)
  228. printk(KERN_INFO DRV_NAME
  229. ": %s is not in hex or decimal form.\n", buf);
  230. else
  231. ieee80211_debug_level = val;
  232. return strnlen(buf, count);
  233. }
  234. int __init ieee80211_debug_init(void)
  235. {
  236. struct proc_dir_entry *e;
  237. ieee80211_debug_level = debug;
  238. ieee80211_proc = create_proc_entry(DRV_NAME, S_IFDIR, init_net.proc_net);
  239. if (ieee80211_proc == NULL) {
  240. IEEE80211_ERROR("Unable to create " DRV_NAME
  241. " proc directory\n");
  242. return -EIO;
  243. }
  244. e = create_proc_entry("debug_level", S_IFREG | S_IRUGO | S_IWUSR,
  245. ieee80211_proc);
  246. if (!e) {
  247. remove_proc_entry(DRV_NAME, init_net.proc_net);
  248. ieee80211_proc = NULL;
  249. return -EIO;
  250. }
  251. e->read_proc = show_debug_level;
  252. e->write_proc = store_debug_level;
  253. e->data = NULL;
  254. return 0;
  255. }
  256. void __exit ieee80211_debug_exit(void)
  257. {
  258. if (ieee80211_proc) {
  259. remove_proc_entry("debug_level", ieee80211_proc);
  260. remove_proc_entry(DRV_NAME, init_net.proc_net);
  261. ieee80211_proc = NULL;
  262. }
  263. }
  264. #include <linux/moduleparam.h>
  265. module_param(debug, int, 0444);
  266. MODULE_PARM_DESC(debug, "debug output mask");
  267. #endif