/*---------------------------------------------------------------------------*/ void pap_rx(u8_t *buffer, u16_t count) { u8_t *bptr=buffer; u8_t len; switch(*bptr++) { case CONF_REQ: DEBUG1(("CONF ACK - only for server, no support\n")); break; case CONF_ACK: /* config Ack */ DEBUG1(("CONF ACK - PAP good - ")); /* Display message if debug */ len = *bptr++; *(bptr + len) = 0; DEBUG1((" %s \n",bptr)); pap_state |= PAP_TX_UP; /* expire the timer to make things happen after a state change */ TIMER_expire(); break; case CONF_NAK: DEBUG1(("CONF NAK - Failed Auth - ")); pap_state |= PAP_TX_AUTH_FAIL; /* display message if debug */ len = *bptr++; *(bptr + len)=0; DEBUG1((" %s \n",bptr)); break; } }
/*---------------------------------------------------------------------------*/ void ipv6cp_init(void) { ANNOTATE("ipv6cp init\n"); ipv6cp_state = 0; ppp_retry = 0; pppif.ipaddr.u16[0] = pppif.ipaddr.u16[1] = 0; TIMER_expire(); }
/*---------------------------------------------------------------------------*/ void ipcp_init(void) { ANNOTATE("ipcp init\n"); ipcp_state = 0; ppp_retry = 0; pppif.ipaddr.u16[0] = pppif.ipaddr.u16[1] = 0; //disable for gprs modem #if 0 pppif.ipaddr.u8[0]=UIP_IPADDR0; pppif.ipaddr.u8[1]=UIP_IPADDR1; pppif.ipaddr.u8[2]=UIP_IPADDR2; pppif.ipaddr.u8[3]=UIP_IPADDR3; #endif TIMER_expire(); }
/* * IPCP RX protocol Handler */ void ipv6cp_rx(u8_t *buffer, u16_t count) { u8_t *bptr = buffer; // IPCPPKT *pkt=(IPCPPKT *)buffer; u16_t len; ANNOTATE("IPV6CP len %d\n",count); switch(*bptr++) { case CONF_REQ: /* parce request and see if we can ACK it */ ++bptr; len = (*bptr++ << 8); len |= *bptr++; /* len-=2; */ ANNOTATE("check lcplist\n"); if(scan_packet(IPV6CP, ipv6cplist, buffer, bptr, (u16_t)(len - 4))) { UIP_LOG("option was bad\n"); } else { ANNOTATE("IPV6CP options are good\n"); /* * Parse out the results */ /* lets try to implement what peer wants */ /* Reject any protocol not */ /* Error? if we we need to send a config Reject ++++ this is good for a subroutine*/ //GD-2011-09-15 None of the IPv6CP options are supported with current implementation. #if 0 #warning option implementation example based on IPCP IPv4 address configuration. /* All we should get is the peer IP address */ if(IPV6CP_IPADDRESS == *bptr++) { /* dump length */ ++bptr; #ifdef IPV6CP_GET_PEER_IP ((u8_t*)peer_ip_addr.u8)[0] = *bptr++; ((u8_t*)peer_ip_addr.u8)[1] = *bptr++; ((u8_t*)peer_ip_addr.u8)[2] = *bptr++; ((u8_t*)peer_ip_addr.u8)[3] = *bptr++; ANNOTATE("Peer IP "); /* printip(peer_ip_addr);*/ ANNOTATE("\n"); #else bptr += 18; #endif } else { UIP_LOG("HMMMM this shouldn't happen IPV6CP1\n"); } #endif #if 0 if(error) { /* write the config NAK packet we've built above, take on the header */ bptr = buffer; *bptr++ = CONF_NAK; /* Write Conf_rej */ *bptr++; /*tptr++;*/ /* skip over ID */ /* Write new length */ *bptr++ = 0; *bptr = tptr - buffer; /* write the reject frame */ UIP_LOG("Writing NAK frame \n"); ahdlc_tx(IPV6CP, buffer, (u16_t)(tptr - buffer)); ANNOTATE("- End NAK Write frame\n"); } else { } #endif /* * If we get here then we are OK, lets send an ACK and tell the rest * of our modules our negotiated config. */ ipv6cp_state |= IPV6CP_RX_UP; ipv6cp_state &= ~IPV6CP_TX_UP;//phlb force send request with ipv6cp task ANNOTATE("Send IPV6CP ACK!\n"); bptr = buffer; *bptr++ = CONF_ACK; /* Write Conf_ACK */ bptr++; /* Skip ID (send same one) */ /* * Set stuff */ ppp_flags |= tflag; ANNOTATE("SET- stuff -- are we up? c=%d dif=%d \n", count, (u16_t)(bptr-buffer)); /* write the ACK frame */ ANNOTATE("Writing ACK frame \n"); /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ ahdlc_tx(IPV6CP, 0, buffer, 0, count /*bptr-buffer*/); ANNOTATE("- End ACK Write frame\n"); /* expire the timer to make things happen after a state change */ TIMER_expire(); //timer_expire(); //modify phlb uncomment /* } */ } break; // case CONF_ACK: /* config Ack */ ANNOTATE("CONF ACK\n"); /* * Parse out the results * * Dump the ID and get the length. */ /* dump the ID */ bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; #if 0 //modify phlb /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { case IPV6CP_IPADDRESS: /* dump length */ bptr++; ((u8_t*)ipaddr)[0] = *bptr++; ((u8_t*)ipaddr)[1] = *bptr++; ((u8_t*)ipaddr)[2] = *bptr++; ((u8_t*)ipaddr)[3] = *bptr++; break; case IPV6CP_PRIMARY_DNS: bptr++; ((u8_t*)pri_dns_addr)[0] = *bptr++; ((u8_t*)pri_dns_addr)[1] = *bptr++; ((u8_t*)pri_dns_addr)[2] = *bptr++; ((u8_t*)pri_dns_addr)[3] = *bptr++; break; case IPV6CP_SECONDARY_DNS: bptr++; ((u8_t*)sec_dns_addr)[0] = *bptr++; ((u8_t*)sec_dns_addr)[1] = *bptr++; ((u8_t*)sec_dns_addr)[2] = *bptr++; ((u8_t*)sec_dns_addr)[3] = *bptr++; break; default: UIP_LOG("IPV6CP CONFIG_ACK problem1\n"); } } #endif ipv6cp_state |= IPV6CP_TX_UP; //ipv6cp_state &= ~IPV6CP_RX_UP; ANNOTATE("were up! \n"); printip(pppif.ipaddr); #ifdef IPV6CP_GET_PRI_DNS printip(pri_dns_addr); #endif #ifdef IPV6CP_GET_SEC_DNS printip(sec_dns_addr); #endif ANNOTATE("\n"); /* expire the timer to make things happen after a state change */ TIMER_expire(); break; // case CONF_NAK: /* Config Nack */ UIP_LOG("CONF NAK\n"); /* dump the ID */ bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { #if 0 #warning option implementation example based on IPCP IPv4 address configuration. case IPV6CP_IPADDRESS: /* dump length */ bptr++; ((u8_t*)pppif.ipaddr.u8)[0] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[1] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[2] = *bptr++; ((u8_t*)pppif.ipaddr.u8)[3] = *bptr++; uip_fw_register( &pppif ); ANNOTATE("My PPP-ipno: (%d.%d.%d.%d)\n", ((u8_t*)pppif.ipaddr.u8)[0], ((u8_t*)pppif.ipaddr.u8)[1], ((u8_t*)pppif.ipaddr.u8)[2], ((u8_t*)pppif.ipaddr.u8)[3]); break; #endif #ifdef IPV6CP_GET_PRI_DNS case IPV6CP_PRIMARY_DNS: bptr++; ((u8_t*)pri_dns_addr)[0] = *bptr++; ((u8_t*)pri_dns_addr)[1] = *bptr++; ((u8_t*)pri_dns_addr)[2] = *bptr++; ((u8_t*)pri_dns_addr)[3] = *bptr++; break; #endif #ifdef IPV6CP_GET_SEC_DNS case IPV6CP_SECONDARY_DNS: bptr++; ((u8_t*)sec_dns_addr)[0] = *bptr++; ((u8_t*)sec_dns_addr)[1] = *bptr++; ((u8_t*)sec_dns_addr)[2] = *bptr++; ((u8_t*)sec_dns_addr)[3] = *bptr++; break; #endif // default: UIP_LOG("IPCP CONFIG_ACK problem 2\n"); } } ppp_id++; printip(pppif.ipaddr); #ifdef IPV6CP_GET_PRI_DNS printip(pri_dns_addr); #endif #ifdef IPV6CP_GET_PRI_DNS printip(sec_dns_addr); #endif ANNOTATE("\n"); /* expire the timer to make things happen after a state change */ TIMER_expire(); break; case CONF_REJ: /* Config Reject */ ANNOTATE("CONF REJ\n"); /* Remove the offending options*/ ppp_id++; /* dump the ID */ bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { #if 0 #warning option implementation example based on IPCP IPv4 address configuration. case IPV6CP_IPADDRESS: ipv6cp_state |= IPV6CP_IP_BIT; bptr += 5; break; #endif #ifdef IPV6CP_GET_PRI_DNS case IPV6CP_PRIMARY_DNS: ipv6cp_state |= IPV6CP_PRI_DNS_BIT; bptr += 5; break; #endif #ifdef IPV6CP_GET_PRI_DNS case IPV6CP_SECONDARY_DNS: ipv6cp_state |= IPV6CP_SEC_DNS_BIT; bptr += 5; break; #endif default: UIP_LOG("IPV6CP this shoudln't happen 3\n"); } } /* expire the timer to make things happen after a state change */ /*timer_expire(); */ break; default: UIP_LOG("-Unknown 4\n"); } }
/* * IPCP RX protocol Handler */ void ipcp_rx(u8_t *buffer, u16_t count) { u8_t *bptr = buffer; IPCPPKT *pkt=(IPCPPKT *)buffer; u16_t len; DEBUG1(("IPCP len %d\n",count)); switch(*bptr++) { case CONF_REQ: /* parce request and see if we can ACK it */ ++bptr; len = (*bptr++ << 8); len |= *bptr++; /* len-=2; */ DEBUG1(("check lcplist\n")); if(scan_packet(IPCP, ipcplist, buffer, bptr, (u16_t)(len - 4))) { DEBUG1(("option was bad\n")); } else { DEBUG1(("IPCP options are good\n")); /* * Parse out the results */ /* lets try to implement what peer wants */ /* Reject any protocol not */ /* Error? if we we need to send a config Reject ++++ this is good for a subroutine*/ /* All we should get is the peer IP address */ if(IPCP_IPADDRESS == *bptr++) { /* dump length */ ++bptr; #ifdef IPCP_GET_PEER_IP peer_ip_addr.ip8[0] = *bptr++; peer_ip_addr.ip8[1] = *bptr++; peer_ip_addr.ip8[2] = *bptr++; peer_ip_addr.ip8[3] = *bptr++; DEBUG1(("Peer IP ")); /* printip(peer_ip_addr);*/ DEBUG1(("\n")); #else bptr += 4; #endif } else { DEBUG1(("HMMMM this shouldn't happen IPCP1\n")); } #if 0 if(error) { /* write the config NAK packet we've built above, take on the header */ bptr = buffer; *bptr++ = CONF_NAK; /* Write Conf_rej */ *bptr++; /*tptr++;*/ /* skip over ID */ /* Write new length */ *bptr++ = 0; *bptr = tptr - buffer; /* write the reject frame */ DEBUG1(("Writing NAK frame \n")); ahdlc_tx(IPCP, buffer, (u16_t)(tptr - buffer)); DEBUG1(("- End NAK Write frame\n")); } else { } #endif /* * If we get here then we are OK, lets send an ACK and tell the rest * of our modules our negotiated config. */ ipcp_state |= IPCP_RX_UP; DEBUG1(("Send IPCP ACK!\n")); bptr = buffer; *bptr++ = CONF_ACK; /* Write Conf_ACK */ bptr++; /* Skip ID (send same one) */ /* * Set stuff */ /* ppp_flags |= tflag; */ DEBUG1(("SET- stuff -- are we up? c=%d dif=%d \n", count, (u16_t)(bptr-buffer))); /* write the ACK frame */ DEBUG1(("Writing ACK frame \n")); /* Send packet ahdlc_txz(procol,header,data,headerlen,datalen); */ ahdlc_tx(IPCP, 0, buffer, 0, count /*bptr-buffer*/); DEBUG1(("- End ACK Write frame\n")); /* expire the timer to make things happen after a state change */ /*timer_expire(); */ /* } */ } break; case CONF_ACK: /* config Ack */ DEBUG1(("CONF ACK\n")); /* * Parse out the results * * Dump the ID and get the length. */ /* dump the ID */ bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; #if 0 /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { case IPCP_IPADDRESS: /* dump length */ bptr++; ipaddr.ip8[0] = *bptr++; ipaddr.ip8[1] = *bptr++; ipaddr.ip8[2] = *bptr++; ipaddr.ip8[3] = *bptr++; break; case IPCP_PRIMARY_DNS: bptr++; pri_dns_addr.ip8[0] = *bptr++; pri_dns_addr.ip8[1] = *bptr++; pri_dns_addr.ip8[2] = *bptr++; pri_dns_addr.ip8[3] = *bptr++; break; case IPCP_SECONDARY_DNS: bptr++; sec_dns_addr.ip8[0] = *bptr++; sec_dns_addr.ip8[1] = *bptr++; sec_dns_addr.ip8[2] = *bptr++; sec_dns_addr.ip8[3] = *bptr++; break; default: DEBUG1(("IPCP CONFIG_ACK problem1\n")); } } #endif ipcp_state |= IPCP_TX_UP; /*ipcp_state &= ~IPCP_RX_UP;*/ DEBUG1(("were up! \n")); printip(our_ipaddr); #ifdef IPCP_GET_PRI_DNS printip(pri_dns_addr); #endif #ifdef IPCP_GET_SEC_DNS printip(sec_dns_addr); #endif DEBUG1(("\n")); /* expire the timer to make things happen after a state change */ TIMER_expire(); break; case CONF_NAK: /* Config Nack */ DEBUG1(("CONF NAK\n")); /* dump the ID */ bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { case IPCP_IPADDRESS: /* dump length */ bptr++; our_ipaddr.ip8[0] = *bptr++; our_ipaddr.ip8[1] = *bptr++; our_ipaddr.ip8[2] = *bptr++; our_ipaddr.ip8[3] = *bptr++; break; #ifdef IPCP_GET_PRI_DNS case IPCP_PRIMARY_DNS: bptr++; pri_dns_addr.ip8[0] = *bptr++; pri_dns_addr.ip8[1] = *bptr++; pri_dns_addr.ip8[2] = *bptr++; pri_dns_addr.ip8[3] = *bptr++; break; #endif #ifdef IPCP_GET_SEC_DNS case IPCP_SECONDARY_DNS: bptr++; sec_dns_addr.ip8[0] = *bptr++; sec_dns_addr.ip8[1] = *bptr++; sec_dns_addr.ip8[2] = *bptr++; sec_dns_addr.ip8[3] = *bptr++; break; #endif default: DEBUG1(("IPCP CONFIG_ACK problem 2\n")); } } ppp_id++; printip(our_ipaddr); #ifdef IPCP_GET_PRI_DNS printip(pri_dns_addr); #endif #ifdef IPCP_GET_PRI_DNS printip(sec_dns_addr); #endif DEBUG1(("\n")); /* expire the timer to make things happen after a state change */ TIMER_expire(); break; case CONF_REJ: /* Config Reject */ DEBUG1(("CONF REJ\n")); /* Remove the offending options*/ ppp_id++; /* dump the ID */ bptr++; /* get the length */ len = (*bptr++ << 8); len |= *bptr++; /* Parse ACK and set data */ while(bptr < buffer + len) { switch(*bptr++) { case IPCP_IPADDRESS: ipcp_state |= IPCP_IP_BIT; bptr += 5; break; #ifdef IPCP_GET_PRI_DNS case IPCP_PRIMARY_DNS: ipcp_state |= IPCP_PRI_DNS_BIT; bptr += 5; break; #endif #ifdef IPCP_GET_PRI_DNS case IPCP_SECONDARY_DNS: ipcp_state |= IPCP_SEC_DNS_BIT; bptr += 5; break; #endif default: DEBUG1(("IPCP this shoudln't happen 3\n")); } } /* expire the timer to make things happen after a state change */ /*timer_expire(); */ break; default: DEBUG1(("-Unknown 4\n")); } }