/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 206 lines · 136 code · 35 blank · 35 comment · 13 complexity · 151ce6431c89a34a424f14f7e138ada3 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/wireless.h>
  41. #include <linux/etherdevice.h>
  42. #include <asm/uaccess.h>
  43. #include <net/arp.h>
  44. #include <net/net_namespace.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. ieee->dev = dev;
  92. err = ieee80211_networks_allocate(ieee);
  93. if (err) {
  94. IEEE80211_ERROR("Unable to allocate beacon storage: %d\n",
  95. err);
  96. goto failed;
  97. }
  98. ieee80211_networks_initialize(ieee);
  99. /* Default fragmentation threshold is maximum payload size */
  100. ieee->fts = DEFAULT_FTS;
  101. ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
  102. ieee->open_wep = 1;
  103. /* Default to enabling full open WEP with host based encrypt/decrypt */
  104. ieee->host_encrypt = 1;
  105. ieee->host_decrypt = 1;
  106. ieee->ieee802_1x = 1; /* Default to supporting 802.1x */
  107. INIT_LIST_HEAD(&ieee->crypt_deinit_list);
  108. init_timer(&ieee->crypt_deinit_timer);
  109. ieee->crypt_deinit_timer.data = (unsigned long)ieee;
  110. ieee->crypt_deinit_timer.function = ieee80211_crypt_deinit_handler;
  111. spin_lock_init(&ieee->lock);
  112. spin_lock_init(&ieee->wpax_suitlist_lock);
  113. ieee->wpax_type_set = 0;
  114. ieee->wpa_enabled = 0;
  115. ieee->tkip_countermeasures = 0;
  116. ieee->drop_unencrypted = 0;
  117. ieee->privacy_invoked = 0;
  118. ieee->ieee802_1x = 1;
  119. ieee->raw_tx = 0;
  120. ieee80211_softmac_init(ieee);
  121. for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++)
  122. INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]);
  123. for (i = 0; i < 17; i++) {
  124. ieee->last_rxseq_num[i] = -1;
  125. ieee->last_rxfrag_num[i] = -1;
  126. ieee->last_packet_time[i] = 0;
  127. }
  128. //These function were added to load crypte module autoly
  129. ieee80211_tkip_null();
  130. ieee80211_wep_null();
  131. ieee80211_ccmp_null();
  132. return dev;
  133. failed:
  134. if (dev)
  135. free_netdev(dev);
  136. return NULL;
  137. }
  138. void free_ieee80211(struct net_device *dev)
  139. {
  140. struct ieee80211_device *ieee = netdev_priv(dev);
  141. int i;
  142. struct list_head *p, *q;
  143. ieee80211_softmac_free(ieee);
  144. del_timer_sync(&ieee->crypt_deinit_timer);
  145. ieee80211_crypt_deinit_entries(ieee, 1);
  146. for (i = 0; i < WEP_KEYS; i++) {
  147. struct ieee80211_crypt_data *crypt = ieee->crypt[i];
  148. if (crypt) {
  149. if (crypt->ops)
  150. crypt->ops->deinit(crypt->priv);
  151. kfree(crypt);
  152. ieee->crypt[i] = NULL;
  153. }
  154. }
  155. ieee80211_networks_free(ieee);
  156. for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++) {
  157. list_for_each_safe(p, q, &ieee->ibss_mac_hash[i]) {
  158. kfree(list_entry(p, struct ieee_ibss_seq, list));
  159. list_del(p);
  160. }
  161. }
  162. free_netdev(dev);
  163. }