⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cardif_linux_wext.c

📁 Linux上的802.1x 的supplicant的实现。很多supplicant程序都是基于它开发的
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************* * Linux wireless extensions interface. * * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.) * * File: cardif_linux_wext.c * * Authors: Chris.Hessing@utah.edu * * $Id: cardif_linux_wext.c,v 1.86 2006/08/28 04:31:54 chessing Exp $ * $Date: 2006/08/28 04:31:54 $ * $Log: cardif_linux_wext.c,v $ * Revision 1.86  2006/08/28 04:31:54  chessing * A couple of fixes. * * Revision 1.85  2006/08/25 23:37:18  chessing * Numerous patches that have come in over the last month or two. * * Revision 1.84  2006/06/23 00:45:19  chessing * Completed basic implementation of operstate support.  Probably need to consider extending it to be used to populate the up/down state of the interface in the statemachine. * * Revision 1.83  2006/06/22 23:24:21  chessing * Added more operstate support.  It now works with the dhcpclient from http://www.flamewarmaster.de/software/dhcpclient/ * * Revision 1.82  2006/06/20 18:17:18  chessing * Fix some endianness problems with WPA and WPA2 IE parsing. * * Revision 1.81  2006/06/02 21:56:49  chessing * One last small fix. * * Revision 1.80  2006/06/01 22:49:49  galimorerpg * Converted all instances of u_char to uint8_t * Fixed a bad #include in the generic frame handler. * * Revision 1.79  2006/05/30 16:56:31  chessing * More patches from Carsten Grohmann and a #if that was missing from the 1.2.5 release. * * Revision 1.78  2006/05/29 04:17:58  chessing * Fixes for some memory leaks. * * Revision 1.77  2006/05/29 02:21:41  chessing * Madwifi now works with WPA/WPA2 and the wext driver. * * Revision 1.76  2006/05/28 22:32:23  chessing * More fixes to make madwifi behave itself. * * Revision 1.75  2006/05/28 21:24:04  chessing * Small fix to madwifi driver for some other changes that were made in the code. * * Revision 1.74  2006/05/27 23:12:31  chessing * More bug fixes that surround the madwifi driver. * * Revision 1.73  2006/05/26 23:21:12  chessing * Fixed some memory leaks. * * Revision 1.72  2006/05/26 22:04:58  chessing * Fixed some memory access errors, and cleaned up some wext stuff that was causing issues with the madwifi driver in wext mode. * * Revision 1.71  2006/05/24 04:36:30  chessing * More work on the GUI interface.  (We can now save.)  Fixed xsupconfwrite so that it doesn't write the firmware roaming option twice. * * Revision 1.70  2006/05/23 23:38:39  chessing * Patch to allow the madwifi driver to associate and authenticate using the regular wireless extensions.  Should this start working, we are dumpping the madwifi specific driver crap! ;) * * Revision 1.69  2006/05/23 23:07:01  chessing * Cleaned up the previous patch for timer_tick.  (There was a cleaner way of doing it.)  Fixed up some stuff that was causing issues getting associated/dynamic WEP authenticated with the madwifi driver.  Madwifi seems to be happily working (with dynamic WEP) now. * * Revision 1.68  2006/05/22 22:29:17  chessing * Compiler warnings patches from Eric Evans.  (And one from me. ;) * * Revision 1.67  2006/05/22 04:02:09  chessing * Some small changes/fixes. * * Revision 1.66  2006/05/17 22:18:10  chessing * A couple of small changes to Xsupplicant, and some major changes to the GUI configuration/monitor tool. * * Revision 1.65  2006/05/17 04:14:07  chessing * Fixed a scanning problem with older versions of wireless extensions. * * Revision 1.64  2006/05/17 03:56:09  chessing * Updates to WPA2. * * Revision 1.63  2006/05/17 02:40:07  chessing * Finished several things on the todo list.  Removed external event core stuff, added gui pings, clear keys and WPA IE when an SSID is set from outside Xsupplicant, etc. * * Revision 1.62  2006/05/14 22:09:28  chessing * A few small changes in the Xsupplicant code.  Beginning of a configuration/monitor program can be found in gui_tools. (Very simple for now, with several known bugs, but no showstopper bugs know.) * * Revision 1.61  2006/05/13 05:56:44  chessing * Removed last pieces of code that relied on SIGALRM.  Active scan timeout is now configurable so that people that wish to hammer on their cards now have the option to do that. ;) * * Revision 1.60  2006/05/13 03:44:46  chessing * Huge patch as a result of the downtime with SourceForge.  Fixed issues with WPA/WPA2.  Fixed a segfault when a scan returned a NULL.  Changed event handleing to use select() instead of older sleep/non-blocking socket resulting in a faster authentication.  Fixed a stack smashing bug that would cause random failures with WPA/WPA2.  Added status messages so that when we run in non-debug mode we have some idea of what is going on.  Various other code cleanups, bug fixes. * * Revision 1.59  2006/04/25 01:17:43  chessing * LOTS of code cleanups, new error checking/debugging code added, and other misc. fixes/changes. * * Revision 1.58  2006/02/23 22:26:53  chessing * Fix for bug id #1415020.  'Building Xsupplicant 1.2.3 Fails on FC4'. * * Revision 1.57  2006/01/24 04:42:26  chessing * A few more fixes to WPA code, along with a fix to the scan reaping code. * * Revision 1.56  2006/01/23 05:28:37  chessing * Fixed a few settings that were causing errors with IOCTLs on some cards.  Updated WPA2 code to properly process group key packets. We now record quality, signal level, and noise level from scan results, so that we can start to make better decisions on which AP to associate to. * * Revision 1.55  2006/01/19 05:37:04  chessing * WPA2 is working correctly.  Added the ability to query the card to gather encryption/authentication capabilities.  1.2.3 is now ready to go. * * Revision 1.54  2006/01/14 06:22:10  chessing * Fixed WPA functionality for cards that don't use IWAUTH to set up the WPA IE. * * Revision 1.53  2006/01/12 17:54:03  chessing * WPA almost works again on cards that use the GENIE setting.  Added a small fix to allow Xsupplicant to build on Open SuSE 10. * * Revision 1.52  2005/12/25 04:54:11  chessing * Fixup to code that added wext support needed for using ndiswrapper. * * Revision 1.51  2005/12/24 04:51:51  chessing * Removed an unneeded file.  Updated scanning code to parse IWEVGENIE events correctly, and make use of them. * * Revision 1.50  2005/12/24 02:39:48  chessing * Fixes to autoconf script to correctly identify the number of arguments that iw_extract_event_stream() takes, along with checking iwlib.h compiles correctly. * * Revision 1.49  2005/12/18 07:44:12  chessing * Added the ability to associate using IWAUTH options instead of setting a full IE.  This allows NDISwrapper to work with vanilla wireless extensions.  For some reason, we can't parse IWEVASSOCREQIE/IWEVASSOCRESPIE since we see the length as 0, even though iwevent sees the correct IE information. :-/  Need to figure out why. * * Revision 1.48  2005/12/03 22:18:51  chessing * Added an include to fix some problems when compiling with WE19. * * Revision 1.47  2005/11/14 17:27:39  chessing * Removed the driver specific code for hostap, ipw, and ndiswrapper, since they all support WE18 now. * * Revision 1.46  2005/11/10 04:56:54  chessing * Added patch from Ben Gardner to add support for setting a specific WEP key prior to attempting to associte.  (With a few slight modifications by me to make it fit in the current CVS code, and get it supported in config-parse.)  Added patch from Pekka Savola to fix some header ordering issues, and a potential buffer overflow. * * Revision 1.45  2005/10/17 03:56:54  chessing * Updates to the libxsupconfig library.  It no longer relies on other source from the main tree, so it can be used safely in other code with problems. * * Revision 1.44  2005/10/14 02:26:18  shaftoe * - cleanup gcc 4 warnings * - (re)add support for a pid in the form of /var/run/xsupplicant.<iface>.pid * * -- Eric Evans <eevans@sym-link.com> * * Revision 1.43  2005/10/13 18:46:47  chessing * Fixed to the Madwifi driver to allow it to do dynamic WEP again.  Fixed up the wext driver to behave correctly again. ;) * * Revision 1.42  2005/09/19 21:45:46  chessing * Fix for the madwifi driver when it connects to certain APs to do WEP.  (Currently the only known one with this problem is the Trapeze APs when they are running MSS 4.x+.) * * Revision 1.41  2005/09/17 18:38:17  chessing * Some updates to make the madwifi driver work with dynamic WEP again. * * Revision 1.40  2005/09/14 02:50:44  chessing * Major updates.  Auto association now works.  Started to rewrite the rtnetlink pieces using iwlib from the wireless tools to avoid compatibility issues.  As a result, getting the WPA and RSN IEs via the IWEVGENIE event no longer works for some reason, but the old style using IWEVCUSTOM events should still work like a champ. * * Revision 1.39  2005/09/08 16:27:02  chessing * Some small updates to the new state machine code.  First attempt at an auto association mode.  (It mostly works. ;) * * Revision 1.38  2005/09/05 01:00:37  chessing * Major overhaul to most of the state machines in Xsupplicant.  Also added additional error messages to the TLS functions to try to debug the one of the problems reported on the list.  Basic testing shows this new code to be more stable than previous code, but it needs more testing. * * Revision 1.37  2005/08/20 19:06:54  chessing * Patch from Carsten Grohmann to fix a few things in xsup_get_state.c.  Also added the ability to define an empty network clause, that will set the card in to encryption disabled mode.  From there, anything short of changing the SSID will be ignored by Xsupplicant. * * Revision 1.36  2005/08/09 01:39:15  chessing * Cleaned out old commit notes from the released version.  Added a few small features including the ability to disable the friendly warnings that are spit out.  (Such as the warning that is displayed when keys aren't rotated after 10 minutes.)  We should also be able to start when the interface is down.  Last, but not least, we can handle empty network configs.  (This may be useful for situations where there isn't a good reason to have a default network defined.) * * *******************************************************************/#ifdef LINUX_FRAMER// Use kernel headers.#define HEADERS_KERNEL#include <string.h>#include <strings.h>#include <errno.h>#include <stdlib.h>#include <sys/ioctl.h>#include <unistd.h>#include <netinet/in.h>#include <linux/types.h>#include <linux/socket.h>#include <linux/compiler.h>#include "wireless_copy.h"#include <iwlib.h>#include <linux/if_packet.h>#include <linux/netlink.h>#include "profile.h"#include "xsupconfig.h"#include "config_ssid.h"#include "xsup_common.h"#include "xsup_debug.h"#include "xsup_err.h"#include "wpa.h"#include "wpa2.h"#include "wpa_common.h"#include "cardif/cardif.h"#include "cardif/linux/cardif_linux.h"#include "cardif/linux/cardif_linux_wext.h"#include "wireless_sm.h"#include "cardif/linux/cardif_linux_rtnetlink.h"#include "timer.h"#include "wpa.h"#include "wpa2.h"#ifdef USE_EFENCE#include <efence.h>#endif// Old versions of wireless.h may not have this defined.#ifndef IW_ENCODE_TEMP#define IW_ENCODE_TEMP            0x0400#endif/************************************************************** * * Cancel our scan timer, if we get here before something else cancels * it for us. ;) * **************************************************************/void cardif_linux_wext_cancel_scantimer(struct interface_data *ctx){  timer_cancel(SCANCHECK_TIMER);}/************************************************************** * * Tell the wireless card to start scanning for wireless networks. * **************************************************************/int cardif_linux_wext_scan(struct interface_data *thisint, char passive){  struct lin_sock_data *sockData;  struct iwreq iwr;  //  char all4s[6]={0x44, 0x44, 0x44, 0x44, 0x44, 0x44};#if WIRELESS_EXT > 17  struct iw_scan_req iwsr;#endif  struct config_globals *globals;  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEGENERROR;  if (!TEST_FLAG(thisint->flags, IS_WIRELESS))    {      debug_printf(DEBUG_INT, "%s is not a wireless interface!\n", 		   thisint->intName);      return XENOWIRELESS;    }  memset(&iwr, 0x00, sizeof(iwr));  sockData = thisint->sockData;  xsup_assert((sockData != NULL), "sockData != NULL", TRUE);  if (sockData->sockInt <= 0)    return XENOSOCK;  cardif_linux_wext_wpa_state(thisint, 1);  debug_printf(DEBUG_INT, "Issuing %s scan request for interface %s!\n",	       passive ? "passive":"active", thisint->intName);#if WIRELESS_EXT > 17    // Build our extended scan structure.  memset(&iwsr, 0x00, sizeof(iwsr));  if (passive)    {      iwsr.scan_type = IW_SCAN_TYPE_PASSIVE;      //      iwsr.scan_type = IW_SCAN_TYPE_ACTIVE;      // If we are doing a passive scan, then we only care about other APs      // that are on this SSID.  Otherwise, we might end up picking an SSID      // later that isn't in the same layer2/3 space.      //      iwr.u.data.flags = IW_SCAN_THIS_ESSID | IW_SCAN_ALL_FREQ |       //	IW_SCAN_THIS_MODE | IW_SCAN_ALL_RATE;      //      iwr.u.data.flags = IW_SCAN_DEFAULT;      iwr.u.data.flags = IW_SCAN_THIS_ESSID;    }  else    {      // Some cards won't do a full scan if they are associated.      //      cardif_linux_wext_set_bssid(thisint, all4s);      iwsr.scan_type = IW_SCAN_TYPE_ACTIVE;      iwr.u.data.flags = IW_SCAN_DEFAULT;    }  // We aren't looking for a specific BSSID.  memset(iwsr.bssid.sa_data, 0xff, 6);  iwr.u.data.length = sizeof(iwsr);  iwr.u.data.pointer = (caddr_t) &iwsr;#else  iwr.u.data.length = 0;  iwr.u.data.pointer = NULL;  iwr.u.data.flags = IW_SCAN_DEFAULT;#endif    strcpy((char *)&iwr.ifr_name, thisint->intName);  if (ioctl(sockData->sockInt, SIOCSIWSCAN, &iwr) < 0)    {      debug_printf(DEBUG_NORMAL, "Error with SCAN ioctl!  (Perhaps your card "		   "doesn't support scanning, or isn't up?)\n");      return -1;    }  SET_FLAG(thisint->flags, SCANNING);  globals = config_get_globals();    if (!globals)    {      debug_printf(DEBUG_NORMAL, "Couldn't get a handle to the scan timeout "		   "variable!  (Perhaps the configuration isn't "		   "initalized?)\n");      debug_printf(DEBUG_NORMAL, "Scanning will commence, but will only be "		   "successful on cards that send scan complete events.\n");      return XENONE;    }  timer_add_timer(SCANCHECK_TIMER, globals->assoc_timeout, 		  cardif_linux_rtnetlink_scancheck, 		  cardif_linux_wext_cancel_scantimer);  return XENONE;}/************************************************************* * * Set all of the keys to 0s. * *************************************************************/void cardif_linux_wext_set_zero_keys(struct interface_data *thisint){  char zerokey[13];  char keylen = 13;  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return;  debug_printf(DEBUG_INT, "Setting keys to zeros!\n");  memset(zerokey, 0x00, 13);  // We set the key index to 0x80, to force key 0 to be set to all 0s,  // and to have key 0 be set as the default transmit key.  cardif_set_wep_key(thisint, (uint8_t *)&zerokey, keylen, 0x80);  cardif_set_wep_key(thisint, (uint8_t *)&zerokey, keylen, 0x01);  cardif_set_wep_key(thisint, (uint8_t *)&zerokey, keylen, 0x02);  cardif_set_wep_key(thisint, (uint8_t *)&zerokey, keylen, 0x03);}/************************************************************** * * If we have detected, or forced this interface to reset keys, then * we need to reset them.  Otherwise, we will just ignore the fact that * we changed APs, and return. * **************************************************************/void cardif_linux_wext_zero_keys(struct interface_data *thisint){  struct config_network *network_data;  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return;  network_data = config_get_network_config();  if (!xsup_assert((network_data != NULL), "network_data != NULL", FALSE))    return;  if (network_data->wireless_ctrl == CTL_NO)     {      debug_printf(DEBUG_INT, "Config file has instructed us not to reset the "		   "key!  Roaming may not work!!!\n");      return;    }  if (TEST_FLAG(thisint->flags, ROAMED))    {      return;    }  SET_FLAG(thisint->flags, ROAMED);  cardif_linux_wext_set_zero_keys(thisint);  cardif_linux_wext_enc_open(thisint);}/************************************************************** * * Disable encryption on the wireless card.  This is used in cases * where we roam to a different AP and the card needs to have WEP * disabled. * **************************************************************/int cardif_linux_wext_enc_disable(struct interface_data *thisint){  int rc = 0;  struct iwreq wrq;  struct config_network *network_data;  struct lin_sock_data *sockData;  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  network_data = config_get_network_config();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -