~ubuntu-branches/ubuntu/precise/linux-lowlatency/precise

« back to all changes in this revision

Viewing changes to drivers/net/wireless/mwifiex/sta_cmd.c

  • Committer: Package Import Robot
  • Author(s): Alessio Igor Bogani
  • Date: 2011-10-26 11:13:05 UTC
  • Revision ID: package-import@ubuntu.com-20111026111305-tz023xykf0i6eosh
Tags: upstream-3.2.0
ImportĀ upstreamĀ versionĀ 3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Marvell Wireless LAN device driver: station command handling
 
3
 *
 
4
 * Copyright (C) 2011, Marvell International Ltd.
 
5
 *
 
6
 * This software file (the "File") is distributed by Marvell International
 
7
 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
 
8
 * (the "License").  You may use, redistribute and/or modify this File in
 
9
 * accordance with the terms and conditions of the License, a copy of which
 
10
 * is available by writing to the Free Software Foundation, Inc.,
 
11
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
 
12
 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
 
13
 *
 
14
 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
 
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
 
16
 * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
 
17
 * this warranty disclaimer.
 
18
 */
 
19
 
 
20
#include "decl.h"
 
21
#include "ioctl.h"
 
22
#include "util.h"
 
23
#include "fw.h"
 
24
#include "main.h"
 
25
#include "wmm.h"
 
26
#include "11n.h"
 
27
 
 
28
/*
 
29
 * This function prepares command to set/get RSSI information.
 
30
 *
 
31
 * Preparation includes -
 
32
 *      - Setting command ID, action and proper size
 
33
 *      - Setting data/beacon average factors
 
34
 *      - Resetting SNR/NF/RSSI values in private structure
 
35
 *      - Ensuring correct endian-ness
 
36
 */
 
37
static int
 
38
mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
 
39
                             struct host_cmd_ds_command *cmd, u16 cmd_action)
 
40
{
 
41
        cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
 
42
        cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
 
43
                                S_DS_GEN);
 
44
        cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
 
45
        cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
 
46
        cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
 
47
 
 
48
        /* Reset SNR/NF/RSSI values in private structure */
 
49
        priv->data_rssi_last = 0;
 
50
        priv->data_nf_last = 0;
 
51
        priv->data_rssi_avg = 0;
 
52
        priv->data_nf_avg = 0;
 
53
        priv->bcn_rssi_last = 0;
 
54
        priv->bcn_nf_last = 0;
 
55
        priv->bcn_rssi_avg = 0;
 
56
        priv->bcn_nf_avg = 0;
 
57
 
 
58
        return 0;
 
59
}
 
60
 
 
61
/*
 
62
 * This function prepares command to set MAC control.
 
63
 *
 
64
 * Preparation includes -
 
65
 *      - Setting command ID, action and proper size
 
66
 *      - Ensuring correct endian-ness
 
67
 */
 
68
static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
 
69
                                   struct host_cmd_ds_command *cmd,
 
70
                                   u16 cmd_action, u16 *action)
 
71
{
 
72
        struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
 
73
 
 
74
        if (cmd_action != HostCmd_ACT_GEN_SET) {
 
75
                dev_err(priv->adapter->dev,
 
76
                        "mac_control: only support set cmd\n");
 
77
                return -1;
 
78
        }
 
79
 
 
80
        cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
 
81
        cmd->size =
 
82
                cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
 
83
        mac_ctrl->action = cpu_to_le16(*action);
 
84
 
 
85
        return 0;
 
86
}
 
87
 
 
88
/*
 
89
 * This function prepares command to set/get SNMP MIB.
 
90
 *
 
91
 * Preparation includes -
 
92
 *      - Setting command ID, action and proper size
 
93
 *      - Setting SNMP MIB OID number and value
 
94
 *        (as required)
 
95
 *      - Ensuring correct endian-ness
 
96
 *
 
97
 * The following SNMP MIB OIDs are supported -
 
98
 *      - FRAG_THRESH_I     : Fragmentation threshold
 
99
 *      - RTS_THRESH_I      : RTS threshold
 
100
 *      - SHORT_RETRY_LIM_I : Short retry limit
 
101
 *      - DOT11D_I          : 11d support
 
102
 */
 
103
static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
 
104
                                       struct host_cmd_ds_command *cmd,
 
105
                                       u16 cmd_action, u32 cmd_oid,
 
106
                                       u32 *ul_temp)
 
107
{
 
108
        struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
 
109
 
 
110
        dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
 
111
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
 
112
        cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
 
113
                - 1 + S_DS_GEN);
 
114
 
 
115
        if (cmd_action == HostCmd_ACT_GEN_GET) {
 
116
                snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
 
117
                snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
 
118
                cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
 
119
                        + MAX_SNMP_BUF_SIZE);
 
120
        }
 
121
 
 
122
        switch (cmd_oid) {
 
123
        case FRAG_THRESH_I:
 
124
                snmp_mib->oid = cpu_to_le16((u16) FRAG_THRESH_I);
 
125
                if (cmd_action == HostCmd_ACT_GEN_SET) {
 
126
                        snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
 
127
                        snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
 
128
                        *((__le16 *) (snmp_mib->value)) =
 
129
                                cpu_to_le16((u16) *ul_temp);
 
130
                        cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
 
131
                                + sizeof(u16));
 
132
                }
 
133
                break;
 
134
        case RTS_THRESH_I:
 
135
                snmp_mib->oid = cpu_to_le16((u16) RTS_THRESH_I);
 
136
                if (cmd_action == HostCmd_ACT_GEN_SET) {
 
137
                        snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
 
138
                        snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
 
139
                        *(__le16 *) (snmp_mib->value) =
 
140
                                cpu_to_le16((u16) *ul_temp);
 
141
                        cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
 
142
                                + sizeof(u16));
 
143
                }
 
144
                break;
 
145
 
 
146
        case SHORT_RETRY_LIM_I:
 
147
                snmp_mib->oid = cpu_to_le16((u16) SHORT_RETRY_LIM_I);
 
148
                if (cmd_action == HostCmd_ACT_GEN_SET) {
 
149
                        snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
 
150
                        snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
 
151
                        *((__le16 *) (snmp_mib->value)) =
 
152
                                cpu_to_le16((u16) *ul_temp);
 
153
                        cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
 
154
                                + sizeof(u16));
 
155
                }
 
156
                break;
 
157
        case DOT11D_I:
 
158
                snmp_mib->oid = cpu_to_le16((u16) DOT11D_I);
 
