]> git.ipfire.org Git - thirdparty/iw.git/blobdiff - link.c
print wdev id in event info
[thirdparty/iw.git] / link.c
diff --git a/link.c b/link.c
index 6e8b4d338c11eeeda6c9d3b52a88e40cf93997d3..3470c4da2b53be38ff971d517ac0c8bfe89abb37 100644 (file)
--- a/link.c
+++ b/link.c
@@ -44,13 +44,13 @@ static int link_bss_handler(struct nl_msg *msg, void *arg)
                  genlmsg_attrlen(gnlh, 0), NULL);
 
        if (!tb[NL80211_ATTR_BSS]) {
-               fprintf(stderr, "bss info missing!");
+               fprintf(stderr, "bss info missing!\n");
                return NL_SKIP;
        }
        if (nla_parse_nested(bss, NL80211_BSS_MAX,
                             tb[NL80211_ATTR_BSS],
                             bss_policy)) {
-               fprintf(stderr, "failed to parse nested attributes!");
+               fprintf(stderr, "failed to parse nested attributes!\n");
                return NL_SKIP;
        }
 
@@ -70,6 +70,9 @@ static int link_bss_handler(struct nl_msg *msg, void *arg)
        case NL80211_BSS_STATUS_AUTHENTICATED:
                printf("Authenticated with %s (on %s)\n", mac_addr, dev);
                return NL_SKIP;
+       case NL80211_BSS_STATUS_IBSS_JOINED:
+               printf("Joined IBSS %s (on %s)\n", mac_addr, dev);
+               break;
        default:
                return NL_SKIP;
        }
@@ -97,7 +100,8 @@ static int link_bss_handler(struct nl_msg *msg, void *arg)
 static int handle_scan_for_link(struct nl80211_state *state,
                                struct nl_cb *cb,
                                struct nl_msg *msg,
-                               int argc, char **argv)
+                               int argc, char **argv,
+                               enum id_input id)
 {
        if (argc > 0)
                return 1;
@@ -105,8 +109,6 @@ static int handle_scan_for_link(struct nl80211_state *state,
        nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, link_bss_handler, &lr);
        return 0;
 }
-HIDDEN(link, get_bss, NULL, NL80211_CMD_GET_SCAN, NLM_F_DUMP,
-       CIB_NETDEV, handle_scan_for_link);
 
 static int print_link_sta(struct nl_msg *msg, void *arg)
 {
@@ -114,6 +116,7 @@ static int print_link_sta(struct nl_msg *msg, void *arg)
        struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
        struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
        struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
+       struct nlattr *binfo[NL80211_STA_BSS_PARAM_MAX + 1];
        static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
                [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
                [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
@@ -129,31 +132,39 @@ static int print_link_sta(struct nl_msg *msg, void *arg)
 
        static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
                [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
+               [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 },
                [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
                [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
                [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
        };
+       static struct nla_policy bss_policy[NL80211_STA_BSS_PARAM_MAX + 1] = {
+               [NL80211_STA_BSS_PARAM_CTS_PROT] = { .type = NLA_FLAG },
+               [NL80211_STA_BSS_PARAM_SHORT_PREAMBLE] = { .type = NLA_FLAG },
+               [NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME] = { .type = NLA_FLAG },
+               [NL80211_STA_BSS_PARAM_DTIM_PERIOD] = { .type = NLA_U8 },
+               [NL80211_STA_BSS_PARAM_BEACON_INTERVAL] = { .type = NLA_U16 },
+       };
 
        nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
                  genlmsg_attrlen(gnlh, 0), NULL);
 
        if (!tb[NL80211_ATTR_STA_INFO]) {
-               fprintf(stderr, "sta stats missing!");
+               fprintf(stderr, "sta stats missing!\n");
                return NL_SKIP;
        }
        if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
                             tb[NL80211_ATTR_STA_INFO],
                             stats_policy)) {
-               fprintf(stderr, "failed to parse nested attributes!");
+               fprintf(stderr, "failed to parse nested attributes!\n");
                return NL_SKIP;
        }
 
        if (sinfo[NL80211_STA_INFO_RX_BYTES] && sinfo[NL80211_STA_INFO_RX_PACKETS])
-               printf("\tRX: %d bytes (%d packets)\n",
+               printf("\tRX: %u bytes (%u packets)\n",
                        nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES]),
                        nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS]));
        if (sinfo[NL80211_STA_INFO_TX_BYTES] && sinfo[NL80211_STA_INFO_TX_PACKETS])
-               printf("\tTX: %d bytes (%d packets)\n",
+               printf("\tTX: %u bytes (%u packets)\n",
                        nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES]),
                        nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS]));
        if (sinfo[NL80211_STA_INFO_SIGNAL])
