11h.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 =
  113. container_of(work, struct delayed_work, work);
  114. struct mwifiex_private *priv =
  115. container_of(delayed_work, struct mwifiex_private,
  116. dfs_cac_work);
  117. if (WARN_ON(!priv))
  118. return;
  119. chandef = priv->dfs_chandef;
  120. if (priv->wdev.cac_started) {
  121. mwifiex_dbg(priv->adapter, MSG,
  122. "CAC timer finished; No radar detected\n");
  123. cfg80211_cac_event(priv->netdev, &chandef,
  124. NL80211_RADAR_CAC_FINISHED,
  125. GFP_KERNEL);
  126. }
  127. }
  128. /* This function prepares channel report request command to FW for
  129. * starting radar detection.
  130. */
  131. int mwifiex_cmd_issue_chan_report_request(struct mwifiex_private *priv,
  132. struct host_cmd_ds_command *cmd,
  133. void *data_buf)
  134. {
  135. struct host_cmd_ds_chan_rpt_req *cr_req = &cmd->params.chan_rpt_req;
  136. struct mwifiex_radar_params *radar_params = (void *)data_buf;
  137. cmd->command = cpu_to_le16(HostCmd_CMD_CHAN_REPORT_REQUEST);
  138. cmd->size = cpu_to_le16(S_DS_GEN);
  139. le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_chan_rpt_req));
  140. cr_req->chan_desc.start_freq = cpu_to_le16(MWIFIEX_A_BAND_START_FREQ);
  141. cr_req->chan_desc.chan_num = radar_params->chandef->chan->hw_value;
  142. cr_req->chan_desc.chan_width = radar_params->chandef->width;
  143. cr_req->msec_dwell_time = cpu_to_le32(radar_params->cac_time_ms);
  144. if (radar_params->cac_time_ms)
  145. mwifiex_dbg(priv->adapter, MSG,
  146. "11h: issuing DFS Radar check for channel=%d\n",
  147. radar_params->chandef->chan->hw_value);
  148. else
  149. mwifiex_dbg(priv->adapter, MSG, "cancelling CAC\n");
  150. return 0;
  151. }
  152. int mwifiex_stop_radar_detection(struct mwifiex_private *priv,
  153. struct cfg80211_chan_def *chandef)
  154. {
  155. struct mwifiex_radar_params radar_params;
  156. memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
  157. radar_params.chandef = chandef;
  158. radar_params.cac_time_ms = 0;
  159. return mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
  160. HostCmd_ACT_GEN_SET, 0, &radar_params, true);
  161. }
  162. /* This function is to abort ongoing CAC upon stopping AP operations
  163. * or during unload.
  164. */
  165. void mwifiex_abort_cac(struct mwifiex_private *priv)
  166. {
  167. if (priv->wdev.cac_started) {
  168. if (mwifiex_stop_radar_detection(priv, &priv->dfs_chandef))
  169. mwifiex_dbg(priv->adapter, ERROR,
  170. "failed to stop CAC in FW\n");
  171. mwifiex_dbg(priv->adapter, MSG,
  172. "Aborting delayed work for CAC.\n");
  173. cancel_delayed_work_sync(&priv->dfs_cac_work);
  174. cfg80211_cac_event(priv->netdev, &priv->dfs_chandef,
  175. NL80211_RADAR_CAC_ABORTED, GFP_KERNEL);
  176. }
  177. }
  178. /* This function handles channel report event from FW during CAC period.
  179. * If radar is detected during CAC, driver indicates the same to cfg80211
  180. * and also cancels ongoing delayed work.
  181. */
  182. int mwifiex_11h_handle_chanrpt_ready(struct mwifiex_private *priv,
  183. struct sk_buff *skb)
  184. {
  185. struct host_cmd_ds_chan_rpt_event *rpt_event;
  186. struct mwifiex_ie_types_chan_rpt_data *rpt;
  187. u8 *evt_buf;
  188. u16 event_len, tlv_len;
  189. rpt_event = (void *)(skb->data + sizeof(u32));
  190. event_len = skb->len - (sizeof(struct host_cmd_ds_chan_rpt_event)+
  191. sizeof(u32));
  192. if (le32_to_cpu(rpt_event->result) != HostCmd_RESULT_OK) {
  193. mwifiex_dbg(priv->adapter, ERROR,
  194. "Error in channel report event\n");
  195. return -1;
  196. }
  197. evt_buf = (void *)&rpt_event->tlvbuf;
  198. while (event_len >= sizeof(struct mwifiex_ie_types_header)) {
  199. rpt = (void *)&rpt_event->tlvbuf;
  200. tlv_len = le16_to_cpu(rpt->header.len);
  201. switch (le16_to_cpu(rpt->header.type)) {
  202. case TLV_TYPE_CHANRPT_11H_BASIC:
  203. if (rpt->map.radar) {
  204. mwifiex_dbg(priv->adapter, MSG,
  205. "RADAR Detected on channel %d!\n",
  206. priv->dfs_chandef.chan->hw_value);
  207. cancel_delayed_work_sync(&priv->dfs_cac_work);
  208. cfg80211_cac_event(priv->netdev,
  209. &priv->dfs_chandef,
  210. NL80211_RADAR_DETECTED,
  211. GFP_KERNEL);
  212. }
  213. break;
  214. default:
  215. break;
  216. }
  217. evt_buf += (tlv_len + sizeof(rpt->header));
  218. event_len -= (tlv_len + sizeof(rpt->header));
  219. }
  220. return 0;
  221. }
  222. /* Handler for radar detected event from FW.*/
  223. int mwifiex_11h_handle_radar_detected(struct mwifiex_private *priv,
  224. struct sk_buff *skb)
  225. {
  226. struct mwifiex_radar_det_event *rdr_event;
  227. rdr_event = (void *)(skb->data + sizeof(u32));
  228. if (le32_to_cpu(rdr_event->passed)) {
  229. mwifiex_dbg(priv->adapter, MSG,
  230. "radar detected; indicating kernel\n");
  231. if (mwifiex_stop_radar_detection(priv, &priv->dfs_chandef))
  232. mwifiex_dbg(priv->adapter, ERROR,
  233. "Failed to stop CAC in FW\n");
  234. cfg80211_radar_event(priv->adapter->wiphy, &priv->dfs_chandef,
  235. GFP_KERNEL);
  236. mwifiex_dbg(priv->adapter, MSG, "regdomain: %d\n",
  237. rdr_event->reg_domain);
  238. mwifiex_dbg(priv->adapter, MSG, "radar detection type: %d\n",
  239. rdr_event->det_type);
  240. } else {
  241. mwifiex_dbg(priv->adapter, MSG,
  242. "false radar detection event!\n");
  243. }
  244. return 0;
  245. }
  246. /* This is work queue function for channel switch handling.
  247. * This function takes care of updating new channel definitin to
  248. * bss config structure, restart AP and indicate channel switch success
  249. * to cfg80211.
  250. */
  251. void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)
  252. {
  253. struct mwifiex_uap_bss_param *bss_cfg;
  254. struct delayed_work *delayed_work =
  255. container_of(work, struct delayed_work, work);
  256. struct mwifiex_private *priv =
  257. container_of(delayed_work, struct mwifiex_private,
  258. dfs_chan_sw_work);
  259. if (WARN_ON(!priv))
  260. return;
  261. bss_cfg = &priv->bss_cfg;
  262. if (!bss_cfg->beacon_period) {
  263. mwifiex_dbg(priv->adapter, ERROR,
  264. "channel switch: AP already stopped\n");
  265. return;
  266. }
  267. mwifiex_uap_set_channel(priv, bss_cfg, priv->dfs_chandef);
  268. if (mwifiex_config_start_uap(priv, bss_cfg)) {
  269. mwifiex_dbg(priv->adapter, ERROR,
  270. "Failed to start AP after channel switch\n");
  271. return;
  272. }
  273. mwifiex_dbg(priv->adapter, MSG,
  274. "indicating channel switch completion to kernel\n");
  275. cfg80211_ch_switch_notify(priv->netdev, &priv->dfs_chandef);
  276. }