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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * wrappers.c: utility for scadm command processing functions
29 */
30
31 #include <libintl.h>
32 #include <stdio.h>
33 #include <errno.h>
34 #include <time.h> /* required by rsc.h */
35
36 #include "librsc.h"
37 #include "adm.h"
38
39
40 void
ADM_Start()41 ADM_Start()
42 {
43 if (rscp_start() != 0) {
44
45 (void) fprintf(stderr, "\n%s\n\n",
46 gettext("scadm: SC firmware not responding"));
47 exit(-1);
48 }
49 }
50
51
52 void
ADM_Send(rscp_msg_t * msg)53 ADM_Send(rscp_msg_t *msg)
54 {
55 int err;
56
57 err = rscp_send(msg);
58
59 if (err == ENOTSUP) {
60
61 (void) fprintf(stderr, "\n%s\n\n",
62 gettext("scadm: command/option not supported"));
63 exit(-1);
64
65 } else if (err != 0) {
66
67 (void) fprintf(stderr, "\n%s\n\n",
68 gettext("scadm: unable to send data to SC"));
69 exit(-1);
70 }
71 }
72
73
74 int
ADM_Send_ret(rscp_msg_t * msg)75 ADM_Send_ret(rscp_msg_t *msg)
76 {
77 return (rscp_send(msg));
78 }
79
80
81 void
ADM_Recv(rscp_msg_t * msg,struct timespec * timeout,int expectType,int expectSize)82 ADM_Recv(rscp_msg_t *msg, struct timespec *timeout, int expectType,
83 int expectSize)
84 {
85 if (rscp_recv(msg, timeout) != 0) {
86 (void) fprintf(stderr, "\n%s\n\n",
87 gettext("scadm: SC not responding to requests"));
88 exit(-1);
89 }
90
91 if ((msg->type != expectType) || (msg->len < expectSize)) {
92 (void) fprintf(stderr, "\n%s: 0x%08x:0x%08lx\n\n",
93 gettext("scadm: SC returned garbage"),
94 msg->type, msg->len);
95 exit(-1);
96 }
97
98 }
99
100
101 void
ADM_Free(rscp_msg_t * msg)102 ADM_Free(rscp_msg_t *msg)
103 {
104 if (rscp_free_msg(msg) != 0) {
105 (void) fprintf(stderr, "\n%s\n\n",
106 gettext("scadm: SC unable to free up memory"));
107 exit(-1);
108 }
109 }
110