Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1 | /* IEEE 802.11 SoftMAC layer |
| 2 | * Copyright (c) 2005 Andrea Merello <andreamrl@tiscali.it> |
| 3 | * |
| 4 | * Mostly extracted from the rtl8180-sa2400 driver for the |
| 5 | * in-kernel generic ieee802.11 stack. |
| 6 | * |
| 7 | * Some pieces of code might be stolen from ipw2100 driver |
| 8 | * copyright of who own it's copyright ;-) |
| 9 | * |
| 10 | * PS wx handler mostly stolen from hostap, copyright who |
| 11 | * own it's copyright ;-) |
| 12 | * |
| 13 | * released under the GPL |
| 14 | */ |
| 15 | |
| 16 | |
| 17 | #include "rtllib.h" |
| 18 | #include "rtl_core.h" |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 19 | #include "dot11d.h" |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 20 | /* FIXME: add A freqs */ |
| 21 | |
| 22 | const long rtllib_wlan_frequencies[] = { |
| 23 | 2412, 2417, 2422, 2427, |
| 24 | 2432, 2437, 2442, 2447, |
| 25 | 2452, 2457, 2462, 2467, |
| 26 | 2472, 2484 |
| 27 | }; |
| 28 | |
| 29 | |
| 30 | int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a, |
| 31 | union iwreq_data *wrqu, char *b) |
| 32 | { |
| 33 | int ret; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 34 | struct iw_freq *fwrq = &wrqu->freq; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 35 | |
| 36 | down(&ieee->wx_sem); |
| 37 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 38 | if (ieee->iw_mode == IW_MODE_INFRA) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 39 | ret = 0; |
| 40 | goto out; |
| 41 | } |
| 42 | |
| 43 | /* if setting by freq convert to channel */ |
| 44 | if (fwrq->e == 1) { |
| 45 | if ((fwrq->m >= (int) 2.412e8 && |
| 46 | fwrq->m <= (int) 2.487e8)) { |
| 47 | int f = fwrq->m / 100000; |
| 48 | int c = 0; |
| 49 | |
| 50 | while ((c < 14) && (f != rtllib_wlan_frequencies[c])) |
| 51 | c++; |
| 52 | |
| 53 | /* hack to fall through */ |
| 54 | fwrq->e = 0; |
| 55 | fwrq->m = c + 1; |
| 56 | } |
| 57 | } |
| 58 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 59 | if (fwrq->e > 0 || fwrq->m > 14 || fwrq->m < 1) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 60 | ret = -EOPNOTSUPP; |
| 61 | goto out; |
| 62 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 63 | } else { /* Set the channel */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 64 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 65 | if (ieee->active_channel_map[fwrq->m] != 1) { |
| 66 | ret = -EINVAL; |
| 67 | goto out; |
| 68 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 69 | ieee->current_network.channel = fwrq->m; |
| 70 | ieee->set_chan(ieee->dev, ieee->current_network.channel); |
| 71 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 72 | if (ieee->iw_mode == IW_MODE_ADHOC || |
| 73 | ieee->iw_mode == IW_MODE_MASTER) |
| 74 | if (ieee->state == RTLLIB_LINKED) { |
| 75 | rtllib_stop_send_beacons(ieee); |
| 76 | rtllib_start_send_beacons(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | ret = 0; |
| 81 | out: |
| 82 | up(&ieee->wx_sem); |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | int rtllib_wx_get_freq(struct rtllib_device *ieee, |
| 88 | struct iw_request_info *a, |
| 89 | union iwreq_data *wrqu, char *b) |
| 90 | { |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 91 | struct iw_freq *fwrq = &wrqu->freq; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 92 | |
| 93 | if (ieee->current_network.channel == 0) |
| 94 | return -1; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 95 | fwrq->m = rtllib_wlan_frequencies[ieee->current_network.channel-1] * |
| 96 | 100000; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 97 | fwrq->e = 1; |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | int rtllib_wx_get_wap(struct rtllib_device *ieee, |
| 102 | struct iw_request_info *info, |
| 103 | union iwreq_data *wrqu, char *extra) |
| 104 | { |
| 105 | unsigned long flags; |
| 106 | |
| 107 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
| 108 | |
| 109 | if (ieee->iw_mode == IW_MODE_MONITOR) |
| 110 | return -1; |
| 111 | |
| 112 | /* We want avoid to give to the user inconsistent infos*/ |
| 113 | spin_lock_irqsave(&ieee->lock, flags); |
| 114 | |
| 115 | if (ieee->state != RTLLIB_LINKED && |
| 116 | ieee->state != RTLLIB_LINKED_SCANNING && |
| 117 | ieee->wap_set == 0) |
| 118 | |
| 119 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); |
| 120 | else |
| 121 | memcpy(wrqu->ap_addr.sa_data, |
| 122 | ieee->current_network.bssid, ETH_ALEN); |
| 123 | |
| 124 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | int rtllib_wx_set_wap(struct rtllib_device *ieee, |
| 131 | struct iw_request_info *info, |
| 132 | union iwreq_data *awrq, |
| 133 | char *extra) |
| 134 | { |
| 135 | |
| 136 | int ret = 0; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 137 | u8 zero[] = {0, 0, 0, 0, 0, 0}; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 138 | unsigned long flags; |
| 139 | |
| 140 | short ifup = ieee->proto_started; |
| 141 | struct sockaddr *temp = (struct sockaddr *)awrq; |
| 142 | |
| 143 | rtllib_stop_scan_syncro(ieee); |
| 144 | |
| 145 | down(&ieee->wx_sem); |
| 146 | /* use ifconfig hw ether */ |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 147 | if (ieee->iw_mode == IW_MODE_MASTER) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 148 | ret = -1; |
| 149 | goto out; |
| 150 | } |
| 151 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 152 | if (temp->sa_family != ARPHRD_ETHER) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 153 | ret = -EINVAL; |
| 154 | goto out; |
| 155 | } |
| 156 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 157 | if (memcmp(temp->sa_data, zero, ETH_ALEN) == 0) { |
| 158 | spin_lock_irqsave(&ieee->lock, flags); |
| 159 | memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN); |
| 160 | ieee->wap_set = 0; |
| 161 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 162 | ret = -1; |
| 163 | goto out; |
| 164 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 165 | |
| 166 | |
| 167 | if (ifup) |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 168 | rtllib_stop_protocol(ieee, true); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 169 | |
| 170 | /* just to avoid to give inconsistent infos in the |
| 171 | * get wx method. not really needed otherwise |
| 172 | */ |
| 173 | spin_lock_irqsave(&ieee->lock, flags); |
| 174 | |
| 175 | ieee->cannot_notify = false; |
| 176 | memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN); |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 177 | ieee->wap_set = (memcmp(temp->sa_data, zero, ETH_ALEN) != 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 178 | |
| 179 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 180 | |
| 181 | if (ifup) |
| 182 | rtllib_start_protocol(ieee); |
| 183 | out: |
| 184 | up(&ieee->wx_sem); |
| 185 | return ret; |
| 186 | } |
| 187 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 188 | int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a, |
| 189 | union iwreq_data *wrqu, char *b) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 190 | { |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 191 | int len, ret = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 192 | unsigned long flags; |
| 193 | |
| 194 | if (ieee->iw_mode == IW_MODE_MONITOR) |
| 195 | return -1; |
| 196 | |
| 197 | /* We want avoid to give to the user inconsistent infos*/ |
| 198 | spin_lock_irqsave(&ieee->lock, flags); |
| 199 | |
| 200 | if (ieee->current_network.ssid[0] == '\0' || |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 201 | ieee->current_network.ssid_len == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 202 | ret = -1; |
| 203 | goto out; |
| 204 | } |
| 205 | |
| 206 | if (ieee->state != RTLLIB_LINKED && |
| 207 | ieee->state != RTLLIB_LINKED_SCANNING && |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 208 | ieee->ssid_set == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 209 | ret = -1; |
| 210 | goto out; |
| 211 | } |
| 212 | len = ieee->current_network.ssid_len; |
| 213 | wrqu->essid.length = len; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 214 | strncpy(b, ieee->current_network.ssid, len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 215 | wrqu->essid.flags = 1; |
| 216 | |
| 217 | out: |
| 218 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 219 | |
| 220 | return ret; |
| 221 | |
| 222 | } |
| 223 | |
| 224 | int rtllib_wx_set_rate(struct rtllib_device *ieee, |
| 225 | struct iw_request_info *info, |
| 226 | union iwreq_data *wrqu, char *extra) |
| 227 | { |
| 228 | |
| 229 | u32 target_rate = wrqu->bitrate.value; |
| 230 | |
| 231 | ieee->rate = target_rate/100000; |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | int rtllib_wx_get_rate(struct rtllib_device *ieee, |
| 236 | struct iw_request_info *info, |
| 237 | union iwreq_data *wrqu, char *extra) |
| 238 | { |
| 239 | u32 tmp_rate = 0; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 240 | tmp_rate = TxCountToDataRate(ieee, |
| 241 | ieee->softmac_stats.CurrentShowTxate); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 242 | wrqu->bitrate.value = tmp_rate * 500000; |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | int rtllib_wx_set_rts(struct rtllib_device *ieee, |
| 249 | struct iw_request_info *info, |
| 250 | union iwreq_data *wrqu, char *extra) |
| 251 | { |
| 252 | if (wrqu->rts.disabled || !wrqu->rts.fixed) |
| 253 | ieee->rts = DEFAULT_RTS_THRESHOLD; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 254 | else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 255 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || |
| 256 | wrqu->rts.value > MAX_RTS_THRESHOLD) |
| 257 | return -EINVAL; |
| 258 | ieee->rts = wrqu->rts.value; |
| 259 | } |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | int rtllib_wx_get_rts(struct rtllib_device *ieee, |
| 264 | struct iw_request_info *info, |
| 265 | union iwreq_data *wrqu, char *extra) |
| 266 | { |
| 267 | wrqu->rts.value = ieee->rts; |
| 268 | wrqu->rts.fixed = 0; /* no auto select */ |
| 269 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a, |
| 274 | union iwreq_data *wrqu, char *b) |
| 275 | { |
| 276 | int set_mode_status = 0; |
| 277 | |
| 278 | rtllib_stop_scan_syncro(ieee); |
| 279 | down(&ieee->wx_sem); |
| 280 | switch (wrqu->mode) { |
| 281 | case IW_MODE_MONITOR: |
| 282 | case IW_MODE_ADHOC: |
| 283 | case IW_MODE_INFRA: |
| 284 | break; |
| 285 | case IW_MODE_AUTO: |
| 286 | wrqu->mode = IW_MODE_INFRA; |
| 287 | break; |
| 288 | default: |
| 289 | set_mode_status = -EINVAL; |
| 290 | goto out; |
| 291 | } |
| 292 | |
| 293 | if (wrqu->mode == ieee->iw_mode) |
| 294 | goto out; |
| 295 | |
| 296 | if (wrqu->mode == IW_MODE_MONITOR) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 297 | ieee->dev->type = ARPHRD_IEEE80211; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 298 | rtllib_EnableNetMonitorMode(ieee->dev, false); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 299 | } else { |
| 300 | ieee->dev->type = ARPHRD_ETHER; |
| 301 | if (ieee->iw_mode == IW_MODE_MONITOR) |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 302 | rtllib_DisableNetMonitorMode(ieee->dev, false); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | if (!ieee->proto_started) { |
| 306 | ieee->iw_mode = wrqu->mode; |
| 307 | } else { |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 308 | rtllib_stop_protocol(ieee, true); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 309 | ieee->iw_mode = wrqu->mode; |
| 310 | rtllib_start_protocol(ieee); |
| 311 | } |
| 312 | |
| 313 | out: |
| 314 | up(&ieee->wx_sem); |
| 315 | return set_mode_status; |
| 316 | } |
| 317 | |
| 318 | void rtllib_wx_sync_scan_wq(void *data) |
| 319 | { |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 320 | struct rtllib_device *ieee = container_of_work_rsl(data, |
| 321 | struct rtllib_device, wx_sync_scan_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 322 | short chan; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 323 | enum ht_extchnl_offset chan_offset = 0; |
| 324 | enum ht_channel_width bandwidth = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 325 | int b40M = 0; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 326 | static int count; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 327 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 328 | if (!(ieee->softmac_features & IEEE_SOFTMAC_SCAN)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 329 | rtllib_start_scan_syncro(ieee, 0); |
| 330 | goto out; |
| 331 | } |
| 332 | |
| 333 | chan = ieee->current_network.channel; |
| 334 | |
| 335 | if (ieee->LeisurePSLeave) |
| 336 | ieee->LeisurePSLeave(ieee->dev); |
| 337 | /* notify AP to be in PS mode */ |
| 338 | rtllib_sta_ps_send_null_frame(ieee, 1); |
| 339 | rtllib_sta_ps_send_null_frame(ieee, 1); |
| 340 | |
| 341 | rtllib_stop_all_queues(ieee); |
| 342 | |
| 343 | if (ieee->data_hard_stop) |
| 344 | ieee->data_hard_stop(ieee->dev); |
| 345 | rtllib_stop_send_beacons(ieee); |
| 346 | ieee->state = RTLLIB_LINKED_SCANNING; |
| 347 | ieee->link_change(ieee->dev); |
| 348 | /* wait for ps packet to be kicked out successfully */ |
| 349 | msleep(50); |
| 350 | |
| 351 | if (ieee->ScanOperationBackupHandler) |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 352 | ieee->ScanOperationBackupHandler(ieee->dev, SCAN_OPT_BACKUP); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 353 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 354 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT && |
| 355 | ieee->pHTInfo->bCurBW40MHz) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 356 | b40M = 1; |
| 357 | chan_offset = ieee->pHTInfo->CurSTAExtChnlOffset; |
Larry Finger | 6e57911 | 2011-07-19 18:20:30 -0500 | [diff] [blame] | 358 | bandwidth = (enum ht_channel_width)ieee->pHTInfo->bCurBW40MHz; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 359 | RT_TRACE(COMP_DBG, "Scan in 40M, force to 20M first:%d, %d\n", |
| 360 | chan_offset, bandwidth); |
| 361 | ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, |
| 362 | HT_EXTCHNL_OFFSET_NO_EXT); |
| 363 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 364 | |
| 365 | rtllib_start_scan_syncro(ieee, 0); |
| 366 | |
| 367 | if (b40M) { |
| 368 | RT_TRACE(COMP_DBG, "Scan in 20M, back to 40M\n"); |
| 369 | if (chan_offset == HT_EXTCHNL_OFFSET_UPPER) |
| 370 | ieee->set_chan(ieee->dev, chan + 2); |
| 371 | else if (chan_offset == HT_EXTCHNL_OFFSET_LOWER) |
| 372 | ieee->set_chan(ieee->dev, chan - 2); |
| 373 | else |
| 374 | ieee->set_chan(ieee->dev, chan); |
| 375 | ieee->SetBWModeHandler(ieee->dev, bandwidth, chan_offset); |
| 376 | } else { |
| 377 | ieee->set_chan(ieee->dev, chan); |
| 378 | } |
| 379 | |
| 380 | if (ieee->ScanOperationBackupHandler) |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 381 | ieee->ScanOperationBackupHandler(ieee->dev, SCAN_OPT_RESTORE); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 382 | |
| 383 | ieee->state = RTLLIB_LINKED; |
| 384 | ieee->link_change(ieee->dev); |
| 385 | |
| 386 | /* Notify AP that I wake up again */ |
| 387 | rtllib_sta_ps_send_null_frame(ieee, 0); |
| 388 | |
| 389 | if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 || |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 390 | ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 391 | ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 392 | ieee->LinkDetectInfo.NumRecvDataInPeriod = 1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | if (ieee->data_hard_resume) |
| 396 | ieee->data_hard_resume(ieee->dev); |
| 397 | |
| 398 | if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER) |
| 399 | rtllib_start_send_beacons(ieee); |
| 400 | |
| 401 | rtllib_wake_all_queues(ieee); |
| 402 | |
| 403 | count = 0; |
| 404 | out: |
| 405 | up(&ieee->wx_sem); |
| 406 | |
| 407 | } |
| 408 | |
| 409 | int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a, |
| 410 | union iwreq_data *wrqu, char *b) |
| 411 | { |
| 412 | int ret = 0; |
| 413 | |
| 414 | down(&ieee->wx_sem); |
| 415 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 416 | if (ieee->iw_mode == IW_MODE_MONITOR || !(ieee->proto_started)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 417 | ret = -1; |
| 418 | goto out; |
| 419 | } |
| 420 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 421 | if (ieee->state == RTLLIB_LINKED) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 422 | queue_work_rsl(ieee->wq, &ieee->wx_sync_scan_wq); |
| 423 | /* intentionally forget to up sem */ |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | out: |
| 428 | up(&ieee->wx_sem); |
| 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | int rtllib_wx_set_essid(struct rtllib_device *ieee, |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 433 | struct iw_request_info *a, |
| 434 | union iwreq_data *wrqu, char *extra) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 435 | { |
| 436 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 437 | int ret = 0, len, i; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 438 | short proto_started; |
| 439 | unsigned long flags; |
| 440 | |
| 441 | rtllib_stop_scan_syncro(ieee); |
| 442 | down(&ieee->wx_sem); |
| 443 | |
| 444 | proto_started = ieee->proto_started; |
| 445 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 446 | len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? wrqu->essid.length : |
| 447 | IW_ESSID_MAX_SIZE; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 448 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 449 | if (len > IW_ESSID_MAX_SIZE) { |
| 450 | ret = -E2BIG; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 451 | goto out; |
| 452 | } |
| 453 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 454 | if (ieee->iw_mode == IW_MODE_MONITOR) { |
| 455 | ret = -1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 456 | goto out; |
| 457 | } |
| 458 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 459 | for (i = 0; i < len; i++) { |
| 460 | if (extra[i] < 0) { |
| 461 | ret = -1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 462 | goto out; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | if (proto_started) |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 467 | rtllib_stop_protocol(ieee, true); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 468 | |
| 469 | |
| 470 | /* this is just to be sure that the GET wx callback |
| 471 | * has consisten infos. not needed otherwise |
| 472 | */ |
| 473 | spin_lock_irqsave(&ieee->lock, flags); |
| 474 | |
| 475 | if (wrqu->essid.flags && wrqu->essid.length) { |
| 476 | strncpy(ieee->current_network.ssid, extra, len); |
| 477 | ieee->current_network.ssid_len = len; |
| 478 | ieee->cannot_notify = false; |
| 479 | ieee->ssid_set = 1; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 480 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 481 | ieee->ssid_set = 0; |
| 482 | ieee->current_network.ssid[0] = '\0'; |
| 483 | ieee->current_network.ssid_len = 0; |
| 484 | } |
| 485 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 486 | |
| 487 | if (proto_started) |
| 488 | rtllib_start_protocol(ieee); |
| 489 | out: |
| 490 | up(&ieee->wx_sem); |
| 491 | return ret; |
| 492 | } |
| 493 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 494 | int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a, |
| 495 | union iwreq_data *wrqu, char *b) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 496 | { |
| 497 | wrqu->mode = ieee->iw_mode; |
| 498 | return 0; |
| 499 | } |
| 500 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 501 | int rtllib_wx_set_rawtx(struct rtllib_device *ieee, |
| 502 | struct iw_request_info *info, |
| 503 | union iwreq_data *wrqu, char *extra) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 504 | { |
| 505 | |
| 506 | int *parms = (int *)extra; |
| 507 | int enable = (parms[0] > 0); |
| 508 | short prev = ieee->raw_tx; |
| 509 | |
| 510 | down(&ieee->wx_sem); |
| 511 | |
| 512 | if (enable) |
| 513 | ieee->raw_tx = 1; |
| 514 | else |
| 515 | ieee->raw_tx = 0; |
| 516 | |
| 517 | printk(KERN_INFO"raw TX is %s\n", |
| 518 | ieee->raw_tx ? "enabled" : "disabled"); |
| 519 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 520 | if (ieee->iw_mode == IW_MODE_MONITOR) { |
| 521 | if (prev == 0 && ieee->raw_tx) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 522 | if (ieee->data_hard_resume) |
| 523 | ieee->data_hard_resume(ieee->dev); |
| 524 | |
| 525 | netif_carrier_on(ieee->dev); |
| 526 | } |
| 527 | |
| 528 | if (prev && ieee->raw_tx == 1) |
| 529 | netif_carrier_off(ieee->dev); |
| 530 | } |
| 531 | |
| 532 | up(&ieee->wx_sem); |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | int rtllib_wx_get_name(struct rtllib_device *ieee, |
| 538 | struct iw_request_info *info, |
| 539 | union iwreq_data *wrqu, char *extra) |
| 540 | { |
| 541 | strcpy(wrqu->name, "802.11"); |
| 542 | |
| 543 | if (ieee->modulation & RTLLIB_CCK_MODULATION) |
| 544 | strcat(wrqu->name, "b"); |
| 545 | if (ieee->modulation & RTLLIB_OFDM_MODULATION) |
| 546 | strcat(wrqu->name, "g"); |
| 547 | if (ieee->mode & (IEEE_N_24G | IEEE_N_5G)) |
| 548 | strcat(wrqu->name, "n"); |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | |
| 553 | /* this is mostly stolen from hostap */ |
| 554 | int rtllib_wx_set_power(struct rtllib_device *ieee, |
| 555 | struct iw_request_info *info, |
| 556 | union iwreq_data *wrqu, char *extra) |
| 557 | { |
| 558 | int ret = 0; |
Mike McCormack | 4f6807e | 2011-07-11 08:56:20 +0900 | [diff] [blame] | 559 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 560 | if ((!ieee->sta_wake_up) || |
| 561 | (!ieee->enter_sleep_state) || |
| 562 | (!ieee->ps_is_queue_empty)) { |
| 563 | RTLLIB_DEBUG(RTLLIB_DL_ERR, "%s(): PS mode is tryied to be use " |
| 564 | "but driver missed a callback\n\n", __func__); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 565 | return -1; |
| 566 | } |
Mike McCormack | 4f6807e | 2011-07-11 08:56:20 +0900 | [diff] [blame] | 567 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 568 | down(&ieee->wx_sem); |
| 569 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 570 | if (wrqu->power.disabled) { |
| 571 | RT_TRACE(COMP_DBG, "===>%s(): power disable\n", __func__); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 572 | ieee->ps = RTLLIB_PS_DISABLED; |
| 573 | goto exit; |
| 574 | } |
| 575 | if (wrqu->power.flags & IW_POWER_TIMEOUT) { |
| 576 | ieee->ps_timeout = wrqu->power.value / 1000; |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 577 | RT_TRACE(COMP_DBG, "===>%s():ps_timeout is %d\n", __func__, |
| 578 | ieee->ps_timeout); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 579 | } |
| 580 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 581 | if (wrqu->power.flags & IW_POWER_PERIOD) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 582 | ieee->ps_period = wrqu->power.value / 1000; |
| 583 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 584 | switch (wrqu->power.flags & IW_POWER_MODE) { |
| 585 | case IW_POWER_UNICAST_R: |
| 586 | ieee->ps = RTLLIB_PS_UNICAST; |
| 587 | break; |
| 588 | case IW_POWER_MULTICAST_R: |
| 589 | ieee->ps = RTLLIB_PS_MBCAST; |
| 590 | break; |
| 591 | case IW_POWER_ALL_R: |
| 592 | ieee->ps = RTLLIB_PS_UNICAST | RTLLIB_PS_MBCAST; |
| 593 | break; |
| 594 | |
| 595 | case IW_POWER_ON: |
| 596 | break; |
| 597 | |
| 598 | default: |
| 599 | ret = -EINVAL; |
| 600 | goto exit; |
| 601 | |
| 602 | } |
| 603 | exit: |
| 604 | up(&ieee->wx_sem); |
| 605 | return ret; |
| 606 | |
| 607 | } |
| 608 | |
| 609 | /* this is stolen from hostap */ |
| 610 | int rtllib_wx_get_power(struct rtllib_device *ieee, |
| 611 | struct iw_request_info *info, |
| 612 | union iwreq_data *wrqu, char *extra) |
| 613 | { |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 614 | int ret = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 615 | |
| 616 | down(&ieee->wx_sem); |
| 617 | |
| 618 | if (ieee->ps == RTLLIB_PS_DISABLED) { |
| 619 | wrqu->power.disabled = 1; |
| 620 | goto exit; |
| 621 | } |
| 622 | |
| 623 | wrqu->power.disabled = 0; |
| 624 | |
| 625 | if ((wrqu->power.flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { |
| 626 | wrqu->power.flags = IW_POWER_TIMEOUT; |
| 627 | wrqu->power.value = ieee->ps_timeout * 1000; |
| 628 | } else { |
| 629 | wrqu->power.flags = IW_POWER_PERIOD; |
| 630 | wrqu->power.value = ieee->ps_period * 1000; |
| 631 | } |
| 632 | |
Larry Finger | a44be77 | 2011-08-25 11:48:27 -0500 | [diff] [blame^] | 633 | if ((ieee->ps & (RTLLIB_PS_MBCAST | RTLLIB_PS_UNICAST)) == |
| 634 | (RTLLIB_PS_MBCAST | RTLLIB_PS_UNICAST)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 635 | wrqu->power.flags |= IW_POWER_ALL_R; |
| 636 | else if (ieee->ps & RTLLIB_PS_MBCAST) |
| 637 | wrqu->power.flags |= IW_POWER_MULTICAST_R; |
| 638 | else |
| 639 | wrqu->power.flags |= IW_POWER_UNICAST_R; |
| 640 | |
| 641 | exit: |
| 642 | up(&ieee->wx_sem); |
| 643 | return ret; |
| 644 | |
| 645 | } |