304-add-channels-PHY-command-listing-frequencies-with-mo.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. From db9d4050d7dff994a43fa954ff47ac94a898f728 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Wed, 1 Jun 2016 07:51:14 +0200
  4. Subject: [PATCH] add "channels" PHY command listing frequencies with more
  5. details
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. Channels (frequencies) are getting more details that users may want to
  10. know about. E.g. it's important to know which frequencies allow using
  11. 40/80/160 MHz channels to setup AP properly.
  12. We list channels in "info" command output but it's already quite big and
  13. it was agreed to introduce new command rather than expand the old one.
  14. This patch adds "channels" command printing what was already available
  15. in the "info" plus details about supported channel widths. It also
  16. removes DFS info from the "info" output.
  17. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  18. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  19. ---
  20. info.c | 30 -------------
  21. phy.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  22. 2 files changed, 152 insertions(+), 30 deletions(-)
  23. --- a/info.c
  24. +++ b/info.c
  25. @@ -49,20 +49,6 @@ static char *cipher_name(__u32 c)
  26. }
  27. }
  28. -static char *dfs_state_name(enum nl80211_dfs_state state)
  29. -{
  30. - switch (state) {
  31. - case NL80211_DFS_USABLE:
  32. - return "usable";
  33. - case NL80211_DFS_AVAILABLE:
  34. - return "available";
  35. - case NL80211_DFS_UNAVAILABLE:
  36. - return "unavailable";
  37. - default:
  38. - return "unknown";
  39. - }
  40. -}
  41. -
  42. static int ext_feature_isset(const unsigned char *ext_features, int ext_features_len,
  43. enum nl80211_ext_feature_index ftidx)
  44. {
  45. @@ -200,22 +186,6 @@ next:
  46. if (open)
  47. printf(")");
  48. printf("\n");
  49. -
  50. - if (!tb_freq[NL80211_FREQUENCY_ATTR_DISABLED] && tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
  51. - enum nl80211_dfs_state state = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
  52. - unsigned long time;
  53. -
  54. - printf("\t\t\t DFS state: %s", dfs_state_name(state));
  55. - if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_TIME]) {
  56. - time = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_TIME]);
  57. - printf(" (for %lu sec)", time/1000);
  58. - }
  59. - printf("\n");
  60. - if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME])
  61. - printf("\t\t\t DFS CAC time: %u ms\n",
  62. - nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]));
  63. - }
  64. -
  65. }
  66. }
  67. --- a/phy.c
  68. +++ b/phy.c
  69. @@ -15,6 +15,158 @@
  70. #include "nl80211.h"
  71. #include "iw.h"
  72. +struct channels_ctx {
  73. + int last_band;
  74. + bool width_40;
  75. + bool width_80;
  76. + bool width_160;
  77. +};
  78. +
  79. +static char *dfs_state_name(enum nl80211_dfs_state state)
  80. +{
  81. + switch (state) {
  82. + case NL80211_DFS_USABLE:
  83. + return "usable";
  84. + case NL80211_DFS_AVAILABLE:
  85. + return "available";
  86. + case NL80211_DFS_UNAVAILABLE:
  87. + return "unavailable";
  88. + default:
  89. + return "unknown";
  90. + }
  91. +}
  92. +
  93. +static int print_channels_handler(struct nl_msg *msg, void *arg)
  94. +{
  95. + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  96. + struct channels_ctx *ctx = arg;
  97. + struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
  98. + struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
  99. + struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
  100. + struct nlattr *nl_band;
  101. + struct nlattr *nl_freq;
  102. + int rem_band, rem_freq;
  103. +
  104. + nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
  105. +
  106. + if (tb_msg[NL80211_ATTR_WIPHY_BANDS]) {
  107. + nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
  108. + if (ctx->last_band != nl_band->nla_type) {
  109. + printf("Band %d:\n", nl_band->nla_type + 1);
  110. + ctx->width_40 = false;
  111. + ctx->width_80 = false;
  112. + ctx->width_160 = false;
  113. + ctx->last_band = nl_band->nla_type;
  114. + }
  115. +
  116. + nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), nla_len(nl_band), NULL);
  117. +
  118. + if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) {
  119. + __u16 cap = nla_get_u16(tb_band[NL80211_BAND_ATTR_HT_CAPA]);
  120. +
  121. + if (cap & BIT(1))
  122. + ctx->width_40 = true;
  123. + }
  124. +
  125. + if (tb_band[NL80211_BAND_ATTR_VHT_CAPA]) {
  126. + __u32 capa;
  127. +
  128. + ctx->width_80 = true;
  129. +
  130. + capa = nla_get_u32(tb_band[NL80211_BAND_ATTR_VHT_CAPA]);
  131. + switch ((capa >> 2) & 3) {
  132. + case 2:
  133. + /* width_80p80 = true; */
  134. + /* fall through */
  135. + case 1:
  136. + ctx->width_160 = true;
  137. + break;
  138. + }
  139. + }
  140. +
  141. + if (tb_band[NL80211_BAND_ATTR_FREQS]) {
  142. + nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
  143. + uint32_t freq;
  144. +
  145. + nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), nla_len(nl_freq), NULL);
  146. +
  147. + if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
  148. + continue;
  149. + freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
  150. + printf("\t* %d MHz [%d] ", freq, ieee80211_frequency_to_channel(freq));
  151. +
  152. + if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) {
  153. + printf("(disabled)\n");
  154. + continue;
  155. + }
  156. + printf("\n");
  157. +
  158. + if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER])
  159. + printf("\t Maximum TX power: %.1f dBm\n", 0.01 * nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]));
  160. +
  161. + /* If both flags are set assume an new kernel */
  162. + if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IR] && tb_freq[__NL80211_FREQUENCY_ATTR_NO_IBSS]) {
  163. + printf("\t No IR\n");
  164. + } else if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) {
  165. + printf("\t Passive scan\n");
  166. + } else if (tb_freq[__NL80211_FREQUENCY_ATTR_NO_IBSS]){
  167. + printf("\t No IBSS\n");
  168. + }
  169. +
  170. + if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
  171. + printf("\t Radar detection\n");
  172. +
  173. + printf("\t Channel widths:");
  174. + if (!tb_freq[NL80211_FREQUENCY_ATTR_NO_20MHZ])
  175. + printf(" 20MHz");
  176. + if (ctx->width_40 && !tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_MINUS])
  177. + printf(" HT40-");
  178. + if (ctx->width_40 && !tb_freq[NL80211_FREQUENCY_ATTR_NO_HT40_PLUS])
  179. + printf(" HT40+");
  180. + if (ctx->width_80 && !tb_freq[NL80211_FREQUENCY_ATTR_NO_80MHZ])
  181. + printf(" VHT80");
  182. + if (ctx->width_160 && !tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
  183. + printf(" VHT160");
  184. + printf("\n");
  185. +
  186. + if (!tb_freq[NL80211_FREQUENCY_ATTR_DISABLED] && tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
  187. + enum nl80211_dfs_state state = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]);
  188. + unsigned long time;
  189. +
  190. + printf("\t DFS state: %s", dfs_state_name(state));
  191. + if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_TIME]) {
  192. + time = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_TIME]);
  193. + printf(" (for %lu sec)", time / 1000);
  194. + }
  195. + printf("\n");
  196. + if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME])
  197. + printf("\t DFS CAC time: %u ms\n",
  198. + nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_CAC_TIME]));
  199. + }
  200. + }
  201. + }
  202. + }
  203. + }
  204. +
  205. + return NL_SKIP;
  206. +}
  207. +
  208. +static int handle_channels(struct nl80211_state *state, struct nl_msg *msg,
  209. + int argc, char **argv, enum id_input id)
  210. +{
  211. + static struct channels_ctx ctx = {
  212. + .last_band = -1,
  213. + };
  214. +
  215. + nla_put_flag(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP);
  216. + nlmsg_hdr(msg)->nlmsg_flags |= NLM_F_DUMP;
  217. +
  218. + register_handler(print_channels_handler, &ctx);
  219. +
  220. + return 0;
  221. +}
  222. +TOPLEVEL(channels, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_PHY, handle_channels, "Show available channels.");
  223. +
  224. static int handle_name(struct nl80211_state *state,
  225. struct nl_msg *msg,
  226. int argc, char **argv,