📄 pppbitsyncframing.c
字号:
/* pppBitSyncFraming.c - PPP Bit-Synchronous HDLC Framing *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01q,28may02,rvr fixed build warnings (teamf1)01p,17dec01,mk added macros to correct alignment problems01o,12apr01,ijm First mbuf in the chain must have mBlkPktHdr info set. Corrected convertNormalDataToSynchronousData to handle zero-length mbufs within an mbuf chain01n,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 collectPppAttributesEvent01i,29jun00,md subscribed COLLECT_PPP_ATTRIBUTES_EVENT01h,17apr00,sj use length of frame as size for decoded frame buffer01g,07mar00,sj use/generate mBuf chains on receive path01f,02mar00,sj On the send path no ACCompression for LCP packets and get clusters on demand01e,23feb00,sj Pedantic ANSI fixes01d,14feb00,sj fixed 32 bit checksum on send path and added comments01c,02dec99,sj All new implementation of encoding and decoding01b,29nov99,sgv Added comments01a,06oct99,sgv Written*//*DESCRIPTIONThis component implements PPP Bit Synchronous HDLC framing as specified in RFC 1662. It resides in the framing layer of the framing plane.*//* includes */#include "vxWorks.h"#include "stdio.h"#include "logLib.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 "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/kstart.h"#include "ppp/kppp.h"#include "ppp/pppLacStructures.h"#include "ppp/pppChecksum.h"#include "private/ppp/vpppstr.h"#include "ppp/interfaces/lcpInterfaces.h"#include "ppp/interfaces/pppInterfacesGroupInterfaces.h"/* defines */#define PPP_ALLSTATIONS 0xFF#define PPP_UI 0x03 /* Unnumbered Information */#define PPP_UI 0x03 /* Unnumbered Information *//* typedefs */typedef struct bsyncFramingStackData { unsigned long localToPeerACCompression; unsigned long peerToLocalACCompression; unsigned long localToPeerProtocolCompression; unsigned long peerToLocalProtocolCompression; unsigned int localMru; unsigned int remoteMru; unsigned int transmitFcsSize; unsigned int receiveFcsSize; NET_POOL_ID netPoolId; u_int bytesSent; u_int bytesRcvd; u_int inputBytes; u_int inputErrors; u_int mru; u_int flags; PFW_PLUGIN_OBJ_CALLBACKS * callbacks; PFW_EVENT_OBJ * lcpUpEvent; 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; } BSYNC_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;/* LOCAL */LOCAL STATUS pppBitSyncSend (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS pppBitSyncReceive (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS pppBitSyncStackAdd (PFW_PLUGIN_OBJ_STATE *state, PFW_PLUGIN_OBJ_CALLBACKS * callbacks);LOCAL STATUS pppBitSyncStackDelete (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS pppBitSyncStackDataConstruct ( PFW_OBJ *, void * stackData, void * profileData);LOCAL STATUS convertNormalDataToSynchronousData (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID src, M_BLK_ID dst);LOCAL int convertSynchronousDataToNormalData (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID src, M_BLK_ID dst);LOCAL STATUS lcpUpEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData);LOCAL STATUS decompress_ppp_header ( PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID);LOCAL STATUS BitSyncFrameEventHandler ( PFW_PLUGIN_OBJ_STATE * state, void *eventData );/******************************************************************************** pppBitSyncFramingComponentCreate - create bit synchronous component** This routine creates the bit synchronous HDLC framing component plug-in* object and adds it to the framework.** RETURNS: OK or ERROR*/STATUS pppBitSyncFramingComponentCreate ( PFW_OBJ *pfw ) { PFW_COMPONENT_OBJ *pBsyncFramingComponent; pBsyncFramingComponent = (PFW_COMPONENT_OBJ *) pfwMalloc (pfw, sizeof (PFW_COMPONENT_OBJ)); if (pBsyncFramingComponent == NULL) { printf ("pppBsyncFramingInit - Unable to allocate memory of size %d \ byte s\n", (int) sizeof (PFW_COMPONENT_OBJ)); return (ERROR); } bzero ((void *)pBsyncFramingComponent, sizeof(PFW_COMPONENT_OBJ)); strcpy (pBsyncFramingComponent->pluginObj.name, "BITSYNC_FRAMING"); pBsyncFramingComponent->pluginObj.pfwObj = pfw; pBsyncFramingComponent->layerObj = pfwLayerObjGet (pfw, "FRAMING_LAYER"); pBsyncFramingComponent->pluginObj.profileDataSize = 0; pBsyncFramingComponent->pluginObj.stackDataSize = sizeof (BSYNC_FRAMING_STACK_DATA); pBsyncFramingComponent->protocol = 0; pBsyncFramingComponent->pluginObj.profileDataConstruct = NULL; pBsyncFramingComponent->pluginObj.profileDataCopy = NULL; pBsyncFramingComponent->pluginObj.profileDataDestruct = NULL; pBsyncFramingComponent->pluginObj.receive = pppBitSyncReceive; pBsyncFramingComponent->pluginObj.send = pppBitSyncSend; pBsyncFramingComponent->pluginObj.stackAdd = pppBitSyncStackAdd; pBsyncFramingComponent->pluginObj.stackDelete = pppBitSyncStackDelete; pBsyncFramingComponent->pluginObj.stackDataConstruct = pppBitSyncStackDataConstruct; pBsyncFramingComponent->pluginObj.stackDataDestruct = NULL; pBsyncFramingComponent->pluginObj.stackDataShow = NULL; if (pfwComponentAdd (pBsyncFramingComponent) == ERROR) { printf ( "pppBitSyncFramingComponentCreate - BitSync Framing could not be added to the framework\n"); return (ERROR); } return (OK); }/********************************************************************************* pppBitSyncFramingComponentDelete - delete the bit synchronous component ** The bit synchronous framing plug-in component object allocated by * pppBitSyncFramingComponentCreate() is freed if there are no references * to this object from a stack or profile object in the framework.** RETURNS: OK or ERROR*/STATUS pppBitSyncFramingComponentDelete ( PFW_OBJ *pfw ) { PFW_COMPONENT_OBJ *pComponent; pComponent = pfwComponentObjGetByName (pfw, "BITSYNC_FRAMING"); if (pComponent == NULL) return ERROR; if (pfwComponentDelete (pComponent) == OK) { pfwFree (pComponent); return OK; } return (ERROR); }/******************************************************************************** pppBitSyncStackDataConstruct -*/LOCAL STATUS pppBitSyncStackDataConstruct ( PFW_OBJ * pfw, void * stackData, void * profileData ) { BSYNC_FRAMING_STACK_DATA *pStackData = (BSYNC_FRAMING_STACK_DATA *)stackData; if ((pStackData->netPoolId = pfwNetPoolIdGet(pfw)) == NULL) { printf("BitSync 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; /* default to 16 bit FCS */ pStackData->transmitFcsSize = PPP_16BIT_FCS; pStackData->receiveFcsSize = PPP_16BIT_FCS; /* Address control and protocol compression is disabled by default */ pStackData->localToPeerACCompression = FALSE; pStackData->peerToLocalACCompression = FALSE; pStackData->localToPeerProtocolCompression = FALSE; pStackData->peerToLocalProtocolCompression = FALSE; return (OK); }/******************************************************************************** pppBitSyncStackAdd -*/LOCAL STATUS pppBitSyncStackAdd ( PFW_PLUGIN_OBJ_STATE *state, PFW_PLUGIN_OBJ_CALLBACKS * callbacks ) { BSYNC_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, BitSyncFrameEventHandler); } } /* get LCP UP event object and subcribe to it*/ if ((stackData->lcpUpEvent = pfwEventObjGet(state->pluginObj->pfwObj,"LCP_UP_EVENT")) != NULL) { pfwEventStackSubscribe(state,stackData->lcpUpEvent, lcpUpEventHandler); } 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); /* stackAdd done */ if (stackData->callbacks && stackData->callbacks->stackAddComplete) { (*stackData->callbacks->stackAddComplete) (stackData->callbacks, state); return OK; } else return ERROR; }/******************************************************************************** pppBitSyncStackDelete -*/LOCAL STATUS pppBitSyncStackDelete ( PFW_PLUGIN_OBJ_STATE *state ) { BSYNC_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; }/******************************************************************************** lcpUpEventHandler -*/LOCAL STATUS lcpUpEventHandler ( PFW_PLUGIN_OBJ_STATE * state, void *eventData ) { PFW_PLUGIN_OBJ_STATE * lcpState = (PFW_PLUGIN_OBJ_STATE * )eventData; BSYNC_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->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); return OK;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -