📄 portmanagerserial.c
字号:
/* portManagerSerial.c - BAP Port Manager Source File *//* Copyright 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02f,12may03,ijm fixed debug message02e,06aug02,jr fixed build warnings 02d,01may02,as converted all printf to logMsg02c,23feb02,ak setting the pointers to NULL after freeing02b,07nov01,as added cleanup operation while deleting port in pmPortListDelete02a,05nov01,as removed pfwStackDelete and mpRemovePortToBundleMapping while unresrving the port01c,08oct01,as added pmFindAndReserveMultiplePort and addNextPortInfo for multiple phone number option support01b,19jun01,sd included taskLib.h for warning free compilation01a,14feb01,nts created. *//*DESCRIPTIONThis module implements the PORT MANAGER functions which are used to manage thephysical port in a BACP system. These functions provides only a model and neednot be strictly followed. The operations performed within each of these port manager functions can be changed based on system requirement.It supports functions - To add new ports to the Port Manager list. - To find and reserve a port from the pool of free ports. - To unreserve the previously reserve port. - To delete the stack associated for each port. - To activate and open the connection on a link. - To print the list of available ports in the system.This file contains code for activating and establishing a connection on a serial port. The function pmPortActivate () MUST be changed to support themodem dial-in and dial-out connections.*//* includes */#include "vxWorks.h"#include "taskLib.h"#include "stdio.h"#include "string.h"#include "sllLib.h"#include "logLib.h"#include "ppp/kstart.h"#include "pfw/pfw.h"#include "ppp/kbacpif.h"#include "pfw/pfwStack.h"#include "ppp/mpAPI.h"#include "ppp/pppInterfaces.h"#include "ppp/portmanager.h"/* globals */SL_LIST portList;IMPORT PFW_PROFILE_OBJ * pppSysProfile;IMPORT PFW_PROFILE_OBJ * pppSysProfile;/* locals */LOCAL STATUS pmPortListSearch (USHORT portNumberToSearch);#if 0LOCAL void addNextPortInfo (PFW_OBJ * pfwObj, SL_LIST * portListToReserve);#endif/********************************************************************************* pmPortFindAndReserve - select a port from a pool of free ports and reserve it* * This function is used to select a port from a pool of free ports and reserve* for use by the calling function. It searches through the list of available * ports in the system for a free port which can support the type of port and* requested bandwidth. It fills the PORT_CONNECTION_INFO and returns OK, * once the port is found. If there is no port present which can serve the * requested bandwidth and port_type, then it retuns an ERROR.** RETURNS: OK or ERROR.** SEE ALSO: pmPortUnreserve, pmPortActivate, pmPortToListAdd*/STATUS pmPortFindAndReserve ( PORT_CONNECTION_INFO *pPortToReserve ) { LINK_INFO *pLinkInfo; pLinkInfo = (LINK_INFO *)SLL_FIRST (&portList); while (pLinkInfo != NULL) { if ((pLinkInfo->bandwidth == pPortToReserve->port_speed) && (pLinkInfo->port_dial_type == pPortToReserve->port_dial_type || pLinkInfo->port_dial_type == PORT_DIAL_IN_AND_OUT) && pLinkInfo->isPortUsed == FALSE) { if (pPortToReserve->is_port_type_specified == TRUE) { if (pLinkInfo->port_type == pPortToReserve->port_type) { pLinkInfo->isPortUsed = TRUE; pPortToReserve->linkProfileObj = pLinkInfo->pLinkProfileObj; pPortToReserve->port_number = pLinkInfo->port_number; pPortToReserve->port_type = pLinkInfo->port_type; strcpy (pPortToReserve->port_local_phone_number, pLinkInfo->port_local_phone_number); strcpy (pPortToReserve->port_remote_phone_number, pLinkInfo->port_remote_phone_number); strcpy (pPortToReserve->port_subaddress_phone_number, pLinkInfo->port_subaddress_phone_number); strcpy (pPortToReserve->port_unique_digits_phone_number, pLinkInfo->port_unique_digits_phone_number); pPortToReserve->port_unique_digits_phone_number_length = pLinkInfo->port_unique_digits_phone_number_length; pPortToReserve->port_status = pLinkInfo->port_dial_status; return OK; } } else { pLinkInfo->isPortUsed = TRUE; pPortToReserve->linkProfileObj = pLinkInfo->pLinkProfileObj; pPortToReserve->port_number = pLinkInfo->port_number; pPortToReserve->port_type = pLinkInfo->port_type; strcpy (pPortToReserve->port_local_phone_number, pLinkInfo->port_local_phone_number); strcpy (pPortToReserve->port_remote_phone_number, pLinkInfo->port_remote_phone_number); strcpy (pPortToReserve->port_subaddress_phone_number, pLinkInfo->port_subaddress_phone_number); strcpy (pPortToReserve->port_unique_digits_phone_number, pLinkInfo->port_unique_digits_phone_number); pPortToReserve->port_unique_digits_phone_number_length = pLinkInfo->port_unique_digits_phone_number_length; pPortToReserve->port_status = pLinkInfo->port_dial_status; return OK; } } pLinkInfo = (LINK_INFO *)SLL_NEXT (pLinkInfo); } #ifdef PPP_DEBUG logMsg ("Port with requested call type and bandwidth is not available\n",1,2,3,4,5,6); #endif return ERROR; }/********************************************************************************* pmFindAndReserveMultiplePort - select multiple port from a pool of free ports * and reserve it. This routine is called only for call-back request sent* and received call-request without No-PhoneNumber option.** By default memory is allocated only for one port connection info of the * parameter portListToReserve. If more port is needed to be by the implementation * then memory required for the PORT_CONNECTION_INFO should be allocated using * pfwMalloc from the framework. ** RETURNS: OK or ERROR.** SEE ALSO: pmPortUnreserve, pmPortActivate, pmPortToListAdd*/STATUS pmFindAndReserveMultiplePort ( PFW_OBJ * pfwObj, /* framework object */ SL_LIST * portListToReserve /* to store the reserved port info */ ) { LINK_INFO *pLinkInfo; PORT_CONNECTION_INFO * pPortToReserve; /* Get the first port information from the Port Manager's port-list */ pLinkInfo = (LINK_INFO *)SLL_FIRST (&portList); /* Get the information about the port to reserve */ pPortToReserve = (PORT_CONNECTION_INFO *)SLL_FIRST (portListToReserve); while (pLinkInfo != NULL) { if ((pLinkInfo->bandwidth == pPortToReserve->port_speed) && (pLinkInfo->port_dial_type == pPortToReserve->port_dial_type || pLinkInfo->port_dial_type == PORT_DIAL_IN_AND_OUT) && pLinkInfo->isPortUsed == FALSE) { if (pPortToReserve->is_port_type_specified == TRUE) { if (pLinkInfo->port_type == pPortToReserve->port_type) { pLinkInfo->isPortUsed = TRUE; pPortToReserve->linkProfileObj = pLinkInfo->pLinkProfileObj; pPortToReserve->port_number = pLinkInfo->port_number; pPortToReserve->port_type = pLinkInfo->port_type; strcpy (pPortToReserve->port_local_phone_number, pLinkInfo->port_local_phone_number); strcpy (pPortToReserve->port_remote_phone_number, pLinkInfo->port_remote_phone_number); strcpy (pPortToReserve->port_subaddress_phone_number, pLinkInfo->port_subaddress_phone_number); strcpy (pPortToReserve->port_unique_digits_phone_number, pLinkInfo->port_unique_digits_phone_number); pPortToReserve->port_unique_digits_phone_number_length = pLinkInfo->port_unique_digits_phone_number_length; pPortToReserve->port_status = pLinkInfo->port_dial_status; pPortToReserve->linkStackObj = NULL; #ifdef PPP_DEBUG logMsg ("Reserved the Port %d\n",pPortToReserve->port_number,2,3,4,5,6);#endif#if 0 /* Add one more port information if required */ addNextPortInfo (pfwObj, portListToReserve);#endif return OK; } } else { pLinkInfo->isPortUsed = TRUE; pPortToReserve->linkProfileObj = pLinkInfo->pLinkProfileObj; pPortToReserve->port_number = pLinkInfo->port_number; pPortToReserve->port_type = pLinkInfo->port_type; strcpy (pPortToReserve->port_local_phone_number, pLinkInfo->port_local_phone_number); strcpy (pPortToReserve->port_remote_phone_number, pLinkInfo->port_remote_phone_number); strcpy (pPortToReserve->port_subaddress_phone_number, pLinkInfo->port_subaddress_phone_number); strcpy (pPortToReserve->port_unique_digits_phone_number, pLinkInfo->port_unique_digits_phone_number); pPortToReserve->port_unique_digits_phone_number_length = pLinkInfo->port_unique_digits_phone_number_length; pPortToReserve->port_status = pLinkInfo->port_dial_status; pPortToReserve->linkStackObj = NULL; #ifdef PPP_DEBUG logMsg ("Reserved the Port %d\n",pPortToReserve->port_number,2,3,4,5,6);#endif#if 0 /* Add one more port information if required */ addNextPortInfo (pfwObj, portListToReserve);#endif return OK; } } pLinkInfo = (LINK_INFO *)SLL_NEXT (pLinkInfo); } #ifdef PPP_DEBUG logMsg ("Port with requested call type and bandwidth is not available \n",1,2,3,4,5,6); #endif return ERROR; }#if 0/********************************************************************************* addNextPortInfo - Add next port information ** RETURNS: N/A** SEE ALSO: pmPortReserve, pmPortUnreserve*/LOCAL void addNextPortInfo ( PFW_OBJ * pfwObj, /* framework object */ SL_LIST * portListToReserve /* to store the reserved port info */ ) { PORT_CONNECTION_INFO * pPortReserved, * pPortToAdd; /* Get the information about the port to reserve */ pPortReserved = (PORT_CONNECTION_INFO *)SLL_FIRST (portListToReserve); /* Explicitly add next phone number information */ if ((pPortToAdd = (PORT_CONNECTION_INFO *)pfwMalloc (pfwObj, sizeof(PORT_CONNECTION_INFO))) == NULL) { logMsg ("addNextPortInfo: could not allocate memory for new port connection info \n",1,2,3,4,5,6); return; } /* Copy the port information */ memcpy (pPortToAdd, pPortReserved, sizeof(PORT_CONNECTION_INFO)); /* Update the port information */ pPortToAdd->next = NULL; pPortToAdd->port_speed = 9600; pPortToAdd->port_number = 11; pPortToAdd->port_type = BAP_ANALOG_TYPE; strcpy (pPortToAdd->port_local_phone_number, "886"); /* 886 commented */ strcpy (pPortToAdd->port_remote_phone_number, ""); strcpy (pPortToAdd->port_subaddress_phone_number, ""); pPortToAdd->port_unique_digits_phone_number_length = 3; strcpy (pPortToAdd->port_unique_digits_phone_number, ""); pPortToAdd->linkProfileObj = pfwProfileCreate ("pppTempProfile", pppSysProfile, 0); sllPutAtTail ((SL_LIST *)portListToReserve, (SL_NODE *)pPortToAdd); } #endif/********************************************************************************* pmPortActivate - activate the reserved port** This function is used to activate a reserved port and establish the connection * on the reserved port. If populates a stack using the pfwStackAdd () function* for the given profile object and calls apiMpLinkAssign () function to assign* the link to a particular bundle in the MP system.* This function should be modified to support modem dial-in and dial-out* features.** RETURNS: Pointer to the PFW_STACK_OBJ structre or NULL** SEE ALSO: pmPortReserve, pmPortUnreserve*/PFW_STACK_OBJ * pmPortActivate ( SL_LIST *portListToCall, PFW_STACK_OBJ *pBundleId ) { PFW_STACK_OBJ *pPortStack; PORT_CONNECTION_INFO *pPortConnectionInfo; pPortConnectionInfo = (PORT_CONNECTION_INFO *) SLL_FIRST (portListToCall); pPortStack = pfwStackAdd (pPortConnectionInfo->linkProfileObj, NULL, NULL); if (pPortStack == NULL) { logMsg ("\n PM PortActivate : stack Add returned NULL \n",1,2,3,4,5,6); return (NULL); } if (apiMpLinkAssign (pPortStack, pBundleId) != OK) { logMsg ("\n PM PortActivate : Assign link to bundle failed \n",1,2,3,4,5,6); return (NULL); } /* save the stack object in the port connection info */ pPortConnectionInfo->linkStackObj = pPortStack; /* open the connection */ taskDelay (100);#ifdef PPP_DEBUG logMsg ("\n PM PortActivate : Calling PPP Connection open \n",1,2,3,4,5,6);#endif pppConnectionOpen (pPortStack, NULL, NULL); return pPortStack; }/********************************************************************************* pmPortActivateAndWait - activate the reserved port and wait for the * peer to call** It populates a stack using the pfwStackAdd () function for the given profile * object and calls apiMpLinkAssign () function to assign
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -