FITkit
Fakulta informačních technologií

enc28j60_ip.h

Zobrazit dokumentaci tohoto souboru.
00001 /*******************************************************************************
00002    enc28j60_ip.h: Sitova vrstva modelu TCP/IP
00003    Copyright (C) 2010 Brno University of Technology,
00004                       Faculty of Information Technology
00005    Author(s): Martin Musil <xmusil34 AT fit.vutbr.cz>
00006 
00007    LICENSE TERMS
00008 
00009    Redistribution and use in source and binary forms, with or without
00010    modification, are permitted provided that the following conditions
00011    are met:
00012    1. Redistributions of source code must retain the above copyright
00013       notice, this list of conditions and the following disclaimer.
00014    2. Redistributions in binary form must reproduce the above copyright
00015       notice, this list of conditions and the following disclaimer in
00016       the documentation and/or other materials provided with the
00017       distribution.
00018    3. All advertising materials mentioning features or use of this software
00019       or firmware must display the following acknowledgement:
00020 
00021         This product includes software developed by the University of
00022         Technology, Faculty of Information Technology, Brno and its
00023         contributors.
00024 
00025    4. Neither the name of the Company nor the names of its contributors
00026       may be used to endorse or promote products derived from this
00027       software without specific prior written permission.
00028 
00029    This software or firmware is provided ``as is'', and any express or implied
00030    warranties, including, but not limited to, the implied warranties of
00031    merchantability and fitness for a particular purpose are disclaimed.
00032    In no event shall the company or contributors be liable for any
00033    direct, indirect, incidental, special, exemplary, or consequential
00034    damages (including, but not limited to, procurement of substitute
00035    goods or services; loss of use, data, or profits; or business
00036    interruption) however caused and on any theory of liability, whether
00037    in contract, strict liability, or tort (including negligence or
00038    otherwise) arising in any way out of the use of this software, even
00039    if advised of the possibility of such damage.
00040 
00041    $Id$
00042 
00043 *******************************************************************************/ 
00044 
00050 #ifndef _ENC28J60_IP_
00051 #define _ENC28J60_IP_
00052 
00053 
00054 //****************************
00055 //prevody
00056 //****************************
00058 #define HTONS(x) ((((x)&0xff)<<8) | ((x)>>8))
00060 #define HTONL(x) ((((x)&0xff)<<24) | (((x)&0x00ff0000l)>>8) | (((x)&0x0000ff00l)<<8) | ((x)>>24))
00061 
00062 #define NTOHS HTONS     
00063 #define NTOHL HTONL     
00064 
00065 
00068 #define CHAR2IP(x0,x1,x2,x3) ( ((unsigned long)x0<<24)|((unsigned long)x1<<16)|((unsigned int)x2<<8)|x3)
00069 
00074 #define IP_LEN 4                        
00075 #define DEFAULT_TTL 128         
00076 #define MIN_IP_LEN 60 - ETH_HEADER_LEN  
00077 
00078 #define IPv4 4                          
00079  
00080 #define IP_FRAG_OFFSET   0x1fff
00081 #define IP_FRAG_MORE     0x2000
00082 #define IP_FRAG_DONT     0x4000
00083 #define IP_FRAG_RESERVED 0x8000
00084 
00085 #define IP_BROADCAST 0xFFFFFFFFL                
00086 
00087 
00088 #define IP_PROTO_ICMP 1                                 
00089 #define IP_PROTO_TCP  6                                 
00090 #define IP_PROTO_UDP 17                                 
00091 
00092 #define ARP_TIMEOUT 12000                               
00093 
00094 
00103 struct ip_h{
00104         unsigned char header_len:4;             
00105         unsigned char ipv:4;                    
00106         unsigned char tos;                              
00107         unsigned int length;                    
00108         unsigned int identification;    
00109         unsigned int fragment;                  
00110         unsigned char ttl;                              
00111         unsigned char protocol;                 
00112         unsigned int checksum;                  
00113         unsigned long src_ip;                   
00114         unsigned long dest_ip;                  
00115 };
00116 
00121 /******************/
00122 
00126 void ip_recv(void);
00127 
00136 char ip_send(unsigned long dest_addr,unsigned char protocol);
00137 
00144 unsigned int count_checksum(void* pointer,int count);
00145 
00149 /******************/
00150 
00156 inline void set_ip(unsigned char a0,unsigned char a1,unsigned char a2, unsigned char a3);
00157 
00163 inline void set_ip_l(unsigned long ip);
00164 
00169 inline unsigned long get_ip();
00170 
00171 
00172 /******************/
00173 
00179 inline void set_netmask(unsigned char m0,unsigned char m1,unsigned char m2, unsigned char m3);
00180 
00186 inline void set_netmask_l(unsigned long netmask);
00187 
00192 inline unsigned long get_netmask();
00193 
00194 
00195 
00196 /******************/
00197 
00198 
00204 inline void set_gateway(unsigned char g0,unsigned char g1,unsigned char g2, unsigned char g3);
00205 
00211 inline void set_gateway_l(unsigned long gateway);
00212 
00217 inline unsigned long get_gateway();
00218 
00219 
00220 /******************/
00221 
00227 inline void set_dns_server(unsigned char d0,unsigned char d1,unsigned char d2, unsigned char d3);
00228 
00234 inline void set_dns_server_l(unsigned long dns);
00235 
00240 inline unsigned long get_dns_server();
00241 
00242 
00243 
00244 #endif /*_ENC28J60_IP_*/