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

📄 arp_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 4 页
字号:
00260         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localHW[2]));00261         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localHW[1]));00262         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localHW[0]));00263         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localip&gt;&gt;24));00264         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localip&gt;&gt;16));00265         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localip&gt;&gt;8));00266         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localip));00267         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)rem_hwadr[5]);00268         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)rem_hwadr[4]);00269         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)rem_hwadr[3]);00270         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)rem_hwadr[2]);00271         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)rem_hwadr[1]);00272         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)rem_hwadr[0]);                                            00273         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(rem_ip&gt;&gt;24));00274         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(rem_ip&gt;&gt;16));00275         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(rem_ip&gt;&gt;8));00276         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)rem_ip);00277         00278         <a class="code" href="system_8h.html#a16">NETWORK_COMPLETE_SEND</a>(0x0040);          <span class="comment">/* Send the packet      */</span>00279         00280         ARP_DEBUGOUT(<span class="stringliteral">"ARP Reply Sent..\n\r"</span>);00281         00282         <span class="comment">/* Add the Sender's info to cache because we can        */</span>00283         00284         <a class="code" href="arp_8c.html#a7">arp_add</a>(rem_ip, &amp;send_frame.destination[0], <a class="code" href="arp_8h.html#a17">ARP_TEMP_IP</a>);00285         00286         <span class="keywordflow">return</span>;00287                 00288 }00289 00290 <a name="l00307"></a><a class="code" href="arp_8c.html#a4">00307</a> <span class="keywordtype">void</span> <a class="code" href="arp_8c.html#a4">arp_get_response</a>(<span class="keywordtype">void</span>)00308 {00309         <span class="keyword">struct </span><a class="code" href="structarp__entry.html">arp_entry</a> *qstruct;00310         UINT8 rem_hwadr[<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>];00311         UINT32  rem_ip;00312         UINT32  ltemp;00313         INT8 i;00314         UINT8 j;00315         00316         <span class="comment">/* Read Sender's HW address     */</span>00317         00318         <span class="keywordflow">for</span>( i=<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>-1; i &gt;= 0; i-- )00319                 rem_hwadr[i] = <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00320                 00321         <span class="comment">/* Read Sender's IP Address     */</span>00322         00323         <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="arp_8h.html#a1">MAXPRALEN</a>; i++) {00324                 rem_ip &lt;&lt;= 8;00325                 rem_ip |= <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00326         }00327         00328         00329         <span class="comment">/* Skip our HW Address  */</span>00330         00331         <span class="keywordflow">for</span>(i=0; i&lt;<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>; i++)00332                 <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00333         00334         00335         <span class="comment">/* Is The Packet For Us?        */</span>00336         00337         <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="arp_8h.html#a1">MAXPRALEN</a>; i++)     {00338                 ltemp &lt;&lt;= 8;00339                 ltemp |= <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00340         }00341                 00342         00343         <span class="keywordflow">if</span>( ltemp != localmachine.localip ) 00344                 <span class="keywordflow">return</span>;                                                         <span class="comment">/* No   */</span>00345 00346         ARP_DEBUGOUT(<span class="stringliteral">"Now entering to process ARP Reply..\n\r"</span>);00347         00348         <span class="comment">/* Are we waiting for that reply?       */</span>00349         00350         <span class="keywordflow">for</span>( i=1; i&lt;ARP_TSIZE; i++ ) {00351                 qstruct = &amp;arp_table[i];00352                 00353                 <span class="keywordflow">if</span>( qstruct-&gt;<a class="code" href="structarp__entry.html#m0">state</a> == <a class="code" href="arp_8h.html#a11">ARP_FREE</a> )00354                         <span class="keywordflow">continue</span>;00355                 00356                 <span class="keywordflow">if</span>( qstruct-&gt;<a class="code" href="structarp__entry.html#m0">state</a> == <a class="code" href="arp_8h.html#a12">ARP_RESERVED</a> )00357                         <span class="keywordflow">continue</span>;                               00358                 00359                 <span class="keywordflow">if</span>( rem_ip == qstruct-&gt;<a class="code" href="structarp__entry.html#m5">pradr</a> ) {00360                         <span class="comment">/* We are caching that IP, refresh it   */</span>00361                         00362                         ARP_DEBUGOUT(<span class="stringliteral">"Refreshing ARP cache from Reply..\n\r"</span>);00363                         00364                         <span class="keywordflow">for</span>( j=0; j&lt;<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>; j++ )            00365                                 qstruct-&gt;<a class="code" href="structarp__entry.html#m4">hwadr</a>[j] = rem_hwadr[j];00366                                 00367                         qstruct-&gt;<a class="code" href="structarp__entry.html#m3">ttl</a> = <a class="code" href="group__opentcp__config.html#a1">ARP_TIMEOUT</a>;00368                         qstruct-&gt;<a class="code" href="structarp__entry.html#m2">retries</a> = <a class="code" href="group__opentcp__config.html#a3">ARP_MAXRETRY</a>;                                <span class="comment">/* No need for Retry    */</span>00369                         qstruct-&gt;<a class="code" href="structarp__entry.html#m0">state</a> = <a class="code" href="arp_8h.html#a14">ARP_RESOLVED</a>;00370                 00371                         <span class="comment">/* Done */</span>00372                         00373                         <span class="keywordflow">break</span>;00374                 }       00375         00376         }00377 00378 }00379 <a name="l00390"></a><a class="code" href="arp_8c.html#a5">00390</a> <span class="keywordtype">void</span> <a class="code" href="arp_8c.html#a5">arp_send_req</a> (UINT8 entry)00391 {00392 00393         <span class="keyword">struct </span><a class="code" href="structarp__entry.html">arp_entry</a> *qstruct;00394         UINT8 i;00395         00396         qstruct = &amp;arp_table[entry];00397         00398         <a class="code" href="system_8h.html#a17">NETWORK_SEND_INITIALIZE</a>(<a class="code" href="ethernet_8h.html#a35">ARP_BUFFER</a>);00399         00400         <span class="comment">/* Add datalink (Ethernet addresses) information        */</span>00401         00402         <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>; i++) {00403                 send_frame.destination[i] = 0xFF;00404                 send_frame.source[i] = localmachine.localHW[i];00405         }00406         00407         send_frame.protocol = <a class="code" href="ethernet_8h.html#a5">PROTOCOL_ARP</a>;00408         00409         <a class="code" href="system_8h.html#a18">NETWORK_ADD_DATALINK</a>(&amp;send_frame);00410         00411         <span class="comment">/* PUT ARP Data */</span>00412 00413         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (BYTE) (AR_HARDWARE&gt;&gt;8) );                      <span class="comment">/* Hardware Type        */</span>00414         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (BYTE) AR_HARDWARE );00415         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(0x08);                                                           <span class="comment">/* Protocol Type        */</span>00416         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(0x00);00417         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>);                                                      <span class="comment">/* HW Adr Len           */</span>00418         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(<a class="code" href="arp_8h.html#a1">MAXPRALEN</a>);                                                      <span class="comment">/* Protocol Adr. Len*/</span>00419         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (BYTE)(ARP_REQUEST&gt;&gt;8));                        <span class="comment">/* ARP Opcode           */</span>00420         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (BYTE) ARP_REQUEST );00421         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)localmachine.localHW[5]);         <span class="comment">/* Address fields       */</span>00422         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)localmachine.localHW[4]);00423         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)localmachine.localHW[3]);00424         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)localmachine.localHW[2]);00425         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)localmachine.localHW[1]);00426         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)localmachine.localHW[0]);00427         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localip&gt;&gt;24));00428         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localip&gt;&gt;16));00429         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localip&gt;&gt;8));00430         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)localmachine.localip);00431         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)0xFF);00432         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)0xFF);00433         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)0xFF);00434         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)0xFF);00435         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)0xFF);00436         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)0xFF);                                            00437         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(qstruct-&gt;<a class="code" href="structarp__entry.html#m5">pradr</a>&gt;&gt;24));00438         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(qstruct-&gt;<a class="code" href="structarp__entry.html#m5">pradr</a>&gt;&gt;16));00439         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(qstruct-&gt;<a class="code" href="structarp__entry.html#m5">pradr</a>&gt;&gt;8));00440         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)qstruct-&gt;<a class="code" href="structarp__entry.html#m5">pradr</a>);00441         00442         00443         <span class="comment">/* Packet assembled now, just send it ... */</span>00444         00445         <a class="code" href="system_8h.html#a16">NETWORK_COMPLETE_SEND</a>(0x0040);                                          <span class="comment">/* Min packet size      */</span>00446  00447         ARP_DEBUGOUT(<span class="stringliteral">"ARP Request Sent\n\r"</span>);00448         00449 }00450 00451 <a name="l00466"></a><a class="code" href="arp_8c.html#a6">00466</a> INT8 <a class="code" href="arp_8c.html#a6">arp_alloc</a> (UINT8 type)00467 {00468         <span class="keyword">struct </span><a class="code" href="structarp__entry.html">arp_entry</a> *qstruct;00469         INT8 i;00470         <span class="keyword">static</span> BYTE aenext = 1;         <span class="comment">/* Cache Manager        */</span>00471         INT16 found;00472         00473         <span class="comment">/* try to find free entry */</span>00474         found=-1;00475 00476         <span class="keywordflow">for</span>( i=0; i&lt;ARP_TSIZE; i++ ) {00477         00478                 <span class="keywordflow">if</span>( arp_table[i].<a class="code" href="structarp__entry.html#m0">state</a> == <a class="code" href="arp_8h.html#a11">ARP_FREE</a> ) {00479                         found=i;00480                         <span class="keywordflow">break</span>;00481                 }00482         }00483         00484         <span class="keywordflow">if</span>(found != (-1) ) {00485                 qstruct = &amp;arp_table[found];00486                 qstruct-&gt;<a class="code" href="structarp__entry.html#m0">state</a> = <a class="code" href="arp_8h.html#a12">ARP_RESERVED</a>;00487                 qstruct-&gt;<a class="code" href="structarp__entry.html#m1">type</a> = type;   00488                 <span class="keywordflow">return</span>( (UINT8)found );00489         }00490 00491 00492         <span class="comment">/* if no success, try ro find first temporary entry     */</span>00493         <span class="comment">/* on round-robin fashion                                                       */</span>00494         00495 00496         <span class="keywordflow">for</span>( i=0; i&lt;ARP_TSIZE; i++ ) {  00497                 <span class="keywordflow">if</span>( arp_table[aenext].<a class="code" href="structarp__entry.html#m1">type</a> == <a class="code" href="arp_8h.html#a17">ARP_TEMP_IP</a>) {00498                         found = aenext;                 00499                         <span class="keywordflow">break</span>;00500                 }00501                         

⌨️ 快捷键说明

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