📄 mpframinglayer.c
字号:
/* mpFramingLayer.c - MP Framing Layer source file *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01m,03mar03,ijm in mpFramingLayerReceive, free packet if pfwReceive returns ERROR, SPR# 8614801l,30jan03,ijm fix for SPR# 86001, cannot re-establish bundle if peer does not end connection gracefully01k,28jan03,ijm removed redundant netMblkClChainFree in mpFraminglayerSend 01j,26oct02,ijm subscribed to PPP_LINK_RESET_EVENT instead of MP_LINK_DOWN01i,06aug02,jr fixed build warnings 01h,18apr02,ak replaced LCP_DOWN event with MP_LINK_DOWN event01g,23feb02,jr setting the pointers to NULL after freeing01f,19feb01,ak input parameter validation in all the functions01e,19dec01,ak support for dynamic assignment of Member Stack to Manager Stack 01d,17oct01,ak deleting component semaphore in mpFramingLayerDelete()01c,19sep01,ak fixed bug in deleting the MpSendQTask and MpReceiveQTask01b,23mar01,sd added profile handler function for mpFramingLayer_localUsername01a,20feb01,sd created*//*DESCRIPTIONThis module implements the MP_FRAMING_LAYER component. It implements the standard plug-in object functions in accordance with theWindNet PPP architecture.This component implements Multilink Point to Point protocol. It is implemented as an operational layer, but with no components in it.It is placed as the upper most layer in the framing plane and this layer is included only in Manager Stack. It implements packetType () function for de-multiplexing control and data packets. This pluginObj does not have any profile parameters.It subscribes for LCP_UP / PPP_LINK_RESET and PPP_AUTH_SUCCESSFUL / PPP_AUTH_UNSUCCESSFUL events. It raises MEMBER_LINK_ADDED and MEMBER_LINK_REMOVED events.INCLUDES: mp.h mpFramingLayerP.h mpFramingLayer.h*//* includes */#include "taskLib.h"#include "netBufLib.h"#include "ppp/mp.h"#include "private/ppp/mpFramingLayerP.h"#include "ppp/pppFramingLayer.h"#include "string.h"#include "ppp/kppp.h"#include "ppp/mpAPI.h"#include "stdio.h"/* typedefs */typedef struct mpFramingLayerParams { char * name; PFW_PARAMETER_HANDLER handler; } MP_FRAMING_LAYER_PARAMS;/* externs */IMPORT STATUS mpSendQueueCreate (MP_FRAMING_LAYER *, unsigned int);IMPORT STATUS mpReceiveQueueCreate (MP_FRAMING_LAYER *, unsigned int);IMPORT void mpSendQueueDelete (MP_FRAMING_LAYER *);IMPORT void mpReceiveQueueDelete (MP_FRAMING_LAYER *);IMPORT void mpSendTask (MP_FRAMING_LAYER *);IMPORT void mpReceiveTask (MP_FRAMING_LAYER *);IMPORT void reassemble_and_dispatch_mp_packet (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *, M_BLK_ID ); IMPORT STATUS mp_send_ppp_packet (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID , PFW_PACKET_TYPE);IMPORT STATUS mpLinkAssign (PFW_STACK_OBJ *, PFW_STACK_OBJ *);IMPORT PFW_STACK_OBJ * mp_open_bundle_or_add_to_the_existing_bundle (PFW_PLUGIN_OBJ_STATE *, MP_UPCALL_FUNCTIONS *, void *); IMPORT STATUS mp_remove_port_from_bundle (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *);IMPORT SL_LIST * mpBAPLinkInfoListGet (PFW_PLUGIN_OBJ_STATE *);/* locals and forwards */LOCAL STATUS mpFramingLayerReceive (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *, M_BLK_ID );/* layer component interface */LOCAL STATUS mpFramingLayerProfileDataConstruct (PFW_OBJ *, void * pProfileData);LOCAL STATUS mpFramingLayerStackAdd (PFW_PLUGIN_OBJ_STATE *, PFW_PLUGIN_OBJ_CALLBACKS *);LOCAL STATUS mpFramingLayerStackDelete (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS mpFramingLayerSend (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS mpFramingLayerStackDataConstruct (PFW_OBJ *, void * stackData, void * profileData);LOCAL STATUS mpFramingLayerInterfaceBind (PFW_PLUGIN_OBJ * pluginObj);LOCAL PFW_PACKET_TYPE mpFramingLayerPacketType (void *);/* parameter handlers */LOCAL STATUS mpFraming_smallPacketLength (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS mpFraming_localUserName (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS mpFraming_disableAuthOnBundle (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL MP_FRAMING_LAYER_PARAMS mpFramingLayerParams[] = { {"mpFraming_smallPacketLength", mpFraming_smallPacketLength}, {"mpFraming_localUserName", mpFraming_localUserName}, {"mpFraming_disableAuthOnBundle", mpFraming_disableAuthOnBundle}, }; LOCAL int numMpFramingLayerParams = NELEMENTS (mpFramingLayerParams);/* event handlers */LOCAL STATUS mpFramingLayerLcpUpEventHandler (PFW_PLUGIN_OBJ_STATE *, void *);LOCAL STATUS mpFramingLayerMpLinkDownEventHandler (PFW_PLUGIN_OBJ_STATE *, void *);#if 0 /* not supported in this release */LOCAL STATUS mpFramingLayerLcpEchoReplyReceivedEventHandler (PFW_PLUGIN_OBJ_STATE *, void *);#endif/******************************************************************************** mpFramingLayerCreate - create MP_FRAMING_LAYER component* * This routine creates the MP_FRAMING_LAYER. It initializes the PFW_PLUGIN_OBJ * data structure representing the MP_FRAMING_LAYER component. It registers the * component with the framework. It adds the plugin object specific configuration* parameters and adds the component to the framework. It creates send and * receive queues, if the queue depths are valid and also publishes the events* MP_MEMBER_ADDED and MP_MEMBER_DROPPED. ** RETURNS: OK/ERROR*/STATUS mpFramingLayerCreate ( PFW_OBJ * pfw, /* framework reference */ UINT mpSendQueueDepth, /* depth of send queue */ UINT mpReceiveQueueDepth, /* depth of receive queue */ UINT mpSendTaskPriority, /* priority of send task */ UINT mpReceiveTaskPriority /* priority of receive task */ ) { MP_FRAMING_LAYER *pMpFramingLayer = NULL; PFW_LAYER_OBJ *pLayerObj = NULL; UINT loopCount = 0; if (pfw == NULL) { pfwPrintError (__FILE__, "mpFramingLayerCreate", __LINE__, 0, 0, \ "NULL Framework reference"); return ERROR; } /* allocate memory for the MP Framing layer object */ if ((pMpFramingLayer = pfwMalloc (pfw, sizeof (MP_FRAMING_LAYER))) == NULL) { pfwPrintError (__FILE__, "mpFramingLayerInit", __LINE__, pfw, 0, \ "Unable to allocate memory"); return (ERROR); } bzero ((void*) pMpFramingLayer, sizeof(MP_FRAMING_LAYER)); /* initialize the MP Framing Layer Plugin Object functions */ pLayerObj = &pMpFramingLayer->layer; strcpy (pLayerObj->pluginObj.name, "MP_FRAMING_LAYER"); pLayerObj->pluginObj.profileDataSize = sizeof (MP_FRAMING_LAYER_PROFILE_DATA); pLayerObj->pluginObj.stackDataSize = sizeof (MP_FRAMING_LAYER_STACK_DATA); pLayerObj->pluginObj.profileDataConstruct = mpFramingLayerProfileDataConstruct; pLayerObj->pluginObj.profileDataCopy = NULL; pLayerObj->pluginObj.profileDataDestruct = NULL; pLayerObj->pluginObj.stackDataConstruct = mpFramingLayerStackDataConstruct; pLayerObj->pluginObj.stackDataDestruct = NULL; pLayerObj->pluginObj.stackAdd = mpFramingLayerStackAdd; pLayerObj->pluginObj.stackDelete = mpFramingLayerStackDelete; pLayerObj->pluginObj.stackDataShow = NULL; pLayerObj->pluginObj.send = mpFramingLayerSend; pLayerObj->pluginObj.receive = NULL; pLayerObj->pluginObj.interfaceBind = mpFramingLayerInterfaceBind; pLayerObj->pluginObj.pfwObj = pfw; /* initialize the MP Framing layer, layer obj members */ pLayerObj->planeId = FRAMING_PLANE; pLayerObj->position = 3; pLayerObj->type = OPERATIONAL_LAYER; pLayerObj->packetType = mpFramingLayerPacketType; pLayerObj->componentAdd = NULL; pLayerObj->componentDelete = NULL; pLayerObj->addDynamicComponentToStack = NULL; pLayerObj->deleteDynamicComponentFromStack = NULL; /* add the MP Framing Layer to the Framework */ if (pfwLayerAdd ( pLayerObj) == ERROR) { pfwPrintError (__FILE__, "mpFramingLayerCreate", __LINE__, pfw,0, \ "MP framing layer could not be added to the stack"); return (ERROR); } /* add configurable parameters to the framework */ for (loopCount = 0; loopCount < numMpFramingLayerParams; loopCount++) { if (pfwParameterAdd ((PFW_PLUGIN_OBJ *)pLayerObj, mpFramingLayerParams [loopCount].name, mpFramingLayerParams [loopCount].handler) == ERROR) { pfwPrintError (__FILE__, "mpFramingLayerCreate", __LINE__, pfw,0, \ "Error in registering a profile parameter"); return (ERROR); } } /* create a semaphore for the send queue */ if ((pMpFramingLayer->sendSem = semBCreate (SEM_Q_PRIORITY, SEM_EMPTY)) == NULL) { pfwPrintError (__FILE__, "mpFraminglayerCreate", __LINE__, pfw, NULL, \ "Unable to create the send task semaphore"); return ERROR; } /* start the send queue task */ if (mpSendQueueDepth > 0) { mpSendQueueCreate (pMpFramingLayer, mpSendQueueDepth); if ((pMpFramingLayer->mpSendQTaskId = taskSpawn ("tMpSendQ", mpSendTaskPriority, VX_FP_TASK | VX_DEALLOC_STACK, 0x4000, (FUNCPTR) mpSendTask, (int) pMpFramingLayer, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == ERROR) { pfwPrintError (__FILE__, "mpFraminglayerCreate", __LINE__, pfw, \ NULL, "Spawning MP send task failed"); return ERROR; } } /* create a semaphore for the receive queue */ if ((pMpFramingLayer->receiveSem = semBCreate (SEM_Q_PRIORITY, SEM_EMPTY)) == NULL) { pfwPrintError (__FILE__, "mpFraminglayerCreate", __LINE__, pfw, NULL, \ "Unable to create the receive task semaphore"); return ERROR; } /* start the receive queue task */ if (mpReceiveQueueDepth > 0) { mpReceiveQueueCreate (pMpFramingLayer, mpReceiveQueueDepth); if ((pMpFramingLayer->mpReceiveQTaskId = taskSpawn ("tMpRxQ", mpReceiveTaskPriority, VX_FP_TASK | VX_DEALLOC_STACK, 0x4000, (FUNCPTR) mpReceiveTask, (int) pMpFramingLayer, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == ERROR) { pfwPrintError (__FILE__, "mpFraminglayerCreate", __LINE__, pfw, \ NULL, "Spawning MP receive task failed"); return ERROR; } } /* Create the component semaphore */ pMpFramingLayer->componentSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); /* publish the events that we will Raise */ if (pfwEventPublish (pfw, "MP_MEMBER_ADDED_EVENT") == NULL) return ERROR; if (pfwEventPublish (pfw, "MP_MEMBER_DROPPED_EVENT") == NULL) return ERROR; if (pfwEventPublish (pfw, "MP_BUNDLE_CLOSED_EVENT") == NULL) return ERROR; if (pfwEventPublish (pfw, "MP_BUNDLE_OPENED_EVENT") == NULL) return ERROR; return OK; }/******************************************************************************** mpFramingLayerDelete - delete the MP_FRAMING_LAYER component.** This function is called with the framework object to delete the * MP_FRAMING_LAYER component from the framework. The plug-in component object * allocated by mpFramingLayerCreate () is freed if there are no references to * this object from a Stack or Profile object in the framework.** RETURNS: OK/ERROR*/STATUS mpFramingLayerDelete ( PFW_OBJ *pfw /* framework reference */ ) { PFW_LAYER_OBJ * pLayerObj = NULL; PFW_PLUGIN_OBJ * pluginObj = NULL; MP_FRAMING_LAYER * mpFramingComponent = NULL; if (pfw == NULL) return ERROR; pluginObj = pfwPluginObjGet (pfw, "MP_FRAMING_LAYER"); mpFramingComponent = (MP_FRAMING_LAYER *) pluginObj; taskDelete (mpFramingComponent->mpSendQTaskId); taskDelete (mpFramingComponent->mpReceiveQTaskId); semDelete (mpFramingComponent->sendSem); semDelete (mpFramingComponent->receiveSem); mpSendQueueDelete (mpFramingComponent); mpReceiveQueueDelete (mpFramingComponent); semDelete (mpFramingComponent->componentSem); pLayerObj = pfwLayerObjGet (pfw, "MP_FRAMING_LAYER"); if (pLayerObj == NULL) return ERROR; /* delete the layer */ if (pfwLayerDelete (pLayerObj) == OK) { pfwFree (pLayerObj); pLayerObj = NULL; return OK; } return ERROR; }/******************************************************************************** mpFramingLayerStackDataConstruct - called by the framework to initialize the * stack data** This function is called when a stack is created to initialize the stack data * of the MP_FRAMING_LAYER component. This function initializes the * mpFramingStackData structure. The structure members are set to their initial * values. ** RETURNS: OK/ERROR*/LOCAL STATUS mpFramingLayerStackDataConstruct ( PFW_OBJ * pfw, /* the framework object */ void * stackData, /* pointer to stackData */ void * profileData /* pointer to profileData */ ) { MP_FRAMING_LAYER_STACK_DATA * pStackData = (MP_FRAMING_LAYER_STACK_DATA *) stackData; if ((pfw == NULL) || (stackData == NULL) || (profileData == NULL)) return ERROR; bzero ((void *)pStackData, sizeof (MP_FRAMING_LAYER_STACK_DATA)); /* get the network pool id */ if ((pStackData->netPoolId = pfwNetPoolIdGet (pfw)) == NULL) return ERROR; /* initialze the stack data members */ pStackData->bundle_state = MP_BUNDLE_CLOSED_STATE; /* assign the event objects */ if ((pStackData->pMpBundleClosedEventObj = pfwEventObjGet (pfw, "MP_BUNDLE_CLOSED_EVENT")) == NULL) { pfwPrintError (__FILE__, "mpFramingLayerStackDataConstruct", __LINE__, \ pfw, NULL, "Failed to get MP_BUNDLE_CLOSED_EVENT event obj"); return ERROR; } if ((pStackData->pMpBundleOpenedEventObj = pfwEventObjGet (pfw, "MP_BUNDLE_OPENED_EVENT")) == NULL) { pfwPrintError (__FILE__, "mpFramingLayerStackDataConstruct", __LINE__, \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -