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

📄 pppbaptx.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* pppbaptx.c - BAP transmit source file *//* Copyright 2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01i,29jan03,ijm fixed build warnings on MIPS01h,06aug02,jr  fixed build warnings 01g,23feb02,jr  setting the pointers to NULL after freeing01f,16feb02,jr  Formatted the Debug Messages and initialized the local variables                as part of the memory reduction process01e,05nov01,as  added parameter to bacpUpcall, code cleanup during BAP API calls 				and new function is added unreservePortInPortList, freeMemoryInPortList.				Code cleanup in error paths of bapBundleBandwidthAdd01d,16oct01,as  added removeThePortInfoFromList to check port info for 				constructing CallBack Request Packet. Added error 				checking bap_calculate_phone_option_length01c,08oct01,as  added functions bap_calculate_phone_option_length and		        bap_calculate_phone_option_length_for_dummy_packet for 		        multiple phone delta option support01b,19jun01,sd 	included listutls.h,pppInterfaces.h for warning free compilation01a,01feb01,as  created from routerware source*//* DESCRIPTIONThis module implements the various BAP packet send functionality. It constructsvarious BAP packet along with the required option that needed to be added.It also implements BAP create packet which is used while sending Call Request,Call-Back request and Link-Drop Request. After constructing each BAP tranmit packet it is send down the protocol stack using pfwSend ().A sepearted set of LOCAL functions are provied that will be used to add optionsto the transmit packet. Two utility functions are provided that will be used by send module to delete a partucukar entry from Active Port Queue and BAP Buffer Queue.INCLUDE FILES pppBacpComponentP.h, bapsend.h, and lcpInterfaces.h*//* includes */#include "private/ppp/pppBacpComponentP.h"#include "private/ppp/bapsend.h"#include "private/ppp/listutls.h"#include "ppp/pppInterfaces.h"#include "ppp/portmanager.h"/**$Log:: /Rtrware/devdrvrs/ppp/ppplcpr $ *  * 9     2/08/99 12:18p Nishit * lcp_configure_request_received() and * identification_packet_received() copy * the packet in the port class, and if * the packet size is larger than the * pre-allocated space, we had a memory * overwrite problem - fixed *  * 8     10/06/98 7:36p Nishit * lcp_termination_ack_received: port * disabled if CLOSED *  * 7     10/01/98 11:43a Alex * Updated the PPP source code to conform * to a single build.  *  * 6     4/30/98 3:03p Alex * Ppp v4.2.0 check in *  * 1     4/24/98 12:10a Release Engineer * code cleanup, code style changes, * linted, system level test * PPP v4.2.0*/LOCAL ULONG bap_calculate_total_bandwidth_for_the_bundle ( 				PFW_PLUGIN_OBJ_STATE *pComponentState);LOCAL void bap_add_link_type_option (M_BLK_ID packet, 				BYTE_ENUM(BAP_LINK_TYPES) link_type, USHORT link_speed);LOCAL void bap_add_reason_option (M_BLK_ID packet, 				char * reason_string);#if 0 LOCAL void bap_add_link_discriminator_option (M_BLK_ID packet, 				USHORT link_discriminator);#endif LOCAL void bap_add_no_phone_option (M_BLK_ID packet);LOCAL void bap_add_phone_delta_option (M_BLK_ID packet, 				char unique_digits_length, char * unique_digits_string,				char * subscriber_number_string, char * subaddress_string);LOCAL STATUS bap_calculate_phone_option_length (				PFW_PLUGIN_OBJ_STATE * pluginState,					PORT_CONNECTION_INFO * port_info, USHORT * packet_length);LOCAL void bap_calculate_phone_option_length_for_dummy_packet (				PFW_PLUGIN_OBJ_STATE * pluginState,					PORT_CONNECTION_INFO * port_info, USHORT * packet_length);LOCAL void removeThePortInfoFromList (SL_LIST * portList, 				PORT_CONNECTION_INFO * port_info);LOCAL void unreservePortInPortList (SL_LIST * portList);LOCAL void freeMemoryInPortList (SL_LIST * portList);/******************************************************************************** bap_send_call_response - send BAP call response packet* * This routine calculates the length of the call response packet based on the * options to be added and allocates memory for the calculated length using * netTupleGet (). The PPP_HEADER and the BAP_HEADER are filled in the allocated * M_BLK_ID and options added to the packet.* * RETURNS: PASS, or FAIL ** NOMANUAL*/TEST bap_send_call_response 	(	PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin obj state in manager stack */	BYTE id,							/* sequence identifier */	char * reason_string, 				/* reason string */	BYTE response_code,					/* response code */	BAP_LINK_TYPES link_type, 			/* link type option value */	USHORT link_speed, 					/* link speed option value */	SL_LIST	* portList					/* port list information */	)	{	USHORT packet_length = 0;	M_BLK_ID packet = NULL;	BAP_CALL_RESPONSE_PACKET * sptr_bap_packet = NULL;	PORT_CONNECTION_INFO * port_info = NULL;    BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData;	/* If reason option needed to be added */	if (reason_string != NULL)		packet_length = strlen (reason_string) + 								(sizeof (BAP_REASON_OPTION) - 1);	/* If link_type option needed to be added */	if (link_speed != 0)		packet_length += sizeof (BAP_LINK_TYPE_OPTION);	/* If phone delta option needed to be added */	if (portList != NULL)		{		port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (portList);		while (port_info != NULL)			{			if (bap_calculate_phone_option_length (pluginState, 										port_info, &packet_length) == ERROR)				{				printf ("Error while calculating phone length \n");				return FAIL;								}					port_info = (PORT_CONNECTION_INFO *) SLL_NEXT (port_info);			}		}	packet_length += sizeof (BAP_CALL_RESPONSE_PACKET);	if ((packet = netTupleGet (pStackData->netPoolId, packet_length,				    M_DONTWAIT, MT_DATA, TRUE)) == NULL)		return FAIL;		sptr_bap_packet = mtod (packet, BAP_CALL_RESPONSE_PACKET *);	/* Filling BAP_CALL_RESPONSE_PACKET members */#if 0		sptr_bap_packet->ppp_header.hdlc_address = HDLC_ADDRESS;	sptr_bap_packet->ppp_header.hdlc_control = UNNUMBERED_INFORMATION;#endif		sptr_bap_packet->ppp_header.protocol_type =  htons((USHORT)BAP_PROTOCOL); 	sptr_bap_packet->bap_type 	= BAP_CALL_RESPONSE;	sptr_bap_packet->bap_id   	= id;	sptr_bap_packet->bap_length = htons (packet_length - sizeof (PPP_HEADER));	sptr_bap_packet->bap_response_code = response_code;	packet->mBlkHdr.mLen = sizeof (BAP_CALL_RESPONSE_PACKET);	if (link_speed != 0)		bap_add_link_type_option (packet, link_type, link_speed);	if (reason_string != NULL)		bap_add_reason_option (packet, reason_string);	/* add multiple Phone Delta Option */	if (portList != NULL)		{		port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (portList);		while (port_info != NULL)			{			bap_add_phone_delta_option (packet, 				(BYTE) port_info->port_unique_digits_phone_number_length,				&port_info->port_unique_digits_phone_number[0],				&port_info->port_local_phone_number[0], 				&port_info->port_subaddress_phone_number[0]);			port_info = (PORT_CONNECTION_INFO *) SLL_NEXT (port_info);				}		}	/* Updating BAP statistics */	pStackData->bap_statistics.number_of_tx_bytes += packet->mBlkHdr.mLen;    ++pStackData->bap_statistics.number_of_tx_packets;    ++pStackData->bap_statistics.					number_of_control_tx_packets [sptr_bap_packet->bap_type];	/* Pass the given packet down in the protocol stack */    pfwSend (pluginState, packet);#ifdef PPP_DEBUG    printf ("BAP: Tx BAP CALL RESPONSE : ID %d Length %d \n",(int) id, \					(int) (packet_length - sizeof (PPP_HEADER)));#endif /* PPP_DEBUG */	return PASS;	}/******************************************************************************** bap_send_callback_response - send BAP call back response packet* * This routine calculates the length of the call back response packet based on * the options to be added and allocates memory for the calculated length using * netTupleGet (). The PPP_HEADER and the BAP_HEADER are filled in the allocated * M_BLK_ID and options added to the packet.** RETURNS: PASS or FAIL ** NOMANUAL*/TEST bap_send_callback_response 	(	PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin object state in manager stack */	BYTE id,							/* sequence identifier */	char * reason_string, 				/* reason string */	BYTE response_code,					/* response code */	BAP_LINK_TYPES link_type, 			/* link type option value */	USHORT link_speed 					/* link speed option value */	)	{	USHORT packet_length = 0;	M_BLK_ID packet = NULL;	BAP_CALLBACK_RESPONSE_PACKET * sptr_bap_packet = NULL;    BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData;	/* If reason option needed to be added */	if (reason_string != NULL) 		packet_length = strlen(reason_string) + (sizeof(BAP_REASON_OPTION) - 1);	/* If link_type option needed to be added */	if (link_speed != 0)		packet_length += sizeof (BAP_LINK_TYPE_OPTION);	packet_length += sizeof (BAP_CALLBACK_RESPONSE_PACKET);	if ((packet = netTupleGet(pStackData->netPoolId, packet_length,				    M_DONTWAIT, MT_DATA, TRUE)) == NULL)		return FAIL;		sptr_bap_packet = mtod (packet, BAP_CALLBACK_RESPONSE_PACKET *);	/* Filling BAP_CALLBACK_RESPONSE_PACKET members */#if 0		sptr_bap_packet->ppp_header.hdlc_address = HDLC_ADDRESS;	sptr_bap_packet->ppp_header.hdlc_control = UNNUMBERED_INFORMATION;#endif	sptr_bap_packet->ppp_header.protocol_type =  htons((USHORT)BAP_PROTOCOL); 	sptr_bap_packet->bap_type 	= BAP_CALLBACK_RESPONSE;	sptr_bap_packet->bap_id   	= id;	sptr_bap_packet->bap_length 	= htons (packet_length - sizeof (PPP_HEADER));	sptr_bap_packet->bap_response_code = response_code;	packet->mBlkHdr.mLen = sizeof (BAP_CALLBACK_RESPONSE_PACKET);	if (link_speed != 0)		bap_add_link_type_option (packet, link_type, link_speed);	if (reason_string != NULL)		bap_add_reason_option (packet, reason_string);	/* Updating BAP statistics */	pStackData->bap_statistics.number_of_tx_bytes += packet->mBlkHdr.mLen;    ++pStackData->bap_statistics.number_of_tx_packets;    ++pStackData->bap_statistics.					number_of_control_tx_packets [sptr_bap_packet->bap_type];	/* Pass the given packet down in the protocol stack */    pfwSend (pluginState, packet);	#ifdef PPP_DEBUG    printf("BAP: Tx BAP BAP CALLBACK RESPONSE PACKET : ID %d\n",id);#endif /* PPP_DEBUG */	return PASS;	}/******************************************************************************** bap_send_link_drop_query_response - send BAP link drop query response packet* * This routine calculates the length of the link drop response packet based on * the options to be added and allocates memory for the calculated length using * netTupleGet (). The PPP_HEADER and the BAP_HEADER are filled in the allocated * M_BLK_ID and options added to the packet.** RETURNS: PASS or FAIL ** NOMANUAL*/TEST bap_send_link_drop_query_response 	(	PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin object state in manager stack */	BYTE id,							/* sequence identifier */	char * reason_string, 				/* reason string */	BYTE response_code					/* response code */	)	{	USHORT packet_length = 0;	M_BLK_ID packet = NULL;	BAP_LINK_DROP_QUERY_RESPONSE_PACKET * sptr_bap_packet = NULL;    BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData;	/* If reason option needed to be added */	if (reason_string != NULL)		packet_length = strlen(reason_string) + (sizeof (BAP_REASON_OPTION) - 1);	packet_length += sizeof (BAP_LINK_DROP_QUERY_RESPONSE_PACKET);	if ((packet = netTupleGet(pStackData->netPoolId, packet_length,				    M_DONTWAIT, MT_DATA, TRUE)) == NULL)		return FAIL;	sptr_bap_packet = mtod (packet, BAP_LINK_DROP_QUERY_RESPONSE_PACKET *);	/* Filling BAP_LINK_DROP_QUERY_RESPONSE_PACKET members */#if 0		sptr_bap_packet->ppp_header.hdlc_address = HDLC_ADDRESS;	sptr_bap_packet->ppp_header.hdlc_control = UNNUMBERED_INFORMATION;#endif	sptr_bap_packet->ppp_header.protocol_type =  htons((USHORT)BAP_PROTOCOL); 	sptr_bap_packet->bap_type 	= BAP_LINK_DROP_QUERY_RESPONSE;	sptr_bap_packet->bap_id   	= id;	sptr_bap_packet->bap_length 	= htons (packet_length - sizeof (PPP_HEADER));	sptr_bap_packet->bap_response_code = response_code;	packet->mBlkHdr.mLen = sizeof (BAP_LINK_DROP_QUERY_RESPONSE_PACKET); 	if (reason_string != NULL)		bap_add_reason_option (packet, reason_string);	/* Updating BAP statistics */	pStackData->bap_statistics.number_of_tx_bytes += packet->mBlkHdr.mLen;    ++pStackData->bap_statistics.number_of_tx_packets;    ++pStackData->bap_statistics.					number_of_control_tx_packets [sptr_bap_packet->bap_type];	/* Pass the given packet down in the protocol stack */    pfwSend (pluginState, packet);#ifdef PPP_DEBUG    printf("BAP: Tx BAP LINK DROP QUERY RESPONSE PACKET : ID %d\n",id);#endif /* PPP_DEBUG */		return PASS;	}/******************************************************************************** bap_send_call_status_response - send BAP call status response packet* * This routine calculates the length of the call status response packet based on * the options to be added and allocates memory for the calculated length using * netTupleGet (). The PPP_HEADER and the BAP_HEADER are filled in the allocated * M_BLK_ID and options added to the packet.** RETURNS: PASS or FAIL ** NOMANUAL*/TEST bap_send_call_status_response 	(	PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin object state in manager stack */	BYTE id, 							/* sequence identifier */	char * reason_string 				/* reason string */	)	{	USHORT packet_length = 0;	M_BLK_ID packet = NULL;	BAP_CALL_STATUS_RESPONSE_PACKET * sptr_bap_packet  = NULL;    BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData;	/* If reason option needed to be added */	if (reason_string != NULL)		packet_length = strlen (reason_string) + (sizeof (BAP_REASON_OPTION) - 1);	packet_length += sizeof (BAP_CALL_STATUS_RESPONSE_PACKET);

⌨️ 快捷键说明

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