17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5dd33c4e4Stimh * Common Development and Distribution License (the "License"). 6dd33c4e4Stimh * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21dd33c4e4Stimh 227c478bd9Sstevel@tonic-gate /* 23*25c6ff4bSstephh * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <fm/fmd_fmri.h> 3024db4641Seschrock #include <fm/libtopo.h> 3124db4641Seschrock #include <fm/topo_mod.h> 327c478bd9Sstevel@tonic-gate #include <libdevinfo.h> 337c478bd9Sstevel@tonic-gate #include <alloca.h> 347c478bd9Sstevel@tonic-gate #include <string.h> 357c478bd9Sstevel@tonic-gate 3624db4641Seschrock int 3724db4641Seschrock fmd_fmri_init(void) 387c478bd9Sstevel@tonic-gate { 3924db4641Seschrock return (0); 407c478bd9Sstevel@tonic-gate } 417c478bd9Sstevel@tonic-gate 4224db4641Seschrock void 4324db4641Seschrock fmd_fmri_fini(void) 4424db4641Seschrock { 4524db4641Seschrock } 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate ssize_t 487c478bd9Sstevel@tonic-gate fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) 497c478bd9Sstevel@tonic-gate { 507c478bd9Sstevel@tonic-gate int err; 5124db4641Seschrock ssize_t len; 5224db4641Seschrock topo_hdl_t *thp; 5324db4641Seschrock char *str; 547c478bd9Sstevel@tonic-gate 5524db4641Seschrock if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL) 567c478bd9Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 577c478bd9Sstevel@tonic-gate 5824db4641Seschrock if (topo_fmri_nvl2str(thp, nvl, &str, &err) != 0) { 5924db4641Seschrock fmd_fmri_topo_rele(thp); 607c478bd9Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 617c478bd9Sstevel@tonic-gate } 627c478bd9Sstevel@tonic-gate 6324db4641Seschrock if (buf != NULL) 6424db4641Seschrock len = snprintf(buf, buflen, "%s", str); 6524db4641Seschrock else 6624db4641Seschrock len = strlen(str); 677c478bd9Sstevel@tonic-gate 6824db4641Seschrock topo_hdl_strfree(thp, str); 6924db4641Seschrock fmd_fmri_topo_rele(thp); 707c478bd9Sstevel@tonic-gate 7124db4641Seschrock return (len); 727c478bd9Sstevel@tonic-gate } 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate int 757c478bd9Sstevel@tonic-gate fmd_fmri_present(nvlist_t *nvl) 767c478bd9Sstevel@tonic-gate { 7724db4641Seschrock int err, present; 7824db4641Seschrock topo_hdl_t *thp; 797c478bd9Sstevel@tonic-gate 8024db4641Seschrock if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL) 817c478bd9Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 8224db4641Seschrock err = 0; 8324db4641Seschrock present = topo_fmri_present(thp, nvl, &err); 8424db4641Seschrock fmd_fmri_topo_rele(thp); 857c478bd9Sstevel@tonic-gate 8624db4641Seschrock return (present); 877c478bd9Sstevel@tonic-gate } 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate int 90*25c6ff4bSstephh fmd_fmri_replaced(nvlist_t *nvl) 91*25c6ff4bSstephh { 92*25c6ff4bSstephh int err, rval; 93*25c6ff4bSstephh topo_hdl_t *thp; 94*25c6ff4bSstephh 95*25c6ff4bSstephh if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL) 96*25c6ff4bSstephh return (fmd_fmri_set_errno(EINVAL)); 97*25c6ff4bSstephh err = 0; 98*25c6ff4bSstephh rval = topo_fmri_replaced(thp, nvl, &err); 99*25c6ff4bSstephh fmd_fmri_topo_rele(thp); 100*25c6ff4bSstephh 101*25c6ff4bSstephh return (rval); 102*25c6ff4bSstephh } 103*25c6ff4bSstephh 104*25c6ff4bSstephh int 1057c478bd9Sstevel@tonic-gate fmd_fmri_unusable(nvlist_t *nvl) 1067c478bd9Sstevel@tonic-gate { 1077c478bd9Sstevel@tonic-gate uint8_t version; 10824db4641Seschrock int err, unusable; 10924db4641Seschrock topo_hdl_t *thp; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || 1127c478bd9Sstevel@tonic-gate version > FM_DEV_SCHEME_VERSION) 1137c478bd9Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 1147c478bd9Sstevel@tonic-gate 11524db4641Seschrock if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL) 11624db4641Seschrock return (fmd_fmri_set_errno(EINVAL)); 11724db4641Seschrock err = 0; 11824db4641Seschrock unusable = topo_fmri_unusable(thp, nvl, &err); 11924db4641Seschrock fmd_fmri_topo_rele(thp); 12024db4641Seschrock 12124db4641Seschrock if (err != 0) 1227c478bd9Sstevel@tonic-gate return (0); 12324db4641Seschrock else 12424db4641Seschrock return (unusable); 1257c478bd9Sstevel@tonic-gate } 126*25c6ff4bSstephh 127*25c6ff4bSstephh int 128*25c6ff4bSstephh fmd_fmri_service_state(nvlist_t *nvl) 129*25c6ff4bSstephh { 130*25c6ff4bSstephh uint8_t version; 131*25c6ff4bSstephh int err, service_state; 132*25c6ff4bSstephh topo_hdl_t *thp; 133*25c6ff4bSstephh 134*25c6ff4bSstephh if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || 135*25c6ff4bSstephh version > FM_DEV_SCHEME_VERSION) 136*25c6ff4bSstephh return (fmd_fmri_set_errno(EINVAL)); 137*25c6ff4bSstephh 138*25c6ff4bSstephh if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL) 139*25c6ff4bSstephh return (fmd_fmri_set_errno(EINVAL)); 140*25c6ff4bSstephh err = 0; 141*25c6ff4bSstephh service_state = topo_fmri_service_state(thp, nvl, &err); 142*25c6ff4bSstephh fmd_fmri_topo_rele(thp); 143*25c6ff4bSstephh 144*25c6ff4bSstephh if (err != 0) 145*25c6ff4bSstephh return (FMD_SERVICE_STATE_UNKNOWN); 146*25c6ff4bSstephh else 147*25c6ff4bSstephh return (service_state); 148*25c6ff4bSstephh } 149