]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
connect API test
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 23 Jun 2009 15:50:27 +0000 (17:50 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Tue, 23 Jun 2009 15:50:27 +0000 (17:50 +0200)
Makefile
connect.c [new file with mode: 0644]
nl80211.h

index 56a11e69c619ce7b0c2ee9643495e6e5aebe5709..520723cf77fd2a7819a2bd7bfb867ae509452646 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ CC ?= "gcc"
 CFLAGS ?= -O2 -g
 CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration
 
-OBJS = iw.o genl.o event.o info.o phy.o interface.o ibss.o station.o util.o mesh.o mpath.o scan.o reg.o version.o reason.o status.o
+OBJS = iw.o genl.o event.o info.o phy.o interface.o ibss.o station.o util.o mesh.o mpath.o scan.o reg.o version.o reason.o status.o connect.o
 ALL = iw
 
 NL1FOUND := $(shell $(PKG_CONFIG) --atleast-version=1 libnl-1 && echo Y)
diff --git a/connect.c b/connect.c
new file mode 100644 (file)
index 0000000..9532e58
--- /dev/null
+++ b/connect.c
@@ -0,0 +1,68 @@
+#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"
+
+static int iw_connect(struct nl80211_state *state,
+                     struct nl_cb *cb,
+                     struct nl_msg *msg,
+                     int argc, char **argv)
+{
+       char *end;
+       unsigned char abssid[6];
+       int freq;
+
+       if (argc < 1)
+               return 1;
+
+       /* SSID */
+       NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
+       argv++;
+       argc--;
+
+       /* freq */
+       if (argc) {
+               freq = strtoul(argv[0], &end, 10);
+               if (*end == '\0') {
+                       NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
+                       argv++;
+                       argc--;
+               }
+       }
+
+       /* bssid */
+       if (argc) {
+               if (mac_addr_a2n(abssid, argv[0]))
+                       return 1;
+               NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
+               argv++;
+               argc--;
+       }
+
+       if (argc)
+               return 1;
+
+       return 0;
+ nla_put_failure:
+       return -ENOSPC;
+}
+
+static int disconnect(struct nl80211_state *state,
+                     struct nl_cb *cb,
+                     struct nl_msg *msg,
+                     int argc, char **argv)
+{
+       return 0;
+}
+TOPLEVEL(disconnect, NULL,
+       NL80211_CMD_DISCONNECT, 0, CIB_NETDEV, disconnect,
+       "Disconnect from the current network.");
+TOPLEVEL(connect, "<SSID> <freq in MHz> [<bssid>]",
+       NL80211_CMD_CONNECT, 0, CIB_NETDEV, iw_connect,
+       "Join the network with the given SSID (and frequency, BSSID).");
index dbea93b694e5aa6e30749949df01fe4dce25f3d3..ec638b17038692e11a6266fc435fc65453230213 100644 (file)
--- a/nl80211.h
+++ b/nl80211.h
  * @NL80211_CMD_LEAVE_IBSS: Leave the IBSS -- no special arguments, the IBSS is
  *     determined by the network interface.
  *
+ * @NL80211_CMD_CONNECT: connection request and notification; this command
+ *     requests to connect to a specified network but without separating
+ *     auth and assoc steps. For this, you need to specify the SSID in a
+ *     %NL80211_ATTR_SSID attribute, and can optionally specify the association
+ *     IEs in %NL80211_ATTR_IE, %NL80211_ATTR_AUTH_TYPE, %NL80211_ATTR_MAC,
+ *     %NL80211_ATTR_WIPHY_FREQ and %NL80211_ATTR_CONTROL_PORT.
+ *     It is also sent as an event, with the BSSID and response IEs when the
+ *     connection is established or failed to be established. This can be
+ *     determined by the STATUS_CODE attribute.
+ * @NL80211_CMD_ROAM: request that the card roam (currently not implemented),
+ *     sent as an event when the card/driver roamed by itself.
+ * @NL80211_CMD_DISCONNECT: drop a given connection; also used to notify
+ *     userspace that a connection was dropped by the AP or due to other
+ *     reasons, for this the %NL80211_ATTR_DISCONNECTED_BY_AP and
+ *     %NL80211_ATTR_REASON_CODE attributes are used.
+ *
  * @NL80211_CMD_MAX: highest used command number
  * @__NL80211_CMD_AFTER_LAST: internal use
  */
@@ -310,6 +326,10 @@ enum nl80211_commands {
        NL80211_CMD_JOIN_IBSS,
        NL80211_CMD_LEAVE_IBSS,
 
+       NL80211_CMD_CONNECT,
+       NL80211_CMD_ROAM,
+       NL80211_CMD_DISCONNECT,
+
        /* add new commands above here */
 
        /* used to define NL80211_CMD_MAX below */
@@ -511,6 +531,12 @@ enum nl80211_commands {
  *     authorized by user space. Otherwise, port is marked authorized by
  *     default in station mode.
  *
+ * @NL80211_ATTR_DISCONNECTED_BY_AP: A flag indicating that the DISCONNECT
+ *     event was due to the AP disconnecting the station, and not due to
+ *     a local disconnect request.
+ * @NL80211_ATTR_STATUS_CODE: StatusCode for the %NL80211_CMD_CONNECT
+ *     event (u16)
+ *
  * @NL80211_ATTR_MAX: highest attribute number currently defined
  * @__NL80211_ATTR_AFTER_LAST: internal use
  */
@@ -619,6 +645,9 @@ enum nl80211_attrs {
 
        NL80211_ATTR_CONTROL_PORT,
 
+       NL80211_ATTR_DISCONNECTED_BY_AP,
+       NL80211_ATTR_STATUS_CODE,
+
        /* add attributes here, update the policy in nl80211.c */
 
        __NL80211_ATTR_AFTER_LAST,