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 MAC _("MAC address: ")
80 #define TRAPS _("[S] SNMP traps: ")
82 #define CHANNEL _("[C] Frequency channel: ")
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")
100 #define BASIC _("Basic")
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.")
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 ERR_SELECT _("select() function error. Press any key.")
112 #define ERR_CREATING_SOCKET _("Create socket error. Press any key.")
113 #define ERR_BINDING_SOCKET _("Bind socket error. Press any key.")
115 #define ERR_WRITING_APCONF _("Unable to write AP list file ~/.ap-config. Press any key.")
116 #define DONE_WRITING_APCONF _("AP list file ~/.ap-config successfully written. Press any key.")
118 #define MAIN_MENU _("Back to main menu")
119 #define MENU_EXIT _("Exit program")
120 #define MENU_SHELL _("Run subshell. To return type 'exit'.")
121 #define MENU_ABOUT _("Short info about program")
122 #define MENU_SEARCH _("Find connected Access Points")
123 #define MENU_CONNECT _("Set connection options: ip and community")
124 #define MENU_ENCRYPT _("Set encryption; edit WEP keys")
125 #define MENU_AUTH _("Set authorization; edit MAC authorization table")
126 #define MENU_COMMUNITY _("Set SNMP community/password for access to the AP")
127 #define MENU_SYSINFO _("Get info about AP hardware and firmware")
128 #define MENU_WIRELESS _("Get wireless port statistics")
129 #define MENU_STAS _("Get list of currently associated stations (Access Point clients)")
130 #define MENU_APLINK _("Get link status in APclient mode")
131 #define MENU_INFO _("Get info and statistics from AP")
132 #define MENU_CONFIG _("Set various configuration options")
134 #define ST_TITLE _("Associated stations")
135 #define AP_TITLE _("AP Client link state")
137 #define POLL_ON _("Polling: on")
138 #define POLL_OFF _("Polling: off")
140 #define INT_VALUE 0x02
141 #define STRING_VALUE 0x04
142 #define NULL_VALUE 0x05
143 #define OID_VALUE 0x06
146 #define GET_NEXT 0xA1
147 #define RESPONSE 0xA2
151 #define ASN_HEADER 0x30
153 #define INT_STRING 0x01
154 #define HEX_STRING 0x02
155 #define ANY_STRING 0x03
157 #define SIZE sizeof(struct sockaddr_in)
158 #define basic(i) (i & 0x80) ? BASIC : (i) ? ON : OFF
161 #define MCOLS 15 /* width of menu window */
162 #define LAST_ROW LINES-5
164 #define WAIT_TIMEOUT 1
165 #define WAIT_FOREVER 0
167 /* Basic distinguished MIB (and AP) types */
168 /* Numbering with respect to order in ap_types */
173 /* Vendor distinguished MIB subtypes */
174 /* Numbering with respect to order in ap_vendorexts */
183 unsigned char *value;
191 unsigned short first_ch;
192 unsigned short chans;
202 struct EthRxStatistics_s {
203 uint32_t TotalBytesRx;
204 uint32_t TotalPacketsRx;
205 uint32_t PacketCRCErrorRx;
206 uint32_t MulticastPacketRx;
207 uint32_t BroadcastPacketRx;
208 uint32_t ControlFramesRx;
209 uint32_t PauseFramesRx;
210 uint32_t UnknownOPCodeRx;
211 uint32_t AlignmentRxError;
212 uint32_t LengthOutOfRangeRx;
213 uint32_t CodeErrorRx;
214 uint32_t FalseCarrierRx;
215 uint32_t UndersizePacketsRx;
216 uint32_t OversizePacketsRx;
217 uint32_t TotalFragmentsRx;
218 uint32_t TotalJabberRx;
221 struct EthTxStatistics_s {
222 uint32_t TotalBytesTx;
223 uint32_t TotalPacketsTx;
224 uint32_t PacketCRCErrorTx;
225 uint32_t MulticastPacketTx;
226 uint32_t BroadcastPacketTx;
227 uint32_t UnicastPacketTx;
228 uint32_t PauseFramesTx;
229 uint32_t SingleDeferPacketTx;
230 uint32_t MultiDeferPacketsTx;
231 uint32_t SingleCollisionsTx;
232 uint32_t MultiCollisionsTx;
233 uint32_t LateCollisionsTx;
234 uint32_t ExcessiveCollisionTx;
235 uint32_t TotalCollisionsTx;
238 struct wirelessStatistics_s {
239 uint32_t UnicastTransmittedPackets;
240 uint32_t BroadcastTransmittedPackets;
241 uint32_t MulticastTransmittedPackets;
242 uint32_t TransmittedBeacon;
243 uint32_t TransmittedACK;
244 uint32_t TransmittedRTS;
245 uint32_t TransmittedCTS;
246 uint32_t UnicastReceivedPackets;
247 uint32_t BroadcastReceivedPackets;
248 uint32_t MulticastReceivedPackets;
249 uint32_t ReceivedBeacon;
250 uint32_t ReceivedACK;
251 uint32_t ReceivedRTS;
252 uint32_t ReceivedCTS;
255 uint32_t RetryPackets;
256 uint32_t ReceivedDuplicate;
257 uint32_t FailedPackets;
258 uint32_t AgedPackets;
260 uint32_t InvalidPLCP;
261 /* following 4 are specific for ATMEL 12350 MIB enhanced by EZYNET */
262 uint32_t TransmittedPackets_11Mbps;
263 uint32_t TransmittedPackets_55Mbps;
264 uint32_t TransmittedPackets_2Mbps;
265 uint32_t TransmittedPackets_1Mbps;
268 struct sysDeviceInfo_128 {
269 /* sysDeviceInfo OID struct - version 128 bytes long */
270 uint32_t StructVersion;
271 unsigned char MacAddress[6];
272 unsigned short Reserved;
273 uint32_t RegulatoryDomain;
274 uint32_t ProductType;
275 unsigned char OEMName[32];
277 unsigned char ProductName[32];
278 uint32_t HardwareRevision;
280 * NOTE: Although MIBs claim 92 bytes length, it is not true.
281 * 92 bytes seems to be just the 'official' part; the unofficial
282 * (and undocumented) remnant just padds it to the total length of
284 * TODO: find out the structure.
288 struct sysDeviceInfo_160 {
289 /* sysDeviceInfo OID struct - version 160 bytes long */
290 uint32_t StructVersion;
291 unsigned char MacAddress[6];
292 unsigned char Channel;
293 unsigned char RegulatoryDomain;
294 uint32_t ProductType;
295 unsigned char OEMName[32];
297 unsigned char ProductName[32];
298 uint32_t HardwareRevision;
299 /* The rest is mostly dormant. */
300 unsigned char PID_VID[4];
303 unsigned char CountryCode[3];
304 unsigned char Reserved1;
305 uint16_t ChannelInformation;
306 unsigned char Reserved2[2];
307 unsigned char TxPower[14];
308 unsigned char Reserved3[10];
311 /* AP mode: Associated stations diagnostics */
313 struct AssociatedSTAsInfo_ATMEL410 {
314 unsigned short Index;
315 unsigned char MacAddress[6];
316 /* The rest is only supported by ATMEL410 SBRIDGES MIB */
317 unsigned char Status;
319 unsigned char ParentMacAddress[6];
321 unsigned char LinkQuality;
323 unsigned char Reserved1[2];
326 struct AssociatedSTAsInfo_ATMEL12350 {
327 unsigned short Index;
328 unsigned char MacAddress[6];
329 /* The rest is only supported by ATMEL12350 EZYNET MIB */
330 unsigned char Status;
332 unsigned char ParentMacAddress[6];
335 unsigned char Reserved1[3];
338 /* This structure unifies all the unique members of the 2 structs above */
340 unsigned char addr[6];
341 struct MacListStat *next;
345 unsigned char Status;
347 unsigned char ParentMacAddress[6];
351 /* APClient mode: AP link diagnostics */
354 struct NetworkSettings_ATMEL410_SBRIDGES {
355 unsigned short reserved1;
356 unsigned char BSSID[6];
357 unsigned short InfoCapability;
359 unsigned char Channel;
360 unsigned char reserved2[2];
361 unsigned char LinkQuality;
362 unsigned char reserved3[5];
363 unsigned char ESSID[32];
364 unsigned char ESSLEN;
368 struct NetworkSettings_ATMEL12350_EZYNET {
369 unsigned short reserved1;
370 unsigned char BSSID[6];
371 unsigned short InfoCapability;
373 unsigned char Channel;
374 unsigned char reserved2[2];
375 unsigned char CurrentRate;
376 unsigned char reserved3[5];
377 unsigned char ESSID[32];
378 unsigned long ESSLEN;
381 /* function prototypes specific/common for both utilites */
384 extern char * oui2manufacturer(char *);
385 extern int regdom_idx(char);
386 extern int ch_list(int, char **);
387 extern void connect_options(unsigned long int, int);
388 extern int get_mib_details(void);
389 extern void about(void);
390 extern void draw_menu_win(void);
391 extern void main_menu(void);
392 extern void print_bold(WINDOW *, char *);
393 extern void print_menusel(int, int, char *, char *);
394 extern void print_bottom(char *);
395 extern void print_top(char *, char *);
396 extern void print_top_rssi(char *);
397 extern void print_help(char *);
398 extern void print_helperr(char *);
399 extern void clear_main(int);
400 extern void clear_main_new(int, int);
401 extern int conv_rssi(int);
402 extern void get_mac(char *, int, int);
403 extern void get_ip(struct in_addr *, int, int, char *);
404 extern void get_mask(struct in_addr *, int, int, char *);
405 extern void get_value(char *, int, int, int, char, unsigned int, unsigned int,
407 extern void get_pass(char *, int, int, int);
408 extern int yes_no(int, int);
409 extern int on_off(int, int);
410 extern int menu_choose(int, int, char **, unsigned int);
411 extern int wait_key(void);
412 extern int help_ysn(void);
413 extern void scroll_rows(struct MacListStat *, int, int, int, int);
414 extern void exit_shell(void);
415 extern void exit_program(void);
416 extern int get_opts(void);
417 extern void save_Stations(struct MacListStat *);
418 extern void uni_menu(struct umitems *umenu, int num);
421 extern void AuthorizedSettings(void);
422 extern void bridging(void);
423 extern void wep(void);
424 extern void WirelessStat(void);
425 extern void atmel_stations(void);
426 extern void atmel_aplink(void);
427 extern void atmel_sysinfo(void);
428 extern void atmel_set_oeminfo(void);
429 extern void ap_search(void);
432 extern int snmp(varbind *, int, int);
433 extern int ber(char *, varbind *, int, int);
434 /* extern unsigned int ber_decode_uint(unsigned char *, int); */
436 /* function prototypes specific for ATMEL utility */
437 extern void reset(void);
438 extern void defaults(void);
439 extern void upload(void);
440 extern int SysUpload(void);
441 extern int SysReset(void);
442 extern void EthStat(void);
443 extern void APs(void);
444 extern void power(void);
445 extern void test(void);
446 extern void atmel_wireless(void);
447 extern void atmel_auth(void);
449 /* function prototypes specific for NWN utility */
450 extern void latest(void);
451 extern int get_RegDomain(void);
452 extern void advanced(void);
453 extern void command_menu(void);
454 extern void nwn_sysinfo(void);
455 extern void nwn_wep(void);
456 extern void nwn_stations(void);
457 extern void nwn_wireless_stat(void);
458 extern void nwn_wireless(void);
459 extern void nwn_auth_mac(void);