📄 mpframinglayerinterface.c
字号:
/* mpFramingLayerInterface.c - Mp Framing Layer Interface Functions *//* Copyright 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history --------------------01s,14may03,ijm fixed diab build warnings01r,30jan03,ijm fix for SPR#86001, cannot re-establish bundle if peer does not end connection gracefully01q,15jan03,ijm removed redundant copy of mpStackConvert code01p,26oct02,ijm change reference to LCP_DOWN. Event is PPP_LINK_RESET01o,06aug02,jr fixed build warnings 01n,27feb02,ak deleting reference to the AUTH_INFO_INTERFACE in userNameOnTheLinkGet ()01m,23feb02,jr setting the pointers to NULL after freeing01l,18dec01,ak support for dynamic assignment of MP Member Stack to Manager Stack01k,10dec01,ak Removed adding "0x" before auth protocols in auth related configurations in mpLinkAssign()01j,17oct01,ak input parameter validation in mpLinkAssign()01i,17oct01,sd bug fixing in Class2 & Class4 EID processing in mpSetProfileFromLcpDiscriminatorBundleOption()01h,19sep01,ak Deleting the interface reference after retrieving negotiated parameters from LCP 01g,19sep01,ak freeing memory after pfwEventRaise() in bundleOpenedEventRaise() and in mpMemberAddedEventRaise()01f,03jul01,ak code change for supporting manual configuration01e,31may01,sd changed the mpStackOptionSet () to retain the local EID profile string set by the user01d,06may01,sd modified EID class 4 option in mpSetProfileFromLcpDiscriminatorBundleOption ()01c,05may01,ak added support for manual configuration of bundle01b,04may01,sd made changes in configuring manager profile configuration to member stack01a,20feb01,ak created*//*DESCRIPTIONThis module implements a part of Multi-Link Point-to-Point Protocol specified by RFC 1990. This module contains functions that implements interfaces implemented by mpFraming layer*/ /* defines *//* includes */#include "ppp/mp.h" #include "private/ppp/mpFramingLayerP.h"#include "private/ppp/mpInterfaceLayerP.h"#include "ppp/interfaces/mpFramingLayerInterfaces.h"#include "ppp/interfaces/lcpInterfaces.h"#include "string.h"#include "sllLib.h"#include "stdlib.h" #include "ppp/pppPapComponent.h"#include "ppp/interfaces/authInfoInterface.h"#include "private/ppp/pppLcpComponentP.h"#include "ppp/mpAPI.h"#include "net/inet.h"#include "inetLib.h"/* externs */IMPORT STATUS mp_remove_port_from_sending_end_of_the_bundle (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *pMemberStackObj);IMPORT STATUS mp_remove_port_from_sending_end_of_the_bundle (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *);IMPORT void mpBundleProfileGet (PFW_PLUGIN_OBJ_STATE *, LCP_BUNDLE_PROFILE *);IMPORT TEST mpFindAPortToBundleMapping (PFW_STACK_OBJ *, PFW_STACK_OBJ **);IMPORT BOOL is_bundle_exist (PFW_OBJ *, PFW_PLUGIN_OBJ_STATE **, MP_BUNDLE_IDENTIFIER *);IMPORT STATUS mp_remove_port_from_receiving_end_of_the_bundle (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *);IMPORT STATUS mpInitialize (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *); IMPORT STATUS mpBundleDown (PFW_STACK_OBJ * pMgrStack, BOOL adminClose);/* locals and forwards */STATUS mpLinkAssign (PFW_STACK_OBJ *, PFW_STACK_OBJ *);PFW_STACK_OBJ * mp_open_bundle_or_add_to_the_existing_bundle (PFW_PLUGIN_OBJ_STATE *, MP_UPCALL_FUNCTIONS *, void *); STATUS mp_remove_port_from_bundle (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *);SL_LIST * mpBAPLinkInfoListGet (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS userNameOnTheLinkGet (PFW_STACK_OBJ *, USHORT, AUTH_PHASE, char *); LOCAL STATUS authInformationOnTheLinkGet (LCP_BUNDLE_OPTIONS *, PFW_STACK_OBJ *);LOCAL STATUS linkToTheBundleAdd (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *, LCP_BUNDLE_OPTIONS *); LOCAL STATUS bundleProfileInit (PFW_PLUGIN_OBJ_STATE *, LCP_BUNDLE_OPTIONS *);LOCAL STATUS bundleOpenedEventRaise (PFW_PLUGIN_OBJ_STATE *, LCP_BUNDLE_OPTIONS *); LOCAL STATUS mpMemberAddedEventRaise (PFW_PLUGIN_OBJ_STATE *, PFW_STACK_OBJ *, LCP_BUNDLE_OPTIONS *); IMPORT STATUS mpStackConvert (PFW_STACK_OBJ * pMemberStackObj);LOCAL void mpStackOptionSet (PFW_STACK_OBJ *pStackObj, char * profileString, UINT paramId); LOCAL void mpSetProfileFromLcpDiscriminatorBundleOption (MP_DISCRIMINATOR_CLASS *lcpBundleOption, unsigned char *local_station_discriminator, BOOL isLocalDiscriminator); LOCAL void mpStackParamSet (PFW_STACK_OBJ *, UINT, char *, BOOL isLocal);BOOL is_RFC_1990_5_1_3_CASE_1 (MP_BUNDLE_IDENTIFIER *);/******************************************************************************** mp_open_bundle_or_add_to_the_existing_bundle - * Opens a new bundle for the given member link or adds to the existing bundle* * The mpInterface layer LCP_UP event handler or AUTH_UP event handler to add the* link to the bundle configured for it calls this function. This function * retrieves the bundle-identifier of the link through the * LCP_BUNDLE_OPTIONS_INTERFACE implemented by LCP. It checks whether the * bundle-identifier matches with that of any of the existing bundle. If matched, * it adds the link to that bundle. Otherwise, it opens the bundle identified by * the pMpFramingLayerState and adds the link to that bundle. If that bundle is * already opened, it returns ERROR. If the pMpFramingLayerState refers to a * non-existing bundle, Bundle Assignment array in the mpFraming layer component * structure is referred. If any matching entry is found, the link is added to * the assigned bundle if it is in closed state. Otherwise, this function returns* ERROR.* * RETURNS: PFW_STACK_OBJ * or NULL*/PFW_STACK_OBJ * mp_open_bundle_or_add_to_the_existing_bundle ( PFW_PLUGIN_OBJ_STATE *pMemberLcpState, /* LCP state of the Member Stack */ MP_UPCALL_FUNCTIONS *pMpUpCalls, /* reference to MP callbacks */ void *userHandler /* user handle for MP callbacks */ ) { MP_FRAMING_LAYER_STACK_DATA *pStackData = NULL; LCP_BUNDLE_OPTIONS *pLcpBundleOptions = NULL; PFW_PLUGIN_OBJ *pPluginObj = NULL; PFW_OBJ *pfwObj = NULL; PFW_STACK_OBJ *pMemberStackObj = NULL; PFW_STACK_OBJ *pManagerStackObj = NULL; PFW_PLUGIN_OBJ_STATE *pManagerLcpState = NULL; STATUS status; BOOL boolStat = FALSE; PFW_PLUGIN_OBJ_STATE *pBundleId = NULL; LCP_PROXYLCP_INTERFACE *pProxyLcpInterfaceObj = NULL; TEST test; MP_FRAMING_LAYER *pComponentData = NULL; LCP_BUNDLE_OPTIONS_INTERFACE *pLcpBundleOptionsInterfaceObj = NULL; UINT interfaceId = 0; PFW_PLUGIN_OBJ *pLcpPluginObj = NULL; BOOL bFlag = FALSE; PFW_STACK_OBJ *pManuallyConfiguredBundle = NULL; PFW_PLUGIN_OBJ_STATE *pManConfigState = NULL; MP_FRAMING_LAYER_STACK_DATA *pManConfigStackData = NULL; BOOL bOpenManuallyConfiguredBundle = FALSE; char paramBuffer[MAX_PROFILE_PARAM_LENGTH]; PFW_PLUGIN_OBJ_STATE *pMpFramingLayerState = NULL; UINT param; if (pMemberLcpState == NULL) { pfwPrintError (__FILE__, "mp_open_bundle_or_add_to_the_existing_bundle", \ __LINE__, 0, 0,"NULL pointer to member stack LCP state"); return (NULL); } bzero (paramBuffer, sizeof (paramBuffer)); pMemberStackObj = pMemberLcpState->stackObj; /* Get framework obj */ pfwObj = pfwStackObjPfwGet (pMemberStackObj); if (pfwObj == NULL) { pfwPrintError (__FILE__, "mp_open_bundle_or_add_to_the_existing_bundle", \ __LINE__, 0, 0,"NULL Framework reference"); return NULL; } /* * Instantiate an LCP Bundle Option structure to retrieve the MP options * negotiated on the member link */ pLcpBundleOptions = (LCP_BUNDLE_OPTIONS *) pfwMalloc (pfwObj, sizeof (LCP_BUNDLE_OPTIONS)); if (pLcpBundleOptions == NULL) { pfwPrintError (__FILE__, "mp_open_bundle_or_add_to_the_existing_bundle", \ __LINE__, pfwObj, 0,"Unable to allocate memory"); return (NULL); } bzero ((char *)pLcpBundleOptions, sizeof(LCP_BUNDLE_OPTIONS)); /* Retrieve the MP options negotiated on the link */ if ((interfaceId = pfwInterfaceIdGet (pfwObj, "LCP_BUNDLE_OPTIONS_INTERFACE")) > 0) { pLcpPluginObj = pfwPluginObjGet (pfwObj, "PPP_LCP"); pLcpBundleOptionsInterfaceObj = (LCP_BUNDLE_OPTIONS_INTERFACE *) pfwInterfaceObjGetViaPluginObj (pLcpPluginObj, interfaceId); if (pLcpBundleOptionsInterfaceObj == NULL) { pfwPrintError (__FILE__, "mp_open_bundle_or_add_to_the_existing_bundle", \ __LINE__, pfwObj, 0,"Unable to get reference to \ LCP_BUNDLE_OPTIONS_INTERFACE "); return (NULL); } status = pLcpBundleOptionsInterfaceObj-> lcpMpOptionsGet (pMemberLcpState, pLcpBundleOptions); if (status == ERROR) { pfwPrintError (__FILE__, \ "mp_open_bundle_or_add_to_the_existing_bundle", \ __LINE__, pfwObj, 0,"Rerieving MP options from the member \ link failed"); pfwInterfaceReferenceDelete ( &pLcpBundleOptionsInterfaceObj->interfaceObj); return NULL; } if (pfwInterfaceReferenceDelete ( &pLcpBundleOptionsInterfaceObj->interfaceObj) == ERROR) { pfwPrintError (__FILE__, \ "mp_open_bundle_or_add_to_the_existing_bundle", \ __LINE__, pfwObj, 0," Deleting the reference to the \ MP_BUNDLE_OPTIONS_INTERFACE failed"); return NULL; } } else { pfwPrintError (__FILE__, "mp_open_bundle_or_add_to_the_existing_bundle", \ __LINE__, pfwObj, 0,"Unable to get interface id \ LCP_BUNDLE_OPTIONS_INTERFACE "); return NULL; } if ((pLcpBundleOptions->localMRRU == 0) && (pLcpBundleOptions->remoteMRRU == 0)) { return (PFW_STACK_OBJ *) NOT_A_MP_LINK; } /* retrieve authentication information from the member link */ status = authInformationOnTheLinkGet (pLcpBundleOptions, pMemberStackObj); if (status == ERROR) { pfwPrintError (__FILE__, "mp_open_bundle_or_add_to_the_existing_bundle", \ __LINE__, pfwObj, 0,"authInformationOnTheLinkGet() failed"); pfwFree (pLcpBundleOptions); pLcpBundleOptions = NULL; return NULL; } /* Call MP upcall function */ if (pMpUpCalls != NULL) if (pMpUpCalls->linkNegotiatedMP != NULL) (*pMpUpCalls->linkNegotiatedMP) (userHandler, pMemberStackObj, &pLcpBundleOptions->bundle_identifier); /* Get the Manager Stack configuration */ param = pfwParameterIdGet (pfwObj, "mpInterface_managerStackId"); if (param == 0) return NULL; if (pfwStackParamGet (pMemberStackObj, param, paramBuffer) == ERROR) return NULL; pManagerStackObj = (PFW_STACK_OBJ *)atoi (paramBuffer); if (pManagerStackObj != NULL) { pPluginObj = pfwPluginObjGet (pfwObj, "MP_FRAMING_LAYER"); pMpFramingLayerState = pfwPluginObjStateGet (pManagerStackObj, pPluginObj); } /* Support for Manual configuration */ bFlag = is_RFC_1990_5_1_3_CASE_1 (&pLcpBundleOptions->bundle_identifier); if (bFlag == TRUE) { /* Get the manual configuration...Manual Cconfiguration can be done in two ways */ if (pMpFramingLayerState != NULL) { pManuallyConfiguredBundle = pMpFramingLayerState->stackObj; } else { mpFindAPortToBundleMapping(pMemberStackObj, &pManuallyConfiguredBundle); } /* if there is a manual configuration, add the link to the manually configured bundle */ if (pManuallyConfiguredBundle != NULL) { pPluginObj = pfwPluginObjGet (pfwObj, "MP_FRAMING_LAYER"); pManConfigState = pfwPluginObjStateGet (pManuallyConfiguredBundle,pPluginObj); pManConfigStackData = (MP_FRAMING_LAYER_STACK_DATA *)pManConfigState->stackData; if (pManConfigStackData->bundle_state == MP_BUNDLE_OPENED_STATE) { pBundleId = pManConfigState; printf ("Adding a link manually to a existing bundle, bundle 0x%x\n", (int)pBundleId->stackObj); boolStat = TRUE; } else /* Manually configured bundle does not exist */ bOpenManuallyConfiguredBundle = TRUE; } } /* Check bundle id matches with that of any of the existing bundle */ if (!(boolStat) && !(bOpenManuallyConfiguredBundle)) { boolStat = is_bundle_exist (pfwObj, &pBundleId, &pLcpBundleOptions->bundle_identifier); } /* Adding the link to the existing bundle */ if (boolStat) { status = linkToTheBundleAdd (pBundleId, pMemberStackObj, pLcpBundleOptions); if (status == ERROR) { if (pLcpBundleOptions != NULL) { pfwFree (pLcpBundleOptions); pLcpBundleOptions = NULL; } printf ("MP:mp_open_bundle_or_add_to_the_existing_bundle(): \ Addition of member stack 0x%x to the bundle 0x%x failed\n", \ (int) pMemberStackObj, (int) pManagerStackObj); return NULL; } if (pfwPluginObjStateLock (pBundleId) == ERROR) return NULL; pStackData = (MP_FRAMING_LAYER_STACK_DATA *) pBundleId->stackData; /* Raise MP_MEMBER_ADDED event */ status = mpMemberAddedEventRaise (pBundleId, pMemberStackObj, pLcpBundleOptions); if (status == ERROR) { pfwPrintError (__FILE__, "mp_open_bundle_or_add_to_the_existing_ \ bundle",__LINE__, pfwObj, 0,"Raising MP_MEMBER_ADDED event failed"); if (pLcpBundleOptions != NULL) { pfwFree (pLcpBundleOptions); pLcpBundleOptions = NULL; } if (pfwPluginObjStateRelease (pBundleId) == ERROR) return NULL; return NULL; } if (pfwPluginObjStateRelease (pBundleId) == ERROR) return NULL; return pBundleId->stackObj; } /* Opening a new bundle for the link */ /* Add the link to the bundle represented by passed pMpFramingLayerState */ bFlag = FALSE; if (pMpFramingLayerState != NULL) { pStackData = (MP_FRAMING_LAYER_STACK_DATA *) pMpFramingLayerState->stackData; if (pStackData->bundle_state != MP_BUNDLE_OPENED_STATE) { pBundleId = pMpFramingLayerState; bFlag = TRUE; } } /* * Try to get bundle mapping for the member link in the * bundle assignment array */ if (!bFlag) { test = mpFindAPortToBundleMapping (pMemberStackObj, &pManagerStackObj); if (test == FAIL) /* Given link has not been mapped to any bundle */ { printf ("MP:mp_open_bundle_or_add_to_the_existing_bundle(): The \ Member Stack 0x%x can not be added to any bundle\n", \ (int)pMemberStackObj); if (pLcpBundleOptions != NULL) { pfwFree (pLcpBundleOptions); pLcpBundleOptions = NULL; } return NULL; } pPluginObj = pfwPluginObjGet (pfwObj, "MP_FRAMING_LAYER"); if (pPluginObj == NULL) { printf ("MP:mp_open_bundle_or_add_to_the_existing_bundle(): \ mpFraming layer does not exist in the framework 0x%x\n", \ (int)pfwObj); if (pLcpBundleOptions != NULL) { pfwFree (pLcpBundleOptions); pLcpBundleOptions = NULL; } return NULL; } pBundleId = pfwPluginObjStateGet(pManagerStackObj, pPluginObj); if (pBundleId == NULL) { printf ("MP: mp_open_bundle_or_add_to_the_existing_bundle(): \ mpFraming layer does not exist in the stack 0x%x\n", \ (int)pManagerStackObj); if (pLcpBundleOptions != NULL) { pfwFree (pLcpBundleOptions); pLcpBundleOptions = NULL; } return NULL; } /* * Check if the bundle is opened. If yes, bundle identifier * mismatch. Link can not be added to the bundle */ if (((MP_FRAMING_LAYER_STACK_DATA *)(pBundleId->stackData)) -> bundle_state == MP_BUNDLE_OPENED_STATE) { printf ("MP:mp_open_bundle_or_add_to_the_existing_bundle(): The \ Member Stack 0x%x can not be added to any bundle\n", \ (int)pMemberStackObj); if (pLcpBundleOptions != NULL) { pfwFree (pLcpBundleOptions);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -