📄 pppcontrollayer.c
字号:
if (controlLayer == NULL) { pfwPrintError (__FILE__, "pppControlLayerInit", __LINE__, pfw,0, "Unable to allocate memory"); return (ERROR); } memset((void *)controlLayer,0,sizeof(CONTROL_LAYER_OBJ)); pControlLayer = &controlLayer->layer; strcpy (pControlLayer->pluginObj.name, "CONTROL_LAYER"); pControlLayer->pluginObj.pfwObj = pfw; pControlLayer->pluginObj.profileDataSize = sizeof(CONTROL_LAYER_PROFILE_DATA); pControlLayer->pluginObj.stackDataSize = sizeof(CONTROL_LAYER_STACK_DATA); pControlLayer->pluginObj.profileDataConstruct = controlLayerProfileDataConstruct; pControlLayer->pluginObj.profileDataCopy = NULL; pControlLayer->pluginObj.profileDataDestruct = NULL; pControlLayer->pluginObj.stackDataConstruct =controlLayerStackDataConstruct; pControlLayer->pluginObj.stackDataDestruct = controlLayerStackDataDestruct; pControlLayer->pluginObj.stackAdd = controlLayerStackAdd; pControlLayer->pluginObj.stackDelete = controlLayerStackDelete; pControlLayer->pluginObj.receive = controlLayerReceive; pControlLayer->pluginObj.send = controlLayerSend; pControlLayer->planeId = CONTROL_PLANE; pControlLayer->position = 1; pControlLayer->type = OPERATIONAL_LAYER; pControlLayer->componentAdd = controlLayerComponentAddComplete; pControlLayer->componentDelete = NULL; pControlLayer->addDynamicComponentToStack = componentStackDynamicAdd; pControlLayer->deleteDynamicComponentFromStack = componentStackDynamicDel;#ifdef OLD_SECRETS_DATABASE_INTERFACES /* create the LOCAL SECRET DATABASE tables */ if ((controlLayer->peerSecretsTable = pfwTableCreate(pfw,2,-1)) == NULL) { pfwPrintError (__FILE__, "pppControlLayerInit", __LINE__, pfw,0, "peer secrets table not be created "); if (controlLayer != NULL) { pfwFree(controlLayer); controlLayer = NULL; } return (ERROR); } if ((controlLayer->localSecretsTable = pfwTableCreate(pfw,2,-1)) == NULL) { pfwPrintError (__FILE__, "pppControlLayerInit", __LINE__, pfw,0, "local secrets table not be created "); if (controlLayer != NULL) { pfwFree(controlLayer); controlLayer = NULL; } return (ERROR); }#endif /* OLD_SECRETS_DATABASE_INTERFACES */ if (pfwLayerAdd (pControlLayer) == ERROR) { pfwFree(controlLayer); controlLayer = NULL; pfwPrintError (__FILE__, "pppControlLayerInit", __LINE__, pfw,0, "Control layer could not be added to the stack"); return (ERROR); } /* * publish "CONTROL_PROTOCOL_INTERFACE" which is supplied by all control * protocols */ if (pfwInterfaceRegister(pfw,"CONTROL_PROTOCOL_INTERFACE") <= 0) { pfwFree(controlLayer); controlLayer = NULL; return ERROR; } /* * publish "AUTH_INFO_INTERFACE" which is supplied by all control * protocols - WindNet Multilink */ if (pfwInterfaceRegister(pfw,"AUTH_INFO_INTERFACE") <= 0) { pfwFree(controlLayer); controlLayer = NULL; return ERROR; } /* * publish and bind "AUTHEN_ATTRIBUTES_INTERFACE" */ if ((i = pfwInterfaceRegister(pfw,"AUTHEN_ATTRIBUTES_INTERFACE")) > 0) { authenAttrGetInterface = &controlLayer->authenAttrGetInterface; authenAttrGetInterface->interfaceObj.id = i; authenAttrGetInterface->interfaceObj.pluginObj = (PFW_PLUGIN_OBJ *) pControlLayer; authenAttrGetInterface->authenAttributesGet = authenAttributesGet; pfwInterfaceBind(&authenAttrGetInterface->interfaceObj); } /* publish and bind PPP_CONTROL_LAYER_INTERFACE */ if ((i = pfwInterfaceRegister(pfw,"PPP_CONTROL_LAYER_INTERFACE")) > 0) { controlLayerInterface = &controlLayer->controlLayerInterface; controlLayerInterface->interfaceObj.id = i; controlLayerInterface->interfaceObj.pluginObj = (PFW_PLUGIN_OBJ *) pControlLayer; controlLayerInterface->protocolUp = protocolUp; controlLayerInterface->protocolDown = protocolDown; controlLayerInterface->protocolFinished = protocolFinished; controlLayerInterface->protocolRejected = protocolRejected; controlLayerInterface->pppLcpTerminationRequest = pppLcpTerminationRequest; controlLayerInterface->pppLcpIdRequest = pppLcpIdRequest ; controlLayerInterface->pppLcpIdRequestReceived = pppLcpIdRequestReceived ; controlLayerInterface->pppLcpTimeRemainingRequest = pppLcpTimeRemainingRequest; controlLayerInterface->pppLcpTimeRemainingReceived = pppLcpTimeRemainingReceived; controlLayerInterface->pppAuthRequest = pppAuthRequest; controlLayerInterface->pppChallengeAuthVerify = pppChallengeAuthVerify; controlLayerInterface->pppPasswordAuthVerify = pppPasswordAuthVerify; controlLayerInterface->pppAuthAckTransmitted = pppAuthAckTransmitted; controlLayerInterface->pppAuthAckReceived = pppAuthAckReceived; controlLayerInterface->pppAuthFailed = pppAuthFailed; controlLayerInterface->pppAuthRefused = pppAuthRefused; pfwInterfaceBind(&controlLayerInterface->interfaceObj); } /* WindNet Multilink - publish and bind MP_CONTROL_LAYER_INTERFACE */ if ((i = pfwInterfaceRegister(pfw,"MP_CONTROL_LAYER_INTERFACE")) > 0) { mpControlLayerInterface = &controlLayer->mpControlLayerInterface; mpControlLayerInterface->interfaceObj.id = i; mpControlLayerInterface->interfaceObj.pluginObj = (PFW_PLUGIN_OBJ *) pControlLayer; mpControlLayerInterface->pppMpMemberSet = pppMpMemberSet; mpControlLayerInterface->mpUpCallsGet = mpUpCallsGet; pfwInterfaceBind(&mpControlLayerInterface->interfaceObj); } else {#ifdef PPP_DEBUG printf ("Registering MP_CONTROL_LAYER_INTERFACE FAILED\n");#endif /* PPP_DEBUG */ } /* add our profile parameters */ pfwParameterAdd ((PFW_PLUGIN_OBJ *)pControlLayer,"ppp_secretsDatabase", ppp_secretsDatabase); /* publish the events we'll raise when it reaches network phase */ if (pfwEventPublish(pfw,"PPP_NETWORK_PHASE_UP") == NULL) { return ERROR; } /* publish the events we'll raise we open or close LCP */ if (pfwEventPublish(pfw,"LCP_OPEN_EVENT") == NULL) { return ERROR; } if (pfwEventPublish(pfw,"LCP_DOWN_EVENT") == NULL) { return ERROR; } if (pfwEventPublish(pfw,"LCP_CLOSE_EVENT") == NULL) { return ERROR; }/* WindNet Multilink */ /* Publishing events that we raise when auth. phase is completed successfully and when auth. phase is closed in the stack */ if (pfwEventPublish(pfw,"PPP_AUTH_SUCCESSFUL_EVENT") == NULL) { return ERROR; } if (pfwEventPublish(pfw,"PPP_AUTH_UNSUCCESSFUL_EVENT") == NULL) { return ERROR; } if (pfwEventPublish (pfw, "PPP_LINK_RESET_EVENT") == NULL) { return ERROR; }/* WindNet Multilink */ return (OK); }/******************************************************************************** pppControlLayerDelete - delete the Control Layer plug-in from the framework** This removes the Control Layer plug-in object from the specified framework.** The layer object allocated by pppControlLayerCreate() is freed if * there are no references to this object from a Stack or Profile object* in the framework.** RETURNS: OK on success and ERROR if the layer object could not be found or* deleted*/STATUS pppControlLayerDelete ( PFW_OBJ * pfw /* framework we are deleting this from */ ) { PFW_LAYER_OBJ * layerObj; layerObj = pfwLayerObjGet(pfw,"CONTROL_LAYER"); if (layerObj == NULL) return ERROR; if (pfwLayerDelete(layerObj) == OK) {#ifdef OLD_SECRETS_DATABASE_INTERFACES pfwTableDelete (((CONTROL_LAYER_OBJ *) layerObj)->peerSecretsTable); pfwTableDelete (((CONTROL_LAYER_OBJ *) layerObj)->localSecretsTable);#endif /* OLD_SECRETS_DATABASE_INTERFACES */ pfwFree(layerObj); layerObj = NULL; return OK; } return ERROR; }/******************************************************************************** pppConnectionOpen - open a PPP connection** Application interface for opening a PPP connection. Before calling this a* stack must be created using pfwStackAdd(). A successful return from a call* to this function does not indicate a opened connection. If it is provided * the pppOpened() callback is used to notify the application of an opened * PPP connection.** The application may provide a sparsely or wholly populated set of callbacks* via the upcalls parameter. ** RETURNS OK on success and ERROR otherwise** SEE ALSO: pfwStackAdd() pppConnectionClose()*/STATUS pppConnectionOpen ( PFW_STACK_OBJ * stackObj, /* stack on which to open connection */ PPP_UPCALL_FUNCTIONS * upcalls, /* upcall interface provided by user */ void * userHandle /* user cookie for this connection */ ) { PFW_PLUGIN_OBJ * layerPluginObj; PFW_PLUGIN_OBJ_STATE * layerState; CONTROL_LAYER_STACK_DATA * pStackData; PFW_OBJ * pfw; STATUS status; PFW_STACK_STATUS stackStatus; if ((pfwStackStatusGet(stackObj,&stackStatus) != OK) || (stackStatus != PFW_STACK_READY)) { printf("PPP: Invalid OR Incomplete stackObj 0x%x\n", (UINT32)stackObj); return ERROR; } if ((pfw = pfwStackObjPfwGet(stackObj)) == NULL) { printf("PPP: Invalid stackObj 0x%x\n", (UINT32)stackObj); return ERROR; } if ((layerPluginObj = pfwPluginObjGet(pfw,"CONTROL_LAYER")) == NULL) { printf("PPP: Could not find Control Layer plugin Obj\n"); return ERROR; } if ((layerState = pfwPluginObjStateExclusiveGet(stackObj,layerPluginObj)) == NULL) { printf("PPP: Control Layer pluginObj is not active in stackObj 0x%x\n", (UINT32)stackObj); return ERROR; } pStackData = (CONTROL_LAYER_STACK_DATA *)layerState->stackData; pStackData->pppUpcall = upcalls; pStackData->userHandle = userHandle; status = bringUpConnection(layerState); pStackData->adminState = OPENED; pfwPluginObjStateRelease(layerState); return (status); }/******************************************************************************** pppConnectionClose - close a PPP connection** User interface for Closing a PPP connection. If it is provided the pppClosed()* callback will be called to indicate that the connection has been closed.** RETURNS: OK on success and ERROR otherwise** SEE ALSO: pfwStackAdd() pppConnectionOpen() pfwStackDelete()*/STATUS pppConnectionClose ( PFW_STACK_OBJ * stackObj /* stack to close connection for */ ) { PFW_PLUGIN_OBJ * layerPluginObj; PFW_PLUGIN_OBJ_STATE * layerState; PFW_OBJ * pfw; STATUS status; PPP_STATE currentLcpState; CONTROL_LAYER_STACK_DATA * pStackData; PFW_STACK_STATUS stackStatus; if ((pfwStackStatusGet(stackObj,&stackStatus) != OK) || (stackStatus != PFW_STACK_READY)) { printf("PPP: Invalid OR Incomplete stackObj 0x%x\n", (UINT32)stackObj); return ERROR; } if ((pfw = pfwStackObjPfwGet(stackObj)) == NULL) { printf("PPP: Invalid stackObj 0x%x\n", (UINT32)stackObj); return ERROR; } if ((layerPluginObj = pfwPluginObjGet(pfw,"CONTROL_LAYER")) == NULL) { printf("PPP: Could not find Control Layer plugin Obj\n"); return ERROR; } if ((layerState = pfwPluginObjStateExclusiveGet(stackObj,layerPluginObj)) == NULL) { printf("PPP: Control Layer pluginObj is not active in stackObj 0x%x\n", (UINT32)stackObj); return ERROR; } pStackData = (CONTROL_LAYER_STACK_DATA *)layerState->stackData; currentLcpState = (*pStackData->lcpProtocolItem->interface->pppStateGet) (pStackData->lcpProtocolItem->state); pStackData->adminState = CLOSED; if (currentLcpState == PPP_STOPPED_STATE) { /* tell listening components on this stack that LCP is now down */ pfwEventRaise(layerState->stackObj,pStackData->lcpCloseEvent,0); /* notify application that connection is closed */ if ((pStackData->adminState == CLOSED) && (pStackData->pppUpcall != NULL) && (pStackData->pppUpcall->pppClosed != NULL)) { (*pStackData->pppUpcall->pppClosed)(pStackData->userHandle, layerState->stackObj); } status = OK; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -