| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * BSS client mode implementation | 
 | 3 |  * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> | 
 | 4 |  * Copyright 2004, Instant802 Networks, Inc. | 
 | 5 |  * Copyright 2005, Devicescape Software, Inc. | 
 | 6 |  * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz> | 
 | 7 |  * Copyright 2007, Michael Wu <flamingice@sourmilk.net> | 
 | 8 |  * | 
 | 9 |  * This program is free software; you can redistribute it and/or modify | 
 | 10 |  * it under the terms of the GNU General Public License version 2 as | 
 | 11 |  * published by the Free Software Foundation. | 
 | 12 |  */ | 
 | 13 |  | 
 | 14 | /* TODO: | 
 | 15 |  * BSS table: use <BSSID,SSID> as the key to support multi-SSID APs | 
 | 16 |  * order BSS list by RSSI(?) ("quality of AP") | 
 | 17 |  * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE, | 
 | 18 |  *    SSID) | 
 | 19 |  */ | 
| Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 21 | #include <linux/if_ether.h> | 
 | 22 | #include <linux/skbuff.h> | 
 | 23 | #include <linux/netdevice.h> | 
 | 24 | #include <linux/if_arp.h> | 
 | 25 | #include <linux/wireless.h> | 
 | 26 | #include <linux/random.h> | 
 | 27 | #include <linux/etherdevice.h> | 
 | 28 | #include <linux/rtnetlink.h> | 
 | 29 | #include <net/iw_handler.h> | 
 | 30 | #include <asm/types.h> | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 31 |  | 
 | 32 | #include <net/mac80211.h> | 
 | 33 | #include "ieee80211_i.h" | 
 | 34 | #include "ieee80211_rate.h" | 
 | 35 | #include "hostapd_ioctl.h" | 
 | 36 |  | 
 | 37 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) | 
 | 38 | #define IEEE80211_AUTH_MAX_TRIES 3 | 
 | 39 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) | 
 | 40 | #define IEEE80211_ASSOC_MAX_TRIES 3 | 
 | 41 | #define IEEE80211_MONITORING_INTERVAL (2 * HZ) | 
 | 42 | #define IEEE80211_PROBE_INTERVAL (60 * HZ) | 
 | 43 | #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) | 
 | 44 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) | 
 | 45 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) | 
 | 46 | #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ) | 
 | 47 |  | 
 | 48 | #define IEEE80211_PROBE_DELAY (HZ / 33) | 
 | 49 | #define IEEE80211_CHANNEL_TIME (HZ / 33) | 
 | 50 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) | 
 | 51 | #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ) | 
 | 52 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) | 
 | 53 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) | 
 | 54 |  | 
 | 55 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 | 
 | 56 |  | 
 | 57 |  | 
 | 58 | #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype) | 
 | 59 |  | 
 | 60 | #define ERP_INFO_USE_PROTECTION BIT(1) | 
 | 61 |  | 
 | 62 | static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst, | 
 | 63 | 				     u8 *ssid, size_t ssid_len); | 
 | 64 | static struct ieee80211_sta_bss * | 
 | 65 | ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid); | 
 | 66 | static void ieee80211_rx_bss_put(struct net_device *dev, | 
 | 67 | 				 struct ieee80211_sta_bss *bss); | 
 | 68 | static int ieee80211_sta_find_ibss(struct net_device *dev, | 
 | 69 | 				   struct ieee80211_if_sta *ifsta); | 
 | 70 | static int ieee80211_sta_wep_configured(struct net_device *dev); | 
 | 71 | static int ieee80211_sta_start_scan(struct net_device *dev, | 
 | 72 | 				    u8 *ssid, size_t ssid_len); | 
 | 73 | static int ieee80211_sta_config_auth(struct net_device *dev, | 
 | 74 | 				     struct ieee80211_if_sta *ifsta); | 
 | 75 |  | 
 | 76 |  | 
 | 77 | /* Parsed Information Elements */ | 
 | 78 | struct ieee802_11_elems { | 
| Johannes Berg | 5558235 | 2007-07-10 19:32:09 +0200 | [diff] [blame] | 79 | 	/* pointers to IEs */ | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 80 | 	u8 *ssid; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 81 | 	u8 *supp_rates; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 82 | 	u8 *fh_params; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 83 | 	u8 *ds_params; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 84 | 	u8 *cf_params; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 85 | 	u8 *tim; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 86 | 	u8 *ibss_params; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 87 | 	u8 *challenge; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 88 | 	u8 *wpa; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 89 | 	u8 *rsn; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 90 | 	u8 *erp_info; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 91 | 	u8 *ext_supp_rates; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 92 | 	u8 *wmm_info; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 93 | 	u8 *wmm_param; | 
| Johannes Berg | 5558235 | 2007-07-10 19:32:09 +0200 | [diff] [blame] | 94 |  | 
 | 95 | 	/* length of them, respectively */ | 
 | 96 | 	u8 ssid_len; | 
 | 97 | 	u8 supp_rates_len; | 
 | 98 | 	u8 fh_params_len; | 
 | 99 | 	u8 ds_params_len; | 
 | 100 | 	u8 cf_params_len; | 
 | 101 | 	u8 tim_len; | 
 | 102 | 	u8 ibss_params_len; | 
 | 103 | 	u8 challenge_len; | 
 | 104 | 	u8 wpa_len; | 
 | 105 | 	u8 rsn_len; | 
 | 106 | 	u8 erp_info_len; | 
 | 107 | 	u8 ext_supp_rates_len; | 
 | 108 | 	u8 wmm_info_len; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 109 | 	u8 wmm_param_len; | 
 | 110 | }; | 
 | 111 |  | 
 | 112 | typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes; | 
 | 113 |  | 
 | 114 |  | 
 | 115 | static ParseRes ieee802_11_parse_elems(u8 *start, size_t len, | 
 | 116 | 				       struct ieee802_11_elems *elems) | 
 | 117 | { | 
 | 118 | 	size_t left = len; | 
 | 119 | 	u8 *pos = start; | 
 | 120 | 	int unknown = 0; | 
 | 121 |  | 
 | 122 | 	memset(elems, 0, sizeof(*elems)); | 
 | 123 |  | 
 | 124 | 	while (left >= 2) { | 
 | 125 | 		u8 id, elen; | 
 | 126 |  | 
 | 127 | 		id = *pos++; | 
 | 128 | 		elen = *pos++; | 
 | 129 | 		left -= 2; | 
 | 130 |  | 
 | 131 | 		if (elen > left) { | 
 | 132 | #if 0 | 
 | 133 | 			if (net_ratelimit()) | 
 | 134 | 				printk(KERN_DEBUG "IEEE 802.11 element parse " | 
 | 135 | 				       "failed (id=%d elen=%d left=%d)\n", | 
 | 136 | 				       id, elen, left); | 
 | 137 | #endif | 
 | 138 | 			return ParseFailed; | 
 | 139 | 		} | 
 | 140 |  | 
 | 141 | 		switch (id) { | 
 | 142 | 		case WLAN_EID_SSID: | 
 | 143 | 			elems->ssid = pos; | 
 | 144 | 			elems->ssid_len = elen; | 
 | 145 | 			break; | 
 | 146 | 		case WLAN_EID_SUPP_RATES: | 
 | 147 | 			elems->supp_rates = pos; | 
 | 148 | 			elems->supp_rates_len = elen; | 
 | 149 | 			break; | 
 | 150 | 		case WLAN_EID_FH_PARAMS: | 
 | 151 | 			elems->fh_params = pos; | 
 | 152 | 			elems->fh_params_len = elen; | 
 | 153 | 			break; | 
 | 154 | 		case WLAN_EID_DS_PARAMS: | 
 | 155 | 			elems->ds_params = pos; | 
 | 156 | 			elems->ds_params_len = elen; | 
 | 157 | 			break; | 
 | 158 | 		case WLAN_EID_CF_PARAMS: | 
 | 159 | 			elems->cf_params = pos; | 
 | 160 | 			elems->cf_params_len = elen; | 
 | 161 | 			break; | 
 | 162 | 		case WLAN_EID_TIM: | 
 | 163 | 			elems->tim = pos; | 
 | 164 | 			elems->tim_len = elen; | 
 | 165 | 			break; | 
 | 166 | 		case WLAN_EID_IBSS_PARAMS: | 
 | 167 | 			elems->ibss_params = pos; | 
 | 168 | 			elems->ibss_params_len = elen; | 
 | 169 | 			break; | 
 | 170 | 		case WLAN_EID_CHALLENGE: | 
 | 171 | 			elems->challenge = pos; | 
 | 172 | 			elems->challenge_len = elen; | 
 | 173 | 			break; | 
 | 174 | 		case WLAN_EID_WPA: | 
 | 175 | 			if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && | 
 | 176 | 			    pos[2] == 0xf2) { | 
 | 177 | 				/* Microsoft OUI (00:50:F2) */ | 
 | 178 | 				if (pos[3] == 1) { | 
 | 179 | 					/* OUI Type 1 - WPA IE */ | 
 | 180 | 					elems->wpa = pos; | 
 | 181 | 					elems->wpa_len = elen; | 
 | 182 | 				} else if (elen >= 5 && pos[3] == 2) { | 
 | 183 | 					if (pos[4] == 0) { | 
 | 184 | 						elems->wmm_info = pos; | 
 | 185 | 						elems->wmm_info_len = elen; | 
 | 186 | 					} else if (pos[4] == 1) { | 
 | 187 | 						elems->wmm_param = pos; | 
 | 188 | 						elems->wmm_param_len = elen; | 
 | 189 | 					} | 
 | 190 | 				} | 
 | 191 | 			} | 
 | 192 | 			break; | 
 | 193 | 		case WLAN_EID_RSN: | 
 | 194 | 			elems->rsn = pos; | 
 | 195 | 			elems->rsn_len = elen; | 
 | 196 | 			break; | 
 | 197 | 		case WLAN_EID_ERP_INFO: | 
 | 198 | 			elems->erp_info = pos; | 
 | 199 | 			elems->erp_info_len = elen; | 
 | 200 | 			break; | 
 | 201 | 		case WLAN_EID_EXT_SUPP_RATES: | 
 | 202 | 			elems->ext_supp_rates = pos; | 
 | 203 | 			elems->ext_supp_rates_len = elen; | 
 | 204 | 			break; | 
 | 205 | 		default: | 
 | 206 | #if 0 | 
 | 207 | 			printk(KERN_DEBUG "IEEE 802.11 element parse ignored " | 
 | 208 | 				      "unknown element (id=%d elen=%d)\n", | 
 | 209 | 				      id, elen); | 
 | 210 | #endif | 
 | 211 | 			unknown++; | 
 | 212 | 			break; | 
 | 213 | 		} | 
 | 214 |  | 
 | 215 | 		left -= elen; | 
 | 216 | 		pos += elen; | 
 | 217 | 	} | 
 | 218 |  | 
 | 219 | 	/* Do not trigger error if left == 1 as Apple Airport base stations | 
 | 220 | 	 * send AssocResps that are one spurious byte too long. */ | 
 | 221 |  | 
 | 222 | 	return unknown ? ParseUnknown : ParseOK; | 
 | 223 | } | 
 | 224 |  | 
 | 225 |  | 
 | 226 |  | 
 | 227 |  | 
 | 228 | static int ecw2cw(int ecw) | 
 | 229 | { | 
 | 230 | 	int cw = 1; | 
 | 231 | 	while (ecw > 0) { | 
 | 232 | 		cw <<= 1; | 
 | 233 | 		ecw--; | 
 | 234 | 	} | 
 | 235 | 	return cw - 1; | 
 | 236 | } | 
 | 237 |  | 
 | 238 |  | 
 | 239 | static void ieee80211_sta_wmm_params(struct net_device *dev, | 
 | 240 | 				     struct ieee80211_if_sta *ifsta, | 
 | 241 | 				     u8 *wmm_param, size_t wmm_param_len) | 
 | 242 | { | 
 | 243 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 244 | 	struct ieee80211_tx_queue_params params; | 
 | 245 | 	size_t left; | 
 | 246 | 	int count; | 
 | 247 | 	u8 *pos; | 
 | 248 |  | 
 | 249 | 	if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) | 
 | 250 | 		return; | 
 | 251 | 	count = wmm_param[6] & 0x0f; | 
 | 252 | 	if (count == ifsta->wmm_last_param_set) | 
 | 253 | 		return; | 
 | 254 | 	ifsta->wmm_last_param_set = count; | 
 | 255 |  | 
 | 256 | 	pos = wmm_param + 8; | 
 | 257 | 	left = wmm_param_len - 8; | 
 | 258 |  | 
 | 259 | 	memset(¶ms, 0, sizeof(params)); | 
 | 260 |  | 
 | 261 | 	if (!local->ops->conf_tx) | 
 | 262 | 		return; | 
 | 263 |  | 
 | 264 | 	local->wmm_acm = 0; | 
 | 265 | 	for (; left >= 4; left -= 4, pos += 4) { | 
 | 266 | 		int aci = (pos[0] >> 5) & 0x03; | 
 | 267 | 		int acm = (pos[0] >> 4) & 0x01; | 
 | 268 | 		int queue; | 
 | 269 |  | 
 | 270 | 		switch (aci) { | 
 | 271 | 		case 1: | 
 | 272 | 			queue = IEEE80211_TX_QUEUE_DATA3; | 
 | 273 | 			if (acm) { | 
 | 274 | 				local->wmm_acm |= BIT(0) | BIT(3); | 
 | 275 | 			} | 
 | 276 | 			break; | 
 | 277 | 		case 2: | 
 | 278 | 			queue = IEEE80211_TX_QUEUE_DATA1; | 
 | 279 | 			if (acm) { | 
 | 280 | 				local->wmm_acm |= BIT(4) | BIT(5); | 
 | 281 | 			} | 
 | 282 | 			break; | 
 | 283 | 		case 3: | 
 | 284 | 			queue = IEEE80211_TX_QUEUE_DATA0; | 
 | 285 | 			if (acm) { | 
 | 286 | 				local->wmm_acm |= BIT(6) | BIT(7); | 
 | 287 | 			} | 
 | 288 | 			break; | 
 | 289 | 		case 0: | 
 | 290 | 		default: | 
 | 291 | 			queue = IEEE80211_TX_QUEUE_DATA2; | 
 | 292 | 			if (acm) { | 
 | 293 | 				local->wmm_acm |= BIT(1) | BIT(2); | 
 | 294 | 			} | 
 | 295 | 			break; | 
 | 296 | 		} | 
 | 297 |  | 
 | 298 | 		params.aifs = pos[0] & 0x0f; | 
 | 299 | 		params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); | 
 | 300 | 		params.cw_min = ecw2cw(pos[1] & 0x0f); | 
 | 301 | 		/* TXOP is in units of 32 usec; burst_time in 0.1 ms */ | 
 | 302 | 		params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100; | 
 | 303 | 		printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " | 
 | 304 | 		       "cWmin=%d cWmax=%d burst=%d\n", | 
 | 305 | 		       dev->name, queue, aci, acm, params.aifs, params.cw_min, | 
 | 306 | 		       params.cw_max, params.burst_time); | 
 | 307 | 		/* TODO: handle ACM (block TX, fallback to next lowest allowed | 
 | 308 | 		 * AC for now) */ | 
 | 309 | 		if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) { | 
 | 310 | 			printk(KERN_DEBUG "%s: failed to set TX queue " | 
 | 311 | 			       "parameters for queue %d\n", dev->name, queue); | 
 | 312 | 		} | 
 | 313 | 	} | 
 | 314 | } | 
 | 315 |  | 
 | 316 |  | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 317 | static void ieee80211_handle_erp_ie(struct net_device *dev, u8 erp_value) | 
 | 318 | { | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 319 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 320 | 	struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 
 | 321 | 	int use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0; | 
 | 322 |  | 
| Daniel Drake | 63fc33c | 2007-07-10 19:32:11 +0200 | [diff] [blame] | 323 | 	if (use_protection != sdata->use_protection) { | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 324 | 		if (net_ratelimit()) { | 
 | 325 | 			printk(KERN_DEBUG "%s: CTS protection %s (BSSID=" | 
 | 326 | 			       MAC_FMT ")\n", | 
 | 327 | 			       dev->name, | 
 | 328 | 			       use_protection ? "enabled" : "disabled", | 
 | 329 | 			       MAC_ARG(ifsta->bssid)); | 
 | 330 | 		} | 
| Daniel Drake | 63fc33c | 2007-07-10 19:32:11 +0200 | [diff] [blame] | 331 | 		sdata->use_protection = use_protection; | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 332 | 	} | 
 | 333 | } | 
 | 334 |  | 
 | 335 |  | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 336 | static void ieee80211_sta_send_associnfo(struct net_device *dev, | 
 | 337 | 					 struct ieee80211_if_sta *ifsta) | 
 | 338 | { | 
 | 339 | 	char *buf; | 
 | 340 | 	size_t len; | 
 | 341 | 	int i; | 
 | 342 | 	union iwreq_data wrqu; | 
 | 343 |  | 
 | 344 | 	if (!ifsta->assocreq_ies && !ifsta->assocresp_ies) | 
 | 345 | 		return; | 
 | 346 |  | 
 | 347 | 	buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len + | 
 | 348 | 				ifsta->assocresp_ies_len), GFP_ATOMIC); | 
 | 349 | 	if (!buf) | 
 | 350 | 		return; | 
 | 351 |  | 
 | 352 | 	len = sprintf(buf, "ASSOCINFO("); | 
 | 353 | 	if (ifsta->assocreq_ies) { | 
 | 354 | 		len += sprintf(buf + len, "ReqIEs="); | 
 | 355 | 		for (i = 0; i < ifsta->assocreq_ies_len; i++) { | 
 | 356 | 			len += sprintf(buf + len, "%02x", | 
 | 357 | 				       ifsta->assocreq_ies[i]); | 
 | 358 | 		} | 
 | 359 | 	} | 
 | 360 | 	if (ifsta->assocresp_ies) { | 
 | 361 | 		if (ifsta->assocreq_ies) | 
 | 362 | 			len += sprintf(buf + len, " "); | 
 | 363 | 		len += sprintf(buf + len, "RespIEs="); | 
 | 364 | 		for (i = 0; i < ifsta->assocresp_ies_len; i++) { | 
 | 365 | 			len += sprintf(buf + len, "%02x", | 
 | 366 | 				       ifsta->assocresp_ies[i]); | 
 | 367 | 		} | 
 | 368 | 	} | 
 | 369 | 	len += sprintf(buf + len, ")"); | 
 | 370 |  | 
 | 371 | 	if (len > IW_CUSTOM_MAX) { | 
 | 372 | 		len = sprintf(buf, "ASSOCRESPIE="); | 
 | 373 | 		for (i = 0; i < ifsta->assocresp_ies_len; i++) { | 
 | 374 | 			len += sprintf(buf + len, "%02x", | 
 | 375 | 				       ifsta->assocresp_ies[i]); | 
 | 376 | 		} | 
 | 377 | 	} | 
 | 378 |  | 
 | 379 | 	memset(&wrqu, 0, sizeof(wrqu)); | 
 | 380 | 	wrqu.data.length = len; | 
 | 381 | 	wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); | 
 | 382 |  | 
 | 383 | 	kfree(buf); | 
 | 384 | } | 
 | 385 |  | 
 | 386 |  | 
 | 387 | static void ieee80211_set_associated(struct net_device *dev, | 
 | 388 | 				     struct ieee80211_if_sta *ifsta, int assoc) | 
 | 389 | { | 
 | 390 | 	union iwreq_data wrqu; | 
| Daniel Drake | 63fc33c | 2007-07-10 19:32:11 +0200 | [diff] [blame] | 391 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 392 |  | 
 | 393 | 	if (ifsta->associated == assoc) | 
 | 394 | 		return; | 
 | 395 |  | 
 | 396 | 	ifsta->associated = assoc; | 
 | 397 |  | 
 | 398 | 	if (assoc) { | 
 | 399 | 		struct ieee80211_sub_if_data *sdata; | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 400 | 		struct ieee80211_sta_bss *bss; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 401 | 		sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 402 | 		if (sdata->type != IEEE80211_IF_TYPE_STA) | 
 | 403 | 			return; | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 404 |  | 
 | 405 | 		bss = ieee80211_rx_bss_get(dev, ifsta->bssid); | 
 | 406 | 		if (bss) { | 
 | 407 | 			if (bss->has_erp_value) | 
 | 408 | 				ieee80211_handle_erp_ie(dev, bss->erp_value); | 
 | 409 | 			ieee80211_rx_bss_put(dev, bss); | 
 | 410 | 		} | 
 | 411 |  | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 412 | 		netif_carrier_on(dev); | 
 | 413 | 		ifsta->prev_bssid_set = 1; | 
 | 414 | 		memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN); | 
 | 415 | 		memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN); | 
 | 416 | 		ieee80211_sta_send_associnfo(dev, ifsta); | 
 | 417 | 	} else { | 
 | 418 | 		netif_carrier_off(dev); | 
| Daniel Drake | 63fc33c | 2007-07-10 19:32:11 +0200 | [diff] [blame] | 419 | 		sdata->use_protection = 0; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 420 | 		memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | 
 | 421 | 	} | 
 | 422 | 	wrqu.ap_addr.sa_family = ARPHRD_ETHER; | 
 | 423 | 	wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); | 
 | 424 | 	ifsta->last_probe = jiffies; | 
 | 425 | } | 
 | 426 |  | 
 | 427 | static void ieee80211_set_disassoc(struct net_device *dev, | 
 | 428 | 				   struct ieee80211_if_sta *ifsta, int deauth) | 
 | 429 | { | 
 | 430 | 	if (deauth) | 
 | 431 | 		ifsta->auth_tries = 0; | 
 | 432 | 	ifsta->assoc_tries = 0; | 
 | 433 | 	ieee80211_set_associated(dev, ifsta, 0); | 
 | 434 | } | 
 | 435 |  | 
 | 436 | static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb, | 
 | 437 | 			     int encrypt) | 
 | 438 | { | 
 | 439 | 	struct ieee80211_sub_if_data *sdata; | 
 | 440 | 	struct ieee80211_tx_packet_data *pkt_data; | 
 | 441 |  | 
 | 442 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 443 | 	skb->dev = sdata->local->mdev; | 
 | 444 | 	skb_set_mac_header(skb, 0); | 
 | 445 | 	skb_set_network_header(skb, 0); | 
 | 446 | 	skb_set_transport_header(skb, 0); | 
 | 447 |  | 
 | 448 | 	pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; | 
 | 449 | 	memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data)); | 
 | 450 | 	pkt_data->ifindex = sdata->dev->ifindex; | 
 | 451 | 	pkt_data->mgmt_iface = (sdata->type == IEEE80211_IF_TYPE_MGMT); | 
 | 452 | 	pkt_data->do_not_encrypt = !encrypt; | 
 | 453 |  | 
 | 454 | 	dev_queue_xmit(skb); | 
 | 455 | } | 
 | 456 |  | 
 | 457 |  | 
 | 458 | static void ieee80211_send_auth(struct net_device *dev, | 
 | 459 | 				struct ieee80211_if_sta *ifsta, | 
 | 460 | 				int transaction, u8 *extra, size_t extra_len, | 
 | 461 | 				int encrypt) | 
 | 462 | { | 
 | 463 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 464 | 	struct sk_buff *skb; | 
 | 465 | 	struct ieee80211_mgmt *mgmt; | 
 | 466 |  | 
 | 467 | 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + | 
 | 468 | 			    sizeof(*mgmt) + 6 + extra_len); | 
 | 469 | 	if (!skb) { | 
 | 470 | 		printk(KERN_DEBUG "%s: failed to allocate buffer for auth " | 
 | 471 | 		       "frame\n", dev->name); | 
 | 472 | 		return; | 
 | 473 | 	} | 
 | 474 | 	skb_reserve(skb, local->hw.extra_tx_headroom); | 
 | 475 |  | 
 | 476 | 	mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); | 
 | 477 | 	memset(mgmt, 0, 24 + 6); | 
 | 478 | 	mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, | 
 | 479 | 					   IEEE80211_STYPE_AUTH); | 
 | 480 | 	if (encrypt) | 
 | 481 | 		mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | 
 | 482 | 	memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | 
 | 483 | 	memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); | 
 | 484 | 	memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | 
 | 485 | 	mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg); | 
 | 486 | 	mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); | 
 | 487 | 	ifsta->auth_transaction = transaction + 1; | 
 | 488 | 	mgmt->u.auth.status_code = cpu_to_le16(0); | 
 | 489 | 	if (extra) | 
 | 490 | 		memcpy(skb_put(skb, extra_len), extra, extra_len); | 
 | 491 |  | 
 | 492 | 	ieee80211_sta_tx(dev, skb, encrypt); | 
 | 493 | } | 
 | 494 |  | 
 | 495 |  | 
 | 496 | static void ieee80211_authenticate(struct net_device *dev, | 
 | 497 | 				   struct ieee80211_if_sta *ifsta) | 
 | 498 | { | 
 | 499 | 	ifsta->auth_tries++; | 
 | 500 | 	if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) { | 
 | 501 | 		printk(KERN_DEBUG "%s: authentication with AP " MAC_FMT | 
 | 502 | 		       " timed out\n", | 
 | 503 | 		       dev->name, MAC_ARG(ifsta->bssid)); | 
 | 504 | 		ifsta->state = IEEE80211_DISABLED; | 
 | 505 | 		return; | 
 | 506 | 	} | 
 | 507 |  | 
 | 508 | 	ifsta->state = IEEE80211_AUTHENTICATE; | 
 | 509 | 	printk(KERN_DEBUG "%s: authenticate with AP " MAC_FMT "\n", | 
 | 510 | 	       dev->name, MAC_ARG(ifsta->bssid)); | 
 | 511 |  | 
 | 512 | 	ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0); | 
 | 513 |  | 
 | 514 | 	mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); | 
 | 515 | } | 
 | 516 |  | 
 | 517 |  | 
 | 518 | static void ieee80211_send_assoc(struct net_device *dev, | 
 | 519 | 				 struct ieee80211_if_sta *ifsta) | 
 | 520 | { | 
 | 521 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 522 | 	struct ieee80211_hw_mode *mode; | 
 | 523 | 	struct sk_buff *skb; | 
 | 524 | 	struct ieee80211_mgmt *mgmt; | 
 | 525 | 	u8 *pos, *ies; | 
 | 526 | 	int i, len; | 
 | 527 | 	u16 capab; | 
 | 528 | 	struct ieee80211_sta_bss *bss; | 
 | 529 | 	int wmm = 0; | 
 | 530 |  | 
 | 531 | 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + | 
 | 532 | 			    sizeof(*mgmt) + 200 + ifsta->extra_ie_len + | 
 | 533 | 			    ifsta->ssid_len); | 
 | 534 | 	if (!skb) { | 
 | 535 | 		printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " | 
 | 536 | 		       "frame\n", dev->name); | 
 | 537 | 		return; | 
 | 538 | 	} | 
 | 539 | 	skb_reserve(skb, local->hw.extra_tx_headroom); | 
 | 540 |  | 
 | 541 | 	mode = local->oper_hw_mode; | 
 | 542 | 	capab = ifsta->capab; | 
 | 543 | 	if (mode->mode == MODE_IEEE80211G) { | 
 | 544 | 		capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME | | 
 | 545 | 			WLAN_CAPABILITY_SHORT_PREAMBLE; | 
 | 546 | 	} | 
 | 547 | 	bss = ieee80211_rx_bss_get(dev, ifsta->bssid); | 
 | 548 | 	if (bss) { | 
 | 549 | 		if (bss->capability & WLAN_CAPABILITY_PRIVACY) | 
 | 550 | 			capab |= WLAN_CAPABILITY_PRIVACY; | 
 | 551 | 		if (bss->wmm_ie) { | 
 | 552 | 			wmm = 1; | 
 | 553 | 		} | 
 | 554 | 		ieee80211_rx_bss_put(dev, bss); | 
 | 555 | 	} | 
 | 556 |  | 
 | 557 | 	mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | 
 | 558 | 	memset(mgmt, 0, 24); | 
 | 559 | 	memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | 
 | 560 | 	memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); | 
 | 561 | 	memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | 
 | 562 |  | 
 | 563 | 	if (ifsta->prev_bssid_set) { | 
 | 564 | 		skb_put(skb, 10); | 
 | 565 | 		mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, | 
 | 566 | 						   IEEE80211_STYPE_REASSOC_REQ); | 
 | 567 | 		mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); | 
 | 568 | 		mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1); | 
 | 569 | 		memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid, | 
 | 570 | 		       ETH_ALEN); | 
 | 571 | 	} else { | 
 | 572 | 		skb_put(skb, 4); | 
 | 573 | 		mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, | 
 | 574 | 						   IEEE80211_STYPE_ASSOC_REQ); | 
 | 575 | 		mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); | 
 | 576 | 		mgmt->u.assoc_req.listen_interval = cpu_to_le16(1); | 
 | 577 | 	} | 
 | 578 |  | 
 | 579 | 	/* SSID */ | 
 | 580 | 	ies = pos = skb_put(skb, 2 + ifsta->ssid_len); | 
 | 581 | 	*pos++ = WLAN_EID_SSID; | 
 | 582 | 	*pos++ = ifsta->ssid_len; | 
 | 583 | 	memcpy(pos, ifsta->ssid, ifsta->ssid_len); | 
 | 584 |  | 
 | 585 | 	len = mode->num_rates; | 
 | 586 | 	if (len > 8) | 
 | 587 | 		len = 8; | 
 | 588 | 	pos = skb_put(skb, len + 2); | 
 | 589 | 	*pos++ = WLAN_EID_SUPP_RATES; | 
 | 590 | 	*pos++ = len; | 
 | 591 | 	for (i = 0; i < len; i++) { | 
 | 592 | 		int rate = mode->rates[i].rate; | 
 | 593 | 		if (mode->mode == MODE_ATHEROS_TURBO) | 
 | 594 | 			rate /= 2; | 
 | 595 | 		*pos++ = (u8) (rate / 5); | 
 | 596 | 	} | 
 | 597 |  | 
 | 598 | 	if (mode->num_rates > len) { | 
 | 599 | 		pos = skb_put(skb, mode->num_rates - len + 2); | 
 | 600 | 		*pos++ = WLAN_EID_EXT_SUPP_RATES; | 
 | 601 | 		*pos++ = mode->num_rates - len; | 
 | 602 | 		for (i = len; i < mode->num_rates; i++) { | 
 | 603 | 			int rate = mode->rates[i].rate; | 
 | 604 | 			if (mode->mode == MODE_ATHEROS_TURBO) | 
 | 605 | 				rate /= 2; | 
 | 606 | 			*pos++ = (u8) (rate / 5); | 
 | 607 | 		} | 
 | 608 | 	} | 
 | 609 |  | 
 | 610 | 	if (ifsta->extra_ie) { | 
 | 611 | 		pos = skb_put(skb, ifsta->extra_ie_len); | 
 | 612 | 		memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len); | 
 | 613 | 	} | 
 | 614 |  | 
 | 615 | 	if (wmm && ifsta->wmm_enabled) { | 
 | 616 | 		pos = skb_put(skb, 9); | 
 | 617 | 		*pos++ = WLAN_EID_VENDOR_SPECIFIC; | 
 | 618 | 		*pos++ = 7; /* len */ | 
 | 619 | 		*pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ | 
 | 620 | 		*pos++ = 0x50; | 
 | 621 | 		*pos++ = 0xf2; | 
 | 622 | 		*pos++ = 2; /* WME */ | 
 | 623 | 		*pos++ = 0; /* WME info */ | 
 | 624 | 		*pos++ = 1; /* WME ver */ | 
 | 625 | 		*pos++ = 0; | 
 | 626 | 	} | 
 | 627 |  | 
 | 628 | 	kfree(ifsta->assocreq_ies); | 
 | 629 | 	ifsta->assocreq_ies_len = (skb->data + skb->len) - ies; | 
 | 630 | 	ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_ATOMIC); | 
 | 631 | 	if (ifsta->assocreq_ies) | 
 | 632 | 		memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len); | 
 | 633 |  | 
 | 634 | 	ieee80211_sta_tx(dev, skb, 0); | 
 | 635 | } | 
 | 636 |  | 
 | 637 |  | 
 | 638 | static void ieee80211_send_deauth(struct net_device *dev, | 
 | 639 | 				  struct ieee80211_if_sta *ifsta, u16 reason) | 
 | 640 | { | 
 | 641 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 642 | 	struct sk_buff *skb; | 
 | 643 | 	struct ieee80211_mgmt *mgmt; | 
 | 644 |  | 
 | 645 | 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); | 
 | 646 | 	if (!skb) { | 
 | 647 | 		printk(KERN_DEBUG "%s: failed to allocate buffer for deauth " | 
 | 648 | 		       "frame\n", dev->name); | 
 | 649 | 		return; | 
 | 650 | 	} | 
 | 651 | 	skb_reserve(skb, local->hw.extra_tx_headroom); | 
 | 652 |  | 
 | 653 | 	mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | 
 | 654 | 	memset(mgmt, 0, 24); | 
 | 655 | 	memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | 
 | 656 | 	memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); | 
 | 657 | 	memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | 
 | 658 | 	mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, | 
 | 659 | 					   IEEE80211_STYPE_DEAUTH); | 
 | 660 | 	skb_put(skb, 2); | 
 | 661 | 	mgmt->u.deauth.reason_code = cpu_to_le16(reason); | 
 | 662 |  | 
 | 663 | 	ieee80211_sta_tx(dev, skb, 0); | 
 | 664 | } | 
 | 665 |  | 
 | 666 |  | 
 | 667 | static void ieee80211_send_disassoc(struct net_device *dev, | 
 | 668 | 				    struct ieee80211_if_sta *ifsta, u16 reason) | 
 | 669 | { | 
 | 670 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 671 | 	struct sk_buff *skb; | 
 | 672 | 	struct ieee80211_mgmt *mgmt; | 
 | 673 |  | 
 | 674 | 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); | 
 | 675 | 	if (!skb) { | 
 | 676 | 		printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc " | 
 | 677 | 		       "frame\n", dev->name); | 
 | 678 | 		return; | 
 | 679 | 	} | 
 | 680 | 	skb_reserve(skb, local->hw.extra_tx_headroom); | 
 | 681 |  | 
 | 682 | 	mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | 
 | 683 | 	memset(mgmt, 0, 24); | 
 | 684 | 	memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); | 
 | 685 | 	memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); | 
 | 686 | 	memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | 
 | 687 | 	mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, | 
 | 688 | 					   IEEE80211_STYPE_DISASSOC); | 
 | 689 | 	skb_put(skb, 2); | 
 | 690 | 	mgmt->u.disassoc.reason_code = cpu_to_le16(reason); | 
 | 691 |  | 
 | 692 | 	ieee80211_sta_tx(dev, skb, 0); | 
 | 693 | } | 
 | 694 |  | 
 | 695 |  | 
 | 696 | static int ieee80211_privacy_mismatch(struct net_device *dev, | 
 | 697 | 				      struct ieee80211_if_sta *ifsta) | 
 | 698 | { | 
 | 699 | 	struct ieee80211_sta_bss *bss; | 
 | 700 | 	int res = 0; | 
 | 701 |  | 
 | 702 | 	if (!ifsta || ifsta->mixed_cell || | 
 | 703 | 	    ifsta->key_mgmt != IEEE80211_KEY_MGMT_NONE) | 
 | 704 | 		return 0; | 
 | 705 |  | 
 | 706 | 	bss = ieee80211_rx_bss_get(dev, ifsta->bssid); | 
 | 707 | 	if (!bss) | 
 | 708 | 		return 0; | 
 | 709 |  | 
 | 710 | 	if (ieee80211_sta_wep_configured(dev) != | 
 | 711 | 	    !!(bss->capability & WLAN_CAPABILITY_PRIVACY)) | 
 | 712 | 		res = 1; | 
 | 713 |  | 
 | 714 | 	ieee80211_rx_bss_put(dev, bss); | 
 | 715 |  | 
 | 716 | 	return res; | 
 | 717 | } | 
 | 718 |  | 
 | 719 |  | 
 | 720 | static void ieee80211_associate(struct net_device *dev, | 
 | 721 | 				struct ieee80211_if_sta *ifsta) | 
 | 722 | { | 
 | 723 | 	ifsta->assoc_tries++; | 
 | 724 | 	if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { | 
 | 725 | 		printk(KERN_DEBUG "%s: association with AP " MAC_FMT | 
 | 726 | 		       " timed out\n", | 
 | 727 | 		       dev->name, MAC_ARG(ifsta->bssid)); | 
 | 728 | 		ifsta->state = IEEE80211_DISABLED; | 
 | 729 | 		return; | 
 | 730 | 	} | 
 | 731 |  | 
 | 732 | 	ifsta->state = IEEE80211_ASSOCIATE; | 
 | 733 | 	printk(KERN_DEBUG "%s: associate with AP " MAC_FMT "\n", | 
 | 734 | 	       dev->name, MAC_ARG(ifsta->bssid)); | 
 | 735 | 	if (ieee80211_privacy_mismatch(dev, ifsta)) { | 
 | 736 | 		printk(KERN_DEBUG "%s: mismatch in privacy configuration and " | 
 | 737 | 		       "mixed-cell disabled - abort association\n", dev->name); | 
 | 738 | 		ifsta->state = IEEE80211_DISABLED; | 
 | 739 | 		return; | 
 | 740 | 	} | 
 | 741 |  | 
 | 742 | 	ieee80211_send_assoc(dev, ifsta); | 
 | 743 |  | 
 | 744 | 	mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); | 
 | 745 | } | 
 | 746 |  | 
 | 747 |  | 
 | 748 | static void ieee80211_associated(struct net_device *dev, | 
 | 749 | 				 struct ieee80211_if_sta *ifsta) | 
 | 750 | { | 
 | 751 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 752 | 	struct sta_info *sta; | 
 | 753 | 	int disassoc; | 
 | 754 |  | 
 | 755 | 	/* TODO: start monitoring current AP signal quality and number of | 
 | 756 | 	 * missed beacons. Scan other channels every now and then and search | 
 | 757 | 	 * for better APs. */ | 
 | 758 | 	/* TODO: remove expired BSSes */ | 
 | 759 |  | 
 | 760 | 	ifsta->state = IEEE80211_ASSOCIATED; | 
 | 761 |  | 
 | 762 | 	sta = sta_info_get(local, ifsta->bssid); | 
 | 763 | 	if (!sta) { | 
 | 764 | 		printk(KERN_DEBUG "%s: No STA entry for own AP " MAC_FMT "\n", | 
 | 765 | 		       dev->name, MAC_ARG(ifsta->bssid)); | 
 | 766 | 		disassoc = 1; | 
 | 767 | 	} else { | 
 | 768 | 		disassoc = 0; | 
 | 769 | 		if (time_after(jiffies, | 
 | 770 | 			       sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { | 
 | 771 | 			if (ifsta->probereq_poll) { | 
 | 772 | 				printk(KERN_DEBUG "%s: No ProbeResp from " | 
 | 773 | 				       "current AP " MAC_FMT " - assume out of " | 
 | 774 | 				       "range\n", | 
 | 775 | 				       dev->name, MAC_ARG(ifsta->bssid)); | 
 | 776 | 				disassoc = 1; | 
 | 777 | 				sta_info_free(sta, 0); | 
 | 778 | 				ifsta->probereq_poll = 0; | 
 | 779 | 			} else { | 
 | 780 | 				ieee80211_send_probe_req(dev, ifsta->bssid, | 
 | 781 | 							 local->scan_ssid, | 
 | 782 | 							 local->scan_ssid_len); | 
 | 783 | 				ifsta->probereq_poll = 1; | 
 | 784 | 			} | 
 | 785 | 		} else { | 
 | 786 | 			ifsta->probereq_poll = 0; | 
 | 787 | 			if (time_after(jiffies, ifsta->last_probe + | 
 | 788 | 				       IEEE80211_PROBE_INTERVAL)) { | 
 | 789 | 				ifsta->last_probe = jiffies; | 
 | 790 | 				ieee80211_send_probe_req(dev, ifsta->bssid, | 
 | 791 | 							 ifsta->ssid, | 
 | 792 | 							 ifsta->ssid_len); | 
 | 793 | 			} | 
 | 794 | 		} | 
 | 795 | 		sta_info_put(sta); | 
 | 796 | 	} | 
 | 797 | 	if (disassoc) { | 
 | 798 | 		union iwreq_data wrqu; | 
 | 799 | 		memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | 
 | 800 | 		wrqu.ap_addr.sa_family = ARPHRD_ETHER; | 
 | 801 | 		wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); | 
 | 802 | 		mod_timer(&ifsta->timer, jiffies + | 
 | 803 | 				      IEEE80211_MONITORING_INTERVAL + 30 * HZ); | 
 | 804 | 	} else { | 
 | 805 | 		mod_timer(&ifsta->timer, jiffies + | 
 | 806 | 				      IEEE80211_MONITORING_INTERVAL); | 
 | 807 | 	} | 
 | 808 | } | 
 | 809 |  | 
 | 810 |  | 
 | 811 | static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst, | 
 | 812 | 				     u8 *ssid, size_t ssid_len) | 
 | 813 | { | 
 | 814 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 815 | 	struct ieee80211_hw_mode *mode; | 
 | 816 | 	struct sk_buff *skb; | 
 | 817 | 	struct ieee80211_mgmt *mgmt; | 
 | 818 | 	u8 *pos, *supp_rates, *esupp_rates = NULL; | 
 | 819 | 	int i; | 
 | 820 |  | 
 | 821 | 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200); | 
 | 822 | 	if (!skb) { | 
 | 823 | 		printk(KERN_DEBUG "%s: failed to allocate buffer for probe " | 
 | 824 | 		       "request\n", dev->name); | 
 | 825 | 		return; | 
 | 826 | 	} | 
 | 827 | 	skb_reserve(skb, local->hw.extra_tx_headroom); | 
 | 828 |  | 
 | 829 | 	mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | 
 | 830 | 	memset(mgmt, 0, 24); | 
 | 831 | 	mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, | 
 | 832 | 					   IEEE80211_STYPE_PROBE_REQ); | 
 | 833 | 	memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); | 
 | 834 | 	if (dst) { | 
 | 835 | 		memcpy(mgmt->da, dst, ETH_ALEN); | 
 | 836 | 		memcpy(mgmt->bssid, dst, ETH_ALEN); | 
 | 837 | 	} else { | 
 | 838 | 		memset(mgmt->da, 0xff, ETH_ALEN); | 
 | 839 | 		memset(mgmt->bssid, 0xff, ETH_ALEN); | 
 | 840 | 	} | 
 | 841 | 	pos = skb_put(skb, 2 + ssid_len); | 
 | 842 | 	*pos++ = WLAN_EID_SSID; | 
 | 843 | 	*pos++ = ssid_len; | 
 | 844 | 	memcpy(pos, ssid, ssid_len); | 
 | 845 |  | 
 | 846 | 	supp_rates = skb_put(skb, 2); | 
 | 847 | 	supp_rates[0] = WLAN_EID_SUPP_RATES; | 
 | 848 | 	supp_rates[1] = 0; | 
 | 849 | 	mode = local->oper_hw_mode; | 
 | 850 | 	for (i = 0; i < mode->num_rates; i++) { | 
 | 851 | 		struct ieee80211_rate *rate = &mode->rates[i]; | 
 | 852 | 		if (!(rate->flags & IEEE80211_RATE_SUPPORTED)) | 
 | 853 | 			continue; | 
 | 854 | 		if (esupp_rates) { | 
 | 855 | 			pos = skb_put(skb, 1); | 
 | 856 | 			esupp_rates[1]++; | 
 | 857 | 		} else if (supp_rates[1] == 8) { | 
 | 858 | 			esupp_rates = skb_put(skb, 3); | 
 | 859 | 			esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES; | 
 | 860 | 			esupp_rates[1] = 1; | 
 | 861 | 			pos = &esupp_rates[2]; | 
 | 862 | 		} else { | 
 | 863 | 			pos = skb_put(skb, 1); | 
 | 864 | 			supp_rates[1]++; | 
 | 865 | 		} | 
 | 866 | 		if (mode->mode == MODE_ATHEROS_TURBO) | 
 | 867 | 			*pos = rate->rate / 10; | 
 | 868 | 		else | 
 | 869 | 			*pos = rate->rate / 5; | 
 | 870 | 	} | 
 | 871 |  | 
 | 872 | 	ieee80211_sta_tx(dev, skb, 0); | 
 | 873 | } | 
 | 874 |  | 
 | 875 |  | 
 | 876 | static int ieee80211_sta_wep_configured(struct net_device *dev) | 
 | 877 | { | 
 | 878 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 879 | 	if (!sdata || !sdata->default_key || | 
 | 880 | 	    sdata->default_key->alg != ALG_WEP) | 
 | 881 | 		return 0; | 
 | 882 | 	return 1; | 
 | 883 | } | 
 | 884 |  | 
 | 885 |  | 
 | 886 | static void ieee80211_auth_completed(struct net_device *dev, | 
 | 887 | 				     struct ieee80211_if_sta *ifsta) | 
 | 888 | { | 
 | 889 | 	printk(KERN_DEBUG "%s: authenticated\n", dev->name); | 
 | 890 | 	ifsta->authenticated = 1; | 
 | 891 | 	ieee80211_associate(dev, ifsta); | 
 | 892 | } | 
 | 893 |  | 
 | 894 |  | 
 | 895 | static void ieee80211_auth_challenge(struct net_device *dev, | 
 | 896 | 				     struct ieee80211_if_sta *ifsta, | 
 | 897 | 				     struct ieee80211_mgmt *mgmt, | 
 | 898 | 				     size_t len) | 
 | 899 | { | 
 | 900 | 	u8 *pos; | 
 | 901 | 	struct ieee802_11_elems elems; | 
 | 902 |  | 
 | 903 | 	printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name); | 
 | 904 | 	pos = mgmt->u.auth.variable; | 
 | 905 | 	if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems) | 
 | 906 | 	    == ParseFailed) { | 
 | 907 | 		printk(KERN_DEBUG "%s: failed to parse Auth(challenge)\n", | 
 | 908 | 		       dev->name); | 
 | 909 | 		return; | 
 | 910 | 	} | 
 | 911 | 	if (!elems.challenge) { | 
 | 912 | 		printk(KERN_DEBUG "%s: no challenge IE in shared key auth " | 
 | 913 | 		       "frame\n", dev->name); | 
 | 914 | 		return; | 
 | 915 | 	} | 
 | 916 | 	ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2, | 
 | 917 | 			    elems.challenge_len + 2, 1); | 
 | 918 | } | 
 | 919 |  | 
 | 920 |  | 
 | 921 | static void ieee80211_rx_mgmt_auth(struct net_device *dev, | 
 | 922 | 				   struct ieee80211_if_sta *ifsta, | 
 | 923 | 				   struct ieee80211_mgmt *mgmt, | 
 | 924 | 				   size_t len) | 
 | 925 | { | 
 | 926 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 927 | 	u16 auth_alg, auth_transaction, status_code; | 
 | 928 |  | 
 | 929 | 	if (ifsta->state != IEEE80211_AUTHENTICATE && | 
 | 930 | 	    sdata->type != IEEE80211_IF_TYPE_IBSS) { | 
 | 931 | 		printk(KERN_DEBUG "%s: authentication frame received from " | 
 | 932 | 		       MAC_FMT ", but not in authenticate state - ignored\n", | 
 | 933 | 		       dev->name, MAC_ARG(mgmt->sa)); | 
 | 934 | 		return; | 
 | 935 | 	} | 
 | 936 |  | 
 | 937 | 	if (len < 24 + 6) { | 
 | 938 | 		printk(KERN_DEBUG "%s: too short (%zd) authentication frame " | 
 | 939 | 		       "received from " MAC_FMT " - ignored\n", | 
 | 940 | 		       dev->name, len, MAC_ARG(mgmt->sa)); | 
 | 941 | 		return; | 
 | 942 | 	} | 
 | 943 |  | 
 | 944 | 	if (sdata->type != IEEE80211_IF_TYPE_IBSS && | 
 | 945 | 	    memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { | 
 | 946 | 		printk(KERN_DEBUG "%s: authentication frame received from " | 
 | 947 | 		       "unknown AP (SA=" MAC_FMT " BSSID=" MAC_FMT ") - " | 
 | 948 | 		       "ignored\n", dev->name, MAC_ARG(mgmt->sa), | 
 | 949 | 		       MAC_ARG(mgmt->bssid)); | 
 | 950 | 		return; | 
 | 951 | 	} | 
 | 952 |  | 
 | 953 | 	if (sdata->type != IEEE80211_IF_TYPE_IBSS && | 
 | 954 | 	    memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) { | 
 | 955 | 		printk(KERN_DEBUG "%s: authentication frame received from " | 
 | 956 | 		       "unknown BSSID (SA=" MAC_FMT " BSSID=" MAC_FMT ") - " | 
 | 957 | 		       "ignored\n", dev->name, MAC_ARG(mgmt->sa), | 
 | 958 | 		       MAC_ARG(mgmt->bssid)); | 
 | 959 | 		return; | 
 | 960 | 	} | 
 | 961 |  | 
 | 962 | 	auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); | 
 | 963 | 	auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); | 
 | 964 | 	status_code = le16_to_cpu(mgmt->u.auth.status_code); | 
 | 965 |  | 
 | 966 | 	printk(KERN_DEBUG "%s: RX authentication from " MAC_FMT " (alg=%d " | 
 | 967 | 	       "transaction=%d status=%d)\n", | 
 | 968 | 	       dev->name, MAC_ARG(mgmt->sa), auth_alg, | 
 | 969 | 	       auth_transaction, status_code); | 
 | 970 |  | 
 | 971 | 	if (sdata->type == IEEE80211_IF_TYPE_IBSS) { | 
 | 972 | 		/* IEEE 802.11 standard does not require authentication in IBSS | 
 | 973 | 		 * networks and most implementations do not seem to use it. | 
 | 974 | 		 * However, try to reply to authentication attempts if someone | 
 | 975 | 		 * has actually implemented this. | 
 | 976 | 		 * TODO: Could implement shared key authentication. */ | 
 | 977 | 		if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) { | 
 | 978 | 			printk(KERN_DEBUG "%s: unexpected IBSS authentication " | 
 | 979 | 			       "frame (alg=%d transaction=%d)\n", | 
 | 980 | 			       dev->name, auth_alg, auth_transaction); | 
 | 981 | 			return; | 
 | 982 | 		} | 
 | 983 | 		ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0); | 
 | 984 | 	} | 
 | 985 |  | 
 | 986 | 	if (auth_alg != ifsta->auth_alg || | 
 | 987 | 	    auth_transaction != ifsta->auth_transaction) { | 
 | 988 | 		printk(KERN_DEBUG "%s: unexpected authentication frame " | 
 | 989 | 		       "(alg=%d transaction=%d)\n", | 
 | 990 | 		       dev->name, auth_alg, auth_transaction); | 
 | 991 | 		return; | 
 | 992 | 	} | 
 | 993 |  | 
 | 994 | 	if (status_code != WLAN_STATUS_SUCCESS) { | 
 | 995 | 		printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d " | 
 | 996 | 		       "code=%d)\n", dev->name, ifsta->auth_alg, status_code); | 
 | 997 | 		if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { | 
 | 998 | 			u8 algs[3]; | 
 | 999 | 			const int num_algs = ARRAY_SIZE(algs); | 
 | 1000 | 			int i, pos; | 
 | 1001 | 			algs[0] = algs[1] = algs[2] = 0xff; | 
 | 1002 | 			if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) | 
 | 1003 | 				algs[0] = WLAN_AUTH_OPEN; | 
 | 1004 | 			if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) | 
 | 1005 | 				algs[1] = WLAN_AUTH_SHARED_KEY; | 
 | 1006 | 			if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) | 
 | 1007 | 				algs[2] = WLAN_AUTH_LEAP; | 
 | 1008 | 			if (ifsta->auth_alg == WLAN_AUTH_OPEN) | 
 | 1009 | 				pos = 0; | 
 | 1010 | 			else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY) | 
 | 1011 | 				pos = 1; | 
 | 1012 | 			else | 
 | 1013 | 				pos = 2; | 
 | 1014 | 			for (i = 0; i < num_algs; i++) { | 
 | 1015 | 				pos++; | 
 | 1016 | 				if (pos >= num_algs) | 
 | 1017 | 					pos = 0; | 
 | 1018 | 				if (algs[pos] == ifsta->auth_alg || | 
 | 1019 | 				    algs[pos] == 0xff) | 
 | 1020 | 					continue; | 
 | 1021 | 				if (algs[pos] == WLAN_AUTH_SHARED_KEY && | 
 | 1022 | 				    !ieee80211_sta_wep_configured(dev)) | 
 | 1023 | 					continue; | 
 | 1024 | 				ifsta->auth_alg = algs[pos]; | 
 | 1025 | 				printk(KERN_DEBUG "%s: set auth_alg=%d for " | 
 | 1026 | 				       "next try\n", | 
 | 1027 | 				       dev->name, ifsta->auth_alg); | 
 | 1028 | 				break; | 
 | 1029 | 			} | 
 | 1030 | 		} | 
 | 1031 | 		return; | 
 | 1032 | 	} | 
 | 1033 |  | 
 | 1034 | 	switch (ifsta->auth_alg) { | 
 | 1035 | 	case WLAN_AUTH_OPEN: | 
 | 1036 | 	case WLAN_AUTH_LEAP: | 
 | 1037 | 		ieee80211_auth_completed(dev, ifsta); | 
 | 1038 | 		break; | 
 | 1039 | 	case WLAN_AUTH_SHARED_KEY: | 
 | 1040 | 		if (ifsta->auth_transaction == 4) | 
 | 1041 | 			ieee80211_auth_completed(dev, ifsta); | 
 | 1042 | 		else | 
 | 1043 | 			ieee80211_auth_challenge(dev, ifsta, mgmt, len); | 
 | 1044 | 		break; | 
 | 1045 | 	} | 
 | 1046 | } | 
 | 1047 |  | 
 | 1048 |  | 
 | 1049 | static void ieee80211_rx_mgmt_deauth(struct net_device *dev, | 
 | 1050 | 				     struct ieee80211_if_sta *ifsta, | 
 | 1051 | 				     struct ieee80211_mgmt *mgmt, | 
 | 1052 | 				     size_t len) | 
 | 1053 | { | 
 | 1054 | 	u16 reason_code; | 
 | 1055 |  | 
 | 1056 | 	if (len < 24 + 2) { | 
 | 1057 | 		printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame " | 
 | 1058 | 		       "received from " MAC_FMT " - ignored\n", | 
 | 1059 | 		       dev->name, len, MAC_ARG(mgmt->sa)); | 
 | 1060 | 		return; | 
 | 1061 | 	} | 
 | 1062 |  | 
 | 1063 | 	if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { | 
 | 1064 | 		printk(KERN_DEBUG "%s: deauthentication frame received from " | 
 | 1065 | 		       "unknown AP (SA=" MAC_FMT " BSSID=" MAC_FMT ") - " | 
 | 1066 | 		       "ignored\n", dev->name, MAC_ARG(mgmt->sa), | 
 | 1067 | 		       MAC_ARG(mgmt->bssid)); | 
 | 1068 | 		return; | 
 | 1069 | 	} | 
 | 1070 |  | 
 | 1071 | 	reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); | 
 | 1072 |  | 
 | 1073 | 	printk(KERN_DEBUG "%s: RX deauthentication from " MAC_FMT | 
 | 1074 | 	       " (reason=%d)\n", | 
 | 1075 | 	       dev->name, MAC_ARG(mgmt->sa), reason_code); | 
 | 1076 |  | 
 | 1077 | 	if (ifsta->authenticated) { | 
 | 1078 | 		printk(KERN_DEBUG "%s: deauthenticated\n", dev->name); | 
 | 1079 | 	} | 
 | 1080 |  | 
 | 1081 | 	if (ifsta->state == IEEE80211_AUTHENTICATE || | 
 | 1082 | 	    ifsta->state == IEEE80211_ASSOCIATE || | 
 | 1083 | 	    ifsta->state == IEEE80211_ASSOCIATED) { | 
 | 1084 | 		ifsta->state = IEEE80211_AUTHENTICATE; | 
 | 1085 | 		mod_timer(&ifsta->timer, jiffies + | 
 | 1086 | 				      IEEE80211_RETRY_AUTH_INTERVAL); | 
 | 1087 | 	} | 
 | 1088 |  | 
 | 1089 | 	ieee80211_set_disassoc(dev, ifsta, 1); | 
 | 1090 | 	ifsta->authenticated = 0; | 
 | 1091 | } | 
 | 1092 |  | 
 | 1093 |  | 
 | 1094 | static void ieee80211_rx_mgmt_disassoc(struct net_device *dev, | 
 | 1095 | 				       struct ieee80211_if_sta *ifsta, | 
 | 1096 | 				       struct ieee80211_mgmt *mgmt, | 
 | 1097 | 				       size_t len) | 
 | 1098 | { | 
 | 1099 | 	u16 reason_code; | 
 | 1100 |  | 
 | 1101 | 	if (len < 24 + 2) { | 
 | 1102 | 		printk(KERN_DEBUG "%s: too short (%zd) disassociation frame " | 
 | 1103 | 		       "received from " MAC_FMT " - ignored\n", | 
 | 1104 | 		       dev->name, len, MAC_ARG(mgmt->sa)); | 
 | 1105 | 		return; | 
 | 1106 | 	} | 
 | 1107 |  | 
 | 1108 | 	if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { | 
 | 1109 | 		printk(KERN_DEBUG "%s: disassociation frame received from " | 
 | 1110 | 		       "unknown AP (SA=" MAC_FMT " BSSID=" MAC_FMT ") - " | 
 | 1111 | 		       "ignored\n", dev->name, MAC_ARG(mgmt->sa), | 
 | 1112 | 		       MAC_ARG(mgmt->bssid)); | 
 | 1113 | 		return; | 
 | 1114 | 	} | 
 | 1115 |  | 
 | 1116 | 	reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); | 
 | 1117 |  | 
 | 1118 | 	printk(KERN_DEBUG "%s: RX disassociation from " MAC_FMT | 
 | 1119 | 	       " (reason=%d)\n", | 
 | 1120 | 	       dev->name, MAC_ARG(mgmt->sa), reason_code); | 
 | 1121 |  | 
 | 1122 | 	if (ifsta->associated) | 
 | 1123 | 		printk(KERN_DEBUG "%s: disassociated\n", dev->name); | 
 | 1124 |  | 
 | 1125 | 	if (ifsta->state == IEEE80211_ASSOCIATED) { | 
 | 1126 | 		ifsta->state = IEEE80211_ASSOCIATE; | 
 | 1127 | 		mod_timer(&ifsta->timer, jiffies + | 
 | 1128 | 				      IEEE80211_RETRY_AUTH_INTERVAL); | 
 | 1129 | 	} | 
 | 1130 |  | 
 | 1131 | 	ieee80211_set_disassoc(dev, ifsta, 0); | 
 | 1132 | } | 
 | 1133 |  | 
 | 1134 |  | 
 | 1135 | static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev, | 
 | 1136 | 					 struct ieee80211_if_sta *ifsta, | 
 | 1137 | 					 struct ieee80211_mgmt *mgmt, | 
 | 1138 | 					 size_t len, | 
 | 1139 | 					 int reassoc) | 
 | 1140 | { | 
 | 1141 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1142 | 	struct ieee80211_hw_mode *mode; | 
 | 1143 | 	struct sta_info *sta; | 
 | 1144 | 	u32 rates; | 
 | 1145 | 	u16 capab_info, status_code, aid; | 
 | 1146 | 	struct ieee802_11_elems elems; | 
 | 1147 | 	u8 *pos; | 
 | 1148 | 	int i, j; | 
 | 1149 |  | 
 | 1150 | 	/* AssocResp and ReassocResp have identical structure, so process both | 
 | 1151 | 	 * of them in this function. */ | 
 | 1152 |  | 
 | 1153 | 	if (ifsta->state != IEEE80211_ASSOCIATE) { | 
 | 1154 | 		printk(KERN_DEBUG "%s: association frame received from " | 
 | 1155 | 		       MAC_FMT ", but not in associate state - ignored\n", | 
 | 1156 | 		       dev->name, MAC_ARG(mgmt->sa)); | 
 | 1157 | 		return; | 
 | 1158 | 	} | 
 | 1159 |  | 
 | 1160 | 	if (len < 24 + 6) { | 
 | 1161 | 		printk(KERN_DEBUG "%s: too short (%zd) association frame " | 
 | 1162 | 		       "received from " MAC_FMT " - ignored\n", | 
 | 1163 | 		       dev->name, len, MAC_ARG(mgmt->sa)); | 
 | 1164 | 		return; | 
 | 1165 | 	} | 
 | 1166 |  | 
 | 1167 | 	if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) { | 
 | 1168 | 		printk(KERN_DEBUG "%s: association frame received from " | 
 | 1169 | 		       "unknown AP (SA=" MAC_FMT " BSSID=" MAC_FMT ") - " | 
 | 1170 | 		       "ignored\n", dev->name, MAC_ARG(mgmt->sa), | 
 | 1171 | 		       MAC_ARG(mgmt->bssid)); | 
 | 1172 | 		return; | 
 | 1173 | 	} | 
 | 1174 |  | 
 | 1175 | 	capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); | 
 | 1176 | 	status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); | 
 | 1177 | 	aid = le16_to_cpu(mgmt->u.assoc_resp.aid); | 
 | 1178 | 	if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) | 
 | 1179 | 		printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " | 
 | 1180 | 		       "set\n", dev->name, aid); | 
 | 1181 | 	aid &= ~(BIT(15) | BIT(14)); | 
 | 1182 |  | 
 | 1183 | 	printk(KERN_DEBUG "%s: RX %sssocResp from " MAC_FMT " (capab=0x%x " | 
 | 1184 | 	       "status=%d aid=%d)\n", | 
 | 1185 | 	       dev->name, reassoc ? "Rea" : "A", MAC_ARG(mgmt->sa), | 
 | 1186 | 	       capab_info, status_code, aid); | 
 | 1187 |  | 
 | 1188 | 	if (status_code != WLAN_STATUS_SUCCESS) { | 
 | 1189 | 		printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", | 
 | 1190 | 		       dev->name, status_code); | 
| Zhu Yi | f11b0f0 | 2007-05-09 13:41:52 +0800 | [diff] [blame] | 1191 | 		if (status_code == WLAN_STATUS_REASSOC_NO_ASSOC) | 
 | 1192 | 			ifsta->prev_bssid_set = 0; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1193 | 		return; | 
 | 1194 | 	} | 
 | 1195 |  | 
 | 1196 | 	pos = mgmt->u.assoc_resp.variable; | 
 | 1197 | 	if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems) | 
 | 1198 | 	    == ParseFailed) { | 
 | 1199 | 		printk(KERN_DEBUG "%s: failed to parse AssocResp\n", | 
 | 1200 | 		       dev->name); | 
 | 1201 | 		return; | 
 | 1202 | 	} | 
 | 1203 |  | 
 | 1204 | 	if (!elems.supp_rates) { | 
 | 1205 | 		printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", | 
 | 1206 | 		       dev->name); | 
 | 1207 | 		return; | 
 | 1208 | 	} | 
 | 1209 |  | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1210 | 	/* it probably doesn't, but if the frame includes an ERP value then | 
 | 1211 | 	 * update our stored copy */ | 
 | 1212 | 	if (elems.erp_info && elems.erp_info_len >= 1) { | 
 | 1213 | 		struct ieee80211_sta_bss *bss | 
 | 1214 | 			= ieee80211_rx_bss_get(dev, ifsta->bssid); | 
 | 1215 | 		if (bss) { | 
 | 1216 | 			bss->erp_value = elems.erp_info[0]; | 
 | 1217 | 			bss->has_erp_value = 1; | 
 | 1218 | 			ieee80211_rx_bss_put(dev, bss); | 
 | 1219 | 		} | 
 | 1220 | 	} | 
 | 1221 |  | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1222 | 	printk(KERN_DEBUG "%s: associated\n", dev->name); | 
 | 1223 | 	ifsta->aid = aid; | 
 | 1224 | 	ifsta->ap_capab = capab_info; | 
 | 1225 |  | 
 | 1226 | 	kfree(ifsta->assocresp_ies); | 
 | 1227 | 	ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt); | 
 | 1228 | 	ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_ATOMIC); | 
 | 1229 | 	if (ifsta->assocresp_ies) | 
 | 1230 | 		memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); | 
 | 1231 |  | 
 | 1232 | 	ieee80211_set_associated(dev, ifsta, 1); | 
 | 1233 |  | 
 | 1234 | 	/* Add STA entry for the AP */ | 
 | 1235 | 	sta = sta_info_get(local, ifsta->bssid); | 
 | 1236 | 	if (!sta) { | 
 | 1237 | 		struct ieee80211_sta_bss *bss; | 
 | 1238 | 		sta = sta_info_add(local, dev, ifsta->bssid, GFP_ATOMIC); | 
 | 1239 | 		if (!sta) { | 
 | 1240 | 			printk(KERN_DEBUG "%s: failed to add STA entry for the" | 
 | 1241 | 			       " AP\n", dev->name); | 
 | 1242 | 			return; | 
 | 1243 | 		} | 
 | 1244 | 		bss = ieee80211_rx_bss_get(dev, ifsta->bssid); | 
 | 1245 | 		if (bss) { | 
 | 1246 | 			sta->last_rssi = bss->rssi; | 
 | 1247 | 			sta->last_signal = bss->signal; | 
 | 1248 | 			sta->last_noise = bss->noise; | 
 | 1249 | 			ieee80211_rx_bss_put(dev, bss); | 
 | 1250 | 		} | 
 | 1251 | 	} | 
 | 1252 |  | 
 | 1253 | 	sta->dev = dev; | 
 | 1254 | 	sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; | 
 | 1255 | 	sta->assoc_ap = 1; | 
 | 1256 |  | 
 | 1257 | 	rates = 0; | 
 | 1258 | 	mode = local->oper_hw_mode; | 
 | 1259 | 	for (i = 0; i < elems.supp_rates_len; i++) { | 
 | 1260 | 		int rate = (elems.supp_rates[i] & 0x7f) * 5; | 
 | 1261 | 		if (mode->mode == MODE_ATHEROS_TURBO) | 
 | 1262 | 			rate *= 2; | 
 | 1263 | 		for (j = 0; j < mode->num_rates; j++) | 
 | 1264 | 			if (mode->rates[j].rate == rate) | 
 | 1265 | 				rates |= BIT(j); | 
 | 1266 | 	} | 
 | 1267 | 	for (i = 0; i < elems.ext_supp_rates_len; i++) { | 
 | 1268 | 		int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; | 
 | 1269 | 		if (mode->mode == MODE_ATHEROS_TURBO) | 
 | 1270 | 			rate *= 2; | 
 | 1271 | 		for (j = 0; j < mode->num_rates; j++) | 
 | 1272 | 			if (mode->rates[j].rate == rate) | 
 | 1273 | 				rates |= BIT(j); | 
 | 1274 | 	} | 
 | 1275 | 	sta->supp_rates = rates; | 
 | 1276 |  | 
 | 1277 | 	rate_control_rate_init(sta, local); | 
 | 1278 |  | 
 | 1279 | 	if (elems.wmm_param && ifsta->wmm_enabled) { | 
 | 1280 | 		sta->flags |= WLAN_STA_WME; | 
 | 1281 | 		ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param, | 
 | 1282 | 					 elems.wmm_param_len); | 
 | 1283 | 	} | 
 | 1284 |  | 
 | 1285 |  | 
 | 1286 | 	sta_info_put(sta); | 
 | 1287 |  | 
 | 1288 | 	ieee80211_associated(dev, ifsta); | 
 | 1289 | } | 
 | 1290 |  | 
 | 1291 |  | 
 | 1292 | /* Caller must hold local->sta_bss_lock */ | 
 | 1293 | static void __ieee80211_rx_bss_hash_add(struct net_device *dev, | 
 | 1294 | 					struct ieee80211_sta_bss *bss) | 
 | 1295 | { | 
 | 1296 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1297 | 	bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)]; | 
 | 1298 | 	local->sta_bss_hash[STA_HASH(bss->bssid)] = bss; | 
 | 1299 | } | 
 | 1300 |  | 
 | 1301 |  | 
 | 1302 | /* Caller must hold local->sta_bss_lock */ | 
 | 1303 | static void __ieee80211_rx_bss_hash_del(struct net_device *dev, | 
 | 1304 | 					struct ieee80211_sta_bss *bss) | 
 | 1305 | { | 
 | 1306 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1307 | 	struct ieee80211_sta_bss *b, *prev = NULL; | 
 | 1308 | 	b = local->sta_bss_hash[STA_HASH(bss->bssid)]; | 
 | 1309 | 	while (b) { | 
 | 1310 | 		if (b == bss) { | 
 | 1311 | 			if (!prev) | 
 | 1312 | 				local->sta_bss_hash[STA_HASH(bss->bssid)] = | 
 | 1313 | 					bss->hnext; | 
 | 1314 | 			else | 
 | 1315 | 				prev->hnext = bss->hnext; | 
 | 1316 | 			break; | 
 | 1317 | 		} | 
 | 1318 | 		prev = b; | 
 | 1319 | 		b = b->hnext; | 
 | 1320 | 	} | 
 | 1321 | } | 
 | 1322 |  | 
 | 1323 |  | 
 | 1324 | static struct ieee80211_sta_bss * | 
 | 1325 | ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid) | 
 | 1326 | { | 
 | 1327 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1328 | 	struct ieee80211_sta_bss *bss; | 
 | 1329 |  | 
| Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 1330 | 	bss = kzalloc(sizeof(*bss), GFP_ATOMIC); | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1331 | 	if (!bss) | 
 | 1332 | 		return NULL; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1333 | 	atomic_inc(&bss->users); | 
 | 1334 | 	atomic_inc(&bss->users); | 
 | 1335 | 	memcpy(bss->bssid, bssid, ETH_ALEN); | 
 | 1336 |  | 
 | 1337 | 	spin_lock_bh(&local->sta_bss_lock); | 
 | 1338 | 	/* TODO: order by RSSI? */ | 
 | 1339 | 	list_add_tail(&bss->list, &local->sta_bss_list); | 
 | 1340 | 	__ieee80211_rx_bss_hash_add(dev, bss); | 
 | 1341 | 	spin_unlock_bh(&local->sta_bss_lock); | 
 | 1342 | 	return bss; | 
 | 1343 | } | 
 | 1344 |  | 
 | 1345 |  | 
 | 1346 | static struct ieee80211_sta_bss * | 
 | 1347 | ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid) | 
 | 1348 | { | 
 | 1349 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1350 | 	struct ieee80211_sta_bss *bss; | 
 | 1351 |  | 
 | 1352 | 	spin_lock_bh(&local->sta_bss_lock); | 
 | 1353 | 	bss = local->sta_bss_hash[STA_HASH(bssid)]; | 
 | 1354 | 	while (bss) { | 
 | 1355 | 		if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) { | 
 | 1356 | 			atomic_inc(&bss->users); | 
 | 1357 | 			break; | 
 | 1358 | 		} | 
 | 1359 | 		bss = bss->hnext; | 
 | 1360 | 	} | 
 | 1361 | 	spin_unlock_bh(&local->sta_bss_lock); | 
 | 1362 | 	return bss; | 
 | 1363 | } | 
 | 1364 |  | 
 | 1365 |  | 
 | 1366 | static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) | 
 | 1367 | { | 
 | 1368 | 	kfree(bss->wpa_ie); | 
 | 1369 | 	kfree(bss->rsn_ie); | 
 | 1370 | 	kfree(bss->wmm_ie); | 
 | 1371 | 	kfree(bss); | 
 | 1372 | } | 
 | 1373 |  | 
 | 1374 |  | 
 | 1375 | static void ieee80211_rx_bss_put(struct net_device *dev, | 
 | 1376 | 				 struct ieee80211_sta_bss *bss) | 
 | 1377 | { | 
 | 1378 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1379 | 	if (!atomic_dec_and_test(&bss->users)) | 
 | 1380 | 		return; | 
 | 1381 |  | 
 | 1382 | 	spin_lock_bh(&local->sta_bss_lock); | 
 | 1383 | 	__ieee80211_rx_bss_hash_del(dev, bss); | 
 | 1384 | 	list_del(&bss->list); | 
 | 1385 | 	spin_unlock_bh(&local->sta_bss_lock); | 
 | 1386 | 	ieee80211_rx_bss_free(bss); | 
 | 1387 | } | 
 | 1388 |  | 
 | 1389 |  | 
 | 1390 | void ieee80211_rx_bss_list_init(struct net_device *dev) | 
 | 1391 | { | 
 | 1392 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1393 | 	spin_lock_init(&local->sta_bss_lock); | 
 | 1394 | 	INIT_LIST_HEAD(&local->sta_bss_list); | 
 | 1395 | } | 
 | 1396 |  | 
 | 1397 |  | 
 | 1398 | void ieee80211_rx_bss_list_deinit(struct net_device *dev) | 
 | 1399 | { | 
 | 1400 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1401 | 	struct ieee80211_sta_bss *bss, *tmp; | 
 | 1402 |  | 
 | 1403 | 	list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list) | 
 | 1404 | 		ieee80211_rx_bss_put(dev, bss); | 
 | 1405 | } | 
 | 1406 |  | 
 | 1407 |  | 
 | 1408 | static void ieee80211_rx_bss_info(struct net_device *dev, | 
 | 1409 | 				  struct ieee80211_mgmt *mgmt, | 
 | 1410 | 				  size_t len, | 
 | 1411 | 				  struct ieee80211_rx_status *rx_status, | 
 | 1412 | 				  int beacon) | 
 | 1413 | { | 
 | 1414 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1415 | 	struct ieee802_11_elems elems; | 
 | 1416 | 	size_t baselen; | 
 | 1417 | 	int channel, invalid = 0, clen; | 
 | 1418 | 	struct ieee80211_sta_bss *bss; | 
 | 1419 | 	struct sta_info *sta; | 
 | 1420 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 1421 | 	u64 timestamp; | 
 | 1422 |  | 
 | 1423 | 	if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN)) | 
 | 1424 | 		return; /* ignore ProbeResp to foreign address */ | 
 | 1425 |  | 
 | 1426 | #if 0 | 
 | 1427 | 	printk(KERN_DEBUG "%s: RX %s from " MAC_FMT " to " MAC_FMT "\n", | 
 | 1428 | 	       dev->name, beacon ? "Beacon" : "Probe Response", | 
 | 1429 | 	       MAC_ARG(mgmt->sa), MAC_ARG(mgmt->da)); | 
 | 1430 | #endif | 
 | 1431 |  | 
 | 1432 | 	baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; | 
 | 1433 | 	if (baselen > len) | 
 | 1434 | 		return; | 
 | 1435 |  | 
 | 1436 | 	timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); | 
 | 1437 |  | 
 | 1438 | 	if (sdata->type == IEEE80211_IF_TYPE_IBSS && beacon && | 
 | 1439 | 	    memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { | 
 | 1440 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | 
 | 1441 | 		static unsigned long last_tsf_debug = 0; | 
 | 1442 | 		u64 tsf; | 
 | 1443 | 		if (local->ops->get_tsf) | 
 | 1444 | 			tsf = local->ops->get_tsf(local_to_hw(local)); | 
 | 1445 | 		else | 
 | 1446 | 			tsf = -1LLU; | 
 | 1447 | 		if (time_after(jiffies, last_tsf_debug + 5 * HZ)) { | 
 | 1448 | 			printk(KERN_DEBUG "RX beacon SA=" MAC_FMT " BSSID=" | 
 | 1449 | 			       MAC_FMT " TSF=0x%llx BCN=0x%llx diff=%lld " | 
 | 1450 | 			       "@%lu\n", | 
 | 1451 | 			       MAC_ARG(mgmt->sa), MAC_ARG(mgmt->bssid), | 
 | 1452 | 			       (unsigned long long)tsf, | 
 | 1453 | 			       (unsigned long long)timestamp, | 
 | 1454 | 			       (unsigned long long)(tsf - timestamp), | 
 | 1455 | 			       jiffies); | 
 | 1456 | 			last_tsf_debug = jiffies; | 
 | 1457 | 		} | 
 | 1458 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | 
 | 1459 | 	} | 
 | 1460 |  | 
 | 1461 | 	if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, | 
 | 1462 | 				   &elems) == ParseFailed) | 
 | 1463 | 		invalid = 1; | 
 | 1464 |  | 
 | 1465 | 	if (sdata->type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates && | 
 | 1466 | 	    memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 && | 
 | 1467 | 	    (sta = sta_info_get(local, mgmt->sa))) { | 
 | 1468 | 		struct ieee80211_hw_mode *mode; | 
 | 1469 | 		struct ieee80211_rate *rates; | 
 | 1470 | 		size_t num_rates; | 
 | 1471 | 		u32 supp_rates, prev_rates; | 
 | 1472 | 		int i, j; | 
 | 1473 |  | 
 | 1474 | 		mode = local->sta_scanning ? | 
 | 1475 | 		       local->scan_hw_mode : local->oper_hw_mode; | 
 | 1476 | 		rates = mode->rates; | 
 | 1477 | 		num_rates = mode->num_rates; | 
 | 1478 |  | 
 | 1479 | 		supp_rates = 0; | 
 | 1480 | 		for (i = 0; i < elems.supp_rates_len + | 
 | 1481 | 			     elems.ext_supp_rates_len; i++) { | 
 | 1482 | 			u8 rate = 0; | 
 | 1483 | 			int own_rate; | 
 | 1484 | 			if (i < elems.supp_rates_len) | 
 | 1485 | 				rate = elems.supp_rates[i]; | 
 | 1486 | 			else if (elems.ext_supp_rates) | 
 | 1487 | 				rate = elems.ext_supp_rates | 
 | 1488 | 					[i - elems.supp_rates_len]; | 
 | 1489 | 			own_rate = 5 * (rate & 0x7f); | 
 | 1490 | 			if (mode->mode == MODE_ATHEROS_TURBO) | 
 | 1491 | 				own_rate *= 2; | 
 | 1492 | 			for (j = 0; j < num_rates; j++) | 
 | 1493 | 				if (rates[j].rate == own_rate) | 
 | 1494 | 					supp_rates |= BIT(j); | 
 | 1495 | 		} | 
 | 1496 |  | 
 | 1497 | 		prev_rates = sta->supp_rates; | 
 | 1498 | 		sta->supp_rates &= supp_rates; | 
 | 1499 | 		if (sta->supp_rates == 0) { | 
 | 1500 | 			/* No matching rates - this should not really happen. | 
 | 1501 | 			 * Make sure that at least one rate is marked | 
 | 1502 | 			 * supported to avoid issues with TX rate ctrl. */ | 
 | 1503 | 			sta->supp_rates = sdata->u.sta.supp_rates_bits; | 
 | 1504 | 		} | 
 | 1505 | 		if (sta->supp_rates != prev_rates) { | 
 | 1506 | 			printk(KERN_DEBUG "%s: updated supp_rates set for " | 
 | 1507 | 			       MAC_FMT " based on beacon info (0x%x & 0x%x -> " | 
 | 1508 | 			       "0x%x)\n", | 
 | 1509 | 			       dev->name, MAC_ARG(sta->addr), prev_rates, | 
 | 1510 | 			       supp_rates, sta->supp_rates); | 
 | 1511 | 		} | 
 | 1512 | 		sta_info_put(sta); | 
 | 1513 | 	} | 
 | 1514 |  | 
 | 1515 | 	if (!elems.ssid) | 
 | 1516 | 		return; | 
 | 1517 |  | 
 | 1518 | 	if (elems.ds_params && elems.ds_params_len == 1) | 
 | 1519 | 		channel = elems.ds_params[0]; | 
 | 1520 | 	else | 
 | 1521 | 		channel = rx_status->channel; | 
 | 1522 |  | 
 | 1523 | 	bss = ieee80211_rx_bss_get(dev, mgmt->bssid); | 
 | 1524 | 	if (!bss) { | 
 | 1525 | 		bss = ieee80211_rx_bss_add(dev, mgmt->bssid); | 
 | 1526 | 		if (!bss) | 
 | 1527 | 			return; | 
 | 1528 | 	} else { | 
 | 1529 | #if 0 | 
 | 1530 | 		/* TODO: order by RSSI? */ | 
 | 1531 | 		spin_lock_bh(&local->sta_bss_lock); | 
 | 1532 | 		list_move_tail(&bss->list, &local->sta_bss_list); | 
 | 1533 | 		spin_unlock_bh(&local->sta_bss_lock); | 
 | 1534 | #endif | 
 | 1535 | 	} | 
 | 1536 |  | 
 | 1537 | 	if (bss->probe_resp && beacon) { | 
 | 1538 | 		/* Do not allow beacon to override data from Probe Response. */ | 
 | 1539 | 		ieee80211_rx_bss_put(dev, bss); | 
 | 1540 | 		return; | 
 | 1541 | 	} | 
 | 1542 |  | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1543 | 	/* save the ERP value so that it is available at association time */ | 
 | 1544 | 	if (elems.erp_info && elems.erp_info_len >= 1) { | 
 | 1545 | 		bss->erp_value = elems.erp_info[0]; | 
 | 1546 | 		bss->has_erp_value = 1; | 
 | 1547 | 	} | 
 | 1548 |  | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1549 | 	bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); | 
 | 1550 | 	bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); | 
 | 1551 | 	if (elems.ssid && elems.ssid_len <= IEEE80211_MAX_SSID_LEN) { | 
 | 1552 | 		memcpy(bss->ssid, elems.ssid, elems.ssid_len); | 
 | 1553 | 		bss->ssid_len = elems.ssid_len; | 
 | 1554 | 	} | 
 | 1555 |  | 
 | 1556 | 	bss->supp_rates_len = 0; | 
 | 1557 | 	if (elems.supp_rates) { | 
 | 1558 | 		clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; | 
 | 1559 | 		if (clen > elems.supp_rates_len) | 
 | 1560 | 			clen = elems.supp_rates_len; | 
 | 1561 | 		memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates, | 
 | 1562 | 		       clen); | 
 | 1563 | 		bss->supp_rates_len += clen; | 
 | 1564 | 	} | 
 | 1565 | 	if (elems.ext_supp_rates) { | 
 | 1566 | 		clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; | 
 | 1567 | 		if (clen > elems.ext_supp_rates_len) | 
 | 1568 | 			clen = elems.ext_supp_rates_len; | 
 | 1569 | 		memcpy(&bss->supp_rates[bss->supp_rates_len], | 
 | 1570 | 		       elems.ext_supp_rates, clen); | 
 | 1571 | 		bss->supp_rates_len += clen; | 
 | 1572 | 	} | 
 | 1573 |  | 
 | 1574 | 	if (elems.wpa && | 
 | 1575 | 	    (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len || | 
 | 1576 | 	     memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) { | 
 | 1577 | 		kfree(bss->wpa_ie); | 
 | 1578 | 		bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC); | 
 | 1579 | 		if (bss->wpa_ie) { | 
 | 1580 | 			memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2); | 
 | 1581 | 			bss->wpa_ie_len = elems.wpa_len + 2; | 
 | 1582 | 		} else | 
 | 1583 | 			bss->wpa_ie_len = 0; | 
 | 1584 | 	} else if (!elems.wpa && bss->wpa_ie) { | 
 | 1585 | 		kfree(bss->wpa_ie); | 
 | 1586 | 		bss->wpa_ie = NULL; | 
 | 1587 | 		bss->wpa_ie_len = 0; | 
 | 1588 | 	} | 
 | 1589 |  | 
 | 1590 | 	if (elems.rsn && | 
 | 1591 | 	    (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len || | 
 | 1592 | 	     memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) { | 
 | 1593 | 		kfree(bss->rsn_ie); | 
 | 1594 | 		bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC); | 
 | 1595 | 		if (bss->rsn_ie) { | 
 | 1596 | 			memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2); | 
 | 1597 | 			bss->rsn_ie_len = elems.rsn_len + 2; | 
 | 1598 | 		} else | 
 | 1599 | 			bss->rsn_ie_len = 0; | 
 | 1600 | 	} else if (!elems.rsn && bss->rsn_ie) { | 
 | 1601 | 		kfree(bss->rsn_ie); | 
 | 1602 | 		bss->rsn_ie = NULL; | 
 | 1603 | 		bss->rsn_ie_len = 0; | 
 | 1604 | 	} | 
 | 1605 |  | 
 | 1606 | 	if (elems.wmm_param && | 
 | 1607 | 	    (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len || | 
 | 1608 | 	     memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) { | 
 | 1609 | 		kfree(bss->wmm_ie); | 
 | 1610 | 		bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC); | 
 | 1611 | 		if (bss->wmm_ie) { | 
 | 1612 | 			memcpy(bss->wmm_ie, elems.wmm_param - 2, | 
 | 1613 | 			       elems.wmm_param_len + 2); | 
 | 1614 | 			bss->wmm_ie_len = elems.wmm_param_len + 2; | 
 | 1615 | 		} else | 
 | 1616 | 			bss->wmm_ie_len = 0; | 
 | 1617 | 	} else if (!elems.wmm_param && bss->wmm_ie) { | 
 | 1618 | 		kfree(bss->wmm_ie); | 
 | 1619 | 		bss->wmm_ie = NULL; | 
 | 1620 | 		bss->wmm_ie_len = 0; | 
 | 1621 | 	} | 
 | 1622 |  | 
 | 1623 |  | 
 | 1624 | 	bss->hw_mode = rx_status->phymode; | 
 | 1625 | 	bss->channel = channel; | 
 | 1626 | 	bss->freq = rx_status->freq; | 
 | 1627 | 	if (channel != rx_status->channel && | 
 | 1628 | 	    (bss->hw_mode == MODE_IEEE80211G || | 
 | 1629 | 	     bss->hw_mode == MODE_IEEE80211B) && | 
 | 1630 | 	    channel >= 1 && channel <= 14) { | 
 | 1631 | 		static const int freq_list[] = { | 
 | 1632 | 			2412, 2417, 2422, 2427, 2432, 2437, 2442, | 
 | 1633 | 			2447, 2452, 2457, 2462, 2467, 2472, 2484 | 
 | 1634 | 		}; | 
 | 1635 | 		/* IEEE 802.11g/b mode can receive packets from neighboring | 
 | 1636 | 		 * channels, so map the channel into frequency. */ | 
 | 1637 | 		bss->freq = freq_list[channel - 1]; | 
 | 1638 | 	} | 
 | 1639 | 	bss->timestamp = timestamp; | 
 | 1640 | 	bss->last_update = jiffies; | 
 | 1641 | 	bss->rssi = rx_status->ssi; | 
 | 1642 | 	bss->signal = rx_status->signal; | 
 | 1643 | 	bss->noise = rx_status->noise; | 
 | 1644 | 	if (!beacon) | 
 | 1645 | 		bss->probe_resp++; | 
 | 1646 | 	ieee80211_rx_bss_put(dev, bss); | 
 | 1647 | } | 
 | 1648 |  | 
 | 1649 |  | 
 | 1650 | static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev, | 
 | 1651 | 					 struct ieee80211_mgmt *mgmt, | 
 | 1652 | 					 size_t len, | 
 | 1653 | 					 struct ieee80211_rx_status *rx_status) | 
 | 1654 | { | 
 | 1655 | 	ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0); | 
 | 1656 | } | 
 | 1657 |  | 
 | 1658 |  | 
 | 1659 | static void ieee80211_rx_mgmt_beacon(struct net_device *dev, | 
 | 1660 | 				     struct ieee80211_mgmt *mgmt, | 
 | 1661 | 				     size_t len, | 
 | 1662 | 				     struct ieee80211_rx_status *rx_status) | 
 | 1663 | { | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1664 | 	struct ieee80211_sub_if_data *sdata; | 
 | 1665 | 	struct ieee80211_if_sta *ifsta; | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1666 | 	size_t baselen; | 
 | 1667 | 	struct ieee802_11_elems elems; | 
 | 1668 |  | 
 | 1669 | 	ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1); | 
 | 1670 |  | 
 | 1671 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 1672 | 	if (sdata->type != IEEE80211_IF_TYPE_STA) | 
 | 1673 | 		return; | 
 | 1674 | 	ifsta = &sdata->u.sta; | 
 | 1675 |  | 
 | 1676 | 	if (!ifsta->associated || | 
 | 1677 | 	    memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) | 
 | 1678 | 		return; | 
 | 1679 |  | 
 | 1680 | 	/* Process beacon from the current BSS */ | 
 | 1681 | 	baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; | 
 | 1682 | 	if (baselen > len) | 
 | 1683 | 		return; | 
 | 1684 |  | 
 | 1685 | 	if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, | 
 | 1686 | 				   &elems) == ParseFailed) | 
 | 1687 | 		return; | 
 | 1688 |  | 
| Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1689 | 	if (elems.erp_info && elems.erp_info_len >= 1) | 
 | 1690 | 		ieee80211_handle_erp_ie(dev, elems.erp_info[0]); | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1691 |  | 
 | 1692 | 	if (elems.wmm_param && ifsta->wmm_enabled) { | 
 | 1693 | 		ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param, | 
 | 1694 | 					 elems.wmm_param_len); | 
 | 1695 | 	} | 
 | 1696 | } | 
 | 1697 |  | 
 | 1698 |  | 
 | 1699 | static void ieee80211_rx_mgmt_probe_req(struct net_device *dev, | 
 | 1700 | 					struct ieee80211_if_sta *ifsta, | 
 | 1701 | 					struct ieee80211_mgmt *mgmt, | 
 | 1702 | 					size_t len, | 
 | 1703 | 					struct ieee80211_rx_status *rx_status) | 
 | 1704 | { | 
 | 1705 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1706 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 1707 | 	int tx_last_beacon; | 
 | 1708 | 	struct sk_buff *skb; | 
 | 1709 | 	struct ieee80211_mgmt *resp; | 
 | 1710 | 	u8 *pos, *end; | 
 | 1711 |  | 
 | 1712 | 	if (sdata->type != IEEE80211_IF_TYPE_IBSS || | 
 | 1713 | 	    ifsta->state != IEEE80211_IBSS_JOINED || | 
 | 1714 | 	    len < 24 + 2 || !ifsta->probe_resp) | 
 | 1715 | 		return; | 
 | 1716 |  | 
 | 1717 | 	if (local->ops->tx_last_beacon) | 
 | 1718 | 		tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local)); | 
 | 1719 | 	else | 
 | 1720 | 		tx_last_beacon = 1; | 
 | 1721 |  | 
 | 1722 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | 
 | 1723 | 	printk(KERN_DEBUG "%s: RX ProbeReq SA=" MAC_FMT " DA=" MAC_FMT " BSSID=" | 
 | 1724 | 	       MAC_FMT " (tx_last_beacon=%d)\n", | 
 | 1725 | 	       dev->name, MAC_ARG(mgmt->sa), MAC_ARG(mgmt->da), | 
 | 1726 | 	       MAC_ARG(mgmt->bssid), tx_last_beacon); | 
 | 1727 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | 
 | 1728 |  | 
 | 1729 | 	if (!tx_last_beacon) | 
 | 1730 | 		return; | 
 | 1731 |  | 
 | 1732 | 	if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 && | 
 | 1733 | 	    memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) | 
 | 1734 | 		return; | 
 | 1735 |  | 
 | 1736 | 	end = ((u8 *) mgmt) + len; | 
 | 1737 | 	pos = mgmt->u.probe_req.variable; | 
 | 1738 | 	if (pos[0] != WLAN_EID_SSID || | 
 | 1739 | 	    pos + 2 + pos[1] > end) { | 
 | 1740 | 		if (net_ratelimit()) { | 
 | 1741 | 			printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " | 
 | 1742 | 			       "from " MAC_FMT "\n", | 
 | 1743 | 			       dev->name, MAC_ARG(mgmt->sa)); | 
 | 1744 | 		} | 
 | 1745 | 		return; | 
 | 1746 | 	} | 
 | 1747 | 	if (pos[1] != 0 && | 
 | 1748 | 	    (pos[1] != ifsta->ssid_len || | 
 | 1749 | 	     memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) { | 
 | 1750 | 		/* Ignore ProbeReq for foreign SSID */ | 
 | 1751 | 		return; | 
 | 1752 | 	} | 
 | 1753 |  | 
 | 1754 | 	/* Reply with ProbeResp */ | 
 | 1755 | 	skb = skb_copy(ifsta->probe_resp, GFP_ATOMIC); | 
 | 1756 | 	if (!skb) | 
 | 1757 | 		return; | 
 | 1758 |  | 
 | 1759 | 	resp = (struct ieee80211_mgmt *) skb->data; | 
 | 1760 | 	memcpy(resp->da, mgmt->sa, ETH_ALEN); | 
 | 1761 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | 
 | 1762 | 	printk(KERN_DEBUG "%s: Sending ProbeResp to " MAC_FMT "\n", | 
 | 1763 | 	       dev->name, MAC_ARG(resp->da)); | 
 | 1764 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | 
 | 1765 | 	ieee80211_sta_tx(dev, skb, 0); | 
 | 1766 | } | 
 | 1767 |  | 
 | 1768 |  | 
 | 1769 | void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb, | 
 | 1770 | 			   struct ieee80211_rx_status *rx_status) | 
 | 1771 | { | 
 | 1772 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1773 | 	struct ieee80211_sub_if_data *sdata; | 
 | 1774 | 	struct ieee80211_if_sta *ifsta; | 
 | 1775 | 	struct ieee80211_mgmt *mgmt; | 
 | 1776 | 	u16 fc; | 
 | 1777 |  | 
 | 1778 | 	if (skb->len < 24) | 
 | 1779 | 		goto fail; | 
 | 1780 |  | 
 | 1781 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 1782 | 	ifsta = &sdata->u.sta; | 
 | 1783 |  | 
 | 1784 | 	mgmt = (struct ieee80211_mgmt *) skb->data; | 
 | 1785 | 	fc = le16_to_cpu(mgmt->frame_control); | 
 | 1786 |  | 
 | 1787 | 	switch (fc & IEEE80211_FCTL_STYPE) { | 
 | 1788 | 	case IEEE80211_STYPE_PROBE_REQ: | 
 | 1789 | 	case IEEE80211_STYPE_PROBE_RESP: | 
 | 1790 | 	case IEEE80211_STYPE_BEACON: | 
 | 1791 | 		memcpy(skb->cb, rx_status, sizeof(*rx_status)); | 
 | 1792 | 	case IEEE80211_STYPE_AUTH: | 
 | 1793 | 	case IEEE80211_STYPE_ASSOC_RESP: | 
 | 1794 | 	case IEEE80211_STYPE_REASSOC_RESP: | 
 | 1795 | 	case IEEE80211_STYPE_DEAUTH: | 
 | 1796 | 	case IEEE80211_STYPE_DISASSOC: | 
 | 1797 | 		skb_queue_tail(&ifsta->skb_queue, skb); | 
 | 1798 | 		queue_work(local->hw.workqueue, &ifsta->work); | 
 | 1799 | 		return; | 
 | 1800 | 	default: | 
 | 1801 | 		printk(KERN_DEBUG "%s: received unknown management frame - " | 
 | 1802 | 		       "stype=%d\n", dev->name, | 
 | 1803 | 		       (fc & IEEE80211_FCTL_STYPE) >> 4); | 
 | 1804 | 		break; | 
 | 1805 | 	} | 
 | 1806 |  | 
 | 1807 |  fail: | 
 | 1808 | 	kfree_skb(skb); | 
 | 1809 | } | 
 | 1810 |  | 
 | 1811 |  | 
 | 1812 | static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev, | 
 | 1813 | 					 struct sk_buff *skb) | 
 | 1814 | { | 
 | 1815 | 	struct ieee80211_rx_status *rx_status; | 
 | 1816 | 	struct ieee80211_sub_if_data *sdata; | 
 | 1817 | 	struct ieee80211_if_sta *ifsta; | 
 | 1818 | 	struct ieee80211_mgmt *mgmt; | 
 | 1819 | 	u16 fc; | 
 | 1820 |  | 
 | 1821 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 1822 | 	ifsta = &sdata->u.sta; | 
 | 1823 |  | 
 | 1824 | 	rx_status = (struct ieee80211_rx_status *) skb->cb; | 
 | 1825 | 	mgmt = (struct ieee80211_mgmt *) skb->data; | 
 | 1826 | 	fc = le16_to_cpu(mgmt->frame_control); | 
 | 1827 |  | 
 | 1828 | 	switch (fc & IEEE80211_FCTL_STYPE) { | 
 | 1829 | 	case IEEE80211_STYPE_PROBE_REQ: | 
 | 1830 | 		ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len, | 
 | 1831 | 					    rx_status); | 
 | 1832 | 		break; | 
 | 1833 | 	case IEEE80211_STYPE_PROBE_RESP: | 
 | 1834 | 		ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status); | 
 | 1835 | 		break; | 
 | 1836 | 	case IEEE80211_STYPE_BEACON: | 
 | 1837 | 		ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status); | 
 | 1838 | 		break; | 
 | 1839 | 	case IEEE80211_STYPE_AUTH: | 
 | 1840 | 		ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len); | 
 | 1841 | 		break; | 
 | 1842 | 	case IEEE80211_STYPE_ASSOC_RESP: | 
 | 1843 | 		ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len, 0); | 
 | 1844 | 		break; | 
 | 1845 | 	case IEEE80211_STYPE_REASSOC_RESP: | 
 | 1846 | 		ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len, 1); | 
 | 1847 | 		break; | 
 | 1848 | 	case IEEE80211_STYPE_DEAUTH: | 
 | 1849 | 		ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len); | 
 | 1850 | 		break; | 
 | 1851 | 	case IEEE80211_STYPE_DISASSOC: | 
 | 1852 | 		ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len); | 
 | 1853 | 		break; | 
 | 1854 | 	} | 
 | 1855 |  | 
 | 1856 | 	kfree_skb(skb); | 
 | 1857 | } | 
 | 1858 |  | 
 | 1859 |  | 
 | 1860 | void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb, | 
 | 1861 | 			   struct ieee80211_rx_status *rx_status) | 
 | 1862 | { | 
 | 1863 | 	struct ieee80211_mgmt *mgmt; | 
 | 1864 | 	u16 fc; | 
 | 1865 |  | 
 | 1866 | 	if (skb->len < 24) { | 
 | 1867 | 		dev_kfree_skb(skb); | 
 | 1868 | 		return; | 
 | 1869 | 	} | 
 | 1870 |  | 
 | 1871 | 	mgmt = (struct ieee80211_mgmt *) skb->data; | 
 | 1872 | 	fc = le16_to_cpu(mgmt->frame_control); | 
 | 1873 |  | 
 | 1874 | 	if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { | 
 | 1875 | 		if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) { | 
 | 1876 | 			ieee80211_rx_mgmt_probe_resp(dev, mgmt, | 
 | 1877 | 						     skb->len, rx_status); | 
 | 1878 | 		} else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) { | 
 | 1879 | 			ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, | 
 | 1880 | 						 rx_status); | 
 | 1881 | 		} | 
 | 1882 | 	} | 
 | 1883 |  | 
 | 1884 | 	dev_kfree_skb(skb); | 
 | 1885 | } | 
 | 1886 |  | 
 | 1887 |  | 
 | 1888 | static int ieee80211_sta_active_ibss(struct net_device *dev) | 
 | 1889 | { | 
 | 1890 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1891 | 	int active = 0; | 
 | 1892 | 	struct sta_info *sta; | 
 | 1893 |  | 
 | 1894 | 	spin_lock_bh(&local->sta_lock); | 
 | 1895 | 	list_for_each_entry(sta, &local->sta_list, list) { | 
 | 1896 | 		if (sta->dev == dev && | 
 | 1897 | 		    time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, | 
 | 1898 | 			       jiffies)) { | 
 | 1899 | 			active++; | 
 | 1900 | 			break; | 
 | 1901 | 		} | 
 | 1902 | 	} | 
 | 1903 | 	spin_unlock_bh(&local->sta_lock); | 
 | 1904 |  | 
 | 1905 | 	return active; | 
 | 1906 | } | 
 | 1907 |  | 
 | 1908 |  | 
 | 1909 | static void ieee80211_sta_expire(struct net_device *dev) | 
 | 1910 | { | 
 | 1911 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1912 | 	struct sta_info *sta, *tmp; | 
 | 1913 |  | 
 | 1914 | 	spin_lock_bh(&local->sta_lock); | 
 | 1915 | 	list_for_each_entry_safe(sta, tmp, &local->sta_list, list) | 
 | 1916 | 		if (time_after(jiffies, sta->last_rx + | 
 | 1917 | 			       IEEE80211_IBSS_INACTIVITY_LIMIT)) { | 
 | 1918 | 			printk(KERN_DEBUG "%s: expiring inactive STA " MAC_FMT | 
 | 1919 | 			       "\n", dev->name, MAC_ARG(sta->addr)); | 
 | 1920 | 			sta_info_free(sta, 1); | 
 | 1921 | 		} | 
 | 1922 | 	spin_unlock_bh(&local->sta_lock); | 
 | 1923 | } | 
 | 1924 |  | 
 | 1925 |  | 
 | 1926 | static void ieee80211_sta_merge_ibss(struct net_device *dev, | 
 | 1927 | 				     struct ieee80211_if_sta *ifsta) | 
 | 1928 | { | 
 | 1929 | 	mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); | 
 | 1930 |  | 
 | 1931 | 	ieee80211_sta_expire(dev); | 
 | 1932 | 	if (ieee80211_sta_active_ibss(dev)) | 
 | 1933 | 		return; | 
 | 1934 |  | 
 | 1935 | 	printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " | 
 | 1936 | 	       "IBSS networks with same SSID (merge)\n", dev->name); | 
 | 1937 | 	ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len); | 
 | 1938 | } | 
 | 1939 |  | 
 | 1940 |  | 
 | 1941 | void ieee80211_sta_timer(unsigned long data) | 
 | 1942 | { | 
 | 1943 | 	struct ieee80211_sub_if_data *sdata = | 
 | 1944 | 		(struct ieee80211_sub_if_data *) data; | 
 | 1945 | 	struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 
 | 1946 | 	struct ieee80211_local *local = wdev_priv(&sdata->wdev); | 
 | 1947 |  | 
 | 1948 | 	set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); | 
 | 1949 | 	queue_work(local->hw.workqueue, &ifsta->work); | 
 | 1950 | } | 
 | 1951 |  | 
 | 1952 |  | 
 | 1953 | void ieee80211_sta_work(struct work_struct *work) | 
 | 1954 | { | 
 | 1955 | 	struct ieee80211_sub_if_data *sdata = | 
 | 1956 | 		container_of(work, struct ieee80211_sub_if_data, u.sta.work); | 
 | 1957 | 	struct net_device *dev = sdata->dev; | 
 | 1958 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 1959 | 	struct ieee80211_if_sta *ifsta; | 
 | 1960 | 	struct sk_buff *skb; | 
 | 1961 |  | 
 | 1962 | 	if (!netif_running(dev)) | 
 | 1963 | 		return; | 
 | 1964 |  | 
 | 1965 | 	if (local->sta_scanning) | 
 | 1966 | 		return; | 
 | 1967 |  | 
 | 1968 | 	if (sdata->type != IEEE80211_IF_TYPE_STA && | 
 | 1969 | 	    sdata->type != IEEE80211_IF_TYPE_IBSS) { | 
 | 1970 | 		printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface " | 
 | 1971 | 		       "(type=%d)\n", dev->name, sdata->type); | 
 | 1972 | 		return; | 
 | 1973 | 	} | 
 | 1974 | 	ifsta = &sdata->u.sta; | 
 | 1975 |  | 
 | 1976 | 	while ((skb = skb_dequeue(&ifsta->skb_queue))) | 
 | 1977 | 		ieee80211_sta_rx_queued_mgmt(dev, skb); | 
 | 1978 |  | 
 | 1979 | 	if (ifsta->state != IEEE80211_AUTHENTICATE && | 
 | 1980 | 	    ifsta->state != IEEE80211_ASSOCIATE && | 
 | 1981 | 	    test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { | 
 | 1982 | 		ieee80211_sta_start_scan(dev, NULL, 0); | 
 | 1983 | 		return; | 
 | 1984 | 	} | 
 | 1985 |  | 
 | 1986 | 	if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) { | 
 | 1987 | 		if (ieee80211_sta_config_auth(dev, ifsta)) | 
 | 1988 | 			return; | 
 | 1989 | 		clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); | 
 | 1990 | 	} else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request)) | 
 | 1991 | 		return; | 
 | 1992 |  | 
 | 1993 | 	switch (ifsta->state) { | 
 | 1994 | 	case IEEE80211_DISABLED: | 
 | 1995 | 		break; | 
 | 1996 | 	case IEEE80211_AUTHENTICATE: | 
 | 1997 | 		ieee80211_authenticate(dev, ifsta); | 
 | 1998 | 		break; | 
 | 1999 | 	case IEEE80211_ASSOCIATE: | 
 | 2000 | 		ieee80211_associate(dev, ifsta); | 
 | 2001 | 		break; | 
 | 2002 | 	case IEEE80211_ASSOCIATED: | 
 | 2003 | 		ieee80211_associated(dev, ifsta); | 
 | 2004 | 		break; | 
 | 2005 | 	case IEEE80211_IBSS_SEARCH: | 
 | 2006 | 		ieee80211_sta_find_ibss(dev, ifsta); | 
 | 2007 | 		break; | 
 | 2008 | 	case IEEE80211_IBSS_JOINED: | 
 | 2009 | 		ieee80211_sta_merge_ibss(dev, ifsta); | 
 | 2010 | 		break; | 
 | 2011 | 	default: | 
 | 2012 | 		printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n", | 
 | 2013 | 		       ifsta->state); | 
 | 2014 | 		break; | 
 | 2015 | 	} | 
 | 2016 |  | 
 | 2017 | 	if (ieee80211_privacy_mismatch(dev, ifsta)) { | 
 | 2018 | 		printk(KERN_DEBUG "%s: privacy configuration mismatch and " | 
 | 2019 | 		       "mixed-cell disabled - disassociate\n", dev->name); | 
 | 2020 |  | 
 | 2021 | 		ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED); | 
 | 2022 | 		ieee80211_set_disassoc(dev, ifsta, 0); | 
 | 2023 | 	} | 
 | 2024 | } | 
 | 2025 |  | 
 | 2026 |  | 
 | 2027 | static void ieee80211_sta_reset_auth(struct net_device *dev, | 
 | 2028 | 				     struct ieee80211_if_sta *ifsta) | 
 | 2029 | { | 
 | 2030 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2031 |  | 
 | 2032 | 	if (local->ops->reset_tsf) { | 
 | 2033 | 		/* Reset own TSF to allow time synchronization work. */ | 
 | 2034 | 		local->ops->reset_tsf(local_to_hw(local)); | 
 | 2035 | 	} | 
 | 2036 |  | 
 | 2037 | 	ifsta->wmm_last_param_set = -1; /* allow any WMM update */ | 
 | 2038 |  | 
 | 2039 |  | 
 | 2040 | 	if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) | 
 | 2041 | 		ifsta->auth_alg = WLAN_AUTH_OPEN; | 
 | 2042 | 	else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) | 
 | 2043 | 		ifsta->auth_alg = WLAN_AUTH_SHARED_KEY; | 
 | 2044 | 	else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) | 
 | 2045 | 		ifsta->auth_alg = WLAN_AUTH_LEAP; | 
 | 2046 | 	else | 
 | 2047 | 		ifsta->auth_alg = WLAN_AUTH_OPEN; | 
 | 2048 | 	printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name, | 
 | 2049 | 	       ifsta->auth_alg); | 
 | 2050 | 	ifsta->auth_transaction = -1; | 
 | 2051 | 	ifsta->associated = ifsta->auth_tries = ifsta->assoc_tries = 0; | 
 | 2052 | 	netif_carrier_off(dev); | 
 | 2053 | } | 
 | 2054 |  | 
 | 2055 |  | 
 | 2056 | void ieee80211_sta_req_auth(struct net_device *dev, | 
 | 2057 | 			    struct ieee80211_if_sta *ifsta) | 
 | 2058 | { | 
 | 2059 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2060 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2061 |  | 
 | 2062 | 	if (sdata->type != IEEE80211_IF_TYPE_STA) | 
 | 2063 | 		return; | 
 | 2064 |  | 
 | 2065 | 	if ((ifsta->bssid_set || ifsta->auto_bssid_sel) && | 
 | 2066 | 	    (ifsta->ssid_set || ifsta->auto_ssid_sel)) { | 
 | 2067 | 		set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); | 
 | 2068 | 		queue_work(local->hw.workqueue, &ifsta->work); | 
 | 2069 | 	} | 
 | 2070 | } | 
 | 2071 |  | 
 | 2072 | static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta, | 
 | 2073 | 				    const char *ssid, int ssid_len) | 
 | 2074 | { | 
 | 2075 | 	int tmp, hidden_ssid; | 
 | 2076 |  | 
 | 2077 | 	if (!memcmp(ifsta->ssid, ssid, ssid_len)) | 
 | 2078 | 		return 1; | 
 | 2079 |  | 
 | 2080 | 	if (ifsta->auto_bssid_sel) | 
 | 2081 | 		return 0; | 
 | 2082 |  | 
 | 2083 | 	hidden_ssid = 1; | 
 | 2084 | 	tmp = ssid_len; | 
 | 2085 | 	while (tmp--) { | 
 | 2086 | 		if (ssid[tmp] != '\0') { | 
 | 2087 | 			hidden_ssid = 0; | 
 | 2088 | 			break; | 
 | 2089 | 		} | 
 | 2090 | 	} | 
 | 2091 |  | 
 | 2092 | 	if (hidden_ssid && ifsta->ssid_len == ssid_len) | 
 | 2093 | 		return 1; | 
 | 2094 |  | 
 | 2095 | 	if (ssid_len == 1 && ssid[0] == ' ') | 
 | 2096 | 		return 1; | 
 | 2097 |  | 
 | 2098 | 	return 0; | 
 | 2099 | } | 
 | 2100 |  | 
 | 2101 | static int ieee80211_sta_config_auth(struct net_device *dev, | 
 | 2102 | 				     struct ieee80211_if_sta *ifsta) | 
 | 2103 | { | 
 | 2104 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2105 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2106 | 	struct ieee80211_sta_bss *bss, *selected = NULL; | 
 | 2107 | 	int top_rssi = 0, freq; | 
 | 2108 |  | 
 | 2109 | 	rtnl_lock(); | 
 | 2110 |  | 
 | 2111 | 	if (!ifsta->auto_channel_sel && !ifsta->auto_bssid_sel && | 
 | 2112 | 	    !ifsta->auto_ssid_sel) { | 
 | 2113 | 		ifsta->state = IEEE80211_AUTHENTICATE; | 
 | 2114 | 		rtnl_unlock(); | 
 | 2115 | 		ieee80211_sta_reset_auth(dev, ifsta); | 
 | 2116 | 		return 0; | 
 | 2117 | 	} | 
 | 2118 |  | 
 | 2119 | 	spin_lock_bh(&local->sta_bss_lock); | 
 | 2120 | 	freq = local->oper_channel->freq; | 
 | 2121 | 	list_for_each_entry(bss, &local->sta_bss_list, list) { | 
 | 2122 | 		if (!(bss->capability & WLAN_CAPABILITY_ESS)) | 
 | 2123 | 			continue; | 
 | 2124 |  | 
 | 2125 | 		if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^ | 
 | 2126 | 		    !!sdata->default_key) | 
 | 2127 | 			continue; | 
 | 2128 |  | 
 | 2129 | 		if (!ifsta->auto_channel_sel && bss->freq != freq) | 
 | 2130 | 			continue; | 
 | 2131 |  | 
 | 2132 | 		if (!ifsta->auto_bssid_sel && | 
 | 2133 | 		    memcmp(bss->bssid, ifsta->bssid, ETH_ALEN)) | 
 | 2134 | 			continue; | 
 | 2135 |  | 
 | 2136 | 		if (!ifsta->auto_ssid_sel && | 
 | 2137 | 		    !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len)) | 
 | 2138 | 			continue; | 
 | 2139 |  | 
 | 2140 | 		if (!selected || top_rssi < bss->rssi) { | 
 | 2141 | 			selected = bss; | 
 | 2142 | 			top_rssi = bss->rssi; | 
 | 2143 | 		} | 
 | 2144 | 	} | 
 | 2145 | 	if (selected) | 
 | 2146 | 		atomic_inc(&selected->users); | 
 | 2147 | 	spin_unlock_bh(&local->sta_bss_lock); | 
 | 2148 |  | 
 | 2149 | 	if (selected) { | 
 | 2150 | 		ieee80211_set_channel(local, -1, selected->freq); | 
 | 2151 | 		if (!ifsta->ssid_set) | 
 | 2152 | 			ieee80211_sta_set_ssid(dev, selected->ssid, | 
 | 2153 | 					       selected->ssid_len); | 
 | 2154 | 		ieee80211_sta_set_bssid(dev, selected->bssid); | 
 | 2155 | 		ieee80211_rx_bss_put(dev, selected); | 
 | 2156 | 		ifsta->state = IEEE80211_AUTHENTICATE; | 
 | 2157 | 		rtnl_unlock(); | 
 | 2158 | 		ieee80211_sta_reset_auth(dev, ifsta); | 
 | 2159 | 		return 0; | 
 | 2160 | 	} else { | 
 | 2161 | 		if (ifsta->state != IEEE80211_AUTHENTICATE) { | 
 | 2162 | 			ieee80211_sta_start_scan(dev, NULL, 0); | 
 | 2163 | 			ifsta->state = IEEE80211_AUTHENTICATE; | 
 | 2164 | 			set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); | 
 | 2165 | 		} else | 
 | 2166 | 			ifsta->state = IEEE80211_DISABLED; | 
 | 2167 | 	} | 
 | 2168 | 	rtnl_unlock(); | 
 | 2169 | 	return -1; | 
 | 2170 | } | 
 | 2171 |  | 
 | 2172 | static int ieee80211_sta_join_ibss(struct net_device *dev, | 
 | 2173 | 				   struct ieee80211_if_sta *ifsta, | 
 | 2174 | 				   struct ieee80211_sta_bss *bss) | 
 | 2175 | { | 
 | 2176 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2177 | 	int res, rates, i, j; | 
 | 2178 | 	struct sk_buff *skb; | 
 | 2179 | 	struct ieee80211_mgmt *mgmt; | 
 | 2180 | 	struct ieee80211_tx_control control; | 
 | 2181 | 	struct ieee80211_rate *rate; | 
 | 2182 | 	struct ieee80211_hw_mode *mode; | 
 | 2183 | 	struct rate_control_extra extra; | 
 | 2184 | 	u8 *pos; | 
 | 2185 | 	struct ieee80211_sub_if_data *sdata; | 
 | 2186 |  | 
 | 2187 | 	/* Remove possible STA entries from other IBSS networks. */ | 
 | 2188 | 	sta_info_flush(local, NULL); | 
 | 2189 |  | 
 | 2190 | 	if (local->ops->reset_tsf) { | 
 | 2191 | 		/* Reset own TSF to allow time synchronization work. */ | 
 | 2192 | 		local->ops->reset_tsf(local_to_hw(local)); | 
 | 2193 | 	} | 
 | 2194 | 	memcpy(ifsta->bssid, bss->bssid, ETH_ALEN); | 
 | 2195 | 	res = ieee80211_if_config(dev); | 
 | 2196 | 	if (res) | 
 | 2197 | 		return res; | 
 | 2198 |  | 
 | 2199 | 	local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10; | 
 | 2200 |  | 
 | 2201 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2202 | 	sdata->drop_unencrypted = bss->capability & | 
 | 2203 | 		WLAN_CAPABILITY_PRIVACY ? 1 : 0; | 
 | 2204 |  | 
 | 2205 | 	res = ieee80211_set_channel(local, -1, bss->freq); | 
 | 2206 |  | 
 | 2207 | 	if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) { | 
 | 2208 | 		printk(KERN_DEBUG "%s: IBSS not allowed on channel %d " | 
 | 2209 | 		       "(%d MHz)\n", dev->name, local->hw.conf.channel, | 
 | 2210 | 		       local->hw.conf.freq); | 
 | 2211 | 		return -1; | 
 | 2212 | 	} | 
 | 2213 |  | 
 | 2214 | 	/* Set beacon template based on scan results */ | 
 | 2215 | 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); | 
 | 2216 | 	do { | 
 | 2217 | 		if (!skb) | 
 | 2218 | 			break; | 
 | 2219 |  | 
 | 2220 | 		skb_reserve(skb, local->hw.extra_tx_headroom); | 
 | 2221 |  | 
 | 2222 | 		mgmt = (struct ieee80211_mgmt *) | 
 | 2223 | 			skb_put(skb, 24 + sizeof(mgmt->u.beacon)); | 
 | 2224 | 		memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); | 
 | 2225 | 		mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, | 
 | 2226 | 						   IEEE80211_STYPE_BEACON); | 
 | 2227 | 		memset(mgmt->da, 0xff, ETH_ALEN); | 
 | 2228 | 		memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); | 
 | 2229 | 		memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | 
 | 2230 | 		mgmt->u.beacon.beacon_int = | 
 | 2231 | 			cpu_to_le16(local->hw.conf.beacon_int); | 
 | 2232 | 		mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability); | 
 | 2233 |  | 
 | 2234 | 		pos = skb_put(skb, 2 + ifsta->ssid_len); | 
 | 2235 | 		*pos++ = WLAN_EID_SSID; | 
 | 2236 | 		*pos++ = ifsta->ssid_len; | 
 | 2237 | 		memcpy(pos, ifsta->ssid, ifsta->ssid_len); | 
 | 2238 |  | 
 | 2239 | 		rates = bss->supp_rates_len; | 
 | 2240 | 		if (rates > 8) | 
 | 2241 | 			rates = 8; | 
 | 2242 | 		pos = skb_put(skb, 2 + rates); | 
 | 2243 | 		*pos++ = WLAN_EID_SUPP_RATES; | 
 | 2244 | 		*pos++ = rates; | 
 | 2245 | 		memcpy(pos, bss->supp_rates, rates); | 
 | 2246 |  | 
 | 2247 | 		pos = skb_put(skb, 2 + 1); | 
 | 2248 | 		*pos++ = WLAN_EID_DS_PARAMS; | 
 | 2249 | 		*pos++ = 1; | 
 | 2250 | 		*pos++ = bss->channel; | 
 | 2251 |  | 
 | 2252 | 		pos = skb_put(skb, 2 + 2); | 
 | 2253 | 		*pos++ = WLAN_EID_IBSS_PARAMS; | 
 | 2254 | 		*pos++ = 2; | 
 | 2255 | 		/* FIX: set ATIM window based on scan results */ | 
 | 2256 | 		*pos++ = 0; | 
 | 2257 | 		*pos++ = 0; | 
 | 2258 |  | 
 | 2259 | 		if (bss->supp_rates_len > 8) { | 
 | 2260 | 			rates = bss->supp_rates_len - 8; | 
 | 2261 | 			pos = skb_put(skb, 2 + rates); | 
 | 2262 | 			*pos++ = WLAN_EID_EXT_SUPP_RATES; | 
 | 2263 | 			*pos++ = rates; | 
 | 2264 | 			memcpy(pos, &bss->supp_rates[8], rates); | 
 | 2265 | 		} | 
 | 2266 |  | 
 | 2267 | 		memset(&control, 0, sizeof(control)); | 
 | 2268 | 		memset(&extra, 0, sizeof(extra)); | 
 | 2269 | 		extra.mode = local->oper_hw_mode; | 
 | 2270 | 		rate = rate_control_get_rate(local, dev, skb, &extra); | 
 | 2271 | 		if (!rate) { | 
 | 2272 | 			printk(KERN_DEBUG "%s: Failed to determine TX rate " | 
 | 2273 | 			       "for IBSS beacon\n", dev->name); | 
 | 2274 | 			break; | 
 | 2275 | 		} | 
 | 2276 | 		control.tx_rate = (local->short_preamble && | 
 | 2277 | 				   (rate->flags & IEEE80211_RATE_PREAMBLE2)) ? | 
 | 2278 | 			rate->val2 : rate->val; | 
 | 2279 | 		control.antenna_sel_tx = local->hw.conf.antenna_sel_tx; | 
 | 2280 | 		control.power_level = local->hw.conf.power_level; | 
 | 2281 | 		control.flags |= IEEE80211_TXCTL_NO_ACK; | 
 | 2282 | 		control.retry_limit = 1; | 
 | 2283 |  | 
 | 2284 | 		ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC); | 
 | 2285 | 		if (ifsta->probe_resp) { | 
 | 2286 | 			mgmt = (struct ieee80211_mgmt *) | 
 | 2287 | 				ifsta->probe_resp->data; | 
 | 2288 | 			mgmt->frame_control = | 
 | 2289 | 				IEEE80211_FC(IEEE80211_FTYPE_MGMT, | 
 | 2290 | 					     IEEE80211_STYPE_PROBE_RESP); | 
 | 2291 | 		} else { | 
 | 2292 | 			printk(KERN_DEBUG "%s: Could not allocate ProbeResp " | 
 | 2293 | 			       "template for IBSS\n", dev->name); | 
 | 2294 | 		} | 
 | 2295 |  | 
 | 2296 | 		if (local->ops->beacon_update && | 
 | 2297 | 		    local->ops->beacon_update(local_to_hw(local), | 
 | 2298 | 					     skb, &control) == 0) { | 
 | 2299 | 			printk(KERN_DEBUG "%s: Configured IBSS beacon " | 
 | 2300 | 			       "template based on scan results\n", dev->name); | 
 | 2301 | 			skb = NULL; | 
 | 2302 | 		} | 
 | 2303 |  | 
 | 2304 | 		rates = 0; | 
 | 2305 | 		mode = local->oper_hw_mode; | 
 | 2306 | 		for (i = 0; i < bss->supp_rates_len; i++) { | 
 | 2307 | 			int bitrate = (bss->supp_rates[i] & 0x7f) * 5; | 
 | 2308 | 			if (mode->mode == MODE_ATHEROS_TURBO) | 
 | 2309 | 				bitrate *= 2; | 
 | 2310 | 			for (j = 0; j < mode->num_rates; j++) | 
 | 2311 | 				if (mode->rates[j].rate == bitrate) | 
 | 2312 | 					rates |= BIT(j); | 
 | 2313 | 		} | 
 | 2314 | 		ifsta->supp_rates_bits = rates; | 
 | 2315 | 	} while (0); | 
 | 2316 |  | 
 | 2317 | 	if (skb) { | 
 | 2318 | 		printk(KERN_DEBUG "%s: Failed to configure IBSS beacon " | 
 | 2319 | 		       "template\n", dev->name); | 
 | 2320 | 		dev_kfree_skb(skb); | 
 | 2321 | 	} | 
 | 2322 |  | 
 | 2323 | 	ifsta->state = IEEE80211_IBSS_JOINED; | 
 | 2324 | 	mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); | 
 | 2325 |  | 
 | 2326 | 	ieee80211_rx_bss_put(dev, bss); | 
 | 2327 |  | 
 | 2328 | 	return res; | 
 | 2329 | } | 
 | 2330 |  | 
 | 2331 |  | 
 | 2332 | static int ieee80211_sta_create_ibss(struct net_device *dev, | 
 | 2333 | 				     struct ieee80211_if_sta *ifsta) | 
 | 2334 | { | 
 | 2335 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2336 | 	struct ieee80211_sta_bss *bss; | 
 | 2337 | 	struct ieee80211_sub_if_data *sdata; | 
 | 2338 | 	struct ieee80211_hw_mode *mode; | 
 | 2339 | 	u8 bssid[ETH_ALEN], *pos; | 
 | 2340 | 	int i; | 
 | 2341 |  | 
 | 2342 | #if 0 | 
 | 2343 | 	/* Easier testing, use fixed BSSID. */ | 
 | 2344 | 	memset(bssid, 0xfe, ETH_ALEN); | 
 | 2345 | #else | 
 | 2346 | 	/* Generate random, not broadcast, locally administered BSSID. Mix in | 
 | 2347 | 	 * own MAC address to make sure that devices that do not have proper | 
 | 2348 | 	 * random number generator get different BSSID. */ | 
 | 2349 | 	get_random_bytes(bssid, ETH_ALEN); | 
 | 2350 | 	for (i = 0; i < ETH_ALEN; i++) | 
 | 2351 | 		bssid[i] ^= dev->dev_addr[i]; | 
 | 2352 | 	bssid[0] &= ~0x01; | 
 | 2353 | 	bssid[0] |= 0x02; | 
 | 2354 | #endif | 
 | 2355 |  | 
 | 2356 | 	printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID " MAC_FMT "\n", | 
 | 2357 | 	       dev->name, MAC_ARG(bssid)); | 
 | 2358 |  | 
 | 2359 | 	bss = ieee80211_rx_bss_add(dev, bssid); | 
 | 2360 | 	if (!bss) | 
 | 2361 | 		return -ENOMEM; | 
 | 2362 |  | 
 | 2363 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2364 | 	mode = local->oper_hw_mode; | 
 | 2365 |  | 
 | 2366 | 	if (local->hw.conf.beacon_int == 0) | 
 | 2367 | 		local->hw.conf.beacon_int = 100; | 
 | 2368 | 	bss->beacon_int = local->hw.conf.beacon_int; | 
 | 2369 | 	bss->hw_mode = local->hw.conf.phymode; | 
 | 2370 | 	bss->channel = local->hw.conf.channel; | 
 | 2371 | 	bss->freq = local->hw.conf.freq; | 
 | 2372 | 	bss->last_update = jiffies; | 
 | 2373 | 	bss->capability = WLAN_CAPABILITY_IBSS; | 
 | 2374 | 	if (sdata->default_key) { | 
 | 2375 | 		bss->capability |= WLAN_CAPABILITY_PRIVACY; | 
 | 2376 | 	} else | 
 | 2377 | 		sdata->drop_unencrypted = 0; | 
 | 2378 | 	bss->supp_rates_len = mode->num_rates; | 
 | 2379 | 	pos = bss->supp_rates; | 
 | 2380 | 	for (i = 0; i < mode->num_rates; i++) { | 
 | 2381 | 		int rate = mode->rates[i].rate; | 
 | 2382 | 		if (mode->mode == MODE_ATHEROS_TURBO) | 
 | 2383 | 			rate /= 2; | 
 | 2384 | 		*pos++ = (u8) (rate / 5); | 
 | 2385 | 	} | 
 | 2386 |  | 
 | 2387 | 	return ieee80211_sta_join_ibss(dev, ifsta, bss); | 
 | 2388 | } | 
 | 2389 |  | 
 | 2390 |  | 
 | 2391 | static int ieee80211_sta_find_ibss(struct net_device *dev, | 
 | 2392 | 				   struct ieee80211_if_sta *ifsta) | 
 | 2393 | { | 
 | 2394 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2395 | 	struct ieee80211_sta_bss *bss; | 
 | 2396 | 	int found = 0; | 
 | 2397 | 	u8 bssid[ETH_ALEN]; | 
 | 2398 | 	int active_ibss; | 
 | 2399 |  | 
 | 2400 | 	if (ifsta->ssid_len == 0) | 
 | 2401 | 		return -EINVAL; | 
 | 2402 |  | 
 | 2403 | 	active_ibss = ieee80211_sta_active_ibss(dev); | 
 | 2404 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | 
 | 2405 | 	printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", | 
 | 2406 | 	       dev->name, active_ibss); | 
 | 2407 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | 
 | 2408 | 	spin_lock_bh(&local->sta_bss_lock); | 
 | 2409 | 	list_for_each_entry(bss, &local->sta_bss_list, list) { | 
 | 2410 | 		if (ifsta->ssid_len != bss->ssid_len || | 
 | 2411 | 		    memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0 | 
 | 2412 | 		    || !(bss->capability & WLAN_CAPABILITY_IBSS)) | 
 | 2413 | 			continue; | 
 | 2414 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | 
 | 2415 | 		printk(KERN_DEBUG "   bssid=" MAC_FMT " found\n", | 
 | 2416 | 		       MAC_ARG(bss->bssid)); | 
 | 2417 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | 
 | 2418 | 		memcpy(bssid, bss->bssid, ETH_ALEN); | 
 | 2419 | 		found = 1; | 
 | 2420 | 		if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0) | 
 | 2421 | 			break; | 
 | 2422 | 	} | 
 | 2423 | 	spin_unlock_bh(&local->sta_bss_lock); | 
 | 2424 |  | 
 | 2425 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | 
 | 2426 | 	printk(KERN_DEBUG "   sta_find_ibss: selected " MAC_FMT " current " | 
 | 2427 | 	       MAC_FMT "\n", MAC_ARG(bssid), MAC_ARG(ifsta->bssid)); | 
 | 2428 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | 
 | 2429 | 	if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 && | 
 | 2430 | 	    (bss = ieee80211_rx_bss_get(dev, bssid))) { | 
 | 2431 | 		printk(KERN_DEBUG "%s: Selected IBSS BSSID " MAC_FMT | 
 | 2432 | 		       " based on configured SSID\n", | 
 | 2433 | 		       dev->name, MAC_ARG(bssid)); | 
 | 2434 | 		return ieee80211_sta_join_ibss(dev, ifsta, bss); | 
 | 2435 | 	} | 
 | 2436 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | 
 | 2437 | 	printk(KERN_DEBUG "   did not try to join ibss\n"); | 
 | 2438 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | 
 | 2439 |  | 
 | 2440 | 	/* Selected IBSS not found in current scan results - try to scan */ | 
 | 2441 | 	if (ifsta->state == IEEE80211_IBSS_JOINED && | 
 | 2442 | 	    !ieee80211_sta_active_ibss(dev)) { | 
 | 2443 | 		mod_timer(&ifsta->timer, jiffies + | 
 | 2444 | 				      IEEE80211_IBSS_MERGE_INTERVAL); | 
 | 2445 | 	} else if (time_after(jiffies, local->last_scan_completed + | 
 | 2446 | 			      IEEE80211_SCAN_INTERVAL)) { | 
 | 2447 | 		printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " | 
 | 2448 | 		       "join\n", dev->name); | 
 | 2449 | 		return ieee80211_sta_req_scan(dev, ifsta->ssid, | 
 | 2450 | 					      ifsta->ssid_len); | 
 | 2451 | 	} else if (ifsta->state != IEEE80211_IBSS_JOINED) { | 
 | 2452 | 		int interval = IEEE80211_SCAN_INTERVAL; | 
 | 2453 |  | 
 | 2454 | 		if (time_after(jiffies, ifsta->ibss_join_req + | 
 | 2455 | 			       IEEE80211_IBSS_JOIN_TIMEOUT)) { | 
 | 2456 | 			if (ifsta->create_ibss && | 
 | 2457 | 			    local->oper_channel->flag & IEEE80211_CHAN_W_IBSS) | 
 | 2458 | 				return ieee80211_sta_create_ibss(dev, ifsta); | 
 | 2459 | 			if (ifsta->create_ibss) { | 
 | 2460 | 				printk(KERN_DEBUG "%s: IBSS not allowed on the" | 
 | 2461 | 				       " configured channel %d (%d MHz)\n", | 
 | 2462 | 				       dev->name, local->hw.conf.channel, | 
 | 2463 | 				       local->hw.conf.freq); | 
 | 2464 | 			} | 
 | 2465 |  | 
 | 2466 | 			/* No IBSS found - decrease scan interval and continue | 
 | 2467 | 			 * scanning. */ | 
 | 2468 | 			interval = IEEE80211_SCAN_INTERVAL_SLOW; | 
 | 2469 | 		} | 
 | 2470 |  | 
 | 2471 | 		ifsta->state = IEEE80211_IBSS_SEARCH; | 
 | 2472 | 		mod_timer(&ifsta->timer, jiffies + interval); | 
 | 2473 | 		return 0; | 
 | 2474 | 	} | 
 | 2475 |  | 
 | 2476 | 	return 0; | 
 | 2477 | } | 
 | 2478 |  | 
 | 2479 |  | 
 | 2480 | int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len) | 
 | 2481 | { | 
 | 2482 | 	struct ieee80211_sub_if_data *sdata; | 
 | 2483 | 	struct ieee80211_if_sta *ifsta; | 
 | 2484 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2485 |  | 
 | 2486 | 	if (len > IEEE80211_MAX_SSID_LEN) | 
 | 2487 | 		return -EINVAL; | 
 | 2488 |  | 
 | 2489 | 	/* TODO: This should always be done for IBSS, even if IEEE80211_QOS is | 
 | 2490 | 	 * not defined. */ | 
 | 2491 | 	if (local->ops->conf_tx) { | 
 | 2492 | 		struct ieee80211_tx_queue_params qparam; | 
 | 2493 | 		int i; | 
 | 2494 |  | 
 | 2495 | 		memset(&qparam, 0, sizeof(qparam)); | 
 | 2496 | 		/* TODO: are these ok defaults for all hw_modes? */ | 
 | 2497 | 		qparam.aifs = 2; | 
 | 2498 | 		qparam.cw_min = | 
 | 2499 | 			local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15; | 
 | 2500 | 		qparam.cw_max = 1023; | 
 | 2501 | 		qparam.burst_time = 0; | 
 | 2502 | 		for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++) | 
 | 2503 | 		{ | 
 | 2504 | 			local->ops->conf_tx(local_to_hw(local), | 
 | 2505 | 					   i + IEEE80211_TX_QUEUE_DATA0, | 
 | 2506 | 					   &qparam); | 
 | 2507 | 		} | 
 | 2508 | 		/* IBSS uses different parameters for Beacon sending */ | 
 | 2509 | 		qparam.cw_min++; | 
 | 2510 | 		qparam.cw_min *= 2; | 
 | 2511 | 		qparam.cw_min--; | 
 | 2512 | 		local->ops->conf_tx(local_to_hw(local), | 
 | 2513 | 				   IEEE80211_TX_QUEUE_BEACON, &qparam); | 
 | 2514 | 	} | 
 | 2515 |  | 
 | 2516 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2517 | 	ifsta = &sdata->u.sta; | 
 | 2518 |  | 
 | 2519 | 	if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) | 
 | 2520 | 		ifsta->prev_bssid_set = 0; | 
 | 2521 | 	memcpy(ifsta->ssid, ssid, len); | 
 | 2522 | 	memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len); | 
 | 2523 | 	ifsta->ssid_len = len; | 
 | 2524 |  | 
 | 2525 | 	ifsta->ssid_set = len ? 1 : 0; | 
 | 2526 | 	if (sdata->type == IEEE80211_IF_TYPE_IBSS && !ifsta->bssid_set) { | 
 | 2527 | 		ifsta->ibss_join_req = jiffies; | 
 | 2528 | 		ifsta->state = IEEE80211_IBSS_SEARCH; | 
 | 2529 | 		return ieee80211_sta_find_ibss(dev, ifsta); | 
 | 2530 | 	} | 
 | 2531 | 	return 0; | 
 | 2532 | } | 
 | 2533 |  | 
 | 2534 |  | 
 | 2535 | int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len) | 
 | 2536 | { | 
 | 2537 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2538 | 	struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 
 | 2539 | 	memcpy(ssid, ifsta->ssid, ifsta->ssid_len); | 
 | 2540 | 	*len = ifsta->ssid_len; | 
 | 2541 | 	return 0; | 
 | 2542 | } | 
 | 2543 |  | 
 | 2544 |  | 
 | 2545 | int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid) | 
 | 2546 | { | 
 | 2547 | 	struct ieee80211_sub_if_data *sdata; | 
 | 2548 | 	struct ieee80211_if_sta *ifsta; | 
 | 2549 | 	int res; | 
 | 2550 |  | 
 | 2551 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2552 | 	ifsta = &sdata->u.sta; | 
 | 2553 |  | 
 | 2554 | 	if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { | 
 | 2555 | 		memcpy(ifsta->bssid, bssid, ETH_ALEN); | 
 | 2556 | 		res = ieee80211_if_config(dev); | 
 | 2557 | 		if (res) { | 
 | 2558 | 			printk(KERN_DEBUG "%s: Failed to config new BSSID to " | 
 | 2559 | 			       "the low-level driver\n", dev->name); | 
 | 2560 | 			return res; | 
 | 2561 | 		} | 
 | 2562 | 	} | 
 | 2563 |  | 
 | 2564 | 	if (!is_valid_ether_addr(bssid)) | 
 | 2565 | 		ifsta->bssid_set = 0; | 
 | 2566 | 	else | 
 | 2567 | 		ifsta->bssid_set = 1; | 
 | 2568 | 	return 0; | 
 | 2569 | } | 
 | 2570 |  | 
 | 2571 |  | 
 | 2572 | static void ieee80211_send_nullfunc(struct ieee80211_local *local, | 
 | 2573 | 				    struct ieee80211_sub_if_data *sdata, | 
 | 2574 | 				    int powersave) | 
 | 2575 | { | 
 | 2576 | 	struct sk_buff *skb; | 
 | 2577 | 	struct ieee80211_hdr *nullfunc; | 
 | 2578 | 	u16 fc; | 
 | 2579 |  | 
 | 2580 | 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); | 
 | 2581 | 	if (!skb) { | 
 | 2582 | 		printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " | 
 | 2583 | 		       "frame\n", sdata->dev->name); | 
 | 2584 | 		return; | 
 | 2585 | 	} | 
 | 2586 | 	skb_reserve(skb, local->hw.extra_tx_headroom); | 
 | 2587 |  | 
 | 2588 | 	nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); | 
 | 2589 | 	memset(nullfunc, 0, 24); | 
 | 2590 | 	fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | | 
 | 2591 | 	     IEEE80211_FCTL_TODS; | 
 | 2592 | 	if (powersave) | 
 | 2593 | 		fc |= IEEE80211_FCTL_PM; | 
 | 2594 | 	nullfunc->frame_control = cpu_to_le16(fc); | 
 | 2595 | 	memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); | 
 | 2596 | 	memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); | 
 | 2597 | 	memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); | 
 | 2598 |  | 
 | 2599 | 	ieee80211_sta_tx(sdata->dev, skb, 0); | 
 | 2600 | } | 
 | 2601 |  | 
 | 2602 |  | 
 | 2603 | void ieee80211_scan_completed(struct ieee80211_hw *hw) | 
 | 2604 | { | 
 | 2605 | 	struct ieee80211_local *local = hw_to_local(hw); | 
 | 2606 | 	struct net_device *dev = local->scan_dev; | 
 | 2607 | 	struct ieee80211_sub_if_data *sdata; | 
 | 2608 | 	union iwreq_data wrqu; | 
 | 2609 |  | 
 | 2610 | 	local->last_scan_completed = jiffies; | 
 | 2611 | 	wmb(); | 
 | 2612 | 	local->sta_scanning = 0; | 
 | 2613 |  | 
 | 2614 | 	if (ieee80211_hw_config(local)) | 
 | 2615 | 		printk(KERN_DEBUG "%s: failed to restore operational" | 
 | 2616 | 		       "channel after scan\n", dev->name); | 
 | 2617 |  | 
 | 2618 | 	if (!(local->hw.flags & IEEE80211_HW_NO_PROBE_FILTERING) && | 
 | 2619 | 	    ieee80211_if_config(dev)) | 
 | 2620 | 		printk(KERN_DEBUG "%s: failed to restore operational" | 
 | 2621 | 		       "BSSID after scan\n", dev->name); | 
 | 2622 |  | 
 | 2623 | 	memset(&wrqu, 0, sizeof(wrqu)); | 
 | 2624 | 	wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); | 
 | 2625 |  | 
 | 2626 | 	read_lock(&local->sub_if_lock); | 
 | 2627 | 	list_for_each_entry(sdata, &local->sub_if_list, list) { | 
| Mattias Nissler | 14042cb | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 2628 |  | 
 | 2629 | 		/* No need to wake the master device. */ | 
 | 2630 | 		if (sdata->dev == local->mdev) | 
 | 2631 | 			continue; | 
 | 2632 |  | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2633 | 		if (sdata->type == IEEE80211_IF_TYPE_STA) { | 
 | 2634 | 			if (sdata->u.sta.associated) | 
 | 2635 | 				ieee80211_send_nullfunc(local, sdata, 0); | 
 | 2636 | 			ieee80211_sta_timer((unsigned long)sdata); | 
 | 2637 | 		} | 
| Mattias Nissler | 14042cb | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 2638 |  | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2639 | 		netif_wake_queue(sdata->dev); | 
 | 2640 | 	} | 
 | 2641 | 	read_unlock(&local->sub_if_lock); | 
 | 2642 |  | 
 | 2643 | 	sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2644 | 	if (sdata->type == IEEE80211_IF_TYPE_IBSS) { | 
 | 2645 | 		struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 
 | 2646 | 		if (!ifsta->bssid_set || | 
 | 2647 | 		    (!ifsta->state == IEEE80211_IBSS_JOINED && | 
 | 2648 | 		    !ieee80211_sta_active_ibss(dev))) | 
 | 2649 | 			ieee80211_sta_find_ibss(dev, ifsta); | 
 | 2650 | 	} | 
 | 2651 | } | 
 | 2652 | EXPORT_SYMBOL(ieee80211_scan_completed); | 
 | 2653 |  | 
 | 2654 | void ieee80211_sta_scan_work(struct work_struct *work) | 
 | 2655 | { | 
 | 2656 | 	struct ieee80211_local *local = | 
 | 2657 | 		container_of(work, struct ieee80211_local, scan_work.work); | 
 | 2658 | 	struct net_device *dev = local->scan_dev; | 
 | 2659 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2660 | 	struct ieee80211_hw_mode *mode; | 
 | 2661 | 	struct ieee80211_channel *chan; | 
 | 2662 | 	int skip; | 
 | 2663 | 	unsigned long next_delay = 0; | 
 | 2664 |  | 
 | 2665 | 	if (!local->sta_scanning) | 
 | 2666 | 		return; | 
 | 2667 |  | 
 | 2668 | 	switch (local->scan_state) { | 
 | 2669 | 	case SCAN_SET_CHANNEL: | 
 | 2670 | 		mode = local->scan_hw_mode; | 
 | 2671 | 		if (local->scan_hw_mode->list.next == &local->modes_list && | 
 | 2672 | 		    local->scan_channel_idx >= mode->num_channels) { | 
 | 2673 | 			ieee80211_scan_completed(local_to_hw(local)); | 
 | 2674 | 			return; | 
 | 2675 | 		} | 
 | 2676 | 		skip = !(local->enabled_modes & (1 << mode->mode)); | 
 | 2677 | 		chan = &mode->channels[local->scan_channel_idx]; | 
 | 2678 | 		if (!(chan->flag & IEEE80211_CHAN_W_SCAN) || | 
 | 2679 | 		    (sdata->type == IEEE80211_IF_TYPE_IBSS && | 
 | 2680 | 		     !(chan->flag & IEEE80211_CHAN_W_IBSS)) || | 
 | 2681 | 		    (local->hw_modes & local->enabled_modes & | 
 | 2682 | 		     (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B)) | 
 | 2683 | 			skip = 1; | 
 | 2684 |  | 
 | 2685 | 		if (!skip) { | 
 | 2686 | #if 0 | 
 | 2687 | 			printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n", | 
 | 2688 | 			       dev->name, chan->chan, chan->freq); | 
 | 2689 | #endif | 
 | 2690 |  | 
 | 2691 | 			local->scan_channel = chan; | 
 | 2692 | 			if (ieee80211_hw_config(local)) { | 
 | 2693 | 				printk(KERN_DEBUG "%s: failed to set channel " | 
 | 2694 | 				       "%d (%d MHz) for scan\n", dev->name, | 
 | 2695 | 				       chan->chan, chan->freq); | 
 | 2696 | 				skip = 1; | 
 | 2697 | 			} | 
 | 2698 | 		} | 
 | 2699 |  | 
 | 2700 | 		local->scan_channel_idx++; | 
 | 2701 | 		if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) { | 
 | 2702 | 			if (local->scan_hw_mode->list.next != &local->modes_list) { | 
 | 2703 | 				local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next, | 
 | 2704 | 								 struct ieee80211_hw_mode, | 
 | 2705 | 								 list); | 
 | 2706 | 				local->scan_channel_idx = 0; | 
 | 2707 | 			} | 
 | 2708 | 		} | 
 | 2709 |  | 
 | 2710 | 		if (skip) | 
 | 2711 | 			break; | 
 | 2712 |  | 
 | 2713 | 		next_delay = IEEE80211_PROBE_DELAY + | 
 | 2714 | 			     usecs_to_jiffies(local->hw.channel_change_time); | 
 | 2715 | 		local->scan_state = SCAN_SEND_PROBE; | 
 | 2716 | 		break; | 
 | 2717 | 	case SCAN_SEND_PROBE: | 
 | 2718 | 		if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) { | 
 | 2719 | 			ieee80211_send_probe_req(dev, NULL, local->scan_ssid, | 
 | 2720 | 						 local->scan_ssid_len); | 
 | 2721 | 			next_delay = IEEE80211_CHANNEL_TIME; | 
 | 2722 | 		} else | 
 | 2723 | 			next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; | 
 | 2724 | 		local->scan_state = SCAN_SET_CHANNEL; | 
 | 2725 | 		break; | 
 | 2726 | 	} | 
 | 2727 |  | 
 | 2728 | 	if (local->sta_scanning) | 
 | 2729 | 		queue_delayed_work(local->hw.workqueue, &local->scan_work, | 
 | 2730 | 				   next_delay); | 
 | 2731 | } | 
 | 2732 |  | 
 | 2733 |  | 
 | 2734 | static int ieee80211_sta_start_scan(struct net_device *dev, | 
 | 2735 | 				    u8 *ssid, size_t ssid_len) | 
 | 2736 | { | 
 | 2737 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2738 | 	struct ieee80211_sub_if_data *sdata; | 
 | 2739 |  | 
 | 2740 | 	if (ssid_len > IEEE80211_MAX_SSID_LEN) | 
 | 2741 | 		return -EINVAL; | 
 | 2742 |  | 
 | 2743 | 	/* MLME-SCAN.request (page 118)  page 144 (11.1.3.1) | 
 | 2744 | 	 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS | 
 | 2745 | 	 * BSSID: MACAddress | 
 | 2746 | 	 * SSID | 
 | 2747 | 	 * ScanType: ACTIVE, PASSIVE | 
 | 2748 | 	 * ProbeDelay: delay (in microseconds) to be used prior to transmitting | 
 | 2749 | 	 *    a Probe frame during active scanning | 
 | 2750 | 	 * ChannelList | 
 | 2751 | 	 * MinChannelTime (>= ProbeDelay), in TU | 
 | 2752 | 	 * MaxChannelTime: (>= MinChannelTime), in TU | 
 | 2753 | 	 */ | 
 | 2754 |  | 
 | 2755 | 	 /* MLME-SCAN.confirm | 
 | 2756 | 	  * BSSDescriptionSet | 
 | 2757 | 	  * ResultCode: SUCCESS, INVALID_PARAMETERS | 
 | 2758 | 	 */ | 
 | 2759 |  | 
 | 2760 | 	if (local->sta_scanning) { | 
 | 2761 | 		if (local->scan_dev == dev) | 
 | 2762 | 			return 0; | 
 | 2763 | 		return -EBUSY; | 
 | 2764 | 	} | 
 | 2765 |  | 
 | 2766 | 	if (local->ops->hw_scan) { | 
 | 2767 | 		int rc = local->ops->hw_scan(local_to_hw(local), | 
 | 2768 | 					    ssid, ssid_len); | 
 | 2769 | 		if (!rc) { | 
 | 2770 | 			local->sta_scanning = 1; | 
 | 2771 | 			local->scan_dev = dev; | 
 | 2772 | 		} | 
 | 2773 | 		return rc; | 
 | 2774 | 	} | 
 | 2775 |  | 
 | 2776 | 	local->sta_scanning = 1; | 
 | 2777 |  | 
 | 2778 | 	read_lock(&local->sub_if_lock); | 
 | 2779 | 	list_for_each_entry(sdata, &local->sub_if_list, list) { | 
| Mattias Nissler | 14042cb | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 2780 |  | 
 | 2781 | 		/* Don't stop the master interface, otherwise we can't transmit | 
 | 2782 | 		 * probes! */ | 
 | 2783 | 		if (sdata->dev == local->mdev) | 
 | 2784 | 			continue; | 
 | 2785 |  | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2786 | 		netif_stop_queue(sdata->dev); | 
 | 2787 | 		if (sdata->type == IEEE80211_IF_TYPE_STA && | 
 | 2788 | 		    sdata->u.sta.associated) | 
 | 2789 | 			ieee80211_send_nullfunc(local, sdata, 1); | 
 | 2790 | 	} | 
 | 2791 | 	read_unlock(&local->sub_if_lock); | 
 | 2792 |  | 
 | 2793 | 	if (ssid) { | 
 | 2794 | 		local->scan_ssid_len = ssid_len; | 
 | 2795 | 		memcpy(local->scan_ssid, ssid, ssid_len); | 
 | 2796 | 	} else | 
 | 2797 | 		local->scan_ssid_len = 0; | 
 | 2798 | 	local->scan_state = SCAN_SET_CHANNEL; | 
 | 2799 | 	local->scan_hw_mode = list_entry(local->modes_list.next, | 
 | 2800 | 					 struct ieee80211_hw_mode, | 
 | 2801 | 					 list); | 
 | 2802 | 	local->scan_channel_idx = 0; | 
 | 2803 | 	local->scan_dev = dev; | 
 | 2804 |  | 
 | 2805 | 	if (!(local->hw.flags & IEEE80211_HW_NO_PROBE_FILTERING) && | 
 | 2806 | 	    ieee80211_if_config(dev)) | 
 | 2807 | 		printk(KERN_DEBUG "%s: failed to set BSSID for scan\n", | 
 | 2808 | 		       dev->name); | 
 | 2809 |  | 
 | 2810 | 	/* TODO: start scan as soon as all nullfunc frames are ACKed */ | 
 | 2811 | 	queue_delayed_work(local->hw.workqueue, &local->scan_work, | 
 | 2812 | 			   IEEE80211_CHANNEL_TIME); | 
 | 2813 |  | 
 | 2814 | 	return 0; | 
 | 2815 | } | 
 | 2816 |  | 
 | 2817 |  | 
 | 2818 | int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len) | 
 | 2819 | { | 
 | 2820 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 2821 | 	struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 
 | 2822 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2823 |  | 
 | 2824 | 	if (sdata->type != IEEE80211_IF_TYPE_STA) | 
 | 2825 | 		return ieee80211_sta_start_scan(dev, ssid, ssid_len); | 
 | 2826 |  | 
 | 2827 | 	if (local->sta_scanning) { | 
 | 2828 | 		if (local->scan_dev == dev) | 
 | 2829 | 			return 0; | 
 | 2830 | 		return -EBUSY; | 
 | 2831 | 	} | 
 | 2832 |  | 
 | 2833 | 	set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); | 
 | 2834 | 	queue_work(local->hw.workqueue, &ifsta->work); | 
 | 2835 | 	return 0; | 
 | 2836 | } | 
 | 2837 |  | 
 | 2838 | static char * | 
 | 2839 | ieee80211_sta_scan_result(struct net_device *dev, | 
 | 2840 | 			  struct ieee80211_sta_bss *bss, | 
 | 2841 | 			  char *current_ev, char *end_buf) | 
 | 2842 | { | 
 | 2843 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 2844 | 	struct iw_event iwe; | 
 | 2845 |  | 
 | 2846 | 	if (time_after(jiffies, | 
 | 2847 | 		       bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) | 
 | 2848 | 		return current_ev; | 
 | 2849 |  | 
 | 2850 | 	if (!(local->enabled_modes & (1 << bss->hw_mode))) | 
 | 2851 | 		return current_ev; | 
 | 2852 |  | 
 | 2853 | 	if (local->scan_flags & IEEE80211_SCAN_WPA_ONLY && | 
 | 2854 | 	    !bss->wpa_ie && !bss->rsn_ie) | 
 | 2855 | 		return current_ev; | 
 | 2856 |  | 
 | 2857 | 	if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID && | 
 | 2858 | 	    (local->scan_ssid_len != bss->ssid_len || | 
 | 2859 | 	     memcmp(local->scan_ssid, bss->ssid, bss->ssid_len) != 0)) | 
 | 2860 | 		return current_ev; | 
 | 2861 |  | 
 | 2862 | 	memset(&iwe, 0, sizeof(iwe)); | 
 | 2863 | 	iwe.cmd = SIOCGIWAP; | 
 | 2864 | 	iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | 
 | 2865 | 	memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); | 
 | 2866 | 	current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, | 
 | 2867 | 					  IW_EV_ADDR_LEN); | 
 | 2868 |  | 
 | 2869 | 	memset(&iwe, 0, sizeof(iwe)); | 
 | 2870 | 	iwe.cmd = SIOCGIWESSID; | 
 | 2871 | 	iwe.u.data.length = bss->ssid_len; | 
 | 2872 | 	iwe.u.data.flags = 1; | 
 | 2873 | 	current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, | 
 | 2874 | 					  bss->ssid); | 
 | 2875 |  | 
 | 2876 | 	if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) { | 
 | 2877 | 		memset(&iwe, 0, sizeof(iwe)); | 
 | 2878 | 		iwe.cmd = SIOCGIWMODE; | 
 | 2879 | 		if (bss->capability & WLAN_CAPABILITY_ESS) | 
 | 2880 | 			iwe.u.mode = IW_MODE_MASTER; | 
 | 2881 | 		else | 
 | 2882 | 			iwe.u.mode = IW_MODE_ADHOC; | 
 | 2883 | 		current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, | 
 | 2884 | 						  IW_EV_UINT_LEN); | 
 | 2885 | 	} | 
 | 2886 |  | 
 | 2887 | 	memset(&iwe, 0, sizeof(iwe)); | 
 | 2888 | 	iwe.cmd = SIOCGIWFREQ; | 
 | 2889 | 	iwe.u.freq.m = bss->channel; | 
 | 2890 | 	iwe.u.freq.e = 0; | 
 | 2891 | 	current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, | 
 | 2892 | 					  IW_EV_FREQ_LEN); | 
 | 2893 | 	iwe.u.freq.m = bss->freq * 100000; | 
 | 2894 | 	iwe.u.freq.e = 1; | 
 | 2895 | 	current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, | 
 | 2896 | 					  IW_EV_FREQ_LEN); | 
 | 2897 |  | 
 | 2898 | 	memset(&iwe, 0, sizeof(iwe)); | 
 | 2899 | 	iwe.cmd = IWEVQUAL; | 
 | 2900 | 	iwe.u.qual.qual = bss->signal; | 
 | 2901 | 	iwe.u.qual.level = bss->rssi; | 
 | 2902 | 	iwe.u.qual.noise = bss->noise; | 
 | 2903 | 	iwe.u.qual.updated = local->wstats_flags; | 
 | 2904 | 	current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, | 
 | 2905 | 					  IW_EV_QUAL_LEN); | 
 | 2906 |  | 
 | 2907 | 	memset(&iwe, 0, sizeof(iwe)); | 
 | 2908 | 	iwe.cmd = SIOCGIWENCODE; | 
 | 2909 | 	if (bss->capability & WLAN_CAPABILITY_PRIVACY) | 
 | 2910 | 		iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | 
 | 2911 | 	else | 
 | 2912 | 		iwe.u.data.flags = IW_ENCODE_DISABLED; | 
 | 2913 | 	iwe.u.data.length = 0; | 
 | 2914 | 	current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ""); | 
 | 2915 |  | 
 | 2916 | 	if (bss && bss->wpa_ie) { | 
 | 2917 | 		memset(&iwe, 0, sizeof(iwe)); | 
 | 2918 | 		iwe.cmd = IWEVGENIE; | 
 | 2919 | 		iwe.u.data.length = bss->wpa_ie_len; | 
 | 2920 | 		current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, | 
 | 2921 | 						  bss->wpa_ie); | 
 | 2922 | 	} | 
 | 2923 |  | 
 | 2924 | 	if (bss && bss->rsn_ie) { | 
 | 2925 | 		memset(&iwe, 0, sizeof(iwe)); | 
 | 2926 | 		iwe.cmd = IWEVGENIE; | 
 | 2927 | 		iwe.u.data.length = bss->rsn_ie_len; | 
 | 2928 | 		current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, | 
 | 2929 | 						  bss->rsn_ie); | 
 | 2930 | 	} | 
 | 2931 |  | 
 | 2932 | 	if (bss && bss->supp_rates_len > 0) { | 
 | 2933 | 		/* display all supported rates in readable format */ | 
 | 2934 | 		char *p = current_ev + IW_EV_LCP_LEN; | 
 | 2935 | 		int i; | 
 | 2936 |  | 
 | 2937 | 		memset(&iwe, 0, sizeof(iwe)); | 
 | 2938 | 		iwe.cmd = SIOCGIWRATE; | 
 | 2939 | 		/* Those two flags are ignored... */ | 
 | 2940 | 		iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | 
 | 2941 |  | 
 | 2942 | 		for (i = 0; i < bss->supp_rates_len; i++) { | 
 | 2943 | 			iwe.u.bitrate.value = ((bss->supp_rates[i] & | 
 | 2944 | 							0x7f) * 500000); | 
 | 2945 | 			p = iwe_stream_add_value(current_ev, p, | 
 | 2946 | 					end_buf, &iwe, IW_EV_PARAM_LEN); | 
 | 2947 | 		} | 
 | 2948 | 		current_ev = p; | 
 | 2949 | 	} | 
 | 2950 |  | 
 | 2951 | 	if (bss) { | 
 | 2952 | 		char *buf; | 
 | 2953 | 		buf = kmalloc(30, GFP_ATOMIC); | 
 | 2954 | 		if (buf) { | 
 | 2955 | 			memset(&iwe, 0, sizeof(iwe)); | 
 | 2956 | 			iwe.cmd = IWEVCUSTOM; | 
 | 2957 | 			sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); | 
 | 2958 | 			iwe.u.data.length = strlen(buf); | 
 | 2959 | 			current_ev = iwe_stream_add_point(current_ev, end_buf, | 
 | 2960 | 							  &iwe, buf); | 
 | 2961 | 			kfree(buf); | 
 | 2962 | 		} | 
 | 2963 | 	} | 
 | 2964 |  | 
 | 2965 | 	do { | 
 | 2966 | 		char *buf; | 
 | 2967 |  | 
 | 2968 | 		if (!(local->scan_flags & IEEE80211_SCAN_EXTRA_INFO)) | 
 | 2969 | 			break; | 
 | 2970 |  | 
 | 2971 | 		buf = kmalloc(100, GFP_ATOMIC); | 
 | 2972 | 		if (!buf) | 
 | 2973 | 			break; | 
 | 2974 |  | 
 | 2975 | 		memset(&iwe, 0, sizeof(iwe)); | 
 | 2976 | 		iwe.cmd = IWEVCUSTOM; | 
 | 2977 | 		sprintf(buf, "bcn_int=%d", bss->beacon_int); | 
 | 2978 | 		iwe.u.data.length = strlen(buf); | 
 | 2979 | 		current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, | 
 | 2980 | 						  buf); | 
 | 2981 |  | 
 | 2982 | 		memset(&iwe, 0, sizeof(iwe)); | 
 | 2983 | 		iwe.cmd = IWEVCUSTOM; | 
 | 2984 | 		sprintf(buf, "capab=0x%04x", bss->capability); | 
 | 2985 | 		iwe.u.data.length = strlen(buf); | 
 | 2986 | 		current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, | 
 | 2987 | 						  buf); | 
 | 2988 |  | 
 | 2989 | 		kfree(buf); | 
 | 2990 | 		break; | 
 | 2991 | 	} while (0); | 
 | 2992 |  | 
 | 2993 | 	return current_ev; | 
 | 2994 | } | 
 | 2995 |  | 
 | 2996 |  | 
 | 2997 | int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len) | 
 | 2998 | { | 
 | 2999 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 3000 | 	char *current_ev = buf; | 
 | 3001 | 	char *end_buf = buf + len; | 
 | 3002 | 	struct ieee80211_sta_bss *bss; | 
 | 3003 |  | 
 | 3004 | 	spin_lock_bh(&local->sta_bss_lock); | 
 | 3005 | 	list_for_each_entry(bss, &local->sta_bss_list, list) { | 
 | 3006 | 		if (buf + len - current_ev <= IW_EV_ADDR_LEN) { | 
 | 3007 | 			spin_unlock_bh(&local->sta_bss_lock); | 
 | 3008 | 			return -E2BIG; | 
 | 3009 | 		} | 
 | 3010 | 		current_ev = ieee80211_sta_scan_result(dev, bss, current_ev, | 
 | 3011 | 						       end_buf); | 
 | 3012 | 	} | 
 | 3013 | 	spin_unlock_bh(&local->sta_bss_lock); | 
 | 3014 | 	return current_ev - buf; | 
 | 3015 | } | 
 | 3016 |  | 
 | 3017 |  | 
 | 3018 | int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len) | 
 | 3019 | { | 
 | 3020 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 3021 | 	struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 
 | 3022 | 	kfree(ifsta->extra_ie); | 
 | 3023 | 	if (len == 0) { | 
 | 3024 | 		ifsta->extra_ie = NULL; | 
 | 3025 | 		ifsta->extra_ie_len = 0; | 
 | 3026 | 		return 0; | 
 | 3027 | 	} | 
 | 3028 | 	ifsta->extra_ie = kmalloc(len, GFP_KERNEL); | 
 | 3029 | 	if (!ifsta->extra_ie) { | 
 | 3030 | 		ifsta->extra_ie_len = 0; | 
 | 3031 | 		return -ENOMEM; | 
 | 3032 | 	} | 
 | 3033 | 	memcpy(ifsta->extra_ie, ie, len); | 
 | 3034 | 	ifsta->extra_ie_len = len; | 
 | 3035 | 	return 0; | 
 | 3036 | } | 
 | 3037 |  | 
 | 3038 |  | 
 | 3039 | struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev, | 
 | 3040 | 					 struct sk_buff *skb, u8 *bssid, | 
 | 3041 | 					 u8 *addr) | 
 | 3042 | { | 
 | 3043 | 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 
 | 3044 | 	struct sta_info *sta; | 
| John W. Linville | 91fa558 | 2007-05-15 16:14:40 -0400 | [diff] [blame] | 3045 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
| Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3046 |  | 
 | 3047 | 	/* TODO: Could consider removing the least recently used entry and | 
 | 3048 | 	 * allow new one to be added. */ | 
 | 3049 | 	if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { | 
 | 3050 | 		if (net_ratelimit()) { | 
 | 3051 | 			printk(KERN_DEBUG "%s: No room for a new IBSS STA " | 
 | 3052 | 			       "entry " MAC_FMT "\n", dev->name, MAC_ARG(addr)); | 
 | 3053 | 		} | 
 | 3054 | 		return NULL; | 
 | 3055 | 	} | 
 | 3056 |  | 
 | 3057 | 	printk(KERN_DEBUG "%s: Adding new IBSS station " MAC_FMT " (dev=%s)\n", | 
 | 3058 | 	       local->mdev->name, MAC_ARG(addr), dev->name); | 
 | 3059 |  | 
 | 3060 | 	sta = sta_info_add(local, dev, addr, GFP_ATOMIC); | 
 | 3061 | 	if (!sta) | 
 | 3062 | 		return NULL; | 
 | 3063 |  | 
 | 3064 | 	sta->supp_rates = sdata->u.sta.supp_rates_bits; | 
 | 3065 |  | 
 | 3066 | 	rate_control_rate_init(sta, local); | 
 | 3067 |  | 
 | 3068 | 	return sta; /* caller will call sta_info_put() */ | 
 | 3069 | } | 
 | 3070 |  | 
 | 3071 |  | 
 | 3072 | int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason) | 
 | 3073 | { | 
 | 3074 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 3075 | 	struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 
 | 3076 |  | 
 | 3077 | 	printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n", | 
 | 3078 | 	       dev->name, reason); | 
 | 3079 |  | 
 | 3080 | 	if (sdata->type != IEEE80211_IF_TYPE_STA && | 
 | 3081 | 	    sdata->type != IEEE80211_IF_TYPE_IBSS) | 
 | 3082 | 		return -EINVAL; | 
 | 3083 |  | 
 | 3084 | 	ieee80211_send_deauth(dev, ifsta, reason); | 
 | 3085 | 	ieee80211_set_disassoc(dev, ifsta, 1); | 
 | 3086 | 	return 0; | 
 | 3087 | } | 
 | 3088 |  | 
 | 3089 |  | 
 | 3090 | int ieee80211_sta_disassociate(struct net_device *dev, u16 reason) | 
 | 3091 | { | 
 | 3092 | 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 
 | 3093 | 	struct ieee80211_if_sta *ifsta = &sdata->u.sta; | 
 | 3094 |  | 
 | 3095 | 	printk(KERN_DEBUG "%s: disassociate(reason=%d)\n", | 
 | 3096 | 	       dev->name, reason); | 
 | 3097 |  | 
 | 3098 | 	if (sdata->type != IEEE80211_IF_TYPE_STA) | 
 | 3099 | 		return -EINVAL; | 
 | 3100 |  | 
 | 3101 | 	if (!ifsta->associated) | 
 | 3102 | 		return -1; | 
 | 3103 |  | 
 | 3104 | 	ieee80211_send_disassoc(dev, ifsta, reason); | 
 | 3105 | 	ieee80211_set_disassoc(dev, ifsta, 0); | 
 | 3106 | 	return 0; | 
 | 3107 | } |