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

📄 pppbaptx.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	if ((packet = netTupleGet (pStackData->netPoolId, packet_length,				    M_DONTWAIT, MT_DATA, TRUE)) == NULL)		return FAIL;	sptr_bap_packet = mtod (packet, BAP_CALL_STATUS_RESPONSE_PACKET *);	/* Filling BAP_CALL_STATUS_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_STATUS_RESPONSE;	sptr_bap_packet->bap_id   	= id;	sptr_bap_packet->bap_length 	= htons (packet_length - sizeof (PPP_HEADER));	sptr_bap_packet->bap_response_code = BAP_RESPONSE_ACK;	packet->mBlkHdr.mLen = sizeof (BAP_CALL_STATUS_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 CALL STATUS RESPONSE : ID %d\n",id);#endif /* PPP_DEBUG */	return PASS;	}/******************************************************************************** bap_send_call_status_indication - send BAP call status response packet* * This routine calculates the length of the call status indication 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_indication 			(	PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin object state in manager stack */	BYTE id,							/* sequence identifier */	char * reason_string, 				/* reason string */	PORT_CONNECTION_INFO * port_info	/* port information */	)	{	USHORT packet_length = 0;	M_BLK_ID packet = NULL;	BAP_CALL_STATUS_INDICATION_PACKET * sptr_bap_packet = NULL;	BAP_BUFFER * sptr_bap_buffer = NULL;    BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData;    BACP_PROFILE_DATA * pProfileData =				(BACP_PROFILE_DATA *)pluginState->profileData;	PORT_CONNECTION_INFO * bap_port_info = NULL; 	/* If reason option needed to be added */	if (reason_string != NULL)		packet_length = strlen (reason_string) + (sizeof (BAP_REASON_OPTION) - 1);	/* If phone delta option needed to be added */	if (port_info != NULL)		{	   	if ((bap_port_info = (PORT_CONNECTION_INFO *)pfwMalloc 		(pluginState->pluginObj->pfwObj, sizeof(PORT_CONNECTION_INFO))) == NULL)			{   			printf("PPP: could not allocate memory for new port connection info \n");  			return FAIL;   			}		bap_port_info->next = NULL; 		memcpy (bap_port_info, port_info, sizeof(PORT_CONNECTION_INFO));		if (strlen (port_info->port_remote_phone_number) != 0)			{			packet_length = (USHORT)(packet_length + 							strlen (port_info->port_remote_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))			{			packet_length = (USHORT)(packet_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) 			{			packet_length = (USHORT)(packet_length + 							strlen (port_info->port_subaddress_phone_number) + 							(USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1);			}		packet_length += (USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1; 		}	packet_length += sizeof (BAP_CALL_STATUS_INDICATION_PACKET);	if ((packet = netTupleGet (pStackData->netPoolId, packet_length,				    M_DONTWAIT, MT_DATA, TRUE)) == NULL)		return FAIL;		sptr_bap_packet = mtod (packet, BAP_CALL_STATUS_INDICATION_PACKET *);	/* Filling BAP_CALL_STATUS_INDICATION_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_STATUS_INDICATION;	sptr_bap_packet->bap_id   	= id;	sptr_bap_packet->bap_length	= htons(packet_length - sizeof (PPP_HEADER));	/* Filling Call Status Option */	sptr_bap_packet->bap_call_status_option.type = BAP_CALL_STATUS;	sptr_bap_packet->bap_call_status_option.length = sizeof (BAP_CALL_STATUS_OPTION);	sptr_bap_packet->bap_call_status_option.status = port_info->port_status; 	sptr_bap_packet->bap_call_status_option.action = port_info->port_action; 		packet->mBlkHdr.mLen = sizeof (BAP_CALL_STATUS_INDICATION_PACKET);	if (reason_string != NULL)		bap_add_reason_option (packet, reason_string);	if (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_remote_phone_number[0], 						&port_info->port_subaddress_phone_number[0]);    sptr_bap_buffer = (BAP_BUFFER *) pfwMalloc 							(pluginState->pluginObj->pfwObj, sizeof (BAP_BUFFER));	if (sptr_bap_buffer == NULL)		return FAIL;	/* duplicate and save the packet information */	sptr_bap_buffer->bap = bacpDupPkt (packet);	if (sptr_bap_buffer->bap == NULL)		{		logMsg ("packet duplication ERROR \n",1,2,3,4,5,6);		return FAIL;		}	/* save all port information */	if (port_info != NULL)		{		sllInit ((SL_LIST *)&sptr_bap_buffer->port_list); 	    sllPutAtTail ((SL_LIST *)&sptr_bap_buffer->port_list, 			(SL_NODE *)bap_port_info);		}	/* If no port info also initilize port list */	else		sllInit ((SL_LIST *)&sptr_bap_buffer->port_list);	/* update the status */	sptr_bap_buffer->status  = BAP_CALL_STATUS_INDICATION_ALREADY_IN_PROGRESS;	/* add to call indication send queue */	add_entry_to_list ((LINK *) &pStackData->call_indication_send_queue, 												(LINK *) sptr_bap_buffer);	/* 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);	pfwTimerCancel (pStackData->indicationRetryTimer);   	pfwTimerStart (pStackData->indicationRetryTimer, 				PFW_100_MILLISECOND,				pProfileData->maximum_bap_status_indication_send_interval * 10,				retry_bap_status_indication, id); #ifdef PPP_DEBUG    printf("BAP: Tx BAP CALL STATUS INDICATION : ID %d\n",id);#endif /* PPP_DEBUG */	return PASS;	}/******************************************************************************** bap_create_call_request - Construct BAP call request packet** This routine calculates the length of call request packet based on the * 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, options are 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_call_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_CALL_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);	/* if we have remote phone number then the other side need not send it */	if (strlen (port_info->port_remote_phone_number) != 0)		packet_length += sizeof (BAP_NO_PHONE_NUMBER_NEEDED_OPTION);	packet_length += sizeof (BAP_CALL_REQUEST_PACKET);	if ((packet = netTupleGet (pStackData->netPoolId, packet_length,				    M_DONTWAIT, MT_DATA, TRUE)) == NULL)		return NULL;		sptr_bap_packet = mtod (packet, BAP_CALL_REQUEST_PACKET *);	/* Filling BAP_CALL_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_CALL_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_CALL_REQUEST_PACKET);	/* if we have remote phone add No Phone Number Option */	if (strlen (port_info->port_remote_phone_number) != 0)		bap_add_no_phone_option (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_create_callback_request - Construct BAP call back request packet** This routine calculates the length of call back 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.* callBackRequest paramter determines wether to create a Call-Back request * packet or just a dummy call-back reuest packet** RETURNS: A pointer to the BAP_BUFFER or NULL** NOMANUAL*/BAP_BUFFER * bap_create_callback_request 	(	PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin object state in manager stack */	BYTE id,							/* sequence identifier */	SL_LIST * portList,					/* port list information */	char * reason_string, 				/* reason string */	BOOL callBackRequest				/* if TRUE create callback-req packet */	)	{	BAP_CALLBACK_REQUEST_PACKET * sptr_bap_packet = NULL;	BAP_BUFFER * sptr_bap_buffer = NULL;    PORT_CONNECTION_INFO * port_info = NULL;    PORT_CONNECTION_INFO * temp_port_info = NULL; 	USHORT portInfoGet = FALSE;			USHORT portCount = -1;					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);		}	/* If phone delta option needed to be added */	if (portList != NULL)		{		port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (portList);		while (port_info != NULL)			{			if (callBackRequest == TRUE)				{				if (bap_calculate_phone_option_length (pluginState, 											port_info, &packet_length) == ERROR)					{					pmPortUnreserve (port_info);					removeThePortInfoFromList (portList, port_info);					temp_port_info = (PORT_CONNECTION_INFO *) SLL_NEXT (port_info);					if (port_info != NULL)                        {                        pfwFree (port_info);                        port_info = NULL;                        }   					port_info = temp_port_info;					portInfoGet = TRUE;						}				}					/* request only for creating dummy Bap Buffer of call-back request */			else 				bap_calculate_phone_option_length_for_dummy_packet (pluginState, 											port_info, &packet_length);			if (portInfoGet == FALSE)				port_info = (PORT_CONNECTION_INFO *) SLL_NEXT (port_info);			portInfoGet = FALSE;			} /* End of while */		} /* end of if */	portCount = sllCount (portList);	if (portCount == 0)		{#ifdef PPP_DEBUG    printf("BAP: Incomplete Port Information while constructing \				CallBack Request Packet \n");#endif /* PPP_DEBUG */		return NULL;				}	packet_length += sizeof (BAP_CALLBACK_REQUEST_PACKET);	if ((packet = netTupleGet (pStackData->netPoolId, packet_length,				    M_DONTWAIT, MT_DATA, TRUE)) == NULL)		{		return NULL;		}	sptr_bap_packet = mtod (packet, BAP_CALLBACK_REQUEST_PACKET *);	/* Set port info with first member node of port list */	if (portList != NULL)		port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (portList);	/* Filling BAP_CALLBACK_REQUEST_PACKET members */#if 0	

⌨️ 快捷键说明

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