Lines Matching refs:sc

146   struct pppoe_softc *sc;
148 sc = (struct pppoe_softc *)memp_malloc(MEMP_PPPOE_IF);
149 if (sc == NULL) {
153 memset(sc, 0, sizeof(struct pppoe_softc));
156 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
158 sc->sc_pd = pd;
159 sc->sc_linkStatusCB = linkStatusCB;
160 sc->sc_ethif = ethif;
163 sc->next = pppoe_softc_list;
164 pppoe_softc_list = sc;
166 *scptr = sc;
174 struct pppoe_softc *sc, *prev = NULL;
176 for (sc = pppoe_softc_list; sc != NULL; prev = sc, sc = sc->next) {
177 if (sc->sc_ethif == ifp) {
182 if(!(sc && (sc->sc_ethif == ifp))) {
186 sys_untimeout(pppoe_timeout, sc);
188 /* remove sc from the head of the list */
189 pppoe_softc_list = sc->next;
191 /* remove sc from the list */
192 prev->next = sc->next;
196 if (sc->sc_concentrator_name) {
197 mem_free(sc->sc_concentrator_name);
199 if (sc->sc_service_name) {
200 mem_free(sc->sc_service_name);
203 memp_free(MEMP_PPPOE_IF, sc);
217 struct pppoe_softc *sc;
223 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
224 if (sc->sc_state == PPPOE_STATE_SESSION
225 && sc->sc_session == session) {
226 if (sc->sc_ethif == rcvif) {
227 return sc;
241 struct pppoe_softc *sc, *t;
247 if (len != sizeof sc) {
252 for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) {
253 if (sc == t) {
258 if (sc == NULL) {
263 /* should be safe to access *sc now */
264 if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) {
266 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_state);
269 if (sc->sc_ethif != rcvif) {
271 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
274 return sc;
278 pppoe_linkstatus_up(struct pppoe_softc *sc)
280 sc->sc_linkStatusCB(sc->sc_pd, 1);
289 struct pppoe_softc *sc;
345 sc = NULL;
362 if (sc != NULL) {
369 sc = pppoe_find_softc_by_hunique((u8_t*)pb->payload + off + sizeof(pt), len, netif);
370 if (sc != NULL) {
371 snprintf(devname, sizeof(devname), "%c%c%"U16_F, sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
420 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
421 if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) {
424 if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
427 if (sc->sc_state == PPPOE_STATE_INITIAL) {
431 if (sc == NULL) {
436 if (sc->sc_hunique) {
437 mem_free(sc->sc_hunique);
439 sc->sc_hunique = mem_malloc(hunique_len);
440 if (sc->sc_hunique == NULL) {
443 sc->sc_hunique_len = hunique_len;
444 MEMCPY(sc->sc_hunique, hunique, hunique_len);
446 MEMCPY(&sc->sc_dest, eh->ether_shost, sizeof sc->sc_dest);
447 sc->sc_state = PPPOE_STATE_PADO_SENT;
448 pppoe_send_pado(sc);
454 * get sc from ac_cookie if IFF_PASSIVE
461 sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, netif);
462 if (sc == NULL) {
469 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
470 printf("%c%c%"U16_F": received unexpected PADR\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
474 if (sc->sc_hunique) {
475 mem_free(sc->sc_hunique);
477 sc->sc_hunique = mem_malloc(hunique_len);
478 if (sc->sc_hunique == NULL) {
481 sc->sc_hunique_len = hunique_len;
482 MEMCPY(sc->sc_hunique, hunique, hunique_len);
484 pppoe_send_pads(sc);
485 sc->sc_state = PPPOE_STATE_SESSION;
486 pppoe_linkstatus_up(sc); /* notify upper layers */
493 if (sc == NULL) {
500 if (sc->sc_state != PPPOE_STATE_PADI_SENT) {
501 printf("%c%c%"U16_F": received unexpected PADO\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
505 sc->sc_ac_cookie_len = ac_cookie_len;
506 MEMCPY(sc->sc_ac_cookie, ac_cookie, ac_cookie_len);
508 MEMCPY(&sc->sc_dest, ethhdr->src.addr, sizeof(sc->sc_dest.addr));
509 sys_untimeout(pppoe_timeout, sc);
510 sc->sc_padr_retried = 0;
511 sc->sc_state = PPPOE_STATE_PADR_SENT;
512 if ((err = pppoe_send_padr(sc)) != 0) {
513 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));
515 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
518 if (sc == NULL) {
521 sc->sc_session = session;
522 sys_untimeout(pppoe_timeout, sc);
523 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));
524 sc->sc_state = PPPOE_STATE_SESSION;
525 pppoe_linkstatus_up(sc); /* notify upper layers */
528 if (sc == NULL) {
531 pppoe_clear_softc(sc, "received PADT");
534 if(sc) {
536 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
564 struct pppoe_softc *sc;
602 sc = pppoe_find_softc_by_session(session, netif);
603 if (sc == NULL) {
621 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num,
628 pppInProcOverEthernet(sc->sc_pd, pb);
637 pppoe_output(struct pppoe_softc *sc, struct pbuf *pb)
643 if (!sc->sc_ethif) {
649 etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : ETHTYPE_PPPOEDISC;
651 MEMCPY(ethhdr->dest.addr, sc->sc_dest.addr, sizeof(ethhdr->dest.addr));
652 MEMCPY(ethhdr->src.addr, ((struct eth_addr *)sc->sc_ethif->hwaddr)->addr, sizeof(ethhdr->src.addr));
655 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, etype,
656 sc->sc_state, sc->sc_session,
657 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],
660 res = sc->sc_ethif->linkoutput(sc->sc_ethif, pb);
668 pppoe_send_padi(struct pppoe_softc *sc)
677 if (sc->sc_state >PPPOE_STATE_PADI_SENT) {
678 PPPDEBUG(LOG_ERR, ("ERROR: pppoe_send_padi in state %d", sc->sc_state));
682 len = 2 + 2 + 2 + 2 + sizeof sc; /* service name tag is required, host unique is send too */
684 if (sc->sc_service_name != NULL) {
685 l1 = (int)strlen(sc->sc_service_name);
688 if (sc->sc_concentrator_name != NULL) {
689 l2 = (int)strlen(sc->sc_concentrator_name);
708 if (sc->sc_service_name != NULL) {
710 MEMCPY(p, sc->sc_service_name, l1);
718 if (sc->sc_concentrator_name != NULL) {
721 MEMCPY(p, sc->sc_concentrator_name, l2);
726 PPPOE_ADD_16(p, sizeof(sc));
727 MEMCPY(p, &sc, sizeof sc);
730 return pppoe_output(sc, pb);
737 struct pppoe_softc *sc = (struct pppoe_softc*)arg;
739 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": timeout\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
741 switch (sc->sc_state) {
754 retry_wait = PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried);
756 sc->sc_padi_retried++;
757 if (sc->sc_padi_retried >= PPPOE_DISC_MAXPADI) {
759 if ((sc->sc_sppp.pp_if.if_flags & IFF_LINK1) == 0) {
765 pppoe_abort_connect(sc);
769 if ((err = pppoe_send_padi(sc)) != 0) {
770 sc->sc_padi_retried--;
771 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));
773 sys_timeout(retry_wait, pppoe_timeout, sc);
777 sc->sc_padr_retried++;
778 if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) {
779 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
780 sc->sc_state = PPPOE_STATE_PADI_SENT;
781 sc->sc_padr_retried = 0;
782 if ((err = pppoe_send_padi(sc)) != 0) {
783 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));
785 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc);
788 if ((err = pppoe_send_padr(sc)) != 0) {
789 sc->sc_padr_retried--;
790 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));
792 sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc);
795 pppoe_do_disconnect(sc);
804 pppoe_connect(struct pppoe_softc *sc)
808 if (sc->sc_state != PPPOE_STATE_INITIAL) {
814 if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) {
819 sc->sc_state = PPPOE_STATE_PADI_SENT;
820 sc->sc_padr_retried = 0;
821 err = pppoe_send_padi(sc);
822 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));
823 sys_timeout(PPPOE_DISC_TIMEOUT, pppoe_timeout, sc);
829 pppoe_disconnect(struct pppoe_softc *sc)
831 if (sc->sc_state < PPPOE_STATE_SESSION) {
839 sc->sc_state = PPPOE_STATE_CLOSING;
840 sys_timeout(20, pppoe_timeout, sc);
844 pppoe_do_disconnect(struct pppoe_softc *sc)
848 if (sc->sc_state < PPPOE_STATE_SESSION) {
851 PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
852 err = pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest);
856 sc->sc_state = PPPOE_STATE_INITIAL;
857 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
858 sc->sc_ac_cookie_len = 0;
860 if (sc->sc_hunique) {
861 mem_free(sc->sc_hunique);
862 sc->sc_hunique = NULL;
864 sc->sc_hunique_len = 0;
866 sc->sc_session = 0;
868 sc->sc_linkStatusCB(sc->sc_pd, 0); /* notify upper layers */
875 pppoe_abort_connect(struct pppoe_softc *sc)
877 printf("%c%c%"U16_F": could not establish connection\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
878 sc->sc_state = PPPOE_STATE_CLOSING;
880 sc->sc_linkStatusCB(sc->sc_pd, 0); /* notify upper layers */
883 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
884 sc->sc_state = PPPOE_STATE_INITIAL;
889 pppoe_send_padr(struct pppoe_softc *sc)
898 if (sc->sc_state != PPPOE_STATE_PADR_SENT) {
902 len = 2 + 2 + 2 + 2 + sizeof(sc); /* service name, host unique */
904 if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
905 l1 = strlen(sc->sc_service_name);
909 if (sc->sc_ac_cookie_len > 0) {
910 len += 2 + 2 + sc->sc_ac_cookie_len; /* AC cookie */
923 if (sc->sc_service_name != NULL) {
925 MEMCPY(p, sc->sc_service_name, l1);
932 if (sc->sc_ac_cookie_len > 0) {
934 PPPOE_ADD_16(p, sc->sc_ac_cookie_len);
935 MEMCPY(p, sc->sc_ac_cookie, sc->sc_ac_cookie_len);
936 p += sc->sc_ac_cookie_len;
939 PPPOE_ADD_16(p, sizeof(sc));
940 MEMCPY(p, &sc, sizeof sc);
942 return pppoe_output(sc, pb);
977 pppoe_send_pado(struct pppoe_softc *sc)
983 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
990 len += 2 + 2 + sizeof(sc);
992 len += 2 + 2 + sc->sc_hunique_len;
1001 PPPOE_ADD_16(p, sizeof(sc));
1002 MEMCPY(p, &sc, sizeof(sc));
1003 p += sizeof(sc);
1005 PPPOE_ADD_16(p, sc->sc_hunique_len);
1006 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
1007 return pppoe_output(sc, pb);
1011 pppoe_send_pads(struct pppoe_softc *sc)
1017 if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
1021 sc->sc_session = mono_time.tv_sec % 0xff + 1;
1025 len += 2 + 2 + 2 + 2 + sc->sc_hunique_len; /* service name, host unique*/
1026 if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
1027 l1 = strlen(sc->sc_service_name);
1036 PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len);
1038 if (sc->sc_service_name != NULL) {
1040 MEMCPY(p, sc->sc_service_name, l1);
1046 PPPOE_ADD_16(p, sc->sc_hunique_len);
1047 MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len);
1048 return pppoe_output(sc, pb);
1053 pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb)
1059 if (sc->sc_state < PPPOE_STATE_SESSION) {
1060 /*sppp_flush(&sc->sc_sppp.pp_if);*/
1070 PPPDEBUG(LOG_ERR, ("pppoe: %c%c%"U16_F": pppoe_xmit: could not allocate room for header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num));
1077 PPPOE_ADD_HEADER(p, 0, sc->sc_session, len);
1079 return pppoe_output(sc, pb);
1086 struct pppoe_softc *sc;
1093 LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
1094 if (sc->sc_ethif != ifp) {
1097 if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
1098 sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1100 sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num);
1102 sc->sc_ethif = NULL;
1103 pppoe_clear_softc(sc, "ethernet interface detached");
1111 pppoe_clear_softc(struct pppoe_softc *sc, const char *message)
1116 sys_untimeout(pppoe_timeout, sc);
1117 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));
1120 sc->sc_state = PPPOE_STATE_INITIAL;
1123 sc->sc_linkStatusCB(sc->sc_pd, 0);
1126 MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
1127 sc->sc_ac_cookie_len = 0;
1128 sc->sc_session = 0;