Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * rtl871x_cmd.c |
| 3 | * |
| 4 | * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. |
| 5 | * Linux device driver for RTL8192SU |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 19 | * |
| 20 | * Modifications for inclusion into the Linux staging tree are |
| 21 | * Copyright(c) 2010 Larry Finger. All rights reserved. |
| 22 | * |
| 23 | * Contact information: |
| 24 | * WLAN FAE <wlanfae@realtek.com> |
| 25 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 26 | * |
| 27 | ******************************************************************************/ |
| 28 | |
| 29 | #define _RTL871X_CMD_C_ |
| 30 | |
Ali Bahar | 359140a | 2011-09-04 03:14:11 +0800 | [diff] [blame] | 31 | #include <linux/compiler.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/errno.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/module.h> |
| 37 | #include <linux/kref.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/skbuff.h> |
| 40 | #include <linux/usb.h> |
| 41 | #include <linux/usb/ch9.h> |
| 42 | #include <linux/circ_buf.h> |
| 43 | #include <linux/uaccess.h> |
| 44 | #include <asm/byteorder.h> |
| 45 | #include <linux/atomic.h> |
| 46 | #include <linux/semaphore.h> |
| 47 | #include <linux/rtnetlink.h> |
| 48 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 49 | #include "osdep_service.h" |
| 50 | #include "drv_types.h" |
| 51 | #include "recv_osdep.h" |
| 52 | #include "mlme_osdep.h" |
| 53 | #include "rtl871x_byteorder.h" |
| 54 | |
| 55 | /* |
| 56 | Caller and the r8712_cmd_thread can protect cmd_q by spin_lock. |
| 57 | No irqsave is necessary. |
| 58 | */ |
| 59 | |
| 60 | static sint _init_cmd_priv(struct cmd_priv *pcmdpriv) |
| 61 | { |
| 62 | sema_init(&(pcmdpriv->cmd_queue_sema), 0); |
| 63 | sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0); |
| 64 | |
| 65 | _init_queue(&(pcmdpriv->cmd_queue)); |
| 66 | |
| 67 | /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ |
| 68 | pcmdpriv->cmd_seq = 1; |
| 69 | pcmdpriv->cmd_allocated_buf = _malloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ); |
| 70 | if (pcmdpriv->cmd_allocated_buf == NULL) |
| 71 | return _FAIL; |
| 72 | pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - |
| 73 | ((addr_t)(pcmdpriv->cmd_allocated_buf) & |
| 74 | (CMDBUFF_ALIGN_SZ-1)); |
| 75 | pcmdpriv->rsp_allocated_buf = _malloc(MAX_RSPSZ + 4); |
| 76 | if (pcmdpriv->rsp_allocated_buf == NULL) |
| 77 | return _FAIL; |
| 78 | pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - |
| 79 | ((addr_t)(pcmdpriv->rsp_allocated_buf) & 3); |
| 80 | pcmdpriv->cmd_issued_cnt = 0; |
| 81 | pcmdpriv->cmd_done_cnt = 0; |
| 82 | pcmdpriv->rsp_cnt = 0; |
| 83 | return _SUCCESS; |
| 84 | } |
| 85 | |
| 86 | static sint _init_evt_priv(struct evt_priv *pevtpriv) |
| 87 | { |
| 88 | /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ |
| 89 | pevtpriv->event_seq = 0; |
| 90 | pevtpriv->evt_allocated_buf = _malloc(MAX_EVTSZ + 4); |
| 91 | |
| 92 | if (pevtpriv->evt_allocated_buf == NULL) |
| 93 | return _FAIL; |
| 94 | pevtpriv->evt_buf = pevtpriv->evt_allocated_buf + 4 - |
| 95 | ((addr_t)(pevtpriv->evt_allocated_buf) & 3); |
| 96 | pevtpriv->evt_done_cnt = 0; |
| 97 | return _SUCCESS; |
| 98 | } |
| 99 | |
| 100 | static void _free_evt_priv(struct evt_priv *pevtpriv) |
| 101 | { |
| 102 | kfree(pevtpriv->evt_allocated_buf); |
| 103 | } |
| 104 | |
| 105 | static void _free_cmd_priv(struct cmd_priv *pcmdpriv) |
| 106 | { |
| 107 | if (pcmdpriv) { |
| 108 | kfree(pcmdpriv->cmd_allocated_buf); |
| 109 | kfree(pcmdpriv->rsp_allocated_buf); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | Calling Context: |
| 115 | |
| 116 | _enqueue_cmd can only be called between kernel thread, |
| 117 | since only spin_lock is used. |
| 118 | |
| 119 | ISR/Call-Back functions can't call this sub-function. |
| 120 | |
| 121 | */ |
| 122 | |
| 123 | static sint _enqueue_cmd(struct __queue *queue, struct cmd_obj *obj) |
| 124 | { |
| 125 | unsigned long irqL; |
| 126 | |
| 127 | if (obj == NULL) |
| 128 | return _SUCCESS; |
| 129 | spin_lock_irqsave(&queue->lock, irqL); |
| 130 | list_insert_tail(&obj->list, &queue->queue); |
| 131 | spin_unlock_irqrestore(&queue->lock, irqL); |
| 132 | return _SUCCESS; |
| 133 | } |
| 134 | |
| 135 | static struct cmd_obj *_dequeue_cmd(struct __queue *queue) |
| 136 | { |
| 137 | unsigned long irqL; |
| 138 | struct cmd_obj *obj; |
| 139 | |
| 140 | spin_lock_irqsave(&(queue->lock), irqL); |
| 141 | if (is_list_empty(&(queue->queue))) |
| 142 | obj = NULL; |
| 143 | else { |
| 144 | obj = LIST_CONTAINOR(get_next(&(queue->queue)), |
| 145 | struct cmd_obj, list); |
| 146 | list_delete(&obj->list); |
| 147 | } |
| 148 | spin_unlock_irqrestore(&(queue->lock), irqL); |
| 149 | return obj; |
| 150 | } |
| 151 | |
| 152 | u32 r8712_init_cmd_priv(struct cmd_priv *pcmdpriv) |
| 153 | { |
| 154 | return _init_cmd_priv(pcmdpriv); |
| 155 | } |
| 156 | |
| 157 | u32 r8712_init_evt_priv(struct evt_priv *pevtpriv) |
| 158 | { |
| 159 | return _init_evt_priv(pevtpriv); |
| 160 | } |
| 161 | |
| 162 | void r8712_free_evt_priv(struct evt_priv *pevtpriv) |
| 163 | { |
| 164 | _free_evt_priv(pevtpriv); |
| 165 | } |
| 166 | |
| 167 | void r8712_free_cmd_priv(struct cmd_priv *pcmdpriv) |
| 168 | { |
| 169 | _free_cmd_priv(pcmdpriv); |
| 170 | } |
| 171 | |
| 172 | u32 r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj) |
| 173 | { |
| 174 | int res; |
| 175 | |
| 176 | if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag == true) |
| 177 | return _FAIL; |
| 178 | res = _enqueue_cmd(&pcmdpriv->cmd_queue, obj); |
| 179 | up(&pcmdpriv->cmd_queue_sema); |
| 180 | return res; |
| 181 | } |
| 182 | |
| 183 | u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj) |
| 184 | { |
| 185 | unsigned long irqL; |
| 186 | struct __queue *queue; |
| 187 | |
| 188 | if (obj == NULL) |
| 189 | return _SUCCESS; |
| 190 | if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag == true) |
| 191 | return _FAIL; |
| 192 | queue = &pcmdpriv->cmd_queue; |
| 193 | spin_lock_irqsave(&queue->lock, irqL); |
| 194 | list_insert_tail(&obj->list, &queue->queue); |
| 195 | spin_unlock_irqrestore(&queue->lock, irqL); |
| 196 | up(&pcmdpriv->cmd_queue_sema); |
| 197 | return _SUCCESS; |
| 198 | } |
| 199 | |
| 200 | struct cmd_obj *r8712_dequeue_cmd(struct __queue *queue) |
| 201 | { |
| 202 | return _dequeue_cmd(queue); |
| 203 | } |
| 204 | |
| 205 | void r8712_free_cmd_obj(struct cmd_obj *pcmd) |
| 206 | { |
| 207 | if ((pcmd->cmdcode != _JoinBss_CMD_) && |
| 208 | (pcmd->cmdcode != _CreateBss_CMD_)) |
| 209 | kfree((unsigned char *)pcmd->parmbuf); |
| 210 | if (pcmd->rsp != NULL) { |
| 211 | if (pcmd->rspsz != 0) |
| 212 | kfree((unsigned char *)pcmd->rsp); |
| 213 | } |
| 214 | kfree((unsigned char *)pcmd); |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | r8712_sitesurvey_cmd(~) |
| 219 | ### NOTE:#### (!!!!) |
| 220 | MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, |
| 221 | YOU SHOULD HAVE LOCKED pmlmepriv->lock |
| 222 | */ |
| 223 | u8 r8712_sitesurvey_cmd(struct _adapter *padapter, |
| 224 | struct ndis_802_11_ssid *pssid) |
| 225 | { |
| 226 | struct cmd_obj *ph2c; |
| 227 | struct sitesurvey_parm *psurveyPara; |
| 228 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 229 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 230 | |
| 231 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 232 | if (ph2c == NULL) |
| 233 | return _FAIL; |
| 234 | psurveyPara = (struct sitesurvey_parm *)_malloc( |
| 235 | sizeof(struct sitesurvey_parm)); |
| 236 | if (psurveyPara == NULL) { |
| 237 | kfree((unsigned char *) ph2c); |
| 238 | return _FAIL; |
| 239 | } |
| 240 | init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, |
| 241 | GEN_CMD_CODE(_SiteSurvey)); |
| 242 | psurveyPara->bsslimit = cpu_to_le32(48); |
| 243 | psurveyPara->passive_mode = cpu_to_le32(1); |
| 244 | psurveyPara->ss_ssidlen = 0; |
| 245 | memset(psurveyPara->ss_ssid, 0, IW_ESSID_MAX_SIZE + 1); |
| 246 | if ((pssid != NULL) && (pssid->SsidLength)) { |
| 247 | memcpy(psurveyPara->ss_ssid, pssid->Ssid, pssid->SsidLength); |
| 248 | psurveyPara->ss_ssidlen = cpu_to_le32(pssid->SsidLength); |
| 249 | } |
| 250 | set_fwstate(pmlmepriv, _FW_UNDER_SURVEY); |
| 251 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 252 | _set_timer(&pmlmepriv->scan_to_timer, SCANNING_TIMEOUT); |
| 253 | padapter->ledpriv.LedControlHandler(padapter, LED_CTL_SITE_SURVEY); |
| 254 | return _SUCCESS; |
| 255 | } |
| 256 | |
| 257 | u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset) |
| 258 | { |
| 259 | struct cmd_obj *ph2c; |
| 260 | struct setdatarate_parm *pbsetdataratepara; |
| 261 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 262 | |
| 263 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 264 | if (ph2c == NULL) |
| 265 | return _FAIL; |
| 266 | pbsetdataratepara = (struct setdatarate_parm *)_malloc( |
| 267 | sizeof(struct setdatarate_parm)); |
| 268 | if (pbsetdataratepara == NULL) { |
| 269 | kfree((u8 *) ph2c); |
| 270 | return _FAIL; |
| 271 | } |
| 272 | init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara, |
| 273 | GEN_CMD_CODE(_SetDataRate)); |
| 274 | pbsetdataratepara->mac_id = 5; |
| 275 | memcpy(pbsetdataratepara->datarates, rateset, NumRates); |
| 276 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 277 | return _SUCCESS; |
| 278 | } |
| 279 | |
Ali Bahar | c6dc001 | 2011-09-04 03:14:20 +0800 | [diff] [blame^] | 280 | u8 r8712_set_chplan_cmd(struct _adapter *padapter, int chplan) |
| 281 | { |
| 282 | struct cmd_obj *ph2c; |
| 283 | struct SetChannelPlan_param *psetchplanpara; |
| 284 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 285 | |
| 286 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 287 | if (ph2c == NULL) |
| 288 | return _FAIL; |
| 289 | psetchplanpara = (struct SetChannelPlan_param *) |
| 290 | _malloc(sizeof(struct SetChannelPlan_param)); |
| 291 | if (psetchplanpara == NULL) { |
| 292 | kfree((u8 *) ph2c); |
| 293 | return _FAIL; |
| 294 | } |
| 295 | init_h2fwcmd_w_parm_no_rsp(ph2c, psetchplanpara, |
| 296 | GEN_CMD_CODE(_SetChannelPlan)); |
| 297 | psetchplanpara->ChannelPlan = chplan; |
| 298 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 299 | return _SUCCESS; |
| 300 | } |
| 301 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 302 | u8 r8712_setbasicrate_cmd(struct _adapter *padapter, u8 *rateset) |
| 303 | { |
| 304 | struct cmd_obj *ph2c; |
| 305 | struct setbasicrate_parm *pssetbasicratepara; |
| 306 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 307 | |
| 308 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 309 | if (ph2c == NULL) |
| 310 | return _FAIL; |
| 311 | pssetbasicratepara = (struct setbasicrate_parm *)_malloc( |
| 312 | sizeof(struct setbasicrate_parm)); |
| 313 | if (pssetbasicratepara == NULL) { |
| 314 | kfree((u8 *) ph2c); |
| 315 | return _FAIL; |
| 316 | } |
| 317 | init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara, |
| 318 | _SetBasicRate_CMD_); |
| 319 | memcpy(pssetbasicratepara->basicrates, rateset, NumRates); |
| 320 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 321 | return _SUCCESS; |
| 322 | } |
| 323 | |
| 324 | /* power tracking mechanism setting */ |
| 325 | u8 r8712_setptm_cmd(struct _adapter *padapter, u8 type) |
| 326 | { |
| 327 | struct cmd_obj *ph2c; |
Ali Bahar | c6dc001 | 2011-09-04 03:14:20 +0800 | [diff] [blame^] | 328 | struct writePTM_parm *pwriteptmparm; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 329 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 330 | |
| 331 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 332 | if (ph2c == NULL) |
| 333 | return _FAIL; |
Ali Bahar | c6dc001 | 2011-09-04 03:14:20 +0800 | [diff] [blame^] | 334 | pwriteptmparm = (struct writePTM_parm *) |
| 335 | _malloc(sizeof(struct writePTM_parm)); |
| 336 | if (pwriteptmparm == NULL) { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 337 | kfree((u8 *) ph2c); |
| 338 | return _FAIL; |
| 339 | } |
Ali Bahar | c6dc001 | 2011-09-04 03:14:20 +0800 | [diff] [blame^] | 340 | init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetPT)); |
| 341 | pwriteptmparm->type = type; |
| 342 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 343 | return _SUCCESS; |
| 344 | } |
| 345 | |
| 346 | u8 r8712_setfwdig_cmd(struct _adapter *padapter, u8 type) |
| 347 | { |
| 348 | struct cmd_obj *ph2c; |
| 349 | struct writePTM_parm *pwriteptmparm; |
| 350 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 351 | |
| 352 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 353 | if (ph2c == NULL) |
| 354 | return _FAIL; |
| 355 | pwriteptmparm = (struct writePTM_parm *) |
| 356 | _malloc(sizeof(struct setdig_parm)); |
| 357 | if (pwriteptmparm == NULL) { |
| 358 | kfree((u8 *) ph2c); |
| 359 | return _FAIL; |
| 360 | } |
| 361 | init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetDIG)); |
| 362 | pwriteptmparm->type = type; |
| 363 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 364 | return _SUCCESS; |
| 365 | } |
| 366 | |
| 367 | u8 r8712_setfwra_cmd(struct _adapter *padapter, u8 type) |
| 368 | { |
| 369 | struct cmd_obj *ph2c; |
| 370 | struct writePTM_parm *pwriteptmparm; |
| 371 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 372 | |
| 373 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 374 | if (ph2c == NULL) |
| 375 | return _FAIL; |
| 376 | pwriteptmparm = (struct writePTM_parm *) |
| 377 | _malloc(sizeof(struct setra_parm)); |
| 378 | if (pwriteptmparm == NULL) { |
| 379 | kfree((u8 *) ph2c); |
| 380 | return _FAIL; |
| 381 | } |
| 382 | init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetRA)); |
| 383 | pwriteptmparm->type = type; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 384 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 385 | return _SUCCESS; |
| 386 | } |
| 387 | |
| 388 | u8 r8712_setrfreg_cmd(struct _adapter *padapter, u8 offset, u32 val) |
| 389 | { |
| 390 | struct cmd_obj *ph2c; |
| 391 | struct writeRF_parm *pwriterfparm; |
| 392 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 393 | |
| 394 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 395 | if (ph2c == NULL) |
| 396 | return _FAIL; |
| 397 | pwriterfparm = (struct writeRF_parm *)_malloc( |
| 398 | sizeof(struct writeRF_parm)); |
| 399 | if (pwriterfparm == NULL) { |
| 400 | kfree((u8 *) ph2c); |
| 401 | return _FAIL; |
| 402 | } |
| 403 | init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg)); |
| 404 | pwriterfparm->offset = offset; |
| 405 | pwriterfparm->value = val; |
| 406 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 407 | return _SUCCESS; |
| 408 | } |
| 409 | |
| 410 | u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval) |
| 411 | { |
| 412 | struct cmd_obj *ph2c; |
| 413 | struct readRF_parm *prdrfparm; |
| 414 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 415 | |
| 416 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 417 | if (ph2c == NULL) |
| 418 | return _FAIL; |
| 419 | prdrfparm = (struct readRF_parm *)_malloc(sizeof(struct readRF_parm)); |
| 420 | if (prdrfparm == NULL) { |
| 421 | kfree((u8 *) ph2c); |
| 422 | return _FAIL; |
| 423 | } |
| 424 | _init_listhead(&ph2c->list); |
| 425 | ph2c->cmdcode = GEN_CMD_CODE(_GetRFReg); |
| 426 | ph2c->parmbuf = (unsigned char *)prdrfparm; |
| 427 | ph2c->cmdsz = sizeof(struct readRF_parm); |
| 428 | ph2c->rsp = pval; |
| 429 | ph2c->rspsz = sizeof(struct readRF_rsp); |
| 430 | prdrfparm->offset = offset; |
| 431 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 432 | return _SUCCESS; |
| 433 | } |
| 434 | |
| 435 | void r8712_getbbrfreg_cmdrsp_callback(struct _adapter *padapter, |
| 436 | struct cmd_obj *pcmd) |
| 437 | { |
Ali Bahar | f15abb8 | 2011-09-04 03:14:19 +0800 | [diff] [blame] | 438 | kfree(pcmd->parmbuf); |
| 439 | kfree(pcmd); |
| 440 | padapter->mppriv.workparam.bcompleted = true; |
| 441 | } |
| 442 | |
| 443 | void r8712_readtssi_cmdrsp_callback(struct _adapter *padapter, |
| 444 | struct cmd_obj *pcmd) |
| 445 | { |
| 446 | kfree(pcmd->parmbuf); |
| 447 | kfree(pcmd); |
| 448 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 449 | padapter->mppriv.workparam.bcompleted = true; |
| 450 | } |
| 451 | |
| 452 | u8 r8712_createbss_cmd(struct _adapter *padapter) |
| 453 | { |
| 454 | struct cmd_obj *pcmd; |
| 455 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 456 | struct wlan_bssid_ex *pdev_network = |
| 457 | &padapter->registrypriv.dev_network; |
| 458 | |
| 459 | padapter->ledpriv.LedControlHandler(padapter, LED_CTL_START_TO_LINK); |
| 460 | pcmd = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 461 | if (pcmd == NULL) |
| 462 | return _FAIL; |
| 463 | _init_listhead(&pcmd->list); |
| 464 | pcmd->cmdcode = _CreateBss_CMD_; |
| 465 | pcmd->parmbuf = (unsigned char *)pdev_network; |
| 466 | pcmd->cmdsz = r8712_get_ndis_wlan_bssid_ex_sz(( |
| 467 | struct ndis_wlan_bssid_ex *) |
| 468 | pdev_network); |
| 469 | pcmd->rsp = NULL; |
| 470 | pcmd->rspsz = 0; |
| 471 | /* notes: translate IELength & Length after assign to cmdsz; */ |
| 472 | pdev_network->Length = cpu_to_le32(pcmd->cmdsz); |
| 473 | pdev_network->IELength = cpu_to_le32(pdev_network->IELength); |
| 474 | pdev_network->Ssid.SsidLength = cpu_to_le32( |
| 475 | pdev_network->Ssid.SsidLength); |
| 476 | r8712_enqueue_cmd(pcmdpriv, pcmd); |
| 477 | return _SUCCESS; |
| 478 | } |
| 479 | |
| 480 | u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork) |
| 481 | { |
| 482 | u8 *auth; |
| 483 | uint t_len = 0; |
| 484 | struct ndis_wlan_bssid_ex *psecnetwork; |
| 485 | struct cmd_obj *pcmd; |
| 486 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 487 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 488 | struct qos_priv *pqospriv = &pmlmepriv->qospriv; |
| 489 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
| 490 | struct registry_priv *pregistrypriv = &padapter->registrypriv; |
| 491 | enum NDIS_802_11_NETWORK_INFRASTRUCTURE ndis_network_mode = pnetwork-> |
| 492 | network.InfrastructureMode; |
| 493 | |
| 494 | padapter->ledpriv.LedControlHandler(padapter, LED_CTL_START_TO_LINK); |
| 495 | pcmd = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 496 | if (pcmd == NULL) |
| 497 | return _FAIL; |
| 498 | t_len = sizeof(u32) + 6 * sizeof(unsigned char) + 2 + |
| 499 | sizeof(struct ndis_802_11_ssid) + sizeof(u32) + |
| 500 | sizeof(s32) + |
| 501 | sizeof(enum NDIS_802_11_NETWORK_TYPE) + |
| 502 | sizeof(struct NDIS_802_11_CONFIGURATION) + |
| 503 | sizeof(enum NDIS_802_11_NETWORK_INFRASTRUCTURE) + |
| 504 | sizeof(NDIS_802_11_RATES_EX) + |
| 505 | sizeof(u32) + MAX_IE_SZ; |
| 506 | |
| 507 | /* for hidden ap to set fw_state here */ |
| 508 | if (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) != |
| 509 | true) { |
| 510 | switch (ndis_network_mode) { |
| 511 | case Ndis802_11IBSS: |
| 512 | pmlmepriv->fw_state |= WIFI_ADHOC_STATE; |
| 513 | break; |
| 514 | case Ndis802_11Infrastructure: |
| 515 | pmlmepriv->fw_state |= WIFI_STATION_STATE; |
| 516 | break; |
| 517 | case Ndis802_11APMode: |
| 518 | case Ndis802_11AutoUnknown: |
| 519 | case Ndis802_11InfrastructureMax: |
| 520 | break; |
| 521 | } |
| 522 | } |
| 523 | psecnetwork = (struct ndis_wlan_bssid_ex *)&psecuritypriv->sec_bss; |
| 524 | if (psecnetwork == NULL) { |
Alexander Beregalov | 4008386 | 2011-03-26 20:18:14 +0300 | [diff] [blame] | 525 | kfree(pcmd); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 526 | return _FAIL; |
| 527 | } |
| 528 | memset(psecnetwork, 0, t_len); |
| 529 | memcpy(psecnetwork, &pnetwork->network, t_len); |
| 530 | auth = &psecuritypriv->authenticator_ie[0]; |
| 531 | psecuritypriv->authenticator_ie[0] = (unsigned char) |
| 532 | psecnetwork->IELength; |
| 533 | if ((psecnetwork->IELength-12) < (256 - 1)) |
| 534 | memcpy(&psecuritypriv->authenticator_ie[1], |
| 535 | &psecnetwork->IEs[12], psecnetwork->IELength-12); |
| 536 | else |
| 537 | memcpy(&psecuritypriv->authenticator_ie[1], |
| 538 | &psecnetwork->IEs[12], (256-1)); |
| 539 | psecnetwork->IELength = 0; |
| 540 | /* If the the driver wants to use the bssid to create the connection. |
| 541 | * If not, we copy the connecting AP's MAC address to it so that |
| 542 | * the driver just has the bssid information for PMKIDList searching. |
| 543 | */ |
| 544 | if (pmlmepriv->assoc_by_bssid == false) |
| 545 | memcpy(&pmlmepriv->assoc_bssid[0], |
| 546 | &pnetwork->network.MacAddress[0], ETH_ALEN); |
| 547 | psecnetwork->IELength = r8712_restruct_sec_ie(padapter, |
| 548 | &pnetwork->network.IEs[0], |
| 549 | &psecnetwork->IEs[0], |
| 550 | pnetwork->network.IELength); |
| 551 | pqospriv->qos_option = 0; |
| 552 | if (pregistrypriv->wmm_enable) { |
| 553 | u32 tmp_len; |
| 554 | |
| 555 | tmp_len = r8712_restruct_wmm_ie(padapter, |
| 556 | &pnetwork->network.IEs[0], |
| 557 | &psecnetwork->IEs[0], |
| 558 | pnetwork->network.IELength, |
| 559 | psecnetwork->IELength); |
| 560 | if (psecnetwork->IELength != tmp_len) { |
| 561 | psecnetwork->IELength = tmp_len; |
| 562 | pqospriv->qos_option = 1; /* WMM IE in beacon */ |
| 563 | } else |
| 564 | pqospriv->qos_option = 0; /* no WMM IE in beacon */ |
| 565 | } |
| 566 | if (pregistrypriv->ht_enable) { |
Larry Finger | 1c9bb32 | 2010-08-30 22:32:34 -0500 | [diff] [blame] | 567 | /* For WEP mode, we will use the bg mode to do the connection |
| 568 | * to avoid some IOT issues, especially for Realtek 8192u |
| 569 | * SoftAP. |
| 570 | */ |
Javier M. Mellid | 2657c30 | 2011-04-02 03:02:12 +0200 | [diff] [blame] | 571 | if ((padapter->securitypriv.PrivacyAlgrthm != _WEP40_) && |
| 572 | (padapter->securitypriv.PrivacyAlgrthm != _WEP104_)) { |
Larry Finger | 1c9bb32 | 2010-08-30 22:32:34 -0500 | [diff] [blame] | 573 | /* restructure_ht_ie */ |
| 574 | r8712_restructure_ht_ie(padapter, |
| 575 | &pnetwork->network.IEs[0], |
| 576 | &psecnetwork->IEs[0], |
| 577 | pnetwork->network.IELength, |
| 578 | &psecnetwork->IELength); |
Larry Finger | 1c9bb32 | 2010-08-30 22:32:34 -0500 | [diff] [blame] | 579 | } |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 580 | } |
| 581 | psecuritypriv->supplicant_ie[0] = (u8)psecnetwork->IELength; |
| 582 | if (psecnetwork->IELength < 255) |
| 583 | memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0], |
| 584 | psecnetwork->IELength); |
| 585 | else |
| 586 | memcpy(&psecuritypriv->supplicant_ie[1], &psecnetwork->IEs[0], |
| 587 | 255); |
| 588 | /* get cmdsz before endian conversion */ |
| 589 | pcmd->cmdsz = r8712_get_ndis_wlan_bssid_ex_sz(psecnetwork); |
| 590 | #ifdef __BIG_ENDIAN |
| 591 | /* wlan_network endian conversion */ |
| 592 | psecnetwork->Length = cpu_to_le32(psecnetwork->Length); |
| 593 | psecnetwork->Ssid.SsidLength = cpu_to_le32( |
| 594 | psecnetwork->Ssid.SsidLength); |
| 595 | psecnetwork->Privacy = cpu_to_le32(psecnetwork->Privacy); |
| 596 | psecnetwork->Rssi = cpu_to_le32(psecnetwork->Rssi); |
| 597 | psecnetwork->NetworkTypeInUse = cpu_to_le32( |
| 598 | psecnetwork->NetworkTypeInUse); |
| 599 | psecnetwork->Configuration.ATIMWindow = cpu_to_le32( |
| 600 | psecnetwork->Configuration.ATIMWindow); |
| 601 | psecnetwork->Configuration.BeaconPeriod = cpu_to_le32( |
| 602 | psecnetwork->Configuration.BeaconPeriod); |
| 603 | psecnetwork->Configuration.DSConfig = cpu_to_le32( |
| 604 | psecnetwork->Configuration.DSConfig); |
| 605 | psecnetwork->Configuration.FHConfig.DwellTime = cpu_to_le32( |
| 606 | psecnetwork->Configuration.FHConfig.DwellTime); |
| 607 | psecnetwork->Configuration.FHConfig.HopPattern = cpu_to_le32( |
| 608 | psecnetwork->Configuration.FHConfig.HopPattern); |
| 609 | psecnetwork->Configuration.FHConfig.HopSet = cpu_to_le32( |
| 610 | psecnetwork->Configuration.FHConfig.HopSet); |
| 611 | psecnetwork->Configuration.FHConfig.Length = cpu_to_le32( |
| 612 | psecnetwork->Configuration.FHConfig.Length); |
| 613 | psecnetwork->Configuration.Length = cpu_to_le32( |
| 614 | psecnetwork->Configuration.Length); |
| 615 | psecnetwork->InfrastructureMode = cpu_to_le32( |
| 616 | psecnetwork->InfrastructureMode); |
| 617 | psecnetwork->IELength = cpu_to_le32(psecnetwork->IELength); |
| 618 | #endif |
| 619 | _init_listhead(&pcmd->list); |
| 620 | pcmd->cmdcode = _JoinBss_CMD_; |
| 621 | pcmd->parmbuf = (unsigned char *)psecnetwork; |
| 622 | pcmd->rsp = NULL; |
| 623 | pcmd->rspsz = 0; |
| 624 | r8712_enqueue_cmd(pcmdpriv, pcmd); |
| 625 | return _SUCCESS; |
| 626 | } |
| 627 | |
| 628 | u8 r8712_disassoc_cmd(struct _adapter *padapter) /* for sta_mode */ |
| 629 | { |
| 630 | struct cmd_obj *pdisconnect_cmd; |
| 631 | struct disconnect_parm *pdisconnect; |
| 632 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 633 | |
| 634 | pdisconnect_cmd = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 635 | if (pdisconnect_cmd == NULL) |
| 636 | return _FAIL; |
| 637 | pdisconnect = (struct disconnect_parm *)_malloc( |
| 638 | sizeof(struct disconnect_parm)); |
| 639 | if (pdisconnect == NULL) { |
| 640 | kfree((u8 *)pdisconnect_cmd); |
| 641 | return _FAIL; |
| 642 | } |
| 643 | init_h2fwcmd_w_parm_no_rsp(pdisconnect_cmd, pdisconnect, |
| 644 | _DisConnect_CMD_); |
| 645 | r8712_enqueue_cmd(pcmdpriv, pdisconnect_cmd); |
| 646 | return _SUCCESS; |
| 647 | } |
| 648 | |
| 649 | u8 r8712_setopmode_cmd(struct _adapter *padapter, |
| 650 | enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype) |
| 651 | { |
| 652 | struct cmd_obj *ph2c; |
| 653 | struct setopmode_parm *psetop; |
| 654 | |
| 655 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 656 | |
| 657 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 658 | if (ph2c == NULL) |
| 659 | return _FAIL; |
| 660 | psetop = (struct setopmode_parm *)_malloc( |
| 661 | sizeof(struct setopmode_parm)); |
| 662 | if (psetop == NULL) { |
| 663 | kfree((u8 *) ph2c); |
| 664 | return _FAIL; |
| 665 | } |
| 666 | init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_); |
| 667 | psetop->mode = (u8)networktype; |
| 668 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 669 | return _SUCCESS; |
| 670 | } |
| 671 | |
| 672 | u8 r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key) |
| 673 | { |
| 674 | struct cmd_obj *ph2c; |
| 675 | struct set_stakey_parm *psetstakey_para; |
| 676 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 677 | struct set_stakey_rsp *psetstakey_rsp = NULL; |
| 678 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 679 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
| 680 | struct sta_info *sta = (struct sta_info *)psta; |
| 681 | |
| 682 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 683 | if (ph2c == NULL) |
| 684 | return _FAIL; |
| 685 | psetstakey_para = (struct set_stakey_parm *)_malloc( |
| 686 | sizeof(struct set_stakey_parm)); |
| 687 | if (psetstakey_para == NULL) { |
| 688 | kfree((u8 *) ph2c); |
| 689 | return _FAIL; |
| 690 | } |
| 691 | psetstakey_rsp = (struct set_stakey_rsp *)_malloc( |
| 692 | sizeof(struct set_stakey_rsp)); |
| 693 | if (psetstakey_rsp == NULL) { |
| 694 | kfree((u8 *) ph2c); |
| 695 | kfree((u8 *) psetstakey_para); |
| 696 | return _FAIL; |
| 697 | } |
| 698 | init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_); |
| 699 | ph2c->rsp = (u8 *) psetstakey_rsp; |
| 700 | ph2c->rspsz = sizeof(struct set_stakey_rsp); |
| 701 | memcpy(psetstakey_para->addr, sta->hwaddr, ETH_ALEN); |
| 702 | if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) |
| 703 | psetstakey_para->algorithm = (unsigned char) |
| 704 | psecuritypriv->PrivacyAlgrthm; |
| 705 | else |
| 706 | GET_ENCRY_ALGO(psecuritypriv, sta, |
| 707 | psetstakey_para->algorithm, false); |
| 708 | if (unicast_key == true) |
| 709 | memcpy(&psetstakey_para->key, &sta->x_UncstKey, 16); |
| 710 | else |
| 711 | memcpy(&psetstakey_para->key, |
| 712 | &psecuritypriv->XGrpKey[ |
| 713 | psecuritypriv->XGrpKeyid - 1]. skey, 16); |
| 714 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 715 | return _SUCCESS; |
| 716 | } |
| 717 | |
| 718 | u8 r8712_setrfintfs_cmd(struct _adapter *padapter, u8 mode) |
| 719 | { |
| 720 | struct cmd_obj *ph2c; |
| 721 | struct setrfintfs_parm *psetrfintfsparm; |
| 722 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 723 | |
| 724 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 725 | if (ph2c == NULL) |
| 726 | return _FAIL; |
| 727 | psetrfintfsparm = (struct setrfintfs_parm *)_malloc( |
| 728 | sizeof(struct setrfintfs_parm)); |
| 729 | if (psetrfintfsparm == NULL) { |
| 730 | kfree((unsigned char *) ph2c); |
| 731 | return _FAIL; |
| 732 | } |
| 733 | init_h2fwcmd_w_parm_no_rsp(ph2c, psetrfintfsparm, |
| 734 | GEN_CMD_CODE(_SetRFIntFs)); |
| 735 | psetrfintfsparm->rfintfs = mode; |
| 736 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 737 | return _SUCCESS; |
| 738 | } |
| 739 | |
| 740 | u8 r8712_setrttbl_cmd(struct _adapter *padapter, |
| 741 | struct setratable_parm *prate_table) |
| 742 | { |
| 743 | struct cmd_obj *ph2c; |
| 744 | struct setratable_parm *psetrttblparm; |
| 745 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 746 | |
| 747 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 748 | if (ph2c == NULL) |
| 749 | return _FAIL; |
| 750 | psetrttblparm = (struct setratable_parm *)_malloc( |
| 751 | sizeof(struct setratable_parm)); |
| 752 | if (psetrttblparm == NULL) { |
| 753 | kfree((unsigned char *)ph2c); |
| 754 | return _FAIL; |
| 755 | } |
| 756 | init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, |
| 757 | GEN_CMD_CODE(_SetRaTable)); |
| 758 | memcpy(psetrttblparm, prate_table, sizeof(struct setratable_parm)); |
| 759 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 760 | return _SUCCESS; |
| 761 | } |
| 762 | |
| 763 | u8 r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr) |
| 764 | { |
| 765 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 766 | struct cmd_obj *ph2c; |
| 767 | struct SetMacAddr_param *psetMacAddr_para; |
| 768 | |
| 769 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 770 | if (ph2c == NULL) |
| 771 | return _FAIL; |
| 772 | psetMacAddr_para = (struct SetMacAddr_param *)_malloc( |
| 773 | sizeof(struct SetMacAddr_param)); |
| 774 | if (psetMacAddr_para == NULL) { |
| 775 | kfree((u8 *) ph2c); |
| 776 | return _FAIL; |
| 777 | } |
| 778 | init_h2fwcmd_w_parm_no_rsp(ph2c, psetMacAddr_para, |
| 779 | _SetMacAddress_CMD_); |
| 780 | memcpy(psetMacAddr_para->MacAddr, mac_addr, ETH_ALEN); |
| 781 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 782 | return _SUCCESS; |
| 783 | } |
| 784 | |
| 785 | u8 r8712_setassocsta_cmd(struct _adapter *padapter, u8 *mac_addr) |
| 786 | { |
| 787 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 788 | struct cmd_obj *ph2c; |
| 789 | struct set_assocsta_parm *psetassocsta_para; |
| 790 | struct set_stakey_rsp *psetassocsta_rsp = NULL; |
| 791 | |
| 792 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 793 | if (ph2c == NULL) |
| 794 | return _FAIL; |
| 795 | psetassocsta_para = (struct set_assocsta_parm *) |
| 796 | _malloc(sizeof(struct set_assocsta_parm)); |
| 797 | if (psetassocsta_para == NULL) { |
| 798 | kfree((u8 *) ph2c); |
| 799 | return _FAIL; |
| 800 | } |
| 801 | psetassocsta_rsp = (struct set_stakey_rsp *)_malloc( |
| 802 | sizeof(struct set_assocsta_rsp)); |
| 803 | if (psetassocsta_rsp == NULL) { |
| 804 | kfree((u8 *)ph2c); |
| 805 | kfree((u8 *)psetassocsta_para); |
| 806 | return _FAIL; |
| 807 | } |
| 808 | init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_); |
| 809 | ph2c->rsp = (u8 *) psetassocsta_rsp; |
| 810 | ph2c->rspsz = sizeof(struct set_assocsta_rsp); |
| 811 | memcpy(psetassocsta_para->addr, mac_addr, ETH_ALEN); |
| 812 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 813 | return _SUCCESS; |
| 814 | } |
| 815 | |
| 816 | u8 r8712_addbareq_cmd(struct _adapter *padapter, u8 tid) |
| 817 | { |
| 818 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 819 | struct cmd_obj *ph2c; |
| 820 | struct addBaReq_parm *paddbareq_parm; |
| 821 | |
| 822 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 823 | if (ph2c == NULL) |
| 824 | return _FAIL; |
| 825 | paddbareq_parm = (struct addBaReq_parm *)_malloc( |
| 826 | sizeof(struct addBaReq_parm)); |
| 827 | if (paddbareq_parm == NULL) { |
| 828 | kfree((unsigned char *)ph2c); |
| 829 | return _FAIL; |
| 830 | } |
| 831 | paddbareq_parm->tid = tid; |
| 832 | init_h2fwcmd_w_parm_no_rsp(ph2c, paddbareq_parm, |
| 833 | GEN_CMD_CODE(_AddBAReq)); |
| 834 | r8712_enqueue_cmd_ex(pcmdpriv, ph2c); |
| 835 | return _SUCCESS; |
| 836 | } |
| 837 | |
| 838 | u8 r8712_wdg_wk_cmd(struct _adapter *padapter) |
| 839 | { |
| 840 | struct cmd_obj *ph2c; |
| 841 | struct drvint_cmd_parm *pdrvintcmd_param; |
| 842 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 843 | |
| 844 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 845 | if (ph2c == NULL) |
| 846 | return _FAIL; |
| 847 | pdrvintcmd_param = (struct drvint_cmd_parm *)_malloc( |
| 848 | sizeof(struct drvint_cmd_parm)); |
| 849 | if (pdrvintcmd_param == NULL) { |
| 850 | kfree((unsigned char *)ph2c); |
| 851 | return _FAIL; |
| 852 | } |
| 853 | pdrvintcmd_param->i_cid = WDG_WK_CID; |
| 854 | pdrvintcmd_param->sz = 0; |
| 855 | pdrvintcmd_param->pbuf = NULL; |
| 856 | init_h2fwcmd_w_parm_no_rsp(ph2c, pdrvintcmd_param, _DRV_INT_CMD_); |
| 857 | r8712_enqueue_cmd_ex(pcmdpriv, ph2c); |
| 858 | return _SUCCESS; |
| 859 | } |
| 860 | |
| 861 | void r8712_survey_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd) |
| 862 | { |
| 863 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 864 | |
| 865 | if (pcmd->res != H2C_SUCCESS) |
| 866 | clr_fwstate(pmlmepriv, _FW_UNDER_SURVEY); |
| 867 | r8712_free_cmd_obj(pcmd); |
| 868 | } |
| 869 | |
| 870 | void r8712_disassoc_cmd_callback(struct _adapter *padapter, |
| 871 | struct cmd_obj *pcmd) |
| 872 | { |
| 873 | unsigned long irqL; |
| 874 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 875 | |
| 876 | if (pcmd->res != H2C_SUCCESS) { |
| 877 | spin_lock_irqsave(&pmlmepriv->lock, irqL); |
| 878 | set_fwstate(pmlmepriv, _FW_LINKED); |
| 879 | spin_unlock_irqrestore(&pmlmepriv->lock, irqL); |
| 880 | return; |
| 881 | } |
| 882 | r8712_free_cmd_obj(pcmd); |
| 883 | } |
| 884 | |
| 885 | void r8712_joinbss_cmd_callback(struct _adapter *padapter, struct cmd_obj *pcmd) |
| 886 | { |
| 887 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 888 | |
| 889 | if ((pcmd->res != H2C_SUCCESS)) |
| 890 | _set_timer(&pmlmepriv->assoc_timer, 1); |
| 891 | r8712_free_cmd_obj(pcmd); |
| 892 | } |
| 893 | |
| 894 | void r8712_createbss_cmd_callback(struct _adapter *padapter, |
| 895 | struct cmd_obj *pcmd) |
| 896 | { |
| 897 | unsigned long irqL; |
| 898 | u8 timer_cancelled; |
| 899 | struct sta_info *psta = NULL; |
| 900 | struct wlan_network *pwlan = NULL; |
| 901 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 902 | struct ndis_wlan_bssid_ex *pnetwork = (struct ndis_wlan_bssid_ex *) |
| 903 | pcmd->parmbuf; |
| 904 | struct wlan_network *tgt_network = &(pmlmepriv->cur_network); |
| 905 | |
| 906 | if ((pcmd->res != H2C_SUCCESS)) |
| 907 | _set_timer(&pmlmepriv->assoc_timer, 1); |
| 908 | _cancel_timer(&pmlmepriv->assoc_timer, &timer_cancelled); |
| 909 | #ifdef __BIG_ENDIAN |
| 910 | /* endian_convert */ |
| 911 | pnetwork->Length = le32_to_cpu(pnetwork->Length); |
| 912 | pnetwork->Ssid.SsidLength = le32_to_cpu(pnetwork->Ssid.SsidLength); |
| 913 | pnetwork->Privacy = le32_to_cpu(pnetwork->Privacy); |
| 914 | pnetwork->Rssi = le32_to_cpu(pnetwork->Rssi); |
| 915 | pnetwork->NetworkTypeInUse = le32_to_cpu(pnetwork->NetworkTypeInUse); |
| 916 | pnetwork->Configuration.ATIMWindow = le32_to_cpu(pnetwork-> |
| 917 | Configuration.ATIMWindow); |
| 918 | pnetwork->Configuration.DSConfig = le32_to_cpu(pnetwork-> |
| 919 | Configuration.DSConfig); |
| 920 | pnetwork->Configuration.FHConfig.DwellTime = le32_to_cpu(pnetwork-> |
| 921 | Configuration.FHConfig.DwellTime); |
| 922 | pnetwork->Configuration.FHConfig.HopPattern = le32_to_cpu(pnetwork-> |
| 923 | Configuration.FHConfig.HopPattern); |
| 924 | pnetwork->Configuration.FHConfig.HopSet = le32_to_cpu(pnetwork-> |
| 925 | Configuration.FHConfig.HopSet); |
| 926 | pnetwork->Configuration.FHConfig.Length = le32_to_cpu(pnetwork-> |
| 927 | Configuration.FHConfig.Length); |
| 928 | pnetwork->Configuration.Length = le32_to_cpu(pnetwork-> |
| 929 | Configuration.Length); |
| 930 | pnetwork->InfrastructureMode = le32_to_cpu(pnetwork-> |
| 931 | InfrastructureMode); |
| 932 | pnetwork->IELength = le32_to_cpu(pnetwork->IELength); |
| 933 | #endif |
| 934 | spin_lock_irqsave(&pmlmepriv->lock, irqL); |
| 935 | if ((pmlmepriv->fw_state) & WIFI_AP_STATE) { |
| 936 | psta = r8712_get_stainfo(&padapter->stapriv, |
| 937 | pnetwork->MacAddress); |
| 938 | if (!psta) { |
| 939 | psta = r8712_alloc_stainfo(&padapter->stapriv, |
| 940 | pnetwork->MacAddress); |
| 941 | if (psta == NULL) |
| 942 | goto createbss_cmd_fail ; |
| 943 | } |
| 944 | r8712_indicate_connect(padapter); |
| 945 | } else { |
| 946 | pwlan = _r8712_alloc_network(pmlmepriv); |
| 947 | if (pwlan == NULL) { |
| 948 | pwlan = r8712_get_oldest_wlan_network( |
| 949 | &pmlmepriv->scanned_queue); |
| 950 | if (pwlan == NULL) |
| 951 | goto createbss_cmd_fail; |
| 952 | pwlan->last_scanned = jiffies; |
| 953 | } else |
| 954 | list_insert_tail(&(pwlan->list), |
| 955 | &pmlmepriv->scanned_queue.queue); |
| 956 | pnetwork->Length = r8712_get_ndis_wlan_bssid_ex_sz(pnetwork); |
| 957 | memcpy(&(pwlan->network), pnetwork, pnetwork->Length); |
| 958 | pwlan->fixed = true; |
| 959 | memcpy(&tgt_network->network, pnetwork, |
| 960 | (r8712_get_ndis_wlan_bssid_ex_sz(pnetwork))); |
| 961 | if (pmlmepriv->fw_state & _FW_UNDER_LINKING) |
| 962 | pmlmepriv->fw_state ^= _FW_UNDER_LINKING; |
| 963 | /* we will set _FW_LINKED when there is one more sat to |
| 964 | * join us (stassoc_event_callback) */ |
| 965 | } |
| 966 | createbss_cmd_fail: |
| 967 | spin_unlock_irqrestore(&pmlmepriv->lock, irqL); |
| 968 | r8712_free_cmd_obj(pcmd); |
| 969 | } |
| 970 | |
| 971 | void r8712_setstaKey_cmdrsp_callback(struct _adapter *padapter, |
| 972 | struct cmd_obj *pcmd) |
| 973 | { |
| 974 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 975 | struct set_stakey_rsp *psetstakey_rsp = (struct set_stakey_rsp *) |
| 976 | (pcmd->rsp); |
| 977 | struct sta_info *psta = r8712_get_stainfo(pstapriv, |
| 978 | psetstakey_rsp->addr); |
| 979 | |
| 980 | if (psta == NULL) |
| 981 | goto exit; |
| 982 | psta->aid = psta->mac_id = psetstakey_rsp->keyid; /*CAM_ID(CAM_ENTRY)*/ |
| 983 | exit: |
| 984 | r8712_free_cmd_obj(pcmd); |
| 985 | } |
| 986 | |
| 987 | void r8712_setassocsta_cmdrsp_callback(struct _adapter *padapter, |
| 988 | struct cmd_obj *pcmd) |
| 989 | { |
| 990 | unsigned long irqL; |
| 991 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 992 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 993 | struct set_assocsta_parm *passocsta_parm = |
| 994 | (struct set_assocsta_parm *)(pcmd->parmbuf); |
| 995 | struct set_assocsta_rsp *passocsta_rsp = |
| 996 | (struct set_assocsta_rsp *) (pcmd->rsp); |
| 997 | struct sta_info *psta = r8712_get_stainfo(pstapriv, |
| 998 | passocsta_parm->addr); |
| 999 | |
| 1000 | if (psta == NULL) |
| 1001 | return; |
| 1002 | psta->aid = psta->mac_id = passocsta_rsp->cam_id; |
| 1003 | spin_lock_irqsave(&pmlmepriv->lock, irqL); |
| 1004 | if ((check_fwstate(pmlmepriv, WIFI_MP_STATE)) && |
| 1005 | (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) |
| 1006 | pmlmepriv->fw_state ^= _FW_UNDER_LINKING; |
| 1007 | set_fwstate(pmlmepriv, _FW_LINKED); |
| 1008 | spin_unlock_irqrestore(&pmlmepriv->lock, irqL); |
| 1009 | r8712_free_cmd_obj(pcmd); |
| 1010 | } |
Ali Bahar | c6dc001 | 2011-09-04 03:14:20 +0800 | [diff] [blame^] | 1011 | |
| 1012 | u8 r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl, |
| 1013 | u32 tryPktCnt, u32 tryPktInterval, u32 firstStageTO) |
| 1014 | { |
| 1015 | struct cmd_obj *ph2c; |
| 1016 | struct DisconnectCtrlEx_param *param; |
| 1017 | struct cmd_priv *pcmdpriv = &adapter->cmdpriv; |
| 1018 | |
| 1019 | ph2c = (struct cmd_obj *)_malloc(sizeof(struct cmd_obj)); |
| 1020 | if (ph2c == NULL) |
| 1021 | return _FAIL; |
| 1022 | param = (struct DisconnectCtrlEx_param *) |
| 1023 | _malloc(sizeof(struct DisconnectCtrlEx_param)); |
| 1024 | if (param == NULL) { |
| 1025 | kfree((unsigned char *) ph2c); |
| 1026 | return _FAIL; |
| 1027 | } |
| 1028 | memset(param, 0, sizeof(struct DisconnectCtrlEx_param)); |
| 1029 | |
| 1030 | param->EnableDrvCtrl = (unsigned char)enableDrvCtrl; |
| 1031 | param->TryPktCnt = (unsigned char)tryPktCnt; |
| 1032 | param->TryPktInterval = (unsigned char)tryPktInterval; |
| 1033 | param->FirstStageTO = (unsigned int)firstStageTO; |
| 1034 | |
| 1035 | init_h2fwcmd_w_parm_no_rsp(ph2c, param, |
| 1036 | GEN_CMD_CODE(_DisconnectCtrlEx)); |
| 1037 | r8712_enqueue_cmd(pcmdpriv, ph2c); |
| 1038 | return _SUCCESS; |
| 1039 | } |