1 /******************************************************************************* 2 **+--------------------------------------------------------------------------+** 3 **| |** 4 **| Copyright 1998-2008 Texas Instruments, Inc. - http://www.ti.com/ |** 5 **| |** 6 **| Licensed under the Apache License, Version 2.0 (the "License"); |** 7 **| you may not use this file except in compliance with the License. |** 8 **| You may obtain a copy of the License at |** 9 **| |** 10 **| http://www.apache.org/licenses/LICENSE-2.0 |** 11 **| |** 12 **| Unless required by applicable law or agreed to in writing, software |** 13 **| distributed under the License is distributed on an "AS IS" BASIS, |** 14 **| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |** 15 **| See the License for the specific language governing permissions and |** 16 **| limitations under the License. |** 17 **| |** 18 **+--------------------------------------------------------------------------+** 19 *******************************************************************************/ 20 21 #ifndef tiwlan_console_h 22 #define tiwlan_console_h 23 24 #include <stdio.h> 25 #include <assert.h> 26 /* 27 * --------------------- * 28 * error codes 29 * --------------------- * 30 */ 31 typedef enum 32 { 33 E_OK = 0 34 , E_BADPARM 35 , E_TOOMANY 36 , E_NOMEMORY 37 , E_NOT_FOUND 38 , E_EXISTS 39 , E_DUMMY 40 } consoleErr_t; 41 42 typedef consoleErr_t consoleErr; 43 44 typedef void * handle_t; 45 46 typedef unsigned char U8; 47 typedef signed char S8; 48 typedef unsigned short U16; 49 typedef signed short S16; 50 typedef unsigned long U32; 51 typedef signed long S32; 52 53 54 55 #ifdef __cplusplus 56 extern "C" { 57 #endif /* __cplusplus */ 58 59 /* Monitor parameter flags */ 60 #define CON_PARM_OPTIONAL 0x01 /* Parameter is optional */ 61 #define CON_PARM_DEFVAL 0x02 /* Default value is set */ 62 #define CON_PARM_RANGE 0x04 /* Range is set */ 63 #define CON_PARM_STRING 0x08 /* String parm */ 64 #define CON_PARM_LINE 0x10 /* String from the current parser position till EOL */ 65 #define CON_PARM_SIGN 0x20 /* Signed param */ 66 #define CON_PARM_NOVAL 0x80 /* Internal flag: parameter is anassigned */ 67 68 /* Function parameter structure */ 69 typedef struct ConParm_t 70 { 71 const char *name; /* Parameter name. Shouldn't be allocated on stack! */ 72 U8 flags; /* Combination of CON_PARM_??? flags */ 73 U32 low_val; /* Low val for range checking */ 74 U32 hi_val; /* Hi val for range checking/max length of string */ 75 U32 value; /* Value/address of string parameter */ 76 } ConParm_t; 77 78 #define CON_LAST_PARM { NULL, 0, 0, 0, 0 } 79 80 /* Monitor command handler prototype */ 81 typedef void (*FuncToken_t)(ConParm_t parm[], U16 nParms); 82 83 /* Add subdirectory to the p_root directory 84 Returns the new directory handle 85 */ 86 handle_t consoleAddDirExt( 87 handle_t hRoot, /* Upper directory handle. NULL=root */ 88 const char *name, /* New directory name */ 89 const char *desc ); /* Optional directory description */ 90 91 /* Add token */ 92 consoleErr consoleAddToken( handle_t hDir, /* Directory handle. NULL=root */ 93 const char *name, /* Token name. Shouldn't be allocated on stack! */ 94 const char *help, /* Token help. Shouldn't be allocated on stack! */ 95 FuncToken_t p_func, /* Token handler */ 96 ConParm_t p_parms[]);/* Array of token parameters. */ 97 /* The last array element has parameter */ 98 /* name = NULL */ 99 100 /* Monitor driver. 101 Calls XX_Gets in infinite loop to get input string. 102 Gives the string to console_ParseString for processing. 103 Monitor token handler can call consoleStop() to exit the 104 consoleStart. 105 */ 106 void consoleStart( void ); 107 108 /* Parse the given input string and exit. 109 All commands in the input string are executed one by one. 110 */ 111 void console_ParseString( char *input_string ); 112 113 /* Stop monitor driver */ 114 void consoleStop( void ); 115 116 /* Execute commands from 'script_file' */ 117 int consoleRunScript( char *script_file ); 118 119 #ifdef _WINDOWS 120 #endif 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 /* ----------------------------------------------------- */ 127 128 #define ALIAS_LEN 1 129 130 #define MAX_NAME_LEN 80 131 #define MAX_HELP_LEN 80 132 #define MAX_PARM_LEN 20 133 #define MAX_NUM_OF_PARMS 30 134 135 #define TOKEN_UP ".." 136 #define TOKEN_ROOT "/" 137 #define TOKEN_BREAK "#" 138 #define TOKEN_HELP "?" 139 #define TOKEN_DIRHELP "help" 140 141 #ifndef FALSE 142 #define FALSE 0 143 #endif 144 145 #ifndef TRUE 146 #define TRUE 1 147 #endif 148 149 #ifndef __LINUX__ // TRS:WDK 150 #define perror(str) printf("\nError at %s:%d - %s.\n", __FILE__, __LINE__, (str)) 151 #endif /* __LINUX__ */ 152 //TRS end 153 #ifdef __cplusplus 154 extern "C" { 155 #endif /* __cplusplus */ 156 157 #ifndef _WINDOWS /* TRS:WDK __LINUX__ */ 158 #ifdef ERRCHK 159 # define ASSERT(p) assert(p) 160 #else 161 # define ASSERT(p) do {} while (0) 162 #endif 163 #endif /* TRS:WDK __LINUX__ */ 164 165 #ifdef __cplusplus 166 } 167 #endif 168 169 typedef enum { Dir, Token } ConEntry_type_t; 170 171 /* Parameter name and format */ 172 typedef char (ParmName_t)[MAX_NAME_LEN+1]; 173 174 /* Monitor token structure */ 175 typedef struct ConEntry_t 176 { 177 struct ConEntry_t *next; 178 char name[MAX_NAME_LEN+1]; /* Entry name */ 179 char help[MAX_HELP_LEN+1]; /* Help string */ 180 char *alias; /* Alias - always in upper case*/ 181 ConEntry_type_t sel; /* Entry selector */ 182 183 union { 184 struct 185 { 186 struct ConEntry_t *upper; /* Upper directory */ 187 struct ConEntry_t *first; /* First entry */ 188 } dir; 189 struct t_Token 190 { 191 FuncToken_t f_tokenFunc; /* Token handler */ 192 ConParm_t parm[MAX_NUM_OF_PARMS]; /* Parameters array */ 193 ParmName_t name[MAX_NUM_OF_PARMS]; /* Parameter name */ 194 } token; 195 } u; 196 } ConEntry_t; 197 198 /* Token types */ 199 typedef enum 200 { 201 EmptyToken, 202 UpToken, 203 RootToken, 204 BreakToken, 205 HelpToken, 206 DirHelpToken, 207 NameToken 208 } t_TokenType; 209 210 char * console_strlwr( char *s ); 211 int console_stricmp( char *s1, char *s2, U16 len ); 212 char * console_ltrim( char *s ); 213 214 #endif /* #ifndef tiwlan_console_h */ 215