4 * Jean II - HPLB 97->99 - HPL 99->04
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-2004 Jean Tourrilhes <jt@hpl.hp.com>
14 #include "iwlib.h" /* Header */
16 /************************** DOCUMENTATION **************************/
21 * Wireless Extension recognise that each wireless device has some
22 * specific features not covered by the standard wireless extensions.
23 * Private wireless ioctls/requests allow a device to export the control
24 * of those device specific features, and allow users to directly interact
26 * There are many other ways you can implement such functionality :
29 * o file system (/proc/ or /sysfs/)
30 * o extra character device (/dev/)
31 * Private wireless ioctls is one of the simplest implementation,
32 * however it is limited, so you may want to check the alternatives.
34 * Like for standard Wireless Extensions, each private wireless
35 * request is identified by an IOCTL NUMBER and carry a certain number
36 * of arguments (SET or GET).
37 * The driver exports a description of those requests (ioctl number,
38 * request name, set and get arguments). Then, iwpriv uses those request
39 * descriptions to call the appropriate request and handle the
44 * The initial implementation of iwpriv was using the SIOCDEVPRIVATE
45 * ioctl range (up to 16 ioctls - driver specific). However, this was
46 * causing some compatibility problems with other usages of those
47 * ioctls, and those ioctls are supposed to be removed.
48 * Therefore, I created a new ioctl range, at SIOCIWFIRSTPRIV. Those
49 * ioctls are specific to Wireless Extensions, so you don't have to
50 * worry about collisions with other usages. On the other hand, in the
51 * new range, the SET convention is enforced (see below).
52 * The differences are : SIOCDEVPRIVATE SIOCIWFIRSTPRIV
53 * o availability <= 2.5.X WE > 11 (>= 2.4.13)
55 * o SET convention optional enforced
60 * Wireless Extension 13 introduces a new driver API. Wireless
61 * Extensions requests can be handled via a iw_handler table instead
62 * of through the regular ioctl handler.
63 * The new driver API can be handled only with the new ioctl range
64 * and enforces the GET convention (see below).
65 * The differences are : old API new API
66 * o handler do_ioctl() struct iw_handler_def
67 * o SIOCIWFIRSTPRIV WE > 11 yes
68 * o SIOCDEVPRIVATE yes no
69 * o GET convention optional enforced
70 * Note that the new API before Wireless Extension 15 contains bugs
71 * when handling sub-ioctls and addr/float data types.
73 * INLINING vs. POINTER :
74 * --------------------
75 * One of the tricky aspect of the old driver API is how the data
76 * is handled, which is how the driver is supposed to extract the data
77 * passed to it by iwpriv.
78 * 1) If the data has a fixed size (private ioctl definition
79 * has the flag IW_PRIV_SIZE_FIXED) and the byte size of the data is
80 * lower than 16 bytes, the data will be inlined. The driver can extract
81 * data in the field 'u.name' of the struct iwreq.
82 * 2) If the if the data doesn't have a fixed size or is larger than
83 * 16 bytes, the data is passed by pointer. struct iwreq contains a
84 * struct iwpoint with a user space pointer to the data. Appropriate
85 * copy_from/to_user() function should be used.
87 * With the new API, this is handled transparently, the data is
88 * always available as the fourth argument of the request handler
89 * (usually called 'extra').
91 * SET/GET CONVENTION :
93 * Simplistic summary :
94 * o even numbered ioctls are SET, restricted to root, and should not
95 * return arguments (get_args = 0).
96 * o odd numbered ioctls are GET, authorised to anybody, and should
97 * not expect any arguments (set_args = 0).
99 * The regular Wireless Extensions use the SET/GET convention, where
100 * the low order bit identify a SET (0) or a GET (1) request. The private
101 * Wireless Extension is not as restrictive, but still has some
103 * The new ioctl range enforces the SET convention : SET request will
104 * be available to root only and can't return any arguments. If you don't
105 * like that, just use every other two ioctl.
106 * The new driver API enforce the GET convention : GET request won't
107 * be able to accept any arguments (except if its fits within (union
108 * iwreq_data)). If you don't like that, you can either use the Token Index
109 * support or the old API (aka the ioctl handler).
110 * In any case, it's a good idea to not have ioctl with both SET
111 * and GET arguments. If the GET arguments doesn't fit within
112 * (union iwreq_data) and SET do, or vice versa, the current code in iwpriv
113 * won't work. One exception is if both SET and GET arguments fit within
114 * (union iwreq_data), this case should be handled safely in a GET
116 * If you don't fully understand those limitations, just follow the
117 * rules of the simplistic summary ;-)
121 * Wireless Extension 15 introduces sub-ioctls. For some applications,
122 * 32 ioctls is not enough, and this simple mechanism allows to increase
123 * the number of ioctls by adding a sub-ioctl index to some of the ioctls
124 * (so basically it's a two level addressing).
125 * One might argue that at the point, some other mechanisms might be
126 * better, like using a real filesystem abstraction (/proc, driverfs, ...),
127 * but sub-ioctls are simple enough and don't have much drawbacks (which
128 * means that it's a quick and dirty hack ;-).
130 * There are two slightly different variations of the sub-ioctl scheme :
131 * 1) If the payload fits within (union iwreq_data), the first int
132 * (4 bytes) is reserved as the sub-ioctl number and the regular payload
133 * shifted by 4 bytes. The handler must extract the sub-ioctl number,
134 * increment the data pointer and then use it in the usual way.
135 * 2) If the ioctl uses (struct iw_point), the sub-ioctl number is
136 * set in the flags member of the structure. In this case, the handler
137 * should simply get the sub-ioctl number from the flags and process the
138 * data in the usual way.
140 * Sub-ioctls are declared normally in the private definition table,
141 * with cmd (first arg) being the sub-ioctl number. Then, you should
142 * declare the real ioctl, which will process the sub-ioctls, with
143 * the SAME ARGUMENTS and a EMPTY NAME.
144 * Here's an example of how it could look like :
145 * --------------------------------------------
146 // --- sub-ioctls handlers ---
147 { 0x8BE0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
148 { 0x8BE1, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
149 // --- sub-ioctls definitions ---
150 { 1, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_param1" },
151 { 1, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param1" },
152 { 2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_param2" },
153 { 2, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param2" },
154 // --- Raw access to sub-ioctl handlers ---
155 { 0x8BE0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_paramN" },
156 { 0x8BE1, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
157 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_paramN" },
158 * --------------------------------------------
159 * And iwpriv should do the rest for you ;-)
161 * Note that versions of iwpriv up to v24 (included) expect at most
162 * 16 ioctls definitions and will likely crash when given more.
163 * There is no fix that I can see, apart from recommending your users
164 * to upgrade their Wireless Tools. Wireless Extensions 15 will check this
165 * condition, so another workaround is restricting those extra definitions
168 * Another problem is that the new API before Wireless Extension 15
169 * has a bug when passing fixed arguments of 12-15 bytes. It will
170 * try to get them inline instead of by pointer. You can fool the new API
171 * to do the right thing using fake ioctl definitions (but remember that
172 * you will be more likely to hit the limit of 16 ioctl definitions).
173 * To play safe, use the old-style ioctl handler before v15.
175 * NEW DATA TYPES (ADDR/FLOAT) :
176 * ---------------------------
177 * Wireless Tools 25 introduce two new data types, addr and float,
178 * corresponding to struct sockaddr and struct iwfreq.
179 * Those types are properly handled with Wireless Extensions 15.
180 * However, the new API before v15 won't handle them properly.
182 * The first problem is that the new API won't know their size, so
183 * it won't copy them. This can be workaround with a fake ioctl definition.
184 * The second problem is that a fixed single addr won't be inlined
185 * in struct iwreq and will be passed as a pointer. This is due to an
186 * off-by-one error, where all fixed data of 16 bytes is considered too
187 * big to fit in struct iwreq.
189 * For those reasons, I would recommend to use the ioctl handler
190 * before v15 when manipulating those data.
194 * Token index is very similar to sub-ioctl. It allows the user
195 * to specify an integer index in front of a bunch of other arguments
196 * (addresses, strings, ...). It's specified in square brackets on the
197 * iwpriv command line before other arguments.
198 * > iwpriv eth0 [index] args...
199 * Token index works only when the data is passed as pointer, and
200 * is otherwise ignored. If your data would fit within struct iwreq, you
201 * should declare the command *without* IW_PRIV_SIZE_FIXED to force
202 * this to happen (and check arg number yourself).
203 * --------------------------------------------
204 // --- Commands that would fit in struct iwreq ---
205 { 0x8BE0, IW_PRIV_TYPE_ADDR | 1, 0, "set_param_with_token" },
206 // --- No problem here (bigger than struct iwreq) ---
207 { 0x8BE1, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 2, 0, "again" },
208 * --------------------------------------------
209 * The token index feature is pretty transparent, the token index
210 * will just be in the flags member of (struct iw_point). Default value
211 * (if the user doesn't specify it) will be 0. Token index itself will
212 * work with any version of Wireless Extensions.
213 * Token index is not compatible with sub-ioctl (both use the same
214 * field of struct iw_point). However, the token index can be used to offer
215 * raw access to the sub-ioctl handlers (if it uses struct iw_point) :
216 * --------------------------------------------
217 // --- sub-ioctls handler ---
218 { 0x8BE0, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "" },
219 // --- sub-ioctls definitions ---
220 { 0, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "setaddr" },
221 { 1, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "deladdr" },
222 // --- raw access with token index (+ iwreq workaround) ---
223 { 0x8BE0, IW_PRIV_TYPE_ADDR | 1, 0, "rawaddr" },
224 * --------------------------------------------
229 /**************************** CONSTANTS ****************************/
231 static const char * argtype[] = {
232 " ", "byte ", "char ", "", "int ", "float", "addr " };
234 /************************* MISC SUBROUTINES **************************/
236 /*------------------------------------------------------------------*/
243 fprintf(stderr, "Usage: iwpriv interface [private-command [private-arguments]]\n");
246 /************************* SETTING ROUTINES **************************/
248 /*------------------------------------------------------------------*/
250 * Execute a private command on the interface
253 set_private_cmd(int skfd, /* Socket */
254 char * args[], /* Command line args */
255 int count, /* Args count */
256 char * ifname, /* Dev name */
257 char * cmdname, /* Command name */
258 iwprivargs * priv, /* Private ioctl description */
259 int priv_num) /* Number of descriptions */
262 u_char buffer[4096]; /* Only that big in v25 and later */
263 int i = 0; /* Start with first command arg */
264 int k; /* Index in private description table */
266 int subcmd = 0; /* sub-ioctl index */
267 int offset = 0; /* Space for sub-ioctl index */
269 /* Check if we have a token index.
270 * Do it now so that sub-ioctl takes precedence, and so that we
271 * don't have to bother with it later on... */
272 if((count >= 1) && (sscanf(args[0], "[%i]", &temp) == 1))
279 /* Search the correct ioctl */
281 while((++k < priv_num) && strcmp(priv[k].name, cmdname));
283 /* If not found... */
286 fprintf(stderr, "Invalid command : %s\n", cmdname);
290 /* Watch out for sub-ioctls ! */
291 if(priv[k].cmd < SIOCDEVPRIVATE)
295 /* Find the matching *real* ioctl */
296 while((++j < priv_num) && ((priv[j].name[0] != '\0') ||
297 (priv[j].set_args != priv[k].set_args) ||
298 (priv[j].get_args != priv[k].get_args)));
300 /* If not found... */
303 fprintf(stderr, "Invalid private ioctl definition for : %s\n",
308 /* Save sub-ioctl number */
309 subcmd = priv[k].cmd;
310 /* Reserve one int (simplify alignment issues) */
311 offset = sizeof(__u32);
312 /* Use real ioctl definition from now on */
316 printf("<mapping sub-ioctl %s to cmd 0x%X-%d>\n", cmdname,
317 priv[k].cmd, subcmd);
321 /* If we have to set some data */
322 if((priv[k].set_args & IW_PRIV_TYPE_MASK) &&
323 (priv[k].set_args & IW_PRIV_SIZE_MASK))
325 switch(priv[k].set_args & IW_PRIV_TYPE_MASK)
327 case IW_PRIV_TYPE_BYTE:
328 /* Number of args to fetch */
329 wrq.u.data.length = count;
330 if(wrq.u.data.length > (priv[k].set_args & IW_PRIV_SIZE_MASK))
331 wrq.u.data.length = priv[k].set_args & IW_PRIV_SIZE_MASK;
334 for(; i < wrq.u.data.length; i++) {
335 sscanf(args[i], "%i", &temp);
336 buffer[i] = (char) temp;
340 case IW_PRIV_TYPE_INT:
341 /* Number of args to fetch */
342 wrq.u.data.length = count;
343 if(wrq.u.data.length > (priv[k].set_args & IW_PRIV_SIZE_MASK))
344 wrq.u.data.length = priv[k].set_args & IW_PRIV_SIZE_MASK;
347 for(; i < wrq.u.data.length; i++) {
348 sscanf(args[i], "%i", &temp);
349 ((__s32 *) buffer)[i] = (__s32) temp;
353 case IW_PRIV_TYPE_CHAR:
356 /* Size of the string to fetch */
357 wrq.u.data.length = strlen(args[i]) + 1;
358 if(wrq.u.data.length > (priv[k].set_args & IW_PRIV_SIZE_MASK))
359 wrq.u.data.length = priv[k].set_args & IW_PRIV_SIZE_MASK;
362 memcpy(buffer, args[i], wrq.u.data.length);
363 buffer[sizeof(buffer) - 1] = '\0';
368 wrq.u.data.length = 1;
373 case IW_PRIV_TYPE_FLOAT:
374 /* Number of args to fetch */
375 wrq.u.data.length = count;
376 if(wrq.u.data.length > (priv[k].set_args & IW_PRIV_SIZE_MASK))
377 wrq.u.data.length = priv[k].set_args & IW_PRIV_SIZE_MASK;
380 for(; i < wrq.u.data.length; i++) {
382 if(sscanf(args[i], "%lg", &(freq)) != 1)
384 printf("Invalid float [%s]...\n", args[i]);
387 if(index(args[i], 'G')) freq *= GIGA;
388 if(index(args[i], 'M')) freq *= MEGA;
389 if(index(args[i], 'k')) freq *= KILO;
390 sscanf(args[i], "%i", &temp);
391 iw_float2freq(freq, ((struct iw_freq *) buffer) + i);
395 case IW_PRIV_TYPE_ADDR:
396 /* Number of args to fetch */
397 wrq.u.data.length = count;
398 if(wrq.u.data.length > (priv[k].set_args & IW_PRIV_SIZE_MASK))
399 wrq.u.data.length = priv[k].set_args & IW_PRIV_SIZE_MASK;
402 for(; i < wrq.u.data.length; i++) {
403 if(iw_in_addr(skfd, ifname, args[i],
404 ((struct sockaddr *) buffer) + i) < 0)
406 printf("Invalid address [%s]...\n", args[i]);
413 fprintf(stderr, "Not implemented...\n");
417 if((priv[k].set_args & IW_PRIV_SIZE_FIXED) &&
418 (wrq.u.data.length != (priv[k].set_args & IW_PRIV_SIZE_MASK)))
420 printf("The command %s needs exactly %d argument(s)...\n",
421 cmdname, priv[k].set_args & IW_PRIV_SIZE_MASK);
424 } /* if args to set */
427 wrq.u.data.length = 0L;
430 strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
432 /* Those two tests are important. They define how the driver
433 * will have to handle the data */
434 if((priv[k].set_args & IW_PRIV_SIZE_FIXED) &&
435 ((iw_get_priv_size(priv[k].set_args) + offset) <= IFNAMSIZ))
437 /* First case : all SET args fit within wrq */
440 memcpy(wrq.u.name + offset, buffer, IFNAMSIZ - offset);
444 if((priv[k].set_args == 0) &&
445 (priv[k].get_args & IW_PRIV_SIZE_FIXED) &&
446 (iw_get_priv_size(priv[k].get_args) <= IFNAMSIZ))
448 /* Second case : no SET args, GET args fit within wrq */
454 /* Third case : args won't fit in wrq, or variable number of args */
455 wrq.u.data.pointer = (caddr_t) buffer;
456 wrq.u.data.flags = subcmd;
460 /* Perform the private ioctl */
461 if(ioctl(skfd, priv[k].cmd, &wrq) < 0)
463 fprintf(stderr, "Interface doesn't accept private ioctl...\n");
464 fprintf(stderr, "%s (%X): %s\n", cmdname, priv[k].cmd, strerror(errno));
468 /* If we have to get some data */
469 if((priv[k].get_args & IW_PRIV_TYPE_MASK) &&
470 (priv[k].get_args & IW_PRIV_SIZE_MASK))
473 int n = 0; /* number of args */
475 printf("%-8.16s %s:", ifname, cmdname);
477 /* Check where is the returned data */
478 if((priv[k].get_args & IW_PRIV_SIZE_FIXED) &&
479 (iw_get_priv_size(priv[k].get_args) <= IFNAMSIZ))
481 memcpy(buffer, wrq.u.name, IFNAMSIZ);
482 n = priv[k].get_args & IW_PRIV_SIZE_MASK;
485 n = wrq.u.data.length;
487 switch(priv[k].get_args & IW_PRIV_TYPE_MASK)
489 case IW_PRIV_TYPE_BYTE:
491 for(j = 0; j < n; j++)
492 printf("%d ", buffer[j]);
496 case IW_PRIV_TYPE_INT:
498 for(j = 0; j < n; j++)
499 printf("%d ", ((__s32 *) buffer)[j]);
503 case IW_PRIV_TYPE_CHAR:
506 printf("%s\n", buffer);
509 case IW_PRIV_TYPE_FLOAT:
513 for(j = 0; j < n; j++)
515 freq = iw_freq2float(((struct iw_freq *) buffer) + j);
517 printf("%gG ", freq / GIGA);
520 printf("%gM ", freq / MEGA);
522 printf("%gk ", freq / KILO);
528 case IW_PRIV_TYPE_ADDR:
531 struct sockaddr * hwa;
533 for(j = 0; j < n; j++)
535 hwa = ((struct sockaddr *) buffer) + j;
538 (int) strlen(cmdname), " ");
539 printf("%s\n", iw_saether_ntop(hwa, scratch));
545 fprintf(stderr, "Not yet implemented...\n");
548 } /* if args to set */
553 /*------------------------------------------------------------------*/
555 * Execute a private command on the interface
558 set_private(int skfd, /* Socket */
559 char * args[], /* Command line args */
560 int count, /* Args count */
561 char * ifname) /* Dev name */
564 int number; /* Max of private ioctl */
567 /* Read the private ioctls */
568 number = iw_get_priv_info(skfd, ifname, &priv);
573 /* Should I skip this message ? */
574 fprintf(stderr, "%-8.16s no private ioctls.\n\n",
582 ret = set_private_cmd(skfd, args + 1, count - 1, ifname, args[0],
589 /************************ CATALOG FUNCTIONS ************************/
591 /*------------------------------------------------------------------*/
593 * Print on the screen in a neat fashion the list of private ioctls
597 print_priv_info(int skfd,
606 /* Avoid "Unused parameter" warning */
607 args = args; count = count;
609 /* Read the private ioctls */
610 n = iw_get_priv_info(skfd, ifname, &priv);
615 /* Should I skip this message ? */
616 fprintf(stderr, "%-8.16s no private ioctls.\n\n",
621 printf("%-8.16s Available private ioctls :\n", ifname);
623 for(k = 0; k < n; k++)
624 if(priv[k].name[0] != '\0')
625 printf(" %-16.16s (%.4X) : set %3d %s & get %3d %s\n",
626 priv[k].name, priv[k].cmd,
627 priv[k].set_args & IW_PRIV_SIZE_MASK,
628 argtype[(priv[k].set_args & IW_PRIV_TYPE_MASK) >> 12],
629 priv[k].get_args & IW_PRIV_SIZE_MASK,
630 argtype[(priv[k].get_args & IW_PRIV_TYPE_MASK) >> 12]);
640 /*------------------------------------------------------------------*/
642 * Print on the screen in a neat fashion the list of private GET ioctl
643 * data for the device and data returned by those.
646 print_priv_all(int skfd,
655 /* Avoid "Unused parameter" warning */
656 args = args; count = count;
658 /* Read the private ioctls */
659 n = iw_get_priv_info(skfd, ifname, &priv);
664 /* Should I skip this message ? */
665 fprintf(stderr, "%-8.16s no private ioctls.\n\n",
670 printf("%-8.16s Available read-only private ioctl :\n", ifname);
672 for(k = 0; k < n; k++)
673 /* We call all ioctls that don't have a null name, don't require
674 * args and return some (avoid triggering "reset" commands) */
675 if((priv[k].name[0] != '\0') && (priv[k].set_args == 0) &&
676 (priv[k].get_args != 0))
677 set_private_cmd(skfd, NULL, 0, ifname, priv[k].name,
688 /********************** PRIVATE IOCTLS MANIPS ***********************/
690 * Convenient access to some private ioctls of some devices
693 /*------------------------------------------------------------------*/
695 * Set roaming mode on and off
696 * Found in wavelan_cs driver
697 * Note : this is obsolete, most 802.11 devices should use the
701 set_roaming(int skfd, /* Socket */
702 char * args[], /* Command line args */
703 int count, /* Args count */
704 char * ifname) /* Dev name */
708 int i = 0; /* Start with first arg */
713 char RoamState; /* buffer to hold new roam state */
714 char ChangeRoamState=0; /* whether or not we are going to
715 change roam states */
717 /* Read the private ioctls */
718 number = iw_get_priv_info(skfd, ifname, &priv);
723 /* Should I skip this message ? */
724 fprintf(stderr, "%-8.16s no private ioctls.\n\n",
731 /* Get the ioctl number */
733 while((++k < number) && strcmp(priv[k].name, "setroam"));
736 fprintf(stderr, "This device doesn't support roaming\n");
740 roamcmd = priv[k].cmd;
751 if(!strcasecmp(args[i], "on"))
753 printf("%-8.16s enable roaming\n", ifname);
756 fprintf(stderr, "This device doesn't support roaming\n");
763 if(!strcasecmp(args[i], "off"))
766 printf("%-8.16s disable roaming\n", ifname);
769 fprintf(stderr, "This device doesn't support roaming\n");
783 strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
787 memcpy(wrq.u.name, &buffer, IFNAMSIZ);
789 if(ioctl(skfd, roamcmd, &wrq) < 0)
791 fprintf(stderr, "Roaming support is broken.\n");
799 /*------------------------------------------------------------------*/
801 * Get and set the port type
802 * Found in wavelan2_cs and wvlan_cs drivers
803 * TODO : Add support for HostAP ?
806 port_type(int skfd, /* Socket */
807 char * args[], /* Command line args */
808 int count, /* Args count */
809 char * ifname) /* Dev name */
812 int i = 0; /* Start with first arg */
817 char * modes[] = { "invalid", "managed (BSS)", "reserved", "ad-hoc" };
819 /* Read the private ioctls */
820 number = iw_get_priv_info(skfd, ifname, &priv);
825 /* Should I skip this message ? */
826 fprintf(stderr, "%-8.16s no private ioctls.\n\n", ifname);
835 /* So, we just want to see the current value... */
837 while((++k < number) && strcmp(priv[k].name, "gport_type") &&
838 strcmp(priv[k].name, "get_port"));
841 fprintf(stderr, "This device doesn't support getting port type\n");
844 strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
847 if(ioctl(skfd, priv[k].cmd, &wrq) < 0)
849 fprintf(stderr, "Port type support is broken.\n");
855 printf("%-8.16s Current port mode is %s <port type is %d>.\n\n",
856 ifname, modes[(int) ptype], ptype);
871 while((k < 4) && strncasecmp(args[i], modes[k], 2))
876 /* ...or as an integer */
877 if(sscanf(args[i], "%i", (int *) &ptype) != 1)
884 while((++k < number) && strcmp(priv[k].name, "sport_type") &&
885 strcmp(priv[k].name, "set_port"));
888 fprintf(stderr, "This device doesn't support setting port type\n");
891 strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
893 *(wrq.u.name) = ptype;
895 if(ioctl(skfd, priv[k].cmd, &wrq) < 0)
897 fprintf(stderr, "Invalid port type (or setting not allowed)\n");
909 /******************************* MAIN ********************************/
911 /*------------------------------------------------------------------*/
919 int skfd; /* generic raw socket desc. */
922 /* Create a channel to the NET kernel. */
923 if((skfd = iw_sockets_open()) < 0)
929 /* No argument : show the list of all devices + ioctl list */
931 iw_enum_devices(skfd, &print_priv_info, NULL, 0);
933 /* Special cases take one... */
935 if((!strncmp(argv[1], "-a", 2)) || (!strcmp(argv[1], "--all")))
936 iw_enum_devices(skfd, &print_priv_all, NULL, 0);
939 if((!strncmp(argv[1], "-h", 2)) || (!strcmp(argv[1], "--help")))
943 if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))
944 goterr = iw_print_version_info("iwpriv");
946 /* The device name must be the first argument */
947 /* Name only : show for that device only */
949 print_priv_info(skfd, argv[1], NULL, 0);
951 /* Special cases take two... */
953 if((!strncmp(argv[2], "-a", 2)) ||
954 (!strcmp(argv[2], "--all")))
955 print_priv_all(skfd, argv[1], NULL, 0);
958 if(!strncmp(argv[2], "roam", 4))
959 goterr = set_roaming(skfd, argv + 3, argc - 3, argv[1]);
962 if(!strncmp(argv[2], "port", 4))
963 goterr = port_type(skfd, argv + 3, argc - 3, argv[1]);
966 /* Otherwise, it's a private ioctl */
967 goterr = set_private(skfd, argv + 2, argc - 2, argv[1]);
969 /* Close the socket. */
970 iw_sockets_close(skfd);