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

📄 cardif_linux.c

📁 Linux上的802.1x 的supplicant的实现。很多supplicant程序都是基于它开发的
💻 C
📖 第 1 页 / 共 4 页
字号:
  // Check if we want ALLMULTI mode, and enable it.  if (TEST_FLAG(globals->flags, CONFIG_GLOBALS_ALLMULTI))    {      // Tell the ifreq struct which interface we want to use.      strncpy((char *)&ifr.ifr_name, thisint->intName, sizeof(ifr.ifr_name));      if (ioctl(sockData->sockInt, SIOCGIFFLAGS, &ifr) < 0)	{	  debug_printf(DEBUG_NORMAL, "Couldn't determine if ALLMULTI is enabled!\n");	} else {	  if (ifr.ifr_flags & IFF_ALLMULTI)	    {	      debug_printf(DEBUG_INT, "Allmulti mode is already enabled on this device!\n");	      thisint->flags |= ALLMULTI;	    } else {	      debug_printf(DEBUG_INT, "Allmulti is currently disabled on this device!\n");	      thisint->flags &= ~ALLMULTI;	    }	}      ifr.ifr_flags |= IFF_ALLMULTI;      if (ioctl(sockData->sockInt, SIOCSIFFLAGS, &ifr) < 0)	{	  debug_printf(DEBUG_NORMAL, "Couldn't set ALLMULTI mode on this interface!  We will continue anyway!\n");	}    }  // Set up wireless card drivers.  cardif_set_driver(driver);  if (cardif_int_is_wireless(thisint->intName) == TRUE)    {      // If we have our destination set to AUTO, then preset our destination      // address.      if (globals->destination == DEST_AUTO)	{	  cardif_GetBSSID(thisint, thisint->dest_mac);	}    }  // Initialize our event handler.  cardif_linux_rtnetlink_init(thisint);	    return XENONE;}/************************************************************** * * Tell the wireless card to start scanning for wireless networks. * **************************************************************/int cardif_do_wireless_scan(struct interface_data *thisint, char passive){  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  if (wireless == NULL)     {      debug_printf(DEBUG_INT, "No valid wireless calls struct! (%s:%d)\n",		   __FUNCTION__, __LINE__);      return -1;    }  // If we are already scanning, then we shouldn't get here, but go ahead   // and ignore it anyway.  if (TEST_FLAG(thisint->flags, SCANNING) )    {      debug_printf(DEBUG_INT, "Got a request to start a new scan when one is"		   " already in progress!  Ignoring!\n");      return XENONE;    }  SET_FLAG(thisint->flags, SCANNING);  config_ssid_clear();  return wireless->scan(thisint, passive);}/************************************************************** * * Send a disassociate message. * **************************************************************/int cardif_disassociate(struct interface_data *thisint, int reason_code){  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  if (wireless == NULL) return -1;  debug_printf(DEBUG_INT, "Called %s\n", __FUNCTION__);  return wireless->disassociate(thisint, reason_code);}/************************************************************** * * Check to see if the BSSID value is valid.  If it is, return TRUE. If * it isn't return FALSE. * **************************************************************/int cardif_valid_dest(struct interface_data *thisint){  char baddest[6];  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  if ((thisint->flags & IS_WIRELESS))    {      memset((char *)&baddest, 0x00, 6);      if (memcmp(thisint->dest_mac, baddest, 6) == 0)	{	  debug_printf(DEBUG_INT, "All 0s for dest mac!\n");	  return FALSE;	}      memset((char *)&baddest, 0x44, 6);      if (memcmp(thisint->dest_mac, baddest, 6) == 0)	{	  debug_printf(DEBUG_INT, "All 4s for dest mac!\n");	  return FALSE;	}      memset((char *)&baddest, 0xff, 6);      if (memcmp(thisint->dest_mac, baddest, 6) == 0)	{	  debug_printf(DEBUG_INT, "All Fs for dest mac!\n");	  return FALSE;	}    }    return TRUE;}/****************************************** * * Return the socket number for functions that need it. * ******************************************/int cardif_get_socket(struct interface_data *thisint){  struct lin_sock_data *sockData;  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  sockData = thisint->sockData;  return sockData->sockInt;}/****************************************** * * Clean up anything that was created during the initialization and operation * of the interface.  This will be called before the program terminates. * ******************************************/int cardif_deinit(struct interface_data *thisint){  struct ifreq ifr;  uint16_t int16;  struct lin_sock_data *sockData;  uint8_t all0s[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;    sockData = thisint->sockData;  debug_printf(DEBUG_EVERYTHING, "Cleaning up interface %s...\n",thisint->intName);  cardif_linux_rtnetlink_cleanup(thisint);  if (TEST_FLAG(thisint->flags, IS_WIRELESS))  {    // Remove all of the keys that we have set.    cardif_linux_clear_keys(thisint);    debug_printf(DEBUG_INT, "Turning off WPA support/state.\n");    // Clear the WPA IE.    cardif_linux_wext_set_wpa_ie(thisint, NULL, 0);    cardif_disable_wpa_state(thisint);    // Reset the MAC address to all 0s.  (This tells the driver to    // scan for new associations.    cardif_setBSSID(thisint, all0s);  }  // Check if we want ALLMULTI mode, and enable it.  if (TEST_FLAG(thisint->flags, ALLMULTI))    {      memset(&ifr, 0x00, sizeof(ifr));      // Tell the ifreq struct which interface we want to use.      strncpy((char *)&ifr.ifr_name, thisint->intName, sizeof(ifr.ifr_name));      if (ioctl(sockData->sockInt, SIOCGIFFLAGS, &ifr) < 0)	{	  debug_printf(DEBUG_NORMAL, "Couldn't get interface flags!\n");	} else {	  // Check if allmulti was disabled when we started.  If it was,	  // then disable it again, so everything is good.	  if (!(thisint->flags & ALLMULTI))	    {	      debug_printf(DEBUG_INT, "Turning off ALLMULTI mode!\n");	      int16 = ifr.ifr_flags;	      // ANDing the flags with 0xfdff will turn off the ALLMULTI flag.	      ifr.ifr_flags = (int16 & 0xfdff);	      if (ioctl(sockData->sockInt, SIOCSIFFLAGS, &ifr) < 0)		{		  debug_printf(DEBUG_NORMAL, "Couldn't set ALLMULTI mode on this interface!  We will continue anyway!\n");		}	    }	}    }  close(sockData->sockInt);  // Now clean up the memory.  if (thisint->sockData != NULL)    {      free(thisint->sockData);      thisint->sockData = NULL;    }  return XENONE;}/****************************************** * * Set a WEP key.  Also, based on the index, we may change the transmit * key. * ******************************************/int cardif_set_wep_key(struct interface_data *thisint, uint8_t *key, 		       int keylen, int index){  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  if (!xsup_assert((key != NULL), "key != NULL", FALSE))    return XEMALLOC;  if (wireless == NULL) return -1;  return wireless->set_wep_key(thisint, key, keylen, index);}/********************************************************** * * Set a TKIP key.  * **********************************************************/int cardif_set_tkip_key(struct interface_data *thisint, char *addr, 			      int keyidx, int settx, char *key, int keylen){  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  if (wireless == NULL) return -1;  return wireless->set_tkip_key(thisint, (uint8_t *) addr, keyidx, settx, 				key, keylen);}/********************************************************** * * Set a CCMP (AES) key * **********************************************************/int cardif_set_ccmp_key(struct interface_data *thisint, char *addr, int keyidx,			int settx, char *key, int keylen){  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  if (wireless == NULL) return -1;  return wireless->set_ccmp_key(thisint, (uint8_t *) addr, keyidx, settx,				key, keylen);}/********************************************************** * * Delete a key * **********************************************************/int cardif_delete_key(struct interface_data *intdata, int key_idx, int set_tx){  if (!xsup_assert((intdata != NULL), "intdata != NULL", FALSE))    return XEMALLOC;  if (wireless == NULL) return -1;  return wireless->delete_key(intdata, key_idx, set_tx);}/****************************************** * * Do whatever we need to do in order to associate based on the flags in * the ssids_list struct. * ******************************************/void cardif_associate(struct interface_data *intdata){  if (!xsup_assert((intdata != NULL), "intdata != NULL", FALSE))    return;  wireless->associate(intdata);}/****************************************** * * Ask the wireless card for the ESSID that we are currently connected to.  If * this is not a wireless card, or the information is not available, we should * return an error. * ******************************************/int cardif_GetSSID(struct interface_data *thisint, char *ssid_name){  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  if (!xsup_assert((ssid_name != NULL), "ssid_name != NULL", FALSE))    return XEMALLOC;  if (wireless == NULL)     {      debug_printf(DEBUG_NORMAL, "No valid call to get SSID for this driver!"		   "\n");      return -1;    }  if ((thisint == NULL) || (ssid_name == NULL))   {    debug_printf(DEBUG_INT, "NULL value passed to %s!\n", __FUNCTION__);    return -1;  }  return wireless->get_ssid(thisint, ssid_name);}/****************************************** * * Get the Broadcast SSID (MAC address) of the Access Point we are connected  * to.  If this is not a wireless card, or the information is not available, * we should return an error. * ******************************************/int cardif_GetBSSID(struct interface_data *thisint, char *bssid_dest){  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  if (!xsup_assert((bssid_dest != NULL), "bssid_dest != NULL", FALSE))    return XEMALLOC;  if (wireless == NULL) return -1;  if (thisint == NULL)    {      debug_printf(DEBUG_NORMAL, "Invalid interface data structure passed to %s!\n", __FUNCTION__);      return -1;    }  if (bssid_dest == NULL)    {      debug_printf(DEBUG_NORMAL, "Invalid bssid_dest in %s!\n", __FUNCTION__);      return -1;    }  return wireless->get_bssid(thisint, bssid_dest);}/****************************************** * * Set the flag in the state machine that indicates if this interface is up * or down.  If there isn't an interface, we should return an error. * ******************************************/int cardif_get_if_state(struct interface_data *thisint){  int retVal;  struct ifreq ifr;  struct lin_sock_data *sockData;  if (!xsup_assert((thisint != NULL), "thisint != NULL", FALSE))    return XEMALLOC;  sockData = thisint->sockData;

⌨️ 快捷键说明

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