159
                if (cmd_action == HostCmd_ACT_GEN_SET) {
 
160
                        snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
 
161
                        snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
 
162
                        *((__le16 *) (snmp_mib->value)) =
 
163
                                cpu_to_le16((u16) *ul_temp);
 
164
                        cmd->size = cpu_to_le16(le16_to_cpu(cmd->size)
 
165
                                + sizeof(u16));
 
166
                }
 
167
                break;
 
168
        default:
 
169
                break;
 
170
        }
 
171
        dev_dbg(priv->adapter->dev,
 
172
                "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
 
173
                " Value=0x%x\n",
 
174
               cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
 
175
               le16_to_cpu(*(__le16 *) snmp_mib->value));
 
176
        return 0;
 
177
}
 
178
 
 
179
/*
 
180
 * This function prepares command to get log.
 
181
 *
 
182
 * Preparation includes -
 
183
 *      - Setting command ID and proper size
 
184
 *      - Ensuring correct endian-ness
 
185
 */
 
186
static int
 
187
mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
 
188
{
 
189
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
 
190
        cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
 
191
                                S_DS_GEN);
 
192
        return 0;
 
193
}
 
194
 
 
195
/*
 
196
 * This function prepares command to set/get Tx data rate configuration.
 
197
 *
 
198
 * Preparation includes -
 
199
 *      - Setting command ID, action and proper size
 
200
 *      - Setting configuration index, rate scope and rate drop pattern
 
201
 *        parameters (as required)
 
202
 *      - Ensuring correct endian-ness
 
203
 */
 
204
static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
 
205
                                   struct host_cmd_ds_command *cmd,
 
206
                                   u16 cmd_action, u16 *pbitmap_rates)
 
207
{
 
208
        struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
 
209
        struct mwifiex_rate_scope *rate_scope;
 
210
        struct mwifiex_rate_drop_pattern *rate_drop;
 
211
        u32 i;
 
212
 
 
213
        cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
 
214
 
 
215
        rate_cfg->action = cpu_to_le16(cmd_action);
 
216
        rate_cfg->cfg_index = 0;
 
217
 
 
218
        rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
 
219
                      sizeof(struct host_cmd_ds_tx_rate_cfg));
 
220
        rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
 
221
        rate_scope->length = cpu_to_le16(sizeof(struct mwifiex_rate_scope) -
 
222
                        sizeof(struct mwifiex_ie_types_header));
 
223
        if (pbitmap_rates != NULL) {
 
224
                rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
 
225
                rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
 
226
                for (i = 0;
 
227
                     i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
 
228
                     i++)
 
229
                        rate_scope->ht_mcs_rate_bitmap[i] =
 
230
                                cpu_to_le16(pbitmap_rates[2 + i]);
 
231
        } else {
 
232
                rate_scope->hr_dsss_rate_bitmap =
 
233
                        cpu_to_le16(priv->bitmap_rates[0]);
 
234
                rate_scope->ofdm_rate_bitmap =
 
235
                        cpu_to_le16(priv->bitmap_rates[1]);
 
236
                for (i = 0;
 
237
                     i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
 
238
                     i++)
 
239
                        rate_scope->ht_mcs_rate_bitmap[i] =
 
240
                                cpu_to_le16(priv->bitmap_rates[2 + i]);
 
241
        }
 
242
 
 
243
        rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
 
244
                        sizeof(struct mwifiex_rate_scope));
 
245
        rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
 
246
        rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
 
247
        rate_drop->rate_drop_mode = 0;
 
248
 
 
249
        cmd->size =
 
250
                cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
 
251
                            sizeof(struct mwifiex_rate_scope) +
 
252
                            sizeof(struct mwifiex_rate_drop_pattern));
 
253
 
 
254
        return 0;
 
255
}
 
256
 
 
257
/*
 
258
 * This function prepares command to set/get Tx power configuration.
 
259
 *
 
260
 * Preparation includes -
 
261
 *      - Setting command ID, action and proper size
 
262
 *      - Setting Tx power mode, power group TLV
 
263
 *        (as required)
 
264
 *      - Ensuring correct endian-ness
 
265
 */
 
266
static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
 
267
                                    u16 cmd_action,
 
268
                                    struct host_cmd_ds_txpwr_cfg *txp)
 
269
{
 
270
        struct mwifiex_types_power_group *pg_tlv;
 
271
        struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
 
272
 
 
273
        cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
 
274
        cmd->size =
 
275
                cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
 
276
        switch (cmd_action) {
 
277
        case HostCmd_ACT_GEN_SET:
 
278
                if (txp->mode) {
 
279
                        pg_tlv = (struct mwifiex_types_power_group
 
280
                                  *) ((unsigned long) txp +
 
281
                                     sizeof(struct host_cmd_ds_txpwr_cfg));
 
282
                        memmove(cmd_txp_cfg, txp,
 
283
                                sizeof(struct host_cmd_ds_txpwr_cfg) +
 
284
                                sizeof(struct mwifiex_types_power_group) +
 
285
                                pg_tlv->length);
 
286
 
 
287
                        pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
 
288
                                  cmd_txp_cfg +
 
289
                                  sizeof(struct host_cmd_ds_txpwr_cfg));
 
290
                        cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
 
291
                                  sizeof(struct mwifiex_types_power_group) +
 
292
                                  pg_tlv->length);
 
293
                } else {
 
294
                        memmove(cmd_txp_cfg, txp, sizeof(*txp));
 
295
                }
 
296
                cmd_txp_cfg->action = cpu_to_le16(cmd_action);
 
297
                break;
 
298
        case HostCmd_ACT_GEN_GET:
 
299
                cmd_txp_cfg->action = cpu_to_le16(cmd_action);
 
300
                break;
 
301
        }
 
302
 
 
303
        return 0;
 
304
}
 
305
 
 
306
/*
 
307
 * This function prepares command to set Host Sleep configuration.
 
308
 *
 
309
 * Preparation includes -
 
310
 *      - Setting command ID and proper size
 
311
 *      - Setting Host Sleep action, conditions, ARP filters
 
312
 *        (as required)
 
313
 *      - Ensuring correct endian-ness
 
314
 */
 
315
static int
 
316
mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
 
317
                          struct host_cmd_ds_command *cmd,
 
318
                          u16 cmd_action,
 
319
                          struct mwifiex_hs_config_param *hscfg_param)
 
