00001 00002 00028 /********************************************************************* 00029 * Software License Agreement 00030 * 00031 * Copyright (C) 2002-2008 Microchip Technology Inc. All rights 00032 * reserved. 00033 * 00034 * Microchip licenses to you the right to use, modify, copy, and 00035 * distribute: 00036 * (i) the Software when embedded on a Microchip microcontroller or 00037 * digital signal controller product ("Device") which is 00038 * integrated into Licensee's product; or 00039 * (ii) ONLY the Software driver source files ENC28J60.c and 00040 * ENC28J60.h ported to a non-Microchip device used in 00041 * conjunction with a Microchip ethernet controller for the 00042 * sole purpose of interfacing with the ethernet controller. 00043 * 00044 * You should refer to the license agreement accompanying this 00045 * Software for additional information regarding your rights and 00046 * obligations. 00047 * 00048 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT 00049 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT 00050 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A 00051 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL 00052 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 00053 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF 00054 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS 00055 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE 00056 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER 00057 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT 00058 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. 00059 * 00060 * 00061 * Author Date Comment 00062 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00063 * Nilesh Rajbharti 4/27/01 Original (Rev 1.0) 00064 * Nilesh Rajbharti 2/9/02 Cleanup 00065 * Nilesh Rajbharti 5/22/02 Rev 2.0 (See version.log for detail) 00066 ********************************************************************/ 00067 #ifndef __IP_H 00068 #define __IP_H 00069 00070 00071 #define IP_PROT_ICMP (1u) 00072 #define IP_PROT_TCP (6u) 00073 #define IP_PROT_UDP (17u) 00074 00075 00076 // IP packet header definition 00077 typedef struct _IP_HEADER 00078 { 00079 BYTE VersionIHL; 00080 BYTE TypeOfService; 00081 WORD TotalLength; 00082 WORD Identification; 00083 WORD FragmentInfo; 00084 BYTE TimeToLive; 00085 BYTE Protocol; 00086 WORD HeaderChecksum; 00087 IP_ADDR SourceAddress; 00088 IP_ADDR DestAddress; 00089 } IP_HEADER; 00090 00091 // IP Pseudo header as defined by RFC 793 (needed for TCP and UDP 00092 // checksum calculations/verification) 00093 typedef struct _PSEUDO_HEADER 00094 { 00095 IP_ADDR SourceAddress; 00096 IP_ADDR DestAddress; 00097 BYTE Zero; 00098 BYTE Protocol; 00099 WORD Length; 00100 } PSEUDO_HEADER; 00101 00102 #define SwapPseudoHeader(h) (h.Length = swaps(h.Length)) 00103 00104 00105 /********************************************************************* 00106 * Function: BOOL IPIsTxReady(BOOL HighPriority) 00107 * 00108 * PreCondition: None 00109 * 00110 * Input: None 00111 * 00112 * Output: TRUE if transmit buffer is empty 00113 * FALSE if transmit buffer is not empty 00114 * 00115 * Side Effects: None 00116 * 00117 * Note: None 00118 * 00119 ********************************************************************/ 00120 #define IPIsTxReady() MACIsTxReady() 00121 00122 00123 /********************************************************************* 00124 * Macro: IPSetTxBuffer(a, b) 00125 * 00126 * PreCondition: None 00127 * 00128 * Input: a - Buffer identifier 00129 * b - Offset 00130 * 00131 * Output: Next Read/Write access to transmit buffer 'a' 00132 * set to offset 'b' 00133 * 00134 * Side Effects: None 00135 * 00136 * Note: None 00137 * 00138 ********************************************************************/ 00139 #define IPSetTxBuffer(b) MACSetWritePtr(b + BASE_TX_ADDR + sizeof(ETHER_HEADER) + sizeof(IP_HEADER)) 00140 00141 00142 00143 /********************************************************************* 00144 * Function: WORD IPPutHeader( IP_ADDR *Dest, 00145 * BYTE Protocol, 00146 * WORD Identifier, 00147 * WORD DataLen) 00148 * 00149 * PreCondition: IPIsTxReady() == TRUE 00150 * 00151 * Input: Src - Destination node address 00152 * Protocol - Current packet protocol 00153 * Identifier - Current packet identifier 00154 * DataLen - Current packet data length 00155 * 00156 * Output: Handle to current packet - For use by 00157 * IPSendByte() function. 00158 * 00159 * Side Effects: None 00160 * 00161 * Note: Only one IP message can be transmitted at any 00162 * time. 00163 * Caller may not transmit and receive a message 00164 * at the same time. 00165 * 00166 ********************************************************************/ 00167 WORD IPPutHeader(NODE_INFO *remote, 00168 BYTE protocol, 00169 WORD len); 00170 00171 00172 /********************************************************************* 00173 * Function: BOOL IPGetHeader( IP_ADDR *localIP, 00174 * NODE_INFO *remote, 00175 * BYTE *Protocol, 00176 * WORD *len) 00177 * 00178 * PreCondition: MACGetHeader() == TRUE 00179 * 00180 * Input: localIP - Local node IP Address as received 00181 * in current IP header. 00182 * If this information is not required 00183 * caller may pass NULL value. 00184 * remote - Remote node info 00185 * Protocol - Current packet protocol 00186 * len - Current packet data length 00187 * 00188 * Output: TRUE, if valid packet was received 00189 * FALSE otherwise 00190 * 00191 * Side Effects: None 00192 * 00193 * Note: Only one IP message can be received. 00194 * Caller may not transmit and receive a message 00195 * at the same time. 00196 * 00197 ********************************************************************/ 00198 BOOL IPGetHeader(IP_ADDR *localIP, 00199 NODE_INFO *remote, 00200 BYTE *protocol, 00201 WORD *len); 00202 00203 00204 /********************************************************************* 00205 * Macro: IPDiscard() 00206 * 00207 * PreCondition: MACGetHeader() == TRUE 00208 * 00209 * Input: None 00210 * 00211 * Output: Current packet is discarded and buffer is 00212 * freed-up 00213 * 00214 * Side Effects: None 00215 * 00216 * Note: None 00217 * 00218 ********************************************************************/ 00219 #define IPDiscard() MACDiscard() 00220 00221 00222 00223 /********************************************************************* 00224 * Macro: IPGetArray(a, b) 00225 * 00226 * PreCondition: MACGetHeader() == TRUE 00227 * 00228 * Input: a - Data buffer 00229 * b - Buffer length 00230 * 00231 * Output: None 00232 * 00233 * Side Effects: None 00234 * 00235 * Note: Data is copied from IP data to given buffer 00236 * 00237 ********************************************************************/ 00238 #define IPGetArray(a, b) MACGetArray(a, b) 00239 00240 00241 00242 00243 /********************************************************************* 00244 * Function: IPSetRxBuffer(WORD Offset) 00245 * 00246 * PreCondition: IPHeaderLen must have been intialized by 00247 * IPGetHeader() or IPPutHeader() 00248 * 00249 * Input: Offset from beginning of IP data field 00250 * 00251 * Output: Next Read/Write access to receive buffer is 00252 * set to Offset 00253 * 00254 * Side Effects: None 00255 * 00256 * Note: None 00257 * 00258 ********************************************************************/ 00259 void IPSetRxBuffer(WORD Offset); 00260 00261 00262 00263 // MODIFIX: Added this both functions. 00265 00284 DWORD IPConvertSubnetToMask(BYTE Subnet); 00285 00286 00288 00308 BYTE IPConvertMaskToSubnet(BYTE * MaskArray); 00309 00310 #endif 00311 00312 00313
1.5.5