]> git.decadent.org.uk Git - ap-utils.git/blob - lib/ap-utils.h
Imported Upstream version 1.5~pre1
[ap-utils.git] / lib / ap-utils.h
1 /*
2  *    ap-utils.h from Wireless Access Point Utilites for Unix
3  *  Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License Version 2 from
7  * June 1991 as published by the Free Software Foundation.
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with this program; if not, write to the Free Software Foundation, Inc.,
14  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16
17 #ifndef _AP_CNF
18 #define _AP_CNF 1
19
20 #include "config.h"
21
22 #ifdef OS_BSD
23 #include <sys/types.h>
24 #ifdef OS_X
25 #include <stdint.h>
26 #endif /* ifdef OS_X */
27 #else
28 #ifdef OS_SOLARIS
29 #include <sys/types.h>
30 #else
31 #include <features.h>
32 #if defined (__GLIBC__)
33 #include <stdint.h>
34 #else
35 typedef unsigned short uint16_t;
36 typedef unsigned int uint32_t;
37 #endif /* if defined (__GLIBC__) */
38 #endif /* ifdef OS_SOLARIS */
39 #endif /* ifdef OS_BSD */
40
41 #include "ap-curses.h"
42
43 #define TITLE "Wireless Access Point Utilites for Unix"
44 #define VIEW "View: "
45
46 #define minimum(x, y)   x <= y ? x : y
47
48 #ifdef HAVE_GETTEXT
49 /* GNU gettext stuff*/
50 #include <locale.h>
51 #include <libgnuintl.h>
52 #define _(String) gettext (String)
53 #else
54 #define _(String) (String)
55 #endif
56
57 #include <sys/socket.h>
58 #include <netinet/in.h>
59 #include <arpa/inet.h>
60
61
62 #ifdef WORDS_BIGENDIAN
63 /*
64  * a quick-and-dirty macros to unconditionally swap bytes in 2 and 4-byte
65  * integers between big-endian and little-endian ordering
66  */
67 #define swap2(d) ((((d) >> 8) & 0x00ff) | (((d) << 8) & 0xff00))
68 #define swap4(d) ((((d) >> 24) & 0x000000ff) | (((d) >>  8) & 0x0000ff00) | (((d) <<  8) & 0x00ff0000) | (((d) << 24) & 0xff000000))
69 #else
70 #define swap2(d) d
71 #define swap4(d) d
72 #endif
73
74 #define rlong(a)        ((a) = swap4(a))
75 #define wlong(a)        ((a) = swap4(a))
76 #define rshort(a)       ((a) = swap2(a))
77 #define wshort(a)       ((a) = swap2(a))
78
79 #define MAC _("MAC address: ")
80 #define TRAPS _("[S] SNMP traps: ")
81
82 #define CHANNEL _("[C] Frequency channel: ")
83
84 #define ANTENNA_RX _("Receive  antenna:")
85 #define ANTENNA_RX_LEFT  _("[U] Left")
86 #define ANTENNA_RX_RIGHT _("[I] Right")
87 #define ANTENNA_TX _("Transmit antenna:")
88 #define ANTENNA_TX_LEFT  _("[O] Left")
89 #define ANTENNA_TX_RIGHT _("[P] Right")
90 #define ANTENNA_DV _("Diversity select:")
91 #define ANTENNA_DV_LEFT  _("[T] Left")
92 #define ANTENNA_DV_RIGHT _("[Y] Right")
93
94 #define YES _("Yes")
95 #define NO _("No")
96
97 #define ON _("On")
98 #define OFF _("Off")
99
100 #define BASIC _("Basic")
101
102 #define ANY_KEY _("Press any key to continue.")
103 #define QT_HELP _("Q - quit to menu. T - toggle polling mode, Other key - force update.")
104
105 #define ERR_SET _("Unable to write data to AP. Press any key to continue.")
106 #define ERR_RET _("Unable to retrieve (valid) data from AP. Press any key to continue.")
107 #define WAIT_RET _("Trying to retrieve data from AP. Please wait...")
108 #define WAIT_SET _("Writing data to AP. Please wait...")
109 #define DONE_SET _("Configuration written to the AP. Press any key to continue.")
110 #define SELECT _("select() function error. Press any key.")
111
112 #define CREATE_SOCKET_ERROR _("Create socket error. Press any key.")
113 #define BIND_SOCKET_ERROR _("Bind socket error. Press any key.")
114
115 #define MAIN_MENU _("Back to main menu")
116 #define MENU_EXIT _("Exit program")
117 #define MENU_SHELL _("Run subshell. To return type 'exit'.")
118 #define MENU_ABOUT _("Short info about program")
119 #define MENU_SEARCH _("Find connected Access Points")
120 #define MENU_CONNECT _("Set connection options: ip and community")
121 #define MENU_ENCRYPT _("Set encryption; edit WEP keys")
122 #define MENU_MAC _("Set MAC authorization; edit MAC authorization table")
123 #define MENU_COMMUNITY _("Set SNMP community/password for access to the AP")
124 #define MENU_SYSINFO _("Get info about AP hardware and firmware")
125 #define MENU_WIRELESS _("Get wireless port statistics")
126 #define MENU_STAS _("Get list of currently associated stations (Access Point clients)")
127 #define MENU_INFO _("Get info and statistics from AP")
128 #define MENU_CONFIG _("Set various configuration options")
129
130 #define TITLE_STAS _("Associated stations")
131
132 #define POLL_ON _("Polling: on")
133 #define POLL_OFF _("Polling: off")
134
135 #define INT_VALUE       0x02
136 #define STRING_VALUE    0x04
137 #define NULL_VALUE      0x05
138 #define OID_VALUE       0x06
139
140 #define GET             0xA0
141 #define GET_NEXT        0xA1
142 #define RESPONSE        0xA2
143 #define SET             0xA3
144 #define TRAP            0xA4
145
146 #define ASN_HEADER      0x30
147
148 #define INT_STRING      0x01
149 #define HEX_STRING      0x02
150 #define ANY_STRING      0x03
151
152 #define SIZE sizeof(struct sockaddr_in)
153 #define basic(i) (i & 0x80) ? BASIC : (i) ? ON : OFF
154
155
156 #define MCOLS 15 /* width of menu window */
157 #define LAST_ROW LINES-5
158
159 #define WAIT_TIMEOUT 1
160 #define WAIT_FOREVER 0
161
162 /* Basic distinguished MIB (and AP) types */
163 /* Numbering with respect to order in ap_types */
164 #define ATMEL410 0
165 #define NWN 1
166 #define ATMEL12350 2
167
168 /* Vendor distinguished MIB subtypes */
169 /* Numbering with respect to order in ap_vendorexts */
170 #define NONE 0
171 #define SBRIDGES 1
172 #define TELLUS 1
173 #define VERNET 2
174
175 typedef struct {
176     unsigned char *oid;
177     int len_oid;
178     unsigned char *value;
179     int len_val;
180     unsigned char type;
181 } varbind;
182
183 typedef struct {
184     char code;
185     char *desc;
186     unsigned short first_ch;
187     unsigned short chans;
188 } rdprops;
189
190 struct umitems {
191         char *item;
192         char *help;
193         void (*func)();
194         int is_menu;
195 };
196
197 struct EthernetRxStatistics {
198         uint32_t TotalBytesRx;
199         uint32_t TotalPacketsRx;
200         uint32_t PacketCRCErrorRx;
201         uint32_t MulticastPacketRx;
202         uint32_t BroadcastPacketRx;
203         uint32_t ControlFramesRx;
204         uint32_t PauseFramesRx;
205         uint32_t UnknownOPCodeRx;
206         uint32_t AlignmentRxError;
207         uint32_t LengthOutOfRangeRx;
208         uint32_t CodeErrorRx;
209         uint32_t FalseCarrierRx;
210         uint32_t UndersizePacketsRx;
211         uint32_t OversizePacketsRx;
212         uint32_t TotalFragmentsRx;
213         uint32_t TotalJabberRx;
214 };
215
216 struct EthernetTxStatistics {
217         uint32_t TotalBytesTx;
218         uint32_t TotalPacketsTx;
219         uint32_t PacketCRCErrorTx;
220         uint32_t MulticastPacketTx;
221         uint32_t BroadcastPacketTx;
222         uint32_t UnicastPacketTx;
223         uint32_t PauseFramesTx;
224         uint32_t SingleDeferPacketTx;
225         uint32_t MultiDeferPacketsTx;
226         uint32_t SingleCollisionsTx;
227         uint32_t MultiCollisionsTx;
228         uint32_t LateCollisionsTx;
229         uint32_t ExcessiveCollisionTx;
230         uint32_t TotalCollisionsTx;
231 };
232
233 struct WirelessStatistics {
234         uint32_t UnicastTransmittedPackets;
235         uint32_t BroadcastTransmittedPackets;
236         uint32_t MulticastTransmittedPackets;
237         uint32_t TransmittedBeacon;
238         uint32_t TransmittedACK;
239         uint32_t TransmittedRTS;
240         uint32_t TransmittedCTS;
241         uint32_t UnicastReceivedPackets;
242         uint32_t BroadcastReceivedPackets;
243         uint32_t MulticastReceivedPackets;
244         uint32_t ReceivedBeacon;
245         uint32_t ReceivedACK;
246         uint32_t ReceivedRTS;
247         uint32_t ReceivedCTS;
248         uint32_t ACKFailure;
249         uint32_t CTSFailure;
250         uint32_t RetryPackets;
251         uint32_t ReceivedDuplicate;
252         uint32_t FailedPackets;
253         uint32_t AgedPackets;
254         uint32_t FCSError;
255         uint32_t InvalidPLCP;
256         /* following 4 are specific for ATMEL 12350 MIB enhanced by VERNET */
257         uint32_t TransmittedPackets_11Mbps;
258         uint32_t TransmittedPackets_55Mbps;
259         uint32_t TransmittedPackets_2Mbps;
260         uint32_t TransmittedPackets_1Mbps;
261 };
262
263 struct sysDeviceInfo_ATMEL410 {
264     /* sysDeviceInfo OID struct for ATMEL 410 */
265     uint32_t StructVersion;
266     unsigned char MacAddress[6];
267     unsigned short Reserved;
268     uint32_t RegulatoryDomain;
269     uint32_t ProductType;
270     unsigned char OEMName[32];
271     uint32_t OEMID;
272     unsigned char ProductName[32];
273     uint32_t HardwareRevision;
274 };
275
276 struct sysDeviceInfo_ATMEL12350 {
277     /* sysDeviceInfo OID struct for ATMEL 12350 */
278     uint32_t StructVersion;
279     unsigned char MacAddress[6];
280     unsigned char Channel;
281     unsigned char RegulatoryDomain;
282     uint32_t ProductType;
283     unsigned char OEMName[32];
284     uint32_t OEMID;
285     unsigned char ProductName[32];
286     uint32_t HardwareRevision;
287     /* The rest is mostly dormant. */
288     unsigned char PID_VID[4];
289     uint32_t sysOIDSize;
290     uint16_t sysOID[16];
291     unsigned char CountryCode[3];
292     unsigned char Reserved1;
293     uint16_t ChannelInformation;
294     unsigned char Reserved2[2];
295     unsigned char TxPower[14];
296     unsigned char Reserved3[10];
297 };
298
299 struct MacListStat {
300     unsigned char addr[6];
301     struct MacListStat *next;
302     int quality;
303     int idle;
304     int rssi;
305     unsigned char  Status;
306     unsigned char  Port;
307     unsigned char  ParentMacAddress[6];
308     struct in_addr IP;
309 };
310
311 /* function prototypes specific/common for both utilites */
312
313 /* service */
314 extern char * oui2manufacturer(char *);
315 extern int  regdom_idx(char);
316 extern int  ch_list(int, char **);
317 extern void connect_options(unsigned long int, int);
318 extern int  get_mib_details(void);
319 extern void about(void);
320 extern void draw_menu_win(void);
321 extern void main_menu(void);
322 extern void print_bold(WINDOW *, char *);
323 extern void print_menusel(int, int, char *, char *);
324 extern void print_bottom(char *);
325 extern void print_top(char *, char *);
326 extern void print_top_rssi(char *);
327 extern void print_help(char *);
328 extern void print_helperr(char *);
329 extern void clear_main(int);
330 extern void clear_main_new(int, int);
331 extern int  conv_rssi(int);
332 extern void get_mac(char *, int, int);
333 extern void get_ip(struct in_addr *, int, int, char *);
334 extern void get_mask(struct in_addr *, int, int, char *);
335 extern void get_value(char *, int, int, int, char, unsigned int, unsigned int,
336                       char *);
337 extern void get_pass(char *, int, int, int);
338 extern int  yes_no(int, int);
339 extern int  on_off(int, int);
340 extern int  menu_choose(int, int, char **, unsigned int);
341 extern int  wait_key(void);
342 extern int  help_ysn(void);
343 extern void scroll_rows(struct MacListStat *, int, int, int, int);
344 extern void exit_shell(void);
345 extern void exit_program(void);
346 extern int  get_opts(void);
347 extern void save_Stations(struct MacListStat *);
348 extern void uni_menu(struct umitems *umenu, int num);
349
350 /* AP */
351 extern void AuthorizedSettings(void);
352 extern void bridging(void);
353 extern void wep(void);
354 extern void WirelessStat(void);
355 extern void atmel_stations(void);
356 extern void atmel_sysinfo(void);
357 extern void atmel_set_oeminfo(void);
358 extern void ap_search(void);
359
360 /* snmp engine*/
361 extern int snmp(varbind *, int, int);
362 extern int ber(char *, varbind *, int, int);
363 /* extern unsigned int ber_decode_uint(unsigned char *, int); */
364
365 /* function prototypes specific for ATMEL utility */
366 extern void reset(void);
367 extern void defaults(void);
368 extern void upload(void);
369 extern int  SysUpload(void);
370 extern int  SysReset(void);
371 extern void EthStat(void);
372 extern void APs(void);
373 extern void power(void);
374 extern void test(void);
375 extern void atmel_wireless(void);
376 extern void atmel_auth_mac(void);
377
378 /* function prototypes specific for NWN utility */
379 extern void latest(void);
380 extern int  get_RegDomain(void);
381 extern void advanced(void);
382 extern void command_menu(void);
383 extern void nwn_sysinfo(void);
384 extern void nwn_wep(void);
385 extern void nwn_stations(void);
386 extern void nwn_wireless_stat(void);
387 extern void nwn_wireless(void);
388 extern void nwn_auth_mac(void);
389
390 #endif