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

📄 vxworks-ppp.c

📁 完成的PPP协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:

extern "C"
{

#include <vxWorks.h>
#include <stdio.h>
#include <ioLib.h>
#include <sysLib.h>
#include <sioLib.h>
#include <pppLib.h>
#include <routeLib.h>
#include <iosLib.h>
#include <socket.h>
#include <sockLib.h>
#include <in.h>
#include <inetLib.h>
#include <hostlib.h>


/*#include "enviomon.h"*/
#include "netinet\ppp\options.h"
#include "netinet\ppp\pppShow.h"


#define IOMOD	*(unsigned int *)0x3ff5000
#define IOCTL	*(unsigned int *)0x3ff5004
#define IODATA	*(unsigned int *)0x3ff5008


#define	PPP_OPT_NO_ALL			0	/* Don't allow any options */
#define	PPP_OPT_PASSIVE_MODE		0	/* Set passive mode */
#define	PPP_OPT_SILENT_MODE		0	/* Set silent mode */
#define	PPP_OPT_DEFAULTROUTE		1	/* Add default route */
#define	PPP_OPT_PROXYARP		1	/* Add proxy ARP entry */
#define	PPP_OPT_IPCP_ACCEPT_LOCAL	1	/* Acpt peer's IP addr for us */
#define	PPP_OPT_IPCP_ACCEPT_REMOTE	1	/* Acpt peer's IP addr for it */
#define	PPP_OPT_NO_IP			0	/* Disable IP addr negot. */
#define	PPP_OPT_NO_ACC			0	/* Disable addr/control compr */
#define	PPP_OPT_NO_PC			0	/* Disable proto field compr */
#define	PPP_OPT_NO_VJ			1	/* Disable VJ compression */
#define	PPP_OPT_NO_VJCCOMP		1	/* Disable VJ conct-ID compr */
#define	PPP_OPT_NO_ASYNCMAP		0	/* Disable async map negot. */
#define	PPP_OPT_NO_MN			0	/* Disable magic num negot. */
#define	PPP_OPT_NO_MRU			0	/* Disable MRU negotiation */
#define	PPP_OPT_NO_PAP			0	/* Don't allow PAP auth */
#define	PPP_OPT_NO_CHAP			0	/* Don't allow CHAP auth */
#define	PPP_OPT_REQUIRE_PAP		0	/* Require PAP auth */
#define	PPP_OPT_REQUIRE_CHAP		0	/* Require CHAP auth */
#define	PPP_OPT_LOGIN			0	/* Use login dbase for PAP */

#define	PPP_OPT_DEBUG			1	/* Enable daemon debug mode */
#define	PPP_OPT_DRIVER_DEBUG		1	/* Enable driver debug mode */

#define	PPP_STR_ASYNCMAP		NULL	/* desired async map */
#define	PPP_STR_ESCAPE_CHARS		NULL	/* chars to escape on xmits */
#define	PPP_STR_VJ_MAX_SLOTS		NULL	/* max VJ compr header slots */
#define	PPP_STR_NETMASK			"255.255.255.0"	/* netmask value */
#define	PPP_STR_MRU			"1600"	/* MRU value for negotiation */
#define	PPP_STR_MTU			NULL	/* MTU value for negotiation */
#define	PPP_STR_LCP_ECHO_FAILURE	NULL    /*"6"* max LCP echo failures */
#define	PPP_STR_LCP_ECHO_INTERVAL	NULL	/*"300"	* time for LCP echo requests */
#define	PPP_STR_LCP_RESTART		"5"		/* timeout for LCP */
#define	PPP_STR_LCP_MAX_TERMINATE	"5"	/* max LCP term-reqs */
#define	PPP_STR_LCP_MAX_CONFIGURE	"5"	/* max LCP conf-reqs */
#define	PPP_STR_LCP_MAX_FAILURE		"5"	/* max conf-naks for LCP */
#define	PPP_STR_IPCP_RESTART		"20"	/* timeout for IPCP */
#define	PPP_STR_IPCP_MAX_TERMINATE	"5"	/* max IPCP term-reqs */
#define	PPP_STR_IPCP_MAX_CONFIGURE	"5"	/* max IPCP conf-reqs */
#define	PPP_STR_IPCP_MAX_FAILURE	"5"	/* max # conf-naks for IPCP */
#define	PPP_STR_LOCAL_AUTH_NAME		" "	/* local name for auth */
#define	PPP_STR_REMOTE_AUTH_NAME	" "	/* remote name for auth */
#define	PPP_STR_PAP_FILE		NULL	/* PAP secrets file */
#define	PPP_STR_PAP_USER_NAME		NULL    /*"guest"	* username for PAP peer auth */
#define	PPP_STR_PAP_PASSWD		NULL	/*"guest"	* password for PAP peer auth */
#define	PPP_STR_PAP_RESTART		NULL	/*"5"	* timeout for PAP */
#define	PPP_STR_PAP_MAX_AUTHREQ		NULL	/*"5"	* max PAP auth-reqs */
#define	PPP_STR_CHAP_FILE		NULL	/* CHAP secrets file */
#define	PPP_STR_CHAP_RESTART		NULL	/* timeout for CHAP */
#define	PPP_STR_CHAP_INTERVAL		NULL	/* CHAP rechallenge interval */
#define	PPP_STR_CHAP_MAX_CHALLENGE	NULL	/* max CHAP challenges */
int fdModem;
int pppUnit=0;
STATUS atCmdSend(unsigned char *sendString, unsigned char *retString);
void controlLed(char ledNum,int ledStatus);

STATUS GPRS_Init(void);
STATUS pppConnect(void);
void pppRetry(void);
PPP_OPTIONS  ippp_options;
PPP_INFO  ippp_info;	
char ISPnumber[100];		/*用户所拨电话号码*/
char username[100];		/*验证的用户名*/
char password[100];		/*验证的密码*/

int find(int x);
void plk(void);

STATUS taskDelay
    (
    int ticks                 /* number of ticks to delay task */
    );
void reboot
    (
    int startType             /* how the boot ROMS will reboot */
    );
int sp
    (
    FUNCPTR func,             /* function to call */
    int     arg1,             /* first of nine args to pass to spawned task */
    int     arg2,
    int     arg3,
    int     arg4,
    int     arg5,
    int     arg6,
    int     arg7,
    int     arg8,
    int     arg9
    );

void lkAddr
    (
    unsigned int addr         /* address around which to look */
    );

/*
void SafeQuit();/ *2004-10-30 by zhoujun* /
void SafeQuit()
{
	SaveFiles();
	printf("保存文件!");
	reboot(0);
}

*/

char NetCom[]="/tyCo/0";


}//extern "C"


