home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume42 / ecu / part23 < prev    next >
Encoding:
Internet Message Format  |  1994-05-24  |  64.5 KB

  1. From: wht@n4hgf.atl.ga.us (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v42i121:  ecu - ECU Asynchronous Communications v3.30, Part23/37
  4. Date: 24 May 1994 09:07:16 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <2rt1mk$d3p@sparky.sterling.com>
  9. X-Md4-Signature: 92b8b557062140cf16f0c57cf52d4c77
  10.  
  11. Submitted-by: wht@n4hgf.atl.ga.us (Warren Tucker)
  12. Posting-number: Volume 42, Issue 121
  13. Archive-name: ecu/part23
  14. Environment: SCO,SCOXENIX,MOTOROLA,HP-UX,LINUX,NetBSD,SUNOS,SYSVR4,SOLARIS2
  15. Supersedes: ecu: Volume 32, Issue 36-75
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  ecu330/gendial/dceT3000.c ecu330/gendial/dceTBPlus.c
  22. #   ecu330/gendial/dialer.h ecu330/z/zmodem.c
  23. # Wrapped by kent@sparky on Mon May 23 13:40:58 1994
  24. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 23 (of 37)."'
  27. if test -f 'ecu330/gendial/dceT3000.c' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'ecu330/gendial/dceT3000.c'\"
  29. else
  30.   echo shar: Extracting \"'ecu330/gendial/dceT3000.c'\" \(17766 characters\)
  31.   sed "s/^X//" >'ecu330/gendial/dceT3000.c' <<'END_OF_FILE'
  32. X/*+-------------------------------------------------------------------------
  33. X    dceT3000.c - DCE-specific portion of generic SCO UUCP dialer
  34. X    Driver for Telebit T3000
  35. X    wht@n4hgf.atl.ga.us
  36. X
  37. Xdialing registers for V.32
  38. X
  39. XT3000SA - Version LA3.00 - Active Configuration
  40. X B1  E0  L2  M0  P   Q2  V1  X12  Y0
  41. X&C1 &D2 &G0 &J0 &L0 &Q0 &R3 &S0 &T4 &X0
  42. XS000=0   S001=0   S002:1   S003=13  S004=10  S005=8   S006=2   S007=40
  43. XS008=2   S009=6   S010=14  S011:50  S012=50  S018=0   S025=5   S026=1
  44. XS038=0   S041=0   S045=0   S046=0   S047=4   S048:1   S050:6   S051:252
  45. XS056=17  S057=19  S058:2   S059=0   S060=0   S061=1   S062:25  S063=0
  46. XS064=0   S068=255 S069=0   S090=0   S093=8   S094=1   S100=0   S102=0
  47. XS104=0   S105=1   S111=255 S112=1   S180=2   S181=1   S183=25  S190=1
  48. XS253=10  S254=255 S255=255
  49. X--------------------------------------------------------------------------*/
  50. X/*+:EDITS:*/
  51. X/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  52. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  53. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  54. X/*:05-11-1992-17:51-wht@gyro-convert dceT2500 for a preliminary version */
  55. X
  56. X#include "dialer.h"
  57. X
  58. X/*
  59. X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
  60. X *                    sees the transition; this value may be changed
  61. X *                    as necessary before each call to lflash_DTR(),
  62. X * but, generally, a constant value will do.
  63. X */
  64. Xlong DCE_DTR_low_msec = 500;
  65. X
  66. X/*
  67. X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
  68. X *                     DCE may be expected to be ready to be commanded
  69. X */
  70. Xlong DCE_DTR_high_msec = 1000L;
  71. X
  72. X/*
  73. X * DCE_write_pace_msec - milliseconds to pause between each character
  74. X *                       sent to the DCE (zero if streaming I/O is
  75. X *                       permitted); this value may be changed as
  76. X * necessary before each call to lwrite(), but, generally, a constant
  77. X * value will do.  Note that this value is used to feed a value to Nap(),
  78. X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
  79. X * and .050 seconds on XENIX/86.
  80. X */
  81. Xlong DCE_write_pace_msec = 10;
  82. X
  83. X/*
  84. X * DCE_name     - short name for DCE
  85. X * DCE_revision - revision number for this module
  86. X */
  87. Xchar *DCE_name = "Telebit T3000";
  88. Xchar *DCE_revision = "x1.10";
  89. X
  90. X/*
  91. X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
  92. X *                    and readying it for dial in access
  93. X *                    (BXXX mask); use a value of zero if the speed
  94. X *                    specified by the invoker is to be used.
  95. X * This value is useful for DCEs such as the early Hayes 2400
  96. X * which are so unfortunately compatible with their 1200 predecessor
  97. X * that they refuse to answer at 2400 baud unless you last spoke to
  98. X * them at that rate. For such bad boys, use B2400 below.
  99. X */
  100. Xint DCE_hangup_CBAUD = 0;
  101. X
  102. X/* int DCE_hangup_CBAUD = B2400; */
  103. X
  104. X/*
  105. X * DCE_results - a table of DCE response strings and a token
  106. X *               code for each; when you call lread() or lread_ignore(),
  107. X *               if the read routine detects one of the strings,
  108. X * the appropriate code is returned.  If no string matches, then
  109. X * lread()/lread_ignore examines the DCE result string for a
  110. X * numeric value; if one is found, the numeric value or'd with
  111. X * 0x40000000 is returned (in this way, e.g., you can read "modem
  112. X * S registers").  If nothing agrees with this search, lread()
  113. X * will abort the program with RC_FAIL|RCE_TIMOUT, lread_ignore()
  114. X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
  115. X * This module is the only consumer  of the codes, although they
  116. X * are decoded by gendial.c's _lread()
  117. X */
  118. X
  119. X/* flag bits */
  120. X#define rfConnect        0x00800000
  121. X#define rfMASK            0x0000FFFF    /* mask off rfBits */
  122. X
  123. X/* unique codes */
  124. X#define rOk                0
  125. X#define rNoCarrier        1
  126. X#define rError            2
  127. X#define rNoDialTone     3
  128. X#define rBusy            4
  129. X#define rNoAnswer        5
  130. X#define rRring            6
  131. X#define rDialing        7
  132. X#define rConnect300        (   300 | rfConnect)
  133. X#define rConnect1200    (  1200 | rfConnect)
  134. X#define rConnect2400    (  1200 | rfConnect)
  135. X#define rConnect9600    (  9600 | rfConnect)
  136. X#define rConnect19200    ( 19200 | rfConnect)
  137. X#define rConnect38400    ( 38400 | rfConnect)
  138. X
  139. XDCE_RESULT DCE_results[] =
  140. X{
  141. X    {"OK", rOk,},
  142. X    {"NO CARRIER", rNoCarrier,},
  143. X    {"ERROR", rError},
  144. X    {"NO DIALTONE", rNoDialTone,},
  145. X    {"BUSY", rBusy},
  146. X    {"NO ANSWER", rNoAnswer},
  147. X    {"DIALING", rDialing},
  148. X    {"RRING", rRring},
  149. X    {"CONNECT 300", rConnect300},
  150. X    {"CONNECT 1200", rConnect1200},
  151. X    {"CONNECT 2400", rConnect2400},
  152. X    {"CONNECT 9600", rConnect9600},
  153. X    {"CONNECT 19200", rConnect19200},
  154. X    {"CONNECT 38400", rConnect38400},
  155. X    {(char *)0, -1}             /* end table */
  156. X};
  157. X
  158. X#include "tbit.sync.h"
  159. X
  160. X/*+-------------------------------------------------------------------------
  161. X    DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
  162. X
  163. X  DCE dependent function must validate baud rates supported by DCE
  164. X  returns baud rate in struct termio c_cflag fashion
  165. X  or terminates program with error
  166. X--------------------------------------------------------------------------*/
  167. Xint
  168. XDCE_baud_to_CBAUD(baud)
  169. Xunsigned int baud;
  170. X{
  171. X    switch (baud)
  172. X    {
  173. X        case 110:
  174. X            return (B110);
  175. X        case 300:
  176. X            return (B300);
  177. X        case 1200:
  178. X            return (B1200);
  179. X        case 2400:
  180. X            return (B2400);
  181. X        case 9600:
  182. X            return (B9600);
  183. X
  184. X#if defined(B19200)
  185. X        case 19200:
  186. X            return (B19200);
  187. X#else
  188. X#ifdef EXTA
  189. X        case 19200:
  190. X            return (EXTA);
  191. X#endif
  192. X#endif
  193. X
  194. X#if defined(B38400)
  195. X        case 38400:
  196. X            return (B38400);
  197. X#else
  198. X#ifdef EXTB
  199. X        case 38400:
  200. X            return (EXTB);
  201. X#endif
  202. X#endif
  203. X
  204. X    }
  205. X    myexit(RC_FAIL | RCE_SPEED);
  206. X#if defined(OPTIMIZE) || defined(__OPTIMIZE__)    /* don't complain */
  207. X    return (0);                 /* keep gcc from complaining about no rtn at
  208. X                              * end */
  209. X#endif
  210. X}                             /* end of DCE_baud_to_CBAUD */
  211. X
  212. X/*+-------------------------------------------------------------------------
  213. X    init_T3000() - init T3000 from scratch, assuming nothing
  214. X
  215. X    reset to factory defaults, then set
  216. X    E0          no local echo in command mode
  217. X    &C1         DCD follows carrier
  218. X    &D2         disconnect on DTR loss
  219. X    M0          speaker off
  220. X    Q2          generate reult codes only for originating use
  221. X    V1          verbal result codes
  222. X    X12         fullest result code set
  223. X    S0=1        answer on first ring
  224. X    S2=255        escape to unusual value
  225. X    S11=50      50 msec DTMF timing
  226. X    S45=0       disable remote access
  227. X    S48=1       all 8 bits are significant
  228. X    S50=0       use automatic connect speed determination
  229. X    S51=252     set serial port baud rate automatically (no typeahead)
  230. X    S58=2       DTE uses CTS/RTS flow control.
  231. X    S61=0       send BREAK (rather than go to command mode)
  232. X    S62=25      BREAK duration 250 msec (default is 150)
  233. X    S63=0       send BREAK in sequence
  234. X    S64=1       ignore characters sent by DTE while answering
  235. X    S66=0       don't lock interface speed, just go with the flow.
  236. X    S69=0       omit XON/XOFF flow control
  237. X    S68=255     DCE uses whatever flow control DTE uses
  238. X    S111=255    accept any protocol
  239. X
  240. XThe nvram is set to factory + E0 Q0 &C1 &D2 S51=252
  241. X--------------------------------------------------------------------------*/
  242. Xvoid
  243. Xinit_T3000()
  244. X{
  245. X    register itmp;
  246. X    int maxretry = 4;
  247. X    char *init0 = "AT&F E0 Q0 &C1 &D2 S51=252 &w M0 Q2 V1 X12\r";
  248. X    char *init1 = "ATS0=1 S2=255 S11=50 S45=0 S48=1 S50=0 \r";
  249. X    char *init2 = "ATS58=2 S61=0 S62=25 S63=0 S62=25 S64=1 S66=0 S68=255 S111=255\r";
  250. X
  251. X    DEBUG(1, "--> initializing %s on ", DCE_name);
  252. X    DEBUG(1, "%s\n", dce_name);
  253. X
  254. X    lflash_DTR();
  255. X    sync_Telebit();
  256. X
  257. X    /*
  258. X     * set to factory default (bless them for this command) and a few
  259. X     * initial beachhead values
  260. X     */
  261. X    for (itmp = 0; itmp < maxretry; itmp++)
  262. X    {
  263. X        lwrite(init0);
  264. X        if (lread(5) == rOk)
  265. X            break;
  266. X    }
  267. X    if (itmp == maxretry)
  268. X    {
  269. X        DEBUG(1, "INIT FAILED (init0)\n", 0);
  270. X        myexit(RC_FAIL | RCE_TIMOUT);
  271. X    }
  272. X
  273. X    /*
  274. X     * send initialization string 1
  275. X     */
  276. X    for (itmp = 0; itmp < maxretry; itmp++)
  277. X    {
  278. X        lwrite(init1);
  279. X        if (lread(5) == rOk)
  280. X            break;
  281. X    }
  282. X    if (itmp == maxretry)
  283. X    {
  284. X        DEBUG(1, "INIT FAILED (init1)\n", 0);
  285. X        myexit(RC_FAIL | RCE_TIMOUT);
  286. X    }
  287. X
  288. X    /*
  289. X     * send initialization string 2
  290. X     */
  291. X    for (itmp = 0; itmp < maxretry; itmp++)
  292. X    {
  293. X        lwrite(init2);
  294. X        if (lread(5) == rOk)
  295. X            break;
  296. X    }
  297. X    if (itmp == maxretry)
  298. X    {
  299. X        DEBUG(1, "INIT FAILED (init2)\n", 0);
  300. X        myexit(RC_FAIL | RCE_TIMOUT);
  301. X    }
  302. X
  303. X}                             /* end of init_T3000 */
  304. X
  305. X/*+-------------------------------------------------------------------------
  306. X    DCE_hangup() - issue hangup command to DCE
  307. X
  308. XThis function should do whatever is necessary to ensure
  309. X1) any active connection is terminated
  310. X2) the DCE is ready to receive an incoming call if DTR is asserted
  311. X3) the DCE will not accept an incoming call if DTR is false
  312. X
  313. XThe function should return when done.
  314. X
  315. XAny necessary switch setting or other configuration necessary for this
  316. Xfunction to succeed should be documented at the top of the module.
  317. X--------------------------------------------------------------------------*/
  318. Xvoid
  319. XDCE_hangup()
  320. X{
  321. X    DEBUG(4, "--> hanging up %s\n", dce_name);
  322. X    init_T3000();
  323. X
  324. X}                             /* end of DCE_hangup */
  325. X
  326. X/*+-------------------------------------------------------------------------
  327. X    DCE_dial(telno_str) - dial a remote DCE
  328. X
  329. XThis function should connect to the remote DCE and use any success
  330. Xindication to modify the tty baud rate if necessary before returning.
  331. X
  332. XUpon successful connection, return 0.
  333. X
  334. XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
  335. XRCE_XXX value from dialer.h.
  336. X
  337. Xlwrite() is used to write to the DCE.
  338. X
  339. Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
  340. Xfrom calling lread() will result automatically in the proper error
  341. Xtermination of the program.  Read timeouts from calling lread_ignore()
  342. Xreturn -1; you handle the execption here.
  343. X
  344. XAny necessary coding of phone numbers, switch settings or other
  345. Xconfiguration necessary for this function to succeed should be
  346. Xdocumented at the top of the module.
  347. X
  348. XT3000-specific comments:
  349. X S0=0        dont allow connect while dialing
  350. X S63=0       pass BREAK signal to remote modem in sequence
  351. X S64=0       abort dialing if characters sent by DTE
  352. X S66=1       lock the interface speed
  353. X--------------------------------------------------------------------------*/
  354. Xint
  355. XDCE_dial(telno_str)
  356. Xchar *telno_str;
  357. X{
  358. X    char cmd[128];
  359. X    char phone[50];
  360. X    int s111_set = 0;
  361. X    int timeout;
  362. X    int result;
  363. X    int rrings = 0;
  364. X    long then;
  365. X    long now;
  366. X    char *cptr;
  367. X    char *dialout_default = "AT S0=0 S7=40 S63=0 S64=0 S66=1\r";
  368. X
  369. X#define MDVALID     "0123456789FfKkMmNnRrSsUuWwXxVv*#,!/()-"
  370. X#ifdef WHT
  371. X#define RRING_MAX 3
  372. X#else
  373. X#define RRING_MAX 6
  374. X#endif
  375. X
  376. X/* preliminary setup */
  377. X    translate("=,-,", telno_str);
  378. X    if (strspn(telno_str, MDVALID) != strlen(telno_str))
  379. X    {
  380. X        DEBUG(1, "phone number has invalid characters\n", 0);
  381. X        return (RC_FAIL | RCE_PHNO);
  382. X    }
  383. X    if (decode_phone_number(telno_str, phone, sizeof(phone)))
  384. X    {
  385. X        DEBUG(1, "phone number too long\n", 0);
  386. X        return (RC_FAIL | RCE_PHNO);
  387. X    }
  388. X
  389. X/* walk through dialer codes, doing custom setup */
  390. X    strcpy(cmd, "AT");
  391. X    cptr = cmd + strlen(cmd);
  392. X    if (dialer_codes['F' - 'A'])
  393. X    {
  394. X        DEBUG(5, "XON/XOFF FLOW CONTROL requested\n", 0);
  395. X        strcat(cmd, "S69=2");
  396. X    }
  397. X    if (dialer_codes['K' - 'A'])
  398. X    {
  399. X        DEBUG(5, "KERMIT requested\n", 0);
  400. X        strcat(cmd, "S111=10");
  401. X        s111_set++;
  402. X    }
  403. X    if (dialer_codes['X' - 'A'])
  404. X    {
  405. X        DEBUG(5, "XMODEM requested\n", 0);
  406. X        strcat(cmd, "S111=20");
  407. X        s111_set++;
  408. X    }
  409. X    if (dialer_codes['U' - 'A'])
  410. X    {
  411. X        DEBUG(5, "UUCP requested\n", 0);
  412. X        strcat(cmd, "S111=30");
  413. X        s111_set++;
  414. X    }
  415. X
  416. X    if (dialer_codes['V' - 'A'])
  417. X    {
  418. X        DEBUG(5, "V.32 requested\n", 0);
  419. X        if (hiCBAUD != B9600)
  420. X        {
  421. X            DEBUG(1, "V.32 baud rate not 9600\n", 0);
  422. X            return (RC_FAIL | RCE_SPEED);
  423. X        }
  424. X        if ((dialer_codes['P' - 'A']) || s111_set)
  425. X        {
  426. X            DEBUG(1, "both PEP and V.32 requested\n", 0);
  427. X            return (RC_FAIL | RCE_ARGS);
  428. X        }
  429. X        strcat(cmd, "S50=6");
  430. X    }
  431. X
  432. X    if ((dialer_codes['P' - 'A']) || s111_set ||
  433. X        ((hiCBAUD >= B9600) && (!dialer_codes['V' - 'A'])))
  434. X    {
  435. X        if (hiCBAUD < B9600)
  436. X        {
  437. X            DEBUG(1, "baud rate not high enough for PEP\n", 0);
  438. X            return (RC_FAIL | RCE_SPEED);
  439. X        }
  440. X        if (dialer_codes['P' - 'A'])
  441. X            DEBUG(5, "PEP requested\n", 0);
  442. X        else
  443. X            DEBUG(5, "PEP inferred: speed >= 9600 and no V.32 requested\n", 0);
  444. X
  445. X        dialer_codes['P' - 'A'] = 1;
  446. X        strcat(cmd, "S50=255");
  447. X    }
  448. X
  449. X    init_T3000();
  450. X
  451. X    DEBUG(2, "--> issuing default setup command\n", 0);
  452. X    lwrite(dialout_default);
  453. X    if (lread(5) != rOk)
  454. X    {
  455. X        DEBUG(1, "default dialout setup failed\n", 0);
  456. X        return (RC_FAIL | RCE_NULL);
  457. X    }
  458. X
  459. X/* issue the custom setup command */
  460. X    if (*cptr)
  461. X    {
  462. X        DEBUG(2, "--> issuing custom setup cmd\n", 0);
  463. X        strcat(cmd, "\r");
  464. X        lwrite(cmd);
  465. X        if (lread(5) != rOk)
  466. X        {
  467. X            DEBUG(1, "custom modem setup failed\n", 0);
  468. X            return (RC_FAIL | RCE_NULL);
  469. X        }
  470. X    }
  471. X
  472. X/*
  473. X * calculate a timeout for the connect
  474. X * allow a minimum of 40 seconds, but if V.32 or PEP, 90
  475. X * also if long distance (North American calculation here)
  476. X * make it 132 (S7 is calculated as timeout * .9)
  477. X */
  478. X    timeout = 40;
  479. X    if ((phone[0] == '1') && (phone[0] != '0'))
  480. X        timeout = 132;
  481. X    if ((timeout < 90) && (dialer_codes['V' - 'A'] || dialer_codes['P' - 'A']))
  482. X        timeout = 90;
  483. X    for (cptr = phone; cptr = strchr(cptr, ','); cptr++)
  484. X        timeout += 2;         /* add extra time for pause characters */
  485. X    DEBUG(4, "wait for connect = %d seconds\n", timeout);
  486. X
  487. X    if (Debug > 8)
  488. X    {
  489. X        lwrite("AT&V\r");
  490. X        lread_ignore(40);
  491. X    }
  492. X
  493. X/* indicate non-root should not see DTE->DCE traffic */
  494. X    secure = 1;
  495. X
  496. X/*
  497. X * build and issue the actual dialing command
  498. X * if root, let him see number, otherwise just say "remote system"
  499. X */
  500. X    DEBUG(1, "--> dialing %s\n", (!ecu_calling & uid)
  501. X        ? "remote system" : telno_str);
  502. X#ifdef WHT
  503. X    if (!strncmp(*gargv, "ECU", 3))
  504. X        dialer_codes['S' - 'A'] = 1;
  505. X#endif
  506. X    sprintf(cmd, "ATM%dS7=%dDT%s\r",
  507. X        ((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
  508. X        (timeout * 9) / 10, phone);
  509. X
  510. X    /* cmd string can only be 80 characters including "AT" */
  511. X    if (strlen(cmd) > 80)
  512. X    {
  513. X        DEBUG(1, "phone number string too long\n", 0);
  514. X        cleanup(RC_FAIL | RCE_PHNO);
  515. X    }
  516. X
  517. X    lwrite(cmd);
  518. X
  519. X/* indicate non-root can see DTE->DCE traffic */
  520. X    secure = 0;
  521. X
  522. X/* wait for connect */
  523. X  WAIT_FOR_CONNECT:
  524. X    time(&then);
  525. X    result = lread(timeout);
  526. X    if (!(result & rfConnect))
  527. X    {
  528. X        switch (result & rfMASK)
  529. X        {
  530. X            case rNoCarrier:
  531. X                return (RC_FAIL | ((rrings > 2) ? RCE_ANSWER : RCE_NOTONE));
  532. X            case rNoDialTone:
  533. X                return (RC_FAIL | RCE_NOTONE);
  534. X            case rBusy:
  535. X                return (RC_FAIL | RCE_BUSY);
  536. X            case rNoAnswer:
  537. X                return (RC_FAIL | RCE_ANSWER);
  538. X            case rRring:
  539. X                if (rrings++ >= RRING_MAX)
  540. X                    return (RC_FAIL | RCE_ANSWER);
  541. X            case rDialing:
  542. X                time(&now);
  543. X                if ((timeout -= ((int)(then - now))) > 0)
  544. X                    goto WAIT_FOR_CONNECT;
  545. X            case rError:
  546. X            default:
  547. X                return (RC_FAIL | RCE_NULL);
  548. X        }
  549. X    }
  550. X
  551. X    return (0);                 /* succeeded */
  552. X
  553. X}                             /* end of DCE_dial */
  554. X
  555. X/**********************************************************
  556. X*  You probably do not need to modify the code below here *
  557. X**********************************************************/
  558. X
  559. X/*+-------------------------------------------------------------------------
  560. X    DCE_abort(sig) - dial attempt aborted
  561. X
  562. X sig =  0 if non-signal abort (read timeout, most likely)
  563. X     != 0 if non-SIGALRM signal caught
  564. X
  565. X extern int dialing set  1 if dialing request was active,
  566. X                    else 0 if hangup request was active
  567. X
  568. XThis is a chance for the DCE-specific code to do anything it
  569. Xneeds to clean up after a failure.  Note that if a dialing
  570. Xcall fails, it is the responsibility of the higher-level
  571. Xprogram calling the dialer to call it again with a hangup request, so
  572. Xthis function is usually a no-op.
  573. X--------------------------------------------------------------------------*/
  574. Xvoid
  575. XDCE_abort(sig)
  576. Xint sig;
  577. X{
  578. X    DEBUG(10, "DCE_abort(%d);\n", sig);
  579. X}                             /* end of DCE_abort */
  580. X
  581. X/*+-------------------------------------------------------------------------
  582. X    DCE_exit(exitcode) - "last chance for gas" in this incarnation
  583. X
  584. XThe independent portion of the dialer program calls this routine in
  585. Xlieu of exit() in every case except one (see DCE_argv_hook() below).
  586. XNormally, this function just passes it's argument to exit(), but
  587. Xany necessary post-processing can be done.  The function must,
  588. Xhowever, eventually call exit(exitcode);
  589. X--------------------------------------------------------------------------*/
  590. Xvoid
  591. XDCE_exit(exitcode)
  592. Xint exitcode;
  593. X{
  594. X    DEBUG(10, "DCE_exit(%d);\n", exitcode);
  595. X    exit(exitcode);
  596. X}                             /* end of DCE_exit */
  597. X
  598. X/*+-------------------------------------------------------------------------
  599. X    DCE_argv_hook(argc,argv,optind,unrecognized_switches)
  600. X
  601. XThis hook gives DCE-specific code a chance to look over the entire
  602. Xcommand line, such as for -z Telebit processing.
  603. X
  604. Xargc andf argv are the same values passed to main(),
  605. X
  606. Xoptind is the value of optind at the end of normal getopt processing.
  607. X
  608. Xunrecognized_switches is the count of switches not handled by main().
  609. XSpecifically, -h and -x are standard switches.
  610. X
  611. XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
  612. Xany unrecognized switches, otherwise zero.  If you keep your nose clean
  613. Xthough, you can do anything you need to do here and exit the program.
  614. X
  615. XNote: only simple switches (with no argument) may be used with this
  616. Xfacility if the functrion is to return,' since main()'s getopt() will
  617. Xstop processing switches if it runs into an unrecognized switch with an
  618. Xargument.
  619. X
  620. XIf the function returns a non-zero value, then the value will be passed
  621. XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
  622. Xof the format expected by dialer program callers, with RC_FAIL set as a
  623. Xminimum.
  624. X--------------------------------------------------------------------------*/
  625. Xint
  626. XDCE_argv_hook(argc, argv, optind, unrecognized_switches)
  627. Xint argc;
  628. Xchar **argv;
  629. Xint optind;
  630. Xint unrecognized_switches;
  631. X{
  632. X    if (unrecognized_switches)
  633. X        return (RC_FAIL | RCE_ARGS);
  634. X    return (0);
  635. X}                             /* end of DCE_argv_hook */
  636. X
  637. X/* vi: set tabstop=4 shiftwidth=4: */
  638. END_OF_FILE
  639.   if test 17766 -ne `wc -c <'ecu330/gendial/dceT3000.c'`; then
  640.     echo shar: \"'ecu330/gendial/dceT3000.c'\" unpacked with wrong size!
  641.   fi
  642.   # end of 'ecu330/gendial/dceT3000.c'
  643. fi
  644. if test -f 'ecu330/gendial/dceTBPlus.c' -a "${1}" != "-c" ; then 
  645.   echo shar: Will not clobber existing file \"'ecu330/gendial/dceTBPlus.c'\"
  646. else
  647.   echo shar: Extracting \"'ecu330/gendial/dceTBPlus.c'\" \(18169 characters\)
  648.   sed "s/^X//" >'ecu330/gendial/dceTBPlus.c' <<'END_OF_FILE'
  649. X/* CHK=0xFF53 */
  650. X /* #define TRUSTING *//* trust user has -z'd before use */
  651. X/*+-------------------------------------------------------------------------
  652. X    dceTBPlus.c - DCE-specific portion of generic SCO UUCP dialer
  653. X    Driver for Telebit Trailblazer Plus
  654. X    wht@n4hgf.atl.ga.us
  655. X--------------------------------------------------------------------------*/
  656. X/*+:EDITS:*/
  657. X/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  658. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  659. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  660. X/*:02-10-1992-00:27-wht@n4hgf-improved sync_Telebit */
  661. X/*:02-02-1992-18:01-root@n4hgf-proper ordering of DCE_result entries */
  662. X/*:01-26-1992-15:30-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
  663. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  664. X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
  665. X/*:11-29-1990-18:31-r@n4hgf-revision/1st releasable */
  666. X/*:07-20-1990-00:10-wht@n4hgf-creation */
  667. X
  668. X#include "dialer.h"
  669. X
  670. X/*
  671. X * DCE_DTR_low_msec - milliseconds to hold DTR low to ensure DCE
  672. X *                    sees the transition; this value may be changed
  673. X *                    as necessary before each call to lflash_DTR(),
  674. X * but, generally, a constant value will do.
  675. X */
  676. Xlong DCE_DTR_low_msec = 500;
  677. X
  678. X/*
  679. X * DCE_DTR_high_msec - milliseconds DTR must remain high before the
  680. X *                     DCE may be expected to be ready to be commanded
  681. X */
  682. Xlong DCE_DTR_high_msec = 500;
  683. X
  684. X/*
  685. X * DCE_write_pace_msec - milliseconds to pause between each character
  686. X *                       sent to the DCE (zero if streaming I/O is
  687. X *                       permitted); this value may be changed as
  688. X * necessary before each call to lwrite(), but, generally, a constant
  689. X * value will do.  Note that this value is used to feed a value to Nap(),
  690. X * which has a granularity of .010 seconds on UNIX/386, .020 on XENIX/286
  691. X * and .050 seconds on XENIX/86.
  692. X */
  693. Xlong DCE_write_pace_msec = 10;
  694. X
  695. X/*
  696. X * DCE_name     - short name for DCE
  697. X * DCE_revision - revision number for this module
  698. X */
  699. Xchar *DCE_name = "Telebit Trailblazer Plus";
  700. Xchar *DCE_revision = "1.30";
  701. X
  702. X/*
  703. X * DCE_hangup_CBAUD - baud rate to use for hanging up DCE
  704. X *                    and readying it for dial in access
  705. X *                    (BXXX mask); use a value of zero if the speed
  706. X *                    specified by the invoker is to be used.
  707. X * This value is useful for DCEs such as the early Hayes 2400
  708. X * which are so unfortunately compatible with their 1200 predecessor
  709. X * that they refuse to answer at 2400 baud unless you last spoke to
  710. X * them at that rate. For such bad boys, use B2400 below.
  711. X */
  712. Xint DCE_hangup_CBAUD = 0;
  713. X
  714. X/* int DCE_hangup_CBAUD = B2400; */
  715. X
  716. X/*
  717. X * DCE_results - a table of DCE response strings and a token
  718. X *               code for each; when you call lread() or lread_ignore(),
  719. X *               if the read routine detects one of the strings,
  720. X * the appropriate code is returned.  If no string matches, then
  721. X * lread()/lread_ignore examines the DCE result string for a
  722. X * numeric value; if one is found, the numeric value or'd with
  723. X * 0x40000000 is returned (in this way, e.g., you can read "modem
  724. X * S registers").  If nothing agrees with this search, lread()
  725. X * will abort the program with RC|FAIL|RCE_TIMOUT, lread_ignore()
  726. X * will return -1.  You may use any value between 0 and 0x3FFFFFFF.
  727. X * This module is the only consumer  of the codes, although they
  728. X * are decoded by gendial.c's _lread().
  729. X *
  730. X * If one possible result is an "early substring" of another, like
  731. X * "CONNECT" is of "CONNECT 1200", then put such results later in the
  732. X * table than the larger result.
  733. X *
  734. X */
  735. X
  736. X/* flag bits */
  737. X#define rfConnect        0x00800000
  738. X#define rfREL            0x00400000
  739. X#define rfFAST            0x00200000
  740. X#define rfMASK            0x0000FFFF    /* mask off rfBits */
  741. X
  742. X/* unique codes */
  743. X#define rOk                0
  744. X#define rNoCarrier        1
  745. X#define rError            2
  746. X#define rNoDialTone     3
  747. X#define rBusy            4
  748. X#define rNoAnswer        5
  749. X#define rRring            6
  750. X#define rConnect300        (  300  | rfConnect)
  751. X#define rConnect1200    ( 1200  | rfConnect)
  752. X#define rConnect2400    ( 2400  | rfConnect)
  753. X#define rConnect300R    (  300  | rfConnect | rfREL)
  754. X#define rConnect1200R    ( 1200  | rfConnect | rfREL)
  755. X#define rConnect2400R    ( 2400  | rfConnect | rfREL)
  756. X#define rConnectFASTK    (19200  | rfConnect | rfFAST)
  757. X#define rConnectFASTX    (19200  | rfConnect | rfFAST)
  758. X#define rConnectFASTU    (19200  | rfConnect | rfFAST)
  759. X#define rConnectFAST    (19200  | rfConnect | rfFAST)
  760. X
  761. XDCE_RESULT DCE_results[] =
  762. X{
  763. X    {"OK", rOk,},
  764. X    {"NO CARRIER", rNoCarrier,},
  765. X    {"ERROR", rError},
  766. X    {"NO DIALTONE", rNoDialTone,},
  767. X    {"BUSY", rBusy},
  768. X    {"NO ANSWER", rNoAnswer},
  769. X    {"RRING", rRring},
  770. X    {"CONNECT 300/REL", rConnect300R},
  771. X    {"CONNECT 1200/REL", rConnect1200R},
  772. X    {"CONNECT 2400/REL", rConnect2400R},
  773. X    {"CONNECT 300", rConnect300},
  774. X    {"CONNECT 1200", rConnect1200},
  775. X    {"CONNECT 2400", rConnect2400},
  776. X    {"CONNECT FAST/KERM", rConnectFASTK},
  777. X    {"CONNECT FAST/XMDM", rConnectFASTX},
  778. X    {"CONNECT FAST/UUCP", rConnectFASTU},
  779. X    {"CONNECT FAST", rConnectFAST},
  780. X    {(char *)0, -1}             /* end table */
  781. X};
  782. X
  783. X#include "tbit.sync.h"
  784. X
  785. X/*+-------------------------------------------------------------------------
  786. X    DCE_baud_to_CBAUD(baud) - check for valid baud rates supported by DCE
  787. X
  788. X  DCE dependent function must validate baud rates supported by DCE
  789. X  returns baud rate in struct termio c_cflag fashion
  790. X  or terminates program with error
  791. X--------------------------------------------------------------------------*/
  792. Xint
  793. XDCE_baud_to_CBAUD(baud)
  794. Xunsigned int baud;
  795. X{
  796. X    switch (baud)
  797. X    {
  798. X        case 110:
  799. X            return (B110);
  800. X        case 300:
  801. X            return (B300);
  802. X        case 1200:
  803. X            return (B1200);
  804. X        case 2400:
  805. X            return (B2400);
  806. X        case 9600:
  807. X            return (B9600);
  808. X
  809. X#if defined(B19200)
  810. X        case 19200:
  811. X            return (B19200);
  812. X#else
  813. X#ifdef EXTA
  814. X        case 19200:
  815. X            return (EXTA);
  816. X#endif
  817. X#endif
  818. X
  819. X#if defined(B38400)
  820. X        case 38400:
  821. X            return (B38400);
  822. X#else
  823. X#ifdef EXTB
  824. X        case 38400:
  825. X            return (EXTB);
  826. X#endif
  827. X#endif
  828. X
  829. X    }
  830. X    myexit(RC_FAIL | RCE_SPEED);
  831. X#if defined(OPTIMIZE) || defined(__OPTIMIZE__)    /* don't complain */
  832. X    return (0);                 /* keep gcc from complaining about no rtn at
  833. X                              * end */
  834. X#endif
  835. X}                             /* end of DCE_baud_to_CBAUD */
  836. X
  837. X/*+-------------------------------------------------------------------------
  838. X    init_TBPlus() - init TBPlus from scratch, assuming nothing
  839. X
  840. X    reset to factory defaults, then set
  841. X    E0          no local echo in command mode
  842. X    F1          no local echo in data transfer mode
  843. X    M0          speaker off
  844. X    Q4          generate reult codes, but not RING
  845. X    V1          verbal result codes
  846. X    X3          extended result codes
  847. X    S0=1        answer on first ring
  848. X    S2=255        escape to "unusual" value
  849. X    S11=50      50 msec DTMF timing
  850. X    S45=1       enable remote access
  851. X    S48=1       all 8 bits are significant
  852. X    S50=0       use automatic connect speed determination
  853. X    S51=252     set serial port baud rate automatically (no typeahead)
  854. X    S52=2       DTR low: drop connection and reset to nvram
  855. X    S53=1       DCD signal follows remote carrier, DSR on when modem ready
  856. X    S54=3       pass BREAK signal to remote modem
  857. X    S55=0       respond to command escape sequence
  858. X    S58=2       DTE uses CTS/RTS flow control.
  859. X    S64=1       ignore characters sent by DTE while answering
  860. X    S66=0       don't lock interface speed, just go with the flow.
  861. X    S68=255     DCE uses whatever flow control DTE uses
  862. X    S92=1       PEP tones at the end of answer sequence
  863. X    S95=0       no MNP
  864. X    S110=255    use data compression when the remote modem requests it.
  865. X    S111=255    accept any protocol
  866. X--------------------------------------------------------------------------*/
  867. Xvoid
  868. Xinit_TBPlus()
  869. X{
  870. X    register itmp;
  871. X    int maxretry = 4;
  872. X    char *init0 = "AT~&FE0F1M0Q4V1X3S52=2\r";
  873. X    char *init1 = "ATS0=1S2=255S11=50S45=1S48=1S50=0S51=252S53=1S54=3\r";
  874. X    char *init2 = "ATS55=0S58=2S64=1S66=0S68=255S92=1S95=0S110=255S111=255\r";
  875. X
  876. X    DEBUG(1, "--> initializing %s\n", dce_name);
  877. X    lflash_DTR();
  878. X    sync_Telebit();
  879. X
  880. X    /*
  881. X     * set to factory default (bless them for this command) and a few
  882. X     * initial beachhead values
  883. X     */
  884. X    for (itmp = 0; itmp < maxretry; itmp++)
  885. X    {
  886. X        lwrite(init0);
  887. X        if (lread(5) == rOk)
  888. X            break;
  889. X    }
  890. X    if (itmp == maxretry)
  891. X    {
  892. X        DEBUG(1, "INIT FAILED (init0)\n", 0);
  893. X        myexit(RC_FAIL | RCE_TIMOUT);
  894. X    }
  895. X
  896. X    /*
  897. X     * send initialization string 1
  898. X     */
  899. X    for (itmp = 0; itmp < maxretry; itmp++)
  900. X    {
  901. X        lwrite(init1);
  902. X        if (lread(5) == rOk)
  903. X            break;
  904. X    }
  905. X    if (itmp == maxretry)
  906. X    {
  907. X        DEBUG(1, "INIT FAILED (init1)\n", 0);
  908. X        myexit(RC_FAIL | RCE_TIMOUT);
  909. X    }
  910. X
  911. X    /*
  912. X     * send initialization string 2
  913. X     */
  914. X    for (itmp = 0; itmp < maxretry; itmp++)
  915. X    {
  916. X        lwrite(init2);
  917. X        if (lread(5) == rOk)
  918. X            break;
  919. X    }
  920. X    if (itmp == maxretry)
  921. X    {
  922. X        DEBUG(1, "INIT FAILED (init2)\n", 0);
  923. X        myexit(RC_FAIL | RCE_TIMOUT);
  924. X    }
  925. X
  926. X}                             /* end of init_TBPlus */
  927. X
  928. X/*+-------------------------------------------------------------------------
  929. X    DCE_hangup() - issue hangup command to DCE
  930. X
  931. XThis function should do whatever is necessary to ensure
  932. X1) any active connection is terminated
  933. X2) the DCE is ready to receive an incoming call if DTR is asserted
  934. X3) the DCE will not accept an incoming call if DTR is false
  935. X
  936. XThe function should return when done.
  937. X
  938. XAny necessary switch setting or other configuration necessary for this
  939. Xfunction to succeed should be documented at the top of the module.
  940. X--------------------------------------------------------------------------*/
  941. Xvoid
  942. XDCE_hangup()
  943. X{
  944. X    DEBUG(1, "--> reseting %s\n", dce_name);
  945. X#ifdef TRUSTING
  946. X    lflash_DTR();
  947. X    lwrite("ATZ\r");
  948. X    (void)lread_ignore(1);
  949. X#else /* !TRUSTING */
  950. X    init_TBPlus();
  951. X#endif
  952. X
  953. X}                             /* end of DCE_hangup */
  954. X
  955. X/*+-------------------------------------------------------------------------
  956. X    DCE_dial(telno_str) - dial a remote DCE
  957. X
  958. XThis function should connect to the remote DCE and use any success
  959. Xindication to modify the tty baud rate if necessary before returning.
  960. X
  961. XUpon successful connection, return 0.
  962. X
  963. XUpon unsuccessful connection, return RC_FAIL or'd with an appropriate
  964. XRCE_XXX value from dialer.h.
  965. X
  966. Xlwrite() is used to write to the DCE.
  967. X
  968. Xlread() and lread_ignore() are used to read from the DCE.  Read timeouts
  969. Xfrom calling lread() will result automatically in the proper error
  970. Xtermination of the program.  Read timeouts from calling lread_ignore()
  971. Xreturn -1; you handle the execption here.
  972. X
  973. XAny necessary coding of phone numbers, switch settings or other
  974. Xconfiguration necessary for this function to succeed should be
  975. Xdocumented at the top of the module.
  976. X
  977. XTelebit Plus-specific comments:
  978. X S0=0        dont allow connect while dialing
  979. X S54=3       pass BREAK signal to remote modem
  980. X S64=0       abort dialing if characters sent by DTE
  981. X S66=1       lock the interface speed
  982. X S110=0      disable data compression unless requested otherwise
  983. X--------------------------------------------------------------------------*/
  984. Xint
  985. XDCE_dial(telno_str)
  986. Xchar *telno_str;
  987. X{
  988. X    char cmd[128];
  989. X    char phone[50];
  990. X    int s111_set = 0;
  991. X    int timeout;
  992. X    int result;
  993. X    int rrings = 0;
  994. X    long then;
  995. X    long now;
  996. X    char *cptr;
  997. X    char *dialout_default = "ATS0=0S7=40S54=3S64=0S66=1S110=0\r";
  998. X
  999. X#define MDVALID     "0123456789CcEeFfKkMmNnPpRrSsUuWwXx*#,!/()-"
  1000. X
  1001. X/* preliminary setup */
  1002. X    translate("=,-,", telno_str);
  1003. X    if (strspn(telno_str, MDVALID) != strlen(telno_str))
  1004. X    {
  1005. X        DEBUG(1, "phone number has invalid characters\n", 0);
  1006. X        return (RC_FAIL | RCE_PHNO);
  1007. X    }
  1008. X    if (decode_phone_number(telno_str, phone, sizeof(phone)))
  1009. X    {
  1010. X        DEBUG(1, "phone number too long\n", 0);
  1011. X        return (RC_FAIL | RCE_PHNO);
  1012. X    }
  1013. X
  1014. X/* walk through dialer codes, doing custom setup */
  1015. X    strcpy(cmd, "AT");
  1016. X    cptr = cmd + strlen(cmd);
  1017. X    if (dialer_codes['C' - 'A'])
  1018. X    {
  1019. X        DEBUG(5, "COMPRESSION requested\n", 0);
  1020. X        strcat(cmd, "S110=1");
  1021. X    }
  1022. X    if (dialer_codes['E' - 'A'])
  1023. X    {
  1024. X        DEBUG(5, "ECHO SUPPRESSION requested\n", 0);
  1025. X        strcat(cmd, "S121=1");
  1026. X    }
  1027. X    if (dialer_codes['F' - 'A'])
  1028. X    {
  1029. X        DEBUG(5, "XON/XOFF FLOW CONTROL requested\n", 0);
  1030. X        strcat(cmd, "S58=3");
  1031. X    }
  1032. X    if (dialer_codes['K' - 'A'])
  1033. X    {
  1034. X        DEBUG(5, "KERMIT requested\n", 0);
  1035. X        strcat(cmd, "S111=10");
  1036. X        s111_set++;
  1037. X    }
  1038. X    if (dialer_codes['X' - 'A'])
  1039. X    {
  1040. X        DEBUG(5, "XMODEM requested\n", 0);
  1041. X        strcat(cmd, "S111=20");
  1042. X        s111_set++;
  1043. X    }
  1044. X    if (dialer_codes['U' - 'A'])
  1045. X    {
  1046. X        DEBUG(5, "UUCP requested\n", 0);
  1047. X        strcat(cmd, "S111=30");
  1048. X        s111_set++;
  1049. X    }
  1050. X    if (dialer_codes['M' - 'A'])
  1051. X    {
  1052. X        DEBUG(5, "MNP requested\n", 0);
  1053. X        strcat(cmd, "S95=1");
  1054. X    }
  1055. X
  1056. X    if ((dialer_codes['P' - 'A']) || s111_set || (hiCBAUD >= B9600))
  1057. X    {
  1058. X        if (hiCBAUD < B9600)
  1059. X        {
  1060. X            DEBUG(1, "baud rate not high enough for PEP\n", 0);
  1061. X            return (RC_FAIL | RCE_SPEED);
  1062. X        }
  1063. X        if (dialer_codes['P' - 'A'])
  1064. X            DEBUG(5, "PEP requested\n", 0);
  1065. X        else
  1066. X            DEBUG(5, "PEP inferred: speed >= 9600\n", 0);
  1067. X
  1068. X        dialer_codes['P' - 'A'] = 1;
  1069. X        strcat(cmd, "S50=255");
  1070. X    }
  1071. X
  1072. X    DEBUG(6, "--> issuing default setup command\n", 0);
  1073. X    sync_Telebit();
  1074. X    lwrite(dialout_default);
  1075. X    if (lread(5) != rOk)
  1076. X    {
  1077. X        DEBUG(1, "default dialout setup failed\n", 0);
  1078. X        return (RC_FAIL | RCE_NULL);
  1079. X    }
  1080. X
  1081. X/* issue the custom setup command */
  1082. X    if (*cptr)
  1083. X    {
  1084. X        DEBUG(5, "--> issuing custom setup cmd\n", 0);
  1085. X        strcat(cmd, "\r");
  1086. X        sync_Telebit();
  1087. X        lwrite(cmd);
  1088. X        if (lread(5) != rOk)
  1089. X        {
  1090. X            DEBUG(1, "custom modem setup failed\n", 0);
  1091. X            return (RC_FAIL | RCE_NULL);
  1092. X        }
  1093. X    }
  1094. X
  1095. X/*
  1096. X * calculate a timeout for the connect
  1097. X * allow a minimum of 40 seconds, but if PEP, 90
  1098. X * also if long distance (North American calculation here)
  1099. X * make it 132 (S7 is calculated as timeout * .9)
  1100. X */
  1101. X    timeout = 40;
  1102. X    if ((phone[0] == '1') && (phone[0] != '0'))
  1103. X        timeout = 132;
  1104. X    if ((timeout < 90) && dialer_codes['P' - 'A'])
  1105. X        timeout = 90;
  1106. X    for (cptr = phone; cptr = strchr(cptr, ','); cptr++)
  1107. X        timeout += 2;         /* add extra time for pause characters */
  1108. X    DEBUG(6, "wait for connect = %d seconds\n", timeout);
  1109. X
  1110. X/* indicate non-root should not see DTE->DCE traffic */
  1111. X    secure = 1;
  1112. X
  1113. X/*
  1114. X * build and issue the actual dialing command
  1115. X * if root, let him see number, otherwise just say "remote system"
  1116. X */
  1117. X    DEBUG(1, "--> dialing %s\n", (!ecu_calling & uid)
  1118. X        ? "remote system" : telno_str);
  1119. X#ifdef WHT
  1120. X    if (!strncmp(*gargv, "ECU", 3))
  1121. X        dialer_codes['S' - 'A'] = 1;
  1122. X#endif
  1123. X    sprintf(cmd, "ATM%dS7=%dDT%s\r",
  1124. X        ((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,
  1125. X        (timeout * 9) / 10, phone);
  1126. X
  1127. X    /* cmd string can only be 80 characters including "AT" */
  1128. X    if (strlen(cmd) > 80)
  1129. X    {
  1130. X        DEBUG(1, "phone number string too long\n", 0);
  1131. X        cleanup(RC_FAIL | RCE_PHNO);
  1132. X    }
  1133. X
  1134. X    sync_Telebit();
  1135. X    lwrite(cmd);
  1136. X
  1137. X/* indicate non-root can see DTE->DCE traffic */
  1138. X    secure = 0;
  1139. X
  1140. X/* wait for connect */
  1141. X  WAIT_FOR_CONNECT:
  1142. X    time(&then);
  1143. X    result = lread(timeout);
  1144. X    if (!(result & rfConnect))
  1145. X    {
  1146. X        switch (result & rfMASK)
  1147. X        {
  1148. X            case rNoCarrier:
  1149. X                return (RC_FAIL | ((rrings > 2) ? RCE_ANSWER : RCE_NOTONE));
  1150. X            case rNoDialTone:
  1151. X                return (RC_FAIL | RCE_NOTONE);
  1152. X            case rBusy:
  1153. X                return (RC_FAIL | RCE_BUSY);
  1154. X            case rNoAnswer:
  1155. X                return (RC_FAIL | RCE_ANSWER);
  1156. X            case rRring:
  1157. X                if (rrings++ > 7)
  1158. X                    return (RC_FAIL | RCE_ANSWER);
  1159. X                time(&now);
  1160. X                if ((timeout -= ((int)(then - now))) > 0)
  1161. X                    goto WAIT_FOR_CONNECT;
  1162. X            case rError:
  1163. X            default:
  1164. X                return (RC_FAIL | RCE_NULL);
  1165. X        }
  1166. X    }
  1167. X
  1168. X    return (0);                 /* succeeded */
  1169. X
  1170. X}                             /* end of DCE_dial */
  1171. X
  1172. X/**********************************************************
  1173. X*  You probably do not need to modify the code below here *
  1174. X**********************************************************/
  1175. X
  1176. X/*+-------------------------------------------------------------------------
  1177. X    DCE_abort(sig) - dial attempt aborted
  1178. X
  1179. X sig =  0 if non-signal abort (read timeout, most likely)
  1180. X     != 0 if non-SIGALRM signal caught
  1181. X
  1182. X extern int dialing set  1 if dialing request was active,
  1183. X                    else 0 if hangup request was active
  1184. X
  1185. XThis is a chance for the DCE-specific code to do anything it
  1186. Xneeds to cl,ean up after a failure.  Note that if a dialing
  1187. Xcall fails, it is the responsibility of the higher-level
  1188. Xprogram calling the dialer to call it again with a hangup request, so
  1189. Xthis function is usually a no-op.
  1190. X--------------------------------------------------------------------------*/
  1191. Xvoid
  1192. XDCE_abort(sig)
  1193. Xint sig;
  1194. X{
  1195. X    DEBUG(10, "DCE_abort(%d);\n", sig);
  1196. X}                             /* end of DCE_abort */
  1197. X
  1198. X/*+-------------------------------------------------------------------------
  1199. X    DCE_exit(exitcode) - "last chance for gas" in this incarnation
  1200. X
  1201. XThe independent portion of the dialer program calls this routine in
  1202. Xlieu of exit() in every case except one (see DCE_argv_hook() below).
  1203. XNormally, this function just passes it's argument to exit(), but
  1204. Xany necessary post-processing can be done.  The function must,
  1205. Xhowever, eventually call exit(exitcode);
  1206. X--------------------------------------------------------------------------*/
  1207. Xvoid
  1208. XDCE_exit(exitcode)
  1209. Xint exitcode;
  1210. X{
  1211. X    DEBUG(10, "DCE_exit(%d);\n", exitcode);
  1212. X    exit(exitcode);
  1213. X}                             /* end of DCE_exit */
  1214. X
  1215. X/*+-------------------------------------------------------------------------
  1216. X    DCE_argv_hook(argc,argv,optind,unrecognized_switches)
  1217. X
  1218. XThis hook gives DCE-specific code a chance to look over the entire
  1219. Xcommand line, such as for -z Telebit processing.
  1220. X
  1221. Xargc andf argv are the same values passed to main(),
  1222. X
  1223. Xoptind is the value of optind at the end of normal getopt processing.
  1224. X
  1225. Xunrecognized_switches is the count of switches not handled by main().
  1226. XSpecifically, -h and -x are standard switches.
  1227. X
  1228. XNormally, this function should just return RC_FAIL|RCE_ARGS if there are
  1229. Xany unrecognized switches, otherwise zero.  If you keep your nose clean
  1230. Xthough, you can do anything you need to do here and exit the program.
  1231. X
  1232. XNote: only simple switches (with no argument) may be used with this
  1233. Xfacility if the functrion is to return,' since main()'s getopt() will
  1234. Xstop processing switches if it runs into an unrecognized switch with an
  1235. Xargument.
  1236. X
  1237. XIf the function returns a non-zero value, then the value will be passed
  1238. XDIRECTLY to exit() with no further ado.  Thus, a non-zero value must be
  1239. Xof the format expected by dialer program callers, with RC_FAIL set as a
  1240. Xminimum.
  1241. X--------------------------------------------------------------------------*/
  1242. Xint
  1243. XDCE_argv_hook(argc, argv, optind, unrecognized_switches)
  1244. Xint argc;
  1245. Xchar **argv;
  1246. Xint optind;
  1247. Xint unrecognized_switches;
  1248. X{
  1249. X    if (unrecognized_switches)
  1250. X        return (RC_FAIL | RCE_ARGS);
  1251. X    return (0);
  1252. X}                             /* end of DCE_argv_hook */
  1253. X
  1254. X/* vi: set tabstop=4 shiftwidth=4: */
  1255. END_OF_FILE
  1256.   if test 18169 -ne `wc -c <'ecu330/gendial/dceTBPlus.c'`; then
  1257.     echo shar: \"'ecu330/gendial/dceTBPlus.c'\" unpacked with wrong size!
  1258.   fi
  1259.   # end of 'ecu330/gendial/dceTBPlus.c'
  1260. fi
  1261. if test -f 'ecu330/gendial/dialer.h' -a "${1}" != "-c" ; then 
  1262.   echo shar: Will not clobber existing file \"'ecu330/gendial/dialer.h'\"
  1263. else
  1264.   echo shar: Extracting \"'ecu330/gendial/dialer.h'\" \(6114 characters\)
  1265.   sed "s/^X//" >'ecu330/gendial/dialer.h' <<'END_OF_FILE'
  1266. X/*+-------------------------------------------------------------------------
  1267. X    dialer.h - SCO UUCP generic dialer program definitions
  1268. X    wht%n4hgf.uucp@emory.mathcs.emory.edu -or- emory!n4hgf!wht
  1269. X--------------------------------------------------------------------------*/
  1270. X/*+:EDITS:*/
  1271. X/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  1272. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1273. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1274. X/*:03-29-1992-12:47-cma@ifsbd-added <sys/filio.h> */
  1275. X/*:03-29-1992-12:30-cma@ifsbd-added <sys/time.h> */
  1276. X/*:01-26-1992-15:30-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup */
  1277. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  1278. X/*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress */
  1279. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1280. X
  1281. X#include <stdio.h>
  1282. X#include <ctype.h>
  1283. X#include <errno.h>
  1284. X#include <fcntl.h>
  1285. X#include <setjmp.h>
  1286. X#include <signal.h>
  1287. X#include <string.h>
  1288. X#include <memory.h>
  1289. X#include <sys/types.h>
  1290. X#include <sys/errno.h>
  1291. X#include <sys/stat.h>
  1292. X#include <sys/timeb.h>
  1293. X#include <sys/time.h>
  1294. X#include <termio.h>
  1295. X#include <time.h>
  1296. X#include <pwd.h>
  1297. X
  1298. X#ifdef sun
  1299. X#define BSD
  1300. X#include <sys/filio.h>
  1301. X#endif
  1302. X
  1303. X#define ff fprintf
  1304. X#define se stderr
  1305. X
  1306. Xlong time();
  1307. Xstruct passwd *getpwnam();
  1308. X
  1309. Xextern int errno;
  1310. Xextern char *sys_errlist[];
  1311. X
  1312. Xextern int gargc;             /* global copy of main's argv */
  1313. Xextern char **gargv;         /* global copy of main's argv */
  1314. Xextern char *dce_name;         /* full pathname of ACU device */
  1315. Xextern char *telno;             /* phone number if dial type request */
  1316. Xextern struct termio dce_termio;    /* last termio for device */
  1317. Xextern int Debug;             /* set per -x flag */
  1318. Xextern int dialing;             /* set while dialing in progress */
  1319. Xextern int dce_fd;             /* file descriptor for dce_name */
  1320. Xextern int DialerExitCode;     /* return code */
  1321. Xextern int status;             /* set on errors */
  1322. Xextern int hangup_flag;         /* set when DCE being hung up */
  1323. Xextern int hiCBAUD;             /* highest permissible baud rate */
  1324. Xextern int loCBAUD;             /* lowest permissible baud rate */
  1325. Xextern struct passwd *passwd;/* pointer to password entry of invoker */
  1326. Xextern int uid;                 /* user id of executor */
  1327. Xextern int uid_uucp;         /* user id of uucp */
  1328. Xextern int secure;             /* non-zero to suppress display of secure DCE
  1329. X                              * traffic */
  1330. Xextern int ecu_calling;         /* true if ecu dialing */
  1331. X
  1332. Xunsigned char dialer_codes[26];    /* A-Z embedded phone number codes */
  1333. X/* return codes: these are set up so that an abort signal at any time can */
  1334. X/* set the fail bit and return to the caller with the correct status */
  1335. X#define    SUCCESS        0
  1336. X#define    RC_FAIL        0x80     /* 1 = failed to connect */
  1337. X#define    RC_ENABLED    0x10     /* enabled flag: 1 = ungetty -r required to
  1338. X                              * restore the line */
  1339. X#define    RC_BAUD        0x0f     /* CBAUD connected at (0=same as dialed
  1340. X                              * speed) */
  1341. X
  1342. X/* DCE result device independent flag */
  1343. X#define    rfNumeric    0x40000000
  1344. X
  1345. X/* program exit codes */
  1346. X#define    RCE_NULL    0         /* general purpose or unknown error code */
  1347. X#define    RCE_INUSE    1         /* line in use */
  1348. X#define    RCE_SIG        2         /* signal aborted dialer */
  1349. X#define    RCE_ARGS    3         /* invalid arguments */
  1350. X#define    RCE_PHNO    4         /* invalid phone number */
  1351. X#define    RCE_SPEED    5         /* invalid baud rate -or- bad connect baud */
  1352. X#define    RCE_OPEN    6         /* can't open line */
  1353. X#define    RCE_IOCTL    7         /* ioctl error */
  1354. X#define    RCE_TIMOUT    8         /* timeout */
  1355. X#define    RCE_NOTONE    9         /* no dial tone */
  1356. X#define    RCE_HANGUP    10         /* hangup failed */
  1357. X#define RCE_NORESP    11         /* Modem didn't respond. */
  1358. X#define    RCE_BUSY    13         /* phone is busy */
  1359. X#define    RCE_NOCARR    14         /* no carrier */
  1360. X#define    RCE_ANSWER    15         /* no answer */
  1361. X
  1362. X/* ungetty return codes */
  1363. X#define    UG_NOTENAB    0
  1364. X#define    UG_ENAB        1
  1365. X#define    UG_RESTART    1
  1366. X#define    UG_FAIL        2
  1367. X
  1368. X/* size for various buffers */
  1369. X#define MAXLINE        2048
  1370. X
  1371. X/* How many errors allowed before call retry fails */
  1372. X#define    DIAL_ERRORS_MAX    4
  1373. X
  1374. X/* DCE message to code mapping struct ... array DCE_results of these
  1375. X * must be terminated with { (char *)0,0 } */
  1376. Xtypedef struct dce_result
  1377. X{
  1378. X    char *result;
  1379. X    long code;
  1380. X}
  1381. XDCE_RESULT;
  1382. X
  1383. X#define DEBUG(level,fmt,arg) if (Debug >= level) fprintf(stderr,fmt,arg)
  1384. X#if !defined(DBG)
  1385. X#define    DBG    0
  1386. X#endif
  1387. X
  1388. X/*
  1389. X * what the hell does __STDC__ mean in reality?  An __STDC__ compiler is
  1390. X * more nouveau than an older one.  ANSI C (or 'D') just stirred new
  1391. X * food for "standard" readers who went off and did what they wanted
  1392. X * to do.  We use __STDC__ to decide between two opinions of
  1393. X * what constitute "ANSI prototypes."  As of this writing, __STDC__ is
  1394. X * defined by the UNIX (MSC 5) compiler and not by the XENIX (MSC 4)
  1395. X * compiler.  We handle the GNU C compiler too.
  1396. X */
  1397. X#if defined(__STDC__) && !defined(__GNUC__)
  1398. Xint DCE_baud_to_CBAUD(unsigned int);
  1399. Xvoid DCE_hangup(void);
  1400. Xint DCE_dial(char *);
  1401. Xvoid DCE_abort(int);
  1402. Xvoid DCE_exit(int);
  1403. Xint DCE_argv_hook(int, char **, int, int);
  1404. Xint get_uucp_uid(void);
  1405. Xint instr(char *, char *);
  1406. Xvoid translate(char *, char *);
  1407. Xint decode_phone_number(char *, char *, int);
  1408. Xchar *make_printable(unsigned char);
  1409. Xchar *RCE_text(int);
  1410. Xvoid myexit(int);
  1411. XSIGTYPE dial_abort(int);
  1412. Xvoid cleanup(int);
  1413. Xint SIGALRM_abort(int);
  1414. XSIGTYPE SIGALRM_alert(int);
  1415. Xint _lread(int, int);
  1416. Xint lread_ignore(int);
  1417. Xint lread(int);
  1418. Xvoid lflush(void);
  1419. Xvoid _lputc(char);
  1420. Xvoid _lputc_paced(long, char);
  1421. Xvoid _lputs(char *);
  1422. Xvoid _lputs_paced(long, char *);
  1423. Xvoid lwrite(char *);
  1424. Xvoid lflash_DTR(void);
  1425. Xint call_ungetty(char);
  1426. Xvoid display_termio(struct termio *, char *);
  1427. Xint open_dce(void);
  1428. Xint main(int, char **);
  1429. X
  1430. X#else
  1431. Xint DCE_baud_to_CBAUD();
  1432. Xvoid DCE_hangup();
  1433. Xint DCE_dial();
  1434. Xvoid DCE_abort();
  1435. Xvoid DCE_exit();
  1436. Xint DCE_argv_hook();
  1437. Xint get_uucp_uid();
  1438. Xint instr();
  1439. Xvoid translate();
  1440. Xint decode_phone_number();
  1441. Xchar *make_printable();
  1442. Xchar *RCE_text();
  1443. Xvoid myexit();
  1444. XSIGTYPE dial_abort();
  1445. Xvoid cleanup();
  1446. XSIGTYPE SIGALRM_alert();
  1447. Xint SIGALRM_abort();
  1448. Xint _lread();
  1449. Xint lread_ignore();
  1450. Xint lread();
  1451. Xvoid lflush();
  1452. Xvoid _lputc();
  1453. Xvoid _lputc_paced();
  1454. Xvoid _lputs();
  1455. Xvoid _lputs_paced();
  1456. Xvoid lwrite();
  1457. Xvoid lflash_DTR();
  1458. Xint call_ungetty();
  1459. Xvoid display_termio();
  1460. Xint open_dce();
  1461. Xint main();
  1462. X
  1463. X#endif
  1464. X
  1465. X/* vi: set tabstop=4 shiftwidth=4: */
  1466. X/* end of dialer.h */
  1467. END_OF_FILE
  1468.   if test 6114 -ne `wc -c <'ecu330/gendial/dialer.h'`; then
  1469.     echo shar: \"'ecu330/gendial/dialer.h'\" unpacked with wrong size!
  1470.   fi
  1471.   # end of 'ecu330/gendial/dialer.h'
  1472. fi
  1473. if test -f 'ecu330/z/zmodem.c' -a "${1}" != "-c" ; then 
  1474.   echo shar: Will not clobber existing file \"'ecu330/z/zmodem.c'\"
  1475. else
  1476.   echo shar: Extracting \"'ecu330/z/zmodem.c'\" \(18074 characters\)
  1477.   sed "s/^X//" >'ecu330/z/zmodem.c' <<'END_OF_FILE'
  1478. X#if defined(WHT) && !defined(SHOW_ZHDR_TYPE)
  1479. X#define SHOW_ZHDR_TYPE
  1480. X#endif
  1481. X/*+-------------------------------------------------------------------------
  1482. X    zmodem.c - ZMODEM protocol primitives
  1483. X    based on code by Chuck Forsberg
  1484. X
  1485. X  Defined functions:
  1486. X    noxrd7()
  1487. X    rclhdr(hdr)
  1488. X    stohdr(pos)
  1489. X    zdlread()
  1490. X    zgeth1()
  1491. X    zgethdr(hdr,eflag)
  1492. X    zgethex()
  1493. X    zputhex(c)
  1494. X    zrbhdr(hdr)
  1495. X    zrbhdr32(hdr)
  1496. X    zrdat32(buf,length)
  1497. X    zrdata(buf,length)
  1498. X    zrhhdr(hdr)
  1499. X    zsbh32(type,hdr)
  1500. X    zsbhdr(type,hdr)
  1501. X    zsda32(buf,length,frameend)
  1502. X    zsdata(buf,length,frameend)
  1503. X    zsendline(c)
  1504. X    zshhdr(type,hdr)
  1505. X
  1506. X--------------------------------------------------------------------------*/
  1507. X/*+:EDITS:*/
  1508. X/*:05-04-1994-04:40-wht@n4hgf-ECU release 3.30 */
  1509. X/*:01-25-1994-17:02-wht@n4hgf-robertl corrections + mv extern crctab to hdr */
  1510. X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  1511. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  1512. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1513. X/*:08-14-1990-20:41-wht@n4hgf-ecu3.00-flush old edit history */
  1514. X
  1515. X#include "zmodem.h"
  1516. X
  1517. Xextern char s128[];
  1518. Xextern int Zctlesc;
  1519. Xextern int Zmodem;
  1520. Xextern unsigned long Baudrate;
  1521. X
  1522. Xint Rxtimeout = 100;         /* Tenths of seconds to wait for something */
  1523. X
  1524. X#if !defined(UNSL)
  1525. X#define UNSL unsigned
  1526. X#endif
  1527. X
  1528. Xstatic lastsent;             /* Last char we sent */
  1529. Xstatic evenp;                 /* Even parity seen on header */
  1530. X
  1531. X/* Globals used by ZMODEM functions */
  1532. Xchar Attn[ZATTNLEN + 1];     /* Attention string rx sends to tx on err */
  1533. Xchar Rxhdr[4];                 /* Received header */
  1534. Xchar Txhdr[4];                 /* Transmitted header */
  1535. Xint Crc32;                     /* Display flag indicating 32 bit CRC being
  1536. X                              * received */
  1537. Xint Crc32t;                     /* Display flag indicating 32 bit CRC being
  1538. X                              * sent */
  1539. Xint Rxcount;                 /* Count of data bytes received */
  1540. Xint Rxframeind;                 /* ZBIN ZBIN32,or ZHEX type of frame received */
  1541. Xint Rxtype;                     /* Type of header received */
  1542. Xint Txfcs32;                 /* TURE means send binary frames with 32 bit
  1543. X                              * FCS */
  1544. Xint Zrwindow;                 /* RX window size (controls garbage count) */
  1545. Xlong Rxpos;                     /* Received file position */
  1546. Xlong Txpos;                     /* Transmitted file position */
  1547. X
  1548. Xchar *frametypes[] =
  1549. X{
  1550. X    "Carrier Lost",             /* -3 */
  1551. X    "TIMEOUT",                 /* -2 */
  1552. X    "ERROR",                 /* -1 */
  1553. X/* #define FTOFFSET 3 moved to zmodem.h */
  1554. X    "ZRQINIT",
  1555. X    "ZRINIT",
  1556. X    "ZSINIT",
  1557. X    "ZACK ",
  1558. X    "ZFILE",
  1559. X    "ZSKIP",
  1560. X    "ZNAK ",
  1561. X    "ZABORT",
  1562. X    "ZFIN ",
  1563. X    "ZRPOS",
  1564. X    "ZDATA",
  1565. X    "ZEOF ",
  1566. X    "ZFERR",
  1567. X    "ZCRC ",
  1568. X    "ZCHALLENGE",
  1569. X    "ZCOMPL",
  1570. X    "ZCAN ",
  1571. X    "ZFREECNT",
  1572. X    "ZCOMMAND",
  1573. X    "ZSTDERR",
  1574. X    "xxxxx"
  1575. X#define FRTYPES 22             /* Total number of frame types in this array */
  1576. X /* not including psuedo negative entries */
  1577. X};
  1578. X
  1579. X/*
  1580. X * Send character c with ZMODEM escape sequence encoding.
  1581. X *  Escape XON,XOFF. Escape CR following @ (Telenet net escape)
  1582. X */
  1583. Xvoid
  1584. Xzsendline(c)
  1585. Xint c;
  1586. X{
  1587. X
  1588. X    /* Quick check for non control characters */
  1589. X    if (c & 0140)
  1590. X        xsendline(lastsent = c);
  1591. X    else
  1592. X    {
  1593. X        switch (c &= 0377)
  1594. X        {
  1595. X            case ZDLE:
  1596. X                xsendline(ZDLE);
  1597. X                xsendline(lastsent = (c ^= 0100));
  1598. X                break;
  1599. X            case 015:
  1600. X            case 0215:
  1601. X                if (!Zctlesc && (lastsent & 0177) != '@')
  1602. X                    goto sendit;
  1603. X                /* **** FALL THRU TO **** */
  1604. X            case 020:
  1605. X            case 021:
  1606. X            case 023:
  1607. X            case 0220:
  1608. X            case 0221:
  1609. X            case 0223:
  1610. X                xsendline(ZDLE);
  1611. X                c ^= 0100;
  1612. X              sendit:
  1613. X                xsendline(lastsent = c);
  1614. X                break;
  1615. X            default:
  1616. X                if (Zctlesc && !(c & 0140))
  1617. X                {
  1618. X                    xsendline(ZDLE);
  1619. X                    c ^= 0100;
  1620. X                }
  1621. X                xsendline(lastsent = c);
  1622. X        }
  1623. X    }
  1624. X}
  1625. X
  1626. Xstatic char masked[] = "8 bit transparent path required";
  1627. Xstatic char badcrc[] = "Bad CRC";
  1628. X
  1629. X/* Send ZMODEM CRC-32 binary header hdr of type type */
  1630. Xvoid
  1631. Xzsbh32(type, hdr)
  1632. Xint type;
  1633. Xregister char *hdr;
  1634. X{
  1635. X    register int n;
  1636. X    register UNSL long crc;
  1637. X
  1638. X    sprintf(s128,
  1639. X#ifdef SHOW_ZHDR_TYPE
  1640. X        "B32 %s %ld",
  1641. X#else
  1642. X        "hdr %s %ld",
  1643. X#endif
  1644. X        frametypes[type + FTOFFSET], rclhdr(hdr));
  1645. X    report_last_txhdr(s128, 0);
  1646. X    report_tx_ind(1);
  1647. X    xsendline(ZBIN32);
  1648. X    zsendline(type);
  1649. X    crc = 0xFFFFFFFFL;
  1650. X    crc = UPDC32(type, crc);
  1651. X
  1652. X    for (n = 4; --n >= 0; ++hdr)
  1653. X    {
  1654. X        crc = UPDC32((0377 & *hdr), crc);
  1655. X        zsendline(*hdr);
  1656. X    }
  1657. X    crc = ~crc;
  1658. X    for (n = 4; --n >= 0;)
  1659. X    {
  1660. X        zsendline((int)crc);
  1661. X        crc >>= 8;
  1662. X    }
  1663. X    report_tx_ind(0);
  1664. X}
  1665. X
  1666. X/* Send ZMODEM binary header hdr of type type */
  1667. Xvoid
  1668. Xzsbhdr(type, hdr)
  1669. Xint type;
  1670. Xregister unsigned char *hdr;
  1671. X{
  1672. X    register int n;
  1673. X    register unsigned crc;
  1674. X
  1675. X    xsendline(ZPAD);
  1676. X    xsendline(ZDLE);
  1677. X
  1678. X    if (Crc32t = Txfcs32)
  1679. X        zsbh32(type, hdr);
  1680. X    else
  1681. X    {
  1682. X        sprintf(s128,
  1683. X#ifdef SHOW_ZHDR_TYPE
  1684. X            "B16 %s %ld",
  1685. X#else
  1686. X            "hdr %s %ld",
  1687. X#endif
  1688. X            frametypes[type + FTOFFSET], rclhdr(hdr));
  1689. X        report_last_txhdr(s128, 0);
  1690. X        report_tx_ind(1);
  1691. X
  1692. X        xsendline(ZBIN);
  1693. X        zsendline(type);
  1694. X        crc = updcrc(type, 0);
  1695. X
  1696. X        for (n = 4; --n >= 0; ++hdr)
  1697. X        {
  1698. X            zsendline(*hdr);
  1699. X            crc = updcrc(*hdr, crc);
  1700. X        }
  1701. X        crc = updcrc(0, updcrc(0, crc));
  1702. X        zsendline(crc >> 8);
  1703. X        zsendline(crc);
  1704. X        report_tx_ind(0);
  1705. X    }
  1706. X    if (type != ZDATA)
  1707. X        flushline();
  1708. X}
  1709. X
  1710. X/*
  1711. X * Send binary array buf of length length,with ending ZDLE sequence frameend
  1712. X */
  1713. Xstatic char *Zendnames[] =
  1714. X{"ZCRCE", "ZCRCG", "ZCRCQ", "ZCRCW"};
  1715. X
  1716. Xvoid
  1717. Xzsda32(buf, length, frameend)
  1718. Xregister char *buf;
  1719. Xint length;
  1720. Xint frameend;
  1721. X{
  1722. X    register int c;
  1723. X    register UNSL long crc;
  1724. X
  1725. X    sprintf(s128,
  1726. X#ifdef SHOW_ZHDR_TYPE
  1727. X        "D32 %s %d",
  1728. X#else
  1729. X        "data %s %d",
  1730. X#endif
  1731. X        Zendnames[frameend - ZCRCE & 3], length);
  1732. X    report_last_txhdr(s128, 0);
  1733. X    report_tx_ind(1);
  1734. X
  1735. X    crc = 0xFFFFFFFFL;
  1736. X    for (; --length >= 0; ++buf)
  1737. X    {
  1738. X        c = *buf & 0377;
  1739. X        if (c & 0140)
  1740. X            xsendline(lastsent = c);
  1741. X        else
  1742. X            zsendline(c);
  1743. X        crc = UPDC32(c, crc);
  1744. X    }
  1745. X    xsendline(ZDLE);
  1746. X    xsendline(frameend);
  1747. X    crc = UPDC32(frameend, crc);
  1748. X
  1749. X    crc = ~crc;
  1750. X    for (length = 4; --length >= 0;)
  1751. X    {
  1752. X        zsendline((int)crc);
  1753. X        crc >>= 8;
  1754. X    }
  1755. X    report_tx_ind(0);
  1756. X}
  1757. X
  1758. Xvoid
  1759. Xzsdata(buf, length, frameend)
  1760. Xregister unsigned char *buf;
  1761. Xint length;
  1762. Xint frameend;
  1763. X{
  1764. X    register unsigned short crc;
  1765. X
  1766. X    if (Crc32t)
  1767. X        zsda32(buf, length, frameend);
  1768. X    else
  1769. X    {
  1770. X        sprintf(s128,
  1771. X#ifdef SHOW_ZHDR_TYPE
  1772. X            "D16 %s %d",
  1773. X#else
  1774. X            "data %s %d",
  1775. X#endif
  1776. X            Zendnames[frameend - ZCRCE & 3], length);
  1777. X        report_last_txhdr(s128, 0);
  1778. X        report_tx_ind(1);
  1779. X        crc = 0;
  1780. X        for (; --length >= 0; ++buf)
  1781. X        {
  1782. X            zsendline(*buf);
  1783. X            crc = updcrc(*buf, crc);
  1784. X        }
  1785. X        xsendline(ZDLE);
  1786. X        xsendline(frameend);
  1787. X        crc = updcrc(frameend, crc);
  1788. X
  1789. X        crc = updcrc(0, updcrc(0, crc));
  1790. X        zsendline(crc >> 8);
  1791. X        zsendline(crc);
  1792. X        report_tx_ind(0);
  1793. X    }
  1794. X    if (frameend == ZCRCW)
  1795. X    {
  1796. X        xsendline(XON);
  1797. X        flushline();
  1798. X    }
  1799. X
  1800. X}
  1801. X
  1802. X/* Send a byte as two hex digits */
  1803. Xvoid
  1804. Xzputhex(c)
  1805. Xregister int c;
  1806. X{
  1807. X    static char digits[] = "0123456789abcdef";
  1808. X
  1809. X    sendline(digits[(c & 0xF0) >> 4]);
  1810. X    sendline(digits[(c) & 0xF]);
  1811. X}
  1812. X
  1813. Xvoid
  1814. Xzshhdr(type, hdr)
  1815. Xint type;
  1816. Xregister unsigned char *hdr;
  1817. X{
  1818. X    register int n;
  1819. X    register unsigned short crc;
  1820. X
  1821. X    sprintf(s128,
  1822. X#ifdef SHOW_ZHDR_TYPE
  1823. X        "HEX %s %ld",
  1824. X#else
  1825. X        "hdr %s %ld",
  1826. X#endif
  1827. X        frametypes[type + FTOFFSET], rclhdr(hdr));
  1828. X    report_last_txhdr(s128, 0);
  1829. X    report_tx_ind(1);
  1830. X    sendline(ZPAD);
  1831. X    sendline(ZPAD);
  1832. X    sendline(ZDLE);
  1833. X    sendline(ZHEX);
  1834. X    zputhex(type);
  1835. X    Crc32t = 0;
  1836. X
  1837. X    crc = updcrc(type, 0);
  1838. X    for (n = 4; --n >= 0; ++hdr)
  1839. X    {
  1840. X        zputhex(*hdr);
  1841. X        crc = updcrc(*hdr, crc);
  1842. X/*        crc = updcrc((0377 & *hdr),crc);  original - wht */
  1843. X    }
  1844. X    crc = updcrc(0, updcrc(0, crc));
  1845. X    zputhex(crc >> 8);
  1846. X    zputhex(crc);
  1847. X
  1848. X    /* Make it printable on remote machine */
  1849. X    sendline(015);
  1850. X    sendline(012);
  1851. X
  1852. X    /*
  1853. X     * Uncork the remote in case a fake XOFF has stopped data flow
  1854. X     */
  1855. X    if (type != ZFIN && type != ZACK)
  1856. X        sendline(021);
  1857. X    flushline();
  1858. X    report_tx_ind(0);
  1859. X}
  1860. X
  1861. X/*
  1862. X * Receive array buf of max length with ending ZDLE sequence
  1863. X *  and CRC.  Returns the ending character or error code.
  1864. X *  NB: On errors may store length+1 bytes!
  1865. X */
  1866. Xint
  1867. Xzrdat32(buf, length)
  1868. Xregister char *buf;
  1869. Xint length;
  1870. X{
  1871. X    register int c;
  1872. X    register UNSL long crc;
  1873. X    register char *end;
  1874. X    register int d;
  1875. X
  1876. X    report_rx_ind(1);
  1877. X    crc = 0xFFFFFFFFL;
  1878. X    Rxcount = 0;
  1879. X    end = buf + length;
  1880. X    while (buf <= end)
  1881. X    {
  1882. X        if ((c = zdlread()) & ~0377)
  1883. X        {
  1884. X          crcfoo:
  1885. X            switch (c)
  1886. X            {
  1887. X                case GOTCRCE:
  1888. X                case GOTCRCG:
  1889. X                case GOTCRCQ:
  1890. X                case GOTCRCW:
  1891. X                    d = c;
  1892. X                    c &= 0377;
  1893. X                    crc = UPDC32(c, crc);
  1894. X                    if ((c = zdlread()) & ~0377)
  1895. X                        goto crcfoo;
  1896. X                    crc = UPDC32(c, crc);
  1897. X                    if ((c = zdlread()) & ~0377)
  1898. X                        goto crcfoo;
  1899. X                    crc = UPDC32(c, crc);
  1900. X                    if ((c = zdlread()) & ~0377)
  1901. X                        goto crcfoo;
  1902. X                    crc = UPDC32(c, crc);
  1903. X                    if ((c = zdlread()) & ~0377)
  1904. X                        goto crcfoo;
  1905. X                    crc = UPDC32(c, crc);
  1906. X                    if (crc != 0xDEBB20E3L)
  1907. X                    {
  1908. X                        report_str(badcrc, 0);
  1909. X                        report_rx_ind(0);
  1910. X                        return (ERROR);
  1911. X                    }
  1912. X                    Rxcount = length - (end - buf);
  1913. X                    report_rxblklen(Rxcount);
  1914. X                    sprintf(s128,
  1915. X#ifdef SHOW_ZHDR_TYPE
  1916. X                        "D32 %s %d",
  1917. X#else
  1918. X                        "data %s %d",
  1919. X#endif
  1920. X                        Zendnames[d - GOTCRCE & 3], Rxcount);
  1921. X                    report_last_rxhdr(s128, 0);
  1922. X                    report_rx_ind(0);
  1923. X                    return (d);
  1924. X                case GOTCAN:
  1925. X                    report_str("Sender Canceled", 1);
  1926. X                    report_rx_ind(0);
  1927. X                    return (ZCAN);
  1928. X                case TIMEOUT:
  1929. X                    report_str("TIMEOUT", 0);
  1930. X                    report_rx_ind(0);
  1931. X                    return (c);
  1932. X                default:
  1933. X                    report_str("Bad data subpacket", 0);
  1934. X                    report_rx_ind(0);
  1935. X                    return (c);
  1936. X            }
  1937. X        }
  1938. X        *buf++ = c;
  1939. X        crc = UPDC32(c, crc);
  1940. X    }
  1941. X    report_str("Data subpacket too long", 0);
  1942. X    report_rx_ind(0);
  1943. X    return (ERROR);
  1944. X}
  1945. X
  1946. Xint
  1947. Xzrdata(buf, length)
  1948. Xregister char *buf;
  1949. Xint length;
  1950. X{
  1951. X    register int c;
  1952. X    register unsigned short crc;
  1953. X    register char *end;
  1954. X    register int d;
  1955. X
  1956. X    if (Rxframeind == ZBIN32)
  1957. X        return (zrdat32(buf, length));
  1958. X
  1959. X    report_rx_ind(1);
  1960. X    crc = Rxcount = 0;
  1961. X    end = buf + length;
  1962. X    while (buf <= end)
  1963. X    {
  1964. X        if ((c = zdlread()) & ~0377)
  1965. X        {
  1966. X          crcfoo:
  1967. X            switch (c)
  1968. X            {
  1969. X                case GOTCRCE:
  1970. X                case GOTCRCG:
  1971. X                case GOTCRCQ:
  1972. X                case GOTCRCW:
  1973. X                    crc = updcrc(((d = c) & 0377), crc);
  1974. X                    if ((c = zdlread()) & ~0377)
  1975. X                        goto crcfoo;
  1976. X                    crc = updcrc(c, crc);
  1977. X                    if ((c = zdlread()) & ~0377)
  1978. X                        goto crcfoo;
  1979. X                    crc = updcrc(c, crc);
  1980. X                    if (crc & 0xFFFF)
  1981. X                    {
  1982. X                        report_str(badcrc, 0);
  1983. X                        report_rx_ind(0);
  1984. X                        return (ERROR);
  1985. X                    }
  1986. X                    Rxcount = length - (end - buf);
  1987. X                    report_rxblklen(Rxcount);
  1988. X                    sprintf(s128,
  1989. X#ifdef SHOW_ZHDR_TYPE
  1990. X                        "D16 %s %d",
  1991. X#else
  1992. X                        "data %s %d",
  1993. X#endif
  1994. X                        Zendnames[d - GOTCRCE & 3], Rxcount);
  1995. X                    report_last_rxhdr(s128, 0);
  1996. X                    report_rx_ind(0);
  1997. X                    return (d);
  1998. X                case GOTCAN:
  1999. X                    report_str("Sender Cancelled", 1);
  2000. X                    report_rx_ind(0);
  2001. X                    return (ZCAN);
  2002. X                case TIMEOUT:
  2003. X                    report_str("TIMEOUT", 0);
  2004. X                    report_rx_ind(0);
  2005. X                    return (c);
  2006. X                default:
  2007. X                    report_str("Bad data subpacket", 0);
  2008. X                    report_rx_ind(0);
  2009. X                    return (c);
  2010. X            }
  2011. X        }
  2012. X        *buf++ = c;
  2013. X        crc = updcrc(c, crc);
  2014. X    }
  2015. X    report_str("Data subpacket too long", 0);
  2016. X    report_rx_ind(0);
  2017. X    return (ERROR);
  2018. X}
  2019. X
  2020. X/*
  2021. X * Read a ZMODEM header to hdr,either binary or hex.
  2022. X *  eflag controls local display of non zmodem characters:
  2023. X *    0:  no display
  2024. X *    1:  display printing characters only
  2025. X *    2:  display all non ZMODEM characters
  2026. X *  On success,set Zmodem to 1,set Rxpos and return type of header.
  2027. X *   Otherwise return negative on error.
  2028. X *   Return ERROR instantly if ZCRCW sequence,for fast error recovery.
  2029. X */
  2030. Xint
  2031. Xzgethdr(hdr, eflag)
  2032. Xchar *hdr;
  2033. Xint eflag;
  2034. X{
  2035. X    register int c, n, cancount;
  2036. X
  2037. X#ifdef SHOW_ZHDR_TYPE
  2038. X    char *hdrtyp = "?";
  2039. X
  2040. X#endif
  2041. X
  2042. X    report_rx_ind(1);
  2043. X    n = Zrwindow + Baudrate; /* Max bytes before start of frame */
  2044. X    Rxframeind = Rxtype = 0;
  2045. X
  2046. X  startover:
  2047. X    cancount = 5;
  2048. X  again:
  2049. X    /* Return immediate ERROR if ZCRCW sequence seen */
  2050. X    switch (c = readline(Rxtimeout))
  2051. X    {
  2052. X        case RCDO:
  2053. X        case TIMEOUT:
  2054. X            goto fifi;
  2055. X        case CAN:
  2056. X          gotcan:
  2057. X            if (--cancount <= 0)
  2058. X            {
  2059. X                c = ZCAN;
  2060. X                goto fifi;
  2061. X            }
  2062. X            switch (c = readline(1))
  2063. X            {
  2064. X                case TIMEOUT:
  2065. X                    goto again;
  2066. X                case ZCRCW:
  2067. X                    c = ERROR;
  2068. X                    /* **** FALL THRU TO **** */
  2069. X                case RCDO:
  2070. X                    goto fifi;
  2071. X                default:
  2072. X                    break;
  2073. X                case CAN:
  2074. X                    if (--cancount <= 0)
  2075. X                    {
  2076. X                        c = ZCAN;
  2077. X                        goto fifi;
  2078. X                    }
  2079. X                    goto again;
  2080. X            }
  2081. X            /* **** FALL THRU TO **** */
  2082. X        default:
  2083. X          agn2:
  2084. X            if (--n == 0)
  2085. X            {
  2086. X                report_str("Garbage count exceeded", 1);
  2087. X                report_last_rxhdr("Noise", 0);
  2088. X                report_rx_ind(0);
  2089. X                return (ERROR);
  2090. X            }
  2091. X            goto startover;
  2092. X        case ZPAD | 0200:     /* This is what we want. */
  2093. X        case ZPAD:             /* This is what we want. */
  2094. X            evenp = c & 0200;
  2095. X            break;
  2096. X    }
  2097. X    cancount = 5;
  2098. X  splat:
  2099. X    switch (c = noxrd7())
  2100. X    {
  2101. X        case ZPAD:
  2102. X            goto splat;
  2103. X        case RCDO:
  2104. X        case TIMEOUT:
  2105. X            goto fifi;
  2106. X        default:
  2107. X            goto agn2;
  2108. X        case ZDLE:             /* This is what we want. */
  2109. X            break;
  2110. X    }
  2111. X
  2112. X    switch (c = noxrd7())
  2113. X    {
  2114. X        case RCDO:
  2115. X        case TIMEOUT:
  2116. X            goto fifi;
  2117. X        case ZBIN:
  2118. X            Rxframeind = ZBIN;
  2119. X            Crc32 = FALSE;
  2120. X            c = zrbhdr(hdr);
  2121. X            break;
  2122. X        case ZBIN32:
  2123. X            Crc32 = Rxframeind = ZBIN32;
  2124. X            c = zrbhdr32(hdr);
  2125. X            break;
  2126. X        case ZHEX:
  2127. X            Rxframeind = ZHEX;
  2128. X            Crc32 = FALSE;
  2129. X            c = zrhhdr(hdr);
  2130. X            break;
  2131. X        case CAN:
  2132. X            goto gotcan;
  2133. X        default:
  2134. X            goto agn2;
  2135. X    }
  2136. X    Rxpos = hdr[ZP3] & 0377;
  2137. X    Rxpos = (Rxpos << 8) + (hdr[ZP2] & 0377);
  2138. X    Rxpos = (Rxpos << 8) + (hdr[ZP1] & 0377);
  2139. X    Rxpos = (Rxpos << 8) + (hdr[ZP0] & 0377);
  2140. X  fifi:
  2141. X    switch (c)
  2142. X    {
  2143. X        case GOTCAN:
  2144. X            c = ZCAN;
  2145. X            /* **** FALL THRU TO **** */
  2146. X        case ZNAK:
  2147. X        case ZCAN:
  2148. X        case ERROR:
  2149. X        case TIMEOUT:
  2150. X        case RCDO:
  2151. X            sprintf(s128, "Got %s", frametypes[c + FTOFFSET]);
  2152. X            report_str(s128, 0);
  2153. X            /* **** FALL THRU TO **** */
  2154. X        default:
  2155. X#ifdef SHOW_ZHDR_TYPE
  2156. X            switch (Rxframeind)
  2157. X            {
  2158. X                case ZBIN:
  2159. X                    hdrtyp = "B16";
  2160. X                    break;
  2161. X                case ZBIN32:
  2162. X                    hdrtyp = "B32";
  2163. X                    break;
  2164. X                case ZHEX:
  2165. X                    hdrtyp = "HEX";
  2166. X                    break;
  2167. X            }
  2168. X            if (c >= -3 && c <= FRTYPES)
  2169. X                sprintf(s128, "%s %s %ld", hdrtyp, frametypes[c + FTOFFSET], Rxpos);
  2170. X            else
  2171. X                sprintf(s128, "%s 0x%02x? %ld", hdrtyp, c, Rxpos);
  2172. X#else
  2173. X            if (c >= -3 && c <= FRTYPES)
  2174. X                sprintf(s128, "hdr %s %ld", frametypes[c + FTOFFSET], Rxpos);
  2175. X            else
  2176. X                sprintf(s128, "hdr 0x%02x? %ld", c, Rxpos);
  2177. X#endif
  2178. X            report_last_rxhdr(s128, 0);
  2179. X    }
  2180. X    report_rx_ind(0);
  2181. X    return (c);
  2182. X}
  2183. X
  2184. X/* Receive a binary style header (type and position) */
  2185. Xint
  2186. Xzrbhdr(hdr)
  2187. Xregister char *hdr;
  2188. X{
  2189. X    register int c, n;
  2190. X    register unsigned short crc;
  2191. X
  2192. X    if ((c = zdlread()) & ~0377)
  2193. X        return (c);
  2194. X    Rxtype = c;
  2195. X    crc = updcrc(c, 0);
  2196. X
  2197. X    for (n = 4; --n >= 0; ++hdr)
  2198. X    {
  2199. X        if ((c = zdlread()) & ~0377)
  2200. X            return (c);
  2201. X        crc = updcrc(c, crc);
  2202. X        *hdr = c;
  2203. X    }
  2204. X    if ((c = zdlread()) & ~0377)
  2205. X        return (c);
  2206. X    crc = updcrc(c, crc);
  2207. X    if ((c = zdlread()) & ~0377)
  2208. X        return (c);
  2209. X    crc = updcrc(c, crc);
  2210. X    if (crc & 0xFFFF)
  2211. X    {
  2212. X        if (evenp)
  2213. X            report_str(masked, 1);
  2214. X        report_str(badcrc, 0);
  2215. X        return (ERROR);
  2216. X    }
  2217. X#if defined(ZMODEM)
  2218. X    Protocol = ZMODEM;
  2219. X#endif
  2220. X    Zmodem = 1;
  2221. X    return (Rxtype);
  2222. X}
  2223. X
  2224. X/* Receive a binary style header (type and position) with 32 bit FCS */
  2225. Xint
  2226. Xzrbhdr32(hdr)
  2227. Xregister char *hdr;
  2228. X{
  2229. X    register int c, n;
  2230. X    register UNSL long crc;
  2231. X
  2232. X    if ((c = zdlread()) & ~0377)
  2233. X        return (c);
  2234. X    Rxtype = c;
  2235. X    crc = 0xFFFFFFFFL;
  2236. X    crc = UPDC32(c, crc);
  2237. X
  2238. X    for (n = 4; --n >= 0; ++hdr)
  2239. X    {
  2240. X        if ((c = zdlread()) & ~0377)
  2241. X            return (c);
  2242. X        crc = UPDC32(c, crc);
  2243. X        *hdr = c;
  2244. X    }
  2245. X    for (n = 4; --n >= 0;)
  2246. X    {
  2247. X        if ((c = zdlread()) & ~0377)
  2248. X            return (c);
  2249. X        crc = UPDC32(c, crc);
  2250. X    }
  2251. X    if (crc != 0xDEBB20E3)
  2252. X    {
  2253. X        if (evenp)
  2254. X            report_str(masked, 1);
  2255. X        report_str(badcrc, 0);
  2256. X        return (ERROR);
  2257. X    }
  2258. X#if defined(ZMODEM)
  2259. X    Protocol = ZMODEM;
  2260. X#endif
  2261. X    Zmodem = 1;
  2262. X    return (Rxtype);
  2263. X}
  2264. X
  2265. X/* Receive a hex style header (type and position) */
  2266. Xint
  2267. Xzrhhdr(hdr)
  2268. Xchar *hdr;
  2269. X{
  2270. X    register int c;
  2271. X    register unsigned short crc;
  2272. X    register int n;
  2273. X
  2274. X    if ((c = zgethex()) < 0)
  2275. X        return (c);
  2276. X    Rxtype = c;
  2277. X    crc = updcrc(c, 0);
  2278. X
  2279. X    for (n = 4; --n >= 0; ++hdr)
  2280. X    {
  2281. X        if ((c = zgethex()) < 0)
  2282. X            return (c);
  2283. X        crc = updcrc(c, crc);
  2284. X        *hdr = c;
  2285. X    }
  2286. X    if ((c = zgethex()) < 0)
  2287. X        return (c);
  2288. X    crc = updcrc(c, crc);
  2289. X    if ((c = zgethex()) < 0)
  2290. X        return (c);
  2291. X    crc = updcrc(c, crc);
  2292. X    if (crc & 0xFFFF)
  2293. X    {
  2294. X        report_str(badcrc, 0);
  2295. X        return (ERROR);
  2296. X    }
  2297. X    if (readline(1) == '\r') /* Throw away possible cr/lf */
  2298. X        readline(1);
  2299. X#if defined(ZMODEM)
  2300. X    Protocol = ZMODEM;
  2301. X#endif
  2302. X    Zmodem = 1;
  2303. X    return (Rxtype);
  2304. X}
  2305. X
  2306. X/* Decode two lower case hex digits into an 8 bit byte value */
  2307. Xint
  2308. Xzgeth1()
  2309. X{
  2310. X    register int c, n;
  2311. X
  2312. X    if ((c = noxrd7()) < 0)
  2313. X        return (c);
  2314. X    n = c - '0';
  2315. X    if (n > 9)
  2316. X        n -= ('a' - ':');
  2317. X    if (n & ~0xF)
  2318. X        return (ERROR);
  2319. X    if ((c = noxrd7()) < 0)
  2320. X        return (c);
  2321. X    c -= '0';
  2322. X    if (c > 9)
  2323. X        c -= ('a' - ':');
  2324. X    if (c & ~0xF)
  2325. X        return (ERROR);
  2326. X    c += (n << 4);
  2327. X    return (c);
  2328. X}
  2329. X
  2330. Xint
  2331. Xzgethex()
  2332. X{
  2333. X    return (zgeth1());
  2334. X}
  2335. X
  2336. X/*
  2337. X * Read a byte,checking for ZMODEM escape encoding
  2338. X *  including CAN*5 which represents a quick abort
  2339. X */
  2340. Xint
  2341. Xzdlread()
  2342. X{
  2343. X    register int c;
  2344. X
  2345. X  again:
  2346. X    /* Quick check for non control characters */
  2347. X    if ((c = readline(Rxtimeout)) & 0140)
  2348. X        return (c);
  2349. X    switch (c)
  2350. X    {
  2351. X        case ZDLE:
  2352. X            break;
  2353. X        case 023:
  2354. X        case 0223:
  2355. X        case 021:
  2356. X        case 0221:
  2357. X            goto again;
  2358. X        default:
  2359. X            if (Zctlesc && !(c & 0140))
  2360. X            {
  2361. X                goto again;
  2362. X            }
  2363. X            return (c);
  2364. X    }
  2365. X  again2:
  2366. X    if ((c = readline(Rxtimeout)) < 0)
  2367. X        return (c);
  2368. X    if (c == CAN && (c = readline(Rxtimeout)) < 0)
  2369. X        return (c);
  2370. X    if (c == CAN && (c = readline(Rxtimeout)) < 0)
  2371. X        return (c);
  2372. X    if (c == CAN && (c = readline(Rxtimeout)) < 0)
  2373. X        return (c);
  2374. X    switch (c)
  2375. X    {
  2376. X        case CAN:
  2377. X            return (GOTCAN);
  2378. X        case ZCRCE:
  2379. X        case ZCRCG:
  2380. X        case ZCRCQ:
  2381. X        case ZCRCW:
  2382. X            return (c | GOTOR);
  2383. X        case ZRUB0:
  2384. X            return (0177);
  2385. X        case ZRUB1:
  2386. X            return (0377);
  2387. X        case 023:
  2388. X        case 0223:
  2389. X        case 021:
  2390. X        case 0221:
  2391. X            goto again2;
  2392. X        default:
  2393. X            if (Zctlesc && !(c & 0140))
  2394. X            {
  2395. X                goto again2;
  2396. X            }
  2397. X            if ((c & 0140) == 0100)
  2398. X                return (c ^ 0100);
  2399. X            break;
  2400. X    }
  2401. X    sprintf(s128, "Bad escape sequence %x", c);
  2402. X    report_str(s128, 0);
  2403. X    return (ERROR);
  2404. X}
  2405. X
  2406. X/*
  2407. X * Read a character from the modem line with timeout.
  2408. X *  Eat parity,XON and XOFF characters.
  2409. X */
  2410. Xint
  2411. Xnoxrd7()
  2412. X{
  2413. X    register int c;
  2414. X
  2415. X    for (;;)
  2416. X    {
  2417. X        if ((c = readline(Rxtimeout)) < 0)
  2418. X            return (c);
  2419. X        switch (c &= 0177)
  2420. X        {
  2421. X            case XON:
  2422. X            case XOFF:
  2423. X                continue;
  2424. X            default:
  2425. X                if (Zctlesc && !(c & 0140))
  2426. X                    continue;
  2427. X            case '\r':
  2428. X            case '\n':
  2429. X            case ZDLE:
  2430. X                return (c);
  2431. X        }
  2432. X    }
  2433. X}
  2434. X
  2435. X/* Store long integer pos in Txhdr */
  2436. Xvoid
  2437. Xstohdr(pos)
  2438. Xlong pos;
  2439. X{
  2440. X    Txhdr[ZP0] = pos;
  2441. X    Txhdr[ZP1] = pos >> 8;
  2442. X    Txhdr[ZP2] = pos >> 16;
  2443. X    Txhdr[ZP3] = pos >> 24;
  2444. X}
  2445. X
  2446. X/* Recover a long integer from a header */
  2447. Xlong
  2448. Xrclhdr(hdr)
  2449. Xregister char *hdr;
  2450. X{
  2451. X    register long l;
  2452. X
  2453. X    l = (hdr[ZP3] & 0377);
  2454. X    l = (l << 8) | (hdr[ZP2] & 0377);
  2455. X    l = (l << 8) | (hdr[ZP1] & 0377);
  2456. X    l = (l << 8) | (hdr[ZP0] & 0377);
  2457. X    return (l);
  2458. X}
  2459. X
  2460. X/* end of zmodem.c */
  2461. X/* vi: set tabstop=4 shiftwidth=4: */
  2462. END_OF_FILE
  2463.   if test 18074 -ne `wc -c <'ecu330/z/zmodem.c'`; then
  2464.     echo shar: \"'ecu330/z/zmodem.c'\" unpacked with wrong size!
  2465.   fi
  2466.   # end of 'ecu330/z/zmodem.c'
  2467. fi
  2468. echo shar: End of archive 23 \(of 37\).
  2469. cp /dev/null ark23isdone
  2470. MISSING=""
  2471. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ; do
  2472.     if test ! -f ark${I}isdone ; then
  2473.     MISSING="${MISSING} ${I}"
  2474.     fi
  2475. done
  2476. if test "${MISSING}" = "" ; then
  2477.     echo You have unpacked all 37 archives.
  2478.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2479. else
  2480.     echo You still must unpack the following archives:
  2481.     echo "        " ${MISSING}
  2482. fi
  2483. exit 0
  2484. exit 0 # Just in case...
  2485.