]> git.ipfire.org Git - thirdparty/iw.git/blobdiff - event.c
event parsing: remove PARSE_BEACON_CHAN
[thirdparty/iw.git] / event.c
diff --git a/event.c b/event.c
index 2f61f511d1c3ed1ba73fef22cae73639dfd8600e..ac2dabc51c2359873e3a2166a843086b8c3d3051 100644 (file)
--- a/event.c
+++ b/event.c
@@ -130,12 +130,6 @@ static void parse_cqm_event(struct nlattr *tb)
 
 static int print_event(struct nl_msg *msg, void *arg)
 {
-#define PARSE_BEACON_CHAN(_attr, _chan) do { \
-       r = parse_beacon_hint_chan(tb[_attr], \
-                                  &_chan); \
-       if (r) \
-               return NL_SKIP; \
-} while (0)
        struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
        struct nlattr *tb[NL80211_ATTR_MAX + 1], *nst;
        struct print_event_args *args = arg;
@@ -144,7 +138,6 @@ static int print_event(struct nl_msg *msg, void *arg)
        __u8 reg_type;
        struct ieee80211_beacon_channel chan_before_beacon,  chan_after_beacon;
        __u32 wiphy_idx = 0;
-       int r;
        int rem_nst;
        __u16 status;
 
@@ -235,8 +228,12 @@ static int print_event(struct nl_msg *msg, void *arg)
                memset(&chan_before_beacon, 0, sizeof(chan_before_beacon));
                memset(&chan_after_beacon, 0, sizeof(chan_after_beacon));
 
-               PARSE_BEACON_CHAN(NL80211_ATTR_FREQ_BEFORE, chan_before_beacon);
-               PARSE_BEACON_CHAN(NL80211_ATTR_FREQ_AFTER, chan_after_beacon);
+               if (parse_beacon_hint_chan(tb[NL80211_ATTR_FREQ_BEFORE],
+                                          &chan_before_beacon))
+                       break;
+               if (parse_beacon_hint_chan(tb[NL80211_ATTR_FREQ_AFTER],
+                                          &chan_after_beacon))
+                       break;
 
                if (chan_before_beacon.center_freq != chan_after_beacon.center_freq)
                        break;
@@ -349,8 +346,8 @@ static int print_event(struct nl_msg *msg, void *arg)
                break;
        }
 
+       fflush(stdout);
        return NL_SKIP;
-#undef PARSE_BEACON_CHAN
 }
 
 struct wait_event {
@@ -369,15 +366,15 @@ static int wait_event(struct nl_msg *msg, void *arg)
        for (i = 0; i < wait->n_cmds; i++) {
                if (gnlh->cmd == wait->cmds[i]) {
                        wait->cmd = gnlh->cmd;
-               if (wait->pargs)
-                       print_event(msg, wait->pargs);
+                       if (wait->pargs)
+                               print_event(msg, wait->pargs);
                }
        }
 
        return NL_SKIP;
 }
 
-static int __prepare_listen_events(struct nl80211_state *state)
+int __prepare_listen_events(struct nl80211_state *state)
 {
        int mcid, ret;
 
@@ -417,23 +414,18 @@ static int __prepare_listen_events(struct nl80211_state *state)
        return 0;
 }
 
-__u32 __listen_events(struct nl80211_state *state,
-                     const int n_waits, const __u32 *waits,
-                     struct print_event_args *args)
+__u32 __do_listen_events(struct nl80211_state *state,
+                        const int n_waits, const __u32 *waits,
+                        struct print_event_args *args)
 {
        struct nl_cb *cb = nl_cb_alloc(iw_debug ? NL_CB_DEBUG : NL_CB_DEFAULT);
        struct wait_event wait_ev;
-       int ret;
 
        if (!cb) {
                fprintf(stderr, "failed to allocate netlink callbacks\n");
                return -ENOMEM;
        }
 
-       ret = __prepare_listen_events(state);
-       if (ret)
-               return ret;
-
        /* no sequence checking for multicast messages */
        nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
 
@@ -458,7 +450,13 @@ __u32 __listen_events(struct nl80211_state *state,
 __u32 listen_events(struct nl80211_state *state,
                    const int n_waits, const __u32 *waits)
 {
-       return __listen_events(state, n_waits, waits, NULL);
+       int ret;
+
+       ret = __prepare_listen_events(state);
+       if (ret)
+               return ret;
+
+       return __do_listen_events(state, n_waits, waits, NULL);
 }
 
 static int print_events(struct nl80211_state *state,
@@ -467,6 +465,7 @@ static int print_events(struct nl80211_state *state,
                        int argc, char **argv)
 {
        struct print_event_args args;
+       int ret;
 
        memset(&args, 0, sizeof(args));
 
@@ -487,7 +486,11 @@ static int print_events(struct nl80211_state *state,
        if (argc)
                return 1;
 
-       return __listen_events(state, 0, NULL, &args);
+       ret = __prepare_listen_events(state);
+       if (ret)
+               return ret;
+
+       return __do_listen_events(state, 0, NULL, &args);
 }
 TOPLEVEL(event, "[-t] [-f]", 0, 0, CIB_NONE, print_events,
        "Monitor events from the kernel.\n"