home *** CD-ROM | disk | FTP | other *** search
- /*
- * lap.c
- *
- * This module contains the MacTCP Lap interface routines.
- *
- * 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>
- /*
- * PPPAttachPH
- * MacTCP passes us the address of the IP protocol handler, which we must
- * call after receiving an IP packet over the serial line.
- * Called at application level or system task time.
- */
-
- OSErr PPPAttachPH(LapInfo *lap, voidProcPtr ptr) {
- lap->ip_ph = ptr; /* save address of routine to call on receive done */
- return (noErr);
- }
-
- /* PPPClose
- * Called by MacTCP to close the LAP.
- * Called at application level or system task time.
- */
- OSErr PPPClose(LapInfo * lap) {
- fsm_close(&(lap->ppp_fsm[Lcp])); /* send close event to LCP */
- while (lap->ppp_phase != pppDEAD) { /* wait for link to close */
- SystemTask();
- }
- }
-
- /*
- * PPPConfigure
- * Called by MacTCP driver after LAP initialization. This routine
- * fills in the IP address and netmask.
- */
-
- void PPPConfigure(LapInfo *lap) {
- if (lap->ppp_fsm[IPcp].state == fsmOPENED) { /* check if IPCP is opened */
- /* return IP address negotiated by IPCP to MacTCP */
- lap->cur_ip_addr = lap->ipcp_i.local.work.ipcp_option.address;
-
- /* set netmask to something reasonable */
- if (lap->cur_ip_addr & 0xC0000000)
- lap->cur_net_mask = 0xffffff00;
- else if (lap->cur_ip_addr & 0x80000000)
- lap->cur_net_mask = 0xffff0000;
- else
- lap->cur_net_mask = 0xff000000;
- return;
- }
- /* lap is closed, so try to re-open */
- PPP_DEBUG_CHECKS("\pConfigure on closed lap");
- if (lap->transProc != nil) {
- (*(lap->transProc))(TransitionOpen); /* try reopening lap */
- }
- }
-
- /*
- * PPPControl
- * This routine is never called by the current version of MacTCP (1.1.1)
- */
-
- OSErr PPPControl(LapInfo * lap) {
- return (noErr);
- }
- /*
- * PPPDetachPH
- * Called when MacTCP driver is closing. This routine releases binding
- * to the IP packet reception routine.
- */
- OSErr PPPDetachPH(LapInfo *lap) {
- lap->ip_ph = nil;
- return (noErr);
- }
-
- /*
- * PPPFault
- * MacTCP detected problem in communication
- */
- void PPPFault(LapInfo *lap, ip_addr lnd) {
- lap->faults++;
- }
-
- /*
- * PPPFindGW
- * The concept of a gateway isn't relevent for a point-to-point link,
- * but we need to provide an address to MacTCP.
- */
- void PPPFindGW(struct LapInfo *lap)
- {
- /* Just use our IP address as the gateway address */
- lap->lc.dfl_gateway_addr = lap->cur_ip_addr;
- return;
- }
- /*
- * PPPInit
- * Called when the MacTCP driver is opened. We attempt to open the
- * PPP session at this point, by sending an open event to the IPCP
- * protocol.
- */
- OSErr PPPInit(LapInfo *lap, longProcPtr transitionProc) {
-
- if (lap->ppp_flags & CLOSE_PPP) {
- lap->ppp_flags &= ~CLOSE_PPP;
- lap->transProc = nil;
- return -1;
- }
- if (lap->ppp_flags & (ECHO_FAIL | IDLE_TIMEOUT)) {
- link_open(lap); /* handle special cases */
- lap->ppp_flags &= ~(ECHO_FAIL | IDLE_TIMEOUT);
- } else {
- fsm_close( &(lap->ppp_fsm[Lcp]) ); /* put in initial state */
- fsm_close( &(lap->ppp_fsm[IPcp]) ); /* put in initial state */
- fsm_open( &(lap->ppp_fsm[IPcp]) ); /* send open event to IPCP */
- }
- if (lap->ppp_fsm[IPcp].state != fsmOPENED) { /* check if IPCP is up */
- lap->transProc = nil; /* reset tranproc pointer */
- return -1; /* indicate init failed to MacTCP */
- }
- if ( transitionProc != nil ) { /* if this is first call */
- lap->ip_ph = nil; /* reset packet handler pointer */
- lap->savProc = transitionProc; /* set pointer to transition proc */
- }
- lap->transProc = lap->savProc; /* refresh transition proc pointer */
- return noErr; /* PPP is up */
- }
- /*
- * PPPOpen
- * Not called by current version of MacTCP (1.1.1)
- */
- OSErr PPPOpen(LapInfo *lap) {
- return (noErr);
- }
- /*
- * PPPProbe
- * Used only for dynamic addressing. Not useful for MacPPP.
- */
- Boolean PPPProbe(LapInfo *lap, ip_addr addr) {
- return (false);
- }
- /*
- * PPPRegister
- * Assume the remote end gave us a good IP address.
- */
- Boolean PPPRegister(LapInfo *lap) {
- lap->addressConflict = FALSE;
- return (1);
- }
- /*
- * PPPStatistics
- * Called by MacTCP to acquire link speed information and for
- * network management. Decision on protocol timeouts and usable MTU
- * are made with the values returned by this call.
- */
- OSErr PPPStatistics(struct LapInfo *lap, struct LapStats *statsPtr) {
- statsPtr->ifMaxMTU = lap->outMaxPacketSize;
- statsPtr->ifSpeed = (unsigned long) lap->configdata.baudrate;
- statsPtr->ifPhyAddrLength = 0;
- statsPtr->ifPhysicalAddress = nil;
- return (noErr);
- }
- /*
- * PPPUnload
- * Called by MacTCP driver to release the memory held by the
- * LAP.
- */
- void PPPUnload(struct LapInfo *lap) {
- if (lap->ppp_phase != pppDEAD)
- link_close(); /* close the link */
- SetLAPPtr(nil); /* set lap pointer to nil */
- DisposPtr((Ptr) lap); /* dispose of memory */
- return;
- }
- /*
- * PPPWrite
- * MacTCP calls this routine to transmit an IP packet on our link.
- * The write requests are queued for transmission.
- */
- void IOCompleted(LapInfo *, struct ipbuf *);
-
- OSErr PPPWrite(LapInfo *lap, ip_addr addr, struct ipbuf *ipb) {
-
- lap->idle_timer = 0; /* clear idle timer */
- if (lap->ppp_fsm[IPcp].state != fsmOPENED) {
- PPP_DEBUG_CHECKS("\pPPPWrite: IPcp not opened");
- IOCompleted(lap, ipb); /* fake the completion routine */
- /* (*(lap->transProc))(TransitionOpen); */ /* signal open */
- lap->OutError++;
- return (noErr); /* return no error */
- }
-
- /* save ptr to LapInfo for IP */
- ipb->lap = lap;
-
- /* try to get a free transmit queue element */
- return(QueueFrame(lap, nil, ipb));
- }
-
-