xref: /titanic_41/usr/src/cmd/scadm/sparc/mpxu/common/show.c (revision f29fbe76ce646ba8bcf62627d89087d5f02c62a8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * show.c: support for scadm show <variable> option (to show the value of
31  * a service processor NV variable)
32  */
33 
34 #include <libintl.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <time.h>  /* required by librsc.h */
38 
39 #include "librsc.h"
40 #include "adm.h"
41 
42 
43 
44 char *ADM_Get_Var(char *Variable);
45 
46 static void ADM_Show_Var(char *Variable);
47 static int ADM_Get_Next_Var(char *oldVar, char *newVar, int maxSize);
48 static void command_line();
49 
50 
51 void
52 ADM_Process_show(int argc, char *argv[])
53 {
54 	char		*oldVar;
55 	static char	newVar[128];
56 
57 
58 	if ((argc != 2) && (argc != 3)) {
59 		(void) fprintf(stderr, "\n%s\n\n",
60 		    gettext("USAGE: scadm show [variable]"));
61 		exit(-1);
62 	}
63 
64 	ADM_Start();
65 
66 	if (argc == 2) {
67 		oldVar = NULL;
68 		newVar[0] = 0x0;
69 		while (ADM_Get_Next_Var(oldVar, newVar, 128) == 0) {
70 			ADM_Show_Var(newVar);
71 			oldVar = newVar;
72 		}
73 	} else {
74 		ADM_Show_Var(argv[2]);
75 	}
76 }
77 
78 void
79 ADM_Process_show_network()
80 {
81 	rscp_msg_t		Message;
82 	struct timespec		Timeout;
83 	dp_get_network_cfg_r_t	*netParams;
84 
85 	ADM_Start();
86 
87 	Message.type = DP_GET_NETWORK_CFG;
88 	Message.len = 0;
89 	Message.data = NULL;
90 
91 	ADM_Send(&Message);
92 
93 	Timeout.tv_nsec = 0;
94 	Timeout.tv_sec = ADM_TIMEOUT;
95 	ADM_Recv(&Message, &Timeout,
96 	    DP_GET_NETWORK_CFG_R, sizeof (dp_get_network_cfg_r_t));
97 
98 	netParams = (dp_get_network_cfg_r_t *)Message.data;
99 
100 	/* Print the network configuration */
101 	if (netParams->status != 0) {
102 		(void) printf("%s \r\n", gettext("SC ethernet is disabled."));
103 	} else {
104 #if 0
105 		/* Include this if we want to display the IP mode */
106 		(void) printf("%s %s\r\n",
107 		    gettext("SC network configuration is:"),
108 		    netParams->ipMode);
109 #endif
110 	if (strcmp(netParams->ipMode, "dhcp") == 0)
111 		(void) printf("%s %s\r\n", gettext("DHCP server:"),
112 		    netParams->ipDHCPServer);
113 		(void) printf("%s %s\r\n", gettext("IP Address:"),
114 		    netParams->ipAddr);
115 		(void) printf("%s %s\r\n", gettext("Gateway address:"),
116 		    netParams->ipGateway);
117 		(void) printf("%s %s\r\n", gettext("Netmask:"),
118 		    netParams->ipMask);
119 		(void) printf("%s %s\r\n", gettext("Ethernet address:"),
120 		    netParams->ethAddr);
121 	}
122 
123 	ADM_Free(&Message);
124 
125 }
126 
127 char
128 *ADM_Get_Var(char *Variable)
129 {
130 	rscp_msg_t	Message;
131 	struct timespec	Timeout;
132 	char		*varValue;
133 
134 	varValue = NULL;
135 
136 	Message.type = DP_GET_CFGVAR;
137 	Message.len = strlen(Variable) + 1; /* + 1 for string termination */
138 	if (Message.len > DP_MAX_MSGLEN-4) {
139 		command_line();
140 		exit(-1);
141 	}
142 
143 	Message.data = Variable;
144 	ADM_Send(&Message);
145 
146 	Timeout.tv_nsec = 0;
147 	Timeout.tv_sec = ADM_TIMEOUT;
148 	ADM_Recv(&Message, &Timeout,
149 	    DP_GET_CFGVAR_R, sizeof (dp_get_cfgvar_r_t));
150 
151 	if (*(int *)Message.data != 0) {
152 		(void) fprintf(stderr, "\n%s - \"%s\"\n\n",
153 		    gettext("scadm: invalid variable"), Variable);
154 		exit(-1);
155 	}
156 
157 	/* show variable setting */
158 	/* The variable setting is right after the Status of the message */
159 	varValue = (char *)(&((char *)Message.data)[
160 	    sizeof (dp_get_cfgvar_r_t)]);
161 
162 	ADM_Free(&Message);
163 
164 	return (varValue);
165 }
166 
167 static void
168 ADM_Show_Var(char *Variable)
169 {
170 	char *varValue;
171 
172 	varValue = ADM_Get_Var(Variable);
173 	(void) printf("%s=\"%s\"\n", Variable, varValue);
174 	(void) fflush(stdout);
175 }
176 
177 static int
178 ADM_Get_Next_Var(char *oldVar, char *newVar, int maxSize)
179 {
180 	rscp_msg_t	Message;
181 	struct timespec	Timeout;
182 	char		*var;
183 
184 
185 	Message.type = DP_GET_CFGVAR_NAME;
186 	if (oldVar == NULL)
187 		Message.len = 0;
188 	else
189 		Message.len  = strlen(oldVar) + 1;	/* + 1 for string */
190 							/* termination */
191 
192 	if (Message.len > DP_MAX_MSGLEN-4) {
193 		command_line();
194 		exit(-1);
195 	}
196 
197 	Message.data = oldVar;
198 	ADM_Send(&Message);
199 
200 	Timeout.tv_nsec = 0;
201 	Timeout.tv_sec  = ADM_TIMEOUT;
202 	ADM_Recv(&Message, &Timeout,
203 	    DP_GET_CFGVAR_NAME_R, sizeof (dp_get_cfgvar_name_r_t));
204 	if (*(int *)Message.data != 0) {
205 		/* Last variable read */
206 		return (-1);
207 	}
208 
209 	/* The variable is right after the Status of the message */
210 	var = (char *)(&((char *)Message.data)[
211 	    sizeof (dp_get_cfgvar_name_r_t)]);
212 	(void) strncpy(newVar, var, maxSize);
213 
214 	ADM_Free(&Message);
215 
216 	return (0);
217 }
218 
219 
220 static void
221 command_line()
222 {
223 	(void) fprintf(stderr, "\n%s\n\n",
224 	    gettext("scadm: command line too long"));
225 }
226