📄 pppinterfacelayer.c
字号:
/* pppInterfaceLayer.c - PPP Interface Layer Source File *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01n,26nov02,ijm add check for protocol = 0 in interfaceLayerReceive01m,01nov02,ijm remove redundant check in interfaceLayerReceive01l,03nov01,ijm delete iflProtocolItems when END is deleted, SPR#6987101k,28feb01,ijm release interfaces when stack is deleted (SPR #63868)01j,26oct00,sj remove annoying accepted protos printf01i,20mar00,sj added description01h,01mar00,sj use LCP_PACKET_SEND_INTERFACE to reject packets01g,23feb00,sj Pedantic ANSI fixes01f,22feb00,sj added missing updates to lastDeletedComponent01e,18feb00,sj removing debug messages01d,29oct99,sgv modified to latest version of framework01c,23aug99,sgv modified for generic framework01b,12jul99,koz included new framework header files and updated interfaces accordingly01a,07jul99,koz created.*//*DESCRIPTIONThis module implements the PPP Interface Layer in the data plane.*//* includes */#include "stdio.h"#include "stdlib.h"#include "string.h"#include "vxWorks.h"#include "logLib.h"#include "netBufLib.h"#include "ppp/kstart.h"#include "ppp/kppp.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwLayer.h"#include "pfw/pfwMemory.h"#include "ppp/pppInterfaceLayer.h"#include "ppp/interfaces/componentAcceptableProtocolsInterface.h"#include "ppp/interfaces/lcpInterfaces.h"#include "sllLib.h"/* defines *//* typedefs */typedef struct iflProtocolItem { struct iflProtocolItem *next; PFW_PLUGIN_OBJ_STATE *state; ACCEPTABLE_PROTOCOLS_ARRAY *acceptableProtocols; } IFL_PROTOCOL_ITEM;typedef struct InterfaceLayerStackData { SL_LIST recvAcceptableProtocols; SL_LIST sendAcceptableProtocols; PFW_INTERFACE_STATE_PAIR lcpPacketSend; PFW_PLUGIN_OBJ_CALLBACKS componentCallbacks; PFW_PLUGIN_OBJ_CALLBACKS * callbacks; PFW_PLUGIN_OBJ_STATE * lastAddedComponent; PFW_PLUGIN_OBJ_STATE * lastDeletedComponent; } INTERFACE_LAYER_STACK_DATA;/* locals */LOCAL STATUS interfaceLayerReceive ( PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID *packet);LOCAL STATUS interfaceLayerStackAdd ( PFW_PLUGIN_OBJ_STATE *state, PFW_PLUGIN_OBJ_CALLBACKS * callbacks);LOCAL STATUS interfaceLayerStackDelete ( PFW_PLUGIN_OBJ_STATE *state);LOCAL STATUS interfaceLayerStackDataConstruct ( PFW_OBJ * pfw, void * stackData, void * profileData);LOCAL STATUS interfaceLayerStackDataDestruct ( PFW_OBJ * pfw, void * stackData, void * profileData);LOCAL void componentStackAddDone (PFW_PLUGIN_OBJ_CALLBACKS *, PFW_PLUGIN_OBJ_STATE *componentState);LOCAL void componentStackDelDone (PFW_PLUGIN_OBJ_CALLBACKS *, PFW_PLUGIN_OBJ_STATE *componentState);LOCAL STATUS componentAdd (PFW_COMPONENT_OBJ *);LOCAL BOOLEAN iflProtocolItemFree ( IFL_PROTOCOL_ITEM * iflProtocolItem, int arg);/* forwards *//********************************************************************************* pppInterfaceLayerCreate - initialize the ppp interface layer** This routine is called to initialize the ppp interface layer. The interface * layer populates a layer object and adds itself to the ppp stack by calling * pfwLayerAdd routine.** RETURNS: OK or ERROR**/STATUS pppInterfaceLayerCreate ( PFW_OBJ *pfw ) { PFW_LAYER_OBJ *pInterfaceLayer; pInterfaceLayer = (PFW_LAYER_OBJ *) pfwMalloc (pfw, sizeof (PFW_LAYER_OBJ)); if (pInterfaceLayer == NULL) { printf ("pppInterfaceLayerInit Unable to allocate memory\n"); return (ERROR); } bzero ((void *)pInterfaceLayer, sizeof (PFW_LAYER_OBJ)); strcpy(pInterfaceLayer->pluginObj.name, "INTERFACE_LAYER"); pInterfaceLayer->pluginObj.pfwObj = pfw; pInterfaceLayer->pluginObj.profileDataSize = 0; pInterfaceLayer->pluginObj.stackDataSize = sizeof (INTERFACE_LAYER_STACK_DATA); pInterfaceLayer->pluginObj.stackDataConstruct = interfaceLayerStackDataConstruct; pInterfaceLayer->pluginObj.stackDataDestruct = interfaceLayerStackDataDestruct; pInterfaceLayer->pluginObj.profileDataConstruct = NULL; pInterfaceLayer->pluginObj.profileDataDestruct = NULL; pInterfaceLayer->pluginObj.profileDataCopy = NULL; pInterfaceLayer->planeId = DATA_PLANE; pInterfaceLayer->position = 2; pInterfaceLayer->type = OPERATIONAL_LAYER; pInterfaceLayer->componentAdd = componentAdd; pInterfaceLayer->componentDelete = NULL; pInterfaceLayer->pluginObj.stackAdd = interfaceLayerStackAdd; pInterfaceLayer->pluginObj.stackDelete = interfaceLayerStackDelete; pInterfaceLayer->pluginObj.receive = interfaceLayerReceive; pInterfaceLayer->pluginObj.send = NULL; pInterfaceLayer->addDynamicComponentToStack = NULL; pInterfaceLayer->deleteDynamicComponentFromStack = NULL; if (pfwLayerAdd (pInterfaceLayer) == ERROR) { printf ("pppInterfaceLayerInit Interface layer could not be added to the\ stack\n"); return (ERROR); } return (OK); }/********************************************************************************* pppInterfaceLayerDelete - delete the ppp interface layer** This routine is called to delete the ppp interface layer. The interface* layer deletes the layer object from the ppp stack by calling the* pfwLayerDelete function.** RETURNS: OK or ERROR*/STATUS pppInterfaceLayerDelete ( PFW_OBJ *pfw ) { PFW_LAYER_OBJ *pInterfaceLayer; pInterfaceLayer = (PFW_LAYER_OBJ *)pfwLayerObjGet (pfw, "INTERFACE_LAYER"); if (pInterfaceLayer == NULL) return ERROR; if (pfwLayerDelete (pInterfaceLayer) == OK) { pfwFree (pInterfaceLayer); return OK; } return (ERROR); }LOCAL STATUS componentAdd ( PFW_COMPONENT_OBJ *obj ) { return (OK); } /********************************************************************************* interfaceLayerStackDataConstruct -**/LOCAL STATUS interfaceLayerStackDataConstruct ( PFW_OBJ * pfw, void * stackData, void * profileData ) { INTERFACE_LAYER_STACK_DATA *pStackData = (INTERFACE_LAYER_STACK_DATA *)stackData; sllInit ((SL_LIST *)&pStackData->recvAcceptableProtocols); sllInit ((SL_LIST *)&pStackData->sendAcceptableProtocols); pStackData->componentCallbacks.stackAddComplete = componentStackAddDone; pStackData->componentCallbacks.stackDeleteComplete = componentStackDelDone; return (OK); }/******************************************************************************** interfaceLayerStackDataDestruct -*/LOCAL STATUS interfaceLayerStackDataDestruct ( PFW_OBJ * pfw, void * stackData, void * profileData ) { INTERFACE_LAYER_STACK_DATA * pStackData = (INTERFACE_LAYER_STACK_DATA * )stackData; sllEach ((SL_LIST *)&pStackData->recvAcceptableProtocols, iflProtocolItemFree, 0); sllEach ((SL_LIST *)&pStackData->sendAcceptableProtocols, iflProtocolItemFree, 0); return OK; }/********************************************************************************* interfaceLayerStackDelete -*/LOCAL STATUS interfaceLayerStackDelete ( PFW_PLUGIN_OBJ_STATE *state ) { PFW_PLUGIN_OBJ_STATE * componentState; INTERFACE_LAYER_STACK_DATA *pStackData = (INTERFACE_LAYER_STACK_DATA *)state->stackData; if ((componentState = pfwFirstComponentStateGet (state)) == NULL) { pfwPrintError (__FILE__, "stackDelete", __LINE__,0,state->stackObj, "Interface Layer Null component"); return (ERROR); } pStackData->lastDeletedComponent = componentState; return ((*componentState->pluginObj->stackDelete)(componentState)); }/********************************************************************************* interfaceLayerReceive -*/LOCAL STATUS interfaceLayerReceive ( PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID *packet ) { IFL_PROTOCOL_ITEM * iflProtocolItem = NULL; PFW_COMPONENT_OBJ * componentObj; int i; struct mbuf *m; BOOL found = FALSE; USHORT protocol = 0; INTERFACE_LAYER_STACK_DATA *pStackData = (INTERFACE_LAYER_STACK_DATA *)state->stackData; LCP_PACKET_SEND_INTERFACE * lcpPacketSendInterface = (LCP_PACKET_SEND_INTERFACE *) pStackData->lcpPacketSend.interfaceObj; m = (struct mbuf *)*packet; /* Get the protocol id from the packet */ protocol = ((m->m_data[0]&0xff) << 8) + (m->m_data[1]&0xff); iflProtocolItem = (IFL_PROTOCOL_ITEM *) SLL_FIRST(&pStackData->recvAcceptableProtocols); while (iflProtocolItem != NULL) { componentObj = (PFW_COMPONENT_OBJ *)iflProtocolItem->state->pluginObj; for (i = 0; i < iflProtocolItem->acceptableProtocols->numberOfProtocols; i++) { if (iflProtocolItem->acceptableProtocols->protocols[i] == protocol) { found = TRUE; break; } } if (!found) iflProtocolItem = (IFL_PROTOCOL_ITEM *)SLL_NEXT(iflProtocolItem); else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -