tw_cli.h.svn-base
资源名称:cli.rar [点击查看]
上传用户:hujq123
上传日期:2016-04-10
资源大小:153k
文件大小:10k
源码类别:
Telnet服务器
开发平台:
Unix_Linux
- /*
- * Copyright (C) 2002 Koninklijke Philips Electronics N.V.,
- * All Rights Reserved.
- *
- * This source code and any compilation or derivative thereof is the
- * proprietary information of Koninklijke Philips Electronics N.V.
- * and is confidential in nature.
- * Under no circumstances is this software to be exposed to or placed
- * under an Open Source License of any type without the expressed
- * written permission of Koninklijke Philips Electronics N.V.
- *
- *###########################################################
- */
- /*!
- * file tw_cli.h
- *
- * brief -
- *
- */
- /*-----------------------------------------------------------*
- *
- * %version: 5 %
- * instance: DS_5
- * %date_created: Fri Feb 21 09:14:08 2003 %
- *
- *###########################################################
- */
- #ifndef _TW_CLI_H
- #define _TW_CLI_H
- /* These constant maps to accessFlag in cmdStruct. Range is 0 to 31.
- */
- #define CLI_ACCESS_NO_MODE 0 /* " " */
- #define CLI_ACCESS_USER_MODE 1 /* "USR" */
- #define CLI_ACCESS_TECH_MODE 2 /* "TEC" */
- #define CLI_ACCESS_ENG_MODE 3 /* "ENG" */
- #define CLI_ACCESS_BLO_MODE 4 /* "BLO" - backdoor access */
- #define CLI_ACCESS_PRODUCT_1 8 /* To create command list per product type */
- #define CLI_ACCESS_PRODUCT_2 9
- #define CLI_ACCESS_PRODUCT_3 10
- #define TO_ACCESS_FLAG(x) (1 << (x))
- /* The following flags are used for specifying access
- * level for a command object.
- */
- #define ALL_ACCESS_MODE (TO_ACCESS_FLAG(CLI_ACCESS_USER_MODE) |
- TO_ACCESS_FLAG(CLI_ACCESS_TECH_MODE) |
- TO_ACCESS_FLAG(CLI_ACCESS_ENG_MODE) |
- TO_ACCESS_FLAG(CLI_ACCESS_BLO_MODE))
- #define USER_ACCESS_MODE TO_ACCESS_FLAG(CLI_ACCESS_USER_MODE)
- #define TECH_ACCESS_MODE TO_ACCESS_FLAG(CLI_ACCESS_TECH_MODE)
- #define ENG_ACCESS_MODE TO_ACCESS_FLAG(CLI_ACCESS_ENG_MODE)
- #define BLO_ACCESS_MODE TO_ACCESS_FLAG(CLI_ACCESS_BLO_MODE)
- #define ALL_PRODUCT_TYPE (TO_ACCESS_FLAG(CLI_ACCESS_PRODUCT_1) |
- TO_ACCESS_FLAG(CLI_ACCESS_PRODUCT_2) |
- TO_ACCESS_FLAG(CLI_ACCESS_PRODUCT_3))
- typedef enum
- {
- CLI_PRINT_DATA_FORMAT_INT32 = 0,
- CLI_PRINT_DATA_FORMAT_UINT32,
- CLI_PRINT_DATA_FORMAT_HEX32,
- CLI_PRINT_DATA_FORMAT_INT16,
- CLI_PRINT_DATA_FORMAT_UINT16,
- CLI_PRINT_DATA_FORMAT_HEX16,
- CLI_PRINT_DATA_FORMAT_INT8,
- CLI_PRINT_DATA_FORMAT_UINT8,
- CLI_PRINT_DATA_FORMAT_HEX8
- } Cli_PrintFormat_e;
- /* A structure to contain all session related parameters. Multiple
- * of such objects in runtime will support multiple sessions.
- */
- #define CLI_ACCESS_CMDSTR_SIZE 128
- #define CLI_ACCESS_HISTORY_DEPTH 12
- #define MAX_USERPASS_LEN 12
- #define MAX_LOGIN_FAILURE 4
- #define SCRATCH_BUF_SIZE 384
- #define CLI_DEFAULT_PAGE_LENGTH 48
- #define CLI_MINIMAL_PAGE_LENGTH 5
- #define MAX_PROMPT_LEN 24 /* first 14 characters of system name can fit */
- typedef struct _Cli_SessionFuns Cli_SessionFuns_t;
- typedef struct _cmdSession Cli_cmdSession_t;
- struct _Cli_SessionFuns {
- int (*write)(char *str, int len);
- int (*writebuf)(char *str, int len);
- int (*read_char)();
- void (*yield)();
- int (*init)();
- void (*cleanup)(Cli_cmdSession_t *pSess);
- int (*log)(const char *fmt, ...);
- int (*create_task)(const char *name, void*(*task_proc)(void*), int prio, int stack_size, void *arg);
- int sessionType;
- };
- struct _cmdSession {
- Cli_SessionFuns_t *pSessFuns; /* the socket, if -1 this entry is free */
- int cmdSessionType; /* either JTAG or Socket */
- char cmdBuf[CLI_ACCESS_CMDSTR_SIZE]; /* hold user input uptil CR */
- int cmdBufIdx; /* location of last char */
- int cmdState; /* track login state */
- char myUserName[MAX_USERPASS_LEN + 2]; /* username as entered */
- /* histroyBuf[][] stores last CLI_ACCESS_HISTORY_DEPTH commands, it's a ring buffer
- * histroyNum[][] stores last CLI_ACCESS_HISTORY_DEPTH command history numbers,
- * historyPtr indicates where in the ring buffer to record the next command
- * historyNextNumber is the next command history number to use.
- */
- char historyBuf[CLI_ACCESS_HISTORY_DEPTH][CLI_ACCESS_CMDSTR_SIZE];
- int historyNum[CLI_ACCESS_HISTORY_DEPTH];
- int historyPtr;
- int historyNextNumber;
- int currentCmdMode; /* operator, admin, cfg or engineering mode */
- int myProductType; /* product type such as Barracuda */
- int loginFailedCount; /* kick user out after a few failures */
- int errValue; /* some place to store error from Fusion's call */
- char scratchBuf[SCRATCH_BUF_SIZE]; /* buffer for any purpose, per session */
- int pageLength; /* store the number of rows in one screen */
- int currentRow; /* indicates current line number */
- int scrollPause; /* if = 1, printing will pause at "numRow" lines */
- int skipPrinting; /* if 1, all calls to print stuff out are discarded. */
- char prompt[MAX_PROMPT_LEN];
- };
- /* Definition of command structure
- *
- * name is the command or option string
- *
- * accessFlag indicates the scope of this command/option; it is compared
- * with user's access right to create a valid set of command and options
- * pertaining to certain access mode and product type.
- *
- * optionList lists all (if any) available command/options as represented
- * by their Cli_CmdStruct_t objects.
- *
- * helpStr is a one line (60 char max) explanation of what this command/
- * option does.
- *
- * HelpFunc is an optional function which is executed after printing out
- * all the helpStrs in optionList's objects.
- *
- * procFunc is the command processing handler. It is executed when user
- * command is fully qualified (match all command options). E.g., a command
- * like "logout" needs no argument, meaning that the parser can fully
- * qualify user input. This will be the job of a procFunc().
- *
- * varOptFunc is the alternative command processing handler when a
- * target procFunc is not available. This is used for a command/option
- * that expect one or more arguments. Argument processing must be done
- * by this handler. E.g., a command like "ping A.B.C.D" contains one
- * argument. Since value of A.B.C.D is not fixed, the parser can only
- * qualify the command/option upto "ping" but no further. It is up to a
- * varOptFunc() for ping to scan and extract A.B.C.D and do something with
- * it.
- *
- * What is variable option list ? A variable option is one which presence
- * and availability is determined during runtime. For example, if we have
- * a command to show available network device, we can implement it via
- * variable option list.
- *
- * show netdev pna0, show netdev pppoa0, show netdev pppoa1. The last
- * option is a variable option.
- */
- typedef struct _cli_cmdStruct
- {
- char *name; /* can't be longer than 16 characters */
- unsigned int accessFlag;
- struct _cli_cmdStruct **optionList;
- char *helpStr; /* can't be longer than 60 characters */
- int (*helpFunc)(Cli_cmdSession_t *pSess, char *cmdStr, int ptr);
- int (*procFunc)(Cli_cmdSession_t *pSess, char *cmdStr, int ptr);
- int (*varOptFunc)(Cli_cmdSession_t *pSess, char *cmdStr, int ptr);
- } Cli_CmdStruct_t;
- #define NULL_HELP_FUNC NULL /* no help function */
- #define NULL_PROC_FUNC NULL /* no (fixed length, no option) processing function */
- #define NULL_VAR_OPT_FUNC NULL /* no variable option processing function */
- typedef enum _cli_sessionType
- {
- CLI_SERIAL_SESSION,
- CLI_SOCK_SESSION,
- CLI_JTAG_SESSION
- } Cli_SessionType_t;
- /*
- * stdio/cli compatible io
- */
- typedef void (*Cli_Printf_t)(void *handle, char *fmt, ...) ;
- /* Common size text string to be reused. See tw_cli.c for definition.
- */
- extern char *badPasswordStr;
- extern char *endSessionStr;
- extern char *noHelpStr;
- extern char *missingCmdStr;
- extern char *invalidCmdStr;
- extern char *cmdOptionsAreStr;
- extern char *noSuchHistoryStr;
- extern char *badParamStr;
- extern char *operationFailedStr;
- extern char *Cli_FailedStr;
- /* CLI Utility Functions */
- #if defined(__cplusplus)
- extern "C"{
- #endif
- int Cli_Initialize(Cli_SessionFuns_t *pSessFuns);
- int Cli_ProcessCmd(char *msgbuf, int len, Cli_cmdSession_t *pSess);
- int Cli_SendCrLf(Cli_cmdSession_t *pSess);
- int Cli_PrintLine(Cli_cmdSession_t *pSess,
- int NumChar,
- char Character,
- int NumFrontCR,
- int NumBackCR);
- int Cli_IpAndMask2int(char *str,
- unsigned int *addr,
- unsigned int *mask);
- int Cli_Printf(Cli_cmdSession_t *pSess, char *fmt, ...);
- int Cli_PutStr(Cli_cmdSession_t *pSess, char *str, int len);
- int Cli_PutChar(Cli_cmdSession_t *pSess, char ch);
- int Cli_PrintAtmPayload(Cli_cmdSession_t *pSess,
- unsigned char *pAtmCellBuf);
- void Cli_DisableScrollPause(Cli_cmdSession_t *pSess);
- void Cli_EnableScrollPause(Cli_cmdSession_t *pSess);
- int Cli_SetPageLength(Cli_cmdSession_t *pSess, int NewPageLen);
- int Cli_GetScrollPauseStatus(Cli_cmdSession_t *pSess, int *PageLen);
- int Cli_PrintFileContent(Cli_cmdSession_t *pSess, char *FileName);
- void Cli_PrintData(Cli_cmdSession_t *pSess, void *pvBuffer, int nBytes,
- Cli_PrintFormat_e eFormat, int bUseRelativeAddr);
- int Cli_GetChar(Cli_cmdSession_t *pSess) ;
- #if defined(__cplusplus)
- }
- #endif
- #endif /* _TW_CLI_H */