124 #ifndef PPP_INPROC_MULTITHREADED
125 #define PPP_INPROC_MULTITHREADED (NO_SYS==0)
131 #ifndef PPP_INPROC_OWNTHREAD
132 #define PPP_INPROC_OWNTHREAD PPP_INPROC_MULTITHREADED
135 #if PPP_INPROC_OWNTHREAD && !PPP_INPROC_MULTITHREADED
136 #error "PPP_INPROC_OWNTHREAD needs PPP_INPROC_MULTITHREADED==1"
142 #define PPP_ADDRESS(p) (((u_char *)(p))[0])
143 #define PPP_CONTROL(p) (((u_char *)(p))[1])
144 #define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
158 #define ESCAPE_P(accm, c) ((accm)[(c) >> 3] & pppACCMMask[c & 0x07])
165 #ifndef PPPOS_RX_BUFSIZE
166 #define PPPOS_RX_BUFSIZE (PPP_MRU + PPP_HDRLEN)
169 typedef struct PPPControlRx_s {
175 u_char rxbuf[PPPOS_RX_BUFSIZE];
178 struct pbuf *inHead, *inTail;
184 PPPDevStates inState;
192 typedef struct PPPControl_s {
197 struct pppoe_softc *pppoe_sc;
209 #if PPPOS_SUPPORT && VJ_SUPPORT
216 struct ppp_addrs addrs;
218 void (*linkStatusCB)(
void *ctx,
int errCode,
void *arg);
239 #if PPP_INPROC_OWNTHREAD
240 static void pppInputThread(
void *arg);
242 static void pppDrop(PPPControlRx *pcrx);
243 static void pppInProc(PPPControlRx *pcrx, u_char *s,
int l);
252 static PPPControl pppControl[NUM_PPP];
259 struct protent *ppp_protocols[] = {
282 u_char outpacket_buf[NUM_PPP][PPP_MRU+PPP_HDRLEN];
294 static const u_short fcstab[256] = {
295 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
296 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
297 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
298 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
299 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
300 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
301 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
302 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
303 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
304 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
305 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
306 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
307 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
308 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
309 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
310 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
311 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
312 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
313 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
314 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
315 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
316 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
317 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
318 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
319 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
320 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
321 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
322 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
323 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
324 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
325 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
326 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
331 static u_char pppACCMMask[] = {
344 pppRecvWakeup(
int pd)
352 pppLinkTerminated(
int pd)
357 if (pppControl[pd].ethif) {
358 pppoe_disconnect(pppControl[pd].pppoe_sc);
365 pc = &pppControl[pd];
368 PPPDEBUG(
LOG_DEBUG, (
"pppLinkTerminated: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode));
369 if (pc->linkStatusCB) {
370 pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL,
NULL);
385 if (pppControl[pd].ethif) {
386 pppoe_disconnect(pppControl[pd].pppoe_sc);
428 struct ppp_settings ppp_settings;
433 struct protent *protp;
436 memset(&ppp_settings, 0,
sizeof(ppp_settings));
437 ppp_settings.usepeerdns = 1;
438 pppSetAuth(PPPAUTHTYPE_NONE,
NULL,
NULL);
444 for (i = 0; i < NUM_PPP; i++) {
446 for (j = 0; (protp = ppp_protocols[j]) !=
NULL; ++j) {
453 pppSetAuth(
enum pppAuthType authType,
const char *user,
const char *passwd)
456 case PPPAUTHTYPE_NONE:
458 #ifdef LWIP_PPP_STRICT_PAP_REJECT
459 ppp_settings.refuse_pap = 1;
462 ppp_settings.refuse_pap = 0;
464 ppp_settings.refuse_chap = 1;
467 case PPPAUTHTYPE_ANY:
487 ppp_settings.refuse_pap = 0;
488 ppp_settings.refuse_chap = 0;
491 case PPPAUTHTYPE_PAP:
492 ppp_settings.refuse_pap = 0;
493 ppp_settings.refuse_chap = 1;
496 case PPPAUTHTYPE_CHAP:
497 ppp_settings.refuse_pap = 1;
498 ppp_settings.refuse_chap = 0;
503 strncpy(ppp_settings.user, user,
sizeof(ppp_settings.user)-1);
504 ppp_settings.user[
sizeof(ppp_settings.user)-1] =
'\0';
506 ppp_settings.user[0] =
'\0';
510 strncpy(ppp_settings.passwd, passwd,
sizeof(ppp_settings.passwd)-1);
511 ppp_settings.passwd[
sizeof(ppp_settings.passwd)-1] =
'\0';
513 ppp_settings.passwd[0] =
'\0';
529 pppOverSerialOpen(
sio_fd_t fd,
void (*linkStatusCB)(
void *ctx,
int errCode,
void *arg),
void *linkStatusCtx)
534 if (linkStatusCB ==
NULL) {
541 for (pd = 0; pd < NUM_PPP && pppControl[pd].openFlag != 0; pd++);
546 pc = &pppControl[pd];
548 memset(pc, 0,
sizeof(PPPControl));
563 pc->rx.inACCM[15] = 0x60;
564 pc->outACCM[15] = 0x60;
566 pc->linkStatusCB = linkStatusCB;
567 pc->linkStatusCtx = linkStatusCtx;
574 #if PPP_INPROC_OWNTHREAD
584 static void pppOverEthernetLinkStatusCB(
int pd,
int up);
587 pppOverEthernetClose(
int pd)
589 PPPControl* pc = &pppControl[pd];
594 pppoe_destroy(&pc->netif);
597 int pppOverEthernetOpen(
struct netif *ethif,
const char *service_name,
const char *concentrator_name,
void (*linkStatusCB)(
void *ctx,
int errCode,
void *arg),
void *linkStatusCtx)
605 if (linkStatusCB ==
NULL) {
612 for (pd = 0; pd < NUM_PPP && pppControl[pd].openFlag != 0; pd++);
616 pc = &pppControl[pd];
617 memset(pc, 0,
sizeof(PPPControl));
621 pc->linkStatusCB = linkStatusCB;
622 pc->linkStatusCtx = linkStatusCtx;
634 if(pppoe_create(ethif, pd, pppOverEthernetLinkStatusCB, &pc->pppoe_sc) !=
ERR_OK) {
639 pppoe_connect(pc->pppoe_sc);
653 PPPControl *pc = &pppControl[pd];
662 pc->errCode = PPPERR_USER;
670 pc->errCode = PPPERR_USER;
685 PPPControl *pc = &pppControl[pd];
702 nPut(PPPControl *pc,
struct pbuf *nb)
707 for(b = nb; b !=
NULL; b = b->
next) {
710 (
"PPP nPut: incomplete sio_write(fd:%"SZT_F", len:%d, c: 0x%"X8_F") c = %d\n", (
size_t)pc->fd, b->
len, c, c));
732 pppAppend(u_char c,
struct pbuf *nb, ext_accm *outACCM)
734 struct pbuf *tb = nb;
751 if (outACCM && ESCAPE_P(*outACCM, c)) {
752 *((u_char*)nb->
payload + nb->
len++) = PPP_ESCAPE;
753 *((u_char*)nb->
payload + nb->
len++) = c ^ PPP_TRANS;
765 pppifOutputOverEthernet(
int pd,
struct pbuf *p)
767 PPPControl *pc = &pppControl[pd];
769 u_short protocol = PPP_IP;
786 if (!pc->pcomp || protocol > 0xFF) {
787 *((u_char*)pb->
payload + i++) = (protocol >> 8) & 0xFF;
789 *((u_char*)pb->
payload + i) = protocol & 0xFF;
794 if(pppoe_xmit(pc->pppoe_sc, pb) !=
ERR_OK) {
797 return PPPERR_DEVICE;
811 int pd = (int)(
size_t)netif->
state;
812 PPPControl *pc = &pppControl[pd];
814 u_short protocol = PPP_IP;
815 u_int fcsOut = PPP_INITFCS;
825 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag || !pb) {
845 return pppifOutputOverEthernet(pd, pb);
852 if (headMB ==
NULL) {
865 if (protocol == PPP_IP && pc->vjEnabled) {
872 protocol = PPP_VJC_COMP;
875 protocol = PPP_VJC_UNCOMP;
891 if ((
sys_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG) {
892 tailMB = pppAppend(PPP_FLAG, tailMB,
NULL);
897 fcsOut = PPP_FCS(fcsOut, PPP_ALLSTATIONS);
898 tailMB = pppAppend(PPP_ALLSTATIONS, tailMB, &pc->outACCM);
899 fcsOut = PPP_FCS(fcsOut, PPP_UI);
900 tailMB = pppAppend(PPP_UI, tailMB, &pc->outACCM);
902 if (!pc->pcomp || protocol > 0xFF) {
903 c = (protocol >> 8) & 0xFF;
904 fcsOut = PPP_FCS(fcsOut, c);
905 tailMB = pppAppend(c, tailMB, &pc->outACCM);
908 fcsOut = PPP_FCS(fcsOut, c);
909 tailMB = pppAppend(c, tailMB, &pc->outACCM);
912 for(p = pb; p; p = p->
next) {
916 sPtr = (u_char*)p->payload;
922 fcsOut = PPP_FCS(fcsOut, c);
925 tailMB = pppAppend(c, tailMB, &pc->outACCM);
931 tailMB = pppAppend(c, tailMB, &pc->outACCM);
932 c = (~fcsOut >> 8) & 0xFF;
933 tailMB = pppAppend(c, tailMB, &pc->outACCM);
934 tailMB = pppAppend(PPP_FLAG, tailMB,
NULL);
939 (
"pppifOutput[%d]: Alloc err - dropping proto=%d\n",
960 pppIOCtl(
int pd,
int cmd,
void *arg)
962 PPPControl *pc = &pppControl[pd];
965 if (pd < 0 || pd >= NUM_PPP) {
969 case PPPCTLG_UPSTATUS:
971 *(
int *)arg = (
int)(pc->if_up);
976 case PPPCTLS_ERRCODE:
978 pc->errCode = *(
int *)arg;
983 case PPPCTLG_ERRCODE:
985 *(
int *)arg = (
int)(pc->errCode);
1014 PPPControl *pc = &pppControl[pd];
1018 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
1029 pppWriteOverEthernet(
int pd,
const u_char *s,
int n)
1031 PPPControl *pc = &pppControl[pd];
1038 LWIP_ASSERT(
"PPPOE_HDRLEN + n <= 0xffff", PPPOE_HDRLEN + n <= 0xffff);
1044 return PPPERR_ALLOC;
1053 if(pppoe_xmit(pc->pppoe_sc, pb) !=
ERR_OK) {
1056 return PPPERR_DEVICE;
1072 pppWrite(
int pd,
const u_char *s,
int n)
1074 PPPControl *pc = &pppControl[pd];
1078 struct pbuf *headMB, *tailMB;
1083 return pppWriteOverEthernet(pd, s, n);
1089 if (headMB ==
NULL) {
1093 return PPPERR_ALLOC;
1100 if ((
sys_jiffies() - pc->lastXMit) >= PPP_MAXIDLEFLAG) {
1101 tailMB = pppAppend(PPP_FLAG, tailMB,
NULL);
1105 fcsOut = PPP_INITFCS;
1111 fcsOut = PPP_FCS(fcsOut, c);
1114 tailMB = pppAppend(c, tailMB, &pc->outACCM);
1119 tailMB = pppAppend(c, tailMB, &pc->outACCM);
1120 c = (~fcsOut >> 8) & 0xFF;
1121 tailMB = pppAppend(c, tailMB, &pc->outACCM);
1122 tailMB = pppAppend(PPP_FLAG, tailMB,
NULL);
1128 (
"pppWrite[%d]: Alloc err - dropping pbuf len=%d\n", pd, headMB->
len));
1134 return PPPERR_ALLOC;
1150 ppp_send_config(
int unit,
u16_t mtu,
u32_t asyncmap,
int pcomp,
int accomp)
1152 PPPControl *pc = &pppControl[unit];
1157 pc->accomp = accomp;
1160 for (i = 0; i < 32/8; i++) {
1161 pc->outACCM[i] = (u_char)((asyncmap >> (8 * i)) & 0xFF);
1165 pc->outACCM[0], pc->outACCM[1], pc->outACCM[2], pc->outACCM[3]));
1173 ppp_set_xaccm(
int unit, ext_accm *accm)
1175 SMEMCPY(pppControl[unit].outACCM, accm,
sizeof(ext_accm));
1178 pppControl[unit].outACCM[0],
1179 pppControl[unit].outACCM[1],
1180 pppControl[unit].outACCM[2],
1181 pppControl[unit].outACCM[3]));
1190 ppp_recv_config(
int unit,
int mru,
u32_t asyncmap,
int pcomp,
int accomp)
1192 PPPControl *pc = &pppControl[unit];
1202 for (i = 0; i < 32 / 8; i++) {
1204 pc->rx.inACCM[i] = (u_char)(asyncmap >> (i * 8));
1209 pc->rx.inACCM[0], pc->rx.inACCM[1], pc->rx.inACCM[2], pc->rx.inACCM[3]));
1220 ccp_test(
int unit,
int opt_len,
int for_transmit, u_char *opt_ptr)
1229 ccp_flags_set(
int unit,
int isopen,
int isup)
1240 ccp_fatal_error(
int unit)
1251 get_idle_time(
int u,
struct ppp_idle *ip)
1284 mask = subnetMask |
htonl(nmask);
1298 sifvjcomp(
int pd,
int vjcomp,
u8_t cidcomp,
u8_t maxcid)
1300 #if PPPOS_SUPPORT && VJ_SUPPORT
1301 PPPControl *pc = &pppControl[pd];
1303 pc->vjEnabled = vjcomp;
1304 pc->vjComp.compressSlot = cidcomp;
1305 pc->vjComp.maxSlotIndex = maxcid;
1306 PPPDEBUG(
LOG_INFO, (
"sifvjcomp: VJ compress enable=%d slot=%d max slot=%d\n",
1307 vjcomp, cidcomp, maxcid));
1322 pppifNetifInit(
struct netif *netif)
1324 netif->
name[0] =
'p';
1325 netif->
name[1] =
'p';
1326 netif->
output = pppifOutput;
1327 netif->
mtu = pppMTU((
int)(
size_t)netif->
state);
1329 #if LWIP_NETIF_HOSTNAME
1343 PPPControl *pc = &pppControl[pd];
1346 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
1351 if (
netif_add(&pc->netif, &pc->addrs.our_ipaddr, &pc->addrs.netmask,
1352 &pc->addrs.his_ipaddr, (
void *)(
size_t)pd, pppifNetifInit,
ip_input)) {
1355 pc->errCode = PPPERR_NONE;
1357 PPPDEBUG(
LOG_DEBUG, (
"sifup: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode));
1358 if (pc->linkStatusCB) {
1359 pc->linkStatusCB(pc->linkStatusCtx, pc->errCode, &pc->addrs);
1374 sifnpmode(
int u,
int proto,
enum NPmode mode)
1388 PPPControl *pc = &pppControl[pd];
1391 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
1399 PPPDEBUG(
LOG_DEBUG, (
"sifdown: unit %d: linkStatusCB=%p errCode=%d\n", pd, pc->linkStatusCB, pc->errCode));
1400 if (pc->linkStatusCB) {
1401 pc->linkStatusCB(pc->linkStatusCtx, PPPERR_CONNECT,
NULL);
1419 PPPControl *pc = &pppControl[pd];
1422 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
1426 SMEMCPY(&pc->addrs.our_ipaddr, &o,
sizeof(o));
1427 SMEMCPY(&pc->addrs.his_ipaddr, &h,
sizeof(h));
1428 SMEMCPY(&pc->addrs.netmask, &m,
sizeof(m));
1429 SMEMCPY(&pc->addrs.dns1, &ns1,
sizeof(ns1));
1430 SMEMCPY(&pc->addrs.dns2, &ns2,
sizeof(ns2));
1445 PPPControl *pc = &pppControl[pd];
1450 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
1454 IP4_ADDR(&pc->addrs.our_ipaddr, 0,0,0,0);
1455 IP4_ADDR(&pc->addrs.his_ipaddr, 0,0,0,0);
1456 IP4_ADDR(&pc->addrs.netmask, 255,255,255,0);
1457 IP4_ADDR(&pc->addrs.dns1, 0,0,0,0);
1458 IP4_ADDR(&pc->addrs.dns2, 0,0,0,0);
1469 PPPControl *pc = &pppControl[pd];
1475 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
1493 PPPControl *pc = &pppControl[pd];
1499 if (pd < 0 || pd >= NUM_PPP || !pc->openFlag) {
1513 #if PPPOS_SUPPORT && PPP_INPROC_OWNTHREAD
1517 pppInputThread(
void *arg)
1520 PPPControlRx *pcrx = arg;
1523 count =
sio_read(pcrx->fd, pcrx->rxbuf, PPPOS_RX_BUFSIZE);
1525 pppInProc(pcrx, pcrx->rxbuf, count);
1537 pppOverEthernetInitFailed(
int pd)
1544 pc = &pppControl[pd];
1545 pppoe_destroy(&pc->netif);
1548 if(pc->linkStatusCB) {
1549 pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL,
NULL);
1554 pppOverEthernetLinkStatusCB(
int pd,
int up)
1557 PPPDEBUG(
LOG_INFO, (
"pppOverEthernetLinkStatusCB: unit %d: Connecting\n", pd));
1560 pppOverEthernetInitFailed(pd);
1566 pppSingleBuf(
struct pbuf *p)
1578 (
"pppSingleBuf: unable to alloc new buf (%d)\n", p->
tot_len));
1592 struct pppInputHeader {
1604 struct pbuf *nb = (
struct pbuf *)arg;
1608 pd = ((
struct pppInputHeader *)nb->
payload)->unit;
1609 protocol = ((
struct pppInputHeader *)nb->
payload)->proto;
1611 if(
pbuf_header(nb, -(
int)
sizeof(
struct pppInputHeader))) {
1626 if(!((protocol == PPP_LQR) || (protocol == PPP_PAP) || (protocol == PPP_CHAP)) ||
1628 PPPDEBUG(
LOG_INFO, (
"pppInput: discarding proto 0x%"X16_F" in phase %d\n", protocol, lcp_phase[pd]));
1635 #if PPPOS_SUPPORT && VJ_SUPPORT
1642 pppControl[pd].netif.input(nb, &pppControl[pd].netif);
1653 case PPP_VJC_UNCOMP:
1654 #if PPPOS_SUPPORT && VJ_SUPPORT
1661 pppControl[pd].netif.input(nb, &pppControl[pd].netif);
1669 (
"pppInput[%d]: drop VJ UnComp in %d:.*H\n",
1676 if (pppControl[pd].netif.
input) {
1677 pppControl[pd].netif.input(nb, &pppControl[pd].netif);
1683 struct protent *protp;
1689 for (i = 0; (protp = ppp_protocols[i]) !=
NULL; ++i) {
1690 if (protp->protocol == protocol && protp->enabled_flag) {
1692 nb = pppSingleBuf(nb);
1705 #if BYTE_ORDER == LITTLE_ENDIAN
1706 protocol =
htons(protocol);
1728 pppDrop(PPPControlRx *pcrx)
1730 if (pcrx->inHead !=
NULL) {
1732 PPPDEBUG(
LOG_INFO, (
"pppDrop: %d:%.*H\n", pcrx->inHead->len, min(60, pcrx->inHead->len * 2), pcrx->inHead->payload));
1734 PPPDEBUG(
LOG_INFO, (
"pppDrop: pbuf len=%d, addr %p\n", pcrx->inHead->len, (
void*)pcrx->inHead));
1735 if (pcrx->inTail && (pcrx->inTail != pcrx->inHead)) {
1739 pcrx->inHead =
NULL;
1740 pcrx->inTail =
NULL;
1758 pppos_input(
int pd, u_char* data,
int len)
1760 pppInProc(&pppControl[pd].rx, data, len);
1767 pppInProc(PPPControlRx *pcrx, u_char *s,
int l)
1769 struct pbuf *nextNBuf;
1779 escaped = ESCAPE_P(pcrx->inACCM, curChar);
1788 if (curChar == PPP_ESCAPE) {
1789 pcrx->inEscaped = 1;
1791 }
else if (curChar == PPP_FLAG) {
1793 if (pcrx->inState <= PDADDRESS) {
1796 }
else if (pcrx->inState < PDDATA) {
1798 (
"pppInProc[%d]: Dropping incomplete packet %d\n",
1799 pcrx->pd, pcrx->inState));
1803 }
else if (pcrx->inFCS != PPP_GOODFCS) {
1805 (
"pppInProc[%d]: Dropping bad fcs 0x%"X16_F" proto=0x%"X16_F"\n",
1806 pcrx->pd, pcrx->inFCS, pcrx->inProtocol));
1813 if(pcrx->inTail->len >= 2) {
1814 pcrx->inTail->len -= 2;
1816 pcrx->inTail->tot_len = pcrx->inTail->len;
1817 if (pcrx->inTail != pcrx->inHead) {
1818 pbuf_cat(pcrx->inHead, pcrx->inTail);
1821 pcrx->inTail->tot_len = pcrx->inTail->len;
1822 if (pcrx->inTail != pcrx->inHead) {
1823 pbuf_cat(pcrx->inHead, pcrx->inTail);
1830 #if PPP_INPROC_MULTITHREADED
1832 PPPDEBUG(
LOG_ERR, (
"pppInProc[%d]: tcpip_callback() failed, dropping packet\n", pcrx->pd));
1838 pppInput(pcrx->inHead);
1840 pcrx->inHead =
NULL;
1841 pcrx->inTail =
NULL;
1845 pcrx->inFCS = PPP_INITFCS;
1846 pcrx->inState = PDADDRESS;
1847 pcrx->inEscaped = 0;
1852 (
"pppInProc[%d]: Dropping ACCM char <%d>\n", pcrx->pd, curChar));
1857 if (pcrx->inEscaped) {
1858 pcrx->inEscaped = 0;
1859 curChar ^= PPP_TRANS;
1863 switch(pcrx->inState) {
1867 if (curChar != PPP_ALLSTATIONS) {
1874 pcrx->inFCS = PPP_INITFCS;
1878 if (curChar == PPP_ALLSTATIONS) {
1879 pcrx->inState = PDCONTROL;
1886 if (curChar == PPP_UI) {
1887 pcrx->inState = PDPROTOCOL1;
1893 (
"pppInProc[%d]: Invalid control <%d>\n", pcrx->pd, curChar));
1894 pcrx->inState = PDSTART;
1901 pcrx->inProtocol = curChar;
1902 pcrx->inState = PDDATA;
1904 pcrx->inProtocol = (u_int)curChar << 8;
1905 pcrx->inState = PDPROTOCOL2;
1909 pcrx->inProtocol |= curChar;
1910 pcrx->inState = PDDATA;
1916 pcrx->inTail->tot_len = pcrx->inTail->len;
1917 if (pcrx->inTail != pcrx->inHead) {
1918 pbuf_cat(pcrx->inHead, pcrx->inTail);
1923 if (nextNBuf ==
NULL) {
1930 pcrx->inState = PDSTART;
1933 if (pcrx->inHead ==
NULL) {
1934 struct pppInputHeader *pih = nextNBuf->
payload;
1936 pih->unit = pcrx->pd;
1937 pih->proto = pcrx->inProtocol;
1939 nextNBuf->
len +=
sizeof(*pih);
1941 pcrx->inHead = nextNBuf;
1943 pcrx->inTail = nextNBuf;
1946 ((u_char*)pcrx->inTail->payload)[pcrx->inTail->len++] = curChar;
1951 pcrx->inFCS = PPP_FCS(pcrx->inFCS, curChar);
1961 pppInProcOverEthernet(
int pd,
struct pbuf *pb)
1963 struct pppInputHeader *pih;
1966 if(pb->
len <
sizeof(inProtocol)) {
1967 PPPDEBUG(
LOG_ERR, (
"pppInProcOverEthernet: too small for protocol field\n"));
1974 if (
pbuf_header(pb,
sizeof(*pih) -
sizeof(inProtocol)) != 0) {
1975 PPPDEBUG(
LOG_ERR, (
"pppInProcOverEthernet: could not allocate room for header\n"));
1982 pih->proto = inProtocol;
1996 #if LWIP_NETIF_STATUS_CALLBACK
2007 netif_set_status_callback(&pppControl[pd].netif, status_callback);
2011 #if LWIP_NETIF_LINK_CALLBACK
2022 netif_set_link_callback(&pppControl[pd].netif, link_callback);