1 | /************************************************************************** |
---|
2 | * |
---|
3 | * Copyright (c) 2013 Alcatel-Lucent |
---|
4 | * |
---|
5 | * Alcatel Lucent licenses this file to You under the Apache License, |
---|
6 | * Version 2.0 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. A copy of the License is contained the |
---|
8 | * file LICENSE at the top level of this repository. |
---|
9 | * You may also obtain a copy of the License at: |
---|
10 | * |
---|
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
12 | * |
---|
13 | * Unless required by applicable law or agreed to in writing, software |
---|
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
16 | * See the License for the specific language governing permissions and |
---|
17 | * limitations under the License. |
---|
18 | * |
---|
19 | ************************************************************************** |
---|
20 | * |
---|
21 | * cmdtbl.c: |
---|
22 | * This is the command table used by the monitor. |
---|
23 | * |
---|
24 | * Original author: Ed Sutter (ed.sutter@alcatel-lucent.com) |
---|
25 | * |
---|
26 | */ |
---|
27 | #include "config.h" |
---|
28 | #include "tfs.h" |
---|
29 | #include "tfsprivate.h" |
---|
30 | #include "cli.h" |
---|
31 | #include "genlib.h" |
---|
32 | #include "xcmddcl.h" |
---|
33 | |
---|
34 | #define ULVLCMD "ulvl" |
---|
35 | |
---|
36 | #if INCLUDE_MEMCMDS |
---|
37 | #define INCLUDE_PM 1 |
---|
38 | #define INCLUDE_DM 1 |
---|
39 | #define INCLUDE_FM 1 |
---|
40 | #define INCLUDE_CM 1 |
---|
41 | #define INCLUDE_SM 1 |
---|
42 | #define INCLUDE_MT 1 |
---|
43 | #endif |
---|
44 | |
---|
45 | extern int Arp(int, char **); |
---|
46 | extern int BbcCmd(int, char **); |
---|
47 | extern int BinfoCmd(int, char **); |
---|
48 | extern int BmemCmd(int, char **); |
---|
49 | extern int Call(int, char **); |
---|
50 | extern int Cast(int, char **); |
---|
51 | extern int Cm(int, char **); |
---|
52 | extern int CfCmd(int, char **); |
---|
53 | extern int Dis(int, char **); |
---|
54 | extern int Dm(int, char **); |
---|
55 | extern int Dhcp(int, char **); |
---|
56 | extern int DnsCmd(int, char **); |
---|
57 | extern int Echo(int, char **); |
---|
58 | extern int Edit(int, char **); |
---|
59 | extern int Ether(int, char **); |
---|
60 | extern int Exit(int, char **); |
---|
61 | extern int FatfsCmd(int, char **); |
---|
62 | extern int FbiCmd(int, char **); |
---|
63 | extern int FlashCmd(int, char **); |
---|
64 | extern int Fm(int, char **); |
---|
65 | extern int Gdb(int, char **); |
---|
66 | extern int Goto(int, char **); |
---|
67 | extern int Gosub(int, char **); |
---|
68 | extern int Heap(int, char **); |
---|
69 | extern int Help(int, char **); |
---|
70 | extern int History(int, char **); |
---|
71 | extern int Icmp(int, char **); |
---|
72 | extern int Ide(int, char **); |
---|
73 | extern int I2cCmd(int, char **); |
---|
74 | extern int If(int, char **); |
---|
75 | extern int Igmp(int, char **); |
---|
76 | extern int Item(int, char **); |
---|
77 | extern int Jffs2Cmd(int, char **); |
---|
78 | extern int Mt(int, char **); |
---|
79 | extern int MtraceCmd(int, char **); |
---|
80 | extern int Pm(int, char **); |
---|
81 | extern int Prof(int, char **); |
---|
82 | extern int Read(int, char **); |
---|
83 | extern int Reg(int, char **); |
---|
84 | extern int Reset(int, char **); |
---|
85 | extern int Return(int, char **); |
---|
86 | extern int SdCmd(int, char **); |
---|
87 | extern int Set(int, char **); |
---|
88 | extern int Sleep(int, char **); |
---|
89 | extern int Sm(int, char **); |
---|
90 | extern int SpifCmd(int, char **); |
---|
91 | extern int Strace(int, char **); |
---|
92 | extern int StructCmd(int, char **); |
---|
93 | extern int SyslogCmd(int, char **); |
---|
94 | extern int Tfs(int, char **); |
---|
95 | extern int Tftp(int, char **); |
---|
96 | extern int TsiCmd(int, char **); |
---|
97 | extern int Ulvl(int, char **); |
---|
98 | extern int Unzip(int, char **); |
---|
99 | extern int Version(int, char **); |
---|
100 | extern int WhatCmd(int, char **); |
---|
101 | extern int Xmodem(int, char **); |
---|
102 | |
---|
103 | extern char *ArpHelp[]; |
---|
104 | extern char *BbcHelp[]; |
---|
105 | extern char *BinfoHelp[]; |
---|
106 | extern char *BmemHelp[]; |
---|
107 | extern char *CallHelp[]; |
---|
108 | extern char *CastHelp[]; |
---|
109 | extern char *CfHelp[]; |
---|
110 | extern char *CmHelp[]; |
---|
111 | extern char *DisHelp[]; |
---|
112 | extern char *DhcpHelp[]; |
---|
113 | extern char *DmHelp[]; |
---|
114 | extern char *DnsHelp[]; |
---|
115 | extern char *EchoHelp[]; |
---|
116 | extern char *EditHelp[]; |
---|
117 | extern char *EtherHelp[]; |
---|
118 | extern char *ExitHelp[]; |
---|
119 | extern char *FatfsHelp[]; |
---|
120 | extern char *FbiHelp[]; |
---|
121 | extern char *FlashHelp[]; |
---|
122 | extern char *FmHelp[]; |
---|
123 | extern char *GdbHelp[]; |
---|
124 | extern char *GosubHelp[]; |
---|
125 | extern char *GotoHelp[]; |
---|
126 | extern char *HelpHelp[]; |
---|
127 | extern char *HeapHelp[]; |
---|
128 | extern char *HistoryHelp[]; |
---|
129 | extern char *IcmpHelp[]; |
---|
130 | extern char *IdeHelp[]; |
---|
131 | extern char *I2cHelp[]; |
---|
132 | extern char *IfHelp[]; |
---|
133 | extern char *IgmpHelp[]; |
---|
134 | extern char *ItemHelp[]; |
---|
135 | extern char *Jffs2Help[]; |
---|
136 | extern char *MtHelp[]; |
---|
137 | extern char *MtraceHelp[]; |
---|
138 | extern char *PmHelp[]; |
---|
139 | extern char *ProfHelp[]; |
---|
140 | extern char *ReadHelp[]; |
---|
141 | extern char *RegHelp[]; |
---|
142 | extern char *ResetHelp[]; |
---|
143 | extern char *ReturnHelp[]; |
---|
144 | extern char *SdHelp[]; |
---|
145 | extern char *SetHelp[]; |
---|
146 | extern char *SleepHelp[]; |
---|
147 | extern char *SmHelp[]; |
---|
148 | extern char *SpifHelp[]; |
---|
149 | extern char *StraceHelp[]; |
---|
150 | extern char *StructHelp[]; |
---|
151 | extern char *SyslogHelp[]; |
---|
152 | extern char *TfsHelp[]; |
---|
153 | extern char *TftpHelp[]; |
---|
154 | extern char *TsiHelp[]; |
---|
155 | extern char *UlvlHelp[]; |
---|
156 | extern char *UnzipHelp[]; |
---|
157 | extern char *VersionHelp[]; |
---|
158 | extern char *WhatHelp[]; |
---|
159 | extern char *XmodemHelp[]; |
---|
160 | |
---|
161 | struct monCommand cmdlist[] = { |
---|
162 | #if INCLUDE_ETHERNET |
---|
163 | { "arp", Arp, ArpHelp, CMDFLAG_NOMONRC }, |
---|
164 | #endif |
---|
165 | #if INCLUDE_BBC |
---|
166 | { "bbc", BbcCmd, BbcHelp, 0 }, |
---|
167 | #endif |
---|
168 | #if INCLUDE_BMEM |
---|
169 | { "bmem", BmemCmd, BmemHelp, 0 }, |
---|
170 | #endif |
---|
171 | #if INCLUDE_BOARDINFO |
---|
172 | { "brdinfo", BinfoCmd, BinfoHelp, 0 }, |
---|
173 | #endif |
---|
174 | { "call", Call, CallHelp, CMDFLAG_NOMONRC }, |
---|
175 | #if INCLUDE_CAST |
---|
176 | { "cast", Cast, CastHelp, 0 }, |
---|
177 | #endif |
---|
178 | #if INCLUDE_CF |
---|
179 | { "cf", CfCmd, CfHelp, 0 }, |
---|
180 | #endif |
---|
181 | #if INCLUDE_CM |
---|
182 | { "cm", Cm, CmHelp, 0 }, |
---|
183 | #endif |
---|
184 | #if INCLUDE_DHCPBOOT |
---|
185 | { "dhcp", Dhcp, DhcpHelp, CMDFLAG_NOMONRC }, |
---|
186 | #endif |
---|
187 | #if INCLUDE_DISASSEMBLER |
---|
188 | { "dis", Dis, DisHelp, 0 }, |
---|
189 | #endif |
---|
190 | #if INCLUDE_DM |
---|
191 | { "dm", Dm, DmHelp, 0 }, |
---|
192 | #endif |
---|
193 | #if INCLUDE_DNS |
---|
194 | { "dns", DnsCmd, DnsHelp, 0 }, |
---|
195 | #endif |
---|
196 | #if INCLUDE_TFSSCRIPT |
---|
197 | { "echo", Echo, EchoHelp, 0 }, |
---|
198 | #endif |
---|
199 | #if INCLUDE_EDIT |
---|
200 | { "edit", Edit, EditHelp, 0 }, |
---|
201 | #endif |
---|
202 | #if INCLUDE_ETHERNET |
---|
203 | { "ether", Ether, EtherHelp, CMDFLAG_NOMONRC }, |
---|
204 | #endif |
---|
205 | #if INCLUDE_TFSSCRIPT |
---|
206 | { "exit", Exit, ExitHelp, 0 }, |
---|
207 | #endif |
---|
208 | #if INCLUDE_FATFS |
---|
209 | { "fatfs", FatfsCmd, FatfsHelp, 0 }, |
---|
210 | #endif |
---|
211 | #if INCLUDE_FBI |
---|
212 | { "fbi", FbiCmd, FbiHelp, 0 }, |
---|
213 | #endif |
---|
214 | #if INCLUDE_FLASH |
---|
215 | { "flash", FlashCmd, FlashHelp, 0 }, |
---|
216 | #endif |
---|
217 | #if INCLUDE_FM |
---|
218 | { "fm", Fm, FmHelp, 0 }, |
---|
219 | #endif |
---|
220 | |
---|
221 | #if INCLUDE_GDB |
---|
222 | { "gdb", Gdb, GdbHelp, CMDFLAG_NOMONRC }, |
---|
223 | #endif |
---|
224 | |
---|
225 | #if INCLUDE_TFSSCRIPT |
---|
226 | { "gosub", Gosub, GosubHelp, 0 }, |
---|
227 | { "goto", Goto, GotoHelp, 0 }, |
---|
228 | #endif |
---|
229 | |
---|
230 | #if INCLUDE_MALLOC |
---|
231 | { "heap", Heap, HeapHelp, 0 }, |
---|
232 | #endif |
---|
233 | |
---|
234 | { "help", Help, HelpHelp, 0 }, |
---|
235 | { "?", Help, HelpHelp, 0 }, |
---|
236 | |
---|
237 | #if INCLUDE_LINEEDIT |
---|
238 | { "history", History, HistoryHelp, 0 }, |
---|
239 | #endif |
---|
240 | |
---|
241 | #if INCLUDE_I2C |
---|
242 | { "i2c", I2cCmd, I2cHelp, 0 }, |
---|
243 | #endif |
---|
244 | |
---|
245 | #if INCLUDE_ICMP |
---|
246 | { "icmp", Icmp, IcmpHelp, CMDFLAG_NOMONRC }, |
---|
247 | #endif |
---|
248 | |
---|
249 | #if INCLUDE_IDE |
---|
250 | { "ide", Ide, IdeHelp, CMDFLAG_NOMONRC }, |
---|
251 | #endif |
---|
252 | |
---|
253 | #if INCLUDE_IGMP |
---|
254 | { "igmp", Igmp, IgmpHelp, CMDFLAG_NOMONRC }, |
---|
255 | #endif |
---|
256 | |
---|
257 | #if INCLUDE_TFSSCRIPT |
---|
258 | { "if", If, IfHelp, 0 }, |
---|
259 | #endif |
---|
260 | |
---|
261 | #if INCLUDE_TFSSCRIPT |
---|
262 | { "item", Item, ItemHelp, 0 }, |
---|
263 | #endif |
---|
264 | |
---|
265 | #if INCLUDE_JFFS2 |
---|
266 | { "jffs2", Jffs2Cmd, Jffs2Help, 0 }, |
---|
267 | #endif |
---|
268 | |
---|
269 | #if INCLUDE_MT |
---|
270 | { "mt", Mt, MtHelp, 0 }, |
---|
271 | #endif |
---|
272 | |
---|
273 | #if INCLUDE_MEMTRACE |
---|
274 | { "mtrace", MtraceCmd, MtraceHelp, 0 }, |
---|
275 | #endif |
---|
276 | |
---|
277 | #if INCLUDE_PM |
---|
278 | { "pm", Pm, PmHelp, 0 }, |
---|
279 | #endif |
---|
280 | |
---|
281 | #if INCLUDE_PROFILER |
---|
282 | { "prof", Prof, ProfHelp, 0 }, |
---|
283 | #endif |
---|
284 | |
---|
285 | #if INCLUDE_TFSSCRIPT |
---|
286 | { "read", Read, ReadHelp, 0 }, |
---|
287 | #endif |
---|
288 | |
---|
289 | #if INCLUDE_STRACE |
---|
290 | { "reg", Reg, RegHelp, 0 }, |
---|
291 | #endif |
---|
292 | |
---|
293 | { "reset", Reset, ResetHelp, 0 }, |
---|
294 | |
---|
295 | #if INCLUDE_TFSSCRIPT |
---|
296 | { "return", Return, ReturnHelp, 0 }, |
---|
297 | #endif |
---|
298 | #if INCLUDE_SD |
---|
299 | { "sd", SdCmd, SdHelp, 0 }, |
---|
300 | #endif |
---|
301 | |
---|
302 | { "set", Set, SetHelp, 0 }, |
---|
303 | |
---|
304 | #if INCLUDE_TFSSCRIPT |
---|
305 | { "sleep", Sleep, SleepHelp, 0 }, |
---|
306 | #endif |
---|
307 | |
---|
308 | #if INCLUDE_SM |
---|
309 | { "sm", Sm, SmHelp, 0 }, |
---|
310 | #endif |
---|
311 | |
---|
312 | #if INCLUDE_SPIF |
---|
313 | { "spif", SpifCmd, SpifHelp, 0 }, |
---|
314 | #endif |
---|
315 | |
---|
316 | #if INCLUDE_STRACE |
---|
317 | { "strace", Strace, StraceHelp, 0 }, |
---|
318 | #endif |
---|
319 | |
---|
320 | #if INCLUDE_STRUCT |
---|
321 | { "struct", StructCmd, StructHelp, 0 }, |
---|
322 | #endif |
---|
323 | |
---|
324 | #if INCLUDE_SYSLOG |
---|
325 | { "syslog", SyslogCmd, SyslogHelp, CMDFLAG_NOMONRC }, |
---|
326 | #endif |
---|
327 | |
---|
328 | #if INCLUDE_USRLVL |
---|
329 | { ULVLCMD, Ulvl, UlvlHelp, 0 }, |
---|
330 | #endif |
---|
331 | |
---|
332 | #if INCLUDE_TFTP |
---|
333 | { "tftp", Tftp, TftpHelp, CMDFLAG_NOMONRC }, |
---|
334 | #endif |
---|
335 | |
---|
336 | #if INCLUDE_TFSCLI |
---|
337 | { "tfs", Tfs, TfsHelp, 0 }, |
---|
338 | #endif |
---|
339 | |
---|
340 | #if INCLUDE_TSI |
---|
341 | { "tsi", TsiCmd, TsiHelp, 0 }, |
---|
342 | #endif |
---|
343 | |
---|
344 | #if INCLUDE_UNZIP |
---|
345 | { "unzip", Unzip, UnzipHelp, 0 }, |
---|
346 | #endif |
---|
347 | |
---|
348 | #if INCLUDE_XMODEM |
---|
349 | { "xmodem", Xmodem, XmodemHelp, 0 }, |
---|
350 | #endif |
---|
351 | |
---|
352 | { "version", Version, VersionHelp, 0 }, |
---|
353 | |
---|
354 | #if INCLUDE_TFS |
---|
355 | { "what", WhatCmd, WhatHelp, 0 }, |
---|
356 | #endif |
---|
357 | |
---|
358 | #include "xcmdtbl.h" /* For non-generic commands that are */ |
---|
359 | /* specific to a particular target. */ |
---|
360 | { 0,0,0,0 }, |
---|
361 | }; |
---|
362 | |
---|
363 | #if INCLUDE_USRLVL |
---|
364 | |
---|
365 | /* cmdUlvl[]: |
---|
366 | * This table stores one char per command that contains that command's |
---|
367 | * user level. The default user level of all commands is 0, but can |
---|
368 | * be re-defined by the ulvl -c command. |
---|
369 | */ |
---|
370 | char cmdUlvl[(sizeof(cmdlist)/sizeof(struct monCommand))]; |
---|
371 | |
---|
372 | /* setCmdUlvl(): |
---|
373 | * The incoming string is a command name followed by a comma and a user |
---|
374 | * level (ranging from 0 thru 4). |
---|
375 | * Return 0 if pass, 1 if new level was user-level rejected, -1 if error. |
---|
376 | */ |
---|
377 | int |
---|
378 | setCmdUlvl(char *cmdlvl, int verbose) |
---|
379 | { |
---|
380 | extern char *appcmdUlvl; |
---|
381 | extern struct monCommand *appCmdlist; |
---|
382 | struct monCommand *cptr; |
---|
383 | int newlevel, idx, pass, doall; |
---|
384 | char *comma, *lvlptr, buffer[32], *cmdandlevel; |
---|
385 | |
---|
386 | /* Make a copy of the incoming string so that we can |
---|
387 | * modify it... |
---|
388 | */ |
---|
389 | if (strlen(cmdlvl) > (sizeof(buffer)-1)) |
---|
390 | goto showerr; |
---|
391 | |
---|
392 | strcpy(buffer,cmdlvl); |
---|
393 | cmdandlevel = buffer; |
---|
394 | |
---|
395 | /* First verify that the comma is in the string... */ |
---|
396 | comma = strchr(cmdandlevel,','); |
---|
397 | if (!comma) |
---|
398 | goto showerr; |
---|
399 | |
---|
400 | /* Retrieve and verify the new level to be assigned... |
---|
401 | * If the level value is the string "off", then we assign a level |
---|
402 | * value that is greater than MAXUSRLEVEL so that the command is |
---|
403 | * essentially disabled as a built-in. |
---|
404 | */ |
---|
405 | if (strcmp(comma+1,"off") == 0) { |
---|
406 | newlevel = MAXUSRLEVEL+1; |
---|
407 | } |
---|
408 | else { |
---|
409 | newlevel = atoi(comma+1); |
---|
410 | if ((newlevel < MINUSRLEVEL) || (newlevel > MAXUSRLEVEL)) |
---|
411 | goto showerr; |
---|
412 | } |
---|
413 | |
---|
414 | *comma = 0; |
---|
415 | |
---|
416 | /* Don't allow adjustment of the ulvl command itself. It must be |
---|
417 | * able to run as user level 0 all the time... |
---|
418 | */ |
---|
419 | if (!strcmp(cmdandlevel,ULVLCMD)) { |
---|
420 | printf("Can't adjust '%s' user level.\n",ULVLCMD); |
---|
421 | return(-1); |
---|
422 | } |
---|
423 | |
---|
424 | if (appCmdlist) { |
---|
425 | pass = 0; |
---|
426 | cptr = appCmdlist; |
---|
427 | lvlptr = appcmdUlvl; |
---|
428 | } |
---|
429 | else { |
---|
430 | pass = 1; |
---|
431 | cptr = cmdlist; |
---|
432 | lvlptr = cmdUlvl; |
---|
433 | } |
---|
434 | |
---|
435 | /* If the command string is "ALL" then we set all commands |
---|
436 | * to the requested level. |
---|
437 | */ |
---|
438 | if (!strcmp(cmdandlevel,"ALL")) |
---|
439 | doall = 1; |
---|
440 | else |
---|
441 | doall = 0; |
---|
442 | |
---|
443 | while(pass < 2) { |
---|
444 | if ((cptr == cmdlist) && (cmdandlevel[0] == '_')) |
---|
445 | cmdandlevel++; |
---|
446 | |
---|
447 | /* Find the command in the table that is to be adjusted... */ |
---|
448 | for(idx=0;cptr->name;cptr++,idx++) { |
---|
449 | if (doall || (!strcmp(cmdandlevel,cptr->name))) { |
---|
450 | /* Even with doall set, we don't want to touch |
---|
451 | * the ULVLCMD level... |
---|
452 | */ |
---|
453 | if (doall && !strcmp(cptr->name,ULVLCMD)) |
---|
454 | continue; |
---|
455 | |
---|
456 | /* If the command's user level is to be lowered, then the |
---|
457 | * current monitor userlevel must be at least as high as the |
---|
458 | * command's current user level... |
---|
459 | */ |
---|
460 | if ((newlevel < lvlptr[idx]) && (getUsrLvl() < lvlptr[idx])) { |
---|
461 | if (verbose) |
---|
462 | printf("User-level access denied: %s\n",cmdandlevel); |
---|
463 | return(1); |
---|
464 | } |
---|
465 | lvlptr[idx] = newlevel; |
---|
466 | if (!doall) |
---|
467 | return(0); |
---|
468 | } |
---|
469 | } |
---|
470 | cptr = cmdlist; |
---|
471 | lvlptr = cmdUlvl; |
---|
472 | pass++; |
---|
473 | } |
---|
474 | |
---|
475 | if (doall) |
---|
476 | return(0); |
---|
477 | |
---|
478 | showerr: |
---|
479 | if (verbose) |
---|
480 | printf("Input error: %s\n",cmdlvl); |
---|
481 | return(-1); |
---|
482 | } |
---|
483 | |
---|
484 | #endif |
---|