From 75c572074f272f0b983d888f7dd23ee59719c6b0 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 17 Jan 2018 13:27:03 +0100 Subject: [PATCH] nl80211: turn nl80211_wait() into variadic function Extend the nl82011_wait() function to accept multiple command numbers. This is useful to wait for different possible results, e.g. either NL80211_CMD_NEW_SCAN_RESULTS or NL80211_CMD_SCAN_ABORTED. Signed-off-by: Jo-Philipp Wich --- iwinfo_nl80211.c | 18 +++++++++++++++--- iwinfo_nl80211.h | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 9044610..895b6ee 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -510,7 +510,7 @@ static int nl80211_wait_cb(struct nl_msg *msg, void *arg) struct nl80211_event_conveyor *cv = arg; struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); - if (gnlh->cmd == cv->wait) + if (cv->wait[gnlh->cmd / 32] & (1 << (gnlh->cmd % 32))) cv->recv = gnlh->cmd; return NL_SKIP; @@ -521,11 +521,13 @@ static int nl80211_wait_seq_check(struct nl_msg *msg, void *arg) return NL_OK; } -static int nl80211_wait(const char *family, const char *group, int cmd) +static int __nl80211_wait(const char *family, const char *group, ...) { - struct nl80211_event_conveyor cv = { .wait = cmd }; + struct nl80211_event_conveyor cv = { }; struct nl_cb *cb; int err = 0; + int cmd; + va_list ap; if (nl80211_subscribe(family, group)) return -ENOENT; @@ -539,6 +541,13 @@ static int nl80211_wait(const char *family, const char *group, int cmd) nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, nl80211_wait_seq_check, NULL); nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, nl80211_wait_cb, &cv ); + va_start(ap, group); + + for (cmd = va_arg(ap, int); cmd != 0; cmd = va_arg(ap, int)) + cv.wait[cmd / 32] |= (1 << (cmd % 32)); + + va_end(ap); + while (!cv.recv && !err) nl_recvmsgs(nls->nl_sock, cb); @@ -547,6 +556,9 @@ static int nl80211_wait(const char *family, const char *group, int cmd) return err; } +#define nl80211_wait(family, group, ...) \ + __nl80211_wait(family, group, __VA_ARGS__, 0) + static int nl80211_freq2channel(int freq) { diff --git a/iwinfo_nl80211.h b/iwinfo_nl80211.h index bb5117e..566ffce 100644 --- a/iwinfo_nl80211.h +++ b/iwinfo_nl80211.h @@ -48,7 +48,7 @@ struct nl80211_msg_conveyor { }; struct nl80211_event_conveyor { - int wait; + uint32_t wait[(NL80211_CMD_MAX / 32) + !!(NL80211_CMD_MAX % 32)]; int recv; }; -- 2.25.1