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, " [freq N.NNNN[k|M|G]]\n");
28 fprintf(stderr, " [channel N]\n");
29 fprintf(stderr, " [sens N]\n");
30 fprintf(stderr, " [nick N]\n");
31 fprintf(stderr, " [rate {N|auto|fixed}]\n");
32 fprintf(stderr, " [rts {N|auto|fixed|off}]\n");
33 fprintf(stderr, " [frag {N|auto|fixed|off}]\n");
34 fprintf(stderr, " [enc NNNN-NNNN]\n");
35 fprintf(stderr, " [power { period N|timeout N}]\n");
36 fprintf(stderr, " [txpower N {mW|dBm}]\n");
37 fprintf(stderr, " [commit]\n");
41 /************************* DISPLAY ROUTINES **************************/
43 /*------------------------------------------------------------------*/
45 * Get wireless informations & config from the device driver
46 * We will call all the classical wireless ioctl on the driver through
47 * the socket to know what is supported and to get the settings...
52 struct wireless_info * info)
56 memset((char *) info, 0, sizeof(struct wireless_info));
58 /* Get wireless name */
59 if(iw_get_ext(skfd, ifname, SIOCGIWNAME, &wrq) < 0)
61 /* If no wireless name : no wireless extensions */
62 /* But let's check if the interface exists at all */
65 strcpy(ifr.ifr_name, ifname);
66 if(ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
72 strcpy(info->name, wrq.u.name);
75 if(iw_get_range_info(skfd, ifname, &(info->range)) >= 0)
79 if(iw_get_ext(skfd, ifname, SIOCGIWNWID, &wrq) >= 0)
82 memcpy(&(info->nwid), &(wrq.u.nwid), sizeof(iwparam));
85 /* Get frequency / channel */
86 if(iw_get_ext(skfd, ifname, SIOCGIWFREQ, &wrq) >= 0)
89 info->freq = iw_freq2float(&(wrq.u.freq));
93 if(iw_get_ext(skfd, ifname, SIOCGIWSENS, &wrq) >= 0)
96 memcpy(&(info->sens), &(wrq.u.sens), sizeof(iwparam));
99 /* Get encryption information */
100 wrq.u.data.pointer = (caddr_t) info->key;
101 wrq.u.data.length = IW_ENCODING_TOKEN_MAX;
102 wrq.u.data.flags = 0;
103 if(iw_get_ext(skfd, ifname, SIOCGIWENCODE, &wrq) >= 0)
106 info->key_size = wrq.u.data.length;
107 info->key_flags = wrq.u.data.flags;
111 wrq.u.essid.pointer = (caddr_t) info->essid;
112 wrq.u.essid.length = IW_ESSID_MAX_SIZE;
113 wrq.u.essid.flags = 0;
114 if(iw_get_ext(skfd, ifname, SIOCGIWESSID, &wrq) >= 0)
117 info->essid_on = wrq.u.data.flags;
121 if(iw_get_ext(skfd, ifname, SIOCGIWAP, &wrq) >= 0)
123 info->has_ap_addr = 1;
124 memcpy(&(info->ap_addr), &(wrq.u.ap_addr), sizeof (sockaddr));
128 wrq.u.essid.pointer = (caddr_t) info->nickname;
129 wrq.u.essid.length = IW_ESSID_MAX_SIZE;
130 wrq.u.essid.flags = 0;
131 if(iw_get_ext(skfd, ifname, SIOCGIWNICKN, &wrq) >= 0)
132 if(wrq.u.data.length > 1)
133 info->has_nickname = 1;
136 if(iw_get_ext(skfd, ifname, SIOCGIWRATE, &wrq) >= 0)
138 info->has_bitrate = 1;
139 memcpy(&(info->bitrate), &(wrq.u.bitrate), sizeof(iwparam));
142 /* Get RTS threshold */
143 if(iw_get_ext(skfd, ifname, SIOCGIWRTS, &wrq) >= 0)
146 memcpy(&(info->rts), &(wrq.u.rts), sizeof(iwparam));
149 /* Get fragmentation threshold */
150 if(iw_get_ext(skfd, ifname, SIOCGIWFRAG, &wrq) >= 0)
153 memcpy(&(info->frag), &(wrq.u.frag), sizeof(iwparam));
156 /* Get operation mode */
157 if(iw_get_ext(skfd, ifname, SIOCGIWMODE, &wrq) >= 0)
159 info->mode = wrq.u.mode;
160 if((info->mode < IW_NUM_OPER_MODE) && (info->mode >= 0))
164 /* Get Power Management settings */
165 wrq.u.power.flags = 0;
166 if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, &wrq) >= 0)
169 memcpy(&(info->power), &(wrq.u.power), sizeof(iwparam));
173 /* Get Transmit Power */
174 if(iw_get_ext(skfd, ifname, SIOCGIWTXPOW, &wrq) >= 0)
176 info->has_txpower = 1;
177 memcpy(&(info->txpower), &(wrq.u.txpower), sizeof(iwparam));
181 #if WIRELESS_EXT > 10
182 /* Get retry limit/lifetime */
183 if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, &wrq) >= 0)
186 memcpy(&(info->retry), &(wrq.u.retry), sizeof(iwparam));
188 #endif /* WIRELESS_EXT > 10 */
191 if(iw_get_stats(skfd, ifname, &(info->stats)) >= 0)
199 /*------------------------------------------------------------------*/
201 * Print on the screen in a neat fashion all the info we have collected
205 display_info(struct wireless_info * info,
208 char buffer[128]; /* Temporary buffer */
210 /* One token is more of less 5 characters, 14 tokens per line */
211 int tokens = 3; /* For name */
213 /* Display device name and wireless name (name of the protocol used) */
214 printf("%-8.8s %s ", ifname, info->name);
216 /* Display ESSID (extended network), if any */
221 /* Does it have an ESSID index ? */
222 if((info->essid_on & IW_ENCODE_INDEX) > 1)
223 printf("ESSID:\"%s\" [%d] ", info->essid,
224 (info->essid_on & IW_ENCODE_INDEX));
226 printf("ESSID:\"%s\" ", info->essid);
229 printf("ESSID:off/any ");
232 /* Display NickName (station name), if any */
233 if(info->has_nickname)
234 printf("Nickname:\"%s\"", info->nickname);
237 if(info->has_essid || info->has_nickname)
243 /* Display Network ID */
246 /* Note : should display proper number of digit according to info
247 * in range structure */
248 if(info->nwid.disabled)
249 printf("NWID:off/any ");
251 printf("NWID:%X ", info->nwid.value);
255 /* Display the current mode of operation */
258 printf("Mode:%s ", iw_operation_mode[info->mode]);
262 /* Display frequency / channel */
265 iw_print_freq(buffer, info->freq);
266 printf("%s ", buffer);
270 /* Display the address of the current Access Point */
271 if(info->has_ap_addr)
273 /* A bit of clever formatting */
281 /* Oups ! No Access Point in Ad-Hoc mode */
282 if((info->has_mode) && (info->mode == IW_MODE_ADHOC))
285 printf("Access Point:");
286 printf(" %s", iw_pr_ether(buffer, info->ap_addr.sa_data));
289 /* Display the currently used/set bit-rate */
290 if(info->has_bitrate)
292 /* A bit of clever formatting */
301 iw_print_bitrate(buffer, info->bitrate.value);
302 printf("Bit Rate%c%s ", (info->bitrate.fixed ? '=' : ':'), buffer);
306 /* Display the Transmit Power */
307 if(info->has_txpower)
309 /* A bit of clever formatting */
318 if(info->txpower.disabled)
319 printf("Tx-Power:off ");
325 if(info->txpower.fixed)
330 /* Convert everything to dBm */
331 if(info->txpower.flags & IW_TXPOW_MWATT)
332 dbm = iw_mwatt2dbm(info->txpower.value);
334 dbm = info->txpower.value;
337 printf("%d dBm ", dbm);
342 /* Display sensitivity */
345 /* A bit of clever formatting */
355 printf("Sensitivity=");
357 printf("Sensitivity:");
360 /* Display in dBm ? */
361 if(info->sens.value < 0)
362 printf("%d dBm ", info->sens.value);
364 printf("%d/%d ", info->sens.value, info->range.sensitivity);
366 printf("%d ", info->sens.value);
372 #if WIRELESS_EXT > 10
373 /* Display retry limit/lifetime information */
378 if(info->retry.disabled)
382 /* Let's check the value and its type */
383 if(info->retry.flags & IW_RETRY_TYPE)
385 iw_print_retry_value(buffer,
386 info->retry.value, info->retry.flags);
387 printf("%s", buffer);
390 /* Let's check if nothing (simply on) */
391 if(info->retry.flags == IW_RETRY_ON)
395 tokens += 5; /* Between 3 and 5, depend on flags */
397 #endif /* WIRELESS_EXT > 10 */
399 /* Display the RTS threshold */
403 if(info->rts.disabled)
404 printf("RTS thr:off ");
413 printf("%d B ", info->rts.value);
418 /* Display the fragmentation threshold */
421 /* A bit of clever formatting */
430 if(info->frag.disabled)
431 printf("Fragment thr:off");
436 printf("Fragment thr=");
438 printf("Fragment thr:");
440 printf("%d B ", info->frag.value);
448 /* Display encryption information */
449 /* Note : we display only the "current" key, use iwlist to list all keys */
452 printf("Encryption key:");
453 if((info->key_flags & IW_ENCODE_DISABLED) || (info->key_size == 0))
457 /* Display the key */
458 iw_print_key(buffer, info->key, info->key_size, info->key_flags);
459 printf("%s", buffer);
462 if((info->key_flags & IW_ENCODE_INDEX) > 1)
463 printf(" [%d]", info->key_flags & IW_ENCODE_INDEX);
464 if(info->key_flags & IW_ENCODE_RESTRICTED)
465 printf(" Encryption mode:restricted");
466 if(info->key_flags & IW_ENCODE_OPEN)
467 printf(" Encryption mode:open");
472 /* Display Power Management information */
473 /* Note : we display only one parameter, period or timeout. If a device
474 * (such as HiperLan) has both, the user need to use iwlist... */
475 if(info->has_power) /* I hope the device has power ;-) */
477 printf("Power Management");
479 if(info->power.disabled)
483 /* Let's check the value and its type */
484 if(info->power.flags & IW_POWER_TYPE)
486 iw_print_pm_value(buffer, info->power.value, info->power.flags);
487 printf("%s ", buffer);
490 /* Let's check the mode */
491 iw_print_pm_mode(buffer, info->power.flags);
492 printf("%s", buffer);
494 /* Let's check if nothing (simply on) */
495 if(info->power.flags == IW_POWER_ON)
501 /* Display statistics */
504 info->stats.qual.updated = 0x0; /* Not that reliable, disable */
505 iw_print_stats(buffer, &info->stats.qual, &info->range, info->has_range);
506 printf("Link %s\n", buffer);
508 #if WIRELESS_EXT > 11
509 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",
510 info->stats.discard.nwid,
511 info->stats.discard.code,
512 info->stats.discard.fragment,
513 info->stats.discard.retries,
514 info->stats.discard.misc,
515 info->stats.miss.beacon);
516 #else /* WIRELESS_EXT > 11 */
517 printf(" Rx invalid nwid:%d invalid crypt:%d invalid misc:%d\n",
518 info->stats.discard.nwid,
519 info->stats.discard.code,
520 info->stats.discard.misc);
521 #endif /* WIRELESS_EXT > 11 */
527 /*------------------------------------------------------------------*/
529 * Print on the screen in a neat fashion all the info we have collected
538 struct wireless_info info;
541 /* Avoid "Unused parameter" warning */
542 args = args; count = count;
544 rc = get_info(skfd, ifname, &info);
547 case 0: /* Success */
549 display_info(&info, ifname);
553 fprintf(stderr, "%-8.8s no wireless extensions.\n\n",
558 fprintf(stderr, "%-8.8s %s\n\n", ifname, strerror(-rc));
563 /************************* SETTING ROUTINES **************************/
565 /*------------------------------------------------------------------*/
567 * Macro to handle errors when setting WE
568 * Print a nice error message and exit...
569 * We define them as macro so that "return" do the right thing.
570 * The "do {...} while(0)" is a standard trick
572 #define ERR_SET_EXT(rname, request) \
573 fprintf(stderr, "Error for wireless request \"%s\" (%X) :\n", \
576 #define ABORT_ARG_NUM(rname, request) \
578 ERR_SET_EXT(rname, request); \
579 fprintf(stderr, " too few arguments.\n"); \
583 #define ABORT_ARG_TYPE(rname, request, arg) \
585 ERR_SET_EXT(rname, request); \
586 fprintf(stderr, " invalid argument \"%s\".\n", arg); \
590 #define ABORT_ARG_SIZE(rname, request, max) \
592 ERR_SET_EXT(rname, request); \
593 fprintf(stderr, " argument too big (max %d)\n", max); \
597 /*------------------------------------------------------------------*/
599 * Wrapper to push some Wireless Parameter in the driver
600 * Use standard wrapper and add pretty error message if fail...
602 #define IW_SET_EXT_ERR(skfd, ifname, request, wrq, rname) \
604 if(iw_set_ext(skfd, ifname, request, wrq) < 0) { \
605 ERR_SET_EXT(rname, request); \
606 fprintf(stderr, " SET failed on device %-1.8s ; %s.\n", \
607 ifname, strerror(errno)); \
611 /*------------------------------------------------------------------*/
613 * Wrapper to extract some Wireless Parameter out of the driver
614 * Use standard wrapper and add pretty error message if fail...
616 #define IW_GET_EXT_ERR(skfd, ifname, request, wrq, rname) \
618 if(iw_get_ext(skfd, ifname, request, wrq) < 0) { \
619 ERR_SET_EXT(rname, request); \
620 fprintf(stderr, " GET failed on device %-1.8s ; %s.\n", \
621 ifname, strerror(errno)); \
625 /*------------------------------------------------------------------*/
627 * Set the wireless options requested on command line
628 * This function is too long and probably should be split,
629 * because it look like the perfect definition of spaghetti code,
630 * but I'm way to lazy
633 set_info(int skfd, /* The socket */
634 char * args[], /* Command line args */
635 int count, /* Args count */
636 char * ifname) /* Dev name */
641 /* if nothing after the device name - will never happen */
644 fprintf(stderr, "Error : too few arguments.\n");
648 /* The other args on the line specify options to be set... */
649 for(i = 0; i < count; i++)
651 /* ---------- Commit changes to driver ---------- */
652 if(!strncmp(args[i], "commit", 6))
655 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWCOMMIT, &wrq,
660 /* ---------- Set network ID ---------- */
661 if((!strcasecmp(args[i], "nwid")) ||
662 (!strcasecmp(args[i], "domain")))
666 ABORT_ARG_NUM("Set NWID", SIOCSIWNWID);
667 if((!strcasecmp(args[i], "off")) ||
668 (!strcasecmp(args[i], "any")))
669 wrq.u.nwid.disabled = 1;
671 if(!strcasecmp(args[i], "on"))
674 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWNWID, &wrq,
676 wrq.u.nwid.disabled = 0;
679 if(sscanf(args[i], "%lX", (unsigned long *) &(wrq.u.nwid.value))
681 ABORT_ARG_TYPE("Set NWID", SIOCSIWNWID, args[i]);
683 wrq.u.nwid.disabled = 0;
684 wrq.u.nwid.fixed = 1;
687 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWNWID, &wrq,
692 /* ---------- Set frequency / channel ---------- */
693 if((!strncmp(args[i], "freq", 4)) ||
694 (!strcmp(args[i], "channel")))
699 ABORT_ARG_NUM("Set Frequency", SIOCSIWFREQ);
700 if(sscanf(args[i], "%lg", &(freq)) != 1)
701 ABORT_ARG_TYPE("Set Frequency", SIOCSIWFREQ, args[i]);
702 if(index(args[i], 'G')) freq *= GIGA;
703 if(index(args[i], 'M')) freq *= MEGA;
704 if(index(args[i], 'k')) freq *= KILO;
706 iw_float2freq(freq, &(wrq.u.freq));
708 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFREQ, &wrq,
713 /* ---------- Set sensitivity ---------- */
714 if(!strncmp(args[i], "sens", 4))
717 ABORT_ARG_NUM("Set Sensitivity", SIOCSIWSENS);
718 if(sscanf(args[i], "%d", &(wrq.u.sens.value)) != 1)
719 ABORT_ARG_TYPE("Set Sensitivity", SIOCSIWSENS, args[i]);
721 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWSENS, &wrq,
726 /* ---------- Set encryption stuff ---------- */
727 if((!strncmp(args[i], "enc", 3)) ||
728 (!strcmp(args[i], "key")))
730 unsigned char key[IW_ENCODING_TOKEN_MAX];
733 ABORT_ARG_NUM("Set Encode", SIOCSIWENCODE);
735 if(!strcasecmp(args[i], "on"))
737 /* Get old encryption information */
738 wrq.u.data.pointer = (caddr_t) key;
739 wrq.u.data.length = 0;
740 wrq.u.data.flags = 0;
741 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWENCODE, &wrq,
743 wrq.u.data.flags &= ~IW_ENCODE_DISABLED; /* Enable */
751 wrq.u.data.pointer = (caddr_t) NULL;
752 wrq.u.data.flags = 0;
753 wrq.u.data.length = 0;
755 /* -- Check for the key -- */
756 keylen = iw_in_key(args[i], key);
759 wrq.u.data.length = keylen;
760 wrq.u.data.pointer = (caddr_t) key;
765 /* -- Check for token index -- */
767 (sscanf(args[i], "[%d]", &temp) == 1) &&
768 (temp > 0) && (temp < IW_ENCODE_INDEX))
770 wrq.u.encoding.flags |= temp;
775 /* -- Check the various flags -- */
778 if(!strcasecmp(args[i], "off"))
779 wrq.u.data.flags |= IW_ENCODE_DISABLED;
780 if(!strcasecmp(args[i], "open"))
781 wrq.u.data.flags |= IW_ENCODE_OPEN;
782 if(!strncasecmp(args[i], "restricted", 5))
783 wrq.u.data.flags |= IW_ENCODE_RESTRICTED;
784 if(wrq.u.data.flags & IW_ENCODE_FLAGS)
790 /* Pointer is absent in new API */
791 if(wrq.u.data.pointer == NULL)
792 wrq.u.data.flags |= IW_ENCODE_NOKEY;
795 ABORT_ARG_TYPE("Set Encode", SIOCSIWENCODE, args[i]);
799 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWENCODE, &wrq,
804 /* ---------- Set ESSID ---------- */
805 if(!strcasecmp(args[i], "essid"))
807 char essid[IW_ESSID_MAX_SIZE + 1];
811 ABORT_ARG_NUM("Set ESSID", SIOCSIWESSID);
812 if((!strcasecmp(args[i], "off")) ||
813 (!strcasecmp(args[i], "any")))
815 wrq.u.essid.flags = 0;
819 if(!strcasecmp(args[i], "on"))
822 wrq.u.essid.pointer = (caddr_t) essid;
823 wrq.u.essid.length = 0;
824 wrq.u.essid.flags = 0;
825 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWESSID, &wrq,
827 wrq.u.essid.flags = 1;
830 /* Check the size of what the user passed us to avoid
831 * buffer overflows */
832 if(strlen(args[i]) > IW_ESSID_MAX_SIZE)
833 ABORT_ARG_SIZE("Set ESSID", SIOCSIWESSID, IW_ESSID_MAX_SIZE);
838 wrq.u.essid.flags = 1;
839 strcpy(essid, args[i]); /* Size checked, all clear */
841 /* Check for ESSID index */
842 if(((i+1) < count) &&
843 (sscanf(args[i+1], "[%d]", &temp) == 1) &&
844 (temp > 0) && (temp < IW_ENCODE_INDEX))
846 wrq.u.essid.flags = temp;
851 wrq.u.essid.pointer = (caddr_t) essid;
852 wrq.u.essid.length = strlen(essid) + 1;
853 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWESSID, &wrq,
858 /* ---------- Set AP address ---------- */
859 if(!strcasecmp(args[i], "ap"))
862 ABORT_ARG_NUM("Set AP Address", SIOCSIWAP);
864 if((!strcasecmp(args[i], "auto")) ||
865 (!strcasecmp(args[i], "any")))
867 /* Send a broadcast address */
868 iw_broad_ether(&(wrq.u.ap_addr));
872 if(!strcasecmp(args[i], "off"))
874 /* Send a NULL address */
875 iw_null_ether(&(wrq.u.ap_addr));
879 /* Get the address and check if the interface supports it */
880 if(iw_in_addr(skfd, ifname, args[i++], &(wrq.u.ap_addr)) < 0)
881 ABORT_ARG_TYPE("Set AP Address", SIOCSIWAP, args[i-1]);
885 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWAP, &wrq,
890 /* ---------- Set NickName ---------- */
891 if(!strncmp(args[i], "nick", 4))
895 ABORT_ARG_NUM("Set Nickname", SIOCSIWNICKN);
896 if(strlen(args[i]) > IW_ESSID_MAX_SIZE)
897 ABORT_ARG_SIZE("Set Nickname", SIOCSIWNICKN, IW_ESSID_MAX_SIZE);
899 wrq.u.essid.pointer = (caddr_t) args[i];
900 wrq.u.essid.length = strlen(args[i]) + 1;
901 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWNICKN, &wrq,
906 /* ---------- Set Bit-Rate ---------- */
907 if((!strncmp(args[i], "bit", 3)) ||
908 (!strcmp(args[i], "rate")))
911 ABORT_ARG_NUM("Set Bit Rate", SIOCSIWRATE);
912 if(!strcasecmp(args[i], "auto"))
914 wrq.u.bitrate.value = -1;
915 wrq.u.bitrate.fixed = 0;
919 if(!strcasecmp(args[i], "fixed"))
921 /* Get old bitrate */
922 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWRATE, &wrq,
924 wrq.u.bitrate.fixed = 1;
926 else /* Should be a numeric value */
930 if(sscanf(args[i], "%lg", &(brate)) != 1)
931 ABORT_ARG_TYPE("Set Bit Rate", SIOCSIWRATE, args[i]);
932 if(index(args[i], 'G')) brate *= GIGA;
933 if(index(args[i], 'M')) brate *= MEGA;
934 if(index(args[i], 'k')) brate *= KILO;
935 wrq.u.bitrate.value = (long) brate;
936 wrq.u.bitrate.fixed = 1;
938 /* Check for an additional argument */
939 if(((i+1) < count) &&
940 (!strcasecmp(args[i+1], "auto")))
942 wrq.u.bitrate.fixed = 0;
945 if(((i+1) < count) &&
946 (!strcasecmp(args[i+1], "fixed")))
948 wrq.u.bitrate.fixed = 1;
954 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRATE, &wrq,
959 /* ---------- Set RTS threshold ---------- */
960 if(!strncasecmp(args[i], "rts", 3))
964 ABORT_ARG_NUM("Set RTS Threshold", SIOCSIWRTS);
965 wrq.u.rts.value = -1;
967 wrq.u.rts.disabled = 0;
968 if(!strcasecmp(args[i], "off"))
969 wrq.u.rts.disabled = 1; /* i.e. max size */
971 if(!strcasecmp(args[i], "auto"))
975 if(!strcasecmp(args[i], "fixed"))
977 /* Get old RTS threshold */
978 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWRTS, &wrq,
979 "Set RTS Threshold");
982 else /* Should be a numeric value */
983 if(sscanf(args[i], "%ld", (unsigned long *) &(wrq.u.rts.value))
985 ABORT_ARG_TYPE("Set RTS Threshold", SIOCSIWRTS, args[i]);
988 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRTS, &wrq,
989 "Set RTS Threshold");
993 /* ---------- Set fragmentation threshold ---------- */
994 if(!strncmp(args[i], "frag", 4))
998 ABORT_ARG_NUM("Set Fragmentation Threshold", SIOCSIWFRAG);
999 wrq.u.frag.value = -1;
1000 wrq.u.frag.fixed = 1;
1001 wrq.u.frag.disabled = 0;
1002 if(!strcasecmp(args[i], "off"))
1003 wrq.u.frag.disabled = 1; /* i.e. max size */
1005 if(!strcasecmp(args[i], "auto"))
1006 wrq.u.frag.fixed = 0;
1009 if(!strcasecmp(args[i], "fixed"))
1011 /* Get old fragmentation threshold */
1012 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWFRAG, &wrq,
1013 "Set Fragmentation Threshold");
1014 wrq.u.frag.fixed = 1;
1016 else /* Should be a numeric value */
1017 if(sscanf(args[i], "%ld",
1018 (unsigned long *) &(wrq.u.frag.value))
1020 ABORT_ARG_TYPE("Set Fragmentation Threshold", SIOCSIWFRAG,
1024 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFRAG, &wrq,
1025 "Set Fragmentation Threshold");
1029 /* ---------- Set operation mode ---------- */
1030 if(!strcmp(args[i], "mode"))
1036 ABORT_ARG_NUM("Set Mode", SIOCSIWMODE);
1038 if(sscanf(args[i], "%d", &k) != 1)
1041 while((k < IW_NUM_OPER_MODE) &&
1042 strncasecmp(args[i], iw_operation_mode[k], 3))
1045 if((k >= IW_NUM_OPER_MODE) || (k < 0))
1046 ABORT_ARG_TYPE("Set Mode", SIOCSIWMODE, args[i]);
1049 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWMODE, &wrq,
1054 /* ---------- Set Power Management ---------- */
1055 if(!strncmp(args[i], "power", 3))
1058 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1060 if(!strcasecmp(args[i], "off"))
1061 wrq.u.power.disabled = 1; /* i.e. max size */
1063 if(!strcasecmp(args[i], "on"))
1065 /* Get old Power info */
1066 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWPOWER, &wrq,
1067 "Set Power Management");
1068 wrq.u.power.disabled = 0;
1074 /* Default - nope */
1075 wrq.u.power.flags = IW_POWER_ON;
1076 wrq.u.power.disabled = 0;
1078 /* Check value modifier */
1079 if(!strcasecmp(args[i], "min"))
1081 wrq.u.power.flags |= IW_POWER_MIN;
1083 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1086 if(!strcasecmp(args[i], "max"))
1088 wrq.u.power.flags |= IW_POWER_MAX;
1090 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1093 /* Check value type */
1094 if(!strcasecmp(args[i], "period"))
1096 wrq.u.power.flags |= IW_POWER_PERIOD;
1098 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1101 if(!strcasecmp(args[i], "timeout"))
1103 wrq.u.power.flags |= IW_POWER_TIMEOUT;
1105 ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
1108 /* Is there any value to grab ? */
1109 if(sscanf(args[i], "%lg", &(temp)) == 1)
1111 temp *= MEGA; /* default = s */
1112 if(index(args[i], 'u')) temp /= MEGA;
1113 if(index(args[i], 'm')) temp /= KILO;
1114 wrq.u.power.value = (long) temp;
1115 if((wrq.u.power.flags & IW_POWER_TYPE) == 0)
1116 wrq.u.power.flags |= IW_POWER_PERIOD;
1121 /* Now, check the mode */
1124 if(!strcasecmp(args[i], "all"))
1125 wrq.u.power.flags |= IW_POWER_ALL_R;
1126 if(!strncasecmp(args[i], "unicast", 4))
1127 wrq.u.power.flags |= IW_POWER_UNICAST_R;
1128 if(!strncasecmp(args[i], "multicast", 5))
1129 wrq.u.power.flags |= IW_POWER_MULTICAST_R;
1130 if(!strncasecmp(args[i], "force", 5))
1131 wrq.u.power.flags |= IW_POWER_FORCE_S;
1132 if(!strcasecmp(args[i], "repeat"))
1133 wrq.u.power.flags |= IW_POWER_REPEATER;
1134 if(wrq.u.power.flags & IW_POWER_MODE)
1141 ABORT_ARG_TYPE("Set Power Management", SIOCSIWPOWER,
1146 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWPOWER, &wrq,
1147 "Set Power Management");
1151 #if WIRELESS_EXT > 9
1152 /* ---------- Set Transmit-Power ---------- */
1153 if(!strncmp(args[i], "txpower", 3))
1155 struct iw_range range;
1158 ABORT_ARG_NUM("Set Tx Power", SIOCSIWTXPOW);
1160 /* Extract range info */
1161 if(iw_get_range_info(skfd, ifname, &range) < 0)
1162 memset(&range, 0, sizeof(range));
1164 /* Prepare the request */
1165 wrq.u.txpower.value = -1;
1166 wrq.u.txpower.fixed = 1;
1167 wrq.u.txpower.disabled = 0;
1168 wrq.u.data.flags = IW_TXPOW_DBM;
1169 if(!strcasecmp(args[i], "off"))
1170 wrq.u.txpower.disabled = 1; /* i.e. turn radio off */
1172 if(!strcasecmp(args[i], "auto"))
1173 wrq.u.txpower.fixed = 0; /* i.e. use power control */
1176 if(!strcasecmp(args[i], "fixed"))
1178 /* Get old tx-power */
1179 IW_GET_EXT_ERR(skfd, ifname, SIOCGIWTXPOW, &wrq,
1181 wrq.u.txpower.fixed = 1;
1183 else /* Should be a numeric value */
1189 if(sscanf(args[i], "%ld",
1190 (unsigned long *) &(power)) != 1)
1191 ABORT_ARG_TYPE("Set Tx Power", SIOCSIWTXPOW, args[i]);
1193 /* Check if milliwatt */
1194 ismwatt = (index(args[i], 'm') != NULL);
1197 if(range.txpower_capa & IW_TXPOW_MWATT)
1200 power = iw_dbm2mwatt(power);
1201 wrq.u.data.flags = IW_TXPOW_MWATT;
1206 power = iw_mwatt2dbm(power);
1207 wrq.u.data.flags = IW_TXPOW_DBM;
1209 wrq.u.bitrate.value = power;
1211 /* Check for an additional argument */
1212 if(((i+1) < count) &&
1213 (!strcasecmp(args[i+1], "auto")))
1215 wrq.u.txpower.fixed = 0;
1218 if(((i+1) < count) &&
1219 (!strcasecmp(args[i+1], "fixed")))
1221 wrq.u.txpower.fixed = 1;
1227 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWTXPOW, &wrq,
1233 #if WIRELESS_EXT > 10
1234 /* ---------- Set Retry limit ---------- */
1235 if(!strncmp(args[i], "retry", 3))
1241 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1243 /* Default - nope */
1244 wrq.u.retry.flags = IW_RETRY_LIMIT;
1245 wrq.u.retry.disabled = 0;
1247 /* Check value modifier */
1248 if(!strcasecmp(args[i], "min"))
1250 wrq.u.retry.flags |= IW_RETRY_MIN;
1252 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1255 if(!strcasecmp(args[i], "max"))
1257 wrq.u.retry.flags |= IW_RETRY_MAX;
1259 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1262 /* Check value type */
1263 if(!strcasecmp(args[i], "limit"))
1265 wrq.u.retry.flags |= IW_RETRY_LIMIT;
1267 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1270 if(!strncasecmp(args[i], "lifetime", 4))
1272 wrq.u.retry.flags |= IW_RETRY_LIFETIME;
1274 ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
1277 /* Is there any value to grab ? */
1278 if(sscanf(args[i], "%lg", &(temp)) == 1)
1280 /* Limit is absolute, on the other hand lifetime is seconds */
1281 if(!(wrq.u.retry.flags & IW_RETRY_LIMIT))
1283 /* Normalise lifetime */
1284 temp *= MEGA; /* default = s */
1285 if(index(args[i], 'u')) temp /= MEGA;
1286 if(index(args[i], 'm')) temp /= KILO;
1288 wrq.u.retry.value = (long) temp;
1294 ABORT_ARG_TYPE("Set Retry Limit", SIOCSIWRETRY, args[i]);
1297 IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRETRY, &wrq,
1302 #endif /* WIRELESS_EXT > 10 */
1304 /* ---------- Other ---------- */
1305 /* Here we have an unrecognised arg... */
1306 fprintf(stderr, "Error : unrecognised wireless request \"%s\"\n",
1309 } /* for(index ... */
1313 /******************************* MAIN ********************************/
1315 /*------------------------------------------------------------------*/
1323 int skfd; /* generic raw socket desc. */
1326 /* Create a channel to the NET kernel. */
1327 if((skfd = iw_sockets_open()) < 0)
1333 /* No argument : show the list of all device + info */
1335 iw_enum_devices(skfd, &print_info, NULL, 0);
1337 /* Special case for help... */
1338 if((!strncmp(argv[1], "-h", 9)) ||
1339 (!strcmp(argv[1], "--help")))
1342 /* The device name must be the first argument */
1344 print_info(skfd, argv[1], NULL, 0);
1346 /* The other args on the line specify options to be set... */
1347 goterr = set_info(skfd, argv + 2, argc - 2, argv[1]);
1349 /* Close the socket. */