📄 os_wireless_ext.c
字号:
/** * A client-side 802.1x implementation supporting EAP/TLS * * This code is released under both the GPL version 2 and BSD licenses. * Either license may be used. The respective licenses are found below. * * Copyright (C) 2002 Bryan D. Payne & Nick L. Petroni Jr. * All Rights Reserved * * --- GPL Version 2 License --- * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * --- BSD License --- * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * Maryland at College Park and its contributors. * - Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *//******************************************************************* * Wireless support for Mac OS-X * * File: os_wireless_ext.c * * Authors: Chris.Hessing@utah.edu * * $Id: os_wireless_ext.c,v 1.10 2003/03/13 22:36:01 galimorerpg Exp $ * $Date: 2003/03/13 22:36:01 $ * $Log: os_wireless_ext.c,v $ * Revision 1.10 2003/03/13 22:36:01 galimorerpg * Fixed a NULL reference in os_wireless.c (for Mac OS X). * * Revision 1.9 2003/03/05 21:18:47 npetroni * migration to libdnet. Please notify developers of build problems AFTER doing a cvs update. * * Revision 1.8 2003/02/07 22:17:31 galimorerpg * Socket code to allow for daemonizing has been added. * * Revision 1.7 2003/02/02 03:29:02 chessing * Fixed -a option, and updated MacOS-X wireless calls to return the MAC of the AP we are associated to. * * Revision 1.6 2003/01/09 20:50:16 chessing * Code cleanups. * * Revision 1.5 2003/01/09 20:17:31 galimorerpg * Logging Updates * * Revision 1.4 2003/01/09 19:14:20 chessing * Updated configure files to allow for wireless debugging options, removed unneeded file in macosx wireless directory, Mac OS-X now can tell the difference between a wireless and wired interface!!!! * * Revision 1.3 2003/01/03 22:25:37 chessing * Turned off debugging code, (use the configure options to turn on the debugging) and added -w option to get around some problems with the Intel iANS drivers, and some wired/wireless issues with the MacOS-X wireless code. * * Revision 1.2 2003/01/02 20:06:16 chessing * Patch to fix problems with the wireless code for MacOS-X * * Revision 1.1 2003/01/02 19:35:47 chessing * Add some files that were missed in the last import.. * * *******************************************************************/#include <sys/types.h>#include <stdlib.h>#include "wireless/macosx/Apple80211.h" // Information about the Airport cards.#include "wireless/os_wireless_ext.h"#include "logging.h"#include "frame_handlers/os_frame_funcs.h" // To give us the MAC that dnet found.#include "logging.h"#ifndef WIRELESS_DEBUG#define WIRELESS_DEBUG 0#endif// This #define is taken from the linux_hermes_rid.h file that is distributed// with the Apple80211.h file.#define HERMES_RID_CNFOWNMACADDR 0xFC01WirelessContextPtr wirelesscntx = NULL;WirelessInfo wirelessinfo;u_char *wireless_mac = NULL;u_char *get_wireless_mac();void print_mac(u_char *mac){ if(mac != NULL) { printf("%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); }}int eapol_wireless_init(){ WirelessAttach(&wirelesscntx, 0); wireless_mac = get_wireless_mac();#if WIRELESS_DEBUG printf("Wireless Mac (from Hermes) is "); print_mac(wireless_mac); printf("\n");#endif if (wirelesscntx != NULL) { return 0; } else { return -1; }}int eapol_wireless_cleanup(){ if (wirelesscntx != NULL) { WirelessDetach(wirelesscntx); wirelesscntx = NULL; } return 0;}int is_airport(){ u_char *dnet_mac = NULL; // First, we need to see if "wireless is available", then check the MAC // addresses to make sure they match. (To be sure we are on the correct // interface.) if (WirelessIsAvailable()==1) { // Check our MAC address dnet_mac = get_src_mac(); //Get the MAC that dnet found. if (dnet_mac == NULL) { xlogf(DEBUG_NORMAL, "ERROR! : Couldn't get MAC address from libdnet! We don't know if we are using wireless or not!\n"); return 0; }#if WIRELESS_DEBUG printf("Libdnet MAC is "); print_mac(dnet_mac); printf("\nWireless (Hermes) MAC is "); print_mac(wireless_mac); printf("\n");#endif if (memcmp(dnet_mac, wireless_mac, 6)==0) {#if WIRELESS_DEBUG printf("MAC addresses match! This must be an Airport!\n");#endif if (dnet_mac != NULL) free(dnet_mac); return 1; } else {#if WIRELESS_DEBUG printf("MAC addresses don't match! This isn't an Airport!\n");#endif if (dnet_mac != NULL) free(dnet_mac); return 0; } } return 0;}u_char *get_wireless_mac(){ SInt32 err; u_char *buf; buf = (u_char *)malloc(100); err = WirelessHCF_GetInfo(wirelesscntx, HERMES_RID_CNFOWNMACADDR, 100, buf); if (err) { printf("Error getting Hermes Chipset info!\n"); return NULL; } return buf;}// Not sure how to return this with the Airport.int eapol_wireless_get_bssid(char *devname, u_char *retbssid){ if (is_airport() == 1) { WirelessGetInfo(wirelesscntx, &wirelessinfo); memcpy(retbssid, wirelessinfo.macAddress, 6); return 0; } retbssid = NULL; return -1;}int eapol_wireless_get_ssid(char *devname, char *retssid){ // We need to check and make sure the interface we are using is really a // wireless interface. But, for now .... if (is_airport() == 1) { WirelessGetInfo(wirelesscntx, &wirelessinfo); if (retssid == NULL) { retssid = (char *)malloc(strlen(wirelessinfo.name)+1); } strncpy(retssid, wirelessinfo.name, strlen(wirelessinfo.name)+1); #ifdef WIRELESS_DEBUG xlogf(DEBUG_CONFIG, "Wireless network name (after copy) is %s\n",retssid);#endif return 0; } return -1;}int eapol_wireless_set_key(char *devname, u_char *inkey, int keylen, int index){ int real_key_val = -1; WirelessKey *wepKey = NULL; //Converted WEP key. // CFStringRef n = CFStringCreateWithCString(NULL, switch (keylen) { case 0: case 40: case 64: real_key_val = 0; break; case 1: case 104: case 128: real_key_val = 1; break; default: return -1; } WirelessEncrypt(CFStringCreateWithCString(NULL, inkey, kCFStringEncodingISOLatin1), wepKey, real_key_val); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -