1
1
#include <stdlib.h>
2
2
#include <string.h>
3
-
4
-
5
-
6
3
#include "lwipDhcpServer.h"
7
4
#include "lwipDhcpServerPriv.h"
8
5
@@ -11,37 +8,12 @@ static const u32_t magic_cookie = 0x63538263;
11
8
12
9
#define BOOTP_BROADCAST 0x8000
13
10
14
- #define DHCP_REQUEST 1
15
- #define DHCP_REPLY 2
16
11
#define DHCP_HTYPE_ETHERNET 1
17
- #define DHCP_HLEN_ETHERNET 6
18
- #define DHCP_MSG_LEN 236
19
12
20
13
#define DHCPS_SERVER_PORT 67
21
14
#define DHCPS_CLIENT_PORT 68
22
15
23
- #define DHCPDISCOVER 1
24
- #define DHCPOFFER 2
25
- #define DHCPREQUEST 3
26
- #define DHCPDECLINE 4
27
- #define DHCPACK 5
28
- #define DHCPNAK 6
29
- #define DHCPRELEASE 7
30
-
31
- #define DHCP_OPTION_SUBNET_MASK 1
32
- #define DHCP_OPTION_ROUTER 3
33
- #define DHCP_OPTION_DNS_SERVER 6
34
- #define DHCP_OPTION_REQ_IPADDR 50
35
- #define DHCP_OPTION_LEASE_TIME 51
36
- #define DHCP_OPTION_MSG_TYPE 53
37
- #define DHCP_OPTION_SERVER_ID 54
38
- #define DHCP_OPTION_INTERFACE_MTU 26
39
16
#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31
40
- #define DHCP_OPTION_BROADCAST_ADDRESS 28
41
- #define DHCP_OPTION_REQ_LIST 55
42
- #define DHCP_OPTION_END 255
43
-
44
-
45
17
46
18
#ifdef DHCPS_DEBUG
47
19
/* function defined in CNetIf.cpp */
@@ -74,13 +46,6 @@ static struct netif *dhcps_netif = NULL;
74
46
static struct udp_pcb * dhcps_pcb ;
75
47
static DHCP_Address dhcp_address ;
76
48
77
-
78
- static uint8_t xid [4 ];
79
-
80
-
81
- //static list_node *plist = NULL;
82
- static bool renew = false;
83
-
84
49
static dhcps_lease_t dhcps_poll ;
85
50
static dhcps_time_t dhcps_lease_time = DHCPS_LEASE_TIME_DEF ; //minute
86
51
static dhcps_offer_t dhcps_offer = 0xFF ;
@@ -191,7 +156,7 @@ void dhcps_set_option_info(uint8_t op_id, void *opt_info, u32_t opt_len)
191
156
*******************************************************************************/
192
157
static uint8_t * add_msg_type (uint8_t * optptr , uint8_t type )
193
158
{
194
- * optptr ++ = DHCP_OPTION_MSG_TYPE ;
159
+ * optptr ++ = DHCP_OPTION_MESSAGE_TYPE ;
195
160
* optptr ++ = 1 ;
196
161
* optptr ++ = type ;
197
162
return optptr ;
@@ -260,7 +225,7 @@ static uint8_t *add_offer_options(uint8_t *optptr)
260
225
}
261
226
262
227
263
- * optptr ++ = DHCP_OPTION_INTERFACE_MTU ;
228
+ * optptr ++ = DHCP_OPTION_MTU ;
264
229
* optptr ++ = 2 ;
265
230
* optptr ++ = 0x05 ;
266
231
* optptr ++ = 0xdc ;
@@ -301,7 +266,7 @@ static uint8_t *add_end(uint8_t *optptr)
301
266
*******************************************************************************/
302
267
static void create_msg (struct dhcps_msg * m )
303
268
{
304
- m -> op = DHCP_REPLY ;
269
+ m -> op = DHCP_BOOTREPLY ;
305
270
306
271
m -> htype = DHCP_HTYPE_ETHERNET ;
307
272
@@ -346,18 +311,17 @@ struct pbuf * dhcps_pbuf_alloc(uint16_t len)
346
311
*******************************************************************************/
347
312
static void send_offer (struct dhcps_msg * msg , uint16_t len )
348
313
{
314
+ (void )len ;
349
315
uint8_t * end ;
350
316
struct pbuf * p , * q ;
351
317
uint8_t * data ;
352
318
uint16_t cnt = 0 ;
353
- uint8_t CopyFinished = 0 ;
354
319
uint16_t i ;
355
- uint32_t endptr , dataptr = NULL ;
356
320
#if DHCPS_DEBUG
357
321
err_t SendOffer_err_t ;
358
322
#endif
359
323
create_msg (msg );
360
- end = add_msg_type (& msg -> options [4 ], DHCPOFFER );
324
+ end = add_msg_type (& msg -> options [4 ], DHCP_OFFER );
361
325
end = add_offer_options (end );
362
326
end = add_end (end );
363
327
@@ -417,6 +381,7 @@ static void send_offer(struct dhcps_msg *msg, uint16_t len)
417
381
*******************************************************************************/
418
382
static void send_nak (struct dhcps_msg * m , uint16_t len )
419
383
{
384
+ (void )len ;
420
385
uint8_t * end ;
421
386
struct pbuf * p , * q ;
422
387
uint8_t * data ;
@@ -427,7 +392,7 @@ static void send_nak(struct dhcps_msg *m, uint16_t len)
427
392
#endif
428
393
create_msg (m );
429
394
430
- end = add_msg_type (& m -> options [4 ], DHCPNAK );
395
+ end = add_msg_type (& m -> options [4 ], DHCP_NAK );
431
396
end = add_end (end );
432
397
433
398
p = dhcps_pbuf_alloc (len );
@@ -483,6 +448,7 @@ static void send_nak(struct dhcps_msg *m, uint16_t len)
483
448
*******************************************************************************/
484
449
static void send_ack (struct dhcps_msg * m , uint16_t len )
485
450
{
451
+ (void )len ;
486
452
uint8_t * end ;
487
453
struct pbuf * p , * q ;
488
454
uint8_t * data ;
@@ -491,7 +457,7 @@ static void send_ack(struct dhcps_msg *m, uint16_t len)
491
457
err_t SendAck_err_t ;
492
458
create_msg (m );
493
459
494
- end = add_msg_type (& m -> options [4 ], DHCPACK );
460
+ end = add_msg_type (& m -> options [4 ], DHCP_ACK );
495
461
end = add_offer_options (end );
496
462
end = add_end (end );
497
463
@@ -573,10 +539,10 @@ static uint8_t parse_options(uint8_t *OptionsPtr, int16_t len)
573
539
DHCPS_LOG ("dhcps: (int16_t)*optptr = %d\n" , (int16_t )* OptionsPtr );
574
540
#endif
575
541
switch ((int16_t ) * OptionsPtr ) {
576
- case DHCP_OPTION_MSG_TYPE : //53
542
+ case DHCP_OPTION_MESSAGE_TYPE : //53
577
543
type = * (OptionsPtr + 2 );
578
544
break ;
579
- case DHCP_OPTION_REQ_IPADDR ://50
545
+ case DHCP_OPTION_REQUESTED_IP ://50
580
546
s .state = DHCPS_STATE_ACK ;
581
547
break ;
582
548
case DHCP_OPTION_END : {
@@ -592,26 +558,26 @@ static uint8_t parse_options(uint8_t *OptionsPtr, int16_t len)
592
558
}
593
559
594
560
switch (type ) {
595
- case DHCPDISCOVER ://1
561
+ case DHCP_DISCOVER ://1
596
562
#if DHCPS_DEBUG
597
563
DHCPS_LOG ("dhcps: DHCPD_STATE_DHCPDISCOVER -- SEND_OFFER\n" );
598
564
#endif
599
565
s .state = DHCPS_STATE_OFFER ;
600
566
break ;
601
- case DHCPREQUEST ://3
567
+ case DHCP_REQUEST ://3
602
568
#if DHCPS_DEBUG
603
569
DHCPS_LOG ("dhcps: DHCPD_STATE_DHCPREQUEST -- SEND_ACK\n" );
604
570
#endif
605
571
s .state = DHCPS_STATE_ACK ;
606
572
607
573
break ;
608
- case DHCPDECLINE ://4
574
+ case DHCP_DECLINE ://4
609
575
s .state = DHCPS_STATE_IDLE ;
610
576
#if DHCPS_DEBUG
611
577
DHCPS_LOG ("dhcps: DHCPD_STATE_IDLE\n" );
612
578
#endif
613
579
break ;
614
- case DHCPRELEASE ://7
580
+ case DHCP_RELEASE ://7
615
581
s .state = DHCPS_STATE_RELEASE ;
616
582
#if DHCPS_DEBUG
617
583
DHCPS_LOG ("dhcps: DHCPD_STATE_IDLE\n" );
@@ -664,10 +630,12 @@ static void handle_dhcp(void *arg,
664
630
const ip_addr_t * addr ,
665
631
uint16_t port )
666
632
{
633
+ (void )arg ;
634
+ (void )pcb ;
635
+ (void )addr ;
636
+ (void )port ;
667
637
struct dhcps_msg * pmsg_dhcps = NULL ;
668
638
int16_t tlen , malloc_len ;
669
- uint16_t i ;
670
- uint16_t dhcps_msg_cnt = 0 ;
671
639
uint8_t * p_dhcps_msg = NULL ;
672
640
struct pbuf * q ;
673
641
0 commit comments