From: Johannes Berg Date: Sun, 24 May 2009 14:48:17 +0000 (+0200) Subject: print scan info on event X-Git-Tag: v0.9.15~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=748f8489caad151e01922f0ba26847aedfd36daf;p=thirdparty%2Fiw.git print scan info on event --- diff --git a/event.c b/event.c index a9e08a9..d525ab4 100644 --- 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 d97cc6e..339ebc1 100644 --- 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 4c0c9e6..b0b6aca 100644 --- 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 dcb3de6..1750de2 100644 --- a/util.c +++ b/util.c @@ -1,3 +1,4 @@ +#include #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]); + } +}