/[H8]/trunk/docs/MCHPStack2.20/Source/ARPTsk.c
ViewVC logotype

Annotation of /trunk/docs/MCHPStack2.20/Source/ARPTsk.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (hide annotations) (download)
Tue May 1 08:17:39 2007 UTC (17 years, 1 month ago) by hedin
File MIME type: text/plain
File size: 6418 byte(s)
Removed tcpip stack 4.02 and added tcpip stack 2.20.
1 hedin 62 /*********************************************************************
2     *
3     * ARP Server Module for Microchip TCP/IP Stack
4     *
5     *********************************************************************
6     * FileName: ARPTsk.c
7     * Dependencies: compiler.h
8     * string.h
9     * ARP.h
10     * ARPTsk.h
11     * Processor: PIC18
12     * Complier: MCC18 v1.00.50 or higher
13     * HITECH PICC-18 V8.10PL1 or higher
14     * Company: Microchip Technology, Inc.
15     *
16     * Software License Agreement
17     *
18     * The software supplied herewith by Microchip Technology Incorporated
19     * (the “Company”) for its PICmicro® Microcontroller is intended and
20     * supplied to you, the Company’s customer, for use solely and
21     * exclusively on Microchip PICmicro Microcontroller products. The
22     * software is owned by the Company and/or its supplier, and is
23     * protected under applicable copyright laws. All rights are reserved.
24     * Any use in violation of the foregoing restrictions may subject the
25     * user to criminal sanctions under applicable laws, as well as to
26     * civil liability for the breach of the terms and conditions of this
27     * license.
28     *
29     * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
30     * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
31     * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
32     * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
33     * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
34     * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
35     *
36     * HiTech PICC18 Compiler Options excluding device selection:
37     * -FAKELOCAL -G -Zg -E -C
38     *
39     *
40     * Author Date Comment
41     *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42     * Nilesh Rajbharti 8/20/01 Original (Rev 1.0)
43     * Nilesh Rajbharti 2/9/02 Cleanup
44     * Nilesh Rajbharti 5/22/02 Rev 2.0 (See version.log for detail)
45     ********************************************************************/
46    
47     #include "compiler.h"
48     #include <string.h>
49    
50     #include "arp.h"
51     #include "arptsk.h"
52    
53     /*
54     * ARP Task FSM States
55     */
56     typedef enum _ARP_STATE
57     {
58     SM_ARP_IDLE,
59     SM_ARP_REPLY
60     } ARP_STATE;
61    
62    
63     /*
64     * This ARP task caches one ARP response.
65     */
66     static ARP_STATE smARP;
67    
68     #ifdef STACK_CLIENT_MODE
69     static NODE_INFO Cache;
70     #endif
71    
72    
73     /*********************************************************************
74     * Function: void ARPInit(void)
75     *
76     * PreCondition: None
77     *
78     * Input: None
79     *
80     * Output: ARP Cache is initialized.
81     *
82     * Side Effects: None
83     *
84     * Overview: None
85     *
86     * Note: None
87     ********************************************************************/
88     void ARPInit(void)
89     {
90     smARP = SM_ARP_IDLE;
91    
92     #ifdef STACK_CLIENT_MODE
93     Cache.MACAddr.v[0] = 0xff;
94     Cache.MACAddr.v[1] = 0xff;
95     Cache.MACAddr.v[2] = 0xff;
96     Cache.MACAddr.v[3] = 0xff;
97     Cache.MACAddr.v[4] = 0xff;
98     Cache.MACAddr.v[5] = 0xff;
99    
100     Cache.IPAddr.Val = 0x0;
101     #endif
102     }
103    
104    
105    
106     /*********************************************************************
107     * Function: BOOL ARPProcess(void)
108     *
109     * PreCondition: ARP packet is ready in MAC buffer.
110     *
111     * Input: None
112     *
113     * Output: ARP FSM is executed.
114     *
115     * Side Effects: None
116     *
117     * Overview: None
118     *
119     * Note: None
120     ********************************************************************/
121     BOOL ARPProcess(void)
122     {
123     NODE_INFO remoteNode;
124     BYTE opCode;
125    
126     switch(smARP)
127     {
128     case SM_ARP_IDLE:
129     if ( !ARPGet(&remoteNode, &opCode) )
130     break;
131    
132     if ( opCode == ARP_REPLY )
133     {
134     #ifdef STACK_CLIENT_MODE
135     Cache.MACAddr.v[0] = remoteNode.MACAddr.v[0];
136     Cache.MACAddr.v[1] = remoteNode.MACAddr.v[1];
137     Cache.MACAddr.v[2] = remoteNode.MACAddr.v[2];
138     Cache.MACAddr.v[3] = remoteNode.MACAddr.v[3];
139     Cache.MACAddr.v[4] = remoteNode.MACAddr.v[4];
140     Cache.MACAddr.v[5] = remoteNode.MACAddr.v[5];
141    
142     Cache.IPAddr.Val = remoteNode.IPAddr.Val;
143     #endif
144     break;
145     }
146     else
147     smARP = SM_ARP_REPLY;
148    
149     default:
150     if ( ARPIsTxReady() )
151     {
152     ARPPut(&remoteNode, ARP_REPLY);
153     smARP = SM_ARP_IDLE;
154     }
155     else
156     return FALSE;
157     break;
158     }
159     return TRUE;
160     }
161    
162    
163     /*********************************************************************
164     * Function: void ARPResolve(IP_ADDR* IPAddr)
165     *
166     * PreCondition: None
167     *
168     * Input: IPAddr - IP Address to be resolved.
169     *
170     * Output: None
171     *
172     * Side Effects: None
173     *
174     * Overview: An ARP request is sent.
175     *
176     * Note: This function is available only when
177     * STACK_CLIENT_MODE is defined.
178     ********************************************************************/
179     #ifdef STACK_CLIENT_MODE
180     void ARPResolve(IP_ADDR *IPAddr)
181     {
182     NODE_INFO remoteNode;
183    
184     remoteNode.IPAddr = *IPAddr;
185    
186     ARPPut(&remoteNode, ARP_REQUEST);
187     }
188     #endif
189    
190    
191    
192     /*********************************************************************
193     * Function: BOOL ARPIsResolved(IP_ADDR* IPAddr,
194     * MAC_ADDR *MACAddr)
195     *
196     * PreCondition: None
197     *
198     * Input: IPAddr - IPAddress to be resolved.
199     * MACAddr - Buffer to hold corresponding
200     * MAC Address.
201     *
202     * Output: TRUE if given IP Address has been resolved.
203     * FALSE otherwise.
204     *
205     * Side Effects: None
206     *
207     * Overview: None
208     *
209     * Note: This function is available only when
210     * STACK_CLIENT_MODE is defined.
211     ********************************************************************/
212     #ifdef STACK_CLIENT_MODE
213     BOOL ARPIsResolved(IP_ADDR *IPAddr, MAC_ADDR *MACAddr)
214     {
215     if ( (Cache.IPAddr.Val == IPAddr->Val) ||
216     (Cache.IPAddr.v[0] == MY_GATE_BYTE1 &&
217     Cache.IPAddr.v[1] == MY_GATE_BYTE2 &&
218     Cache.IPAddr.v[2] == MY_GATE_BYTE3 &&
219     Cache.IPAddr.v[3] == MY_GATE_BYTE4) )
220     {
221     *MACAddr = Cache.MACAddr;
222     return TRUE;
223     }
224     return FALSE;
225     }
226     #endif
227    

  ViewVC Help
Powered by ViewVC 1.1.20