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

📄 netppp.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 4 页
字号:

		default:

			st = PPPERR_PARAM;

			break;

		}

	}

	

	return st;

}



/*

 * Return the Maximum Transmission Unit for the given PPP connection.

 */

u_int pppMTU(int pd)

{

	PPPControl *pc = &pppControl[pd];

	u_int st;

	

	/* Validate parameters. */

	if (pd < 0 || pd >= NUM_PPP || !pc->openFlag)

		st = 0;

	else

		st = pc->mtu;

		

	return st;

}



/*

 * Write n characters to a ppp link.

 *	RETURN: >= 0 Number of characters written

 *		 	 -1 Failed to write to device

 */

int pppWrite(int pd, const char *s, int n)

{

	PPPControl *pc = &pppControl[pd];

	short st = 0;

	u_char c;

	u_int fcsOut = PPP_INITFCS;

	NBuf *headMB = NULL, *tailMB;



	nGET(headMB);

	if (headMB == NULL) {

		st = PPPERR_ALLOC;

#if STATS_SUPPORT > 0

		pppStats.PPPoerrors++;

#endif

	} else {

		headMB->len = 0;

		tailMB = headMB;

		

		/* If the link has been idle, we'll send a fresh flag character to

		 * flush any noise. */

		if (diffTime(pc->lastXMit) <= MAXIDLEFLAG)

			tailMB = pppMPutRaw(PPP_FLAG, tailMB);

		pc->lastXMit = mtime();

		 

		/* Load output buffer. */

		while (n-- > 0) {

			c = *s++;

			

			/* Update FCS before checking for special characters. */

			fcsOut = PPP_FCS(fcsOut, c);

			

			/* Copy to output buffer escaping special characters. */

			tailMB = pppMPutC(c, &pc->outACCM, tailMB);

		}

		

		/* Add FCS and trailing flag. */

		c = ~fcsOut & 0xFF;

		tailMB = pppMPutC(c, &pc->outACCM, tailMB);

		c = (~fcsOut >> 8) & 0xFF;

		tailMB = pppMPutC(c, &pc->outACCM, tailMB);

		tailMB = pppMPutRaw(PPP_FLAG, tailMB);

		

		/* If we failed to complete the packet, throw it away.

		 * Otherwise send it. */

		if (tailMB) {

			PPPDEBUG((pppControl[pd].traceOffset + LOG_INFO, TL_PPP,

						"pppWrite[%d]: %d:%.*H", 

						pd,

						headMB->len, MIN(headMB->len * 2, 40), headMB->data));

#if LXNDEBUG > 0

			if (outhead + sizeof(NBuf) <= &out_buf[OUTBUFSIZE-1]) {

				memcpy(outhead, (char*)headMB, sizeof(NBuf));

				outhead += sizeof(NBuf);

				}

#endif

			nPut(pc->fd, headMB);

#if STATS_SUPPORT > 0

			pppStats.PPPopackets++;

#endif

		}

		else {

			PPPDEBUG((pppControl[pd].traceOffset + LOG_WARNING, TL_PPP,

						"pppWrite[%d]: Alloc err - dropping %d:%.*H", 

						pd,

						headMB->len, MIN(headMB->len * 2, 40), headMB->data));

			nFreeChain(headMB);

#if STATS_SUPPORT > 0

			pppStats.PPPoerrors++;

#endif

		}

	}



	return st;

}



/*

 * ppp_send_config - configure the transmit characteristics of

 * the ppp interface.

 */

void ppp_send_config(

	int unit, 

	int mtu,

	u_int32_t asyncmap,

	int pcomp, 

	int accomp

)

{

	PPPControl *pc = &pppControl[unit];

	int i;

	

	pc->mtu = mtu;

	pc->pcomp = pcomp;

	pc->accomp = accomp;

	

	/* Load the ACCM bits for the 32 control codes. */

	for (i = 0; i < 32/8; i++)

		pc->outACCM[i] = (u_char)((asyncmap >> (8 * i)) & 0xFF);

	PPPDEBUG((LOG_INFO, TL_PPP, "ppp_send_config[%d]: outACCM=%X %X %X %X",

				unit,

				pc->outACCM[0], pc->outACCM[1], pc->outACCM[2], pc->outACCM[3]));

}





