FITkit
Fakulta informačních technologií

enc28j60_dhcp.h

Zobrazit dokumentaci tohoto souboru.
00001 /*******************************************************************************
00002    enc28j60_dhcp.h: Implementace protokolu DHCP.
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_DHCP_
00051 #define _ENC28J60_DHCP_
00052 
00057 #define BOOTP_HEADER_LEN 44                     
00058 #define BOOTP_HEADER_LEN_TOTAL 236      
00059  
00060 
00065 struct bootp_h{
00066         unsigned char opcode;                                   
00067         unsigned char hw_type;                                  
00068         unsigned char hw_address_length;                
00069         unsigned char hop_count;
00070         unsigned long transaction_id;                   
00071         unsigned int seconds;
00072         unsigned int flags;
00073         unsigned long client_ip;
00074         unsigned long your_ip;                                  
00075         unsigned long server_ip;
00076         unsigned long gateway_ip;
00077         unsigned char client_hw_address[16];    
00078 };
00079 
00080 
00081 #define BOOTP_REQUEST 1
00082 #define BOOTP_REPLY 2
00083 
00084 #define BOOTP_HW_ETH 1
00085 
00086 #define BOOTP_FLAG_BROADCAST 0x8000
00087 
00088 //DHCP porty
00089 #define DHCP_CLIENT_PORT 68
00090 #define DHCP_SERVER_PORT 67
00091 
00092 #define MAGIC_LEN 4
00093 #define MAGIC_COOKIE 0x63538263
00094 
00095 //parametry DHCP
00096 #define DHCP_PAD 0
00097 #define DHCP_SUBNET_MASK 1
00098 #define DHCP_ROUTER 3
00099 #define DHCP_DNS_SERVER 6
00100 #define DHCP_REQUESTED_IP 50
00101 #define DHCP_MESSAGE_TYPE 53
00102 #define DHCP_SERVER_ID 54
00103 #define DHCP_END 255
00104 
00105 //DHCP typy zprav
00106 #define DHCP_DISCOVER 1
00107 #define DHCP_OFFER 2
00108 #define DHCP_REQUEST 3
00109 #define DHCP_DECLINE 4
00110 #define DHCP_ACK 5
00111 #define DHCP_NACK 6
00112 #define DHCP_RELEASE 7
00113 
00114 #define DHCP_START 0
00115 
00116 #define DHCP_TIMEOUT    30                      
00117 
00126 char dhcp_init();
00127 
00133 char dhcp_reset();
00134 
00139 void dhcp_timer();
00140 
00146 char dhcp_ready();
00147 
00148 #define TIMERA_ISR_INIT() /* inicializace casovace, 500ms */ \
00149    { CCTL0 = CCIE;      /* povoleni preruseni pro casovac, rezim vystupni komparace      */ \
00150           CCR0 = 0x4000;           /* 16384 = 0x4000; preruseni kazdych 500ms */ \
00151           TACTL = TASSEL_1 + MC_2; } /* ACLK (f_tiku = 32768 Hz = 0x8000 Hz), nepretrzity rezim */ \
00152 
00153 #define TIMERA_ISR_DHCP() \
00154   interrupt (TIMERA0_VECTOR) Timer_A (void) { \
00155      dhcp_timer();              /*dhcp casovac*/ \
00156           CCR0 += 0x4000;         /*preruseni kazdych 500ms*/ \
00157   }
00158 
00159 #define TIMERA_ISR_DHCP_TCP() \
00160   interrupt (TIMERA0_VECTOR) Timer_A (void) { \
00161      dhcp_timer();        /*dhcp casovac*/ \
00162      tcp_timer();                 /*tcp casovac*/ \
00163           CCR0 += 0x4000;         /*preruseni kazdych 500ms*/ \
00164   }
00165 
00166 #endif /*_ENC28J60_DHCP_*/