OneCore⢠Storage SDK Release 11.2
Emulex SDK Utility (elxsdkutil)
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
elxu_main.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011-2015, Emulex
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
*
11
* 2. Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
*
15
* 3. Neither the name of the copyright holder nor the names of its contributors
16
* may be used to endorse or promote products derived from this software
17
* without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
* POSSIBILITY OF SUCH DAMAGE.
30
*
31
*/
32
33
/**
34
* @file
35
* TBD
36
*/
37
38
/**
39
* @defgroup cmd_line_parsing Command Line Parsing and Command Execution
40
* @defgroup dev_enum Device Enumeration (Using "list")
41
* @defgroup flash_parsing Flash File Parsing (Using "file-info")
42
* @defgroup flash_access Flash Access
43
* @defgroup mbox_cmd Mailbox Command Construction
44
* @defgroup dev_mgmt Device Management API
45
*/
46
47
48
#include <stdio.h>
49
#include <stdlib.h>
50
#include <unistd.h>
51
#include <getopt.h>
52
#include <stdint.h>
53
#include <string.h>
54
#include <ctype.h>
55
56
#include <
elxu_device.h
>
57
#include <
elxu_sli4.h
>
58
#include <
elxu_sky.h
>
59
#include <
elxu_ufi.h
>
60
#include <
elxu_dwnld.h
>
61
#include <
elxu_dump.h
>
62
#include <
elxu_mbox.h
>
63
#include "
elxu_common.h
"
64
#include "
elxu_commands.h
"
65
66
#include <
ecd_api.h
>
67
68
#include "
version.h
"
69
70
71
/**
72
* @brief main elxsdkutil CLI functionality
73
*
74
* This function processes CLI parameters and initiates appropriate functional
75
* calls.
76
*
77
* @param argc number of entered cli words
78
* @param *argv[] pointer to array of entered words
79
*/
80
int
main
(
int
argc,
char
*argv[])
81
{
82
elxu_device_t
*device;
83
int
i;
84
int
result;
85
86
if
(getuid() != 0) {
87
printf(
"==[ you may need root to run the command ]==\n"
);
88
}
89
90
/* Special case - if no arguments given print usage and exit */
91
if
(argc == 1) {
92
fprintf(stderr,
"Type 'elxsdkutil help' for usage\n"
);
93
exit(0);
94
}
95
96
elxu_build_device_list
(argc, argv);
97
device =
elxu_device_from_args
(argc, argv);
98
99
for
(i = 0; i <
ARRAY_SIZE
(
cmd_table
); i++) {
100
if
(strcmp(argv[1],
cmd_table
[i].name) == 0) {
101
if
(device == NULL) {
102
if
(
cmd_table
[i].nodev_handler != NULL) {
103
result =
cmd_table
[i].
nodev_handler
(argc, argv);
104
}
else
{
105
fprintf(stderr,
"The %s command requires a device\n"
,
106
argv[1]);
107
result = -1;
108
}
109
}
else
{
110
switch
(device->
driver
) {
111
case
DEVICE_DRIVER_OCS
:
112
case
DEVICE_DRIVER_USPACE
:
113
if
(
cmd_table
[i].ocs_handler != NULL) {
114
result =
cmd_table
[i].
ocs_handler
(argc, argv);
115
}
else
{
116
fprintf(stderr,
117
"The %s command is not supported with the OCS SDK drivers\n"
,
118
argv[1]);
119
result = -1;
120
}
121
break
;
122
case
DEVICE_DRIVER_PT
:
123
if
(
cmd_table
[i].pt_handler != NULL) {
124
result =
cmd_table
[i].
pt_handler
(argc, argv);
125
}
else
{
126
fprintf(stderr,
"The %s command is not supported with the elx_pt driver\n"
,
127
argv[1]);
128
result = -1;
129
}
130
break
;
131
case
DEVICE_DRIVER_NONE
:
132
if
(
cmd_table
[i].nodriver_handler != NULL) {
133
result =
cmd_table
[i].
nodriver_handler
(argc, argv);
134
}
else
{
135
fprintf(stderr,
136
"The %s command is not supported with the OCS SDK drivers\n"
,
137
argv[1]);
138
result = -1;
139
}
140
break
;
141
case
DEVICE_DRIVER_BE2NET
:
142
/* See if there's a nodev handler that will work */
143
if
(
cmd_table
[i].nodev_handler != NULL) {
144
result =
cmd_table
[i].
nodev_handler
(argc, argv);
145
}
else
{
146
fprintf(stderr,
"Device %d is controlled by the be2net driver, \
147
which is unsupported by %s\n"
, device->
deviceIndex
, argv[0]);
148
result = -1;
149
}
150
break
;
151
case
DEVICE_DRIVER_UNKNOWN
:
152
/* See if there's a nodev handler that will work */
153
if
(
cmd_table
[i].nodev_handler != NULL) {
154
result =
cmd_table
[i].
nodev_handler
(argc, argv);
155
}
else
{
156
fprintf(stderr,
"Unknown driver handling device %d\n"
,
157
device->
deviceIndex
);
158
result = -1;
159
}
160
break
;
161
}
162
}
163
164
elxu_delete_device_list
();
165
return
result;
166
}
167
}
168
169
fprintf(stderr,
"Unknown command: %s\n"
, argv[1]);
170
fprintf(stderr,
"Type 'elxsdkutil help' for usage\n"
);
171
172
elxu_delete_device_list
();
173
return
-1;
174
}
175
176
/**
177
* @page elxsdkutil_components.html Design and Main Components
178
* - @ref cmd_line_parsing
179
* - @ref dev_enum
180
* - @ref flash_parsing
181
* - @ref flash_access
182
* - @ref mbox_cmd
183
* - @ref dev_mgmt
184
*
185
* @n @section util_main_components Main Components of the elxsdkutil Structure
186
*
187
*/
ecd_api.h
DEVICE_DRIVER_USPACE
Definition:
elxu_device.h:71
elxu_device.h
elxu_dump.h
elxu_device_from_args
elxu_device_t * elxu_device_from_args(int argc, char *argv[])
Return a pointer to a device based on command line args.
Definition:
elxu_device.c:688
DEVICE_DRIVER_PT
Definition:
elxu_device.h:72
cmd_table_entry_t::nodriver_handler
handler_t nodriver_handler
Definition:
elxu_commands.h:52
elxu_ufi.h
elxu_common.h
cmd_table
static cmd_table_entry_t cmd_table[]
Definition:
elxu_commands.h:199
DEVICE_DRIVER_NONE
Definition:
elxu_device.h:74
elxu_sli4.h
elxu_device_t
Definition:
elxu_device.h:78
elxu_device_t::deviceIndex
uint32_t deviceIndex
Definition:
elxu_device.h:85
elxu_mbox.h
elxu_sky.h
main
int main(int argc, char *argv[])
main elxsdkutil CLI functionality
Definition:
elxu_main.c:80
DEVICE_DRIVER_UNKNOWN
Definition:
elxu_device.h:75
version.h
cmd_table_entry_t::pt_handler
handler_t pt_handler
Definition:
elxu_commands.h:50
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition:
elxu_common.h:46
cmd_table_entry_t::nodev_handler
handler_t nodev_handler
Definition:
elxu_commands.h:51
elxu_build_device_list
void elxu_build_device_list(int argc, char *argv[])
Create a list of devices.
Definition:
elxu_device.c:131
elxu_delete_device_list
void elxu_delete_device_list()
Definition:
elxu_device.c:164
DEVICE_DRIVER_OCS
Definition:
elxu_device.h:70
DEVICE_DRIVER_BE2NET
Definition:
elxu_device.h:73
elxu_commands.h
elxu_dwnld.h
elxu_device_t::driver
elxu_device_driver_e driver
Definition:
elxu_device.h:90
cmd_table_entry_t::ocs_handler
handler_t ocs_handler
Definition:
elxu_commands.h:49
elxu_main.c