2 * This file contains the handling of command
3 * responses as well as events generated by firmware.
5 #include <linux/delay.h>
6 #include <linux/if_arp.h>
7 #include <linux/netdevice.h>
9 #include <net/iw_handler.h>
19 * @brief This function handles disconnect event. it
20 * reports disconnect to upper layer, clean tx/rx packets,
21 * reset link state etc.
23 * @param priv A pointer to struct lbs_private structure
26 void lbs_mac_event_disconnected(struct lbs_private
*priv
)
28 union iwreq_data wrqu
;
30 if (priv
->connect_status
!= LBS_CONNECTED
)
33 lbs_deb_enter(LBS_DEB_ASSOC
);
35 memset(wrqu
.ap_addr
.sa_data
, 0x00, ETH_ALEN
);
36 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
39 * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
40 * It causes problem in the Supplicant
43 msleep_interruptible(1000);
44 wireless_send_event(priv
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
46 /* report disconnect to upper layer */
47 netif_stop_queue(priv
->dev
);
48 netif_carrier_off(priv
->dev
);
50 /* Free Tx and Rx packets */
51 kfree_skb(priv
->currenttxskb
);
52 priv
->currenttxskb
= NULL
;
53 priv
->tx_pending_len
= 0;
55 /* reset SNR/NF/RSSI values */
56 memset(priv
->SNR
, 0x00, sizeof(priv
->SNR
));
57 memset(priv
->NF
, 0x00, sizeof(priv
->NF
));
58 memset(priv
->RSSI
, 0x00, sizeof(priv
->RSSI
));
59 memset(priv
->rawSNR
, 0x00, sizeof(priv
->rawSNR
));
60 memset(priv
->rawNF
, 0x00, sizeof(priv
->rawNF
));
63 priv
->connect_status
= LBS_DISCONNECTED
;
65 /* Clear out associated SSID and BSSID since connection is
68 memset(&priv
->curbssparams
.bssid
, 0, ETH_ALEN
);
69 memset(&priv
->curbssparams
.ssid
, 0, IW_ESSID_MAX_SIZE
);
70 priv
->curbssparams
.ssid_len
= 0;
72 if (priv
->psstate
!= PS_STATE_FULL_POWER
) {
73 /* make firmware to exit PS mode */
74 lbs_deb_cmd("disconnected, so exit PS mode\n");
75 lbs_ps_wakeup(priv
, 0);
77 lbs_deb_leave(LBS_DEB_CMD
);
81 * @brief This function handles MIC failure event.
83 * @param priv A pointer to struct lbs_private structure
84 * @para event the event id
87 static void handle_mic_failureevent(struct lbs_private
*priv
, u32 event
)
91 lbs_deb_enter(LBS_DEB_CMD
);
92 memset(buf
, 0, sizeof(buf
));
94 sprintf(buf
, "%s", "MLME-MICHAELMICFAILURE.indication ");
96 if (event
== MACREG_INT_CODE_MIC_ERR_UNICAST
) {
97 strcat(buf
, "unicast ");
99 strcat(buf
, "multicast ");
102 lbs_send_iwevcustom_event(priv
, buf
);
103 lbs_deb_leave(LBS_DEB_CMD
);
106 static int lbs_ret_reg_access(struct lbs_private
*priv
,
107 u16 type
, struct cmd_ds_command
*resp
)
111 lbs_deb_enter(LBS_DEB_CMD
);
114 case CMD_RET(CMD_MAC_REG_ACCESS
):
116 struct cmd_ds_mac_reg_access
*reg
= &resp
->params
.macreg
;
118 priv
->offsetvalue
.offset
= (u32
)le16_to_cpu(reg
->offset
);
119 priv
->offsetvalue
.value
= le32_to_cpu(reg
->value
);
123 case CMD_RET(CMD_BBP_REG_ACCESS
):
125 struct cmd_ds_bbp_reg_access
*reg
= &resp
->params
.bbpreg
;
127 priv
->offsetvalue
.offset
= (u32
)le16_to_cpu(reg
->offset
);
128 priv
->offsetvalue
.value
= reg
->value
;
132 case CMD_RET(CMD_RF_REG_ACCESS
):
134 struct cmd_ds_rf_reg_access
*reg
= &resp
->params
.rfreg
;
136 priv
->offsetvalue
.offset
= (u32
)le16_to_cpu(reg
->offset
);
137 priv
->offsetvalue
.value
= reg
->value
;
145 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
149 static int lbs_ret_802_11_stat(struct lbs_private
*priv
,
150 struct cmd_ds_command
*resp
)
152 lbs_deb_enter(LBS_DEB_CMD
);
153 /* currently priv->wlan802_11Stat is unused
155 struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
157 // TODO Convert it to Big endian befor copy
158 memcpy(&priv->wlan802_11Stat,
159 p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
161 lbs_deb_leave(LBS_DEB_CMD
);
165 static int lbs_ret_802_11_snmp_mib(struct lbs_private
*priv
,
166 struct cmd_ds_command
*resp
)
168 struct cmd_ds_802_11_snmp_mib
*smib
= &resp
->params
.smib
;
169 u16 oid
= le16_to_cpu(smib
->oid
);
170 u16 querytype
= le16_to_cpu(smib
->querytype
);
172 lbs_deb_enter(LBS_DEB_CMD
);
174 lbs_deb_cmd("SNMP_RESP: oid 0x%x, querytype 0x%x\n", oid
,
176 lbs_deb_cmd("SNMP_RESP: Buf size %d\n", le16_to_cpu(smib
->bufsize
));
178 if (querytype
== CMD_ACT_GET
) {
182 le16_to_cpu(*((__le16
*)(smib
->value
)));
183 lbs_deb_cmd("SNMP_RESP: frag threshold %u\n",
188 le16_to_cpu(*((__le16
*)(smib
->value
)));
189 lbs_deb_cmd("SNMP_RESP: rts threshold %u\n",
192 case SHORT_RETRYLIM_I
:
194 le16_to_cpu(*((__le16
*)(smib
->value
)));
195 lbs_deb_cmd("SNMP_RESP: tx retry count %u\n",
203 lbs_deb_enter(LBS_DEB_CMD
);
207 static int lbs_ret_802_11_key_material(struct lbs_private
*priv
,
208 struct cmd_ds_command
*resp
)
210 struct cmd_ds_802_11_key_material
*pkeymaterial
=
211 &resp
->params
.keymaterial
;
212 u16 action
= le16_to_cpu(pkeymaterial
->action
);
214 lbs_deb_enter(LBS_DEB_CMD
);
216 /* Copy the returned key to driver private data */
217 if (action
== CMD_ACT_GET
) {
218 u8
* buf_ptr
= (u8
*) &pkeymaterial
->keyParamSet
;
219 u8
* resp_end
= (u8
*) (resp
+ le16_to_cpu(resp
->size
));
221 while (buf_ptr
< resp_end
) {
222 struct MrvlIEtype_keyParamSet
* pkeyparamset
=
223 (struct MrvlIEtype_keyParamSet
*) buf_ptr
;
224 struct enc_key
* pkey
;
225 u16 param_set_len
= le16_to_cpu(pkeyparamset
->length
);
226 u16 key_len
= le16_to_cpu(pkeyparamset
->keylen
);
227 u16 key_flags
= le16_to_cpu(pkeyparamset
->keyinfo
);
228 u16 key_type
= le16_to_cpu(pkeyparamset
->keytypeid
);
231 end
= (u8
*) pkeyparamset
+ sizeof (pkeyparamset
->type
)
232 + sizeof (pkeyparamset
->length
)
234 /* Make sure we don't access past the end of the IEs */
238 if (key_flags
& KEY_INFO_WPA_UNICAST
)
239 pkey
= &priv
->wpa_unicast_key
;
240 else if (key_flags
& KEY_INFO_WPA_MCAST
)
241 pkey
= &priv
->wpa_mcast_key
;
245 /* Copy returned key into driver */
246 memset(pkey
, 0, sizeof(struct enc_key
));
247 if (key_len
> sizeof(pkey
->key
))
249 pkey
->type
= key_type
;
250 pkey
->flags
= key_flags
;
252 memcpy(pkey
->key
, pkeyparamset
->key
, pkey
->len
);
258 lbs_deb_enter(LBS_DEB_CMD
);
262 static int lbs_ret_802_11_mac_address(struct lbs_private
*priv
,
263 struct cmd_ds_command
*resp
)
265 struct cmd_ds_802_11_mac_address
*macadd
= &resp
->params
.macadd
;
267 lbs_deb_enter(LBS_DEB_CMD
);
269 memcpy(priv
->current_addr
, macadd
->macadd
, ETH_ALEN
);
271 lbs_deb_enter(LBS_DEB_CMD
);
275 static int lbs_ret_802_11_rf_tx_power(struct lbs_private
*priv
,
276 struct cmd_ds_command
*resp
)
278 struct cmd_ds_802_11_rf_tx_power
*rtp
= &resp
->params
.txp
;
280 lbs_deb_enter(LBS_DEB_CMD
);
282 priv
->txpowerlevel
= le16_to_cpu(rtp
->currentlevel
);
284 lbs_deb_cmd("TX power currently %d\n", priv
->txpowerlevel
);
286 lbs_deb_leave(LBS_DEB_CMD
);
290 static int lbs_ret_802_11_rate_adapt_rateset(struct lbs_private
*priv
,
291 struct cmd_ds_command
*resp
)
293 struct cmd_ds_802_11_rate_adapt_rateset
*rates
= &resp
->params
.rateset
;
295 lbs_deb_enter(LBS_DEB_CMD
);
297 if (rates
->action
== CMD_ACT_GET
) {
298 priv
->enablehwauto
= le16_to_cpu(rates
->enablehwauto
);
299 priv
->ratebitmap
= le16_to_cpu(rates
->bitmap
);
302 lbs_deb_leave(LBS_DEB_CMD
);
306 static int lbs_ret_802_11_rssi(struct lbs_private
*priv
,
307 struct cmd_ds_command
*resp
)
309 struct cmd_ds_802_11_rssi_rsp
*rssirsp
= &resp
->params
.rssirsp
;
311 lbs_deb_enter(LBS_DEB_CMD
);
313 /* store the non average value */
314 priv
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = le16_to_cpu(rssirsp
->SNR
);
315 priv
->NF
[TYPE_BEACON
][TYPE_NOAVG
] = le16_to_cpu(rssirsp
->noisefloor
);
317 priv
->SNR
[TYPE_BEACON
][TYPE_AVG
] = le16_to_cpu(rssirsp
->avgSNR
);
318 priv
->NF
[TYPE_BEACON
][TYPE_AVG
] = le16_to_cpu(rssirsp
->avgnoisefloor
);
320 priv
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] =
321 CAL_RSSI(priv
->SNR
[TYPE_BEACON
][TYPE_NOAVG
],
322 priv
->NF
[TYPE_BEACON
][TYPE_NOAVG
]);
324 priv
->RSSI
[TYPE_BEACON
][TYPE_AVG
] =
325 CAL_RSSI(priv
->SNR
[TYPE_BEACON
][TYPE_AVG
] / AVG_SCALE
,
326 priv
->NF
[TYPE_BEACON
][TYPE_AVG
] / AVG_SCALE
);
328 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
329 priv
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
],
330 priv
->RSSI
[TYPE_BEACON
][TYPE_AVG
]);
332 lbs_deb_leave(LBS_DEB_CMD
);
336 static int lbs_ret_802_11_eeprom_access(struct lbs_private
*priv
,
337 struct cmd_ds_command
*resp
)
339 struct lbs_ioctl_regrdwr
*pbuf
;
340 pbuf
= (struct lbs_ioctl_regrdwr
*) priv
->prdeeprom
;
342 lbs_deb_enter_args(LBS_DEB_CMD
, "len %d",
343 le16_to_cpu(resp
->params
.rdeeprom
.bytecount
));
344 if (pbuf
->NOB
< le16_to_cpu(resp
->params
.rdeeprom
.bytecount
)) {
346 lbs_deb_cmd("EEPROM read length too big\n");
349 pbuf
->NOB
= le16_to_cpu(resp
->params
.rdeeprom
.bytecount
);
352 memcpy(&pbuf
->value
, (u8
*) & resp
->params
.rdeeprom
.value
,
353 le16_to_cpu(resp
->params
.rdeeprom
.bytecount
));
354 lbs_deb_hex(LBS_DEB_CMD
, "EEPROM", (char *)&pbuf
->value
,
355 le16_to_cpu(resp
->params
.rdeeprom
.bytecount
));
357 lbs_deb_leave(LBS_DEB_CMD
);
361 static int lbs_ret_get_log(struct lbs_private
*priv
,
362 struct cmd_ds_command
*resp
)
364 struct cmd_ds_802_11_get_log
*logmessage
= &resp
->params
.glog
;
366 lbs_deb_enter(LBS_DEB_CMD
);
368 /* Stored little-endian */
369 memcpy(&priv
->logmsg
, logmessage
, sizeof(struct cmd_ds_802_11_get_log
));
371 lbs_deb_leave(LBS_DEB_CMD
);
375 static int lbs_ret_802_11_bcn_ctrl(struct lbs_private
* priv
,
376 struct cmd_ds_command
*resp
)
378 struct cmd_ds_802_11_beacon_control
*bcn_ctrl
=
379 &resp
->params
.bcn_ctrl
;
381 lbs_deb_enter(LBS_DEB_CMD
);
383 if (bcn_ctrl
->action
== CMD_ACT_GET
) {
384 priv
->beacon_enable
= (u8
) le16_to_cpu(bcn_ctrl
->beacon_enable
);
385 priv
->beacon_period
= le16_to_cpu(bcn_ctrl
->beacon_period
);
388 lbs_deb_enter(LBS_DEB_CMD
);
392 static inline int handle_cmd_response(struct lbs_private
*priv
,
394 struct cmd_header
*cmd_response
)
396 struct cmd_ds_command
*resp
= (struct cmd_ds_command
*) cmd_response
;
399 uint16_t respcmd
= le16_to_cpu(resp
->command
);
401 lbs_deb_enter(LBS_DEB_HOST
);
404 case CMD_RET(CMD_MAC_REG_ACCESS
):
405 case CMD_RET(CMD_BBP_REG_ACCESS
):
406 case CMD_RET(CMD_RF_REG_ACCESS
):
407 ret
= lbs_ret_reg_access(priv
, respcmd
, resp
);
410 case CMD_RET(CMD_802_11_SCAN
):
411 ret
= lbs_ret_80211_scan(priv
, resp
);
414 case CMD_RET(CMD_802_11_GET_LOG
):
415 ret
= lbs_ret_get_log(priv
, resp
);
418 case CMD_RET_802_11_ASSOCIATE
:
419 case CMD_RET(CMD_802_11_ASSOCIATE
):
420 case CMD_RET(CMD_802_11_REASSOCIATE
):
421 ret
= lbs_ret_80211_associate(priv
, resp
);
424 case CMD_RET(CMD_802_11_DISASSOCIATE
):
425 case CMD_RET(CMD_802_11_DEAUTHENTICATE
):
426 ret
= lbs_ret_80211_disassociate(priv
, resp
);
429 case CMD_RET(CMD_802_11_AD_HOC_START
):
430 case CMD_RET(CMD_802_11_AD_HOC_JOIN
):
431 ret
= lbs_ret_80211_ad_hoc_start(priv
, resp
);
434 case CMD_RET(CMD_802_11_GET_STAT
):
435 ret
= lbs_ret_802_11_stat(priv
, resp
);
438 case CMD_RET(CMD_802_11_SNMP_MIB
):
439 ret
= lbs_ret_802_11_snmp_mib(priv
, resp
);
442 case CMD_RET(CMD_802_11_RF_TX_POWER
):
443 ret
= lbs_ret_802_11_rf_tx_power(priv
, resp
);
446 case CMD_RET(CMD_802_11_SET_AFC
):
447 case CMD_RET(CMD_802_11_GET_AFC
):
448 spin_lock_irqsave(&priv
->driver_lock
, flags
);
449 memmove((void *)priv
->cur_cmd
->callback_arg
, &resp
->params
.afc
,
450 sizeof(struct cmd_ds_802_11_afc
));
451 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
455 case CMD_RET(CMD_MAC_MULTICAST_ADR
):
456 case CMD_RET(CMD_MAC_CONTROL
):
457 case CMD_RET(CMD_802_11_RESET
):
458 case CMD_RET(CMD_802_11_AUTHENTICATE
):
459 case CMD_RET(CMD_802_11_BEACON_STOP
):
462 case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET
):
463 ret
= lbs_ret_802_11_rate_adapt_rateset(priv
, resp
);
466 case CMD_RET(CMD_802_11_RSSI
):
467 ret
= lbs_ret_802_11_rssi(priv
, resp
);
470 case CMD_RET(CMD_802_11_MAC_ADDRESS
):
471 ret
= lbs_ret_802_11_mac_address(priv
, resp
);
474 case CMD_RET(CMD_802_11_AD_HOC_STOP
):
475 ret
= lbs_ret_80211_ad_hoc_stop(priv
, resp
);
478 case CMD_RET(CMD_802_11_KEY_MATERIAL
):
479 ret
= lbs_ret_802_11_key_material(priv
, resp
);
482 case CMD_RET(CMD_802_11_EEPROM_ACCESS
):
483 ret
= lbs_ret_802_11_eeprom_access(priv
, resp
);
486 case CMD_RET(CMD_802_11D_DOMAIN_INFO
):
487 ret
= lbs_ret_802_11d_domain_info(priv
, resp
);
490 case CMD_RET(CMD_802_11_TPC_CFG
):
491 spin_lock_irqsave(&priv
->driver_lock
, flags
);
492 memmove((void *)priv
->cur_cmd
->callback_arg
, &resp
->params
.tpccfg
,
493 sizeof(struct cmd_ds_802_11_tpc_cfg
));
494 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
496 case CMD_RET(CMD_802_11_LED_GPIO_CTRL
):
497 spin_lock_irqsave(&priv
->driver_lock
, flags
);
498 memmove((void *)priv
->cur_cmd
->callback_arg
, &resp
->params
.ledgpio
,
499 sizeof(struct cmd_ds_802_11_led_ctrl
));
500 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
503 case CMD_RET(CMD_802_11_PWR_CFG
):
504 spin_lock_irqsave(&priv
->driver_lock
, flags
);
505 memmove((void *)priv
->cur_cmd
->callback_arg
, &resp
->params
.pwrcfg
,
506 sizeof(struct cmd_ds_802_11_pwr_cfg
));
507 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
511 case CMD_RET(CMD_GET_TSF
):
512 spin_lock_irqsave(&priv
->driver_lock
, flags
);
513 memcpy((void *)priv
->cur_cmd
->callback_arg
,
514 &resp
->params
.gettsf
.tsfvalue
, sizeof(u64
));
515 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
517 case CMD_RET(CMD_BT_ACCESS
):
518 spin_lock_irqsave(&priv
->driver_lock
, flags
);
519 if (priv
->cur_cmd
->callback_arg
)
520 memcpy((void *)priv
->cur_cmd
->callback_arg
,
521 &resp
->params
.bt
.addr1
, 2 * ETH_ALEN
);
522 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
524 case CMD_RET(CMD_FWT_ACCESS
):
525 spin_lock_irqsave(&priv
->driver_lock
, flags
);
526 if (priv
->cur_cmd
->callback_arg
)
527 memcpy((void *)priv
->cur_cmd
->callback_arg
, &resp
->params
.fwt
,
528 sizeof(resp
->params
.fwt
));
529 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
531 case CMD_RET(CMD_802_11_BEACON_CTRL
):
532 ret
= lbs_ret_802_11_bcn_ctrl(priv
, resp
);
536 lbs_deb_host("CMD_RESP: unknown cmd response 0x%04x\n",
537 le16_to_cpu(resp
->command
));
540 lbs_deb_leave(LBS_DEB_HOST
);
544 int lbs_process_rx_command(struct lbs_private
*priv
)
546 uint16_t respcmd
, curcmd
;
547 struct cmd_header
*resp
;
552 lbs_deb_enter(LBS_DEB_HOST
);
554 mutex_lock(&priv
->lock
);
555 spin_lock_irqsave(&priv
->driver_lock
, flags
);
557 if (!priv
->cur_cmd
) {
558 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
560 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
564 resp
= (void *)priv
->upld_buf
;
565 curcmd
= le16_to_cpu(priv
->cur_cmd
->cmdbuf
->command
);
566 respcmd
= le16_to_cpu(resp
->command
);
567 result
= le16_to_cpu(resp
->result
);
569 lbs_deb_host("CMD_RESP: response 0x%04x, seq %d, size %d, jiffies %lu\n",
570 respcmd
, le16_to_cpu(resp
->seqnum
), priv
->upld_len
, jiffies
);
571 lbs_deb_hex(LBS_DEB_HOST
, "CMD_RESP", (void *) resp
, priv
->upld_len
);
573 if (resp
->seqnum
!= priv
->cur_cmd
->cmdbuf
->seqnum
) {
574 lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n",
575 le16_to_cpu(resp
->seqnum
), le16_to_cpu(priv
->cur_cmd
->cmdbuf
->seqnum
));
576 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
580 if (respcmd
!= CMD_RET(curcmd
) &&
581 respcmd
!= CMD_RET_802_11_ASSOCIATE
&& curcmd
!= CMD_802_11_ASSOCIATE
) {
582 lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd
, curcmd
);
583 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
588 if (resp
->result
== cpu_to_le16(0x0004)) {
589 /* 0x0004 means -EAGAIN. Drop the response, let it time out
590 and be resubmitted */
591 lbs_pr_info("Firmware returns DEFER to command %x. Will let it time out...\n",
592 le16_to_cpu(resp
->command
));
593 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
598 /* Now we got response from FW, cancel the command timer */
599 del_timer(&priv
->command_timer
);
600 priv
->cmd_timed_out
= 0;
601 if (priv
->nr_retries
) {
602 lbs_pr_info("Received result %x to command %x after %d retries\n",
603 result
, curcmd
, priv
->nr_retries
);
604 priv
->nr_retries
= 0;
607 /* Store the response code to cur_cmd_retcode. */
608 priv
->cur_cmd_retcode
= result
;
610 if (respcmd
== CMD_RET(CMD_802_11_PS_MODE
)) {
611 struct cmd_ds_802_11_ps_mode
*psmode
= (void *) &resp
[1];
612 u16 action
= le16_to_cpu(psmode
->action
);
615 "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
619 lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
622 * We should not re-try enter-ps command in
623 * ad-hoc mode. It takes place in
624 * lbs_execute_next_command().
626 if (priv
->mode
== IW_MODE_ADHOC
&&
627 action
== CMD_SUBCMD_ENTER_PS
)
628 priv
->psmode
= LBS802_11POWERMODECAM
;
629 } else if (action
== CMD_SUBCMD_ENTER_PS
) {
630 priv
->needtowakeup
= 0;
631 priv
->psstate
= PS_STATE_AWAKE
;
633 lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
634 if (priv
->connect_status
!= LBS_CONNECTED
) {
636 * When Deauth Event received before Enter_PS command
637 * response, We need to wake up the firmware.
640 "disconnected, invoking lbs_ps_wakeup\n");
642 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
643 mutex_unlock(&priv
->lock
);
644 lbs_ps_wakeup(priv
, 0);
645 mutex_lock(&priv
->lock
);
646 spin_lock_irqsave(&priv
->driver_lock
, flags
);
648 } else if (action
== CMD_SUBCMD_EXIT_PS
) {
649 priv
->needtowakeup
= 0;
650 priv
->psstate
= PS_STATE_FULL_POWER
;
651 lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
653 lbs_deb_host("CMD_RESP: PS action 0x%X\n", action
);
656 lbs_complete_command(priv
, priv
->cur_cmd
, result
);
657 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
663 /* If the command is not successful, cleanup and return failure */
664 if ((result
!= 0 || !(respcmd
& 0x8000))) {
665 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
668 * Handling errors here
671 case CMD_RET(CMD_GET_HW_SPEC
):
672 case CMD_RET(CMD_802_11_RESET
):
673 lbs_deb_host("CMD_RESP: reset failed\n");
677 lbs_complete_command(priv
, priv
->cur_cmd
, result
);
678 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
684 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
686 if (priv
->cur_cmd
&& priv
->cur_cmd
->callback
) {
687 ret
= priv
->cur_cmd
->callback(priv
, priv
->cur_cmd
->callback_arg
,
690 ret
= handle_cmd_response(priv
, 0, resp
);
692 spin_lock_irqsave(&priv
->driver_lock
, flags
);
695 /* Clean up and Put current command back to cmdfreeq */
696 lbs_complete_command(priv
, priv
->cur_cmd
, result
);
698 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
701 mutex_unlock(&priv
->lock
);
702 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
706 static int lbs_send_confirmwake(struct lbs_private
*priv
)
708 struct cmd_header
*cmd
= &priv
->lbs_ps_confirm_wake
;
711 lbs_deb_enter(LBS_DEB_HOST
);
713 cmd
->command
= cpu_to_le16(CMD_802_11_WAKEUP_CONFIRM
);
714 cmd
->size
= cpu_to_le16(sizeof(*cmd
));
715 cmd
->seqnum
= cpu_to_le16(++priv
->seqnum
);
718 lbs_deb_host("SEND_WAKEC_CMD: before download\n");
720 lbs_deb_hex(LBS_DEB_HOST
, "wake confirm command", (void *)cmd
, sizeof(*cmd
));
722 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (void *)cmd
, sizeof(*cmd
));
724 lbs_pr_alert("SEND_WAKEC_CMD: Host to Card failed for Confirm Wake\n");
726 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
730 int lbs_process_event(struct lbs_private
*priv
)
735 lbs_deb_enter(LBS_DEB_CMD
);
737 spin_lock_irq(&priv
->driver_lock
);
738 eventcause
= priv
->eventcause
>> SBI_EVENT_CAUSE_SHIFT
;
739 spin_unlock_irq(&priv
->driver_lock
);
741 lbs_deb_cmd("event cause %d\n", eventcause
);
743 switch (eventcause
) {
744 case MACREG_INT_CODE_LINK_SENSED
:
745 lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
748 case MACREG_INT_CODE_DEAUTHENTICATED
:
749 lbs_deb_cmd("EVENT: deauthenticated\n");
750 lbs_mac_event_disconnected(priv
);
753 case MACREG_INT_CODE_DISASSOCIATED
:
754 lbs_deb_cmd("EVENT: disassociated\n");
755 lbs_mac_event_disconnected(priv
);
758 case MACREG_INT_CODE_LINK_LOST_NO_SCAN
:
759 lbs_deb_cmd("EVENT: link lost\n");
760 lbs_mac_event_disconnected(priv
);
763 case MACREG_INT_CODE_PS_SLEEP
:
764 lbs_deb_cmd("EVENT: sleep\n");
766 /* handle unexpected PS SLEEP event */
767 if (priv
->psstate
== PS_STATE_FULL_POWER
) {
769 "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
772 priv
->psstate
= PS_STATE_PRE_SLEEP
;
774 lbs_ps_confirm_sleep(priv
, (u16
) priv
->psmode
);
778 case MACREG_INT_CODE_HOST_AWAKE
:
779 lbs_deb_cmd("EVENT: HOST_AWAKE\n");
780 lbs_send_confirmwake(priv
);
783 case MACREG_INT_CODE_PS_AWAKE
:
784 lbs_deb_cmd("EVENT: awake\n");
785 /* handle unexpected PS AWAKE event */
786 if (priv
->psstate
== PS_STATE_FULL_POWER
) {
788 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
792 priv
->psstate
= PS_STATE_AWAKE
;
794 if (priv
->needtowakeup
) {
796 * wait for the command processing to finish
797 * before resuming sending
798 * priv->needtowakeup will be set to FALSE
801 lbs_deb_cmd("waking up ...\n");
802 lbs_ps_wakeup(priv
, 0);
806 case MACREG_INT_CODE_MIC_ERR_UNICAST
:
807 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
808 handle_mic_failureevent(priv
, MACREG_INT_CODE_MIC_ERR_UNICAST
);
811 case MACREG_INT_CODE_MIC_ERR_MULTICAST
:
812 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
813 handle_mic_failureevent(priv
, MACREG_INT_CODE_MIC_ERR_MULTICAST
);
815 case MACREG_INT_CODE_MIB_CHANGED
:
816 case MACREG_INT_CODE_INIT_DONE
:
819 case MACREG_INT_CODE_ADHOC_BCN_LOST
:
820 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
823 case MACREG_INT_CODE_RSSI_LOW
:
824 lbs_pr_alert("EVENT: rssi low\n");
826 case MACREG_INT_CODE_SNR_LOW
:
827 lbs_pr_alert("EVENT: snr low\n");
829 case MACREG_INT_CODE_MAX_FAIL
:
830 lbs_pr_alert("EVENT: max fail\n");
832 case MACREG_INT_CODE_RSSI_HIGH
:
833 lbs_pr_alert("EVENT: rssi high\n");
835 case MACREG_INT_CODE_SNR_HIGH
:
836 lbs_pr_alert("EVENT: snr high\n");
839 case MACREG_INT_CODE_MESH_AUTO_STARTED
:
840 /* Ignore spurious autostart events if autostart is disabled */
841 if (!priv
->mesh_autostart_enabled
) {
842 lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
845 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
846 priv
->mesh_connect_status
= LBS_CONNECTED
;
847 if (priv
->mesh_open
) {
848 netif_carrier_on(priv
->mesh_dev
);
849 if (!priv
->tx_pending_len
)
850 netif_wake_queue(priv
->mesh_dev
);
852 priv
->mode
= IW_MODE_ADHOC
;
853 schedule_work(&priv
->sync_channel
);
857 lbs_pr_alert("EVENT: unknown event id %d\n", eventcause
);
861 spin_lock_irq(&priv
->driver_lock
);
862 priv
->eventcause
= 0;
863 spin_unlock_irq(&priv
->driver_lock
);
865 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);