320
{
 
321
        struct mwifiex_adapter *adapter = priv->adapter;
 
322
        struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
 
323
        u16 hs_activate = false;
 
324
 
 
325
        if (!hscfg_param)
 
326
                /* New Activate command */
 
327
                hs_activate = true;
 
328
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
 
329
 
 
330
        if (!hs_activate &&
 
331
            (hscfg_param->conditions
 
332
            != cpu_to_le32(HOST_SLEEP_CFG_CANCEL))
 
333
            && ((adapter->arp_filter_size > 0)
 
334
                && (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
 
335
                dev_dbg(adapter->dev,
 
336
                        "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
 
337
                       adapter->arp_filter_size);
 
338
                memcpy(((u8 *) hs_cfg) +
 
339
                       sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
 
340
                       adapter->arp_filter, adapter->arp_filter_size);
 
341
                cmd->size = cpu_to_le16(adapter->arp_filter_size +
 
342
                                    sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
 
343
                                    + S_DS_GEN);
 
344
        } else {
 
345
                cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
 
346
                                           host_cmd_ds_802_11_hs_cfg_enh));
 
347
        }
 
348
        if (hs_activate) {
 
349
                hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
 
350
                hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED;
 
351
        } else {
 
352
                hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
 
353
                hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
 
354
                hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
 
355
                hs_cfg->params.hs_config.gap = hscfg_param->gap;
 
356
                dev_dbg(adapter->dev,
 
357
                        "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
 
358
                       hs_cfg->params.hs_config.conditions,
 
359
                       hs_cfg->params.hs_config.gpio,
 
360
                       hs_cfg->params.hs_config.gap);
 
361
        }
 
362
 
 
363
        return 0;
 
364
}
 
365
 
 
366
/*
 
367
 * This function prepares command to set/get MAC address.
 
368
 *
 
369
 * Preparation includes -
 
370
 *      - Setting command ID, action and proper size
 
371
 *      - Setting MAC address (for SET only)
 
372
 *      - Ensuring correct endian-ness
 
373
 */
 
374
static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
 
375
                                          struct host_cmd_ds_command *cmd,
 
376
                                          u16 cmd_action)
 
377
{
 
378
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
 
379
        cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
 
380
                                S_DS_GEN);
 
381
        cmd->result = 0;
 
382
 
 
383
        cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
 
384
 
 
385
        if (cmd_action == HostCmd_ACT_GEN_SET)
 
386
                memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
 
387
                       ETH_ALEN);
 
388
        return 0;
 
389
}
 
390
 
 
391
/*
 
392
 * This function prepares command to set MAC multicast address.
 
393
 *
 
394
 * Preparation includes -
 
395
 *      - Setting command ID, action and proper size
 
396
 *      - Setting MAC multicast address
 
397
 *      - Ensuring correct endian-ness
 
398
 */
 
399
static int
 
400
mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
 
401
                              u16 cmd_action,
 
402
                              struct mwifiex_multicast_list *mcast_list)
 
403
{
 
404
        struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
 
405
 
 
406
        cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
 
407
                                S_DS_GEN);
 
408
        cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
 
409
 
 
410
        mcast_addr->action = cpu_to_le16(cmd_action);
 
411
        mcast_addr->num_of_adrs =
 
412
                cpu_to_le16((u16) mcast_list->num_multicast_addr);
 
413
        memcpy(mcast_addr->mac_list, mcast_list->mac_list,
 
414
               mcast_list->num_multicast_addr * ETH_ALEN);
 
415
 
 
416
        return 0;
 
417
}
 
418
 
 
419
/*
 
420
 * This function prepares command to deauthenticate.
 
421
 *
 
422
 * Preparation includes -
 
423
 *      - Setting command ID and proper size
 
424
 *      - Setting AP MAC address and reason code
 
425
 *      - Ensuring correct endian-ness
 
426
 */
 
427
static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
 
428
                                             struct host_cmd_ds_command *cmd,
 
429
                                             u8 *mac)
 
430
{
 
431
        struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
 
432
 
 
433
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
 
434
        cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
 
435
                                + S_DS_GEN);
 
436
 
 
437
        /* Set AP MAC address */
 
438
        memcpy(deauth->mac_addr, mac, ETH_ALEN);
 
439
 
 
440
        dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
 
441
 
 
442
        deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
 
443
 
 
444
        return 0;
 
445
}
 
446
 
 
447
/*
 
448
 * This function prepares command to stop Ad-Hoc network.
 
449
 *
 
450
 * Preparation includes -
 
451
 *      - Setting command ID and proper size
 
452
 *      - Ensuring correct endian-ness
 
453
 */
 
454
static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
 
455
{
 
456
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
 
457
        cmd->size = cpu_to_le16(S_DS_GEN);
 
458
        return 0;
 
459
}
 
460
 
 
461
/*
 
462
 * This function sets WEP key(s) to key parameter TLV(s).
 
463
 *
 
464
 * Multi-key parameter TLVs are supported, so we can send multiple
 
465
 * WEP keys in a single buffer.
 
466
 */
 
467
static int
 
468
mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
 
469
                            struct mwifiex_ie_type_key_param_set *key_param_set,
 
470
                            u16 *key_param_len)
 
471
{
 
472
        int cur_key_param_len;
 
473
        u8 i;
 
474
 
 
475
        /* Multi-key_param_set TLV is supported */
 
476
        for (i = 0; i < NUM_WEP_KEYS; i++) {
 
477
                if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
 
478
                    (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
 
479
                        key_param_set->type =
 
480
                                cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
 
481
/* Key_param_set WEP fixed length */
 
482
#define KEYPARAMSET_WEP_FIXED_LEN 8
 
483
                        key_param_set->length = cpu_to_le16((u16)
 
484
                                        (priv->wep_key[i].
 
485
                                         key_length +
 
486
                                         KEYPARAMSET_WEP_FIXED_LEN));
 
487
                        key_param_set->key_type_id =
 
488
                                cpu_to_le16(KEY_TYPE_ID_WEP);
 
489
                        key_param_set->key_info =
 
490
                                cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
 
491
                                            KEY_MCAST);
 
492
                        key_param_set->key_len =
 
493
                                cpu_to_le16(priv->wep_key[i].key_length);
 
494
                        /* Set WEP key index */
 
495
                        key_param_set->key[0] = i;
 
496
                        /* Set default Tx key flag */
 
497
                        if (i ==
 
498
                            (priv->
 
499
                             wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
 
500
                                key_param_set->key[1] = 1;
 
501
                        else
 
502
                                key_param_set->key[1] = 0;
 
503
                        memmove(&key_param_set->key[2],
 
504
                                priv->wep_key[i].key_material,
 
505
                                priv->wep_key[i].key_length);
 
506
 
 
507
                        cur_key_param_len = priv->wep_key[i].key_length +
 
508
                                KEYPARAMSET_WEP_FIXED_LEN +
 
509
                                sizeof(struct mwifiex_ie_types_header);
 
510
                        *key_param_len += (u16) cur_key_param_len;
 
511
                        key_param_set =
 
512
                                (struct mwifiex_ie_type_key_param_set *)
 
513
                                                ((u8 *)key_param_set +
 
514
                                                cur_key_param_len);
 
515
                } else if (!priv->wep_key[i].key_length) {
 
516
                        continue;
 
517
                } else {
 
518
                        dev_err(priv->adapter->dev,
 
519
                                "key%d Length = %d is incorrect\n",
 
520
                               (i + 1), priv->wep_key[i].key_length);
 
521
                        return -1;
 
522
                }
 
523
        }
 
524
 
 
525
        return 0;
 
526
}
 
527
 
 
528
/*
 
529
 * This function prepares command to set/get/reset network key(s).
 
530
 *
 
531
 * Preparation includes -
 
532
 *      - Setting command ID, action and proper size
 
533
 *      - Setting WEP keys, WAPI keys or WPA keys along with required
 
534
 *        encryption (TKIP, AES) (as required)
 
535
 *      - Ensuring correct endian-ness
 
536
 */
 
537
static int
 
538
mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
 
539
                                struct host_cmd_ds_command *cmd,
 
540
                                u16 cmd_action, u32 cmd_oid,
 
541
                                struct mwifiex_ds_encrypt_key *enc_key)
 
