📄 pppbaprx.c
字号:
/* pppbaprx.c - BAP received packet processing *//* Copyright 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02m,13may03,ijm fixed diab build warnings02l,22oct02,ijm include mpP.h02k,06aug02,jr fixed build warnings 02j,23feb02,jr setting the pointers to NULL after freeing02i,16feb02,jr Formatted the Debug Messages and initialized the local variables as part of the memory reduction process01h,05nov01,as code cleanup to support an extra parameter in bacpUpcall01g,16oct01,as in bap_call_request_received on failure of pmPortActivateAndWait added port information as parameter to bap_send_call_status_indication01f,08oct01,as addded support to multiple phone delta option 01e,30jun01,as reason string validation in function bap_callback_request_received favored peer NAK function chnged to bap_callback_request_received01d,19jun01,sd removed the unused variables for warning free compilation01c,19jun01,sd included listutls.h,pppInterfaces.h for warning free compilation01b,01may01,as incoming packet was made contiguous in bap_packet_received ()01a,16feb01,as created*//* DESCRIPTIONThis module implements the BAP packet receive functionality. After receivingvarious BAP packet it check for various error conditions on received packet.Based on the decision on BAP Header Code respective receive function in thereceive module is called with the received M_BLK_ID packet.These functions in receive module also decides on response packet that need to be sent for the incoming request.For this it uses various packet send functions in the send module to reply the request.INCLUDE FILES pppBacpComponentP.h, bapsend.h*/#include "private/ppp/pppBacpComponentP.h"#include "private/ppp/bapsend.h"#include "private/ppp/listutls.h"#include "ppp/pppInterfaces.h"#include "ppp/portmanager.h" #include "private/ppp/mpP.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*//* locals and forwards */LOCAL TEST bap_call_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST bap_call_response_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST bap_callback_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST bap_callback_response_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST bap_link_drop_query_request_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST bap_link_drop_query_response_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST bap_call_status_indication_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST bap_call_status_response_received (PFW_PLUGIN_OBJ_STATE *pluginState, M_BLK_ID packet);LOCAL TEST bap_code_zero_received (PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet);LOCAL FPTR_BAP_PACKET_RECEIVED bap_received_packet_processors[] = { bap_code_zero_received, bap_call_request_received, bap_call_response_received, bap_callback_request_received, bap_callback_response_received, bap_link_drop_query_request_received, bap_link_drop_query_response_received, bap_call_status_indication_received, bap_call_status_response_received };LOCAL BAP_TLV_OPTION * bap_find_option_in_packet (M_BLK_ID packet, enum BAP_OPTION_TYPE option_type, enum BAP_PHONE_DELTA_TYPES suboption_type);LOCAL void bap_store_and_select_phone_number (PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet, BAP_BUFFER *bap_buffer); LOCAL STATUS callRequestPortActivate (PFW_PLUGIN_OBJ_STATE * pluginState, BAP_BUFFER * bap_buffer);LOCAL void removePortInfoFromBapBuffer (SL_LIST * portList, PFW_STACK_OBJ * activeLinkStackObj);LOCAL STATUS checkForLocalPhoneNumberInPortInfo (PFW_PLUGIN_OBJ_STATE * pluginState, BYTE id, SL_LIST * portList);LOCAL void unReservePortAndMemory (SL_LIST * portList);/******************************************************************************** bap_code_zero_received - */LOCAL TEST bap_code_zero_received ( PFW_PLUGIN_OBJ_STATE * pluginState, M_BLK_ID packet ) { logMsg("bap_code_zero_received Invalid packet with Code 0 for BAP \ \n",1,2,3,4,5,6); return FAIL; }/******************************************************************************** bapSetReceiveFunctions - set receive function pointers*/void bapSetReceiveFunctions ( PPP_BACP_COMPONENT * bacpComponent ) { bacpComponent->fptr_bap_packet_received = bap_received_packet_processors; }/******************************************************************************** bap_packet_received - processes the received BAP packet*/TEST bap_packet_received ( PFW_PLUGIN_OBJ_STATE * pluginState, /* plugin object state in manager stack */ M_BLK_ID packet /* packet received */ ) { BYTE packetCode; USHORT number_of_bytes_rxed; BAP_PACKET *sptr_bap_rx_packet = NULL; USHORT pppPacketLength; M_BLK_ID contiguousPacket = packet; BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pluginState->stackData; PPP_BACP_COMPONENT * bacpComponent = (PPP_BACP_COMPONENT *)pluginState->pluginObj; if (pluginState == NULL || packet == NULL) {#ifdef PPP_DEBUG logMsg ("BAP Rx: Packet or pluginState is NULL \n",\ 1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ return FAIL; } if (pStackData->stateData.state != PPP_OPENED_STATE) {#ifdef PPP_DEBUG logMsg ("BAP Rx: Illegal PPP state \n",1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ netMblkClChainFree (packet); /* free the incoming packet */ return FAIL; } sptr_bap_rx_packet = mtod(packet, BAP_PACKET *); /* If the received packet is chained make it to single contiguous packet */ if (packet->mBlkHdr.mNext != NULL) { number_of_bytes_rxed = packet->mBlkPktHdr.len; contiguousPacket = m_pullup (packet, ntohs(sptr_bap_rx_packet->bap_header.length)); if (contiguousPacket == NULL) {#ifdef PPP_DEBUG logMsg ("BAP Rx: m_pullup () Failed \n", 1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ return FAIL; } sptr_bap_rx_packet = mtod (contiguousPacket, BAP_PACKET *); } else number_of_bytes_rxed = packet->mBlkHdr.mLen; pppPacketLength = ntohs (sptr_bap_rx_packet->bap_header.length);#ifdef PPP_DEBUG logMsg ("BAP Rx: Packet Type: %d Length: %d ID: %d\n",\ sptr_bap_rx_packet->bap_header.code,\ pppPacketLength,\ sptr_bap_rx_packet->bap_header.id, 4, 5, 6);#endif /* PPP_DEBUG */ if (pppPacketLength != (number_of_bytes_rxed - sizeof(PPP_HEADER))) { logMsg ("BAP: Illegal Packet Length %d \n",pppPacketLength,2,3,4,5,6); netMblkClChainFree (contiguousPacket); /* free the incoming packet */ return PASS; } /* accept PPP packets of length < local MRRU OR default MRRU */ if ((pppPacketLength > pStackData->bundleLocalMRRU) && (pppPacketLength != DEFAULT_MAXIMUM_MRRU)) {#ifdef PPP_DEBUG logMsg ("BAP Rx: Packet dropped: Length %d, ID %d\n",pppPacketLength,\ sptr_bap_rx_packet->bap_header.id, 3, 4, 5, 6);#endif /* PPP_DEBUG */ netMblkClChainFree (contiguousPacket); /* free the incoming packet */ return PASS; } packetCode = sptr_bap_rx_packet->bap_header.code; /* * Here received packet is freed and stastics counter is updated * and FAIL is return */ if ((packetCode > NUMBER_OF_BAP_PACKET_TYPES) || (packetCode == (BYTE) 0x00)) {#ifdef PPP_DEBUG logMsg ("BAP Rx: Illegal Packet Code %d for stack: 0x%x\n",\ packetCode, (UINT32)pluginState->stackObj, 3, 4, 5, 6);#endif /* PPP_DEBUG */ ++pStackData->link_quality_counters.ifInErrors; pStackData->link_quality_counters.InGoodOctets -= number_of_bytes_rxed; netMblkClChainFree (contiguousPacket); /* free the incoming packet */ return FAIL; } if ((*bacpComponent->fptr_bap_packet_received[packetCode]) (pluginState,contiguousPacket) == FAIL) { ++pStackData->bap_statistics.number_of_rx_packets; ++pStackData->bap_statistics.number_of_control_rx_packets[packetCode]; pStackData->bap_statistics.number_of_rx_bytes += number_of_bytes_rxed; netMblkClChainFree (contiguousPacket); /* free the incoming packet */ return FAIL; } ++pStackData->bap_statistics.number_of_rx_packets; ++pStackData->bap_statistics.number_of_control_rx_packets[packetCode]; pStackData->bap_statistics.number_of_rx_bytes += number_of_bytes_rxed; netMblkClChainFree (contiguousPacket); /* free the incoming packet */ return PASS; }/******************************************************************************* bap_call_request_received - processes the received BAP call request packet** This routine is called to process the BAP call request packet.The received * BAP call request packet is verified against duplication and race condition. * The port manager functions are then called to reserve a port and wait for * the call from the peer. A call back request packet is constructed with the * received options in the call request packet and copied into * callback_request_send_queue (as this is equivalent to sending a * call back request).** RETURNS: PASS, or FAIL */LOCAL TEST bap_call_request_received ( PFW_PLUGIN_OBJ_STATE * pluginState, /* plugin object state in manager stack */ M_BLK_ID packet /* packet received */ ) { BAP_LINK_TYPE_OPTION * ptr_link_option = NULL; BAP_REASON_OPTION * ptr_reason_option = NULL; BAP_NO_PHONE_NUMBER_NEEDED_OPTION * ptr_nophone_option = NULL; enum BAP_RESPONSE_CODE response_code = BAP_RESPONSE_ACK; BOOL request_from_callback_queue = FALSE; USHORT link_speed = 0; BYTE_ENUM(BAP_LINK_TYPES) link_type = BAP_ANALOG_TYPE; char * ptr_reason_string = NULL; char reason_string[256]; BAP_ACTIVE_PORT *ptr_active_port = NULL; SL_LIST tempPortList; PORT_CONNECTION_INFO *port_info = NULL; BAP_BUFFER * sptr_bap_buffer = NULL; BAP_BUFFER * bap_buffer = NULL; BAP_CALL_REQUEST_PACKET * bap_rx_packet = NULL; PFW_STACK_OBJ * pLinkStackObj = NULL; PFW_STACK_OBJ * pManagerStackObj = pluginState->stackObj; BACP_STACK_DATA * pStackData = (BACP_STACK_DATA *)pluginState->stackData; PFW_OBJ * pfwObj = pluginState->pluginObj->pfwObj; USHORT numberOfEntries = 0; numberOfEntries = bap_number_of_active_port_entries ( (LINK *) &pStackData->active_port_queue); bap_rx_packet = mtod (packet, BAP_CALL_REQUEST_PACKET *);#ifdef PPP_DEBUG logMsg ("BAP Rx: Call Request Packet: ID %d\n",\ bap_rx_packet->bap_id, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ if (numberOfEntries == MAX_NO_OF_PPP_PORTS) {#ifdef PPP_DEBUG logMsg ("BAP Rx: Call Request could not be processed as Bundle 0x%x \ has reached to its MAX(%d) number of ports \n",\ (int)pManagerStackObj, numberOfEntries, 3, 4, 5, 6);#endif /* PPP_DEBUG */ bap_send_call_response (pluginState, bap_rx_packet->bap_id, "Reached MAX port for the Bundle", BAP_RESPONSE_FULL_NAK, 0, 0, NULL); return (PASS); } sptr_bap_buffer = bap_match_received_response_to_outstanding_request ( (LINK *) &pStackData->callback_request_send_queue, bap_rx_packet->bap_id); /* If you have already received the request and responded then reply again */ if (sptr_bap_buffer != NULL) {#ifdef PPP_DEBUG logMsg ("BAP Rx: Duplicate Call 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_call_response (pluginState, bap_rx_packet->bap_id, "Retransmission", BAP_RESPONSE_ACK, port_info->port_type, port_info->port_speed, &sptr_bap_buffer->port_list); 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 peer is the \ Favored-Peer \n",1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ if (request_from_callback_queue)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -