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 wlan_private structure
26 void libertas_mac_event_disconnected(wlan_private
* priv
)
28 wlan_adapter
*adapter
= priv
->adapter
;
29 union iwreq_data wrqu
;
31 if (adapter
->connect_status
!= LIBERTAS_CONNECTED
)
34 lbs_deb_enter(LBS_DEB_CMD
);
36 memset(wrqu
.ap_addr
.sa_data
, 0x00, ETH_ALEN
);
37 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
40 * Cisco AP sends EAP failure and de-auth in less than 0.5 ms.
41 * It causes problem in the Supplicant
44 msleep_interruptible(1000);
45 wireless_send_event(priv
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
47 /* Free Tx and Rx packets */
48 kfree_skb(priv
->adapter
->currenttxskb
);
49 priv
->adapter
->currenttxskb
= NULL
;
51 /* report disconnect to upper layer */
52 netif_stop_queue(priv
->dev
);
53 netif_carrier_off(priv
->dev
);
55 /* reset SNR/NF/RSSI values */
56 memset(adapter
->SNR
, 0x00, sizeof(adapter
->SNR
));
57 memset(adapter
->NF
, 0x00, sizeof(adapter
->NF
));
58 memset(adapter
->RSSI
, 0x00, sizeof(adapter
->RSSI
));
59 memset(adapter
->rawSNR
, 0x00, sizeof(adapter
->rawSNR
));
60 memset(adapter
->rawNF
, 0x00, sizeof(adapter
->rawNF
));
61 adapter
->nextSNRNF
= 0;
62 adapter
->numSNRNF
= 0;
63 lbs_deb_cmd("current SSID '%s', length %u\n",
64 escape_essid(adapter
->curbssparams
.ssid
,
65 adapter
->curbssparams
.ssid_len
),
66 adapter
->curbssparams
.ssid_len
);
68 adapter
->connect_status
= LIBERTAS_DISCONNECTED
;
70 /* Clear out associated SSID and BSSID since connection is
73 memset(&adapter
->curbssparams
.bssid
, 0, ETH_ALEN
);
74 memset(&adapter
->curbssparams
.ssid
, 0, IW_ESSID_MAX_SIZE
);
75 adapter
->curbssparams
.ssid_len
= 0;
77 if (adapter
->psstate
!= PS_STATE_FULL_POWER
) {
78 /* make firmware to exit PS mode */
79 lbs_deb_cmd("disconnected, so exit PS mode\n");
80 libertas_ps_wakeup(priv
, 0);
82 lbs_deb_leave(LBS_DEB_CMD
);
86 * @brief This function handles MIC failure event.
88 * @param priv A pointer to wlan_private structure
89 * @para event the event id
92 static void handle_mic_failureevent(wlan_private
* priv
, u32 event
)
96 lbs_deb_enter(LBS_DEB_CMD
);
97 memset(buf
, 0, sizeof(buf
));
99 sprintf(buf
, "%s", "MLME-MICHAELMICFAILURE.indication ");
101 if (event
== MACREG_INT_CODE_MIC_ERR_UNICAST
) {
102 strcat(buf
, "unicast ");
104 strcat(buf
, "multicast ");
107 libertas_send_iwevcustom_event(priv
, buf
);
108 lbs_deb_leave(LBS_DEB_CMD
);
111 static int wlan_ret_reg_access(wlan_private
* priv
,
112 u16 type
, struct cmd_ds_command
*resp
)
115 wlan_adapter
*adapter
= priv
->adapter
;
117 lbs_deb_enter(LBS_DEB_CMD
);
120 case CMD_RET(CMD_MAC_REG_ACCESS
):
122 struct cmd_ds_mac_reg_access
*reg
= &resp
->params
.macreg
;
124 adapter
->offsetvalue
.offset
= (u32
)le16_to_cpu(reg
->offset
);
125 adapter
->offsetvalue
.value
= le32_to_cpu(reg
->value
);
129 case CMD_RET(CMD_BBP_REG_ACCESS
):
131 struct cmd_ds_bbp_reg_access
*reg
= &resp
->params
.bbpreg
;
133 adapter
->offsetvalue
.offset
= (u32
)le16_to_cpu(reg
->offset
);
134 adapter
->offsetvalue
.value
= reg
->value
;
138 case CMD_RET(CMD_RF_REG_ACCESS
):
140 struct cmd_ds_rf_reg_access
*reg
= &resp
->params
.rfreg
;
142 adapter
->offsetvalue
.offset
= (u32
)le16_to_cpu(reg
->offset
);
143 adapter
->offsetvalue
.value
= reg
->value
;
151 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
155 static int wlan_ret_get_hw_spec(wlan_private
* priv
,
156 struct cmd_ds_command
*resp
)
159 struct cmd_ds_get_hw_spec
*hwspec
= &resp
->params
.hwspec
;
160 wlan_adapter
*adapter
= priv
->adapter
;
162 DECLARE_MAC_BUF(mac
);
164 lbs_deb_enter(LBS_DEB_CMD
);
166 adapter
->fwcapinfo
= le32_to_cpu(hwspec
->fwcapinfo
);
168 memcpy(adapter
->fwreleasenumber
, hwspec
->fwreleasenumber
, 4);
170 lbs_deb_cmd("GET_HW_SPEC: firmware release %u.%u.%up%u\n",
171 adapter
->fwreleasenumber
[2], adapter
->fwreleasenumber
[1],
172 adapter
->fwreleasenumber
[0], adapter
->fwreleasenumber
[3]);
173 lbs_deb_cmd("GET_HW_SPEC: MAC addr %s\n",
174 print_mac(mac
, hwspec
->permanentaddr
));
175 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
176 hwspec
->hwifversion
, hwspec
->version
);
178 /* Clamp region code to 8-bit since FW spec indicates that it should
179 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
180 * returns non-zero high 8 bits here.
182 adapter
->regioncode
= le16_to_cpu(hwspec
->regioncode
) & 0xFF;
184 for (i
= 0; i
< MRVDRV_MAX_REGION_CODE
; i
++) {
185 /* use the region code to search for the index */
186 if (adapter
->regioncode
== libertas_region_code_to_index
[i
]) {
191 /* if it's unidentified region code, use the default (USA) */
192 if (i
>= MRVDRV_MAX_REGION_CODE
) {
193 adapter
->regioncode
= 0x10;
194 lbs_pr_info("unidentified region code; using the default (USA)\n");
197 if (adapter
->current_addr
[0] == 0xff)
198 memmove(adapter
->current_addr
, hwspec
->permanentaddr
, ETH_ALEN
);
200 memcpy(priv
->dev
->dev_addr
, adapter
->current_addr
, ETH_ALEN
);
202 memcpy(priv
->mesh_dev
->dev_addr
, adapter
->current_addr
, ETH_ALEN
);
204 if (libertas_set_regiontable(priv
, adapter
->regioncode
, 0)) {
209 if (libertas_set_universaltable(priv
, 0)) {
215 lbs_deb_enter_args(LBS_DEB_CMD
, "ret %d", ret
);
219 static int wlan_ret_802_11_sleep_params(wlan_private
* priv
,
220 struct cmd_ds_command
*resp
)
222 struct cmd_ds_802_11_sleep_params
*sp
= &resp
->params
.sleep_params
;
223 wlan_adapter
*adapter
= priv
->adapter
;
225 lbs_deb_enter(LBS_DEB_CMD
);
227 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, calcontrol 0x%x "
228 "extsleepclk 0x%x\n", le16_to_cpu(sp
->error
),
229 le16_to_cpu(sp
->offset
), le16_to_cpu(sp
->stabletime
),
230 sp
->calcontrol
, sp
->externalsleepclk
);
232 adapter
->sp
.sp_error
= le16_to_cpu(sp
->error
);
233 adapter
->sp
.sp_offset
= le16_to_cpu(sp
->offset
);
234 adapter
->sp
.sp_stabletime
= le16_to_cpu(sp
->stabletime
);
235 adapter
->sp
.sp_calcontrol
= sp
->calcontrol
;
236 adapter
->sp
.sp_extsleepclk
= sp
->externalsleepclk
;
237 adapter
->sp
.sp_reserved
= le16_to_cpu(sp
->reserved
);
239 lbs_deb_enter(LBS_DEB_CMD
);
243 static int wlan_ret_802_11_stat(wlan_private
* priv
,
244 struct cmd_ds_command
*resp
)
246 lbs_deb_enter(LBS_DEB_CMD
);
247 /* currently adapter->wlan802_11Stat is unused
249 struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat;
250 wlan_adapter *adapter = priv->adapter;
252 // TODO Convert it to Big endian befor copy
253 memcpy(&adapter->wlan802_11Stat,
254 p11Stat, sizeof(struct cmd_ds_802_11_get_stat));
256 lbs_deb_leave(LBS_DEB_CMD
);
260 static int wlan_ret_802_11_snmp_mib(wlan_private
* priv
,
261 struct cmd_ds_command
*resp
)
263 struct cmd_ds_802_11_snmp_mib
*smib
= &resp
->params
.smib
;
264 u16 oid
= le16_to_cpu(smib
->oid
);
265 u16 querytype
= le16_to_cpu(smib
->querytype
);
267 lbs_deb_enter(LBS_DEB_CMD
);
269 lbs_deb_cmd("SNMP_RESP: oid 0x%x, querytype 0x%x\n", oid
,
271 lbs_deb_cmd("SNMP_RESP: Buf size %d\n", le16_to_cpu(smib
->bufsize
));
273 if (querytype
== CMD_ACT_GET
) {
276 priv
->adapter
->fragthsd
=
277 le16_to_cpu(*((__le16
*)(smib
->value
)));
278 lbs_deb_cmd("SNMP_RESP: frag threshold %u\n",
279 priv
->adapter
->fragthsd
);
282 priv
->adapter
->rtsthsd
=
283 le16_to_cpu(*((__le16
*)(smib
->value
)));
284 lbs_deb_cmd("SNMP_RESP: rts threshold %u\n",
285 priv
->adapter
->rtsthsd
);
287 case SHORT_RETRYLIM_I
:
288 priv
->adapter
->txretrycount
=
289 le16_to_cpu(*((__le16
*)(smib
->value
)));
290 lbs_deb_cmd("SNMP_RESP: tx retry count %u\n",
291 priv
->adapter
->rtsthsd
);
298 lbs_deb_enter(LBS_DEB_CMD
);
302 static int wlan_ret_802_11_key_material(wlan_private
* priv
,
303 struct cmd_ds_command
*resp
)
305 struct cmd_ds_802_11_key_material
*pkeymaterial
=
306 &resp
->params
.keymaterial
;
307 wlan_adapter
*adapter
= priv
->adapter
;
308 u16 action
= le16_to_cpu(pkeymaterial
->action
);
310 lbs_deb_enter(LBS_DEB_CMD
);
312 /* Copy the returned key to driver private data */
313 if (action
== CMD_ACT_GET
) {
314 u8
* buf_ptr
= (u8
*) &pkeymaterial
->keyParamSet
;
315 u8
* resp_end
= (u8
*) (resp
+ le16_to_cpu(resp
->size
));
317 while (buf_ptr
< resp_end
) {
318 struct MrvlIEtype_keyParamSet
* pkeyparamset
=
319 (struct MrvlIEtype_keyParamSet
*) buf_ptr
;
320 struct enc_key
* pkey
;
321 u16 param_set_len
= le16_to_cpu(pkeyparamset
->length
);
322 u16 key_len
= le16_to_cpu(pkeyparamset
->keylen
);
323 u16 key_flags
= le16_to_cpu(pkeyparamset
->keyinfo
);
324 u16 key_type
= le16_to_cpu(pkeyparamset
->keytypeid
);
327 end
= (u8
*) pkeyparamset
+ sizeof (pkeyparamset
->type
)
328 + sizeof (pkeyparamset
->length
)
330 /* Make sure we don't access past the end of the IEs */
334 if (key_flags
& KEY_INFO_WPA_UNICAST
)
335 pkey
= &adapter
->wpa_unicast_key
;
336 else if (key_flags
& KEY_INFO_WPA_MCAST
)
337 pkey
= &adapter
->wpa_mcast_key
;
341 /* Copy returned key into driver */
342 memset(pkey
, 0, sizeof(struct enc_key
));
343 if (key_len
> sizeof(pkey
->key
))
345 pkey
->type
= key_type
;
346 pkey
->flags
= key_flags
;
348 memcpy(pkey
->key
, pkeyparamset
->key
, pkey
->len
);
354 lbs_deb_enter(LBS_DEB_CMD
);
358 static int wlan_ret_802_11_mac_address(wlan_private
* priv
,
359 struct cmd_ds_command
*resp
)
361 struct cmd_ds_802_11_mac_address
*macadd
= &resp
->params
.macadd
;
362 wlan_adapter
*adapter
= priv
->adapter
;
364 lbs_deb_enter(LBS_DEB_CMD
);
366 memcpy(adapter
->current_addr
, macadd
->macadd
, ETH_ALEN
);
368 lbs_deb_enter(LBS_DEB_CMD
);
372 static int wlan_ret_802_11_rf_tx_power(wlan_private
* priv
,
373 struct cmd_ds_command
*resp
)
375 struct cmd_ds_802_11_rf_tx_power
*rtp
= &resp
->params
.txp
;
376 wlan_adapter
*adapter
= priv
->adapter
;
378 lbs_deb_enter(LBS_DEB_CMD
);
380 adapter
->txpowerlevel
= le16_to_cpu(rtp
->currentlevel
);
382 lbs_deb_cmd("TX power currently %d\n", adapter
->txpowerlevel
);
384 lbs_deb_leave(LBS_DEB_CMD
);
388 static int wlan_ret_802_11_rate_adapt_rateset(wlan_private
* priv
,
389 struct cmd_ds_command
*resp
)
391 struct cmd_ds_802_11_rate_adapt_rateset
*rates
= &resp
->params
.rateset
;
392 wlan_adapter
*adapter
= priv
->adapter
;
394 lbs_deb_enter(LBS_DEB_CMD
);
396 if (rates
->action
== CMD_ACT_GET
) {
397 adapter
->enablehwauto
= le16_to_cpu(rates
->enablehwauto
);
398 adapter
->ratebitmap
= le16_to_cpu(rates
->bitmap
);
401 lbs_deb_leave(LBS_DEB_CMD
);
405 static int wlan_ret_802_11_data_rate(wlan_private
* priv
,
406 struct cmd_ds_command
*resp
)
408 struct cmd_ds_802_11_data_rate
*pdatarate
= &resp
->params
.drate
;
409 wlan_adapter
*adapter
= priv
->adapter
;
411 lbs_deb_enter(LBS_DEB_CMD
);
413 lbs_deb_hex(LBS_DEB_CMD
, "DATA_RATE_RESP", (u8
*) pdatarate
,
414 sizeof(struct cmd_ds_802_11_data_rate
));
416 /* FIXME: get actual rates FW can do if this command actually returns
417 * all data rates supported.
419 adapter
->cur_rate
= libertas_fw_index_to_data_rate(pdatarate
->rates
[0]);
420 lbs_deb_cmd("DATA_RATE: current rate 0x%02x\n", adapter
->cur_rate
);
422 lbs_deb_leave(LBS_DEB_CMD
);
426 static int wlan_ret_802_11_rf_channel(wlan_private
* priv
,
427 struct cmd_ds_command
*resp
)
429 struct cmd_ds_802_11_rf_channel
*rfchannel
= &resp
->params
.rfchannel
;
430 wlan_adapter
*adapter
= priv
->adapter
;
431 u16 action
= le16_to_cpu(rfchannel
->action
);
432 u16 newchannel
= le16_to_cpu(rfchannel
->currentchannel
);
434 lbs_deb_enter(LBS_DEB_CMD
);
436 if (action
== CMD_OPT_802_11_RF_CHANNEL_GET
437 && adapter
->curbssparams
.channel
!= newchannel
) {
438 lbs_deb_cmd("channel switch from %d to %d\n",
439 adapter
->curbssparams
.channel
, newchannel
);
441 /* Update the channel again */
442 adapter
->curbssparams
.channel
= newchannel
;
445 lbs_deb_enter(LBS_DEB_CMD
);
449 static int wlan_ret_802_11_rssi(wlan_private
* priv
,
450 struct cmd_ds_command
*resp
)
452 struct cmd_ds_802_11_rssi_rsp
*rssirsp
= &resp
->params
.rssirsp
;
453 wlan_adapter
*adapter
= priv
->adapter
;
455 lbs_deb_enter(LBS_DEB_CMD
);
457 /* store the non average value */
458 adapter
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = le16_to_cpu(rssirsp
->SNR
);
459 adapter
->NF
[TYPE_BEACON
][TYPE_NOAVG
] = le16_to_cpu(rssirsp
->noisefloor
);
461 adapter
->SNR
[TYPE_BEACON
][TYPE_AVG
] = le16_to_cpu(rssirsp
->avgSNR
);
462 adapter
->NF
[TYPE_BEACON
][TYPE_AVG
] = le16_to_cpu(rssirsp
->avgnoisefloor
);
464 adapter
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] =
465 CAL_RSSI(adapter
->SNR
[TYPE_BEACON
][TYPE_NOAVG
],
466 adapter
->NF
[TYPE_BEACON
][TYPE_NOAVG
]);
468 adapter
->RSSI
[TYPE_BEACON
][TYPE_AVG
] =
469 CAL_RSSI(adapter
->SNR
[TYPE_BEACON
][TYPE_AVG
] / AVG_SCALE
,
470 adapter
->NF
[TYPE_BEACON
][TYPE_AVG
] / AVG_SCALE
);
472 lbs_deb_cmd("RSSI: beacon %d, avg %d\n",
473 adapter
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
],
474 adapter
->RSSI
[TYPE_BEACON
][TYPE_AVG
]);
476 lbs_deb_leave(LBS_DEB_CMD
);
480 static int wlan_ret_802_11_eeprom_access(wlan_private
* priv
,
481 struct cmd_ds_command
*resp
)
483 wlan_adapter
*adapter
= priv
->adapter
;
484 struct wlan_ioctl_regrdwr
*pbuf
;
485 pbuf
= (struct wlan_ioctl_regrdwr
*) adapter
->prdeeprom
;
487 lbs_deb_enter_args(LBS_DEB_CMD
, "len %d",
488 le16_to_cpu(resp
->params
.rdeeprom
.bytecount
));
489 if (pbuf
->NOB
< le16_to_cpu(resp
->params
.rdeeprom
.bytecount
)) {
491 lbs_deb_cmd("EEPROM read length too big\n");
494 pbuf
->NOB
= le16_to_cpu(resp
->params
.rdeeprom
.bytecount
);
497 memcpy(&pbuf
->value
, (u8
*) & resp
->params
.rdeeprom
.value
,
498 le16_to_cpu(resp
->params
.rdeeprom
.bytecount
));
499 lbs_deb_hex(LBS_DEB_CMD
, "EEPROM", (char *)&pbuf
->value
,
500 le16_to_cpu(resp
->params
.rdeeprom
.bytecount
));
502 lbs_deb_leave(LBS_DEB_CMD
);
506 static int wlan_ret_get_log(wlan_private
* priv
,
507 struct cmd_ds_command
*resp
)
509 struct cmd_ds_802_11_get_log
*logmessage
= &resp
->params
.glog
;
510 wlan_adapter
*adapter
= priv
->adapter
;
512 lbs_deb_enter(LBS_DEB_CMD
);
514 /* Stored little-endian */
515 memcpy(&adapter
->logmsg
, logmessage
, sizeof(struct cmd_ds_802_11_get_log
));
517 lbs_deb_leave(LBS_DEB_CMD
);
521 static int libertas_ret_802_11_enable_rsn(wlan_private
* priv
,
522 struct cmd_ds_command
*resp
)
524 struct cmd_ds_802_11_enable_rsn
*enable_rsn
= &resp
->params
.enbrsn
;
525 wlan_adapter
*adapter
= priv
->adapter
;
526 u32
* pdata_buf
= adapter
->cur_cmd
->pdata_buf
;
528 lbs_deb_enter(LBS_DEB_CMD
);
530 if (enable_rsn
->action
== cpu_to_le16(CMD_ACT_GET
)) {
532 *pdata_buf
= (u32
) le16_to_cpu(enable_rsn
->enable
);
535 lbs_deb_leave(LBS_DEB_CMD
);
539 static inline int handle_cmd_response(u16 respcmd
,
540 struct cmd_ds_command
*resp
,
545 wlan_adapter
*adapter
= priv
->adapter
;
547 lbs_deb_enter(LBS_DEB_HOST
);
550 case CMD_RET(CMD_MAC_REG_ACCESS
):
551 case CMD_RET(CMD_BBP_REG_ACCESS
):
552 case CMD_RET(CMD_RF_REG_ACCESS
):
553 ret
= wlan_ret_reg_access(priv
, respcmd
, resp
);
556 case CMD_RET(CMD_GET_HW_SPEC
):
557 ret
= wlan_ret_get_hw_spec(priv
, resp
);
560 case CMD_RET(CMD_802_11_SCAN
):
561 ret
= libertas_ret_80211_scan(priv
, resp
);
564 case CMD_RET(CMD_802_11_GET_LOG
):
565 ret
= wlan_ret_get_log(priv
, resp
);
568 case CMD_RET_802_11_ASSOCIATE
:
569 case CMD_RET(CMD_802_11_ASSOCIATE
):
570 case CMD_RET(CMD_802_11_REASSOCIATE
):
571 ret
= libertas_ret_80211_associate(priv
, resp
);
574 case CMD_RET(CMD_802_11_DISASSOCIATE
):
575 case CMD_RET(CMD_802_11_DEAUTHENTICATE
):
576 ret
= libertas_ret_80211_disassociate(priv
, resp
);
579 case CMD_RET(CMD_802_11_AD_HOC_START
):
580 case CMD_RET(CMD_802_11_AD_HOC_JOIN
):
581 ret
= libertas_ret_80211_ad_hoc_start(priv
, resp
);
584 case CMD_RET(CMD_802_11_GET_STAT
):
585 ret
= wlan_ret_802_11_stat(priv
, resp
);
588 case CMD_RET(CMD_802_11_SNMP_MIB
):
589 ret
= wlan_ret_802_11_snmp_mib(priv
, resp
);
592 case CMD_RET(CMD_802_11_RF_TX_POWER
):
593 ret
= wlan_ret_802_11_rf_tx_power(priv
, resp
);
596 case CMD_RET(CMD_802_11_SET_AFC
):
597 case CMD_RET(CMD_802_11_GET_AFC
):
598 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
599 memmove(adapter
->cur_cmd
->pdata_buf
, &resp
->params
.afc
,
600 sizeof(struct cmd_ds_802_11_afc
));
601 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
605 case CMD_RET(CMD_MAC_MULTICAST_ADR
):
606 case CMD_RET(CMD_MAC_CONTROL
):
607 case CMD_RET(CMD_802_11_SET_WEP
):
608 case CMD_RET(CMD_802_11_RESET
):
609 case CMD_RET(CMD_802_11_AUTHENTICATE
):
610 case CMD_RET(CMD_802_11_RADIO_CONTROL
):
611 case CMD_RET(CMD_802_11_BEACON_STOP
):
614 case CMD_RET(CMD_802_11_ENABLE_RSN
):
615 ret
= libertas_ret_802_11_enable_rsn(priv
, resp
);
618 case CMD_RET(CMD_802_11_DATA_RATE
):
619 ret
= wlan_ret_802_11_data_rate(priv
, resp
);
621 case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET
):
622 ret
= wlan_ret_802_11_rate_adapt_rateset(priv
, resp
);
624 case CMD_RET(CMD_802_11_RF_CHANNEL
):
625 ret
= wlan_ret_802_11_rf_channel(priv
, resp
);
628 case CMD_RET(CMD_802_11_RSSI
):
629 ret
= wlan_ret_802_11_rssi(priv
, resp
);
632 case CMD_RET(CMD_802_11_MAC_ADDRESS
):
633 ret
= wlan_ret_802_11_mac_address(priv
, resp
);
636 case CMD_RET(CMD_802_11_AD_HOC_STOP
):
637 ret
= libertas_ret_80211_ad_hoc_stop(priv
, resp
);
640 case CMD_RET(CMD_802_11_KEY_MATERIAL
):
641 ret
= wlan_ret_802_11_key_material(priv
, resp
);
644 case CMD_RET(CMD_802_11_EEPROM_ACCESS
):
645 ret
= wlan_ret_802_11_eeprom_access(priv
, resp
);
648 case CMD_RET(CMD_802_11D_DOMAIN_INFO
):
649 ret
= libertas_ret_802_11d_domain_info(priv
, resp
);
652 case CMD_RET(CMD_802_11_SLEEP_PARAMS
):
653 ret
= wlan_ret_802_11_sleep_params(priv
, resp
);
655 case CMD_RET(CMD_802_11_INACTIVITY_TIMEOUT
):
656 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
657 *((u16
*) adapter
->cur_cmd
->pdata_buf
) =
658 le16_to_cpu(resp
->params
.inactivity_timeout
.timeout
);
659 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
662 case CMD_RET(CMD_802_11_TPC_CFG
):
663 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
664 memmove(adapter
->cur_cmd
->pdata_buf
, &resp
->params
.tpccfg
,
665 sizeof(struct cmd_ds_802_11_tpc_cfg
));
666 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
668 case CMD_RET(CMD_802_11_LED_GPIO_CTRL
):
669 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
670 memmove(adapter
->cur_cmd
->pdata_buf
, &resp
->params
.ledgpio
,
671 sizeof(struct cmd_ds_802_11_led_ctrl
));
672 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
674 case CMD_RET(CMD_802_11_PWR_CFG
):
675 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
676 memmove(adapter
->cur_cmd
->pdata_buf
, &resp
->params
.pwrcfg
,
677 sizeof(struct cmd_ds_802_11_pwr_cfg
));
678 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
682 case CMD_RET(CMD_GET_TSF
):
683 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
684 memcpy(priv
->adapter
->cur_cmd
->pdata_buf
,
685 &resp
->params
.gettsf
.tsfvalue
, sizeof(u64
));
686 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
688 case CMD_RET(CMD_BT_ACCESS
):
689 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
690 if (adapter
->cur_cmd
->pdata_buf
)
691 memcpy(adapter
->cur_cmd
->pdata_buf
,
692 &resp
->params
.bt
.addr1
, 2 * ETH_ALEN
);
693 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
695 case CMD_RET(CMD_FWT_ACCESS
):
696 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
697 if (adapter
->cur_cmd
->pdata_buf
)
698 memcpy(adapter
->cur_cmd
->pdata_buf
, &resp
->params
.fwt
,
699 sizeof(resp
->params
.fwt
));
700 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
702 case CMD_RET(CMD_MESH_ACCESS
):
703 if (adapter
->cur_cmd
->pdata_buf
)
704 memcpy(adapter
->cur_cmd
->pdata_buf
, &resp
->params
.mesh
,
705 sizeof(resp
->params
.mesh
));
708 lbs_deb_host("CMD_RESP: unknown cmd response 0x%04x\n",
712 lbs_deb_leave(LBS_DEB_HOST
);
716 int libertas_process_rx_command(wlan_private
* priv
)
719 struct cmd_ds_command
*resp
;
720 wlan_adapter
*adapter
= priv
->adapter
;
725 lbs_deb_enter(LBS_DEB_HOST
);
727 /* Now we got response from FW, cancel the command timer */
728 del_timer(&adapter
->command_timer
);
730 mutex_lock(&adapter
->lock
);
731 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
733 if (!adapter
->cur_cmd
) {
734 lbs_deb_host("CMD_RESP: cur_cmd is NULL\n");
736 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
739 resp
= (struct cmd_ds_command
*)(adapter
->cur_cmd
->bufvirtualaddr
);
741 respcmd
= le16_to_cpu(resp
->command
);
742 result
= le16_to_cpu(resp
->result
);
744 lbs_deb_host("CMD_RESP: response 0x%04x, size %d, jiffies %lu\n",
745 respcmd
, priv
->upld_len
, jiffies
);
746 lbs_deb_hex(LBS_DEB_HOST
, "CMD_RESP", adapter
->cur_cmd
->bufvirtualaddr
,
749 if (!(respcmd
& 0x8000)) {
750 lbs_deb_host("invalid response!\n");
751 adapter
->cur_cmd_retcode
= -1;
752 __libertas_cleanup_and_insert_cmd(priv
, adapter
->cur_cmd
);
753 adapter
->nr_cmd_pending
--;
754 adapter
->cur_cmd
= NULL
;
755 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
760 /* Store the response code to cur_cmd_retcode. */
761 adapter
->cur_cmd_retcode
= result
;;
763 if (respcmd
== CMD_RET(CMD_802_11_PS_MODE
)) {
764 struct cmd_ds_802_11_ps_mode
*psmode
= &resp
->params
.psmode
;
765 u16 action
= le16_to_cpu(psmode
->action
);
768 "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n",
772 lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n",
775 * We should not re-try enter-ps command in
776 * ad-hoc mode. It takes place in
777 * libertas_execute_next_command().
779 if (adapter
->mode
== IW_MODE_ADHOC
&&
780 action
== CMD_SUBCMD_ENTER_PS
)
781 adapter
->psmode
= WLAN802_11POWERMODECAM
;
782 } else if (action
== CMD_SUBCMD_ENTER_PS
) {
783 adapter
->needtowakeup
= 0;
784 adapter
->psstate
= PS_STATE_AWAKE
;
786 lbs_deb_host("CMD_RESP: ENTER_PS command response\n");
787 if (adapter
->connect_status
!= LIBERTAS_CONNECTED
) {
789 * When Deauth Event received before Enter_PS command
790 * response, We need to wake up the firmware.
793 "disconnected, invoking libertas_ps_wakeup\n");
795 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
796 mutex_unlock(&adapter
->lock
);
797 libertas_ps_wakeup(priv
, 0);
798 mutex_lock(&adapter
->lock
);
799 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
801 } else if (action
== CMD_SUBCMD_EXIT_PS
) {
802 adapter
->needtowakeup
= 0;
803 adapter
->psstate
= PS_STATE_FULL_POWER
;
804 lbs_deb_host("CMD_RESP: EXIT_PS command response\n");
806 lbs_deb_host("CMD_RESP: PS action 0x%X\n", action
);
809 __libertas_cleanup_and_insert_cmd(priv
, adapter
->cur_cmd
);
810 adapter
->nr_cmd_pending
--;
811 adapter
->cur_cmd
= NULL
;
812 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
818 if (adapter
->cur_cmd
->cmdflags
& CMD_F_HOSTCMD
) {
819 /* Copy the response back to response buffer */
820 memcpy(adapter
->cur_cmd
->pdata_buf
, resp
,
821 le16_to_cpu(resp
->size
));
822 adapter
->cur_cmd
->cmdflags
&= ~CMD_F_HOSTCMD
;
825 /* If the command is not successful, cleanup and return failure */
826 if ((result
!= 0 || !(respcmd
& 0x8000))) {
827 lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n",
830 * Handling errors here
833 case CMD_RET(CMD_GET_HW_SPEC
):
834 case CMD_RET(CMD_802_11_RESET
):
835 lbs_deb_host("CMD_RESP: reset failed\n");
840 __libertas_cleanup_and_insert_cmd(priv
, adapter
->cur_cmd
);
841 adapter
->nr_cmd_pending
--;
842 adapter
->cur_cmd
= NULL
;
843 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
849 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
851 ret
= handle_cmd_response(respcmd
, resp
, priv
);
853 spin_lock_irqsave(&adapter
->driver_lock
, flags
);
854 if (adapter
->cur_cmd
) {
855 /* Clean up and Put current command back to cmdfreeq */
856 __libertas_cleanup_and_insert_cmd(priv
, adapter
->cur_cmd
);
857 adapter
->nr_cmd_pending
--;
858 WARN_ON(adapter
->nr_cmd_pending
> 128);
859 adapter
->cur_cmd
= NULL
;
861 spin_unlock_irqrestore(&adapter
->driver_lock
, flags
);
864 mutex_unlock(&adapter
->lock
);
865 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
869 int libertas_process_event(wlan_private
* priv
)
872 wlan_adapter
*adapter
= priv
->adapter
;
875 lbs_deb_enter(LBS_DEB_CMD
);
877 spin_lock_irq(&adapter
->driver_lock
);
878 eventcause
= adapter
->eventcause
;
879 spin_unlock_irq(&adapter
->driver_lock
);
881 lbs_deb_cmd("event cause 0x%x\n", eventcause
);
883 switch (eventcause
>> SBI_EVENT_CAUSE_SHIFT
) {
884 case MACREG_INT_CODE_LINK_SENSED
:
885 lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n");
888 case MACREG_INT_CODE_DEAUTHENTICATED
:
889 lbs_deb_cmd("EVENT: deauthenticated\n");
890 libertas_mac_event_disconnected(priv
);
893 case MACREG_INT_CODE_DISASSOCIATED
:
894 lbs_deb_cmd("EVENT: disassociated\n");
895 libertas_mac_event_disconnected(priv
);
898 case MACREG_INT_CODE_LINK_LOSE_NO_SCAN
:
899 lbs_deb_cmd("EVENT: link lost\n");
900 libertas_mac_event_disconnected(priv
);
903 case MACREG_INT_CODE_PS_SLEEP
:
904 lbs_deb_cmd("EVENT: sleep\n");
906 /* handle unexpected PS SLEEP event */
907 if (adapter
->psstate
== PS_STATE_FULL_POWER
) {
909 "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n");
912 adapter
->psstate
= PS_STATE_PRE_SLEEP
;
914 libertas_ps_confirm_sleep(priv
, (u16
) adapter
->psmode
);
918 case MACREG_INT_CODE_PS_AWAKE
:
919 lbs_deb_cmd("EVENT: awake\n");
921 /* handle unexpected PS AWAKE event */
922 if (adapter
->psstate
== PS_STATE_FULL_POWER
) {
924 "EVENT: In FULL POWER mode - ignore PS AWAKE\n");
928 adapter
->psstate
= PS_STATE_AWAKE
;
930 if (adapter
->needtowakeup
) {
932 * wait for the command processing to finish
933 * before resuming sending
934 * adapter->needtowakeup will be set to FALSE
935 * in libertas_ps_wakeup()
937 lbs_deb_cmd("waking up ...\n");
938 libertas_ps_wakeup(priv
, 0);
942 case MACREG_INT_CODE_MIC_ERR_UNICAST
:
943 lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n");
944 handle_mic_failureevent(priv
, MACREG_INT_CODE_MIC_ERR_UNICAST
);
947 case MACREG_INT_CODE_MIC_ERR_MULTICAST
:
948 lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n");
949 handle_mic_failureevent(priv
, MACREG_INT_CODE_MIC_ERR_MULTICAST
);
951 case MACREG_INT_CODE_MIB_CHANGED
:
952 case MACREG_INT_CODE_INIT_DONE
:
955 case MACREG_INT_CODE_ADHOC_BCN_LOST
:
956 lbs_deb_cmd("EVENT: ADHOC beacon lost\n");
959 case MACREG_INT_CODE_RSSI_LOW
:
960 lbs_pr_alert("EVENT: rssi low\n");
962 case MACREG_INT_CODE_SNR_LOW
:
963 lbs_pr_alert("EVENT: snr low\n");
965 case MACREG_INT_CODE_MAX_FAIL
:
966 lbs_pr_alert("EVENT: max fail\n");
968 case MACREG_INT_CODE_RSSI_HIGH
:
969 lbs_pr_alert("EVENT: rssi high\n");
971 case MACREG_INT_CODE_SNR_HIGH
:
972 lbs_pr_alert("EVENT: snr high\n");
975 case MACREG_INT_CODE_MESH_AUTO_STARTED
:
976 /* Ignore spurious autostart events if autostart is disabled */
977 if (!priv
->mesh_autostart_enabled
) {
978 lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n");
981 lbs_pr_info("EVENT: MESH_AUTO_STARTED\n");
982 adapter
->connect_status
= LIBERTAS_CONNECTED
;
983 if (priv
->mesh_open
== 1) {
984 netif_wake_queue(priv
->mesh_dev
);
985 netif_carrier_on(priv
->mesh_dev
);
987 adapter
->mode
= IW_MODE_ADHOC
;
988 schedule_work(&priv
->sync_channel
);
992 lbs_pr_alert("EVENT: unknown event id 0x%04x\n",
993 eventcause
>> SBI_EVENT_CAUSE_SHIFT
);
997 spin_lock_irq(&adapter
->driver_lock
);
998 adapter
->eventcause
= 0;
999 spin_unlock_irq(&adapter
->driver_lock
);
1001 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);