]> git.ipfire.org Git - thirdparty/iw.git/blobdiff - interface.c
add P2P Device handling primitives
[thirdparty/iw.git] / interface.c
index 8c07ba1d7420b84ec924b0734271ea7794ec494c..810c2b96d25e56c6ce0c09602d33880b5c3f51b0 100644 (file)
@@ -133,6 +133,9 @@ static int get_if_type(int *argc, char ***argv, enum nl80211_iftype *type,
        } else if (strcmp(tpstr, "__p2pcl") == 0) {
                *type = NL80211_IFTYPE_P2P_CLIENT;
                return 0;
+       } else if (strcmp(tpstr, "__p2pdev") == 0) {
+               *type = NL80211_IFTYPE_P2P_DEVICE;
+               return 0;
        } else if (strcmp(tpstr, "__p2pgo") == 0) {
                *type = NL80211_IFTYPE_P2P_GO;
                return 0;
@@ -159,7 +162,8 @@ nla_put_failure:
 static int handle_interface_add(struct nl80211_state *state,
                                struct nl_cb *cb,
                                struct nl_msg *msg,
-                               int argc, char **argv)
+                               int argc, char **argv,
+                               enum id_input id)
 {
        char *name;
        char *mesh_id = NULL;
@@ -233,7 +237,8 @@ COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [4addr on|off] [f
 static int handle_interface_del(struct nl80211_state *state,
                                struct nl_cb *cb,
                                struct nl_msg *msg,
-                               int argc, char **argv)
+                               int argc, char **argv,
+                               enum id_input id)
 {
        return 0;
 }
@@ -241,6 +246,22 @@ TOPLEVEL(del, NULL, NL80211_CMD_DEL_INTERFACE, 0, CIB_NETDEV, handle_interface_d
         "Remove this virtual interface");
 HIDDEN(interface, del, NULL, NL80211_CMD_DEL_INTERFACE, 0, CIB_NETDEV, handle_interface_del);
 
+static char *channel_type_name(enum nl80211_channel_type channel_type)
+{
+       switch (channel_type) {
+       case NL80211_CHAN_NO_HT:
+               return "NO HT";
+       case NL80211_CHAN_HT20:
+               return "HT20";
+       case NL80211_CHAN_HT40MINUS:
+               return "HT40-";
+       case NL80211_CHAN_HT40PLUS:
+               return "HT40+";
+       default:
+               return "unknown";
+       }
+}
+
 static int print_iface_handler(struct nl_msg *msg, void *arg)
 {
        struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
@@ -261,12 +282,33 @@ static int print_iface_handler(struct nl_msg *msg, void *arg)
 
        if (tb_msg[NL80211_ATTR_IFNAME])
                printf("%sInterface %s\n", indent, nla_get_string(tb_msg[NL80211_ATTR_IFNAME]));
+       else
+               printf("%sUnnamed/non-netdev interface\n", indent);
        if (tb_msg[NL80211_ATTR_IFINDEX])
                printf("%s\tifindex %d\n", indent, nla_get_u32(tb_msg[NL80211_ATTR_IFINDEX]));
+       if (tb_msg[NL80211_ATTR_WDEV])
+               printf("%s\twdev 0x%llx\n", indent,
+                      (unsigned long long)nla_get_u64(tb_msg[NL80211_ATTR_WDEV]));
+       if (tb_msg[NL80211_ATTR_MAC]) {
+               char mac_addr[20];
+               mac_addr_n2a(mac_addr, nla_data(tb_msg[NL80211_ATTR_MAC]));
+               printf("%s\taddr %s\n", indent, mac_addr);
+       }
        if (tb_msg[NL80211_ATTR_IFTYPE])
                printf("%s\ttype %s\n", indent, iftype_name(nla_get_u32(tb_msg[NL80211_ATTR_IFTYPE])));
        if (!wiphy && tb_msg[NL80211_ATTR_WIPHY])
                printf("%s\twiphy %d\n", indent, nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]));
+       if (tb_msg[NL80211_ATTR_WIPHY_FREQ]) {
+               uint32_t freq = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FREQ]);
+               enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
+
+               if (tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE])
+                       channel_type = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
+
+               printf("%s\tchannel %d (%d MHz) %s\n", indent,
+                      ieee80211_frequency_to_channel(freq), freq,
+                      channel_type_name(channel_type));
+       }
 
        return NL_SKIP;
 }
@@ -274,7 +316,8 @@ static int print_iface_handler(struct nl_msg *msg, void *arg)
 static int handle_interface_info(struct nl80211_state *state,
                                 struct nl_cb *cb,
                                 struct nl_msg *msg,
-                                int argc, char **argv)
+                                int argc, char **argv,
+                                enum id_input id)
 {
        nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_iface_handler, NULL);
        return 0;
@@ -285,7 +328,8 @@ TOPLEVEL(info, NULL, NL80211_CMD_GET_INTERFACE, 0, CIB_NETDEV, handle_interface_
 static int handle_interface_set(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)
                return 1;
@@ -315,7 +359,8 @@ COMMAND(set, monitor, "<flag>*",
 static int handle_interface_meshid(struct nl80211_state *state,
                                   struct nl_cb *cb,
                                   struct nl_msg *msg,
-                                  int argc, char **argv)
+                                  int argc, char **argv,
+                                  enum id_input id)
 {
        char *mesh_id = NULL;
 
@@ -338,7 +383,8 @@ static unsigned int dev_dump_wiphy;
 static int handle_dev_dump(struct nl80211_state *state,
                           struct nl_cb *cb,
                           struct nl_msg *msg,
-                          int argc, char **argv)
+                          int argc, char **argv,
+                          enum id_input id)
 {
        dev_dump_wiphy = -1;
        nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_iface_handler, &dev_dump_wiphy);
@@ -350,7 +396,8 @@ TOPLEVEL(dev, NULL, NL80211_CMD_GET_INTERFACE, NLM_F_DUMP, CIB_NONE, handle_dev_
 static int handle_interface_type(struct nl80211_state *state,
                                 struct nl_cb *cb,
                                 struct nl_msg *msg,
-                                int argc, char **argv)
+                                int argc, char **argv,
+                                enum id_input id)
 {
        enum nl80211_iftype type;
        int tpset;
@@ -374,9 +421,10 @@ COMMAND(set, type, "<type>",
        IFACE_TYPES);
 
 static int handle_interface_4addr(struct nl80211_state *state,
-                                struct nl_cb *cb,
-                                struct nl_msg *msg,
-                                int argc, char **argv)
+                                 struct nl_cb *cb,
+                                 struct nl_msg *msg,
+                                 int argc, char **argv,
+                                 enum id_input id)
 {
        if (argc != 1)
                return 1;
@@ -389,7 +437,8 @@ COMMAND(set, 4addr, "<on|off>",
 static int handle_interface_noack_map(struct nl80211_state *state,
                                      struct nl_cb *cb,
                                      struct nl_msg *msg,
-                                     int argc, char **argv)
+                                     int argc, char **argv,
+                                     enum id_input id)
 {
        uint16_t noack_map;
        char *end;
@@ -416,7 +465,8 @@ COMMAND(set, noack_map, "<map>",
 static int handle_interface_wds_peer(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];