cmd.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 (count=%d)",
  33. ch_switch->count);
  34. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  35. if (!cmd) {
  36. ret = -ENOMEM;
  37. goto out;
  38. }
  39. cmd->role_id = wlvif->role_id;
  40. cmd->channel = ch_switch->chandef.chan->hw_value;
  41. cmd->switch_time = ch_switch->count;
  42. cmd->stop_tx = ch_switch->block_tx;
  43. switch (ch_switch->chandef.chan->band) {
  44. case IEEE80211_BAND_2GHZ:
  45. cmd->band = WLCORE_BAND_2_4GHZ;
  46. break;
  47. case IEEE80211_BAND_5GHZ:
  48. cmd->band = WLCORE_BAND_5GHZ;
  49. break;
  50. default:
  51. wl1271_error("invalid channel switch band: %d",
  52. ch_switch->chandef.chan->band);
  53. ret = -EINVAL;
  54. goto out_free;
  55. }
  56. supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES;
  57. if (wlvif->bss_type == BSS_TYPE_STA_BSS)
  58. supported_rates |= wlcore_hw_sta_get_ap_rate_mask(wl, wlvif);
  59. else
  60. supported_rates |=
  61. wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
  62. if (wlvif->p2p)
  63. supported_rates &= ~CONF_TX_CCK_RATES;
  64. cmd->local_supported_rates = cpu_to_le32(supported_rates);
  65. cmd->channel_type = wlvif->channel_type;
  66. ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
  67. if (ret < 0) {
  68. wl1271_error("failed to send channel switch command");
  69. goto out_free;
  70. }
  71. out_free:
  72. kfree(cmd);
  73. out:
  74. return ret;
  75. }
  76. int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap)
  77. {
  78. struct wl18xx_cmd_smart_config_start *cmd;
  79. int ret = 0;
  80. wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x",
  81. group_bitmap);
  82. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  83. if (!cmd) {
  84. ret = -ENOMEM;
  85. goto out;
  86. }
  87. cmd->group_id_bitmask = cpu_to_le32(group_bitmap);
  88. ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0);
  89. if (ret < 0) {
  90. wl1271_error("failed to send smart config start command");
  91. goto out_free;
  92. }
  93. out_free:
  94. kfree(cmd);
  95. out:
  96. return ret;
  97. }
  98. int wl18xx_cmd_smart_config_stop(struct wl1271 *wl)
  99. {
  100. struct wl1271_cmd_header *cmd;
  101. int ret = 0;
  102. wl1271_debug(DEBUG_CMD, "cmd smart config stop");
  103. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  104. if (!cmd) {
  105. ret = -ENOMEM;
  106. goto out;
  107. }
  108. ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0);
  109. if (ret < 0) {
  110. wl1271_error("failed to send smart config stop command");
  111. goto out_free;
  112. }
  113. out_free:
  114. kfree(cmd);
  115. out:
  116. return ret;
  117. }
  118. int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id,
  119. u8 key_len, u8 *key)
  120. {
  121. struct wl18xx_cmd_smart_config_set_group_key *cmd;
  122. int ret = 0;
  123. wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x",
  124. group_id);
  125. if (key_len != sizeof(cmd->key)) {
  126. wl1271_error("invalid group key size: %d", key_len);
  127. return -E2BIG;
  128. }
  129. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  130. if (!cmd) {
  131. ret = -ENOMEM;
  132. goto out;
  133. }
  134. cmd->group_id = cpu_to_le32(group_id);
  135. memcpy(cmd->key, key, key_len);
  136. ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd,
  137. sizeof(*cmd), 0);
  138. if (ret < 0) {
  139. wl1271_error("failed to send smart config set group key cmd");
  140. goto out_free;
  141. }
  142. out_free:
  143. kfree(cmd);
  144. out:
  145. return ret;
  146. }
  147. int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start)
  148. {
  149. struct wlcore_cmd_cac_start *cmd;
  150. int ret = 0;
  151. wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s",
  152. wlvif->channel, start ? "start" : "stop");
  153. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  154. if (!cmd)
  155. return -ENOMEM;
  156. cmd->role_id = wlvif->role_id;
  157. cmd->channel = wlvif->channel;
  158. if (wlvif->band == IEEE80211_BAND_5GHZ)
  159. cmd->band = WLCORE_BAND_5GHZ;
  160. cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type);
  161. ret = wl1271_cmd_send(wl,
  162. start ? CMD_CAC_START : CMD_CAC_STOP,
  163. cmd, sizeof(*cmd), 0);
  164. if (ret < 0) {
  165. wl1271_error("failed to send cac command");
  166. goto out_free;
  167. }
  168. out_free:
  169. kfree(cmd);
  170. return ret;
  171. }
  172. int wl18xx_cmd_radar_detection_debug(struct wl1271 *wl, u8 channel)
  173. {
  174. struct wl18xx_cmd_dfs_radar_debug *cmd;
  175. int ret = 0;
  176. wl1271_debug(DEBUG_CMD, "cmd radar detection debug (chan %d)",
  177. channel);
  178. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  179. if (!cmd)
  180. return -ENOMEM;
  181. cmd->channel = channel;
  182. ret = wl1271_cmd_send(wl, CMD_DFS_RADAR_DETECTION_DEBUG,
  183. cmd, sizeof(*cmd), 0);
  184. if (ret < 0) {
  185. wl1271_error("failed to send radar detection debug command");
  186. goto out_free;
  187. }
  188. out_free:
  189. kfree(cmd);
  190. return ret;
  191. }
  192. int wl18xx_cmd_dfs_master_restart(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  193. {
  194. struct wl18xx_cmd_dfs_master_restart *cmd;
  195. int ret = 0;
  196. wl1271_debug(DEBUG_CMD, "cmd dfs master restart (role %d)",
  197. wlvif->role_id);
  198. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  199. if (!cmd)
  200. return -ENOMEM;
  201. cmd->role_id = wlvif->role_id;
  202. ret = wl1271_cmd_send(wl, CMD_DFS_MASTER_RESTART,
  203. cmd, sizeof(*cmd), 0);
  204. if (ret < 0) {
  205. wl1271_error("failed to send dfs master restart command");
  206. goto out_free;
  207. }
  208. out_free:
  209. kfree(cmd);
  210. return ret;
  211. }