90 #include "netif/ppp/ppp_opts.h" 91 #if PPP_SUPPORT && PPPOE_SUPPORT 104 #include "netif/ppp/ppp_impl.h" 105 #include "netif/ppp/lcp.h" 106 #include "netif/ppp/ipcp.h" 107 #include "netif/ppp/pppoe.h" 110 LWIP_MEMPOOL_DECLARE(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES,
sizeof(
struct pppoe_softc),
"PPPOE_IF")
113 #define PPPOE_ADD_16(PTR, VAL) \ 114 *(PTR)++ = (u8_t)((VAL) / 256); \ 115 *(PTR)++ = (u8_t)((VAL) % 256) 118 #define PPPOE_ADD_HEADER(PTR, CODE, SESS, LEN) \ 119 *(PTR)++ = PPPOE_VERTYPE; \ 121 PPPOE_ADD_16(PTR, SESS); \ 122 PPPOE_ADD_16(PTR, LEN) 124 #define PPPOE_DISC_TIMEOUT (5*1000) 125 #define PPPOE_SLOW_RETRY (60*1000) 126 #define PPPOE_DISC_MAXPADI 4 127 #define PPPOE_DISC_MAXPADR 2 130 #error "PPPOE_SERVER is not yet supported under lwIP!" 132 #define IFF_PASSIVE IFF_LINK0 135 #define PPPOE_ERRORSTRING_LEN 64 139 static err_t pppoe_write(ppp_pcb *ppp,
void *ctx,
struct pbuf *p);
140 static err_t pppoe_netif_output(ppp_pcb *ppp,
void *ctx,
struct pbuf *p, u_short protocol);
141 static void pppoe_connect(ppp_pcb *ppp,
void *ctx);
142 static void pppoe_disconnect(ppp_pcb *ppp,
void *ctx);
143 static err_t pppoe_destroy(ppp_pcb *ppp,
void *ctx);
146 static void pppoe_abort_connect(
struct pppoe_softc *);
148 static void pppoe_clear_softc(
struct pppoe_softc *,
const char *);
152 static void pppoe_timeout(
void *);
155 static err_t pppoe_send_padi(
struct pppoe_softc *);
156 static err_t pppoe_send_padr(
struct pppoe_softc *);
158 static err_t pppoe_send_pado(
struct pppoe_softc *);
159 static err_t pppoe_send_pads(
struct pppoe_softc *);
161 static err_t pppoe_send_padt(
struct netif *, u_int,
const u8_t *);
164 static err_t pppoe_xmit(
struct pppoe_softc *sc,
struct pbuf *pb);
165 static struct pppoe_softc* pppoe_find_softc_by_session(u_int session,
struct netif *rcvif);
166 static struct pppoe_softc* pppoe_find_softc_by_hunique(u8_t *token,
size_t len,
struct netif *rcvif);
169 static struct pppoe_softc *pppoe_softc_list;
172 static const struct link_callbacks pppoe_callbacks = {
190 ppp_pcb *pppoe_create(
struct netif *pppif,
192 const char *service_name,
const char *concentrator_name,
193 ppp_link_status_cb_fn link_status_cb,
void *ctx_cb)
196 struct pppoe_softc *sc;
205 ppp = ppp_new(pppif, &pppoe_callbacks, sc, link_status_cb, ctx_cb);
211 memset(sc, 0,
sizeof(
struct pppoe_softc));
213 sc->sc_ethif = ethif;
215 sc->
next = pppoe_softc_list;
216 pppoe_softc_list = sc;
221 static err_t pppoe_write(ppp_pcb *ppp,
void *ctx,
struct pbuf *p) {
222 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
236 LINK_STATS_INC(link.memerr);
237 LINK_STATS_INC(link.proterr);
238 MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
249 ret = pppoe_xmit(sc, ph);
251 LINK_STATS_INC(link.err);
252 MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
256 MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, (u16_t)tot_len);
257 MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts);
258 LINK_STATS_INC(link.xmit);
263 static err_t pppoe_netif_output(ppp_pcb *ppp,
void *ctx,
struct pbuf *p, u_short protocol) {
264 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
277 LINK_STATS_INC(link.memerr);
278 LINK_STATS_INC(link.proterr);
279 MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
286 PUTSHORT(protocol, pl);
293 if( (err = pppoe_xmit(sc, pb)) !=
ERR_OK) {
294 LINK_STATS_INC(link.err);
295 MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
299 MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, tot_len);
300 MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts);
301 LINK_STATS_INC(link.xmit);
306 pppoe_destroy(ppp_pcb *ppp,
void *ctx)
308 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
309 struct pppoe_softc **copp, *freep;
312 sys_untimeout(pppoe_timeout, sc);
315 for (copp = &pppoe_softc_list; (freep = *copp); copp = &freep->next) {
323 if (sc->sc_concentrator_name) {
326 if (sc->sc_service_name) {
341 static struct pppoe_softc* pppoe_find_softc_by_session(u_int session,
struct netif *rcvif) {
342 struct pppoe_softc *sc;
344 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
345 if (sc->sc_state == PPPOE_STATE_SESSION
346 && sc->sc_session == session
347 && sc->sc_ethif == rcvif) {
356 static struct pppoe_softc* pppoe_find_softc_by_hunique(u8_t *token,
size_t len,
struct netif *rcvif) {
357 struct pppoe_softc *sc, *t;
359 if (len !=
sizeof sc) {
362 MEMCPY(&t, token, len);
364 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
371 PPPDEBUG(LOG_DEBUG, (
"pppoe: alien host unique tag, no session found\n"));
376 if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) {
377 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F
": host unique tag found, but it belongs to a connection in state %d\n",
378 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_state));
381 if (sc->sc_ethif != rcvif) {
382 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F
": wrong interface, not accepting host unique\n",
383 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
395 struct pppoe_softc *sc;
397 const char *err_msg = NULL;
411 if (pppoe_softc_list == NULL) {
416 pb = ppp_singlebuf(pb);
418 if (pb->
len <
sizeof(*ethhdr)) {
422 off =
sizeof(*ethhdr);
431 if (pb->
len - off < (u16_t)PPPOE_HEADERLEN) {
432 PPPDEBUG(LOG_DEBUG, (
"pppoe: packet too short: %d\n", pb->
len));
436 ph = (
struct pppoehdr *) (ethhdr + 1);
437 if (ph->vertype != PPPOE_VERTYPE) {
438 PPPDEBUG(LOG_DEBUG, (
"pppoe: unknown version/type packet: 0x%x\n", ph->vertype));
441 session = lwip_ntohs(ph->session);
442 plen = lwip_ntohs(ph->plen);
445 if (plen + off > pb->
len) {
446 PPPDEBUG(LOG_DEBUG, (
"pppoe: packet content does not fit: data available = %d, packet size = %u\n",
447 pb->
len - off, plen));
456 while (off +
sizeof(pt) <= pb->
len) {
457 MEMCPY(&pt, (u8_t*)pb->
payload + off,
sizeof(pt));
458 tag = lwip_ntohs(pt.tag);
459 len = lwip_ntohs(pt.len);
460 if (off +
sizeof(pt) + len > pb->
len) {
461 PPPDEBUG(LOG_DEBUG, (
"pppoe: tag 0x%x len 0x%x is too long\n", tag, len));
467 case PPPOE_TAG_SNAME:
469 case PPPOE_TAG_ACNAME:
471 case PPPOE_TAG_HUNIQUE:
476 hunique = (u8_t*)pb->
payload + off +
sizeof(pt);
479 sc = pppoe_find_softc_by_hunique((u8_t*)pb->
payload + off +
sizeof(pt), len, netif);
481 case PPPOE_TAG_ACCOOKIE:
482 if (ac_cookie == NULL) {
483 if (len > PPPOE_MAX_AC_COOKIE_LEN) {
484 PPPDEBUG(LOG_DEBUG, (
"pppoe: AC cookie is too long: len = %d, max = %d\n", len, PPPOE_MAX_AC_COOKIE_LEN));
487 ac_cookie = (u8_t*)pb->
payload + off +
sizeof(pt);
492 case PPPOE_TAG_SNAME_ERR:
493 err_msg =
"SERVICE NAME ERROR";
495 case PPPOE_TAG_ACSYS_ERR:
496 err_msg =
"AC SYSTEM ERROR";
498 case PPPOE_TAG_GENERIC_ERR:
499 err_msg =
"GENERIC ERROR";
506 if (err_msg != NULL) {
507 char error_tmp[PPPOE_ERRORSTRING_LEN];
508 u16_t error_len = LWIP_MIN(len,
sizeof(error_tmp)-1);
509 strncpy(error_tmp, (
char*)pb->
payload + off +
sizeof(pt), error_len);
510 error_tmp[error_len] =
'\0';
512 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": %s: %s\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err_msg, error_tmp));
514 PPPDEBUG(LOG_DEBUG, (
"pppoe: %s: %s\n", err_msg, error_tmp));
518 off +=
sizeof(pt) + len;
523 case PPPOE_CODE_PADI:
529 if (LIST_EMPTY(&pppoe_softc_list)) {
532 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
533 if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) {
536 if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
539 if (sc->sc_state == PPPOE_STATE_INITIAL) {
548 if (sc->sc_hunique) {
552 if (sc->sc_hunique == NULL) {
555 sc->sc_hunique_len = hunique_len;
556 MEMCPY(sc->sc_hunique, hunique, hunique_len);
558 MEMCPY(&sc->sc_dest, eh->ether_shost,
sizeof sc->sc_dest);
559 sc->sc_state = PPPOE_STATE_PADO_SENT;
563 case PPPOE_CODE_PADR:
568 if (ac_cookie == NULL) {
570 PPPDEBUG(LOG_DEBUG, (
"pppoe: received PADR but not includes ac_cookie\n"));
573 sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, netif);
576 if (!LIST_EMPTY(&pppoe_softc_list)) {
577 PPPDEBUG(LOG_DEBUG, (
"pppoe: received PADR but could not find request for it\n"));
581 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
582 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F
": received unexpected PADR\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
586 if (sc->sc_hunique) {
590 if (sc->sc_hunique == NULL) {
593 sc->sc_hunique_len = hunique_len;
594 MEMCPY(sc->sc_hunique, hunique, hunique_len);
597 sc->sc_state = PPPOE_STATE_SESSION;
604 case PPPOE_CODE_PADO:
607 if (pppoe_softc_list != NULL) {
608 PPPDEBUG(LOG_DEBUG, (
"pppoe: received PADO but could not find request for it\n"));
612 if (sc->sc_state != PPPOE_STATE_PADI_SENT) {
613 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F
": received unexpected PADO\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
617 sc->sc_ac_cookie_len = ac_cookie_len;
618 MEMCPY(sc->sc_ac_cookie, ac_cookie, ac_cookie_len);
620 MEMCPY(&sc->sc_dest, ethhdr->src.addr,
sizeof(sc->sc_dest.addr));
621 sys_untimeout(pppoe_timeout, sc);
622 sc->sc_padr_retried = 0;
623 sc->sc_state = PPPOE_STATE_PADR_SENT;
624 if ((err = pppoe_send_padr(sc)) != 0) {
625 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
627 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
629 case PPPOE_CODE_PADS:
633 sc->sc_session = session;
634 sys_untimeout(pppoe_timeout, sc);
635 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": session 0x%x connected\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, session));
636 sc->sc_state = PPPOE_STATE_SESSION;
639 case PPPOE_CODE_PADT:
649 pppoe_clear_softc(sc,
"received PADT");
654 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F
": unknown code (0x%"X16_F
") session = 0x%"X16_F
"\n",
655 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
656 (u16_t)ph->code, session));
658 PPPDEBUG(LOG_DEBUG, (
"pppoe: unknown code (0x%"X16_F
") session = 0x%"X16_F
"\n", (u16_t)ph->code, session));
669 pppoe_data_input(
struct netif *netif,
struct pbuf *pb)
672 struct pppoe_softc *sc;
674 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS 675 u8_t shost[ETHER_ADDR_LEN];
678 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS 679 MEMCPY(shost, ((
struct eth_hdr *)pb->
payload)->src.addr,
sizeof(shost));
683 PPPDEBUG(LOG_ERR, (
"pppoe_data_input: pbuf_header failed\n"));
684 LINK_STATS_INC(link.lenerr);
688 if (pb->
len <
sizeof(*ph)) {
689 PPPDEBUG(LOG_DEBUG, (
"pppoe_data_input: could not get PPPoE header\n"));
692 ph = (
struct pppoehdr *)pb->
payload;
694 if (ph->vertype != PPPOE_VERTYPE) {
695 PPPDEBUG(LOG_DEBUG, (
"pppoe (data): unknown version/type packet: 0x%x\n", ph->vertype));
702 session = lwip_ntohs(ph->session);
703 sc = pppoe_find_softc_by_session(session, netif);
705 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS 706 PPPDEBUG(LOG_DEBUG, (
"pppoe: input for unknown session 0x%x, sending PADT\n", session));
707 pppoe_send_padt(netif, session, shost);
712 plen = lwip_ntohs(ph->plen);
714 if (
pbuf_header(pb, -(s16_t)(PPPOE_HEADERLEN)) != 0) {
716 PPPDEBUG(LOG_ERR, (
"pppoe_data_input: pbuf_header PPPOE_HEADERLEN failed\n"));
717 LINK_STATS_INC(link.lenerr);
721 PPPDEBUG(LOG_DEBUG, (
"pppoe_data_input: %c%c%"U16_F
": pkthdr.len=%d, pppoe.len=%d\n",
722 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
730 ppp_input(sc->pcb, pb);
738 pppoe_output(
struct pppoe_softc *sc,
struct pbuf *pb)
747 PPPDEBUG(LOG_ERR, (
"pppoe: %c%c%"U16_F
": pppoe_output: could not allocate room for Ethernet header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
748 LINK_STATS_INC(link.lenerr);
754 ethhdr->type = lwip_htons(etype);
755 MEMCPY(ðhdr->dest.addr, &sc->sc_dest.addr,
sizeof(ethhdr->dest.addr));
756 MEMCPY(ðhdr->src.addr, &sc->sc_ethif->hwaddr,
sizeof(ethhdr->src.addr));
758 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
" (%x) state=%d, session=0x%x output -> %02"X16_F
":%02"X16_F
":%02"X16_F
":%02"X16_F
":%02"X16_F
":%02"X16_F
", len=%d\n",
759 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, etype,
760 sc->sc_state, sc->sc_session,
761 sc->sc_dest.addr[0], sc->sc_dest.addr[1], sc->sc_dest.addr[2], sc->sc_dest.addr[3], sc->sc_dest.addr[4], sc->sc_dest.addr[5],
764 res = sc->sc_ethif->linkoutput(sc->sc_ethif, pb);
772 pppoe_send_padi(
struct pppoe_softc *sc)
782 len = 2 + 2 + 2 + 2 +
sizeof sc;
784 if (sc->sc_service_name != NULL) {
785 l1 = (int)strlen(sc->sc_service_name);
788 if (sc->sc_concentrator_name != NULL) {
789 l2 = (int)strlen(sc->sc_concentrator_name);
793 LWIP_ASSERT(
"sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff",
794 sizeof(
struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff);
801 LWIP_ASSERT(
"pb->tot_len == pb->len", pb->
tot_len == pb->
len);
805 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADI, 0, (u16_t)
len);
806 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
808 if (sc->sc_service_name != NULL) {
810 MEMCPY(p, sc->sc_service_name, l1);
818 if (sc->sc_concentrator_name != NULL) {
819 PPPOE_ADD_16(p, PPPOE_TAG_ACNAME);
821 MEMCPY(p, sc->sc_concentrator_name, l2);
825 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
826 PPPOE_ADD_16(p,
sizeof(sc));
827 MEMCPY(p, &sc,
sizeof sc);
830 return pppoe_output(sc, pb);
834 pppoe_timeout(
void *arg)
838 struct pppoe_softc *sc = (
struct pppoe_softc*)arg;
840 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": timeout\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
842 switch (sc->sc_state) {
843 case PPPOE_STATE_PADI_SENT:
853 if (sc->sc_padi_retried < 0xff) {
854 sc->sc_padi_retried++;
856 if (!sc->pcb->settings.persist && sc->sc_padi_retried >= PPPOE_DISC_MAXPADI) {
858 if ((sc->sc_sppp.pp_if.if_flags & IFF_LINK1) == 0) {
860 retry_wait = PPPOE_SLOW_RETRY;
864 pppoe_abort_connect(sc);
869 retry_wait = LWIP_MIN(PPPOE_DISC_TIMEOUT * sc->sc_padi_retried, PPPOE_SLOW_RETRY);
870 if ((err = pppoe_send_padi(sc)) != 0) {
871 sc->sc_padi_retried--;
872 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": failed to transmit PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
874 sys_timeout(retry_wait, pppoe_timeout, sc);
877 case PPPOE_STATE_PADR_SENT:
878 sc->sc_padr_retried++;
879 if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) {
880 MEMCPY(&sc->sc_dest, ethbroadcast.addr,
sizeof(sc->sc_dest));
881 sc->sc_state = PPPOE_STATE_PADI_SENT;
882 sc->sc_padr_retried = 0;
883 if ((err = pppoe_send_padi(sc)) != 0) {
884 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
886 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc);
889 if ((err = pppoe_send_padr(sc)) != 0) {
890 sc->sc_padr_retried--;
891 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
893 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
902 pppoe_connect(ppp_pcb *ppp,
void *ctx)
905 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
908 #if PPP_IPV4_SUPPORT && VJ_SUPPORT 909 ipcp_options *ipcp_wo;
910 ipcp_options *ipcp_ao;
914 sc->sc_ac_cookie_len = 0;
915 sc->sc_padi_retried = 0;
916 sc->sc_padr_retried = 0;
918 MEMCPY(&sc->sc_dest, ethbroadcast.addr,
sizeof(sc->sc_dest));
921 if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
926 lcp_wo = &ppp->lcp_wantoptions;
927 lcp_wo->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2;
928 lcp_wo->neg_asyncmap = 0;
929 lcp_wo->neg_pcompression = 0;
930 lcp_wo->neg_accompression = 0;
934 lcp_ao = &ppp->lcp_allowoptions;
935 lcp_ao->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2;
936 lcp_ao->neg_asyncmap = 0;
937 lcp_ao->neg_pcompression = 0;
938 lcp_ao->neg_accompression = 0;
940 #if PPP_IPV4_SUPPORT && VJ_SUPPORT 941 ipcp_wo = &ppp->ipcp_wantoptions;
945 ipcp_ao = &ppp->ipcp_allowoptions;
951 sc->sc_state = PPPOE_STATE_PADI_SENT;
952 if ((err = pppoe_send_padi(sc)) != 0) {
953 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err));
955 sys_timeout(PPPOE_DISC_TIMEOUT, pppoe_timeout, sc);
960 pppoe_disconnect(ppp_pcb *ppp,
void *ctx)
962 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
964 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
965 if (sc->sc_state == PPPOE_STATE_SESSION) {
966 pppoe_send_padt(sc->sc_ethif, sc->sc_session, (
const u8_t *)&sc->sc_dest);
970 sys_untimeout(pppoe_timeout, sc);
971 sc->sc_state = PPPOE_STATE_INITIAL;
973 if (sc->sc_hunique) {
975 sc->sc_hunique = NULL;
977 sc->sc_hunique_len = 0;
985 pppoe_abort_connect(
struct pppoe_softc *sc)
987 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F
": could not establish connection\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
988 sc->sc_state = PPPOE_STATE_INITIAL;
989 ppp_link_failed(sc->pcb);
994 pppoe_send_padr(
struct pppoe_softc *sc)
1003 len = 2 + 2 + 2 + 2 +
sizeof(sc);
1005 if (sc->sc_service_name != NULL) {
1006 l1 = strlen(sc->sc_service_name);
1010 if (sc->sc_ac_cookie_len > 0) {
1011 len += 2 + 2 + sc->sc_ac_cookie_len;
1013 LWIP_ASSERT(
"sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff",
1014 sizeof(
struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff);
1019 LWIP_ASSERT(
"pb->tot_len == pb->len", pb->
tot_len == pb->
len);
1021 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADR, 0, len);
1022 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
1024 if (sc->sc_service_name != NULL) {
1025 PPPOE_ADD_16(p, l1);
1026 MEMCPY(p, sc->sc_service_name, l1);
1033 if (sc->sc_ac_cookie_len > 0) {
1034 PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
1035 PPPOE_ADD_16(p, sc->sc_ac_cookie_len);
1036 MEMCPY(p, sc->sc_ac_cookie, sc->sc_ac_cookie_len);
1037 p += sc->sc_ac_cookie_len;
1039 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
1040 PPPOE_ADD_16(p,
sizeof(sc));
1041 MEMCPY(p, &sc,
sizeof sc);
1043 return pppoe_output(sc, pb);
1048 pppoe_send_padt(
struct netif *outgoing_if, u_int session,
const u8_t *dest)
1059 LWIP_ASSERT(
"pb->tot_len == pb->len", pb->
tot_len == pb->
len);
1064 MEMCPY(ðhdr->dest.addr, dest,
sizeof(ethhdr->dest.addr));
1065 MEMCPY(ðhdr->src.addr, &outgoing_if->
hwaddr,
sizeof(ethhdr->src.addr));
1067 p = (u8_t*)(ethhdr + 1);
1068 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADT, session, 0);
1070 res = outgoing_if->
linkoutput(outgoing_if, pb);
1079 pppoe_send_pado(
struct pppoe_softc *sc)
1088 len += 2 + 2 +
sizeof(sc);
1090 len += 2 + 2 + sc->sc_hunique_len;
1095 LWIP_ASSERT(
"pb->tot_len == pb->len", pb->
tot_len == pb->
len);
1097 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADO, 0, len);
1098 PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
1099 PPPOE_ADD_16(p,
sizeof(sc));
1100 MEMCPY(p, &sc,
sizeof(sc));
1102 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
1103 PPPOE_ADD_16(p, sc->sc_hunique_len);
1104 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
1105 return pppoe_output(sc, pb);
1109 pppoe_send_pads(
struct pppoe_softc *sc)
1115 sc->sc_session = mono_time.tv_sec % 0xff + 1;
1119 len += 2 + 2 + 2 + 2 + sc->sc_hunique_len;
1120 if (sc->sc_service_name != NULL) {
1121 l1 = strlen(sc->sc_service_name);
1128 LWIP_ASSERT(
"pb->tot_len == pb->len", pb->
tot_len == pb->
len);
1130 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len);
1131 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
1132 if (sc->sc_service_name != NULL) {
1133 PPPOE_ADD_16(p, l1);
1134 MEMCPY(p, sc->sc_service_name, l1);
1139 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
1140 PPPOE_ADD_16(p, sc->sc_hunique_len);
1141 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
1142 return pppoe_output(sc, pb);
1147 pppoe_xmit(
struct pppoe_softc *sc,
struct pbuf *pb)
1155 if (
pbuf_header(pb, (s16_t)(PPPOE_HEADERLEN)) != 0) {
1157 PPPDEBUG(LOG_ERR, (
"pppoe: %c%c%"U16_F
": pppoe_xmit: could not allocate room for PPPoE header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
1158 LINK_STATS_INC(link.lenerr);
1164 PPPOE_ADD_HEADER(p, 0, sc->sc_session, len);
1166 return pppoe_output(sc, pb);
1171 pppoe_ifattach_hook(
void *arg,
struct pbuf **mp,
struct netif *ifp,
int dir)
1173 struct pppoe_softc *sc;
1176 if (mp != (
struct pbuf **)PFIL_IFNET_DETACH) {
1180 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
1181 if (sc->sc_ethif != ifp) {
1184 if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
1185 sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1186 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F
": ethernet interface detached, going down\n",
1187 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
1189 sc->sc_ethif = NULL;
1190 pppoe_clear_softc(sc,
"ethernet interface detached");
1199 pppoe_clear_softc(
struct pppoe_softc *sc,
const char *message)
1204 sys_untimeout(pppoe_timeout, sc);
1205 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F
": session 0x%x terminated, %s\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_session, message));
1206 sc->sc_state = PPPOE_STATE_INITIAL;
1207 ppp_link_end(sc->pcb);
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
void mem_free(void *rmem)
#define LWIP_MEMPOOL_ALLOC(name)
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
#define LWIP_MEMPOOL_FREE(name, x)
void pbuf_chain(struct pbuf *h, struct pbuf *t)
#define LWIP_MEMPOOL_DECLARE(name, num, size, desc)
void pbuf_cat(struct pbuf *h, struct pbuf *t)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
#define LWIP_UNUSED_ARG(x)
u8_t pbuf_free(struct pbuf *p)
void * mem_malloc(mem_size_t size)
netif_linkoutput_fn linkoutput