542
{
 
543
        struct host_cmd_ds_802_11_key_material *key_material =
 
544
                &cmd->params.key_material;
 
545
        u16 key_param_len = 0;
 
546
        int ret = 0;
 
547
        const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
548
 
 
549
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
 
550
        key_material->action = cpu_to_le16(cmd_action);
 
551
 
 
552
        if (cmd_action == HostCmd_ACT_GEN_GET) {
 
553
                cmd->size =
 
554
                        cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
 
555
                return ret;
 
556
        }
 
557
 
 
558
        if (!enc_key) {
 
559
                memset(&key_material->key_param_set, 0,
 
560
                       (NUM_WEP_KEYS *
 
561
                        sizeof(struct mwifiex_ie_type_key_param_set)));
 
562
                ret = mwifiex_set_keyparamset_wep(priv,
 
563
                                                  &key_material->key_param_set,
 
564
                                                  &key_param_len);
 
565
                cmd->size = cpu_to_le16(key_param_len +
 
566
                                    sizeof(key_material->action) + S_DS_GEN);
 
567
                return ret;
 
568
        } else
 
569
                memset(&key_material->key_param_set, 0,
 
570
                       sizeof(struct mwifiex_ie_type_key_param_set));
 
571
        if (enc_key->is_wapi_key) {
 
572
                dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
 
573
                key_material->key_param_set.key_type_id =
 
574
                        cpu_to_le16(KEY_TYPE_ID_WAPI);
 
575
                if (cmd_oid == KEY_INFO_ENABLED)
 
576
                        key_material->key_param_set.key_info =
 
577
                                cpu_to_le16(KEY_ENABLED);
 
578
                else
 
579
                        key_material->key_param_set.key_info =
 
580
                                cpu_to_le16(!KEY_ENABLED);
 
581
 
 
582
                key_material->key_param_set.key[0] = enc_key->key_index;
 
583
                if (!priv->sec_info.wapi_key_on)
 
584
                        key_material->key_param_set.key[1] = 1;
 
585
                else
 
586
                        /* set 0 when re-key */
 
587
                        key_material->key_param_set.key[1] = 0;
 
588
 
 
589
                if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
 
590
                        /* WAPI pairwise key: unicast */
 
591
                        key_material->key_param_set.key_info |=
 
592
                                cpu_to_le16(KEY_UNICAST);
 
593
                } else {        /* WAPI group key: multicast */
 
594
                        key_material->key_param_set.key_info |=
 
595
                                cpu_to_le16(KEY_MCAST);
 
596
                        priv->sec_info.wapi_key_on = true;
 
597
                }
 
598
 
 
599
                key_material->key_param_set.type =
 
600
                        cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
 
601
                key_material->key_param_set.key_len =
 
602
                        cpu_to_le16(WAPI_KEY_LEN);
 
603
                memcpy(&key_material->key_param_set.key[2],
 
604
                       enc_key->key_material, enc_key->key_len);
 
605
                memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
 
606
                       enc_key->wapi_rxpn, WAPI_RXPN_LEN);
 
607
                key_material->key_param_set.length =
 
608
                        cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
 
609
 
 
610
                key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
 
611
                                 sizeof(struct mwifiex_ie_types_header);
 
612
                cmd->size = cpu_to_le16(key_param_len +
 
613
                                sizeof(key_material->action) + S_DS_GEN);
 
614
                return ret;
 
615
        }
 
616
        if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
 
617
                dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
 
618
                key_material->key_param_set.key_type_id =
 
619
                        cpu_to_le16(KEY_TYPE_ID_AES);
 
620
                if (cmd_oid == KEY_INFO_ENABLED)
 
621
                        key_material->key_param_set.key_info =
 
622
                                cpu_to_le16(KEY_ENABLED);
 
623
                else
 
624
                        key_material->key_param_set.key_info =
 
625
                                cpu_to_le16(!KEY_ENABLED);
 
626
 
 
627
                if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
 
628
                                /* AES pairwise key: unicast */
 
629
                        key_material->key_param_set.key_info |=
 
630
                                cpu_to_le16(KEY_UNICAST);
 
631
                else            /* AES group key: multicast */
 
632
                        key_material->key_param_set.key_info |=
 
633
                                cpu_to_le16(KEY_MCAST);
 
634
        } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
 
635
                dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
 
636
                key_material->key_param_set.key_type_id =
 
637
                        cpu_to_le16(KEY_TYPE_ID_TKIP);
 
638
                key_material->key_param_set.key_info =
 
639
                        cpu_to_le16(KEY_ENABLED);
 
640
 
 
641
                if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
 
642
                                /* TKIP pairwise key: unicast */
 
643
                        key_material->key_param_set.key_info |=
 
644
                                cpu_to_le16(KEY_UNICAST);
 
645
                else            /* TKIP group key: multicast */
 
646
                        key_material->key_param_set.key_info |=
 
647
                                cpu_to_le16(KEY_MCAST);
 
648
        }
 
