72 #if PPP_SUPPORT && PPPOE_SUPPORT 90 #define PPPOE_ADD_16(PTR, VAL) \ 91 *(PTR)++ = (u8_t)((VAL) / 256); \ 92 *(PTR)++ = (u8_t)((VAL) % 256) 95 #define PPPOE_ADD_HEADER(PTR, CODE, SESS, LEN) \ 96 *(PTR)++ = PPPOE_VERTYPE; \ 98 PPPOE_ADD_16(PTR, SESS); \ 99 PPPOE_ADD_16(PTR, LEN) 101 #define PPPOE_DISC_TIMEOUT (5*1000) 102 #define PPPOE_SLOW_RETRY (60*1000) 103 #define PPPOE_DISC_MAXPADI 4 104 #define PPPOE_DISC_MAXPADR 2 107 #error "PPPOE_SERVER is not yet supported under lwIP!" 109 #define IFF_PASSIVE IFF_LINK0 112 #define PPPOE_ERRORSTRING_LEN 64 116 static err_t pppoe_write(ppp_pcb *ppp,
void *ctx,
struct pbuf *p);
117 static err_t pppoe_netif_output(ppp_pcb *ppp,
void *ctx,
struct pbuf *p, u_short protocol);
118 static err_t pppoe_connect(ppp_pcb *ppp,
void *ctx);
119 static void pppoe_disconnect(ppp_pcb *ppp,
void *ctx);
120 static err_t pppoe_destroy(ppp_pcb *ppp,
void *ctx);
123 static void pppoe_abort_connect(
struct pppoe_softc *);
125 static void pppoe_clear_softc(
struct pppoe_softc *,
const char *);
129 static void pppoe_timeout(
void *);
132 static err_t pppoe_send_padi(
struct pppoe_softc *);
133 static err_t pppoe_send_padr(
struct pppoe_softc *);
135 static err_t pppoe_send_pado(
struct pppoe_softc *);
136 static err_t pppoe_send_pads(
struct pppoe_softc *);
138 static err_t pppoe_send_padt(
struct netif *, u_int,
const u8_t *);
141 static err_t pppoe_xmit(
struct pppoe_softc *sc,
struct pbuf *pb);
142 static struct pppoe_softc* pppoe_find_softc_by_session(u_int session,
struct netif *rcvif);
143 static struct pppoe_softc* pppoe_find_softc_by_hunique(
u8_t *token,
size_t len,
struct netif *rcvif);
146 static struct pppoe_softc *pppoe_softc_list;
149 static const struct link_callbacks pppoe_callbacks = {
167 ppp_pcb *pppoe_create(
struct netif *pppif,
169 const char *service_name,
const char *concentrator_name,
170 ppp_link_status_cb_fn link_status_cb,
void *ctx_cb)
173 struct pppoe_softc *sc;
177 sc = (
struct pppoe_softc *)
memp_malloc(MEMP_PPPOE_IF);
182 ppp = ppp_new(pppif, &pppoe_callbacks, sc, link_status_cb, ctx_cb);
188 memset(sc, 0,
sizeof(
struct pppoe_softc));
190 MEMCPY(&sc->sc_dest, ethbroadcast.addr,
sizeof(sc->sc_dest));
192 sc->sc_ethif = ethif;
194 sc->
next = pppoe_softc_list;
195 pppoe_softc_list = sc;
200 static err_t pppoe_write(ppp_pcb *ppp,
void *ctx,
struct pbuf *p) {
201 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
228 ret = pppoe_xmit(sc, ph);
242 static err_t pppoe_netif_output(ppp_pcb *ppp,
void *ctx,
struct pbuf *p, u_short protocol) {
243 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
265 PUTSHORT(protocol, pl);
272 if( (err = pppoe_xmit(sc, pb)) !=
ERR_OK) {
285 pppoe_destroy(ppp_pcb *ppp,
void *ctx)
287 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
288 struct pppoe_softc **copp, *freep;
294 for (copp = &pppoe_softc_list; (freep = *copp); copp = &freep->next) {
302 if (sc->sc_concentrator_name) {
305 if (sc->sc_service_name) {
320 static struct pppoe_softc* pppoe_find_softc_by_session(u_int session,
struct netif *rcvif) {
321 struct pppoe_softc *sc;
327 for (sc = pppoe_softc_list; sc !=
NULL; sc = sc->next) {
328 if (sc->sc_state == PPPOE_STATE_SESSION
329 && sc->sc_session == session
330 && sc->sc_ethif == rcvif) {
339 static struct pppoe_softc* pppoe_find_softc_by_hunique(
u8_t *token,
size_t len,
struct netif *rcvif) {
340 struct pppoe_softc *sc, *t;
342 if (pppoe_softc_list ==
NULL) {
346 if (len !=
sizeof sc) {
351 for (sc = pppoe_softc_list; sc !=
NULL; sc = sc->next) {
358 PPPDEBUG(LOG_DEBUG, (
"pppoe: alien host unique tag, no session found\n"));
363 if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) {
364 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F": host unique tag found, but it belongs to a connection in state %d\n",
365 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_state));
368 if (sc->sc_ethif != rcvif) {
369 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F": wrong interface, not accepting host unique\n",
370 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
382 struct pppoe_softc *sc;
384 const char *err_msg =
NULL;
395 struct eth_hdr *ethhdr;
398 if (pppoe_softc_list ==
NULL) {
403 pb = ppp_singlebuf(pb);
405 if (pb->
len <
sizeof(*ethhdr)) {
408 ethhdr = (
struct eth_hdr *)pb->
payload;
409 off =
sizeof(*ethhdr);
418 if (pb->
len - off < (
u16_t)PPPOE_HEADERLEN) {
419 PPPDEBUG(LOG_DEBUG, (
"pppoe: packet too short: %d\n", pb->
len));
423 ph = (
struct pppoehdr *) (ethhdr + 1);
424 if (ph->vertype != PPPOE_VERTYPE) {
425 PPPDEBUG(LOG_DEBUG, (
"pppoe: unknown version/type packet: 0x%x\n", ph->vertype));
428 session =
ntohs(ph->session);
429 plen =
ntohs(ph->plen);
432 if (plen + off > pb->
len) {
433 PPPDEBUG(LOG_DEBUG, (
"pppoe: packet content does not fit: data available = %d, packet size = %u\n",
434 pb->
len - off, plen));
443 while (off +
sizeof(pt) <= pb->
len) {
447 if (off +
sizeof(pt) + len > pb->
len) {
448 PPPDEBUG(LOG_DEBUG, (
"pppoe: tag 0x%x len 0x%x is too long\n", tag, len));
454 case PPPOE_TAG_SNAME:
456 case PPPOE_TAG_ACNAME:
458 case PPPOE_TAG_HUNIQUE:
466 sc = pppoe_find_softc_by_hunique((
u8_t*)pb->
payload + off +
sizeof(pt), len, netif);
468 case PPPOE_TAG_ACCOOKIE:
469 if (ac_cookie ==
NULL) {
475 case PPPOE_TAG_SNAME_ERR:
476 err_msg =
"SERVICE NAME ERROR";
478 case PPPOE_TAG_ACSYS_ERR:
479 err_msg =
"AC SYSTEM ERROR";
481 case PPPOE_TAG_GENERIC_ERR:
482 err_msg =
"GENERIC ERROR";
489 if (err_msg !=
NULL) {
490 char error_tmp[PPPOE_ERRORSTRING_LEN];
492 strncpy(error_tmp, (
char*)pb->
payload + off +
sizeof(pt), error_len);
493 error_tmp[error_len] =
'\0';
495 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));
497 PPPDEBUG(LOG_DEBUG, (
"pppoe: %s: %s\n", err_msg, error_tmp));
501 off +=
sizeof(pt) + len;
506 case PPPOE_CODE_PADI:
512 if (LIST_EMPTY(&pppoe_softc_list)) {
515 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
516 if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) {
519 if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
522 if (sc->sc_state == PPPOE_STATE_INITIAL) {
531 if (sc->sc_hunique) {
535 if (sc->sc_hunique ==
NULL) {
538 sc->sc_hunique_len = hunique_len;
539 MEMCPY(sc->sc_hunique, hunique, hunique_len);
541 MEMCPY(&sc->sc_dest, eh->ether_shost,
sizeof sc->sc_dest);
542 sc->sc_state = PPPOE_STATE_PADO_SENT;
546 case PPPOE_CODE_PADR:
551 if (ac_cookie ==
NULL) {
553 PPPDEBUG(LOG_DEBUG, (
"pppoe: received PADR but not includes ac_cookie\n"));
556 sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, netif);
559 if (!LIST_EMPTY(&pppoe_softc_list)) {
560 PPPDEBUG(LOG_DEBUG, (
"pppoe: received PADR but could not find request for it\n"));
564 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
565 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));
569 if (sc->sc_hunique) {
573 if (sc->sc_hunique ==
NULL) {
576 sc->sc_hunique_len = hunique_len;
577 MEMCPY(sc->sc_hunique, hunique, hunique_len);
580 sc->sc_state = PPPOE_STATE_SESSION;
587 case PPPOE_CODE_PADO:
590 if (pppoe_softc_list !=
NULL) {
591 PPPDEBUG(LOG_DEBUG, (
"pppoe: received PADO but could not find request for it\n"));
595 if (sc->sc_state != PPPOE_STATE_PADI_SENT) {
596 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));
600 sc->sc_ac_cookie_len = ac_cookie_len;
601 MEMCPY(sc->sc_ac_cookie, ac_cookie, ac_cookie_len);
603 MEMCPY(&sc->sc_dest, ethhdr->src.addr,
sizeof(sc->sc_dest.addr));
605 sc->sc_padr_retried = 0;
606 sc->sc_state = PPPOE_STATE_PADR_SENT;
607 if ((err = pppoe_send_padr(sc)) != 0) {
608 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));
610 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
612 case PPPOE_CODE_PADS:
616 sc->sc_session = session;
618 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));
619 sc->sc_state = PPPOE_STATE_SESSION;
622 case PPPOE_CODE_PADT:
632 pppoe_clear_softc(sc,
"received PADT");
637 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F": unknown code (0x%"X16_F") session = 0x%"X16_F"\n",
638 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
639 (
u16_t)ph->code, session));
641 PPPDEBUG(LOG_DEBUG, (
"pppoe: unknown code (0x%"X16_F") session = 0x%"X16_F"\n", (
u16_t)ph->code, session));
652 pppoe_data_input(
struct netif *netif,
struct pbuf *pb)
655 struct pppoe_softc *sc;
657 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS 658 u8_t shost[ETHER_ADDR_LEN];
661 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS 662 MEMCPY(shost, ((
struct eth_hdr *)pb->
payload)->src.addr,
sizeof(shost));
666 PPPDEBUG(LOG_ERR, (
"pppoe_data_input: pbuf_header failed\n"));
671 if (pb->
len <
sizeof(*ph)) {
672 PPPDEBUG(LOG_DEBUG, (
"pppoe_data_input: could not get PPPoE header\n"));
675 ph = (
struct pppoehdr *)pb->
payload;
677 if (ph->vertype != PPPOE_VERTYPE) {
678 PPPDEBUG(LOG_DEBUG, (
"pppoe (data): unknown version/type packet: 0x%x\n", ph->vertype));
685 session =
ntohs(ph->session);
686 sc = pppoe_find_softc_by_session(session, netif);
688 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS 689 PPPDEBUG(LOG_DEBUG, (
"pppoe: input for unknown session 0x%x, sending PADT\n", session));
690 pppoe_send_padt(netif, session, shost);
695 plen =
ntohs(ph->plen);
699 PPPDEBUG(LOG_ERR, (
"pppoe_data_input: pbuf_header PPPOE_HEADERLEN failed\n"));
704 PPPDEBUG(LOG_DEBUG, (
"pppoe_data_input: %c%c%"U16_F": pkthdr.len=%d, pppoe.len=%d\n",
705 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
713 ppp_input(sc->pcb, pb);
721 pppoe_output(
struct pppoe_softc *sc,
struct pbuf *pb)
723 struct eth_hdr *ethhdr;
735 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));
740 ethhdr = (
struct eth_hdr *)pb->
payload;
741 etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : ETHTYPE_PPPOEDISC;
742 ethhdr->type =
htons(etype);
743 MEMCPY(ðhdr->dest.addr, &sc->sc_dest.addr,
sizeof(ethhdr->dest.addr));
744 MEMCPY(ðhdr->src.addr, &sc->sc_ethif->hwaddr,
sizeof(ethhdr->src.addr));
747 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, etype,
748 sc->sc_state, sc->sc_session,
749 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],
752 res = sc->sc_ethif->linkoutput(sc->sc_ethif, pb);
760 pppoe_send_padi(
struct pppoe_softc *sc)
769 if (sc->sc_state >PPPOE_STATE_PADI_SENT) {
770 PPPDEBUG(LOG_ERR, (
"ERROR: pppoe_send_padi in state %d", sc->sc_state));
774 len = 2 + 2 + 2 + 2 +
sizeof sc;
776 if (sc->sc_service_name !=
NULL) {
777 l1 = (int)strlen(sc->sc_service_name);
780 if (sc->sc_concentrator_name !=
NULL) {
781 l2 = (int)strlen(sc->sc_concentrator_name);
785 LWIP_ASSERT(
"sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff",
786 sizeof(
struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff);
797 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADI, 0, (
u16_t)
len);
798 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
800 if (sc->sc_service_name !=
NULL) {
802 MEMCPY(p, sc->sc_service_name, l1);
810 if (sc->sc_concentrator_name !=
NULL) {
811 PPPOE_ADD_16(p, PPPOE_TAG_ACNAME);
813 MEMCPY(p, sc->sc_concentrator_name, l2);
817 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
818 PPPOE_ADD_16(p,
sizeof(sc));
819 MEMCPY(p, &sc,
sizeof sc);
822 return pppoe_output(sc, pb);
826 pppoe_timeout(
void *arg)
830 struct pppoe_softc *sc = (
struct pppoe_softc*)arg;
832 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F": timeout\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
834 switch (sc->sc_state) {
835 case PPPOE_STATE_PADI_SENT:
845 if (sc->sc_padi_retried < 0xff) {
846 sc->sc_padi_retried++;
848 if (!sc->pcb->settings.persist && sc->sc_padi_retried >= PPPOE_DISC_MAXPADI) {
850 if ((sc->sc_sppp.pp_if.if_flags & IFF_LINK1) == 0) {
852 retry_wait = PPPOE_SLOW_RETRY;
856 pppoe_abort_connect(sc);
861 retry_wait =
LWIP_MIN(PPPOE_DISC_TIMEOUT * sc->sc_padi_retried, PPPOE_SLOW_RETRY);
862 if ((err = pppoe_send_padi(sc)) != 0) {
863 sc->sc_padi_retried--;
864 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));
869 case PPPOE_STATE_PADR_SENT:
870 sc->sc_padr_retried++;
871 if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) {
872 MEMCPY(&sc->sc_dest, ethbroadcast.addr,
sizeof(sc->sc_dest));
873 sc->sc_state = PPPOE_STATE_PADI_SENT;
874 sc->sc_padr_retried = 0;
875 if ((err = pppoe_send_padi(sc)) != 0) {
876 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));
878 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc);
881 if ((err = pppoe_send_padr(sc)) != 0) {
882 sc->sc_padr_retried--;
883 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));
885 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
894 pppoe_connect(ppp_pcb *ppp,
void *ctx)
897 struct pppoe_softc *sc = (
struct pppoe_softc *)ctx;
900 #if PPP_IPV4_SUPPORT && VJ_SUPPORT 901 ipcp_options *ipcp_wo;
902 ipcp_options *ipcp_ao;
905 if (sc->sc_state != PPPOE_STATE_INITIAL) {
906 #ifdef LWIP_PROVIDE_ERRNO 916 sc->sc_padi_retried = 0;
917 sc->sc_padr_retried = 0;
920 if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
927 lcp_wo = &ppp->lcp_wantoptions;
928 lcp_wo->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2;
929 lcp_wo->neg_asyncmap = 0;
930 lcp_wo->neg_pcompression = 0;
931 lcp_wo->neg_accompression = 0;
933 lcp_ao = &ppp->lcp_allowoptions;
934 lcp_ao->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2;
935 lcp_ao->neg_asyncmap = 0;
936 lcp_ao->neg_pcompression = 0;
937 lcp_ao->neg_accompression = 0;
939 #if PPP_IPV4_SUPPORT && VJ_SUPPORT 940 ipcp_wo = &ppp->ipcp_wantoptions;
944 ipcp_ao = &ppp->ipcp_allowoptions;
950 sc->sc_state = PPPOE_STATE_PADI_SENT;
951 if ((err = pppoe_send_padi(sc)) != 0) {
952 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));
954 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 if (sc->sc_state < PPPOE_STATE_SESSION) {
968 PPPDEBUG(LOG_DEBUG, (
"pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
969 pppoe_send_padt(sc->sc_ethif, sc->sc_session, (
const u8_t *)&sc->sc_dest);
972 sc->sc_state = PPPOE_STATE_INITIAL;
973 MEMCPY(&sc->sc_dest, ethbroadcast.addr,
sizeof(sc->sc_dest));
974 sc->sc_ac_cookie_len = 0;
976 if (sc->sc_hunique) {
978 sc->sc_hunique =
NULL;
980 sc->sc_hunique_len = 0;
983 sc->sc_padi_retried = 0;
984 sc->sc_padr_retried = 0;
992 pppoe_abort_connect(
struct pppoe_softc *sc)
994 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));
997 sc->sc_state = PPPOE_STATE_INITIAL;
998 MEMCPY(&sc->sc_dest, ethbroadcast.addr,
sizeof(sc->sc_dest));
999 sc->sc_ac_cookie_len = 0;
1001 sc->sc_padi_retried = 0;
1002 sc->sc_padr_retried = 0;
1004 ppp_link_failed(sc->pcb);
1009 pppoe_send_padr(
struct pppoe_softc *sc)
1018 if (sc->sc_state != PPPOE_STATE_PADR_SENT) {
1022 len = 2 + 2 + 2 + 2 +
sizeof(sc);
1024 if (sc->sc_service_name !=
NULL) {
1025 l1 = strlen(sc->sc_service_name);
1029 if (sc->sc_ac_cookie_len > 0) {
1030 len += 2 + 2 + sc->sc_ac_cookie_len;
1032 LWIP_ASSERT(
"sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff",
1033 sizeof(
struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff);
1040 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADR, 0, len);
1041 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
1043 if (sc->sc_service_name !=
NULL) {
1044 PPPOE_ADD_16(p, l1);
1045 MEMCPY(p, sc->sc_service_name, l1);
1052 if (sc->sc_ac_cookie_len > 0) {
1053 PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
1054 PPPOE_ADD_16(p, sc->sc_ac_cookie_len);
1055 MEMCPY(p, sc->sc_ac_cookie, sc->sc_ac_cookie_len);
1056 p += sc->sc_ac_cookie_len;
1058 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
1059 PPPOE_ADD_16(p,
sizeof(sc));
1060 MEMCPY(p, &sc,
sizeof sc);
1062 return pppoe_output(sc, pb);
1067 pppoe_send_padt(
struct netif *outgoing_if, u_int session,
const u8_t *dest)
1070 struct eth_hdr *ethhdr;
1081 ethhdr = (
struct eth_hdr *)pb->
payload;
1082 ethhdr->type =
PP_HTONS(ETHTYPE_PPPOEDISC);
1083 MEMCPY(ðhdr->dest.addr, dest,
sizeof(ethhdr->dest.addr));
1084 MEMCPY(ðhdr->src.addr, &outgoing_if->
hwaddr,
sizeof(ethhdr->src.addr));
1086 p = (
u8_t*)(ethhdr + 1);
1087 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADT, session, 0);
1089 res = outgoing_if->
linkoutput(outgoing_if, pb);
1098 pppoe_send_pado(
struct pppoe_softc *sc)
1104 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
1111 len += 2 + 2 +
sizeof(sc);
1113 len += 2 + 2 + sc->sc_hunique_len;
1120 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADO, 0, len);
1121 PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
1122 PPPOE_ADD_16(p,
sizeof(sc));
1123 MEMCPY(p, &sc,
sizeof(sc));
1125 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
1126 PPPOE_ADD_16(p, sc->sc_hunique_len);
1127 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
1128 return pppoe_output(sc, pb);
1132 pppoe_send_pads(
struct pppoe_softc *sc)
1138 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
1142 sc->sc_session = mono_time.tv_sec % 0xff + 1;
1146 len += 2 + 2 + 2 + 2 + sc->sc_hunique_len;
1147 if (sc->sc_service_name !=
NULL) {
1148 l1 = strlen(sc->sc_service_name);
1157 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len);
1158 PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
1159 if (sc->sc_service_name !=
NULL) {
1160 PPPOE_ADD_16(p, l1);
1161 MEMCPY(p, sc->sc_service_name, l1);
1166 PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
1167 PPPOE_ADD_16(p, sc->sc_hunique_len);
1168 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
1169 return pppoe_output(sc, pb);
1174 pppoe_xmit(
struct pppoe_softc *sc,
struct pbuf *pb)
1180 if (sc->sc_state < PPPOE_STATE_SESSION) {
1191 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));
1198 PPPOE_ADD_HEADER(p, 0, sc->sc_session, len);
1200 return pppoe_output(sc, pb);
1205 pppoe_ifattach_hook(
void *arg,
struct pbuf **mp,
struct netif *ifp,
int dir)
1207 struct pppoe_softc *sc;
1210 if (mp != (
struct pbuf **)PFIL_IFNET_DETACH) {
1214 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
1215 if (sc->sc_ethif != ifp) {
1218 if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
1219 sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1220 PPPDEBUG(LOG_DEBUG, (
"%c%c%"U16_F": ethernet interface detached, going down\n",
1221 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
1223 sc->sc_ethif =
NULL;
1224 pppoe_clear_softc(sc,
"ethernet interface detached");
1233 pppoe_clear_softc(
struct pppoe_softc *sc,
const char *message)
1239 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));
1241 sc->sc_state = PPPOE_STATE_INITIAL;
1244 ppp_link_end(sc->pcb);
1247 MEMCPY(&sc->sc_dest, ethbroadcast.addr,
sizeof(sc->sc_dest));
1248 sc->sc_ac_cookie_len = 0;
1250 sc->sc_padi_retried = 0;
1251 sc->sc_padr_retried = 0;
void mem_free(void *rmem)
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
#define MEMCPY(dst, src, len)
void memp_free(memp_t type, void *mem)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
#define MIB2_STATS_NETIF_ADD(n, x, val)
netif_linkoutput_fn linkoutput
u8_t pbuf_free(struct pbuf *p)
void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
void pbuf_chain(struct pbuf *h, struct pbuf *t)
#define LINK_STATS_INC(x)
#define LWIP_ASSERT(message, assertion)
void pbuf_cat(struct pbuf *h, struct pbuf *t)
void * mem_malloc(mem_size_t size)
#define MIB2_STATS_NETIF_INC(n, x)
void * memp_malloc(memp_t type)
#define LWIP_UNUSED_ARG(x)
void sys_untimeout(sys_timeout_handler handler, void *arg)