/* FILENAME: embcli.h
 *
 * Copyright 2006-2008 by InterNiche Technologies Inc. All rights reserved.
 *
 * embedded CLI definition file
 */

/* CLI error codes */
#define CLI_ERR_EXECUTE       -1       /* command execution error */
#define CLI_ERR_TIMEOUT       -2       /* command timeout error */
#define CLI_ERR_FATAL         -3       /* fatal parsing error */
#define CLI_ERR_FULL          -4       /* menu array is full */
#define CLI_ERR_OVERFLOW      -5       /* stack overflow */
#define CLI_ERR_PARAM         -10      /* parameter error */
#define CLI_ERR_MISSING       -11      /* missing parameter argument */
#define CLI_ERR_CMD           -12      /* unknown command */
#define CLI_ERR_AMBIG         -13      /* ambiguous command */
#define CLI_ERR_TYPE          -14      /* parameter type error */
#define CLI_ERR_DELIM         -15      /* missing string delimiter */
#define CLI_ERR_DUP           -16      /* duplicate parameter */
#define CLI_ERR_TOOBIG        -17      /* string too big */
#define CLI_ERR_IPADDR        -18      /* bad IP address specification */
#define CLI_ERR_GROUP         -19      /* bad menu group or missing option */
#define CLI_ERR_UNKNOWN       -20      /* unknown CLI error */
#define CLI_MAX_ERROR         CLI_ERR_UNKNOWN

#define CLI_MAX_ERR_STR        63     /* Max len of err strings returned by CLI */

/* CLI data/symbol types */
#define CLI_NONE              0
#define CLI_INT               1
#define CLI_UINT              2
#define CLI_STRING            3
#define CLI_IPADDR            4
#define CLI_UNDEF             -1

/* CLI IP address types */
#define CLI_IPV4              4
#define CLI_MAC               6

extern int cli_defined(void *ctx, char c);
extern int cli_help(void *ctx);
extern int cli_count(void *ctx);

/* CLI parameter mask (params are 'a'..'z') */
#define CLI_FLAG(c)           (1L << ((c) - 'a'))
#define CLI_QMARK             (1L << 26)
#define CLI_PARAM(ctx, c)     cli_get_param(ctx, c)
#define CLI_VALUE(ctx, c)     cli_get_value(ctx, c)
#define CLI_DEFINED(ctx, c)   cli_defined(ctx, c)
#define CLI_HELP(ctx)         cli_help(ctx)
#define CLI_COUNT(ctx)        cli_count(ctx)

/* CLI parameter element */
struct cli_parm {
   char  option;              /* option letter */
   char  opttype;             /* CLI data type */
};

/* CLI command element */
struct cli_cmd {
   char  *name;               /* command name */
   char  *desc;               /* command description */
                              /* pointer to CLI command function */
   int   (*func)(void *);
   int   nparms;              /* number of parameters */
   struct cli_parm *parms;    /* pointer to parameter array */
};

/* CLI menu description */
struct cli_menu {
   char  *name;               /* menu name */
   int   ncmds;               /* number of commands */
   struct cli_cmd *cmds;      /* command element array */
};

/* IP address / MAC address structure */
struct cli_addr {
   int   type;                /* CLI_IPV4, CLI_IPV6, or CLI_MAC */
   uint8_t  addr[8];          /* IPv4/MAC address (network-order) */
};


/* CLI functions */
extern char *cli_get_errstr(int, char *);
extern int cli_install_menu(struct cli_menu *);
extern int cli_uninstall_menu(struct cli_menu *);
extern int cli_parse_ipaddr(char *, char **, int, struct cli_addr *);
extern int  cli_command(void *, char *);
extern struct cli_arg *cli_get_param(void *, char);
extern void *cli_get_value(void *, char);

/* CLI variables */
extern char cli_prompt[];
