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