mwifiex: add AP command sys_config and set channel
[deliverable/linux.git] / drivers / net / wireless / mwifiex / uap_cmd.c
CommitLineData
40d07030
AP
1/*
2 * Marvell Wireless LAN device driver: AP specific command handling
3 *
4 * Copyright (C) 2012, 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 "main.h"
21
4db16a18
AP
22/* Parse AP config structure and prepare TLV based command structure
23 * to be sent to FW for uAP configuration
24 */
25static int mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd,
26 u16 cmd_action, void *cmd_buf)
27{
28 u8 *tlv;
29 struct host_cmd_ds_sys_config *sys_config = &cmd->params.uap_sys_config;
30 struct host_cmd_tlv_channel_band *chan_band;
31 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
32 u16 cmd_size;
33
34 cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
35 cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
36
37 sys_config->action = cpu_to_le16(cmd_action);
38
39 tlv = sys_config->tlv;
40
41 if (bss_cfg->channel && bss_cfg->channel <= MAX_CHANNEL_BAND_BG) {
42 chan_band = (struct host_cmd_tlv_channel_band *)tlv;
43 chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
44 chan_band->tlv.len =
45 cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
46 sizeof(struct host_cmd_tlv));
47 chan_band->band_config = bss_cfg->band_cfg;
48 chan_band->channel = bss_cfg->channel;
49 cmd_size += sizeof(struct host_cmd_tlv_channel_band);
50 tlv += sizeof(struct host_cmd_tlv_channel_band);
51 }
52
53 cmd->size = cpu_to_le16(cmd_size);
54 return 0;
55}
56
40d07030
AP
57/* This function prepares the AP specific commands before sending them
58 * to the firmware.
59 * This is a generic function which calls specific command preparation
60 * routines based upon the command number.
61 */
62int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
63 u16 cmd_action, u32 cmd_oid,
64 void *data_buf, void *cmd_buf)
65{
66 struct host_cmd_ds_command *cmd = cmd_buf;
67
68 switch (cmd_no) {
4db16a18
AP
69 case HostCmd_CMD_UAP_SYS_CONFIG:
70 if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, data_buf))
71 return -1;
72 break;
40d07030
AP
73 case HostCmd_CMD_UAP_BSS_START:
74 case HostCmd_CMD_UAP_BSS_STOP:
75 cmd->command = cpu_to_le16(cmd_no);
76 cmd->size = cpu_to_le16(S_DS_GEN);
77 break;
78 default:
79 dev_err(priv->adapter->dev,
80 "PREP_CMD: unknown cmd %#x\n", cmd_no);
81 return -1;
82 }
83
84 return 0;
85}
4db16a18
AP
86
87/* This function sets the RF channel for AP.
88 *
89 * This function populates channel information in AP config structure
90 * and sends command to configure channel information in AP.
91 */
92int mwifiex_uap_set_channel(struct mwifiex_private *priv, int channel)
93{
94 struct mwifiex_uap_bss_param *bss_cfg;
95 struct wiphy *wiphy = priv->wdev->wiphy;
96
97 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
98 if (!bss_cfg)
99 return -ENOMEM;
100
101 bss_cfg->band_cfg = BAND_CONFIG_MANUAL;
102 bss_cfg->channel = channel;
103
104 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
105 HostCmd_ACT_GEN_SET, 0, bss_cfg)) {
106 wiphy_err(wiphy, "Failed to set the uAP channel\n");
107 kfree(bss_cfg);
108 return -1;
109 }
110
111 kfree(bss_cfg);
112 return 0;
113}
This page took 0.027863 seconds and 5 git commands to generate.