4 * Jean II - HPLB 97->99 - HPL 99->01
6 * Main code for "iwconfig". This is the generic tool for most
8 * You need to link this code against "iwlib.c" and "-lm".
10 * This file is released under the GPL license.
11 * Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com>
14 #include "iwlib.h" /* Header */
16 /************************* MISC SUBROUTINES **************************/
18 /*------------------------------------------------------------------*/
25 fprintf(stderr, "Usage: iwconfig interface [essid {NN|on|off}]\n");
26 fprintf(stderr, " [nwid {NN|on|off}]\n");
27 fprintf(stderr, " [mode {managed|ad-hoc|...}\n");
28 fprintf(stderr, " [freq N.NNNN[k|M|G]]\n");
29 fprintf(stderr, " [channel N]\n");
30 fprintf(stderr, " [sens N]\n");
31 fprintf(stderr, " [nick N]\n");
32 fprintf(stderr, " [rate {N|auto|fixed}]\n");
33 fprintf(stderr, " [rts {N|auto|fixed|off}]\n");
34 fprintf(stderr, " [frag {N|auto|fixed|off}]\n");
35 fprintf(stderr, " [enc {NNNN-NNNN|off}]\n");
36 fprintf(stderr, " [power {period N|timeout N}]\n");
37 fprintf(stderr, " [txpower N {mW|dBm}]\n");
38 fprintf(stderr, " [commit]\n");
39 fprintf(stderr, " Check man pages for more details.\n\n");
43 /************************* DISPLAY ROUTINES **************************/
45 /*------------------------------------------------------------------*/
47 * Get wireless informations & config from the device driver
48 * We will call all the classical wireless ioctl on the driver through
49 * the socket to know what is supported and to get the settings...
54 struct wireless_info * info)
58 memset((char *) info, 0, sizeof(struct wireless_info));
60 /* Get wireless name */
61 if(iw_get_ext(skfd, ifname, SIOCGIWNAME, &wrq) < 0)
63 /* If no wireless name : no wireless extensions */
64 /* But let's check if the interface exists at all */
67 strcpy(ifr.ifr_name, ifname);
68 if(ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
75 strncpy(info->name, wrq.u.name, IFNAMSIZ);
76 info->name[IFNAMSIZ] = '\0';
80 if(iw_get_range_info(skfd, ifname, &(info->range)) >= 0)
84 if(iw_get_ext(skfd, ifname, SIOCGIWNWID, &wrq) >= 0)
87 memcpy(&(info->nwid), &(wrq.u.nwid), sizeof(iwparam));
90 /* Get frequency / channel */
91 if(iw_get_ext(skfd, ifname, SIOCGIWFREQ, &wrq) >= 0)
94 info->freq = iw_freq2float(&(wrq.u.freq));
98 if(iw_get_ext(skfd, ifname, SIOCGIWSENS, &wrq) >= 0)
101 memcpy(&(info->sens), &(wrq.u.sens), sizeof(iwparam));
104 /* Get encryption information */
105 wrq.u.data.pointer = (caddr_t) info->key;
106 wrq.u.data.length = IW_ENCODING_TOKEN_MAX;
107 wrq.u.data.flags = 0;
108 if(iw_get_ext(skfd, ifname, SIOCGIWENCODE, &wrq) >= 0)
111 info->key_size = wrq.u.data.length;
112 info->key_flags = wrq.u.data.flags;
116 wrq.u.essid.pointer = (caddr_t) info->essid;
117 wrq.u.essid.length = IW_ESSID_MAX_SIZE + 1;
118 wrq.u.essid.flags = 0;
119 if(iw_get_ext(skfd, ifname, SIOCGIWESSID, &wrq) >= 0)
122 info->essid_on = wrq.u.data.flags;
126 if(iw_get_ext(skfd, ifname, SIOCGIWAP, &wrq) >= 0)
128 info->has_ap_addr = 1;
129 memcpy(&(info->ap_addr), &(wrq.u.ap_addr), sizeof (sockaddr));
133 wrq.u.essid.pointer = (caddr_t) info->nickname;
134 wrq.u.essid.length = IW_ESSID_MAX_SIZE + 1;
135 wrq.u.essid.flags = 0;
136 if(iw_get_ext(skfd, ifname, SIOCGIWNICKN, &wrq) >= 0)
137 if(wrq.u.data.length > 1)
138 info->has_nickname = 1;
141 if(iw_get_ext(skfd, ifname, SIOCGIWRATE, &wrq) >= 0)
143 info->has_bitrate = 1;
144 memcpy(&(info->bitrate), &(wrq.u.bitrate), sizeof(iwparam));
147 /* Get RTS threshold */
148 if(iw_get_ext(skfd, ifname, SIOCGIWRTS, &wrq) >= 0)
151 memcpy(&(info->rts), &(wrq.u.rts), sizeof(iwparam));
154 /* Get fragmentation threshold */
155 if(iw_get_ext(skfd, ifname, SIOCGIWFRAG, &wrq) >= 0)
158 memcpy(&(info->frag), &(wrq.u.frag), sizeof(iwparam));
161 /* Get operation mode */
162 if(iw_get_ext(skfd, ifname, SIOCGIWMODE, &wrq) >= 0)
164 info->mode = wrq.u.mode;
165 if((info->mode < IW_NUM_OPER_MODE) && (info->mode >= 0))
169 /* Get Power Management settings */
170 wrq.u.power.flags = 0;
171 if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, &wrq) >= 0)
174 memcpy(&(info->power), &(wrq.u.power), sizeof(iwparam));
178 /* Get Transmit Power */
179 if(iw_get_ext(skfd, ifname, SIOCGIWTXPOW, &wrq) >= 0)
181 info->has_txpower = 1;
182 memcpy(&(info->txpower), &(wrq.u.txpower), sizeof(iwparam));
186 #if WIRELESS_EXT > 10
187 /* Get retry limit/lifetime */
188 if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, &wrq) >= 0)
191 memcpy(&(info->retry), &(wrq.u.retry), sizeof(iwparam));
193 #endif /* WIRELESS_EXT > 10 */
196 if(iw_get_stats(skfd, ifname, &(info->stats)) >= 0)
204 /*------------------------------------------------------------------*/
206 * Print on the screen in a neat fashion all the info we have collected
210 display_info(struct wireless_info * info,
213 char buffer[128]; /* Temporary buffer */
215 /* One token is more of less 5 characters, 14 tokens per line */
216 int tokens = 3; /* For name */
218 /* Display device name and wireless name (name of the protocol used) */
219 printf("%-8.8s %s ", ifname, info->name);
221 /* Display ESSID (extended network), if any */
226 /* Does it have an ESSID index ? */
227 if((info->essid_on & IW_ENCODE_INDEX) > 1)
228 printf("ESSID:\"%s\" [%d] ", info->essid,
229 (info->essid_on & IW_ENCODE_INDEX));
231 printf("ESSID:\"%s\" ", info->essid);
234 printf("ESSID:off/any ");
237 /* Display NickName (station name), if any */
238 if(info->has_nickname)
239 printf("Nickname:\"%s\"", info->nickname);
242 if(info->has_essid || info->has_nickname)
248 /* Display Network ID */
251 /* Note : should display proper number of digit according to info
252 * in range structure */
253 if(info->nwid.disabled)
254 printf("NWID:off/any ");
256 printf("NWID:%X ", info->nwid.value);
260 /* Display the current mode of operation */
263 printf("Mode:%s ", iw_operation_mode[info->mode]);
267 /* Display frequency / channel */
270 iw_print_freq(buffer, info->freq);
271 printf("%s ", buffer);
275 /* Display the address of the current Access Point */
276 if(info->has_ap_addr)
278 /* A bit of clever formatting */
286 /* Oups ! No Access Point in Ad-Hoc mode */
287 if((info->has_mode) && (info->mode == IW_MODE_ADHOC))
290 printf("Access Point:");
291 printf(" %s ", iw_pr_ether(buffer, info->ap_addr.sa_data));
294 /* Display the currently used/set bit-rate */
295 if(info->has_bitrate)
297 /* A bit of clever formatting */
306 iw_print_bitrate(buffer, info->bitrate.value);
307 printf("Bit Rate%c%s ", (info->bitrate.fixed ? '=' : ':'), buffer);
311 /* Display the Transmit Power */
312 if(info->has_txpower)
314 /* A bit of clever formatting */
323 if(info->txpower.disabled)
324 printf("Tx-Power:off ");
330 if(info->txpower.fixed)
335 /* Convert everything to dBm */
336 if(info->txpower.flags & IW_TXPOW_MWATT)
337 dbm = iw_mwatt2dbm(info->txpower.value);
339 dbm = info->txpower.value;
342 printf("%d dBm ", dbm);
347 /* Display sensitivity */
350 /* A bit of clever formatting */
360 printf("Sensitivity=");
362 printf("Sensitivity:");
365 /* Display in dBm ? */
366 if(info->sens.value < 0)
367 printf("%d dBm ", info->sens.value);
369 printf("%d/%d ", info->sens.value, info->range.sensitivity);
371 printf("%d ", info->sens.value);
377 #if WIRELESS_EXT > 10
378 /* Display retry limit/lifetime information */
383 if(info->retry.disabled)
387 /* Let's check the value and its type */
388 if(info->retry.flags & IW_RETRY_TYPE)
390 iw_print_retry_value(buffer,
391 info->retry.value, info->retry.flags);
392 printf("%s", buffer);
395 /* Let's check if nothing (simply on) */
396 if(info->retry.flags == IW_RETRY_ON)
400 tokens += 5; /* Between 3 and 5, depend on flags */
402 #endif /* WIRELESS_EXT > 10 */
404 /* Display the RTS threshold */
408 if(info->rts.disabled)
409 printf("RTS thr:off ");
418 printf("%d B ", info->rts.value);
423 /* Display the fragmentation threshold */
426 /* A bit of clever formatting */
435 if(info->frag.disabled)
436 printf("Fragment thr:off");
441 printf("Fragment thr=");
443 printf("Fragment thr:");
445 printf("%d B ", info->frag.value);
453 /* Display encryption information */
454 /* Note : we display only the "current" key, use iwlist to list all keys */
457 printf("Encryption key:");
458 if((info->key_flags & IW_ENCODE_DISABLED) || (info->key_size == 0))
462 /* Display the key */
463 iw_print_key(buffer, info->key, info->key_size, info->key_flags);
464 printf("%s", buffer);
467 if((info->key_flags & IW_ENCODE_INDEX) > 1)
468 printf(" [%d]", info->key_flags & IW_ENCODE_INDEX);
469 if(info->key_flags & IW_ENCODE_RESTRICTED)
470 printf(" Encryption mode:restricted");
471 if(info->key_flags & IW_ENCODE_OPEN)
472 printf(" Encryption mode:open");
477 /* Display Power Management information */
478 /* Note : we display only one parameter, period or timeout. If a device
479 * (such as HiperLan) has both, the user need to use iwlist... */
480 if(info->has_power) /* I hope the device has power ;-) */
482 printf("Power Management");
484 if(info->power.disabled)
488 /* Let's check the value and its type */
489 if(info->power.flags & IW_POWER_TYPE)
491 iw_print_pm_value(buffer, info->power.value, info->power.flags);
492 printf("%s ", buffer);
495 /* Let's check the mode */
496 iw_print_pm_mode(buffer, info->power.flags);
497 printf("%s", buffer);
499 /* Let's check if nothing (simply on) */
500 if(info->power.flags == IW_POWER_ON)
506 /* Display statistics */
509 info->stats.qual.updated = 0x0; /* Not that reliable, disable */
510 iw_print_stats(buffer, &info->stats.qual, &info->range, info->has_range);
511 printf("Link %s\n", buffer);
513 #if WIRELESS_EXT > 11
514 printf(" Rx invalid nwid:%d Rx invalid crypt:%d Rx invalid frag:%d\n Tx excessive retries:%d Invalid misc:%d Missed beacon:%d\n",
515 info->stats.discard.nwid,
516 info->stats.discard.code,
517 info->stats.discard.fragment,
518 info->stats.discard.retries,
519 info->stats.discard.misc,
520 info->stats.miss.beacon);
521 #else /* WIRELESS_EXT > 11 */
522 printf(" Rx invalid nwid:%d invalid crypt:%d invalid misc:%d\n",
523 info->stats.discard.nwid,
524 info->stats.discard.code,
525 info->stats.discard.misc);
526 #endif /* WIRELESS_EXT > 11 */
532 /*------------------------------------------------------------------*/
534 * Print on the screen in a neat fashion all the info we have collected
543 struct wireless_info info;
546 /* Avoid "Unused parameter" warning */
547 args = args; count = count;
549 rc = get_info(skfd, ifname, &info);
552 case 0: /* Success */
554 display_info(&info, ifname);
558 fprintf(stderr, "%-8.8s no wireless extensions.\n\n",
563 fprintf(stderr, "%-8.8s %s\n\n", ifname, strerror(-rc));
568 /************************* SETTING ROUTINES **************************/
570 /*------------------------------------------------------------------*/
572 * Macro to handle errors when setting WE
573 * Print a nice error message and exit...
574 * We define them as macro so that "return" do the right thing.
575 * The "do {...} while(0)" is a standard trick
577 #define ERR_SET_EXT(rname, request) \
578 fprintf(stderr, "Error for wireless request \"%s\" (%X) :\n", \
581 #define ABORT_ARG_NUM(rname, request) \
583 ERR_SET_EXT(rname, request); \
584 fprintf(stderr, " too few arguments.\n"); \
588 #define ABORT_ARG_TYPE(rname, request, arg) \
590 ERR_SET_EXT(rname, request); \
591 fprintf(stderr, " invalid argument \"%s\".\n", arg); \
595 #define ABORT_ARG_SIZE(rname, request, max) \
597 ERR_SET_EXT(rname, request); \
598 fprintf(stderr, " argument too big (max %d)\n", max); \
602 /*------------------------------------------------------------------*/
604 * Wrapper to push some Wireless Parameter in the driver
605 * Use standard wrapper and add pretty error message if fail...
607 #define IW_SET_EXT_ERR(skfd, ifname, request, wrq, rname) \
609 if(iw_set_ext(skfd, ifname, request, wrq) < 0) { \
610 ERR_SET_EXT(rname, request); \
611 fprintf(stderr, " SET failed on device %-1.8s ; %s.\n", \
612 ifname, strerror(errno)); \
616 /*------------------------------------------------------------------*/
618 * Wrapper to extract some Wireless Parameter out of the driver
619 * Use standard wrapper and add pretty error message if fail...
621 #define IW_GET_EXT_ERR(skfd, ifname, request, wrq, rname) \
623 if(iw_get_ext(skfd, ifname, request, wrq) < 0) { \
624 ERR_SET_EXT(rname, request); \
625 fprintf(stderr, " GET failed on device %-1.8s ; %s.\n", \
626 ifname, strerror(errno)); \
630 /*------------------------------------------------------------------*/
632 * Set the wireless options requested on command line
633 * This function is too long and probably should be split,
634 * because it look like the perfect definition of spaghetti code,
635 * but I'm way to lazy
638 set_info(int skfd, /* The socket */
639 char * args[], /* Command line args */
640 int count, /* Args count */
641 char * ifname) /* Dev name */
646 /* if nothing after the device name - will never happen */
649 fprintf(stderr, "Error : too few arguments.\n");
653 /* The other args on the line specify options to be set... */
654 for(i = 0; i < count; i++)
656 /* ---------- Commit changes to driver ---------- */
657 if(!strncmp(args[i], "commit", 6))
660 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWCOMMIT, &wrq,
665 /* ---------- Set network ID ---------- */
666 if((!strcasecmp(args[i], "nwid")) ||
667 (!strcasecmp(args[i], "domain")))
671 ABORT_ARG_NUM("Set NWID", SIOCSIWNWID);
672 if((!strcasecmp(args[i], "off")) ||
673 (!strcasecmp(args[i], "any")))
674 wrq.u.nwid.disabled = 1;
676 if(!strcasecmp(args[i], "on"))
679 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWNWID, &wrq,
681 wrq.u.nwid.disabled = 0;
684 if(sscanf(args[i], "%lX", (unsigned long *) &(wrq.u.nwid.value))
686 ABORT_ARG_TYPE("Set NWID", SIOCSIWNWID, args[i]);
688 wrq.u.nwid.disabled = 0;
689 wrq.u.nwid.fixed = 1;
692 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWNWID, &wrq,
697 /* ---------- Set frequency / channel ---------- */
698 if((!strncmp(args[i], "freq", 4)) ||
699 (!strcmp(args[i], "channel")))
704 ABORT_ARG_NUM("Set Frequency", SIOCSIWFREQ);
705 if(sscanf(args[i], "%lg", &(freq)) != 1)
706 ABORT_ARG_TYPE("Set Frequency", SIOCSIWFREQ, args[i]);
707 if(index(args[i], 'G')) freq *= GIGA;
708 if(index(args[i], 'M')) freq *= MEGA;
709 if(index(args[i], 'k')) freq *= KILO;
711 iw_float2freq(freq, &(wrq.u.freq));
713 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFREQ, &wrq,
718 /* ---------- Set sensitivity ---------- */
719 if(!strncmp(args[i], "sens", 4))
722 ABORT_ARG_NUM("Set Sensitivity", SIOCSIWSENS);
723 if(sscanf(args[i], "%d", &(wrq.u.sens.value)) != 1)
724 ABORT_ARG_TYPE("Set Sensitivity", SIOCSIWSENS, args[i]);
726 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWSENS, &wrq,
731 /* ---------- Set encryption stuff ---------- */
732 if((!strncmp(args[i], "enc", 3)) ||
733 (!strcmp(args[i], "key")))
735 unsigned char key[IW_ENCODING_TOKEN_MAX];
738 ABORT_ARG_NUM("Set Encode", SIOCSIWENCODE);
740 if(!strcasecmp(args[i], "on"))
742 /* Get old encryption information */
743 wrq.u.data.pointer = (caddr_t) key;
744 wrq.u.data.length = 0;
745 wrq.u.data.flags = 0;
746 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWENCODE, &wrq,
748 wrq.u.data.flags &= ~IW_ENCODE_DISABLED; /* Enable */
757 wrq.u.data.pointer = (caddr_t) NULL;
758 wrq.u.data.flags = 0;
759 wrq.u.data.length = 0;
761 /* Allow arguments in any order (it's safe) */
766 /* -- Check for the key -- */
769 keylen = iw_in_key(args[i], key);
772 wrq.u.data.length = keylen;
773 wrq.u.data.pointer = (caddr_t) key;
779 /* -- Check for token index -- */
781 (sscanf(args[i], "[%d]", &temp) == 1) &&
782 (temp > 0) && (temp < IW_ENCODE_INDEX))
784 wrq.u.encoding.flags |= temp;
789 /* -- Check the various flags -- */
790 if((i < count) && (!strcasecmp(args[i], "off")))
792 wrq.u.data.flags |= IW_ENCODE_DISABLED;
796 if((i < count) && (!strcasecmp(args[i], "open")))
798 wrq.u.data.flags |= IW_ENCODE_OPEN;
802 if((i < count) && (!strncasecmp(args[i], "restricted", 5)))
804 wrq.u.data.flags |= IW_ENCODE_RESTRICTED;
809 while(gotone != oldone);
811 /* Pointer is absent in new API */
812 if(wrq.u.data.pointer == NULL)
813 wrq.u.data.flags |= IW_ENCODE_NOKEY;
815 /* Check if we have any invalid argument */
817 ABORT_ARG_TYPE("Set Encode", SIOCSIWENCODE, args[i]);
818 /* Get back to last processed argument */
822 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWENCODE, &wrq,
827 /* ---------- Set ESSID ---------- */
828 if(!strcasecmp(args[i], "essid"))
830 char essid[IW_ESSID_MAX_SIZE + 1];
834 ABORT_ARG_NUM("Set ESSID", SIOCSIWESSID);
835 if((!strcasecmp(args[i], "off")) ||
836 (!strcasecmp(args[i], "any")))
838 wrq.u.essid.flags = 0;
842 if(!strcasecmp(args[i], "on"))
845 wrq.u.essid.pointer = (caddr_t) essid;
846 wrq.u.essid.length = 0;
847 wrq.u.essid.flags = 0;
848 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWESSID, &wrq,
850 wrq.u.essid.flags = 1;
853 /* Check the size of what the user passed us to avoid
854 * buffer overflows */
855 if(strlen(args[i]) > IW_ESSID_MAX_SIZE)
856 ABORT_ARG_SIZE("Set ESSID", SIOCSIWESSID, IW_ESSID_MAX_SIZE);
861 wrq.u.essid.flags = 1;
862 strcpy(essid, args[i]); /* Size checked, all clear */
864 /* Check for ESSID index */
865 if(((i+1) < count) &&
866 (sscanf(args[i+1], "[%d]", &temp) == 1) &&
867 (temp > 0) && (temp < IW_ENCODE_INDEX))
869 wrq.u.essid.flags = temp;
874 wrq.u.essid.pointer = (caddr_t) essid;
875 wrq.u.essid.length = strlen(essid) + 1;
876 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWESSID, &wrq,
881 /* ---------- Set AP address ---------- */
882 if(!strcasecmp(args[i], "ap"))
885 ABORT_ARG_NUM("Set AP Address", SIOCSIWAP);
887 if((!strcasecmp(args[i], "auto")) ||
888 (!strcasecmp(args[i], "any")))
890 /* Send a broadcast address */
891 iw_broad_ether(&(wrq.u.ap_addr));
895 if(!strcasecmp(args[i], "off"))
897 /* Send a NULL address */
898 iw_null_ether(&(wrq.u.ap_addr));
902 /* Get the address and check if the interface supports it */
903 if(iw_in_addr(skfd, ifname, args[i++], &(wrq.u.ap_addr)) < 0)
904 ABORT_ARG_TYPE("Set AP Address", SIOCSIWAP, args[i-1]);
908 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWAP, &wrq,
913 /* ---------- Set NickName ---------- */
914 if(!strncmp(args[i], "nick", 4))
918 ABORT_ARG_NUM("Set Nickname", SIOCSIWNICKN);
919 if(strlen(args[i]) > IW_ESSID_MAX_SIZE)
920 ABORT_ARG_SIZE("Set Nickname", SIOCSIWNICKN, IW_ESSID_MAX_SIZE);
922 wrq.u.essid.pointer = (caddr_t) args[i];
923 wrq.u.essid.length = strlen(args[i]) + 1;
924 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWNICKN, &wrq,
929 /* ---------- Set Bit-Rate ---------- */
930 if((!strncmp(args[i], "bit", 3)) ||
931 (!strcmp(args[i], "rate")))
934 ABORT_ARG_NUM("Set Bit Rate", SIOCSIWRATE);
935 if(!strcasecmp(args[i], "auto"))
937 wrq.u.bitrate.value = -1;
938 wrq.u.bitrate.fixed = 0;
942 if(!strcasecmp(args[i], "fixed"))
944 /* Get old bitrate */
945 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWRATE, &wrq,
947 wrq.u.bitrate.fixed = 1;
949 else /* Should be a numeric value */
953 if(sscanf(args[i], "%lg", &(brate)) != 1)
954 ABORT_ARG_TYPE("Set Bit Rate", SIOCSIWRATE, args[i]);
955 if(index(args[i], 'G')) brate *= GIGA;
956 if(index(args[i], 'M')) brate *= MEGA;
957 if(index(args[i], 'k')) brate *= KILO;
958 wrq.u.bitrate.value = (long) brate;
959 wrq.u.bitrate.fixed = 1;
961 /* Check for an additional argument */
962 if(((i+1) < count) &&
963 (!strcasecmp(args[i+1], "auto")))
965 wrq.u.bitrate.fixed = 0;
968 if(((i+1) < count) &&
969 (!strcasecmp(args[i+1], "fixed")))
971 wrq.u.bitrate.fixed = 1;
977 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRATE, &wrq,
982 /* ---------- Set RTS threshold ---------- */
983 if(!strncasecmp(args[i], "rts", 3))
987 ABORT_ARG_NUM("Set RTS Threshold", SIOCSIWRTS);
988 wrq.u.rts.value = -1;
990 wrq.u.rts.disabled = 0;
991 if(!strcasecmp(args[i], "off"))
992 wrq.u.rts.disabled = 1; /* i.e. max size */
994 if(!strcasecmp(args[i], "auto"))
998 if(!strcasecmp(args[i], "fixed"))
1000 /* Get old RTS threshold */
1001 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWRTS, &wrq,
1002 "Set RTS Threshold");
1003 wrq.u.rts.fixed = 1;
1005 else /* Should be a numeric value */
1006 if(sscanf(args[i], "%ld", (unsigned long *) &(wrq.u.rts.value))
1008 ABORT_ARG_TYPE("Set RTS Threshold", SIOCSIWRTS, args[i]);
1011 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRTS, &wrq,
1012 "Set RTS Threshold");
1016 /* ---------- Set fragmentation threshold ---------- */
1017 if(!strncmp(args[i], "frag", 4))
1021 ABORT_ARG_NUM("Set Fragmentation Threshold", SIOCSIWFRAG);
1022 wrq.u.frag.value = -1;
1023 wrq.u.frag.fixed = 1;
1024 wrq.u.frag.disabled = 0;
1025 if(!strcasecmp(args[i], "off"))
1026 wrq.u.frag.disabled = 1; /* i.e. max size */
1028 if(!strcasecmp(args[i], "auto"))
1029 wrq.u.frag.fixed = 0;
1032 if(!strcasecmp(args[i], "fixed"))
1034 /* Get old fragmentation threshold */
1035 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWFRAG, &wrq,
1036 "Set Fragmentation Threshold");
1037 wrq.u.frag.fixed = 1;
1039 else /* Should be a numeric value */
1040 if(sscanf(args[i], "%ld",
1041 (unsigned long *) &(wrq.u.frag.value))
1043 ABORT_ARG_TYPE("Set Fragmentation Threshold", SIOCSIWFRAG,
1047 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFRAG, &wrq,
1048 "Set Fragmentation Threshold");
1052 /* ---------- Set operation mode ---------- */
1053 if(!strcmp(args[i], "mode"))
1059 ABORT_ARG_NUM("Set Mode", SIOCSIWMODE);
1061 if(sscanf(args[i], "%d", &k) != 1)
1064 while((k < IW_NUM_OPER_MODE) &&
1065 strncasecmp(args[i], iw_operation_mode[k], 3))
1068 if((k >= IW_NUM_OPER_MODE) || (k < 0))
1069 ABORT_ARG_TYPE("Set Mode", SIOCSIWMODE, args[i]);
1072 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWMODE, &wrq,
1077 /* ---------- Set Power Management ---------- */
1078 if(!strncmp(args[i], "power", 3))
1081 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1083 if(!strcasecmp(args[i], "off"))
1084 wrq.u.power.disabled = 1; /* i.e. max size */
1086 if(!strcasecmp(args[i], "on"))
1088 /* Get old Power info */
1089 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWPOWER, &wrq,
1090 "Set Power Management");
1091 wrq.u.power.disabled = 0;
1097 /* Default - nope */
1098 wrq.u.power.flags = IW_POWER_ON;
1099 wrq.u.power.disabled = 0;
1101 /* Check value modifier */
1102 if(!strcasecmp(args[i], "min"))
1104 wrq.u.power.flags |= IW_POWER_MIN;
1106 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1109 if(!strcasecmp(args[i], "max"))
1111 wrq.u.power.flags |= IW_POWER_MAX;
1113 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1116 /* Check value type */
1117 if(!strcasecmp(args[i], "period"))
1119 wrq.u.power.flags |= IW_POWER_PERIOD;
1121 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1124 if(!strcasecmp(args[i], "timeout"))
1126 wrq.u.power.flags |= IW_POWER_TIMEOUT;
1128 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1131 /* Is there any value to grab ? */
1132 if(sscanf(args[i], "%lg", &(temp)) == 1)
1134 temp *= MEGA; /* default = s */
1135 if(index(args[i], 'u')) temp /= MEGA;
1136 if(index(args[i], 'm')) temp /= KILO;
1137 wrq.u.power.value = (long) temp;
1138 if((wrq.u.power.flags & IW_POWER_TYPE) == 0)
1139 wrq.u.power.flags |= IW_POWER_PERIOD;
1144 /* Now, check the mode */
1147 if(!strcasecmp(args[i], "all"))
1148 wrq.u.power.flags |= IW_POWER_ALL_R;
1149 if(!strncasecmp(args[i], "unicast", 4))
1150 wrq.u.power.flags |= IW_POWER_UNICAST_R;
1151 if(!strncasecmp(args[i], "multicast", 5))
1152 wrq.u.power.flags |= IW_POWER_MULTICAST_R;
1153 if(!strncasecmp(args[i], "force", 5))
1154 wrq.u.power.flags |= IW_POWER_FORCE_S;
1155 if(!strcasecmp(args[i], "repeat"))
1156 wrq.u.power.flags |= IW_POWER_REPEATER;
1157 if(wrq.u.power.flags & IW_POWER_MODE)
1164 ABORT_ARG_TYPE("Set Power Management", SIOCSIWPOWER,
1169 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWPOWER, &wrq,
1170 "Set Power Management");
1174 #if WIRELESS_EXT > 9
1175 /* ---------- Set Transmit-Power ---------- */
1176 if(!strncmp(args[i], "txpower", 3))
1178 struct iw_range range;
1181 ABORT_ARG_NUM("Set Tx Power", SIOCSIWTXPOW);
1183 /* Extract range info */
1184 if(iw_get_range_info(skfd, ifname, &range) < 0)
1185 memset(&range, 0, sizeof(range));
1187 /* Prepare the request */
1188 wrq.u.txpower.value = -1;
1189 wrq.u.txpower.fixed = 1;
1190 wrq.u.txpower.disabled = 0;
1191 wrq.u.data.flags = IW_TXPOW_DBM;
1192 if(!strcasecmp(args[i], "off"))
1193 wrq.u.txpower.disabled = 1; /* i.e. turn radio off */
1195 if(!strcasecmp(args[i], "auto"))
1196 wrq.u.txpower.fixed = 0; /* i.e. use power control */
1199 if(!strcasecmp(args[i], "fixed"))
1201 /* Get old tx-power */
1202 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWTXPOW, &wrq,
1204 wrq.u.txpower.fixed = 1;
1206 else /* Should be a numeric value */
1212 if(sscanf(args[i], "%ld",
1213 (unsigned long *) &(power)) != 1)
1214 ABORT_ARG_TYPE("Set Tx Power", SIOCSIWTXPOW, args[i]);
1216 /* Check if milliwatt */
1217 ismwatt = (index(args[i], 'm') != NULL);
1220 if(range.txpower_capa & IW_TXPOW_MWATT)
1223 power = iw_dbm2mwatt(power);
1224 wrq.u.data.flags = IW_TXPOW_MWATT;
1229 power = iw_mwatt2dbm(power);
1230 wrq.u.data.flags = IW_TXPOW_DBM;
1232 wrq.u.bitrate.value = power;
1234 /* Check for an additional argument */
1235 if(((i+1) < count) &&
1236 (!strcasecmp(args[i+1], "auto")))
1238 wrq.u.txpower.fixed = 0;
1241 if(((i+1) < count) &&
1242 (!strcasecmp(args[i+1], "fixed")))
1244 wrq.u.txpower.fixed = 1;
1250 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWTXPOW, &wrq,
1256 #if WIRELESS_EXT > 10
1257 /* ---------- Set Retry limit ---------- */
1258 if(!strncmp(args[i], "retry", 3))
1264 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1266 /* Default - nope */
1267 wrq.u.retry.flags = IW_RETRY_LIMIT;
1268 wrq.u.retry.disabled = 0;
1270 /* Check value modifier */
1271 if(!strcasecmp(args[i], "min"))
1273 wrq.u.retry.flags |= IW_RETRY_MIN;
1275 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1278 if(!strcasecmp(args[i], "max"))
1280 wrq.u.retry.flags |= IW_RETRY_MAX;
1282 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1285 /* Check value type */
1286 if(!strcasecmp(args[i], "limit"))
1288 wrq.u.retry.flags |= IW_RETRY_LIMIT;
1290 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1293 if(!strncasecmp(args[i], "lifetime", 4))
1295 wrq.u.retry.flags |= IW_RETRY_LIFETIME;
1297 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1300 /* Is there any value to grab ? */
1301 if(sscanf(args[i], "%lg", &(temp)) == 1)
1303 /* Limit is absolute, on the other hand lifetime is seconds */
1304 if(!(wrq.u.retry.flags & IW_RETRY_LIMIT))
1306 /* Normalise lifetime */
1307 temp *= MEGA; /* default = s */
1308 if(index(args[i], 'u')) temp /= MEGA;
1309 if(index(args[i], 'm')) temp /= KILO;
1311 wrq.u.retry.value = (long) temp;
1317 ABORT_ARG_TYPE("Set Retry Limit", SIOCSIWRETRY, args[i]);
1320 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRETRY, &wrq,
1325 #endif /* WIRELESS_EXT > 10 */
1327 /* ---------- Other ---------- */
1328 /* Here we have an unrecognised arg... */
1329 fprintf(stderr, "Error : unrecognised wireless request \"%s\"\n",
1332 } /* for(index ... */
1336 /******************************* MAIN ********************************/
1338 /*------------------------------------------------------------------*/
1346 int skfd; /* generic raw socket desc. */
1349 /* Create a channel to the NET kernel. */
1350 if((skfd = iw_sockets_open()) < 0)
1356 /* No argument : show the list of all device + info */
1358 iw_enum_devices(skfd, &print_info, NULL, 0);
1360 /* Special case for help... */
1361 if((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")))
1364 /* Special case for version... */
1365 if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))
1366 goterr = iw_print_version_info("iwconfig");
1368 /* The device name must be the first argument */
1370 print_info(skfd, argv[1], NULL, 0);
1372 /* The other args on the line specify options to be set... */
1373 goterr = set_info(skfd, argv + 2, argc - 2, argv[1]);
1375 /* Close the socket. */