Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 2 | * This file contains the handling of command |
| 3 | * responses as well as events generated by firmware. |
| 4 | */ |
| 5 | #include <linux/delay.h> |
| 6 | #include <linux/if_arp.h> |
| 7 | #include <linux/netdevice.h> |
| 8 | |
| 9 | #include <net/iw_handler.h> |
| 10 | |
| 11 | #include "host.h" |
| 12 | #include "sbi.h" |
| 13 | #include "decl.h" |
| 14 | #include "defs.h" |
| 15 | #include "dev.h" |
| 16 | #include "join.h" |
| 17 | #include "wext.h" |
| 18 | |
| 19 | /** |
| 20 | * @brief This function handles disconnect event. it |
| 21 | * reports disconnect to upper layer, clean tx/rx packets, |
| 22 | * reset link state etc. |
| 23 | * |
| 24 | * @param priv A pointer to wlan_private structure |
| 25 | * @return n/a |
| 26 | */ |
| 27 | void libertas_mac_event_disconnected(wlan_private * priv) |
| 28 | { |
| 29 | wlan_adapter *adapter = priv->adapter; |
| 30 | union iwreq_data wrqu; |
| 31 | |
| 32 | if (adapter->connect_status != libertas_connected) |
| 33 | return; |
| 34 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 35 | lbs_deb_cmd("Handles disconnect event.\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 36 | |
| 37 | memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN); |
| 38 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 39 | |
| 40 | /* |
| 41 | * Cisco AP sends EAP failure and de-auth in less than 0.5 ms. |
| 42 | * It causes problem in the Supplicant |
| 43 | */ |
| 44 | |
| 45 | msleep_interruptible(1000); |
| 46 | wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL); |
| 47 | |
| 48 | /* Free Tx and Rx packets */ |
| 49 | kfree_skb(priv->adapter->currenttxskb); |
| 50 | priv->adapter->currenttxskb = NULL; |
| 51 | |
| 52 | /* report disconnect to upper layer */ |
| 53 | netif_stop_queue(priv->wlan_dev.netdev); |
| 54 | netif_carrier_off(priv->wlan_dev.netdev); |
| 55 | |
| 56 | /* reset SNR/NF/RSSI values */ |
| 57 | memset(adapter->SNR, 0x00, sizeof(adapter->SNR)); |
| 58 | memset(adapter->NF, 0x00, sizeof(adapter->NF)); |
| 59 | memset(adapter->RSSI, 0x00, sizeof(adapter->RSSI)); |
| 60 | memset(adapter->rawSNR, 0x00, sizeof(adapter->rawSNR)); |
| 61 | memset(adapter->rawNF, 0x00, sizeof(adapter->rawNF)); |
| 62 | adapter->nextSNRNF = 0; |
| 63 | adapter->numSNRNF = 0; |
| 64 | adapter->rxpd_rate = 0; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 65 | lbs_deb_cmd("Current SSID=%s, ssid length=%u\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 66 | adapter->curbssparams.ssid.ssid, |
| 67 | adapter->curbssparams.ssid.ssidlength); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 68 | lbs_deb_cmd("Previous SSID=%s, ssid length=%u\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 69 | adapter->previousssid.ssid, adapter->previousssid.ssidlength); |
| 70 | |
| 71 | /* reset internal flags */ |
| 72 | adapter->secinfo.WPAenabled = 0; |
| 73 | adapter->secinfo.WPA2enabled = 0; |
| 74 | adapter->wpa_ie_len = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 75 | |
| 76 | adapter->connect_status = libertas_disconnected; |
| 77 | |
| 78 | /* |
| 79 | * memorize the previous SSID and BSSID |
| 80 | * it could be used for re-assoc |
| 81 | */ |
| 82 | memcpy(&adapter->previousssid, |
| 83 | &adapter->curbssparams.ssid, sizeof(struct WLAN_802_11_SSID)); |
| 84 | memcpy(adapter->previousbssid, |
| 85 | adapter->curbssparams.bssid, ETH_ALEN); |
| 86 | |
| 87 | /* need to erase the current SSID and BSSID info */ |
| 88 | adapter->pattemptedbssdesc = NULL; |
| 89 | memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams)); |
| 90 | |
| 91 | if (adapter->psstate != PS_STATE_FULL_POWER) { |
| 92 | /* make firmware to exit PS mode */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 93 | lbs_deb_cmd("Disconnected, so exit PS mode.\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 94 | libertas_ps_wakeup(priv, 0); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @brief This function handles MIC failure event. |
| 100 | * |
| 101 | * @param priv A pointer to wlan_private structure |
| 102 | * @para event the event id |
| 103 | * @return n/a |
| 104 | */ |
| 105 | static void handle_mic_failureevent(wlan_private * priv, u32 event) |
| 106 | { |
| 107 | char buf[50]; |
| 108 | |
| 109 | memset(buf, 0, sizeof(buf)); |
| 110 | |
| 111 | sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication "); |
| 112 | |
| 113 | if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) { |
| 114 | strcat(buf, "unicast "); |
| 115 | } else { |
| 116 | strcat(buf, "multicast "); |
| 117 | } |
| 118 | |
| 119 | libertas_send_iwevcustom_event(priv, buf); |
| 120 | } |
| 121 | |
| 122 | static int wlan_ret_reg_access(wlan_private * priv, |
| 123 | u16 type, struct cmd_ds_command *resp) |
| 124 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 125 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 126 | wlan_adapter *adapter = priv->adapter; |
| 127 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 128 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 129 | |
| 130 | switch (type) { |
| 131 | case cmd_ret_mac_reg_access: |
| 132 | { |
| 133 | struct cmd_ds_mac_reg_access *reg; |
| 134 | |
| 135 | reg = |
| 136 | (struct cmd_ds_mac_reg_access *)&resp->params. |
| 137 | macreg; |
| 138 | |
| 139 | adapter->offsetvalue.offset = reg->offset; |
| 140 | adapter->offsetvalue.value = reg->value; |
| 141 | break; |
| 142 | } |
| 143 | |
| 144 | case cmd_ret_bbp_reg_access: |
| 145 | { |
| 146 | struct cmd_ds_bbp_reg_access *reg; |
| 147 | reg = |
| 148 | (struct cmd_ds_bbp_reg_access *)&resp->params. |
| 149 | bbpreg; |
| 150 | |
| 151 | adapter->offsetvalue.offset = reg->offset; |
| 152 | adapter->offsetvalue.value = reg->value; |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | case cmd_ret_rf_reg_access: |
| 157 | { |
| 158 | struct cmd_ds_rf_reg_access *reg; |
| 159 | reg = |
| 160 | (struct cmd_ds_rf_reg_access *)&resp->params. |
| 161 | rfreg; |
| 162 | |
| 163 | adapter->offsetvalue.offset = reg->offset; |
| 164 | adapter->offsetvalue.value = reg->value; |
| 165 | break; |
| 166 | } |
| 167 | |
| 168 | default: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 169 | ret = -1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 170 | } |
| 171 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 172 | lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret); |
| 173 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static int wlan_ret_get_hw_spec(wlan_private * priv, |
| 177 | struct cmd_ds_command *resp) |
| 178 | { |
| 179 | u32 i; |
| 180 | struct cmd_ds_get_hw_spec *hwspec = &resp->params.hwspec; |
| 181 | wlan_adapter *adapter = priv->adapter; |
| 182 | int ret = 0; |
| 183 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 184 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 185 | |
| 186 | adapter->fwcapinfo = le32_to_cpu(hwspec->fwcapinfo); |
| 187 | |
| 188 | adapter->fwreleasenumber = hwspec->fwreleasenumber; |
| 189 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 190 | lbs_deb_cmd("GET_HW_SPEC: FWReleaseVersion- 0x%X\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 191 | adapter->fwreleasenumber); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 192 | lbs_deb_cmd("GET_HW_SPEC: Permanent addr- %2x:%2x:%2x:%2x:%2x:%2x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 193 | hwspec->permanentaddr[0], hwspec->permanentaddr[1], |
| 194 | hwspec->permanentaddr[2], hwspec->permanentaddr[3], |
| 195 | hwspec->permanentaddr[4], hwspec->permanentaddr[5]); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 196 | lbs_deb_cmd("GET_HW_SPEC: hwifversion=0x%X version=0x%X\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 197 | hwspec->hwifversion, hwspec->version); |
| 198 | |
| 199 | adapter->regioncode = le16_to_cpu(hwspec->regioncode); |
| 200 | |
| 201 | for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) { |
| 202 | /* use the region code to search for the index */ |
| 203 | if (adapter->regioncode == libertas_region_code_to_index[i]) { |
| 204 | adapter->regiontableindex = (u16) i; |
| 205 | break; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /* if it's unidentified region code, use the default (USA) */ |
| 210 | if (i >= MRVDRV_MAX_REGION_CODE) { |
| 211 | adapter->regioncode = 0x10; |
| 212 | adapter->regiontableindex = 0; |
| 213 | lbs_pr_info( |
| 214 | "unidentified region code, use the default (USA)\n"); |
| 215 | } |
| 216 | |
| 217 | if (adapter->current_addr[0] == 0xff) { |
| 218 | memmove(adapter->current_addr, hwspec->permanentaddr, |
| 219 | ETH_ALEN); |
| 220 | } |
| 221 | |
| 222 | memcpy(priv->wlan_dev.netdev->dev_addr, adapter->current_addr, ETH_ALEN); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame^] | 223 | if (priv->mesh_dev) |
| 224 | memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, |
| 225 | ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 226 | |
| 227 | if (libertas_set_regiontable(priv, adapter->regioncode, 0)) { |
| 228 | ret = -1; |
| 229 | goto done; |
| 230 | } |
| 231 | |
| 232 | if (libertas_set_universaltable(priv, 0)) { |
| 233 | ret = -1; |
| 234 | goto done; |
| 235 | } |
| 236 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 237 | done: |
| 238 | lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 239 | return ret; |
| 240 | } |
| 241 | |
| 242 | static int wlan_ret_802_11_sleep_params(wlan_private * priv, |
| 243 | struct cmd_ds_command *resp) |
| 244 | { |
| 245 | struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params; |
| 246 | wlan_adapter *adapter = priv->adapter; |
| 247 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 248 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 249 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 250 | lbs_deb_cmd("error=%x offset=%x stabletime=%x calcontrol=%x\n" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 251 | " extsleepclk=%x\n", sp->error, sp->offset, |
| 252 | sp->stabletime, sp->calcontrol, sp->externalsleepclk); |
| 253 | adapter->sp.sp_error = le16_to_cpu(sp->error); |
| 254 | adapter->sp.sp_offset = le16_to_cpu(sp->offset); |
| 255 | adapter->sp.sp_stabletime = le16_to_cpu(sp->stabletime); |
| 256 | adapter->sp.sp_calcontrol = le16_to_cpu(sp->calcontrol); |
| 257 | adapter->sp.sp_extsleepclk = le16_to_cpu(sp->externalsleepclk); |
| 258 | adapter->sp.sp_reserved = le16_to_cpu(sp->reserved); |
| 259 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 260 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | static int wlan_ret_802_11_stat(wlan_private * priv, |
| 265 | struct cmd_ds_command *resp) |
| 266 | { |
| 267 | /* currently adapter->wlan802_11Stat is unused |
| 268 | |
| 269 | struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat; |
| 270 | wlan_adapter *adapter = priv->adapter; |
| 271 | |
| 272 | // TODO Convert it to Big endian befor copy |
| 273 | memcpy(&adapter->wlan802_11Stat, |
| 274 | p11Stat, sizeof(struct cmd_ds_802_11_get_stat)); |
| 275 | */ |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static int wlan_ret_802_11_snmp_mib(wlan_private * priv, |
| 280 | struct cmd_ds_command *resp) |
| 281 | { |
| 282 | struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib; |
| 283 | u16 oid = le16_to_cpu(smib->oid); |
| 284 | u16 querytype = le16_to_cpu(smib->querytype); |
| 285 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 286 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 287 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 288 | lbs_deb_cmd("SNMP_RESP: value of the oid = %x, querytype=%x\n", oid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 289 | querytype); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 290 | lbs_deb_cmd("SNMP_RESP: Buf size = %x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 291 | le16_to_cpu(smib->bufsize)); |
| 292 | |
| 293 | if (querytype == cmd_act_get) { |
| 294 | switch (oid) { |
| 295 | case fragthresh_i: |
| 296 | priv->adapter->fragthsd = |
| 297 | le16_to_cpu(* |
| 298 | ((unsigned short *)(smib->value))); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 299 | lbs_deb_cmd("SNMP_RESP: fragthsd =%u\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 300 | priv->adapter->fragthsd); |
| 301 | break; |
| 302 | case rtsthresh_i: |
| 303 | priv->adapter->rtsthsd = |
| 304 | le16_to_cpu(* |
| 305 | ((unsigned short *)(smib->value))); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 306 | lbs_deb_cmd("SNMP_RESP: rtsthsd =%u\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 307 | priv->adapter->rtsthsd); |
| 308 | break; |
| 309 | case short_retrylim_i: |
| 310 | priv->adapter->txretrycount = |
| 311 | le16_to_cpu(* |
| 312 | ((unsigned short *)(smib->value))); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 313 | lbs_deb_cmd("SNMP_RESP: txretrycount =%u\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 314 | priv->adapter->rtsthsd); |
| 315 | break; |
| 316 | default: |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 321 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | static int wlan_ret_802_11_key_material(wlan_private * priv, |
| 326 | struct cmd_ds_command *resp) |
| 327 | { |
| 328 | struct cmd_ds_802_11_key_material *pkeymaterial = |
| 329 | &resp->params.keymaterial; |
| 330 | wlan_adapter *adapter = priv->adapter; |
| 331 | u16 action = le16_to_cpu(pkeymaterial->action); |
| 332 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 333 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 334 | |
| 335 | /* Copy the returned key to driver private data */ |
| 336 | if (action == cmd_act_get) { |
| 337 | u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet; |
| 338 | u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size)); |
| 339 | |
| 340 | while (buf_ptr < resp_end) { |
| 341 | struct MrvlIEtype_keyParamSet * pkeyparamset = |
| 342 | (struct MrvlIEtype_keyParamSet *) buf_ptr; |
| 343 | struct WLAN_802_11_KEY * pkey; |
| 344 | u16 key_info = le16_to_cpu(pkeyparamset->keyinfo); |
| 345 | u16 param_set_len = le16_to_cpu(pkeyparamset->length); |
| 346 | u8 * end; |
| 347 | u16 key_len = le16_to_cpu(pkeyparamset->keylen); |
| 348 | |
| 349 | end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type) |
| 350 | + sizeof (pkeyparamset->length) |
| 351 | + param_set_len; |
| 352 | /* Make sure we don't access past the end of the IEs */ |
| 353 | if (end > resp_end) |
| 354 | break; |
| 355 | |
| 356 | if (key_info & KEY_INFO_WPA_UNICAST) |
| 357 | pkey = &adapter->wpa_unicast_key; |
| 358 | else if (key_info & KEY_INFO_WPA_MCAST) |
| 359 | pkey = &adapter->wpa_mcast_key; |
| 360 | else |
| 361 | break; |
| 362 | |
| 363 | /* Copy returned key into driver */ |
| 364 | memset(pkey, 0, sizeof(struct WLAN_802_11_KEY)); |
| 365 | if (key_len > sizeof(pkey->key)) |
| 366 | break; |
| 367 | pkey->type = le16_to_cpu(pkeyparamset->keytypeid); |
| 368 | pkey->flags = le16_to_cpu(pkeyparamset->keyinfo); |
| 369 | pkey->len = le16_to_cpu(pkeyparamset->keylen); |
| 370 | memcpy(pkey->key, pkeyparamset->key, pkey->len); |
| 371 | |
| 372 | buf_ptr = end + 1; |
| 373 | } |
| 374 | } |
| 375 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 376 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static int wlan_ret_802_11_mac_address(wlan_private * priv, |
| 381 | struct cmd_ds_command *resp) |
| 382 | { |
| 383 | struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd; |
| 384 | wlan_adapter *adapter = priv->adapter; |
| 385 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 386 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 387 | |
| 388 | memcpy(adapter->current_addr, macadd->macadd, ETH_ALEN); |
| 389 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 390 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static int wlan_ret_802_11_rf_tx_power(wlan_private * priv, |
| 395 | struct cmd_ds_command *resp) |
| 396 | { |
| 397 | struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp; |
| 398 | wlan_adapter *adapter = priv->adapter; |
| 399 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 400 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 401 | |
| 402 | adapter->txpowerlevel = le16_to_cpu(rtp->currentlevel); |
| 403 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 404 | lbs_deb_cmd("Current TxPower Level = %d\n", adapter->txpowerlevel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 405 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 406 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | static int wlan_ret_802_11_rf_antenna(wlan_private * priv, |
| 411 | struct cmd_ds_command *resp) |
| 412 | { |
| 413 | struct cmd_ds_802_11_rf_antenna *pAntenna = &resp->params.rant; |
| 414 | wlan_adapter *adapter = priv->adapter; |
| 415 | u16 action = le16_to_cpu(pAntenna->action); |
| 416 | |
| 417 | if (action == cmd_act_get_rx) |
| 418 | adapter->rxantennamode = |
| 419 | le16_to_cpu(pAntenna->antennamode); |
| 420 | |
| 421 | if (action == cmd_act_get_tx) |
| 422 | adapter->txantennamode = |
| 423 | le16_to_cpu(pAntenna->antennamode); |
| 424 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 425 | lbs_deb_cmd("RF_ANT_RESP: action = 0x%x, mode = 0x%04x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 426 | action, le16_to_cpu(pAntenna->antennamode)); |
| 427 | |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static int wlan_ret_802_11_rate_adapt_rateset(wlan_private * priv, |
| 432 | struct cmd_ds_command *resp) |
| 433 | { |
| 434 | struct cmd_ds_802_11_rate_adapt_rateset *rates = |
| 435 | &resp->params.rateset; |
| 436 | wlan_adapter *adapter = priv->adapter; |
| 437 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 438 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 439 | |
| 440 | if (rates->action == cmd_act_get) { |
| 441 | adapter->enablehwauto = rates->enablehwauto; |
| 442 | adapter->ratebitmap = rates->bitmap; |
| 443 | } |
| 444 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 445 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static int wlan_ret_802_11_data_rate(wlan_private * priv, |
| 450 | struct cmd_ds_command *resp) |
| 451 | { |
| 452 | struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate; |
| 453 | wlan_adapter *adapter = priv->adapter; |
| 454 | u8 dot11datarate; |
| 455 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 456 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 457 | |
| 458 | lbs_dbg_hex("DATA_RATE_RESP: data_rate- ", |
| 459 | (u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate)); |
| 460 | |
| 461 | dot11datarate = pdatarate->datarate[0]; |
| 462 | if (pdatarate->action == cmd_act_get_tx_rate) { |
| 463 | memcpy(adapter->libertas_supported_rates, pdatarate->datarate, |
| 464 | sizeof(adapter->libertas_supported_rates)); |
| 465 | } |
| 466 | adapter->datarate = libertas_index_to_data_rate(dot11datarate); |
| 467 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 468 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | static int wlan_ret_802_11_rf_channel(wlan_private * priv, |
| 473 | struct cmd_ds_command *resp) |
| 474 | { |
| 475 | struct cmd_ds_802_11_rf_channel *rfchannel = |
| 476 | &resp->params.rfchannel; |
| 477 | wlan_adapter *adapter = priv->adapter; |
| 478 | u16 action = le16_to_cpu(rfchannel->action); |
| 479 | u16 newchannel = le16_to_cpu(rfchannel->currentchannel); |
| 480 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 481 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 482 | |
| 483 | if (action == cmd_opt_802_11_rf_channel_get |
| 484 | && adapter->curbssparams.channel != newchannel) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 485 | lbs_deb_cmd("channel Switch: %d to %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 486 | adapter->curbssparams.channel, newchannel); |
| 487 | |
| 488 | /* Update the channel again */ |
| 489 | adapter->curbssparams.channel = newchannel; |
| 490 | } |
| 491 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 492 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | static int wlan_ret_802_11_rssi(wlan_private * priv, |
| 497 | struct cmd_ds_command *resp) |
| 498 | { |
| 499 | struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp; |
| 500 | wlan_adapter *adapter = priv->adapter; |
| 501 | |
| 502 | /* store the non average value */ |
| 503 | adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR); |
| 504 | adapter->NF[TYPE_BEACON][TYPE_NOAVG] = |
| 505 | le16_to_cpu(rssirsp->noisefloor); |
| 506 | |
| 507 | adapter->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR); |
| 508 | adapter->NF[TYPE_BEACON][TYPE_AVG] = |
| 509 | le16_to_cpu(rssirsp->avgnoisefloor); |
| 510 | |
| 511 | adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = |
| 512 | CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG], |
| 513 | adapter->NF[TYPE_BEACON][TYPE_NOAVG]); |
| 514 | |
| 515 | adapter->RSSI[TYPE_BEACON][TYPE_AVG] = |
| 516 | CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE, |
| 517 | adapter->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE); |
| 518 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 519 | lbs_deb_cmd("Beacon RSSI value = 0x%x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 520 | adapter->RSSI[TYPE_BEACON][TYPE_AVG]); |
| 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | static int wlan_ret_802_11_eeprom_access(wlan_private * priv, |
| 526 | struct cmd_ds_command *resp) |
| 527 | { |
| 528 | wlan_adapter *adapter = priv->adapter; |
| 529 | struct wlan_ioctl_regrdwr *pbuf; |
| 530 | pbuf = (struct wlan_ioctl_regrdwr *) adapter->prdeeprom; |
| 531 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 532 | lbs_deb_cmd("eeprom read len=%x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 533 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
| 534 | if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) { |
| 535 | pbuf->NOB = 0; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 536 | lbs_deb_cmd("eeprom read return length is too big\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 537 | return -1; |
| 538 | } |
| 539 | pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount); |
| 540 | if (pbuf->NOB > 0) { |
| 541 | |
| 542 | memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value, |
| 543 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
| 544 | lbs_dbg_hex("adapter", (char *)&pbuf->value, |
| 545 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
| 546 | } |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | static int wlan_ret_get_log(wlan_private * priv, |
| 551 | struct cmd_ds_command *resp) |
| 552 | { |
| 553 | struct cmd_ds_802_11_get_log *logmessage = |
| 554 | (struct cmd_ds_802_11_get_log *)&resp->params.glog; |
| 555 | wlan_adapter *adapter = priv->adapter; |
| 556 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 557 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 558 | |
| 559 | /* TODO Convert it to Big Endian before copy */ |
| 560 | memcpy(&adapter->logmsg, logmessage, |
| 561 | sizeof(struct cmd_ds_802_11_get_log)); |
| 562 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 563 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static inline int handle_cmd_response(u16 respcmd, |
| 568 | struct cmd_ds_command *resp, |
| 569 | wlan_private *priv) |
| 570 | { |
| 571 | int ret = 0; |
| 572 | unsigned long flags; |
| 573 | wlan_adapter *adapter = priv->adapter; |
| 574 | |
| 575 | switch (respcmd) { |
| 576 | case cmd_ret_mac_reg_access: |
| 577 | case cmd_ret_bbp_reg_access: |
| 578 | case cmd_ret_rf_reg_access: |
| 579 | ret = wlan_ret_reg_access(priv, respcmd, resp); |
| 580 | break; |
| 581 | |
| 582 | case cmd_ret_hw_spec_info: |
| 583 | ret = wlan_ret_get_hw_spec(priv, resp); |
| 584 | break; |
| 585 | |
| 586 | case cmd_ret_802_11_scan: |
| 587 | ret = libertas_ret_80211_scan(priv, resp); |
| 588 | break; |
| 589 | |
| 590 | case cmd_ret_802_11_get_log: |
| 591 | ret = wlan_ret_get_log(priv, resp); |
| 592 | break; |
| 593 | |
| 594 | case cmd_ret_802_11_associate: |
| 595 | case cmd_ret_802_11_reassociate: |
| 596 | ret = libertas_ret_80211_associate(priv, resp); |
| 597 | break; |
| 598 | |
| 599 | case cmd_ret_802_11_disassociate: |
| 600 | case cmd_ret_802_11_deauthenticate: |
| 601 | ret = libertas_ret_80211_disassociate(priv, resp); |
| 602 | break; |
| 603 | |
| 604 | case cmd_ret_802_11_ad_hoc_start: |
| 605 | case cmd_ret_802_11_ad_hoc_join: |
| 606 | ret = libertas_ret_80211_ad_hoc_start(priv, resp); |
| 607 | break; |
| 608 | |
| 609 | case cmd_ret_802_11_stat: |
| 610 | ret = wlan_ret_802_11_stat(priv, resp); |
| 611 | break; |
| 612 | |
| 613 | case cmd_ret_802_11_snmp_mib: |
| 614 | ret = wlan_ret_802_11_snmp_mib(priv, resp); |
| 615 | break; |
| 616 | |
| 617 | case cmd_ret_802_11_rf_tx_power: |
| 618 | ret = wlan_ret_802_11_rf_tx_power(priv, resp); |
| 619 | break; |
| 620 | |
| 621 | case cmd_ret_802_11_set_afc: |
| 622 | case cmd_ret_802_11_get_afc: |
| 623 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 624 | memmove(adapter->cur_cmd->pdata_buf, |
| 625 | &resp->params.afc, |
| 626 | sizeof(struct cmd_ds_802_11_afc)); |
| 627 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 628 | |
| 629 | break; |
| 630 | case cmd_ret_802_11_rf_antenna: |
| 631 | ret = wlan_ret_802_11_rf_antenna(priv, resp); |
| 632 | break; |
| 633 | |
| 634 | case cmd_ret_mac_multicast_adr: |
| 635 | case cmd_ret_mac_control: |
| 636 | case cmd_ret_802_11_set_wep: |
| 637 | case cmd_ret_802_11_reset: |
| 638 | case cmd_ret_802_11_authenticate: |
| 639 | case cmd_ret_802_11_radio_control: |
| 640 | case cmd_ret_802_11_beacon_stop: |
| 641 | case cmd_ret_802_11_enable_rsn: |
| 642 | break; |
| 643 | |
| 644 | case cmd_ret_802_11_data_rate: |
| 645 | ret = wlan_ret_802_11_data_rate(priv, resp); |
| 646 | break; |
| 647 | case cmd_ret_802_11_rate_adapt_rateset: |
| 648 | ret = wlan_ret_802_11_rate_adapt_rateset(priv, resp); |
| 649 | break; |
| 650 | case cmd_ret_802_11_rf_channel: |
| 651 | ret = wlan_ret_802_11_rf_channel(priv, resp); |
| 652 | break; |
| 653 | |
| 654 | case cmd_ret_802_11_rssi: |
| 655 | ret = wlan_ret_802_11_rssi(priv, resp); |
| 656 | break; |
| 657 | |
| 658 | case cmd_ret_802_11_mac_address: |
| 659 | ret = wlan_ret_802_11_mac_address(priv, resp); |
| 660 | break; |
| 661 | |
| 662 | case cmd_ret_802_11_ad_hoc_stop: |
| 663 | ret = libertas_ret_80211_ad_hoc_stop(priv, resp); |
| 664 | break; |
| 665 | |
| 666 | case cmd_ret_802_11_key_material: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 667 | lbs_deb_cmd("CMD_RESP: KEY_MATERIAL command response\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 668 | ret = wlan_ret_802_11_key_material(priv, resp); |
| 669 | break; |
| 670 | |
| 671 | case cmd_ret_802_11_eeprom_access: |
| 672 | ret = wlan_ret_802_11_eeprom_access(priv, resp); |
| 673 | break; |
| 674 | |
| 675 | case cmd_ret_802_11d_domain_info: |
| 676 | ret = libertas_ret_802_11d_domain_info(priv, resp); |
| 677 | break; |
| 678 | |
| 679 | case cmd_ret_802_11_sleep_params: |
| 680 | ret = wlan_ret_802_11_sleep_params(priv, resp); |
| 681 | break; |
| 682 | case cmd_ret_802_11_inactivity_timeout: |
| 683 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 684 | *((u16 *) adapter->cur_cmd->pdata_buf) = |
| 685 | le16_to_cpu(resp->params.inactivity_timeout.timeout); |
| 686 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 687 | break; |
| 688 | |
| 689 | case cmd_ret_802_11_tpc_cfg: |
| 690 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 691 | memmove(adapter->cur_cmd->pdata_buf, |
| 692 | &resp->params.tpccfg, |
| 693 | sizeof(struct cmd_ds_802_11_tpc_cfg)); |
| 694 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 695 | break; |
| 696 | case cmd_ret_802_11_led_gpio_ctrl: |
| 697 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 698 | memmove(adapter->cur_cmd->pdata_buf, |
| 699 | &resp->params.ledgpio, |
| 700 | sizeof(struct cmd_ds_802_11_led_ctrl)); |
| 701 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 702 | break; |
| 703 | case cmd_ret_802_11_pwr_cfg: |
| 704 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 705 | memmove(adapter->cur_cmd->pdata_buf, |
| 706 | &resp->params.pwrcfg, |
| 707 | sizeof(struct cmd_ds_802_11_pwr_cfg)); |
| 708 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 709 | |
| 710 | break; |
| 711 | |
| 712 | case cmd_ret_get_tsf: |
| 713 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 714 | memcpy(priv->adapter->cur_cmd->pdata_buf, |
| 715 | &resp->params.gettsf.tsfvalue, sizeof(u64)); |
| 716 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 717 | break; |
| 718 | case cmd_ret_bt_access: |
| 719 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 720 | if (adapter->cur_cmd->pdata_buf) |
| 721 | memcpy(adapter->cur_cmd->pdata_buf, |
| 722 | &resp->params.bt.addr1, 2 * ETH_ALEN); |
| 723 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 724 | break; |
| 725 | case cmd_ret_fwt_access: |
| 726 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 727 | if (adapter->cur_cmd->pdata_buf) |
| 728 | memcpy(adapter->cur_cmd->pdata_buf, |
| 729 | &resp->params.fwt, |
| 730 | sizeof(resp->params.fwt)); |
| 731 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 732 | break; |
| 733 | case cmd_ret_mesh_access: |
| 734 | if (adapter->cur_cmd->pdata_buf) |
| 735 | memcpy(adapter->cur_cmd->pdata_buf, |
| 736 | &resp->params.mesh, |
| 737 | sizeof(resp->params.mesh)); |
| 738 | break; |
| 739 | case cmd_rte_802_11_tx_rate_query: |
| 740 | priv->adapter->txrate = resp->params.txrate.txrate; |
| 741 | break; |
| 742 | default: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 743 | lbs_deb_cmd("CMD_RESP: Unknown command response %#x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 744 | resp->command); |
| 745 | break; |
| 746 | } |
| 747 | return ret; |
| 748 | } |
| 749 | |
| 750 | int libertas_process_rx_command(wlan_private * priv) |
| 751 | { |
| 752 | u16 respcmd; |
| 753 | struct cmd_ds_command *resp; |
| 754 | wlan_adapter *adapter = priv->adapter; |
| 755 | int ret = 0; |
| 756 | ulong flags; |
| 757 | u16 result; |
| 758 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 759 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 760 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 761 | lbs_deb_cmd("CMD_RESP: @ %lu\n", jiffies); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 762 | |
| 763 | /* Now we got response from FW, cancel the command timer */ |
| 764 | del_timer(&adapter->command_timer); |
| 765 | |
| 766 | mutex_lock(&adapter->lock); |
| 767 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 768 | |
| 769 | if (!adapter->cur_cmd) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 770 | lbs_deb_cmd("CMD_RESP: NULL cur_cmd=%p\n", adapter->cur_cmd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 771 | ret = -1; |
| 772 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 773 | goto done; |
| 774 | } |
| 775 | resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr); |
| 776 | |
| 777 | lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr, |
| 778 | priv->wlan_dev.upld_len); |
| 779 | |
| 780 | respcmd = le16_to_cpu(resp->command); |
| 781 | |
| 782 | result = le16_to_cpu(resp->result); |
| 783 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 784 | lbs_deb_cmd("CMD_RESP: %x result: %d length: %d\n", respcmd, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 785 | result, priv->wlan_dev.upld_len); |
| 786 | |
| 787 | if (!(respcmd & 0x8000)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 788 | lbs_deb_cmd("Invalid response to command!"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 789 | adapter->cur_cmd_retcode = -1; |
| 790 | __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
| 791 | adapter->nr_cmd_pending--; |
| 792 | adapter->cur_cmd = NULL; |
| 793 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 794 | ret = -1; |
| 795 | goto done; |
| 796 | } |
| 797 | |
| 798 | /* Store the response code to cur_cmd_retcode. */ |
| 799 | adapter->cur_cmd_retcode = le16_to_cpu(resp->result); |
| 800 | |
| 801 | if (respcmd == cmd_ret_802_11_ps_mode) { |
| 802 | struct cmd_ds_802_11_ps_mode *psmode; |
| 803 | |
| 804 | psmode = &resp->params.psmode; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 805 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 806 | "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n", |
| 807 | resp->result, psmode->action); |
| 808 | psmode->action = cpu_to_le16(psmode->action); |
| 809 | |
| 810 | if (result) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 811 | lbs_deb_cmd("CMD_RESP: PS command failed- %#x \n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 812 | resp->result); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 813 | if (adapter->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 814 | /* |
| 815 | * We should not re-try enter-ps command in |
| 816 | * ad-hoc mode. It takes place in |
| 817 | * libertas_execute_next_command(). |
| 818 | */ |
| 819 | if (psmode->action == cmd_subcmd_enter_ps) |
| 820 | adapter->psmode = |
| 821 | wlan802_11powermodecam; |
| 822 | } |
| 823 | } else if (psmode->action == cmd_subcmd_enter_ps) { |
| 824 | adapter->needtowakeup = 0; |
| 825 | adapter->psstate = PS_STATE_AWAKE; |
| 826 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 827 | lbs_deb_cmd("CMD_RESP: Enter_PS command response\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 828 | if (adapter->connect_status != libertas_connected) { |
| 829 | /* |
| 830 | * When Deauth Event received before Enter_PS command |
| 831 | * response, We need to wake up the firmware. |
| 832 | */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 833 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 834 | "Disconnected, Going to invoke libertas_ps_wakeup\n"); |
| 835 | |
| 836 | mutex_unlock(&adapter->lock); |
| 837 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 838 | libertas_ps_wakeup(priv, 0); |
| 839 | mutex_lock(&adapter->lock); |
| 840 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 841 | } |
| 842 | } else if (psmode->action == cmd_subcmd_exit_ps) { |
| 843 | adapter->needtowakeup = 0; |
| 844 | adapter->psstate = PS_STATE_FULL_POWER; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 845 | lbs_deb_cmd("CMD_RESP: Exit_PS command response\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 846 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 847 | lbs_deb_cmd("CMD_RESP: PS- action=0x%X\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 848 | psmode->action); |
| 849 | } |
| 850 | |
| 851 | __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
| 852 | adapter->nr_cmd_pending--; |
| 853 | adapter->cur_cmd = NULL; |
| 854 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 855 | |
| 856 | ret = 0; |
| 857 | goto done; |
| 858 | } |
| 859 | |
| 860 | if (adapter->cur_cmd->cmdflags & CMD_F_HOSTCMD) { |
| 861 | /* Copy the response back to response buffer */ |
| 862 | memcpy(adapter->cur_cmd->pdata_buf, resp, resp->size); |
| 863 | |
| 864 | adapter->cur_cmd->cmdflags &= ~CMD_F_HOSTCMD; |
| 865 | } |
| 866 | |
| 867 | /* If the command is not successful, cleanup and return failure */ |
| 868 | if ((result != 0 || !(respcmd & 0x8000))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 869 | lbs_deb_cmd("CMD_RESP: command reply %#x result=%#x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 870 | resp->command, resp->result); |
| 871 | /* |
| 872 | * Handling errors here |
| 873 | */ |
| 874 | switch (respcmd) { |
| 875 | case cmd_ret_hw_spec_info: |
| 876 | case cmd_ret_802_11_reset: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 877 | lbs_deb_cmd("CMD_RESP: Reset command failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 878 | break; |
| 879 | |
| 880 | } |
| 881 | |
| 882 | __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
| 883 | adapter->nr_cmd_pending--; |
| 884 | adapter->cur_cmd = NULL; |
| 885 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 886 | |
| 887 | ret = -1; |
| 888 | goto done; |
| 889 | } |
| 890 | |
| 891 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 892 | |
| 893 | ret = handle_cmd_response(respcmd, resp, priv); |
| 894 | |
| 895 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 896 | if (adapter->cur_cmd) { |
| 897 | /* Clean up and Put current command back to cmdfreeq */ |
| 898 | __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
| 899 | adapter->nr_cmd_pending--; |
| 900 | WARN_ON(adapter->nr_cmd_pending > 128); |
| 901 | adapter->cur_cmd = NULL; |
| 902 | } |
| 903 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 904 | |
| 905 | done: |
| 906 | mutex_unlock(&adapter->lock); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 907 | lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 908 | return ret; |
| 909 | } |
| 910 | |
| 911 | int libertas_process_event(wlan_private * priv) |
| 912 | { |
| 913 | int ret = 0; |
| 914 | wlan_adapter *adapter = priv->adapter; |
| 915 | u32 eventcause; |
| 916 | |
| 917 | spin_lock_irq(&adapter->driver_lock); |
| 918 | eventcause = adapter->eventcause; |
| 919 | spin_unlock_irq(&adapter->driver_lock); |
| 920 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 921 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 922 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 923 | lbs_deb_cmd("EVENT Cause %x\n", eventcause); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 924 | |
| 925 | switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) { |
| 926 | case MACREG_INT_CODE_LINK_SENSED: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 927 | lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 928 | break; |
| 929 | |
| 930 | case MACREG_INT_CODE_DEAUTHENTICATED: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 931 | lbs_deb_cmd("EVENT: Deauthenticated\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 932 | libertas_mac_event_disconnected(priv); |
| 933 | break; |
| 934 | |
| 935 | case MACREG_INT_CODE_DISASSOCIATED: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 936 | lbs_deb_cmd("EVENT: Disassociated\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 937 | libertas_mac_event_disconnected(priv); |
| 938 | break; |
| 939 | |
| 940 | case MACREG_INT_CODE_LINK_LOSE_NO_SCAN: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 941 | lbs_deb_cmd("EVENT: Link lost\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 942 | libertas_mac_event_disconnected(priv); |
| 943 | break; |
| 944 | |
| 945 | case MACREG_INT_CODE_PS_SLEEP: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 946 | lbs_deb_cmd("EVENT: SLEEP\n"); |
| 947 | lbs_deb_cmd("_"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 948 | |
| 949 | /* handle unexpected PS SLEEP event */ |
| 950 | if (adapter->psstate == PS_STATE_FULL_POWER) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 951 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 952 | "EVENT: In FULL POWER mode - ignore PS SLEEP\n"); |
| 953 | break; |
| 954 | } |
| 955 | adapter->psstate = PS_STATE_PRE_SLEEP; |
| 956 | |
| 957 | libertas_ps_confirm_sleep(priv, (u16) adapter->psmode); |
| 958 | |
| 959 | break; |
| 960 | |
| 961 | case MACREG_INT_CODE_PS_AWAKE: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 962 | lbs_deb_cmd("EVENT: AWAKE \n"); |
| 963 | lbs_deb_cmd("|"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 964 | |
| 965 | /* handle unexpected PS AWAKE event */ |
| 966 | if (adapter->psstate == PS_STATE_FULL_POWER) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 967 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 968 | "EVENT: In FULL POWER mode - ignore PS AWAKE\n"); |
| 969 | break; |
| 970 | } |
| 971 | |
| 972 | adapter->psstate = PS_STATE_AWAKE; |
| 973 | |
| 974 | if (adapter->needtowakeup) { |
| 975 | /* |
| 976 | * wait for the command processing to finish |
| 977 | * before resuming sending |
| 978 | * adapter->needtowakeup will be set to FALSE |
| 979 | * in libertas_ps_wakeup() |
| 980 | */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 981 | lbs_deb_cmd("Waking up...\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 982 | libertas_ps_wakeup(priv, 0); |
| 983 | } |
| 984 | break; |
| 985 | |
| 986 | case MACREG_INT_CODE_MIC_ERR_UNICAST: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 987 | lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 988 | handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST); |
| 989 | break; |
| 990 | |
| 991 | case MACREG_INT_CODE_MIC_ERR_MULTICAST: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 992 | lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 993 | handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST); |
| 994 | break; |
| 995 | case MACREG_INT_CODE_MIB_CHANGED: |
| 996 | case MACREG_INT_CODE_INIT_DONE: |
| 997 | break; |
| 998 | |
| 999 | case MACREG_INT_CODE_ADHOC_BCN_LOST: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1000 | lbs_deb_cmd("EVENT: HWAC - ADHOC BCN LOST\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1001 | break; |
| 1002 | |
| 1003 | case MACREG_INT_CODE_RSSI_LOW: |
| 1004 | lbs_pr_alert( "EVENT: RSSI_LOW\n"); |
| 1005 | break; |
| 1006 | case MACREG_INT_CODE_SNR_LOW: |
| 1007 | lbs_pr_alert( "EVENT: SNR_LOW\n"); |
| 1008 | break; |
| 1009 | case MACREG_INT_CODE_MAX_FAIL: |
| 1010 | lbs_pr_alert( "EVENT: MAX_FAIL\n"); |
| 1011 | break; |
| 1012 | case MACREG_INT_CODE_RSSI_HIGH: |
| 1013 | lbs_pr_alert( "EVENT: RSSI_HIGH\n"); |
| 1014 | break; |
| 1015 | case MACREG_INT_CODE_SNR_HIGH: |
| 1016 | lbs_pr_alert( "EVENT: SNR_HIGH\n"); |
| 1017 | break; |
| 1018 | |
| 1019 | default: |
| 1020 | lbs_pr_alert( "EVENT: unknown event id: %#x\n", |
| 1021 | eventcause >> SBI_EVENT_CAUSE_SHIFT); |
| 1022 | break; |
| 1023 | } |
| 1024 | |
| 1025 | spin_lock_irq(&adapter->driver_lock); |
| 1026 | adapter->eventcause = 0; |
| 1027 | spin_unlock_irq(&adapter->driver_lock); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1028 | |
| 1029 | lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1030 | return ret; |
| 1031 | } |