+ /* ---------- Set operation mode ---------- */
+ if(!strcmp(args[i], "mode"))
+ {
+ int k;
+
+ i++;
+ if(i >= count)
+ iw_usage();
+
+ if(sscanf(args[i], "%d", &k) != 1)
+ {
+ k = 0;
+ while(k < 6 && strncasecmp(args[i], operation_mode[k], 3))
+ k++;
+ }
+ if((k > 5) || (k < 0))
+ iw_usage();
+
+ wrq.u.mode = k;
+ if(ioctl(skfd, SIOCSIWMODE, &wrq) < 0)
+ {
+ fprintf(stderr, "SIOCSIWMODE: %s\n", strerror(errno));
+ return(-1);
+ }
+ continue;
+ }
+
+ /* ---------- Set Power Management ---------- */
+ if(!strncmp(args[i], "power", 3))
+ {
+ if(++i >= count)
+ iw_usage();
+
+ if(!strcasecmp(args[i], "off"))
+ wrq.u.power.disabled = 1; /* i.e. max size */
+ else
+ if(!strcasecmp(args[i], "on"))
+ {
+ /* Get old Power info */
+ if(ioctl(skfd, SIOCGIWPOWER, &wrq) < 0)
+ {
+ fprintf(stderr, "SIOCGIWFRAG: %s\n", strerror(errno));
+ return(-1);
+ }
+ strcpy(wrq.ifr_name, ifname);
+ wrq.u.power.disabled = 0;
+ }
+ else
+ {
+ double temp;
+ int gotone = 0;
+ /* Default - nope */
+ wrq.u.power.flags = IW_POWER_ON;
+ wrq.u.power.disabled = 0;
+
+ /* Check value modifier */
+ if(!strcasecmp(args[i], "period"))
+ {
+ wrq.u.power.flags = IW_POWER_PERIOD;
+ if(++i >= count)
+ iw_usage();
+ }
+ else
+ if(!strcasecmp(args[i], "timeout"))
+ {
+ wrq.u.power.flags = IW_POWER_TIMEOUT;
+ if(++i >= count)
+ iw_usage();
+ }
+
+ /* Is there any value to grab ? */
+ if(sscanf(args[i], "%lg", &(temp)) == 1)
+ {
+ temp *= MEGA; /* default = s */
+ if(index(args[i], 'u')) temp /= MEGA;
+ if(index(args[i], 'm')) temp /= KILO;
+ wrq.u.power.value = (long) temp;
+ if(wrq.u.power.flags == IW_POWER_ON)
+ wrq.u.power.flags = IW_POWER_PERIOD;
+ ++i;
+ gotone = 1;
+ }
+
+ /* Now, check the mode */
+ if(i < count)
+ {
+ if(!strcasecmp(args[i], "all"))
+ wrq.u.power.flags |= IW_POWER_ALL_R;
+ if(!strncasecmp(args[i], "unicast", 4))
+ wrq.u.power.flags |= IW_POWER_UNICAST_R;
+ if(!strncasecmp(args[i], "multicast", 5))
+ wrq.u.power.flags |= IW_POWER_MULTICAST_R;
+ if(!strncasecmp(args[i], "force", 5))
+ wrq.u.power.flags |= IW_POWER_FORCE_S;
+ if(!strcasecmp(args[i], "repeat"))
+ wrq.u.power.flags |= IW_POWER_REPEATER;
+ if(wrq.u.power.flags & IW_POWER_MODE)
+ {
+ ++i;
+ gotone = 1;
+ }
+ }
+ if(!gotone)
+ iw_usage();
+ --i;
+ }
+
+ if(ioctl(skfd, SIOCSIWPOWER, &wrq) < 0)
+ {
+ fprintf(stderr, "SIOCSIWPOWER(%d): %s\n",
+ errno, strerror(errno));
+ return(-1);
+ }
+ continue;
+ }
+
+ /* ---------- Other ---------- */