649
 
 
650
        if (key_material->key_param_set.key_type_id) {
 
651
                key_material->key_param_set.type =
 
652
                        cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
 
653
                key_material->key_param_set.key_len =
 
654
                        cpu_to_le16((u16) enc_key->key_len);
 
655
                memcpy(key_material->key_param_set.key, enc_key->key_material,
 
656
                       enc_key->key_len);
 
657
                key_material->key_param_set.length =
 
658
                        cpu_to_le16((u16) enc_key->key_len +
 
659
                                    KEYPARAMSET_FIXED_LEN);
 
660
 
 
661
                key_param_len = (u16) (enc_key->key_len + KEYPARAMSET_FIXED_LEN)
 
662
                                      + sizeof(struct mwifiex_ie_types_header);
 
663
 
 
664
                cmd->size = cpu_to_le16(key_param_len +
 
665
                                    sizeof(key_material->action) + S_DS_GEN);
 
666
        }
 
667
 
 
668
        return ret;
 
669
}
 
670
 
 
671
/*
 
672
 * This function prepares command to set/get 11d domain information.
 
673
 *
 
674
 * Preparation includes -
 
675
 *      - Setting command ID, action and proper size
 
676
 *      - Setting domain information fields (for SET only)
 
677
 *      - Ensuring correct endian-ness
 
678
 */
 
679
static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
 
680
                                           struct host_cmd_ds_command *cmd,
 
681
                                           u16 cmd_action)
 
682
{
 
683
        struct mwifiex_adapter *adapter = priv->adapter;
 
684
        struct host_cmd_ds_802_11d_domain_info *domain_info =
 
685
                &cmd->params.domain_info;
 
686
        struct mwifiex_ietypes_domain_param_set *domain =
 
687
                &domain_info->domain;
 
688
        u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
 
689
 
 
690
        dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
 
691
 
 
692
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
 
693
        domain_info->action = cpu_to_le16(cmd_action);
 
694
        if (cmd_action == HostCmd_ACT_GEN_GET) {
 
695
                cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
 
696
                return 0;
 
697
        }
 
698
 
 
699
        /* Set domain info fields */
 
700
        domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
 
701
        memcpy(domain->country_code, adapter->domain_reg.country_code,
 
702
                        sizeof(domain->country_code));
 
703
 
 
704
        domain->header.len = cpu_to_le16((no_of_triplet *
 
705
                                sizeof(struct ieee80211_country_ie_triplet)) +
 
706
                                sizeof(domain->country_code));
 
707
 
 
708
        if (no_of_triplet) {
 
709
                memcpy(domain->triplet, adapter->domain_reg.triplet,
 
710
                                no_of_triplet *
 
711
                                sizeof(struct ieee80211_country_ie_triplet));
 
712
 
 
713
                cmd->size = cpu_to_le16(sizeof(domain_info->action) +
 
714
                                le16_to_cpu(domain->header.len) +
 
715
                                sizeof(struct mwifiex_ie_types_header)
 
716
                                + S_DS_GEN);
 
717
        } else {
 
718
                cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
 
719
        }
 
720
 
 
721
        return 0;
 
722
}
 
723
 
 
724
/*
 
725
 * This function prepares command to set/get RF channel.
 
726
 *
 
727
 * Preparation includes -
 
728
 *      - Setting command ID, action and proper size
 
729
 *      - Setting RF type and current RF channel (for SET only)
 
730
 *      - Ensuring correct endian-ness
 
731
 */
 
732
static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv,
 
733
                                         struct host_cmd_ds_command *cmd,
 
734
                                         u16 cmd_action, u16 *channel)
 
735
{
 
736
        struct host_cmd_ds_802_11_rf_channel *rf_chan =
 
737
                &cmd->params.rf_channel;
 
738
        uint16_t rf_type = le16_to_cpu(rf_chan->rf_type);
 
739
 
 
740
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL);
 
741
        cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel)
 
742
                                + S_DS_GEN);
 
743
 
 
744
        if (cmd_action == HostCmd_ACT_GEN_SET) {
 
745
                if ((priv->adapter->adhoc_start_band & BAND_A)
 
746
                    || (priv->adapter->adhoc_start_band & BAND_AN))
 
747
                        rf_chan->rf_type =
 
748
                                cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A);
 
749
 
 
750
                rf_type = le16_to_cpu(rf_chan->rf_type);
 
751
                SET_SECONDARYCHAN(rf_type, priv->adapter->chan_offset);
 
752
                rf_chan->current_channel = cpu_to_le16(*channel);
 
753
        }
 
754
        rf_chan->action = cpu_to_le16(cmd_action);
 
755
        return 0;
 
756
}
 
757
 
 
758
/*
 
759
 * This function prepares command to set/get IBSS coalescing status.
 
760
 *
 
761
 * Preparation includes -
 
762
 *      - Setting command ID, action and proper size
 
763
 *      - Setting status to enable or disable (for SET only)
 
764
 *      - Ensuring correct endian-ness
 
765
 */
 
766
static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
 
767
                                              u16 cmd_action, u16 *enable)
 
768
{
 
769
        struct host_cmd_ds_802_11_ibss_status *ibss_coal =
 
770
                &(cmd->params.ibss_coalescing);
 
771
 
 
772
        cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
 
773
        cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
 
774
                                S_DS_GEN);
 
775
        cmd->result = 0;
 
776
        ibss_coal->action = cpu_to_le16(cmd_action);
 
777
 
 
778
        switch (cmd_action) {
 
779
        case HostCmd_ACT_GEN_SET:
 
780
                if (enable)
 
781
                        ibss_coal->enable = cpu_to_le16(*enable);
 
782
                else
 
783
                        ibss_coal->enable = 0;
 
784
                break;
 
785
 
 
786
                /* In other case.. Nothing to do */
 
787
        case HostCmd_ACT_GEN_GET:
 
788
        default:
 
789
                break;
 
790
        }
 
791
 
 
792
        return 0;
 
793
}
 
794
 
 
795
/*
 
796
 * This function prepares command to set/get register value.
 
797
 *
 
798
 * Preparation includes -
 
799
 *      - Setting command ID, action and proper size
 
800
 *      - Setting register offset (for both GET and SET) and
 
801
 *        register value (for SET only)
 
802
 *      - Ensuring correct endian-ness
 
803
 *
 
804
 * The following type of registers can be accessed with this function -
 
805
 *      - MAC register
 
806
 *      - BBP register
 
807
 *      - RF register
 
808
 *      - PMIC register
 
809
 *      - CAU register
 
810
 *      - EEPROM
 
811
 */
 
812
static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
 
813
                                  u16 cmd_action, void *data_buf)
 
