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

USB commands. More...

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/usb.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>

Go to the source code of this file.

Data Structures

struct  usbscan_options
 "usbscan" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int usbscan_exec (int argc, char **argv)
 "usbscan" command More...
 
 COMMAND (usbscan, usbscan_exec)
 USB commands. More...
 

Variables

static struct option_descriptor usbscan_opts [] = {}
 "usbscan" option list More...
 
static struct command_descriptor usbscan_cmd
 "usbscan" command descriptor More...
 

Detailed Description

USB commands.

Definition in file usb_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ usbscan_exec()

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

"usbscan" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 58 of file usb_cmd.c.

58  {
59  struct usbscan_options opts;
60  struct named_setting setting;
61  struct usb_device *usb;
62  unsigned long prev;
63  uint16_t busdev;
64  int len;
65  int rc;
66 
67  /* Parse options */
68  if ( ( rc = parse_options ( argc, argv, &usbscan_cmd, &opts ) ) != 0 )
69  goto err_parse_options;
70 
71  /* Parse setting name */
72  if ( ( rc = parse_autovivified_setting ( argv[optind],
73  &setting ) ) != 0 )
74  goto err_parse_setting;
75 
76  /* Determine starting bus:dev.fn address */
77  if ( ( len = fetchn_setting ( setting.settings, &setting.setting,
78  NULL, &setting.setting, &prev ) ) < 0 ) {
79  /* Setting not yet defined: start searching from 00:00 */
80  busdev = 0;
81  } else {
82  /* Setting is defined: start searching from next location */
83  busdev = ( prev + 1 );
84  if ( ! busdev ) {
85  rc = -ENOENT;
86  goto err_end;
87  }
88  }
89 
90  /* Find next existent USB device */
91  if ( ( rc = usb_find_next ( &usb, &busdev ) ) != 0 )
92  goto err_find_next;
93 
94  /* Apply default type if necessary. Use ":uint16" rather than
95  * ":hex" to allow for easy inclusion within a
96  * "${usb/${location}....}" constructed setting.
97  */
98  if ( ! setting.setting.type )
99  setting.setting.type = &setting_type_uint16;
100 
101  /* Store setting */
102  if ( ( rc = storen_setting ( setting.settings, &setting.setting,
103  busdev ) ) != 0 ) {
104  printf ( "Could not store \"%s\": %s\n",
105  setting.setting.name, strerror ( rc ) );
106  goto err_store;
107  }
108 
109  err_store:
110  err_end:
111  err_find_next:
112  err_parse_setting:
113  err_parse_options:
114  return rc;
115 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
A parsed named setting.
Definition: parseopt.h:122
int optind
Current option index.
Definition: getopt.c:51
"usbscan" options
Definition: usb_cmd.c:41
static struct command_descriptor usbscan_cmd
"usbscan" command descriptor
Definition: usb_cmd.c:47
int storen_setting(struct settings *settings, const struct setting *setting, unsigned long value)
Store numeric value of setting.
Definition: settings.c:1414
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
Definition: parseopt.c:336
#define ENOENT
No such file or directory.
Definition: errno.h:514
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
const char * name
Name.
Definition: settings.h:28
int usb_find_next(struct usb_device **usb, uint16_t *busdev)
Find next USB device.
Definition: usb.c:2301
ring len
Length.
Definition: dwmac.h:231
const struct setting_type * type
Setting type.
Definition: settings.h:36
A USB device.
Definition: usb.h:722
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:1372
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A setting.
Definition: settings.h:23
static union @447 opts
"cert<xxx>" option list
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References ENOENT, fetchn_setting(), len, setting::name, NULL, optind, opts, parse_autovivified_setting(), parse_options(), printf(), rc, storen_setting(), strerror(), setting::type, usb_find_next(), and usbscan_cmd.

◆ COMMAND()

COMMAND ( usbscan  ,
usbscan_exec   
)

USB commands.

Variable Documentation

◆ usbscan_opts

struct option_descriptor usbscan_opts[] = {}
static

"usbscan" option list

Definition at line 44 of file usb_cmd.c.

◆ usbscan_cmd

struct command_descriptor usbscan_cmd
static
Initial value:
=
"<setting>" )
"usbscan" options
Definition: usb_cmd.c:41
static struct option_descriptor usbscan_opts[]
"usbscan" option list
Definition: usb_cmd.c:44
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108

"usbscan" command descriptor

Definition at line 47 of file usb_cmd.c.

Referenced by usbscan_exec().