uap_cmd.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /* This function initializes some of mwifiex_uap_bss_param variables.
  21. * This helps FW in ignoring invalid values. These values may or may not
  22. * be get updated to valid ones at later stage.
  23. */
  24. void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
  25. {
  26. config->rts_threshold = 0x7FFF;
  27. config->frag_threshold = 0x7FFF;
  28. config->retry_limit = 0x7F;
  29. }
  30. /* Parse AP config structure and prepare TLV based command structure
  31. * to be sent to FW for uAP configuration
  32. */
  33. static int mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd,
  34. u16 cmd_action, void *cmd_buf)
  35. {
  36. u8 *tlv;
  37. struct host_cmd_ds_sys_config *sys_config = &cmd->params.uap_sys_config;
  38. struct host_cmd_tlv_channel_band *chan_band;
  39. struct host_cmd_tlv_frag_threshold *frag_threshold;
  40. struct host_cmd_tlv_rts_threshold *rts_threshold;
  41. struct host_cmd_tlv_retry_limit *retry_limit;
  42. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  43. u16 cmd_size;
  44. cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
  45. cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
  46. sys_config->action = cpu_to_le16(cmd_action);
  47. tlv = sys_config->tlv;
  48. if (bss_cfg->channel && bss_cfg->channel <= MAX_CHANNEL_BAND_BG) {
  49. chan_band = (struct host_cmd_tlv_channel_band *)tlv;
  50. chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
  51. chan_band->tlv.len =
  52. cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
  53. sizeof(struct host_cmd_tlv));
  54. chan_band->band_config = bss_cfg->band_cfg;
  55. chan_band->channel = bss_cfg->channel;
  56. cmd_size += sizeof(struct host_cmd_tlv_channel_band);
  57. tlv += sizeof(struct host_cmd_tlv_channel_band);
  58. }
  59. if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
  60. rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
  61. rts_threshold->tlv.type =
  62. cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
  63. rts_threshold->tlv.len =
  64. cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
  65. sizeof(struct host_cmd_tlv));
  66. rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
  67. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  68. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  69. }
  70. if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
  71. (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
  72. frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
  73. frag_threshold->tlv.type =
  74. cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
  75. frag_threshold->tlv.len =
  76. cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
  77. sizeof(struct host_cmd_tlv));
  78. frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
  79. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  80. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  81. }
  82. if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
  83. retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
  84. retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
  85. retry_limit->tlv.len =
  86. cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
  87. sizeof(struct host_cmd_tlv));
  88. retry_limit->limit = (u8)bss_cfg->retry_limit;
  89. cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
  90. tlv += sizeof(struct host_cmd_tlv_retry_limit);
  91. }
  92. cmd->size = cpu_to_le16(cmd_size);
  93. return 0;
  94. }
  95. /* This function prepares the AP specific commands before sending them
  96. * to the firmware.
  97. * This is a generic function which calls specific command preparation
  98. * routines based upon the command number.
  99. */
  100. int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
  101. u16 cmd_action, u32 cmd_oid,
  102. void *data_buf, void *cmd_buf)
  103. {
  104. struct host_cmd_ds_command *cmd = cmd_buf;
  105. switch (cmd_no) {
  106. case HostCmd_CMD_UAP_SYS_CONFIG:
  107. if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, data_buf))
  108. return -1;
  109. break;
  110. case HostCmd_CMD_UAP_BSS_START:
  111. case HostCmd_CMD_UAP_BSS_STOP:
  112. cmd->command = cpu_to_le16(cmd_no);
  113. cmd->size = cpu_to_le16(S_DS_GEN);
  114. break;
  115. default:
  116. dev_err(priv->adapter->dev,
  117. "PREP_CMD: unknown cmd %#x\n", cmd_no);
  118. return -1;
  119. }
  120. return 0;
  121. }
  122. /* This function sets the RF channel for AP.
  123. *
  124. * This function populates channel information in AP config structure
  125. * and sends command to configure channel information in AP.
  126. */
  127. int mwifiex_uap_set_channel(struct mwifiex_private *priv, int channel)
  128. {
  129. struct mwifiex_uap_bss_param *bss_cfg;
  130. struct wiphy *wiphy = priv->wdev->wiphy;
  131. bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
  132. if (!bss_cfg)
  133. return -ENOMEM;
  134. bss_cfg->band_cfg = BAND_CONFIG_MANUAL;
  135. bss_cfg->channel = channel;
  136. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  137. HostCmd_ACT_GEN_SET, 0, bss_cfg)) {
  138. wiphy_err(wiphy, "Failed to set the uAP channel\n");
  139. kfree(bss_cfg);
  140. return -1;
  141. }
  142. kfree(bss_cfg);
  143. return 0;
  144. }