ieee80211_module.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*******************************************************************************
  2. Copyright(c) 2004-2005 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/errno.h>
  26. #include <linux/if_arp.h>
  27. #include <linux/in6.h>
  28. #include <linux/in.h>
  29. #include <linux/ip.h>
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/proc_fs.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/slab.h>
  36. #include <linux/tcp.h>
  37. #include <linux/types.h>
  38. #include <linux/wireless.h>
  39. #include <linux/etherdevice.h>
  40. #include <asm/uaccess.h>
  41. #include <net/arp.h>
  42. #include <net/ieee80211.h>
  43. #define DRV_DESCRIPTION "802.11 data/management/control stack"
  44. #define DRV_NAME "ieee80211"
  45. #define DRV_VERSION IEEE80211_VERSION
  46. #define DRV_COPYRIGHT "Copyright (C) 2004-2005 Intel Corporation <jketreno@linux.intel.com>"
  47. MODULE_VERSION(DRV_VERSION);
  48. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  49. MODULE_AUTHOR(DRV_COPYRIGHT);
  50. MODULE_LICENSE("GPL");
  51. static int ieee80211_networks_allocate(struct ieee80211_device *ieee)
  52. {
  53. if (ieee->networks)
  54. return 0;
  55. ieee->networks =
  56. kzalloc(MAX_NETWORK_COUNT * sizeof(struct ieee80211_network),
  57. GFP_KERNEL);
  58. if (!ieee->networks) {
  59. printk(KERN_WARNING "%s: Out of memory allocating beacons\n",
  60. ieee->dev->name);
  61. return -ENOMEM;
  62. }
  63. return 0;
  64. }
  65. void ieee80211_network_reset(struct ieee80211_network *network)
  66. {
  67. if (!network)
  68. return;
  69. if (network->ibss_dfs) {
  70. kfree(network->ibss_dfs);
  71. network->ibss_dfs = NULL;
  72. }
  73. }
  74. static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
  75. {
  76. int i;
  77. if (!ieee->networks)
  78. return;
  79. for (i = 0; i < MAX_NETWORK_COUNT; i++)
  80. if (ieee->networks[i].ibss_dfs)
  81. kfree(ieee->networks[i].ibss_dfs);
  82. kfree(ieee->networks);
  83. ieee->networks = NULL;
  84. }
  85. static void ieee80211_networks_initialize(struct ieee80211_device *ieee)
  86. {
  87. int i;
  88. INIT_LIST_HEAD(&ieee->network_free_list);
  89. INIT_LIST_HEAD(&ieee->network_list);
  90. for (i = 0; i < MAX_NETWORK_COUNT; i++)
  91. list_add_tail(&ieee->networks[i].list,
  92. &ieee->network_free_list);
  93. }
  94. static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
  95. {
  96. if ((new_mtu < 68) || (new_mtu > IEEE80211_DATA_LEN))
  97. return -EINVAL;
  98. dev->mtu = new_mtu;
  99. return 0;
  100. }
  101. static struct net_device_stats *ieee80211_generic_get_stats(
  102. struct net_device *dev)
  103. {
  104. struct ieee80211_device *ieee = netdev_priv(dev);
  105. return &ieee->stats;
  106. }
  107. struct net_device *alloc_ieee80211(int sizeof_priv)
  108. {
  109. struct ieee80211_device *ieee;
  110. struct net_device *dev;
  111. int err;
  112. IEEE80211_DEBUG_INFO("Initializing...\n");
  113. dev = alloc_etherdev(sizeof(struct ieee80211_device) + sizeof_priv);
  114. if (!dev) {
  115. IEEE80211_ERROR("Unable to network device.\n");
  116. goto failed;
  117. }
  118. ieee = netdev_priv(dev);
  119. dev->hard_start_xmit = ieee80211_xmit;
  120. dev->change_mtu = ieee80211_change_mtu;
  121. /* Drivers are free to override this if the generic implementation
  122. * does not meet their needs. */
  123. dev->get_stats = ieee80211_generic_get_stats;
  124. ieee->dev = dev;
  125. err = ieee80211_networks_allocate(ieee);
  126. if (err) {
  127. IEEE80211_ERROR("Unable to allocate beacon storage: %d\n", err);
  128. goto failed;
  129. }
  130. ieee80211_networks_initialize(ieee);
  131. /* Default fragmentation threshold is maximum payload size */
  132. ieee->fts = DEFAULT_FTS;
  133. ieee->rts = DEFAULT_FTS;
  134. ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
  135. ieee->open_wep = 1;
  136. /* Default to enabling full open WEP with host based encrypt/decrypt */
  137. ieee->host_encrypt = 1;
  138. ieee->host_decrypt = 1;
  139. ieee->host_mc_decrypt = 1;
  140. /* Host fragementation in Open mode. Default is enabled.
  141. * Note: host fragmentation is always enabled if host encryption
  142. * is enabled. For cards can do hardware encryption, they must do
  143. * hardware fragmentation as well. So we don't need a variable
  144. * like host_enc_frag. */
  145. ieee->host_open_frag = 1;
  146. ieee->ieee802_1x = 1; /* Default to supporting 802.1x */
  147. INIT_LIST_HEAD(&ieee->crypt_deinit_list);
  148. init_timer(&ieee->crypt_deinit_timer);
  149. ieee->crypt_deinit_timer.data = (unsigned long)ieee;
  150. ieee->crypt_deinit_timer.function = ieee80211_crypt_deinit_handler;
  151. ieee->crypt_quiesced = 0;
  152. spin_lock_init(&ieee->lock);
  153. ieee->wpa_enabled = 0;
  154. ieee->drop_unencrypted = 0;
  155. ieee->privacy_invoked = 0;
  156. return dev;
  157. failed:
  158. if (dev)
  159. free_netdev(dev);
  160. return NULL;
  161. }
  162. void free_ieee80211(struct net_device *dev)
  163. {
  164. struct ieee80211_device *ieee = netdev_priv(dev);
  165. int i;
  166. ieee80211_crypt_quiescing(ieee);
  167. del_timer_sync(&ieee->crypt_deinit_timer);
  168. ieee80211_crypt_deinit_entries(ieee, 1);
  169. for (i = 0; i < WEP_KEYS; i++) {
  170. struct ieee80211_crypt_data *crypt = ieee->crypt[i];
  171. if (crypt) {
  172. if (crypt->ops) {
  173. crypt->ops->deinit(crypt->priv);
  174. module_put(crypt->ops->owner);
  175. }
  176. kfree(crypt);
  177. ieee->crypt[i] = NULL;
  178. }
  179. }
  180. ieee80211_networks_free(ieee);
  181. free_netdev(dev);
  182. }
  183. #ifdef CONFIG_IEEE80211_DEBUG
  184. static int debug = 0;
  185. u32 ieee80211_debug_level = 0;
  186. static struct proc_dir_entry *ieee80211_proc = NULL;
  187. static int show_debug_level(char *page, char **start, off_t offset,
  188. int count, int *eof, void *data)
  189. {
  190. return snprintf(page, count, "0x%08X\n", ieee80211_debug_level);
  191. }
  192. static int store_debug_level(struct file *file, const char __user * buffer,
  193. unsigned long count, void *data)
  194. {
  195. char buf[] = "0x00000000\n";
  196. unsigned long len = min((unsigned long)sizeof(buf) - 1, count);
  197. unsigned long val;
  198. if (copy_from_user(buf, buffer, len))
  199. return count;
  200. buf[len] = 0;
  201. if (sscanf(buf, "%li", &val) != 1)
  202. printk(KERN_INFO DRV_NAME
  203. ": %s is not in hex or decimal form.\n", buf);
  204. else
  205. ieee80211_debug_level = val;
  206. return strnlen(buf, len);
  207. }
  208. #endif /* CONFIG_IEEE80211_DEBUG */
  209. static int __init ieee80211_init(void)
  210. {
  211. #ifdef CONFIG_IEEE80211_DEBUG
  212. struct proc_dir_entry *e;
  213. ieee80211_debug_level = debug;
  214. ieee80211_proc = proc_mkdir(DRV_NAME, proc_net);
  215. if (ieee80211_proc == NULL) {
  216. IEEE80211_ERROR("Unable to create " DRV_NAME
  217. " proc directory\n");
  218. return -EIO;
  219. }
  220. e = create_proc_entry("debug_level", S_IFREG | S_IRUGO | S_IWUSR,
  221. ieee80211_proc);
  222. if (!e) {
  223. remove_proc_entry(DRV_NAME, proc_net);
  224. ieee80211_proc = NULL;
  225. return -EIO;
  226. }
  227. e->read_proc = show_debug_level;
  228. e->write_proc = store_debug_level;
  229. e->data = NULL;
  230. #endif /* CONFIG_IEEE80211_DEBUG */
  231. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  232. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  233. return 0;
  234. }
  235. static void __exit ieee80211_exit(void)
  236. {
  237. #ifdef CONFIG_IEEE80211_DEBUG
  238. if (ieee80211_proc) {
  239. remove_proc_entry("debug_level", ieee80211_proc);
  240. remove_proc_entry(DRV_NAME, proc_net);
  241. ieee80211_proc = NULL;
  242. }
  243. #endif /* CONFIG_IEEE80211_DEBUG */
  244. }
  245. #ifdef CONFIG_IEEE80211_DEBUG
  246. #include <linux/moduleparam.h>
  247. module_param(debug, int, 0444);
  248. MODULE_PARM_DESC(debug, "debug output mask");
  249. #endif /* CONFIG_IEEE80211_DEBUG */
  250. module_exit(ieee80211_exit);
  251. module_init(ieee80211_init);
  252. const char *escape_essid(const char *essid, u8 essid_len)
  253. {
  254. static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  255. const char *s = essid;
  256. char *d = escaped;
  257. if (ieee80211_is_empty_essid(essid, essid_len)) {
  258. memcpy(escaped, "<hidden>", sizeof("<hidden>"));
  259. return escaped;
  260. }
  261. essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
  262. while (essid_len--) {
  263. if (*s == '\0') {
  264. *d++ = '\\';
  265. *d++ = '0';
  266. s++;
  267. } else {
  268. *d++ = *s++;
  269. }
  270. }
  271. *d = '\0';
  272. return escaped;
  273. }
  274. EXPORT_SYMBOL(alloc_ieee80211);
  275. EXPORT_SYMBOL(free_ieee80211);
  276. EXPORT_SYMBOL(escape_essid);