// $Id: ucon.h,v 1.26 2013/03/22 21:46:57 lpoulsen Exp $
// Copyright (C) 2001 Wi_LAN Technologies, Inc
//
// $Log: ucon.h,v $
// Revision 1.26  2013/03/22 21:46:57  lpoulsen
// Make -i filename work together with -r name
//
// Revision 1.25  2013/03/22 17:37:17  lpoulsen
// Allow "econ -r name" to make one connection with the named radio
//     without ever entering the Econsole> command prompt.
//
// Revision 1.24  2011/07/08 21:50:30  lpoulsen
// Eliminate (almost all) use of debug_level, use debug_flags instead.
//
// Revision 1.23  2011/05/06 22:15:14  lpoulsen
// Preparing for ECON 04.07 release
//
// Revision 1.22  2011/03/22 00:26:10  lpoulsen
// Resolve sequence errors on very weak links
// Resolve hangs when Ctrl-C between "dir" and "download"
// Resolve conflicting build date information
//
// Revision 1.21  2011/03/02 18:19:35  lpoulsen
// Allow Ctrl-C to close a session
//
// Revision 1.20  2011/01/22 01:29:05  lpoulsen
// Release candidate:
// - allow "show first=1 max=45" to support large systems
// - allow "sort by=distance" to support "connect all reboot"
// - improve download efficiency
//
// Revision 1.19  2011/01/11 00:49:15  lpoulsen
// Add definitions for more session result codes.
//
// Revision 1.18  2010/12/23 02:25:41  lpoulsen
// Add "loss" command for testing retransmissions
//
// Revision 1.17  2010/12/22 17:36:34  lpoulsen
// Select/Deselect list of ranges
// Expand to up to 511 radios
// Protocol fixes
//
// Revision 1.16  2008/08/05 23:58:37  lpoulsen
// User interface updates.
//
// Revision 1.15  2008/07/30 07:11:42  lpoulsen
// New option "Connect keyboard=yes"
// Fixes for timeout probelm at end of file.
//
// Revision 1.14  2008/07/26 02:00:48  lpoulsen
// Econ protocol version 4 - prompt bit
//
// Revision 1.13  2008/07/11 20:14:10  lpoulsen
// Resolve many compiler warnings on Linux
//
// Revision 1.12  2008/07/11 17:10:27  lpoulsen
// Resolve compiler warnings.
//
// Revision 1.11  2008/07/11 16:28:46  lpoulsen
// Econ 4.00 release candidate supports UPDATE and SELECT commands.
//
// Revision 1.10  2008/06/10 00:06:10  lpoulsen
// New -X option is now working
// Updated -I and -O implementation
//
// Revision 1.9  2008/05/31 00:35:09  lpoulsen
// Econ 4.x preview - now with command shell
//
// Revision 1.8  2008/05/10 01:17:37  lpoulsen
// Making econ -x filename work (not yet complete)
//
// Revision 1.7  2008/04/26 00:48:25  lpoulsen
// Rename selectedAdapterId global var to option_C
//
// Revision 1.6  2002/05/15 00:22:16  mourlouk
// Ok, finished with the linux compilation
//
// Revision 1.5  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.3  2001/11/07 02:47:25  lpoulsen
// Running econ on linux:
// - make the executable name be "econ"
// - remove a few compiler warnings
//
// Revision 1.2  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.
//
//
//** Includes ......................................................

#include <stdio.h>              /* standard I/O routines                 */

#include "dbflags.h"

//** Type definitions & structures .................................

enum econ_phases {
    ECON_STARTING = 0,
    ECON_CONNECT_DEV,
    ECON_CONNECTED,
    ECON_CLOSE_ADAPTER,
    ECON_INIT_THREADS,
    ECON_CLOSING_SESSION,
    ECON_CLOSE_THREADS,
    ECON_DISCOVER
};

//** Error codes ...................................................

#define ES_DOWNLOAD_GOOD     -3
#define ES_INVALID_DEVICE    -17
#define INVALID_ADAPTER      -18
#define THREAD_FAILURE       -19
#define INVALID_RADIO_ID     -20
#define UNABLE_TO_CONNECT    -21
#define READ_THREAD_ERROR    -22
#define SEND_THREAD_ERROR    -23
#define RECEIVE_THREAD_ERROR -24
#define UNABLE_TO_SEND_DATA  -25
#define ES_GO_AWAY           -26
#define ES_REMOTE_CLOSE      -27
#define ES_CONNECT_FAILED    -28
#define ES_SEND_FAILED       -29
#define ES_FILESEND_FAILED   -30
#define ES_F3_KEY            -31
#define ES_F4_KEY            -32
#define ES_ESC_KEY           -33
#define ES_READ_EOF          -34
#define ES_READ_ERROR        -35
#define ES_NO_SPACE          -36
#define ES_CMD_FAILED        -37
#define ES_CTRL_C            -38
#define ES_DIR_FAILED        -39

//** Constants .....................................................

#define MAX_CHAR_PACKET 256

//** Global variables ..............................................

extern int      option_C;
extern char    *option_I;
extern boolean  option_K;
extern char    *option_O;
extern char    *option_R;
extern boolean  option_Z;
extern int      numOfRadiosFound;
extern enum     econ_phases econ_phase;
extern int      session_result;
extern int      loss_pct_recv;
extern int      loss_pct_xmit;
extern FILE    *session_pcap_file;

#ifdef __cplusplus
extern "C" char             *get_cvs_tag(void);
extern "C" enum econ_phases  get_econ_phase(void);
extern "C" char             *get_option_I(void);
extern "C" char             *get_option_R(void);
#else
extern char  cvs_tag[];
extern enum  econ_phases econ_phase;
extern char *option_R;
extern enum econ_phases  get_econ_phase(void);
#endif

extern char bld_date[];
extern char bld_time[];

//** Function prototypes ...........................................

#ifdef LINUX
#define strcmpi(a,b)     strcasecmp(a,b)
#define strnicmp(a,b,c)  strncasecmp(a,b,c)
#define ThreadReturnType void*
#else
#define ThreadReturnType unsigned _stdcall
#endif
extern ThreadReturnType SendThread(void *radioID);
extern ThreadReturnType ReadThread(void *radioID);
extern ThreadReturnType ReceiveThread(void *radioID);
extern ThreadReturnType FileThread(void *radioID);

#ifdef _EPACKET_H

extern void econ_trace_packet(econ_packet *packet, size_t nbytes);
extern void econ_trace_open(char *devname);
extern void econ_trace_close(void);
extern void epacket_clear_receive_stats(void);
extern void epacket_print_receive_stats(void);
extern void self_init_thread();
extern void self_terminate_thread();
extern void start_all_threads();
extern void wait_for_all_threads_to_terminate();
extern void terminate_all_threads(int send_thread_is_last);
extern void readThreadInit();
extern void readThreadTerminate();
extern void setReverseTextBackground();
extern void run_a_session(int device_index, char *input_file_name,
                                            char *output_file_name);
extern int  discover_radios(boolean show_progress, int delay_seconds);
extern int  lookup_radio(char *name);
extern void process_econ_output(uint8 *data, int nbytes);
extern void show_radios(boolean line_0, uint16 format, int first, int last);
extern void sort_device_table(int sortby);

#endif // _EPACKET_H

// End
