⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 watt-32 tcp-ip src-ppp_c source file.htm

📁 关于PPP点对点协议的一些详细资料
💻 HTM
📖 第 1 页 / 共 5 页
字号:
00399 <SPAN class=comment> */</SPAN>
00400 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> show_packet (<SPAN class=keyword>const</SPAN> <SPAN class=keywordtype>char</SPAN> *inout, <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct</SPAN> ppp_state *state,
00401                          <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp, <SPAN class=keyword>const</SPAN> BYTE *bp, <SPAN class=keywordtype>int</SPAN> len)
00402 {
00403   <SPAN class=keyword>static</SPAN> <SPAN class=keyword>const</SPAN> <SPAN class=keywordtype>char</SPAN> *code_str[] = {
00404                     <SPAN class=stringliteral>"Vendor"</SPAN>, <SPAN class=stringliteral>"Configure-Request"</SPAN>, <SPAN class=stringliteral>"Configure-Ack"</SPAN>,
00405                     <SPAN class=stringliteral>"Configure-Nak"</SPAN>, <SPAN class=stringliteral>"Configure-Reject"</SPAN>, <SPAN class=stringliteral>"Terminate-Request"</SPAN>,
00406                     <SPAN class=stringliteral>"Terminate-Ack"</SPAN>, <SPAN class=stringliteral>"Code-Reject"</SPAN>, <SPAN class=stringliteral>"Protocol-Reject"</SPAN>,
00407                     <SPAN class=stringliteral>"Echo-Request"</SPAN>, <SPAN class=stringliteral>"Echo-Reply"</SPAN>, <SPAN class=stringliteral>"Discard-Request"</SPAN>
00408                   };
00409   <SPAN class=keywordtype>int</SPAN> code   = *bp++;
00410   <SPAN class=keywordtype>int</SPAN> id     = *bp++;
00411   <SPAN class=keywordtype>int</SPAN> length = intel16 (*(WORD*)bp);
00412 
00413   bp += 2;
00414   <SPAN class=keywordflow>if</SPAN> (len &gt; length)
00415       len = length;
00416   len -= PPP_HDRLEN;
00417 
00418   (*_printf) (<SPAN class=stringliteral>"%s %s "</SPAN>, inout, xcp-&gt;name);
00419   <SPAN class=keywordflow>if</SPAN> (code &lt; DIM(code_str) &amp;&amp; code_str[code])
00420        (*_printf) (<SPAN class=stringliteral>"%s"</SPAN>, code_str[code]);
00421   <SPAN class=keywordflow>else</SPAN> (*_printf) (<SPAN class=stringliteral>"code:%d"</SPAN>, code);
00422 
00423   (*_printf) (<SPAN class=stringliteral>" ID:%d"</SPAN>, id);
00424   <SPAN class=keywordflow>if</SPAN> ((code == CODE_CONF_ACK || code == CODE_CONF_NAK ||
00425        code == CODE_CONF_REJ || code == CODE_TERM_ACK ||
00426        code == CODE_ECHO_REP) &amp;&amp; id != xcp-&gt;ident)
00427      (*_printf) (<SPAN class=stringliteral>" **ERR**"</SPAN>);
00428   (*_printf) (<SPAN class=stringliteral>" len:%d"</SPAN>, length);
00429 
00430   <SPAN class=keywordflow>switch</SPAN> (code)
00431   {
00432     <SPAN class=keywordflow>case</SPAN> CODE_CONF_REQ:
00433     <SPAN class=keywordflow>case</SPAN> CODE_CONF_ACK:
00434     <SPAN class=keywordflow>case</SPAN> CODE_CONF_NAK:
00435     <SPAN class=keywordflow>case</SPAN> CODE_CONF_REJ:
00436          option_show (state, xcp, bp, len);
00437          <SPAN class=keywordflow>break</SPAN>;
00438     <SPAN class=keywordflow>case</SPAN> CODE_TERM_REQ:
00439     <SPAN class=keywordflow>case</SPAN> CODE_TERM_ACK:
00440          <SPAN class=keywordflow>if</SPAN> (len &gt; 0)
00441          {
00442            (*_printf) (<SPAN class=stringliteral>" "</SPAN>);
00443            safe_string (bp, len);
00444          }
00445          <SPAN class=keywordflow>break</SPAN>;
00446     <SPAN class=keywordflow>case</SPAN> CODE_CODE_REJ:
00447          (*_printf) (<SPAN class=stringliteral>" code %d"</SPAN>, *bp);
00448          <SPAN class=keywordflow>break</SPAN>;
00449     <SPAN class=keywordflow>case</SPAN> CODE_PROTO_REJ:
00450          (*_printf) (<SPAN class=stringliteral>" protocol %02X%02X"</SPAN>, bp[0], bp[1]);
00451          <SPAN class=keywordflow>break</SPAN>;
00452     <SPAN class=keywordflow>case</SPAN> CODE_ECHO_REQ:
00453     <SPAN class=keywordflow>case</SPAN> CODE_ECHO_REP:
00454     <SPAN class=keywordflow>case</SPAN> CODE_DISCARD_REQ:
00455          <SPAN class=keywordflow>if</SPAN> (len &gt;= 4)
00456             (*_printf) (<SPAN class=stringliteral>" magic %02X%02X%02X%02X"</SPAN>, bp[0], bp[1], bp[2], bp[3]);
00457          <SPAN class=keywordflow>if</SPAN> (len &gt; 4)
00458          {
00459            (*_printf) (<SPAN class=stringliteral>" "</SPAN>);
00460            safe_string (bp+4, len-4);
00461          }
00462          <SPAN class=keywordflow>break</SPAN>;
00463   }
00464   (*_printf) (<SPAN class=stringliteral>"\n"</SPAN>);
00465 }
00466 
00467 <SPAN class=preprocessor>#undef  PRINTF</SPAN>
00468 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#define PRINTF(lvl,x)  do {                \</SPAN>
00469 <SPAN class=preprocessor>                         if (debug &gt;= lvl) \</SPAN>
00470 <SPAN class=preprocessor>                            (*_printf) x;  \</SPAN>
00471 <SPAN class=preprocessor>                       } while (0)</SPAN>
00472 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#else</SPAN>
00473 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>  #undef  PRINTF</SPAN>
00474 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>  #define PRINTF(lvl,x)  ((void)0)</SPAN>
00475 <SPAN class=preprocessor></SPAN><SPAN class=preprocessor>#endif  </SPAN><SPAN class=comment>/* USE_DEBUG */</SPAN>
00476 
00477 
00478 <SPAN class=comment>/*</SPAN>
00479 <SPAN class=comment> * Write packet to PPPoE session. Display contents if debugging.</SPAN>
00480 <SPAN class=comment> */</SPAN>
00481 <SPAN class=keyword>static</SPAN> __inline <SPAN class=keywordtype>void</SPAN> ppp_write (<SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct</SPAN> ppp_state *state,
00482                                 <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp,
00483                                 <SPAN class=keyword>const</SPAN> BYTE *buf, <SPAN class=keywordtype>int</SPAN> len)
00484 {
00485   WATT_ASSERT (state);
00486   WATT_ASSERT (xcp);
00487 
00488 <SPAN class=preprocessor>#if defined(USE_DEBUG)</SPAN>
00489 <SPAN class=preprocessor></SPAN>  <SPAN class=keywordflow>if</SPAN> (debug &gt; 3)
00490      buffer_print (<SPAN class=stringliteral>"Transmitting"</SPAN>, buf, len);
00491 
00492   <SPAN class=keywordflow>if</SPAN> (debug &gt; 2)
00493   {
00494     <SPAN class=keywordtype>int</SPAN> retv = buf[0] == 0xFF ? 2 : 0;
00495     retv += buf[retv] &amp; 1 ? 1 : 2;
00496     show_packet (<SPAN class=stringliteral>"SENT"</SPAN>, state, xcp, buf + retv, len - retv);
00497   }
00498 <SPAN class=preprocessor>#endif</SPAN>
00499 <SPAN class=preprocessor></SPAN>  pppoe_send_sess (NULL <SPAN class=comment>/*\todo state-&gt;sock */</SPAN>, buf, len);
00500 }
00501 
00502 <SPAN class=comment>/*</SPAN>
00503 <SPAN class=comment> * Insert PPP protocol field.</SPAN>
00504 <SPAN class=comment> */</SPAN>
00505 <SPAN class=keyword>static</SPAN> __inline <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *setup_acpf (BYTE *buf, WORD proto)
00506 {
00507   *(<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a1">WORD</A>*)buf = intel16 (proto);
00508   <SPAN class=keywordflow>return</SPAN> (buf + 2);
00509 }
00510 
00511 <SPAN class=comment>/*</SPAN>
00512 <SPAN class=comment> * Set up buffer for a new message (Configure-Request, Protocol-Reject,</SPAN>
00513 <SPAN class=comment> * Echo-Request, or Discard-Request).</SPAN>
00514 <SPAN class=comment> */</SPAN>
00515 <SPAN class=keyword>static</SPAN> <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *code_id (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp, <SPAN class=keywordtype>int</SPAN> code)
00516 {
00517   <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *buf = setup_acpf (state-&gt;outbuffer, xcp-&gt;proto);
00518 
00519   *buf++ = code;
00520   *buf++ = ++xcp-&gt;ident;
00521   *buf++ = 0;
00522   *buf++ = 4;
00523   <SPAN class=keywordflow>return</SPAN> (buf);
00524 }
00525 
00526 <SPAN class=comment>/*</SPAN>
00527 <SPAN class=comment> * Set up buffer for a reply to a previous message (Configure-Ack,</SPAN>
00528 <SPAN class=comment> * Configure-Nak, Configure-Reject, Echo-Reply).</SPAN>
00529 <SPAN class=comment> */</SPAN>
00530 <SPAN class=keyword>static</SPAN> <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *code_reply (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp, <SPAN class=keywordtype>int</SPAN> code)
00531 {
00532   <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A> *buf = setup_acpf (state-&gt;outbuffer, xcp-&gt;proto);
00533 
00534   *buf++ = code;
00535   *buf++ = state-&gt;inbuffer[3]; <SPAN class=comment>/* ident */</SPAN>
00536   *buf++ = 0;
00537   *buf++ = 4;
00538   <SPAN class=keywordflow>return</SPAN> (buf);
00539 }
00540 
00541 <SPAN class=comment>/*</SPAN>
00542 <SPAN class=comment> * Find a given option in the list for an XCP.</SPAN>
00543 <SPAN class=comment> */</SPAN>
00544 <SPAN class=keyword>static</SPAN> <SPAN class=keyword>struct </SPAN>option_state *find_option (const struct ppp_xcp *xcp, int type)
00545 {
00546   <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct </SPAN>xcp_type *tp;
00547 
00548   <SPAN class=keywordflow>for</SPAN> (tp = xcp-&gt;types; tp-&gt;type != -1; tp++)
00549       <SPAN class=keywordflow>if</SPAN> (tp-&gt;type == type)
00550          <SPAN class=keywordflow>return</SPAN> (xcp-&gt;opts + (tp - xcp-&gt;types));
00551   <SPAN class=keywordflow>return</SPAN> (NULL);
00552 }
00553 
00554 <SPAN class=comment>/*</SPAN>
00555 <SPAN class=comment> * Loop over all known options and insert into a Configure-Request</SPAN>
00556 <SPAN class=comment> * being built.</SPAN>
00557 <SPAN class=comment> */</SPAN>
00558 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> create_request (<SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp)
00559 {
00560   <SPAN class=keyword>struct </SPAN>xcp_type     *tp;
00561   <SPAN class=keyword>struct </SPAN>option_state *os;
00562   <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A>  *bp, *obp;
00563 
00564   obp = bp = code_id (state, xcp, CODE_CONF_REQ);
00565   <SPAN class=keywordflow>for</SPAN> (tp = xcp-&gt;types, os = xcp-&gt;opts; tp-&gt;type != -1; tp++, os++)
00566   {
00567     <SPAN class=keywordflow>if</SPAN> (os-&gt;state == osUnusable)
00568        <SPAN class=keywordflow>continue</SPAN>;
00569 
00570     <SPAN class=keywordflow>if</SPAN> (!tp-&gt;flag &amp;&amp; os-&gt;my_value == tp-&gt;default_value)
00571        <SPAN class=keywordflow>continue</SPAN>;
00572 
00573     bp[0] = tp-&gt;type;
00574     bp[1] = tp-&gt;minlen;
00575     <SPAN class=keywordflow>if</SPAN> (tp-&gt;minlen &gt; 2)
00576        bp[2] = (os-&gt;my_value &gt;&gt; (8 * (tp-&gt;minlen - 3))) &amp; 0xFF;
00577     <SPAN class=keywordflow>if</SPAN> (tp-&gt;minlen &gt; 3)
00578        bp[3] = (os-&gt;my_value &gt;&gt; (8 * (tp-&gt;minlen - 4))) &amp; 0xFF;
00579     <SPAN class=keywordflow>if</SPAN> (tp-&gt;minlen &gt; 4)
00580        bp[4] = (os-&gt;my_value &gt;&gt; (8 * (tp-&gt;minlen - 5))) &amp; 0xFF;
00581     <SPAN class=keywordflow>if</SPAN> (tp-&gt;minlen &gt; 5)
00582        bp[5] = os-&gt;my_value &amp; 0xFF;
00583     bp += bp[1];
00584   }
00585   *(<A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a1">WORD</A>*) (obp-2) = intel16 (bp-obp+4);
00586   state-&gt;up = bp;
00587 }
00588 
00589 <SPAN class=comment>/*</SPAN>
00590 <SPAN class=comment> * We've gotten a Configure-Request we like (RCR+), so we're agreeing</SPAN>
00591 <SPAN class=comment> * with the peer.  Set up to send Configure-Ack.</SPAN>
00592 <SPAN class=comment> */</SPAN>
00593 <SPAN class=keyword>static</SPAN> <SPAN class=keywordtype>void</SPAN> copy_peer_values (<SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct</SPAN> ppp_state *state, <SPAN class=keyword>struct</SPAN> ppp_xcp *xcp)
00594 {
00595   <SPAN class=keyword>struct </SPAN>option_state *os;
00596   <SPAN class=keyword>const</SPAN> <SPAN class=keyword>struct </SPAN>xcp_type *tp;
00597   <SPAN class=keyword>const</SPAN> <A class=code href="http://www.bgnett.no/~giva/watt-doc/a01345.html#a0">BYTE</A>  *bp;
00598   <SPAN class=keywordtype>int</SPAN>   rlen;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -