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); |
| 223 | memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN); |
| 224 | |
| 225 | if (libertas_set_regiontable(priv, adapter->regioncode, 0)) { |
| 226 | ret = -1; |
| 227 | goto done; |
| 228 | } |
| 229 | |
| 230 | if (libertas_set_universaltable(priv, 0)) { |
| 231 | ret = -1; |
| 232 | goto done; |
| 233 | } |
| 234 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 235 | done: |
| 236 | lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 237 | return ret; |
| 238 | } |
| 239 | |
| 240 | static int wlan_ret_802_11_sleep_params(wlan_private * priv, |
| 241 | struct cmd_ds_command *resp) |
| 242 | { |
| 243 | struct cmd_ds_802_11_sleep_params *sp = &resp->params.sleep_params; |
| 244 | wlan_adapter *adapter = priv->adapter; |
| 245 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 246 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 247 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 248 | lbs_deb_cmd("error=%x offset=%x stabletime=%x calcontrol=%x\n" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 249 | " extsleepclk=%x\n", sp->error, sp->offset, |
| 250 | sp->stabletime, sp->calcontrol, sp->externalsleepclk); |
| 251 | adapter->sp.sp_error = le16_to_cpu(sp->error); |
| 252 | adapter->sp.sp_offset = le16_to_cpu(sp->offset); |
| 253 | adapter->sp.sp_stabletime = le16_to_cpu(sp->stabletime); |
| 254 | adapter->sp.sp_calcontrol = le16_to_cpu(sp->calcontrol); |
| 255 | adapter->sp.sp_extsleepclk = le16_to_cpu(sp->externalsleepclk); |
| 256 | adapter->sp.sp_reserved = le16_to_cpu(sp->reserved); |
| 257 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 258 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | static int wlan_ret_802_11_stat(wlan_private * priv, |
| 263 | struct cmd_ds_command *resp) |
| 264 | { |
| 265 | /* currently adapter->wlan802_11Stat is unused |
| 266 | |
| 267 | struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat; |
| 268 | wlan_adapter *adapter = priv->adapter; |
| 269 | |
| 270 | // TODO Convert it to Big endian befor copy |
| 271 | memcpy(&adapter->wlan802_11Stat, |
| 272 | p11Stat, sizeof(struct cmd_ds_802_11_get_stat)); |
| 273 | */ |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | static int wlan_ret_802_11_snmp_mib(wlan_private * priv, |
| 278 | struct cmd_ds_command *resp) |
| 279 | { |
| 280 | struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib; |
| 281 | u16 oid = le16_to_cpu(smib->oid); |
| 282 | u16 querytype = le16_to_cpu(smib->querytype); |
| 283 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 284 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 285 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 286 | 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] | 287 | querytype); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 288 | lbs_deb_cmd("SNMP_RESP: Buf size = %x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 289 | le16_to_cpu(smib->bufsize)); |
| 290 | |
| 291 | if (querytype == cmd_act_get) { |
| 292 | switch (oid) { |
| 293 | case fragthresh_i: |
| 294 | priv->adapter->fragthsd = |
| 295 | le16_to_cpu(* |
| 296 | ((unsigned short *)(smib->value))); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 297 | lbs_deb_cmd("SNMP_RESP: fragthsd =%u\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 298 | priv->adapter->fragthsd); |
| 299 | break; |
| 300 | case rtsthresh_i: |
| 301 | priv->adapter->rtsthsd = |
| 302 | le16_to_cpu(* |
| 303 | ((unsigned short *)(smib->value))); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 304 | lbs_deb_cmd("SNMP_RESP: rtsthsd =%u\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 305 | priv->adapter->rtsthsd); |
| 306 | break; |
| 307 | case short_retrylim_i: |
| 308 | priv->adapter->txretrycount = |
| 309 | le16_to_cpu(* |
| 310 | ((unsigned short *)(smib->value))); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 311 | lbs_deb_cmd("SNMP_RESP: txretrycount =%u\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 312 | priv->adapter->rtsthsd); |
| 313 | break; |
| 314 | default: |
| 315 | break; |
| 316 | } |
| 317 | } |
| 318 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 319 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static int wlan_ret_802_11_key_material(wlan_private * priv, |
| 324 | struct cmd_ds_command *resp) |
| 325 | { |
| 326 | struct cmd_ds_802_11_key_material *pkeymaterial = |
| 327 | &resp->params.keymaterial; |
| 328 | wlan_adapter *adapter = priv->adapter; |
| 329 | u16 action = le16_to_cpu(pkeymaterial->action); |
| 330 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 331 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 332 | |
| 333 | /* Copy the returned key to driver private data */ |
| 334 | if (action == cmd_act_get) { |
| 335 | u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet; |
| 336 | u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size)); |
| 337 | |
| 338 | while (buf_ptr < resp_end) { |
| 339 | struct MrvlIEtype_keyParamSet * pkeyparamset = |
| 340 | (struct MrvlIEtype_keyParamSet *) buf_ptr; |
| 341 | struct WLAN_802_11_KEY * pkey; |
| 342 | u16 key_info = le16_to_cpu(pkeyparamset->keyinfo); |
| 343 | u16 param_set_len = le16_to_cpu(pkeyparamset->length); |
| 344 | u8 * end; |
| 345 | u16 key_len = le16_to_cpu(pkeyparamset->keylen); |
| 346 | |
| 347 | end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type) |
| 348 | + sizeof (pkeyparamset->length) |
| 349 | + param_set_len; |
| 350 | /* Make sure we don't access past the end of the IEs */ |
| 351 | if (end > resp_end) |
| 352 | break; |
| 353 | |
| 354 | if (key_info & KEY_INFO_WPA_UNICAST) |
| 355 | pkey = &adapter->wpa_unicast_key; |
| 356 | else if (key_info & KEY_INFO_WPA_MCAST) |
| 357 | pkey = &adapter->wpa_mcast_key; |
| 358 | else |
| 359 | break; |
| 360 | |
| 361 | /* Copy returned key into driver */ |
| 362 | memset(pkey, 0, sizeof(struct WLAN_802_11_KEY)); |
| 363 | if (key_len > sizeof(pkey->key)) |
| 364 | break; |
| 365 | pkey->type = le16_to_cpu(pkeyparamset->keytypeid); |
| 366 | pkey->flags = le16_to_cpu(pkeyparamset->keyinfo); |
| 367 | pkey->len = le16_to_cpu(pkeyparamset->keylen); |
| 368 | memcpy(pkey->key, pkeyparamset->key, pkey->len); |
| 369 | |
| 370 | buf_ptr = end + 1; |
| 371 | } |
| 372 | } |
| 373 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 374 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int wlan_ret_802_11_mac_address(wlan_private * priv, |
| 379 | struct cmd_ds_command *resp) |
| 380 | { |
| 381 | struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd; |
| 382 | wlan_adapter *adapter = priv->adapter; |
| 383 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 384 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 385 | |
| 386 | memcpy(adapter->current_addr, macadd->macadd, ETH_ALEN); |
| 387 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 388 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int wlan_ret_802_11_rf_tx_power(wlan_private * priv, |
| 393 | struct cmd_ds_command *resp) |
| 394 | { |
| 395 | struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp; |
| 396 | wlan_adapter *adapter = priv->adapter; |
| 397 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 398 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 399 | |
| 400 | adapter->txpowerlevel = le16_to_cpu(rtp->currentlevel); |
| 401 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 402 | lbs_deb_cmd("Current TxPower Level = %d\n", adapter->txpowerlevel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 403 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 404 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static int wlan_ret_802_11_rf_antenna(wlan_private * priv, |
| 409 | struct cmd_ds_command *resp) |
| 410 | { |
| 411 | struct cmd_ds_802_11_rf_antenna *pAntenna = &resp->params.rant; |
| 412 | wlan_adapter *adapter = priv->adapter; |
| 413 | u16 action = le16_to_cpu(pAntenna->action); |
| 414 | |
| 415 | if (action == cmd_act_get_rx) |
| 416 | adapter->rxantennamode = |
| 417 | le16_to_cpu(pAntenna->antennamode); |
| 418 | |
| 419 | if (action == cmd_act_get_tx) |
| 420 | adapter->txantennamode = |
| 421 | le16_to_cpu(pAntenna->antennamode); |
| 422 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 423 | 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] | 424 | action, le16_to_cpu(pAntenna->antennamode)); |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static int wlan_ret_802_11_rate_adapt_rateset(wlan_private * priv, |
| 430 | struct cmd_ds_command *resp) |
| 431 | { |
| 432 | struct cmd_ds_802_11_rate_adapt_rateset *rates = |
| 433 | &resp->params.rateset; |
| 434 | wlan_adapter *adapter = priv->adapter; |
| 435 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 436 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 437 | |
| 438 | if (rates->action == cmd_act_get) { |
| 439 | adapter->enablehwauto = rates->enablehwauto; |
| 440 | adapter->ratebitmap = rates->bitmap; |
| 441 | } |
| 442 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 443 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | static int wlan_ret_802_11_data_rate(wlan_private * priv, |
| 448 | struct cmd_ds_command *resp) |
| 449 | { |
| 450 | struct cmd_ds_802_11_data_rate *pdatarate = &resp->params.drate; |
| 451 | wlan_adapter *adapter = priv->adapter; |
| 452 | u8 dot11datarate; |
| 453 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 454 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 455 | |
| 456 | lbs_dbg_hex("DATA_RATE_RESP: data_rate- ", |
| 457 | (u8 *) pdatarate, sizeof(struct cmd_ds_802_11_data_rate)); |
| 458 | |
| 459 | dot11datarate = pdatarate->datarate[0]; |
| 460 | if (pdatarate->action == cmd_act_get_tx_rate) { |
| 461 | memcpy(adapter->libertas_supported_rates, pdatarate->datarate, |
| 462 | sizeof(adapter->libertas_supported_rates)); |
| 463 | } |
| 464 | adapter->datarate = libertas_index_to_data_rate(dot11datarate); |
| 465 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 466 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static int wlan_ret_802_11_rf_channel(wlan_private * priv, |
| 471 | struct cmd_ds_command *resp) |
| 472 | { |
| 473 | struct cmd_ds_802_11_rf_channel *rfchannel = |
| 474 | &resp->params.rfchannel; |
| 475 | wlan_adapter *adapter = priv->adapter; |
| 476 | u16 action = le16_to_cpu(rfchannel->action); |
| 477 | u16 newchannel = le16_to_cpu(rfchannel->currentchannel); |
| 478 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 479 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 480 | |
| 481 | if (action == cmd_opt_802_11_rf_channel_get |
| 482 | && adapter->curbssparams.channel != newchannel) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 483 | lbs_deb_cmd("channel Switch: %d to %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 484 | adapter->curbssparams.channel, newchannel); |
| 485 | |
| 486 | /* Update the channel again */ |
| 487 | adapter->curbssparams.channel = newchannel; |
| 488 | } |
| 489 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 490 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static int wlan_ret_802_11_rssi(wlan_private * priv, |
| 495 | struct cmd_ds_command *resp) |
| 496 | { |
| 497 | struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp; |
| 498 | wlan_adapter *adapter = priv->adapter; |
| 499 | |
| 500 | /* store the non average value */ |
| 501 | adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR); |
| 502 | adapter->NF[TYPE_BEACON][TYPE_NOAVG] = |
| 503 | le16_to_cpu(rssirsp->noisefloor); |
| 504 | |
| 505 | adapter->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR); |
| 506 | adapter->NF[TYPE_BEACON][TYPE_AVG] = |
| 507 | le16_to_cpu(rssirsp->avgnoisefloor); |
| 508 | |
| 509 | adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = |
| 510 | CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG], |
| 511 | adapter->NF[TYPE_BEACON][TYPE_NOAVG]); |
| 512 | |
| 513 | adapter->RSSI[TYPE_BEACON][TYPE_AVG] = |
| 514 | CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE, |
| 515 | adapter->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE); |
| 516 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 517 | lbs_deb_cmd("Beacon RSSI value = 0x%x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 518 | adapter->RSSI[TYPE_BEACON][TYPE_AVG]); |
| 519 | |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static int wlan_ret_802_11_eeprom_access(wlan_private * priv, |
| 524 | struct cmd_ds_command *resp) |
| 525 | { |
| 526 | wlan_adapter *adapter = priv->adapter; |
| 527 | struct wlan_ioctl_regrdwr *pbuf; |
| 528 | pbuf = (struct wlan_ioctl_regrdwr *) adapter->prdeeprom; |
| 529 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 530 | lbs_deb_cmd("eeprom read len=%x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 531 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
| 532 | if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) { |
| 533 | pbuf->NOB = 0; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 534 | lbs_deb_cmd("eeprom read return length is too big\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 535 | return -1; |
| 536 | } |
| 537 | pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount); |
| 538 | if (pbuf->NOB > 0) { |
| 539 | |
| 540 | memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value, |
| 541 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
| 542 | lbs_dbg_hex("adapter", (char *)&pbuf->value, |
| 543 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
| 544 | } |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static int wlan_ret_get_log(wlan_private * priv, |
| 549 | struct cmd_ds_command *resp) |
| 550 | { |
| 551 | struct cmd_ds_802_11_get_log *logmessage = |
| 552 | (struct cmd_ds_802_11_get_log *)&resp->params.glog; |
| 553 | wlan_adapter *adapter = priv->adapter; |
| 554 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 555 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 556 | |
| 557 | /* TODO Convert it to Big Endian before copy */ |
| 558 | memcpy(&adapter->logmsg, logmessage, |
| 559 | sizeof(struct cmd_ds_802_11_get_log)); |
| 560 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 561 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | static inline int handle_cmd_response(u16 respcmd, |
| 566 | struct cmd_ds_command *resp, |
| 567 | wlan_private *priv) |
| 568 | { |
| 569 | int ret = 0; |
| 570 | unsigned long flags; |
| 571 | wlan_adapter *adapter = priv->adapter; |
| 572 | |
| 573 | switch (respcmd) { |
| 574 | case cmd_ret_mac_reg_access: |
| 575 | case cmd_ret_bbp_reg_access: |
| 576 | case cmd_ret_rf_reg_access: |
| 577 | ret = wlan_ret_reg_access(priv, respcmd, resp); |
| 578 | break; |
| 579 | |
| 580 | case cmd_ret_hw_spec_info: |
| 581 | ret = wlan_ret_get_hw_spec(priv, resp); |
| 582 | break; |
| 583 | |
| 584 | case cmd_ret_802_11_scan: |
| 585 | ret = libertas_ret_80211_scan(priv, resp); |
| 586 | break; |
| 587 | |
| 588 | case cmd_ret_802_11_get_log: |
| 589 | ret = wlan_ret_get_log(priv, resp); |
| 590 | break; |
| 591 | |
| 592 | case cmd_ret_802_11_associate: |
| 593 | case cmd_ret_802_11_reassociate: |
| 594 | ret = libertas_ret_80211_associate(priv, resp); |
| 595 | break; |
| 596 | |
| 597 | case cmd_ret_802_11_disassociate: |
| 598 | case cmd_ret_802_11_deauthenticate: |
| 599 | ret = libertas_ret_80211_disassociate(priv, resp); |
| 600 | break; |
| 601 | |
| 602 | case cmd_ret_802_11_ad_hoc_start: |
| 603 | case cmd_ret_802_11_ad_hoc_join: |
| 604 | ret = libertas_ret_80211_ad_hoc_start(priv, resp); |
| 605 | break; |
| 606 | |
| 607 | case cmd_ret_802_11_stat: |
| 608 | ret = wlan_ret_802_11_stat(priv, resp); |
| 609 | break; |
| 610 | |
| 611 | case cmd_ret_802_11_snmp_mib: |
| 612 | ret = wlan_ret_802_11_snmp_mib(priv, resp); |
| 613 | break; |
| 614 | |
| 615 | case cmd_ret_802_11_rf_tx_power: |
| 616 | ret = wlan_ret_802_11_rf_tx_power(priv, resp); |
| 617 | break; |
| 618 | |
| 619 | case cmd_ret_802_11_set_afc: |
| 620 | case cmd_ret_802_11_get_afc: |
| 621 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 622 | memmove(adapter->cur_cmd->pdata_buf, |
| 623 | &resp->params.afc, |
| 624 | sizeof(struct cmd_ds_802_11_afc)); |
| 625 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 626 | |
| 627 | break; |
| 628 | case cmd_ret_802_11_rf_antenna: |
| 629 | ret = wlan_ret_802_11_rf_antenna(priv, resp); |
| 630 | break; |
| 631 | |
| 632 | case cmd_ret_mac_multicast_adr: |
| 633 | case cmd_ret_mac_control: |
| 634 | case cmd_ret_802_11_set_wep: |
| 635 | case cmd_ret_802_11_reset: |
| 636 | case cmd_ret_802_11_authenticate: |
| 637 | case cmd_ret_802_11_radio_control: |
| 638 | case cmd_ret_802_11_beacon_stop: |
| 639 | case cmd_ret_802_11_enable_rsn: |
| 640 | break; |
| 641 | |
| 642 | case cmd_ret_802_11_data_rate: |
| 643 | ret = wlan_ret_802_11_data_rate(priv, resp); |
| 644 | break; |
| 645 | case cmd_ret_802_11_rate_adapt_rateset: |
| 646 | ret = wlan_ret_802_11_rate_adapt_rateset(priv, resp); |
| 647 | break; |
| 648 | case cmd_ret_802_11_rf_channel: |
| 649 | ret = wlan_ret_802_11_rf_channel(priv, resp); |
| 650 | break; |
| 651 | |
| 652 | case cmd_ret_802_11_rssi: |
| 653 | ret = wlan_ret_802_11_rssi(priv, resp); |
| 654 | break; |
| 655 | |
| 656 | case cmd_ret_802_11_mac_address: |
| 657 | ret = wlan_ret_802_11_mac_address(priv, resp); |
| 658 | break; |
| 659 | |
| 660 | case cmd_ret_802_11_ad_hoc_stop: |
| 661 | ret = libertas_ret_80211_ad_hoc_stop(priv, resp); |
| 662 | break; |
| 663 | |
| 664 | case cmd_ret_802_11_key_material: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 665 | lbs_deb_cmd("CMD_RESP: KEY_MATERIAL command response\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 666 | ret = wlan_ret_802_11_key_material(priv, resp); |
| 667 | break; |
| 668 | |
| 669 | case cmd_ret_802_11_eeprom_access: |
| 670 | ret = wlan_ret_802_11_eeprom_access(priv, resp); |
| 671 | break; |
| 672 | |
| 673 | case cmd_ret_802_11d_domain_info: |
| 674 | ret = libertas_ret_802_11d_domain_info(priv, resp); |
| 675 | break; |
| 676 | |
| 677 | case cmd_ret_802_11_sleep_params: |
| 678 | ret = wlan_ret_802_11_sleep_params(priv, resp); |
| 679 | break; |
| 680 | case cmd_ret_802_11_inactivity_timeout: |
| 681 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 682 | *((u16 *) adapter->cur_cmd->pdata_buf) = |
| 683 | le16_to_cpu(resp->params.inactivity_timeout.timeout); |
| 684 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 685 | break; |
| 686 | |
| 687 | case cmd_ret_802_11_tpc_cfg: |
| 688 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 689 | memmove(adapter->cur_cmd->pdata_buf, |
| 690 | &resp->params.tpccfg, |
| 691 | sizeof(struct cmd_ds_802_11_tpc_cfg)); |
| 692 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 693 | break; |
| 694 | case cmd_ret_802_11_led_gpio_ctrl: |
| 695 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 696 | memmove(adapter->cur_cmd->pdata_buf, |
| 697 | &resp->params.ledgpio, |
| 698 | sizeof(struct cmd_ds_802_11_led_ctrl)); |
| 699 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 700 | break; |
| 701 | case cmd_ret_802_11_pwr_cfg: |
| 702 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 703 | memmove(adapter->cur_cmd->pdata_buf, |
| 704 | &resp->params.pwrcfg, |
| 705 | sizeof(struct cmd_ds_802_11_pwr_cfg)); |
| 706 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 707 | |
| 708 | break; |
| 709 | |
| 710 | case cmd_ret_get_tsf: |
| 711 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 712 | memcpy(priv->adapter->cur_cmd->pdata_buf, |
| 713 | &resp->params.gettsf.tsfvalue, sizeof(u64)); |
| 714 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 715 | break; |
| 716 | case cmd_ret_bt_access: |
| 717 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 718 | if (adapter->cur_cmd->pdata_buf) |
| 719 | memcpy(adapter->cur_cmd->pdata_buf, |
| 720 | &resp->params.bt.addr1, 2 * ETH_ALEN); |
| 721 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 722 | break; |
| 723 | case cmd_ret_fwt_access: |
| 724 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 725 | if (adapter->cur_cmd->pdata_buf) |
| 726 | memcpy(adapter->cur_cmd->pdata_buf, |
| 727 | &resp->params.fwt, |
| 728 | sizeof(resp->params.fwt)); |
| 729 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 730 | break; |
| 731 | case cmd_ret_mesh_access: |
| 732 | if (adapter->cur_cmd->pdata_buf) |
| 733 | memcpy(adapter->cur_cmd->pdata_buf, |
| 734 | &resp->params.mesh, |
| 735 | sizeof(resp->params.mesh)); |
| 736 | break; |
| 737 | case cmd_rte_802_11_tx_rate_query: |
| 738 | priv->adapter->txrate = resp->params.txrate.txrate; |
| 739 | break; |
| 740 | default: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 741 | lbs_deb_cmd("CMD_RESP: Unknown command response %#x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 742 | resp->command); |
| 743 | break; |
| 744 | } |
| 745 | return ret; |
| 746 | } |
| 747 | |
| 748 | int libertas_process_rx_command(wlan_private * priv) |
| 749 | { |
| 750 | u16 respcmd; |
| 751 | struct cmd_ds_command *resp; |
| 752 | wlan_adapter *adapter = priv->adapter; |
| 753 | int ret = 0; |
| 754 | ulong flags; |
| 755 | u16 result; |
| 756 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 757 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 758 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 759 | lbs_deb_cmd("CMD_RESP: @ %lu\n", jiffies); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 760 | |
| 761 | /* Now we got response from FW, cancel the command timer */ |
| 762 | del_timer(&adapter->command_timer); |
| 763 | |
| 764 | mutex_lock(&adapter->lock); |
| 765 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 766 | |
| 767 | if (!adapter->cur_cmd) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 768 | 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] | 769 | ret = -1; |
| 770 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 771 | goto done; |
| 772 | } |
| 773 | resp = (struct cmd_ds_command *)(adapter->cur_cmd->bufvirtualaddr); |
| 774 | |
| 775 | lbs_dbg_hex("CMD_RESP:", adapter->cur_cmd->bufvirtualaddr, |
| 776 | priv->wlan_dev.upld_len); |
| 777 | |
| 778 | respcmd = le16_to_cpu(resp->command); |
| 779 | |
| 780 | result = le16_to_cpu(resp->result); |
| 781 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 782 | lbs_deb_cmd("CMD_RESP: %x result: %d length: %d\n", respcmd, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 783 | result, priv->wlan_dev.upld_len); |
| 784 | |
| 785 | if (!(respcmd & 0x8000)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 786 | lbs_deb_cmd("Invalid response to command!"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 787 | adapter->cur_cmd_retcode = -1; |
| 788 | __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
| 789 | adapter->nr_cmd_pending--; |
| 790 | adapter->cur_cmd = NULL; |
| 791 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 792 | ret = -1; |
| 793 | goto done; |
| 794 | } |
| 795 | |
| 796 | /* Store the response code to cur_cmd_retcode. */ |
| 797 | adapter->cur_cmd_retcode = le16_to_cpu(resp->result); |
| 798 | |
| 799 | if (respcmd == cmd_ret_802_11_ps_mode) { |
| 800 | struct cmd_ds_802_11_ps_mode *psmode; |
| 801 | |
| 802 | psmode = &resp->params.psmode; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 803 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 804 | "CMD_RESP: PS_MODE cmd reply result=%#x action=0x%X\n", |
| 805 | resp->result, psmode->action); |
| 806 | psmode->action = cpu_to_le16(psmode->action); |
| 807 | |
| 808 | if (result) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 809 | lbs_deb_cmd("CMD_RESP: PS command failed- %#x \n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 810 | resp->result); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame] | 811 | if (adapter->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 812 | /* |
| 813 | * We should not re-try enter-ps command in |
| 814 | * ad-hoc mode. It takes place in |
| 815 | * libertas_execute_next_command(). |
| 816 | */ |
| 817 | if (psmode->action == cmd_subcmd_enter_ps) |
| 818 | adapter->psmode = |
| 819 | wlan802_11powermodecam; |
| 820 | } |
| 821 | } else if (psmode->action == cmd_subcmd_enter_ps) { |
| 822 | adapter->needtowakeup = 0; |
| 823 | adapter->psstate = PS_STATE_AWAKE; |
| 824 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 825 | lbs_deb_cmd("CMD_RESP: Enter_PS command response\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 826 | if (adapter->connect_status != libertas_connected) { |
| 827 | /* |
| 828 | * When Deauth Event received before Enter_PS command |
| 829 | * response, We need to wake up the firmware. |
| 830 | */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 831 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 832 | "Disconnected, Going to invoke libertas_ps_wakeup\n"); |
| 833 | |
| 834 | mutex_unlock(&adapter->lock); |
| 835 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 836 | libertas_ps_wakeup(priv, 0); |
| 837 | mutex_lock(&adapter->lock); |
| 838 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 839 | } |
| 840 | } else if (psmode->action == cmd_subcmd_exit_ps) { |
| 841 | adapter->needtowakeup = 0; |
| 842 | adapter->psstate = PS_STATE_FULL_POWER; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 843 | lbs_deb_cmd("CMD_RESP: Exit_PS command response\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 844 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 845 | lbs_deb_cmd("CMD_RESP: PS- action=0x%X\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 846 | psmode->action); |
| 847 | } |
| 848 | |
| 849 | __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
| 850 | adapter->nr_cmd_pending--; |
| 851 | adapter->cur_cmd = NULL; |
| 852 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 853 | |
| 854 | ret = 0; |
| 855 | goto done; |
| 856 | } |
| 857 | |
| 858 | if (adapter->cur_cmd->cmdflags & CMD_F_HOSTCMD) { |
| 859 | /* Copy the response back to response buffer */ |
| 860 | memcpy(adapter->cur_cmd->pdata_buf, resp, resp->size); |
| 861 | |
| 862 | adapter->cur_cmd->cmdflags &= ~CMD_F_HOSTCMD; |
| 863 | } |
| 864 | |
| 865 | /* If the command is not successful, cleanup and return failure */ |
| 866 | if ((result != 0 || !(respcmd & 0x8000))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 867 | lbs_deb_cmd("CMD_RESP: command reply %#x result=%#x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 868 | resp->command, resp->result); |
| 869 | /* |
| 870 | * Handling errors here |
| 871 | */ |
| 872 | switch (respcmd) { |
| 873 | case cmd_ret_hw_spec_info: |
| 874 | case cmd_ret_802_11_reset: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 875 | lbs_deb_cmd("CMD_RESP: Reset command failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 876 | break; |
| 877 | |
| 878 | } |
| 879 | |
| 880 | __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
| 881 | adapter->nr_cmd_pending--; |
| 882 | adapter->cur_cmd = NULL; |
| 883 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 884 | |
| 885 | ret = -1; |
| 886 | goto done; |
| 887 | } |
| 888 | |
| 889 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 890 | |
| 891 | ret = handle_cmd_response(respcmd, resp, priv); |
| 892 | |
| 893 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 894 | if (adapter->cur_cmd) { |
| 895 | /* Clean up and Put current command back to cmdfreeq */ |
| 896 | __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd); |
| 897 | adapter->nr_cmd_pending--; |
| 898 | WARN_ON(adapter->nr_cmd_pending > 128); |
| 899 | adapter->cur_cmd = NULL; |
| 900 | } |
| 901 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 902 | |
| 903 | done: |
| 904 | mutex_unlock(&adapter->lock); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 905 | lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 906 | return ret; |
| 907 | } |
| 908 | |
| 909 | int libertas_process_event(wlan_private * priv) |
| 910 | { |
| 911 | int ret = 0; |
| 912 | wlan_adapter *adapter = priv->adapter; |
| 913 | u32 eventcause; |
| 914 | |
| 915 | spin_lock_irq(&adapter->driver_lock); |
| 916 | eventcause = adapter->eventcause; |
| 917 | spin_unlock_irq(&adapter->driver_lock); |
| 918 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 919 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 920 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 921 | lbs_deb_cmd("EVENT Cause %x\n", eventcause); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 922 | |
| 923 | switch (eventcause >> SBI_EVENT_CAUSE_SHIFT) { |
| 924 | case MACREG_INT_CODE_LINK_SENSED: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 925 | lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case MACREG_INT_CODE_DEAUTHENTICATED: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 929 | lbs_deb_cmd("EVENT: Deauthenticated\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 930 | libertas_mac_event_disconnected(priv); |
| 931 | break; |
| 932 | |
| 933 | case MACREG_INT_CODE_DISASSOCIATED: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 934 | lbs_deb_cmd("EVENT: Disassociated\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 935 | libertas_mac_event_disconnected(priv); |
| 936 | break; |
| 937 | |
| 938 | case MACREG_INT_CODE_LINK_LOSE_NO_SCAN: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 939 | lbs_deb_cmd("EVENT: Link lost\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 940 | libertas_mac_event_disconnected(priv); |
| 941 | break; |
| 942 | |
| 943 | case MACREG_INT_CODE_PS_SLEEP: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 944 | lbs_deb_cmd("EVENT: SLEEP\n"); |
| 945 | lbs_deb_cmd("_"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 946 | |
| 947 | /* handle unexpected PS SLEEP event */ |
| 948 | if (adapter->psstate == PS_STATE_FULL_POWER) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 949 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 950 | "EVENT: In FULL POWER mode - ignore PS SLEEP\n"); |
| 951 | break; |
| 952 | } |
| 953 | adapter->psstate = PS_STATE_PRE_SLEEP; |
| 954 | |
| 955 | libertas_ps_confirm_sleep(priv, (u16) adapter->psmode); |
| 956 | |
| 957 | break; |
| 958 | |
| 959 | case MACREG_INT_CODE_PS_AWAKE: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 960 | lbs_deb_cmd("EVENT: AWAKE \n"); |
| 961 | lbs_deb_cmd("|"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 962 | |
| 963 | /* handle unexpected PS AWAKE event */ |
| 964 | if (adapter->psstate == PS_STATE_FULL_POWER) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 965 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 966 | "EVENT: In FULL POWER mode - ignore PS AWAKE\n"); |
| 967 | break; |
| 968 | } |
| 969 | |
| 970 | adapter->psstate = PS_STATE_AWAKE; |
| 971 | |
| 972 | if (adapter->needtowakeup) { |
| 973 | /* |
| 974 | * wait for the command processing to finish |
| 975 | * before resuming sending |
| 976 | * adapter->needtowakeup will be set to FALSE |
| 977 | * in libertas_ps_wakeup() |
| 978 | */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 979 | lbs_deb_cmd("Waking up...\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 980 | libertas_ps_wakeup(priv, 0); |
| 981 | } |
| 982 | break; |
| 983 | |
| 984 | case MACREG_INT_CODE_MIC_ERR_UNICAST: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 985 | lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 986 | handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST); |
| 987 | break; |
| 988 | |
| 989 | case MACREG_INT_CODE_MIC_ERR_MULTICAST: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 990 | lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 991 | handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST); |
| 992 | break; |
| 993 | case MACREG_INT_CODE_MIB_CHANGED: |
| 994 | case MACREG_INT_CODE_INIT_DONE: |
| 995 | break; |
| 996 | |
| 997 | case MACREG_INT_CODE_ADHOC_BCN_LOST: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 998 | lbs_deb_cmd("EVENT: HWAC - ADHOC BCN LOST\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 999 | break; |
| 1000 | |
| 1001 | case MACREG_INT_CODE_RSSI_LOW: |
| 1002 | lbs_pr_alert( "EVENT: RSSI_LOW\n"); |
| 1003 | break; |
| 1004 | case MACREG_INT_CODE_SNR_LOW: |
| 1005 | lbs_pr_alert( "EVENT: SNR_LOW\n"); |
| 1006 | break; |
| 1007 | case MACREG_INT_CODE_MAX_FAIL: |
| 1008 | lbs_pr_alert( "EVENT: MAX_FAIL\n"); |
| 1009 | break; |
| 1010 | case MACREG_INT_CODE_RSSI_HIGH: |
| 1011 | lbs_pr_alert( "EVENT: RSSI_HIGH\n"); |
| 1012 | break; |
| 1013 | case MACREG_INT_CODE_SNR_HIGH: |
| 1014 | lbs_pr_alert( "EVENT: SNR_HIGH\n"); |
| 1015 | break; |
| 1016 | |
| 1017 | default: |
| 1018 | lbs_pr_alert( "EVENT: unknown event id: %#x\n", |
| 1019 | eventcause >> SBI_EVENT_CAUSE_SHIFT); |
| 1020 | break; |
| 1021 | } |
| 1022 | |
| 1023 | spin_lock_irq(&adapter->driver_lock); |
| 1024 | adapter->eventcause = 0; |
| 1025 | spin_unlock_irq(&adapter->driver_lock); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame^] | 1026 | |
| 1027 | lbs_deb_enter_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1028 | return ret; |
| 1029 | } |