iPXE
Data Structures | Functions | Variables
nvo_cmd.c File Reference

Non-volatile option commands. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <byteswap.h>
#include <ipxe/settings.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <readline/readline.h>

Go to the source code of this file.

Data Structures

struct  show_options
 "show" options More...
 
struct  set_core_options
 "set", "clear", and "read" options More...
 
struct  inc_options
 "inc" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static int show_exec (int argc, char **argv)
 "show" command More...
 
static int set_core_exec (int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, struct set_core_options *opts, char **args, char **value))
 "set", "clear", and "read" command More...
 
static int set_value (struct named_setting *setting __unused, struct set_core_options *opts __unused, char **args, char **value)
 Get setting value for "set" command. More...
 
static int set_exec (int argc, char **argv)
 "set" command More...
 
static int clear_value (struct named_setting *setting __unused, struct set_core_options *opts __unused, char **args __unused, char **value)
 Get setting value for "clear" command. More...
 
static int clear_exec (int argc, char **argv)
 "clear" command More...
 
static int read_value (struct named_setting *setting, struct set_core_options *opts, char **args __unused, char **value)
 Get setting value for "read" command. More...
 
static int read_exec (int argc, char **argv)
 "read" command More...
 
static int inc_exec (int argc, char **argv)
 "inc" command More...
 
 COMMAND (show, show_exec)
 Non-volatile option commands. More...
 
 COMMAND (set, set_exec)
 
 COMMAND (clear, clear_exec)
 
 COMMAND (read, read_exec)
 
 COMMAND (inc, inc_exec)
 

Variables

static struct option_descriptor show_opts [] = {}
 "show" option list More...
 
static struct command_descriptor show_cmd
 "show" command descriptor More...
 
union {
   struct option_descriptor   set [0]
 
   struct option_descriptor   clear [0]
 