814
{
 
815
        struct mwifiex_ds_reg_rw *reg_rw = data_buf;
 
816
 
 
817
        switch (le16_to_cpu(cmd->command)) {
 
818
        case HostCmd_CMD_MAC_REG_ACCESS:
 
819
        {
 
820
                struct host_cmd_ds_mac_reg_access *mac_reg;
 
821
 
 
822
                cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
 
823
                mac_reg = (struct host_cmd_ds_mac_reg_access *) &cmd->
 
824
                        params.mac_reg;
 
825
                mac_reg->action = cpu_to_le16(cmd_action);
 
826
                mac_reg->offset =
 
827
                        cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
 
828
                mac_reg->value = reg_rw->value;
 
829
                break;
 
830
        }
 
831
        case HostCmd_CMD_BBP_REG_ACCESS:
 
832
        {
 
833
                struct host_cmd_ds_bbp_reg_access *bbp_reg;
 
834
 
 
835
                cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
 
836
                bbp_reg = (struct host_cmd_ds_bbp_reg_access *) &cmd->
 
837
                        params.bbp_reg;
 
838
                bbp_reg->action = cpu_to_le16(cmd_action);
 
839
                bbp_reg->offset =
 
840
                        cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
 
841
                bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
 
842
                break;
 
843
        }
 
844
        case HostCmd_CMD_RF_REG_ACCESS:
 
845
        {
 
846
                struct host_cmd_ds_rf_reg_access *rf_reg;
 
847
 
 
848
                cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
 
849
                rf_reg = (struct host_cmd_ds_rf_reg_access *) &cmd->
 
850
                        params.rf_reg;
 
851
                rf_reg->action = cpu_to_le16(cmd_action);
 
852
                rf_reg->offset =
 
853
                        cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
 
854
                rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
 
855
                break;
 
856
        }
 
857
        case HostCmd_CMD_PMIC_REG_ACCESS:
 
858
        {
 
859
                struct host_cmd_ds_pmic_reg_access *pmic_reg;
 
860
 
 
861
                cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
 
862
                pmic_reg = (struct host_cmd_ds_pmic_reg_access *) &cmd->
 
863
                                params.pmic_reg;
 
864
                pmic_reg->action = cpu_to_le16(cmd_action);
 
865
                pmic_reg->offset =
 
866
                        cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
 
867
                pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
 
868
                break;
 
869
        }
 
870
        case HostCmd_CMD_CAU_REG_ACCESS:
 
871
        {
 
872
                struct host_cmd_ds_rf_reg_access *cau_reg;
 
873
 
 
874
                cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
 
875
                cau_reg = (struct host_cmd_ds_rf_reg_access *) &cmd->
 
876
                                params.rf_reg;
 
877
                cau_reg->action = cpu_to_le16(cmd_action);
 
878
                cau_reg->offset =
 
879
                        cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
 
880
                cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
 
881
                break;
 
882
        }
 
883
        case HostCmd_CMD_802_11_EEPROM_ACCESS:
 
884
        {
 
885
                struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
 
886
                struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
 
887
                        (struct host_cmd_ds_802_11_eeprom_access *)
 
888
                        &cmd->params.eeprom;
 
889
 
 
890
                cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
 
891
                cmd_eeprom->action = cpu_to_le16(cmd_action);
 
892
                cmd_eeprom->offset = rd_eeprom->offset;
 
893
                cmd_eeprom->byte_count = rd_eeprom->byte_count;
 
894
                cmd_eeprom->value = 0;
 
895
                break;
 
896
        }
 
897
        default:
 
898
                return -1;
 
899
        }
 
900
 
 
901
        return 0;
 
902
}
 
903
 
 
904
/*
 
905
 * This function prepares command to set PCI-Express
 
906
 * host buffer configuration
 
907
 *
 
908
 * Preparation includes -
 
909
 *      - Setting command ID, action and proper size
 
910
 *      - Setting host buffer configuration
 
911
 *      - Ensuring correct endian-ness
 
912
 */
 
913
static int
 
914
mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
 
915
                                   struct host_cmd_ds_command *cmd, u16 action)
 
916
{
 
917
        struct host_cmd_ds_pcie_details *host_spec =
 
918
                                        &cmd->params.pcie_host_spec;
 
919
        struct pcie_service_card *card = priv->adapter->card;
 
920
        phys_addr_t *buf_pa;
 
921
 
 
922
        cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
 
923
        cmd->size = cpu_to_le16(sizeof(struct
 
924
                                        host_cmd_ds_pcie_details) + S_DS_GEN);
 
925
        cmd->result = 0;
 
926
 
 
927
        memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
 
928
 
 
929
        if (action == HostCmd_ACT_GEN_SET) {
 
930
                /* Send the ring base addresses and count to firmware */
 
931
                host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
 
932
                host_spec->txbd_addr_hi =
 
933
                                (u32)(((u64)card->txbd_ring_pbase)>>32);
 
934
                host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
 
935
                host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
 
936
                host_spec->rxbd_addr_hi =
 
937
                                (u32)(((u64)card->rxbd_ring_pbase)>>32);
 
938
                host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
 
939
                host_spec->evtbd_addr_lo =
 
940
                                (u32)(card->evtbd_ring_pbase);
 
941
                host_spec->evtbd_addr_hi =
 
942
                                (u32)(((u64)card->evtbd_ring_pbase)>>32);
 
943
                host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
 
944
                if (card->sleep_cookie) {
 
945
                        buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie);
 
946
                        host_spec->sleep_cookie_addr_lo = (u32) *buf_pa;
 
947
                        host_spec->sleep_cookie_addr_hi =
 
948
                                                (u32) (((u64)*buf_pa) >> 32);
 
949
                        dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: "
 
950
                                 "0x%x\n", host_spec->sleep_cookie_addr_lo);
 
951
                }
 
952
        }
 
953
 
 
954
        return 0;
 
955
}
 
956
 
 
957
/*
 
958
 * This function prepares the commands before sending them to the firmware.
 
959
 *
 
960
 * This is a generic function which calls specific command preparation
 
961
 * routines based upon the command number.
 
962
 */
 
963
int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
 
964
                            u16 cmd_action, u32 cmd_oid,
 
965
                            void *data_buf, void *cmd_buf)
 
966
{
 
967
        struct host_cmd_ds_command *cmd_ptr = cmd_buf;
 
968
        int ret = 0;
 
969
 
 
970
        /* Prepare command */
 
971
        switch (cmd_no) {
 
972
        case HostCmd_CMD_GET_HW_SPEC:
 
973
                ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
 
974
                break;
 
975
        case HostCmd_CMD_MAC_CONTROL:
 
976
                ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
 
977
                                              data_buf);
 
978
                break;
 
979
        case HostCmd_CMD_802_11_MAC_ADDRESS:
 
980
                ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
 
981
                                                     cmd_action);
 
