Command Processor and Console

SDK provide in-built command processor and console with many features like User authentication and command autocomplete etc.

By default SDK provide system commands and linux like core utility commands.

Available commands

Command

Description

devinfo

Get device information

sysinfo

Get system information

loglevel

Set or get current debug loglevel

reboot

Reboot system

ntpdate

Get date time information from NTP server

df

Show information about filesystem

ls

List file(s) or directory

echo

Display line of text

cat

Display file on standard output

mkdir

Make directory

rm

Remove file or directory

mv

Move file or directory

logout

Logout current user

help

Get command help

Optional Commands

Some commands are available only when a module is used or enabled by the application.

Following is the list of Commands with modules.

TODO: optional command list to be added

Custom commands

Command processor APIs can be used to add new commands to the system.

Command Processor API Reference

Header File

Functions

int command_process(const char *cmd, int len, struct cmdinfo_t *info, commandproc_cb callback, void *arg)

Execute command buffer

Multiple commands can be separated by ; and will be executed by the built-in parser.

Return

0 on success, or != 0 on error. command_ret_e

Parameters
  • cmd: [in] String containing list of commands

  • len: [in] length of cmd string

  • info: [in] Command information structure

  • callback: [in] process callback function of type commandproc_cb, called after execution of each command in the list

  • arg: [in] Argument passed to callback function

Structures

struct cmdinfo_t

Command information structure, passed to command handler function

Public Members

int src

Command source command_src_e

void *data

user data attached to command

struct cmddesc_t

Command descriptor structure

Public Members

const char *cmd

Name of command

int min_arg

Minimum arguments

int max_arg

Maximum arguments

cmd_handler_f cmdfn

Command handler function

const char *help

Short help message

const char *usage

Long help message with usage

int type

Command type flags command_type_e

Macros

CMD_MAX_ARGS

Maximum number of allowed arguments including commmand

CMD_ADD(_name, _minarg, _maxarg, _cmd, _help, _usage, _type)

Add new command

Parameters
  • _name: Name of command

  • _minarg: Minimum number of arguments including command (must be >= 1)

  • _maxarg: Maximum number of arguments including command (must be >= 1 & <= CMD_MAX_ARGS)

  • _cmd: Command handler function

  • _help: Short help message

  • _usage: Long help message and usage detail

  • _type: Command type flag see command_type_e

Type Definitions

typedef int (*cmd_handler_f)(int argc, const char **argv, struct cmdinfo_t *info)

Command Handler function

Return

Command return type command_ret_e

Parameters
  • argc: Number of arguments

  • argv: Argument list

  • info: Command info structure

typedef void (*commandproc_cb)(int result, struct cmdinfo_t *info, void *arg)

Command process callback function

Parameters
  • result: Result of command executing

  • info: Command information structure

  • arg: User argument

Enumerations

enum command_ret_e

Command executing return code

Values:

enumerator CMD_RET_SUCCESS

Command executed successfully

enumerator CMD_RET_FAILURE

Command executing failure

enumerator CMD_RET_PERM

Command Permission denied

enumerator CMD_RET_LOGOUT

Execute session logout

enumerator CMD_RET_USAGE = -1

Failure, please report ‘usage’ error

enum command_src_e

Source of command used in cmdinfo_t structure

Values:

enumerator CMD_SRC_CONSOLE

Command source console

enumerator CMD_SRC_BTCONSOLE

Command source Bluetooth Console

enumerator CMD_SRC_DBG

Command source Remote debug console

enumerator CMD_SRC_SMS

Command source SMS

enumerator CMD_SRC_TCP

Command source TCP

enumerator CMD_SRC_SYS

Command source system() API

enum command_type_e

Command type flags. These flags can be ORed together.

Values:

enumerator CMD_TYPE_DEFAULT = 0

Default command, executing allowed everywhere and can be executed by user and admin.

enumerator CMD_TYPE_HIDDEN = 1

Hidden command, Only executed by admin user; Unless allowed by allow flags

enumerator CMD_ALLOW_SMS = 2

Command allowed over SMS

enumerator CMD_ALLOW_TCP = 4

Command allowed over TCP

enumerator CMD_ALLOW_DBG = 8

Command allowed over remote debug

enumerator CMD_ALLOW_CONSOLE = 0x10

Command allowed over console

enumerator CMD_ALLOW_BT_CONSOLE = 0x20

Command allowed over Bluetooth console

enumerator CMD_ALLOW_SYS = 0x40

Command allowed to execute via system() API

enumerator CMD_ALLOW_ALL = 0x7F

Command allowed from all sources

enumerator CMD_ALLOW_TCP_SMS = 0x6

Command allowed over TCP and SMS

enumerator CMD_ALLOW_CONSOLE_ONLY = 0x38

Command allowed over Console only

enumerator CMD_ALLOW_TCP_SMS_DBG = 0xE

Command allowed over TCP, SMS and remote console

Console API Reference

Header File

Functions

int cli_set_authfn(cliauth_f fn)

Set Authentication function

Return

0 on success, negative value on error

Parameters
  • fn: Pointer to auth function of type cliauth_f

Type Definitions

typedef int (*cliauth_f)(const char *user, const char *pass)

CLI Authentication function

Return

Authentication return code, see cli_auth_rc

Parameters
  • user: Username entered on console.

    For Remote debug console this value is “rdbg”.

    For Bluetooth console this value is “btcli”.

  • pass: Password

Enumerations

enum cli_auth_rc

CLI authentication return code

Values:

enumerator AUTH_FAIL

Authentication failed

enumerator AUTH_USER

Authentication success with user credentials

enumerator AUTH_ADMIN

Authentication success with admin credentials