2 * ap-utils.h from Wireless Access Point Utilites for Unix
3 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
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
23 #include <sys/types.h>
26 #endif /* ifdef OS_X */
29 #include <sys/types.h>
32 #if defined (__GLIBC__)
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 */
41 #include "ap-curses.h"
43 #define TITLE "Wireless Access Point Utilites for Unix"
46 #define minimum(x, y) x <= y ? x : y
49 /* GNU gettext stuff*/
51 #include <libgnuintl.h>
52 #define _(String) gettext (String)
54 #define _(String) (String)
57 #include <sys/socket.h>
58 #include <netinet/in.h>
59 #include <arpa/inet.h>
62 #ifdef WORDS_BIGENDIAN
64 * a quick-and-dirty macros to unconditionally swap bytes in 2 and 4-byte
65 * integers between big-endian and little-endian ordering
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))
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))
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 */
83 #define dbmconv(x) -96 + x
85 #define MAC _("MAC address: ")
86 #define TRAPS _("[S] SNMP traps: ")
88 #define CHANNEL _("[C] Frequency channel: ")
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")
106 #define BASIC _("Basic")
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")
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.")
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.")
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")
139 #define ST_TITLE _("Associated stations")
140 #define AP_TITLE _("AP Client link state")
142 #define POLL_ON _("Polling: on")
143 #define POLL_OFF _("Polling: off")
145 #define INT_VALUE 0x02
146 #define STRING_VALUE 0x04
147 #define NULL_VALUE 0x05
148 #define OID_VALUE 0x06
151 #define GET_NEXT 0xA1
152 #define RESPONSE 0xA2
156 #define ASN_HEADER 0x30
158 #define INT_STRING 0x01
159 #define HEX_STRING 0x02
160 #define ANY_STRING 0x03
162 #define SIZE sizeof(struct sockaddr_in)
163 #define basic(i) (i & 0x80) ? BASIC : (i) ? ON : OFF
166 #define MCOLS 15 /* width of menu window */
167 #define LAST_ROW LINES-5
169 #define WAIT_TIMEOUT 1
170 #define WAIT_FOREVER 0
172 /* Basic distinguished MIB (and AP) types */
173 /* Numbering with respect to order in ap_types */
178 /* Vendor distinguished MIB subtypes */
179 /* Numbering with respect to order in ap_vendorexts */
188 unsigned char *value;
196 unsigned short first_ch;
197 unsigned short chans;
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;
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;
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;
260 uint32_t RetryPackets;
261 uint32_t ReceivedDuplicate;
262 uint32_t FailedPackets;
263 uint32_t AgedPackets;
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;
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];
282 unsigned char ProductName[32];
283 uint32_t HardwareRevision;
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.).
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];
301 unsigned char ProductName[32];
302 uint32_t HardwareRevision;
303 /* The rest is mostly dormant. */
304 unsigned char PID_VID[4];
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];
315 /* AP mode: Associated stations diagnostics */
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;
323 unsigned char ParentMacAddress[6];
325 unsigned char LinkQuality;
327 unsigned char Reserved1[2];
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;
336 unsigned char ParentMacAddress[6];
339 unsigned char Reserved1[3];
342 /* This structure unifies all the unique members of the 2 structs above */
344 unsigned char addr[6];
345 struct MacListStat *next;
349 unsigned char Status;
351 unsigned char ParentMacAddress[6];
355 /* APClient mode: AP link diagnostics */
358 struct NetworkSettings_ATMEL410_SBRIDGES {
359 unsigned short reserved1;
360 unsigned char BSSID[6];
361 unsigned short InfoCapability;
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;
372 struct NetworkSettings_ATMEL12350_EZYNET {
373 unsigned short reserved1;
374 unsigned char BSSID[6];
375 unsigned short InfoCapability;
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;
385 /* function prototypes specific/common for both utilites */
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,
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);
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);
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); */
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);
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);