?? cardif_linux.c
字號:
* we need to reset them. Otherwise, we will just ignore the fact that * we changed APs, and return. * **************************************************************/void cardif_reset_keys(struct interface_data *thisint){ char zerokey[13]; char keylen = 13; if (thisint->userdata == NULL) { debug_printf(DEBUG_INT, "Userdata is NULL!\n"); return; } if (thisint->userdata->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 (cardif_enc_enabled(thisint) != TRUE) { debug_printf(DEBUG_INT, "Encryption appears to be disabled. We will not reset keys on interface %s!\n", thisint->intName); return; } bzero(&zerokey, 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. set_wireless_key(thisint, (char *)&zerokey, keylen, 0x80);}/************************************************************** * * If we determine that this interface is a wireless interface, then * we should call this, to have the destination address changed to the * AP that we are talking to. Otherwise, we will always send frames to * the multicast address, instead of the AP. (And, most APs won't answer * to the multicast address.) * **************************************************************/int cardif_check_dest(struct interface_data *thisint){ char newdest[6], *newssid; char baddest[6]; int changed = FALSE; bzero((char *)&newdest, 6); // If we are on wireless, figure out the target MAC address. if ((thisint->isWireless == TRUE) && (GetBSSID(thisint, (char *)&newdest) == XENONE)) { if (memcmp(thisint->dest_mac, newdest, 6) != 0) { debug_printf(DEBUG_INT, "The card reported that the destination MAC address is now "); debug_hex_printf(DEBUG_INT, (char *)&newdest, 6); memcpy((char *)&thisint->dest_mac[0], (char *)&newdest, 6); changed = TRUE; // Since we changed destination addresses, we need to see if // we should reset keys. cardif_reset_keys(thisint); } memset((char *)&baddest, 0x00, 6); if (memcmp(thisint->dest_mac, baddest, 6) == 0) { debug_printf(DEBUG_INT, "We don't appear to be associated! Resetting keys!\n"); cardif_reset_keys(thisint); } memset((char *)&baddest, 0x44, 6); if (memcmp(thisint->dest_mac, baddest, 6) == 0) { debug_printf(DEBUG_INT, "All 4s for dest mac! Resetting keys!\n"); cardif_reset_keys(thisint); } memset((char *)&baddest, 0xff, 6); if (memcmp(thisint->dest_mac, baddest, 6) == 0) { debug_printf(DEBUG_INT, "All Fs for dest mac! Resetting keys!\n"); cardif_reset_keys(thisint); } // If we were able to get a BSSID, we should also try to get an SSID. newssid = malloc(100); if (newssid == NULL) { debug_printf(DEBUG_NORMAL, "Couldn't malloc newssid in cardif_linux.\n"); return XEMALLOC; } bzero(newssid, 100); GetSSID(thisint, newssid); if ((thisint->cur_essid == NULL) || (strncmp(newssid, thisint->cur_essid, 100) != 0)) { if (thisint->cur_essid != NULL) free(thisint->cur_essid); thisint->cur_essid = newssid; debug_printf(DEBUG_INT, "Working with ESSID : %s\n", thisint->cur_essid); } else { if (newssid != NULL) { free(newssid); newssid = NULL; } } } else { // debug_printf(DEBUG_INT, "Interface doesn't appear to be a wireless interface!\n"); } return changed;}/****************************************** * * 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){ debug_printf(DEBUG_EVERYTHING, "Cleaning up interface %s...\n",thisint->intName); close(thisint->sockInt); return XENONE;}/****************************************** * * Set a wireless key. Also, based on the index, we may change the transmit * key. * ******************************************/int set_wireless_key(struct interface_data *thisint, u_char *key, int keylen, int index){ int rc = 0; int skfd; struct iwreq wrq; if (thisint->isWireless == FALSE) { if ((cardif_int_is_wireless(thisint->intName) != TRUE) || (thisint->userdata->type == WIRED) || (thisint->userdata->wireless_ctrl == CTL_NO)) { debug_printf(DEBUG_NORMAL, "Interface isn't wireless, but an attempt to set a key was made!\n"); return XENOWIRELESS; } else { thisint->isWireless = TRUE; } } skfd = socket(AF_INET, SOCK_DGRAM, 0); if (skfd < 0) return -1; strncpy(wrq.ifr_name, thisint->intName, IFNAMSIZ); wrq.u.data.flags = ((index & 0x7f) + 1) & IW_ENCODE_INDEX; wrq.u.data.flags |= IW_ENCODE_OPEN; wrq.u.data.length = keylen; wrq.u.data.pointer = (caddr_t)key; if ((rc = ioctl(skfd, SIOCSIWENCODE, &wrq)) < 0) { debug_printf(DEBUG_NORMAL, "Failed to set WEP key [%d], error %d : %s\n", (index & 0x7f) + 1, errno, strerror(errno)); rc = XENOKEYSUPPORT; } else { debug_printf(DEBUG_INT, "Successfully set WEP key [%d]\n", (index & 0x7f)+1); if (index & 0x80) { // This is a unicast key, use it for transmissions. strncpy(wrq.ifr_name, thisint->intName, IFNAMSIZ); wrq.u.data.flags = ((index & 0x7f) + 1) & IW_ENCODE_INDEX; wrq.u.data.flags |= IW_ENCODE_OPEN; wrq.u.data.length = 0; wrq.u.data.pointer = (caddr_t)NULL; if (ioctl(skfd, SIOCSIWENCODE, &wrq) < 0) { debug_printf(DEBUG_NORMAL, "Failed to set the WEP transmit key ID [%d]\n", (index & 0x7f)+1); rc = XENOKEYSUPPORT; } else { debug_printf(DEBUG_INT, "Successfully set the WEP transmit key [%d]\n", (index & 0x7f)+1); } } } close(skfd); return rc;}/****************************************** * * 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 GetSSID(struct interface_data *thisint, char *ssid_name){ struct iwreq iwr; if (thisint->isWireless == FALSE) { // We want to verify that the interface is in fact, not wireless, and // not that we are in a situation where the interface has just been // down. if (thisint->wasDown == FALSE) { return XENOWIRELESS; } } // If we get here, and isWireless == FALSE, then we need to double // check that our interface is really not wireless. if (thisint->isWireless == FALSE) { thisint->isWireless = cardif_int_is_wireless(thisint->intName); if (thisint->isWireless == FALSE) { thisint->wasDown = FALSE; } } // Specify the interface name we are asking about. strncpy(iwr.ifr_name, thisint->intName, sizeof(iwr.ifr_name)); iwr.u.essid.pointer = (caddr_t) ssid_name; iwr.u.essid.length = 100; iwr.u.essid.flags = 0; if (ioctl(thisint->sockInt, SIOCGIWESSID, &iwr) < 0) return XENOWIRELESS; thisint->wasDown = FALSE; return XENONE;}/****************************************** * * Check the SSID against what we currently have, and determine if we need * to reset our configuration. * ******************************************/int cardif_check_ssid(struct interface_data *thisint){ char new_essid[100]; bzero((char *)&new_essid, 100); if (GetSSID(thisint, (char *)&new_essid) != XENONE) { // This interface probably isn't wireless! // On the off chance that it is, we will trash the essid we have // listed as the current one, so that if we suddenly do get an // essid, we will load the proper config. if (thisint->cur_essid != NULL) { free(thisint->cur_essid); thisint->cur_essid = NULL; } return XENONE; } if (thisint->cur_essid != NULL) { if (strcmp(thisint->cur_essid, (char *)&new_essid) != 0) { // We have changed essids. debug_printf(DEBUG_INT, "ESSID Changed to : %s\n", (char *)&new_essid); // Kill off the essid we currently have. free(thisint->cur_essid); thisint->cur_essid = (char *)malloc(strlen(new_essid)+1); if (thisint->cur_essid == NULL) return XEMALLOC; strncpy(thisint->cur_essid, new_essid, strlen(new_essid)); // Since we changed essids, we no longer have completed a // "first auth" thisint->firstauth = FALSE; return XNEWESSID; } } return XENONE;}/****************************************** * * 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 GetBSSID(struct interface_data *thisint, char *bssid_dest){ struct iwreq iwr;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -