6 * Main code for "iwconfig". This is the generic tool for most
8 * You need to link this code against "iwcommon.c" and "-lm".
11 #include "iwcommon.h" /* Header */
13 /**************************** VARIABLES ****************************/
14 char * operation_mode[] = { "Auto",
21 /************************* MISC SUBROUTINES **************************/
23 /*------------------------------------------------------------------*/
30 fprintf(stderr, "Usage: iwconfig interface [essid {NN|on|off}]\n");
31 fprintf(stderr, " [nwid {NN|on|off}]\n");
32 fprintf(stderr, " [freq N.NNNN[k|M|G]]\n");
33 fprintf(stderr, " [channel N]\n");
34 fprintf(stderr, " [sens N]\n");
35 fprintf(stderr, " [nick N]\n");
36 fprintf(stderr, " [rate {N|auto|fixed}]\n");
37 fprintf(stderr, " [rts {N|auto|fixed|off}]\n");
38 fprintf(stderr, " [frag {N|auto|fixed|off}]\n");
39 fprintf(stderr, " [enc NNNN-NNNN]\n");
44 /************************* DISPLAY ROUTINES **************************/
46 /*------------------------------------------------------------------*/
48 * Read /proc/net/wireless to get the latest statistics
51 iw_getstats(char * ifname,
54 FILE * f=fopen("/proc/net/wireless","r");
60 /* Loop on all devices */
61 while(fgets(buf,255,f))
64 while(*bp&&isspace(*bp))
66 /* Is it the good device ? */
67 if(strncmp(bp,ifname,strlen(ifname))==0 && bp[strlen(ifname)]==':')
75 stats->status = (unsigned short) t;
76 /* -- link quality -- */
77 bp = strtok(NULL, " ");
78 if(strchr(bp,'.') != NULL)
79 stats->qual.updated |= 1;
81 stats->qual.qual = (unsigned char) t;
82 /* -- signal level -- */
83 bp = strtok(NULL, " ");
84 if(strchr(bp,'.') != NULL)
85 stats->qual.updated |= 2;
87 stats->qual.level = (unsigned char) t;
88 /* -- noise level -- */
89 bp = strtok(NULL, " ");
90 if(strchr(bp,'.') != NULL)
91 stats->qual.updated += 4;
93 stats->qual.noise = (unsigned char) t;
94 /* -- discarded packets -- */
95 bp = strtok(NULL, " ");
96 sscanf(bp, "%d", &stats->discard.nwid);
97 bp = strtok(NULL, " ");
98 sscanf(bp, "%d", &stats->discard.code);
99 bp = strtok(NULL, " ");
100 sscanf(bp, "%d", &stats->discard.misc);
109 /*------------------------------------------------------------------*/
111 * Get wireless informations & config from the device driver
112 * We will call all the classical wireless ioctl on the driver through
113 * the socket to know what is supported and to get the settings...
118 struct wireless_info * info)
122 memset((char *) info, 0, sizeof(struct wireless_info));
124 /* Get wireless name */
125 strcpy(wrq.ifr_name, ifname);
126 if(ioctl(skfd, SIOCGIWNAME, &wrq) < 0)
127 /* If no wireless name : no wireless extensions */
130 strcpy(info->name, wrq.u.name);
133 strcpy(wrq.ifr_name, ifname);
134 if(ioctl(skfd, SIOCGIWNWID, &wrq) >= 0)
137 memcpy(&(info->nwid), &(wrq.u.nwid), sizeof(iwparam));
140 /* Get frequency / channel */
141 strcpy(wrq.ifr_name, ifname);
142 if(ioctl(skfd, SIOCGIWFREQ, &wrq) >= 0)
145 info->freq = freq2float(&(wrq.u.freq));
148 /* Get sensitivity */
149 strcpy(wrq.ifr_name, ifname);
150 if(ioctl(skfd, SIOCGIWSENS, &wrq) >= 0)
153 memcpy(&(info->sens), &(wrq.u.sens), sizeof(iwparam));
156 /* Get encryption information */
157 strcpy(wrq.ifr_name, ifname);
158 wrq.u.data.pointer = (caddr_t) info->key;
159 wrq.u.data.length = 0;
160 wrq.u.data.flags = 0;
161 if(ioctl(skfd, SIOCGIWENCODE, &wrq) >= 0)
164 info->key_size = wrq.u.data.length;
165 info->key_flags = wrq.u.data.flags;
169 strcpy(wrq.ifr_name, ifname);
170 wrq.u.essid.pointer = (caddr_t) info->essid;
171 wrq.u.essid.length = 0;
172 wrq.u.essid.flags = 0;
173 if(ioctl(skfd, SIOCGIWESSID, &wrq) >= 0)
176 info->essid_on = wrq.u.data.flags;
180 strcpy(wrq.ifr_name, ifname);
181 if(ioctl(skfd, SIOCGIWAP, &wrq) >= 0)
183 info->has_ap_addr = 1;
184 memcpy(&(info->ap_addr), &(wrq.u.ap_addr), sizeof (sockaddr));
188 strcpy(wrq.ifr_name, ifname);
189 wrq.u.essid.pointer = (caddr_t) info->nickname;
190 wrq.u.essid.length = 0;
191 wrq.u.essid.flags = 0;
192 if(ioctl(skfd, SIOCGIWNICKN, &wrq) >= 0)
193 if(wrq.u.data.length > 1)
194 info->has_nickname = 1;
197 strcpy(wrq.ifr_name, ifname);
198 if(ioctl(skfd, SIOCGIWRATE, &wrq) >= 0)
200 info->has_bitrate = 1;
201 memcpy(&(info->bitrate), &(wrq.u.bitrate), sizeof(iwparam));
204 /* Get RTS threshold */
205 strcpy(wrq.ifr_name, ifname);
206 if(ioctl(skfd, SIOCGIWRTS, &wrq) >= 0)
209 memcpy(&(info->rts), &(wrq.u.rts), sizeof(iwparam));
212 /* Get fragmentation threshold */
213 strcpy(wrq.ifr_name, ifname);
214 if(ioctl(skfd, SIOCGIWFRAG, &wrq) >= 0)
217 memcpy(&(info->frag), &(wrq.u.frag), sizeof(iwparam));
220 /* Get operation mode */
221 strcpy(wrq.ifr_name, ifname);
222 if(ioctl(skfd, SIOCGIWMODE, &wrq) >= 0)
224 if((wrq.u.mode < 6) && (wrq.u.mode >= 0))
226 info->mode = wrq.u.mode;
229 /* Get Power Management settings */
230 strcpy(wrq.ifr_name, ifname);
231 if(ioctl(skfd, SIOCGIWPOWER, &wrq) >= 0)
234 memcpy(&(info->power), &(wrq.u.power), sizeof(iwparam));
238 if(iw_getstats(ifname, &(info->stats)) >= 0)
244 if(get_range_info(skfd, ifname, &(info->range)) >= 0)
250 /*------------------------------------------------------------------*/
252 * Print on the screen in a neat fashion all the info we have collected
256 display_info(struct wireless_info * info,
259 /* Display device name and wireless name (name of the protocol used) */
260 printf("%-8.8s %s ", ifname, info->name);
262 /* Display ESSID (extended network), if any */
266 printf("ESSID:\"%s\" ", info->essid);
268 printf("ESSID:off ");
271 /* Display NickName (station name), if any */
272 if(info->has_nickname)
273 printf("Nickname:\"%s\"", info->nickname);
276 if(info->has_essid || info->has_nickname)
279 /* Display Network ID */
282 /* Note : should display right number of digit according to info
283 * in range structure */
284 if(info->nwid.disabled)
285 printf("NWID:off/any ");
287 printf("NWID:%X ", info->nwid.value);
290 /* Display frequency / channel */
293 if(info->freq < KILO)
294 printf("Channel:%g ", info->freq);
297 if(info->freq >= GIGA)
298 printf("Frequency:%gGHz ", info->freq / GIGA);
301 if(info->freq >= MEGA)
302 printf("Frequency:%gMHz ", info->freq / MEGA);
304 printf("Frequency:%gkHz ", info->freq / KILO);
309 /* Display sensitivity */
314 printf("Sensitivity=");
316 printf("Sensitivity:");
319 /* Display in dBm ? */
320 if(info->sens.value < 0)
321 printf("%d dBm ", info->sens.value);
323 printf("%d/%d ", info->sens.value, info->range.sensitivity);
325 printf("%d ", info->sens.value);
328 /* Display the current mode of operation */
331 /* A bit of clever formatting */
332 if((info->has_nwid + 2*info->has_freq + 2*info->has_sens
333 + !info->has_essid) > 4)
336 printf("Mode:%s ", operation_mode[info->mode]);
339 /* Display the address of the current Access Point */
340 if(info->has_ap_addr)
342 /* A bit of clever formatting */
343 if((info->has_nwid + 2*info->has_freq + 2*info->has_sens
344 + info->has_mode + !info->has_essid) > 3)
347 printf("Access Point: %s", pr_ether(info->ap_addr.sa_data));
352 /* Display the currently used/set bit-rate */
353 if(info->has_bitrate)
356 if(info->bitrate.fixed)
361 if(info->bitrate.value >= GIGA)
362 printf("%gGb/s", info->bitrate.value / GIGA);
364 if(info->bitrate.value >= MEGA)
365 printf("%gMb/s", info->bitrate.value / MEGA);
367 printf("%gkb/s", info->bitrate.value / KILO);
371 /* Display the RTS threshold */
375 if(info->rts.disabled)
376 printf("RTS thr:off ");
385 printf("%d B ", info->rts.value);
389 /* Display the fragmentation threshold */
393 if(info->frag.disabled)
394 printf("Fragment thr:off ");
399 printf("Fragment thr=");
401 printf("Fragment thr:");
403 printf("%d B ", info->frag.value);
408 if((info->has_bitrate) || (info->has_rts) || (info->has_bitrate))
411 /* Display encryption information */
412 /* Note : we display only the "current" key, use iwspy to list all keys */
415 printf("Encryption key:");
416 if((info->key_flags & IW_ENCODE_DISABLED) || (info->key_size == 0))
422 printf("%.2X", info->key[0]);
423 for(i = 1; i < info->key_size; i++)
427 printf("%.2X", info->key[i]);
431 if((info->key_flags & IW_ENCODE_INDEX) > 1)
432 printf(" [%d]", info->key_flags & IW_ENCODE_INDEX);
433 if(info->key_flags & IW_ENCODE_RESTRICTED)
434 printf(" Encryption mode:restricted");
435 if(info->key_flags & IW_ENCODE_OPEN)
436 printf(" Encryption mode:open");
441 /* Display Power Management information */
442 /* Note : we display only one parameter, period or timeout. If a device
443 * (such as HiperLan) has both, we would need to be a bit more clever... */
444 if(info->has_power) /* I hope the device has power ;-) */
446 printf("Power Management");
448 if(info->power.disabled)
452 /* Let's check the value and its type */
453 if(info->power.flags & IW_POWER_TYPE)
456 if(info->power.flags & IW_POWER_TIMEOUT)
461 /* Display value with units */
462 if(info->power.value >= (int) MEGA)
463 printf("%gs ", ((double) info->power.value) / MEGA);
465 if(info->power.value >= (int) KILO)
466 printf("%gms ", ((double) info->power.value) / KILO);
468 printf("%dus ", info->power.value);
471 /* Let's check the mode */
472 switch(info->power.flags & IW_POWER_MODE)
474 case IW_POWER_UNICAST_R:
475 printf(" mode:Unicast received");
477 case IW_POWER_MULTICAST_R:
478 printf(" mode:Multicast received");
481 printf(" mode:All packets received");
483 case IW_POWER_FORCE_S:
484 printf(" mode:Force sending");
486 case IW_POWER_REPEATER:
487 printf(" mode:Repeat multicasts");
492 /* Let's check if nothing (simply on) */
493 if(info->power.flags == IW_POWER_ON)
501 if(info->has_range && (info->stats.qual.level != 0))
502 /* If the statistics are in dBm */
503 if(info->stats.qual.level > info->range.max_qual.level)
504 printf("Link quality:%d/%d Signal level:%d dBm Noise level:%d dBm\n",
505 info->stats.qual.qual, info->range.max_qual.qual,
506 info->stats.qual.level - 0x100,
507 info->stats.qual.noise - 0x100);
509 /* Statistics are relative values (0 -> max) */
510 printf("Link quality:%d/%d Signal level:%d/%d Noise level:%d/%d\n",
511 info->stats.qual.qual, info->range.max_qual.qual,
512 info->stats.qual.level, info->range.max_qual.level,
513 info->stats.qual.noise, info->range.max_qual.noise);
515 /* We can't read the range, so we don't know... */
516 printf("Link quality:%d Signal level:%d Noise level:%d\n",
517 info->stats.qual.qual,
518 info->stats.qual.level,
519 info->stats.qual.noise);
521 printf(" Rx invalid nwid:%d invalid crypt:%d invalid misc:%d\n",
522 info->stats.discard.nwid,
523 info->stats.discard.code,
524 info->stats.discard.misc);
530 /*------------------------------------------------------------------*/
532 * Print on the screen in a neat fashion all the info we have collected
539 struct wireless_info info;
541 if(get_info(skfd, ifname, &info) < 0)
543 fprintf(stderr, "%-8.8s no wireless extensions.\n\n",
549 display_info(&info, ifname);
552 /*------------------------------------------------------------------*/
554 * Get info on all devices and print it on the screen
557 print_devices(int skfd)
564 /* Get list of active devices */
565 ifc.ifc_len = sizeof(buff);
567 if(ioctl(skfd, SIOCGIFCONF, &ifc) < 0)
569 fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno));
575 for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++)
576 print_info(skfd, ifr->ifr_name);
579 /************************* SETTING ROUTINES **************************/
581 /*------------------------------------------------------------------*/
583 * Set the wireless options requested on command line
584 * This function is too long and probably should be split,
585 * because it look like the perfect definition of spaghetti code,
586 * but I'm way to lazy
589 set_info(int skfd, /* The socket */
590 char * args[], /* Command line args */
591 int count, /* Args count */
592 char * ifname) /* Dev name */
598 strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
600 /* if nothing after the device name */
604 /* The other args on the line specify options to be set... */
605 for(i = 0; i < count; i++)
607 /* ---------- Set network ID ---------- */
608 if((!strcasecmp(args[i], "nwid")) ||
609 (!strcasecmp(args[i], "domain")))
614 if((!strcasecmp(args[i], "off")) ||
615 (!strcasecmp(args[i], "any")))
616 wrq.u.nwid.disabled = 1;
618 if(!strcasecmp(args[i], "on"))
621 if(ioctl(skfd, SIOCGIWNWID, &wrq) < 0)
623 fprintf(stderr, "SIOCGIWNWID: %s\n", strerror(errno));
626 strcpy(wrq.ifr_name, ifname);
627 wrq.u.nwid.disabled = 0;
630 if(sscanf(args[i], "%lX", (unsigned long *) &(wrq.u.nwid.value))
634 wrq.u.nwid.disabled = 0;
635 wrq.u.nwid.fixed = 1;
637 if(ioctl(skfd, SIOCSIWNWID, &wrq) < 0)
639 fprintf(stderr, "SIOCSIWNWID: %s\n", strerror(errno));
645 /* ---------- Set frequency / channel ---------- */
646 if((!strncmp(args[i], "freq", 4)) ||
647 (!strcmp(args[i], "channel")))
653 if(sscanf(args[i], "%lg", &(freq)) != 1)
655 if(index(args[i], 'G')) freq *= GIGA;
656 if(index(args[i], 'M')) freq *= MEGA;
657 if(index(args[i], 'k')) freq *= KILO;
659 float2freq(freq, &(wrq.u.freq));
661 if(ioctl(skfd, SIOCSIWFREQ, &wrq) < 0)
663 fprintf(stderr, "SIOCSIWFREQ: %s\n", strerror(errno));
669 /* ---------- Set sensitivity ---------- */
670 if(!strncmp(args[i], "sens", 4))
674 if(sscanf(args[i], "%d", &(wrq.u.sens.value)) != 1)
677 if(ioctl(skfd, SIOCSIWSENS, &wrq) < 0)
679 fprintf(stderr, "SIOCSIWSENS: %s\n", strerror(errno));
685 /* ---------- Set encryption stuff ---------- */
686 if((!strncmp(args[i], "enc", 3)) ||
687 (!strcmp(args[i], "key")))
689 unsigned char key[IW_ENCODING_TOKEN_MAX];
694 if(!strcasecmp(args[i], "on"))
696 /* Get old encryption information */
697 wrq.u.data.pointer = (caddr_t) key;
698 wrq.u.data.length = 0;
699 wrq.u.data.flags = 0;
700 if(ioctl(skfd, SIOCGIWENCODE, &wrq) < 0)
702 fprintf(stderr, "SIOCGIWENCODE: %s\n", strerror(errno));
705 strcpy(wrq.ifr_name, ifname);
706 wrq.u.data.flags &= ~IW_ENCODE_DISABLED; /* Enable */
716 wrq.u.data.pointer = (caddr_t) NULL;
717 wrq.u.data.flags = 0;
718 wrq.u.data.length = 0;
720 /* -- Check for the key -- */
721 if(!strncmp(args[i], "s:", 2))
723 /* First case : as an ASCII string */
724 wrq.u.data.length = strlen(args[i] + 2);
725 if(wrq.u.data.length > IW_ENCODING_TOKEN_MAX)
726 wrq.u.data.length = IW_ENCODING_TOKEN_MAX;
727 strncpy(key, args[i] + 2, wrq.u.data.length);
728 wrq.u.data.pointer = (caddr_t) key;
734 /* Second case : has hexadecimal digits */
735 p = buff = malloc(strlen(args[i]) + 1);
736 strcpy(buff, args[i]);
738 p = strtok(buff, "-:;.,");
739 while(p != (char *) NULL)
741 if(sscanf(p, "%2X", &temp) != 1)
746 key[k++] = (unsigned char) (temp & 0xFF);
747 if(strlen(p) > 2) /* Token not finished yet */
750 p = strtok((char *) NULL, "-:;.,");
757 wrq.u.data.length = k;
758 wrq.u.data.pointer = (caddr_t) key;
762 /* -- Check for token index -- */
764 (sscanf(args[i], "[%d]", &temp) == 1) &&
765 (temp > 0) && (temp < IW_ENCODE_INDEX))
767 wrq.u.encoding.flags |= temp;
772 /* -- Check the various flags -- */
775 if(!strcasecmp(args[i], "off"))
776 wrq.u.data.flags |= IW_ENCODE_DISABLED;
777 if(!strcasecmp(args[i], "open"))
778 wrq.u.data.flags |= IW_ENCODE_OPEN;
779 if(!strncasecmp(args[i], "restricted", 5))
780 wrq.u.data.flags |= IW_ENCODE_RESTRICTED;
781 if(wrq.u.data.flags & IW_ENCODE_FLAGS)
793 if(ioctl(skfd, SIOCSIWENCODE, &wrq) < 0)
795 fprintf(stderr, "SIOCSIWENCODE(%d): %s\n",
796 errno, strerror(errno));
802 /* ---------- Set ESSID ---------- */
803 if(!strcasecmp(args[i], "essid"))
805 char essid[IW_ESSID_MAX_SIZE + 1];
810 if((!strcasecmp(args[i], "off")) ||
811 (!strcasecmp(args[i], "any")))
813 wrq.u.essid.flags = 0;
817 if(!strcasecmp(args[i], "on"))
820 wrq.u.essid.pointer = (caddr_t) essid;
821 wrq.u.essid.length = 0;
822 wrq.u.essid.flags = 0;
823 if(ioctl(skfd, SIOCGIWESSID, &wrq) < 0)
825 fprintf(stderr, "SIOCGIWESSID: %s\n", strerror(errno));
828 strcpy(wrq.ifr_name, ifname);
829 wrq.u.essid.flags = 1;
832 if(strlen(args[i]) > IW_ESSID_MAX_SIZE)
834 fprintf(stderr, "ESSID too long (max %d): ``%s''\n",
835 IW_ESSID_MAX_SIZE, args[i]);
840 wrq.u.essid.flags = 1;
841 strcpy(essid, args[i]);
844 wrq.u.essid.pointer = (caddr_t) essid;
845 wrq.u.essid.length = strlen(essid) + 1;
846 if(ioctl(skfd, SIOCSIWESSID, &wrq) < 0)
848 fprintf(stderr, "SIOCSIWESSID: %s\n", strerror(errno));
854 /* ---------- Set AP address ---------- */
855 if(!strcasecmp(args[i], "ap"))
860 /* Check if we have valid address types */
861 if(check_addr_type(skfd, ifname) < 0)
863 fprintf(stderr, "%-8.8s Interface doesn't support MAC & IP addresses\n", ifname);
867 /* Get the address */
868 if(in_addr(skfd, ifname, args[i++], &(wrq.u.ap_addr)) < 0)
871 if(ioctl(skfd, SIOCSIWAP, &wrq) < 0)
873 fprintf(stderr, "SIOCSIWAP: %s\n", strerror(errno));
879 /* ---------- Set NickName ---------- */
880 if(!strncmp(args[i], "nick", 4))
885 if(strlen(args[i]) > IW_ESSID_MAX_SIZE)
887 fprintf(stderr, "Name too long (max %d) : ``%s''\n",
888 IW_ESSID_MAX_SIZE, args[i]);
892 wrq.u.essid.pointer = (caddr_t) args[i];
893 wrq.u.essid.length = strlen(args[i]) + 1;
894 if(ioctl(skfd, SIOCSIWNICKN, &wrq) < 0)
896 fprintf(stderr, "SIOCSIWNICKN: %s\n", strerror(errno));
902 /* ---------- Set Bit-Rate ---------- */
903 if((!strncmp(args[i], "bit", 3)) ||
904 (!strcmp(args[i], "rate")))
908 if(!strcasecmp(args[i], "auto"))
910 wrq.u.bitrate.value = -1;
911 wrq.u.bitrate.fixed = 0;
915 if(!strcasecmp(args[i], "fixed"))
917 /* Get old bitrate */
918 if(ioctl(skfd, SIOCGIWRATE, &wrq) < 0)
920 fprintf(stderr, "SIOCGIWRATE: %s\n", strerror(errno));
923 strcpy(wrq.ifr_name, ifname);
924 wrq.u.bitrate.fixed = 1;
926 else /* Should be a numeric value */
930 if(sscanf(args[i], "%lg", &(brate)) != 1)
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;
948 if(ioctl(skfd, SIOCSIWRATE, &wrq) < 0)
950 fprintf(stderr, "SIOCSIWRATE: %s\n", strerror(errno));
956 /* ---------- Set RTS threshold ---------- */
957 if(!strncasecmp(args[i], "rts", 3))
962 wrq.u.rts.value = -1;
964 wrq.u.rts.disabled = 0;
965 if(!strcasecmp(args[i], "off"))
966 wrq.u.rts.disabled = 1; /* i.e. max size */
968 if(!strcasecmp(args[i], "auto"))
972 if(!strcasecmp(args[i], "fixed"))
974 /* Get old RTS threshold */
975 if(ioctl(skfd, SIOCGIWRTS, &wrq) < 0)
977 fprintf(stderr, "SIOCGIWRTS: %s\n", strerror(errno));
980 strcpy(wrq.ifr_name, ifname);
983 else /* Should be a numeric value */
984 if(sscanf(args[i], "%ld", (unsigned long *) &(wrq.u.rts.value))
989 if(ioctl(skfd, SIOCSIWRTS, &wrq) < 0)
991 fprintf(stderr, "SIOCSIWRTS: %s\n", strerror(errno));
997 /* ---------- Set fragmentation threshold ---------- */
998 if(!strncmp(args[i], "frag", 4))
1003 wrq.u.frag.value = -1;
1004 wrq.u.frag.fixed = 1;
1005 wrq.u.frag.disabled = 0;
1006 if(!strcasecmp(args[i], "off"))
1007 wrq.u.frag.disabled = 1; /* i.e. max size */
1009 if(!strcasecmp(args[i], "auto"))
1010 wrq.u.frag.fixed = 0;
1013 if(!strcasecmp(args[i], "fixed"))
1015 /* Get old fragmentation threshold */
1016 if(ioctl(skfd, SIOCGIWFRAG, &wrq) < 0)
1018 fprintf(stderr, "SIOCGIWFRAG: %s\n", strerror(errno));
1021 strcpy(wrq.ifr_name, ifname);
1022 wrq.u.frag.fixed = 1;
1024 else /* Should be a numeric value */
1025 if(sscanf(args[i], "%ld", (unsigned long *) &(wrq.u.frag.value))
1030 if(ioctl(skfd, SIOCSIWFRAG, &wrq) < 0)
1032 fprintf(stderr, "SIOCSIWFRAG: %s\n", strerror(errno));
1038 /* ---------- Set operation mode ---------- */
1039 if(!strcmp(args[i], "mode"))
1047 if(sscanf(args[i], "%d", &k) != 1)
1050 while(k < 6 && strncasecmp(args[i], operation_mode[k], 3))
1053 if((k > 5) || (k < 0))
1057 if(ioctl(skfd, SIOCSIWMODE, &wrq) < 0)
1059 fprintf(stderr, "SIOCSIWMODE: %s\n", strerror(errno));
1065 /* ---------- Set Power Management ---------- */
1066 if(!strncmp(args[i], "power", 3))
1071 if(!strcasecmp(args[i], "off"))
1072 wrq.u.power.disabled = 1; /* i.e. max size */
1074 if(!strcasecmp(args[i], "on"))
1076 /* Get old Power info */
1077 if(ioctl(skfd, SIOCGIWPOWER, &wrq) < 0)
1079 fprintf(stderr, "SIOCGIWFRAG: %s\n", strerror(errno));
1082 strcpy(wrq.ifr_name, ifname);
1083 wrq.u.power.disabled = 0;
1089 /* Default - nope */
1090 wrq.u.power.flags = IW_POWER_ON;
1091 wrq.u.power.disabled = 0;
1093 /* Check value modifier */
1094 if(!strcasecmp(args[i], "period"))
1096 wrq.u.power.flags = IW_POWER_PERIOD;
1101 if(!strcasecmp(args[i], "timeout"))
1103 wrq.u.power.flags = IW_POWER_TIMEOUT;
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_ON)
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)
1145 if(ioctl(skfd, SIOCSIWPOWER, &wrq) < 0)
1147 fprintf(stderr, "SIOCSIWPOWER(%d): %s\n",
1148 errno, strerror(errno));
1154 /* ---------- Other ---------- */
1155 /* Here we have an unrecognised arg... */
1156 fprintf(stderr, "Invalid argument : %s\n", args[i]);
1159 } /* for(index ... */
1163 /******************************* MAIN ********************************/
1165 /*------------------------------------------------------------------*/
1173 int skfd = -1; /* generic raw socket desc. */
1176 /* Create a channel to the NET kernel. */
1177 if((skfd = sockets_open()) < 0)
1183 /* No argument : show the list of all device + info */
1186 print_devices(skfd);
1191 /* Special case for help... */
1192 if((!strncmp(argv[1], "-h", 9)) ||
1193 (!strcmp(argv[1], "--help")))
1200 /* The device name must be the first argument */
1203 print_info(skfd, argv[1]);
1208 /* The other args on the line specify options to be set... */
1209 goterr = set_info(skfd, argv + 2, argc - 2, argv[1]);
1211 /* Close the socket. */