]> git.decadent.org.uk Git - ap-utils.git/blob - lib/ap-utils.h
Imported Upstream version 1.5
[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 dbmconv(x)      (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ? \
80                             (int)(-95 + x * (float)2.125) : -96 + x
81
82 #define MAC _("MAC address: ")
83 #define TRAPS _("[S] SNMP traps: ")
84
85 #define CHANNEL _("[C] Frequency channel: ")
86
87 #define ANTENNA_RX _("Receive  antenna:")
88 #define ANTENNA_RX_LEFT  _("[U] Left")
89 #define ANTENNA_RX_RIGHT _("[I] Right")
90 #define ANTENNA_TX _("Transmit antenna:")
91 #define ANTENNA_TX_LEFT  _("[O] Left")
92 #define ANTENNA_TX_RIGHT _("[P] Right")
93 #define ANTENNA_DV _("Diversity select:")
94 #define ANTENNA_DV_LEFT  _("[T] Left")
95 #define ANTENNA_DV_RIGHT _("[Y] Right")
96
97 #define YES _("Yes")
98 #define NO _("No")
99
100 #define ON _("On")
101 #define OFF _("Off")
102
103 #define BASIC _("Basic")
104
105 #define ANY_KEY _("Press any key to continue.")
106 #define QT_HELP _("Q - quit to menu. T - toggle polling mode, Other key - force update")
107
108 #define ERR_SET _("Unable to write data to AP. Press any key to continue.")
109 #define ERR_RET _("Unable to retrieve (valid) data from AP. Press any key to continue.")
110 #define WAIT_RET _("Trying to retrieve data from AP - please wait (or press Q to quit).")
111 #define WAIT_SET _("Writing data to AP. Please wait...")
112 #define DONE_SET _("Configuration written to the AP. Press any key to continue.")
113 #define ERR_SELECT _("select() function error. Press any key.")
114 #define ERR_SOCKET _("socket() or bind() function error. Press any key.")
115
116 #define ERR_WRITING_APCONF _("Unable to write AP list file ~/.ap-config. Press any key.")
117 #define DONE_WRITING_APCONF _("AP list file ~/.ap-config successfully written. Press any key.")
118
119 #define MAIN_MENU _("Back to main menu")
120 #define MENU_EXIT _("Exit program")
121 #define MENU_SHELL _("Run subshell. To return type 'exit'.")
122 #define MENU_POLLING _("Change polling mode interval")
123 #define MENU_ABOUT _("Short info about program")
124 #define MENU_SEARCH _("Find connected Access Points")
125 #define MENU_CONNECT _("Set connection options: ip and community")
126 #define MENU_ENCRYPT _("Set encryption; edit WEP keys")
127 #define MENU_AUTH _("Set authorization; edit MAC authorization table")
128 #define MENU_COMMUNITY _("Set SNMP community/password for access to the AP")
129 #define MENU_SYSINFO _("Get info about AP hardware and firmware")
130 #define MENU_WIRELESS _("Get wireless port statistics")
131 #define MENU_STAS _("Get list of currently associated stations (Access Point clients)")
132 #define MENU_APLINK _("Get link status in APclient mode")
133 #define MENU_INFO _("Get info and statistics from AP")
134 #define MENU_CONFIG _("Set various configuration options")
135
136 #define ST_TITLE _("Associated stations")
137 #define AP_TITLE _("AP Client link state")
138
139 #define POLL_ON _("Polling: on")
140 #define POLL_OFF _("Polling: off")
141
142 #define INT_VALUE       0x02
143 #define STRING_VALUE    0x04
144 #define NULL_VALUE      0x05
145 #define OID_VALUE       0x06
146
147 #define GET             0xA0
148 #define GET_NEXT        0xA1
149 #define RESPONSE        0xA2
150 #define SET             0xA3
151 #define TRAP            0xA4
152
153 #define ASN_HEADER      0x30
154
155 #define INT_STRING      0x01
156 #define HEX_STRING      0x02
157 #define ANY_STRING      0x03
158
159 #define SIZE sizeof(struct sockaddr_in)
160 #define basic(i) (i & 0x80) ? BASIC : (i) ? ON : OFF
161
162
163 #define MCOLS 15 /* width of menu window */
164 #define LAST_ROW LINES-5
165
166 #define WAIT_TIMEOUT 1
167 #define WAIT_FOREVER 0
168
169 /* Basic distinguished MIB (and AP) types */
170 /* Numbering with respect to order in ap_types */
171 #define ATMEL410 0
172 #define NWN 1
173 #define ATMEL12350 2
174
175 /* Vendor distinguished MIB subtypes */
176 /* Numbering with respect to order in ap_vendorexts */
177 #define NONE 0
178 #define SBRIDGES 1
179 #define GEMTEK 1
180 #define EZYNET 2
181
182 typedef struct {
183     unsigned char *oid;
184     int len_oid;
185     unsigned char *value;
186     int len_val;
187     unsigned char type;
188 } varbind;
189
190 typedef struct {
191     char code;
192     char *desc;
193     unsigned short first_ch;
194     unsigned short chans;
195 } rdprops;
196
197 struct umitems {
198         char *item;
199         char *help;
200         void (*func)();
201         int is_menu;
202 };
203
204 struct EthRxStatistics_s {
205         uint32_t TotalBytesRx;
206         uint32_t TotalPacketsRx;
207         uint32_t PacketCRCErrorRx;
208         uint32_t MulticastPacketRx;
209         uint32_t BroadcastPacketRx;
210         uint32_t ControlFramesRx;
211         uint32_t PauseFramesRx;
212         uint32_t UnknownOPCodeRx;
213         uint32_t AlignmentRxError;
214         uint32_t LengthOutOfRangeRx;
215         uint32_t CodeErrorRx;
216         uint32_t FalseCarrierRx;
217         uint32_t UndersizePacketsRx;
218         uint32_t OversizePacketsRx;
219         uint32_t TotalFragmentsRx;
220         uint32_t TotalJabberRx;
221 };
222
223 struct EthTxStatistics_s {
224         uint32_t TotalBytesTx;
225         uint32_t TotalPacketsTx;
226         uint32_t PacketCRCErrorTx;
227         uint32_t MulticastPacketTx;
228         uint32_t BroadcastPacketTx;
229         uint32_t UnicastPacketTx;
230         uint32_t PauseFramesTx;
231         uint32_t SingleDeferPacketTx;
232         uint32_t MultiDeferPacketsTx;
233         uint32_t SingleCollisionsTx;
234         uint32_t MultiCollisionsTx;
235         uint32_t LateCollisionsTx;
236         uint32_t ExcessiveCollisionTx;
237         uint32_t TotalCollisionsTx;
238 };
239
240 struct wirelessStatistics_s {
241         uint32_t UnicastTransmittedPackets;
242         uint32_t BroadcastTransmittedPackets;
243         uint32_t MulticastTransmittedPackets;
244         uint32_t TransmittedBeacon;
245         uint32_t TransmittedACK;
246         uint32_t TransmittedRTS;
247         uint32_t TransmittedCTS;
248         uint32_t UnicastReceivedPackets;
249         uint32_t BroadcastReceivedPackets;
250         uint32_t MulticastReceivedPackets;
251         uint32_t ReceivedBeacon;
252         uint32_t ReceivedACK;
253         uint32_t ReceivedRTS;
254         uint32_t ReceivedCTS;
255         uint32_t ACKFailure;
256         uint32_t CTSFailure;
257         uint32_t RetryPackets;
258         uint32_t ReceivedDuplicate;
259         uint32_t FailedPackets;
260         uint32_t AgedPackets;
261         uint32_t FCSError;
262         uint32_t InvalidPLCP;
263         /* following 4 are specific for ATMEL 12350 MIB enhanced by EZYNET */
264         uint32_t TransmittedPackets_11Mbps;
265         uint32_t TransmittedPackets_55Mbps;
266         uint32_t TransmittedPackets_2Mbps;
267         uint32_t TransmittedPackets_1Mbps;
268 };
269
270 struct sysDeviceInfo_128 {
271     /* sysDeviceInfo OID struct - version 128 bytes long */
272     uint32_t StructVersion;
273     unsigned char MacAddress[6];
274     unsigned short Reserved;
275     uint32_t RegulatoryDomain;
276     uint32_t ProductType;
277     unsigned char OEMName[32];
278     uint32_t OEMID;
279     unsigned char ProductName[32];
280     uint32_t HardwareRevision;
281     /*
282      * NOTE: Although MIBs claim 92 bytes length, it does not need to be true.
283      * 92 bytes seems to be just the 'official' part; the unofficial
284      * (and undocumented) remnant padding the total length to 128 bytes
285      * may or may not eventually appear (resulting in returned length 128 b.).
286      */
287 };
288
289 struct sysDeviceInfo_160 {
290     /* sysDeviceInfo OID struct - version 160 bytes long */
291     uint32_t StructVersion;
292     unsigned char MacAddress[6];
293     unsigned char Channel;
294     unsigned char RegulatoryDomain;
295     uint32_t ProductType;
296     unsigned char OEMName[32];
297     uint32_t OEMID;
298     unsigned char ProductName[32];
299     uint32_t HardwareRevision;
300     /* The rest is mostly dormant. */
301     unsigned char PID_VID[4];
302     uint32_t sysOIDSize;
303     uint16_t sysOID[16];
304     unsigned char CountryCode[3];
305     unsigned char Reserved1;
306     uint16_t ChannelInformation;
307     unsigned char Reserved2[2];
308     unsigned char TxPower[14];
309     unsigned char Reserved3[10];
310 };
311
312 /* AP mode: Associated stations diagnostics */
313
314 struct AssociatedSTAsInfo_ATMEL410 {
315     unsigned short Index;
316     unsigned char  MacAddress[6];
317     /* The rest is only supported by ATMEL410 SBRIDGES MIB */
318     unsigned char  Status;
319     unsigned char  Port;
320     unsigned char  ParentMacAddress[6];
321     unsigned char  RSSI;
322     unsigned char  LinkQuality;
323     unsigned char  IP[4];
324     unsigned char  Reserved1[2];
325 };
326
327 struct AssociatedSTAsInfo_ATMEL12350 {
328     unsigned short Index;
329     unsigned char  MacAddress[6];
330     /* The rest is only supported by ATMEL12350 EZYNET MIB */
331     unsigned char  Status;
332     unsigned char  Port;
333     unsigned char  ParentMacAddress[6];
334     unsigned char  RSSI;
335     unsigned char  IP[4];
336     unsigned char  Reserved1[3];
337 };
338
339 /* This structure unifies all the unique members of the 2 structs above */
340 struct MacListStat {
341     unsigned char addr[6];
342     struct MacListStat *next;
343     int quality;
344     int idle;
345     int rssi;
346     unsigned char  Status;
347     unsigned char  Port;
348     unsigned char  ParentMacAddress[6];
349     struct in_addr IP;
350 };
351
352 /* APClient mode: AP link diagnostics */
353
354 /* size: 53 bytes */
355 struct NetworkSettings_ATMEL410_SBRIDGES {
356     unsigned short reserved1;
357     unsigned char BSSID[6];
358     unsigned short InfoCapability;
359     unsigned char Rssi;
360     unsigned char Channel;
361     unsigned char reserved2[2];
362     unsigned char LinkQuality;
363     unsigned char reserved3[5];
364     unsigned char ESSID[32];
365     unsigned char ESSLEN;
366 };
367
368 /* size: 56 bytes */
369 struct NetworkSettings_ATMEL12350_EZYNET {
370     unsigned short reserved1;
371     unsigned char BSSID[6];
372     unsigned short InfoCapability;
373     unsigned char Rssi;
374     unsigned char Channel;
375     unsigned char reserved2[2];
376     unsigned char CurrentRate;
377     unsigned char reserved3[5];
378     unsigned char ESSID[32];
379     unsigned long ESSLEN;
380 };
381
382 /* function prototypes specific/common for both utilites */
383
384 /* service */
385 extern char * oui2manufacturer(char *);
386 extern int  regdom_idx(char);
387 extern int  ch_list(int, char **);
388 extern void connect_options(unsigned long int, int);
389 extern int  get_mib_details(void);
390 extern void about(void);
391 extern void draw_menu_win(void);
392 extern void main_menu(void);
393 extern void print_bold(WINDOW *, char *);
394 extern void print_menusel(int, int, char *, char *);
395 extern void print_bottom(char *);
396 extern void print_top(char *, char *);
397 extern void print_top_rssi(char *);
398 extern void print_help(char *);
399 extern void print_helperr(char *);
400 extern void clear_main(int);
401 extern void clear_main_new(int, int);
402 extern int  conv_rssi(int);
403 extern void get_mac(char *, int, int);
404 extern void get_ip(struct in_addr *, int, int, char *);
405 extern void get_mask(struct in_addr *, int, int, char *);
406 extern void get_value(char *, int, int, int, char, unsigned int, unsigned int,
407                       char *);
408 extern void get_pass(char *, int, int, int);
409 extern int  yes_no(int, int);
410 extern int  on_off(int, int);
411 extern int  menu_choose(int, int, char **, unsigned int);
412 extern int  wait_key(int);
413 extern int  help_ysn(void);
414 extern void scroll_rows(struct MacListStat *, int, int, int, int);
415 extern void exit_shell(void);
416 extern void exit_program(void);
417 extern void polling_interval(void);
418 extern int  get_opts(void);
419 extern void save_Stations(struct MacListStat *);
420 extern void uni_menu(struct umitems *umenu, int num);
421
422 /* AP */
423 extern void AuthorizedSettings(void);
424 extern void bridging(void);
425 extern void wep(void);
426 extern void WirelessStat(void);
427 extern void atmel_stations(void);
428 extern void atmel_aplink(void);
429 extern void atmel_sysinfo(void);
430 extern void atmel_set_oeminfo(void);
431 extern void ap_search(void);
432
433 /* snmp engine*/
434 extern void close_sockfd(void);
435 extern int  open_sockfd(void);
436 extern int  reopen_sockfd(void);
437 extern int snmp(varbind *, int, int);
438 extern int ber(char *, varbind *, int, int);
439 /* extern unsigned int ber_decode_uint(unsigned char *, int); */
440
441 /* function prototypes specific for ATMEL utility */
442 extern void reset(void);
443 extern void defaults(void);
444 extern void upload(void);
445 extern int  SysUpload(void);
446 extern int  SysReset(void);
447 extern void EthStat(void);
448 extern void APs(void);
449 extern void power(void);
450 extern void test(void);
451 extern void atmel_wireless(void);
452 extern void atmel_auth(void);
453
454 /* function prototypes specific for NWN utility */
455 extern void latest(void);
456 extern int  get_RegDomain(void);
457 extern void advanced(void);
458 extern void command_menu(void);
459 extern void nwn_sysinfo(void);
460 extern void nwn_wep(void);
461 extern void nwn_stations(void);
462 extern void nwn_wireless_stat(void);
463 extern void nwn_wireless(void);
464 extern void nwn_auth_mac(void);
465
466 #endif