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

📄 tftps_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
00235         dlen -= 2;00236         00237         <span class="comment">/* Process it   */</span>00238         00239         <span class="keywordflow">switch</span>(opcode) {00240                 <span class="keywordflow">case</span> TFTPS_OPCODE_WRQ:                                                  <span class="comment">/* Write request?       */</span>00241                 00242                         <span class="comment">/* Get filename */</span> 00243                         00244                         fname[0] = <span class="charliteral">'\0'</span>;00245                         00246                         <span class="keywordflow">for</span>(i=0; i&lt;dlen; i++) {00247                                 <span class="keywordflow">if</span>(i &gt;= <a class="code" href="tftps_8h.html#a1">TFTPS_FILENAME_MAXLEN</a>) {00248                                         tftps_senderror(TFTPS_NOTDEFINED);00249                                         tftps_deletesocket();00250                                         <span class="keywordflow">return</span>(1);00251                                 }00252                                 00253                                 ch = <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00254                                 00255                                 fname[i] = ch;00256                                 00257                                 <span class="keywordflow">if</span>(ch == <span class="charliteral">'\0'</span>) {00258                                         i++;00259                                         <span class="keywordflow">break</span>;00260                                 }00261                         }00262                         00263                         dlen -= i;00264                         <span class="comment">/* !!!!!!!!!!!!!!!!!!!!!!!!     */</span>00265                         <span class="comment">/* Check here the filename      */</span>00266                         <span class="comment">/* if NOT OK, RETURN            */</span>00267                         <span class="comment">/* !!!!!!!!!!!!!!!!!!!!!!!! */</span>00268                         00269                         <span class="comment">/* Check mode, only octet mode is supported     */</span>00270                         00271                         <span class="keywordflow">if</span>(dlen &lt; 6) {00272                                 tftps_senderror(TFTPS_NOTDEFINED);00273                                 tftps_deletesocket();                   00274                                 <span class="keywordflow">return</span>(1);00275                         }00276                         00277                         <span class="keywordflow">if</span>( (<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>() != <span class="charliteral">'o'</span>) || (<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>() != <span class="charliteral">'c'</span>) || (<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>() != <span class="charliteral">'t'</span>) ||00278                                 (<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>() != <span class="charliteral">'e'</span>) || (<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>() != <span class="charliteral">'t'</span>) || (<a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>() != <span class="charliteral">'\0'</span>)   ) {00279                                 tftps_senderror(TFTPS_NOTDEFINED);00280                                 tftps_deletesocket();00281                                 <span class="keywordflow">return</span>(1);00282                         }00283                         00284                         <span class="comment">/* All OK, send ACK     */</span>00285                         00286                         <a class="code" href="tftps_8c.html#a18">tftps</a>.state = TFTPS_STATE_CONNECTED;00287                         <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber = 0;00288                         <a class="code" href="tftps_8c.html#a18">tftps</a>.bytecount = 0;00289                         <a class="code" href="tftps_8c.html#a18">tftps</a>.retries = <a class="code" href="tftps_8h.html#a2">TFTPS_DEF_RETRIES</a>;00290                         <a class="code" href="timers_8c.html#a6">init_timer</a>(<a class="code" href="tftps_8c.html#a18">tftps</a>.tmrhandle, <a class="code" href="tftps_8h.html#a3">TFTPS_TIMEOUT</a>*<a class="code" href="timers_8h.html#a1">TIMERTIC</a>);00291                                         00292                         tftps_sendack();00293                                         00294                         <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber++;00295                                         00296                         <span class="keywordflow">return</span>(1);                      00297                         00298                 00299                 <span class="keywordflow">case</span> TFTPS_OPCODE_DATA:                                                                                 <span class="comment">/* Data Packet ? */</span>00300                 00301                         <span class="keywordflow">if</span>(<a class="code" href="tftps_8c.html#a18">tftps</a>.state != TFTPS_STATE_CONNECTED) {00302                                 tftps_senderror(TFTPS_NOTDEFINED);00303                                 tftps_deletesocket();00304                                 <span class="keywordflow">return</span>(1);00305                         }               00306                         00307                         <span class="keywordflow">if</span>(dlen &lt; 2) {00308                                 tftps_senderror(TFTPS_NOTDEFINED);00309                                 tftps_deletesocket();                   00310                                 <span class="keywordflow">return</span>(1);00311                         }                               00312         00313                         <span class="comment">/* Get block number     */</span>00314                         00315                         u16temp = <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00316                         u16temp &lt;&lt;= 8;00317                         u16temp |= <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00318         00319                         dlen -= 2;      00320                         00321                         <span class="keywordflow">if</span>( (u16temp &lt; <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber) &amp;&amp; (<a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber &gt; 0) ) {00322                                 <span class="comment">/* Duplicate msg, send ACK again        */</span>00323                         00324                                 <span class="keywordflow">if</span>( <a class="code" href="tftps_8c.html#a18">tftps</a>.retries &gt; 0 ) {00325                                         <a class="code" href="tftps_8c.html#a18">tftps</a>.retries--;00326                                         <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber--;00327                                         tftps_sendack();00328                                         <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber++;00329                                 } <span class="keywordflow">else</span> {00330                                         tftps_senderror(TFTPS_NOTDEFINED);00331                                         tftps_deletesocket();00332                                 }00333                 00334                                 <span class="keywordflow">return</span>(1);              00335                         }00336                 00337                         <span class="keywordflow">if</span>( u16temp != <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber ) {00338                                 <span class="comment">/* Something really wrong */</span>00339                 00340                                 tftps_senderror(TFTPS_NOTDEFINED);00341                                 tftps_deletesocket();00342                                 <span class="keywordflow">return</span>(1);00343                         }                                       00344                         00345                         <span class="comment">/* !!!!!!!!!!!!!!!!!!!!!!!!     */</span>00346                         <span class="comment">/* Read the data here           */</span>00347                         <span class="comment">/* !!!!!!!!!!!!!!!!!!!!!!!!     */</span>00348                         00349                         <span class="keywordflow">if</span>( dlen &lt; 512 ) {00350                                 <span class="comment">/* Other side Wants to close */</span>00351                         00352                                 tftps_sendack();00353                                 tftps_deletesocket();00354                                 <span class="keywordflow">return</span>(1);00355                         }                       00356                         00357                         <span class="comment">/* All OK       */</span>00358                         00359                         <a class="code" href="tftps_8c.html#a18">tftps</a>.retries = <a class="code" href="tftps_8h.html#a2">TFTPS_DEF_RETRIES</a>;00360                         <a class="code" href="timers_8c.html#a6">init_timer</a>(<a class="code" href="tftps_8c.html#a18">tftps</a>.tmrhandle, <a class="code" href="tftps_8h.html#a3">TFTPS_TIMEOUT</a>*<a class="code" href="timers_8h.html#a1">TIMERTIC</a>);00361                         tftps_sendack();00362                         <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber++;                    00363         00364                         <span class="keywordflow">return</span>(1);00365                         00366                 <span class="keywordflow">case</span> TFTPS_OPCODE_ERROR:00367                 00368                         tftps_deletesocket();00369         00370                         <span class="keywordflow">return</span>(1);00371         00372                 <span class="keywordflow">default</span>:00373                 00374                         <span class="comment">/* Unsupported Opcode, Send error */</span>00375                 00376                         tftps_senderror(TFTPS_ILLEGALOPERATION);00377                         tftps_deletesocket();                   00378         00379                         <span class="keywordflow">return</span>(1);00380         }       00381                 00382 }00383 00384 00385 <span class="keywordtype">void</span> tftps_sendack (<span class="keywordtype">void</span>)00386 {00387         <span class="comment">/* Send a TFTP ACK packet */</span>00388         00389         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 0] = 0;                <span class="comment">/* Opcode       */</span>00390         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 1] = 4;00391         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 2] = (UINT8)(<a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber &gt;&gt; 8);00392         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 3] = (UINT8)<a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber;00393         00394         <a class="code" href="udp_8c.html#a7">udp_send</a>(<a class="code" href="tftps_8c.html#a18">tftps</a>.sochandle, <a class="code" href="tftps_8c.html#a18">tftps</a>.remip, <a class="code" href="tftps_8c.html#a18">tftps</a>.remport, &amp;net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>], <a class="code" href="group__opentcp__config.html#a4">NETWORK_TX_BUFFER_SIZE</a> - <a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>, 4);00395         00396 00397 }00398 00399 00400 00401 00402 <span class="keywordtype">void</span> tftps_senderror (UINT8 errno )00403 {00404         <span class="comment">/* Send TFTP Error -packet */</span>00405         00406         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 0] = 0;                <span class="comment">/* Opcode       */</span>00407         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 1] = 5;00408         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 2] = (UINT8)(<a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber &gt;&gt; 8);00409         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 3] = (UINT8)<a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber;00410         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 4] = errno;00411         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 5] = <span class="charliteral">'\0'</span>;00412         net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a> + 6] = 0;00413         00414         <a class="code" href="udp_8c.html#a7">udp_send</a>(<a class="code" href="tftps_8c.html#a18">tftps</a>.sochandle, <a class="code" href="tftps_8c.html#a18">tftps</a>.remip, <a class="code" href="tftps_8c.html#a18">tftps</a>.remport, &amp;net_buf[<a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>], <a class="code" href="group__opentcp__config.html#a4">NETWORK_TX_BUFFER_SIZE</a> - <a class="code" href="tcp__ip_8h.html#a62">UDP_APP_OFFSET</a>, 7);    00415         00416 }00417 00418 <span class="keywordtype">void</span> tftps_deletesocket (<span class="keywordtype">void</span>)00419 {00420         <span class="comment">/* Clear Socket Data */</span>00421 00422         <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber = 0;00423         <a class="code" href="tftps_8c.html#a18">tftps</a>.state = TFTPS_STATE_ENABLED;00424         <a class="code" href="tftps_8c.html#a18">tftps</a>.retries = 0;00425         <a class="code" href="tftps_8c.html#a18">tftps</a>.remip = 0;00426         <a class="code" href="tftps_8c.html#a18">tftps</a>.remport = 0;      00427 00428 00429 }00430 00431 00432 </pre></div><hr><address style="align: right;"><small>Generated on Sun Aug 3 20:33:00 2003 for OpenTCP by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>

⌨️ 快捷键说明

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