Aktuální adresář: FITkit /
trunk /
mcu /
libs /
enc28j60 /
enc28j60_dhcp.h
1 /*******************************************************************************
2 enc28j60_dhcp.h: Implementace protokolu DHCP.
3 Copyright (C) 2010 Brno University of Technology,
4 Faculty of Information Technology
5 Author(s): Martin Musil <xmusil34 AT fit.vutbr.cz>
6
7 LICENSE TERMS
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12 1. Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in
16 the documentation and/or other materials provided with the
17 distribution.
18 3. All advertising materials mentioning features or use of this software
19 or firmware must display the following acknowledgement:
20
21 This product includes software developed by the University of
22 Technology, Faculty of Information Technology, Brno and its
23 contributors.
24
25 4. Neither the name of the Company nor the names of its contributors
26 may be used to endorse or promote products derived from this
27 software without specific prior written permission.
28
29 This software or firmware is provided ``as is'', and any express or implied
30 warranties, including, but not limited to, the implied warranties of
31 merchantability and fitness for a particular purpose are disclaimed.
32 In no event shall the company or contributors be liable for any
33 direct, indirect, incidental, special, exemplary, or consequential
34 damages (including, but not limited to, procurement of substitute
35 goods or services; loss of use, data, or profits; or business
36 interruption) however caused and on any theory of liability, whether
37 in contract, strict liability, or tort (including negligence or
38 otherwise) arising in any way out of the use of this software, even
39 if advised of the possibility of such damage.
40
41 $Id$
42
43 *******************************************************************************/
44
45 /**
46 \file enc28j60_dhcp.h
47 \brief Implementace protokolu DHCP.
48 */
49
50 #ifndef _ENC28J60_DHCP_
51 #define _ENC28J60_DHCP_
52
53 /**
54 \cond
55 **/
56
57
58
59
60 /**
61
62 \struct bootp_h
63 **/
64
65 struct bootp_h{
66
67 unsigned char hw_type; ///< typ HW adresy
68
69 unsigned char hop_count;
70 unsigned long transaction_id; ///< ID transakce
71 unsigned int seconds;
72 unsigned int flags;
73 unsigned long client_ip;
74
75 unsigned long server_ip;
76 unsigned long gateway_ip;
77 unsigned char client_hw_address[16]; ///< HW adresa klienta
78 };
79
80
81 #define BOOTP_REQUEST 1
82 #define BOOTP_REPLY 2
83
84 #define BOOTP_HW_ETH 1
85
86 #define BOOTP_FLAG_BROADCAST 0x8000
87
88 //DHCP porty
89 #define DHCP_CLIENT_PORT 68
90 #define DHCP_SERVER_PORT 67
91
92 #define MAGIC_LEN 4
93 #define MAGIC_COOKIE 0x63538263
94
95 //parametry DHCP
96 #define DHCP_PAD 0
97 #define DHCP_SUBNET_MASK 1
98 #define DHCP_ROUTER 3
99 #define DHCP_DNS_SERVER 6
100 #define DHCP_REQUESTED_IP 50
101 #define DHCP_MESSAGE_TYPE 53
102 #define DHCP_SERVER_ID 54
103 #define DHCP_END 255
104
105 //DHCP typy zprav
106 #define DHCP_DISCOVER 1
107 #define DHCP_OFFER 2
108 #define DHCP_REQUEST 3
109 #define DHCP_DECLINE 4
110 #define DHCP_ACK 5
111 #define DHCP_NACK 6
112 #define DHCP_RELEASE 7
113
114 #define DHCP_START 0
115
116
117 /**
118 \endcond
119 **/
120
121 /**
122 \brief Inicializace DHCP klienta.
123
124
125 **/
126 char dhcp_init();
127
128 /**
129 \brief Restart DHCP klienta.
130
131
132 **/
133 char dhcp_reset();
134
135 /**
136
137
138 **/
139 void dhcp_timer();
140
141 /**
142
143
144
145 **/
146 char dhcp_ready();
147
148 #define TIMERA_ISR_INIT() /* inicializace casovace, 500ms */ \
149 { CCTL0 = CCIE; /* povoleni preruseni pro casovac, rezim vystupni komparace */ \
150 CCR0 = 0x4000; /* 16384 = 0x4000; preruseni kazdych 500ms */ \
151 TACTL = TASSEL_1 + MC_2; } /* ACLK (f_tiku = 32768 Hz = 0x8000 Hz), nepretrzity rezim */ \
152
153 #define TIMERA_ISR_DHCP() \
154 interrupt (TIMERA0_VECTOR) Timer_A (void) { \
155 dhcp_timer(); /*dhcp casovac*/ \
156 CCR0 += 0x4000; /*preruseni kazdych 500ms*/ \
157 }
158
159 #define TIMERA_ISR_DHCP_TCP() \
160 interrupt (TIMERA0_VECTOR) Timer_A (void) { \
161 dhcp_timer(); /*dhcp casovac*/ \
162 tcp_timer(); /*tcp casovac*/ \
163 CCR0 += 0x4000; /*preruseni kazdych 500ms*/ \
164 }
165
166 #endif /*_ENC28J60_DHCP_*/
167