io6Library
WIZnet Dual Stack TCP/IP Ethernet Controller Driver
dhcpv4.c
Go to the documentation of this file.
1 //*****************************************************************************
2 //
50 //
51 //*****************************************************************************
52 
53 #include "socket.h"
54 #include "dhcpv4.h"
55 
56 /* If you want to display debug & processing message, Define _DHCPV4_DEBUG_ in dhcp.h */
57 
58 #ifdef _DHCPV4_DEBUG_
59  #include <stdio.h>
60 #endif
61 
62 /* DHCP state machine. */
63 #define STATE_DHCPV4_INIT 0
64 #define STATE_DHCPV4_DISCOVER 1
65 #define STATE_DHCPV4_REQUEST 2
66 #define STATE_DHCPV4_LEASED 3
67 #define STATE_DHCPV4_REREQUEST 4
68 #define STATE_DHCPV4_RELEASE 5
69 #define STATE_DHCPV4_STOP 6
70 
71 #define DHCPV4_FLAGSBROADCAST 0x8000
72 #define DHCPV4_FLAGSUNICAST 0x0000
73 
74 /* DHCP message OP code */
75 #define DHCPV4_BOOTREQUEST 1
76 #define DHCPV4_BOOTREPLY 2
77 
78 /* DHCP message type */
79 #define DHCPV4_DISCOVER 1
80 #define DHCPV4_OFFER 2
81 #define DHCPV4_REQUEST 3
82 #define DHCPV4_DECLINE 4
83 #define DHCPV4_ACK 5
84 #define DHCPV4_NAK 6
85 #define DHCPV4_RELEASE 7
86 #define DHCPV4_INFORM 8
87 
88 #define DHCPV4_HTYPE10MB 1
89 #define DHCPV4_HTYPE100MB 2
90 
91 #define DHCPV4_HLENETHERNET 6
92 #define DHCPV4_HOPS 0
93 #define DHCPV4_SECS 0
94 
95 #define INFINITE_LEASETIME 0xffffffff
96 
97 #define OPT_SIZE 312
98 #define RIP_MSG_SIZE (236+OPT_SIZE)
99 
100 /*
101  * @brief DHCP option and value (cf. RFC1533)
102  */
103 enum
104 {
111  dns = 6,
117  hostName = 12,
122  rootPath = 17,
131  ifMTU = 26,
161  dhcpMsg = 56,
167  endOption = 255
168 };
169 
170 /*
171  * @brief DHCP message format
172  */
173 typedef struct {
174  uint8_t op;
175  uint8_t htype;
176  uint8_t hlen;
177  uint8_t hops;
178  uint32_t xid;
179  uint16_t secs;
180  uint16_t flags;
181  uint8_t ciaddr[4];
182  uint8_t yiaddr[4];
183  uint8_t siaddr[4];
184  uint8_t giaddr[4];
185  uint8_t chaddr[16];
186  uint8_t sname[64];
187  uint8_t file[128];
188  uint8_t OPT[OPT_SIZE];
189 } RIP_MSG;
190 
191 
192 
193 uint8_t DHCPV4_SOCKET; // Socket number for DHCP
194 
195 uint8_t DHCPV4_SIP[4]; // DHCP Server IP address
196 uint8_t DHCPV4_REAL_SIP[4]; // For extract my DHCP server in a few DHCP server
197 
198 // Network information from DHCP Server
199 uint8_t OLD_allocated_ip[4] = {0, }; // Previous IP address
200 uint8_t DHCPv4_allocated_ip[4] = {0, }; // IP address from DHCP
201 uint8_t DHCPv4_allocated_gw[4] = {0, }; // Gateway address from DHCP
202 uint8_t DHCPv4_allocated_sn[4] = {0, }; // Subnet mask from DHCP
203 uint8_t DHCPv4_allocated_dns[4] = {0, }; // DNS address from DHCP
204 
205 
206 int8_t dhcpv4_state = STATE_DHCPV4_INIT; // DHCP state
208 
210 volatile uint32_t dhcpv4_tick_1s = 0; // unit 1 second
212 
213 uint32_t DHCPV4_XID; // Any number
214 
215 RIP_MSG* pDHCPv4MSG; // Buffer pointer for DHCP processing
216 
218 
219 uint8_t DHCPv4_CHADDR[6]; // DHCP Client MAC address.
220 
221 /* The default callback function */
222 void default_ipv4_assign(void);
223 void default_ipv4_update(void);
224 void default_ipv4_conflict(void);
225 
226 /* Callback handler */
227 void (*dhcp_ipv4_assign)(void) = default_ipv4_assign; /* handler to be called when the IP address from DHCP server is first assigned */
228 void (*dhcp_ipv4_update)(void) = default_ipv4_update; /* handler to be called when the IP address from DHCP server is updated */
229 void (*dhcp_ipv4_conflict)(void) = default_ipv4_conflict; /* handler to be called when the IP address from DHCP server is conflict */
230 
231 void reg_dhcpv4_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
232 
233 char NibbleToHex(uint8_t nibble);
234 
235 /* send DISCOVER message to DHCP server */
236 void send_DHCPv4_DISCOVER(void);
237 
238 /* send REQEUST message to DHCP server */
239 void send_DHCPv4_REQUEST(void);
240 
241 /* send DECLINE message to DHCP server */
242 void send_DHCPv4_DECLINE(void);
243 
244 /* IP conflict check by sending ARP-request to leased IP and wait ARP-response. */
245 int8_t check_DHCPv4_leasedIP(void);
246 
247 /* check the timeout in DHCP process */
248 uint8_t check_DHCPv4_timeout(void);
249 
250 /* Initialize to timeout process. */
251 void reset_DHCPv4_timeout(void);
252 
253 /* Parse message as OFFER and ACK and NACK from DHCP server.*/
254 int8_t parseDHCPCMSG(void);
255 
256 /* The default handler of ip assign first */
257 void default_ipv4_assign(void)
258 {
262 }
263 
264 /* The default handler of ip changed */
266 {
267  /* WIZchip Software Reset */
269  getSYCR0(); // for delay
272 }
273 
274 /* The default handler of ip changed */
276 {
277  // WIZchip Software Reset
279  getSYCR0(); // for delay
281 }
282 
283 /* register the call back func. */
284 void reg_dhcpv4_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void))
285 {
287  dhcp_ipv4_update = default_ipv4_update;
288  dhcp_ipv4_conflict = default_ipv4_conflict;
289  if(ip_assign) dhcp_ipv4_assign = ip_assign;
290  if(ip_update) dhcp_ipv4_update = ip_update;
291  if(ip_conflict) dhcp_ipv4_conflict = ip_conflict;
292 }
293 
294 /* make the common DHCP message */
295 void makeDHCPV4MSG(void)
296 {
297  uint8_t bk_mac[6];
298  uint8_t* ptmp;
299  uint8_t i;
300  getSHAR(bk_mac);
305  ptmp = (uint8_t*)(&pDHCPv4MSG->xid);
306  *(ptmp+0) = (uint8_t)((DHCPV4_XID & 0xFF000000) >> 24);
307  *(ptmp+1) = (uint8_t)((DHCPV4_XID & 0x00FF0000) >> 16);
308  *(ptmp+2) = (uint8_t)((DHCPV4_XID & 0x0000FF00) >> 8);
309  *(ptmp+3) = (uint8_t)((DHCPV4_XID & 0x000000FF) >> 0);
311  ptmp = (uint8_t*)(&pDHCPv4MSG->flags);
312  *(ptmp+0) = (uint8_t)((DHCPV4_FLAGSBROADCAST & 0xFF00) >> 8);
313  *(ptmp+1) = (uint8_t)((DHCPV4_FLAGSBROADCAST & 0x00FF) >> 0);
314 
315  pDHCPv4MSG->ciaddr[0] = 0;
316  pDHCPv4MSG->ciaddr[1] = 0;
317  pDHCPv4MSG->ciaddr[2] = 0;
318  pDHCPv4MSG->ciaddr[3] = 0;
319 
320  pDHCPv4MSG->yiaddr[0] = 0;
321  pDHCPv4MSG->yiaddr[1] = 0;
322  pDHCPv4MSG->yiaddr[2] = 0;
323  pDHCPv4MSG->yiaddr[3] = 0;
324 
325  pDHCPv4MSG->siaddr[0] = 0;
326  pDHCPv4MSG->siaddr[1] = 0;
327  pDHCPv4MSG->siaddr[2] = 0;
328  pDHCPv4MSG->siaddr[3] = 0;
329 
330  pDHCPv4MSG->giaddr[0] = 0;
331  pDHCPv4MSG->giaddr[1] = 0;
332  pDHCPv4MSG->giaddr[2] = 0;
333  pDHCPv4MSG->giaddr[3] = 0;
334 
341 
342  for (i = 6; i < 16; i++) pDHCPv4MSG->chaddr[i] = 0;
343  for (i = 0; i < 64; i++) pDHCPv4MSG->sname[i] = 0;
344  for (i = 0; i < 128; i++) pDHCPv4MSG->file[i] = 0;
345 
346  // MAGIC_COOKIE
347  pDHCPv4MSG->OPT[0] = (uint8_t)((MAGIC_COOKIE & 0xFF000000) >> 24);
348  pDHCPv4MSG->OPT[1] = (uint8_t)((MAGIC_COOKIE & 0x00FF0000) >> 16);
349  pDHCPv4MSG->OPT[2] = (uint8_t)((MAGIC_COOKIE & 0x0000FF00) >> 8);
350  pDHCPv4MSG->OPT[3] = (uint8_t) (MAGIC_COOKIE & 0x000000FF) >> 0;
351 }
352 
353 /* SEND DHCP DISCOVER */
355 {
356  uint16_t i;
357  uint8_t ip[4];
358  uint16_t k = 0;
359 
360  makeDHCPV4MSG();
361  DHCPV4_SIP[0]=0;
362  DHCPV4_SIP[1]=0;
363  DHCPV4_SIP[2]=0;
364  DHCPV4_SIP[3]=0;
365  DHCPV4_REAL_SIP[0]=0;
366  DHCPV4_REAL_SIP[1]=0;
367  DHCPV4_REAL_SIP[2]=0;
368  DHCPV4_REAL_SIP[3]=0;
369 
370  k = 4; // because MAGIC_COOKIE already made by makeDHCPV4MSG()
371 
372  // Option Request Param
374  pDHCPv4MSG->OPT[k++] = 0x01;
376 
377  // Client identifier
379  pDHCPv4MSG->OPT[k++] = 0x07;
380  pDHCPv4MSG->OPT[k++] = 0x01;
381  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[0];
382  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[1];
383  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[2];
384  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[3];
385  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[4];
386  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[5];
387 
388  // host name
389  pDHCPv4MSG->OPT[k++] = hostName;
390  pDHCPv4MSG->OPT[k++] = 0; // fill zero length of hostname
391  for(i = 0 ; HOST_NAMEv4[i] != 0; i++)
392  pDHCPv4MSG->OPT[k++] = HOST_NAMEv4[i];
393  pDHCPv4MSG->OPT[k++] = NibbleToHex(DHCPv4_CHADDR[3] >> 4);
395  pDHCPv4MSG->OPT[k++] = NibbleToHex(DHCPv4_CHADDR[4] >> 4);
397  pDHCPv4MSG->OPT[k++] = NibbleToHex(DHCPv4_CHADDR[5] >> 4);
399  pDHCPv4MSG->OPT[k - (i+6+1)] = i+6; // length of hostname
400 
402  pDHCPv4MSG->OPT[k++] = 0x06; // length of request
403  pDHCPv4MSG->OPT[k++] = subnetMask;
405  pDHCPv4MSG->OPT[k++] = dns;
406  pDHCPv4MSG->OPT[k++] = domainName;
407  pDHCPv4MSG->OPT[k++] = dhcpT1value;
408  pDHCPv4MSG->OPT[k++] = dhcpT2value;
409  pDHCPv4MSG->OPT[k++] = endOption;
410 
411  for (i = k; i < OPT_SIZE; i++) pDHCPv4MSG->OPT[i] = 0;
412 
413  // send broadcasting packet
414  ip[0] = 255;
415  ip[1] = 255;
416  ip[2] = 255;
417  ip[3] = 255;
418 
419 #ifdef _DHCPV4_DEBUG_
420  printf("> Send DHCP_DISCOVER\r\n");
421 #endif
422 
424 }
425 
426 /* SEND DHCP REQUEST */
428 {
429  int i;
430  uint8_t ip[4];
431  uint16_t k = 0;
432 
433  makeDHCPV4MSG();
434 
436  {
437  *((uint8_t*)(&pDHCPv4MSG->flags)) = ((DHCPV4_FLAGSUNICAST & 0xFF00)>> 8);
438  *((uint8_t*)(&pDHCPv4MSG->flags)+1) = (DHCPV4_FLAGSUNICAST & 0x00FF);
443  ip[0] = DHCPV4_SIP[0];
444  ip[1] = DHCPV4_SIP[1];
445  ip[2] = DHCPV4_SIP[2];
446  ip[3] = DHCPV4_SIP[3];
447  }
448  else
449  {
450  ip[0] = 255;
451  ip[1] = 255;
452  ip[2] = 255;
453  ip[3] = 255;
454  }
455 
456  k = 4; // because MAGIC_COOKIE already made by makeDHCPV4MSG()
457 
458  // Option Request Param.
460  pDHCPv4MSG->OPT[k++] = 0x01;
461  pDHCPv4MSG->OPT[k++] = DHCPV4_REQUEST;
462 
464  pDHCPv4MSG->OPT[k++] = 0x07;
465  pDHCPv4MSG->OPT[k++] = 0x01;
466  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[0];
467  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[1];
468  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[2];
469  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[3];
470  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[4];
471  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[5];
472 
473  if(ip[3] == 255) // if(dchp_state == STATE_DHCPV4_LEASED || dchp_state == DHCP_REREQUEST_STATE)
474  {
476  pDHCPv4MSG->OPT[k++] = 0x04;
481 
483  pDHCPv4MSG->OPT[k++] = 0x04;
484  pDHCPv4MSG->OPT[k++] = DHCPV4_SIP[0];
485  pDHCPv4MSG->OPT[k++] = DHCPV4_SIP[1];
486  pDHCPv4MSG->OPT[k++] = DHCPV4_SIP[2];
487  pDHCPv4MSG->OPT[k++] = DHCPV4_SIP[3];
488  }
489 
490  // host name
491  pDHCPv4MSG->OPT[k++] = hostName;
492  pDHCPv4MSG->OPT[k++] = 0; // length of hostname
493  for(i = 0 ; HOST_NAMEv4[i] != 0; i++)
494  pDHCPv4MSG->OPT[k++] = HOST_NAMEv4[i];
495  pDHCPv4MSG->OPT[k++] = NibbleToHex(DHCPv4_CHADDR[3] >> 4);
497  pDHCPv4MSG->OPT[k++] = NibbleToHex(DHCPv4_CHADDR[4] >> 4);
499  pDHCPv4MSG->OPT[k++] = NibbleToHex(DHCPv4_CHADDR[5] >> 4);
501  pDHCPv4MSG->OPT[k - (i+6+1)] = i+6; // length of hostname
502 
504  pDHCPv4MSG->OPT[k++] = 0x08;
505  pDHCPv4MSG->OPT[k++] = subnetMask;
507  pDHCPv4MSG->OPT[k++] = dns;
508  pDHCPv4MSG->OPT[k++] = domainName;
509  pDHCPv4MSG->OPT[k++] = dhcpT1value;
510  pDHCPv4MSG->OPT[k++] = dhcpT2value;
512  pDHCPv4MSG->OPT[k++] = staticRoute;
513  pDHCPv4MSG->OPT[k++] = endOption;
514 
515  for (i = k; i < OPT_SIZE; i++) pDHCPv4MSG->OPT[i] = 0;
516 
517 #ifdef _DHCPV4_DEBUG_
518  printf("> Send DHCP_REQUEST\r\n");
519 #endif
520 
522 
523 }
524 
525 /* SEND DHCP DHCPDECLINE */
527 {
528  int i;
529  uint8_t ip[4];
530  uint16_t k = 0;
531 
532  makeDHCPV4MSG();
533 
534  k = 4; // because MAGIC_COOKIE already made by makeDHCPV4MSG()
535 
536  *((uint8_t*)(&pDHCPv4MSG->flags)) = ((DHCPV4_FLAGSUNICAST & 0xFF00)>> 8);
537  *((uint8_t*)(&pDHCPv4MSG->flags)+1) = (DHCPV4_FLAGSUNICAST & 0x00FF);
538 
539  // Option Request Param.
541  pDHCPv4MSG->OPT[k++] = 0x01;
542  pDHCPv4MSG->OPT[k++] = DHCPV4_DECLINE;
543 
545  pDHCPv4MSG->OPT[k++] = 0x07;
546  pDHCPv4MSG->OPT[k++] = 0x01;
547  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[0];
548  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[1];
549  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[2];
550  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[3];
551  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[4];
552  pDHCPv4MSG->OPT[k++] = DHCPv4_CHADDR[5];
553 
555  pDHCPv4MSG->OPT[k++] = 0x04;
560 
562  pDHCPv4MSG->OPT[k++] = 0x04;
563  pDHCPv4MSG->OPT[k++] = DHCPV4_SIP[0];
564  pDHCPv4MSG->OPT[k++] = DHCPV4_SIP[1];
565  pDHCPv4MSG->OPT[k++] = DHCPV4_SIP[2];
566  pDHCPv4MSG->OPT[k++] = DHCPV4_SIP[3];
567 
568  pDHCPv4MSG->OPT[k++] = endOption;
569 
570  for (i = k; i < OPT_SIZE; i++) pDHCPv4MSG->OPT[i] = 0;
571 
572  //send broadcasting packet
573  ip[0] = 0xFF;
574  ip[1] = 0xFF;
575  ip[2] = 0xFF;
576  ip[3] = 0xFF;
577 
578 #ifdef _DHCPV4_DEBUG_
579  printf("\r\n> Send DHCPV4_DECLINE\r\n");
580 #endif
581 
583 }
584 
585 /* PARSE REPLY pDHCPv4MSG */
586 int8_t parseDHCPv4MSG(void)
587 {
588  uint8_t svr_addr[6];
589  uint16_t svr_port;
590  uint16_t len;
591 
592  uint8_t * p;
593  uint8_t * e;
594  uint8_t type = 0;
595  uint8_t opt_len;
596  uint8_t addr_len;
597 
598  if((len = getSn_RX_RSR(DHCPV4_SOCKET)) > 0)
599  {
600  len = recvfrom(DHCPV4_SOCKET, (uint8_t *)pDHCPv4MSG, len, svr_addr, &svr_port, &addr_len);
601  #ifdef _DHCPV4_DEBUG_
602  printf("DHCP message : %d.%d.%d.%d(%d) %d received. \r\n",svr_addr[0],svr_addr[1],svr_addr[2], svr_addr[3],svr_port, len);
603  #endif
604  }
605  else return 0;
606  if (svr_port == DHCPV4_SERVER_PORT) {
607  // compare mac address
608  if ( (pDHCPv4MSG->chaddr[0] != DHCPv4_CHADDR[0]) || (pDHCPv4MSG->chaddr[1] != DHCPv4_CHADDR[1]) ||
609  (pDHCPv4MSG->chaddr[2] != DHCPv4_CHADDR[2]) || (pDHCPv4MSG->chaddr[3] != DHCPv4_CHADDR[3]) ||
610  (pDHCPv4MSG->chaddr[4] != DHCPv4_CHADDR[4]) || (pDHCPv4MSG->chaddr[5] != DHCPv4_CHADDR[5]) )
611  {
612 #ifdef _DHCPV4_DEBUG_
613  printf("No My DHCP Message. This message is ignored.\r\n");
614 #endif
615  return 0;
616  }
617  //compare DHCP server ip address
618  if((DHCPV4_SIP[0]!=0) || (DHCPV4_SIP[1]!=0) || (DHCPV4_SIP[2]!=0) || (DHCPV4_SIP[3]!=0)){
619  if( ((svr_addr[0]!=DHCPV4_SIP[0])|| (svr_addr[1]!=DHCPV4_SIP[1])|| (svr_addr[2]!=DHCPV4_SIP[2])|| (svr_addr[3]!=DHCPV4_SIP[3])) &&
620  ((svr_addr[0]!=DHCPV4_REAL_SIP[0])|| (svr_addr[1]!=DHCPV4_REAL_SIP[1])|| (svr_addr[2]!=DHCPV4_REAL_SIP[2])|| (svr_addr[3]!=DHCPV4_REAL_SIP[3])) )
621  {
622 #ifdef _DHCPV4_DEBUG_
623  printf("Another DHCP sever send a response message. This is ignored.\r\n");
624 #endif
625  return 0;
626  }
627  }
628  p = (uint8_t *)(&pDHCPv4MSG->op);
629  p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
630  e = p + (len - 240);
631 
632  while ( p < e ) {
633 
634  switch ( *p ) {
635 
636  case endOption :
637  p = e; // for break while(p < e)
638  break;
639  case padOption :
640  p++;
641  break;
642  case dhcpMessageType :
643  p++;
644  p++;
645  type = *p++;
646  break;
647  case subnetMask :
648  p++;
649  p++;
650  DHCPv4_allocated_sn[0] = *p++;
651  DHCPv4_allocated_sn[1] = *p++;
652  DHCPv4_allocated_sn[2] = *p++;
653  DHCPv4_allocated_sn[3] = *p++;
654  break;
655  case routersOnSubnet :
656  p++;
657  opt_len = *p++;
658  DHCPv4_allocated_gw[0] = *p++;
659  DHCPv4_allocated_gw[1] = *p++;
660  DHCPv4_allocated_gw[2] = *p++;
661  DHCPv4_allocated_gw[3] = *p++;
662  p = p + (opt_len - 4);
663  break;
664  case dns :
665  p++;
666  opt_len = *p++;
667  DHCPv4_allocated_dns[0] = *p++;
668  DHCPv4_allocated_dns[1] = *p++;
669  DHCPv4_allocated_dns[2] = *p++;
670  DHCPv4_allocated_dns[3] = *p++;
671  p = p + (opt_len - 4);
672  break;
673  case dhcpIPaddrLeaseTime :
674  p++;
675  opt_len = *p++;
676  dhcpv4_lease_time = *p++;
677  dhcpv4_lease_time = (dhcpv4_lease_time << 8) + *p++;
678  dhcpv4_lease_time = (dhcpv4_lease_time << 8) + *p++;
679  dhcpv4_lease_time = (dhcpv4_lease_time << 8) + *p++;
680  #ifdef _DHCPV4_DEBUG_
681  dhcpv4_lease_time = 10;
682  #endif
683  break;
684  case dhcpServerIdentifier :
685  p++;
686  opt_len = *p++;
687  DHCPV4_SIP[0] = *p++;
688  DHCPV4_SIP[1] = *p++;
689  DHCPV4_SIP[2] = *p++;
690  DHCPV4_SIP[3] = *p++;
691  DHCPV4_REAL_SIP[0]=svr_addr[0];
692  DHCPV4_REAL_SIP[1]=svr_addr[1];
693  DHCPV4_REAL_SIP[2]=svr_addr[2];
694  DHCPV4_REAL_SIP[3]=svr_addr[3];
695  break;
696  default :
697  p++;
698  opt_len = *p++;
699  p += opt_len;
700  break;
701  } // switch
702  } // while
703  } // if
704  return type;
705 }
706 
707 uint8_t DHCPv4_run(void)
708 {
709  uint8_t type;
710  uint8_t ret;
711 
713 
716 
717  ret = DHCPV4_RUNNING;
718  type = parseDHCPv4MSG();
719 
720 
721  switch ( dhcpv4_state ) {
722  case STATE_DHCPV4_INIT :
723  DHCPv4_allocated_ip[0] = 0;
724  DHCPv4_allocated_ip[1] = 0;
725  DHCPv4_allocated_ip[2] = 0;
726  DHCPv4_allocated_ip[3] = 0;
729  break;
730  case STATE_DHCPV4_DISCOVER :
731  if (type == DHCPV4_OFFER){
732 #ifdef _DHCPV4_DEBUG_
733  printf("> Receive DHCP_OFFER\r\n");
734 #endif
739 
742  } else ret = check_DHCPv4_timeout();
743  break;
744 
745  case STATE_DHCPV4_REQUEST :
746  if (type == DHCPV4_ACK) {
747 
748 #ifdef _DHCPV4_DEBUG_
749  printf("> Receive DHCP_ACK\r\n");
750 #endif
751  if (check_DHCPv4_leasedIP()) {
752  // Network info assignment from DHCP
755 
757  } else {
758  // IP address conflict occurred
760  dhcp_ipv4_conflict();
762  }
763  } else if (type == DHCPV4_NAK) {
764 
765 #ifdef _DHCPV4_DEBUG_
766  printf("> Receive DHCP_NACK\r\n");
767 #endif
768 
770 
772  } else ret = check_DHCPv4_timeout();
773  break;
774 
775  case STATE_DHCPV4_LEASED :
776  ret = DHCP_IPV4_LEASED;
778 
779 #ifdef _DHCPV4_DEBUG_
780  printf("> Maintains the IP address \r\n");
781 #endif
782 
783  type = 0;
788 
789  DHCPV4_XID++;
790 
792 
794 
796  }
797  break;
798 
800  ret = DHCP_IPV4_LEASED;
801  if (type == DHCPV4_ACK) {
802  dhcpv4_retry_count = 0;
803  if (OLD_allocated_ip[0] != DHCPv4_allocated_ip[0] ||
807  {
808  ret = DHCP_IPV4_CHANGED;
809  dhcp_ipv4_update();
810  #ifdef _DHCPV4_DEBUG_
811  printf(">IP changed.\r\n");
812  #endif
813 
814  }
815  #ifdef _DHCPV4_DEBUG_
816  else printf(">IP is continued.\r\n");
817  #endif
820  } else if (type == DHCPV4_NAK) {
821 
822 #ifdef _DHCPV4_DEBUG_
823  printf("> Receive DHCP_NACK, Failed to maintain ip\r\n");
824 #endif
825 
827 
829  } else ret = check_DHCPv4_timeout();
830  break;
831  default :
832  break;
833  }
834 
835  return ret;
836 }
837 
838 void DHCPv4_stop(void)
839 {
842 }
843 
844 uint8_t check_DHCPv4_timeout(void)
845 {
846  uint8_t ret = DHCPV4_RUNNING;
847 
850 
851  switch ( dhcpv4_state ) {
852  case STATE_DHCPV4_DISCOVER :
853 // printf("<<timeout>> state : STATE_DHCPV4_DISCOVER\r\n");
855  break;
856 
857  case STATE_DHCPV4_REQUEST :
858 // printf("<<timeout>> state : STATE_DHCPV4_REQUEST\r\n");
859 
861  break;
862 
864 // printf("<<timeout>> state : STATE_DHCPV4_REREQUEST\r\n");
865 
867  break;
868 
869  default :
870  break;
871  }
872 
873  dhcpv4_tick_1s = 0;
876  }
877  } else { // timeout occurred
878 
879  switch(dhcpv4_state) {
882  ret = DHCPV4_FAILED;
883  break;
888  break;
889  default :
890  break;
891  }
893  }
894  return ret;
895 }
896 
898 {
899  uint8_t tmp;
900  int32_t ret;
901 
902  //WIZchip RCR value changed for ARP Timeout count control
903  tmp = getRCR();
904  setRCR(0x03);
905 
906  // IP conflict detection : ARP request - ARP reply
907  // Broadcasting ARP Request for check the IP conflict using UDP sendto() function
908  ret = sendto(DHCPV4_SOCKET, (uint8_t *)"CHECK_IP_CONFLICT", 17, DHCPv4_allocated_ip, 5000, 4);
909 
910  // RCR value restore
911  setRCR(tmp);
912 
913  if(ret == SOCKERR_TIMEOUT) {
914  // UDP send Timeout occurred : allocated IP address is unique, DHCP Success
915 
916 #ifdef _DHCPV4_DEBUG_
917  printf("\r\n> Check leased IP - OK\r\n");
918 #endif
919 
920  return 1;
921  } else {
922  // Received ARP reply or etc : IP address conflict occur, DHCP Failed
924 
925  ret = dhcpv4_tick_1s;
926  while((dhcpv4_tick_1s - ret) < 2) ; // wait for 1s over; wait to complete to send DECLINE message;
927 
928  return 0;
929  }
930 }
931 
932 void DHCPv4_init(uint8_t s, uint8_t * buf)
933 {
934  uint8_t zeroip[4] = {0,0,0,0};
936  if((DHCPv4_CHADDR[0] | DHCPv4_CHADDR[1] | DHCPv4_CHADDR[2] | DHCPv4_CHADDR[3] | DHCPv4_CHADDR[4] | DHCPv4_CHADDR[5]) == 0x00)
937  {
938  // assigning temporary mac address, you should be set SHAR before call this function.
939  DHCPv4_CHADDR[0] = 0x00;
940  DHCPv4_CHADDR[1] = 0x08;
941  DHCPv4_CHADDR[2] = 0xdc;
942  DHCPv4_CHADDR[3] = 0x00;
943  DHCPv4_CHADDR[4] = 0x00;
944  DHCPv4_CHADDR[5] = 0x00;
946  }
947 
948  DHCPV4_SOCKET = s; // SOCK_DHCP
949  pDHCPv4MSG = (RIP_MSG*)buf;
950  DHCPV4_XID = 0x12345678;
951 
952  // WIZchip Netinfo Clear
953  setSIPR(zeroip);
954  setGAR(zeroip);
955 
958 }
959 
960 
961 /* Reset the DHCP timeout count and retry count. */
963 {
964  dhcpv4_tick_1s = 0;
966  dhcpv4_retry_count = 0;
967 }
968 
970 {
971  dhcpv4_tick_1s++;
972 }
973 
974 void getIPfromDHCPv4(uint8_t* ip)
975 {
976  ip[0] = DHCPv4_allocated_ip[0];
977  ip[1] = DHCPv4_allocated_ip[1];
978  ip[2] = DHCPv4_allocated_ip[2];
979  ip[3] = DHCPv4_allocated_ip[3];
980 }
981 
982 void getGWfromDHCPv4(uint8_t* ip)
983 {
984  ip[0] =DHCPv4_allocated_gw[0];
985  ip[1] =DHCPv4_allocated_gw[1];
986  ip[2] =DHCPv4_allocated_gw[2];
987  ip[3] =DHCPv4_allocated_gw[3];
988 }
989 
990 void getSNfromDHCPv4(uint8_t* ip)
991 {
992  ip[0] = DHCPv4_allocated_sn[0];
993  ip[1] = DHCPv4_allocated_sn[1];
994  ip[2] = DHCPv4_allocated_sn[2];
995  ip[3] = DHCPv4_allocated_sn[3];
996 }
997 
998 void getDNSfromDHCPv4(uint8_t* ip)
999 {
1000  ip[0] = DHCPv4_allocated_dns[0];
1001  ip[1] = DHCPv4_allocated_dns[1];
1002  ip[2] = DHCPv4_allocated_dns[2];
1003  ip[3] = DHCPv4_allocated_dns[3];
1004 }
1005 
1006 uint32_t getDHCPv4Leasetime(void)
1007 {
1008  return dhcpv4_lease_time;
1009 }
1010 
1011 char NibbleToHex(uint8_t nibble)
1012 {
1013  nibble &= 0x0F;
1014  if (nibble <= 9)
1015  return nibble + '0';
1016  else
1017  return nibble + ('A'-0x0A);
1018 }
getDNSfromDHCPv4
void getDNSfromDHCPv4(uint8_t *ip)
Definition: dhcpv4.c:998
nisDomainName
@ nisDomainName
Definition: dhcpv4.c:145
sendto
datasize_t sendto(uint8_t sn, uint8_t *buf, datasize_t len, uint8_t *addr, uint16_t port, uint8_t addrlen)
Send datagram to the peer specifed by destination IP address and port number passed as parameter.
Definition: socket.c:372
getSYCR0
#define getSYCR0()
Definition: w6100.h:3431
trailerEncapsulation
@ trailerEncapsulation
Definition: dhcpv4.c:139
DHCPV4_REAL_SIP
uint8_t DHCPV4_REAL_SIP[4]
Definition: dhcpv4.c:196
STATE_DHCPV4_REQUEST
#define STATE_DHCPV4_REQUEST
send REQEUST and wait ACK or NACK
Definition: dhcpv4.c:65
HOST_NAMEv4
uint8_t HOST_NAMEv4[]
Definition: dhcpv4.c:217
makeDHCPV4MSG
void makeDHCPV4MSG(void)
Definition: dhcpv4.c:295
DHCPv4_allocated_ip
uint8_t DHCPv4_allocated_ip[4]
Definition: dhcpv4.c:200
ethernetEncapsulation
@ ethernetEncapsulation
Definition: dhcpv4.c:141
socket
int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
Open a socket.
Definition: socket.c:101
SOCKERR_TIMEOUT
#define SOCKERR_TIMEOUT
Timeout occurred.
Definition: socket.h:97
DHCPV4_REQUEST
#define DHCPV4_REQUEST
REQUEST message in OPT of RIP_MSG.
Definition: dhcpv4.c:81
getIPfromDHCPv4
void getIPfromDHCPv4(uint8_t *ip)
Definition: dhcpv4.c:974
pathMTUagingTimeout
@ pathMTUagingTimeout
Definition: dhcpv4.c:129
dhcpv4_tick_next
uint32_t dhcpv4_tick_next
Definition: dhcpv4.c:211
hostName
@ hostName
Definition: dhcpv4.c:117
nonLocalSourceRouting
@ nonLocalSourceRouting
Definition: dhcpv4.c:125
MAGIC_COOKIE
#define MAGIC_COOKIE
You should not modify it number.
Definition: dhcpv4.h:71
DHCPV4_XID
uint32_t DHCPV4_XID
Definition: dhcpv4.c:213
lprServer
@ lprServer
Definition: dhcpv4.c:114
default_ipv4_conflict
void default_ipv4_conflict(void)
Definition: dhcpv4.c:275
STATE_DHCPV4_DISCOVER
#define STATE_DHCPV4_DISCOVER
send DISCOVER and wait OFFER
Definition: dhcpv4.c:64
DHCPV4_FLAGSBROADCAST
#define DHCPV4_FLAGSBROADCAST
The broadcast value of flags in RIP_MSG.
Definition: dhcpv4.c:71
DHCPV4_SIP
uint8_t DHCPV4_SIP[4]
Definition: dhcpv4.c:195
dhcpv4_tick_1s
volatile uint32_t dhcpv4_tick_1s
Definition: dhcpv4.c:210
dhcpServerIdentifier
@ dhcpServerIdentifier
Definition: dhcpv4.c:159
send_DHCPv4_DECLINE
void send_DHCPv4_DECLINE(void)
Definition: dhcpv4.c:526
DHCPV4_BOOTREQUEST
#define DHCPV4_BOOTREQUEST
Request Message used in op of RIP_MSG.
Definition: dhcpv4.c:75
DHCPV4_HOPS
#define DHCPV4_HOPS
Used in hops of RIP_MSG.
Definition: dhcpv4.c:92
DCHPV4_HOST_NAME
#define DCHPV4_HOST_NAME
Definition: dhcpv4.h:73
INFINITE_LEASETIME
#define INFINITE_LEASETIME
Infinite lease time.
Definition: dhcpv4.c:95
reset_DHCPv4_timeout
void reset_DHCPv4_timeout(void)
Definition: dhcpv4.c:962
policyFilter
@ policyFilter
Definition: dhcpv4.c:126
DHCPV4_FLAGSUNICAST
#define DHCPV4_FLAGSUNICAST
The unicast value of flags in RIP_MSG.
Definition: dhcpv4.c:72
meritDumpFile
@ meritDumpFile
Definition: dhcpv4.c:119
pDHCPv4MSG
RIP_MSG * pDHCPv4MSG
Definition: dhcpv4.c:215
DHCP_IPV4_LEASED
@ DHCP_IPV4_LEASED
Stand by.
Definition: dhcpv4.h:84
setSIPR
#define setSIPR(sipr)
Definition: w6100.h:3619
setSYCR0
#define setSYCR0(sycr0)
Definition: w6100.h:3434
DHCPv4_run
uint8_t DHCPv4_run(void)
Definition: dhcpv4.c:707
reg_dhcpv4_cbfunc
void reg_dhcpv4_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void))
Definition: dhcpv4.c:284
dhcp_ipv4_assign
void(* dhcp_ipv4_assign)(void)
Definition: dhcpv4.c:227
getSn_RX_RSR
datasize_t getSn_RX_RSR(uint8_t s)
RIP_MSG::sname
uint8_t sname[64]
No use.
Definition: dhcpv4.c:186
performMaskDiscovery
@ performMaskDiscovery
Definition: dhcpv4.c:134
tcpDefaultTTL
@ tcpDefaultTTL
Definition: dhcpv4.c:142
RIP_MSG::flags
uint16_t flags
DHCPV4_FLAGSBROADCAST or DHCPV4_FLAGSUNICAST
Definition: dhcpv4.c:180
netBIOSnameServer
@ netBIOSnameServer
Definition: dhcpv4.c:149
DHCPv4_stop
void DHCPv4_stop(void)
Definition: dhcpv4.c:838
ntpServers
@ ntpServers
Definition: dhcpv4.c:147
dhcpClientIdentifier
@ dhcpClientIdentifier
Definition: dhcpv4.c:166
SOCK_UDP
#define SOCK_UDP
UDP SOCKETn status.
Definition: w6100.h:2893
DHCP_IPV4_CHANGED
@ DHCP_IPV4_CHANGED
Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
Definition: dhcpv4.h:83
DHCPv4_allocated_dns
uint8_t DHCPv4_allocated_dns[4]
Definition: dhcpv4.c:203
DHCPv4_init
void DHCPv4_init(uint8_t s, uint8_t *buf)
Definition: dhcpv4.c:932
broadcastAddr
@ broadcastAddr
Definition: dhcpv4.c:133
DHCPv4_allocated_sn
uint8_t DHCPv4_allocated_sn[4]
Definition: dhcpv4.c:202
routerSolicitationAddr
@ routerSolicitationAddr
Definition: dhcpv4.c:137
timeServer
@ timeServer
Definition: dhcpv4.c:109
STATE_DHCPV4_LEASED
#define STATE_DHCPV4_LEASED
ReceiveD ACK and IP leased.
Definition: dhcpv4.c:66
timerOffset
@ timerOffset
Definition: dhcpv4.c:107
send_DHCPv4_REQUEST
void send_DHCPv4_REQUEST(void)
Definition: dhcpv4.c:427
logServer
@ logServer
Definition: dhcpv4.c:112
DHCPV4_WAIT_TIME
#define DHCPV4_WAIT_TIME
Wait Time 10s.
Definition: dhcpv4.h:63
setGAR
#define setGAR(gar)
Definition: w6100.h:3601
check_DHCPv4_timeout
uint8_t check_DHCPv4_timeout(void)
Definition: dhcpv4.c:844
xFontServer
@ xFontServer
Definition: dhcpv4.c:153
maskSupplier
@ maskSupplier
Definition: dhcpv4.c:135
Sn_MR_UDP
#define Sn_MR_UDP
IPv4 UDP mode.
Definition: w6100.h:2403
dhcpT1value
@ dhcpT1value
Definition: dhcpv4.c:163
swapServer
@ swapServer
Definition: dhcpv4.c:121
xDisplayManager
@ xDisplayManager
Definition: dhcpv4.c:154
setSUBR
#define setSUBR(subr)
Definition: w6100.h:3610
RIP_MSG::hops
uint8_t hops
DHCPV4_HOPS
Definition: dhcpv4.c:177
default_ipv4_update
void default_ipv4_update(void)
Definition: dhcpv4.c:265
netBIOSdgramDistServer
@ netBIOSdgramDistServer
Definition: dhcpv4.c:150
dhcpOptionOverload
@ dhcpOptionOverload
Definition: dhcpv4.c:157
RIP_MSG::hlen
uint8_t hlen
DHCPV4_HLENETHERNET
Definition: dhcpv4.c:176
nisServers
@ nisServers
Definition: dhcpv4.c:146
resourceLocationServer
@ resourceLocationServer
Definition: dhcpv4.c:116
DHCPV4_SECS
#define DHCPV4_SECS
Used in secs of RIP_MSG.
Definition: dhcpv4.c:93
cookieServer
@ cookieServer
Definition: dhcpv4.c:113
DHCPV4_FAILED
@ DHCPV4_FAILED
Processing Fail.
Definition: dhcpv4.h:80
dhcpT2value
@ dhcpT2value
Definition: dhcpv4.c:164
DHCPv4_CHADDR
uint8_t DHCPv4_CHADDR[6]
Definition: dhcpv4.c:219
vendorSpecificInfo
@ vendorSpecificInfo
Definition: dhcpv4.c:148
getDHCPv4Leasetime
uint32_t getDHCPv4Leasetime(void)
Definition: dhcpv4.c:1006
MAX_DHCPV4_RETRY
#define MAX_DHCPV4_RETRY
Maximum retry count.
Definition: dhcpv4.h:62
getSHAR
#define getSHAR(shar)
Definition: w6100.h:3598
netBIOSscope
@ netBIOSscope
Definition: dhcpv4.c:152
send_DHCPv4_DISCOVER
void send_DHCPv4_DISCOVER(void)
Definition: dhcpv4.c:354
setRCR
#define setRCR(rcr)
Definition: w6100.h:3772
getRCR
#define getRCR()
Definition: w6100.h:3775
RIP_MSG::siaddr
uint8_t siaddr[4]
No use.
Definition: dhcpv4.c:183
dhcpv4.h
DHCP APIs Header file.
bootFileSize
@ bootFileSize
Definition: dhcpv4.c:118
arpCacheTimeout
@ arpCacheTimeout
Definition: dhcpv4.c:140
tcpKeepaliveInterval
@ tcpKeepaliveInterval
Definition: dhcpv4.c:143
dhcpMaxMsgSize
@ dhcpMaxMsgSize
Definition: dhcpv4.c:162
DHCPV4_HTYPE10MB
#define DHCPV4_HTYPE10MB
Used in type of RIP_MSG.
Definition: dhcpv4.c:88
DHCPv4_allocated_gw
uint8_t DHCPv4_allocated_gw[4]
Definition: dhcpv4.c:201
RIP_MSG::OPT
uint8_t OPT[OPT_SIZE]
Option.
Definition: dhcpv4.c:188
RIP_MSG
Definition: dhcpv4.c:173
dhcpMsg
@ dhcpMsg
Definition: dhcpv4.c:161
dhcpParamRequest
@ dhcpParamRequest
Definition: dhcpv4.c:160
allSubnetsLocal
@ allSubnetsLocal
Definition: dhcpv4.c:132
DHCPV4_STOPPED
@ DHCPV4_STOPPED
Stop processing DHCP protocol.
Definition: dhcpv4.h:85
domainName
@ domainName
Definition: dhcpv4.c:120
RIP_MSG_SIZE
#define RIP_MSG_SIZE
Definition: dhcpv4.c:98
pathMTUplateauTable
@ pathMTUplateauTable
Definition: dhcpv4.c:130
ifMTU
@ ifMTU
Definition: dhcpv4.c:131
endOption
@ endOption
Definition: dhcpv4.c:167
RIP_MSG::op
uint8_t op
DHCPV4_BOOTREQUEST or DHCPV4_BOOTREPLY
Definition: dhcpv4.c:174
DHCPV4_ACK
#define DHCPV4_ACK
ACK message in OPT of RIP_MSG.
Definition: dhcpv4.c:83
dhcpv4_retry_count
int8_t dhcpv4_retry_count
Definition: dhcpv4.c:207
dhcpv4_lease_time
uint32_t dhcpv4_lease_time
Definition: dhcpv4.c:209
DHCPV4_NAK
#define DHCPV4_NAK
NACK message in OPT of RIP_MSG.
Definition: dhcpv4.c:84
dhcpRequestedIPaddr
@ dhcpRequestedIPaddr
Definition: dhcpv4.c:155
parseDHCPv4MSG
int8_t parseDHCPv4MSG(void)
Definition: dhcpv4.c:586
extentionsPath
@ extentionsPath
Definition: dhcpv4.c:123
DHCPV4_HLENETHERNET
#define DHCPV4_HLENETHERNET
Used in hlen of RIP_MSG.
Definition: dhcpv4.c:91
RIP_MSG::giaddr
uint8_t giaddr[4]
No use.
Definition: dhcpv4.c:184
getGWfromDHCPv4
void getGWfromDHCPv4(uint8_t *ip)
Definition: dhcpv4.c:982
close
int8_t close(uint8_t sn)
Close a SOCKET.
Definition: socket.c:186
dhcpIPaddrLeaseTime
@ dhcpIPaddrLeaseTime
Definition: dhcpv4.c:156
getSn_SR
#define getSn_SR(sn)
Definition: w6100.h:3837
IPforwarding
@ IPforwarding
Definition: dhcpv4.c:124
defaultIPTTL
@ defaultIPTTL
Definition: dhcpv4.c:128
dhcpMessageType
@ dhcpMessageType
Definition: dhcpv4.c:158
SYCR0_RST
#define SYCR0_RST
RST bit of _SYCR0_.
Definition: w6100.h:1480
impressServer
@ impressServer
Definition: dhcpv4.c:115
netBIOSnodeType
@ netBIOSnodeType
Definition: dhcpv4.c:151
rootPath
@ rootPath
Definition: dhcpv4.c:122
staticRoute
@ staticRoute
Definition: dhcpv4.c:138
tcpKeepaliveGarbage
@ tcpKeepaliveGarbage
Definition: dhcpv4.c:144
OPT_SIZE
#define OPT_SIZE
Definition: dhcpv4.c:97
socket.h
SOCKET APIs Header File.
performRouterDiscovery
@ performRouterDiscovery
Definition: dhcpv4.c:136
padOption
@ padOption
Definition: dhcpv4.c:105
dns
@ dns
Definition: dhcpv4.c:111
RIP_MSG::secs
uint16_t secs
DHCPV4_SECS
Definition: dhcpv4.c:179
RIP_MSG::file
uint8_t file[128]
No use.
Definition: dhcpv4.c:187
RIP_MSG::ciaddr
uint8_t ciaddr[4]
Request IP to DHCP sever
Definition: dhcpv4.c:181
DHCPv4_time_handler
void DHCPv4_time_handler(void)
Definition: dhcpv4.c:969
setSHAR
#define setSHAR(shar)
Definition: w6100.h:3595
default_ipv4_assign
void default_ipv4_assign(void)
DHCPV4_RUNNING
@ DHCPV4_RUNNING
Processing DHCP protocol.
Definition: dhcpv4.h:81
STATE_DHCPV4_STOP
#define STATE_DHCPV4_STOP
Stop processing DHCP.
Definition: dhcpv4.c:69
DHCPV4_SERVER_PORT
#define DHCPV4_SERVER_PORT
DHCP server port number.
Definition: dhcpv4.h:67
nameServer
@ nameServer
Definition: dhcpv4.c:110
routersOnSubnet
@ routersOnSubnet
Definition: dhcpv4.c:108
dhcpv4_state
int8_t dhcpv4_state
Definition: dhcpv4.c:206
DHCPV4_DISCOVER
#define DHCPV4_DISCOVER
DISCOVER message in OPT of RIP_MSG.
Definition: dhcpv4.c:79
DHCPV4_DECLINE
#define DHCPV4_DECLINE
DECLINE message in OPT of RIP_MSG.
Definition: dhcpv4.c:82
DHCPV4_OFFER
#define DHCPV4_OFFER
OFFER message in OPT of RIP_MSG.
Definition: dhcpv4.c:80
DHCPV4_SOCKET
uint8_t DHCPV4_SOCKET
Definition: dhcpv4.c:193
RIP_MSG::htype
uint8_t htype
DHCPV4_HTYPE10MB or DHCPV4_HTYPE100MB
Definition: dhcpv4.c:175
subnetMask
@ subnetMask
Definition: dhcpv4.c:106
STATE_DHCPV4_REREQUEST
#define STATE_DHCPV4_REREQUEST
send REQUEST for maintaining leased IP
Definition: dhcpv4.c:67
getSNfromDHCPv4
void getSNfromDHCPv4(uint8_t *ip)
Definition: dhcpv4.c:990
DHCPV4_CLIENT_PORT
#define DHCPV4_CLIENT_PORT
DHCP client port number.
Definition: dhcpv4.h:68
maxDgramReasmSize
@ maxDgramReasmSize
Definition: dhcpv4.c:127
NibbleToHex
char NibbleToHex(uint8_t nibble)
Definition: dhcpv4.c:1011
RIP_MSG::xid
uint32_t xid
DHCPV4_XID This increase one every DHCP transaction.
Definition: dhcpv4.c:178
STATE_DHCPV4_INIT
#define STATE_DHCPV4_INIT
Initialize.
Definition: dhcpv4.c:63
recvfrom
datasize_t recvfrom(uint8_t sn, uint8_t *buf, datasize_t len, uint8_t *addr, uint16_t *port, uint8_t *addrlen)
Receive datagram from a peer.
Definition: socket.c:441
dhcpClassIdentifier
@ dhcpClassIdentifier
Definition: dhcpv4.c:165
check_DHCPv4_leasedIP
int8_t check_DHCPv4_leasedIP(void)
Definition: dhcpv4.c:897
RIP_MSG::yiaddr
uint8_t yiaddr[4]
Offered IP from DHCP server
Definition: dhcpv4.c:182
RIP_MSG::chaddr
uint8_t chaddr[16]
DHCP client 6bytes MAC address. Others is filled to zero.
Definition: dhcpv4.c:185
OLD_allocated_ip
uint8_t OLD_allocated_ip[4]
Definition: dhcpv4.c:199