11h.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * Marvell Wireless LAN device driver: 802.11h
  3. *
  4. * Copyright (C) 2013-2014, 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. #include "fw.h"
  21. void mwifiex_init_11h_params(struct mwifiex_private *priv)
  22. {
  23. priv->state_11h.is_11h_enabled = true;
  24. priv->state_11h.is_11h_active = false;
  25. }
  26. inline int mwifiex_is_11h_active(struct mwifiex_private *priv)
  27. {
  28. return priv->state_11h.is_11h_active;
  29. }
  30. /* This function appends 11h info to a buffer while joining an
  31. * infrastructure BSS
  32. */
  33. static void
  34. mwifiex_11h_process_infra_join(struct mwifiex_private *priv, u8 **buffer,
  35. struct mwifiex_bssdescriptor *bss_desc)
  36. {
  37. struct mwifiex_ie_types_header *ie_header;
  38. struct mwifiex_ie_types_pwr_capability *cap;
  39. struct mwifiex_ie_types_local_pwr_constraint *constraint;
  40. struct ieee80211_supported_band *sband;
  41. u8 radio_type;
  42. int i;
  43. if (!buffer || !(*buffer))
  44. return;
  45. radio_type = mwifiex_band_to_radio_type((u8) bss_desc->bss_band);
  46. sband = priv->wdev.wiphy->bands[radio_type];
  47. cap = (struct mwifiex_ie_types_pwr_capability *)*buffer;
  48. cap->header.type = cpu_to_le16(WLAN_EID_PWR_CAPABILITY);
  49. cap->header.len = cpu_to_le16(2);
  50. cap->min_pwr = 0;
  51. cap->max_pwr = 0;
  52. *buffer += sizeof(*cap);
  53. constraint = (struct mwifiex_ie_types_local_pwr_constraint *)*buffer;
  54. constraint->header.type = cpu_to_le16(WLAN_EID_PWR_CONSTRAINT);
  55. constraint->header.len = cpu_to_le16(2);
  56. constraint->chan = bss_desc->channel;
  57. constraint->constraint = bss_desc->local_constraint;
  58. *buffer += sizeof(*constraint);
  59. ie_header = (struct mwifiex_ie_types_header *)*buffer;
  60. ie_header->type = cpu_to_le16(TLV_TYPE_PASSTHROUGH);
  61. ie_header->len = cpu_to_le16(2 * sband->n_channels + 2);
  62. *buffer += sizeof(*ie_header);
  63. *(*buffer)++ = WLAN_EID_SUPPORTED_CHANNELS;
  64. *(*buffer)++ = 2 * sband->n_channels;
  65. for (i = 0; i < sband->n_channels; i++) {
  66. *(*buffer)++ = ieee80211_frequency_to_channel(
  67. sband->channels[i].center_freq);
  68. *(*buffer)++ = 1; /* one channel in the subband */
  69. }
  70. }
  71. /* Enable or disable the 11h extensions in the firmware */
  72. int mwifiex_11h_activate(struct mwifiex_private *priv, bool flag)
  73. {
  74. u32 enable = flag;
  75. /* enable master mode radar detection on AP interface */
  76. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) && enable)
  77. enable |= MWIFIEX_MASTER_RADAR_DET_MASK;
  78. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  79. HostCmd_ACT_GEN_SET, DOT11H_I, &enable, true);
  80. }
  81. /* This functions processes TLV buffer for a pending BSS Join command.
  82. *
  83. * Activate 11h functionality in the firmware if the spectrum management
  84. * capability bit is found in the network we are joining. Also, necessary
  85. * TLVs are set based on requested network's 11h capability.
  86. */
  87. void mwifiex_11h_process_join(struct mwifiex_private *priv, u8 **buffer,
  88. struct mwifiex_bssdescriptor *bss_desc)
  89. {
  90. if (bss_desc->sensed_11h) {
  91. /* Activate 11h functions in firmware, turns on capability
  92. * bit
  93. */
  94. mwifiex_11h_activate(priv, true);
  95. priv->state_11h.is_11h_active = true;
  96. bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  97. mwifiex_11h_process_infra_join(priv, buffer, bss_desc);
  98. } else {
  99. /* Deactivate 11h functions in the firmware */
  100. mwifiex_11h_activate(priv, false);
  101. priv->state_11h.is_11h_active = false;
  102. bss_desc->cap_info_bitmap &= ~WLAN_CAPABILITY_SPECTRUM_MGMT;
  103. }
  104. }
  105. /* This is DFS CAC work queue function.
  106. * This delayed work emits CAC finished event for cfg80211 if
  107. * CAC was started earlier.
  108. */
  109. void mwifiex_dfs_cac_work_queue(struct work_struct *work)
  110. {
  111. struct cfg80211_chan_def chandef;
  112. struct delayed_work *delayed_work = to_delayed_work(work);
  113. struct mwifiex_private *priv =
  114. container_of(delayed_work, struct mwifiex_private,
  115. dfs_cac_work);
  116. if (WARN_ON(!priv))
  117. return;
  118. chandef = priv->dfs_chandef;
  119. if (priv->wdev.cac_started) {
  120. mwifiex_dbg(priv->adapter, MSG,
  121. "CAC timer finished; No radar detected\n");
  122. cfg80211_cac_event(priv->netdev, &chandef,
  123. NL80211_RADAR_CAC_FINISHED,
  124. GFP_KERNEL);
  125. }
  126. }
  127. /* This function prepares channel report request command to FW for
  128. * starting radar detection.
  129. */
  130. int mwifiex_cmd_issue_chan_report_request(struct mwifiex_private *priv,
  131. struct host_cmd_ds_command *cmd,
  132. void *data_buf)
  133. {
  134. struct host_cmd_ds_chan_rpt_req *cr_req = &cmd->params.chan_rpt_req;
  135. struct mwifiex_radar_params *radar_params = (void *)data_buf;
  136. cmd->command = cpu_to_le16(HostCmd_CMD_CHAN_REPORT_REQUEST);
  137. cmd->size = cpu_to_le16(S_DS_GEN);
  138. le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_chan_rpt_req));
  139. cr_req->chan_desc.start_freq = cpu_to_le16(MWIFIEX_A_BAND_START_FREQ);
  140. cr_req->chan_desc.chan_num = radar_params->chandef->chan->hw_value;
  141. cr_req->chan_desc.chan_width = radar_params->chandef->width;
  142. cr_req->msec_dwell_time = cpu_to_le32(radar_params->cac_time_ms);
  143. if (radar_params->cac_time_ms)
  144. mwifiex_dbg(priv->adapter, MSG,
  145. "11h: issuing DFS Radar check for channel=%d\n",
  146. radar_params->chandef->chan->hw_value);
  147. else
  148. mwifiex_dbg(priv->adapter, MSG, "cancelling CAC\n");
  149. return 0;
  150. }
  151. int mwifiex_stop_radar_detection(struct mwifiex_private *priv,
  152. struct cfg80211_chan_def *chandef)
  153. {
  154. struct mwifiex_radar_params radar_params;
  155. memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
  156. radar_params.chandef = chandef;
  157. radar_params.cac_time_ms = 0;
  158. return mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
  159. HostCmd_ACT_GEN_SET, 0, &radar_params, true);
  160. }
  161. /* This function is to abort ongoing CAC upon stopping AP operations
  162. * or during unload.
  163. */
  164. void mwifiex_abort_cac(struct mwifiex_private *priv)
  165. {
  166. if (priv->wdev.cac_started) {
  167. if (mwifiex_stop_radar_detection(priv, &priv->dfs_chandef))
  168. mwifiex_dbg(priv->adapter, ERROR,
  169. "failed to stop CAC in FW\n");
  170. mwifiex_dbg(priv->adapter, MSG,
  171. "Aborting delayed work for CAC.\n");
  172. cancel_delayed_work_sync(&priv->dfs_cac_work);
  173. cfg80211_cac_event(priv->netdev, &priv->dfs_chandef,
  174. NL80211_RADAR_CAC_ABORTED, GFP_KERNEL);
  175. }
  176. }
  177. /* This function handles channel report event from FW during CAC period.
  178. * If radar is detected during CAC, driver indicates the same to cfg80211
  179. * and also cancels ongoing delayed work.
  180. */
  181. int mwifiex_11h_handle_chanrpt_ready(struct mwifiex_private *priv,
  182. struct sk_buff *skb)
  183. {
  184. struct host_cmd_ds_chan_rpt_event *rpt_event;
  185. struct mwifiex_ie_types_chan_rpt_data *rpt;
  186. u8 *evt_buf;
  187. u16 event_len, tlv_len;
  188. rpt_event = (void *)(skb->data + sizeof(u32));
  189. event_len = skb->len - (sizeof(struct host_cmd_ds_chan_rpt_event)+
  190. sizeof(u32));
  191. if (le32_to_cpu(rpt_event->result) != HostCmd_RESULT_OK) {
  192. mwifiex_dbg(priv->adapter, ERROR,
  193. "Error in channel report event\n");
  194. return -1;
  195. }
  196. evt_buf = (void *)&rpt_event->tlvbuf;
  197. while (event_len >= sizeof(struct mwifiex_ie_types_header)) {
  198. rpt = (void *)&rpt_event->tlvbuf;
  199. tlv_len = le16_to_cpu(rpt->header.len);
  200. switch (le16_to_cpu(rpt->header.type)) {
  201. case TLV_TYPE_CHANRPT_11H_BASIC:
  202. if (rpt->map.radar) {
  203. mwifiex_dbg(priv->adapter, MSG,
  204. "RADAR Detected on channel %d!\n",
  205. priv->dfs_chandef.chan->hw_value);
  206. cancel_delayed_work_sync(&priv->dfs_cac_work);
  207. cfg80211_cac_event(priv->netdev,
  208. &priv->dfs_chandef,
  209. NL80211_RADAR_DETECTED,
  210. GFP_KERNEL);
  211. }
  212. break;
  213. default:
  214. break;
  215. }
  216. evt_buf += (tlv_len + sizeof(rpt->header));
  217. event_len -= (tlv_len + sizeof(rpt->header));
  218. }
  219. return 0;
  220. }
  221. /* Handler for radar detected event from FW.*/
  222. int mwifiex_11h_handle_radar_detected(struct mwifiex_private *priv,
  223. struct sk_buff *skb)
  224. {
  225. struct mwifiex_radar_det_event *rdr_event;
  226. rdr_event = (void *)(skb->data + sizeof(u32));
  227. mwifiex_dbg(priv->adapter, MSG,
  228. "radar detected; indicating kernel\n");
  229. if (mwifiex_stop_radar_detection(priv, &priv->dfs_chandef))
  230. mwifiex_dbg(priv->adapter, ERROR,
  231. "Failed to stop CAC in FW\n");
  232. cfg80211_radar_event(priv->adapter->wiphy, &priv->dfs_chandef,
  233. GFP_KERNEL);
  234. mwifiex_dbg(priv->adapter, MSG, "regdomain: %d\n",
  235. rdr_event->reg_domain);
  236. mwifiex_dbg(priv->adapter, MSG, "radar detection type: %d\n",
  237. rdr_event->det_type);
  238. return 0;
  239. }
  240. /* This is work queue function for channel switch handling.
  241. * This function takes care of updating new channel definitin to
  242. * bss config structure, restart AP and indicate channel switch success
  243. * to cfg80211.
  244. */
  245. void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
  246. {
  247. struct mwifiex_uap_bss_param *bss_cfg;
  248. struct delayed_work *delayed_work = to_delayed_work(work);
  249. struct mwifiex_private *priv =
  250. container_of(delayed_work, struct mwifiex_private,
  251. dfs_chan_sw_work);
  252. if (WARN_ON(!priv))
  253. return;
  254. bss_cfg = &priv->bss_cfg;
  255. if (!bss_cfg->beacon_period) {
  256. mwifiex_dbg(priv->adapter, ERROR,
  257. "channel switch: AP already stopped\n");
  258. return;
  259. }
  260. mwifiex_uap_set_channel(priv, bss_cfg, priv->dfs_chandef);
  261. if (mwifiex_config_start_uap(priv, bss_cfg)) {
  262. mwifiex_dbg(priv->adapter, ERROR,
  263. "Failed to start AP after channel switch\n");
  264. return;
  265. }
  266. mwifiex_dbg(priv->adapter, MSG,
  267. "indicating channel switch completion to kernel\n");
  268. cfg80211_ch_switch_notify(priv->netdev, &priv->dfs_chandef);
  269. }