cmd.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * This file is part of wl18xx
  3. *
  4. * Copyright (C) 2011 Texas Instruments Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include "../wlcore/cmd.h"
  22. #include "../wlcore/debug.h"
  23. #include "../wlcore/hw_ops.h"
  24. #include "cmd.h"
  25. int wl18xx_cmd_channel_switch(struct wl1271 *wl,
  26. struct wl12xx_vif *wlvif,
  27. struct ieee80211_channel_switch *ch_switch)
  28. {
  29. struct wl18xx_cmd_channel_switch *cmd;
  30. u32 supported_rates;
  31. int ret;
  32. wl1271_debug(DEBUG_ACX, "cmd channel switch");
  33. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  34. if (!cmd) {
  35. ret = -ENOMEM;
  36. goto out;
  37. }
  38. cmd->role_id = wlvif->role_id;
  39. cmd->channel = ch_switch->chandef.chan->hw_value;
  40. cmd->switch_time = ch_switch->count;
  41. cmd->stop_tx = ch_switch->block_tx;
  42. switch (ch_switch->chandef.chan->band) {
  43. case IEEE80211_BAND_2GHZ:
  44. cmd->band = WLCORE_BAND_2_4GHZ;
  45. break;
  46. case IEEE80211_BAND_5GHZ:
  47. cmd->band = WLCORE_BAND_5GHZ;
  48. break;
  49. default:
  50. wl1271_error("invalid channel switch band: %d",
  51. ch_switch->chandef.chan->band);
  52. ret = -EINVAL;
  53. goto out_free;
  54. }
  55. supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES |
  56. wlcore_hw_sta_get_ap_rate_mask(wl, wlvif);
  57. if (wlvif->p2p)
  58. supported_rates &= ~CONF_TX_CCK_RATES;
  59. cmd->local_supported_rates = cpu_to_le32(supported_rates);
  60. cmd->channel_type = wlvif->channel_type;
  61. ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
  62. if (ret < 0) {
  63. wl1271_error("failed to send channel switch command");
  64. goto out_free;
  65. }
  66. out_free:
  67. kfree(cmd);
  68. out:
  69. return ret;
  70. }
  71. int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap)
  72. {
  73. struct wl18xx_cmd_smart_config_start *cmd;
  74. int ret = 0;
  75. wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x",
  76. group_bitmap);
  77. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  78. if (!cmd) {
  79. ret = -ENOMEM;
  80. goto out;
  81. }
  82. cmd->group_id_bitmask = cpu_to_le32(group_bitmap);
  83. ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0);
  84. if (ret < 0) {
  85. wl1271_error("failed to send smart config start command");
  86. goto out_free;
  87. }
  88. out_free:
  89. kfree(cmd);
  90. out:
  91. return ret;
  92. }
  93. int wl18xx_cmd_smart_config_stop(struct wl1271 *wl)
  94. {
  95. struct wl1271_cmd_header *cmd;
  96. int ret = 0;
  97. wl1271_debug(DEBUG_CMD, "cmd smart config stop");
  98. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  99. if (!cmd) {
  100. ret = -ENOMEM;
  101. goto out;
  102. }
  103. ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0);
  104. if (ret < 0) {
  105. wl1271_error("failed to send smart config stop command");
  106. goto out_free;
  107. }
  108. out_free:
  109. kfree(cmd);
  110. out:
  111. return ret;
  112. }
  113. int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id,
  114. u8 key_len, u8 *key)
  115. {
  116. struct wl18xx_cmd_smart_config_set_group_key *cmd;
  117. int ret = 0;
  118. wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x",
  119. group_id);
  120. if (key_len != sizeof(cmd->key)) {
  121. wl1271_error("invalid group key size: %d", key_len);
  122. return -E2BIG;
  123. }
  124. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  125. if (!cmd) {
  126. ret = -ENOMEM;
  127. goto out;
  128. }
  129. cmd->group_id = cpu_to_le32(group_id);
  130. memcpy(cmd->key, key, key_len);
  131. ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd,
  132. sizeof(*cmd), 0);
  133. if (ret < 0) {
  134. wl1271_error("failed to send smart config set group key cmd");
  135. goto out_free;
  136. }
  137. out_free:
  138. kfree(cmd);
  139. out:
  140. return ret;
  141. }