⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pppoethernet.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* pppOEthernet.c - PPP over Ethernet framing component *//* Copyright 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02o,15may03,ijm removed adv_net.h02n,28mar03,rp  move test code for SPR 73591 to Vantive02m,08nov02,ijm clear pppOELastReceivedSession when stack is deleted02l,01nov02,ijm include adv_net.h for IPv6 stack02k,15oct02,qhu fixed cookie corruption problem, SPR 7359102j,20aug02,ijm fixed diab compiler warnings02i,15jul02,rp  multi-service support02h,26jun02,ijm added header files to support dual stack02g,28may02,rvr fixed build warnings 02f,07dec01,mk  added macros _WRS_PACK_ALIGN(x),to fix alignment                problems for PPP for arm02e,30nov01,ijm set mBlkPktHdr.len in pppOEAddHeader02d,14nov01,sj  added support for returning all service names available                when service name "" (ANY) is requested, SPR#7168302c,23aug01,ijm removed duplicate freeing of packet if M_PREPEND fails02b,02may01,ijm set pRecvdDiscPkt to NULL in pppOEMakePADO, PADR, and		PADS.  Removed duplicate free in pppOEReceive                case PPPOE_CODE_PADT.02a,20mar01,ijm corrected race condition in pppOEReceive01z,20mar01,ijm corrected casting of PPPOE_STACK_DATA pointer                 in pppOEStackObjGet and pppOEStackIdMapClear01y,18dec00,ijm corrected packet length in pppOEAddHeader01x,29sep00,sj  Merging in and reorganizing RFC2233 instrumentation01w,29sep00,sj  merging with TOR2_0-WINDNET_PPP-CUM_PATCH_201v,24aug00,sj  PADT uses 0x8863 as protocol01u,21aug00,sj  call stackAddError Callback when retries are exhausted; TSR                #16056801t,07aug00,adb publish and raise PPP_SUB_LAYER_DEAD_EVENT01s,02aug00,adb Merging in LAC modifications01r,01aug00,adb Merging with openstack view except RFC 2233 and                closing SPR 33371; expanded names from 16 to 32 bytes01q,31jul00,md  initializes collectPppAttributesEvent01p,11jul00,md  subscribed COLLECT_PPP_ATTRIBUTES_EVENT01o,18jul00,bsn Added Statistics and Port Interface01n,29jun00,md  subscribed COLLECT_PPP_ATTRIUBTES_EVENT01m,14mar00,sj  removed #if 0 #endif sequences01l,06mar00,sj  dont send A PADT if we received one + validate stackObj in                pppOEStackObjResolve when retrieved from packet01k,10jan00,sj  added PADT support + check acNameTag in case PADO + dont send                ac name tag in PADI + AC mode does not support HOST mode01j,12nov99,sj  TAG end of tag list is not required01i,08nov99,sj  Init to Create01h,03nov99,sj  save callbacks in stackData;+ session list fix01g,03nov99,sj  updated for latest version of framework; filled in some TO DOs01f,20aug99,sj  modified for generic framework; fixed for Little Endian 01e,20jul99,sj  added timers and retry mechanisms01d,20jul99,sj  fixed src and dest enet addr mixup.01c,19jul99,sj  achieved connection via ethernet between two PPC 860 targets01b,19jul99,sj  tested with loopback via the MUX and achieved session state01a,01jul99,sj 	created*//*DESCRIPTIONThis component enables PPP sessions over Ethernet as defined in RFC 2516.At the time of instantiation/creation this component may be configured tofunction as a HOST/CLIENT only or as an Access Concentrator(AC) only.It is implemented as a component plug-in object and when added to aframework instance it resides in the FRAMING plane within the FRAMING_LAYERof the framework. The profile/configuration parameters are definedin $WIND_BASE/target/h/ppp/pppOEthernet.hThis component supports interfaces for adding services that are supportedas an AC. Adding a service creates a daemon stack that remains in"PFW_STACKADD_IN_PROGRESS" state for its life, and listens for servicerequests. Requests for a service names that are available are processedwithin the context of the corresponding daemon stack. When issuing a sessionID to the client/host a new stack instance is added based on the same profilethat created the service. The stackId of this new stack is issued as the session ID to the client. The newly added stack is allowed to completethrough upper layers if any and achive "PFW_STACK_READY" state.This component sends PPPoE Packets and receives entire Ethernet frames.The destination address and the protocol type (DISCOVERY=0x8863 orSESSION=0x8864) for outgoing packets is set using the interface:"ADAPTER_DEST_ADDR_AND_PROTOCOL_SET," to be provided by the underlyingadapter component. This is done for each packet sent during the DISCOVERYphase and one last time after attaining sesssion phase for all packets tobe transmitted during the life of the session.To faciliate Stack resolution by the underlying adapter for eachreceived PPPoE packet this component supports the interface:"FRAMING_COMPONENT_STACK_RESOLVE_INTERFACE". This interface returns tothe adapter component a reference to the stack corresponding to thesession ID for established sessions and the stack corresponding to therequested service name during DISCOVERY phase.Currenly only END model ethernet drivers are supported if the underlyingadapter is the MUX_ADAPTER. Also if the MUX_ADAPTER is used the "muxSvcType"profile parameter should be set to the value "0x8863:0x8864" for DISCOVERYand SESSION phase protocol types respectively.CAVEAT: When using the MUX_ADAPTER only one framework in the system mayhave and use this PPPoE component. INCLUDE FILES: if_ether.h pppOEthernet.h  framingComponentInterfaces.h adapterComponentInterfaces.h*/#include "vxWorks.h"#include "pfw/pfw.h"#include "logLib.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "ctype.h"#include "memLib.h"#include "sllLib.h"#include "net/mbuf.h"#include "netBufLib.h"#include "netinet/if_ether.h"#include "pfw/pfwProfile.h"#include "pfw/pfwStack.h"#include "pfw/pfwEvent.h"#include "pfw/pfwComponent.h"#include "pfw/pfwLayer.h"#include "pfw/pfwTimer.h"#include "pfw/pfwMemory.h"#include "ppp/kppp.h"#include "ppp/pppLacStructures.h"#include "ppp/pppOEthernet.h"#include "ppp/interfaces/framingComponentInterfaces.h"#include "ppp/interfaces/adapterComponentInterfaces.h"#include "ppp/interfaces/pppInterfacesGroupInterfaces.h"/* defines */#define PPPOE_DEBUG#undef PPPOE_COPIES_PACKET_CHAINS#define PFW_OK_TERMINATE 2/* these should be moved to if_ether.h */#define ETHERTYPE_PPPOE_DISCOVERY 0x8863	/* Ethernet type for discovery*/#define ETHERTYPE_PPPOE_SESSION   0x8864	/* Ethernet type for session */#define ENET_LEN   6                    	/* Ethernet Address LEN */#define PPPOE_HDR_VERSION 0x1#define PPPOE_HDR_TYPE 0x1#define PPPOE_CODE_PADI 0x09	/* PPPoE Active Discovery Initiation */#define PPPOE_CODE_PADO 0x07	/* PPPoE Active Discovery Offer */#define PPPOE_CODE_PADR 0x19	/* PPPoE Active Discovery Request */#define PPPOE_CODE_PADS 0x65	/* PPPoE Active Discovery Session */#define PPPOE_CODE_PADT 0xa7	/* PPPoE Active Session Terminate */#define PPPOE_CODE_SESSION 0x00	/* PPPoE Session */#define PPPOE_SESSION_DISCOVERY 0x0000#define PPPOE_DISCOVERY_RETRIES 4 /* default number of discovery retries */#define PPPOE_STATE_PADI 0#define PPPOE_STATE_PADO 1#define PPPOE_STATE_PADR 2#define PPPOE_STATE_PADS 4#define PPPOE_STATE_SESSION 5#define PPPOE_MAX_PADI_SIZE 1484	/* size in bytes */#define PPPOE_TAG_EOL                  0x0	/* End of tag list */#define PPPOE_TAG_SVC_NAME             0x0101	/* service name tag */#define PPPOE_TAG_AC_NAME              0x0102	/* Access Concentrator name */#define PPPOE_TAG_HOST_UNIQ            0x0103	/* Host unique tag  */#define PPPOE_TAG_AC_COOKIE            0x0104	/* Access Concentrator cookie */#define PPPOE_TAG_VENDOR_INFO          0x0105	/* Vendor proprietary info */#define PPPOE_TAG_RELAY_SESSION_ID     0x0110	/* Relay session ID */#define PPPOE_TAG_SVC_NAME_ERROR       0x0201	/* BAD service name */#define PPPOE_TAG_AC_SYSTEM_ERROR      0x0202	/* AC encountered an error */#define PPPOE_RELAY_SESSION_ID_SIZE    12	/* Relay session ID tag size*/#define PPPOE_DEFAULT_AC_NAME "WindNetPPPoEAC"#define PPPOE_MAX_SESSIONS 0x10000     /* 16K */#define PPPOE_MIN_TIMEOUT 1	       /* one second */#define PPPOE_FREE_PKT netMblkClChainFree#define PPPOE_FREE_RECVD_PKT(p) \		    if ((p)->pRecvdDiscPkt != NULL) \			{\			PPPOE_FREE_PKT((p)->pRecvdDiscPkt); \			(p)->pRecvdDiscPkt = NULL; \			}#define PPPOE_FREE_RETRY_PKT(p) \		    if ((p)->pRetryDiscPkt != NULL) \			{\			PPPOE_FREE_PKT((p)->pRetryDiscPkt); \			(p)->pRetryDiscPkt = NULL; \			}#define PPPOE_STACK_ADD_DONE(state)\		{\		PPPOE_STACK_DATA * stack =(PPPOE_STACK_DATA *)state->stackData;\		\		if (stack->callbacks && stack->callbacks->stackAddComplete)\		    (*stack->callbacks->stackAddComplete)\					    (stack->callbacks,state);\		}#define PPPOE_STACK_ADD_ERROR(state)\		{\		PPPOE_STACK_DATA * stack =(PPPOE_STACK_DATA *)state->stackData;\		\		if (stack->callbacks && stack->callbacks->stackAddError)\		    (*stack->callbacks->stackAddError)\					    (stack->callbacks,state);\		}#define PPPOE_STACK_DELETE_DONE(state)\		{\		PPPOE_STACK_DATA * stack =(PPPOE_STACK_DATA *)state->stackData;\		\		if (stack->callbacks && stack->callbacks->stackDeleteComplete)\		    (*stack->callbacks->stackDeleteComplete)\					    (stack->callbacks,state);\		}#define ADAPTER_DEST_ADDR_AND_PROTOCOL_SET(stack,protocol) \	{\	UINT16 pppOEProtocol = protocol;\	ADAPTER_DESTINATION_AND_PROTOCOL_SET_INTERFACE * adapterInterface;\	\	if (stack->adapterInterface.interfaceObj && \					stack->adapterInterface.state) \	    { \	    adapterInterface = \		    (ADAPTER_DESTINATION_AND_PROTOCOL_SET_INTERFACE *) \				    stack->adapterInterface.interfaceObj; \	     \	    adapterInterface->destAddrAndProtocolSet(\				    stack->adapterInterface.state,\				    (char *)stack->destEnet,\				    ENET_LEN,\				    (char *)&pppOEProtocol,\				    sizeof(UINT16));\	    }\	}/* typedefs */typedef struct pppOEProfileData    {    UINT32  connectionMode;     /* mode bit flags; ACTIVE,PASSIVE etc. */    UINT8   discoveryRetries;   /* number of retries during discovery phase */    UINT8   minDiscTimeout;     /* number of retries during discovery phase */    char    svcNameTag[32];	/* Supported/Requested Service */    char    acNameTag[32];	/* Requested/Supported Access Concentrator */                                /* Name Tags */    char  vendorInfo[8]; 	/* Proprietary info if any */    } PPPOE_PROFILE_DATA;typedef struct pppOEStackData    {    SL_NODE node;                   /* used for HOST/CLIENT mode session list */    PFW_PLUGIN_OBJ_STATE *pfwState; /* pfw state this StackData belogs to*/    PFW_PROFILE_OBJ *profileObj;    /* for an AC we need this */    UINT32 connectionMode; 	        /* Mode for this connection */    UINT8  remPADIRetries;	        /* remaining PADI retries */    UINT8  remPADRRetries;	        /* remaining PADR retries */    PFW_TIMER_OBJ *pTimer;     	    /* Retry timer */    UINT32 state; 		            /* connection state */    BOOL   sendPADT;                /* send a PADT packet if TRUE */    UINT32 sessionId;		        /* PPPoE session ID */    UINT32 serviceMapId;	        /* set for Daemon AC connections */    char   serviceName[32];	        /* Service name for this connection */    char   acName[32];   	        /* Access Concentartor name */    UINT8  srcEnet[ENET_LEN];	    /* Source(my) ethernet address */    UINT8  destEnet[ENET_LEN];	    /* destination ethernet address */    UINT   inputOctets;             /* octets received */    UINT   outputOctets;            /* octets sent     */    UINT   inputPackets;            /* packets received */    UINT   outputPackets;           /* packets sent */    NET_POOL_ID netPoolId;          /* netPool to allocate packets from */    M_BLK_ID  pRecvdDiscPkt;	    /* Received Discovery Packet */    M_BLK_ID  pRetryDiscPkt;	    /* Discovery packet that must be re-sent */    PFW_PLUGIN_OBJ_STATE * more;    /* when session IDs from two ACs */				                    /* collide this points to the state of */				                    /* next one on the list */    void * userHandle;              /* installed during pppOEServiceNameAdd */    PFW_STACK_OBJ_CALLBACKS  * stackObjCallbacks; /* installed during                                                   * pppOEServiceNameAdd */    PFW_PLUGIN_OBJ_CALLBACKS * callbacks;/*framework add and delete callbacks */    PFW_INTERFACE_STATE_PAIR adapterInterface;    PFW_EVENT_OBJ * collectPppAttributesEvent;    PFW_EVENT_OBJ * pppSubordinateLayerDeadEvent;     BOOL lcpUpFlag;    ULONG portId;    /* auxiliary variables aiding RFC 2233 counters's implementation */    int pfwAuxIfId;    PFW_INTERFACE_STATE_PAIR pfwRFC2233CountPair;    BOOL pfwRFC2233CountTest;    } PPPOE_STACK_DATA;LOCAL STATUS pppOEFramingTypeHandler    (    PFW_PLUGIN_OBJ_STATE * state,    void *eventData    );/* Component data per instance; one per pfw */typedef struct pppOEComponent    {    PFW_COMPONENT_OBJ component;    BOOL pppOEnetInitialized;    UINT32 operatingMode;    int pppOESessions;    int pppOEMaxSessions;    int pppOEServices;    int pppOEMaxServices;    union	{	SL_LIST                 list; /* client's list of active sessions */#if 0	PFW_PLUGIN_OBJ_STATE ** map;  /* AC's map of sessionId to stack */#endif	} pppOESession2Stack;    PFW_PLUGIN_OBJ_STATE *  pppOELastReceivedSession; /* last received cache */    PFW_PLUGIN_OBJ_STATE ** pppOEServiceNameMap;    FRAMING_COMPONENT_STACK_RESOLVE_INTERFACE stackResolveInterface;    ADAPTER_COMPONENT_STATISTICS_INTERFACE statisticsInterface;    PHY_PORT_INTERFACE phyPortInterface;    } PPPOE_COMPONENT;typedef struct pppOEParams    {    char * name;    PFW_PARAMETER_HANDLER handler;    } PPPOE_PARAMS;typedef struct pppOEHeader    {#if _BYTE_ORDER == _LITTLE_ENDIAN    UINT8 pppOE_type:4,	        /* type */	  pppOE_ver:4;		/* version */#endif#if _BYTE_ORDER == _BIG_ENDIAN    UINT8 pppOE_ver:4,  	/* version */	  pppOE_type:4; 	/* type */#endif    UINT8    pppOE_code;  	/* code */    UINT16   pppOE_session;	/* session ID */    UINT16 pppOE_length;	/* payload length */    } _WRS_PACK_ALIGN(1)  PPPOE_HEADER;typedef struct pppOETLV    {    UINT16 tagType;    UINT16 tagLength;#ifdef COMMENT_ONLY    UINT8  tagValue[];#endif /* COMMENT_ONLY */    } _WRS_PACK_ALIGN(1)  PPPOE_TLV;#define PPPOE_TAG_TYPE(p) (UINT16)((*(UINT8 *)p << 8)|*(UINT8 *)((UINT8 *)p+1))#define PPPOE_TAG_LENGTH(p) (UINT16)((*((UINT8 *)&p->tagLength) << 8) |\				*(UINT8 *)(((UINT8 *)&p->tagLength)+1))#define PPPOE_TAG_TYPE_EOL(p)(PPPOE_TAG_TYPE(p) == PPPOE_TAG_EOL &&\						    PPPOE_TAG_LENGTH(p) == 0)#define SET_PPPOE_TAG_TYPE(p,t) \		    { \		    UINT8 * cp = (UINT8 *)p; \		    cp[0] = ((t & 0xff00) >> 8); \		    cp[1] = (t & 0xff);\		    }#define SET_PPPOE_TAG_LENGTH(p,l) \		    {\                    UINT16 temp = p->tagLength; \		    UINT8 * cp = (UINT8 *)&temp; \		    cp[0] = ((l & 0xff00) >> 8); \		    cp[1] = (l & 0xff);\                    p->tagLength = temp; \		    }#define PPPOE_TAG_VALUE(p) (char *)((char *)p + sizeof(PPPOE_TLV))#define PPPOE_TLV_SIZE(p) (UINT16)(sizeof(PPPOE_TLV)+PPPOE_TAG_LENGTH(p))#define PPPOE_NEXT_TLV(p) (PPPOE_TLV *)((char *)p + PPPOE_TLV_SIZE(p))#define PPPOE_VALID_TLV(p,f) ((char *)p < (f->mBlkHdr.mData + f->mBlkHdr.mLen))/* externs *//* globals */#ifdef PPP_DEBUGint pppOEDebug = 1;#endifLOCAL PFW_STACK_OBJ * pppOEStackObjResolve (PFW_PLUGIN_OBJ *, M_BLK_ID pFrame, ULONG portId);/* forward declarations */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -