dhcp debugging
This commit is contained in:
@ -56,7 +56,8 @@
|
||||
/* If you want to display debug & processing message, Define _DHCP_DEBUG_ in dhcp.h */
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
#include <stdio.h>
|
||||
//#include <stdio.h>
|
||||
int logMsg(const char *format, ...);
|
||||
#endif
|
||||
|
||||
/* DHCP state machine. */
|
||||
@ -417,7 +418,7 @@ void send_DHCP_DISCOVER(void)
|
||||
ip[3] = 255;
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("> Send DHCP_DISCOVER\r\n");
|
||||
logMsg("> Send DHCP_DISCOVER\r\n");
|
||||
#endif
|
||||
|
||||
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
||||
@ -515,7 +516,7 @@ void send_DHCP_REQUEST(void)
|
||||
for (i = k; i < OPT_SIZE; i++) pDHCPMSG->OPT[i] = 0;
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("> Send DHCP_REQUEST\r\n");
|
||||
logMsg("> Send DHCP_REQUEST\r\n");
|
||||
#endif
|
||||
|
||||
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
||||
@ -576,7 +577,7 @@ void send_DHCP_DECLINE(void)
|
||||
ip[3] = 0xFF;
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("\r\n> Send DHCP_DECLINE\r\n");
|
||||
logMsg("\r\n> Send DHCP_DECLINE\r\n");
|
||||
#endif
|
||||
|
||||
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
|
||||
@ -598,7 +599,7 @@ int8_t parseDHCPMSG(void)
|
||||
{
|
||||
len = recvfrom(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port);
|
||||
#ifdef _DHCP_DEBUG_
|
||||
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);
|
||||
logMsg("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);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
@ -611,7 +612,7 @@ int8_t parseDHCPMSG(void)
|
||||
(pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5]) )
|
||||
{
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("No My DHCP Message. This message is ignored.\r\n");
|
||||
logMsg("No My DHCP Message. This message is ignored.\r\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -621,7 +622,7 @@ int8_t parseDHCPMSG(void)
|
||||
((svr_addr[0]!=DHCP_REAL_SIP[0])|| (svr_addr[1]!=DHCP_REAL_SIP[1])|| (svr_addr[2]!=DHCP_REAL_SIP[2])|| (svr_addr[3]!=DHCP_REAL_SIP[3])) )
|
||||
{
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("Another DHCP sever send a response message. This is ignored.\r\n");
|
||||
logMsg("Another DHCP sever send a response message. This is ignored.\r\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -730,7 +731,7 @@ uint8_t DHCP_run(void)
|
||||
case STATE_DHCP_DISCOVER :
|
||||
if (type == DHCP_OFFER){
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("> Receive DHCP_OFFER\r\n");
|
||||
logMsg("> Receive DHCP_OFFER\r\n");
|
||||
#endif
|
||||
DHCP_allocated_ip[0] = pDHCPMSG->yiaddr[0];
|
||||
DHCP_allocated_ip[1] = pDHCPMSG->yiaddr[1];
|
||||
@ -746,7 +747,7 @@ uint8_t DHCP_run(void)
|
||||
if (type == DHCP_ACK) {
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("> Receive DHCP_ACK\r\n");
|
||||
logMsg("> Receive DHCP_ACK\r\n");
|
||||
#endif
|
||||
if (check_DHCP_leasedIP()) {
|
||||
// Network info assignment from DHCP
|
||||
@ -763,7 +764,7 @@ uint8_t DHCP_run(void)
|
||||
} else if (type == DHCP_NAK) {
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("> Receive DHCP_NACK\r\n");
|
||||
logMsg("> Receive DHCP_NACK\r\n");
|
||||
#endif
|
||||
|
||||
reset_DHCP_timeout();
|
||||
@ -777,7 +778,7 @@ uint8_t DHCP_run(void)
|
||||
if ((dhcp_lease_time != INFINITE_LEASETIME) && ((dhcp_lease_time/2) < dhcp_tick_1s)) {
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("> Maintains the IP address \r\n");
|
||||
logMsg("> Maintains the IP address \r\n");
|
||||
#endif
|
||||
|
||||
type = 0;
|
||||
@ -808,19 +809,19 @@ uint8_t DHCP_run(void)
|
||||
ret = DHCP_IP_CHANGED;
|
||||
dhcp_ip_update();
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf(">IP changed.\r\n");
|
||||
logMsg(">IP changed.\r\n");
|
||||
#endif
|
||||
|
||||
}
|
||||
#ifdef _DHCP_DEBUG_
|
||||
else printf(">IP is continued.\r\n");
|
||||
else logMsg(">IP is continued.\r\n");
|
||||
#endif
|
||||
reset_DHCP_timeout();
|
||||
dhcp_state = STATE_DHCP_LEASED;
|
||||
} else if (type == DHCP_NAK) {
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("> Receive DHCP_NACK, Failed to maintain ip\r\n");
|
||||
logMsg("> Receive DHCP_NACK, Failed to maintain ip\r\n");
|
||||
#endif
|
||||
|
||||
reset_DHCP_timeout();
|
||||
@ -850,18 +851,18 @@ uint8_t check_DHCP_timeout(void)
|
||||
|
||||
switch ( dhcp_state ) {
|
||||
case STATE_DHCP_DISCOVER :
|
||||
// printf("<<timeout>> state : STATE_DHCP_DISCOVER\r\n");
|
||||
// logMsg("<<timeout>> state : STATE_DHCP_DISCOVER\r\n");
|
||||
send_DHCP_DISCOVER();
|
||||
break;
|
||||
|
||||
case STATE_DHCP_REQUEST :
|
||||
// printf("<<timeout>> state : STATE_DHCP_REQUEST\r\n");
|
||||
// logMsg("<<timeout>> state : STATE_DHCP_REQUEST\r\n");
|
||||
|
||||
send_DHCP_REQUEST();
|
||||
break;
|
||||
|
||||
case STATE_DHCP_REREQUEST :
|
||||
// printf("<<timeout>> state : STATE_DHCP_REREQUEST\r\n");
|
||||
// logMsg("<<timeout>> state : STATE_DHCP_REREQUEST\r\n");
|
||||
|
||||
send_DHCP_REQUEST();
|
||||
break;
|
||||
@ -914,7 +915,7 @@ int8_t check_DHCP_leasedIP(void)
|
||||
// UDP send Timeout occurred : allocated IP address is unique, DHCP Success
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("\r\n> Check leased IP - OK\r\n");
|
||||
logMsg("\r\n> Check leased IP - OK\r\n");
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
|
@ -55,7 +55,7 @@ extern "C" {
|
||||
* @details If you want to display debug & processing message, Define _DHCP_DEBUG_
|
||||
* @note If defined, it depends on <stdio.h>
|
||||
*/
|
||||
//#define _DHCP_DEBUG_
|
||||
#define _DHCP_DEBUG_
|
||||
|
||||
|
||||
/* Retry to processing DHCP */
|
||||
|
Reference in New Issue
Block a user