// $Id: util.h,v 1.27 2014/05/21 20:05:57 lpoulsen Exp $
// Copyright (C) 2001 Wi_LAN Technologies, Inc
//
// $Log: util.h,v $
// Revision 1.27  2014/05/21 20:05:57  lpoulsen
// uint32 is not long anymore, so remove long qualifiers in printf formats
//
// Revision 1.26  2011/10/07 00:52:46  lpoulsen
// On Windows, use the ntohs() and ntohl() from winsock.
//
// Revision 1.25  2011/08/29 22:29:27  lpoulsen
// Clean compilation on FC3 linux.
//
// Revision 1.24  2011/05/09 19:32:27  lpoulsen
// Reject device range (1-7) where a single radio is required
//
// Revision 1.23  2011/05/06 22:15:14  lpoulsen
// Preparing for ECON 04.07 release
//
// Revision 1.22  2011/02/21 22:26:36  lpoulsen
// "adapter" command works on Linux
//
// Revision 1.21  2008/08/19 00:38:29  lpoulsen
// Rewritten core protocol module
//
// Revision 1.20  2008/08/05 23:58:37  lpoulsen
// User interface updates.
//
// Revision 1.19  2008/07/26 02:00:48  lpoulsen
// Econ protocol version 4 - prompt bit
//
// Revision 1.18  2008/07/11 16:28:46  lpoulsen
// Econ 4.00 release candidate supports UPDATE and SELECT commands.
//
// Revision 1.17  2008/06/10 00:06:10  lpoulsen
// New -X option is now working
// Updated -I and -O implementation
//
// Revision 1.16  2008/05/31 00:35:09  lpoulsen
// Econ 4.x preview - now with command shell
//
// Revision 1.15  2008/05/10 01:17:37  lpoulsen
// Making econ -x filename work (not yet complete)
//
// Revision 1.14  2006/06/06 02:03:29  lpoulsen
// First attempt at compiling on MAC OS X
//
// Revision 1.13  2004/07/13 18:37:22  lpoulsen
// Fix bug where F3 or F4 did not send CLOSE_REQUEST
//
// Revision 1.12  2003/12/17 18:19:08  lpoulsen
// Respond to IDENTIFY_REQUEST (to support "show econ" on radio/mux)
//
// Revision 1.11  2003/08/21 23:46:51  lpoulsen
// Improved handling of -r option to allow selection by name
// Miscellaneous minor cleanup
//
// Revision 1.10  2003/08/19 03:08:25  lpoulsen
// Remove many compiler warnings.
//
// Revision 1.9  2002/05/15 00:22:16  mourlouk
// Ok, finished with the linux compilation
//
// Revision 1.8  2002/05/14 23:21:48  mourlouk
// Minor changes - trying to compile Linux version
//
// Revision 1.7  2002/04/19 19:04:44  mourlouk
// Release 1.15 - It fixes a bug that was introduced in version 1.13 (econ unable to
// read properly multiple MAC addresses)
//
// Revision 1.6  2001/11/12 22:52:32  mourlouk
// making compiler happy (I)
//
// Revision 1.5  2001/10/31 17:38:03  lpoulsen
// Generate version display from CVS tag.
//
// Revision 1.4  2001/10/31 02:21:11  mourlouk
// Changed the clear_screen method
//
// Revision 1.3  2001/10/30 01:07:45  lpoulsen
// Add "module ID" statement, audit trail generator and copyright line
// Remove "win_or_linux.h" and use a -D in Linux makefile instead.
//
//

struct timeval;

extern FILE         *console_out_file;
extern char          console_out_filename[];
extern unsigned char lMACDefinition[];
extern boolean       gTranferErrorFlag;

#define PRINT_NORMAL 1          // screen
#define PRINT_FILE 2            // screen + file
#define PRINT_ONLYFILE 3        // only file
#define PRINT_MORE 4

#define READ_FROM_KEYBOARD 1
#define READ_FROM_FILE 2

#define OPEN_FILE_ERROR -29
#define FILE_FAILURE -83

#define BOOT_UPDATE 1
#define VINE_UPDATE 2
#define DOWNLOAD_ONLY 3

#define DOWNLOAD_TIMEOUT 60000  // 1 min
#define SDP_TIMEOUT 4000        // 4 sec

extern boolean showInputPercentage;
extern boolean showOutputToScreen;
extern int     WhiteOnBlack;
extern int     howToPrint;
extern int     howToWritePrintFile; //  0-> append
                                //  1-> destroy
                                //  2-> append, but no screen
                                //  3-> destroy, but no screen
extern boolean gotoReselect;
extern boolean gotoConnect;

extern uint16 swap_uint16(uint16 i);
extern uint32 swap_uint32(uint32 i);

#ifdef LINUX
#define ntohs(a) swap_uint16(a)
#define ntohl(a) swap_uint32(a)
#endif

extern void getShort(short *num, BYTE * source);
extern void getLong(uint32 *num, BYTE * source);
extern void letLong(BYTE * dest, long *num);
extern uint16 getRandomID();
extern char upper(char c);
extern int isDigit(char c);
extern int decval(char c);
extern boolean isHexDigit(char c);
extern int hexToInt(char c1, char c2);
extern void set_config_defaults();
extern int extractSerialNumber(macAddr mac, char serialNumber[]);
extern long pwr(int p);
extern boolean isnumeric(char *device_name);
extern boolean isValidMAC(char *mac_string, byte curMACAddr[]);
extern boolean isValidSerialNum(char *radio_serial_num, byte curMACAddr[]);
extern char *format_ip_addr(ip_addr *ip_addr);
extern char *fmt_mac_addr(uint8 *mac_addr);
extern char *format_mac_addr(uint8 *mac_addr);
void print_hex(unsigned char *data, int data_size);
extern void print_discovery_header();
extern void print_help(int session_id);
extern int select_radio(void);
extern void terminate(int exitCode, int errorCode);
extern void terminate_all_threads(int read_thread_is_last);
extern int close_all_adapters();
extern void init_econ();
extern void close_econ();
extern void clean_session(int session_id);
extern void terminate_session(int session_id, int result_code);
extern void process_command_arguments(int argc, char **argv);
extern void show_logo();
extern boolean fileExist(char *filename);
extern int verifyPrefix(char *filename_with_prefix, char *prefixString, char *filename_without_prefix);
extern void diagnostic_message(char *econ_diagnostic_msg);
extern long timeval_subtract(struct timeval *x, struct timeval *y);
