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

📄 pppmuxadapter.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* pppMuxAdapter.c - MUX Adapter component for PPP over END devices *//* Copyright 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02e,10jun03,ijm use STACK_NAME to distinguish network stacks02d,14may03,ijm fixed diab compiler warning02c,29oct02,ijm use PPP_MUX_ADAPTER_MAX_BINDS, instead of muxMaxBinds,                for IPv4/IPv6 stack02b,27aug02,ijm fixed gnu warnings02a,20aug02,ijm fixed diab compiler warnings01z,15jul02,rp  rfc2233 counters not getting correctly updated SPR 7374601y,17jul02,ijm discontinue use of NET_PROTOCOL01x,15jul02,rp  multi-service support and muxCookie changes01w,12apr01,sj  added muxL2SvcType parameter01v,12mar01,ijm added mutual exclusion to slot selection in muxAdptrStackAdd                and muxAdptrStackDel01u,07mar01,ijm muxAdptrBindInfoFind should not increase bindInfo reference count01t,30jan01,sj  protocol may bind only once across all framework stacks              	if FRAMING_COMPONENT_STACK_RESOLVE interface is not provided01s,21dec00,sj  release state only if locked01r,20dec00,sj  on failure to lock state in RestartRtn delete node from list01q,17dec00,sj  add stacks to txBlockedList on END_ERR_BLOCKED01p,17dec00,sj  raise PPP_SUB_LAYER_TX_BLOCKED event on END_ERR_BLOCKED and                 undo blocked condition by raising PPP_SUB_LAYER_TX_UNBLOCKED01o,29sep00,sj  Merging in and reorganizing RFC2233 instrumentation01n,29sep00,sj  merging with TOR2_0-WINDNET_PPP-CUM_PATCH_201m,06sep00,cn   free dstAddr string in muxAdptrStackDataDestruct () SPR# 34219.01l,02aug00,adb  Merging in LAC modifications01k,01aug00,adb  Merging with openstack view except RFC 223301j,31jul00,md  initializes collectPppAttributesEvent01i,28jul00,md  initialize ppp attributes to a default value01h,11jul00,md  subscribed COLLECT_PPP_ATTRIBUTES_EVENT01g,10mar00,sj  interfaceReferenceDelete needs to be done only once01f,16nov99,sj  increment bindInfo refCount for each attempt to bind01e,14sep99,sj  adding events01d,12aug99,sj  reworked for generic framework; 01c,19jul99,sj  disabled loopback mode added macros for freeing packets01b,19jul99,sj  successfully tested PPPOE under loopback mode01a,02jul99,sj 	created*//*DESCRIPTIONThis component enables PPP sessions over END/NPT devices via the MUX. BeforePPP sessions over the END/NPT devices can be established, this adapter componentmust be added to the PPP framework.This component provides a generic interface to the MUX for the PPP frameworkto communicate via END/NPT devices in the system.INCLUDE FILES:  muxLib.h muxTkLib.h*/#include "vxWorks.h"#include "pfw/pfw.h"#include "logLib.h"#include "errnoLib.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "ctype.h"#include "memLib.h"#include "semLib.h"#include "sllLib.h"#include "inetLib.h"#include "hostLib.h"#include "end.h"#include "muxLib.h"#include "netBufLib.h"#include "private/muxLibP.h"#include "muxTkLib.h"#include "pfw/pfwStack.h"#include "pfw/pfwProfile.h"#include "pfw/pfwComponent.h"#include "pfw/pfwEvent.h"#include "pfw/pfwLayer.h"#include "pfw/pfwInterface.h"#include "pfw/pfwMemory.h"#include "ppp/kppp.h"#include "ppp/pppLacStructures.h"#include "ppp/pppMuxAdapter.h"#include "ppp/interfaces/framingComponentInterfaces.h"#include "ppp/interfaces/adapterComponentInterfaces.h"#include "ppp/interfaces/pppInterfacesGroupInterfaces.h"/* defines *//* max number of protocols per stack that this adapter has to deal with*/#define MAX_MUX_ADPTR_SERVICES 6#define MUX_FREE_PKT netMblkClChainFree#define MUX_STACK_ADD_DONE(state)\	{\	MUX_ADPTR_STACK_DATA * stack =(MUX_ADPTR_STACK_DATA *)state->stackData;\	\	if (stack->callbacks && stack->callbacks->stackAddComplete)\	    (*stack->callbacks->stackAddComplete) (stack->callbacks,state);\	}#define MUX_STACK_DELETE_DONE(state)\	{\	MUX_ADPTR_STACK_DATA * stack =(MUX_ADPTR_STACK_DATA *)state->stackData;\	\	if (stack->callbacks && stack->callbacks->stackDeleteComplete)\	    (*stack->callbacks->stackDeleteComplete) (stack->callbacks,state);\	}#define MUX_ADPTR_STACK_ADD_ERROR(state)\	{\	MUX_ADPTR_STACK_DATA * stack =(MUX_ADPTR_STACK_DATA *)state->stackData;\	\	if (stack->callbacks && stack->callbacks->stackAddError)\	    (*stack->callbacks->stackAddError)\				    (stack->callbacks,state);\	}/* typedefs */typedef struct muxAdptrBindInfo    {    int refCount;                              /* number of stacks using this */    void * cookie;		               /* binding instance handle */    PFW_INTERFACE_STATE_PAIR stackObjResolver; /* stack resolver data */    PFW_PLUGIN_OBJ * pluginObj;                /* reference to this component*/    SL_LIST          txBlockedList;            /* stacks blocked for send */    ULONG            portId;                   /* port id for adapterPortIdGet */    long             netSvcType;               /* network service type */    int              unitNo;                   /* unit number of the device */    char             devName[END_NAME_MAX];    /* device name */    } MUX_ADPTR_BIND_INFO;/* MUX adapter profile data */typedef struct muxAdptrProfileData    {    char muxDevName[END_NAME_MAX];    int muxDevUnit;    int muxNumSvcs;    UINT32 muxL2SvcType;    UINT32 muxSvcType[MAX_MUX_ADPTR_SERVICES];    } MUX_ADPTR_PROFILE_DATA;/* MUX adapter connection data */typedef struct muxAdptrStackData    {    SL_NODE node;           /* this is how we stay on txBlocked List */    MUX_ADPTR_BIND_INFO * bindInfoCache;/* bind info cache for currently */                                        /* sending protocol */    UINT32 nboProtocol;     /* protocol number in network byte order */    char * destAddr;        /* current send destination */    UINT32 destAddrLen;     /* current send destination add length*/    PFW_INTERFACE_STATE_PAIR resolverInterface; /* stack resolver data */    PFW_PLUGIN_OBJ_CALLBACKS * callbacks;    PFW_PLUGIN_OBJ_STATE * state; /* back pointer to state */    int bindInfoIndex[MAX_MUX_ADPTR_SERVICES]; /* bind info for each protocol */    BOOL            txBlocked; /* set when muxTkSend returns END_ERR_BLOCKED */    PFW_EVENT_OBJ *collectPppAttributesEvent;    PFW_EVENT_OBJ * txBlockedEvent;     PFW_EVENT_OBJ * txUnblockedEvent;     ULONG           portId;    /* auxiliary variables aiding RFC 2233 counters's implementation */    int    pfwAuxIfId;    PFW_INTERFACE_STATE_PAIR pfwRFC2233CountPair;    BOOL   pfwRFC2233CountTest;    } MUX_ADPTR_STACK_DATA;LOCAL STATUS muxPPPAttributesEventHandler    (    PFW_PLUGIN_OBJ_STATE * state,    void *eventData    );typedef struct muxAdptrParams    {    char * name;    PFW_PARAMETER_HANDLER handler;    } MUX_ADPTR_PARAMS;typedef struct muxAdptrComponent    {    PFW_COMPONENT_OBJ component;    int muxMaxBinds;    SEM_ID muxAdptrMutex;       MUX_ADPTR_BIND_INFO * bindInfo;    ADAPTER_DESTINATION_AND_PROTOCOL_SET_INTERFACE adapterInterface;    ADAPTER_INFO_GET_INTERFACE adapterInfoGetInterface;    }MUX_ADPTR_COMPONENT;/* externs */#if (!((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6)))IMPORT int muxMaxBinds; /* maximum number of binds configured in the system */#endif /* (!((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6))) *//* globals *//* forward declarations *//* component interface */LOCAL STATUS muxAdptrProfileDataConstruct (PFW_OBJ *,void *);LOCAL STATUS muxAdptrStackDataConstruct (PFW_OBJ *,void *stackData,							void * profileData);LOCAL STATUS muxAdptrStackDataDestruct (PFW_OBJ *, void *stackData,							void * profileData);LOCAL STATUS muxAdptrStackAdd(PFW_PLUGIN_OBJ_STATE*,PFW_PLUGIN_OBJ_CALLBACKS *);LOCAL STATUS muxAdptrStackDel (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS muxAdptrSend (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS muxAdptrStackDataShow (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS muxAdptrInterfaceBind (PFW_PLUGIN_OBJ *);/* paramter handlers */LOCAL STATUS muxAdptr_muxDevName(PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE,								void *, char *);LOCAL STATUS muxAdptr_muxDevUnit(PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE,								void *, char *);LOCAL STATUS muxAdptr_muxSvcType(PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE,								void *, char *);LOCAL STATUS muxAdptr_muxL2SvcType(PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE,								void *, char *);/* MUX NPT callback routines */LOCAL BOOL muxAdptrRecvRtn (void *, long, M_BLK_ID, void *);LOCAL STATUS muxAdptrShutdownRtn (void *);LOCAL STATUS muxAdptrTxRestartRtn (void *);LOCAL void muxAdptrErrorRtn (void *, END_ERR *);/* MUX END callback routines */LOCAL BOOL muxAdptrEndRecvRtn (void * cookie, long, M_BLK_ID, LL_HDR_INFO *,								void* pSpare);LOCAL STATUS muxAdptrEndShutdownRtn (void* cookie, void * pSpare);LOCAL STATUS muxAdptrEndTxRestartRtn  (void * cookie, void * pSpare);LOCAL void muxAdptrEndErrorRtn (END_OBJ * cookie, END_ERR *, void * pSpare);/* utilities */LOCAL int muxAdptrBindInfoFind (MUX_ADPTR_COMPONENT *,						char * devName, int unit,						int protocol);LOCAL STATUS muxAdptrBindInfoClear ( MUX_ADPTR_BIND_INFO *pBindInfo,				     MUX_ADPTR_STACK_DATA *pStackData);    /* interfaces */LOCAL STATUS destAddrAndProtocolSet			   (			    PFW_PLUGIN_OBJ_STATE *adapterState,			    char * destAddr,			    UINT32 addrLength,			    char * protocol,			    UINT32 protocolLength			   );LOCAL STATUS adapterPortIdGet                          (                          PFW_PLUGIN_OBJ_STATE * pAdapterState,                          ULONG *                pPortId                          );/* locals */LOCAL MUX_ADPTR_PARAMS muxAdptrParams[] = 			{{"muxDevName",muxAdptr_muxDevName},			 {"muxDevUnit",muxAdptr_muxDevUnit},		     {"muxL2SvcType",muxAdptr_muxL2SvcType},			 {"muxSvcType",muxAdptr_muxSvcType}};LOCAL int numMuxAdptrParams = NELEMENTS (muxAdptrParams);/******************************************************************************** muxAdapterCreate - add the MUX adapter component to the PPP framework** This function should be called to add the MUX adapter to the PPP framework* if PPP connections have to be established over END/NPT devices.* This adapter is a generic component which interfaces the PPP framework with* any END/NPT device in the system** RETURNS: OK on success and ERROR otherwise*/STATUS muxAdapterCreate    (    PFW_OBJ * pfw	/* framework we are adding ourselves to */    )    {    int i = 0;    MUX_ADPTR_COMPONENT *pComponent;    PFW_PLUGIN_OBJ * muxAdptrPluginObj = NULL;    int pppMuxMaxBinds;    if (pfw == NULL)	{        logMsg ("muAdapterCreate: Framework is NULL\n",                 1,2,3,4,5,6);	return ERROR;	}    /* allocate the component object */    if ( (pComponent = pfwMalloc(pfw,sizeof(MUX_ADPTR_COMPONENT))) == NULL)        {        logMsg ("muxAptrCreate: Could not malloc memory for MUX ADAPTER component\n",                 1,2,3,4,5,6);	return ERROR;        }    bzero((void *)pComponent,sizeof(MUX_ADPTR_COMPONENT));    if ((pComponent->muxAdptrMutex = semMCreate(SEM_Q_PRIORITY)) == NULL)        {        pfwFree (pComponent);        logMsg ("muxAptrCreate: Could not create semaphore for MUX ADAPTER component\n",                 1,2,3,4,5,6);        return ERROR;        }    muxAdptrPluginObj = (PFW_PLUGIN_OBJ *)&(pComponent->component);    /* initialize our component object */    bzero(muxAdptrPluginObj->name, PFW_MAX_NAME_LENGTH);    strncpy(muxAdptrPluginObj->name,"MUX_ADAPTER",	    (PFW_MAX_NAME_LENGTH -1));    muxAdptrPluginObj->pfwObj = pfw;    muxAdptrPluginObj->profileDataSize = sizeof (MUX_ADPTR_PROFILE_DATA);    muxAdptrPluginObj->stackDataSize = sizeof (MUX_ADPTR_STACK_DATA);    muxAdptrPluginObj->profileDataConstruct = muxAdptrProfileDataConstruct;    muxAdptrPluginObj->profileDataCopy = NULL;    muxAdptrPluginObj->profileDataDestruct = NULL;    muxAdptrPluginObj->stackDataConstruct = muxAdptrStackDataConstruct;    muxAdptrPluginObj->stackDataDestruct = muxAdptrStackDataDestruct;    muxAdptrPluginObj->interfaceBind = muxAdptrInterfaceBind;    muxAdptrPluginObj->receive = NULL;    muxAdptrPluginObj->send = muxAdptrSend;    muxAdptrPluginObj->stackAdd = muxAdptrStackAdd;    muxAdptrPluginObj->stackDelete = muxAdptrStackDel;    muxAdptrPluginObj->stackDataShow = muxAdptrStackDataShow;    pComponent->component.protocol = 0;    pComponent->component.layerObj = pfwLayerObjGet(pfw, "ADAPTER_LAYER");    /* register this component with the framework */    if (pfwComponentAdd (&pComponent->component) == ERROR)        {        logMsg ("muxAdapterCreate: Could not add MUX ADAPTER component\n",                 1,2,3,4,5,6);        semDelete (pComponent->muxAdptrMutex);        pfwFree (pComponent);        return (ERROR);        }    /* add our parameters to the framework */    for (i = 0; i < numMuxAdptrParams ; i++)	{        if (pfwParameterAdd ((PFW_PLUGIN_OBJ *)pComponent,			muxAdptrParams[i].name, muxAdptrParams[i].handler)			== ERROR)	    {	    logMsg ("muxAdapterCreate - Parameter %s could not be added\n",	    (int)muxAdptrParams[i].name,2,3,4,5,6);	    return (ERROR);	    }	}    /* allocate memory for the bindInfo Array */#if ((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6))    pppMuxMaxBinds = PPP_MUX_ADAPTER_MAX_BINDS;#else    pppMuxMaxBinds = muxMaxBinds;#endif /* ((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6)) */    if ((pComponent->bindInfo = (MUX_ADPTR_BIND_INFO *) pfwMalloc		(pfw,pppMuxMaxBinds * sizeof(MUX_ADPTR_BIND_INFO))) == NULL)        {        logMsg ("muxAdapterCreate: Could not malloc memory for bindInfo\n",                 1,2,3,4,5,6);	return ERROR;        }    bzero((void *)pComponent->bindInfo, 		pppMuxMaxBinds * sizeof(MUX_ADPTR_BIND_INFO));    pComponent->muxMaxBinds = pppMuxMaxBinds;    return OK;    }/******************************************************************************** muxAdapterDelete - delete the MUX adapter component from the framework** The MUX_ADAPTER plug-in component object allocated by muxAdapterCreate() is * freed if there are no references to this object from a * Stack or Profile object in the framework.** RETURNS: OK or ERROR*/STATUS muxAdapterDelete    (    PFW_OBJ * pfw	/* framework we are deleting this from */    )    {    PFW_COMPONENT_OBJ *pComponent;    MUX_ADPTR_COMPONENT * muxComponent;    pComponent = pfwComponentObjGetByName(pfw,"MUX_ADAPTER");    if (pComponent == NULL)	return ERROR;    if (pfwComponentDelete(pComponent) != OK)	return ERROR;    muxComponent = (MUX_ADPTR_COMPONENT *)pComponent;    pfwFree(muxComponent->bindInfo);    semDelete (muxComponent->muxAdptrMutex);    pfwFree(pComponent);    return OK;    }/******************************************************************************** muxAdptrProfileDataConstruct - initialize component parameter default values** This function is called by the framework to get default values for the* parameters managed and supported by this component** RETURNS: OK on success and ERROR otherwise*/LOCAL STATUS muxAdptrProfileDataConstruct    (    PFW_OBJ *pfw,    void * pProfileData 	/* reference to this component's profile data */    )    {    MUX_ADPTR_PROFILE_DATA * pMuxAdptrData = 					(MUX_ADPTR_PROFILE_DATA *)pProfileData;    /* start with a clean slate */    bzero ((void *)pMuxAdptrData, sizeof(MUX_ADPTR_PROFILE_DATA));    return OK;    }/******************************************************************************** muxAdptrStackDataDestruct - clean up stack data** This function is called by the framework at the time this component* is being removed from a stack for the purpose of cleaning up the stack Data* which includes freeing of any memory that may have been allocated** RETURNS: OK on success and ERROR otherwise

⌨️ 快捷键说明

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