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

📄 pppmodem.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* pppModem.c - modem support for PPP framework */ /* Copyright 1999 Wind River Systems, Inc. */ #include "copyright_wrs.h" /*modification history--------------------01e,18apr01,as	updated for modemConnectTest and modemDisconnectTest 				to support BAP port manager.01d,29sep00,sj  merging with TOR2_0-WINDNET_PPP-CUM_PATCH_201c,31jul00,adb  Merging with wrs.tor2_0.windNet_ppp.cum_patch01b,31may00,cn  corrected documentation.01a,19apr00,cn  created.*/ /*DESCRIPTIONThis component implements a generic library for a dial-up modem. It enables PPP sessions over modem dial-up line. To do so, it explots the interfacePPP_MODEM_INTERFACE implemented by the module pppSioAdapter.EXTERNAL INTERFACEThe external routines provided by this library are modemConnect () andmodemDisconnect ()..CS    STATUS modemConnect (PFW_STACK_OBJ * pStackObj,			 MODEM_CONN_DESC * pModemConnDesc);.CE.CS    STATUS modemDisconnect (PFW_STACK_OBJ * pStackObj,			    MODEM_CONN_DESC * pModemConnDesc);.CE INTERNALThis library contains conditional compilation switch MODEM_DEBUGIf defined, adds debug output routines and some test routines:modemConnectTest () and modemDisconnectTest ().INCLUDE FILES:  SEE ALSO*/ /* includes */ #include "vxWorks.h"#include "logLib.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "ctype.h"#include "memLib.h"#include "semLib.h"#include "sysLib.h"#include "intLib.h"#include "stdio.h" #include "string.h"#include "ioLib.h" #include "sysLib.h"#include "tickLib.h"#include "taskLib.h" #include "net/mbuf.h"#include "netBufLib.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwLayer.h"#include "pfw/pfwEvent.h"#include "pfw/pfwInterface.h"#include "pfw/pfwMemory.h"#include "pfw/pfwComponent.h"#include "ppp/pppInterfaces.h"#include "ppp/interfaces/pppModemInterface.h"/*  * US Robotics default init string:  * &F1		load hardware flow control configuration * S0=0		disable auto answer mode * S7=90	wait at most 90 seconds for a carrie * E1		echo is ON * V1		display verbal result codes * &H1		hardware flow control (CTS) * &I0		disable software flow control * &R2		hardware flow control (RTS) */#define USR_SPORTSTER_DEF_INIT_STRING         "AT&F1S0=0S7=90E1V1&H1&I0&R2"#define MODEM_HARD_INIT         "AT&F1"#define MODEM_INIT_OK           "OK"#define MODEM_CONNECT           "CONNECT"#define MODEM_MAX_STRLEN        50#define MODEM_TIMEOUT_INIT      5#define MODEM_TIMEOUT_CMD       5#define MODEM_TIMEOUT_DIAL      100 #define MODEM_DEBUG#ifdef MODEM_DEBUGUINT32 modemDbg = 0;    #define MODEM_LOG_MSG(p1, p2, p3, p4, p5, p6, p7)			\	if (modemDbg)							\	    logMsg ((p1), (p2), (p3), (p4), (p5), (p6), (p7))    #define MODEM_DEBUG_PRINT(p1)					\	printf p1#else /* MODEM_DEBUG */    #define MODEM_LOG_MSG(p1, p2, p3, p4, p5, p6, p7)    #define MODEM_DEBUG_PRINT(p1)#endif /* MODEM_DEBUG *//* globals */extern PFW_PROFILE_OBJ * pppSysProfile;#ifdef MODEM_DEBUGSTATUS modemConnectTest (char * initString, char * modemNumber,			 char * modemDialResponse, PFW_STACK_OBJ   * pModemStack);STATUS modemDisconnectTest (PFW_STACK_OBJ   * pModemStack);#endif /* MODEM_DEBUG */typedef struct modemConnDesc    {    UINT                        modemDialTimeout;    UINT                        modemCmdTimeout;    char                        * modemInitString;    char                        * modemNumber;    char                        * modemDialResponse;    void                 	(* modemConnCallback) (void *);    void                        * modemConnParm;    void                 	(* modemDisconnCallback) (void *);    void                        * modemDisconnParm;    } MODEM_CONN_DESC; STATUS modemConnect (PFW_STACK_OBJ * pStackObj,                     MODEM_CONN_DESC * pModemConnDesc); STATUS modemDisconnect (PFW_STACK_OBJ * pStackObj,			MODEM_CONN_DESC * pModemConnDesc); /* locals */#if 0LOCAL PFW_STACK_OBJ   * pModemStack = NULL;#endif LOCAL STATUS modemInit (PFW_PLUGIN_OBJ_STATE * pObjState,			PPP_MODEM_INTERFACE * pModemInterface,                        char * userInitString,                        UINT modemCmdTimeout); LOCAL STATUS modemDial (PFW_PLUGIN_OBJ_STATE * pObjState,			PPP_MODEM_INTERFACE * pModemInterface,                        char * phoneNumber,                        char * modemDialResponse,                        UINT modemDialTimeout); LOCAL STATUS modemHangup (PFW_PLUGIN_OBJ_STATE * pObjState,			  PPP_MODEM_INTERFACE * pModemInterface); LOCAL STATUS modemCommand (PFW_PLUGIN_OBJ_STATE	* pObjState, 			   PPP_MODEM_INTERFACE * pModemInterface, 			   char	* cmd,			   char	* rsp,			   UINT	rspBufLen,			   char	* goodRsp,			   UINT	timeout);LOCAL STATUS modemStringRead (PFW_PLUGIN_OBJ_STATE	* pObjState,			      PPP_MODEM_INTERFACE * pModemInterface,			      char * rsp,			      UINT rspBufLen,			      UINT timeout);LOCAL void modemConnCallback (void * modemConnParm);LOCAL void modemDisconnCallback (void * modemDisconnParm);/***************************************************************************** modemStringRead - read a string from a modem** This routine reads a string from a modem. Strings here has a specialized* meaning, in that they are terminated with special control characters* like <carriage return>, etc.** RETURNS: OK on success, ERROR otherwise*/LOCAL STATUS modemStringRead    (    PFW_PLUGIN_OBJ_STATE        * pObjState,    PPP_MODEM_INTERFACE         * pModemInterface,    char                        * rsp,    UINT                        rspBufLen,    UINT                        timeout    )    {    UCHAR       readChar;    UINT        readCharCount = 0;    UINT        timerStart = 0;    UINT        clockRate = 0;     timerStart = tickGet();    clockRate = sysClkRateGet();     while (TRUE)        {        static BOOL crCharReceived = FALSE;         /* check against the timeout */         if (((tickGet () - timerStart) / clockRate) >= timeout)            {            MODEM_LOG_MSG ("modem: timeout waiting for response\n",                           0, 0, 0, 0, 0, 0);            return (ERROR);            }          /* read the response */         if (pModemInterface->modemRead != NULL)            if (pModemInterface->modemRead (pObjState, &readChar, 1, timeout)                == ERROR)                {                MODEM_LOG_MSG ("modem error %x reading response \n",                                errno, 0, 0, 0, 0, 0);                return (ERROR);                }         if ((readChar < ' ') && (readChar != '\r') && (readChar != '\n'))            {            MODEM_LOG_MSG ("modem: ignoring control character %x \n",                            (int) readChar, 0, 0, 0, 0, 0);            continue;            }         if (readChar == '\r')            {            MODEM_LOG_MSG ("read 0x%x byte\n", (int) readChar, 0, 0, 0, 0, 0);            crCharReceived = TRUE;            continue;            }         if ((readChar == '\n') && crCharReceived)            {            MODEM_LOG_MSG ("read 0x%x byte\n", (int) readChar, 0, 0, 0, 0, 0);            MODEM_DEBUG_PRINT (("response = %s \n", rsp));            crCharReceived = FALSE;             /* null-terminate the response */             rsp [readCharCount] = '\0';            return (OK);            }        /* store read character */        rsp [readCharCount++] = readChar;         /* check on the buffer lenght */         if (readCharCount == (rspBufLen - 1))            {            rsp [readCharCount] = '\0';            return (OK);            }         MODEM_LOG_MSG ("read 0x%x byte\n", readChar, 0, 0, 0, 0, 0);        }     return (OK);    } /***************************************************************************** modemCommand - issue a command to a modem* * This routine issues a command to a modem and waits up to a timeout in seconds* for a response of up to rspBufLen characters. It finally compares the* response with the expected one.** RETURNS: OK on success, ERROR otherwise*/LOCAL STATUS modemCommand    (    PFW_PLUGIN_OBJ_STATE	* pObjState,    PPP_MODEM_INTERFACE		* pModemInterface,    char			* cmd,    char			* rsp,    UINT			rspBufLen,    char			* goodRsp,    UINT			timeout    )    {    BOOL	echoResponse = TRUE;	    if (cmd!=NULL)	{	/* flush any responses to previous commands or other data */	if (pModemInterface->modemIoctl != NULL)	    if ((* pModemInterface->modemIoctl) (pObjState, 						 MODEM_FLUSH, 						 0) == ERROR)	    return (ERROR);	MODEM_DEBUG_PRINT (("modem: command = %s\n", cmd));	if (pModemInterface->modemWrite != NULL)	    if (pModemInterface->modemWrite (pObjState, 					    cmd, 					    strlen (cmd)) != OK)		{		MODEM_LOG_MSG ("modem: error %d sending command\n", 				errno, 0, 0, 0, 0, 0);		return (ERROR);		}	}    /* do we need a response? */    if (rsp==NULL || !rspBufLen)	{ 	return (OK);	}    while (echoResponse)	{	if (modemStringRead (pObjState, pModemInterface, 			     rsp, rspBufLen, timeout) == ERROR)	    return (ERROR);	MODEM_DEBUG_PRINT (("modem response %s to command %s \n", rsp, cmd));	/* is echo on? */	if (cmd!=NULL && !strncmp (cmd, rsp, strlen (cmd)-1))	    {	    MODEM_LOG_MSG ("modem: ignoring echoed command\n",			    0, 0, 0, 0, 0, 0);	    *rsp = '\0';	    continue;	    }	/* break! */	echoResponse = FALSE;	}    MODEM_DEBUG_PRINT (("modem: response = %s\n", rsp));    if (goodRsp != NULL)	if (strncmp (rsp, goodRsp, strlen (goodRsp)) != 0)	/* !OK */	    {	    MODEM_LOG_MSG ("modem: invalid response: \n", 0, 0, 0, 0, 0, 0);	    return (ERROR);	    }    return (OK);    }#ifdef MODEM_DEBUG/***************************************************************************** modemConnectTest - test connection with a modem* * This routine tests connection with a modem by filling up all the relevant* fields in the MODEM_CONN_DESC structure, and then calling the modem * connection routine.** The parameter <initString> may be specified to the initialization string* most suitable for the modem being used. If this parameter is NULL, a default* initialization string for a USRobotics Sportster modem is used.* The parameter <modemNumber> should point to a string including the number* the user wishes to call. There is no default value for it.* The parameter <modemDialResponse> should point at a string representing the* expected return code for a successful dial-up connection. A default * connection string is provided, should this parameter be invalid.** RETURNS: OK on success, ERROR otherwise* * NOMANUAL*/STATUS modemConnectTest    (    char	* initString,    char	* modemNumber,    char	* modemDialResponse,	PFW_STACK_OBJ   * pModemStack    )    {    MODEM_CONN_DESC	modemConnDesc;    if (pModemStack == NULL)	{	    MODEM_LOG_MSG ("modemConnectTest: Invalid stack object \n", 0, 0, 0, 0, 0, 0);	    printf ("modemConnectTest: Invalid stack object \n");	    return (ERROR);	}    modemConnDesc.modemDialTimeout = MODEM_TIMEOUT_DIAL;    modemConnDesc.modemCmdTimeout = MODEM_TIMEOUT_CMD;    modemConnDesc.modemNumber = malloc (100);    modemConnDesc.modemInitString = malloc (100);    modemConnDesc.modemDialResponse = malloc (100);    if (initString != NULL && initString [0] != 0)	strcpy (modemConnDesc.modemInitString, initString);    else	strcpy (modemConnDesc.modemInitString, 		USR_SPORTSTER_DEF_INIT_STRING);    if (modemNumber != NULL && modemNumber [0] != 0)	strcpy (modemConnDesc.modemNumber, modemNumber);    else	return (ERROR);    if (modemDialResponse != NULL && modemDialResponse [0] != 0)	strcpy (modemConnDesc.modemDialResponse, modemDialResponse);    else	strcpy (modemConnDesc.modemDialResponse, MODEM_CONNECT);    modemConnDesc.modemConnCallback = (VOIDFUNCPTR) modemConnCallback;    modemConnDesc.modemDisconnCallback = (VOIDFUNCPTR) modemDisconnCallback;    modemConnDesc.modemConnParm = (void *) pModemStack;    modemConnDesc.modemDisconnParm = (void *) pModemStack;    if (modemConnect (pModemStack, &modemConnDesc) == ERROR)	{	MODEM_LOG_MSG ("failed to connect to modem \n",			0, 0, 0, 0, 0, 0);	return (ERROR);	}    return (OK);    }/***************************************************************************** modemDisconnectTest - test disconnection with a modem* * This routine tests disconnection with a modem by filling up all the relevant* fields in the MODEM_CONN_DESC structure, and then calling the modem * disconnection routine.** RETURNS: OK on success, ERROR otherwise* * NOMANUAL

⌨️ 快捷键说明

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