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

📄 driver_atheros.c

📁 最新的Host AP 新添加了许多pcmcia 的驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * hostapd / Driver interaction with Atheros driver * Copyright (c) 2004, Sam Leffler <sam@errno.com> * Copyright (c) 2004, Video54 Technologies * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi> * Copyright (c) 2009, Atheros Communications * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Alternatively, this software may be distributed under the terms of BSD * license. * * See README and COPYING for more details. */#include "includes.h"#include <net/if.h>#include <sys/ioctl.h>#include "common.h"#ifndef _BYTE_ORDER#ifdef WORDS_BIGENDIAN#define _BYTE_ORDER _BIG_ENDIAN#else#define _BYTE_ORDER _LITTLE_ENDIAN#endif#endif /* _BYTE_ORDER */#include <net80211/ieee80211.h>#include <net80211/_ieee80211.h>#include <net80211/ieee80211_crypto.h>/* * Note, the ATH_WPS_IE setting must match with the driver build.. If the * driver does not include this, the IEEE80211_IOCTL_GETWPAIE ioctl will fail. */#define ATH_WPS_IE#include <net80211/ieee80211_ioctl.h>#ifdef CONFIG_WPS#ifdef IEEE80211_IOCTL_FILTERFRAME#include <netpacket/packet.h>#ifndef ETH_P_80211_RAW#define ETH_P_80211_RAW 0x0019#endif#endif /* IEEE80211_IOCTL_FILTERFRAME */#endif /* CONFIG_WPS *//* * Avoid conflicts with hostapd definitions by undefining couple of defines * from madwifi header files. */#undef WPA_OUI_TYPE#undef WME_OUI_TYPE#include "wireless_copy.h"#include "hostapd.h"#include "driver.h"#include "eloop.h"#include "priv_netlink.h"#include "l2_packet/l2_packet.h"#include "wps_hostapd.h"#include "ieee802_11_defs.h"struct madwifi_driver_data {	struct hostapd_data *hapd;		/* back pointer */	char	iface[IFNAMSIZ + 1];	int     ifindex;	struct l2_packet_data *sock_xmit;	/* raw packet xmit socket */	struct l2_packet_data *sock_recv;	/* raw packet recv socket */	int	ioctl_sock;			/* socket for ioctl() use */	int	wext_sock;			/* socket for wireless events */	int	we_version;	u8	acct_mac[ETH_ALEN];	struct hostap_sta_driver_data acct_data;	struct l2_packet_data *sock_raw; /* raw 802.11 management frames */};static int madwifi_sta_deauth(void *priv, const u8 *addr, int reason_code);/* hostapd 0.7.x compatibility - START */#include "ieee802_1x.h"#include "sta_info.h"#include "wpa.h"#include "radius/radius.h"#include "ieee802_11.h"#include "accounting.h"static int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,			       const u8 *ie, size_t ielen){	struct sta_info *sta;	int new_assoc, res;	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,		       HOSTAPD_LEVEL_INFO, "associated");	sta = ap_get_sta(hapd, addr);	if (sta) {		accounting_sta_stop(hapd, sta);	} else {		sta = ap_sta_add(hapd, addr);		if (sta == NULL)			return -1;	}	sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);	if (hapd->conf->wpa) {		if (ie == NULL || ielen == 0) {			if (hapd->conf->wps_state) {				wpa_printf(MSG_DEBUG, "STA did not include "					   "WPA/RSN IE in (Re)Association "					   "Request - possible WPS use");				sta->flags |= WLAN_STA_MAYBE_WPS;				goto skip_wpa_check;			}			wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");			return -1;		}		if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&		    os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {			sta->flags |= WLAN_STA_WPS;			goto skip_wpa_check;		}		if (sta->wpa_sm == NULL)			sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,							sta->addr);		if (sta->wpa_sm == NULL) {			wpa_printf(MSG_ERROR, "Failed to initialize WPA state "				   "machine");			return -1;		}		res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,					  ie, ielen, NULL, 0);		if (res != WPA_IE_OK) {			wpa_printf(MSG_DEBUG, "WPA/RSN information element "				   "rejected? (res %u)", res);			wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);			return -1;		}	} else if (hapd->conf->wps_state) {		if (ie && ielen > 4 && ie[0] == 0xdd && ie[1] >= 4 &&		    os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {			sta->flags |= WLAN_STA_WPS;		} else			sta->flags |= WLAN_STA_MAYBE_WPS;	}skip_wpa_check:	new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;	sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;	wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);	hostapd_new_assoc_sta(hapd, sta, !new_assoc);	ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);	return 0;}static void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr){	struct sta_info *sta;	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,		       HOSTAPD_LEVEL_INFO, "disassociated");	sta = ap_get_sta(hapd, addr);	if (sta == NULL) {		wpa_printf(MSG_DEBUG, "Disassociation notification for "			   "unknown STA " MACSTR, MAC2STR(addr));		return;	}	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);	wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;	ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);	ap_free_sta(hapd, sta);}static void hostapd_eapol_receive(struct hostapd_data *hapd, const u8 *sa,				  const u8 *buf, size_t len){	ieee802_1x_receive(hapd, sa, buf, len);}static void hostapd_michael_mic_failure(struct hostapd_data *hapd,					const u8 *addr){	ieee80211_michael_mic_failure(hapd, addr, 1);}/* hostapd 0.7.x compatibility - END */static intset80211priv(struct madwifi_driver_data *drv, int op, void *data, int len){	struct iwreq iwr;	int do_inline = len < IFNAMSIZ;	/* Certain ioctls must use the non-inlined method */	if (op == IEEE80211_IOCTL_SET_APPIEBUF ||	    op == IEEE80211_IOCTL_FILTERFRAME)		do_inline = 0;	memset(&iwr, 0, sizeof(iwr));	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);	if (do_inline) {		/*		 * Argument data fits inline; put it there.		 */		memcpy(iwr.u.name, data, len);	} else {		/*		 * Argument data too big for inline transfer; setup a		 * parameter block instead; the kernel will transfer		 * the data for the driver.		 */		iwr.u.data.pointer = data;		iwr.u.data.length = len;	}	if (ioctl(drv->ioctl_sock, op, &iwr) < 0) {		int first = IEEE80211_IOCTL_SETPARAM;		static const char *opnames[] = {			"ioctl[IEEE80211_IOCTL_SETPARAM]",			"ioctl[IEEE80211_IOCTL_GETPARAM]",			"ioctl[IEEE80211_IOCTL_SETKEY]",			"ioctl[IEEE80211_IOCTL_SETWMMPARAMS]",			"ioctl[IEEE80211_IOCTL_DELKEY]",			"ioctl[IEEE80211_IOCTL_GETWMMPARAMS]",			"ioctl[IEEE80211_IOCTL_SETMLME]",			"ioctl[IEEE80211_IOCTL_GETCHANINFO]",			"ioctl[IEEE80211_IOCTL_SETOPTIE]",			"ioctl[IEEE80211_IOCTL_GETOPTIE]",			"ioctl[IEEE80211_IOCTL_ADDMAC]",			"ioctl[IEEE80211_IOCTL_DELMAC]",			"ioctl[IEEE80211_IOCTL_GETCHANLIST]",			"ioctl[IEEE80211_IOCTL_SETCHANLIST]",			"ioctl[IEEE80211_IOCTL_KICKMAC]",			"ioctl[IEEE80211_IOCTL_CHANSWITCH]",			"ioctl[IEEE80211_IOCTL_GETMODE]",			"ioctl[IEEE80211_IOCTL_SETMODE]",			"ioctl[IEEE80211_IOCTL_GET_APPIEBUF]",			"ioctl[IEEE80211_IOCTL_SET_APPIEBUF]",			NULL,			"ioctl[IEEE80211_IOCTL_FILTERFRAME]",		};		int idx = op - first;		if (first <= op &&		    idx < (int) (sizeof(opnames) / sizeof(opnames[0])) &&		    opnames[idx])			perror(opnames[idx]);		else {			perror("ioctl[unknown???]");			wpa_printf(MSG_DEBUG, "Failed ioctl: 0x%x", op);		}		return -1;	}	return 0;}static intset80211param(struct madwifi_driver_data *drv, int op, int arg){	struct iwreq iwr;	memset(&iwr, 0, sizeof(iwr));	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);	iwr.u.mode = op;	memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg));	if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) {		perror("ioctl[IEEE80211_IOCTL_SETPARAM]");		wpa_printf(MSG_DEBUG, "%s: Failed to set parameter (op %d "			   "arg %d)", __func__, op, arg);		return -1;	}	return 0;}#ifndef CONFIG_NO_STDOUT_DEBUGstatic const char *ether_sprintf(const u8 *addr){	static char buf[sizeof(MACSTR)];	if (addr != NULL)		snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));	else		snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);	return buf;}#endif /* CONFIG_NO_STDOUT_DEBUG *//* * Configure WPA parameters. */static intmadwifi_configure_wpa(struct madwifi_driver_data *drv){	struct hostapd_data *hapd = drv->hapd;	struct hostapd_bss_config *conf = hapd->conf;	int v;	switch (conf->wpa_group) {	case WPA_CIPHER_CCMP:		v = IEEE80211_CIPHER_AES_CCM;		break;	case WPA_CIPHER_TKIP:		v = IEEE80211_CIPHER_TKIP;		break;	case WPA_CIPHER_WEP104:		v = IEEE80211_CIPHER_WEP;		break;	case WPA_CIPHER_WEP40:		v = IEEE80211_CIPHER_WEP;		break;	case WPA_CIPHER_NONE:		v = IEEE80211_CIPHER_NONE;		break;	default:		wpa_printf(MSG_ERROR, "Unknown group key cipher %u",			   conf->wpa_group);		return -1;	}	wpa_printf(MSG_DEBUG, "%s: group key cipher=%d", __func__, v);	if (set80211param(drv, IEEE80211_PARAM_MCASTCIPHER, v)) {		printf("Unable to set group key cipher to %u\n", v);		return -1;	}	if (v == IEEE80211_CIPHER_WEP) {		/* key length is done only for specific ciphers */		v = (conf->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);		if (set80211param(drv, IEEE80211_PARAM_MCASTKEYLEN, v)) {			printf("Unable to set group key length to %u\n", v);			return -1;		}	}	v = 0;	if (conf->wpa_pairwise & WPA_CIPHER_CCMP)		v |= 1<<IEEE80211_CIPHER_AES_CCM;	if (conf->wpa_pairwise & WPA_CIPHER_TKIP)		v |= 1<<IEEE80211_CIPHER_TKIP;	if (conf->wpa_pairwise & WPA_CIPHER_NONE)		v |= 1<<IEEE80211_CIPHER_NONE;	wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);	if (set80211param(drv, IEEE80211_PARAM_UCASTCIPHERS, v)) {		printf("Unable to set pairwise key ciphers to 0x%x\n", v);		return -1;	}	wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",		   __func__, conf->wpa_key_mgmt);	if (set80211param(drv, IEEE80211_PARAM_KEYMGTALGS, conf->wpa_key_mgmt)) {		printf("Unable to set key management algorithms to 0x%x\n",			conf->wpa_key_mgmt);		return -1;	}	v = 0;	if (conf->rsn_preauth)		v |= BIT(0);	wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x",		   __func__, conf->rsn_preauth);	if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {		printf("Unable to set RSN capabilities to 0x%x\n", v);		return -1;	}	wpa_printf(MSG_DEBUG, "%s: enable WPA=0x%x", __func__, conf->wpa);	if (set80211param(drv, IEEE80211_PARAM_WPA, conf->wpa)) {		printf("Unable to set WPA to %u\n", conf->wpa);		return -1;	}	return 0;}static intmadwifi_set_iface_flags(void *priv, int dev_up){	struct madwifi_driver_data *drv = priv;	struct ifreq ifr;	wpa_printf(MSG_DEBUG, "%s: dev_up=%d", __func__, dev_up);	if (drv->ioctl_sock < 0)		return -1;	memset(&ifr, 0, sizeof(ifr));	os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);	if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {		perror("ioctl[SIOCGIFFLAGS]");		return -1;	}	if (dev_up)		ifr.ifr_flags |= IFF_UP;	else		ifr.ifr_flags &= ~IFF_UP;	if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {		perror("ioctl[SIOCSIFFLAGS]");		return -1;	}	if (dev_up) {		memset(&ifr, 0, sizeof(ifr));		os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);		ifr.ifr_mtu = HOSTAPD_MTU;		if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {			perror("ioctl[SIOCSIFMTU]");			printf("Setting MTU failed - trying to survive with "			       "current value\n");		}	}	return 0;}static intmadwifi_set_ieee8021x(const char *ifname, void *priv, int enabled){	struct madwifi_driver_data *drv = priv;	struct hostapd_data *hapd = drv->hapd;	struct hostapd_bss_config *conf = hapd->conf;	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);	if (!enabled) {		/* XXX restore state */		return set80211param(priv, IEEE80211_PARAM_AUTHMODE,			IEEE80211_AUTH_AUTO);	}	if (!conf->wpa && !conf->ieee802_1x) {		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,			HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");		return -1;	}	if (conf->wpa && madwifi_configure_wpa(drv) != 0) {		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,			HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");		return -1;	}	if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,		(conf->wpa ?  IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,			HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!");		return -1;	}	return 0;}static intmadwifi_set_privacy(const char *ifname, void *priv, int enabled){	struct madwifi_driver_data *drv = priv;	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);	return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);}static intmadwifi_set_sta_authorized(void *priv, const u8 *addr, int authorized){	struct madwifi_driver_data *drv = priv;	struct ieee80211req_mlme mlme;	int ret;

⌨️ 快捷键说明

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