2008-02-05 00:42:17 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
/**
|
|
|
|
* \file
|
2009-03-02 21:44:15 +01:00
|
|
|
* Main header file for the Contiki shell
|
2008-02-05 00:42:17 +01:00
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
2006-06-18 00:41:10 +02:00
|
|
|
*/
|
|
|
|
|
2014-11-08 01:15:42 +01:00
|
|
|
/** \addtogroup apps
|
|
|
|
* @{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup shell The Contiki shell
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* The Contiki shell provides both interactive and batch processing
|
|
|
|
* for Contiki.
|
|
|
|
*
|
|
|
|
* The shell consists of two parts: the shell application and a shell
|
|
|
|
* back-end. The shell application contains all the logic of the
|
|
|
|
* shell, whereas the shell back-end provides I/O for the
|
|
|
|
* shell. Examples of shell back-ends are a serial I/O shell back-end,
|
|
|
|
* that allows the shell to operate over a serial connection, and a
|
|
|
|
* telnet server back-end, that allows the shell to operate over a
|
|
|
|
* TCP/IP telnet connection.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-11-24 16:57:08 +01:00
|
|
|
#ifndef SHELL_H_
|
|
|
|
#define SHELL_H_
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "sys/process.h"
|
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief Holds a information about a shell command
|
|
|
|
*
|
|
|
|
* This structure contains information about a shell
|
|
|
|
* command. It is an opaque structure with no user-visible
|
|
|
|
* elements.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
struct shell_command {
|
|
|
|
struct shell_command *next;
|
|
|
|
char *command;
|
|
|
|
char *description;
|
|
|
|
struct process *process;
|
|
|
|
struct shell_command *child;
|
|
|
|
};
|
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \name Shell back-end API
|
|
|
|
*
|
|
|
|
* The shell back-end API contains functions that are used
|
|
|
|
* by shell back-ends.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Initialize the shell.
|
|
|
|
*
|
|
|
|
* This function initializes the shell. It typically is
|
|
|
|
* called from the shell back-end.
|
|
|
|
*
|
|
|
|
*/
|
2006-06-18 00:41:10 +02:00
|
|
|
void shell_init(void);
|
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief Start the shell.
|
|
|
|
*
|
|
|
|
* This function starts the shell and prints out the shell
|
|
|
|
* prompt. It typically is called by the shell back-end to
|
|
|
|
* start a new shell session.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-24 21:35:03 +01:00
|
|
|
void shell_start(void);
|
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief Send a line of input to the shell
|
|
|
|
* \param commandline A pointer to a string that contains the command line
|
|
|
|
* \param commandline_len Length of the command line, in bytes
|
|
|
|
*
|
|
|
|
* This function is called by a shell back-end to send an
|
|
|
|
* incoming command line to the shell. The shell parses
|
|
|
|
* the command line and starts any commands found in the
|
|
|
|
* command line.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
void shell_input(char *commandline, int commandline_len);
|
2009-03-02 21:44:15 +01:00
|
|
|
|
2011-04-16 21:10:22 +02:00
|
|
|
/**
|
|
|
|
* \brief Stop the shell
|
|
|
|
*
|
|
|
|
* This function stops all running commands. It typically
|
|
|
|
* is called by a shell back-end to to indicate that the
|
|
|
|
* user has quit the shell.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void shell_stop(void);
|
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief Quit the shell
|
|
|
|
*
|
2011-04-16 21:10:22 +02:00
|
|
|
* This function is called by a shell back-end to stop the
|
|
|
|
* shell processes.
|
2009-03-02 21:44:15 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
void shell_quit(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \name Shell back-end callback functions
|
|
|
|
*
|
|
|
|
* These callback functions are called from the shell to
|
|
|
|
* the shell back-end. The shell back-end must implement
|
|
|
|
* all back-end callback functions.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Print a prompt
|
|
|
|
* \param prompt A suggested prompt
|
|
|
|
*
|
|
|
|
* This function is called by the shell to print a
|
|
|
|
* prompt. The shell back-end may show the suggested
|
|
|
|
* prompt, or another prompt.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void shell_prompt(char *prompt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Print a line of output from the shell
|
|
|
|
* \param data1 A pointer to the first half of the data
|
|
|
|
* \param size1 The size of the first half of the data
|
|
|
|
* \param data2 A pointer to the second half of the data
|
|
|
|
* \param size2 The size of the second half of the data
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This function is called by a shell command to output
|
|
|
|
* data. The output is split into two halves to make it
|
|
|
|
* easier for shell commands to output data that contains
|
|
|
|
* a static part (such as a static string) and a dynamic
|
|
|
|
* part (a dynamically generated string).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void shell_default_output(const char *data1, int size1,
|
|
|
|
const char *data2, int size2);
|
|
|
|
|
2011-04-16 21:10:22 +02:00
|
|
|
/**
|
|
|
|
* \brief Request shell exit
|
|
|
|
*
|
|
|
|
* This function is called by the shell to request exiting
|
|
|
|
* the current session. The shell back-end will later call
|
|
|
|
* shell_stop() when the session was successfully exited.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void shell_exit(void);
|
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \name Shell command API
|
|
|
|
*
|
|
|
|
* These functions are used by shell commands.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Define a shell command
|
|
|
|
* \param name The variable name of the shell command definition
|
|
|
|
* \param command A string with the name of the shell command
|
|
|
|
* \param description A string that contains a one-line description of the command
|
|
|
|
* \param process A pointer to the process that implements the shell command
|
|
|
|
*
|
|
|
|
* This macro defines and declares a shell command (struct
|
|
|
|
* shell_command). This is used with the
|
|
|
|
* shell_register_command() function to register the
|
|
|
|
* command with the shell.
|
|
|
|
*
|
|
|
|
* \hideinitializer
|
|
|
|
*/
|
|
|
|
#define SHELL_COMMAND(name, command, description, process) \
|
|
|
|
static struct shell_command name = { NULL, command, \
|
|
|
|
description, process }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Output data from a shell command
|
|
|
|
* \param c The command that outputs data
|
|
|
|
* \param data1 A pointer to the first half of the data
|
|
|
|
* \param size1 The size of the first half of the data
|
|
|
|
* \param data2 A pointer to the second half of the data
|
|
|
|
* \param size2 The size of the second half of the data
|
|
|
|
*
|
|
|
|
* This function is called by a shell command to output
|
|
|
|
* data. The output is split into two halves to make it
|
|
|
|
* easier for shell commands to output data that contains
|
|
|
|
* a static part (such as a static string) and a dynamic
|
|
|
|
* part (a dynamically generated string).
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
void shell_output(struct shell_command *c,
|
|
|
|
void *data1, int size1,
|
|
|
|
const void *data2, int size2);
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief Output strings from a shell command
|
|
|
|
* \param c The command that outputs data
|
|
|
|
* \param str1 A pointer to the first half of the string
|
|
|
|
* \param str2 A pointer to the second half of the string
|
|
|
|
*
|
|
|
|
* This function is called by a shell command to output a
|
|
|
|
* string. Internally, the function uses the
|
|
|
|
* shell_output() function to output the data. The output
|
|
|
|
* is split into two halves to make it easier for shell
|
|
|
|
* commands to output data that contains a static part
|
|
|
|
* (such as a static string) and a dynamic part (a
|
|
|
|
* dynamically generated string).
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
void shell_output_str(struct shell_command *c,
|
|
|
|
char *str1, const char *str2);
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief Register a command with the shell
|
|
|
|
* \param c A pointer to a shell command structure, defined with SHELL_COMMAND()
|
|
|
|
*
|
|
|
|
* This function registers a shell command with the
|
|
|
|
* shell. After becoming registered, the shell command
|
|
|
|
* will appear in the list of available shell commands and
|
|
|
|
* is possible to invoke by a user. The shell command must
|
|
|
|
* have been defined with the SHELL_COMMAND() macro.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
void shell_register_command(struct shell_command *c);
|
2009-03-02 21:44:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Unregister a previously registered shell command
|
|
|
|
* \param c A pointer to a shell command structure
|
|
|
|
*
|
|
|
|
* This function unregisters a shell command that has
|
|
|
|
* previously been registered with eht
|
|
|
|
* shell_register_command() function.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
void shell_unregister_command(struct shell_command *c);
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief Start a shell command from another shell command
|
|
|
|
* \param commandline A pointer to a string that contains the command line
|
|
|
|
* \param commandline_len Length of the command line, in bytes
|
|
|
|
* \param child A pointer to the shell command that starts the command
|
|
|
|
* \param started_process A pointer to a shell command pointer that will be filled in with a pointer to the started command structure
|
|
|
|
* \retval A shell_retval indicating if the command was started as a foreground or a background process
|
|
|
|
*
|
|
|
|
* This function starts a command, or a set of
|
|
|
|
* commands. The function is called by a shell command to
|
|
|
|
* start other shell commands.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int shell_start_command(char *commandline, int commandline_len,
|
|
|
|
struct shell_command *child,
|
|
|
|
struct process **started_process);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \name Shell convenience functions
|
|
|
|
*
|
|
|
|
* These functions assist shell commands in parsing
|
|
|
|
* command lines
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Convert a string to a number
|
|
|
|
* \param str The input string
|
|
|
|
* \param retstr A pointer to a pointer to a string, is filled in with a pointer to the data after the number in the input string
|
|
|
|
* \retval The converted number
|
|
|
|
*
|
|
|
|
* This function converts a string to a number. The
|
|
|
|
* function returns the converted number and a pointer to
|
|
|
|
* the data that follows the number in the input string.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
unsigned long shell_strtolong(const char *str, const char **retstr);
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2008-02-05 00:42:17 +01:00
|
|
|
unsigned long shell_time(void);
|
|
|
|
void shell_set_time(unsigned long seconds);
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
2008-02-29 00:29:07 +01:00
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \name Shell variables, definitions, and return values
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
enum shell_retval {
|
2008-02-05 00:42:17 +01:00
|
|
|
SHELL_FOREGROUND,
|
|
|
|
SHELL_BACKGROUND,
|
|
|
|
SHELL_NOTHING,
|
|
|
|
};
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief The event number for shell input data
|
|
|
|
*
|
|
|
|
* The shell sends data as Contiki events to shell command
|
|
|
|
* processes. This variable contains the number of the
|
|
|
|
* Contiki event.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
extern int shell_event_input;
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* \brief Structure for shell input data
|
|
|
|
*
|
|
|
|
* The shell sends data as Contiki events to shell command
|
|
|
|
* processes. This structure contains the data in the
|
|
|
|
* event. The data is split into two halves, data1 and
|
|
|
|
* data2. The length of the data in the two halves is
|
|
|
|
* given by len1 and len2.
|
|
|
|
*
|
|
|
|
*/
|
2008-02-05 00:42:17 +01:00
|
|
|
struct shell_input {
|
|
|
|
char *data1;
|
|
|
|
const char *data2;
|
|
|
|
int len1, len2;
|
|
|
|
};
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2009-03-02 21:44:15 +01:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2010-02-03 21:37:29 +01:00
|
|
|
#include "shell-base64.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-blink.h"
|
2010-10-20 17:21:43 +02:00
|
|
|
#include "shell-collect-view.h"
|
2009-03-06 08:23:08 +01:00
|
|
|
#include "shell-coffee.h"
|
2009-04-16 16:33:47 +02:00
|
|
|
#include "shell-download.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-exec.h"
|
|
|
|
#include "shell-file.h"
|
2008-11-09 13:38:02 +01:00
|
|
|
#include "shell-httpd.h"
|
2009-03-02 00:33:46 +01:00
|
|
|
#include "shell-irc.h"
|
2010-02-02 16:28:52 +01:00
|
|
|
#include "shell-memdebug.h"
|
2009-11-03 23:52:39 +01:00
|
|
|
#include "shell-netperf.h"
|
2009-05-10 23:05:06 +02:00
|
|
|
#include "shell-netstat.h"
|
2009-03-06 08:23:08 +01:00
|
|
|
#include "shell-ping.h"
|
2009-03-05 22:12:02 +01:00
|
|
|
#include "shell-power.h"
|
2010-10-12 13:34:49 +02:00
|
|
|
#include "shell-powertrace.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-ps.h"
|
|
|
|
#include "shell-reboot.h"
|
2008-07-04 10:23:00 +02:00
|
|
|
#include "shell-rime-debug.h"
|
2010-01-31 20:35:12 +01:00
|
|
|
#include "shell-rime-debug-runicast.h"
|
2009-05-10 23:05:06 +02:00
|
|
|
#include "shell-rime-neighbors.h"
|
2008-02-05 13:23:32 +01:00
|
|
|
#include "shell-rime-netcmd.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-rime-ping.h"
|
2009-04-16 16:33:47 +02:00
|
|
|
#include "shell-rime-sendcmd.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-rime-sniff.h"
|
2009-05-10 23:05:06 +02:00
|
|
|
#include "shell-rime-unicast.h"
|
2008-07-03 19:56:17 +02:00
|
|
|
#include "shell-rime.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-rsh.h"
|
2008-02-08 13:49:54 +01:00
|
|
|
#include "shell-run.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-sendtest.h"
|
|
|
|
#include "shell-sky.h"
|
2009-03-06 08:23:08 +01:00
|
|
|
#include "shell-tcpsend.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-text.h"
|
|
|
|
#include "shell-time.h"
|
2009-03-06 08:23:08 +01:00
|
|
|
#include "shell-udpsend.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
#include "shell-vars.h"
|
2008-11-09 13:38:02 +01:00
|
|
|
#include "shell-wget.h"
|
2008-02-05 00:42:17 +01:00
|
|
|
|
2013-11-24 16:57:08 +01:00
|
|
|
#endif /* SHELL_H_ */
|
2009-03-02 21:44:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
/** @} */
|