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

📄 pppasyncframing.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* pppAsyncFraming.c - PPP Asynchronous HDLC Framing *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01w,07oct02,ijm increment bad address,bad control and packet too long counters,                SPR#8171301v,04oct02,ijm subscribe to PPP_LINK_RESET_EVENT, SPR# 8236901u,25jun02,rp  adding missed multilink patch 2 changes01t,28may02,rvr fixed build warnings 01s,01may02,as  avoided memcopy in the decompress_ppp_header to access the                 protocol id for arm fixes01r,17dec01,mk  added macros to correct alignment problems01q,16apr01,ijm corrected mBlkPktHdr settings01p,17dec00,ihw support checksum bytes across cluster boundaries on recvd frames01o,20nov00,ihw when looking at previous bytes for detecting occurences of             	duplicate escape sequences, mind cluster boundaries-Ian Willats01n,29sep00,sj  Merging in and reorganizing RFC2233 instrumentation01m,29sep00,sj  merging with TOR2_0-WINDNET_PPP-CUM_PATCH_201l,02aug00,adb  Merging in LAC modifications01k,01aug00,adb  Merging with openstack view except RFC 223301j,31jul00,md  initializes collectPppAttributesEvent01j,30jun00,md                  fix prototype error01i,29jun00,md  subscribed COLLECT_PPP_ATTRIBUTES_EVENT01h,17apr00,sj  use length of frame as size for decoded frame buffer01g,16mar00,cn  updated documentation.01f,07mar00,sj  use/generate mBuf chains on receive path01e,02mar00,sj  On the send path no ACCompression for LCP packets and get              	clusters on demand01d,23feb00,sj  Pedandic ANSI fixes01c,15feb00,cn  Modified send and receive routines to allow for chained		mBlks, also defaulted to 16-bit checksum in 		pppAsyncFramingStackDataConstruct ().01b,11nov99,sgv Modified to the latest framework01a,12sep99.sgv Derived from routerware PPP codebase*//*DESCRIPTIONThis component implements PPP Asynchronous HDLC framing as specified in RFC 1662. It resides in the framing layer of the framing plane.*/#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "ctype.h"#include "memLib.h"#include "inetLib.h"#include "hostLib.h"#include "netBufLib.h"#include "ioLib.h"#include "logLib.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwComponent.h"#include "pfw/pfwTimer.h"#include "pfw/pfwLayer.h"#include "pfw/pfwEvent.h"#include "pfw/pfwInterface.h"#include "pfw/pfwMemory.h"#include "ppp/kppp.h"#include "ppp/pppLacStructures.h"#include "private/ppp/vpppstr.h"#include "ppp/pppAsyncFramingComponent.h"#include "ppp/interfaces/lcpInterfaces.h"#include "ppp/interfaces/pppInterfacesGroupInterfaces.h"#include "ppp/pppChecksum.h"/* defines */#define PPP_ALLSTATIONS 0xFF#define PPP_UI          0x03    /* Unnumbered Information */#define PPP_HDRLEN      4       /* sizeof(struct ppp_header) must be 4 *//* typedefs */typedef struct asyncFramingStackData    {    unsigned long localToPeerACCompression;    unsigned long peerToLocalACCompression;    unsigned long localToPeerProtocolCompression;    unsigned long peerToLocalProtocolCompression;    unsigned long localToPeerACCMap;    unsigned long peerToLocalACCMap;    unsigned  int localMru;    unsigned  int remoteMru;    unsigned  int transmitFcsSize;    unsigned  int receiveFcsSize;    BOOL          frameCheckSequenceEnabled;    NET_POOL_ID   netPoolId;    unsigned  int bytesSent;    unsigned  int bytesRcvd;    unsigned  int inputBytes;    unsigned  int inputErrors;    unsigned  int mru;    unsigned  int flags;    PFW_PLUGIN_OBJ_CALLBACKS    * callbacks;    PFW_EVENT_OBJ * lcpUpEvent;    PFW_EVENT_OBJ * pppLinkResetEvent;    PFW_INTERFACE_STATE_PAIR pppLinkStatusInterface;    PFW_INTERFACE_STATE_PAIR pppLinkCounterInterface;    PFW_EVENT_OBJ *collectPppAttributesEvent;    /* auxiliary variables aiding RFC 2233 counters's implementation */    int            pfwAuxIfId;    PFW_INTERFACE_STATE_PAIR pfwRFC2233CountPair;    BOOL           pfwRFC2233CountTest;    } ASYNC_FRAMING_STACK_DATA;typedef struct _PPP_HEADER    {    BYTE                             hdlc_address;    BYTE_ENUM (LLC_FRAME_TYPE)       hdlc_control;    USHORT_ENUM (PPP_PROTOCOL_TYPE)  protocol_type;    }_WRS_PACK_ALIGN(1) _PPP_HEADER;typedef struct _PPP_PACKET    {    _PPP_HEADER                   header;    BYTE_ENUM (PPP_CONTROL_CODE)  code;    BYTE                          id;    USHORT                        length;    BYTE                          data[VARIABLE_NUMBER_OF_BYTES];    }_WRS_PACK_ALIGN(1) _PPP_PACKET;#if     _BYTE_ORDER==_BIG_ENDIAN#define BIG_ENDIAN_CONSTANT(ushort) ushort#else   /* Little Endian */#define BIG_ENDIAN_CONSTANT(ushort) (((0x00ff & ushort) << 8) | (ushort >> 8))#endif  /* _BYTE_ORDER==_BIG_ENDIAN *//* defines */#define PARAMETER_NUMBER_SERIAL 1LOCAL STATUS pppAsyncFramingSend (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS pppAsyncFramingReceive (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS pppAsyncFramingStackAdd (PFW_PLUGIN_OBJ_STATE *, 	PFW_PLUGIN_OBJ_CALLBACKS * callbacks);LOCAL STATUS pppAsyncFramingStackDelete (PFW_PLUGIN_OBJ_STATE *);LOCAL BOOL encode_byte (ULONG *async_control_character_map, 	BYTE byte_to_encode);LOCAL STATUS convertNormalDataToAsynchronousData (PFW_PLUGIN_OBJ_STATE *state,						 M_BLK_ID srcPacket,						 M_BLK_ID destPacket);LOCAL STATUS convertAsynchronousDataToNormalData (PFW_PLUGIN_OBJ_STATE *state,						 M_BLK_ID inFrame,						 M_BLK_ID outPacket);LOCAL STATUS decompress_ppp_header (PFW_PLUGIN_OBJ_STATE *state,    	M_BLK_ID packet);LOCAL STATUS pppAsyncFramingStackDataConstruct (PFW_OBJ *,void * stackData,void * profileData);LOCAL STATUS pppAsyncFramingLcpUpEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); LOCAL STATUS pppAsyncFramingLinkResetEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData);LOCAL STATUS AsyncFrameEventHandler    (    PFW_PLUGIN_OBJ_STATE * state,    void *eventData    );/******************************************************************************** pppAsyncFramingComponentCreate - create the asynchronous framing component ** This routine creates the asynchronous HDLC framing component plugin object* and adds it to the specified framework.** RETURNS: OK or ERROR*/STATUS pppAsyncFramingComponentCreate    (    PFW_OBJ *pfw    )    {    PFW_COMPONENT_OBJ *pAsyncFramingComponent;    pAsyncFramingComponent = (PFW_COMPONENT_OBJ *) pfwMalloc (pfw,                                                sizeof (PFW_COMPONENT_OBJ));    if (pAsyncFramingComponent == NULL)        {        printf ("pppAsyncFramingInit - Unable to allocate memory of size %d \		 bytes\n", (int) sizeof (PFW_COMPONENT_OBJ));        return (ERROR);        }    bzero ((void *)pAsyncFramingComponent, sizeof (PFW_COMPONENT_OBJ));    strcpy (pAsyncFramingComponent->pluginObj.name, "ASYNC_FRAMING");    pAsyncFramingComponent->pluginObj.pfwObj = pfw;    pAsyncFramingComponent->layerObj = pfwLayerObjGet (pfw, "FRAMING_LAYER");    pAsyncFramingComponent->pluginObj.profileDataSize =  0;    pAsyncFramingComponent->pluginObj.stackDataSize = 					sizeof (ASYNC_FRAMING_STACK_DATA);    pAsyncFramingComponent->protocol = 0;    pAsyncFramingComponent->pluginObj.profileDataConstruct  = NULL;    pAsyncFramingComponent->pluginObj.profileDataCopy = NULL;    pAsyncFramingComponent->pluginObj.profileDataDestruct = NULL;    pAsyncFramingComponent->pluginObj.receive = pppAsyncFramingReceive;    pAsyncFramingComponent->pluginObj.send = pppAsyncFramingSend;    pAsyncFramingComponent->pluginObj.stackAdd = pppAsyncFramingStackAdd;    pAsyncFramingComponent->pluginObj.stackDelete = pppAsyncFramingStackDelete;    pAsyncFramingComponent->pluginObj.stackDataConstruct = 				      pppAsyncFramingStackDataConstruct;    pAsyncFramingComponent->pluginObj.stackDataDestruct = NULL;    pAsyncFramingComponent->pluginObj.stackDataShow = NULL;    if (pfwComponentAdd (pAsyncFramingComponent) == ERROR)        {        printf("pppAsyncInit  Async Driver cannot be added to the framework\n");        return (ERROR);        }    return (OK);    }/********************************************************************************* pppAsyncFramingComponentDelete - delete the asynchronous framing component ** The asynchronous framing plug-in component object allocated by * pppAsyncFramingComponentCreate(), is freed if there are no references * to this object from a stack or profile object in the specified framework.** RETURNS: OK or ERROR*/STATUS pppAsyncFramingComponentDelete    (    PFW_OBJ *pfw    )    {    PFW_COMPONENT_OBJ *pComponent;    pComponent = pfwComponentObjGetByName (pfw, "ASYNC_FRAMING");    if (pComponent == NULL)        return ERROR;    if (pfwComponentDelete (pComponent) == OK)        {        pfwFree (pComponent);        return OK;        }    return (ERROR);    }/********************************************************************************* pppAsyncFramingStackDataConstruct - construct the stack data for the framework** RETURNS: OK or ERROR*/LOCAL STATUS pppAsyncFramingStackDataConstruct    (    PFW_OBJ * pfw,    void * stackData,    void * profileData    )    {    ASYNC_FRAMING_STACK_DATA *pStackData = 				(ASYNC_FRAMING_STACK_DATA *)stackData;    if ((pStackData->netPoolId = pfwNetPoolIdGet(pfw)) == NULL)        {        printf("Async Framing:MUST have a valid NetPoolId;See pfwCreate()\n");        return ERROR;        }        pStackData->collectPppAttributesEvent = NULL;    pStackData->localMru = 1500;    pStackData->remoteMru = 1500;    pStackData->flags = 0;    pStackData->inputBytes = 0;    pStackData->frameCheckSequenceEnabled  =  TRUE;    pStackData->localToPeerACCMap  = DEFAULT_ASYNC_CONTROL_CHARACTER_MAP;    pStackData->peerToLocalACCMap  = DEFAULT_ASYNC_CONTROL_CHARACTER_MAP;    /* Address control and protocol compression is disabled by default */    pStackData->localToPeerACCompression = FALSE;    pStackData->peerToLocalACCompression = FALSE;    pStackData->localToPeerProtocolCompression = FALSE;    pStackData->peerToLocalProtocolCompression = FALSE;    pStackData->transmitFcsSize = PPP_16BIT_FCS;    pStackData->receiveFcsSize = PPP_16BIT_FCS;    return (OK);    }/********************************************************************************* pppAsyncFramingStackAdd - add the stack data to the framework** RETURNS: OK or ERROR*/LOCAL STATUS pppAsyncFramingStackAdd    (    PFW_PLUGIN_OBJ_STATE *state,    PFW_PLUGIN_OBJ_CALLBACKS * callbacks    )    {    ASYNC_FRAMING_STACK_DATA *stackData = state->stackData;    int id;    stackData->callbacks = callbacks;    if (stackData->collectPppAttributesEvent == NULL)	{	if ((stackData->collectPppAttributesEvent =	    pfwEventObjGet(state->pluginObj->pfwObj,                           "COLLECT_PPP_ATTRIBUTES_EVENT")) != NULL)            {	    pfwEventStackSubscribe(state,stackData->collectPppAttributesEvent,                                   AsyncFrameEventHandler);	    }        }    /* get LCP UP event object and subcribe to it*/    if ((stackData->lcpUpEvent = 	    pfwEventObjGet(state->pluginObj->pfwObj,"LCP_UP_EVENT")) != NULL)	{	pfwEventStackSubscribe(state,stackData->lcpUpEvent, 			       pppAsyncFramingLcpUpEventHandler);	}    else	return ERROR;    /* get PPP LINK_RESET event object and subcribe to it*/    if ((stackData->pppLinkResetEvent =            pfwEventObjGet(state->pluginObj->pfwObj,"PPP_LINK_RESET_EVENT")) != NULL)        {        pfwEventStackSubscribe(state,stackData->pppLinkResetEvent,                               pppAsyncFramingLinkResetEventHandler);        }    else        return ERROR;    /* get LCP interfaces */    if ((id = pfwInterfaceIdGet(state->pluginObj->pfwObj,			"PPP_LINK_STATUS_ENTRY_INTERFACE")) > 0)	{	if (pfwInterfaceObjAndStateGetViaStackObj(state->stackObj,				id, &stackData->pppLinkStatusInterface) != OK)	    return ERROR;	}    else	return ERROR;    if ((id = pfwInterfaceIdGet(state->pluginObj->pfwObj,			"PPP_LINK_STATUS_COUNTER_INCREMENT_INTERFACE")) > 0)	{	if (pfwInterfaceObjAndStateGetViaStackObj(state->stackObj,				id, &stackData->pppLinkCounterInterface) != OK)	    return ERROR;	}    /* Get pfwRFC2233CountPair and set pfwRFC2233CountTest */    RFC2233_COUNT_PAIR_GET(state,                            stackData->pfwAuxIfId,                            stackData->pfwRFC2233CountPair, 			   stackData->pfwRFC2233CountTest);    /* Allocate a buffer for input processing */      if (stackData->callbacks && stackData->callbacks->stackAddComplete)        {        (*stackData->callbacks->stackAddComplete) (stackData->callbacks, state);	return OK;        }    else        return ERROR;    }/********************************************************************************* pppAsyncFramingStackDelete - delete the stack data from the framework** RETURNS: OK or ERROR*/LOCAL STATUS pppAsyncFramingStackDelete    (    PFW_PLUGIN_OBJ_STATE *state    )    {    ASYNC_FRAMING_STACK_DATA *stackData = state->stackData;    /* Delete the LCP LinkStatus Interface reference */    pfwInterfaceReferenceDelete (		stackData->pppLinkStatusInterface.interfaceObj);    /* Delete the LCP LinkCounter Interface reference */    pfwInterfaceReferenceDelete (		stackData->pppLinkCounterInterface.interfaceObj);    if (stackData->pfwRFC2233CountTest)       pfwInterfaceReferenceDelete(stackData->pfwRFC2233CountPair.interfaceObj);    if (stackData->callbacks && stackData->callbacks->stackDeleteComplete)        {        (*stackData->callbacks->stackDeleteComplete)                                    (stackData->callbacks , state);	return OK;        }    else        return ERROR;    }/********************************************************************************* pppAsyncFramingLcpUpEventHandler - handle LCP events** RETURNS: OK or ERROR*/LOCAL STATUS pppAsyncFramingLcpUpEventHandler    (    PFW_PLUGIN_OBJ_STATE * state,    void *eventData    )    {    PFW_PLUGIN_OBJ_STATE * lcpState = (PFW_PLUGIN_OBJ_STATE * )eventData;    ASYNC_FRAMING_STACK_DATA *stackData = state->stackData;    PPP_LINK_STATUS_ENTRY_INTERFACE * linkStatus = 		    (PPP_LINK_STATUS_ENTRY_INTERFACE *)				stackData->pppLinkStatusInterface.interfaceObj;    stackData->localMru = (*linkStatus->pppLinkStatusLocalMRUGet)(lcpState);    stackData->remoteMru = (*linkStatus->pppLinkStatusRemoteMRUGet)(lcpState);    stackData->localToPeerACCMap =		(*linkStatus->pppLinkStatusLocalToPeerACCMapGet)(lcpState);    stackData->peerToLocalACCMap = 		(*linkStatus->pppLinkStatusPeerToLocalACCMapGet)(lcpState);    stackData->localToPeerProtocolCompression =      (*linkStatus->pppLinkStatusLocalToRemoteProtocolCompressionGet)(lcpState);    stackData->peerToLocalProtocolCompression =       (*linkStatus->pppLinkStatusRemoteToLocalProtocolCompressionGet)(lcpState);    stackData->localToPeerACCompression = 	   (*linkStatus->pppLinkStatusLocalToRemoteACCompressionGet) (lcpState);    stackData->peerToLocalACCompression = 	    (*linkStatus->pppLinkStatusRemoteToLocalACCompressionGet)(lcpState);    stackData->transmitFcsSize = 		(*linkStatus->pppLinkStatusTransmitFcsSizeGet)(lcpState);    stackData->receiveFcsSize =		(*linkStatus->pppLinkStatusReceiveFcsSizeGet) (lcpState);

⌨️ 快捷键说明

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