   struct option_descriptor   read [1]
 
set_core_opts
 "set", "clear", and "read" option list More...
 
static struct command_descriptor set_cmd
 "set" command descriptor More...
 
static struct command_descriptor clear_cmd
 "clear" command descriptor More...
 
static struct command_descriptor read_cmd
 "read" command descriptor More...
 
static struct option_descriptor inc_opts [] = {}
 "inc" option list More...
 
static struct command_descriptor inc_cmd
 "inc" command descriptor More...
 

Detailed Description

Non-volatile option commands.

Definition in file nvo_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ show_exec()

static int show_exec ( int  argc,
char **  argv 
)
static

"show" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 62 of file nvo_cmd.c.

62  {
63  struct show_options opts;
64  struct named_setting setting;
65  struct settings *origin;
66  struct setting fetched;
67  char name_buf[32];
68  char *value;
69  int len;
70  int rc;
71 
72  /* Parse options */
73  if ( ( rc = parse_options ( argc, argv, &show_cmd, &opts ) ) != 0 )
74  goto err_parse_options;
75 
76  /* Parse setting name */
77  if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
78  goto err_parse_setting;
79 
80  /* Fetch formatted setting value */
81  if ( ( len = fetchf_setting_copy ( setting.settings, &setting.setting,
82  &origin, &fetched, &value ) ) < 0 ) {
83  rc = len;
84  printf ( "Could not find \"%s\": %s\n",
85  setting.setting.name, strerror ( rc ) );
86  goto err_fetchf;
87  }
88 
89  /* Print setting value */
90  setting_name ( origin, &fetched, name_buf, sizeof ( name_buf ) );
91  printf ( "%s = %s\n", name_buf, value );
92 
93  /* Success */
94  rc = 0;
95 
96  free ( value );
97  err_fetchf:
98  err_parse_setting:
99  err_parse_options:
100  return rc;
101 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t origin
Origin.
Definition: hyperv.h:20
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
A parsed named setting.
Definition: parseopt.h:123
int optind
Current option index.
Definition: getopt.c:52
int fetchf_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, char **value)
Fetch copy of formatted value of setting.
Definition: settings.c:1277
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:485
const char * name
Name.
Definition: settings.h:29
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
ring len
Length.
Definition: dwmac.h:231
int parse_existing_setting(char *text, struct named_setting *setting)
Parse existing setting name.
Definition: parseopt.c:323
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
static struct command_descriptor show_cmd
"show" command descriptor
Definition: nvo_cmd.c:52
"show" options
Definition: nvo_cmd.c:46
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
static union @447 opts
"cert<xxx>" option list
int setting_name(struct settings *settings, const struct setting *setting, char *buf, size_t len)
Return full setting name.
Definition: settings.c:1607

References fetchf_setting_copy(), free, len, setting::name, optind, opts, origin, parse_existing_setting(), parse_options(), printf(), rc, setting_name(), show_cmd, strerror(), and value.

◆ set_core_exec()

static int set_core_exec ( int  argc,
char **  argv,
struct command_descriptor cmd,
int(*)(struct named_setting *setting, struct set_core_options *opts, char **args, char **value get_value 
)
static

"set", "clear", and "read" command

Parameters
argcArgument count
argvArgument list
cmdCommand descriptor
get_valueMethod to obtain setting value
Return values
rcReturn status code

Definition at line 148 of file nvo_cmd.c.

152  {
153  struct set_core_options opts;
154  struct named_setting setting;
155  char *value;
156  int rc;
157 
158  /* Parse options */
159  if ( ( rc = parse_options ( argc, argv, cmd, &opts ) ) != 0 )
160  goto err_parse_options;
161 
162  /* Parse setting name */
163  if ( ( rc = parse_autovivified_setting ( argv[optind],
164  &setting ) ) != 0 )
165  goto err_parse_setting;
166 
167  /* Parse setting value */
168  if ( ( rc = get_value ( &setting, &opts, &argv[ optind + 1 ],
169  &value ) ) != 0 )
170  goto err_get_value;
171 
172  /* Apply default type if necessary */
173  if ( ! setting.setting.type )
174  setting.setting.type = &setting_type_string;
175 
176  /* Store setting */
177  if ( ( rc = storef_setting ( setting.settings, &setting.setting,
178  value ) ) != 0 ) {
179  printf ( "Could not store \"%s\": %s\n",
180  setting.setting.name, strerror ( rc ) );
181  goto err_store;
182  }
183 
184  err_store:
185  free ( value );
186  err_get_value:
187  err_parse_setting:
188  err_parse_options:
189  return rc;
190 }
"set", "clear", and "read" options
Definition: nvo_cmd.c:104
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
A parsed named setting.
Definition: parseopt.h:123
int optind
Current option index.
Definition: getopt.c:52
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
Definition: parseopt.c:337
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:485
const char * name
Name.
Definition: settings.h:29
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
const struct setting_type * type
Setting type.
Definition: settings.h:37
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition: settings.c:1320
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A setting.
Definition: settings.h:24
static union @447 opts
"cert<xxx>" option list
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29

References cmd, free, setting::name, optind, opts, parse_autovivified_setting(), parse_options(), printf(), rc, storef_setting(), strerror(), setting::type, and value.

Referenced by clear_exec(), read_exec(), and set_exec().

◆ set_value()

static int set_value ( struct named_setting *setting  __unused,
struct set_core_options *opts  __unused,
char **  args,
char **  value 
)
static

Get setting value for "set" command.

Parameters
settingNamed setting
optsOptions list
argsRemaining arguments
Return values
valueSetting value
rcReturn status code

Definition at line 201 of file nvo_cmd.c.

203  {
204 
205  *value = concat_args ( args );
206  if ( ! *value )
207  return -ENOMEM;
208 
209  return 0;
210 }
#define ENOMEM
Not enough space.
Definition: errno.h:535
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * concat_args(char **args)
Concatenate arguments.
Definition: exec.c:359

References concat_args(), ENOMEM, and value.

Referenced by set_exec().

◆ set_exec()

static int set_exec ( int  argc,
char **  argv 
)
static

"set" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 219 of file nvo_cmd.c.

219  {
220  return set_core_exec ( argc, argv, &set_cmd, set_value );
221 }
static struct command_descriptor set_cmd
"set" command descriptor
Definition: nvo_cmd.c:125
static int set_value(struct named_setting *setting __unused, struct set_core_options *opts __unused, char **args, char **value)
Get setting value for "set" command.
Definition: nvo_cmd.c:201
static int set_core_exec(int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, struct set_core_options *opts, char **args, char **value))
"set", "clear", and "read" command
Definition: nvo_cmd.c:148

References set_cmd, set_core_exec(), and set_value().

◆ clear_value()

static int clear_value ( struct named_setting *setting  __unused,
struct set_core_options *opts  __unused,
char **args  __unused,
char **  value 
)
static

Get setting value for "clear" command.

Parameters
settingNamed setting
argsRemaining arguments
optsOptions list
Return values
valueSetting value
rcReturn status code

Definition at line 232 of file nvo_cmd.c.

234  {
235 
236  *value = NULL;
237  return 0;
238 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References NULL, and value.

Referenced by clear_exec().

◆ clear_exec()

static int clear_exec ( int  argc,
char **  argv 
)
static

"clear" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 247 of file nvo_cmd.c.

247  {
248  return set_core_exec ( argc, argv, &clear_cmd, clear_value );
249 }
static int clear_value(struct named_setting *setting __unused, struct set_core_options *opts __unused, char **args __unused, char **value)
Get setting value for "clear" command.
Definition: nvo_cmd.c:232
static struct command_descriptor clear_cmd
"clear" command descriptor
Definition: nvo_cmd.c:130
static int set_core_exec(int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, struct set_core_options *opts, char **args, char **value))
"set", "clear", and "read" command
Definition: nvo_cmd.c:148

References clear_cmd, clear_value(), and set_core_exec().

◆ read_value()

static int read_value ( struct named_setting setting,
struct set_core_options opts,
char **args  __unused,
char **  value 
)
static

Get setting value for "read" command.

Parameters
settingNamed setting
argsRemaining arguments
optsOptions list
Return values
valueSetting value
rcReturn status code

Definition at line 260 of file nvo_cmd.c.

262  {
263  char *existing;
264  int rc;
265 
266  /* Read existing value, treating errors as equivalent to an
267  * empty initial setting.
268  */
269  fetchf_setting_copy ( setting->settings, &setting->setting,
270  NULL, &setting->setting, &existing );
271 
272  /* Read new value */
273  if ( ( rc = readline_history ( NULL, existing, NULL, opts->timeout,
274  value ) ) != 0 )
275  goto err_readline;
276 
277  err_readline:
278  free ( existing );
279  return rc;
280 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int fetchf_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, char **value)
Fetch copy of formatted value of setting.
Definition: settings.c:1277
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A readline history buffer.
Definition: readline.h:32
A setting.
Definition: settings.h:24
static union @447 opts
"cert<xxx>" option list
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References fetchf_setting_copy(), free, NULL, opts, rc, and value.

Referenced by read_exec().

◆ read_exec()

static int read_exec ( int  argc,
char **  argv 
)
static

"read" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 289 of file nvo_cmd.c.

289  {
290  return set_core_exec ( argc, argv, &read_cmd, read_value );
291 }
static int set_core_exec(int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, struct set_core_options *opts, char **args, char **value))
"set", "clear", and "read" command
Definition: nvo_cmd.c:148
static int read_value(struct named_setting *setting, struct set_core_options *opts, char **args __unused, char **value)
Get setting value for "read" command.
Definition: nvo_cmd.c:260
static struct command_descriptor read_cmd
"read" command descriptor
Definition: nvo_cmd.c:135

References read_cmd, read_value(), and set_core_exec().

◆ inc_exec()

static int inc_exec ( int  argc,
char **  argv 
)
static

"inc" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 311 of file nvo_cmd.c.

311  {
312  struct inc_options opts;
313  struct named_setting setting;
314  unsigned int increment = 1;
315  unsigned long value;
316  int rc;
317 
318  /* Parse options */
319  if ( ( rc = parse_options ( argc, argv, &inc_cmd, &opts ) ) != 0 )
320  goto err_parse_options;
321 
322  /* Parse setting name */
323  if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
324  goto err_parse_setting;
325 
326  /* Parse increment (if present) */
327  if ( ( ( optind + 1 ) < argc ) &&
328  ( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
329  goto err_parse_increment;
330 
331  /* Read existing value, treating errors as equivalent to a
332  * zero-valued :int32 initial setting.
333  */
334  if ( ( rc = fetchn_setting ( setting.settings, &setting.setting,
335  NULL, &setting.setting, &value ) ) != 0 ) {
336  value = 0;
337  if ( ! setting.setting.type )
338  setting.setting.type = &setting_type_int32;
339  }
340 
341  /* Increment value */
342  value += increment;
343 
344  /* Store updated setting value */
345  if ( ( rc = storen_setting ( setting.settings, &setting.setting,
346  value ) ) != 0 ) {
347  printf ( "Could not store \"%s\": %s\n",
348  setting.setting.name, strerror ( rc ) );
349  goto err_store;
350  }
351 
352  err_store:
353  err_parse_increment:
354  err_parse_setting:
355  err_parse_options:
356  return rc;
357 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
A parsed named setting.
Definition: parseopt.h:123
int optind
Current option index.
Definition: getopt.c:52
int storen_setting(struct settings *settings, const struct setting *setting, unsigned long value)
Store numeric value of setting.
Definition: settings.c:1415
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:485
const char * name
Name.
Definition: settings.h:29
"inc" options
Definition: nvo_cmd.c:294
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
const struct setting_type * type
Setting type.
Definition: settings.h:37
int parse_existing_setting(char *text, struct named_setting *setting)
Parse existing setting name.
Definition: parseopt.c:323
int fetchn_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, unsigned long *value)
Fetch numeric value of setting.
Definition: settings.c:1373
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
A setting.
Definition: settings.h:24
static union @447 opts
"cert<xxx>" option list
static struct command_descriptor inc_cmd
"inc" command descriptor
Definition: nvo_cmd.c:300
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References fetchn_setting(), inc_cmd, setting::name, NULL, optind, opts, parse_existing_setting(), parse_integer(), parse_options(), printf(), rc, storen_setting(), strerror(), setting::type, and value.

◆ COMMAND() [1/5]

COMMAND ( show  ,
show_exec   
)

Non-volatile option commands.

◆ COMMAND() [2/5]

COMMAND ( set  ,
set_exec   
)

◆ COMMAND() [3/5]

COMMAND ( clear  ,
clear_exec   
)

◆ COMMAND() [4/5]

COMMAND ( read  ,
read_exec   
)

◆ COMMAND() [5/5]

COMMAND ( inc  ,
inc_exec   
)

Variable Documentation

◆ show_opts

struct option_descriptor show_opts[] = {}
static

"show" option list

Definition at line 49 of file nvo_cmd.c.

◆ show_cmd

struct command_descriptor show_cmd
static
Initial value:
=
COMMAND_DESC ( struct show_options, show_opts, 1, 1, "<setting>" )
static struct option_descriptor show_opts[]
"show" option list
Definition: nvo_cmd.c:49
"show" options
Definition: nvo_cmd.c:46
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109

"show" command descriptor

Definition at line 52 of file nvo_cmd.c.

Referenced by show_exec().

◆ set

static fd_set * set
Initial value:
{
*set &= ~( 1 << fd )
struct option_descriptor set[0]
Definition: nvo_cmd.c:112

Definition at line 112 of file nvo_cmd.c.

Referenced by ath5k_hw_rfb_op(), ath9k_hw_set_operating_mode(), ath9k_hw_setrxabort(), ath9k_reg_rmw(), igbvf_vfta_set_vf(), net80211_set_state(), and tg3_phy_auxctl_write().

◆ clear

struct option_descriptor clear[0]

Definition at line 114 of file nvo_cmd.c.

Referenced by b44_wait_bit(), and net80211_set_state().

◆ read

struct option_descriptor read[1]

◆ set_core_opts

union { ... } set_core_opts
Initial value:
= {
.read = {
OPTION_DESC ( "timeout", 't', required_argument,
},
}
"set", "clear", and "read" options
Definition: nvo_cmd.c:104
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:115
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:68
Option requires an argument.
Definition: getopt.h:19
void timeout(int)

"set", "clear", and "read" option list

◆ set_cmd

struct command_descriptor set_cmd
static
Initial value:
=
1, MAX_ARGUMENTS, "<setting> <value>" )
"set", "clear", and "read" options
Definition: nvo_cmd.c:104
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:98
static union @449 set_core_opts
"set", "clear", and "read" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109

"set" command descriptor

Definition at line 125 of file nvo_cmd.c.

Referenced by set_exec().

◆ clear_cmd

struct command_descriptor clear_cmd
static
Initial value:
=
1, 1, "<setting>" )
"set", "clear", and "read" options
Definition: nvo_cmd.c:104
static union @449 set_core_opts
"set", "clear", and "read" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109

"clear" command descriptor

Definition at line 130 of file nvo_cmd.c.

Referenced by clear_exec().

◆ read_cmd

struct command_descriptor read_cmd
static
Initial value:
=
1, 1, "<setting>" )
"set", "clear", and "read" options
Definition: nvo_cmd.c:104
static union @449 set_core_opts
"set", "clear", and "read" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109

"read" command descriptor

Definition at line 135 of file nvo_cmd.c.

Referenced by eeprom_read(), falcon_spi_rw(), mdio_read(), read_eeprom(), read_exec(), and sis900_read_eeprom().

◆ inc_opts

struct option_descriptor inc_opts[] = {}
static

"inc" option list

Definition at line 297 of file nvo_cmd.c.

◆ inc_cmd

struct command_descriptor inc_cmd
static
Initial value:
=
"<setting> [<increment>]" )
static struct option_descriptor inc_opts[]
"inc" option list
Definition: nvo_cmd.c:297
"inc" options
Definition: nvo_cmd.c:294
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109

"inc" command descriptor

Definition at line 300 of file nvo_cmd.c.

Referenced by inc_exec().