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

📄 pppoethernet.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* component interface */LOCAL STATUS pppOEProfileDataConstruct (PFW_OBJ *,void * pProfileData);LOCAL STATUS pppOEStackDataConstruct (PFW_OBJ *,void * pStackData,							    void *profileData);LOCAL STATUS pppOEStackDataDestruct (PFW_OBJ *,void * pStackData,							    void * profileData);LOCAL STATUS pppOEInterfaceBind (PFW_PLUGIN_OBJ *);LOCAL STATUS pppOEStackAdd (PFW_PLUGIN_OBJ_STATE *,PFW_PLUGIN_OBJ_CALLBACKS *);LOCAL STATUS pppOEStackDel (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS pppOEReceive (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS pppOESend (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS pppOEStackShow (PFW_PLUGIN_OBJ_STATE *);    /* parameter handlers */LOCAL STATUS pppOE_connectionMode(PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE,void *,				    char *);LOCAL STATUS pppOE_discoveryRetries(PFW_OBJ*,PFW_PARAMETER_OPERATION_TYPE,void *				    ,char *);LOCAL STATUS pppOE_minDiscTimeout(PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE,void *,				    char *);LOCAL STATUS pppOE_svcName(PFW_OBJ*,PFW_PARAMETER_OPERATION_TYPE,void *,char *);LOCAL STATUS pppOE_acName(PFW_OBJ*,PFW_PARAMETER_OPERATION_TYPE,void *, char *);LOCAL STATUS pppOE_vendorInfo(PFW_OBJ *,PFW_PARAMETER_OPERATION_TYPE,void *,				    char *);    /* misc */LOCAL M_BLK_ID pppOEMakePADI (PFW_PLUGIN_OBJ_STATE *);LOCAL M_BLK_ID pppOEMakePADR (PFW_PLUGIN_OBJ_STATE *);LOCAL M_BLK_ID pppOEMakePADO (PFW_PLUGIN_OBJ_STATE *);LOCAL M_BLK_ID pppOEMakePADS (PFW_PLUGIN_OBJ_STATE *);LOCAL M_BLK_ID pppOEMakePADT (PFW_PLUGIN_OBJ_STATE *);LOCAL M_BLK_ID pppOEAddHeader(UINT8, UINT16, UINT8 *, M_BLK_ID); LOCAL M_BLK_ID pppOEAddSvcNameError ( PFW_PLUGIN_OBJ_STATE *pComponentState);LOCAL STATUS pppOESendDiscPkt (PFW_PLUGIN_OBJ_STATE *, int );LOCAL M_BLK_ID pppOEDupPkt (M_BLK_ID pPacket);LOCAL STATUS lcpOpenEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); LOCAL STATUS lcpUpEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); LOCAL STATUS lcpDownEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); LOCAL PPPOE_TLV * pppOEFindTlv (UINT16 tagType, PPPOE_TLV * firstTlv,M_BLK_ID);LOCAL PFW_STACK_OBJ * pppOESvcStackObjGet(PPPOE_COMPONENT *,PPPOE_TLV *svcName, ULONG portId);LOCAL PFW_STACK_OBJ * pppOEStackObjGet(PPPOE_COMPONENT *, UINT16, UINT8 *);LOCAL STATUS pppOEMapStackId(UINT16 sessionId, PFW_PLUGIN_OBJ_STATE *);LOCAL void pppOEStackIdMapClear(PFW_PLUGIN_OBJ_STATE *);#if 0LOCAL STATUS etherAsciiToEnet (char * asciiAddr, u_char * retEnet);#endifLOCAL STATUS etherEnetToAscii (UINT8 * pEnetAddr, char * pAsciiBuf);LOCAL void pppOEAdptrStatisticsGet (PFW_PLUGIN_OBJ_STATE *,                                  UINT *, UINT *, UINT *, UINT *);LOCAL UINT pppOEAdptrPortNumberGet (PFW_PLUGIN_OBJ_STATE *);LOCAL UINT pppOEAdptrPortTypeGet  (PFW_PLUGIN_OBJ_STATE *);LOCAL int pppOEGetAllServiceNameTagsButThis (	    PFW_PLUGIN_OBJ_STATE * thisStackState, PPPOE_TLV ** ppTlv);LOCAL STATUS pppOEVerifyACCookie(PPPOE_COMPONENT *pComponent,                                  PFW_STACK_OBJ *stackObj);/* locals *//* component parameters; basically members of PPPOE_PROFILE_PARAMS struct */LOCAL PPPOE_PARAMS pppOEParams[]={{"pppOE_connectionMode",pppOE_connectionMode},                                  {"pppOE_discRetries", pppOE_discoveryRetries},                                  {"pppOE_minDiscTimeout",pppOE_minDiscTimeout},                                  {"pppOE_svcName", pppOE_svcName},                                  {"pppOE_acName", pppOE_acName},                                  {"pppOE_vendorInfo", pppOE_vendorInfo}};LOCAL int numPPPOEParams = NELEMENTS (pppOEParams);LOCAL UINT8 etherBroadcastAddr[] = {0xff,0xff,0xff,0xff,0xff,0xff};/******************************************************************************** pppOEthernetCreate - create and add PPP over Ethernet component to framework** This routine initializes and adds the PPP over Ethernet component to the PPP* framework. This component implements RFC 2516.** RETURNS: OK on success and ERROR otherwise*/STATUS pppOEthernetCreate    (    PFW_OBJ * pfw,	  /* pfw we are adding ourselves to */    UINT32 maxServices,	  /* maximum number of services we support as an AC */    UINT32 operatingMode  /* operating modes: HOST or AC */    )    {    int i = 0;    PPPOE_COMPONENT * pComponent;    PFW_PLUGIN_OBJ * pPPPOEPluginObj;    if (pfw == NULL)	{	return ERROR;	}    /* allocate the component object */    if ( (pComponent = pfwMalloc(pfw,sizeof(PPPOE_COMPONENT))) == NULL)	return ERROR;    bzero((void *)pComponent,sizeof(PPPOE_COMPONENT));    pPPPOEPluginObj = (PFW_PLUGIN_OBJ *)&(pComponent->component);    /* initialize our component object */    bzero(pPPPOEPluginObj->name, PFW_MAX_NAME_LENGTH);    strncpy(pPPPOEPluginObj->name,"PPP_O_ETHERNET",(PFW_MAX_NAME_LENGTH -1));    pPPPOEPluginObj->pfwObj = pfw;    pPPPOEPluginObj->profileDataSize = sizeof (PPPOE_PROFILE_DATA);    pPPPOEPluginObj->stackDataSize = sizeof (PPPOE_STACK_DATA);    pPPPOEPluginObj->profileDataConstruct = pppOEProfileDataConstruct;    pPPPOEPluginObj->profileDataCopy = NULL;    pPPPOEPluginObj->profileDataDestruct = NULL;    pPPPOEPluginObj->stackDataConstruct = pppOEStackDataConstruct;    pPPPOEPluginObj->stackDataDestruct = pppOEStackDataDestruct;    pPPPOEPluginObj->interfaceBind = pppOEInterfaceBind;    pPPPOEPluginObj->receive = pppOEReceive;    pPPPOEPluginObj->send = pppOESend;    pPPPOEPluginObj->stackDataShow = pppOEStackShow;    pPPPOEPluginObj->stackAdd = pppOEStackAdd;    pPPPOEPluginObj->stackDelete = pppOEStackDel;    pComponent->component.protocol = 0;    pComponent->component.layerObj = pfwLayerObjGet(pfw,"FRAMING_LAYER");    /* register this component with the framework */    if (pfwComponentAdd (&pComponent->component) == ERROR)	{	printf ("pppOEthernetInit: Couldn't add PPPOE component to pfw 0x%x\n"	, (UINT32) pfw);	pfwFree((void *)pComponent);	return (ERROR);	}    /* add our parameters to the framework */    for (i = 0; i < numPPPOEParams; i++)	{	if (pfwParameterAdd ((PFW_PLUGIN_OBJ *)pComponent,			    pppOEParams[i].name, pppOEParams[i].handler)			    == ERROR)	    {	    printf ("pppOEthernetInit - Parameter %s could not be added\n",	    pppOEParams[i].name);	    pfwComponentDelete(&pComponent->component);	    pfwFree((void *)pComponent);	    return (ERROR);	    }	}    pComponent->pppOESessions = 0;    pComponent->pppOEMaxSessions = 0;    pComponent->pppOEMaxServices = 0;    pComponent->pppOEServices = 0;    pComponent->operatingMode = operatingMode;    /*     * allocate memory for the MAP;     * If configured to be in AC mode allocate 0x40000 bytes of memory for the     * MAP     *     * if configured to be in HOST initialize the list of sessions      */     if (operatingMode == PPPOE_HOST_MODE)	 {	 sllInit(&pComponent->pppOESession2Stack.list);	 return OK;	 }     else if (operatingMode != PPPOE_AC_MODE)	 {	 printf("PPPOE: Illegal mode:%x;Must be either HOST(0x%x) OR AC(0x%x)\n"			     ,operatingMode, PPPOE_HOST_MODE, PPPOE_AC_MODE);	 pfwComponentDelete(&pComponent->component);	 pfwFree((void *)pComponent);	 return ERROR;	 }     /* complete AC mode initialization */	 sllInit(&pComponent->pppOESession2Stack.list);    pComponent->pppOEMaxSessions = PPPOE_MAX_SESSIONS;    /* allocate memory for services offered by this component as an AC */     if (pComponent->pppOEServiceNameMap == NULL)	 pComponent->pppOEServiceNameMap = (PFW_PLUGIN_OBJ_STATE **)pfwMalloc			 (pfw,(maxServices+1) * sizeof(PFW_PLUGIN_OBJ_STATE *));     if (pComponent->pppOEServiceNameMap == NULL)	 {	 printf ("pppOEthernetInit - could not allocate Service Name MAP\n");	 return ERROR;	 }     else	 bzero ((void *)pComponent->pppOEServiceNameMap,			     maxServices * sizeof(PFW_PLUGIN_OBJ_STATE *));    pComponent->pppOEMaxServices = maxServices;    if  (NULL == pfwEventPublish(pfw, "PPP_SUB_LAYER_DEAD_EVENT"))        return(ERROR);    return OK;    }/******************************************************************************** pppOEthernetDelete - delete PPPoE component from the specified framework** This routine deletes the PPPoE component from the framework** The PPPoE plug-in component object allocated by pppOEthernetCreate() is * freed if there are no references to this object from a * Stack or Profile object in the framework.** RETURNS: OK or ERROR*/STATUS pppOEthernetDelete    (    PFW_OBJ * pfw	  /* framework we are removing ourselves from */    )    {    PFW_COMPONENT_OBJ *pComponent;    PPPOE_COMPONENT *pppOEComponent;    pComponent = pfwComponentObjGetByName (pfw,"PPP_O_ETHERNET");    if (pComponent == NULL)	return ERROR;    if (pfwComponentDelete(pComponent) != OK)	return ERROR;    pppOEComponent = (PPPOE_COMPONENT *) pComponent;    if (pppOEComponent->operatingMode == PPPOE_AC_MODE)	{	pfwFree(pppOEComponent->pppOEServiceNameMap);	}    pfwFree(pComponent);    return OK;    }/******************************************************************************** pppOEInterfaceBind - bind our interfaces here*/LOCAL STATUS pppOEInterfaceBind    (    PFW_PLUGIN_OBJ * pluginObj    )    {    PPPOE_COMPONENT * pComponent = (PPPOE_COMPONENT *)pluginObj;    ADAPTER_COMPONENT_STATISTICS_INTERFACE * statisticsInterface;    PHY_PORT_INTERFACE * phyPortInterface;    PFW_OBJ * pfw = pluginObj->pfwObj;    unsigned int id;    /* publish and bind our adapter component statistics interface */    if ((id = pfwInterfaceRegister(pfw,                      "ADAPTER_COMPONENT_STATISTICS_INTERFACE")) > 0)        {        statisticsInterface = &pComponent->statisticsInterface;        statisticsInterface->interfaceObj.id = id;        statisticsInterface->interfaceObj.pluginObj = pluginObj;        statisticsInterface->statisticsGet = pppOEAdptrStatisticsGet;        pfwInterfaceBind (&statisticsInterface->interfaceObj);        }    /* publish and bind our physical port interface */    if ((id = pfwInterfaceRegister(pfw, "PHY_PORT_INTERFACE")) > 0)        {        phyPortInterface = &pComponent->phyPortInterface;        phyPortInterface->interfaceObj.id = id;        phyPortInterface->interfaceObj.pluginObj = pluginObj;        phyPortInterface->portNumberGet = pppOEAdptrPortNumberGet;        phyPortInterface->portTypeGet = pppOEAdptrPortTypeGet;        pfwInterfaceBind (&phyPortInterface->interfaceObj);        }    /*      * first register our interfaces; Note that registration could have been     * done during pppOEthernetInit as well     */    if ((id = pfwInterfaceRegister (pfw,                        "FRAMING_COMPONENT_STACK_RESOLVE_INTERFACE")) == 0)        {        printf("PPPOE: Could not Register FRAMING_STACK_RESOLVE_INTERFACE\n");        return ERROR;        }    /* bind the interface */    pComponent->stackResolveInterface.interfaceObj.pluginObj = pluginObj;    pComponent->stackResolveInterface.interfaceObj.id = id;    pComponent->stackResolveInterface.stackResolve = pppOEStackObjResolve;    return (pfwInterfaceBind (&pComponent->stackResolveInterface.interfaceObj));    }/********************************************************************************* pppOEServiceNameAdd - add a service name and listen for service requests** This routine installs a service with the specified "svcName" by creating* a stack based on the given profileObj. This stack listens for clients * requesting the specified service. For every session assigned a new stack * is created using the same profileObj. Specifying a zero length string* implies that any service is acceptable** NOTE: Care must be taken to avoid changing the profileObj in a manner that* will disable creation of stacks by the daemon stack ** RETURNS: OK on success and ERROR otherwise*/STATUS pppOEServiceNameAdd    (    PFW_PROFILE_OBJ * profileObj,        /* profile this service is based on */    char * svcName,      	         /* service name we're adding */    PFW_STACK_OBJ_CALLBACKS *callbacks,  /* stack add/delete callbacks */    void * userHandle                	 /* callback handle */    )    {    PFW_OBJ * pfw;    PFW_STACK_OBJ * stackObj = 0;    PFW_PLUGIN_OBJ_STATE * pComponentState = NULL;    PPPOE_STACK_DATA * pStackData =  NULL;    PPPOE_PROFILE_DATA * pProfileData =  NULL;    UINT32 paramId;    PPPOE_COMPONENT *pComponent;    char paramValue[32];    int i;    if (profileObj == NULL)	{	printf ("PPPOE: Null profile object \n");	return ERROR;	}    if ((pfw = pfwProfilePfwObjGet(profileObj)) == NULL)	{	printf ("PPPOE: Null framework object \n");	return ERROR;	}    /* retrieve our object from the framework */    pComponent =(PPPOE_COMPONENT *)pfwPluginObjGet(pfw,"PPP_O_ETHERNET");    if (pComponent == NULL)	{	printf ("PPPOE: Null plugin object \n");	return ERROR;	}    if (pComponent->operatingMode != PPPOE_AC_MODE)	return ERROR;    bzero(paramValue,32);    if (pComponent->pppOEServices < pComponent->pppOEMaxServices)	{	/* find room for the new service in the table and add it */	for (i = 1 ; i <= pComponent->pppOEMaxServices ; i++)	    {	    if (pComponent->pppOEServiceNameMap[i] == NULL)		{		/* make sure PROFILE has connection mode set to AC */		paramId = pfwParameterIdGet(pfw, "pppOE_connectionMode");		sprintf (paramValue,"0x%x",PPPOE_AC_MODE);		pfwProfileSet(profileObj, paramId, paramValue);		paramId = pfwParameterIdGet(pfw, "pppOE_svcName");		pfwProfileSet(profileObj,paramId, svcName);		if ((stackObj =pfwStackAdd(profileObj,callbacks,userHandle))		    == NULL)		    {		    printf("PPPOE: Stack add failed for service Name %s\n",			    svcName);		    return ERROR;		    }		pComponentState = pfwPluginObjStateGet (stackObj,					(PFW_PLUGIN_OBJ *)pComponent);		if (pComponentState == NULL)		    {		    /* delete connection */		    return (pfwStackDelete(stackObj));		    }		pStackData = (PPPOE_STACK_DATA *)pComponentState->stackData;		pStackData->serviceMapId = i;		pStackData->profileObj = profileObj;

⌨️ 快捷键说明

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