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

📄 portmanagermodem.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* portManagerModem.c - BAP Port Manager Source File *//* Copyright 1999 Wind River Systems, Inc. *//***********************************************************	Modified portmanager.c adding modem functionalities 	for BAP to bring the link up and down./***********************************************************/#include "copyright_wrs.h"/*modification history--------------------01b,18apr01,as   addition of modem funtionalities for BAP to bring the link                 UP/DOWN01a,14feb01,nts  created.*//*DESCRIPTIONThis module implements the PORT MANAGER functions which are used to manage thephysical port in a BACP system. 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 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 connected by modem. Modem dial out functions are provided.*//* defines */#define USR_SPORTSTER_DEF_INIT_STRING  "AT&F1S0=0S7=60E1V1&K3X4"#define MODEM_CONNECT           "CONNECT"/* includes */#include "vxWorks.h"#include "stdio.h"#include "sllLib.h"#include "ppp/kstart.h"#include "pfw/pfw.h"#include "ppp/kbacpif.h"#include "pfw/pfwStack.h"/* globals */SL_LIST				portList;/* locals */LOCAL STATUS pmPortListSearch (USHORT portNumberToSearch);LOCAL STATUS pmModemActivate (PFW_STACK_OBJ *pPortStack,			SL_LIST 	  portInfo);/********************************************************************************* 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;	BOOL	  port_type_requirement_matched;		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);		}		printf ("Port with requested call type and bandwidth is not available\n");		return ERROR;	}/********************************************************************************* pmPortActivate - activate the reserved port** This function is used to activate a reserved port and establish the connection * on the reserved port. It 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.** RETURNS: Pointer to the PFW_STACK_OBJ structre or NULL** SEE ALSO: pmModemActivate*/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 (apiMpLinkAssign (pPortStack, pBundleId) != OK)		{		printf ("\n PM PortActivate : Assign link to bundle failed \n");		return (NULL);		}	/* save the stack object in the port connection info */	pPortConnectionInfo->linkStackObj = pPortStack; 	/* activate the modem (dial-out) and open the connection */	if (pmModemActivate (pPortStack, portListToCall) == ERROR)		return NULL;	return pPortStack;    }/********************************************************************************* pmModemActivate - activate the modem connected to the reserved port ** RETURNS: OK / ERROR*/LOCAL STATUS pmModemActivate 	(	PFW_STACK_OBJ *pPortStack,	SL_LIST 	  portToCall		)	{	PORT_CONNECTION_INFO *pPortConnectionInfo;	char	* initString;	char	* modemNumber;	char	* modemDialResponse;	initString = (char *)malloc (100);    modemNumber = (char *)malloc (100);    modemDialResponse = (char *)malloc (100);	pPortConnectionInfo = (PORT_CONNECTION_INFO *)SLL_FIRST (&portToCall);	strcpy (initString, 		USR_SPORTSTER_DEF_INIT_STRING); 	/* fill in the PhoneNumber to be called */	strcpy (modemNumber, pPortConnectionInfo->port_remote_phone_number); 	strcpy (modemDialResponse, MODEM_CONNECT);	if (modemConnectTest(initString, modemNumber, modemDialResponse, pPortStack) == OK)		{		printf(" modemConnectTest OK \n");		return OK;		}	printf("modemConnectTest Failed \n");	return ERROR;	}/********************************************************************************* 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* the link to a particular bundle in the MP system. This function also * activates the reserved port and waits for the peer to call for making the * physical link up on the reserved port connected to a modem. ** RETURNS: Pointer to the PFW_STACK_OBJ structre or NULL** NOTE : Modem dial-in function has to be called to bring up the physical link and*        call pppConnectionOpen.*/PFW_STACK_OBJ *pmPortActivateAndWait    (	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 (apiMpLinkAssign (pPortStack, pBundleId) != OK)		{		printf ("Assign link to bundle failed \n");		return (NULL);		}	/* save the stack object in the port connection info */	pPortConnectionInfo->linkStackObj = pPortStack; 	/* modem dial in function to be called here */	return pPortStack;    }/********************************************************************************* pmPortUnreserve - unreserve the port** This function is used to unreserve a previously reserved port. It takes the * PORT_CONNECTION_INFO as the input parameter and it searches through the list* of ports available in the system. It marks the PORT as unreserved once it * finds the matching port type, bandwidth and number and returns OK. If the 

⌨️ 快捷键说明

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