📄 baputil.c
字号:
/* baputil.c - bap utils *//* Copyright 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02e,13may03,ijm fixed diab build warnings02d,17apr02,jr setting the pointers to NULL after freeing02c,08oct01,as added copyPortInfoToBapBuffer for multiple phone delta option02b,02may01,as updated bapPrintOptionsInPacket ()01a,16feb01,as created*//*DESCRIPTIONThis module implements the BAP utility function that might be used by both send module and receive BAP module. These utility functions mainly used to search through the various queues maintained by BACP component for the matching input entry needed to be searched. Queue like active_port_queue, call_request_send_queue, callback_request_send_queue, call_indication_send_queue and link_drop_request_send_queueINCLUDE FILES pfwProfile.h, vbacputil.h*//**$Log:: /Rtrware/devdrvrs/ppp/pppoptn $ * * 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 */#include "stdio.h"#include "stdlib.h"#include "pfw/pfwProfile.h"#include "pfw/pfwMemory.h"#include "private/ppp/vbacputil.h"#include "private/ppp/listutls.h"/******************************************************************************** bacpDupPkt - DUP the given packet ** RETURNS: The the duplicated MBLK for the packet if successful, else it frees * the original packet and returns NULL*/M_BLK_ID bacpDupPkt ( M_BLK_ID pPacket /* packet to DUP */ ) { NET_POOL_ID pNetPool = NULL; M_BLK_ID pDupPkt = NULL; if ((pPacket == NULL) || ((pNetPool = MBLK_TO_NET_POOL (pPacket)) == NULL)) return NULL; /* dup the given packet/chain */ if (pPacket->mBlkHdr.mNext != NULL) { if ((pDupPkt = netMblkChainDup (pNetPool, pPacket, 0, M_COPYALL, M_DONTWAIT)) == NULL) return NULL; } else { /* get a new MBLK */ if ((pDupPkt = netMblkGet (pNetPool, M_DONTWAIT, MT_DATA)) == NULL) return NULL; if (netMblkDup (pPacket, pDupPkt) == NULL) { netMblkFree (pNetPool, pDupPkt); return NULL; } } return pDupPkt; }/******************************************************************************** bap_match_received_response_to_outstanding_request - * matches the received id to the sent request packet** This routine is called to match the received BAP packet identifier to the * bap_id in the elements of the linked list of ptr_linked_list. It gets a * pointer to the first entry in the list to be searched and searches the list * for a match untill end of the list.** RETURNS pointer to BAP_BUFFER on success or NULL on failure*/BAP_BUFFER * bap_match_received_response_to_outstanding_request ( LINK * ptr_linked_list, /* list to be searched */ BYTE id /* BAP packet id */ ) { BAP_BUFFER *sptr_bap_buffer; BAP_RESPONSE_PACKET *sptr_response_packet; sptr_bap_buffer = (BAP_BUFFER *) get_pointer_to_first_entry_in_list (ptr_linked_list); while (sptr_bap_buffer != NULL) { sptr_response_packet = mtod (sptr_bap_buffer->bap, BAP_RESPONSE_PACKET *); if (sptr_response_packet->bap_id == id) break; sptr_bap_buffer = (BAP_BUFFER *) get_pointer_to_next_entry_in_list ((LINK *) sptr_bap_buffer); } return (sptr_bap_buffer); }/******************************************************************************** bap_find_outstanding_request_for_port - * find any outstanding request for the port** This routine is called to match the port_number in the elements of the linked * list of ptr_linked_list. It searches the list for a match of port-number, * if found, a pointer to the matching buffer is returned else NULL is returned.** RETURNS pointer to BAP_BUFFER on success or NULL on failure*/BAP_BUFFER * bap_find_outstanding_request_for_port ( LINK * ptr_linked_list, /* list to be searched */ USHORT portNumber /* port number */ ) { BAP_BUFFER *sptr_bap_buffer; PORT_CONNECTION_INFO *port_info = NULL; sptr_bap_buffer = (BAP_BUFFER *) get_pointer_to_first_entry_in_list (ptr_linked_list); while (sptr_bap_buffer != NULL) { port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (&sptr_bap_buffer->port_list); if (port_info->port_number == portNumber) break; sptr_bap_buffer = (BAP_BUFFER *) get_pointer_to_next_entry_in_list ((LINK *) sptr_bap_buffer); } return (sptr_bap_buffer); }/******************************************************************************** bap_find_unacknowledged_outstanding_request - * find any unacknowledged outstanding request** This routine is called to find if there is any unacknowledged request in the * elements of the linked list of ptr_linked_list. It gets a pointer to the first * entry in the list to be searched and searches the list for an element with * status not equal to BAP_CALL_REQUEST_ACCEPTED, ** RETURNS pointer to BAP_BUFFER on success or NULL on failure*/BAP_BUFFER * bap_find_unacknowledged_outstanding_request ( LINK * ptr_linked_list /* list to be searched */ ) { BAP_BUFFER *sptr_bap_buffer; sptr_bap_buffer = (BAP_BUFFER *) get_pointer_to_first_entry_in_list (ptr_linked_list); while (sptr_bap_buffer != NULL) { if (sptr_bap_buffer->status != BAP_CALL_REQUEST_ACCEPTED) break; sptr_bap_buffer = (BAP_BUFFER *) get_pointer_to_next_entry_in_list ((LINK *) sptr_bap_buffer); } return (sptr_bap_buffer); }/******************************************************************************** bap_find_active_port_with_this_bandwidth - * find a active port with the given bandwidth* * This routine is called to find if there is any active port with the given * bandwidth in the elements of the linked list of ptr_linked_list. It gets a * pointer to the first entry in the list to be searched and searches the list * for the matching bandwidth.** RETURNS active_port_entry on success and NULL otherwise*/BAP_ACTIVE_PORT * bap_find_active_port_with_this_bandwidth ( LINK * ptr_linked_list, /* list to be searched */ USHORT bandwidth /* bandwidth */ ) { BAP_ACTIVE_PORT *sptr_active_port; BAP_ACTIVE_PORT *port_to_delete = NULL; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_first_entry_in_list (ptr_linked_list); /* try exact match */ while (sptr_active_port != NULL) { if (bandwidth == sptr_active_port->port_speed) { port_to_delete = sptr_active_port; break; } sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_next_entry_in_list ((LINK *) sptr_active_port); } /* Try closest match not exceeding the BW to be deleted */ if (port_to_delete == NULL) { sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_first_entry_in_list (ptr_linked_list); while (sptr_active_port != NULL) { if (sptr_active_port->port_speed <= bandwidth) { if ((port_to_delete == NULL) || (sptr_active_port->port_speed > port_to_delete->port_speed)) { port_to_delete = sptr_active_port; } } sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_next_entry_in_list ((LINK *) sptr_active_port); } } return (port_to_delete); }/******************************************************************************** bap_find_active_port_with_this_stackobj - * to find a active port with the given stackObject** This routine is called to find if there is any active port with the given * stackObj. This routine finds an entry in the active port list for the * matching stackObj. If found returns a pointer to the BAP_ACTIVE_PORT. ** RETURNS active_port_entry on success and NULL otherwise*/BAP_ACTIVE_PORT * bap_find_active_port_with_this_stackobj ( LINK * ptr_linked_list, /* list to be searched */ PFW_STACK_OBJ * stackObj /* stack object to search */ ) { BAP_ACTIVE_PORT *sptr_active_port; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_first_entry_in_list (ptr_linked_list); while (sptr_active_port != NULL) { if (stackObj == sptr_active_port->linkStackObj) break; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_next_entry_in_list ((LINK *) sptr_active_port); } return (sptr_active_port); }/******************************************************************************** bap_find_active_port_with_this_portnumber - * to find a active port with the given portnumber** This routine is called to find if there is any active port with the given * portnumber. This routine finds an entry in the active port list for the * matching portnumber. If found returns a pointer to the BAP_ACTIVE_PORT. ** RETURNS active_port_entry on success and NULL otherwise*/BAP_ACTIVE_PORT * bap_find_active_port_with_this_portnumber ( LINK * ptr_linked_list, /* list to be searched */ USHORT portnumber /* portnumber to search */ ) { BAP_ACTIVE_PORT *sptr_active_port; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_first_entry_in_list (ptr_linked_list); while (sptr_active_port != NULL) { if (portnumber == sptr_active_port->port_number) break; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_next_entry_in_list ((LINK *) sptr_active_port); } return (sptr_active_port); }/******************************************************************************** bap_match_discriminator_and_active_port - * to find a active port with the given discriminator** This routine is called to find if there is any active port with the given * discriminator. This routine finds an entry in the active port list for the * matching local discriminator. If found returns a pointer to the * BAP_ACTIVE_PORT. ** RETURNS active_port_entry on success and NULL otherwise*/BAP_ACTIVE_PORT * bap_match_discriminator_and_active_port ( LINK * ptr_linked_list, /* list to be searched */ USHORT localDiscriminator /* discriminator */ ) { BAP_ACTIVE_PORT *sptr_active_port; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_first_entry_in_list (ptr_linked_list); while (sptr_active_port != NULL) { if (localDiscriminator == sptr_active_port->port_bacp_local_discr) break; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_next_entry_in_list ((LINK *) sptr_active_port); } return (sptr_active_port); }/******************************************************************************** bap_find_acknowledged_linkdrop_request_with_discriminator - * find the acknowledged linkdrop request** This routine is called to find if there is any acknowledged link drop requests.* It searches the list for status = BAP_LINK_DROP_ACCEPTED and match in discrimanator.* If found, a pointer to the buffer is returned else returns NULL.** RETURNS pointer to BAP_BUFFER on success or NULL on failure*/BAP_BUFFER * bap_find_acknowledged_linkdrop_request_with_discriminator ( LINK * ptr_linked_list, /* list to be searched */ USHORT localDiscriminator /* discriminator */ ) { BAP_BUFFER *sptr_bap_buffer; PORT_CONNECTION_INFO *port_info = NULL; sptr_bap_buffer = (BAP_BUFFER *) get_pointer_to_first_entry_in_list (ptr_linked_list); while (sptr_bap_buffer != NULL) { port_info = (PORT_CONNECTION_INFO *)SLL_FIRST (&sptr_bap_buffer->port_list); if ((sptr_bap_buffer->status == BAP_LINK_DROP_ACCEPTED) && (localDiscriminator == port_info->port_lcp_local_link_discriminator)) break; sptr_bap_buffer = (BAP_BUFFER *) get_pointer_to_next_entry_in_list ((LINK *) sptr_bap_buffer); } return (sptr_bap_buffer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -