464310c77551b9c18b99a695dd1a8ee163185e79
[openwrt.git] / openwrt / package / openwrt / wlc / wlc.c
1 /*
2 * wl - tool for configuring the Broadcom Wireless Network Adapter
3 * Copyright (C) 2005 Felix Fietkau <nbd@vd-s.ath.cx>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include <typedefs.h>
25 #include <wlutils.h>
26
27 struct wl_config {
28 char *name, *desc;
29 enum {
30 INT,
31 BOOL,
32 OTHER
33 } type;
34 int get, set;
35 int r1, r2;
36 char *data;
37 };
38
39 struct wl_config commands[] = {
40 {"txpwr", "transmit power (in mW)", INT, WLC_GET_TXPWR, WLC_SET_TXPWR, 0, 255, NULL},
41 {"promisc", "promiscuous mode", BOOL, WLC_GET_PROMISC, WLC_SET_PROMISC, 0, 0, NULL},
42 {"monitor", "monitor mode", BOOL, WLC_GET_AP, WLC_SET_AP, 0, 0, NULL},
43 {"ap", "access point mode (0 = STA, 1 = AP)", BOOL, WLC_GET_AP, WLC_SET_AP, 0, 0, NULL},
44 {"infra", "infrastructure mode (0 = IBSS, 1 = Infra BSS)", BOOL, WLC_GET_INFRA, WLC_SET_INFRA, 0, 0, NULL},
45 {"antdiv", "rx antenna diversity (0 = antenna 0, 1 = antenna 1, 3 = auto select)", INT, WLC_GET_ANTDIV, WLC_SET_ANTDIV, 0, 3, NULL},
46 {"txant", "set tx antenna (0 = antenna 0, 1 = antenna 1, 3 = rx antenna)", INT, WLC_GET_TXANT, WLC_SET_TXANT, 0, 3, NULL},
47 {"channel", "set channel", INT, WLC_GET_CHANNEL, WLC_SET_CHANNEL, 1, 14, NULL},
48 {NULL, NULL, 0, 0, 0, 0, 0, NULL}
49 };
50
51 void set_int(char *name, int ioctl, int value, int r1, int r2)
52 {
53 if ((value >= r1) || (value <= r2)) {
54 wl_ioctl(name, ioctl, &value, sizeof(value));
55 } else
56 fprintf(stderr, "invalid value.\n");
57 }
58
59 void get_int(char *name, int ioctl)
60 {
61 int value = 0;
62 wl_ioctl(name, ioctl, &value, sizeof(value));
63 printf("%d\n", value);
64 }
65
66 int main(int argc, char **argv)
67 {
68 struct wl_config *cmd;
69 int i;
70
71 if (argc < 3) {
72 fprintf(stderr, "Usage: %s <interface> <command> [...]\n\n", argv[0]);
73 fprintf(stderr, "Commands:\n\n");
74
75 cmd = commands;
76 while (cmd->name != NULL) {
77 fprintf(stderr, "\t%s", cmd->name);
78 switch (cmd->type) {
79 case INT:
80 fprintf(stderr, " [%d-%d]", cmd->r1, cmd->r2);
81 break;
82 case BOOL:
83 fprintf(stderr, " [0|1]");
84 cmd->r1 = 0;
85 cmd->r2 = 1;
86
87 }
88 fprintf(stderr, "\t%s\n", cmd->desc);
89 cmd++;
90 }
91 fprintf(stderr, "\n");
92
93 return -1;
94 }
95
96 if (wl_probe(argv[1]) < 0) {
97 fprintf(stderr, "No broadcom extensions detected on interface %s\n", argv[1]);
98 return -1;
99 }
100
101 if ((argc > 4) && (strcmp(argv[2], "ioctl") == 0)) {
102 if (strcmp(argv[3], "int") == 0) {
103 int ioctl = atoi(argv[4]);
104 if (argc > 5)
105 i = atoi(argv[5]);
106 else
107 i = 0;
108 fprintf(stderr, "ioctl = 0x%x (%d)\nold value = 0x%x (%d)\n", ioctl, ioctl, i, i);
109 wl_ioctl(argv[1], ioctl, &i, sizeof(i));
110 fprintf(stderr, "new value = 0x%x (%d)\n", i, i);
111 }
112 return 0;
113 }
114 cmd = commands;
115 while (cmd->name != NULL) {
116 if (strcmp(argv[2], cmd->name) == 0) {
117 switch (cmd->type) {
118 case INT:
119 case BOOL:
120 if (argc < 4) {
121 get_int(argv[1], cmd->get);
122 } else {
123 set_int(argv[1], cmd->set, atoi(argv[3]), cmd->r1, cmd->r2);
124 }
125 break;
126 }
127 }
128 cmd++;
129 }
130
131
132 return 0;
133 }
This page took 0.057254 seconds and 3 git commands to generate.