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 #define dbmconv(x) (ap_type == ATMEL410 && ap_vendorext == SBRIDGES) ? \
80 (int)(-95 + x * (float)2.125) : -96 + x
82 #define MAC _("MAC address: ")
83 #define TRAPS _("[S] SNMP traps: ")
85 #define CHANNEL _("[C] Frequency channel: ")
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")
103 #define BASIC _("Basic")
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")
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.")
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.")
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")
136 #define ST_TITLE _("Associated stations")
137 #define AP_TITLE _("AP Client link state")
139 #define POLL_ON _("Polling: on")
140 #define POLL_OFF _("Polling: off")
142 #define INT_VALUE 0x02
143 #define STRING_VALUE 0x04
144 #define NULL_VALUE 0x05
145 #define OID_VALUE 0x06
148 #define GET_NEXT 0xA1
149 #define RESPONSE 0xA2
153 #define ASN_HEADER 0x30
155 #define INT_STRING 0x01
156 #define HEX_STRING 0x02
157 #define ANY_STRING 0x03
159 #define SIZE sizeof(struct sockaddr_in)
160 #define basic(i) (i & 0x80) ? BASIC : (i) ? ON : OFF
163 #define MCOLS 15 /* width of menu window */
164 #define LAST_ROW LINES-5
166 #define WAIT_TIMEOUT 1
167 #define WAIT_FOREVER 0
169 /* Basic distinguished MIB (and AP) types */
170 /* Numbering with respect to order in ap_types */
175 /* Vendor distinguished MIB subtypes */
176 /* Numbering with respect to order in ap_vendorexts */
185 unsigned char *value;
193 unsigned short first_ch;
194 unsigned short chans;
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;
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;
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;
257 uint32_t RetryPackets;
258 uint32_t ReceivedDuplicate;
259 uint32_t FailedPackets;
260 uint32_t AgedPackets;
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;
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];
279 unsigned char ProductName[32];
280 uint32_t HardwareRevision;
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.).
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];
298 unsigned char ProductName[32];
299 uint32_t HardwareRevision;
300 /* The rest is mostly dormant. */
301 unsigned char PID_VID[4];
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];
312 /* AP mode: Associated stations diagnostics */
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;
320 unsigned char ParentMacAddress[6];
322 unsigned char LinkQuality;
324 unsigned char Reserved1[2];
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;
333 unsigned char ParentMacAddress[6];
336 unsigned char Reserved1[3];
339 /* This structure unifies all the unique members of the 2 structs above */
341 unsigned char addr[6];
342 struct MacListStat *next;
346 unsigned char Status;
348 unsigned char ParentMacAddress[6];
352 /* APClient mode: AP link diagnostics */
355 struct NetworkSettings_ATMEL410_SBRIDGES {
356 unsigned short reserved1;
357 unsigned char BSSID[6];
358 unsigned short InfoCapability;
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;
369 struct NetworkSettings_ATMEL12350_EZYNET {
370 unsigned short reserved1;
371 unsigned char BSSID[6];
372 unsigned short InfoCapability;
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;
382 /* function prototypes specific/common for both utilites */
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,
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);
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);
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); */
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);
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);