00001 00065 /* 00066 * $Log$ 00067 * Revision 1.9 2008/08/11 07:00:32 haraldkipp 00068 * BSD types replaced by stdint types (feature request #1282721). 00069 * 00070 * Revision 1.8 2006/10/05 17:25:41 haraldkipp 00071 * Avoid possible alignment errors. Fixes bug #1567748. 00072 * 00073 * Revision 1.7 2005/04/30 16:42:42 chaac 00074 * Fixed bug in handling of NUTDEBUG. Added include for cfg/os.h. If NUTDEBUG 00075 * is defined in NutConf, it will make effect where it is used. 00076 * 00077 * Revision 1.6 2005/04/08 15:20:51 olereinhardt 00078 * added <sys/types.h> (__APPLE__) and <netinet/in.h> (__linux__) 00079 * for htons and simmilar. 00080 * 00081 * Revision 1.5 2004/03/18 15:36:09 haraldkipp 00082 * ICCAVR failed to compile 00083 * 00084 * Revision 1.4 2004/03/08 11:27:44 haraldkipp 00085 * Accept incoming header compression. 00086 * 00087 * Revision 1.3 2003/08/14 15:15:28 haraldkipp 00088 * Unsuccessful try to fix ICCAVR bug 00089 * 00090 * Revision 1.2 2003/07/13 19:05:22 haraldkipp 00091 * Debug output corrected. 00092 * 00093 * Revision 1.1.1.1 2003/05/09 14:41:36 haraldkipp 00094 * Initial using 3.2.1 00095 * 00096 * Revision 1.2 2003/05/06 18:17:11 harald 00097 * Separate PPP debug module added. 00098 * 00099 * Revision 1.1 2003/03/31 14:53:28 harald 00100 * Prepare release 3.1 00101 * 00102 */ 00103 00104 #include <cfg/os.h> 00105 #include <dev/ppp.h> 00106 #include <dev/ahdlc.h> 00107 00108 #include <netinet/in.h> 00109 #include <netinet/if_ppp.h> 00110 #include <netinet/ppp_fsm.h> 00111 #include <netinet/ip.h> 00112 #include <net/ppp.h> 00113 #include <sys/types.h> 00114 #include <sys/timer.h> 00115 00116 #ifdef NUTDEBUG 00117 #include <net/netdebug.h> 00118 #endif 00119 00124 00125 00140 void NutPppInput(NUTDEVICE * dev, NETBUF * nb) 00141 { 00142 PPPHDR *ph = (PPPHDR *) nb->nb_dl.vp; 00143 PPPDCB *dcb = dev->dev_dcb; 00144 uint16_t protocol; 00145 uint8_t protocolsz; 00146 00147 #ifdef NUTDEBUG 00148 if (__ppp_trf) { 00149 fputs("\nPPP>", __ppp_trs); 00150 NutDumpPpp(__ppp_trs, nb); 00151 } 00152 #elif defined(__IMAGECRAFT__) 00153 /* 00154 * No idea what this is, but ICCAVR fails if this call isn't there. 00155 */ 00156 NutSleep(100); 00157 #endif 00158 00159 /* 00160 * Check if the address and control field is compressed. 00161 * Thanks to Francois Rademeyer. 00162 */ 00163 if (ph->address != AHDLC_ALLSTATIONS) { 00164 00165 /* 00166 * Check for protocol compression. 00167 * LSB of 2nd octet for protocol is always 1. 00168 */ 00169 if (((uint8_t *) nb->nb_dl.vp)[0] & 0x01) { 00170 protocolsz = 1; 00171 protocol = *(uint8_t *) nb->nb_dl.vp; 00172 } else { 00173 char *cp = (char *)nb->nb_dl.vp; 00174 protocolsz = 2; 00175 protocol = ntohs(((uint16_t)cp[0] << 8) | cp[1]); 00176 } 00177 00178 /* 00179 * Chop off the compressed header. 00180 */ 00181 nb->nb_nw.vp = (char *)nb->nb_dl.vp + protocolsz; 00182 nb->nb_nw.sz = nb->nb_dl.sz - protocolsz; 00183 nb->nb_dl.sz = protocolsz; 00184 } else { 00185 /* 00186 * Chop off the PPP header. 00187 */ 00188 nb->nb_nw.vp = ph + 1; 00189 nb->nb_nw.sz = nb->nb_dl.sz - sizeof(PPPHDR); 00190 nb->nb_dl.sz = sizeof(PPPHDR); 00191 00192 protocol = ntohs(ph->prot_type); 00193 } 00194 00195 /* 00196 * Toss all non-LCP packets unless LCP is OPEN. 00197 */ 00198 if (protocol != PPP_LCP && dcb->dcb_lcp_state != PPPS_OPENED) { 00199 NutNetBufFree(nb); 00200 return; 00201 } 00202 00203 /* 00204 * Until we get past the authentication phase, toss all packets 00205 * except LCP, LQR and authentication packets. 00206 */ 00207 if (dcb->dcb_auth_state != PAPCS_OPEN && 00208 !(protocol == PPP_LCP || protocol == PPP_LQR || protocol == PPP_PAP || protocol == PPP_CHAP)) { 00209 NutNetBufFree(nb); 00210 return; 00211 } 00212 00213 /* 00214 * Route frame to the proper handler. 00215 */ 00216 switch (protocol) { 00217 case PPP_IP: 00218 /* Internet protocol. */ 00219 if (dcb->dcb_ipcp_state == PPPS_OPENED) 00220 NutIpInput(dev, nb); 00221 else 00222 NutNetBufFree(nb); 00223 break; 00224 00225 case PPP_LCP: 00226 /* Link control protocol. */ 00227 NutLcpInput(dev, nb); 00228 break; 00229 00230 case PPP_IPCP: 00231 /* IP control protocol. */ 00232 NutIpcpInput(dev, nb); 00233 break; 00234 00235 case PPP_PAP: 00236 /* Password authentication protocol. */ 00237 NutPapInput(dev, nb); 00238 break; 00239 00240 default: 00241 LcpTxProtRej(dev, protocol, nb); 00242 break; 00243 } 00244 } 00245