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 <jo@mein.io>
struct nl80211_event_conveyor *cv = arg;
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
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;
cv->recv = gnlh->cmd;
return NL_SKIP;
-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;
struct nl_cb *cb;
int err = 0;
if (nl80211_subscribe(family, group))
return -ENOENT;
if (nl80211_subscribe(family, group))
return -ENOENT;
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 );
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);
while (!cv.recv && !err)
nl_recvmsgs(nls->nl_sock, cb);
+#define nl80211_wait(family, group, ...) \
+ __nl80211_wait(family, group, __VA_ARGS__, 0)
+
static int nl80211_freq2channel(int freq)
{
static int nl80211_freq2channel(int freq)
{
};
struct nl80211_event_conveyor {
};
struct nl80211_event_conveyor {
+ uint32_t wait[(NL80211_CMD_MAX / 32) + !!(NL80211_CMD_MAX % 32)];