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