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

📄 pppbaptx.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	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_REQUEST;	sptr_bap_packet->bap_id   	= id;	sptr_bap_packet->bap_length = htons (packet_length - sizeof (PPP_HEADER));	sptr_bap_packet->link_type_option.type   = BAP_LINK_TYPE;	sptr_bap_packet->link_type_option.length = sizeof (BAP_LINK_TYPE_OPTION);	sptr_bap_packet->link_type_option.link_speed = htons (port_info->port_speed);	sptr_bap_packet->link_type_option.link_type  = port_info->port_type;	packet->mBlkHdr.mLen = sizeof (BAP_CALLBACK_REQUEST_PACKET);	/* add Reason Option */	if (reason_string != NULL)		bap_add_reason_option (packet, reason_string);	/* add multiple Phone Delta Option */	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);				}	/* create BAP BUFFER and fill in the members */    sptr_bap_buffer = (BAP_BUFFER *) pfwMalloc 						(pluginState->pluginObj->pfwObj, sizeof (BAP_BUFFER));	if (sptr_bap_buffer == NULL)		return NULL;	/* save the packet information */	sptr_bap_buffer->bap = packet;	return sptr_bap_buffer;	}/******************************************************************************** removeThePortInfoFromList - To remove the port information from the list** This routine removes portinfo from the list after checking for various * terminating conditions.* * RETURNS: N/A*/LOCAL void removeThePortInfoFromList 	(	SL_LIST * portList,					/* port list */ 	PORT_CONNECTION_INFO * port_info	/* port info to be removed from the list */	)	{	/* If node to be deleted is the last node */	if (SLL_NEXT (port_info) == NULL)		{		sllRemove (portList, 			(SL_NODE *)port_info, 							sllPrevious (portList, (SL_NODE *)port_info));		}	/* For all other intermediate nodes */	else		{		if (sllPrevious (portList, (SL_NODE *)port_info) == NULL)			sllRemove (portList, (SL_NODE *)port_info, NULL);			else 			sllRemove (portList, 					(SL_NODE *)port_info, 					sllPrevious (portList, (SL_NODE *)port_info));		}	}/******************************************************************************** bap_calculate_phone_option_length - To calculate length of phone delta option** This routine calculates the length for phone delta option from the port * information for a call-back request. It checks various error conditions as * required by RFC for a for a call-back request. * * RETURNS: OK/ERROR** SEE ALSO: bap_calculate_phone_option_length_for_dummy_packet*/LOCAL STATUS bap_calculate_phone_option_length 	(	PFW_PLUGIN_OBJ_STATE * pluginState,	 /* plugin object state in manager stack */	PORT_CONNECTION_INFO * port_info,	 /* port information */	USHORT 				 * phone_length  /* phone length */	)	{	USHORT 	old_phone_length = 0; 	old_phone_length = *phone_length; 	if (strlen (port_info->port_local_phone_number) != 0)		{		*phone_length = (USHORT)(*phone_length + 						strlen (port_info->port_local_phone_number) + 						(USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1);		}	else		{		logMsg ("bap_calculate_phone_option_length - NULL Local Phone Number \n",1,2,3,4,5,6);		return ERROR;		}	if ((strlen (port_info->port_unique_digits_phone_number) != 0) ||		(port_info->port_unique_digits_phone_number_length != 0))		{	   /* 	 	* If the Phone-Number-Sub-Address Sub-Option is present, the Unique-Digits	 	* Sub-Option MUST NOT include any of the Sub Address digits in its count	 	* of different rightmost digits. 						  RFC 2125:Page 18	 	*/ 			if (strlen (port_info->port_subaddress_phone_number) == 0)			{			*phone_length = (USHORT)(*phone_length + 				strlen (port_info->port_unique_digits_phone_number) +				sizeof (port_info->port_unique_digits_phone_number_length) + 				(USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1);			}		else			port_info->port_unique_digits_phone_number_length = 0;		}	else		{		logMsg ("bap_calculate_phone_option_length - \				Unique digit Phone Number length is Zero \n",1,2,3,4,5,6);		*phone_length = old_phone_length; 		return ERROR;		}	if (strlen (port_info->port_subaddress_phone_number) != 0) 		{		*phone_length = (USHORT) (*phone_length + 				strlen (port_info->port_subaddress_phone_number) + 				(USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1);					}	*phone_length += (USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1; 	return OK;	}/******************************************************************************** bap_calculate_phone_option_length_for_dummy_packet - To calculate length of * 							phone delta option.** This routine calculates the length for phone delta option from the port * information for a call-back request. It doesn't checks for any error conditions * as required for call-back request, since only dummy packet is been constructed.* * RETURNS: N/A* * SEE ALSO: bap_calculate_phone_option_length*/LOCAL void bap_calculate_phone_option_length_for_dummy_packet 	(	PFW_PLUGIN_OBJ_STATE * pluginState,	 /* plugin object state in manager stack */	PORT_CONNECTION_INFO * port_info,	 /* port information */	USHORT 				 * phone_length  /* phone length */	)	{	if (strlen (port_info->port_local_phone_number) != 0)		{		*phone_length = (USHORT)(*phone_length + 					strlen (port_info->port_local_phone_number) + 					(USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1);		}	if ((strlen (port_info->port_unique_digits_phone_number) != 0) ||					(port_info->port_unique_digits_phone_number_length != 0))		{		*phone_length = (USHORT)(*phone_length + 					strlen (port_info->port_unique_digits_phone_number) +					sizeof (port_info->port_unique_digits_phone_number_length) + 					(USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1);		}	if (strlen (port_info->port_subaddress_phone_number) != 0) 		{		*phone_length = (USHORT)(*phone_length + 					strlen (port_info->port_subaddress_phone_number) + 					(USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1);		}	*phone_length += (USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1; 	}/******************************************************************************** bap_create_link_drop_request - Construct BAP link drop request packet** This routine calculates the length of link drop request 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. The memory to the BAP_BUFFER is * allocated and the created packet is copied into the BAP_BUFFER and is returned.* * RETURNS: A pointer to the BAP_BUFFER or NULL** NOMANUAL*/BAP_BUFFER * bap_create_link_drop_request 	(	PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin object state in manager stack */	BYTE id,							/* sequence identifier */	PORT_CONNECTION_INFO * port_info,	/* port information */	char * reason_string 				/* reason string */	)	{	BAP_LINK_DROP_QUERY_REQUEST_PACKET * sptr_bap_packet = NULL;	BAP_BUFFER * sptr_bap_buffer = NULL;	M_BLK_ID packet = NULL;	USHORT packet_length = 0;    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_REQUEST_PACKET);	if ((packet = netTupleGet (pStackData->netPoolId, packet_length,				    M_DONTWAIT, MT_DATA, TRUE)) == NULL)		return NULL;		sptr_bap_packet = mtod (packet, BAP_LINK_DROP_QUERY_REQUEST_PACKET *);	/* Filling BAP_LINK_DROP_QUERY_REQUEST_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_REQUEST;	sptr_bap_packet->bap_id   	= id;	sptr_bap_packet->bap_length = htons (packet_length - sizeof (PPP_HEADER));	sptr_bap_packet->link_discriminator_option.type       								= BAP_LINK_DISCRIMINATOR;	sptr_bap_packet->link_discriminator_option.length     								= sizeof (BAP_LINK_DISCRIMINATOR_OPTION);	sptr_bap_packet->link_discriminator_option.link_discriminator 								= htons (port_info->port_lcp_remote_link_discriminator);	packet->mBlkHdr.mLen = sizeof (BAP_LINK_DROP_QUERY_REQUEST_PACKET);	/* add Reason Option */	if (reason_string != NULL)		bap_add_reason_option (packet, reason_string);	/* create BAP BUFFER and fill in the members */    sptr_bap_buffer = (BAP_BUFFER *) pfwMalloc 						(pluginState->pluginObj->pfwObj, sizeof (BAP_BUFFER));	if (sptr_bap_buffer == NULL)		return NULL;	/* save the packet information */	sptr_bap_buffer->bap = packet;	return sptr_bap_buffer;	}/* BAP add option functions *//******************************************************************************** bap_add_link_type_option - add the Link-Type Option to BAP packet** This routine is used to add the link type option to the BAP packet. The data * pointer is advanced to the current packet length. Link type option fields are * populated and the packet length is updated with the new packet length got after * adding this option.** RETURNS: N/A*/LOCAL void bap_add_link_type_option 	(	M_BLK_ID packet, 						/* BAP packet */	BYTE_ENUM(BAP_LINK_TYPES) link_type, 	/* link type option value */	USHORT link_speed						/* link speed option value */	)	{	BAP_LINK_TYPE_OPTION * ptr_link_type_option = NULL;	/* Get the data pointer->ie base address */	char * packet_address = packet->mBlkHdr.mData;	/* Move to the Address were Option field start */	ptr_link_type_option = (BAP_LINK_TYPE_OPTION *) 								(packet_address + packet->mBlkHdr.mLen);	ptr_link_type_option->type       = BAP_LINK_TYPE;	ptr_link_type_option->length     = sizeof (BAP_LINK_TYPE_OPTION);	ptr_link_type_option->link_type  = link_type;	ptr_link_type_option->link_speed = htons (link_speed);	/* Update packet length with new lenght */	packet->mBlkHdr.mLen += sizeof (BAP_LINK_TYPE_OPTION);	}/******************************************************************************** bap_add_reason_option - add the Reason Option to BAP packet** This routine is used to add the reason option to the BAP packet. The data * pointer is advanced to the current packet length. Reason option fields are * populated and the packet length is updated with the new packet length * got after adding this option.* * RETURNS: N/A*/LOCAL void bap_add_reason_option 	(	M_BLK_ID packet, 			/* BAP packet */	char * reason_string		/* reason string */	)	{	BAP_REASON_OPTION * ptr_reason_option = NULL;	USHORT reason_length;	/* Get the data pointer->ie base address */	char * packet_address = packet->mBlkHdr.mData;	/* Move to the Address were Option field start */	ptr_reason_option = (BAP_REASON_OPTION *) 								(packet_address + packet->mBlkHdr.mLen);	reason_length = (USHORT) strlen (reason_string);	ptr_reason_option->type = BAP_REASON;	ptr_reason_option->length = (BYTE) (reason_length + 										(BYTE) sizeof (BAP_REASON_OPTION) - 1);	memcpy ((void *) ptr_reason_option->reason, 			(void *) reason_string, reason_length);	/* Update packet length with new lenght */	packet->mBlkHdr.mLen += ptr_reason_option->length;	}/******************************************************************************** bap_add_no_phone_option - add No-Phone-Number-Needed Option to BAP packet** This routine is used to add the no phone number needed option to the BAP * packet. The data pointer is advanced to the current packet length. * No phone number needed option fields are populated and the packet length is * updated with the new packet length got after adding this option.* * RETURNS: N/A*/LOCAL void bap_add_no_phone_option 	(	M_BLK_ID packet			/* BAP packet */	)	{	BAP_NO_PHONE_NUMBER_NEEDED_OPTION * ptr_no_phone_option = NULL;	/* Get the data pointer->ie base address */	char * packet_address = packet->mBlkHdr.mData;	ptr_no_phone_option = (BAP_NO_PHONE_NUMBER_NEEDED_OPTION *) 								(packet_address + packet->mBlkHdr.mLen);	ptr_no_phone_option->type = BAP_NO_PHONE_NUMBER_NEEDED;	ptr_no_phone_option->length = sizeof (BAP_NO_PHONE_NUMBER_NEEDED_OPTION);	/* Update packet length with new lenght */	packet->mBlkHdr.mLen += sizeof(BAP_NO_PHONE_NUMBER_NEEDED_OPTION);	}/******************************************************************************** bap_add_phone_delta_option - add the Phone Delta Option to BAP packet** This routine is used to add the phone delta option to the BAP packet. The data * pointer is advanced to the current packet length. Phone delta option* fields are populated with phone delta sub otions and the packet length is * updated with with the new packet length got after adding this option.** RETURNS: N/A*/LOCAL void bap_add_phone_delta_option	(

⌨️ 快捷键说明

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