uap_cmd.c 3.6 KB

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