]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: Add support for start/stop AP
authorIlan Peer <ilan.peer@intel.com>
Sun, 4 Sep 2016 14:02:35 +0000 (17:02 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 12 Dec 2017 10:58:40 +0000 (11:58 +0100)
The beacon head (mandatory) and tail should be provided as part of the
AP start command.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Makefile
ap.c [new file with mode: 0644]
iw.h
util.c

index 38d782d055b5cc2d28b2d36cf61bf38f1c9d6fcf..43c034dcbec92178b110da45ac14de2b8a1892ee 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,8 @@ OBJS = iw.o genl.o event.o info.o phy.o \
        interface.o ibss.o station.o survey.o util.o ocb.o \
        mesh.o mpath.o mpp.o scan.o reg.o version.o \
        reason.o status.o connect.o link.o offch.o ps.o cqm.o \
-       bitrate.o wowlan.o coalesce.o roc.o p2p.o vendor.o mgmt.o
+       bitrate.o wowlan.o coalesce.o roc.o p2p.o vendor.o mgmt.o \
+       ap.o
 OBJS += sections.o
 
 OBJS-$(HWSIM) += hwsim.o
diff --git a/ap.c b/ap.c
new file mode 100644 (file)
index 0000000..bc16b77
--- /dev/null
+++ b/ap.c
@@ -0,0 +1,123 @@
+#include <errno.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+#include "nl80211.h"
+#include "iw.h"
+
+SECTION(ap);
+
+static int handle_start_ap(struct nl80211_state *state,
+                          struct nl_msg *msg, int argc, char **argv,
+                          enum id_input id)
+{
+       char *end;
+       int val, len;
+       char buf[2304];
+
+       if (argc < 6)
+               return 1;
+
+       /* SSID */
+       NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
+       argv++;
+       argc--;
+
+       /* freq */
+       val = strtoul(argv[0], &end, 10);
+       if (*end != '\0')
+               return -EINVAL;
+
+       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, val);
+       argv++;
+       argc--;
+
+       /* beacon interval */
+       val = strtoul(argv[0], &end, 10);
+       if (*end != '\0')
+               return -EINVAL;
+
+       NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, val);
+       argv++;
+       argc--;
+
+       /* dtim */
+       val = strtoul(argv[0], &end, 10);
+       if (*end != '\0')
+               return -EINVAL;
+
+       NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, val);
+       argv++;
+       argc--;
+
+       /* beacon head must be provided */
+       if (strcmp(argv[0], "head") != 0)
+               return -1;
+       argv++;
+       argc--;
+
+       len = strlen(argv[0]);
+       if (!len || (len % 2))
+               return -EINVAL;
+
+       if (!hex2bin(&argv[0][0], buf))
+               return -EINVAL;
+
+       NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, (len / 2), &buf);
+       argv++;
+       argc--;
+
+       if (!argc)
+               return 0;
+
+       /* tail is optional */
+       if (strcmp(argv[0], "tail") == 0) {
+               argv++;
+               argc--;
+
+               if (!argc)
+                       return -EINVAL;
+
+               len = strlen(argv[0]);
+               if (!len || (len % 2))
+                       return -EINVAL;
+
+               if (!hex2bin(&argv[0][0], buf))
+                       return -EINVAL;
+
+               NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, (len / 2), &buf);
+               argv++;
+               argc--;
+       }
+
+       if (!argc)
+               return 0;
+
+       if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
+               return 1;
+
+       argv++;
+       argc--;
+
+       return parse_keys(msg, argv, argc);
+ nla_put_failure:
+       return -ENOSPC;
+}
+COMMAND(ap, start, "",
+       NL80211_CMD_NEW_BEACON, 0, CIB_NETDEV, handle_start_ap,
+       "<SSID> <freq in MHz> <beacon interval in TU> <DTIM period> <head>"
+       " <beacon head in hexadecimal> [<tail> <beacon tail in hexadecimal>]"
+       " [key0:abcde d:1:6162636465]\n");
+
+static int handle_stop_ap(struct nl80211_state *state,
+                         struct nl_msg *msg,
+                         int argc, char **argv,
+                         enum id_input id)
+{
+       return 0;
+}
+COMMAND(ap, stop, "",
+       NL80211_CMD_DEL_BEACON, 0, CIB_NETDEV, handle_stop_ap,
+       "Stop AP functionality\n");
diff --git a/iw.h b/iw.h
index 3c51d84c55478739da2d0daa53f82019a8e1baa6..ee7ca208311bf08de82341c2b8b7b8159e963c46 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -230,4 +230,6 @@ DECLARE_SECTION(switch);
 DECLARE_SECTION(set);
 DECLARE_SECTION(get);
 
+char *hex2bin(const char *hex, char *buf);
+
 #endif /* __IW_H */
diff --git a/util.c b/util.c
index 276c8cab96c97b9b3fa396e326222cb58275a138..7fd6153bac1d9e2a719c79289d2893b813d1d802 100644 (file)
--- a/util.c
+++ b/util.c
@@ -368,7 +368,7 @@ static int hex2byte(const char *hex)
        return (d1 << 4) | d2;
 }
 
-static char *hex2bin(const char *hex, char *buf)
+char *hex2bin(const char *hex, char *buf)
 {
        char *result = buf;
        int d;