982
                break;
 
983
        case HostCmd_CMD_MAC_MULTICAST_ADR:
 
984
                ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
 
985
                                                    data_buf);
 
986
                break;
 
987
        case HostCmd_CMD_TX_RATE_CFG:
 
988
                ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
 
989
                                              data_buf);
 
990
                break;
 
991
        case HostCmd_CMD_TXPWR_CFG:
 
992
                ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
 
993
                                               data_buf);
 
994
                break;
 
995
        case HostCmd_CMD_802_11_PS_MODE_ENH:
 
996
                ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
 
997
                                                 (uint16_t)cmd_oid, data_buf);
 
998
                break;
 
999
        case HostCmd_CMD_802_11_HS_CFG_ENH:
 
1000
                ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
 
1001
                                (struct mwifiex_hs_config_param *) data_buf);
 
1002
                break;
 
1003
        case HostCmd_CMD_802_11_SCAN:
 
1004
                ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
 
1005
                break;
 
1006
        case HostCmd_CMD_802_11_BG_SCAN_QUERY:
 
1007
                ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
 
1008
                break;
 
1009
        case HostCmd_CMD_802_11_ASSOCIATE:
 
1010
                ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
 
1011
                break;
 
1012
        case HostCmd_CMD_802_11_DEAUTHENTICATE:
 
1013
                ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
 
1014
                                                        data_buf);
 
1015
                break;
 
1016
        case HostCmd_CMD_802_11_AD_HOC_START:
 
1017
                ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
 
1018
                                                      data_buf);
 
1019
                break;
 
1020
        case HostCmd_CMD_802_11_GET_LOG:
 
1021
                ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
 
1022
                break;
 
1023
        case HostCmd_CMD_802_11_AD_HOC_JOIN:
 
1024
                ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
 
1025
                                                     data_buf);
 
1026
                break;
 
1027
        case HostCmd_CMD_802_11_AD_HOC_STOP:
 
1028
                ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
 
1029
                break;
 
1030
        case HostCmd_CMD_RSSI_INFO:
 
1031
                ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
 
1032
                break;
 
1033
        case HostCmd_CMD_802_11_SNMP_MIB:
 
1034
                ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
 
1035
                                                  cmd_oid, data_buf);
 
1036
                break;
 
1037
        case HostCmd_CMD_802_11_TX_RATE_QUERY:
 
1038
                cmd_ptr->command =
 
1039
                        cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
 
1040
                cmd_ptr->size =
 
1041
                        cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
 
1042
                                    S_DS_GEN);
 
1043
                priv->tx_rate = 0;
 
1044
                ret = 0;
 
1045
                break;
 
1046
        case HostCmd_CMD_VERSION_EXT:
 
1047
                cmd_ptr->command = cpu_to_le16(cmd_no);
 
1048
                cmd_ptr->params.verext.version_str_sel =
 
1049
                        (u8) (*((u32 *) data_buf));
 
1050
                memcpy(&cmd_ptr->params, data_buf,
 
1051
                       sizeof(struct host_cmd_ds_version_ext));
 
1052
                cmd_ptr->size =
 
1053
                        cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
 
1054
                                    S_DS_GEN);
 
1055
                ret = 0;
 
1056
                break;
 
1057
        case HostCmd_CMD_802_11_RF_CHANNEL:
 
1058
                ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action,
 
1059
                                                    data_buf);
 
1060
                break;
 
1061
        case HostCmd_CMD_FUNC_INIT:
 
1062
                if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
 
1063
                        priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
 
1064
                cmd_ptr->command = cpu_to_le16(cmd_no);
 
1065
                cmd_ptr->size = cpu_to_le16(S_DS_GEN);
 
1066
                break;
 
1067
        case HostCmd_CMD_FUNC_SHUTDOWN:
 
1068
                priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
 
1069
                cmd_ptr->command = cpu_to_le16(cmd_no);
 
1070
                cmd_ptr->size = cpu_to_le16(S_DS_GEN);
 
1071
                break;
 
1072
        case HostCmd_CMD_11N_ADDBA_REQ:
 
1073
                ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
 
1074
                break;
 
1075
        case HostCmd_CMD_11N_DELBA:
 
1076
                ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
 
1077
                break;
 
1078
        case HostCmd_CMD_11N_ADDBA_RSP:
 
1079
                ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
 
1080
                break;
 
1081
        case HostCmd_CMD_802_11_KEY_MATERIAL:
 
1082
                ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
 
1083
                                                cmd_action, cmd_oid,
 
1084
                                                data_buf);
 
1085
                break;
 
1086
        case HostCmd_CMD_802_11D_DOMAIN_INFO:
 
1087
                ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
 
1088
                                                cmd_action);
 
1089
                break;
 
1090
        case HostCmd_CMD_RECONFIGURE_TX_BUFF:
 
1091
                ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
 
1092
                                               data_buf);
 
1093
                break;
 
1094
        case HostCmd_CMD_AMSDU_AGGR_CTRL:
 
1095
                ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
 
1096
                                                  data_buf);
 
1097
                break;
 
1098
        case HostCmd_CMD_11N_CFG:
 
1099
                ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action,
 
1100
                                          data_buf);
 
1101
                break;
 
1102
        case HostCmd_CMD_WMM_GET_STATUS:
 
1103
                dev_dbg(priv->adapter->dev,
 
1104
                        "cmd: WMM: WMM_GET_STATUS cmd sent\n");
 
1105
                cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
 
1106
                cmd_ptr->size =
 
1107
                        cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
 
1108
                                    S_DS_GEN);
 
1109
                ret = 0;
 
1110
                break;
 
1111
        case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
 
1112
                ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
 
1113
                                                         data_buf);
 
1114
                break;
 
1115
        case HostCmd_CMD_MAC_REG_ACCESS:
 
1116
        case HostCmd_CMD_BBP_REG_ACCESS:
 
1117
        case HostCmd_CMD_RF_REG_ACCESS:
 
1118
        case HostCmd_CMD_PMIC_REG_ACCESS:
 
1119
        case HostCmd_CMD_CAU_REG_ACCESS:
 
1120
        case HostCmd_CMD_802_11_EEPROM_ACCESS:
 
1121
                ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
 
1122
                break;
 
1123
        case HostCmd_CMD_SET_BSS_MODE:
 
1124
                cmd_ptr->command = cpu_to_le16(cmd_no);
 
1125
                if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
 
1126
                        cmd_ptr->params.bss_mode.con_type =
 
1127
                                CONNECTION_TYPE_ADHOC;
 
1128
                else if (priv->bss_mode == NL80211_IFTYPE_STATION)
 
1129
                        cmd_ptr->params.bss_mode.con_type =
 
