annotate packages/redboot/current/src/net/bootp.c @ 2863:7d8c61e6225c default tip

* Added execute permissions to files missed in conversion from CVS
author alexs
date Thu, 26 Mar 2009 20:39:18 +0000
parents 74dbf4c3f2e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
1 //==========================================================================
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
2 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
3 // net/bootp.c
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
4 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
5 // Stand-alone minimal BOOTP support for RedBoot
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
6 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 184
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
16 // version.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 184
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
21 // for more details.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 184
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 184
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
33 // General Public License v2.
208
e0c0827131d1 Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents: 184
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2395
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
39 //==========================================================================
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
41 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
42 // Author(s): gthomas
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
43 // Contributors: gthomas
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
44 // Date: 2000-07-14
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
45 // Purpose:
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
46 // Description:
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
47 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
48 // This code is part of RedBoot (tm).
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
49 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
50 //####DESCRIPTIONEND####
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
51 //
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
52 //==========================================================================
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
53
184
022f1e506033 Merge from eCos master repository on 2001-10-02-17:59:22-BST
jlarmour
parents: 165
diff changeset
54 #include <redboot.h>
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
55 #include <net/net.h>
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
56 #include <net/bootp.h>
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
57
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
58 #define SHOULD_BE_RANDOM 0x12345555
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
59
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
60 /* How many milliseconds to wait before retrying the request */
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
61 #define RETRY_TIME 2000
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
62 #define MAX_RETRIES 8
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
63
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
64 static bootp_header_t *bp_info;
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
65
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
66 #ifdef CYGSEM_REDBOOT_NETWORKING_DHCP
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
67 static const unsigned char dhcpCookie[] = {99,130,83,99};
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
68 static const unsigned char dhcpEnd[] = {255};
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
69 static const unsigned char dhcpDiscover[] = {53,1,1};
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
70 static const unsigned char dhcpRequest[] = {53,1,3};
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
71 static const unsigned char dhcpRequestIP[] = {50,4};
1217
0e1c2770aa9d Add new options to DHCP request - from David Vrabel
gthomas
parents: 1122
diff changeset
72 static const unsigned char dhcpParamRequestList[] = {55,3,1,3,6};
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
73 static enum {
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
74 DHCP_NONE = 0,
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
75 DHCP_DISCOVER,
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
76 DHCP_OFFER,
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
77 DHCP_REQUEST,
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
78 DHCP_ACK
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
79 } dhcpState;
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
80 #endif
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
81
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
82 static void
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
83 bootp_handler(udp_socket_t *skt, char *buf, int len,
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
84 ip_route_t *src_route, word src_port)
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
85 {
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
86 bootp_header_t *b;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
87 #ifdef CYGSEM_REDBOOT_NETWORKING_DHCP
1412
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
88 unsigned char *p, expected = 0;
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
89 #endif
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
90
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
91 b = (bootp_header_t *)buf;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
92 if (bp_info) {
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
93 memset(bp_info,0,sizeof *bp_info);
156
b939e9cada46 Merge from eCos master repository on 2001-03-29-21:44:39-BST
jlarmour
parents: 151
diff changeset
94 if (len > sizeof *bp_info)
b939e9cada46 Merge from eCos master repository on 2001-03-29-21:44:39-BST
jlarmour
parents: 151
diff changeset
95 len = sizeof *bp_info;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
96 memcpy(bp_info, b, len);
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
97 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
98
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
99 // Only accept pure REPLY responses
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
100 if (b->bp_op != BOOTREPLY)
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
101 return;
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
102
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
103 // Must be sent to me, as well!
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
104 if (memcmp(b->bp_chaddr, __local_enet_addr, 6))
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
105 return;
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
106
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
107 #ifdef CYGSEM_REDBOOT_NETWORKING_DHCP
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
108 p = b->bp_vend;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
109 if (memcmp(p, dhcpCookie, sizeof(dhcpCookie)))
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
110 return;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
111 p += 4;
1412
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
112
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
113 // Find the DHCP Message Type tag
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
114 while (*p != TAG_DHCP_MESS_TYPE) {
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
115 p += p[1] + 2;
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
116 if (p >= (unsigned char*)b + sizeof(*bp_info))
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
117 return;
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
118 }
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
119
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
120 p += 2;
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
121
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
122 switch (dhcpState) {
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
123 case DHCP_DISCOVER:
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
124 // The discover message has been sent, only accept an offer reply
1412
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
125 if (*p == DHCP_MESS_TYPE_OFFER) {
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
126 dhcpState = DHCP_OFFER;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
127 return;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
128 } else {
1412
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
129 expected = DHCP_MESS_TYPE_OFFER;
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
130 }
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
131 break;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
132 case DHCP_REQUEST:
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
133 // The request message has been sent, only accept an ack reply
1412
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
134 if (*p == DHCP_MESS_TYPE_ACK) {
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
135 dhcpState = DHCP_ACK;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
136 return;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
137 } else {
1412
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
138 expected = DHCP_MESS_TYPE_ACK;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
139 }
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
140 break;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
141 case DHCP_NONE:
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
142 case DHCP_OFFER:
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
143 case DHCP_ACK:
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
144 // Quitely ignore these - they indicate repeated message from server
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
145 return;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
146 }
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
147 // See if we've been NAK'd - if so, give up and try again
1412
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
148 if (*p == DHCP_MESS_TYPE_NAK) {
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
149 dhcpState = DHCP_NONE;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
150 return;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
151 }
1412
7423c71e5c19 Improve scanning for DHCP options - from David Vrabel
gthomas
parents: 1396
diff changeset
152 diag_printf("DHCP reply: %d, not %d\n", (int)*p, (int)expected);
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
153 return;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
154 #else
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
155 // Simple BOOTP - this is all there is!
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
156 memcpy(__local_ip_addr, &b->bp_yiaddr, 4);
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
157 #endif
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
158 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
159
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
160 #define AddOption(p,d) do {memcpy(p,d,sizeof d); p += sizeof d;} while (0)
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
161
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
162 /*
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
163 * Find our IP address and copy to __local_ip_addr.
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
164 * Return zero if successful, -1 if not.
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
165 */
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
166 int
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
167 __bootp_find_local_ip(bootp_header_t *info)
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
168 {
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
169 udp_socket_t udp_skt;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
170 bootp_header_t b;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
171 ip_route_t r;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
172 int retry;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
173 unsigned long start;
165
d63db767121d Merge from eCos master repository on 2001-06-29-06:43:03-BST
jlarmour
parents: 156
diff changeset
174 ip_addr_t saved_ip_addr;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
175 #ifdef CYGSEM_REDBOOT_NETWORKING_DHCP
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
176 unsigned char *p;
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
177 int oldState;
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
178 #endif
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
179 int txSize;
1122
92e31da869cc Add ^C abort functionality to BOOTP and PING operations.
gthomas
parents: 1117
diff changeset
180 bool abort = false;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
181 static int xid = SHOULD_BE_RANDOM;
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
182
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
183 #ifdef CYGSEM_REDBOOT_NETWORKING_DHCP
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
184 dhcpState = DHCP_NONE;
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
185 #endif
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
186
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
187 // Where we want the results saved
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
188 bp_info = info;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
189 // Preserve any IP address we currently have, just in case
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
190 memcpy(saved_ip_addr, __local_ip_addr, sizeof(__local_ip_addr));
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
191
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
192 // fill out route for a broadcast
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
193 r.ip_addr[0] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
194 r.ip_addr[1] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
195 r.ip_addr[2] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
196 r.ip_addr[3] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
197 r.enet_addr[0] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
198 r.enet_addr[1] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
199 r.enet_addr[2] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
200 r.enet_addr[3] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
201 r.enet_addr[4] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
202 r.enet_addr[5] = 255;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
203
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
204 // setup a socket listener for bootp replies
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
205 __udp_install_listener(&udp_skt, IPPORT_BOOTPC, bootp_handler);
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
206
1122
92e31da869cc Add ^C abort functionality to BOOTP and PING operations.
gthomas
parents: 1117
diff changeset
207 retry = MAX_RETRIES;
1886
5f0c796f46a6 Make BOOTP/DHCP quieter - from David Vrable
gthomas
parents: 1412
diff changeset
208 do {
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
209 start = MS_TICKS();
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
210
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
211 // Build up the BOOTP/DHCP request
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
212 memset(&b, 0, sizeof(b));
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
213 b.bp_op = BOOTREQUEST;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
214 b.bp_htype = HTYPE_ETHERNET;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
215 b.bp_hlen = 6;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
216 b.bp_xid = xid++;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
217 memcpy(b.bp_chaddr, __local_enet_addr, 6);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
218 memset(__local_ip_addr, 0, sizeof(__local_ip_addr));
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
219
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
220 #ifdef CYGSEM_REDBOOT_NETWORKING_DHCP
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
221 p = b.bp_vend;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
222 switch (dhcpState) {
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
223 case DHCP_NONE:
1242
bc69956ed7c9 Handle DHCP retries
gthomas
parents: 1227
diff changeset
224 case DHCP_DISCOVER:
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
225 AddOption(p,dhcpCookie);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
226 AddOption(p,dhcpDiscover);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
227 AddOption(p,dhcpParamRequestList);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
228 AddOption(p,dhcpEnd);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
229 dhcpState = DHCP_DISCOVER;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
230 break;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
231 case DHCP_OFFER:
1243
4f0c5ba87a3a Fix more DHCP buglets
gthomas
parents: 1242
diff changeset
232 retry = MAX_RETRIES;
1242
bc69956ed7c9 Handle DHCP retries
gthomas
parents: 1227
diff changeset
233 case DHCP_REQUEST:
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
234 b.bp_xid = bp_info->bp_xid; // Match what server sent
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
235 AddOption(p,dhcpCookie);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
236 AddOption(p,dhcpRequest);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
237 AddOption(p,dhcpRequestIP);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
238 memcpy(p, &bp_info->bp_yiaddr, 4); p += 4; // Ask for the address just given
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
239 AddOption(p,dhcpParamRequestList);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
240 AddOption(p,dhcpEnd);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
241 dhcpState = DHCP_REQUEST;
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
242 memset(&b.bp_yiaddr, 0xFF, 4);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
243 memset(&b.bp_siaddr, 0xFF, 4);
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
244 memset(&b.bp_yiaddr, 0x00, 4);
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
245 memset(&b.bp_siaddr, 0x00, 4);
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
246 break;
1246
55fbbf4dffb2 Clean up warnings
gthomas
parents: 1245
diff changeset
247 case DHCP_ACK:
55fbbf4dffb2 Clean up warnings
gthomas
parents: 1245
diff changeset
248 // Ignore these states (they won't happen)
55fbbf4dffb2 Clean up warnings
gthomas
parents: 1245
diff changeset
249 break;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
250 }
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
251
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
252 // Some servers insist on a minimum amount of "vendor" data
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
253 if (p < &b.bp_vend[BP_MIN_VEND_SIZE]) p = &b.bp_vend[BP_MIN_VEND_SIZE];
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
254 txSize = p - (unsigned char*)&b;
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
255 oldState = dhcpState;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
256 #else
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
257 txSize = sizeof(b);
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
258 #endif
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
259
231
4ebdd3788c30 Merge gateway support from Grant Edwards
gthomas
parents: 210
diff changeset
260 __udp_send((char *)&b, txSize, &r, IPPORT_BOOTPS, IPPORT_BOOTPC);
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
261
1886
5f0c796f46a6 Make BOOTP/DHCP quieter - from David Vrable
gthomas
parents: 1412
diff changeset
262 // If we're retrying, inform the user
5f0c796f46a6 Make BOOTP/DHCP quieter - from David Vrable
gthomas
parents: 1412
diff changeset
263 if (retry == (MAX_RETRIES-1))
5f0c796f46a6 Make BOOTP/DHCP quieter - from David Vrable
gthomas
parents: 1412
diff changeset
264 diag_printf("... waiting for BOOTP information\n");
5f0c796f46a6 Make BOOTP/DHCP quieter - from David Vrable
gthomas
parents: 1412
diff changeset
265
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
266 do {
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
267 __enet_poll();
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
268 #ifdef CYGSEM_REDBOOT_NETWORKING_DHCP
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
269 if (dhcpState != oldState) {
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
270 if (dhcpState == DHCP_ACK) {
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
271 unsigned char *end;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
272 int optlen;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
273 // Address information has now arrived!
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
274 memcpy(__local_ip_addr, &bp_info->bp_yiaddr, 4);
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
275 #ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
276 memcpy(__local_ip_gate, &bp_info->bp_giaddr, 4);
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
277 #endif
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
278 p = bp_info->bp_vend+4;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
279 end = (unsigned char *)bp_info+sizeof(*bp_info);
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
280 while (p < end) {
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
281 unsigned char tag = *p;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
282 if (tag == TAG_END)
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
283 break;
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
284 if (tag == TAG_PAD)
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
285 optlen = 1;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
286 else {
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
287 optlen = p[1];
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
288 p += 2;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
289 switch (tag) {
1288
c07ec2765e3e Fix compile problems if GATEWAY support disabled
gthomas
parents: 1246
diff changeset
290 #ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
291 case TAG_SUBNET_MASK: // subnet mask
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
292 memcpy(__local_ip_mask,p,4);
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
293 break;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
294 case TAG_GATEWAY: // router
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
295 memcpy(__local_ip_gate,p,4);
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
296 break;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
297 #endif
1357
7b0dae4bd7a9 Use DNS server from DHCP info if present
gthomas
parents: 1288
diff changeset
298 #ifdef CYGPKG_REDBOOT_NETWORKING_DNS
7b0dae4bd7a9 Use DNS server from DHCP info if present
gthomas
parents: 1288
diff changeset
299 case TAG_DOMAIN_SERVER:
1396
72d234fe1607 Suppress diagnostic message (noisy)
gthomas
parents: 1357
diff changeset
300 // diag_printf(" DNS server found!\n");
1357
7b0dae4bd7a9 Use DNS server from DHCP info if present
gthomas
parents: 1288
diff changeset
301 memcpy(&__bootp_dns_addr, p, 4);
7b0dae4bd7a9 Use DNS server from DHCP info if present
gthomas
parents: 1288
diff changeset
302 __bootp_dns_set = 1;
7b0dae4bd7a9 Use DNS server from DHCP info if present
gthomas
parents: 1288
diff changeset
303 break;
2395
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
304 #ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
305 case TAG_DOMAIN_NAME:
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
306 if(optlen < sizeof(__bootp_dns_domain)) {
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
307 memcpy(__bootp_dns_domain, p, optlen);
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
308 __bootp_dns_domain[optlen] = '\0';
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
309 __bootp_dns_domain_set = 1;
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
310 } else {
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
311 diag_printf("DNS domain name too long\n");
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
312 }
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
313 break;
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
314 #endif //CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN
b8111f0a6f98 * src/net/net_io.c: (do_ip_addr): Option to set domain name.
asl
parents: 1886
diff changeset
315 #endif //CYGPKG_REDBOOT_NETWORKING_DNS
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
316 default:
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
317 break;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
318 }
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
319 }
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
320 p += optlen;
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
321 }
1245
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
322 __udp_remove_listener(IPPORT_BOOTPC);
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
323 return 0;
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
324 } else {
844ff6aec80b Improve DHCP again
gthomas
parents: 1243
diff changeset
325 break; // State changed, handle it
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
326 }
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
327 }
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
328 #else
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
329 // All done, if address response has arrived
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
330 if (__local_ip_addr[0] || __local_ip_addr[1] ||
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
331 __local_ip_addr[2] || __local_ip_addr[3]) {
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
332 /* success */
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
333 __udp_remove_listener(IPPORT_BOOTPC);
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
334 return 0;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
335 }
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
336 #endif
1122
92e31da869cc Add ^C abort functionality to BOOTP and PING operations.
gthomas
parents: 1117
diff changeset
337 if (_rb_break(1)) {
92e31da869cc Add ^C abort functionality to BOOTP and PING operations.
gthomas
parents: 1117
diff changeset
338 // The user typed ^C on the console
92e31da869cc Add ^C abort functionality to BOOTP and PING operations.
gthomas
parents: 1117
diff changeset
339 abort = true;
92e31da869cc Add ^C abort functionality to BOOTP and PING operations.
gthomas
parents: 1117
diff changeset
340 break;
92e31da869cc Add ^C abort functionality to BOOTP and PING operations.
gthomas
parents: 1117
diff changeset
341 }
92e31da869cc Add ^C abort functionality to BOOTP and PING operations.
gthomas
parents: 1117
diff changeset
342 MS_TICKS_DELAY(); // Count for ^C test
151
25e238959bae Merge from eCos master repository on 2001-02-12-23:44:24-GMT
jlarmour
parents: 115
diff changeset
343 } while ((MS_TICKS_DELAY() - start) < RETRY_TIME);
1886
5f0c796f46a6 Make BOOTP/DHCP quieter - from David Vrable
gthomas
parents: 1412
diff changeset
344 } while (!abort && (retry-- > 0));
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
345
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
346 // timed out
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
347 __udp_remove_listener(IPPORT_BOOTPC);
1227
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
348 // Restore any previous IP address
54f8d0daacd4 Fix DHCP - BUG #1000053
gthomas
parents: 1217
diff changeset
349 memcpy(__local_ip_addr, saved_ip_addr, sizeof(__local_ip_addr));
115
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
350 return -1;
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
351 }
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
352
6ed91473a1cd Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
diff changeset
353