xref: /titanic_41/usr/src/cmd/scadm/sparc/mpxu/common/wrappers.c (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * wrappers.c: utility for scadm command processing functions
31  */
32 
33 #include <libintl.h>
34 #include <stdio.h>
35 #include <errno.h>
36 #include <time.h>  /* required by rsc.h */
37 
38 #include "librsc.h"
39 #include "adm.h"
40 
41 
42 void
ADM_Start()43 ADM_Start()
44 {
45 	if (rscp_start() != 0) {
46 
47 		(void) fprintf(stderr, "\n%s\n\n",
48 		    gettext("scadm: SC firmware not responding"));
49 		exit(-1);
50 	}
51 }
52 
53 
54 void
ADM_Send(rscp_msg_t * msg)55 ADM_Send(rscp_msg_t *msg)
56 {
57 	int err;
58 
59 	err = rscp_send(msg);
60 
61 	if (err == ENOTSUP) {
62 
63 		(void) fprintf(stderr, "\n%s\n\n",
64 		    gettext("scadm: command/option not supported"));
65 		exit(-1);
66 
67 	} else if (err != 0) {
68 
69 		(void) fprintf(stderr, "\n%s\n\n",
70 		    gettext("scadm: unable to send data to SC"));
71 		exit(-1);
72 	}
73 }
74 
75 
76 int
ADM_Send_ret(rscp_msg_t * msg)77 ADM_Send_ret(rscp_msg_t *msg)
78 {
79 	return (rscp_send(msg));
80 }
81 
82 
83 void
ADM_Recv(rscp_msg_t * msg,struct timespec * timeout,int expectType,int expectSize)84 ADM_Recv(rscp_msg_t *msg, struct timespec *timeout, int expectType,
85     int expectSize)
86 {
87 	if (rscp_recv(msg, timeout) != 0) {
88 		(void) fprintf(stderr, "\n%s\n\n",
89 		    gettext("scadm: SC not responding to requests"));
90 		exit(-1);
91 	}
92 
93 	if ((msg->type != expectType) || (msg->len < expectSize)) {
94 		(void) fprintf(stderr, "\n%s: 0x%08x:0x%08lx\n\n",
95 		    gettext("scadm: SC returned garbage"),
96 		    msg->type, msg->len);
97 		exit(-1);
98 	}
99 
100 }
101 
102 
103 void
ADM_Free(rscp_msg_t * msg)104 ADM_Free(rscp_msg_t *msg)
105 {
106 	if (rscp_free_msg(msg) != 0) {
107 		(void) fprintf(stderr, "\n%s\n\n",
108 		    gettext("scadm: SC unable to free up memory"));
109 		exit(-1);
110 	}
111 }
112