home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / ncsat.cpt / Telnet2.5 final / tcpip / ether.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-12  |  8.6 KB  |  404 lines

  1. #ifndef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4. /*
  5. *    ether.c
  6. *     by Gaige B. Paulsen
  7. ****************************************************************************
  8. *                                                                          *
  9. *      Uses    :                                                               *
  10. *      TCP/IP kernel for NCSA Telnet                                       *
  11. *      by Tim Krauskopf                                                    *
  12. *       with Macintosh code by Gaige B. Paulsen                                 *
  13. *                                                                          *
  14. *      National Center for Supercomputing Applications                     *
  15. *      152 Computing Applications Building                                 *
  16. *      605 E. Springfield Ave.                                             *
  17. *      Champaign, IL  61820                                                *
  18. *                                                                          *
  19. *                                                                          *
  20. ****************************************************************************
  21. *
  22. *    EtherNet init and shutdown (and utility) procs.    
  23. *
  24. *    Called by:
  25. *        dlayer.c
  26. *        mactools.c
  27. *        macutil.c
  28. */
  29.  
  30. #include <StdLib.h>
  31. #include <ctype.h>
  32.  
  33. #include <Devices.h>
  34. #include <Dialogs.h>
  35. #include <Files.h>
  36. #include <ROMDefs.h>
  37. #include <Slots.h>
  38. #include <stdio.h>
  39. #include <String.h>
  40. #include <AppleTalk.h>
  41.  
  42. #include "configrec.h"
  43. #include "protocol.h"
  44. #include "data.h"
  45. #include "EtherTalk.h"
  46. #include "hostform.h"
  47.  
  48. #include "event.h"            /* BYU 2.4.15 */
  49. #include "fastnet.h"
  50. #include "maclook.h"
  51. #include "confile.h"
  52. #include "croft.h"
  53.  
  54.  
  55. typedef struct {
  56.     char    node[26];
  57.     char    net[2];
  58. } ABusVarStruct, *ABusVarPtr, **ABusVarHdl;
  59.  
  60. extern int EtherNet;
  61. short ENETdriver;
  62.  
  63. extern ETListen();
  64.  
  65. void ETcall
  66.   (
  67.     EtParam *ep,
  68.     int call
  69.   )
  70. {
  71.     int bkgr=-1;
  72.  
  73.     ep->ioCompletion=0L;
  74.     ep->ioCRefNum = ENETdriver;
  75.     ep->csCode= call;
  76.  
  77.     if (call = EWrite) bkgr=0;
  78.  
  79.     PBControl((ParmBlkPtr) ep, bkgr);
  80. }
  81.  
  82. void getETaddress
  83.   (
  84.     char *store
  85.   )
  86. {
  87.     EtParam EP;
  88.  
  89.     if (EtherNet==-2)
  90.         getFNaddress(store);
  91.     EP.address= store;
  92.     EP.bufsize= 6;
  93.     ETcall(&EP, EGetInfo);
  94. }
  95.  
  96. /*
  97.  * ETfindcard()
  98.  *
  99.  * Finds the EtherNet Card in a Mac II
  100.  *    if *slotp is != 0, then look on that slot for the sResource ID #
  101.  *
  102.  */
  103.  
  104. int ETfindcard
  105.   (
  106.     int *slotp,
  107.     int *spidp
  108.   )
  109. {
  110.     OSErr err;
  111.     SpBlock spb;
  112.  
  113.     spb.spSlot        = *slotp;
  114.     spb.spID        = 0;
  115.     spb.spExtDev    = 0;
  116.     spb.spCategory    = catNetwork;
  117.     spb.spCType     = typeEtherNet;
  118.     spb.spTBMask    = 0x03;
  119.  
  120.     err = SNextTypeSRsrc( &spb);
  121.     *slotp= spb.spSlot;
  122.     *spidp= spb.spID;
  123.  
  124.     if (err)
  125.         return(-1);
  126.     else
  127.         return( 0);
  128. }
  129. #ifdef AZTEC
  130. #asm
  131.     public    _SNextTypeSRsrc
  132. _SNextTypeSRsrc
  133.     move.l    4(sp),a0
  134.     moveq    #$15,D0
  135.     dc.w    $A06E
  136.     rts                
  137.  
  138.     public    _OpenSlot
  139. _OpenSlot
  140.     move.l    4(sp),a0
  141.     move.w    8(sp),d0
  142.     bne.s    os1
  143.     dc.w    $a200
  144.     bra.s    os2
  145. os1:
  146.     dc.w    $a600
  147. os2:
  148.     rts
  149. #endasm
  150. #endif AZTEC
  151.  
  152. int ETclose
  153.   (
  154.     void
  155.   )
  156. {
  157.     /* int err; */
  158.     EtParam EP;
  159.  
  160.     EP.protocol= EARP;
  161.     /* err = */ ETcall(&EP, EDetachPH);
  162.  
  163.     EP.protocol= ERARP;
  164.     /* err = */ ETcall(&EP, EDetachPH);
  165.  
  166.     EP.protocol= EIP;
  167.     /* err = */ ETcall(&EP, EDetachPH);
  168.  
  169.     /*Close( ENETdriver); */
  170.  
  171.     return
  172.         0;
  173. }
  174.  
  175. int ETopen
  176.   (
  177.     void
  178.   )
  179. {
  180.     short err;
  181.     short socket=72;        /* BYU 2.4.15 MPW */
  182.     char buffr[100];
  183.     DialogPtr dtemp;
  184.     EtParam EP;
  185.  
  186.     if (EtherNet<0) {
  187. #ifndef MPW
  188.         err=opendriver("\P.ENET0",&ENETdriver );
  189. #else 
  190.         err=opendriver(".ENET0",&ENETdriver );
  191. #endif MPW
  192.         ETcall(&EP, 1010);        /* Turn off the Kinetics stuff */
  193.         ETcall(&EP, 1011);
  194.         }
  195.     else {
  196.         SlotDevParam sdpb;
  197.         int slot, spid;
  198.  
  199.         err=-1;                    /* So we can be an error by default */
  200.  
  201.         if (EtherNet <9)        /* No Slot Specified */
  202.             slot=0;
  203.         else
  204.             slot=EtherNet;
  205.  
  206.         if (!ETfindcard( &slot, &spid)) {
  207.             sdpb.ioSlot = slot;
  208.             sdpb.ioID = spid;
  209.             sdpb.ioCompletion = 0L;
  210. #ifndef MPW
  211.             sdpb.ioNamePtr = "\P.ENET";
  212. #else
  213.             sdpb.ioNamePtr = "\p.ENET";
  214. #endif MPW
  215.             sdpb.ioPermssn = fsCurPerm;
  216.             sdpb.ioVRefNum = 0;
  217.             sdpb.ioMix = 0L;
  218.             sdpb.ioFlags = 0;
  219.     
  220.             sprintf(buffr, "Opening the ENET driver for %d(%d)",slot,spid);
  221.             EtherNet = slot;
  222.             putln(buffr);
  223.  
  224. /* Mac Quadra with Friendly Net Adaptor is             /* BYU 2.4.20 */
  225. /* slot 0, which causes a problem here for             /* BYU 2.4.20 */
  226. /* the NCSA driver because EtherNet = 0              /* BYU 2.4.20 */
  227. /* means AppleTalk.                                    /* BYU 2.4.20 */
  228.             if (!slot)                                /* BYU 2.4.20 */
  229.               EtherNet = 1;                            /* BYU 2.4.20 */
  230.             else                                    /* BYU 2.4.20 */
  231.               EtherNet = slot;                        /* BYU 2.4.20 */
  232.  
  233.             OpenSlot((ParmBlkPtr) &sdpb, FALSE);
  234.             err= sdpb.ioResult;
  235.             ENETdriver = sdpb.ioRefNum;
  236.             }
  237.         }
  238.  
  239.     if (err!=0) { 
  240.             sprintf(buffr,"Failed EtherTalk initialization (%d)\015",err);    /* BYU 2.4.18 - changed \n to \015 */
  241.             putln(buffr);
  242. #ifndef MPW
  243.             paramtext(0L,0L,0L,"\PCouldn't open driver[E]");
  244. #else
  245.             paramtext(0L,0L,0L,"Couldn't open driver[E]");
  246. #endif MPW
  247.             dtemp=GetNewDialog(302, (Ptr) 0L, (WindowPtr) -1L);
  248. #if 1                                                            /* BYU 2.4.15 */
  249.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  250.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  251.             EtherNet = -100;                                    /* BYU 2.4.15 */
  252. #else                                                            /* BYU 2.4.15 */
  253.             ModalDialog(0L,&item);
  254. #endif                                                            /* BYU 2.4.15 */
  255.             DisposDialog(dtemp);
  256. /*            exit(1);                                            /* BYU 2.4.15 */
  257.             }
  258.  
  259.     EP.address=ETListen;
  260.     EP.protocol= EIP;
  261.     /*err = */ ETcall(&EP, EAttachPH);
  262.     if (/* err != */ 0) { 
  263.             sprintf(buffr,"Failed EtherTalk initialization (%d)\015",err);    /* BYU 2.4.18 - changed \n to \015 */
  264.             putln(buffr);
  265. #ifndef MPW
  266.             paramtext(0L,0L,0L,"\PCouldn't Install IP Handler[E]");
  267. #else
  268.             paramtext(0L,0L,0L,"Couldn't Install IP Handler[E]");
  269. #endif MPW
  270.             dtemp=GetNewDialog(302,(Ptr) 0L,(WindowPtr) -1L);
  271. #if 1                                                            /* BYU 2.4.15 */
  272.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  273.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  274.             EtherNet = -100;                                    /* BYU 2.4.15 */
  275. #else                                                            /* BYU 2.4.15 */
  276.             ModalDialog(0L,&item);
  277. #endif                                                            /* BYU 2.4.15 */
  278.             DisposDialog(dtemp);
  279.             ETclose();
  280. /*            exit(1);                                            /* BYU 2.4.15 */
  281.             }
  282.  
  283.     EP.address=ETListen;
  284.     EP.protocol= EARP;
  285.     /* err = */ ETcall(&EP, EAttachPH);
  286.     if (/* err != */ 0) { 
  287.             sprintf(buffr,"Failed EtherTalk initialization (%d)\015",err);    /* BYU 2.4.18 - changed \n to \015 */
  288.             putln(buffr);
  289. #ifndef MPW
  290.             paramtext(0L,0L,0L,"\PCouldn't Install ARP Handler[E]");
  291. #else
  292.             paramtext(0L,0L,0L,"Couldn't Install ARP Handler[E]");
  293. #endif MPW
  294.             dtemp=GetNewDialog(302,(Ptr) 0L,(WindowPtr) -1L);
  295. #if 1                                                            /* BYU 2.4.15 */
  296.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  297.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  298.             EtherNet = -100;                                    /* BYU 2.4.15 */
  299. #else                                                            /* BYU 2.4.15 */
  300.             ModalDialog(0L,&item);
  301. #endif                                                            /* BYU 2.4.15 */
  302.             DisposDialog(dtemp);
  303.             ETclose();
  304. /*            exit(1);                                            /* BYU 2.4.15 */
  305.             }
  306.  
  307.     EP.address=ETListen;
  308.     EP.protocol= ERARP;
  309.     /* err = */ ETcall(&EP, EAttachPH);
  310.     if (/* err != */ 0) { 
  311.             sprintf(buffr,"Failed EtherTalk initialization (%d)\015",err);    /* BYU 2.4.18 - changed \n to \015 */
  312.             putln(buffr);
  313. #ifndef MPW
  314.             paramtext(0L,0L,0L,"\PCouldn't Install RARP Handler[E]");
  315. #else
  316.             paramtext(0L,0L,0L,"Couldn't Install RARP Handler[E]");
  317. #endif MPW
  318.             dtemp=GetNewDialog(302,(Ptr) 0L,(WindowPtr) -1L);
  319. #if 1                                                            /* BYU 2.4.15 */
  320.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  321.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  322.             EtherNet = -100;                                    /* BYU 2.4.15 */
  323. #else                                                            /* BYU 2.4.15 */
  324.             ModalDialog(0L,&item);
  325. #endif                                                            /* BYU 2.4.15 */
  326.             DisposDialog(dtemp);
  327.             ETclose();
  328. /*            exit(1);                                            /* BYU 2.4.15 */
  329.             }
  330.  
  331.  
  332.     ETcall(&EP, ESetGeneral);
  333.  
  334.     getETaddress( &nnmyaddr[0]);
  335.     return(0);
  336. }
  337.  
  338. int netconfig
  339.   (
  340.     char *hardware
  341.   )
  342. {
  343.     extern int nnemac;
  344.     int len;
  345.     char *p, temp[50];
  346.  
  347.     len = strlen(hardware);
  348.  
  349.     p=hardware;
  350.     /*
  351.     if (len <=0)
  352.         return(-1);
  353.     */
  354.  
  355.     while (len--) {
  356.         *p= toupper( *p);
  357.         p++;
  358.         }
  359.  
  360.     if (!strncmp( hardware, "SERIAL", 5))         /* BYU 2.4.15 */
  361.         EtherNet = -100;                        /* BYU 2.4.15 */
  362.  
  363.     if (!strncmp( hardware, "MACTCP", 5))         /* BYU 2.4.16 */
  364.         EtherNet = -99;                            /* BYU 2.4.16 */
  365.  
  366.     if (!strncmp( hardware, "ETHER", 5)) {
  367.         p=hardware+5;
  368.         if (!strncmp( p, "SE",2) || !strncmp(p,"SC",2))
  369.             EtherNet=-1;
  370.         else {
  371.             if (sscanf(p, "%d", &EtherNet)>0) {
  372.                 if (EtherNet>14 || EtherNet<9)
  373.                     EtherNet=1;
  374.                 }
  375.             else
  376.                 EtherNet=1;
  377.             }
  378.         sprintf( temp, "We got ether something (%d)", EtherNet);
  379.         putln(temp);
  380.         }
  381.  
  382.     if (!strncmp( hardware,"FASTNET",7)) {
  383.         extern int SCSI_ID;                        /* The Fastnet Scuzzi ID */
  384.         char temp[100];
  385.  
  386.         EtherNet=-2;
  387.         if (sscanf(hardware+7L,"%d",&len)==1)
  388.             SCSI_ID = len;
  389.         sprintf(temp, "Got one of them FastNet thingies(%d)", SCSI_ID);
  390.         putln(temp);
  391.         }
  392.  
  393.     nnemac = (EtherNet != 0);
  394.     if (!EtherNet) {
  395.         struct config c;
  396.  
  397.         Sgetconfig(&c);
  398.         KIPsetzone(c.zone);
  399.         }
  400.     initipnum(0);
  401.  
  402.     return(0);
  403. }
  404.