Skip to contentSkip to conversation

iw: add option to set auth type for connect

PATCH New Jianhui Zhao 1 participant 1 message May 30, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iw: add option to set auth type for connect

---
 connect.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
connect.c +28 -2
index 3237a27..e5b177f 100644
@@ -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.");
Signature · 1 line
2.25.1