void test()
{
	char tempFrame[]={0x7e,0x80,0x21,0x01,0x01,0x00,0x22,0x03,
		0x06,0x00,0x00,0x00,0x00,0x81,0x06,0x00,0x00,0x00,0x00,0x82,
		0x06,0x00,0x00,0x00,0x00,0x83,0x06,0x00,0x00,0x00,0x00,0x84,
		0x06,0x00,0x00,0x00,0x00,0xbc,0xb0,0x7e};
	char tempFrame2[]={0x7E,0x80,0x21,0x01 ,0xEF ,0x00 ,0x04 ,0x01 ,0x80 ,0x7E};

	write(fdModem,tempFrame2,10);

}

STATUS	GPRS_Init()
{
	fdModem=open(NetCom,O_RDWR,0);
	if(fdModem==ERROR)
	{
		printf("Communicate port open error!\n");
		return ERROR;
	}
	ioctl(fdModem,FIOBAUDRATE,19200);
	ioctl(fdModem,FIOFLUSH,0);
	ioctl(fdModem,OPT_RAW,0);
	memset(username,0,100);
	memset(password,0,100);
	strcpy(username,"guest");
	strcpy(password,"abcde");
	strcpy(ISPnumber,"*99***1#");
	memset(&ippp_options,0,sizeof(PPP_OPTIONS));
	ippp_options.flags=	(OPT_NO_ALL*PPP_OPT_NO_ALL|
						OPT_PASSIVE_MODE*PPP_OPT_PASSIVE_MODE|
						OPT_SILENT_MODE*PPP_OPT_SILENT_MODE|
						OPT_DEFAULTROUTE*PPP_OPT_DEFAULTROUTE|
						OPT_PROXYARP*PPP_OPT_PROXYARP|
						OPT_IPCP_ACCEPT_LOCAL*PPP_OPT_IPCP_ACCEPT_LOCAL|
						OPT_IPCP_ACCEPT_REMOTE*PPP_OPT_IPCP_ACCEPT_REMOTE|
						OPT_NO_IP*PPP_OPT_NO_IP|
						OPT_NO_ACC*PPP_OPT_NO_ACC|
						OPT_NO_PC*PPP_OPT_NO_PC|
						OPT_NO_VJ*PPP_OPT_NO_VJ|
						OPT_NO_VJCCOMP*PPP_OPT_NO_VJCCOMP|
						OPT_NO_ASYNCMAP*PPP_OPT_NO_ASYNCMAP|
						OPT_NO_MN*PPP_OPT_NO_MN|
						OPT_NO_MRU*PPP_OPT_NO_MRU|
						OPT_NO_PAP*PPP_OPT_NO_PAP|
						OPT_NO_CHAP*PPP_OPT_NO_CHAP|
						OPT_REQUIRE_PAP*PPP_OPT_REQUIRE_PAP|
						OPT_REQUIRE_CHAP*PPP_OPT_REQUIRE_CHAP|
						OPT_LOGIN*PPP_OPT_LOGIN|
						OPT_DEBUG*PPP_OPT_DEBUG|
						OPT_DRIVER_DEBUG*PPP_OPT_DRIVER_DEBUG);

/*
    strcpy(ippp_options.asyncmap,PPP_STR_ASYNCMAP);
    strcpy(ippp_options.escape_chars,PPP_STR_ESCAPE_CHARS);
    strcpy(ippp_options.vj_max_slots,PPP_STR_VJ_MAX_SLOTS);
    strcpy(ippp_options.netmask,PPP_STR_NETMASK);
    strcpy(ippp_options.mru,PPP_STR_MRU);
    strcpy(ippp_options.mtu,PPP_STR_MTU);
    strcpy(ippp_options.lcp_echo_failure,PPP_STR_LCP_ECHO_FAILURE);
    strcpy(ippp_options.lcp_echo_interval,PPP_STR_LCP_ECHO_INTERVAL);
    strcpy(ippp_options.lcp_restart,PPP_STR_LCP_RESTART);
    strcpy(ippp_options.lcp_max_terminate,PPP_STR_LCP_MAX_TERMINATE);
    strcpy(ippp_options.lcp_max_configure,PPP_STR_LCP_MAX_CONFIGURE);
    strcpy(ippp_options.lcp_max_failure,PPP_STR_LCP_MAX_FAILURE);
    strcpy(ippp_options.ipcp_restart,PPP_STR_IPCP_RESTART);
    strcpy(ippp_options.ipcp_max_terminate,PPP_STR_IPCP_MAX_TERMINATE);
    strcpy(ippp_options.ipcp_max_configure,PPP_STR_IPCP_MAX_CONFIGURE);
    strcpy(ippp_options.ipcp_max_failure,PPP_STR_IPCP_MAX_FAILURE);
    strcpy(ippp_options.local_auth_name,PPP_STR_LOCAL_AUTH_NAME);
    strcpy(ippp_options.remote_auth_name,PPP_STR_REMOTE_AUTH_NAME);
    strcpy(ippp_options.pap_file,PPP_STR_PAP_FILE);
    strcpy(ippp_options.pap_user_name,PPP_STR_PAP_USER_NAME);
    strcpy(ippp_options.pap_passwd,PPP_STR_PAP_PASSWD);
    strcpy(ippp_options.pap_restart,PPP_STR_PAP_RESTART);
    strcpy(ippp_options.pap_max_authreq,PPP_STR_PAP_MAX_AUTHREQ);
    strcpy(ippp_options.chap_file,PPP_STR_CHAP_FILE);
    strcpy(ippp_options.chap_restart,PPP_STR_CHAP_RESTART);
    strcpy(ippp_options.chap_interval,PPP_STR_CHAP_INTERVAL);
    strcpy(ippp_options.chap_max_challenge,PPP_STR_CHAP_MAX_CHALLENGE);
*/


    (ippp_options.asyncmap=PPP_STR_ASYNCMAP);
    (ippp_options.escape_chars=PPP_STR_ESCAPE_CHARS);
    (ippp_options.vj_max_slots=PPP_STR_VJ_MAX_SLOTS);
    (ippp_options.netmask=(PPP_STR_NETMASK));
    (ippp_options.mru=PPP_STR_MRU);
    (ippp_options.mtu=PPP_STR_MTU);
    (ippp_options.lcp_echo_failure=PPP_STR_LCP_ECHO_FAILURE);
    (ippp_options.lcp_echo_interval=PPP_STR_LCP_ECHO_INTERVAL);
    (ippp_options.lcp_restart=PPP_STR_LCP_RESTART);
    (ippp_options.lcp_max_terminate=PPP_STR_LCP_MAX_TERMINATE);
    (ippp_options.lcp_max_configure=PPP_STR_LCP_MAX_CONFIGURE);
    (ippp_options.lcp_max_failure=PPP_STR_LCP_MAX_FAILURE);
    (ippp_options.ipcp_restart=PPP_STR_IPCP_RESTART);
    (ippp_options.ipcp_max_terminate=PPP_STR_IPCP_MAX_TERMINATE);
    (ippp_options.ipcp_max_configure=PPP_STR_IPCP_MAX_CONFIGURE);
    (ippp_options.ipcp_max_failure=PPP_STR_IPCP_MAX_FAILURE);
    (ippp_options.local_auth_name=PPP_STR_LOCAL_AUTH_NAME);

/*
    ippp_options.lcp_echo_interval = "30";
    ippp_options.lcp_echo_failure = "10";
	*/
	pppSecretDelete(username,"*",password);
	pppSecretAdd(username,"*",password,NULL);
	return OK;	
}

STATUS	VPDN_Init()
{
	fdModem=open(NetCom,O_RDWR,0);
	if(fdModem==ERROR)
	{
		printf("Communicate port open error!\n");
		return ERROR;
	}
/*	simcomsimcomsimcomsimcom`
	ioctl(fdModem,FIOBAUDRATE,19200);*/

	ioctl(fdModem,FIOFLUSH,0);

/*	simcomsimcomsimcomsimcom
	ioctl(fdModem,OPT_RAW,0);*/

	memset(username,0,100);
	memset(password,0,100);

/*	simcomsimcomsimcomsimcom
	strcpy(username,"guest");
	strcpy(password,"abcde");
	strcpy(ISPnumber,"*99***1#");
*/

	ISPnumber[19]=0;
	username[19]=0;
	password[19]=0;
	/*
	strcpy(username,"16300");
	strcpy(password,"16300");
	strcpy(ISPnumber,"16300");
	*/

	ippp_options.flags=	(OPT_NO_ALL*PPP_OPT_NO_ALL|
						OPT_PASSIVE_MODE*PPP_OPT_PASSIVE_MODE|
						OPT_SILENT_MODE*PPP_OPT_SILENT_MODE|
						OPT_DEFAULTROUTE*PPP_OPT_DEFAULTROUTE|
						OPT_PROXYARP*PPP_OPT_PROXYARP|
						OPT_IPCP_ACCEPT_LOCAL*PPP_OPT_IPCP_ACCEPT_LOCAL|
						OPT_IPCP_ACCEPT_REMOTE*PPP_OPT_IPCP_ACCEPT_REMOTE|
						OPT_NO_IP*PPP_OPT_NO_IP|
						OPT_NO_ACC*PPP_OPT_NO_ACC|
						OPT_NO_PC*PPP_OPT_NO_PC|
						OPT_NO_VJ*PPP_OPT_NO_VJ|
						OPT_NO_VJCCOMP*PPP_OPT_NO_VJCCOMP|
						OPT_NO_ASYNCMAP*PPP_OPT_NO_ASYNCMAP|
						OPT_NO_MN*PPP_OPT_NO_MN|
						OPT_NO_MRU*PPP_OPT_NO_MRU|
						OPT_NO_PAP*PPP_OPT_NO_PAP|
						OPT_NO_CHAP*PPP_OPT_NO_CHAP|
						OPT_REQUIRE_PAP*PPP_OPT_REQUIRE_PAP|
						OPT_REQUIRE_CHAP*PPP_OPT_REQUIRE_CHAP|
						OPT_LOGIN*PPP_OPT_LOGIN|
						OPT_DEBUG*PPP_OPT_DEBUG|
						OPT_DRIVER_DEBUG*PPP_OPT_DRIVER_DEBUG);

    strcpy(ippp_options.asyncmap,PPP_STR_ASYNCMAP);
    strcpy(ippp_options.escape_chars,PPP_STR_ESCAPE_CHARS);
    strcpy(ippp_options.vj_max_slots,PPP_STR_VJ_MAX_SLOTS);
//    strcpy(ippp_options.netmask,PPP_STR_NETMASK);
    strcpy(ippp_options.mru,PPP_STR_MRU);
    strcpy(ippp_options.mtu,PPP_STR_MTU);
    strcpy(ippp_options.lcp_echo_failure,PPP_STR_LCP_ECHO_FAILURE);
    strcpy(ippp_options.lcp_echo_interval,PPP_STR_LCP_ECHO_INTERVAL);
    strcpy(ippp_options.lcp_restart,PPP_STR_LCP_RESTART);
    strcpy(ippp_options.lcp_max_terminate,PPP_STR_LCP_MAX_TERMINATE);
    strcpy(ippp_options.lcp_max_configure,PPP_STR_LCP_MAX_CONFIGURE);
    strcpy(ippp_options.lcp_max_failure,PPP_STR_LCP_MAX_FAILURE);
    strcpy(ippp_options.ipcp_restart,PPP_STR_IPCP_RESTART);
    strcpy(ippp_options.ipcp_max_terminate,PPP_STR_IPCP_MAX_TERMINATE);
    strcpy(ippp_options.ipcp_max_configure,PPP_STR_IPCP_MAX_CONFIGURE);
    strcpy(ippp_options.ipcp_max_failure,PPP_STR_IPCP_MAX_FAILURE);
    strcpy(ippp_options.local_auth_name,PPP_STR_LOCAL_AUTH_NAME);
    strcpy(ippp_options.remote_auth_name,PPP_STR_REMOTE_AUTH_NAME);
    strcpy(ippp_options.pap_file,PPP_STR_PAP_FILE);
    strcpy(ippp_options.pap_user_name,PPP_STR_PAP_USER_NAME);
    strcpy(ippp_options.pap_passwd,PPP_STR_PAP_PASSWD);
    strcpy(ippp_options.pap_restart,PPP_STR_PAP_RESTART);
    strcpy(ippp_options.pap_max_authreq,PPP_STR_PAP_MAX_AUTHREQ);
    strcpy(ippp_options.chap_file,PPP_STR_CHAP_FILE);
    strcpy(ippp_options.chap_restart,PPP_STR_CHAP_RESTART);
    strcpy(ippp_options.chap_interval,PPP_STR_CHAP_INTERVAL);
    strcpy(ippp_options.chap_max_challenge,PPP_STR_CHAP_MAX_CHALLENGE);

	pppSecretDelete(username,"*",password);
	pppSecretAdd(username,"*",password,NULL);
	return OK;	
}
STATUS atCmdSend(unsigned char *sendString,unsigned char *retString)
{
	unsigned char stringLength;
	unsigned char addressInc=0;
	unsigned char readBytes=0;
	unsigned char string[50];

	int procBytes=0;
	unsigned int waitTime;
	stringLength=strlen((char *)sendString);
	memset(string,0,50);
	memset(retString,0,50);
	strcpy((char *)string,(char *)sendString);
	string[stringLength]=0x0d;
	ioctl (fdModem,FIORFLUSH,0);
	if(write(fdModem,(char *)string,strlen((char *)string))==ERROR)
	{
		printf("Write Com1 port1 error!\n");
		return ERROR;
	}
	do
	{
		ioctl (fdModem,FIONWRITE,(int)&procBytes);
	} while(procBytes!=0);
	for(waitTime=0;waitTime<1000;waitTime++)
	{
		taskDelay(1);
		ioctl(fdModem,FIONREAD,(int)&procBytes);
		if(procBytes>=2)
		{
			readBytes=read(fdModem,(char *)(addressInc+string),50);
			if(strstr((char *)string,"ok")!=NULL)
			{
				strcpy((char *)retString,"OK");
				return OK;
			}				
			if(strstr((char *)string,"OK")!=NULL)
			{
				strcpy((char *)retString,"OK");
				return OK;
			}				
			if(strstr((char *)string,"er")!=NULL)
			{
				strcpy((char *)retString,"ERROR");
				return OK;
			}				
			if(strstr((char *)string,"ER")!=NULL)
			{
				strcpy((char *)retString,"ERROR");
				return OK;
			}				
			if(strstr((char *)string,"co")!=NULL)
			{
				strcpy((char *)retString,"CONNECT");
				return OK;
			}				
			if(strstr((char *)string,"CO")!=NULL)
			{
				strcpy((char *)retString,"CONNECT");
				return OK;
			}				
		printf("%s\n",string);	
		addressInc+=readBytes;					
		}
		
	}
	sprintf((char *)retString,"GPRS module has no response!   %s\n",sendString);
/*	strcpy((char *)retString,"GPRS module has no response!\n");*/
	return ERROR;	
}

unsigned char localIpAddress[20];
unsigned char remoteIpAddress[20]; 

void pppttt(void)
{
	int i;

⌨️ 快捷键说明

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