rtllib_module.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. The full GNU General Public License is included in this distribution in the
  16. file called LICENSE.
  17. Contact Information:
  18. James P. Ketrenos <ipw2100-admin@linux.intel.com>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/compiler.h>
  22. #include <linux/errno.h>
  23. #include <linux/if_arp.h>
  24. #include <linux/in6.h>
  25. #include <linux/in.h>
  26. #include <linux/ip.h>
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/pci.h>
  31. #include <linux/proc_fs.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/slab.h>
  34. #include <linux/tcp.h>
  35. #include <linux/types.h>
  36. #include <linux/wireless.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/uaccess.h>
  39. #include <net/arp.h>
  40. #include "rtllib.h"
  41. u32 rt_global_debug_component = COMP_ERR;
  42. EXPORT_SYMBOL(rt_global_debug_component);
  43. static inline int rtllib_networks_allocate(struct rtllib_device *ieee)
  44. {
  45. if (ieee->networks)
  46. return 0;
  47. ieee->networks = kcalloc(MAX_NETWORK_COUNT,
  48. sizeof(struct rtllib_network), GFP_KERNEL);
  49. if (!ieee->networks)
  50. return -ENOMEM;
  51. return 0;
  52. }
  53. static inline void rtllib_networks_free(struct rtllib_device *ieee)
  54. {
  55. if (!ieee->networks)
  56. return;
  57. kfree(ieee->networks);
  58. ieee->networks = NULL;
  59. }
  60. static inline void rtllib_networks_initialize(struct rtllib_device *ieee)
  61. {
  62. int i;
  63. INIT_LIST_HEAD(&ieee->network_free_list);
  64. INIT_LIST_HEAD(&ieee->network_list);
  65. for (i = 0; i < MAX_NETWORK_COUNT; i++)
  66. list_add_tail(&ieee->networks[i].list,
  67. &ieee->network_free_list);
  68. }
  69. struct net_device *alloc_rtllib(int sizeof_priv)
  70. {
  71. struct rtllib_device *ieee = NULL;
  72. struct net_device *dev;
  73. int i, err;
  74. pr_debug("rtllib: Initializing...\n");
  75. dev = alloc_etherdev(sizeof(struct rtllib_device) + sizeof_priv);
  76. if (!dev) {
  77. pr_err("Unable to allocate net_device.\n");
  78. return NULL;
  79. }
  80. ieee = (struct rtllib_device *)netdev_priv_rsl(dev);
  81. memset(ieee, 0, sizeof(struct rtllib_device)+sizeof_priv);
  82. ieee->dev = dev;
  83. err = rtllib_networks_allocate(ieee);
  84. if (err) {
  85. pr_err("Unable to allocate beacon storage: %d\n", err);
  86. goto failed;
  87. }
  88. rtllib_networks_initialize(ieee);
  89. /* Default fragmentation threshold is maximum payload size */
  90. ieee->fts = DEFAULT_FTS;
  91. ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
  92. ieee->open_wep = 1;
  93. /* Default to enabling full open WEP with host based encrypt/decrypt */
  94. ieee->host_encrypt = 1;
  95. ieee->host_decrypt = 1;
  96. ieee->ieee802_1x = 1; /* Default to supporting 802.1x */
  97. ieee->rtllib_ap_sec_type = rtllib_ap_sec_type;
  98. spin_lock_init(&ieee->lock);
  99. spin_lock_init(&ieee->wpax_suitlist_lock);
  100. spin_lock_init(&ieee->reorder_spinlock);
  101. atomic_set(&(ieee->atm_swbw), 0);
  102. /* SAM FIXME */
  103. lib80211_crypt_info_init(&ieee->crypt_info, "RTLLIB", &ieee->lock);
  104. ieee->wpa_enabled = 0;
  105. ieee->tkip_countermeasures = 0;
  106. ieee->drop_unencrypted = 0;
  107. ieee->privacy_invoked = 0;
  108. ieee->ieee802_1x = 1;
  109. ieee->raw_tx = 0;
  110. ieee->hwsec_active = 0;
  111. memset(ieee->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
  112. rtllib_softmac_init(ieee);
  113. ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL);
  114. if (ieee->pHTInfo == NULL)
  115. return NULL;
  116. HTUpdateDefaultSetting(ieee);
  117. HTInitializeHTInfo(ieee);
  118. TSInitialize(ieee);
  119. for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++)
  120. INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]);
  121. for (i = 0; i < 17; i++) {
  122. ieee->last_rxseq_num[i] = -1;
  123. ieee->last_rxfrag_num[i] = -1;
  124. ieee->last_packet_time[i] = 0;
  125. }
  126. return dev;
  127. failed:
  128. free_netdev(dev);
  129. return NULL;
  130. }
  131. EXPORT_SYMBOL(alloc_rtllib);
  132. void free_rtllib(struct net_device *dev)
  133. {
  134. struct rtllib_device *ieee = (struct rtllib_device *)
  135. netdev_priv_rsl(dev);
  136. kfree(ieee->pHTInfo);
  137. ieee->pHTInfo = NULL;
  138. rtllib_softmac_free(ieee);
  139. lib80211_crypt_info_free(&ieee->crypt_info);
  140. rtllib_networks_free(ieee);
  141. free_netdev(dev);
  142. }
  143. EXPORT_SYMBOL(free_rtllib);
  144. static int __init rtllib_init(void)
  145. {
  146. return 0;
  147. }
  148. static void __exit rtllib_exit(void)
  149. {
  150. }
  151. module_init(rtllib_init);
  152. module_exit(rtllib_exit);
  153. MODULE_LICENSE("GPL");