]> git.ipfire.org Git - thirdparty/iw.git/blobdiff - ocb.c
update nl80211.h
[thirdparty/iw.git] / ocb.c
diff --git a/ocb.c b/ocb.c
index fc48ecfcf29b7713fa79b2b0dedc8393830470a2..fc9579b8f3d0603bb0c003ec69395e32360b9089 100644 (file)
--- a/ocb.c
+++ b/ocb.c
@@ -1,4 +1,3 @@
-#include <net/if.h>
 #include <errno.h>
 #include <string.h>
 
@@ -11,55 +10,24 @@ static int join_ocb(struct nl80211_state *state,
                    struct nl_msg *msg, int argc, char **argv,
                    enum id_input id)
 {
-       unsigned long freq;
-       char *end;
-       int i;
-       static const struct {
-               const char *name;
-               unsigned int width;
-       } *chanmode_selected, chanmode[] = {
-               { .name = "5MHZ",
-                 .width = NL80211_CHAN_WIDTH_5 },
-               { .name = "10MHZ",
-                 .width = NL80211_CHAN_WIDTH_10 },
-       };
+       struct chandef chandef;
+       int err, parsed;
 
        if (argc < 2)
                return 1;
 
-       /* freq */
-       freq = strtoul(argv[0], &end, 10);
-       if (*end != '\0')
-               return 1;
-
-       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
-       argv++;
-       argc--;
+       err = parse_freqchan(&chandef, false, argc, argv, &parsed);
 
-       /* channel width */
-       for (i = 0; i < ARRAY_SIZE(chanmode); i++) {
-               if (strcasecmp(chanmode[i].name, argv[0]) == 0) {
-                       chanmode_selected = &chanmode[i];
-                       break;
-               }
-       }
-       if (chanmode_selected) {
-               NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH,
-                           chanmode_selected->width);
-               NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq);
+       if (err)
+               return err;
 
-               argv++;
-               argc--;
-       } else {
-               return 1;
-       }
+       err = put_chandef(msg, &chandef);
+       if (err)
+               return err;
 
        return 0;
-
-nla_put_failure:
-       return -ENOBUFS;
 }
-COMMAND(ocb, join, "<freq in MHz> <5MHZ|10MHZ>",
+COMMAND(ocb, join, "<freq in MHz> <5MHz|10MHz>",
        NL80211_CMD_JOIN_OCB, 0, CIB_NETDEV, join_ocb,
        "Join the OCB mode network.");