📄 arp.lst
字号:
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE ARP
OBJECT MODULE PLACED IN .\8052-obj\arp.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\arp.c LARGE OPTIMIZE(SIZE) BROWSE INTVECTOR(0X2000) INCDIR(D:\Work\opent
-cp\1-0-2\src\include\) DEFINE(MONITOR,CS8900) DEBUG OBJECTEXTEND CODE SYMBOLS PRINT(.\8052-lst\arp.lst) PREPRINT(.\8052-
-lst\arp.i) OBJECT(.\8052-obj\arp.obj)
stmt level source
1 /*
2 *Copyright (c) 2000-2002 Viola Systems Ltd.
3 *All rights reserved.
4 *
5 *Redistribution and use in source and binary forms, with or without
6 *modification, are permitted provided that the following conditions
7 *are met:
8 *
9 *1. Redistributions of source code must retain the above copyright
10 *notice, this list of conditions and the following disclaimer.
11 *
12 *2. Redistributions in binary form must reproduce the above copyright
13 *notice, this list of conditions and the following disclaimer in the
14 *documentation and/or other materials provided with the distribution.
15 *
16 *3. The end-user documentation included with the redistribution, if
17 *any, must include the following acknowledgment:
18 * "This product includes software developed by Viola
19 * Systems (http://www.violasystems.com/)."
20 *
21 *Alternately, this acknowledgment may appear in the software itself,
22 *if and wherever such third-party acknowledgments normally appear.
23 *
24 *4. The names "OpenTCP" and "Viola Systems" must not be used to
25 *endorse or promote products derived from this software without prior
26 *written permission. For written permission, please contact
27 *opentcp@opentcp.org.
28 *
29 *5. Products derived from this software may not be called "OpenTCP",
30 *nor may "OpenTCP" appear in their name, without prior written
31 *permission of the Viola Systems Ltd.
32 *
33 *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
34 *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35 *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE
37 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
40 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
41 *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
42 *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43 *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 *====================================================================
45 *
46 *OpenTCP is the unified open source TCP/IP stack available on a series
47 *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.
48 *
49 *For more information on how to network-enable your devices, or how to
50 *obtain commercial technical support for OpenTCP, please see
51 *<http://www.violasystems.com/>.
52 */
53
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 2
54 /** \file arp.c
55 * \brief OpenTCP ARP implementation
56 * \author
57 * \li Jari Lahti (jari.lahti@violasystems.com)
58 * \li Vladan Jovanovic (vladan.jovanovic@violasystems.com)
59 * \version 1.0
60 * \date 10.7.2002
61 * \bug
62 * \warning
63 * \todo
64 * \li Offer direct control over ARP (needed in future for DHCP)
65 *
66 * OpenTCP ARP protocol implementation. Function declarations
67 * can be found in inet/arp.h.
68 */
69 #include <inet/datatypes.h>
*** WARNING C318 IN LINE 69 OF ..\arp.c: can't open file 'inet/datatypes.h'
70 #include <inet/debug.h>
*** WARNING C318 IN LINE 70 OF ..\arp.c: can't open file 'inet/debug.h'
71 #include <inet/ethernet.h>
*** WARNING C318 IN LINE 71 OF ..\arp.c: can't open file 'inet/ethernet.h'
72 #include <inet/arp.h>
*** WARNING C318 IN LINE 72 OF ..\arp.c: can't open file 'inet/arp.h'
73 #include <inet/timers.h>
*** WARNING C318 IN LINE 73 OF ..\arp.c: can't open file 'inet/timers.h'
74 #include <inet/system.h>
*** WARNING C318 IN LINE 74 OF ..\arp.c: can't open file 'inet/system.h'
75 #include <inet/globalvariables.h>
*** WARNING C318 IN LINE 75 OF ..\arp.c: can't open file 'inet/globalvariables.h'
76
77 /** \brief ARP cache table holding ARP_TSIZE cache values
78 *
79 * ARP cache table is an array of arp_entry structures holding
80 * all of the necessary information about the state, timeouts and
81 * hardware/IP addresses of individual entries. By modifying the
82 * #ARP_TSIZE, cache size can be changed and thus RAM memory occupied
83 * by the ARP cache significantly reduced or increased. See arp_entry
84 * definition for more information about struct fields.
85 */
86 struct arp_entry arp_table[ARP_TSIZE];
*** ERROR C202 IN LINE 86 OF ..\ARP.C: 'ARP_TSIZE': undefined identifier
*** ERROR C136 IN LINE 86 OF ..\ARP.C: invalid dimension size: [0]
87
88 /** \brief ARP timer handle used for measuring timeouts, doing retransmissions,..
89 *
90 * ARP module uses this timer handle to detect that a certain period of
91 * time has expired (defined by the value of #ARP_MANG_TOUT) and that
92 * cache entries should be examined to see what to do with them.
93 */
94 UINT8 arp_timer;
*** ERROR C129 IN LINE 94 OF ..\ARP.C: missing ';' before 'arp_timer'
95
96 /** \brief Process and analyze the received ARP packet
97 * \author
98 * \li Jari Lahti (jari.lahti@violasystems.com)
99 *
100 * \date 10.07.2002
101 * \param frame Pointer to ethernet_frame structure containing information
102 * about the received frame
103 * \return Return #TRUE if Ethernet frame processed held ARP packet,
104 * otherwise #FALSE.
105 *
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 3
106 * Invoke process_arp function whenever ARP packet is received
107 * (see main_demo.c for an example loop). This function will process the
108 * received packet, analyze it'c content briefly and perform on of the
109 * two possible actions:
110 * \li If the received packet is ARP request it will invoke
111 * arp_send_reply in order to send ARP reply back
112 * \li If the received packet is ARP response it will iterate through
113 * the cache table and try to find ARP entry that is beeing resolved
114 * or refreshed
115 */
116 UINT8 process_arp (struct ethernet_frame* frame) {
117
118 UINT8 temp;
119
120 /* Check if ARP packet*/
121
122 if( frame->protocol == ARP_ETHCODE ) {
123 /* Yep, ARP */
124
125 NETWORK_RECEIVE_INITIALIZE(frame->buf_index);
126
127 /* Is it long enough? */
128
129 if( frame->frame_size < (2*MAXHWALEN + 2*MAXPRALEN + 2 + 6) ) {
130 /* Somehow corrupted ARP packet */
131 ARP_DEBUGOUT("Corrupted ARP packet\n\r");
132 /*NETWORK_RECEIVE_END();*/
133 return(TRUE);
134 }
135
136
137 /* Ignore next 6 bytes: <HW type>, <Protocol type> */
138 /* <HW address len> and <Protocol address len> */
139
140 for(temp=0; temp<6; temp++)
141 RECEIVE_NETWORK_B();
142
143 ARP_DEBUGOUT("Incoming ARP..\n\r");
144
145 /* Check if request or response */
146
147 if( RECEIVE_NETWORK_B() == 0x00) {
148
149 temp = RECEIVE_NETWORK_B(); /* get opcode */
150
151 if( temp == ARP_REQUEST ) {
152 ARP_DEBUGOUT(" ARP REQUEST Received..\n\r");
153 arp_send_response();
154 } else if( temp == ARP_REPLY ) {
155 ARP_DEBUGOUT("ARP Response Received..\n\r");
156 arp_get_response();
157 }
158
159 /* Wasn't request or response or all done, dump it */
160
161 }
162
163 /*NETWORK_RECEIVE_END();*/
164 return(TRUE);
165
166 }
167
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 4
168 /* Wasn't ARP, don't touch the packet */
169
170 return(FALSE);
171 }
172
173 /** \brief Send response to an ARP request
174 * \author
175 * \li Jari Lahti (jari.lahti@violasystems.com)
176 * \date 10.07.2002
177 * \warning
178 * \li This function starts reading data from Ethernet controller
179 * without initializing it for reading it first, so NIC must already
180 * be initialized for reading from correct address (it expects ar$sha
181 * field from ARP packet immediately)
182 *
183 * This function is invoked from process_arp() function in order to send
184 * a reply to an ARP request. First, incoming packet is checked to see
185 * if it is intended for us or not. If not, function does not do anything.
186 * Otherwise, ARP reply packet is formed and sent.
187 */
188 void arp_send_response(void)
189 {
190 struct arp_entry *qstruct;
191 UINT8 rem_hwadr[MAXHWALEN];
192 UINT32 rem_ip;
193 UINT32 ltemp;
194 INT8 i;
195 BYTE j;
196
197 /* Record Sender's HW address */
198
199 for( i=MAXHWALEN-1; i >= 0; i-- )
200 rem_hwadr[i] = RECEIVE_NETWORK_B();
201
202 /* Read Sender's IP Address */
203
204 for( i=0; i<MAXPRALEN; i++) {
205 rem_ip <<= 8;
206 rem_ip |= RECEIVE_NETWORK_B();
207 }
208
209
210 /* Skip Target HW address */
211
212 RECEIVE_NETWORK_B();
213 RECEIVE_NETWORK_B();
214 RECEIVE_NETWORK_B();
215 RECEIVE_NETWORK_B();
216 RECEIVE_NETWORK_B();
217 RECEIVE_NETWORK_B();
218
219 /* Is The Packet For Us? */
220
221 for( i=0; i<MAXPRALEN; i++) {
222 ltemp <<= 8;
223 ltemp |= RECEIVE_NETWORK_B();
224 }
225
226
227 if( ltemp != localmachine.localip )
228 return; /* No */
229
C51 COMPILER V7.06 ARP 11/26/2004 11:32:44 PAGE 5
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -