int mac80211_get_coverageclass(char *interface) { struct nlattr *tb[NL80211_ATTR_MAX + 1]; struct nl_msg *msg; struct genlmsghdr *gnlh; int phy; unsigned char coverage=0; phy = mac80211_get_phyidx_by_vifname(interface); if (phy == -1) return 0; msg = unl_genl_msg(&unl, NL80211_CMD_GET_WIPHY, false); NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, phy); if (unl_genl_request_single(&unl, msg, &msg) < 0) return 0; if (!msg) return 0; gnlh=nlmsg_data(nlmsg_hdr(msg)); nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); if (tb[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { coverage = nla_get_u8(tb[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); /* See handle_distance() for an explanation where the '450' comes from */ // printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage); } // printf ("%d\n", coverage); nlmsg_free(msg); return coverage; nla_put_failure: nlmsg_free(msg); return 0; }
static int unl_genl_multicast_id(struct unl *unl, const char *name) { struct nlattr *tb[CTRL_ATTR_MCAST_GRP_MAX + 1]; struct nlattr *groups, *group; struct nl_msg *msg; int ctrlid; int ret = -1; int rem; msg = nlmsg_alloc(); if (!msg) return -1; ctrlid = genl_ctrl_resolve(unl->sock, "nlctrl"); genlmsg_put(msg, 0, 0, ctrlid, 0, 0, CTRL_CMD_GETFAMILY, 0); NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, unl->family_name); unl_genl_request_single(unl, msg, &msg); if (!msg) goto nla_put_failure; groups = unl_find_attr(unl, msg, CTRL_ATTR_MCAST_GROUPS); if (!groups) goto fail; nla_for_each_nested(group, groups, rem) { const char *gn; nla_parse(tb, CTRL_ATTR_MCAST_GRP_MAX, nla_data(group), nla_len(group), NULL); if (!tb[CTRL_ATTR_MCAST_GRP_NAME] || !tb[CTRL_ATTR_MCAST_GRP_ID]) continue; gn = nla_data(tb[CTRL_ATTR_MCAST_GRP_NAME]); if (strcmp(gn, name) != 0) continue; ret = nla_get_u32(tb[CTRL_ATTR_MCAST_GRP_ID]); break; } fail: nlmsg_free(msg); nla_put_failure: return ret; }
int unl_nl80211_wdev_to_phy(struct unl *unl, int wdev) { struct nl_msg *msg; struct nlattr *attr; int ret = -1; msg = unl_genl_msg(unl, NL80211_CMD_GET_INTERFACE, false); if (!msg) return -1; NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev); if (unl_genl_request_single(unl, msg, &msg) < 0) return -1; attr = unl_find_attr(unl, msg, NL80211_ATTR_WIPHY); if (!attr) goto out; ret = nla_get_u32(attr); out: nla_put_failure: nlmsg_free(msg); return ret; }