📄 pppbacpcomponent.c
字号:
/* pppBacpComponent.c - BACP and BAP component *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02f,22aug02,ijm include mpP.h02e,06aug02,jr fixed build warnings 02d,01may02,as modified in event handler all printf to logMsg02c,23feb02,jr setting the pointers to NULL after freeing02b,16feb02,jr modifications as part of memory reduction process02a,05nov01,as code cleanup to support an extra parameter in bacpUpcall01e,08oct01,as included portmanager.h for warning free compilation01d,18sep01,as removed pfwInterfaceReferenceDelete call for lcpPacketSendInterface.01c,20jun01,sd added the bacpMemoryFree () as wrapper for pfwFree () to remove the warnings01b,19jun01,sd included listutls.h for warning free compilation01a,01feb01,sd created*//*DESCRIPTIONThis module implements BACP and BAP specified in RFC 2125.This module gives functions to create and delete the BACP component and all theplugin object functions to be implemented for the BACP component.The plugin object functions are used when the BACP component is added to the stack, to initialize the profile parameters, the stack data and to bind to the interfaces.When the BACP component is deleted from the stack, the plugin object functions are used to delete the references held by the component and free all the memoryheld.This module also gives the event handler routines, which are called when aparticular event is raised.INCLUDE FILES: pppBacpComponent.h pppBacpComponentP.h*//* includes */#include "ppp/pppBacpComponent.h"#include "private/ppp/pppBacpComponentP.h"#include "private/ppp/listutls.h"#include "ppp/portmanager.h"#include "private/ppp/mpP.h"#include "pfw/pfwProfile.h"#define MAXIMUM_BAP_CALL_REQUESTS 10 #define MAXIMUM_BAP_CALLBACK_REQUESTS 10#define MAXIMUM_BAP_LINKDROP_REQUESTS 10#define MAXIMUM_BAP_STATUS_INDICATIONS 10#define MAXIMUM_BAP_CALL_REQUEST_RETRANSMIT_INTERVAL 10#define MAXIMUM_BAP_CALLBACK_REQUEST_RETRANSMIT_INTERVAL 10#define MAXIMUM_BAP_LINKDROP_REQUEST_RETRANSMIT_INTERVAL 10#define MAXIMUM_BAP_STATUS_INDICATION_RETRANSMIT_INTERVAL 10/* typedefs */typedef struct bacpParams { char * name; PFW_PARAMETER_HANDLER handler; } BACP_PARAMS;/* externs */IMPORT STATE_MACHINE_ACTION_TABLE bacpStateActionTable;IMPORT TEST bacp_packet_received (PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet);IMPORT TEST bap_packet_received (PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet);IMPORT OPTION_LIST_ENTRY *find_matching_option (OPTION_LIST *sptr_option_list, BYTE type);IMPORT STATUS generate_option_list_entry (PFW_OBJ *, OPTION_LISTS *, char *, char *, BYTE, char *, char *);IMPORT void free_ppp_option_lists (OPTION_LISTS *);IMPORT TEST bap_send_call_status_indication (PFW_PLUGIN_OBJ_STATE *, BYTE, char *, PORT_CONNECTION_INFO *);IMPORT void free_ppp_tx_accepted_option_list (OPTION_LIST *);IMPORT void free_ppp_option_list_entry (OPTION_LIST_ENTRY *);IMPORT void get_value_string (UNION_OPTION_DATA_TYPES *, BYTE, char *, char *, UNION_OPTION_TYPES, char *);/* locals and forwards */LOCAL void initialize_bacp_statistics_counters (PFW_PLUGIN_OBJ_STATE * state);LOCAL void initialize_bap_statistics_counters (PFW_PLUGIN_OBJ_STATE * state);LOCAL void free_bap_buffer_list (LINK *sptr_list);LOCAL void free_active_port_list (LINK *sptr_list);LOCAL void removeAlternateValues (BACP_CONFIG_STRINGS *, char *);LOCAL STATUS bacp_setStackData (PFW_OBJ *, BACP_PROFILE_DATA *, BACP_CONFIG_OPTION *, char *); LOCAL void bacpOptionConfigStringsFree (BACP_CONFIG_STRINGS *);void bacpMemoryFree (void * dataToFree);/* component interface */LOCAL STATUS bacpProfileDataConstruct (PFW_OBJ *, void * pProfileData);LOCAL STATUS bacpProfileDataCopy (PFW_OBJ *, void * srcProfile, void * dstProfile);LOCAL STATUS bacpProfileDataDestruct (PFW_OBJ *, void * pProfileData);LOCAL STATUS bacpStackDataConstruct (PFW_OBJ *, void * stackData, void * profileData);LOCAL STATUS bacpStackDataDestruct (PFW_OBJ *, void * stackData, void * profileData); LOCAL STATUS bacpInterfaceBind (PFW_PLUGIN_OBJ * pluginObj);LOCAL STATUS bacpStackAdd (PFW_PLUGIN_OBJ_STATE *, PFW_PLUGIN_OBJ_CALLBACKS *);LOCAL STATUS bacpStackDelete (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS bacpReceive (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);#if 0LOCAL STATUS bacpSend (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS bacpStackDataShow (PFW_PLUGIN_OBJ_STATE *);#endif/* interface functions */LOCAL PPP_CONTROL_PHASE bacpPhaseGet ();LOCAL PPP_STATE bacpStateGet (PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS bacpReceivePathAcceptableProtocolsGet (PFW_PLUGIN_OBJ_STATE *state, ACCEPTABLE_PROTOCOLS_ARRAY **recvProtocols );LOCAL UINT bacpProtocols[2] = {BACP_PROTOCOL, BAP_PROTOCOL};LOCAL ACCEPTABLE_PROTOCOLS_ARRAY receiveAcceptableProtocols = {2, bacpProtocols};/* parameter handlers */LOCAL STATUS bacp_optionsHandler (PFW_OBJ *, BACP_OPTION_TYPE, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bacp_optionsHandlerX01 (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bacp_maxConfigRequests (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bacp_maxConfigFailures (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bacp_maxTerminationRequests (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bacp_configReqSendInterval (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bacp_terminationReqSendInterval (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bacp_configReqBackoffInterval (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bap_callRequestSendInterval (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bap_maxCallRequests (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bap_callbackRequestSendInterval (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bap_maxCallbackRequests (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bap_linkdropRequestSendInterval (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bap_maxLinkdropRequests (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bap_indicationSendInterval (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL STATUS bap_maxIndications (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE, void *, char *);LOCAL BACP_PARAMS bacpParams[] = { {"bacp_FP", bacp_optionsHandlerX01},/* * END of bacp negotiation options */ {"bacp_maxConfigRequests", bacp_maxConfigRequests}, {"bacp_maxTerminationRequests", bacp_maxTerminationRequests}, {"bacp_configReqSendInterval", bacp_configReqSendInterval}, {"bacp_terminationReqSendInterval", bacp_terminationReqSendInterval}, {"bacp_configReqBackoffInterval", bacp_configReqBackoffInterval}, {"bacp_maxConfigFailures", bacp_maxConfigFailures}, {"bacp_callRequestSendInterval", bap_callRequestSendInterval}, {"bacp_maxCallRequests", bap_maxCallRequests}, {"bacp_callbackRequestSendInterval", bap_callbackRequestSendInterval}, {"bacp_maxCallbackRequests", bap_maxCallbackRequests}, {"bacp_linkdropRequestSendInterval", bap_linkdropRequestSendInterval}, {"bacp_maxLinkdropRequests", bap_maxLinkdropRequests}, {"bacp_indicationSendInterval", bap_indicationSendInterval}, {"bacp_maxIndications", bap_maxIndications} }; LOCAL int numBacpParams = NELEMENTS (bacpParams);/* event handlers */LOCAL STATUS bacpLinkAdded (PFW_PLUGIN_OBJ_STATE *, void *eventData);LOCAL STATUS bacpLinkRemoved (PFW_PLUGIN_OBJ_STATE *, void *eventData);LOCAL STATUS mpBundleOpen (PFW_PLUGIN_OBJ_STATE *, void *eventData);LOCAL STATUS mpBundleClose (PFW_PLUGIN_OBJ_STATE *, void *eventData);LOCAL STATUS linkRemoveCleanOperation (PFW_PLUGIN_OBJ_STATE *, BAP_BUFFER *, BYTE requestType);/******************************************************************************** bacpComponentCreate - initialize and add BACP component to framework ** This component implements RFC 2125* The PFW_PLUGIN_OBJ data structure representing BACP component is allocated * and initialized. The plugin object specific configuration parameters are * added to the framework, the events are published and the component is added * to the framework* * RETURNS: OK/ERROR*/STATUS bacpComponentCreate ( PFW_OBJ * pfw /* framework reference */ ) { PPP_BACP_COMPONENT * pComponent = NULL; PFW_PLUGIN_OBJ * pBacpPluginObj = NULL; UINT loopCount = 0; BACP_CONFIG_OPTION *pBacpOption = NULL; if (pfw == NULL) return ERROR; /* allocate the component object */ if ((pComponent = pfwMalloc (pfw, sizeof (PPP_BACP_COMPONENT))) == NULL) return ERROR; bzero ((void *)pComponent, sizeof (PPP_BACP_COMPONENT)); pBacpPluginObj = (PFW_PLUGIN_OBJ *) &(pComponent->component); /* initialize our component object */ bzero (pBacpPluginObj->name, PFW_MAX_NAME_LENGTH); strcpy (pBacpPluginObj->name, "PPP_BACP"); pBacpPluginObj->pfwObj = pfw; pBacpPluginObj->profileDataSize = sizeof (BACP_PROFILE_DATA); pBacpPluginObj->stackDataSize = sizeof (BACP_STACK_DATA); pBacpPluginObj->profileDataConstruct = bacpProfileDataConstruct; pBacpPluginObj->profileDataCopy = bacpProfileDataCopy; pBacpPluginObj->profileDataDestruct = bacpProfileDataDestruct; pBacpPluginObj->stackDataConstruct = bacpStackDataConstruct; pBacpPluginObj->stackDataDestruct = bacpStackDataDestruct; pBacpPluginObj->interfaceBind = bacpInterfaceBind; pBacpPluginObj->receive = bacpReceive; pBacpPluginObj->send = NULL; pBacpPluginObj->stackDataShow = NULL; pBacpPluginObj->stackAdd = bacpStackAdd; pBacpPluginObj->stackDelete = bacpStackDelete; pComponent->component.protocol = BACP_PROTOCOL; pComponent->component.layerObj = pfwLayerObjGet (pfw, "CONTROL_LAYER"); /* register this component with the framework */ if (pfwComponentAdd (&pComponent->component) == ERROR) { logMsg ("pppBACPInit: Couldn't add BACP component to pfw 0x%x\n", (int)pfw, 2, 3, 4, 5, 6); return (ERROR); } /* add our parameters to the framework */ for (loopCount = 0; loopCount < numBacpParams; loopCount++) { if (pfwParameterAdd ((PFW_PLUGIN_OBJ *)pComponent, bacpParams [loopCount].name, bacpParams [loopCount].handler) == ERROR) { logMsg ("pppBacpComponent - Parameter %s could not be added\n", (int)bacpParams [loopCount].name, 2, 3, 4, 5, 6); return (ERROR); } } /* initialize the favored peer option */ pBacpOption = &pComponent->option [BACP_FAVORED_PEER]; pBacpOption->optionType = BACP_FAVORED_PEER; bzero (pBacpOption->optionTypeString, sizeof (pBacpOption->optionTypeString)); strcpy (pBacpOption->optionTypeString, "D4S"); bzero (pBacpOption->name, sizeof (pBacpOption->name)); strcpy (pBacpOption->name, "Magic Number"); /* publish the event we'll raise when we attain OPENED state */ if (pfwEventPublish (pfw, "BACP_UP_EVENT") == NULL) return ERROR; /* publish the event we'll raise when we attain CLOSED state */ if (pfwEventPublish (pfw, "BACP_DOWN_EVENT") == NULL) return ERROR; /* set the send and receive function pointers */ bacpSetSendActionFunctions (&bacpStateActionTable); bacpSetReceiveFunctions (pComponent); bapSetReceiveFunctions (pComponent); return OK; }/******************************************************************************** bacpComponentDelete - delete the BACP component from the framework** The BACP plug-in component object allocated by bacpComponentCreate () is * freed if there are no references to this object from a * Stack or Profile object in the framework.** RETURNS: OK/ERROR*/STATUS bacpComponentDelete ( PFW_OBJ * pfw /* framework reference */ ) { PFW_COMPONENT_OBJ *pComponent = NULL; pComponent = pfwComponentObjGetByName (pfw, "PPP_BACP"); if (pComponent == NULL) return ERROR; /* delete the component */ if (pfwComponentDelete (pComponent) == OK) { pfwFree (pComponent); pComponent = NULL; return OK; } return ERROR; }/******************************************************************************** bacpStackDataConstruct - initialize stack data ** This function is called when a stack is created to initialize the stack data * of the BACP component. The stack data structure members are initialized to * their initial values. Profile data is copied into the option_lists member of* the stack data and the current state of BACP component is set to * PPP_INITIAL_STATE.** RETURNS: OK/ERROR*/LOCAL STATUS bacpStackDataConstruct ( PFW_OBJ * pfw, /* framework reference */ void * stackData, /* stack data */ void * profileData /* profile data */ ) { BACP_CONFIG_STRINGS *pBacpConfigStrings = NULL; BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *) stackData; BACP_PROFILE_DATA *pProfileData = (BACP_PROFILE_DATA *) profileData; char partialString[256]; BACP_CONFIG_OPTION *bacpOption = NULL; ALTERNATE_OPTION_STRING *alternateConfigString = NULL; UINT options; UINT stringLength = 0; PPP_BACP_COMPONENT *pComponentData = NULL; pComponentData = (PPP_BACP_COMPONENT *)pfwPluginObjGet (pfw, "PPP_BACP"); if (pComponentData == NULL) return ERROR; bzero ((char *)pStackData, sizeof (BACP_STACK_DATA)); /* get the network pool id */ if ((pStackData->netPoolId = pfwNetPoolIdGet (pfw)) == NULL) { logMsg ("BACP: MUST have a valid NetPoolId; See pfwCreate ()\n",1,2,3,4,5,6); return ERROR; } /* generate the initial id */ pStackData->id_sequence_number = (BYTE) (tickGet () &0xff); pStackData->last_bap_id = (BYTE) (tickGet () &0xff); /* copy the profile data option into option_lists */ if (pProfileData->bacpConfigStrings != NULL) { for (options = 1; options < NUMBER_OF_BACP_OPTIONS; options++) { bacpOption = &pComponentData->option[options]; pBacpConfigStrings = &pProfileData->bacpConfigStrings[options]; if (pBacpConfigStrings->configString == NULL && pBacpConfigStrings->remoteConfigString == NULL) continue; if (pBacpConfigStrings->configString != NULL) { stringLength = strlen(pBacpConfigStrings->configString) + 1; bzero(partialString,stringLength);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -