Browse Source

IAP: fix dhcp tries

balbekova 7 years ago
parent
commit
21144a1ef1
1 changed files with 14 additions and 15 deletions
  1. 14 15
      iap/Modules/Ethernet/netconf.c

+ 14 - 15
iap/Modules/Ethernet/netconf.c

@@ -1,6 +1,9 @@
 /* Includes ------------------------------------------------------------------*/
 /* Includes ------------------------------------------------------------------*/
 #include "lwip/mem.h"
 #include "lwip/mem.h"
 #include "lwip/memp.h"
 #include "lwip/memp.h"
+#include "lwip/tcp.h"
+#include "lwip/udp.h"
+#include "netif/etharp.h"
 #include "lwip/dhcp.h"
 #include "lwip/dhcp.h"
 #include "ethernetif.h"
 #include "ethernetif.h"
 #include "tcpip.h"
 #include "tcpip.h"
@@ -8,11 +11,10 @@
 #include "netconf.h"
 #include "netconf.h"
 #include "common_config.h"
 #include "common_config.h"
 #include "settings_api.h"
 #include "settings_api.h"
-#include "netconf.h"
 #include "tinystdio.h"
 #include "tinystdio.h"
 #include "lwip/init.h"
 #include "lwip/init.h"
 #include "lwip/timeouts.h"
 #include "lwip/timeouts.h"
-#include "netif/etharp.h"
+#include "lwip/sys.h"
 
 
 /* Private typedef -----------------------------------------------------------*/
 /* Private typedef -----------------------------------------------------------*/
 #define MAX_DHCP_TRIES        4
 #define MAX_DHCP_TRIES        4
@@ -146,14 +148,15 @@ void LwIP_Pkt_Handle(void)
   */
   */
 void LwIP_Periodic_Handle(__IO uint32_t localtime)
 void LwIP_Periodic_Handle(__IO uint32_t localtime)
 {
 {
+
   if (sSettings.sWebParams.dhcpEnable)
   if (sSettings.sWebParams.dhcpEnable)
   {
   {
     /* Fine DHCP periodic process every 500ms */
     /* Fine DHCP periodic process every 500ms */
 
 
-      if ((DHCP_state != DHCP_ADDRESS_ASSIGNED)&&(DHCP_state != DHCP_TIMEOUT)) {
-        /* process DHCP state machine */
-        LwIP_DHCP_Process_Handle();    
-      }
+	  if ((DHCP_state != DHCP_ADDRESS_ASSIGNED)&&(DHCP_state != DHCP_TIMEOUT)) {
+		/* process DHCP state machine */
+		LwIP_DHCP_Process_Handle();
+	  }
   }
   }
 
 
   sys_check_timeouts();
   sys_check_timeouts();
@@ -169,7 +172,7 @@ void LwIP_DHCP_Process_Handle()
   struct ip4_addr ipaddr;
   struct ip4_addr ipaddr;
   struct ip4_addr netmask;
   struct ip4_addr netmask;
   struct ip4_addr gw;
   struct ip4_addr gw;
-  static uint8_t dhcpTry = 0;
+  struct dhcp *dhcp = netif_dhcp_data(&netif);
 
 
   switch (DHCP_state)
   switch (DHCP_state)
   {
   {
@@ -208,20 +211,16 @@ void LwIP_DHCP_Process_Handle()
 
 
       } else {
       } else {
         /* DHCP timeout */
         /* DHCP timeout */
-        if (dhcpTry++ > MAX_DHCP_TRIES)
+        if (dhcp->tries > MAX_DHCP_TRIES)
 		{
 		{
           DHCP_state = DHCP_TIMEOUT;
           DHCP_state = DHCP_TIMEOUT;
 
 
           /* Stop DHCP */
           /* Stop DHCP */
           dhcp_stop(&netif);
           dhcp_stop(&netif);
 
 
-//		  ipaddr.addr = ipaddr_addr(sSettings.sWebTempParams.ip);
-//	      netmask.addr = ipaddr_addr(sSettings.sWebTempParams.mask);
-//	      gw.addr = ipaddr_addr(sSettings.sWebTempParams.gate);
-          
-          ipaddr.addr = ipaddr_addr("192.168.14.48");
-          netmask.addr = ipaddr_addr("255.255.255.0");
-          gw.addr = ipaddr_addr("192.168.14.1");
+		  ipaddr.addr = ipaddr_addr(sSettings.sWebTempParams.ip);
+	      netmask.addr = ipaddr_addr(sSettings.sWebTempParams.mask);
+	      gw.addr = ipaddr_addr(sSettings.sWebTempParams.gate);
 
 
           netif_set_addr(&netif, &ipaddr , &netmask, &gw);
           netif_set_addr(&netif, &ipaddr , &netmask, &gw);