@@ -163,13 +174,16 @@ static int print_link_sta(struct nl_msg *msg, void *arg)
        if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
                if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
                                     sinfo[NL80211_STA_INFO_TX_BITRATE], rate_policy)) {
-                       fprintf(stderr, "failed to parse nested rate attributes!");
+                       fprintf(stderr, "failed to parse nested rate attributes!\n");
                } else {
+                       int rate = 0;
                        printf("\ttx bitrate: ");
-                       if (rinfo[NL80211_RATE_INFO_BITRATE]) {
-                               int rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]);
+                       if (rinfo[NL80211_RATE_INFO_BITRATE32])
+                               rate = nla_get_u32(rinfo[NL80211_RATE_INFO_BITRATE32]);
+                       else if (rinfo[NL80211_RATE_INFO_BITRATE])
+                               rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]);
+                       if (rate > 0)
                                printf("%d.%d MBit/s", rate / 10, rate % 10);
-                       }
 
                        if (rinfo[NL80211_RATE_INFO_MCS])
                                printf(" MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_MCS]));
@@ -181,13 +195,40 @@ static int print_link_sta(struct nl_msg *msg, void *arg)
                }
        }
 
+       if (sinfo[NL80211_STA_INFO_BSS_PARAM]) {
+               if (nla_parse_nested(binfo, NL80211_STA_BSS_PARAM_MAX,
+                                    sinfo[NL80211_STA_INFO_BSS_PARAM],
+                                    bss_policy)) {
+                       fprintf(stderr, "failed to parse nested bss parameters!\n");
+               } else {
+                       char *delim = "";
+                       printf("\n\tbss flags:\t");
+                       if (binfo[NL80211_STA_BSS_PARAM_CTS_PROT]) {
+                               printf("CTS-protection");
+                               delim = " ";
+                       }
+                       if (binfo[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE]) {
+                               printf("%sshort-preamble", delim);
+                               delim = " ";
+                       }
+                       if (binfo[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME])
+                               printf("%sshort-slot-time", delim);
+                       printf("\n\tdtim period:\t%d",
+                              nla_get_u8(binfo[NL80211_STA_BSS_PARAM_DTIM_PERIOD]));
+                       printf("\n\tbeacon int:\t%d",
+                              nla_get_u16(binfo[NL80211_STA_BSS_PARAM_BEACON_INTERVAL]));
+                       printf("\n");
+               }
+       }
+
        return NL_SKIP;
 }
 
 static int handle_link_sta(struct nl80211_state *state,
                           struct nl_cb *cb,
                           struct nl_msg *msg,
-                          int argc, char **argv)
+                          int argc, char **argv,
+                          enum id_input id)
 {
        unsigned char mac_addr[ETH_ALEN];
 
@@ -213,11 +254,10 @@ static int handle_link_sta(struct nl80211_state *state,
  nla_put_failure:
        return -ENOBUFS;
 }
-HIDDEN(link, get_sta, "", NL80211_CMD_GET_STATION, 0,
-       CIB_NETDEV, handle_link_sta);
 
 static int handle_link(struct nl80211_state *state, struct nl_cb *cb,
-                      struct nl_msg *msg, int argc, char **argv)
+                      struct nl_msg *msg, int argc, char **argv,
+                      enum id_input id)
 {
        char *link_argv[] = {
                NULL,
@@ -236,13 +276,13 @@ static int handle_link(struct nl80211_state *state, struct nl_cb *cb,
        int err;
 
        link_argv[0] = argv[0];
-       err = handle_cmd(state, II_NETDEV, 3, link_argv);
+       err = handle_cmd(state, id, 3, link_argv);
        if (err)
                return err;
 
        if (!lr.link_found) {
                if (!lr.anything_found)
-                       printf("Not connected.");
+                       printf("Not connected.\n");
                return 0;
        }
 
@@ -251,7 +291,11 @@ static int handle_link(struct nl80211_state *state, struct nl_cb *cb,
 
        station_argv[0] = argv[0];
        station_argv[3] = bssid_buf;
-       return handle_cmd(state, II_NETDEV, 4, station_argv);
+       return handle_cmd(state, id, 4, station_argv);
 }
 TOPLEVEL(link, NULL, 0, 0, CIB_NETDEV, handle_link,
         "Print information about the current link, if any.");
+HIDDEN(link, get_sta, "", NL80211_CMD_GET_STATION, 0,
+       CIB_NETDEV, handle_link_sta);
+HIDDEN(link, get_bss, NULL, NL80211_CMD_GET_SCAN, NLM_F_DUMP,
+       CIB_NETDEV, handle_scan_for_link);