Lines Matching refs:sc
145 static err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb);
177 struct pppoe_softc *sc;
184 sc = (struct pppoe_softc *)LWIP_MEMPOOL_ALLOC(PPPOE_IF);
185 if (sc == NULL) {
189 ppp = ppp_new(pppif, &pppoe_callbacks, sc, link_status_cb, ctx_cb);
191 LWIP_MEMPOOL_FREE(PPPOE_IF, sc);
195 memset(sc, 0, sizeof(struct pppoe_softc));
196 sc->pcb = ppp;
197 sc->sc_ethif = ethif;
199 sc->sc_service_name = service_name;
200 sc->sc_concentrator_name = concentrator_name;
203 sc->next = pppoe_softc_list;
204 pppoe_softc_list = sc;
210 struct pppoe_softc *sc = (struct pppoe_softc *)ctx;
237 ret = pppoe_xmit(sc, ph);
252 struct pppoe_softc *sc = (struct pppoe_softc *)ctx;
281 if( (err = pppoe_xmit(sc, pb)) != ERR_OK) {
296 struct pppoe_softc *sc = (struct pppoe_softc *)ctx;
300 sys_untimeout(pppoe_timeout, sc);
304 if (freep == sc) {
309 LWIP_MEMPOOL_FREE(PPPOE_IF, sc);
321 struct pppoe_softc *sc;
323 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
324 if (sc->sc_state == PPPOE_STATE_SESSION
325 && sc->sc_session == session
326 && sc->sc_ethif == rcvif) {
327 return sc;
336 struct pppoe_softc *sc, *t;
338 if (len != sizeof sc) {
343 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
344 if (sc == t) {
349 if (sc == NULL) {
354 /* should be safe to access *sc now */
355 if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) {
357 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_state));
360 if (sc->sc_ethif != rcvif) {
362 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
365 return sc;
374 struct pppoe_softc *sc;
434 sc = NULL;
451 if (sc != NULL) {
458 sc = pppoe_find_softc_by_hunique((u8_t*)pb->payload + off + sizeof(pt), len, netif);
490 if (sc) {
491 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));
511 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
512 if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) {
515 if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
518 if (sc->sc_state == PPPOE_STATE_INITIAL) {
522 if (sc == NULL) {
527 if (sc->sc_hunique) {
528 mem_free(sc->sc_hunique);
530 sc->sc_hunique = mem_malloc(hunique_len);
531 if (sc->sc_hunique == NULL) {
534 sc->sc_hunique_len = hunique_len;
535 MEMCPY(sc->sc_hunique, hunique, hunique_len);
537 MEMCPY(&sc->sc_dest, eh->ether_shost, sizeof sc->sc_dest);
538 sc->sc_state = PPPOE_STATE_PADO_SENT;
539 pppoe_send_pado(sc);
545 * get sc from ac_cookie if IFF_PASSIVE
552 sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, netif);
553 if (sc == NULL) {
560 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
561 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));
565 if (sc->sc_hunique) {
566 mem_free(sc->sc_hunique);
568 sc->sc_hunique = mem_malloc(hunique_len);
569 if (sc->sc_hunique == NULL) {
572 sc->sc_hunique_len = hunique_len;
573 MEMCPY(sc->sc_hunique, hunique, hunique_len);
575 pppoe_send_pads(sc);
576 sc->sc_state = PPPOE_STATE_SESSION;
577 ppp_start(sc->pcb); /* notify upper layers */
584 if (sc == NULL) {
591 if (sc->sc_state != PPPOE_STATE_PADI_SENT) {
592 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));
596 sc->sc_ac_cookie_len = ac_cookie_len;
597 MEMCPY(sc->sc_ac_cookie, ac_cookie, ac_cookie_len);
599 MEMCPY(&sc->sc_dest, ethhdr->src.addr, sizeof(sc->sc_dest.addr));
600 sys_untimeout(pppoe_timeout, sc);
601 sc->sc_padr_retried = 0;
602 sc->sc_state = PPPOE_STATE_PADR_SENT;
603 if ((err = pppoe_send_padr(sc)) != 0) {
604 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));
607 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
610 if (sc == NULL) {
613 sc->sc_session = session;
614 sys_untimeout(pppoe_timeout, sc);
615 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));
616 sc->sc_state = PPPOE_STATE_SESSION;
617 ppp_start(sc->pcb); /* notify upper layers */
626 if (sc == NULL) { /* PADT frames are rarely sent with a hunique tag, this is actually almost always true */
629 pppoe_clear_softc(sc, "received PADT");
633 if(sc) {
635 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
652 struct pppoe_softc *sc;
683 sc = pppoe_find_softc_by_session(session, netif);
684 if (sc == NULL) {
702 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
710 ppp_input(sc->pcb, pb);
718 pppoe_output(struct pppoe_softc *sc, struct pbuf *pb)
727 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));
733 etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : ETHTYPE_PPPOEDISC;
735 MEMCPY(ðhdr->dest.addr, &sc->sc_dest.addr, sizeof(ethhdr->dest.addr));
736 MEMCPY(ðhdr->src.addr, &sc->sc_ethif->hwaddr, sizeof(ethhdr->src.addr));
739 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, etype,
740 sc->sc_state, sc->sc_session,
741 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],
744 res = sc->sc_ethif->linkoutput(sc->sc_ethif, pb);
752 pppoe_send_padi(struct pppoe_softc *sc)
762 len = 2 + 2 + 2 + 2 + sizeof sc; /* service name tag is required, host unique is send too */
764 if (sc->sc_service_name != NULL) {
765 l1 = (int)strlen(sc->sc_service_name);
768 if (sc->sc_concentrator_name != NULL) {
769 l2 = (int)strlen(sc->sc_concentrator_name);
788 if (sc->sc_service_name != NULL) {
790 MEMCPY(p, sc->sc_service_name, l1);
798 if (sc->sc_concentrator_name != NULL) {
801 MEMCPY(p, sc->sc_concentrator_name, l2);
806 PPPOE_ADD_16(p, sizeof(sc));
807 MEMCPY(p, &sc, sizeof sc);
810 return pppoe_output(sc, pb);
818 struct pppoe_softc *sc = (struct pppoe_softc*)arg;
820 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": timeout\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
822 switch (sc->sc_state) {
833 if (sc->sc_padi_retried < 0xff) {
834 sc->sc_padi_retried++;
836 if (!sc->pcb->settings.persist && sc->sc_padi_retried >= PPPOE_DISC_MAXPADI) {
838 if ((sc->sc_sppp.pp_if.if_flags & IFF_LINK1) == 0) {
844 pppoe_abort_connect(sc);
849 retry_wait = LWIP_MIN(PPPOE_DISC_TIMEOUT * sc->sc_padi_retried, PPPOE_SLOW_RETRY);
850 if ((err = pppoe_send_padi(sc)) != 0) {
851 sc->sc_padi_retried--;
852 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));
855 sys_timeout(retry_wait, pppoe_timeout, sc);
859 sc->sc_padr_retried++;
860 if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) {
861 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
862 sc->sc_state = PPPOE_STATE_PADI_SENT;
863 sc->sc_padr_retried = 0;
864 if ((err = pppoe_send_padi(sc)) != 0) {
865 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));
868 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc);
871 if ((err = pppoe_send_padr(sc)) != 0) {
872 sc->sc_padr_retried--;
873 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));
876 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
888 struct pppoe_softc *sc = (struct pppoe_softc *)ctx;
896 sc->sc_session = 0;
897 sc->sc_ac_cookie_len = 0;
898 sc->sc_padi_retried = 0;
899 sc->sc_padr_retried = 0;
901 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
904 if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
910 lcp_wo->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */
918 lcp_ao->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */
934 sc->sc_state = PPPOE_STATE_PADI_SENT;
935 if ((err = pppoe_send_padi(sc)) != 0) {
936 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));
938 sys_timeout(PPPOE_DISC_TIMEOUT, pppoe_timeout, sc);
945 struct pppoe_softc *sc = (struct pppoe_softc *)ctx;
947 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
948 if (sc->sc_state == PPPOE_STATE_SESSION) {
949 pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest);
953 sys_untimeout(pppoe_timeout, sc);
954 sc->sc_state = PPPOE_STATE_INITIAL;
956 if (sc->sc_hunique) {
957 mem_free(sc->sc_hunique);
958 sc->sc_hunique = NULL; /* probably not necessary, if state is initial we shouldn't have to access hunique anyway */
960 sc->sc_hunique_len = 0; /* probably not necessary, if state is initial we shouldn't have to access hunique anyway */
968 pppoe_abort_connect(struct pppoe_softc *sc)
970 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));
971 sc->sc_state = PPPOE_STATE_INITIAL;
972 ppp_link_failed(sc->pcb); /* notify upper layers */
977 pppoe_send_padr(struct pppoe_softc *sc)
986 len = 2 + 2 + 2 + 2 + sizeof(sc); /* service name, host unique */
988 if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
989 l1 = strlen(sc->sc_service_name);
993 if (sc->sc_ac_cookie_len > 0) {
994 len += 2 + 2 + sc->sc_ac_cookie_len; /* AC cookie */
1007 if (sc->sc_service_name != NULL) {
1009 MEMCPY(p, sc->sc_service_name, l1);
1016 if (sc->sc_ac_cookie_len > 0) {
1018 PPPOE_ADD_16(p, sc->sc_ac_cookie_len);
1019 MEMCPY(p, sc->sc_ac_cookie, sc->sc_ac_cookie_len);
1020 p += sc->sc_ac_cookie_len;
1023 PPPOE_ADD_16(p, sizeof(sc));
1024 MEMCPY(p, &sc, sizeof sc);
1026 return pppoe_output(sc, pb);
1067 pppoe_send_pado(struct pppoe_softc *sc)
1076 len += 2 + 2 + sizeof(sc);
1078 len += 2 + 2 + sc->sc_hunique_len;
1087 PPPOE_ADD_16(p, sizeof(sc));
1088 MEMCPY(p, &sc, sizeof(sc));
1089 p += sizeof(sc);
1091 PPPOE_ADD_16(p, sc->sc_hunique_len);
1092 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
1093 return pppoe_output(sc, pb);
1097 pppoe_send_pads(struct pppoe_softc *sc)
1103 sc->sc_session = mono_time.tv_sec % 0xff + 1;
1107 len += 2 + 2 + 2 + 2 + sc->sc_hunique_len; /* service name, host unique*/
1108 if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
1109 l1 = strlen(sc->sc_service_name);
1118 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len);
1120 if (sc->sc_service_name != NULL) {
1122 MEMCPY(p, sc->sc_service_name, l1);
1128 PPPOE_ADD_16(p, sc->sc_hunique_len);
1129 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
1130 return pppoe_output(sc, pb);
1135 pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb)
1145 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));
1152 PPPOE_ADD_HEADER(p, 0, sc->sc_session, len);
1154 return pppoe_output(sc, pb);
1161 struct pppoe_softc *sc;
1168 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
1169 if (sc->sc_ethif != ifp) {
1172 if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
1173 sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1175 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
1177 sc->sc_ethif = NULL;
1178 pppoe_clear_softc(sc, "ethernet interface detached");
1187 pppoe_clear_softc(struct pppoe_softc *sc, const char *message)
1192 sys_untimeout(pppoe_timeout, sc);
1193 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));
1194 sc->sc_state = PPPOE_STATE_INITIAL;
1195 ppp_link_end(sc->pcb); /* notify upper layers - /!\ dangerous /!\ - see pppoe_disc_input() */