changeset 3306:e6d3a5184d69

6501164 dladm reset-linkprop returns 0 on failure 6501166 dladm scan-wifi's AUTH field should be removed 6503476 dladm die() nits 6505029 replace the nanosleep() call with poll() in do_connect()
author xz162242
date Wed, 20 Dec 2006 22:32:03 -0800
parents 904e0ec142b5
children 08dd9db5d94e
files usr/src/cmd/dladm/dladm.c usr/src/lib/libwladm/common/libwladm.c usr/src/lib/libwladm/common/libwladm_impl.h
diffstat 3 files changed, 37 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/dladm/dladm.c	Wed Dec 20 22:04:44 2006 -0800
+++ b/usr/src/cmd/dladm/dladm.c	Wed Dec 20 22:32:03 2006 -0800
@@ -1211,7 +1211,7 @@
 				die_optdup(option);
 
 			if (L_arg)
-				die("the option -L cannot be used with -k");
+				die("the option -s cannot be used with -L");
 
 			s_arg = B_TRUE;
 			break;
@@ -1659,7 +1659,7 @@
 { "ibssid",	"BSSID/IBSSID", 17,	WLADM_WLAN_ATTR_BSSID,	WIFI_CMD_ALL},
 { "mode",	"MODE",		6,	WLADM_WLAN_ATTR_MODE,	WIFI_CMD_ALL},
 { "speed",	"SPEED",	6,	WLADM_WLAN_ATTR_SPEED,	WIFI_CMD_ALL},
-{ "auth",	"AUTH",		8,	WLADM_WLAN_ATTR_AUTH,	WIFI_CMD_ALL},
+{ "auth",	"AUTH",		8,	WLADM_WLAN_ATTR_AUTH,	WIFI_CMD_SHOW},
 { "bsstype",	"BSSTYPE",	8,	WLADM_WLAN_ATTR_BSSTYPE, WIFI_CMD_ALL},
 { "sec",	"SEC",		6,	WLADM_WLAN_ATTR_SECMODE, WIFI_CMD_ALL},
 { "status",	"STATUS",	17,	WLADM_LINK_ATTR_STATUS, WIFI_CMD_SHOW},
@@ -1667,7 +1667,7 @@
 ;
 
 static char *all_scan_wifi_fields =
-	"link,essid,bssid,sec,strength,mode,speed,auth,bsstype";
+	"link,essid,bssid,sec,strength,mode,speed,bsstype";
 static char *all_show_wifi_fields =
 	"link,status,essid,sec,strength,mode,speed,auth,bssid,bsstype";
 static char *def_scan_wifi_fields =
@@ -1766,7 +1766,7 @@
 		for (j = 0; j < WIFI_MAX_FIELDS; j++) {
 			if (strcasecmp(sp->s_fields[i],
 			    wifi_fields[j].wf_name) == 0) {
-				good_match = wifi_fields[i].
+				good_match = wifi_fields[j].
 				    wf_cmdtype & cmdtype;
 				break;
 			}
@@ -2249,11 +2249,11 @@
 			if (attr.wa_valid == 0) {
 				die("no wifi networks are available");
 			} else {
-				die("no wifi networks with the specified"
+				die("no wifi networks with the specified "
 				    "criteria are available");
 			}
 		}
-		die_wlerr(status, "cannot connect");
+		die_wlerr(status, "cannot connect link '%s'", link);
 	}
 	free(keys);
 }
@@ -2525,7 +2525,7 @@
 		switch (option) {
 		case 'p':
 			if (parse_props(optarg, &proplist, B_TRUE) < 0)
-				die("invalid field(s) specified");
+				die("invalid link properties specified");
 			break;
 		case 'c':
 			state.ls_parseable = B_TRUE;
@@ -2659,8 +2659,11 @@
 			    "on '%s'", link);
 		}
 		if (!temp) {
-			status = set_linkprop_persist(link, NULL, NULL, 0,
-			    reset);
+			dladm_status_t	s;
+
+			s = set_linkprop_persist(link, NULL, NULL, 0, reset);
+			if (s != DLADM_STATUS_OK)
+				status = s;
 		}
 		goto done;
 	}
--- a/usr/src/lib/libwladm/common/libwladm.c	Wed Dec 20 22:04:44 2006 -0800
+++ b/usr/src/lib/libwladm/common/libwladm.c	Wed Dec 20 22:32:03 2006 -0800
@@ -515,46 +515,46 @@
 	wladm_bsstype_t		bsstype;
 	wladm_essid_t		essid;
 	boolean_t		essid_valid = B_FALSE;
-	wladm_status_t		status = WLADM_STATUS_FAILED;
 	wladm_channel_t		channel;
 	hrtime_t		start;
-	struct timespec		ts;
 
 	if ((attrp->wa_valid & WLADM_WLAN_ATTR_CHANNEL) != 0) {
 		channel = attrp->wa_channel;
 		if (do_set_channel(fd, gbuf, &channel) < 0)
-			goto done;
+			goto fail;
 	}
 
 	secmode = ((attrp->wa_valid & WLADM_WLAN_ATTR_SECMODE) != 0) ?
 	    attrp->wa_secmode : WLADM_SECMODE_NONE;
 
 	if (do_set_encryption(fd, gbuf, &secmode) < 0)
-		goto done;
+		goto fail;
 
 	authmode = ((attrp->wa_valid & WLADM_WLAN_ATTR_AUTH) != 0) ?
 	    attrp->wa_auth : WLADM_AUTH_OPEN;
 
 	if (do_set_authmode(fd, gbuf, &authmode) < 0)
-		goto done;
+		goto fail;
 
 	bsstype = ((attrp->wa_valid & WLADM_WLAN_ATTR_BSSTYPE) != 0) ?
 	    attrp->wa_bsstype : WLADM_BSSTYPE_BSS;
 
 	if (do_set_bsstype(fd, gbuf, &bsstype) < 0)
-		goto done;
+		goto fail;
 
-	if (secmode == WLADM_SECMODE_WEP &&
-	    (keys == NULL || key_count == 0 || key_count > MAX_NWEPKEYS ||
-	    do_set_wepkey(fd, gbuf, keys, key_count) < 0))
-		goto done;
+	if (secmode == WLADM_SECMODE_WEP) {
+		if (keys == NULL || key_count == 0 || key_count > MAX_NWEPKEYS)
+			return (WLADM_STATUS_BADARG);
+		if (do_set_wepkey(fd, gbuf, keys, key_count) < 0)
+			goto fail;
+	}
 
 	if (create_ibss) {
 		if (do_set_channel(fd, gbuf, &channel) < 0)
-			goto done;
+			goto fail;
 
 		if (do_set_createibss(fd, gbuf, &create_ibss) < 0)
-			goto done;
+			goto fail;
 
 		if ((attrp->wa_valid & WLADM_WLAN_ATTR_ESSID) == 0) {
 			generate_essid(&essid);
@@ -567,31 +567,27 @@
 		essid_valid = B_TRUE;
 	}
 
-	if (!essid_valid || do_set_essid(fd, gbuf, &essid) < 0)
-		goto done;
+	if (!essid_valid)
+		return (WLADM_STATUS_FAILED);
+	if (do_set_essid(fd, gbuf, &essid) < 0)
+		goto fail;
 
-	ts.tv_sec = 0;
-	ts.tv_nsec = WLADM_CONNECT_POLLRATE;
 	start = gethrtime();
 	for (;;) {
-		if (do_get_linkstatus(fd, gbuf) < 0) {
-			status = WLADM_STATUS_FAILED;
-			goto done;
-		}
+		if (do_get_linkstatus(fd, gbuf) < 0)
+			goto fail;
 
 		if (IS_CONNECTED(gbuf))
 			break;
 
-		(void) nanosleep(&ts, NULL);
+		(void) poll(NULL, 0, WLADM_CONNECT_POLLRATE);
 		if ((timeout >= 0) && (gethrtime() - start) /
-		    NANOSEC >= timeout) {
-			status = WLADM_STATUS_TIMEDOUT;
-			goto done;
-		}
+		    NANOSEC >= timeout)
+			return (WLADM_STATUS_TIMEDOUT);
 	}
-	status = WLADM_STATUS_OK;
-done:
-	return (status);
+	return (WLADM_STATUS_OK);
+fail:
+	return (wladm_wlresult2status(gbuf));
 }
 
 wladm_status_t
--- a/usr/src/lib/libwladm/common/libwladm_impl.h	Wed Dec 20 22:04:44 2006 -0800
+++ b/usr/src/lib/libwladm/common/libwladm_impl.h	Wed Dec 20 22:32:03 2006 -0800
@@ -55,7 +55,7 @@
  */
 #define	WLADM_OFDM2CHAN(mhz)		(((mhz) - 5000) / 5)
 
-#define	WLADM_CONNECT_POLLRATE		200000000 /* nanoseconds */
+#define	WLADM_CONNECT_POLLRATE		200 /* milliseconds */
 #define	WLADM_CONNECT_DEFAULT_CHANNEL	1
 
 #define	WLADM_MAX_RATES	4