fix wificonf segfault when maclist is enabled
[openwrt.git] / package / openwrt / wlc.c
1 /*
2 * wlc - 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 * $Id$
20 *
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include <typedefs.h>
28 #include <wlutils.h>
29
30 int _argc;
31 char **_argv;
32
33 void qtxpwr() {
34 int i = 0;
35
36 if (_argc > 3) {
37 if (_argv[3][0] == '@') {
38 i = atoi(_argv[3] + 1);
39 i |= 0x80000000;
40 } else {
41 i = atoi(_argv[3]);
42 }
43 wl_set_val(_argv[1], "qtxpower", &i, sizeof(i));
44 } else {
45 wl_get_val(_argv[1], "qtxpower", &i, sizeof(i));
46 if ((i & 0x80000000) == 0x80000000)
47 printf("@");
48 printf("%d\n", i & 0x7ffffff);
49 }
50 }
51
52
53 struct wl_config {
54 char *name, *desc;
55 enum {
56 INT,
57 BOOL,
58 OTHER
59 } type;
60 int get, set;
61 int r1, r2;
62 void *handler;
63 };
64
65 struct wl_config commands[] = {
66 {"txpwr", "transmit power (in mW)", INT, WLC_GET_TXPWR, WLC_SET_TXPWR, 0, 255, NULL},
67 {"qtxpwr", "\ttransmit power (in qdbm)\n\t\t\t\"@\" before value means regulatory override", OTHER, 0, 0, 0, 0, qtxpwr},
68 {"promisc", "promiscuous mode", BOOL, WLC_GET_PROMISC, WLC_SET_PROMISC, 0, 0, NULL},
69 {"monitor", "monitor mode", BOOL, WLC_GET_MONITOR, WLC_SET_MONITOR, 0, 0, NULL},
70 {"passive", "passive mode", BOOL, WLC_GET_PASSIVE, WLC_SET_PASSIVE, 0, 0, NULL},
71 {"ap", "access point mode (0 = STA, 1 = AP)", BOOL, WLC_GET_AP, WLC_SET_AP, 0, 0, NULL},
72 {"infra", "infrastructure mode (0 = IBSS, 1 = Infra BSS)", BOOL, WLC_GET_INFRA, WLC_SET_INFRA, 0, 0, NULL},
73 {"antdiv", "rx antenna diversity (0 = antenna 0, 1 = antenna 1, 3 = auto select)", INT, WLC_GET_ANTDIV, WLC_SET_ANTDIV, 0, 3, NULL},
74 {"txant", "set tx antenna (0 = antenna 0, 1 = antenna 1, 3 = rx antenna)", INT, WLC_GET_TXANT, WLC_SET_TXANT, 0, 3, NULL},
75 {"wet", "wireless ethernet bridging mode", BOOL, WLC_GET_WET, WLC_SET_WET, 0, 0, NULL},
76 {"channel", "set channel", INT, WLC_GET_CHANNEL, WLC_SET_CHANNEL, 1, 14, NULL},
77 {NULL, NULL, 0, 0, 0, 0, 0, NULL}
78 };
79
80 void set_int(char *name, int ioctl, int value, int r1, int r2)
81 {
82 if ((value >= r1) || (value <= r2)) {
83 wl_ioctl(name, ioctl, &value, sizeof(value));
84 } else
85 fprintf(stderr, "invalid value.\n");
86 }
87
88 void get_int(char *name, int ioctl)
89 {
90 int value = 0;
91 wl_ioctl(name, ioctl, &value, sizeof(value));
92 printf("%d\n", value);
93 }
94
95 int main(int argc, char **argv)
96 {
97 struct wl_config *cmd;
98 int i;
99
100 _argc = argc;
101 _argv = argv;
102
103 if (argc < 3) {
104 fprintf(stderr, "Usage: %s <interface> <command> [...]\n\n", argv[0]);
105 fprintf(stderr, "Commands:\n\n");
106
107 cmd = commands;
108 while (cmd->name != NULL) {
109 fprintf(stderr, "\t%s", cmd->name);
110 switch (cmd->type) {
111 case INT:
112 fprintf(stderr, " [%d-%d]", cmd->r1, cmd->r2);
113 break;
114 case BOOL:
115 fprintf(stderr, " [0|1]");
116 cmd->r1 = 0;
117 cmd->r2 = 1;
118
119 }
120 fprintf(stderr, "\t%s\n", cmd->desc);
121 cmd++;
122 }
123 fprintf(stderr, "\n");
124
125 return -1;
126 }
127
128 if (wl_probe(argv[1]) < 0) {
129 fprintf(stderr, "No broadcom extensions detected on interface %s\n", argv[1]);
130 return -1;
131 }
132
133 if ((argc > 4) && (strcmp(argv[2], "ioctl") == 0)) {
134 if (strcmp(argv[3], "int") == 0) {
135 int ioctl = atoi(argv[4]);
136 if (argc > 5)
137 i = atoi(argv[5]);
138 else
139 i = 0;
140 fprintf(stderr, "ioctl = 0x%x (%d)\nold value = 0x%x (%d)\n", ioctl, ioctl, i, i);
141 wl_ioctl(argv[1], ioctl, &i, sizeof(i));
142 fprintf(stderr, "new value = 0x%x (%d)\n", i, i);
143 } else if (strcmp(argv[3], "intval") == 0) {
144 i = 0;
145 fprintf(stderr, "var = \"%s\"\nold value = 0x%x (%d)\n", argv[4], i, i);
146 if (argc > 5) {
147 i = atoi(argv[5]);
148 wl_set_val(argv[1], argv[4], &i, sizeof(i));
149 } else {
150 wl_get_val(argv[1], argv[4], &i, sizeof(i));
151 }
152 fprintf(stderr, "new value = 0x%x (%d)\n", i, i);
153 }
154 return 0;
155 }
156 cmd = commands;
157 while (cmd->name != NULL) {
158 if (strcmp(argv[2], cmd->name) == 0) {
159 switch (cmd->type) {
160 case INT:
161 case BOOL:
162 if (argc < 4) {
163 get_int(argv[1], cmd->get);
164 } else {
165 set_int(argv[1], cmd->set, atoi(argv[3]), cmd->r1, cmd->r2);
166 }
167 break;
168 case OTHER: {
169 void (*handler)(void) = cmd->handler;
170 handler();
171 }
172 break;
173 }
174 }
175 cmd++;
176 }
177
178
179 return 0;
180 }
This page took 0.048899 seconds and 5 git commands to generate.