/*

 * ppp_set_xaccm - set the extended transmit ACCM for the interface.

 */

void ppp_set_xaccm(int unit, ext_accm *accm)

{

	memcpy(pppControl[unit].outACCM, accm, sizeof(ext_accm));

	PPPDEBUG((LOG_INFO, TL_PPP, "ppp_set_xaccm[%d]: outACCM=%X %X %X %X",

				unit,

				pppControl[unit].outACCM[0],

				pppControl[unit].outACCM[1],

				pppControl[unit].outACCM[2],

				pppControl[unit].outACCM[3]));

}





/*

 * ppp_recv_config - configure the receive-side characteristics of

 * the ppp interface.

 */

//#pragma argsused /* XXX */

void ppp_recv_config(

	int unit, 

	int mru,

	u_int32_t asyncmap,

	int pcomp, 

	int accomp

)

{

	PPPControl *pc = &pppControl[unit];

	int i;

	

	/* Load the ACCM bits for the 32 control codes. */

	for (i = 0; i < 32 / 8; i++)

		pc->inACCM[i] = (u_char)(asyncmap >> (i * 8));

	PPPDEBUG((LOG_INFO, TL_PPP, "ppp_recv_config[%d]: inACCM=%X %X %X %X",

				unit,

				pc->inACCM[0], pc->inACCM[1], pc->inACCM[2], pc->inACCM[3]));

}



/*

 * ccp_test - ask kernel whether a given compression method

 * is acceptable for use.  Returns 1 if the method and parameters

 * are OK, 0 if the method is known but the parameters are not OK

 * (e.g. code size should be reduced), or -1 if the method is unknown.

 */

//#pragma argsused

int ccp_test(

	int unit, 

	int opt_len, 

	int for_transmit,

	u_char *opt_ptr

)

{

	return 0;	/* XXX Currently no compression. */

}



/*

 * ccp_flags_set - inform kernel about the current state of CCP.

 */

//#pragma argsused

void ccp_flags_set(int unit, int isopen, int isup)

{

	/* XXX */

}



/*

 * ccp_fatal_error - returns 1 if decompression was disabled as a

 * result of an error detected after decompression of a packet,

 * 0 otherwise.  This is necessary because of patent nonsense.

 */

//#pragma argsused

int ccp_fatal_error(int unit)

{

	/* XXX */

	return 0;

}



/*

 * get_idle_time - return how long the link has been idle.

 */

//#pragma argsused

int get_idle_time(int u, struct ppp_idle *ip)

{	

	/* XXX */

	return 0;

}





/*

 * Return user specified netmask, modified by any mask we might determine

 * for address `addr' (in network byte order).

 * Here we scan through the system's list of interfaces, looking for

 * any non-point-to-point interfaces which might appear to be on the same

 * network as `addr'.  If we find any, we OR in their netmask to the

 * user-specified netmask.

 */

u_int32_t GetMask(u_int32_t addr)

{

	u_int32_t mask, nmask;

	

	htonl(addr);

	if (IN_CLASSA(addr))	/* determine network mask for address class */

		nmask = IN_CLASSA_NET;

	else if (IN_CLASSB(addr))

		nmask = IN_CLASSB_NET;

	else

		nmask = IN_CLASSC_NET;

	/* class D nets are disallowed by bad_ip_adrs */

	mask = netMask | htonl(nmask);

	

	/* XXX

	 * Scan through the system's network interfaces.

	 * Get each netmask and OR them into our mask.

	 */

	

	return mask;

}



/*

 * sifvjcomp - config tcp header compression

 */

//#pragma argsused

int sifvjcomp(

	int pd, 

	int vjcomp, 

	int cidcomp, 

	int maxcid

)

