]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
nl80211: Add nl80211_*_msg() helpers
authorJouni Malinen <j@w1.fi>
Sat, 6 Dec 2014 10:56:05 +0000 (12:56 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 6 Dec 2014 14:41:01 +0000 (16:41 +0200)
These new functions can be used to both allocate and build a header for
most nl80211 commands.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/drivers/driver_nl80211.c
src/drivers/driver_nl80211.h

index 6cc33a3aa0cef4311fbb47a3b80ad70ca6575aef..272f278be4fbd00eec465389062da192c03b77c6 100644 (file)
@@ -439,6 +439,57 @@ void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
 }
 
 
+struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
+{
+       struct nl_msg *msg;
+
+       msg = nlmsg_alloc();
+       if (!msg)
+               return NULL;
+
+       if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
+           nl80211_set_iface_id(msg, bss) < 0) {
+               nlmsg_free(msg);
+               return NULL;
+       }
+
+       return msg;
+}
+
+
+static struct nl_msg *
+nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
+                   int flags, uint8_t cmd)
+{
+       struct nl_msg *msg;
+
+       msg = nlmsg_alloc();
+       if (!msg)
+               return NULL;
+
+       if (!nl80211_cmd(drv, msg, flags, cmd) ||
+           nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
+               nlmsg_free(msg);
+               return NULL;
+       }
+
+       return msg;
+}
+
+
+struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
+                               uint8_t cmd)
+{
+       return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
+}
+
+
+struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
+{
+       return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
+}
+
+
 struct wiphy_idx_data {
        int wiphy_idx;
        enum nl80211_iftype nlmode;
index 60bf390ba82f043eb672d2149c54bd72638aa721..7133d82a215e547459eb2e87dac414a17e9c0a5e 100644 (file)
@@ -186,6 +186,10 @@ struct nl_msg;
 int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss);
 void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
                   struct nl_msg *msg, int flags, uint8_t cmd);
+struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
+struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
+                               uint8_t cmd);
+struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
 int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg,
                       int (*valid_handler)(struct nl_msg *, void *),
                       void *valid_data);