home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / ip / ppp / mac / macppp2.0.1-src.hqx / MacPPP 2.0.1 src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-29  |  4.6 KB  |  174 lines

  1. /*
  2.  *  main.c    - main setup routine for MacPPP called by MacTCP
  3.  *
  4.  * Copyright 1992-1993 Merit Network, Inc. and The Regents of the
  5.  *  University of Michigan.  Usage of this source code is restricted
  6.  *  to non-profit, non-commercial purposes.  The source is provided
  7.  *  "as-is", without warranty.
  8.  */
  9. #include "ppp.h"
  10. #include <Folders.h>
  11. #include <GestaltEqu.h>
  12. #include <SetUpA4.h>
  13. /* The #include <SetUpA4.h> above generates code, so you better be
  14.     compiling this with Custom Headers OFF!  The standard header
  15.     would branch around this code. */
  16.  
  17. #define    PKT_HDR_SIZE    4
  18. #define FCSPOLY 0x8408
  19.  
  20. /*    This module is called at system startup.  Its main purpose is to
  21. *    allocate memory for the LapInfo structure and initialize the entry
  22. *    points. Since this is the only time we will have addressibility to
  23. *    ourselves, all globals must be defined here.  Pointers to globals
  24. *    are saved in the LapInfo.
  25. *
  26. *   1993 Merit Network, Inc.
  27. */
  28.  
  29. LapInfo *main() {
  30.  
  31. LapInfo        *lap;
  32. extern b_8 lcp_option_length[];
  33. extern struct lcp_value_s lcp_default;
  34. extern b_8 ipcp_option_length[];
  35. extern struct ipcp_value_s ipcp_default;
  36. extern struct NMRec errnmrec;
  37. extern b_8      memerrmes[];
  38. int            i,n;
  39. unsigned short    v;
  40. pascal    OSErr    pppSelectorFunc(OSType, long *);
  41.  
  42.     /* Get addressibility to ourself. A0->code resource. */
  43.     RememberA0();
  44.     SetUpA4();
  45.  
  46.     /* Allocate memory for LapInfo and clear it */
  47.     if ( (lap = (LapInfo *) NewPtrClear(sizeof(LapInfo))) == nil) {
  48.         errnmrec.nmStr = memerrmes;    /* initialize pointer to error message */
  49.         NMInstall(&errnmrec);        /* Install the notification */
  50.         return (nil);
  51.     }
  52.  
  53. #ifdef LOG
  54.     lap->logp = &(lap->log[0]);
  55. #endif
  56.     /* Store our entry points */
  57.     lap->lapInit = PPPInit;
  58.     lap->lapOpen = PPPOpen;
  59.     lap->lapClose = PPPClose;
  60.     lap->lapUnload = PPPUnload;
  61.     lap->lapAttach = PPPAttachPH;
  62.     lap->lapDetach = PPPDetachPH;
  63.     lap->lapOutput = PPPWrite;
  64.     lap->lapControl = PPPControl;
  65.     lap->lapFault = PPPFault;
  66.     lap->lapStatistics = PPPStatistics;
  67.     lap->lapConfigure = PPPConfigure;
  68.     lap->lapProbe = PPPProbe;
  69.     lap->lapRegister = PPPRegister;
  70.     lap->lapFindGateway = PPPFindGW;
  71.     lap->lapGwyCheck = nil;
  72.     
  73.     lap->lapAddrLength = 0;
  74.     lap->addressConflict = FALSE;
  75.  
  76.             /* build FCS table */
  77.     for (n=0; n < 256; n++) {
  78.         v = n;
  79.         for (i = 0; i < 8; i++)
  80.             v = v & 1 ? (v>>1)^FCSPOLY : v >> 1;            
  81.         lap->fcstab[n] = v;
  82.     }
  83.         
  84.     /* save application's A5 for callbacks */
  85.     lap->ipGlobals = (Ptr)geta5();
  86.  
  87.     /* save Lap's A4 global data access */
  88.     lap->LapA4 = (Ptr)geta4();
  89.  
  90.     /* Store size requirements for this link access protocol */
  91.     lap->headerSize = 0;        /* size of LAP link header */
  92.     lap->outMaxPacketSize = LCP_MRU_DEFAULT;    /* not used */
  93.     lap->inMaxPacketSize = LCP_MRU_DEFAULT;        /* not used */
  94.     lap->maxDataSize = LCP_MRU_DEFAULT;
  95.  
  96.     /* initialize pointers to option defaults and lengths */
  97.     
  98.     lap->lcp_option_length_p = lcp_option_length;
  99.     lap->ipcp_option_length_p = ipcp_option_length;
  100.     lap->lcp_default_p = &lcp_default;
  101.     lap->ipcp_default_p = &ipcp_default;
  102.     
  103.     lap->ppp_flags = 0;
  104.         
  105.     SetLAPPtr(lap);        /* set up pointer to lap, for easy access */
  106.     
  107.     ppp_init(lap);        /* initialize ppp pointers, etc. */
  108.     
  109.     /* Install PPP Gestalt function */
  110.     NewGestalt((OSType) 'PPP ', (ProcPtr) pppSelectorFunc);
  111.     
  112.     RestoreA4();
  113.     return (lap);
  114. }
  115.  
  116. pascal OSErr pppSelectorFunc(OSType ppptype, long *response)
  117. {
  118.     *response = (long) GetLAPPtr();        /* get pointer to Lap globals */
  119.     return noErr;
  120. }
  121.  
  122. /* 
  123. *    Define globals.  Note this must come at the end of the file since 
  124. *    MacTCP jumps to the beginning of the code resource, expecting
  125. *    main to be there.
  126. */
  127. b_8 lcp_option_length[] = {
  128.      0,        /* unused */
  129.      4,        /* MRU */
  130.      6,        /* ACCM */
  131.      4,        /* authentication */
  132.      8,        /* LQM */
  133.      6,        /* magic number */
  134.      2,        /* undefined */
  135.      2,        /* Protocol compression */
  136.      2        /* Address/Control compression */
  137. };
  138.     
  139. struct lcp_value_s lcp_default = {
  140.     LCP_MRU_DEFAULT,    /* default MRU (1500) */
  141.     0,                    /* no authentication */
  142.     LCP_ACCM_DEFAULT,    /* default ACCM (0xffffffff) */
  143.     0L                    /* no default for magic number */
  144. };
  145.  
  146. b_8 ipcp_option_length[] = {
  147.      0,        /* unused */
  148.     10,        /* address */
  149.      6,        /* compression */
  150.      6        /* new address negotiation */
  151. };
  152. struct ipcp_value_s ipcp_default = {
  153.     0L,        /* no local address */
  154.     0L,        /* no remote address (only used in old-style Addresses negotiation */
  155.     0,        /* no compression protocol */
  156.     0,        /* no compression slots */
  157.     0        /* do not compress slot id */
  158. };
  159.  
  160. b_8 memerrmes[]="\pMacPPP: Insufficient memory!";
  161. struct NMRec errnmrec = {
  162.     (QElemPtr) 0,    /* qLink */
  163.     nmType,            /* qType */
  164.     0,                /* nmFlags */
  165.     0L,                /* nmPrivate */
  166.     0,                /* nmReserved */
  167.     0,                /* nmMark */
  168.     (Handle) 0,    /* nmIcon */
  169.     (Handle) -1,    /* nmSound */
  170.     (StringPtr) 0, /* nmStr, need to fill this in */
  171.     (NMProcPtr) -1,    /* nmResp */
  172.     0L,                /* nmRefCon */
  173. };
  174.