Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of lwip by
Diff: netif/ppp/ppp.c
- Revision:
- 15:e5bb25d5506f
- Parent:
- 4:f71f5d9d5846
- Child:
- 16:a61070aa2e98
--- a/netif/ppp/ppp.c Mon Dec 09 15:15:09 2013 +0000 +++ b/netif/ppp/ppp.c Wed Mar 12 20:22:30 2014 +0000 @@ -241,6 +241,7 @@ #endif /* PPP_INPROC_OWNTHREAD */ static void pppDrop(PPPControlRx *pcrx); static void pppInProc(PPPControlRx *pcrx, u_char *s, int l); +static void pppFreeCurrentInputPacket(PPPControlRx *pcrx); //lwip 1.4.1 backport #endif /* PPPOS_SUPPORT */ @@ -251,7 +252,8 @@ static PPPControl pppControl[NUM_PPP] __attribute((section("AHBSRAM1"))); /* The PPP interface control blocks. */ -sys_mbox_t pppMbox; //Used to signal PPP thread that a PPP session begins +static sys_mbox_t pppMboxStart; //Used to signal PPP thread that a PPP session begins +static sys_mbox_t pppMboxStopped; //Used to signal remote thread that a PPP session has stopped /* * PPP Data Link Layer "protocol" table. @@ -373,7 +375,7 @@ pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL, NULL); } - pc->openFlag = 0;/**/ + pc->openFlag = 0; #endif /* PPPOS_SUPPORT */ } PPPDEBUG(LOG_DEBUG, ("pppLinkTerminated: finished.\n")); @@ -400,6 +402,12 @@ static void pppStart(int pd) { + struct protent *protp; + int j; + /* Initialize each protocol to the standard option set. */ + for (j = 0; (protp = ppp_protocols[j]) != NULL; ++j) { + (*protp->init)(pd); + } PPPDEBUG(LOG_DEBUG, ("pppStart: unit %d\n", pd)); lcp_lowerup(pd); lcp_open(pd); /* Start protocol */ @@ -433,9 +441,6 @@ void pppInit(void) { - struct protent *protp; - int i, j; - memset(&ppp_settings, 0, sizeof(ppp_settings)); ppp_settings.usepeerdns = 1; pppSetAuth(PPPAUTHTYPE_NONE, NULL, NULL); @@ -444,14 +449,9 @@ subnetMask = PP_HTONL(0xffffff00UL); - for (i = 0; i < NUM_PPP; i++) { - /* Initialize each protocol to the standard option set. */ - for (j = 0; (protp = ppp_protocols[j]) != NULL; ++j) { - (*protp->init)(i); - } - } - - sys_mbox_new(&pppMbox, 1); + sys_mbox_new(&pppMboxStart, 1); + sys_mbox_new(&pppMboxStopped, 1); + sys_thread_new(PPP_THREAD_NAME, pppInputThread, (void*)NULL, PPP_THREAD_STACKSIZE, PPP_THREAD_PRIO); //Create PPP thread here } @@ -550,6 +550,8 @@ pd = PPPERR_OPEN; } else { pc = &pppControl[pd]; + /* input pbuf left over from last session? */ //Backport from lwip 1.4.1 + pppFreeCurrentInputPacket(&pc->rx); /* @todo: is this correct or do I overwrite something? */ memset(pc, 0, sizeof(PPPControl)); pc->rx.pd = pd; @@ -578,7 +580,7 @@ PPPDEBUG(LOG_INFO, ("pppOverSerialOpen: unit %d: Connecting\n", pd)); pppStart(pd); #if PPP_INPROC_OWNTHREAD - sys_mbox_post(&pppMbox, (void*)&pc->rx); + sys_mbox_post(&pppMboxStart, (void*)&pc->rx); #endif } @@ -680,6 +682,9 @@ #endif /* PPPOS_SUPPORT */ } + void* pcrx; + sys_arch_mbox_fetch(&pppMboxStopped, (void**)&pcrx, 0); //Wait indefinitely for link to become dead + return st; } @@ -1515,17 +1520,20 @@ do { - sys_arch_mbox_fetch(&pppMbox, (void**)&pcrx, 0); //Wait indefinitely - - while (lcp_phase[pcrx->pd] != PHASE_DEAD) { - count = sio_read(pcrx->fd, pcrx->rxbuf, PPPOS_RX_BUFSIZE); - if(count > 0) { - pppInProc(pcrx, pcrx->rxbuf, count); - } else { - /* nothing received, give other tasks a chance to run */ - sys_msleep(1); + sys_arch_mbox_fetch(&pppMboxStart, (void**)&pcrx, 0); //Wait indefinitely + PPPDEBUG(LOG_INFO, ("pppInputThread: unit %d: Woken up\n", pcrx->pd)); + while (lcp_phase[pcrx->pd] != PHASE_DEAD) { + count = sio_read(pcrx->fd, pcrx->rxbuf, PPPOS_RX_BUFSIZE); + if(count > 0) { + pppInProc(pcrx, pcrx->rxbuf, count); + } else { + /* nothing received, give other tasks a chance to run */ + sys_msleep(1); + } + } - } + PPPDEBUG(LOG_INFO, ("pppInputThread: unit %d: Released\n", pcrx->pd)); + sys_mbox_post(&pppMboxStopped, (void*)pcrx); } while(1); //Never terminates } #endif /* PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD */ @@ -1724,6 +1732,22 @@ * Drop the input packet. */ static void +pppFreeCurrentInputPacket(PPPControlRx *pcrx) +{ + if (pcrx->inHead != NULL) { + if (pcrx->inTail && (pcrx->inTail != pcrx->inHead)) { + pbuf_free(pcrx->inTail); + } + pbuf_free(pcrx->inHead); + pcrx->inHead = NULL; + } + pcrx->inTail = NULL; +} + +/* + * Drop the input packet and increase error counters. + */ +static void pppDrop(PPPControlRx *pcrx) { if (pcrx->inHead != NULL) { @@ -1731,13 +1755,8 @@ PPPDEBUG(LOG_INFO, ("pppDrop: %d:%.*H\n", pcrx->inHead->len, min(60, pcrx->inHead->len * 2), pcrx->inHead->payload)); #endif PPPDEBUG(LOG_INFO, ("pppDrop: pbuf len=%d, addr %p\n", pcrx->inHead->len, (void*)pcrx->inHead)); - if (pcrx->inTail && (pcrx->inTail != pcrx->inHead)) { - pbuf_free(pcrx->inTail); - } - pbuf_free(pcrx->inHead); - pcrx->inHead = NULL; - pcrx->inTail = NULL; } + pppFreeCurrentInputPacket(pcrx); //backport from lwip 1.4.1 #if VJ_SUPPORT vj_uncompress_err(&pppControl[pcrx->pd].vjComp); #endif /* VJ_SUPPORT */