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

📄 cardif_linux_rtnetlink.c

📁 Linux上的802.1x 的supplicant的实现。很多supplicant程序都是基于它开发的
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************* * File: cardif_linux_rtnetlink.c * * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.) * * Authors: Chris.Hessing@utah.edu * * $Id: cardif_linux_rtnetlink.c,v 1.106 2006/08/28 15:59:31 chessing Exp $ * $Date: 2006/08/28 15:59:31 $ * $Log: cardif_linux_rtnetlink.c,v $ * Revision 1.106  2006/08/28 15:59:31  chessing * Fixed a few things. * * Revision 1.105  2006/08/25 23:37:18  chessing * Numerous patches that have come in over the last month or two. * * Revision 1.104  2006/06/29 20:56:18  chessing * Cleaned up some debugging gunk left over from the operstate addition. * * Revision 1.103  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.102  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.101  2006/06/22 04:33:10  chessing * More bits added for the operstate pieces. * * Revision 1.100  2006/06/21 20:02:04  chessing * Started to implement the operstate pieces needed for DHCP. * * Revision 1.99  2006/06/20 18:17:18  chessing * Fix some endianness problems with WPA and WPA2 IE parsing. * * Revision 1.98  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.97  2006/05/29 04:17:58  chessing * Fixes for some memory leaks. * * Revision 1.96  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.95  2006/05/24 18:42:22  chessing * Small fix from Carsten Grohman, and a few little fixes/changes from me. * * Revision 1.94  2006/05/22 22:29:17  chessing * Compiler warnings patches from Eric Evans.  (And one from me. ;) * * Revision 1.93  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.92  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.91  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.90  2006/04/25 01:17:43  chessing * LOTS of code cleanups, new error checking/debugging code added, and other misc. fixes/changes. * * Revision 1.89  2006/04/08 22:54:02  chessing * Fix to SIOCGIWAP as reported by Roger Karis. * * Revision 1.88  2006/03/02 04:52:41  chessing * Added the ability to load a config based on the hints that are included in an EAP request identity message.  Should consider having a way to override listening to these messages. * * Revision 1.87  2006/02/23 22:26:53  chessing * Fix for bug id #1415020.  'Building Xsupplicant 1.2.3 Fails on FC4'. * * Revision 1.86  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.85  2006/01/23 07:13:50  chessing * A couple of fixups to the WPA and WPA2 code. * * Revision 1.84  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.83  2006/01/20 06:53:48  chessing * Added support for large scan results. * * Revision 1.82  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.81  2006/01/07 03:12:58  chessing * Small update to fix a problem where we were processing wireless events twice. * * Revision 1.80  2006/01/03 04:17:43  chessing * Added a library to check that the configuration information in the configuration structure should be enough to complete an authentication. * * Revision 1.79  2005/12/25 04:54:11  chessing * Fixup to code that added wext support needed for using ndiswrapper. * * Revision 1.78  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.77  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.76  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.75  2005/12/03 22:18:51  chessing * Added an include to fix some problems when compiling with WE19. * * Revision 1.74  2005/11/30 00:42:29  chessing * Cleaned up some warnings during the build process. * * Revision 1.73  2005/11/22 19:49:42  chessing * When the desired interface isn't available when Xsupplicant starts, Xsupplicant will wait for it to show up before starting to authenticate.  In this case, the interface isn't 'available' when an ifconfig doesn't show that the interface exists.  It has *NOTHING* to do with the up/down state of the interface.  This is mostly useful for situations where a cardbus wireless card is plugged in before linux is booted. * * Revision 1.72  2005/11/16 02:18:38  chessing * Updates to the config writing library.  The config-parser tool has been modified to be able to parse a config, and rewrite it. * * Revision 1.71  2005/11/14 16:41:05  chessing * Fix to cardif_linux_rtnetlink code to work when *REALLY* old versions of WE are used that don't define IW_CUSTOM_MAX. * * Revision 1.70  2005/11/12 23:01:12  chessing * Fix for problems with compiling when older versions of iwlib are used.  Added the missing Makefile.in to the lib directory so that we don't have to run automake before compiling. * * Revision 1.69  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.68  2005/10/17 00:15:55  chessing * Moved the config parsing routines out to a new library called libxsupconfig.a, so that it will be easier to create third-party tools that can easily parse a config. * * Revision 1.67  2005/10/16 04:31:30  chessing * Changed gui_interface.c/h to be a library called libxsupgui, and moved it to a new lib directory. * * Revision 1.66  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.65  2005/10/13 18:57:28  chessing * Removed some leftover debug strings.  Cleaned up some compiler warnings. Fixed an association bug in the madwifi driver. * * Revision 1.64  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.63  2005/09/26 02:04:07  shaftoe * Yet another round of log output cleanup. * * -- Eric Evans <eevans@sym-link.com> * * Revision 1.62  2005/09/23 02:31:33  shaftoe * Log output cleanup for the benefit of syslog. * * -- Eric Evans <eevans@sym-link.com> * * Revision 1.61  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.60  2005/09/14 03:34:54  chessing * Small cosmetic changes.  Default association mode is now auto instead of manual. Fixes for bug IDs #1290449 & #1290323. * * Revision 1.59  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.58  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.57  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.56  2005/08/25 03:34:05  chessing * Removed a bunch of functions from config.c that could be handled better in other ways. * * Revision 1.55  2005/08/25 02:20:20  chessing * Some cleanup in xsup_debug.c, added the ability to wait for an interface to come up if it is down when Xsupplicant is started.  Roughed in the ability to choose between having Xsupplicant auto associate you, or allow you to set the ssid manually.  The stale key timer can now be set in the config file.  The association timeout can be set in the config file, and will also be used once the functionality is in place to attempt to guess the key settings needed for association, as well as the functionality to auto associate. * * Revision 1.54  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.53  2005/08/18 03:19:04  chessing * Added the ability to define an SSID with static WEP keys.  When we switch to a network that has this type of configuration we will set the keys, and stop the various association timers. * * Revision 1.52  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 <unistd.h>#include <sys/socket.h>#include <linux/compiler.h>#include <iwlib.h>#include <sys/ioctl.h>#include "netlink.h"#include "rtnetlink.h"#include <linux/if.h>#include <linux/if_packet.h>#include <math.h>#include "wireless_copy.h"#include "profile.h"#include "xsupconfig.h"#include "xsup_common.h"#include "xsup_debug.h"#include "xsup_err.h"#include "wireless_sm.h"#include "cardif_linux.h"#include "statemachine.h"#include "../cardif.h"#include "wpa.h"#include "wpa2.h"#include "eap.h"#include "eap_types/mschapv2/mschapv2.h"#include "config_ssid.h"#include "eapol_key_type254.h"#include "timer.h"#include "mic.h"#include "cardif_linux_rtnetlink.h"#include "event_core.h"#include "cardif_linux_wext.h"#ifdef USE_EFENCE#include <efence.h>#endif// Define this, so the compiler doesn't complain.extern char *if_indextoname(unsigned int, char *);#define INT_DEL    0#define INT_NEW    1static int rtnl_sock=-1;static struct sockaddr_nl rtnl_data;#ifndef IWEVCUSTOM#warning IWEVCUSTOM is not defined!  We will define it, and try to continue!#define IWEVCUSTOM   0x8C02#endif#ifndef IW_CUSTOM_MAX#warning IW_CUSTOM_MAX is not defined!  You should upgrade to a more current version of wireless extensions.  We will attempt to define it ourselves, but the results may not be good.#define IW_CUSTOM_MAX  256  // In bytes, matches current WE versions. (11/14/05)#endif// Forward def to avoid compiler warnings.void cardif_linux_rtnetlink_process_token(struct interface_data *ctx,					  struct iw_event *iwe,					  struct wireless_state *state);/******************************************************** * * Do whatever is needed to establish a netlink socket so that we can * catch events, and take action. * ********************************************************/void cardif_linux_rtnetlink_init(struct interface_data *ctx){  rtnl_sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);    if (rtnl_sock < 0)    {      debug_printf(DEBUG_NORMAL, "Couldn't establish an rtnetlink socket!  Some functionality won't be available!\n");      return;    }  bzero((char *)&rtnl_data, sizeof(rtnl_data));  rtnl_data.nl_family = AF_NETLINK;  rtnl_data.nl_groups = RTMGRP_LINK;  if (bind(rtnl_sock, (struct sockaddr *)&rtnl_data, sizeof(rtnl_data)) < 0)    {      debug_printf(DEBUG_NORMAL, "Couldn't bind netlink socket!  Some functionality won't be available!\n");      close(rtnl_sock);      return;    }  event_core_register(rtnl_sock, cardif_linux_rtnetlink_check_event, 		      HIGH_PRIORITY, "rtnetlink handler");  cardif_linux_rtnetlink_set_linkmode(ctx, IF_LINK_MODE_DORMANT);}/******************************************************** * * Do whatever is needed to shutdown the netlink socket that we set up. * ********************************************************/void cardif_linux_rtnetlink_cleanup(struct interface_data *ctx){  debug_printf(DEBUG_INT, "Called cardif_linux_rtnetlink_cleanup()!\n");  cardif_linux_rtnetlink_set_operstate(ctx, IF_OPER_UP);  cardif_linux_rtnetlink_set_linkmode(ctx, IF_LINK_MODE_DEFAULT);  // Close the rtnetlink socket.  close(rtnl_sock);}/********************************************************************* * * Get the wireless extensions version that this driver was built with. * *********************************************************************/int cardif_linux_rtnetlink_get_we_ver(struct interface_data *intdata){  struct iwreq iwr;  struct iw_range *range;  char buffer[sizeof(iwrange)*2];  int sock;  if (!xsup_assert((intdata != NULL), "intdata != NULL", FALSE))    return XEMALLOC;  bzero(buffer, (sizeof(iwrange)*2));  iwr.u.data.pointer = (caddr_t) buffer;  iwr.u.data.length = sizeof(buffer);  iwr.u.data.flags = 0;  sock = cardif_get_socket(intdata);  if (iw_get_ext(sock, intdata->intName, SIOCGIWRANGE, &iwr) < 0)    {      debug_printf(DEBUG_NORMAL, "Error with ioctl SIOCGIWRANGE (Error: %s)\n",		   strerror(errno));      return -1;    }  range = (struct iw_range *)buffer;  return range->we_version_compiled;}/******************************************************** * * Gather the data that was returned from a scan. * ********************************************************/void cardif_linux_rtnetlink_reap(struct interface_data *intdata, 				 char *data, int len){  struct stream_descr stream;  struct iw_event iwe;  int retval;  if (!xsup_assert((intdata != NULL), "intdata != NULL", FALSE))    return;  if (!xsup_assert((data != NULL), "data != NULL", FALSE))    return;  xsup_assert((len >= 0), "len >= 0", TRUE);  xsup_assert((len < 65001), "len < 65001", TRUE);  iw_init_event_stream(&stream, data, len);  do    {#ifdef NEW_IWLIB      retval = iw_extract_event_stream(&stream, &iwe, 				       cardif_linux_rtnetlink_get_we_ver(intdata));#else      retval = iw_extract_event_stream(&stream, &iwe);#endif      if (retval == 1)  // Then we got something	{	  cardif_linux_rtnetlink_process_token(intdata, &iwe, NULL);	} else {	  switch (retval)	    {	    case 0:	      // No error.	      break;	    case -1:debug_printf(DEBUG_NORMAL, "Invalid event!\n");	      break;	    case 2:debug_printf(DEBUG_NORMAL, "Unknown event found. Skipping."				"(Event %04X) (Not supported in wireless "				"extensions %d?)\n", iwe.cmd, WIRELESS_EXT);	      break;	    case -2:debug_printf(DEBUG_NORMAL, "Invalid event data. Skipping."				 "\n");	      break;	    default:debug_printf(DEBUG_NORMAL, "Unknown result code from "				 "iw_extract_event_stream(). (Result was %d)"				 "\n", retval);	      break;	    }	}    }  while (retval > 0);}/******************************************************* * * Check to see if we have data in the returned scan buffer, even if  * we didn't get a scan complete event.  (Some cards may not send the * scan complete event.) * *******************************************************/uint8_t cardif_linux_rtnetlink_check_nets(struct interface_data *idata){  struct lin_sock_data *sockData;  struct iwreq iwr;  char *buffer = NULL;  uint16_t buf_size = 8192;  if (!xsup_assert((idata != NULL), "idata != NULL", FALSE))    return XEMALLOC;  if (!TEST_FLAG(idata->flags, SCANNING))     {      return XENONE;    }  debug_printf(DEBUG_INT, "Checking for returned SSID information....\n");  sockData = idata->sockData;  if (!xsup_assert((sockData != NULL), "sockData != NULL", FALSE))    return XEMALLOC;  if (!xsup_assert((buf_size != 0), "buf_size != 0", FALSE))    return XEMALLOC;

⌨️ 快捷键说明

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