1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <ctype.h> 30*0Sstevel@tonic-gate #include <stdio.h> 31*0Sstevel@tonic-gate #include <stdlib.h> 32*0Sstevel@tonic-gate #include <string.h> 33*0Sstevel@tonic-gate #include <unistd.h> 34*0Sstevel@tonic-gate #include <macros.h> 35*0Sstevel@tonic-gate #include <libdevinfo.h> 36*0Sstevel@tonic-gate #define CFGA_PLUGIN_LIB 37*0Sstevel@tonic-gate #include <config_admin.h> 38*0Sstevel@tonic-gate #include "ap.h" 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate int cfga_version = CFGA_HSL_V2; 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate /*ARGSUSED*/ 43*0Sstevel@tonic-gate cfga_err_t 44*0Sstevel@tonic-gate cfga_change_state( 45*0Sstevel@tonic-gate cfga_cmd_t cfga_cmd, 46*0Sstevel@tonic-gate const char *ap_id, 47*0Sstevel@tonic-gate const char *options, 48*0Sstevel@tonic-gate struct cfga_confirm *confp, 49*0Sstevel@tonic-gate struct cfga_msg *msgp, 50*0Sstevel@tonic-gate char **errstring, 51*0Sstevel@tonic-gate cfga_flags_t flags) 52*0Sstevel@tonic-gate { 53*0Sstevel@tonic-gate int cmd; 54*0Sstevel@tonic-gate const char *name; 55*0Sstevel@tonic-gate apd_t *a; 56*0Sstevel@tonic-gate cfga_err_t rc; 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate if ((rc = ap_state_cmd(cfga_cmd, &cmd)) != CFGA_OK) 59*0Sstevel@tonic-gate return (rc); 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate rc = CFGA_LIB_ERROR; 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate if ((a = apd_alloc(ap_id, flags, errstring, msgp, confp)) == NULL) 64*0Sstevel@tonic-gate return (rc); 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate name = ap_cmd_name(cmd); 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate if ((rc = ap_cmd_parse(a, name, options, NULL)) == CFGA_OK) 69*0Sstevel@tonic-gate rc = ap_cmd_seq(a, cmd); 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate apd_free(a); 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate return (rc); 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate /* 77*0Sstevel@tonic-gate * Check if this is a valid -x command. 78*0Sstevel@tonic-gate */ 79*0Sstevel@tonic-gate static int 80*0Sstevel@tonic-gate private_func(const char *function) 81*0Sstevel@tonic-gate { 82*0Sstevel@tonic-gate char **f; 83*0Sstevel@tonic-gate static char * 84*0Sstevel@tonic-gate private_funcs[] = { 85*0Sstevel@tonic-gate "assign", 86*0Sstevel@tonic-gate "unassign", 87*0Sstevel@tonic-gate "poweron", 88*0Sstevel@tonic-gate "poweroff", 89*0Sstevel@tonic-gate "passthru", 90*0Sstevel@tonic-gate "errtest", 91*0Sstevel@tonic-gate NULL 92*0Sstevel@tonic-gate }; 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate for (f = private_funcs; *f != NULL; f++) 95*0Sstevel@tonic-gate if (strcmp(*f, function) == 0) 96*0Sstevel@tonic-gate break; 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate return (*f == NULL ? CFGA_INVAL : CFGA_OK); 99*0Sstevel@tonic-gate } 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate /*ARGSUSED*/ 102*0Sstevel@tonic-gate cfga_err_t 103*0Sstevel@tonic-gate cfga_private_func( 104*0Sstevel@tonic-gate const char *function, 105*0Sstevel@tonic-gate const char *ap_id, 106*0Sstevel@tonic-gate const char *options, 107*0Sstevel@tonic-gate struct cfga_confirm *confp, 108*0Sstevel@tonic-gate struct cfga_msg *msgp, 109*0Sstevel@tonic-gate char **errstring, 110*0Sstevel@tonic-gate cfga_flags_t flags) 111*0Sstevel@tonic-gate { 112*0Sstevel@tonic-gate int cmd; 113*0Sstevel@tonic-gate apd_t *a; 114*0Sstevel@tonic-gate cfga_err_t rc; 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate DBG("cfga_private_func(%s)\n", ap_id); 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate rc = CFGA_LIB_ERROR; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate if ((a = apd_alloc(ap_id, flags, errstring, msgp, confp)) == NULL) 121*0Sstevel@tonic-gate return (rc); 122*0Sstevel@tonic-gate else if ((rc = private_func(function)) != CFGA_OK) { 123*0Sstevel@tonic-gate ap_err(a, ERR_CMD_INVAL, function); 124*0Sstevel@tonic-gate goto done; 125*0Sstevel@tonic-gate } else if ((rc = ap_cmd_parse(a, function, options, &cmd)) != CFGA_OK) 126*0Sstevel@tonic-gate goto done; 127*0Sstevel@tonic-gate else if (cmd == CMD_ERRTEST) 128*0Sstevel@tonic-gate rc = ap_test_err(a, options); 129*0Sstevel@tonic-gate else 130*0Sstevel@tonic-gate rc = ap_cmd_exec(a, cmd); 131*0Sstevel@tonic-gate done: 132*0Sstevel@tonic-gate apd_free(a); 133*0Sstevel@tonic-gate return (rc); 134*0Sstevel@tonic-gate } 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate /*ARGSUSED*/ 138*0Sstevel@tonic-gate cfga_err_t 139*0Sstevel@tonic-gate cfga_test( 140*0Sstevel@tonic-gate const char *ap_id, 141*0Sstevel@tonic-gate const char *options, 142*0Sstevel@tonic-gate struct cfga_msg *msgp, 143*0Sstevel@tonic-gate char **errstring, 144*0Sstevel@tonic-gate cfga_flags_t flags) 145*0Sstevel@tonic-gate { 146*0Sstevel@tonic-gate int cmd; 147*0Sstevel@tonic-gate const char *f; 148*0Sstevel@tonic-gate apd_t *a; 149*0Sstevel@tonic-gate cfga_err_t rc; 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate DBG("cfga_test(%s)\n", ap_id); 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate f = "test"; 154*0Sstevel@tonic-gate rc = CFGA_LIB_ERROR; 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate /* 157*0Sstevel@tonic-gate * A test that is not sequenced by a change 158*0Sstevel@tonic-gate * state operation should be forced. 159*0Sstevel@tonic-gate */ 160*0Sstevel@tonic-gate flags |= CFGA_FLAG_FORCE; 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate if ((a = apd_alloc(ap_id, flags, errstring, msgp, NULL)) == NULL) 163*0Sstevel@tonic-gate return (rc); 164*0Sstevel@tonic-gate else if ((rc = ap_cmd_parse(a, f, options, &cmd)) != CFGA_OK) 165*0Sstevel@tonic-gate goto done; 166*0Sstevel@tonic-gate else 167*0Sstevel@tonic-gate rc = ap_cmd_exec(a, cmd); 168*0Sstevel@tonic-gate done: 169*0Sstevel@tonic-gate apd_free(a); 170*0Sstevel@tonic-gate return (rc); 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate /*ARGSUSED*/ 174*0Sstevel@tonic-gate cfga_err_t 175*0Sstevel@tonic-gate cfga_list_ext( 176*0Sstevel@tonic-gate const char *ap_id, 177*0Sstevel@tonic-gate cfga_list_data_t **ap_id_list, 178*0Sstevel@tonic-gate int *nlist, 179*0Sstevel@tonic-gate const char *options, 180*0Sstevel@tonic-gate const char *listopts, 181*0Sstevel@tonic-gate char **errstring, 182*0Sstevel@tonic-gate cfga_flags_t flags) 183*0Sstevel@tonic-gate { 184*0Sstevel@tonic-gate int i; 185*0Sstevel@tonic-gate int apcnt; 186*0Sstevel@tonic-gate const char *f; 187*0Sstevel@tonic-gate apd_t *a; 188*0Sstevel@tonic-gate size_t szl, szp; 189*0Sstevel@tonic-gate cfga_list_data_t *aplist, *ap; 190*0Sstevel@tonic-gate cfga_err_t rc; 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate rc = CFGA_LIB_ERROR; 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate aplist = NULL; 195*0Sstevel@tonic-gate f = ap_cmd_name(CMD_STATUS); 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate DBG("cfga_list_ext(%s %x)\n", ap_id, flags); 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate if ((a = apd_alloc(ap_id, flags, errstring, NULL, NULL)) == NULL) 200*0Sstevel@tonic-gate return (rc); 201*0Sstevel@tonic-gate else if ((rc = ap_cmd_parse(a, f, options, NULL)) != CFGA_OK) 202*0Sstevel@tonic-gate goto done; 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate apcnt = ap_cnt(a); 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gate DBG("apcnt=%d\n", apcnt); 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate if ((aplist = calloc(apcnt, sizeof (*aplist))) == NULL) { 209*0Sstevel@tonic-gate rc = CFGA_LIB_ERROR; 210*0Sstevel@tonic-gate ap_err(a, ERR_CMD_FAIL, CMD_STATUS); 211*0Sstevel@tonic-gate goto done; 212*0Sstevel@tonic-gate } 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate ap = aplist; 215*0Sstevel@tonic-gate szl = sizeof (ap->ap_log_id); 216*0Sstevel@tonic-gate szp = sizeof (ap->ap_phys_id); 217*0Sstevel@tonic-gate 218*0Sstevel@tonic-gate /* 219*0Sstevel@tonic-gate * Initialize the AP specified directly by the caller. 220*0Sstevel@tonic-gate * The target ID for the 0th element already includes 221*0Sstevel@tonic-gate * the (potential) dynamic portion. The dynamic portion 222*0Sstevel@tonic-gate * does need to be appended to the path to form the 223*0Sstevel@tonic-gate * physical apid for components. 224*0Sstevel@tonic-gate */ 225*0Sstevel@tonic-gate (void) strncpy(ap->ap_log_id, a->target, szl - 1); 226*0Sstevel@tonic-gate (void) snprintf(ap->ap_phys_id, szp, "%s%s%s", a->path, 227*0Sstevel@tonic-gate a->tgt != AP_BOARD ? "::" : "", 228*0Sstevel@tonic-gate a->tgt != AP_BOARD ? a->cid : ""); 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate DBG("ap_phys_id=%s ap_log_id=%s\n", ap->ap_phys_id, ap->ap_log_id); 232*0Sstevel@tonic-gate 233*0Sstevel@tonic-gate if (a->tgt == AP_BOARD) { 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate ap_init(a, ap++); 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate /* 238*0Sstevel@tonic-gate * Initialize the components, if any. 239*0Sstevel@tonic-gate */ 240*0Sstevel@tonic-gate for (i = 0; i < apcnt - 1; i++, ap++) { 241*0Sstevel@tonic-gate char dyn[MAXPATHLEN]; 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate ap_cm_id(a, i, dyn, sizeof (dyn)); 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate (void) snprintf(ap->ap_log_id, szl, "%s::%s", 246*0Sstevel@tonic-gate a->target, dyn); 247*0Sstevel@tonic-gate (void) snprintf(ap->ap_phys_id, szp, "%s::%s", 248*0Sstevel@tonic-gate a->path, dyn); 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate ap_cm_init(a, ap, i); 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate DBG("ap_phys_id=%s ap_log_id=%s\n", 253*0Sstevel@tonic-gate ap->ap_phys_id, ap->ap_log_id); 254*0Sstevel@tonic-gate } 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gate } else 257*0Sstevel@tonic-gate ap_cm_init(a, ap, 0); 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate apd_free(a); 260*0Sstevel@tonic-gate *ap_id_list = aplist; 261*0Sstevel@tonic-gate *nlist = apcnt; 262*0Sstevel@tonic-gate return (CFGA_OK); 263*0Sstevel@tonic-gate 264*0Sstevel@tonic-gate done: 265*0Sstevel@tonic-gate s_free(aplist); 266*0Sstevel@tonic-gate apd_free(a); 267*0Sstevel@tonic-gate return (rc); 268*0Sstevel@tonic-gate } 269*0Sstevel@tonic-gate 270*0Sstevel@tonic-gate /*ARGSUSED*/ 271*0Sstevel@tonic-gate cfga_err_t 272*0Sstevel@tonic-gate cfga_help(struct cfga_msg *msgp, const char *options, cfga_flags_t flags) 273*0Sstevel@tonic-gate { 274*0Sstevel@tonic-gate return (ap_help(msgp, options, flags)); 275*0Sstevel@tonic-gate } 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate /* 279*0Sstevel@tonic-gate * cfga_ap_id_cmp -- use default_ap_id_cmp() in libcfgadm 280*0Sstevel@tonic-gate */ 281