ieee80211_module.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 <linux/uaccess.h>
  43. #include <net/arp.h>
  44. #include "ieee80211.h"
  45. MODULE_DESCRIPTION("802.11 data/management/control stack");
  46. MODULE_AUTHOR("Copyright (C) 2004 Intel Corporation <jketreno@linux.intel.com>");
  47. MODULE_LICENSE("GPL");
  48. #define DRV_NAME "ieee80211"
  49. static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
  50. {
  51. if (ieee->networks)
  52. return 0;
  53. ieee->networks = kcalloc(
  54. MAX_NETWORK_COUNT, sizeof(struct ieee80211_network),
  55. GFP_KERNEL);
  56. if (!ieee->networks) {
  57. printk(KERN_WARNING "%s: Out of memory allocating beacons\n",
  58. ieee->dev->name);
  59. return -ENOMEM;
  60. }
  61. return 0;
  62. }
  63. static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
  64. {
  65. if (!ieee->networks)
  66. return;
  67. kfree(ieee->networks);
  68. ieee->networks = NULL;
  69. }
  70. static inline void ieee80211_networks_initialize(struct ieee80211_device *ieee)
  71. {
  72. int i;
  73. INIT_LIST_HEAD(&ieee->network_free_list);
  74. INIT_LIST_HEAD(&ieee->network_list);
  75. for (i = 0; i < MAX_NETWORK_COUNT; i++)
  76. list_add_tail(&ieee->networks[i].list, &ieee->network_free_list);
  77. }
  78. struct net_device *alloc_ieee80211(int sizeof_priv)
  79. {
  80. struct ieee80211_device *ieee;
  81. struct net_device *dev;
  82. int i, err;
  83. IEEE80211_DEBUG_INFO("Initializing...\n");
  84. dev = alloc_etherdev(sizeof(struct ieee80211_device) + sizeof_priv);
  85. if (!dev) {
  86. IEEE80211_ERROR("Unable to network device.\n");
  87. goto failed;
  88. }
  89. ieee = netdev_priv(dev);
  90. memset(ieee, 0, sizeof(struct ieee80211_device)+sizeof_priv);
  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. setup_timer(&ieee->crypt_deinit_timer,
  109. ieee80211_crypt_deinit_handler, (unsigned long)ieee);
  110. spin_lock_init(&ieee->lock);
  111. spin_lock_init(&ieee->wpax_suitlist_lock);
  112. spin_lock_init(&ieee->bw_spinlock);
  113. spin_lock_init(&ieee->reorder_spinlock);
  114. /* added by WB */
  115. atomic_set(&(ieee->atm_chnlop), 0);
  116. atomic_set(&(ieee->atm_swbw), 0);
  117. ieee->wpax_type_set = 0;
  118. ieee->wpa_enabled = 0;
  119. ieee->tkip_countermeasures = 0;
  120. ieee->drop_unencrypted = 0;
  121. ieee->privacy_invoked = 0;
  122. ieee->ieee802_1x = 1;
  123. ieee->raw_tx = 0;
  124. //ieee->hwsec_support = 1; //defalt support hw security. //use module_param instead.
  125. ieee->hwsec_active = 0; /* disable hwsec, switch it on when necessary. */
  126. ieee80211_softmac_init(ieee);
  127. ieee->pHTInfo = kzalloc(sizeof(RT_HIGH_THROUGHPUT), GFP_KERNEL);
  128. if (ieee->pHTInfo == NULL)
  129. {
  130. IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for HTInfo\n");
  131. goto failed;
  132. }
  133. HTUpdateDefaultSetting(ieee);
  134. HTInitializeHTInfo(ieee); /* may move to other place. */
  135. TSInitialize(ieee);
  136. for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++)
  137. INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]);
  138. for (i = 0; i < 17; i++) {
  139. ieee->last_rxseq_num[i] = -1;
  140. ieee->last_rxfrag_num[i] = -1;
  141. ieee->last_packet_time[i] = 0;
  142. }
  143. /* These function were added to load crypte module autoly */
  144. ieee80211_tkip_null();
  145. ieee80211_wep_null();
  146. ieee80211_ccmp_null();
  147. return dev;
  148. failed:
  149. if (dev)
  150. free_netdev(dev);
  151. return NULL;
  152. }
  153. void free_ieee80211(struct net_device *dev)
  154. {
  155. struct ieee80211_device *ieee = netdev_priv(dev);
  156. int i;
  157. /* struct list_head *p, *q; */
  158. // del_timer_sync(&ieee->SwBwTimer);
  159. kfree(ieee->pHTInfo);
  160. ieee->pHTInfo = NULL;
  161. RemoveAllTS(ieee);
  162. ieee80211_softmac_free(ieee);
  163. del_timer_sync(&ieee->crypt_deinit_timer);
  164. ieee80211_crypt_deinit_entries(ieee, 1);
  165. for (i = 0; i < WEP_KEYS; i++) {
  166. struct ieee80211_crypt_data *crypt = ieee->crypt[i];
  167. if (crypt) {
  168. if (crypt->ops)
  169. crypt->ops->deinit(crypt->priv);
  170. kfree(crypt);
  171. ieee->crypt[i] = NULL;
  172. }
  173. }
  174. ieee80211_networks_free(ieee);
  175. free_netdev(dev);
  176. }
  177. #ifdef CONFIG_IEEE80211_DEBUG
  178. u32 ieee80211_debug_level;
  179. static int debug = \
  180. // IEEE80211_DL_INFO |
  181. // IEEE80211_DL_WX |
  182. // IEEE80211_DL_SCAN |
  183. // IEEE80211_DL_STATE |
  184. // IEEE80211_DL_MGMT |
  185. // IEEE80211_DL_FRAG |
  186. // IEEE80211_DL_EAP |
  187. // IEEE80211_DL_DROP |
  188. // IEEE80211_DL_TX |
  189. // IEEE80211_DL_RX |
  190. //IEEE80211_DL_QOS |
  191. // IEEE80211_DL_HT |
  192. // IEEE80211_DL_TS |
  193. // IEEE80211_DL_BA |
  194. // IEEE80211_DL_REORDER|
  195. // IEEE80211_DL_TRACE |
  196. //IEEE80211_DL_DATA |
  197. IEEE80211_DL_ERR /* awayls open this flags to show error out */
  198. ;
  199. static struct proc_dir_entry *ieee80211_proc;
  200. static int show_debug_level(struct seq_file *m, void *v)
  201. {
  202. seq_printf(m, "0x%08X\n", ieee80211_debug_level);
  203. return 0;
  204. }
  205. static ssize_t write_debug_level(struct file *file, const char __user *buffer,
  206. size_t count, loff_t *ppos)
  207. {
  208. unsigned long val;
  209. int err = kstrtoul_from_user(buffer, count, 0, &val);
  210. if (err)
  211. return err;
  212. ieee80211_debug_level = val;
  213. return count;
  214. }
  215. static int open_debug_level(struct inode *inode, struct file *file)
  216. {
  217. return single_open(file, show_debug_level, NULL);
  218. }
  219. static const struct file_operations fops = {
  220. .open = open_debug_level,
  221. .read = seq_read,
  222. .llseek = seq_lseek,
  223. .write = write_debug_level,
  224. .release = single_release,
  225. };
  226. int __init ieee80211_debug_init(void)
  227. {
  228. struct proc_dir_entry *e;
  229. ieee80211_debug_level = debug;
  230. ieee80211_proc = proc_mkdir(DRV_NAME, init_net.proc_net);
  231. if (ieee80211_proc == NULL) {
  232. IEEE80211_ERROR("Unable to create " DRV_NAME
  233. " proc directory\n");
  234. return -EIO;
  235. }
  236. e = proc_create("debug_level", S_IRUGO | S_IWUSR,
  237. ieee80211_proc, &fops);
  238. if (!e) {
  239. remove_proc_entry(DRV_NAME, init_net.proc_net);
  240. ieee80211_proc = NULL;
  241. return -EIO;
  242. }
  243. return 0;
  244. }
  245. void __exit ieee80211_debug_exit(void)
  246. {
  247. if (ieee80211_proc) {
  248. remove_proc_entry("debug_level", ieee80211_proc);
  249. remove_proc_entry(DRV_NAME, init_net.proc_net);
  250. ieee80211_proc = NULL;
  251. }
  252. }
  253. module_param(debug, int, 0444);
  254. MODULE_PARM_DESC(debug, "debug output mask");
  255. #endif