10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 30Sstevel@tonic-gate * Use is subject to license terms. 40Sstevel@tonic-gate */ 5*549Smuffin 60Sstevel@tonic-gate /* 70Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 80Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 90Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 100Sstevel@tonic-gate */ 11*549Smuffin 12*549Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 130Sstevel@tonic-gate 140Sstevel@tonic-gate #include "tip.h" 150Sstevel@tonic-gate 16*549Smuffin static int hayes_sync(int); 17*549Smuffin static void sigALRM(void); 18*549Smuffin static sigjmp_buf timeoutbuf; 19*549Smuffin 20*549Smuffin void hayes_disconnect(void); 210Sstevel@tonic-gate 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Dial up on a Hayes Smart Modem 1200 or 2400 240Sstevel@tonic-gate */ 25*549Smuffin /* ARGSUSED */ 260Sstevel@tonic-gate int 27*549Smuffin hayes_dialer(char *num, char *acu) 280Sstevel@tonic-gate { 290Sstevel@tonic-gate char code = 0, cr = 0; 30*549Smuffin sig_handler_t f; 310Sstevel@tonic-gate struct termios buf; 320Sstevel@tonic-gate 33*549Smuffin f = signal(SIGALRM, (sig_handler_t)sigALRM); 340Sstevel@tonic-gate 350Sstevel@tonic-gate if (!hayes_sync(FD)) { 36*549Smuffin (void) printf("can't synchronize with hayes\n"); 370Sstevel@tonic-gate #ifdef ACULOG 380Sstevel@tonic-gate logent(value(HOST), num, "hayes", "can't synch up"); 390Sstevel@tonic-gate #endif 40*549Smuffin (void) signal(SIGALRM, f); 410Sstevel@tonic-gate return (0); 420Sstevel@tonic-gate } 430Sstevel@tonic-gate if (boolean(value(VERBOSE))) 44*549Smuffin (void) printf("\ndialing..."); 45*549Smuffin (void) fflush(stdout); 46*549Smuffin (void) ioctl(FD, TCGETS, &buf); 470Sstevel@tonic-gate buf.c_cflag |= HUPCL; 48*549Smuffin (void) ioctl(FD, TCSETS, &buf); 49*549Smuffin (void) ioctl(FD, TCFLSH, TCIOFLUSH); 500Sstevel@tonic-gate 510Sstevel@tonic-gate if (sigsetjmp(timeoutbuf, 1)) { 520Sstevel@tonic-gate #ifdef ACULOG 530Sstevel@tonic-gate char line[80]; 540Sstevel@tonic-gate 55*549Smuffin (void) sprintf(line, "%d second dial timeout", 56*549Smuffin number(value(DIALTIMEOUT))); 570Sstevel@tonic-gate logent(value(HOST), num, "hayes", line); 580Sstevel@tonic-gate #endif 590Sstevel@tonic-gate hayes_disconnect(); 60*549Smuffin (void) signal(SIGALRM, f); 610Sstevel@tonic-gate return (0); 620Sstevel@tonic-gate } 63*549Smuffin (void) alarm(number(value(DIALTIMEOUT))); 64*549Smuffin (void) ioctl(FD, TCFLSH, TCIOFLUSH); 650Sstevel@tonic-gate if (*num == 'S') 66*549Smuffin (void) write(FD, "AT", 2); 670Sstevel@tonic-gate else 68*549Smuffin (void) write(FD, "ATDT", 4); /* use tone dialing */ 69*549Smuffin (void) write(FD, num, strlen(num)); 70*549Smuffin (void) write(FD, "\r", 1); 71*549Smuffin (void) read(FD, &code, 1); 72*549Smuffin (void) read(FD, &cr, 1); 730Sstevel@tonic-gate if (code == '1' && cr == '0') 74*549Smuffin (void) read(FD, &cr, 1); 75*549Smuffin (void) alarm(0); 76*549Smuffin (void) signal(SIGALRM, f); 770Sstevel@tonic-gate if ((code == '1' || code == '5') && cr == '\r') 780Sstevel@tonic-gate return (1); 790Sstevel@tonic-gate return (0); 800Sstevel@tonic-gate } 810Sstevel@tonic-gate 82*549Smuffin void 83*549Smuffin hayes_disconnect(void) 840Sstevel@tonic-gate { 85*549Smuffin (void) close(FD); 860Sstevel@tonic-gate } 870Sstevel@tonic-gate 88*549Smuffin void 89*549Smuffin hayes_abort(void) 900Sstevel@tonic-gate { 910Sstevel@tonic-gate int dtr = TIOCM_DTR; 920Sstevel@tonic-gate 93*549Smuffin (void) alarm(0); 94*549Smuffin (void) ioctl(FD, TIOCMBIC, &dtr); 95*549Smuffin (void) sleep(2); 96*549Smuffin (void) ioctl(FD, TCFLSH, TCIOFLUSH); 97*549Smuffin (void) close(FD); 980Sstevel@tonic-gate } 990Sstevel@tonic-gate 1000Sstevel@tonic-gate static void 101*549Smuffin sigALRM(void) 1020Sstevel@tonic-gate { 1030Sstevel@tonic-gate siglongjmp(timeoutbuf, 1); 1040Sstevel@tonic-gate } 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * This piece of code attempts to get the hayes in sync. 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate static int 110*549Smuffin hayes_sync(int fd) 1110Sstevel@tonic-gate { 112*549Smuffin int tries; 1130Sstevel@tonic-gate char code = 0, cr = 0; 1140Sstevel@tonic-gate int dtr = TIOCM_DTR; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * Toggle DTR to force anyone off that might have left 1180Sstevel@tonic-gate * the modem connected, and insure a consistent state 1190Sstevel@tonic-gate * to start from. 1200Sstevel@tonic-gate */ 121*549Smuffin (void) ioctl(fd, TIOCMBIC, &dtr); 122*549Smuffin (void) sleep(1); 123*549Smuffin (void) ioctl(fd, TIOCMBIS, &dtr); 1240Sstevel@tonic-gate for (tries = 0; tries < 3; tries++) { 1250Sstevel@tonic-gate /* 1260Sstevel@tonic-gate * After reseting the modem, initialize all 1270Sstevel@tonic-gate * parameters to required vaules: 1280Sstevel@tonic-gate * 1290Sstevel@tonic-gate * V0 - result codes are single digits 1300Sstevel@tonic-gate * Q0 - result codes ARE sent 1310Sstevel@tonic-gate * E0 - do not echo 1320Sstevel@tonic-gate * S0=1 - automatically answer phone 1330Sstevel@tonic-gate * S2=255 - disable escape character 1340Sstevel@tonic-gate * S12=255 - longest possible escape guard time 1350Sstevel@tonic-gate */ 136*549Smuffin (void) write(fd, "ATV0Q0E0S0=1S2=255S12=255\r", 26); 137*549Smuffin (void) sleep(1); 1380Sstevel@tonic-gate /* flush any echoes or return codes */ 139*549Smuffin (void) ioctl(fd, TCFLSH, TCIOFLUSH); 1400Sstevel@tonic-gate /* now see if the modem is talking to us properly */ 141*549Smuffin (void) write(fd, "AT\r", 3); 1420Sstevel@tonic-gate if (sigsetjmp(timeoutbuf, 1) == 0) { 143*549Smuffin (void) alarm(2); 144*549Smuffin (void) read(FD, &code, 1); 145*549Smuffin (void) read(FD, &cr, 1); 1460Sstevel@tonic-gate if (code == '0' && cr == '\r') 1470Sstevel@tonic-gate return (1); 1480Sstevel@tonic-gate } 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate return (0); 1510Sstevel@tonic-gate } 152