4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * modem_setup.c: support for the scadm modem_setup option (access to the
31 * service processor modem - if present)
40 #include <time.h> /* required by librsc.h */
47 extern char *ADM_Get_Var(char *Variable
);
49 static void ADM_Send_Char(char C
);
50 static void ADM_Modem_Listen();
51 static void cleanup();
54 typedef enum {ST_RESET
, ST_IDLE
, ST_TILDA
} ADM_state_t
;
56 static int ADM_Continue
;
58 static pthread_t modemListen
;
62 ADM_Process_modem_setup()
65 struct timespec timeout
;
76 msg
.type
= DP_MODEM_CONNECT
;
82 timeout
.tv_sec
= ADM_TIMEOUT
;
83 ADM_Recv(&msg
, &timeout
, DP_MODEM_CONNECT_R
,
84 sizeof (dp_modem_connect_r_t
));
85 if (*(int *)msg
.data
!= DP_MODEM_PASS
) {
86 (void) fprintf(stderr
, "\n%s\n\n",
87 gettext("scadm: could not connect to modem"));
92 /* Get the escape char BEFORE starting up the "listen" thread */
93 (void) strcpy(rsc_escape
, ADM_Get_Var("escape_char"));
96 /* Create Listening Thread */
98 if (pthread_create(&modemListen
, NULL
,
99 (void * (*)(void *))ADM_Modem_Listen
, (void *)NULL
) != 0) {
100 (void) fprintf(stderr
, "\n%s\n\n",
101 gettext("scadm: couldn't create thread"));
105 if (signal(SIGINT
, cleanup
) == SIG_ERR
) {
106 (void) fprintf(stderr
, "\n%s\n\n",
107 gettext("scadm: cleanup() registration failed"));
113 (void) sprintf(string
, gettext("... Type %s. to return to prompt ..."),
120 printw("\n%s\n\n", string
);
123 while ((Input
= getch()) == ERR
);
134 if ((char)Input
== rsc_escape
[0]) {
138 ADM_Send_Char((char)Input
);
143 ADM_Send_Char((char)Input
);
147 if ((char)Input
== '.') {
153 ADM_Send_Char((char)Input
);
159 ADM_Send_Char((char)Input
);
165 /* Terminate Thread */
167 (void) sleep(3); /* Make sure thread has time to 'see' */
170 msg
.type
= DP_MODEM_DISCONNECT
;
176 timeout
.tv_sec
= ADM_TIMEOUT
;
177 ADM_Recv(&msg
, &timeout
, DP_MODEM_DISCONNECT_R
,
178 sizeof (dp_modem_disconnect_r_t
));
179 if (*(int *)msg
.data
!= DP_MODEM_PASS
) {
180 (void) fprintf(stderr
, "\n%s\n\n",
181 gettext("scadm: could not disconnect from modem"));
187 pthread_join(modemListen
, NULL
);
193 ADM_Send_Char(char C
)
200 Message
.type
= DP_MODEM_DATA
;
204 if (rscp_send(&Message
) != 0) {
205 (void) fprintf(stderr
, "\n%s\n\n",
206 gettext("scadm: Unable to send modem data to SC"));
219 struct timespec Timeout
;
222 while (ADM_Continue
) {
223 Timeout
.tv_nsec
= 500000000;
225 if (rscp_recv(&Message
, &Timeout
) != 0) {
229 if (Message
.type
!= DP_MODEM_DATA
) {
230 (void) fprintf(stderr
, "\n%s: 0x%08x:0x%08lx\n\n",
231 gettext("scadm: SC returned garbage"),
232 Message
.type
, Message
.len
);
236 (void) printf("%s", (char *)Message
.data
);
237 (void) fflush(stdout
);
247 struct timespec timeout
;
253 /* Terminate Thread */
256 msg
.type
= DP_MODEM_DISCONNECT
;
262 timeout
.tv_sec
= ADM_TIMEOUT
;
263 ADM_Recv(&msg
, &timeout
, DP_MODEM_DISCONNECT_R
,
264 sizeof (dp_modem_disconnect_r_t
));
265 if (*(int *)msg
.data
!= DP_MODEM_PASS
) {
266 (void) fprintf(stderr
, "\n%s\n\n",
267 gettext("scadm: could not disconnect from modem"));
272 pthread_join(modemListen
, NULL
);