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

📄 pppbaprx.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
            pfwFree(port_info);	 		 /* free the port_info */            port_info = NULL;            }		port_info = temp_port_info;		}	}/******************************************************************************* bap_callback_request_received - *					processes the received BAP call request packet** This routine is called to process the BAP call back request packet. The * received BAP call back request packet is verified against duplication and * race condition. The port manager functions are then called to reserve a port * and dial to the peer. A call request packet is constructed with the received * options in the call back request packet and copied into * call_request_send_queue (this is equivalent to sending a call request).** RETURNS: PASS, or FAIL */LOCAL TEST bap_callback_request_received 	(    PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin object state in manager stack */    M_BLK_ID packet						/* packet received */	)	{	BAP_BUFFER * sptr_bap_buffer,* bap_buffer;	PORT_CONNECTION_INFO * port_info = NULL;    BAP_CALLBACK_REQUEST_PACKET * bap_rx_packet;	BAP_LINK_TYPE_OPTION * ptr_link_option;	BAP_PHONE_DELTA_OPTION * ptr_phone_delta_option;	BAP_REASON_OPTION *	ptr_reason_option;	USHORT link_speed = 0;	BYTE_ENUM(BAP_LINK_TYPES) link_type = BAP_ANALOG_TYPE;	enum BAP_RESPONSE_CODE response_code = BAP_RESPONSE_ACK;	char * ptr_reason_string = NULL;	char reason_string[256];		USHORT	request_from_callback_queue = 0;	USHORT numberOfEntries = 0;	PFW_STACK_OBJ * pManagerStackObj = pluginState->stackObj;    BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *)pluginState->stackData;    bap_rx_packet = mtod(packet, BAP_CALLBACK_REQUEST_PACKET *);#ifdef PPP_DEBUG    logMsg ("BAP Rx: Call-Back Request Packet: ID %d\n",\				bap_rx_packet->bap_id, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */    numberOfEntries = bap_number_of_active_port_entries (                      (LINK *) &pStackData->active_port_queue);	if (numberOfEntries == MAX_NO_OF_PPP_PORTS)		{#ifdef PPP_DEBUG        logMsg ("BAP Rx: Call-Back Request could not be processed as Bundle 0x%x \                has reached its MAX(%d) number of ports \n", \                (int) pManagerStackObj, numberOfEntries, 3, 4, 5, 6);#endif /* PPP_DEBUG */        bap_send_callback_response (pluginState, bap_rx_packet->bap_id,                        "Reached MAX port for the Bundle", BAP_RESPONSE_FULL_NAK,                        0, 0);		return (PASS);		}	sptr_bap_buffer = bap_match_received_response_to_outstanding_request						((LINK *) &pStackData->call_request_send_queue, 							bap_rx_packet->bap_id);		/* If u have already received the request and responded then reply again  */	if (sptr_bap_buffer != NULL)		{#ifdef PPP_DEBUG        logMsg ("BAP Rx: Duplicate Call-Back Request Packet of ID %d\n",\                    bap_rx_packet->bap_id, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */		port_info = (PORT_CONNECTION_INFO *)						SLL_FIRST (&sptr_bap_buffer->port_list); 		bap_send_callback_response (pluginState, bap_rx_packet->bap_id,					"Retransmission", BAP_RESPONSE_ACK,					port_info->port_type, port_info->port_speed);		return (PASS);		}	/* To avoid potential RACE condition first we have to check if a call     */	/* request is already sent by us. If so and we are not the favored peer   */ 	/* then drop the request												  */	sptr_bap_buffer = bap_find_unacknowledged_outstanding_request 		((LINK *) &pStackData->call_request_send_queue );	/* If sptr_bap_buffer == NULL no unacknowledge call-request */	if (sptr_bap_buffer == NULL)		{		request_from_callback_queue = TRUE;		sptr_bap_buffer = bap_find_unacknowledged_outstanding_request 			((LINK *) &pStackData->callback_request_send_queue);		}	/* if the peer is the Favored-Peer then drop our request */		if (sptr_bap_buffer != NULL)		{		if (pStackData->favored_peer_is_me == FALSE)			{			port_info = (PORT_CONNECTION_INFO *)					SLL_FIRST (&sptr_bap_buffer->port_list); 			if (pStackData->bacpUpcall != NULL)				{				(*pStackData->bacpUpcall->bacpUpCallFunction) 							(pManagerStackObj, BAP_EVENT_CALL_REQUEST_STATUS,							port_info->port_number, NULL,							BAP_FAVORED_PEER_PRIORITY_DROP,	&ptr_reason_string);				}			pmPortUnreserve (port_info); #ifdef PPP_DEBUG    logMsg ("BAP Rx: Dropping our Call-Back Request Packet as the peer is Favored \n",					1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */			if (request_from_callback_queue)				{				pfwTimerCancel (pStackData->callbackRequestRetryTimer);				pStackData->number_of_bap_callback_requests = 0;				free_bap_buffer ((LINK *) &pStackData->callback_request_send_queue,							sptr_bap_buffer);				}			else				{				pfwTimerCancel (pStackData->callRequestRetryTimer);				pStackData->number_of_bap_call_requests = 0;				free_bap_buffer ((LINK *) &pStackData->call_request_send_queue,							sptr_bap_buffer);				}	   		}			/* if the implementation is the Favored-Peer then drop peers request */		else			{ #ifdef PPP_DEBUG    logMsg ("BAP Rx: Dropping Call-Back Request Packet of ID %d as I am the Favored-Peer \n",\					bap_rx_packet->bap_id, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */			bap_send_callback_response (pluginState, bap_rx_packet->bap_id, 				"Favored-Peer NAK the request", BAP_RESPONSE_NAK, 0, 0);			return (FAIL); 			}		}	if (pStackData->bacpUpcall == NULL)		{#ifdef PPP_DEBUG        logMsg ("BAP Rx: In Call-Back Request BODA up call is NULL \n", 1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */		bap_send_callback_response (pluginState, bap_rx_packet->bap_id,					NULL, BAP_RESPONSE_NAK,	0, 0);		return (FAIL); 		}	/* Callback request option field MUST include Linktype and Phonedelta     */	/* options. The Reason option MAY also be included.   RFC 2125 Pg:13 	  */	ptr_reason_option = (BAP_REASON_OPTION *) bap_find_option_in_packet 							(packet, BAP_REASON, SUBOPTION_TYPE_NONE);	if (ptr_reason_option)		{		ptr_reason_string = (char *) &ptr_reason_option->reason[0];		memcpy((void *) &reason_string, 				(void *) ptr_reason_string, 				ptr_reason_option->length - 2);		reason_string[ptr_reason_option->length - 2]  = 0x00;		ptr_reason_string = &reason_string[0];				}	ptr_link_option = (BAP_LINK_TYPE_OPTION *) bap_find_option_in_packet 							(packet, BAP_LINK_TYPE, SUBOPTION_TYPE_NONE);	ptr_phone_delta_option = (BAP_PHONE_DELTA_OPTION *) 								bap_find_option_in_packet 								(packet, BAP_PHONE_DELTA, SUBOPTION_TYPE_NONE);	if (ptr_phone_delta_option == NULL || ptr_link_option == NULL)		{#ifdef PPP_DEBUG        logMsg ("BAP Rx: Call-Back Request packet of ID =%d :\                    with NO-Phone-Number or Link-Type Option \n",\                    bap_rx_packet->bap_id, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */		bap_send_callback_response (pluginState, bap_rx_packet->bap_id, 				"No Phone Delta or Link Type Option", BAP_RESPONSE_NAK, 0, 0);		return (FAIL);		}	link_type = ptr_link_option->link_type;	link_speed = ntohs (ptr_link_option->link_speed);	if (pStackData->bacpUpcall != NULL)		response_code = (*pStackData->bacpUpcall->bacpUpCallFunction) 							(pManagerStackObj, 							BAP_EVENT_CALL_REQUEST_RECEIVED, link_speed, 							NULL,							(BYTE) BAP_CALLBACK_REQUEST, &ptr_reason_string);   	if ((port_info = (PORT_CONNECTION_INFO *)pfwMalloc   		(pluginState->pluginObj->pfwObj, sizeof(PORT_CONNECTION_INFO))) == NULL)		{        logMsg ("BAP Rx: Memory alloc failed for new port connection info \n",					1, 2, 3, 4, 5, 6);        return (FAIL);   		}	port_info->next = NULL;	if (response_code == BAP_RESPONSE_ACK)		{		port_info->port_type      = link_type;		port_info->port_speed     = link_speed;		port_info->port_dial_type = PORT_DIAL_OUT;		/* For the request reserve a port. If fail send response with NAK */		if (pmPortFindAndReserve (port_info) == ERROR) 			{			if (pStackData->bacpUpcall != NULL)				(*pStackData->bacpUpcall->bacpUpCallFunction) 							(pManagerStackObj, BAP_EVENT_CALL_REQUEST_STATUS,							port_info->port_number, NULL,							BAP_RESPONSE_NAK, &ptr_reason_string);			bap_send_callback_response (pluginState, bap_rx_packet->bap_id,					ptr_reason_string, BAP_RESPONSE_NAK, link_type, link_speed);            if (port_info != NULL)               {               pfwFree(port_info);	 		 /* free the port_info */               port_info = NULL;               }			return (FAIL);			}		if ((bap_buffer = bap_create_call_request (pluginState, 					bap_rx_packet->bap_id, port_info, ptr_reason_string)) == NULL)			{			if (pStackData->bacpUpcall != NULL)				(*pStackData->bacpUpcall->bacpUpCallFunction) 								(pManagerStackObj, BAP_EVENT_CALL_REQUEST_STATUS,								port_info->port_number, NULL,								BAP_RESPONSE_NAK, &ptr_reason_string);			bap_send_callback_response (pluginState, bap_rx_packet->bap_id,					ptr_reason_string, BAP_RESPONSE_NAK, link_type, link_speed);			/* unreserve the previously reserved port */			pmPortUnreserve (port_info);             if (port_info != NULL)               {               pfwFree(port_info);	 		 /* free the port_info */               port_info = NULL;               }			return (FAIL);			}		/* save all port information */		sllInit ((SL_LIST *)&bap_buffer->port_list);     	sllPutAtTail ((SL_LIST *)&bap_buffer->port_list, 				(SL_NODE *)port_info);		bap_buffer->status = BAP_CALL_REQUEST_ACCEPTED; 		bap_store_and_select_phone_number (pluginState, packet, bap_buffer);		add_entry_to_list ((LINK *) &pStackData->call_request_send_queue,					(LINK *) bap_buffer);		/* send a positve Ack */ 				bap_send_callback_response (pluginState, bap_rx_packet->bap_id,					ptr_reason_string, response_code, link_type, link_speed);		/* activation of port */		if (callRequestPortActivate (pluginState, bap_buffer) == ERROR)				return FAIL;		}	else /* send NAK */		{		bap_send_callback_response (pluginState, bap_rx_packet->bap_id,					ptr_reason_string, response_code, link_type, link_speed);        if (port_info != NULL)           {           pfwFree(port_info);	 		 /* free the port_info */           port_info = NULL;           }		return (FAIL);		}    return (PASS);			}/******************************************************************************* bap_call_response_received - processes the received BAP call response packet** This routine is called to process the BAP call response packet. The received * BAP call response packet is matched with the call request packet sent, the * phone number is got and pmPortActivate () is called to dial the number. ** RETURNS: PASS, or FAIL */LOCAL TEST bap_call_response_received 	(    PFW_PLUGIN_OBJ_STATE * pluginState,	/* plugin object state in manager stack */    M_BLK_ID packet						/* packet received */	)	{	BAP_BUFFER * ptr_matching_request = NULL;	BAP_PHONE_DELTA_OPTION * ptr_phone_delta_option = NULL;	BAP_REASON_OPTION * ptr_reason_option = NULL;    BAP_CALL_RESPONSE_PACKET * bap_rx_packet = NULL;    BAP_CALL_REQUEST_PACKET * call_rq_packet = NULL;	PORT_CONNECTION_INFO * port_info = NULL;	char * ptr_reason_string = NULL;	char   reason_string[256];	BYTE response_code;	PFW_STACK_OBJ * pManagerStackObj = pluginState->stackObj;    BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *)pluginState->stackData;    bap_rx_packet = mtod (packet, BAP_CALL_RESPONSE_PACKET *);	/* Whenver a call request is placed an entry is added to the             */    /* call_request_send_queue. Incoming packet's ID is checked for any of   */	/* matching entry existence in call_request_send_queue					 */	#ifdef PPP_DEBUG    logMsg ("BAP Rx: BAP Call Response Packet: ID %d  Length %d  Code %d \n",\			bap_rx_packet->bap_id, ntohs(bap_rx_packet->bap_length), \			bap_rx_packet->bap_response_code, 4, 5, 6);#endif /* PPP_DEBUG */	ptr_matching_request = bap_match_received_response_to_outstanding_request 							((LINK *) &pStackData->call_request_send_queue, 								bap_rx_packet->bap_id);	/* If response is not matching any of our request placed then return fail */	if (ptr_matching_request == NULL)		{#ifdef PPP_DEBUG        logMsg ("BAP Rx: Illegal Call Response or Request might been dropped due \                    to Favored Peer: ID %d\n",bap_rx_packet->bap_id, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */		return (PASS);		}	port_info = (PORT_CONNECTION_INFO *)						SLL_FIRST (&ptr_matching_request->port_list); 	if (port_info == NULL)		{		logMsg ("BAP Rx: For Call Response packet Port Info is NULL \n",1,2,3,4,5,6);		return FAIL;		}	/* If already responded for the request then need not reply, return */	if (ptr_matching_request->status == BAP_CALL_REQUEST_ACCEPTED)		{#ifdef PPP_DEBUG        logMsg ("BAP Rx: Duplicate Call Response Packet of ID %d \n",\                            bap_rx_packet->bap_id, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */		return (PASS);		}	/* Cancel the timer and reset number_of_bap_call_requests to zero */	pfwTimerCancel (pStackData->callRequestRetryTimer);	pStackData->number_of_bap_call_requests = 0;	response_code = bap_rx_packet->bap_response_code;	/* If response is negative ACK then delete request addedd in the */	/* call_request_send_queue 			 							 */	if (response_code != BAP_RESPONSE_ACK)		{		if (pStackData->bacpUpcall != NULL)			{			(*pStackData->bacpUpcall->bacpUpCallFunction) 						(pManagerStackObj, BAP_EVENT_CALL_REQUEST_STATUS,						port_info->port_number, NULL,						response_code, &ptr_reason_string);			}		/* unreserve the previously reserved port */		pmPortUnreserve (port_info);

⌨️ 快捷键说明

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