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

📄 cardif_linux.c

📁 Linux上的802.1x 的supplicant的实现。很多supplicant程序都是基于它开发的
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************* * Linux card interface implementation. * * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.) * * File: cardif_linux.c * * Authors: Chris.Hessing@utah.edu * * $Id: cardif_linux.c,v 1.142 2006/08/28 04:31:54 chessing Exp $ * $Date: 2006/08/28 04:31:54 $ * $Log: cardif_linux.c,v $ * Revision 1.142  2006/08/28 04:31:54  chessing * A couple of fixes. * * Revision 1.141  2006/08/25 23:37:18  chessing * Numerous patches that have come in over the last month or two. * * Revision 1.140  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.139  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.138  2006/06/22 04:33:10  chessing * More bits added for the operstate pieces. * * Revision 1.137  2006/06/20 18:17:18  chessing * Fix some endianness problems with WPA and WPA2 IE parsing. * * Revision 1.136  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.135  2006/05/29 20:31:00  chessing * Removed madwifi specific driver code.  (Wext works with the madwifi driver now.) * * Revision 1.134  2006/05/28 22:32:21  chessing * More fixes to make madwifi behave itself. * * Revision 1.133  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.132  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.131  2006/05/23 00:53:08  chessing * Code cleanup. * * Revision 1.130  2006/05/22 22:29:17  chessing * Compiler warnings patches from Eric Evans.  (And one from me. ;) * * Revision 1.129  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.128  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.127  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.126  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.125  2006/04/25 01:17:43  chessing * LOTS of code cleanups, new error checking/debugging code added, and other misc. fixes/changes. * * Revision 1.124  2006/04/16 21:20:42  chessing * Added initial TNC support via patch from Mike McCauley.  Requires libtnc in order to work, which isn't yet available to the public. * * Revision 1.123  2006/03/21 18:22:10  chessing * Fixes to EAP-AKA code.  Changed a few defaults to disable Xsupplicant based roaming, and passive scanning for this release.  (It would currently cause more problems than it would solve. * * Revision 1.122  2006/02/23 22:26:53  chessing * Fix for bug id #1415020.  'Building Xsupplicant 1.2.3 Fails on FC4'. * * Revision 1.121  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.120  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.119  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.118  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.117  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.116  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.115  2005/12/03 22:18:51  chessing * Added an include to fix some problems when compiling with WE19. * * Revision 1.114  2005/11/30 00:42:29  chessing * Cleaned up some warnings during the build process. * * Revision 1.113  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.112  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.111  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.110  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.109  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.108  2005/09/25 15:03:36  shaftoe * Document syslog functionality in example config file. * * -- Eric Evans <eevans@sym-link.com> * * Revision 1.107  2005/09/25 00:39:48  shaftoe * - More work to pretty up syslog output. * * -- Eric Evans <eevans@sym-link.com> * * Revision 1.106  2005/09/19 21:48:05  chessing * Added a line that will indicate that the interface is scanning when running in normal (non-debug) mode. * * Revision 1.105  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.104  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.103  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.102  2005/09/08 16:27:01  chessing * Some small updates to the new state machine code.  First attempt at an auto association mode.  (It mostly works. ;) * * Revision 1.101  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.100  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.99  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.98  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.97  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// We want to use kernel headers to build.#define HEADERS_KERNEL#include <fcntl.h>#include <string.h>#include <stdlib.h>#include <sys/ioctl.h>#include <netinet/in.h>#include <linux/types.h>#include <linux/socket.h>#include <linux/compiler.h>#include <iwlib.h>#include <linux/if_packet.h>#include <stdio.h>#include <errno.h>#include <unistd.h>#include <linux/rtnetlink.h>#include "wireless_copy.h"#include "xsupconfig.h"#include "profile.h"#include "config_ssid.h"#include "cardif/linux/cardif_linux_wext.h"#include "cardif/cardif.h"#include "xsup_common.h"#include "xsup_debug.h"#include "xsup_err.h"#include "snmp.h"#include "statemachine.h"#include "wireless_sm.h"#include "cardif/linux/cardif_linux.h"#include "cardif/linux/cardif_atmel_driver.h"#include "cardif/linux/cardif_linux_rtnetlink.h"#include "timer.h"#ifdef USE_EFENCE#include <efence.h>#endif#ifndef ETH_P_EAPOL#define ETH_P_EAPOL 0x888e#endif// Define this, so the compiler doesn't complain.extern unsigned int if_nametoindex(const char *);// This contains a pointer to the functions needed for wireless.  struct cardif_funcs *wireless;// Store values about what state our interface was in before we start messing// with it.struct int_starting_data *startup;/******************************************************************** * * Clear all keys, and accept unencrypted traffic again. * ********************************************************************/void cardif_linux_clear_keys(struct interface_data *ctx){  int i;  if (!xsup_assert((ctx != NULL), "ctx != NULL", FALSE))    return;  debug_printf(DEBUG_INT, "Clearing keys!\n");    // Clear the PTK.  cardif_delete_key(ctx, 0, 1);  for (i=0;i<4;i++)    {      cardif_delete_key(ctx, i, 0);    }  // Accept unencrypted frames again.  cardif_drop_unencrypted(ctx, 0);}/*********************************************** * * Determine if we are currently associated.  * ***********************************************/int cardif_check_associated(struct interface_data *intdata){  char newmac[6], curbssid[6];  if (!xsup_assert((intdata != NULL), "intdata != NULL", FALSE))    return XEMALLOC;  // If we are wired, this function doesn't do anything useful.  if (!TEST_FLAG(intdata->flags, IS_WIRELESS)) return XENONE;  cardif_GetBSSID(intdata, curbssid);  memset(newmac, 0x00, 6);  if (memcmp(newmac, curbssid, 6) == 0)    {      return IS_UNASSOCIATED;    }  memset(newmac, 0x44, 6);  if (memcmp(newmac, curbssid, 6) == 0)    {      return IS_UNASSOCIATED;    }  memset(newmac, 0xFF, 6);  if (memcmp(newmac, curbssid, 6) == 0)    {      return IS_UNASSOCIATED;    }  //Otherwise, we are associated.  return IS_ASSOCIATED;}/*********************************************** * * Set up the wireless cardif_funcs structure to the driver that the user * has requested. * ***********************************************/void cardif_set_driver(char driver){  switch (driver)    {    case DRIVER_NONE:      wireless = NULL;      break;    case DRIVER_WEXT:      wireless = &cardif_linux_wext_driver;      break;    case DRIVER_ATMEL:      wireless = &cardif_atmel_driver;      break;    }}/*********************************************** * * Do whatever is needed to get the interface in to a state that we can send * and recieve frames on the network.  Any information that we need to later * use should be stored in the interface_data structure. * ***********************************************/int cardif_init(struct interface_data *thisint, char driver){  struct ifreq ifr;  struct lin_sock_data *sockData;  int retval;  struct config_globals *globals;  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  // Get the information about the global settings from the config file.  globals = config_get_globals();  if (!xsup_assert((globals != NULL), "globals != NULL", FALSE))    return XEGENERROR;  debug_printf(DEBUG_INT, "Initializing socket for interface %s..\n",	       thisint->intName);  // Keep track of which driver we were assigned.  thisint->driver_in_use = driver;  // Find out what the interface index is.  thisint->intIndex = if_nametoindex(thisint->intName);  if (thisint->intIndex < 0)    {      debug_printf(DEBUG_NORMAL, "Invalid value for interface index! (%d)\n",		   thisint->intIndex);      return XENOSOCK;    }  // Allocate memory for the things we need.  thisint->sockData = (void *)malloc(sizeof(struct lin_sock_data));  if (thisint->sockData == NULL)    {      debug_printf(DEBUG_NORMAL, "Error allocating memory!\n");      return XEMALLOC;    }  sockData = thisint->sockData;  // Establish a socket handle.  sockData->sockInt = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_EAPOL));  if (sockData->sockInt < 0)    {      debug_printf(DEBUG_NORMAL, 		   "Couldn't initialize raw socket for interface %s!\n",		   thisint->intName);      return XENOSOCK;    }          // Build our link layer socket struct, so we can bind it to a specific  // interface.  sockData->sll.sll_family = PF_PACKET;  sockData->sll.sll_ifindex = thisint->intIndex;  sockData->sll.sll_protocol = htons(ETH_P_EAPOL);  // Bind to the interface.  retval = bind(sockData->sockInt, (const struct sockaddr *)&sockData->sll, 		sizeof(struct sockaddr_ll));  if (retval < 0)    {      debug_printf(DEBUG_NORMAL, "Error binding raw socket to interface %s!\n",		   thisint->intName);      return XESOCKOP;    }  memset(&ifr, 0x00, sizeof(ifr));  ifr.ifr_ifindex = thisint->intIndex;  // Tell the ifreq struct which interface we want to use.  Strncpy((char *)&ifr.ifr_name, thisint->intName, sizeof(ifr.ifr_name));  // Get our MAC address.  (Needed for sending frames out correctly.)  retval = ioctl(sockData->sockInt, SIOCGIFHWADDR, &ifr);  if (retval < 0)    {      debug_printf(DEBUG_NORMAL, "Error getting hardware (MAC) address for interface %s!\n",		   thisint->intName);      return XENOTINT;    }  // Store a copy of our source MAC for later use.  memcpy((char *)&thisint->source_mac[0], (char *)&ifr.ifr_hwaddr.sa_data[0], 6);

⌨️ 快捷键说明

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