home *** CD-ROM | disk | FTP | other *** search
- /*
- * main.c - main setup routine for MacPPP called by MacTCP
- *
- * Copyright 1992-1993 Merit Network, Inc. and The Regents of the
- * University of Michigan. Usage of this source code is restricted
- * to non-profit, non-commercial purposes. The source is provided
- * "as-is", without warranty.
- */
- #include "ppp.h"
- #include <Folders.h>
- #include <GestaltEqu.h>
- #include <SetUpA4.h>
- /* The #include <SetUpA4.h> above generates code, so you better be
- compiling this with Custom Headers OFF! The standard header
- would branch around this code. */
-
- #define PKT_HDR_SIZE 4
- #define FCSPOLY 0x8408
-
- /* This module is called at system startup. Its main purpose is to
- * allocate memory for the LapInfo structure and initialize the entry
- * points. Since this is the only time we will have addressibility to
- * ourselves, all globals must be defined here. Pointers to globals
- * are saved in the LapInfo.
- *
- * 1993 Merit Network, Inc.
- */
-
- LapInfo *main() {
-
- LapInfo *lap;
- extern b_8 lcp_option_length[];
- extern struct lcp_value_s lcp_default;
- extern b_8 ipcp_option_length[];
- extern struct ipcp_value_s ipcp_default;
- extern struct NMRec errnmrec;
- extern b_8 memerrmes[];
- int i,n;
- unsigned short v;
- pascal OSErr pppSelectorFunc(OSType, long *);
-
- /* Get addressibility to ourself. A0->code resource. */
- RememberA0();
- SetUpA4();
-
- /* Allocate memory for LapInfo and clear it */
- if ( (lap = (LapInfo *) NewPtrClear(sizeof(LapInfo))) == nil) {
- errnmrec.nmStr = memerrmes; /* initialize pointer to error message */
- NMInstall(&errnmrec); /* Install the notification */
- return (nil);
- }
-
- #ifdef LOG
- lap->logp = &(lap->log[0]);
- #endif
- /* Store our entry points */
- lap->lapInit = PPPInit;
- lap->lapOpen = PPPOpen;
- lap->lapClose = PPPClose;
- lap->lapUnload = PPPUnload;
- lap->lapAttach = PPPAttachPH;
- lap->lapDetach = PPPDetachPH;
- lap->lapOutput = PPPWrite;
- lap->lapControl = PPPControl;
- lap->lapFault = PPPFault;
- lap->lapStatistics = PPPStatistics;
- lap->lapConfigure = PPPConfigure;
- lap->lapProbe = PPPProbe;
- lap->lapRegister = PPPRegister;
- lap->lapFindGateway = PPPFindGW;
- lap->lapGwyCheck = nil;
-
- lap->lapAddrLength = 0;
- lap->addressConflict = FALSE;
-
- /* build FCS table */
- for (n=0; n < 256; n++) {
- v = n;
- for (i = 0; i < 8; i++)
- v = v & 1 ? (v>>1)^FCSPOLY : v >> 1;
- lap->fcstab[n] = v;
- }
-
- /* save application's A5 for callbacks */
- lap->ipGlobals = (Ptr)geta5();
-
- /* save Lap's A4 global data access */
- lap->LapA4 = (Ptr)geta4();
-
- /* Store size requirements for this link access protocol */
- lap->headerSize = 0; /* size of LAP link header */
- lap->outMaxPacketSize = LCP_MRU_DEFAULT; /* not used */
- lap->inMaxPacketSize = LCP_MRU_DEFAULT; /* not used */
- lap->maxDataSize = LCP_MRU_DEFAULT;
-
- /* initialize pointers to option defaults and lengths */
-
- lap->lcp_option_length_p = lcp_option_length;
- lap->ipcp_option_length_p = ipcp_option_length;
- lap->lcp_default_p = &lcp_default;
- lap->ipcp_default_p = &ipcp_default;
-
- lap->ppp_flags = 0;
-
- SetLAPPtr(lap); /* set up pointer to lap, for easy access */
-
- ppp_init(lap); /* initialize ppp pointers, etc. */
-
- /* Install PPP Gestalt function */
- NewGestalt((OSType) 'PPP ', (ProcPtr) pppSelectorFunc);
-
- RestoreA4();
- return (lap);
- }
-
- pascal OSErr pppSelectorFunc(OSType ppptype, long *response)
- {
- *response = (long) GetLAPPtr(); /* get pointer to Lap globals */
- return noErr;
- }
-
- /*
- * Define globals. Note this must come at the end of the file since
- * MacTCP jumps to the beginning of the code resource, expecting
- * main to be there.
- */
- b_8 lcp_option_length[] = {
- 0, /* unused */
- 4, /* MRU */
- 6, /* ACCM */
- 4, /* authentication */
- 8, /* LQM */
- 6, /* magic number */
- 2, /* undefined */
- 2, /* Protocol compression */
- 2 /* Address/Control compression */
- };
-
- struct lcp_value_s lcp_default = {
- LCP_MRU_DEFAULT, /* default MRU (1500) */
- 0, /* no authentication */
- LCP_ACCM_DEFAULT, /* default ACCM (0xffffffff) */
- 0L /* no default for magic number */
- };
-
- b_8 ipcp_option_length[] = {
- 0, /* unused */
- 10, /* address */
- 6, /* compression */
- 6 /* new address negotiation */
- };
- struct ipcp_value_s ipcp_default = {
- 0L, /* no local address */
- 0L, /* no remote address (only used in old-style Addresses negotiation */
- 0, /* no compression protocol */
- 0, /* no compression slots */
- 0 /* do not compress slot id */
- };
-
- b_8 memerrmes[]="\pMacPPP: Insufficient memory!";
- struct NMRec errnmrec = {
- (QElemPtr) 0, /* qLink */
- nmType, /* qType */
- 0, /* nmFlags */
- 0L, /* nmPrivate */
- 0, /* nmReserved */
- 0, /* nmMark */
- (Handle) 0, /* nmIcon */
- (Handle) -1, /* nmSound */
- (StringPtr) 0, /* nmStr, need to fill this in */
- (NMProcPtr) -1, /* nmResp */
- 0L, /* nmRefCon */
- };
-