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" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 12 | #include "decl.h" |
| 13 | #include "defs.h" |
| 14 | #include "dev.h" |
| 15 | #include "join.h" |
| 16 | #include "wext.h" |
| 17 | |
| 18 | /** |
| 19 | * @brief This function handles disconnect event. it |
| 20 | * reports disconnect to upper layer, clean tx/rx packets, |
| 21 | * reset link state etc. |
| 22 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 23 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 24 | * @return n/a |
| 25 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 26 | void lbs_mac_event_disconnected(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 27 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 28 | union iwreq_data wrqu; |
| 29 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 30 | if (priv->connect_status != LBS_CONNECTED) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 31 | return; |
| 32 | |
Holger Schurig | 9184346 | 2007-11-28 14:05:02 +0100 | [diff] [blame] | 33 | lbs_deb_enter(LBS_DEB_ASSOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 34 | |
| 35 | memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN); |
| 36 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 37 | |
| 38 | /* |
| 39 | * Cisco AP sends EAP failure and de-auth in less than 0.5 ms. |
| 40 | * It causes problem in the Supplicant |
| 41 | */ |
| 42 | |
| 43 | msleep_interruptible(1000); |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 44 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 45 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 46 | /* report disconnect to upper layer */ |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 47 | netif_stop_queue(priv->dev); |
| 48 | netif_carrier_off(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 49 | |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 50 | /* Free Tx and Rx packets */ |
| 51 | kfree_skb(priv->currenttxskb); |
| 52 | priv->currenttxskb = NULL; |
| 53 | priv->tx_pending_len = 0; |
| 54 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 55 | /* reset SNR/NF/RSSI values */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 56 | memset(priv->SNR, 0x00, sizeof(priv->SNR)); |
| 57 | memset(priv->NF, 0x00, sizeof(priv->NF)); |
| 58 | memset(priv->RSSI, 0x00, sizeof(priv->RSSI)); |
| 59 | memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR)); |
| 60 | memset(priv->rawNF, 0x00, sizeof(priv->rawNF)); |
| 61 | priv->nextSNRNF = 0; |
| 62 | priv->numSNRNF = 0; |
| 63 | priv->connect_status = LBS_DISCONNECTED; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 64 | |
Dan Williams | e76850d | 2007-05-25 17:09:41 -0400 | [diff] [blame] | 65 | /* Clear out associated SSID and BSSID since connection is |
| 66 | * no longer valid. |
| 67 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 68 | memset(&priv->curbssparams.bssid, 0, ETH_ALEN); |
| 69 | memset(&priv->curbssparams.ssid, 0, IW_ESSID_MAX_SIZE); |
| 70 | priv->curbssparams.ssid_len = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 71 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 72 | if (priv->psstate != PS_STATE_FULL_POWER) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 73 | /* make firmware to exit PS mode */ |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 74 | lbs_deb_cmd("disconnected, so exit PS mode\n"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 75 | lbs_ps_wakeup(priv, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 76 | } |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 77 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @brief This function handles MIC failure event. |
| 82 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 83 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 84 | * @para event the event id |
| 85 | * @return n/a |
| 86 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 87 | static void handle_mic_failureevent(struct lbs_private *priv, u32 event) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 88 | { |
| 89 | char buf[50]; |
| 90 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 91 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 92 | memset(buf, 0, sizeof(buf)); |
| 93 | |
| 94 | sprintf(buf, "%s", "MLME-MICHAELMICFAILURE.indication "); |
| 95 | |
| 96 | if (event == MACREG_INT_CODE_MIC_ERR_UNICAST) { |
| 97 | strcat(buf, "unicast "); |
| 98 | } else { |
| 99 | strcat(buf, "multicast "); |
| 100 | } |
| 101 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 102 | lbs_send_iwevcustom_event(priv, buf); |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 103 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 104 | } |
| 105 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 106 | static int lbs_ret_reg_access(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 107 | u16 type, struct cmd_ds_command *resp) |
| 108 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 109 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 110 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 111 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 112 | |
| 113 | switch (type) { |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 114 | case CMD_RET(CMD_MAC_REG_ACCESS): |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 115 | { |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 116 | struct cmd_ds_mac_reg_access *reg = &resp->params.macreg; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 117 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 118 | priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset); |
| 119 | priv->offsetvalue.value = le32_to_cpu(reg->value); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 120 | break; |
| 121 | } |
| 122 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 123 | case CMD_RET(CMD_BBP_REG_ACCESS): |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 124 | { |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 125 | struct cmd_ds_bbp_reg_access *reg = &resp->params.bbpreg; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 126 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 127 | priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset); |
| 128 | priv->offsetvalue.value = reg->value; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 129 | break; |
| 130 | } |
| 131 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 132 | case CMD_RET(CMD_RF_REG_ACCESS): |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 133 | { |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 134 | struct cmd_ds_rf_reg_access *reg = &resp->params.rfreg; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 135 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 136 | priv->offsetvalue.offset = (u32)le16_to_cpu(reg->offset); |
| 137 | priv->offsetvalue.value = reg->value; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 138 | break; |
| 139 | } |
| 140 | |
| 141 | default: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 142 | ret = -1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 143 | } |
| 144 | |
Holger Schurig | 8b17d72 | 2007-10-08 11:09:30 +0200 | [diff] [blame] | 145 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 146 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 147 | } |
| 148 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 149 | static int lbs_ret_802_11_stat(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 150 | struct cmd_ds_command *resp) |
| 151 | { |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 152 | lbs_deb_enter(LBS_DEB_CMD); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 153 | /* currently priv->wlan802_11Stat is unused |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 154 | |
| 155 | struct cmd_ds_802_11_get_stat *p11Stat = &resp->params.gstat; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 156 | |
| 157 | // TODO Convert it to Big endian befor copy |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 158 | memcpy(&priv->wlan802_11Stat, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 159 | p11Stat, sizeof(struct cmd_ds_802_11_get_stat)); |
| 160 | */ |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 161 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 162 | return 0; |
| 163 | } |
| 164 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 165 | static int lbs_ret_802_11_snmp_mib(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 166 | struct cmd_ds_command *resp) |
| 167 | { |
| 168 | struct cmd_ds_802_11_snmp_mib *smib = &resp->params.smib; |
| 169 | u16 oid = le16_to_cpu(smib->oid); |
| 170 | u16 querytype = le16_to_cpu(smib->querytype); |
| 171 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 172 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 173 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 174 | lbs_deb_cmd("SNMP_RESP: oid 0x%x, querytype 0x%x\n", oid, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 175 | querytype); |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 176 | lbs_deb_cmd("SNMP_RESP: Buf size %d\n", le16_to_cpu(smib->bufsize)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 177 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 178 | if (querytype == CMD_ACT_GET) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 179 | switch (oid) { |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 180 | case FRAGTHRESH_I: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 181 | priv->fragthsd = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 182 | le16_to_cpu(*((__le16 *)(smib->value))); |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 183 | lbs_deb_cmd("SNMP_RESP: frag threshold %u\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 184 | priv->fragthsd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 185 | break; |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 186 | case RTSTHRESH_I: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 187 | priv->rtsthsd = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 188 | le16_to_cpu(*((__le16 *)(smib->value))); |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 189 | lbs_deb_cmd("SNMP_RESP: rts threshold %u\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 190 | priv->rtsthsd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 191 | break; |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 192 | case SHORT_RETRYLIM_I: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 193 | priv->txretrycount = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 194 | le16_to_cpu(*((__le16 *)(smib->value))); |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 195 | lbs_deb_cmd("SNMP_RESP: tx retry count %u\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 196 | priv->rtsthsd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 197 | break; |
| 198 | default: |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 203 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 207 | static int lbs_ret_802_11_key_material(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 208 | struct cmd_ds_command *resp) |
| 209 | { |
| 210 | struct cmd_ds_802_11_key_material *pkeymaterial = |
| 211 | &resp->params.keymaterial; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 212 | u16 action = le16_to_cpu(pkeymaterial->action); |
| 213 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 214 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 215 | |
| 216 | /* Copy the returned key to driver private data */ |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 217 | if (action == CMD_ACT_GET) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 218 | u8 * buf_ptr = (u8 *) &pkeymaterial->keyParamSet; |
| 219 | u8 * resp_end = (u8 *) (resp + le16_to_cpu(resp->size)); |
| 220 | |
| 221 | while (buf_ptr < resp_end) { |
| 222 | struct MrvlIEtype_keyParamSet * pkeyparamset = |
| 223 | (struct MrvlIEtype_keyParamSet *) buf_ptr; |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 224 | struct enc_key * pkey; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 225 | u16 param_set_len = le16_to_cpu(pkeyparamset->length); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 226 | u16 key_len = le16_to_cpu(pkeyparamset->keylen); |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 227 | u16 key_flags = le16_to_cpu(pkeyparamset->keyinfo); |
| 228 | u16 key_type = le16_to_cpu(pkeyparamset->keytypeid); |
| 229 | u8 * end; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 230 | |
| 231 | end = (u8 *) pkeyparamset + sizeof (pkeyparamset->type) |
| 232 | + sizeof (pkeyparamset->length) |
| 233 | + param_set_len; |
| 234 | /* Make sure we don't access past the end of the IEs */ |
| 235 | if (end > resp_end) |
| 236 | break; |
| 237 | |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 238 | if (key_flags & KEY_INFO_WPA_UNICAST) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 239 | pkey = &priv->wpa_unicast_key; |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 240 | else if (key_flags & KEY_INFO_WPA_MCAST) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 241 | pkey = &priv->wpa_mcast_key; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 242 | else |
| 243 | break; |
| 244 | |
| 245 | /* Copy returned key into driver */ |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 246 | memset(pkey, 0, sizeof(struct enc_key)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 247 | if (key_len > sizeof(pkey->key)) |
| 248 | break; |
Dan Williams | 1443b65 | 2007-08-02 10:45:55 -0400 | [diff] [blame] | 249 | pkey->type = key_type; |
| 250 | pkey->flags = key_flags; |
| 251 | pkey->len = key_len; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 252 | memcpy(pkey->key, pkeyparamset->key, pkey->len); |
| 253 | |
| 254 | buf_ptr = end + 1; |
| 255 | } |
| 256 | } |
| 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 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 262 | static int lbs_ret_802_11_mac_address(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 263 | struct cmd_ds_command *resp) |
| 264 | { |
| 265 | struct cmd_ds_802_11_mac_address *macadd = &resp->params.macadd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 266 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 267 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 268 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 269 | memcpy(priv->current_addr, macadd->macadd, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 270 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 271 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 272 | return 0; |
| 273 | } |
| 274 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 275 | static int lbs_ret_802_11_rf_tx_power(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 276 | struct cmd_ds_command *resp) |
| 277 | { |
| 278 | struct cmd_ds_802_11_rf_tx_power *rtp = &resp->params.txp; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 279 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 280 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 281 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 282 | priv->txpowerlevel = le16_to_cpu(rtp->currentlevel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 283 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 284 | lbs_deb_cmd("TX power currently %d\n", priv->txpowerlevel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 285 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 286 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 290 | static int lbs_ret_802_11_rate_adapt_rateset(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 291 | struct cmd_ds_command *resp) |
| 292 | { |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 293 | struct cmd_ds_802_11_rate_adapt_rateset *rates = &resp->params.rateset; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 294 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 295 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 296 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 297 | if (rates->action == CMD_ACT_GET) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 298 | priv->enablehwauto = le16_to_cpu(rates->enablehwauto); |
| 299 | priv->ratebitmap = le16_to_cpu(rates->bitmap); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 300 | } |
| 301 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 302 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 306 | static int lbs_ret_802_11_rssi(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 307 | struct cmd_ds_command *resp) |
| 308 | { |
| 309 | struct cmd_ds_802_11_rssi_rsp *rssirsp = &resp->params.rssirsp; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 310 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 311 | lbs_deb_enter(LBS_DEB_CMD); |
| 312 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 313 | /* store the non average value */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 314 | priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR); |
| 315 | priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 316 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 317 | priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR); |
| 318 | priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 319 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 320 | priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = |
| 321 | CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG], |
| 322 | priv->NF[TYPE_BEACON][TYPE_NOAVG]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 323 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 324 | priv->RSSI[TYPE_BEACON][TYPE_AVG] = |
| 325 | CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_AVG] / AVG_SCALE, |
| 326 | priv->NF[TYPE_BEACON][TYPE_AVG] / AVG_SCALE); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 327 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 328 | lbs_deb_cmd("RSSI: beacon %d, avg %d\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 329 | priv->RSSI[TYPE_BEACON][TYPE_NOAVG], |
| 330 | priv->RSSI[TYPE_BEACON][TYPE_AVG]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 331 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 332 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 336 | static int lbs_ret_802_11_eeprom_access(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 337 | struct cmd_ds_command *resp) |
| 338 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 339 | struct lbs_ioctl_regrdwr *pbuf; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 340 | pbuf = (struct lbs_ioctl_regrdwr *) priv->prdeeprom; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 341 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 342 | lbs_deb_enter_args(LBS_DEB_CMD, "len %d", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 343 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
| 344 | if (pbuf->NOB < le16_to_cpu(resp->params.rdeeprom.bytecount)) { |
| 345 | pbuf->NOB = 0; |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 346 | lbs_deb_cmd("EEPROM read length too big\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 347 | return -1; |
| 348 | } |
| 349 | pbuf->NOB = le16_to_cpu(resp->params.rdeeprom.bytecount); |
| 350 | if (pbuf->NOB > 0) { |
| 351 | |
| 352 | memcpy(&pbuf->value, (u8 *) & resp->params.rdeeprom.value, |
| 353 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 354 | lbs_deb_hex(LBS_DEB_CMD, "EEPROM", (char *)&pbuf->value, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 355 | le16_to_cpu(resp->params.rdeeprom.bytecount)); |
| 356 | } |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 357 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 361 | static int lbs_ret_get_log(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 362 | struct cmd_ds_command *resp) |
| 363 | { |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 364 | struct cmd_ds_802_11_get_log *logmessage = &resp->params.glog; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 365 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 366 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 367 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 368 | /* Stored little-endian */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 369 | memcpy(&priv->logmsg, logmessage, sizeof(struct cmd_ds_802_11_get_log)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 370 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 371 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | |
Brajesh Dave | 96287ac | 2007-11-20 17:44:28 -0500 | [diff] [blame] | 375 | static int lbs_ret_802_11_bcn_ctrl(struct lbs_private * priv, |
| 376 | struct cmd_ds_command *resp) |
| 377 | { |
| 378 | struct cmd_ds_802_11_beacon_control *bcn_ctrl = |
| 379 | &resp->params.bcn_ctrl; |
Brajesh Dave | 96287ac | 2007-11-20 17:44:28 -0500 | [diff] [blame] | 380 | |
| 381 | lbs_deb_enter(LBS_DEB_CMD); |
| 382 | |
| 383 | if (bcn_ctrl->action == CMD_ACT_GET) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 384 | priv->beacon_enable = (u8) le16_to_cpu(bcn_ctrl->beacon_enable); |
| 385 | priv->beacon_period = le16_to_cpu(bcn_ctrl->beacon_period); |
Brajesh Dave | 96287ac | 2007-11-20 17:44:28 -0500 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | lbs_deb_enter(LBS_DEB_CMD); |
| 389 | return 0; |
| 390 | } |
| 391 | |
David Woodhouse | 1309b55 | 2007-12-10 13:36:10 -0500 | [diff] [blame] | 392 | static inline int handle_cmd_response(struct lbs_private *priv, |
| 393 | unsigned long dummy, |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 394 | struct cmd_header *cmd_response) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 395 | { |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 396 | struct cmd_ds_command *resp = (struct cmd_ds_command *) cmd_response; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 397 | int ret = 0; |
| 398 | unsigned long flags; |
David Woodhouse | 1309b55 | 2007-12-10 13:36:10 -0500 | [diff] [blame] | 399 | uint16_t respcmd = le16_to_cpu(resp->command); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 400 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 401 | lbs_deb_enter(LBS_DEB_HOST); |
| 402 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 403 | switch (respcmd) { |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 404 | case CMD_RET(CMD_MAC_REG_ACCESS): |
| 405 | case CMD_RET(CMD_BBP_REG_ACCESS): |
| 406 | case CMD_RET(CMD_RF_REG_ACCESS): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 407 | ret = lbs_ret_reg_access(priv, respcmd, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 408 | break; |
| 409 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 410 | case CMD_RET(CMD_802_11_SCAN): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 411 | ret = lbs_ret_80211_scan(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 412 | break; |
| 413 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 414 | case CMD_RET(CMD_802_11_GET_LOG): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 415 | ret = lbs_ret_get_log(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 416 | break; |
| 417 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 418 | case CMD_RET_802_11_ASSOCIATE: |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 419 | case CMD_RET(CMD_802_11_ASSOCIATE): |
| 420 | case CMD_RET(CMD_802_11_REASSOCIATE): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 421 | ret = lbs_ret_80211_associate(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 422 | break; |
| 423 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 424 | case CMD_RET(CMD_802_11_DISASSOCIATE): |
| 425 | case CMD_RET(CMD_802_11_DEAUTHENTICATE): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 426 | ret = lbs_ret_80211_disassociate(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 427 | break; |
| 428 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 429 | case CMD_RET(CMD_802_11_AD_HOC_START): |
| 430 | case CMD_RET(CMD_802_11_AD_HOC_JOIN): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 431 | ret = lbs_ret_80211_ad_hoc_start(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 432 | break; |
| 433 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 434 | case CMD_RET(CMD_802_11_GET_STAT): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 435 | ret = lbs_ret_802_11_stat(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 436 | break; |
| 437 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 438 | case CMD_RET(CMD_802_11_SNMP_MIB): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 439 | ret = lbs_ret_802_11_snmp_mib(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 440 | break; |
| 441 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 442 | case CMD_RET(CMD_802_11_RF_TX_POWER): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 443 | ret = lbs_ret_802_11_rf_tx_power(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 444 | break; |
| 445 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 446 | case CMD_RET(CMD_802_11_SET_AFC): |
| 447 | case CMD_RET(CMD_802_11_GET_AFC): |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 448 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | 7556767 | 2007-12-15 02:38:17 -0500 | [diff] [blame] | 449 | memmove((void *)priv->cur_cmd->callback_arg, &resp->params.afc, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 450 | sizeof(struct cmd_ds_802_11_afc)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 451 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 452 | |
| 453 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 454 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 455 | case CMD_RET(CMD_MAC_MULTICAST_ADR): |
| 456 | case CMD_RET(CMD_MAC_CONTROL): |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 457 | case CMD_RET(CMD_802_11_RESET): |
| 458 | case CMD_RET(CMD_802_11_AUTHENTICATE): |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 459 | case CMD_RET(CMD_802_11_BEACON_STOP): |
Dan Williams | 18c96c34 | 2007-06-18 12:01:12 -0400 | [diff] [blame] | 460 | break; |
| 461 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 462 | case CMD_RET(CMD_802_11_RATE_ADAPT_RATESET): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 463 | ret = lbs_ret_802_11_rate_adapt_rateset(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 464 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 465 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 466 | case CMD_RET(CMD_802_11_RSSI): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 467 | ret = lbs_ret_802_11_rssi(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 468 | break; |
| 469 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 470 | case CMD_RET(CMD_802_11_MAC_ADDRESS): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 471 | ret = lbs_ret_802_11_mac_address(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 472 | break; |
| 473 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 474 | case CMD_RET(CMD_802_11_AD_HOC_STOP): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 475 | ret = lbs_ret_80211_ad_hoc_stop(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 476 | break; |
| 477 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 478 | case CMD_RET(CMD_802_11_KEY_MATERIAL): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 479 | ret = lbs_ret_802_11_key_material(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 480 | break; |
| 481 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 482 | case CMD_RET(CMD_802_11_EEPROM_ACCESS): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 483 | ret = lbs_ret_802_11_eeprom_access(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 484 | break; |
| 485 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 486 | case CMD_RET(CMD_802_11D_DOMAIN_INFO): |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 487 | ret = lbs_ret_802_11d_domain_info(priv, resp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 488 | break; |
| 489 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 490 | case CMD_RET(CMD_802_11_TPC_CFG): |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 491 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | 7556767 | 2007-12-15 02:38:17 -0500 | [diff] [blame] | 492 | memmove((void *)priv->cur_cmd->callback_arg, &resp->params.tpccfg, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 493 | sizeof(struct cmd_ds_802_11_tpc_cfg)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 494 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 495 | break; |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 496 | case CMD_RET(CMD_802_11_LED_GPIO_CTRL): |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 497 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | 7556767 | 2007-12-15 02:38:17 -0500 | [diff] [blame] | 498 | memmove((void *)priv->cur_cmd->callback_arg, &resp->params.ledgpio, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 499 | sizeof(struct cmd_ds_802_11_led_ctrl)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 500 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 501 | break; |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 502 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 503 | case CMD_RET(CMD_802_11_PWR_CFG): |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 504 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | 7556767 | 2007-12-15 02:38:17 -0500 | [diff] [blame] | 505 | memmove((void *)priv->cur_cmd->callback_arg, &resp->params.pwrcfg, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 506 | sizeof(struct cmd_ds_802_11_pwr_cfg)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 507 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 508 | |
| 509 | break; |
| 510 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 511 | case CMD_RET(CMD_GET_TSF): |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 512 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | 7556767 | 2007-12-15 02:38:17 -0500 | [diff] [blame] | 513 | memcpy((void *)priv->cur_cmd->callback_arg, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 514 | &resp->params.gettsf.tsfvalue, sizeof(u64)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 515 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 516 | break; |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 517 | case CMD_RET(CMD_BT_ACCESS): |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 518 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | 7556767 | 2007-12-15 02:38:17 -0500 | [diff] [blame] | 519 | if (priv->cur_cmd->callback_arg) |
| 520 | memcpy((void *)priv->cur_cmd->callback_arg, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 521 | &resp->params.bt.addr1, 2 * ETH_ALEN); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 522 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 523 | break; |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 524 | case CMD_RET(CMD_FWT_ACCESS): |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 525 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | 7556767 | 2007-12-15 02:38:17 -0500 | [diff] [blame] | 526 | if (priv->cur_cmd->callback_arg) |
| 527 | memcpy((void *)priv->cur_cmd->callback_arg, &resp->params.fwt, |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 528 | sizeof(resp->params.fwt)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 529 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 530 | break; |
Brajesh Dave | 96287ac | 2007-11-20 17:44:28 -0500 | [diff] [blame] | 531 | case CMD_RET(CMD_802_11_BEACON_CTRL): |
| 532 | ret = lbs_ret_802_11_bcn_ctrl(priv, resp); |
| 533 | break; |
| 534 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 535 | default: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 536 | lbs_deb_host("CMD_RESP: unknown cmd response 0x%04x\n", |
David Woodhouse | e125817 | 2007-12-11 23:42:49 -0500 | [diff] [blame] | 537 | le16_to_cpu(resp->command)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 538 | break; |
| 539 | } |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 540 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 541 | return ret; |
| 542 | } |
| 543 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 544 | int lbs_process_rx_command(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 545 | { |
David Woodhouse | e125817 | 2007-12-11 23:42:49 -0500 | [diff] [blame] | 546 | uint16_t respcmd, curcmd; |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 547 | struct cmd_header *resp; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 548 | int ret = 0; |
David Woodhouse | e125817 | 2007-12-11 23:42:49 -0500 | [diff] [blame] | 549 | unsigned long flags; |
| 550 | uint16_t result; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 551 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 552 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 553 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 554 | mutex_lock(&priv->lock); |
| 555 | spin_lock_irqsave(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 556 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 557 | if (!priv->cur_cmd) { |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 558 | lbs_deb_host("CMD_RESP: cur_cmd is NULL\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 559 | ret = -1; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 560 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 561 | goto done; |
| 562 | } |
David Woodhouse | e125817 | 2007-12-11 23:42:49 -0500 | [diff] [blame] | 563 | |
David Woodhouse | 7003b07 | 2007-12-17 15:22:43 -0500 | [diff] [blame] | 564 | resp = (void *)priv->upld_buf; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 565 | |
David Woodhouse | ac4cced | 2007-12-17 15:12:49 -0500 | [diff] [blame] | 566 | curcmd = le16_to_cpu(resp->command); |
| 567 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 568 | respcmd = le16_to_cpu(resp->command); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 569 | result = le16_to_cpu(resp->result); |
| 570 | |
David Woodhouse | e125817 | 2007-12-11 23:42:49 -0500 | [diff] [blame] | 571 | lbs_deb_host("CMD_RESP: response 0x%04x, seq %d, size %d, jiffies %lu\n", |
| 572 | respcmd, le16_to_cpu(resp->seqnum), priv->upld_len, jiffies); |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 573 | lbs_deb_hex(LBS_DEB_HOST, "CMD_RESP", (void *) resp, priv->upld_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 574 | |
David Woodhouse | 6305f49 | 2008-03-03 12:20:12 +0100 | [diff] [blame^] | 575 | if (resp->seqnum != priv->cur_cmd->cmdbuf->seqnum) { |
David Woodhouse | e125817 | 2007-12-11 23:42:49 -0500 | [diff] [blame] | 576 | lbs_pr_info("Received CMD_RESP with invalid sequence %d (expected %d)\n", |
David Woodhouse | 6305f49 | 2008-03-03 12:20:12 +0100 | [diff] [blame^] | 577 | le16_to_cpu(resp->seqnum), le16_to_cpu(priv->cur_cmd->cmdbuf->seqnum)); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 578 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 579 | ret = -1; |
| 580 | goto done; |
| 581 | } |
David Woodhouse | e125817 | 2007-12-11 23:42:49 -0500 | [diff] [blame] | 582 | if (respcmd != CMD_RET(curcmd) && |
| 583 | respcmd != CMD_802_11_ASSOCIATE && curcmd != CMD_RET_802_11_ASSOCIATE) { |
| 584 | lbs_pr_info("Invalid CMD_RESP %x to command %x!\n", respcmd, curcmd); |
| 585 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 586 | ret = -1; |
| 587 | goto done; |
| 588 | } |
| 589 | |
David Woodhouse | 8538823 | 2007-12-17 15:41:30 -0500 | [diff] [blame] | 590 | if (resp->result == cpu_to_le16(0x0004)) { |
| 591 | /* 0x0004 means -EAGAIN. Drop the response, let it time out |
| 592 | and be resubmitted */ |
| 593 | lbs_pr_info("Firmware returns DEFER to command %x. Will let it time out...\n", |
| 594 | le16_to_cpu(resp->command)); |
| 595 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 596 | ret = -1; |
| 597 | goto done; |
| 598 | } |
| 599 | |
David Woodhouse | e125817 | 2007-12-11 23:42:49 -0500 | [diff] [blame] | 600 | /* Now we got response from FW, cancel the command timer */ |
| 601 | del_timer(&priv->command_timer); |
David Woodhouse | 2a34509 | 2007-12-15 19:33:43 -0500 | [diff] [blame] | 602 | priv->cmd_timed_out = 0; |
| 603 | if (priv->nr_retries) { |
| 604 | lbs_pr_info("Received result %x to command %x after %d retries\n", |
| 605 | result, curcmd, priv->nr_retries); |
| 606 | priv->nr_retries = 0; |
| 607 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 608 | |
| 609 | /* Store the response code to cur_cmd_retcode. */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 610 | priv->cur_cmd_retcode = result; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 611 | |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 612 | if (respcmd == CMD_RET(CMD_802_11_PS_MODE)) { |
David Woodhouse | 38bfab1 | 2007-12-16 23:26:54 -0500 | [diff] [blame] | 613 | struct cmd_ds_802_11_ps_mode *psmode = (void *) &resp[1]; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 614 | u16 action = le16_to_cpu(psmode->action); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 615 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 616 | lbs_deb_host( |
| 617 | "CMD_RESP: PS_MODE cmd reply result 0x%x, action 0x%x\n", |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 618 | result, action); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 619 | |
| 620 | if (result) { |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 621 | lbs_deb_host("CMD_RESP: PS command failed with 0x%x\n", |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 622 | result); |
| 623 | /* |
| 624 | * We should not re-try enter-ps command in |
| 625 | * ad-hoc mode. It takes place in |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 626 | * lbs_execute_next_command(). |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 627 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 628 | if (priv->mode == IW_MODE_ADHOC && |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 629 | action == CMD_SUBCMD_ENTER_PS) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 630 | priv->psmode = LBS802_11POWERMODECAM; |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 631 | } else if (action == CMD_SUBCMD_ENTER_PS) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 632 | priv->needtowakeup = 0; |
| 633 | priv->psstate = PS_STATE_AWAKE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 634 | |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 635 | lbs_deb_host("CMD_RESP: ENTER_PS command response\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 636 | if (priv->connect_status != LBS_CONNECTED) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 637 | /* |
| 638 | * When Deauth Event received before Enter_PS command |
| 639 | * response, We need to wake up the firmware. |
| 640 | */ |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 641 | lbs_deb_host( |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 642 | "disconnected, invoking lbs_ps_wakeup\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 643 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 644 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 645 | mutex_unlock(&priv->lock); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 646 | lbs_ps_wakeup(priv, 0); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 647 | mutex_lock(&priv->lock); |
| 648 | spin_lock_irqsave(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 649 | } |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 650 | } else if (action == CMD_SUBCMD_EXIT_PS) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 651 | priv->needtowakeup = 0; |
| 652 | priv->psstate = PS_STATE_FULL_POWER; |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 653 | lbs_deb_host("CMD_RESP: EXIT_PS command response\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 654 | } else { |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 655 | lbs_deb_host("CMD_RESP: PS action 0x%X\n", action); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 656 | } |
| 657 | |
David Woodhouse | 183aeac | 2007-12-15 01:52:54 -0500 | [diff] [blame] | 658 | lbs_complete_command(priv, priv->cur_cmd, result); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 659 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 660 | |
| 661 | ret = 0; |
| 662 | goto done; |
| 663 | } |
| 664 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 665 | /* If the command is not successful, cleanup and return failure */ |
| 666 | if ((result != 0 || !(respcmd & 0x8000))) { |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 667 | lbs_deb_host("CMD_RESP: error 0x%04x in command reply 0x%04x\n", |
| 668 | result, respcmd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 669 | /* |
| 670 | * Handling errors here |
| 671 | */ |
| 672 | switch (respcmd) { |
Holger Schurig | 6b63cd0 | 2007-08-02 11:53:36 -0400 | [diff] [blame] | 673 | case CMD_RET(CMD_GET_HW_SPEC): |
| 674 | case CMD_RET(CMD_802_11_RESET): |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 675 | lbs_deb_host("CMD_RESP: reset failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 676 | break; |
| 677 | |
| 678 | } |
David Woodhouse | 183aeac | 2007-12-15 01:52:54 -0500 | [diff] [blame] | 679 | lbs_complete_command(priv, priv->cur_cmd, result); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 680 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 681 | |
| 682 | ret = -1; |
| 683 | goto done; |
| 684 | } |
| 685 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 686 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
David Woodhouse | 1723047 | 2007-12-07 15:13:05 +0000 | [diff] [blame] | 687 | |
Dan Williams | 7ad994d | 2007-12-11 12:33:30 -0500 | [diff] [blame] | 688 | if (priv->cur_cmd && priv->cur_cmd->callback) { |
| 689 | ret = priv->cur_cmd->callback(priv, priv->cur_cmd->callback_arg, |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 690 | resp); |
Dan Williams | 7ad994d | 2007-12-11 12:33:30 -0500 | [diff] [blame] | 691 | } else |
David Woodhouse | 1309b55 | 2007-12-10 13:36:10 -0500 | [diff] [blame] | 692 | ret = handle_cmd_response(priv, 0, resp); |
David Woodhouse | 1723047 | 2007-12-07 15:13:05 +0000 | [diff] [blame] | 693 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 694 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | 1723047 | 2007-12-07 15:13:05 +0000 | [diff] [blame] | 695 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 696 | if (priv->cur_cmd) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 697 | /* Clean up and Put current command back to cmdfreeq */ |
David Woodhouse | 183aeac | 2007-12-15 01:52:54 -0500 | [diff] [blame] | 698 | lbs_complete_command(priv, priv->cur_cmd, result); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 699 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 700 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 701 | |
| 702 | done: |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 703 | mutex_unlock(&priv->lock); |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 704 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 705 | return ret; |
| 706 | } |
| 707 | |
David Woodhouse | b47ef24 | 2007-12-17 13:26:42 -0500 | [diff] [blame] | 708 | static int lbs_send_confirmwake(struct lbs_private *priv) |
| 709 | { |
| 710 | struct cmd_header *cmd = &priv->lbs_ps_confirm_wake; |
| 711 | int ret = 0; |
| 712 | |
| 713 | lbs_deb_enter(LBS_DEB_HOST); |
| 714 | |
| 715 | cmd->command = cpu_to_le16(CMD_802_11_WAKEUP_CONFIRM); |
| 716 | cmd->size = cpu_to_le16(sizeof(*cmd)); |
| 717 | cmd->seqnum = cpu_to_le16(++priv->seqnum); |
| 718 | cmd->result = 0; |
| 719 | |
| 720 | lbs_deb_host("SEND_WAKEC_CMD: before download\n"); |
| 721 | |
| 722 | lbs_deb_hex(LBS_DEB_HOST, "wake confirm command", (void *)cmd, sizeof(*cmd)); |
| 723 | |
| 724 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (void *)cmd, sizeof(*cmd)); |
| 725 | if (ret) |
| 726 | lbs_pr_alert("SEND_WAKEC_CMD: Host to Card failed for Confirm Wake\n"); |
| 727 | |
| 728 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
| 729 | return ret; |
| 730 | } |
| 731 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 732 | int lbs_process_event(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 733 | { |
| 734 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 735 | u32 eventcause; |
| 736 | |
Holger Schurig | 9556d21 | 2007-08-02 13:14:07 -0400 | [diff] [blame] | 737 | lbs_deb_enter(LBS_DEB_CMD); |
| 738 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 739 | spin_lock_irq(&priv->driver_lock); |
| 740 | eventcause = priv->eventcause >> SBI_EVENT_CAUSE_SHIFT; |
| 741 | spin_unlock_irq(&priv->driver_lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 742 | |
Holger Schurig | 0b3c07f | 2007-11-28 09:15:11 +0100 | [diff] [blame] | 743 | lbs_deb_cmd("event cause %d\n", eventcause); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 744 | |
Holger Schurig | 0b3c07f | 2007-11-28 09:15:11 +0100 | [diff] [blame] | 745 | switch (eventcause) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 746 | case MACREG_INT_CODE_LINK_SENSED: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 747 | lbs_deb_cmd("EVENT: MACREG_INT_CODE_LINK_SENSED\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case MACREG_INT_CODE_DEAUTHENTICATED: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 751 | lbs_deb_cmd("EVENT: deauthenticated\n"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 752 | lbs_mac_event_disconnected(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 753 | break; |
| 754 | |
| 755 | case MACREG_INT_CODE_DISASSOCIATED: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 756 | lbs_deb_cmd("EVENT: disassociated\n"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 757 | lbs_mac_event_disconnected(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 758 | break; |
| 759 | |
Holger Schurig | 0b3c07f | 2007-11-28 09:15:11 +0100 | [diff] [blame] | 760 | case MACREG_INT_CODE_LINK_LOST_NO_SCAN: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 761 | lbs_deb_cmd("EVENT: link lost\n"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 762 | lbs_mac_event_disconnected(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case MACREG_INT_CODE_PS_SLEEP: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 766 | lbs_deb_cmd("EVENT: sleep\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 767 | |
| 768 | /* handle unexpected PS SLEEP event */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 769 | if (priv->psstate == PS_STATE_FULL_POWER) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 770 | lbs_deb_cmd( |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 771 | "EVENT: in FULL POWER mode, ignoreing PS_SLEEP\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 772 | break; |
| 773 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 774 | priv->psstate = PS_STATE_PRE_SLEEP; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 775 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 776 | lbs_ps_confirm_sleep(priv, (u16) priv->psmode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 777 | |
| 778 | break; |
| 779 | |
David Woodhouse | b47ef24 | 2007-12-17 13:26:42 -0500 | [diff] [blame] | 780 | case MACREG_INT_CODE_HOST_AWAKE: |
| 781 | lbs_deb_cmd("EVENT: HOST_AWAKE\n"); |
| 782 | lbs_send_confirmwake(priv); |
| 783 | break; |
| 784 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 785 | case MACREG_INT_CODE_PS_AWAKE: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 786 | lbs_deb_cmd("EVENT: awake\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 787 | /* handle unexpected PS AWAKE event */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 788 | if (priv->psstate == PS_STATE_FULL_POWER) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 789 | lbs_deb_cmd( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 790 | "EVENT: In FULL POWER mode - ignore PS AWAKE\n"); |
| 791 | break; |
| 792 | } |
| 793 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 794 | priv->psstate = PS_STATE_AWAKE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 795 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 796 | if (priv->needtowakeup) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 797 | /* |
| 798 | * wait for the command processing to finish |
| 799 | * before resuming sending |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 800 | * priv->needtowakeup will be set to FALSE |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 801 | * in lbs_ps_wakeup() |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 802 | */ |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 803 | lbs_deb_cmd("waking up ...\n"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 804 | lbs_ps_wakeup(priv, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 805 | } |
| 806 | break; |
| 807 | |
| 808 | case MACREG_INT_CODE_MIC_ERR_UNICAST: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 809 | lbs_deb_cmd("EVENT: UNICAST MIC ERROR\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 810 | handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_UNICAST); |
| 811 | break; |
| 812 | |
| 813 | case MACREG_INT_CODE_MIC_ERR_MULTICAST: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 814 | lbs_deb_cmd("EVENT: MULTICAST MIC ERROR\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 815 | handle_mic_failureevent(priv, MACREG_INT_CODE_MIC_ERR_MULTICAST); |
| 816 | break; |
| 817 | case MACREG_INT_CODE_MIB_CHANGED: |
| 818 | case MACREG_INT_CODE_INIT_DONE: |
| 819 | break; |
| 820 | |
| 821 | case MACREG_INT_CODE_ADHOC_BCN_LOST: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 822 | lbs_deb_cmd("EVENT: ADHOC beacon lost\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 823 | break; |
| 824 | |
| 825 | case MACREG_INT_CODE_RSSI_LOW: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 826 | lbs_pr_alert("EVENT: rssi low\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 827 | break; |
| 828 | case MACREG_INT_CODE_SNR_LOW: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 829 | lbs_pr_alert("EVENT: snr low\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 830 | break; |
| 831 | case MACREG_INT_CODE_MAX_FAIL: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 832 | lbs_pr_alert("EVENT: max fail\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 833 | break; |
| 834 | case MACREG_INT_CODE_RSSI_HIGH: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 835 | lbs_pr_alert("EVENT: rssi high\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 836 | break; |
| 837 | case MACREG_INT_CODE_SNR_HIGH: |
Holger Schurig | a6c8700 | 2007-08-02 11:54:10 -0400 | [diff] [blame] | 838 | lbs_pr_alert("EVENT: snr high\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 839 | break; |
| 840 | |
Luis Carlos Cobo Rus | 7d8d28b | 2007-05-25 23:12:19 -0400 | [diff] [blame] | 841 | case MACREG_INT_CODE_MESH_AUTO_STARTED: |
Dan Williams | 5612c01 | 2007-08-02 13:20:12 -0400 | [diff] [blame] | 842 | /* Ignore spurious autostart events if autostart is disabled */ |
| 843 | if (!priv->mesh_autostart_enabled) { |
| 844 | lbs_pr_info("EVENT: MESH_AUTO_STARTED (ignoring)\n"); |
| 845 | break; |
| 846 | } |
Luis Carlos Cobo | 9cdc6d2 | 2007-08-02 11:55:22 -0400 | [diff] [blame] | 847 | lbs_pr_info("EVENT: MESH_AUTO_STARTED\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 848 | priv->mesh_connect_status = LBS_CONNECTED; |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 849 | if (priv->mesh_open) { |
Luis Carlos Cobo | 9cdc6d2 | 2007-08-02 11:55:22 -0400 | [diff] [blame] | 850 | netif_carrier_on(priv->mesh_dev); |
David Woodhouse | a27b9f9 | 2007-12-12 00:41:51 -0500 | [diff] [blame] | 851 | if (!priv->tx_pending_len) |
| 852 | netif_wake_queue(priv->mesh_dev); |
Luis Carlos Cobo Rus | 7d8d28b | 2007-05-25 23:12:19 -0400 | [diff] [blame] | 853 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 854 | priv->mode = IW_MODE_ADHOC; |
Luis Carlos Cobo Rus | b8bedef | 2007-05-30 12:14:34 -0400 | [diff] [blame] | 855 | schedule_work(&priv->sync_channel); |
Luis Carlos Cobo Rus | 7d8d28b | 2007-05-25 23:12:19 -0400 | [diff] [blame] | 856 | break; |
| 857 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 858 | default: |
Holger Schurig | 0b3c07f | 2007-11-28 09:15:11 +0100 | [diff] [blame] | 859 | lbs_pr_alert("EVENT: unknown event id %d\n", eventcause); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 860 | break; |
| 861 | } |
| 862 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 863 | spin_lock_irq(&priv->driver_lock); |
| 864 | priv->eventcause = 0; |
| 865 | spin_unlock_irq(&priv->driver_lock); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 866 | |
Holger Schurig | 9556d21 | 2007-08-02 13:14:07 -0400 | [diff] [blame] | 867 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 868 | return ret; |
| 869 | } |