2016-12-22 23:40:00 +01:00
|
|
|
#include <linux/nl80211.h>
|
|
|
|
#include <netlink/genl/genl.h>
|
|
|
|
|
|
|
|
#include "ifaces.h"
|
2017-02-08 19:32:43 +01:00
|
|
|
#include "netlink.h"
|
2016-12-22 23:40:00 +01:00
|
|
|
|
|
|
|
static int iface_dump_handler(struct nl_msg *msg, void *arg) {
|
|
|
|
struct nlattr *tb[NL80211_ATTR_MAX + 1];
|
|
|
|
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
|
|
|
|
struct iface_list **last_next;
|
|
|
|
|
|
|
|
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
|
|
|
|
|
2017-02-08 19:33:53 +01:00
|
|
|
if (!tb[NL80211_ATTR_WIPHY] || !tb[NL80211_ATTR_IFINDEX])
|
|
|
|
goto skip;
|
|
|
|
|
2018-08-08 06:17:23 +02:00
|
|
|
#ifdef GLUON
|
|
|
|
if(nla_strcmp(tb[NL80211_ATTR_IFNAME], "client") == -1)
|
|
|
|
goto skip;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO fix add to head list - instatt find last item
|
|
|
|
for (last_next = arg; *last_next != NULL; last_next = &(*last_next)->next) {}
|
|
|
|
|
2016-12-22 23:40:00 +01:00
|
|
|
*last_next = malloc(sizeof(**last_next));
|
2017-02-08 19:33:53 +01:00
|
|
|
if (!*last_next)
|
|
|
|
goto skip;
|
2016-12-22 23:40:00 +01:00
|
|
|
(*last_next)->next = NULL;
|
2018-08-08 06:17:23 +02:00
|
|
|
(*last_next)->wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
|
2016-12-22 23:40:00 +01:00
|
|
|
(*last_next)->ifx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
|
2018-08-08 06:17:23 +02:00
|
|
|
(*last_next)->frequency = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
|
|
|
|
(*last_next)->txpower = nla_get_u32(tb[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]);
|
2016-12-22 23:40:00 +01:00
|
|
|
|
|
|
|
skip:
|
|
|
|
return NL_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iface_list *get_ifaces() {
|
|
|
|
struct iface_list *ifaces = NULL;
|
2017-02-08 19:32:43 +01:00
|
|
|
nl_send_dump(&iface_dump_handler, &ifaces, NL80211_CMD_GET_INTERFACE, 0);
|
2016-12-22 23:40:00 +01:00
|
|
|
return ifaces;
|
|
|
|
}
|