pppin.c
Go to the documentation of this file.00001
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
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
00155
00156 NutSleep(100);
00157 #endif
00158
00159
00160
00161
00162
00163 if (ph->address != AHDLC_ALLSTATIONS) {
00164
00165
00166
00167
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
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
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
00197
00198 if (protocol != PPP_LCP && dcb->dcb_lcp_state != PPPS_OPENED) {
00199 NutNetBufFree(nb);
00200 return;
00201 }
00202
00203
00204
00205
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
00215
00216 switch (protocol) {
00217 case PPP_IP:
00218
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
00227 NutLcpInput(dev, nb);
00228 break;
00229
00230 case PPP_IPCP:
00231
00232 NutIpcpInput(dev, nb);
00233 break;
00234
00235 case PPP_PAP:
00236
00237 NutPapInput(dev, nb);
00238 break;
00239
00240 default:
00241 LcpTxProtRej(dev, protocol, nb);
00242 break;
00243 }
00244 }
00245