1130
                                CONNECTION_TYPE_INFRA;
 
1131
                cmd_ptr->size = cpu_to_le16(sizeof(struct
 
1132
                                host_cmd_ds_set_bss_mode) + S_DS_GEN);
 
1133
                ret = 0;
 
1134
                break;
 
1135
        case HostCmd_CMD_PCIE_DESC_DETAILS:
 
1136
                ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
 
1137
                break;
 
1138
        default:
 
1139
                dev_err(priv->adapter->dev,
 
1140
                        "PREP_CMD: unknown cmd- %#x\n", cmd_no);
 
1141
                ret = -1;
 
1142
                break;
 
1143
        }
 
1144
        return ret;
 
1145
}
 
1146
 
 
1147
/*
 
1148
 * This function issues commands to initialize firmware.
 
1149
 *
 
1150
 * This is called after firmware download to bring the card to
 
1151
 * working state.
 
1152
 *
 
1153
 * The following commands are issued sequentially -
 
1154
 *      - Set PCI-Express host buffer configuration (PCIE only)
 
1155
 *      - Function init (for first interface only)
 
1156
 *      - Read MAC address (for first interface only)
 
1157
 *      - Reconfigure Tx buffer size (for first interface only)
 
1158
 *      - Enable auto deep sleep (for first interface only)
 
1159
 *      - Get Tx rate
 
1160
 *      - Get Tx power
 
1161
 *      - Set IBSS coalescing status
 
1162
 *      - Set AMSDU aggregation control
 
1163
 *      - Set 11d control
 
1164
 *      - Set MAC control (this must be the last command to initialize firmware)
 
1165
 */
 
1166
int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
 
1167
{
 
1168
        int ret;
 
1169
        u16 enable = true;
 
1170
        struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
 
1171
        struct mwifiex_ds_auto_ds auto_ds;
 
1172
        enum state_11d_t state_11d;
 
1173
        struct mwifiex_ds_11n_tx_cfg tx_cfg;
 
1174
 
 
1175
        if (first_sta) {
 
1176
                if (priv->adapter->iface_type == MWIFIEX_PCIE) {
 
1177
                        ret = mwifiex_send_cmd_async(priv,
 
1178
                                        HostCmd_CMD_PCIE_DESC_DETAILS,
 
1179
                                        HostCmd_ACT_GEN_SET, 0, NULL);
 
1180
                        if (ret)
 
1181
                                return -1;
 
1182
                }
 
1183
 
 
1184
                ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
 
1185
                                             HostCmd_ACT_GEN_SET, 0, NULL);
 
1186
                if (ret)
 
1187
                        return -1;
 
1188
                /* Read MAC address from HW */
 
1189
                ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
 
1190
                                             HostCmd_ACT_GEN_GET, 0, NULL);
 
1191
                if (ret)
 
1192
                        return -1;
 
1193
 
 
1194
                /* Reconfigure tx buf size */
 
1195
                ret = mwifiex_send_cmd_async(priv,
 
1196
                                             HostCmd_CMD_RECONFIGURE_TX_BUFF,
 
1197
                                             HostCmd_ACT_GEN_SET, 0,
 
1198
                                             &priv->adapter->tx_buf_size);
 
1199
                if (ret)
 
1200
                        return -1;
 
1201
 
 
1202
                /* Enable IEEE PS by default */
 
1203
                priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
 
1204
                ret = mwifiex_send_cmd_async(priv,
 
1205
                                             HostCmd_CMD_802_11_PS_MODE_ENH,
 
1206
                                             EN_AUTO_PS, BITMAP_STA_PS, NULL);
 
1207
                if (ret)
 
1208
                        return -1;
 
1209
        }
 
1210
 
 
1211
        /* get tx rate */
 
1212
        ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
 
1213
                                     HostCmd_ACT_GEN_GET, 0, NULL);
 
1214
        if (ret)
 
1215
                return -1;
 
1216
        priv->data_rate = 0;
 
1217
 
 
1218
        /* get tx power */
 
1219
        ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TXPWR_CFG,
 
1220
                                     HostCmd_ACT_GEN_GET, 0, NULL);
 
1221
        if (ret)
 
1222
                return -1;
 
1223
 
 
1224
        /* set ibss coalescing_status */
 
1225
        ret = mwifiex_send_cmd_async(priv,
 
1226
                                     HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
 
1227
                                     HostCmd_ACT_GEN_SET, 0, &enable);
 
1228
        if (ret)
 
1229
                return -1;
 
1230
 
 
1231
        memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
 
1232
        amsdu_aggr_ctrl.enable = true;
 
1233
        /* Send request to firmware */
 
1234
        ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
 
1235
                                     HostCmd_ACT_GEN_SET, 0,
 
1236
                                     &amsdu_aggr_ctrl);
 
1237
        if (ret)
 
1238
                return -1;
 
1239
        /* MAC Control must be the last command in init_fw */
 
1240
        /* set MAC Control */
 
1241
        ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
 
1242
                                     HostCmd_ACT_GEN_SET, 0,
 
1243
                                     &priv->curr_pkt_filter);
 
1244
        if (ret)
 
1245
                return -1;
 
1246
 
 
1247
        if (first_sta) {
 
1248
                /* Enable auto deep sleep */
 
1249
                auto_ds.auto_ds = DEEP_SLEEP_ON;
 
1250
                auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
 
1251
                ret = mwifiex_send_cmd_async(priv,
 
1252
                                             HostCmd_CMD_802_11_PS_MODE_ENH,
 
1253
                                             EN_AUTO_PS, BITMAP_AUTO_DS,
 
1254
                                             &auto_ds);
 
1255
                if (ret)
 
1256
                        return -1;
 
1257
        }
 
1258
 
 
1259
        /* Send cmd to FW to enable/disable 11D function */
 
1260
        state_11d = ENABLE_11D;
 
1261
        ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
 
1262
                                     HostCmd_ACT_GEN_SET, DOT11D_I, &state_11d);
 
1263
        if (ret)
 
1264
                dev_err(priv->adapter->dev, "11D: failed to enable 11D\n");
 
1265
 
 
1266
        /* Send cmd to FW to configure 11n specific configuration
 
1267
         * (Short GI, Channel BW, Green field support etc.) for transmit
 
1268
         */
 
1269
        tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
 
1270
        ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
 
1271
                                     HostCmd_ACT_GEN_SET, 0, &tx_cfg);
 
1272
 
 
1273
        /* set last_init_cmd */
 
1274
        priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
 
1275
        ret = -EINPROGRESS;
 
1276
 
 
1277
        return ret;
 
1278
}