{

#if VJ_SUPPORT > 0

	PPPControl *pc = &pppControl[pd];

	

	pc->vjEnabled = vjcomp;

	pc->vjComp.compressSlot = cidcomp;

	pc->vjComp.maxSlotIndex = maxcid;

	PPPDEBUG((LOG_INFO, TL_PPP, "sifvjcomp: VJ compress enable=%d slot=%d max slot=%d",

				vjcomp, cidcomp, maxcid));

#endif



	return 0;

}



/*

 * sifup - Config the interface up and enable IP packets to pass.

 */

//#pragma argsused

int sifup(int pd)

{

	PPPControl *pc = &pppControl[pd];

	int st = 1;

	

	if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {

		st = 0;

		PPPDEBUG((LOG_WARNING, TL_PPP, "sifup[%d]: bad parms", pd));

	} else {

	    pc->if_up = 1;

	    pc->errCode = 0;

	}

	return st;

}



/*

 * sifnpmode - Set the mode for handling packets for a given NP.

 */

//#pragma argsused

int sifnpmode(int u, int proto, enum NPmode mode)

{

	return 0;

}



/*

 * sifdown - Config the interface down and disable IP.

 */

//#pragma argsused

int sifdown(int pd)

{

	PPPControl *pc = &pppControl[pd];

	int st = 1;

	

	if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {

		st = 0;

		PPPDEBUG((LOG_WARNING, TL_PPP, "sifup[%d]: bad parms", pd));

	} else

	    pc->if_up = 0;

	return st;

}



/*

 * sifaddr - Config the interface IP addresses and netmask.

 */

//#pragma argsused

int sifaddr(

	int u,				/* Interface unit ??? */

	u_int32_t o,		/* Our IP address ??? */

	u_int32_t h,		/* IP subnet mask ??? */

	u_int32_t m			/* IP broadcast address ??? */

)

{

	return 1;

}



/*

 * cifaddr - Clear the interface IP addresses, and delete routes

 * through the interface if possible.

 */

//#pragma argsused

int cifaddr(

	int u, 			/* Interface unit ??? */

	u_int32_t o,	/* Our IP address ??? */

	u_int32_t h		/* IP broadcast address ??? */

)

{

	return 1;

}



/*

 * sifdefaultroute - assign a default route through the address given.

 */

//#pragma argsused

int sifdefaultroute(int u, u_int32_t l, u_int32_t g)

{

	ipSetDefault(l, g, IFT_PPP, u);

	return !0;

}



/*

 * cifdefaultroute - delete a default route through the address given.

 */

//#pragma argsused

int cifdefaultroute(int u, u_int32_t l, u_int32_t g)

{

	ipClearDefault();

	return !0;

}





/**********************************/

/*** LOCAL FUNCTION DEFINITIONS ***/

/**********************************/

/* The main PPP process function.  This implements the state machine according

 * to section 4 of RFC 1661: The Point-To-Point Protocol. */

 

void pppMain(void)

{

	int pd = ppp_id;
	int i = 1;

	int count;

	PPPControl *pc = &pppControl[(int)pd];

	NBuf *curNBuf;



	//long looptime=0;                                                   修改

	

	/*

	 * 	Start the connection and handle incoming events (packet or timeout).

	 */



	trace(LOG_NOTICE, "Connecting %s <--> %s", pc->ifname, nameForDevice(pc->fd));

	lcp_lowerup((int)pd);

	lcp_open((int)pd);		/* Start protocol */

	while (lcp_phase[(int)pd] != PHASE_DEAD) {


	//if(i==1) {
			if(user_cancel==1||mail_finish==1)
					pc->kill_link = 1;

		//	--i;
		//}

		if (pc->kill_link) {

			/* This will leave us at PHASE_DEAD. */

			lcp_close(0, "User request");
		//	lcp_phase[(int)pd] = PHASE_DEAD;


			pc->kill_link = 0;

		}

		//else {

			count = nGet(pc->fd, &curNBuf, MAXKILLDELAY);

			avRandomize();

⌨️ 快捷键说明

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