diff mbox series

iw: add option to set auth type for connect

Message ID 20210530112552.577329-1-zhaojh329@gmail.com (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series iw: add option to set auth type for connect | expand

Commit Message

Jianhui Zhao May 30, 2021, 11:25 a.m. UTC
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
---
 connect.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/connect.c b/connect.c
index 3237a27..e5b177f 100644
--- a/connect.c
+++ b/connect.c
@@ -15,6 +15,7 @@  static int iw_conn(struct nl80211_state *state,
 {
 	char *end;
 	unsigned char bssid[6];
+	bool need_key = false;
 	int freq;
 	int ret;
 
@@ -48,7 +49,32 @@  static int iw_conn(struct nl80211_state *state,
 	if (!argc)
 		return 0;
 
-	if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
+	if (strcmp(*argv, "auth") == 0) {
+		argv++;
+		argc--;
+
+		if (!argc)
+			return 1;
+
+		if (strcmp(argv[0], "open") == 0) {
+			NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE,
+			    NL80211_AUTHTYPE_OPEN_SYSTEM);
+		} else if (strcmp(argv[0], "shared") == 0) {
+			NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE,
+			    NL80211_AUTHTYPE_SHARED_KEY);
+			need_key = true;
+		} else {
+			return 1;
+		}
+
+		argv++;
+		argc--;
+	}
+
+	if (need_key && !argc)
+		return 1;
+
+	if (argc && strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
 		return 1;
 
 	argv++;
@@ -160,7 +186,7 @@  static int iw_connect(struct nl80211_state *state,
 			   &printargs);
 	return 0;
 }
-TOPLEVEL(connect, "[-w] <SSID> [<freq in MHz>] [<bssid>] [key 0:abcde d:1:6162636465] [mfp:req/opt/no]",
+TOPLEVEL(connect, "[-w] <SSID> [<freq in MHz>] [<bssid>] [auth open|shared] [key 0:abcde d:1:6162636465] [mfp:req/opt/no]",
 	0, 0, CIB_NETDEV, iw_connect,
 	"Join the network with the given SSID (and frequency, BSSID).\n"
 	"With -w, wait for the connect to finish or fail.");