linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iw: support multiple regdom print
@ 2014-12-15 16:44 Arik Nemtsov
  2014-12-17 14:16 ` Johannes Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Arik Nemtsov @ 2014-12-15 16:44 UTC (permalink / raw)
  To: linux-wireless; +Cc: Johannes Berg, Arik Nemtsov

When a phy is given, print only its regdomain. Otherwise, use the newly
implement dump functionality to print all regdomains in the system.

Signed-off-by: Arik Nemtsov <arik@wizery.com>
---
v2: fix reg get for older kernels

 reg.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/reg.c b/reg.c
index a02c982..0aef7ba 100644
--- a/reg.c
+++ b/reg.c
@@ -114,7 +114,6 @@ COMMAND(reg, set, "<ISO/IEC 3166-1 alpha2>",
 	"Notify the kernel about the current regulatory domain.");
 
 static int print_reg_handler(struct nl_msg *msg, void *arg)
-
 {
 #define PARSE_FLAG(nl_flag, string_value)  do { \
 		if ((flags & nl_flag)) { \
@@ -150,6 +149,13 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
 		return NL_SKIP;
 	}
 
+	if (tb_msg[NL80211_ATTR_WIPHY])
+		printf("phy#%d%s\n", nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]),
+		       tb_msg[NL80211_ATTR_WIPHY_SELF_MANAGED_REG] ?
+		       " (self-managed)" : "");
+	else
+		printf("global\n");
+
 	if (tb_msg[NL80211_ATTR_DFS_REGION])
 		dfs_domain = nla_get_u8(tb_msg[NL80211_ATTR_DFS_REGION]);
 	else
@@ -216,18 +222,44 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
 
 		printf("\n");
 	}
-	return NL_OK;
+
+	printf("\n");
+	return NL_SKIP;
 #undef PARSE_FLAG
 }
 
+static int handle_reg_dump(struct nl80211_state *state,
+			   struct nl_cb *cb,
+			   struct nl_msg *msg,
+			   int argc, char **argv,
+			   enum id_input id)
+{
+	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_reg_handler, NULL);
+	return 0;
+}
+
 static int handle_reg_get(struct nl80211_state *state,
 			  struct nl_cb *cb,
 			  struct nl_msg *msg,
 			  int argc, char **argv,
 			  enum id_input id)
 {
-	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_reg_handler, NULL);
-	return 0;
+	char *dump_args[] = { "reg", "dump" };
+	int err;
+
+	err = handle_cmd(state, CIB_NONE, 2, dump_args);
+	/* dump might fail since it's not supported on older kernels */
+	if (err == -EOPNOTSUPP) {
+		nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_reg_handler,
+			  NULL);
+		return 0;
+	}
+
+	return err;
 }
 COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_NONE, handle_reg_get,
 	"Print out the kernel's current regulatory domain information.");
+COMMAND(reg, get, NULL, NL80211_CMD_GET_REG, 0, CIB_PHY, handle_reg_get,
+	"Print out the devices' current regulatory domain information.");
+HIDDEN(reg, dump, NULL, NL80211_CMD_GET_REG, NLM_F_DUMP, CIB_NONE,
+       handle_reg_dump);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iw: support multiple regdom print
  2014-12-15 16:44 [PATCH v2] iw: support multiple regdom print Arik Nemtsov
@ 2014-12-17 14:16 ` Johannes Berg
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Berg @ 2014-12-17 14:16 UTC (permalink / raw)
  To: Arik Nemtsov; +Cc: linux-wireless

On Mon, 2014-12-15 at 18:44 +0200, Arik Nemtsov wrote:
> When a phy is given, print only its regdomain. Otherwise, use the newly
> implement dump functionality to print all regdomains in the system.

Applied.

johannes


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-17 14:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-15 16:44 [PATCH v2] iw: support multiple regdom print Arik Nemtsov
2014-12-17 14:16 ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).