?lang_form?
?lang_select?
?lang_submit?
?lang_endform?
{HEADER END}
{FILE START}
library
?curdirlinks? - Rev 6
?prevdifflink? - Blame - ?getfile?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Procyon AVRlib: net/netstack.c Source File</title>
<link href="dox.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<div class="nav">
<a class="el" href="dir_000001.html">net</a></div>
<h1>netstack.c</h1><a href="netstack_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file netstack.c \brief Network Stack. */</span>
00002 <span class="comment">//*****************************************************************************</span>
00003 <span class="comment">//</span>
00004 <span class="comment">// File Name : 'netstack.c'</span>
00005 <span class="comment">// Title : Network Stack</span>
00006 <span class="comment">// Author : Pascal Stang</span>
00007 <span class="comment">// Created : 6/28/2005</span>
00008 <span class="comment">// Revised : 9/20/2005</span>
00009 <span class="comment">// Version : 0.3</span>
00010 <span class="comment">// Target MCU : Atmel AVR series</span>
00011 <span class="comment">// Editor Tabs : 4</span>
00012 <span class="comment">//</span>
00013 <span class="comment">//*****************************************************************************</span>
00014
00015 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>
00016 <span class="preprocessor">#include "<a class="code" href="debug_8h.html">debug.h</a>"</span>
00017
00018 <span class="preprocessor">#include "<a class="code" href="netstack_8h.html">netstack.h</a>"</span>
00019
00020 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> NetBuffer[<a class="code" href="group__netstack.html#ga6">NETSTACK_BUFFERSIZE</a>];
00021
<a name="l00022"></a><a class="code" href="group__netstack.html#ga0">00022</a> <span class="keywordtype">void</span> <a class="code" href="group__netstack.html#ga0">netstackInit</a>(uint32_t ipaddress, uint32_t netmask, uint32_t gatewayip)
00023 {
00024 <span class="comment">// init network device driver</span>
00025 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00026 <span class="preprocessor"></span> rprintf(<span class="stringliteral">"Initializing Network Device\r\n"</span>);
00027 <span class="preprocessor"> #endif</span>
00028 <span class="preprocessor"></span> <a class="code" href="group__nic.html#ga0">nicInit</a>();
00029 <span class="comment">// init ARP</span>
00030 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00031 <span class="preprocessor"></span> rprintf(<span class="stringliteral">"Initializing ARP cache\r\n"</span>);
00032 <span class="preprocessor"> #endif</span>
00033 <span class="preprocessor"></span> <a class="code" href="group__arp.html#ga0">arpInit</a>();
00034 <span class="comment">// init addressing</span>
00035 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00036 <span class="preprocessor"></span> rprintf(<span class="stringliteral">"Initializing Addressing\r\n"</span>);
00037 <span class="preprocessor"> #endif</span>
00038 <span class="preprocessor"></span> <a class="code" href="group__ip.html#ga0">ipSetConfig</a>(ipaddress, netmask, gatewayip);
00039 }
00040
<a name="l00041"></a><a class="code" href="group__netstack.html#ga1">00041</a> u08* <a class="code" href="group__netstack.html#ga1">netstackGetBuffer</a>(<span class="keywordtype">void</span>)
00042 {
00043 <span class="keywordflow">return</span> NetBuffer;
00044 }
00045
<a name="l00046"></a><a class="code" href="group__netstack.html#ga2">00046</a> <span class="keywordtype">int</span> <a class="code" href="group__netstack.html#ga2">netstackService</a>(<span class="keywordtype">void</span>)
00047 {
00048 <span class="keywordtype">int</span> len;
00049 <span class="keyword">struct </span>netEthHeader* ethPacket;
00050
00051 <span class="comment">// look for a packet</span>
00052 len = <a class="code" href="group__nic.html#ga2">nicPoll</a>(<a class="code" href="group__netstack.html#ga6">NETSTACK_BUFFERSIZE</a>, NetBuffer);
00053
00054 <span class="keywordflow">if</span>(len)
00055 {
00056 ethPacket = (<span class="keyword">struct </span>netEthHeader*)&NetBuffer[0];
00057
00058 <span class="preprocessor"> #if NET_DEBUG >= 5</span>
00059 <span class="preprocessor"></span> rprintf(<span class="stringliteral">"Received packet len: %d, type:"</span>, len);
00060 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(<a class="code" href="group__net.html#ga2">htons</a>(ethPacket->type));
00061 <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();
00062 rprintf(<span class="stringliteral">"Packet Contents\r\n"</span>);
00063 <a class="code" href="debug_8c.html#a0">debugPrintHexTable</a>(len, NetBuffer);
00064 <span class="preprocessor"> #endif</span>
00065 <span class="preprocessor"></span>
00066 <span class="keywordflow">if</span>(ethPacket->type == <a class="code" href="group__net.html#ga2">htons</a>(ETHTYPE_IP))
00067 {
00068 <span class="comment">// process an IP packet</span>
00069 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00070 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"NET Rx: IP packet\r\n"</span>);
00071 <span class="preprocessor"> #endif</span>
00072 <span class="preprocessor"></span> <span class="comment">// add the source to the ARP cache</span>
00073 <span class="comment">// also correctly set the ethernet packet length before processing?</span>
00074 <a class="code" href="group__arp.html#ga3">arpIpIn</a>((<span class="keyword">struct</span> netEthIpHeader*)&NetBuffer[0]);
00075 <span class="comment">//arpPrintTable();</span>
00076
00077 <a class="code" href="group__netstack.html#ga3">netstackIPProcess</a>( len-ETH_HEADER_LEN, (ip_hdr*)&NetBuffer[ETH_HEADER_LEN] );
00078 }
00079 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ethPacket->type == <a class="code" href="group__net.html#ga2">htons</a>(ETHTYPE_ARP))
00080 {
00081 <span class="comment">// process an ARP packet</span>
00082 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00083 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"NET Rx: ARP packet\r\n"</span>);
00084 <span class="preprocessor"> #endif</span>
00085 <span class="preprocessor"></span> <a class="code" href="group__arp.html#ga2">arpArpIn</a>(len, ((<span class="keyword">struct</span> netEthArpHeader*)&NetBuffer[0]) );
00086 }
00087 }
00088 <span class="keywordflow">return</span> len;
00089 }
00090
<a name="l00091"></a><a class="code" href="group__netstack.html#ga3">00091</a> <span class="keywordtype">void</span> <a class="code" href="group__netstack.html#ga3">netstackIPProcess</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len, ip_hdr* packet)
00092 {
00093 <span class="comment">// check IP addressing, stop processing if not for me and not a broadcast</span>
00094 <span class="keywordflow">if</span>( (<a class="code" href="group__net.html#ga3">htonl</a>(packet->destipaddr) != <a class="code" href="group__ip.html#ga1">ipGetConfig</a>()->ip) &&
00095 (<a class="code" href="group__net.html#ga3">htonl</a>(packet->destipaddr) != (<a class="code" href="group__ip.html#ga1">ipGetConfig</a>()->ip|<a class="code" href="group__ip.html#ga1">ipGetConfig</a>()->netmask)) &&
00096 (<a class="code" href="group__net.html#ga3">htonl</a>(packet->destipaddr) != 0xFFFFFFFF) )
00097 <span class="keywordflow">return</span>;
00098
00099 <span class="comment">// handle ICMP packet</span>
00100 <span class="keywordflow">if</span>( packet->proto == IP_PROTO_ICMP )
00101 {
00102 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00103 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"NET Rx: ICMP/IP packet\r\n"</span>);
00104 <span class="comment">//icmpPrintHeader((icmpip_hdr*)packet);</span>
00105 <span class="preprocessor"> #endif</span>
00106 <span class="preprocessor"></span> <a class="code" href="group__icmp.html#ga1">icmpIpIn</a>((icmpip_hdr*)packet);
00107 }
00108 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( packet->proto == IP_PROTO_UDP )
00109 {
00110 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00111 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"NET Rx: UDP/IP packet\r\n"</span>);
00112 <span class="comment">//debugPrintHexTable(NetBufferLen-14, &NetBuffer[14]);</span>
00113 <span class="preprocessor"> #endif</span>
00114 <span class="preprocessor"></span> <a class="code" href="group__netstack.html#ga4">netstackUDPIPProcess</a>(len, ((udpip_hdr*)packet) );
00115 }
00116 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( packet->proto == IP_PROTO_TCP )
00117 {
00118 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00119 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"NET Rx: TCP/IP packet\r\n"</span>);
00120 <span class="preprocessor"> #endif</span>
00121 <span class="preprocessor"></span> <a class="code" href="group__netstack.html#ga5">netstackTCPIPProcess</a>(len, ((tcpip_hdr*)packet) );
00122 }
00123 <span class="keywordflow">else</span>
00124 {
00125 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00126 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">"NET Rx: IP packet\r\n"</span>);
00127 <span class="preprocessor"> #endif</span>
00128 <span class="preprocessor"></span> }
00129 }
00130
<a name="l00131"></a><a class="code" href="group__netstack.html#ga4">00131</a> <span class="keywordtype">void</span> <a class="code" href="group__netstack.html#ga4">netstackUDPIPProcess</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len, udpip_hdr* packet)
00132 {
00133 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00134 <span class="preprocessor"></span> rprintf(<span class="stringliteral">"NetStack UDP/IP Rx Dummy Handler\r\n"</span>);
00135 <span class="preprocessor"> #endif</span>
00136 <span class="preprocessor"></span>}
00137
<a name="l00138"></a><a class="code" href="group__netstack.html#ga5">00138</a> <span class="keywordtype">void</span> <a class="code" href="group__netstack.html#ga5">netstackTCPIPProcess</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len, tcpip_hdr* packet)
00139 {
00140 <span class="preprocessor"> #ifdef NETSTACK_DEBUG</span>
00141 <span class="preprocessor"></span> rprintf(<span class="stringliteral">"NetStack TCP/IP Rx Dummy Handler\r\n"</span>);
00142 <span class="preprocessor"> #endif</span>
00143 <span class="preprocessor"></span>}
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
|
{FILE END}
{FOOTER START}
Powered by WebSVN v2.8.3