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