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
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
237c478bd9Sstevel@tonic-gate /* All Rights Reserved */
247c478bd9Sstevel@tonic-gate
25*ace1a5f1Sdp /*
26*ace1a5f1Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27*ace1a5f1Sdp * Use is subject to license terms.
28*ace1a5f1Sdp */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include "uucp.h"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #ifdef D_PROTOCOL
337c478bd9Sstevel@tonic-gate #include <dk.h>
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #define XBUFSIZ 1024
367c478bd9Sstevel@tonic-gate time_t time();
377c478bd9Sstevel@tonic-gate static jmp_buf Dfailbuf;
387c478bd9Sstevel@tonic-gate extern int drdblk();
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate * Datakit protocol
427c478bd9Sstevel@tonic-gate */
437c478bd9Sstevel@tonic-gate /* ARGSUSED */
447c478bd9Sstevel@tonic-gate static void
dalarm(sig)457c478bd9Sstevel@tonic-gate dalarm(sig)
467c478bd9Sstevel@tonic-gate int sig;
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate longjmp(Dfailbuf,1);
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate static void (*dsig)();
527c478bd9Sstevel@tonic-gate #ifndef V8
537c478bd9Sstevel@tonic-gate static short dkrmode[3] = { DKR_BLOCK, 0, 0 };
547c478bd9Sstevel@tonic-gate static short dkeof[3] = { 106, 0, 0 }; /* End of File signal */
557c478bd9Sstevel@tonic-gate #endif
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate * turn on protocol
597c478bd9Sstevel@tonic-gate */
607c478bd9Sstevel@tonic-gate int
dturnon()617c478bd9Sstevel@tonic-gate dturnon()
627c478bd9Sstevel@tonic-gate {
637c478bd9Sstevel@tonic-gate #ifdef V8
647c478bd9Sstevel@tonic-gate extern int dkp_ld;
657c478bd9Sstevel@tonic-gate #endif
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate dsig=signal(SIGALRM, dalarm);
687c478bd9Sstevel@tonic-gate #ifdef V8
697c478bd9Sstevel@tonic-gate if (dkproto(Ofn, dkp_ld) < 0)
707c478bd9Sstevel@tonic-gate {
717c478bd9Sstevel@tonic-gate DEBUG(3, "%s\n", "No dkp_ld");
727c478bd9Sstevel@tonic-gate return(-1);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate #else
757c478bd9Sstevel@tonic-gate if((*Ioctl)(Ofn, DIOCRMODE, dkrmode) < 0) {
767c478bd9Sstevel@tonic-gate int ret;
777c478bd9Sstevel@tonic-gate ret=(*Ioctl)(Ofn, DIOCRMODE, dkrmode);
787c478bd9Sstevel@tonic-gate DEBUG(4, "dturnon: ret=%d, ", ret);
797c478bd9Sstevel@tonic-gate DEBUG(4, "Ofn=%d, ", Ofn);
807c478bd9Sstevel@tonic-gate DEBUG(4, "errno=%d\n", errno);
817c478bd9Sstevel@tonic-gate return(-1);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate #endif /* V8 */
847c478bd9Sstevel@tonic-gate return(0);
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate int
dturnoff()887c478bd9Sstevel@tonic-gate dturnoff()
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, dsig);
917c478bd9Sstevel@tonic-gate return(0);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate * write message across Datakit link
967c478bd9Sstevel@tonic-gate * type -> message type
977c478bd9Sstevel@tonic-gate * str -> message body (ascii string)
987c478bd9Sstevel@tonic-gate * fn -> Datakit file descriptor
997c478bd9Sstevel@tonic-gate * return
1007c478bd9Sstevel@tonic-gate * SUCCESS -> message sent
1017c478bd9Sstevel@tonic-gate * FAIL -> write failed
1027c478bd9Sstevel@tonic-gate */
1037c478bd9Sstevel@tonic-gate int
dwrmsg(type,str,fn)1047c478bd9Sstevel@tonic-gate dwrmsg(type, str, fn)
1057c478bd9Sstevel@tonic-gate register char *str;
1067c478bd9Sstevel@tonic-gate int fn;
1077c478bd9Sstevel@tonic-gate char type;
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate register char *s;
1107c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ];
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate bufr[0] = type;
1137c478bd9Sstevel@tonic-gate s = &bufr[1];
1147c478bd9Sstevel@tonic-gate while (*str)
1157c478bd9Sstevel@tonic-gate *s++ = *str++;
1167c478bd9Sstevel@tonic-gate *s = '\0';
1177c478bd9Sstevel@tonic-gate if (*(--s) == '\n')
1187c478bd9Sstevel@tonic-gate *s = '\0';
1197c478bd9Sstevel@tonic-gate return((*Write)(fn, bufr, (unsigned) strlen(bufr) + 1) < 0 ? FAIL : SUCCESS);
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate * read message from Datakit link
1247c478bd9Sstevel@tonic-gate * str -> message buffer
1257c478bd9Sstevel@tonic-gate * fn -> Datakit file descriptor
1267c478bd9Sstevel@tonic-gate * return
1277c478bd9Sstevel@tonic-gate * FAIL -> send timed out
1287c478bd9Sstevel@tonic-gate * SUCCESS -> ok message in str
1297c478bd9Sstevel@tonic-gate */
1307c478bd9Sstevel@tonic-gate int
drdmsg(str,fn)1317c478bd9Sstevel@tonic-gate drdmsg(str, fn)
1327c478bd9Sstevel@tonic-gate register char *str;
1337c478bd9Sstevel@tonic-gate {
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate register int len;
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate if(setjmp(Dfailbuf))
1387c478bd9Sstevel@tonic-gate return(FAIL);
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate (void) alarm(60);
1417c478bd9Sstevel@tonic-gate for (;;) {
1427c478bd9Sstevel@tonic-gate if( (len = (*Read)(fn, str, XBUFSIZ)) <= 0) {
1437c478bd9Sstevel@tonic-gate (void) alarm(0);
1447c478bd9Sstevel@tonic-gate return(FAIL);
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate str += len;
1477c478bd9Sstevel@tonic-gate if (*(str - 1) == '\0')
1487c478bd9Sstevel@tonic-gate break;
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate (void) alarm(0);
1517c478bd9Sstevel@tonic-gate return(SUCCESS);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate * read data from file fp1 and write
1567c478bd9Sstevel@tonic-gate * on Datakit link
1577c478bd9Sstevel@tonic-gate * fp1 -> file descriptor
1587c478bd9Sstevel@tonic-gate * fn -> Datakit descriptor
1597c478bd9Sstevel@tonic-gate * returns:
1607c478bd9Sstevel@tonic-gate * FAIL ->failure in Datakit link
1617c478bd9Sstevel@tonic-gate * SUCCESS -> ok
1627c478bd9Sstevel@tonic-gate */
1637c478bd9Sstevel@tonic-gate int
dwrdata(fp1,fn)1647c478bd9Sstevel@tonic-gate dwrdata(fp1, fn)
1657c478bd9Sstevel@tonic-gate FILE *fp1;
1667c478bd9Sstevel@tonic-gate {
1677c478bd9Sstevel@tonic-gate register int fd1;
1687c478bd9Sstevel@tonic-gate register int len, ret;
1697c478bd9Sstevel@tonic-gate unsigned long bytes;
1707c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ];
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate bytes = 0L;
1737c478bd9Sstevel@tonic-gate fd1 = fileno( fp1 );
1747c478bd9Sstevel@tonic-gate while ((len = read( fd1, bufr, XBUFSIZ )) > 0) {
1757c478bd9Sstevel@tonic-gate bytes += len;
1767c478bd9Sstevel@tonic-gate putfilesize(bytes);
1777c478bd9Sstevel@tonic-gate ret = (*Write)(fn, bufr, (unsigned) len);
1787c478bd9Sstevel@tonic-gate if (ret != len) {
1797c478bd9Sstevel@tonic-gate return(FAIL);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate if (len != XBUFSIZ)
1827c478bd9Sstevel@tonic-gate break;
1837c478bd9Sstevel@tonic-gate }
184*ace1a5f1Sdp ASSERT(len >= 0, "DISK READ ERROR", strerror(errno), len);
1857c478bd9Sstevel@tonic-gate #ifndef V8
1867c478bd9Sstevel@tonic-gate (*Ioctl)(fn, DIOCXCTL, dkeof);
1877c478bd9Sstevel@tonic-gate #endif
1887c478bd9Sstevel@tonic-gate ret = (*Write)(fn, bufr, (unsigned) 0);
1897c478bd9Sstevel@tonic-gate return(SUCCESS);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate /*
1937c478bd9Sstevel@tonic-gate * read data from Datakit link and
1947c478bd9Sstevel@tonic-gate * write into file
1957c478bd9Sstevel@tonic-gate * fp2 -> file descriptor
1967c478bd9Sstevel@tonic-gate * fn -> Datakit descriptor
1977c478bd9Sstevel@tonic-gate * returns:
1987c478bd9Sstevel@tonic-gate * SUCCESS -> ok
1997c478bd9Sstevel@tonic-gate * FAIL -> failure on Datakit link
2007c478bd9Sstevel@tonic-gate */
2017c478bd9Sstevel@tonic-gate int
drddata(fn,fp2)2027c478bd9Sstevel@tonic-gate drddata(fn, fp2)
2037c478bd9Sstevel@tonic-gate FILE *fp2;
2047c478bd9Sstevel@tonic-gate {
2057c478bd9Sstevel@tonic-gate register int fd2;
2067c478bd9Sstevel@tonic-gate register int len;
2077c478bd9Sstevel@tonic-gate register int ret = SUCCESS;
2087c478bd9Sstevel@tonic-gate unsigned long bytes;
2097c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ];
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate bytes = 0L;
2127c478bd9Sstevel@tonic-gate fd2 = fileno( fp2 );
2137c478bd9Sstevel@tonic-gate for (;;) {
2147c478bd9Sstevel@tonic-gate len = drdblk(bufr, XBUFSIZ, fn);
2157c478bd9Sstevel@tonic-gate if (len < 0) {
2167c478bd9Sstevel@tonic-gate return(FAIL);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate bytes += len;
2197c478bd9Sstevel@tonic-gate putfilesize(bytes);
2207c478bd9Sstevel@tonic-gate if( ret == SUCCESS && write( fd2, bufr, len ) != len )
2217c478bd9Sstevel@tonic-gate ret = errno;
2227c478bd9Sstevel@tonic-gate if (len < XBUFSIZ)
2237c478bd9Sstevel@tonic-gate break;
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate return(ret);
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate /*
2297c478bd9Sstevel@tonic-gate * read block from Datakit link
2307c478bd9Sstevel@tonic-gate * reads are timed
2317c478bd9Sstevel@tonic-gate * blk -> address of buffer
2327c478bd9Sstevel@tonic-gate * len -> size to read
2337c478bd9Sstevel@tonic-gate * fn -> Datakit descriptor
2347c478bd9Sstevel@tonic-gate * returns:
2357c478bd9Sstevel@tonic-gate * FAIL -> link error timeout on link
2367c478bd9Sstevel@tonic-gate * i -> # of bytes read
2377c478bd9Sstevel@tonic-gate */
2387c478bd9Sstevel@tonic-gate int
drdblk(blk,len,fn)2397c478bd9Sstevel@tonic-gate drdblk(blk, len, fn)
2407c478bd9Sstevel@tonic-gate register char *blk;
2417c478bd9Sstevel@tonic-gate {
2427c478bd9Sstevel@tonic-gate register int i, ret;
2437c478bd9Sstevel@tonic-gate struct dkqqabo why;
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate if(setjmp(Dfailbuf))
2467c478bd9Sstevel@tonic-gate return(FAIL);
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate for (i = 0; i < len; i += ret) {
2497c478bd9Sstevel@tonic-gate (void) alarm(60);
2507c478bd9Sstevel@tonic-gate if ((ret = (*Read)(fn, blk, (unsigned) len - i)) < 0) {
2517c478bd9Sstevel@tonic-gate (void) alarm(0);
2527c478bd9Sstevel@tonic-gate return(FAIL);
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate blk += ret;
2557c478bd9Sstevel@tonic-gate if (ret == 0) { /* zero length block contains only EOF signal */
2567c478bd9Sstevel@tonic-gate ioctl(fn, DIOCQQABO, &why);
2577c478bd9Sstevel@tonic-gate if (why.rcv_ctlchar != dkeof[0])
2587c478bd9Sstevel@tonic-gate i = FAIL;
2597c478bd9Sstevel@tonic-gate break;
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate (void) alarm(0);
2637c478bd9Sstevel@tonic-gate return(i);
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate #endif /* D_PROTOCOL */
266