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

📄 tftps_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>/opentcp/tftp/tftps.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindex" href="examples.html">Examples</a> &nbsp; </center><hr><h1>/opentcp/tftp/tftps.c</h1><a href="tftps_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> *Copyright (c) 2000-2002 Viola Systems Ltd.</span>00003 <span class="comment"> *All rights reserved.</span>00004 <span class="comment"> *</span>00005 <span class="comment"> *Redistribution and use in source and binary forms, with or without </span>00006 <span class="comment"> *modification, are permitted provided that the following conditions </span>00007 <span class="comment"> *are met:</span>00008 <span class="comment"> *</span>00009 <span class="comment"> *1. Redistributions of source code must retain the above copyright </span>00010 <span class="comment"> *notice, this list of conditions and the following disclaimer.</span>00011 <span class="comment"> *</span>00012 <span class="comment"> *2. Redistributions in binary form must reproduce the above copyright </span>00013 <span class="comment"> *notice, this list of conditions and the following disclaimer in the </span>00014 <span class="comment"> *documentation and/or other materials provided with the distribution.</span>00015 <span class="comment"> *</span>00016 <span class="comment"> *3. The end-user documentation included with the redistribution, if </span>00017 <span class="comment"> *any, must include the following acknowledgment:</span>00018 <span class="comment"> *      "This product includes software developed by Viola </span>00019 <span class="comment"> *      Systems (http://www.violasystems.com/)."</span>00020 <span class="comment"> *</span>00021 <span class="comment"> *Alternately, this acknowledgment may appear in the software itself, </span>00022 <span class="comment"> *if and wherever such third-party acknowledgments normally appear.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> *4. The names "OpenTCP" and "Viola Systems" must not be used to </span>00025 <span class="comment"> *endorse or promote products derived from this software without prior </span>00026 <span class="comment"> *written permission. For written permission, please contact </span>00027 <span class="comment"> *opentcp@opentcp.org.</span>00028 <span class="comment"> *</span>00029 <span class="comment"> *5. Products derived from this software may not be called "OpenTCP", </span>00030 <span class="comment"> *nor may "OpenTCP" appear in their name, without prior written </span>00031 <span class="comment"> *permission of the Viola Systems Ltd.</span>00032 <span class="comment"> *</span>00033 <span class="comment"> *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED </span>00034 <span class="comment"> *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF </span>00035 <span class="comment"> *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. </span>00036 <span class="comment"> *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE </span>00037 <span class="comment"> *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR </span>00038 <span class="comment"> *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF </span>00039 <span class="comment"> *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR </span>00040 <span class="comment"> *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span>00041 <span class="comment"> *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE </span>00042 <span class="comment"> *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, </span>00043 <span class="comment"> *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>00044 <span class="comment"> *====================================================================</span>00045 <span class="comment"> *</span>00046 <span class="comment"> *OpenTCP is the unified open source TCP/IP stack available on a series </span>00047 <span class="comment"> *of 8/16-bit microcontrollers, please see &lt;http://www.opentcp.org&gt;.</span>00048 <span class="comment"> *</span>00049 <span class="comment"> *For more information on how to network-enable your devices, or how to </span>00050 <span class="comment"> *obtain commercial technical support for OpenTCP, please see </span>00051 <span class="comment"> *&lt;http://www.violasystems.com/&gt;.</span>00052 <span class="comment"> */</span>00053 00070 <span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span>00071 <span class="preprocessor">#include &lt;<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>&gt;</span>00072 <span class="preprocessor">#include &lt;<a class="code" href="globalvariables_8h.html">inet/globalvariables.h</a>&gt;</span>00073 <span class="preprocessor">#include &lt;<a class="code" href="system_8h.html">inet/system.h</a>&gt;</span>00074 <span class="preprocessor">#include &lt;<a class="code" href="timers_8h.html">inet/timers.h</a>&gt;</span>00075 <span class="preprocessor">#include &lt;<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>&gt;</span>00076 <span class="preprocessor">#include &lt;<a class="code" href="tftps_8h.html">inet/tftp/tftps.h</a>&gt;</span>00077 <a name="l00078"></a><a class="code" href="tftps_8c.html#a9">00078</a> UINT8 <a class="code" href="tftps_8c.html#a9">tftpsapp_init</a> = 0; 00081 <span class="comment">/* TFTPS states                 */</span>00082 00083 <span class="preprocessor">#define TFTPS_STATE_ENABLED             1</span>00084 <span class="preprocessor"></span><span class="preprocessor">#define TFTPS_STATE_CONNECTED   2</span>00085 <span class="preprocessor"></span>00086 00087 00088 <span class="comment">/* TFTP Error codes             */</span>00089 00090 <span class="preprocessor">#define TFTPS_NOTDEFINED                        0       </span><span class="comment">/* Not Definet Error            */</span>00091 <span class="preprocessor">#define TFTPS_ACCESSVIOLATION   2       </span><span class="comment">/* Access Violation     Error   */</span>00092 <span class="preprocessor">#define TFTPS_ILLEGALOPERATION  4       </span><span class="comment">/* Not supported Opcode         */</span>00093 00094 00095 <span class="comment">/* TFTP Opcodes         */</span>00096 00097 <span class="preprocessor">#define TFTPS_OPCODE_WRQ                        2       </span><span class="comment">/* Packet is Write Request      */</span>00098 <span class="preprocessor">#define TFTPS_OPCODE_DATA               3       </span><span class="comment">/* Data Packet                          */</span>00099 <span class="preprocessor">#define TFTPS_OPCODE_ACK                        4       </span><span class="comment">/* ACK Packet                           */</span>00100 <span class="preprocessor">#define TFTPS_OPCODE_ERROR              5       </span><span class="comment">/* Error Packet                         */</span>00101 00110 <span class="keyword">struct</span>00111 <span class="keyword"></span>{00112         UINT8   <a class="code" href="structtcb.html#m0">state</a>;00113         INT8    sochandle;      00114         UINT16  tmrhandle;00115         UINT32  remip;00116         UINT16  <a class="code" href="structtcb.html#m4">remport</a>;00117         UINT16  blocknumber;00118         UINT32  bytecount;00119         UINT8   retries;00120 00121 } <a class="code" href="tftps_8c.html#a18">tftps</a>;00122 00123 00124 <a name="l00136"></a><a class="code" href="tftps_8c.html#a19">00136</a> INT8 <a class="code" href="tftps_8c.html#a4">tftps_init</a> (<span class="keywordtype">void</span>){00137         <span class="comment">/* Already initialized? */</span>00138         00139         <span class="keywordflow">if</span>(tftpsapp_init)00140                 <span class="keywordflow">return</span>(1);00141         00142         <span class="comment">/* Get socket handle            */</span>00143         00144         <a class="code" href="tftps_8c.html#a18">tftps</a>.sochandle = <a class="code" href="udp_8c.html#a3">udp_getsocket</a>(0, tftps_eventlistener, <a class="code" href="tcp__ip_8h.html#a5">UDP_OPT_SEND_CS</a> | <a class="code" href="tcp__ip_8h.html#a6">UDP_OPT_CHECK_CS</a>);00145         00146         <span class="keywordflow">if</span>(<a class="code" href="tftps_8c.html#a18">tftps</a>.sochandle &lt; 0)00147                 <span class="keywordflow">return</span>(-1);00148         00149         <span class="comment">/* Put it to listening mode     */</span>00150                 00151         <span class="keywordflow">if</span>( <a class="code" href="udp_8c.html#a5">udp_open</a>(<a class="code" href="tftps_8c.html#a18">tftps</a>.sochandle, <a class="code" href="tftps_8h.html#a0">TFTPS_SERVERPORT</a>) &lt; 0 )00152                 <span class="keywordflow">return</span>(-1);00153         00154         <span class="comment">/* Get timer handle                     */</span>00155         00156         <a class="code" href="tftps_8c.html#a18">tftps</a>.tmrhandle = <a class="code" href="timers_8c.html#a2">get_timer</a>();00157         00158         <a class="code" href="tftps_8c.html#a18">tftps</a>.state = TFTPS_STATE_ENABLED;00159         <a class="code" href="tftps_8c.html#a18">tftps</a>.remip = 0;00160         <a class="code" href="tftps_8c.html#a18">tftps</a>.remport = 0;00161         <a class="code" href="tftps_8c.html#a18">tftps</a>.retries = 0;00162         <a class="code" href="tftps_8c.html#a18">tftps</a>.blocknumber = 0;00163         <a class="code" href="tftps_8c.html#a18">tftps</a>.bytecount = 0;00164         <a class="code" href="tftps_8c.html#a9">tftpsapp_init</a> = 1;00165         00166         <span class="keywordflow">return</span>(1);              00167         00168 }00169 00170 <span class="comment">/********************************************************************************</span>00171 <span class="comment">Function:               tftps_run</span>00172 <span class="comment"></span>00173 <span class="comment">Parameters:             void</span>00174 <span class="comment">                                </span>00175 <span class="comment">Return val:             void</span>00176 <span class="comment">                                </span>00177 <span class="comment">Date:                   7.10.2002</span>00178 <span class="comment"></span>00179 <span class="comment">Desc:                   The main thread of TFTP server that should be called periodically</span>00180 <span class="comment">*********************************************************************************/</span>00181 00182 <span class="keywordtype">void</span> tftps_run (<span class="keywordtype">void</span>)00183 {00184         <span class="keywordflow">if</span>(<a class="code" href="tftps_8c.html#a9">tftpsapp_init</a> == 0)00185                 <span class="keywordflow">return</span>;00186         00187         <span class="comment">/* Check for timeouts   */</span>00188         00189         <span class="keywordflow">if</span>(<a class="code" href="tftps_8c.html#a18">tftps</a>.state == TFTPS_STATE_CONNECTED) {00190                 <span class="keywordflow">if</span>(<a class="code" href="timers_8c.html#a7">check_timer</a>(<a class="code" href="tftps_8c.html#a18">tftps</a>.tmrhandle) == 0)00191                         tftps_deletesocket();   00192         }00193                 00194 }00195 00196 INT32 tftps_eventlistener (INT8 cbhandle, UINT8 event, UINT32 remip, UINT16 remport, UINT16 bufindex, UINT16 dlen)00197 {00198         UINT16 opcode;00199         UINT16 i;00200         UINT8 ch;00201         UINT16 u16temp;00202         UINT8 fname[<a class="code" href="tftps_8h.html#a1">TFTPS_FILENAME_MAXLEN</a>];00203 00204         <span class="keywordflow">if</span>(<a class="code" href="tftps_8c.html#a9">tftpsapp_init</a> == 0)00205                 <span class="keywordflow">return</span>(-1);00206                 00207         <span class="keywordflow">if</span>(cbhandle != <a class="code" href="tftps_8c.html#a18">tftps</a>.sochandle)00208                 <span class="keywordflow">return</span>(-1);     00209                 00210         <span class="comment">/* If we are on other state than enabled, check that we are talking with the same gyu   */</span>00211         00212         <span class="keywordflow">if</span>(     <a class="code" href="tftps_8c.html#a18">tftps</a>.state != TFTPS_STATE_ENABLED)     {00213                 <span class="keywordflow">if</span>(remip != <a class="code" href="tftps_8c.html#a18">tftps</a>.remip)00214                         <span class="keywordflow">return</span>(-1);00215                 <span class="keywordflow">if</span>(remport != <a class="code" href="tftps_8c.html#a18">tftps</a>.remport)00216                         <span class="keywordflow">return</span>(-1);     00217         }00218         00219         <span class="keywordflow">if</span>(dlen &lt; 2)00220                 <span class="keywordflow">return</span>(-1);00221                 00222         <span class="comment">/* Bind socket  */</span>00223                         00224         <a class="code" href="tftps_8c.html#a18">tftps</a>.remip = remip;00225         <a class="code" href="tftps_8c.html#a18">tftps</a>.remport = remport;        00226         00227         <span class="comment">/* Get information      */</span>00228         00229         <a class="code" href="system_8h.html#a14">NETWORK_RECEIVE_INITIALIZE</a>(bufindex);00230         00231         opcode = <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00232         opcode &lt;&lt;= 8;00233         opcode |= <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00234         

⌨️ 快捷键说明

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