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

📄 mpframinglayer.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		return OK;		}    else		return ERROR;    }/******************************************************************************** mpFramingLayerReceive - process the received packet** This function is called with the packet received on the MEMBER stack that is * being passed up through the stack. The function checks the protocol id of the * received packet, if the protocol id is MULTILINK_PROTOCOL, then the packet is * submitted to the re-assembly module. IF it is not MULTILINK_PROTOCOL, then it * is passed up in the stack using pfwReceive function.** RETURNS: OK/ERROR*/LOCAL STATUS mpFramingLayerReceive 	(	PFW_PLUGIN_OBJ_STATE 	* pMpFramingLayerState, /* state for the manager stack */	PFW_STACK_OBJ		    * pMemberStackObj,		/* member stack obj */	M_BLK_ID 			    packet 				/* packet received */	)	{	PPP_PACKET 						*pPppPacket = NULL;	MP_FRAMING_LAYER_STACK_DATA 	*pStackData = NULL;	USHORT 							packetLength = 0;	if ((pMpFramingLayerState == NULL) || (pMemberStackObj == NULL))		return ERROR;	pStackData = 			(MP_FRAMING_LAYER_STACK_DATA *) pMpFramingLayerState->stackData;	if (packet == NULL)		return ERROR;/*	if ((mp_receive_port_is_in_bundle (pMpFramingLayerState, pMemberStackObj)) 																	== FALSE)		{		netMblkClChainFree (packet);		return ERROR;		}*/	if (packet->mBlkHdr.mNext != NULL)		packetLength = packet->mBlkPktHdr.len;	else		packetLength = packet->mBlkHdr.mLen;	/* get the protocol id from the packet */	pPppPacket = mtod (packet, PPP_PACKET *);	if (pPppPacket->header.protocol_type == ntohs (MULTILINK_PROTOCOL))		{		if (pStackData->bundle.receiving_end.use_short_sequence_number == TRUE)			{			if (packetLength < (sizeof(PPP_HEADER) + 								sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER)))				{#ifdef PPP_DEBUG				printf ("Received a bad length MP packet\n");#endif								netMblkClChainFree (packet);				return OK;				}			}		else			{			if (packetLength < (sizeof(PPP_HEADER) + 								sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER)))				{#ifdef PPP_DEBUG				printf ("Received a bad length MP packet\n");#endif								netMblkClChainFree (packet);				return OK;				}			}		/* if MP packet call reassembly module */		reassemble_and_dispatch_mp_packet 							(pMpFramingLayerState, pMemberStackObj, packet);		}    else        {        if (pfwReceive (pMpFramingLayerState, packet) != OK)            netMblkClChainFree (packet);        }	return OK;	}/******************************************************************************** mpFraminglayerSend - sends the packet** This function is called to send the PPP packets. It fragments the larger PPP * packets and sends it through the individual member links. It uses the * packetType function to check the type of the packet and calls * mp_send_ppp_packet function to send the packet.** RETURNS: OK/ERROR*/LOCAL STATUS mpFramingLayerSend 	(	PFW_PLUGIN_OBJ_STATE * pLayerState,		/*state for this stack */	M_BLK_ID 		 	 * packet    		/* packet received */	)	{	PFW_PACKET_TYPE 				packetType;	MP_FRAMING_LAYER_STACK_DATA 	*pStackData = NULL;	if (pLayerState == NULL)		return ERROR;	pStackData = (MP_FRAMING_LAYER_STACK_DATA *)pLayerState->stackData;	if (packet == NULL || *packet == NULL)		return ERROR;	if (pStackData->bundle_state == MP_BUNDLE_CLOSED_STATE) 		{		netMblkClChainFree (*packet);		return ERROR;		}	/* get the packet type */	packetType = mpFramingLayerPacketType ((void *)*packet); 	/* fragment and send the packet */	mp_send_ppp_packet (pLayerState, *packet, packetType);	return ERROR;	}/******************************************************************************** mpFramingLayerProfileDataConstruct - called by the framework to initialize the *										profile data** The framework calls this function when the first configuration parameter * associated with the Plugin object is added to the profile to initialize the * profile data associated with the Plugin object. This function initializes the * profile data parameters to their default values.** RETURNS: OK/ERROR*/LOCAL STATUS mpFramingLayerProfileDataConstruct	(		PFW_OBJ * pfw,		    /* framework object */	void * pData			/* pointer to hold profile data */	)	{	MP_FRAMING_LAYER_PROFILE_DATA *pProfileData = 							(MP_FRAMING_LAYER_PROFILE_DATA *) pData;	pProfileData->mpFraming_smallPacketLength = MP_SMALL_PACKET_LENGTH;	pProfileData->mpFraming_disableAuthOnBundle = 1;	bzero ((char *)pProfileData->mpFraming_localUserName, 			MAX_PROFILE_PARAM_LENGTH);	return OK;	}	/******************************************************************************** mpFramingLayerPacketType - get the packet type** This function gets the Protocol id from the packet, if its a control packet* returns CONTROL_PACKET else DATA_PACKET.** RETURNS: PFW_PACKET_TYPE*/LOCAL PFW_PACKET_TYPE mpFramingLayerPacketType 	(	void  *packet	)	{	struct mbuf *m = (struct mbuf *)packet;	if ((m->m_data[0] & 0xff) > 0)		{		return (CONTROL_PACKET);		}	return (DATA_PACKET);    }/******************************************************************************* mpFraming_smallPacketLength - get/set the small packet length parameter** This routine gets or sets the value of the MP_FRAMING_LAYER profile data * parameter mpFraming_smallPacketLength.** RETURNS: OK/ERROR*/LOCAL STATUS mpFraming_smallPacketLength	(	PFW_OBJ * pfw,							/* framework reference */		PFW_PARAMETER_OPERATION_TYPE operType,	/* operation type */	void * pData,                        	/* profile data bucket */	char * value	                 		/* value for this parameter */	)	{	MP_FRAMING_LAYER_PROFILE_DATA * pProfileData = 							(MP_FRAMING_LAYER_PROFILE_DATA *)pData;	UINT configValue = 0;	if (operType == PFW_PARAMETER_SET)		{		if (value == NULL)			return ERROR;		if ((configValue = atoi (value)) > 0)			pProfileData->mpFraming_smallPacketLength =	configValue;		return OK;		}	else 		if (operType == PFW_PARAMETER_GET)			{			sprintf (value, "%ld", \                              pProfileData->mpFraming_smallPacketLength);			return OK;			}		else			return ERROR;	}/******************************************************************************* mpFraming_localUserName - get/set the localUserName parameter** This routine gets or sets the value of the MP_FRAMING_LAYER profile data * parameter mpFraming_localUserName.** RETURNS: OK/ERROR*/LOCAL STATUS mpFraming_localUserName	(	PFW_OBJ * pfw,							/* framework reference */		PFW_PARAMETER_OPERATION_TYPE operType,	/* operation type */	void * pData,                        	/* profile data bucket */	char * value	                 		/* value for this parameter */	)	{	MP_FRAMING_LAYER_PROFILE_DATA * pProfileData = 							(MP_FRAMING_LAYER_PROFILE_DATA *)pData;	if (operType == PFW_PARAMETER_SET)		{		strcpy (pProfileData->mpFraming_localUserName, value);		return OK;		}	else 		if (operType == PFW_PARAMETER_GET)			{			strcpy (value, pProfileData->mpFraming_localUserName);			return OK;			}	return ERROR;	}/******************************************************************************* mpFraming_disableAuthOnBundle - *				get/set the enable mpFraming_disableAuthOnBundle parameter** This routine gets or sets the value of the MP_FRAMING_LAYER profile data * parameter mpFraming_disableAuthOnBundle.** RETURNS: OK/ERROR*/LOCAL STATUS mpFraming_disableAuthOnBundle	(	PFW_OBJ * pfw,							/* framework reference */		PFW_PARAMETER_OPERATION_TYPE operType,	/* operation type */	void * pData,                        	/* profile data bucket */	char * value	                 		/* value for this parameter */	)	{	MP_FRAMING_LAYER_PROFILE_DATA * pProfileData = 							(MP_FRAMING_LAYER_PROFILE_DATA *)pData;	if (operType == PFW_PARAMETER_SET)		{		if (value == NULL)			return ERROR;		if ((strcmp (value, "TRUE") == 0) || (strcmp (value, "1") == 0))			pProfileData->mpFraming_disableAuthOnBundle = TRUE;		else			pProfileData->mpFraming_disableAuthOnBundle = FALSE;		return OK;		}	else if (operType == PFW_PARAMETER_GET)		{		if (pProfileData->mpFraming_disableAuthOnBundle == TRUE)			strcpy (value, "TRUE");		else			strcpy (value, "FALSE");		return OK;		}	else		return ERROR;	}/******************************************************************************** mpFramingLayerLcpUpEventHandler - mpFraming layer LCP_UP event handler* 	* This function marks the bundle state as UP.*  * RETURNS: OK or ERROR*/LOCAL STATUS mpFramingLayerLcpUpEventHandler 	(	PFW_PLUGIN_OBJ_STATE	*pMpFramingLayerState,	void 					*eventData	)	{	MP_FRAMING_LAYER_STACK_DATA *pStackData = NULL;	if (pMpFramingLayerState == NULL)		return ERROR;	pStackData = 		(MP_FRAMING_LAYER_STACK_DATA *) pMpFramingLayerState->stackData;	pStackData->bundle.sending_end.master_long_sequence_number = 0;	pStackData->bundle.sending_end.master_short_sequence_number = 0;	pStackData->bundle_state = MP_BUNDLE_OPENED_STATE;	return OK;	}/******************************************************************************** mpFramingLayerLcpDownEventHandler - mpFraming layer PPP_LINK_RESET event handler* 	* This function closes the bundle.*  * RETURNS: OK or ERROR*/LOCAL STATUS mpFramingLayerMpLinkDownEventHandler 	(	PFW_PLUGIN_OBJ_STATE	*pMpFramingLayerState,	void 					*eventData	)	{	STATUS returnCode;	if (pMpFramingLayerState == NULL)		return ERROR;	returnCode =  mpBundleClose (pMpFramingLayerState->stackObj);	return returnCode;	}#if 0 /* NOT SUPPORTED IN THIS RELEASE *//******************************************************************************** mpLcpEchoReplyReceivedEventHandler - *		Time the link and calculate receiver buffer size required for the bundle* 	* This function is registered as the handler function for * LCP_ECHO_REPLY_RECEIVED event. This function records the current system tick. * It checks whether the stack that raised the event is the one, which is * representing a member link of the bundle represented by pMpFramingLayerState. * If not, it will not handle the event further. Otherwise, it checks the whether* the link is being timed by MP. If not, it just returns. Otherwise, it times * the link and estimate the receiver buffers size required.*  * RETURNS: OK or ERROR*/LOCAL STATUS mpFramingLayerLcpEchoReplyReceivedEventHandler 	(	PFW_PLUGIN_OBJ_STATE	*pMpFramingLayerState,	void 					*eventData	)	{	ULONG 							currentTick = 0;	PFW_STACK_OBJ					*pMemberStackObj = NULL;	MP_FRAMING_LAYER_STACK_DATA 	*pStackData = NULL;	UINT							loopIndex = 0;	MP_BUNDLE_RECEIVING_END_CLASS	*pRcvEndClass = NULL;	/* Record the current clock tick */	currentTick = tickGet ();	pStackData = 		(MP_FRAMING_LAYER_STACK_DATA *) pMpFramingLayerState->stackData;	pMemberStackObj = (PFW_STACK_OBJ *) eventData;	pRcvEndClass = &pStackData->bundle.receiving_end;		/* Search the matching entry for the link in receiving end links array */		for (loopIndex = 0; loopIndex < pStackData->bundle.no_of_links;     														loopIndex++)		{		if (pStackData->bundle.receiving_end.links[loopIndex].pMemberStackObj == 																pMemberStackObj)			break;		}	if (loopIndex == pStackData->bundle.no_of_links)		return ERROR;		 	/* Time the link */	if (pRcvEndClass->links [loopIndex].mp_is_timing_the_link == TRUE)		{		pRcvEndClass->links [loopIndex].delay = 			(currentTick - 			 pRcvEndClass->links [loopIndex].clock_ticks_when_timer_starts);		pRcvEndClass->links [loopIndex].mp_is_timing_the_link == FALSE;		pRcvEndClass->links [loopIndex].link_has_been_timed == TRUE;		/* Re-estimate the buffer requirement at the receiving end */	    mp_estimate_buffer_requirement (pMpFramingLayerState);		}	return OK;	}#endif /* NOT SUPPORTED IN THIS RELEASE */

⌨️ 快捷键说明

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