]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
print scan info on event
authorJohannes Berg <johannes@sipsolutions.net>
Sun, 24 May 2009 14:48:17 +0000 (16:48 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Sun, 24 May 2009 14:48:17 +0000 (16:48 +0200)
event.c
iw.h
scan.c
util.c

diff --git a/event.c b/event.c
index a9e08a9f8d6449c5c04a01f219f8c7190fa7b1c2..d525ab4e084efb03aa17653d40d892b211851bc1 100644 (file)
--- a/event.c
+++ b/event.c
@@ -75,11 +75,12 @@ static void print_frame(struct print_event_args *args, struct nlattr *attr)
 static int print_event(struct nl_msg *msg, void *arg)
 {
        struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
-       struct nlattr *tb[NL80211_ATTR_MAX + 1];
+       struct nlattr *tb[NL80211_ATTR_MAX + 1], *nst;
        struct print_event_args *args = arg;
        char ifname[100];
        char macbuf[6*3];
        __u8 reg_type;
+       int rem_nst;
 
        if (args->time) {
                struct timeval tv;
@@ -105,10 +106,23 @@ static int print_event(struct nl_msg *msg, void *arg)
                printf("renamed to %s\n", nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]));
                break;
        case NL80211_CMD_NEW_SCAN_RESULTS:
-               printf("scan finished\n");
-               break;
+               printf("scan finished:");
        case NL80211_CMD_SCAN_ABORTED:
-               printf("scan aborted\n");
+               if (gnlh->cmd == NL80211_CMD_SCAN_ABORTED)
+                       printf("scan aborted:");
+               if (tb[NL80211_ATTR_SCAN_FREQUENCIES]) {
+                       nla_for_each_nested(nst, tb[NL80211_ATTR_SCAN_FREQUENCIES], rem_nst)
+                               printf(" %d", nla_get_u32(nst));
+                       printf(",");
+               }
+               if (tb[NL80211_ATTR_SCAN_SSIDS]) {
+                       nla_for_each_nested(nst, tb[NL80211_ATTR_SCAN_SSIDS], rem_nst) {
+                               printf(" \"");
+                               print_ssid_escaped(nla_len(nst), nla_data(nst));
+                               printf("\"");
+                       }
+               }
+               printf("\n");
                break;
        case NL80211_CMD_REG_CHANGE:
                printf("regulatory domain change: ");
diff --git a/iw.h b/iw.h
index d97cc6e5320591dd28436e19451b536248059af4..339ebc1eec46ed3243c35b80196cc41303bf971b 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -95,6 +95,8 @@ const char *iftype_name(enum nl80211_iftype iftype);
 int ieee80211_channel_to_frequency(int chan);
 int ieee80211_frequency_to_channel(int freq);
 
+void print_ssid_escaped(const uint8_t len, const uint8_t *data);
+
 int nl_get_multicast_id(struct nl_sock *sock, const char *family, const char *group);
 
 char *reg_initiator_to_string(__u8 initiator);
diff --git a/scan.c b/scan.c
index 4c0c9e6deaf495891492d2848f71df62dbc51749..b0b6aca105aa24c56f0b4a706aaaa373d51edbf3 100644 (file)
--- a/scan.c
+++ b/scan.c
@@ -122,16 +122,8 @@ static void tab_on_first(bool *first)
 
 static void print_ssid(const uint8_t type, uint8_t len, const uint8_t *data)
 {
-       int i;
-
        printf(" ");
-
-       for (i = 0; i < len; i++) {
-               if (isprint(data[i]))
-                       printf("%c", data[i]);
-               else
-                       printf("\\x%.2x", data[i]);
-       }
+       print_ssid_escaped(len, data);
        printf("\n");
 }
 
diff --git a/util.c b/util.c
index dcb3de610352d0516895a0b8fd065f6075ced784..1750de26c1379c237b4aec9bed10966528b6992c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,3 +1,4 @@
+#include <ctype.h>
 #include "iw.h"
 #include "nl80211.h"
 
@@ -89,3 +90,15 @@ int ieee80211_frequency_to_channel(int freq)
        /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */
        return freq/5 - 1000;
 }
+
+void print_ssid_escaped(const uint8_t len, const uint8_t *data)
+{
+       int i;
+
+       for (i = 0; i < len; i++) {
+               if (isprint(data[i]))
+                       printf("%c", data[i]);
+               else
+                       printf("\\x%.2x", data[i]);
+       }
+}