/*---------------------------------------------------------------------------*
 * Routine:  App_OverTheAirProgrammingPushMetheod
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into over the air programming mode in Push Method after connecting to an
 *      access point in infrastructure mode.
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_OverTheAirProgrammingPushMetheod(void)
{
    ATLIBGS_MSG_ID_E r;

    App_InitModule();

    while(1)
    {
       r = AtLibGs_GetMAC(WiFiMAC);
       if(r != ATLIBGS_MSG_ID_OK) 
       {
          DisplayLCD(LCD_LINE6, "Get MAC Failed!");
          MSTimerDelay(2000);
          continue;
       } 
       break;
    }; 
    
    if(r == ATLIBGS_MSG_ID_OK)
      AtLibGs_ParseGetMacResponse(WiFiMACStr);    
    strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID); 
    strcat(str_config_ssid, &WiFiMACStr[6]);                     // concatenate last 6 digis of MAC as SSID  
    
    App_StartupLimitedAP(str_config_ssid);
    
    r = AtLibGs_WebProv(",", ",");
    while(r != ATLIBGS_MSG_ID_OK) {
        DisplayLCD(LCD_LINE6, "Bad WebProv!");
        MSTimerDelay(2000);
        continue;
    }
    DisplayLCD(LCD_LINE6, "Download ON");   
    DisplayLCD(LCD_LINE7, (const uint8_t *) "192.168.240.");
    DisplayLCD(LCD_LINE8, (const uint8_t *) "1/otafu.html");  
    while(1)
      ;
}
/*---------------------------------------------------------------------------*
 * Routine:  WIFI_init
 *---------------------------------------------------------------------------*
 * Description:
 *      Initial setting + DHCP and show status on the LCD.
 *
 * Inputs:
 *      void
 * Outputs:
 *      ATLIBGS_MSG_ID_E
 *---------------------------------------------------------------------------*/
ATLIBGS_MSG_ID_E WIFI_init(int16_t showMessage)
{
  ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;
  char wifi_mac[20];

  // Check the link
#ifdef HOST_APP_DEBUG_ENABLE
  ConsolePrintf("Checking link\r\n");
#endif

  AtLibGs_Init();
  // Wait for the banner
  MSTimerDelay(500);

  // Send command to check
  do {
    AtLibGs_FlushIncomingMessage();
    DisplayLCD(LCD_LINE8, "Checking...");
    rxMsgId = AtLibGs_Check();
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);

  do {
    rxMsgId = AtLibGs_SetEcho(0);               // disable Echo
  }while (ATLIBGS_MSG_ID_OK != rxMsgId);

  do {
    rxMsgId = AtLibGs_Version();                // check the GS version
  }while (ATLIBGS_MSG_ID_OK != rxMsgId);

  // Get MAC Address & Show
  rxMsgId = AtLibGs_GetMAC(wifi_mac);
  if (rxMsgId == ATLIBGS_MSG_ID_OK)
    AtLibGs_ParseGetMacResponse(wifi_mac);
  memset(&wifi_mac[12], 0, 7);
  if (showMessage > 0) {
    DisplayLCD(LCD_LINE5, "MAC ADDRESS");
    DisplayLCD(LCD_LINE6, (const uint8_t *)wifi_mac);
    DisplayLCD(LCD_LINE2, (const uint8_t *)AppVersion);
    MSTimerDelay(2000);
    DisplayLCD(LCD_LINE2, "            ");
  }

  do {
    AtLibGs_FlushIncomingMessage();
    DisplayLCD(LCD_LINE8, "Disassociate");
    rxMsgId = AtLibGs_DisAssoc();
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);

  // Enable DHCP
  do {
    DisplayLCD(LCD_LINE8, "DHCP On...");
    rxMsgId = AtLibGs_DHCPSet(1);
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);

  if(strlen(GNV_Setting.webprov.ssid) > 0)
  {
    if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP)
    {
      do {
        DisplayLCD(LCD_LINE8, " Setting WEP");
        rxMsgId = AtLibGs_SetWEP1((int8_t*)GNV_Setting.webprov.password);
      } while (ATLIBGS_MSG_ID_OK != rxMsgId);
      DisplayLCD(LCD_LINE8, " WEP Set");
    }
    else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_PER)
    {
      do {
        DisplayLCD(LCD_LINE8, " Setting PSK");
        rxMsgId = AtLibGs_CalcNStorePSK(GNV_Setting.webprov.ssid, GNV_Setting.webprov.password);
      } while (ATLIBGS_MSG_ID_OK != rxMsgId); 
      DisplayLCD(LCD_LINE8, " PSK Set");
    }
    else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_ENT)
    {
      // Set AT+WAUTH=0 for WPA or WPA2
      do {
        DisplayLCD(LCD_LINE8, "       " );
        rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA);
      } while (ATLIBGS_MSG_ID_OK != rxMsgId);
      // Security Configuration
      do {
        DisplayLCD(LCD_LINE8, "Set Security");
        rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMAUTO);
      } while (ATLIBGS_MSG_ID_OK != rxMsgId);  
    }
  }
  else
  {
#ifdef HOST_APP_SEC_WEP
    // Set AT+WAUTH=2 for WEP
    do {
      DisplayLCD(LCD_LINE8, " WEP AUTH " );
      rxMsgId = AtLibGs_SetAuthentictionMode(2);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
    // Set WEP
    do {
      rxMsgId = AtLibGs_SetWEP1(HOST_APP_AP_SEC_WEP);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
    // Security Configuration
    do {
      rxMsgId = AtLibGs_SetSecurity(2);        // WEP
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_SEC_PSK
    // Store the PSK value. This call takes might take few seconds to return
    do {
      DisplayLCD(LCD_LINE8, "Setting PSK");
      rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_SEC_OPEN
    // Store the PSK value. This call takes might take few seconds to return
    do {
      DisplayLCD(LCD_LINE8, "No Security" );
      rxMsgId = AtLibGs_SetAuthentictionMode(1);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_WPA
    // Set AT+WAUTH=0 for WPA or WPA2
    do {
      DisplayLCD(LCD_LINE8, "   WPA   " );
      rxMsgId = AtLibGs_SetAuthentictionMode(0);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);

    // Store the PSK value. This call takes might take few seconds to return
    do {
      DisplayLCD(LCD_LINE8, "Setting PSK");
      rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);

    // Security Configuration
    do {
      DisplayLCD(LCD_LINE8, "   WPA   ");
      rxMsgId = AtLibGs_SetSecurity(4);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_WPA2
    // Set AT+WAUTH=0 for WPA or WPA2
    do {
      DisplayLCD(LCD_LINE8, "  WPA2   " );
      rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);

    // Store the PSK value. This call takes might take few seconds to return
    do {
      DisplayLCD(LCD_LINE8, "Setting PSK");
      rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);

    // Security Configuration
    do {
      DisplayLCD(LCD_LINE8, "  Set WPA  ");
      rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMWPA2PSK);
    } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif
  }
  // Clear MAC Address and show WIFI
  DisplayLCD(LCD_LINE6, "    WIFI   ");
  DisplayLCD(LCD_LINE5, "           ");

  return rxMsgId;
}
Exemplo n.º 3
0
ATLIBGS_MSG_ID_E WIFI_init(int16_t showMessage)
{
  ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;

 // Check the link
#ifdef HOST_APP_DEBUG_ENABLE
    ConsolePrintf("Checking link\r\n");
#endif

  AtLibGs_Init();
  // Wait for the banner
  MSTimerDelay(500);

  /* Send command to check */
  do {
    AtLibGs_FlushIncomingMessage();
    DisplayLCD(LCD_LINE4, "wl_check..  ");
    rxMsgId = AtLibGs_Check();
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);
   
  do {   
       rxMsgId = AtLibGs_SetEcho(0);               // disable Echo
  }while (ATLIBGS_MSG_ID_OK != rxMsgId);
  
  do {                                               
       rxMsgId = AtLibGs_Version();                // check the GS version
    }while (ATLIBGS_MSG_ID_OK != rxMsgId);
#if 0  
  if(strstr((const char *)MRBuffer, "2.3."))       // still debug why receive 2 extra bytes: ESC S
  {
    G_Extra2B = 2;
  }
#endif
  
  do{  
       rxMsgId = AtLibGs_EnableRadio(1);                       // enable radio
  }while(rxMsgId != ATLIBGS_MSG_ID_OK);
  
  /* Get MAC Address & Show */
  rxMsgId = AtLibGs_GetMAC(WiFiMAC);    
  if (rxMsgId == ATLIBGS_MSG_ID_OK)
    AtLibGs_ParseGetMacResponse(WifiMAC);
  if (showMessage > 0) {   
    DisplayLCD(LCD_LINE3, (const uint8_t *)WifiMAC);
    MSTimerDelay(2000);
  }
  
  do {
    AtLibGs_FlushIncomingMessage();
    DisplayLCD(LCD_LINE4, "wl_disass.. ");
    rxMsgId = AtLibGs_DisAssoc();
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);
    
    // Enable DHCP
  do { 
    DisplayLCD(LCD_LINE4, "wl_dhcpon.. ");
    rxMsgId = AtLibGs_DHCPSet(1);
  } while (ATLIBGS_MSG_ID_OK != rxMsgId);
 
  if(strlen(GNV_Setting.webprov.ssid) > 0)
  { 

    if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP)
    {
        do {
          DisplayLCD(LCD_LINE4, "wl_setwep.. ");
          rxMsgId = AtLibGs_SetWEP1((int8_t*)GNV_Setting.webprov.password);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId); 
        DisplayLCD(LCD_LINE4, "wl_wepset.. ");      
    }
    else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_PER)
    {
        do {
          DisplayLCD(LCD_LINE4, "wl_setpsk.. ");
          rxMsgId = AtLibGs_CalcNStorePSK(GNV_Setting.webprov.ssid, GNV_Setting.webprov.password);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId); 
        DisplayLCD(LCD_LINE4, "wl_pskset.. ");
    }
    else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_ENT)
    {
     /* Set AT+WAUTH=0 for WPA or WPA2  */
         do {
           DisplayLCD(LCD_LINE4, "       " );
           rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA);
         } while (ATLIBGS_MSG_ID_OK != rxMsgId);
       /* Security Configuration */
         do {
           DisplayLCD(LCD_LINE4, "wl_setsec.. ");
           rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMAUTO);
         } while (ATLIBGS_MSG_ID_OK != rxMsgId);  
     }
   }
   else
   {
#ifdef HOST_APP_SEC_WEP
        // Set AT+WAUTH=2 for WEP
        do {
          DisplayLCD(LCD_LINE4, "wl_wepauth.." );
          rxMsgId = AtLibGs_SetAuthentictionMode(2);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
        // Set WEP
        do {
          rxMsgId = AtLibGs_SetWEP1(HOST_APP_AP_SEC_WEP);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
          /* Security Configuration */
        do {
          rxMsgId = AtLibGs_SetSecurity(2);        // WEP
          } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif
    
#ifdef HOST_APP_SEC_PSK
        /* Store the PSK value. This call takes might take few seconds to return */
        do {
          DisplayLCD(LCD_LINE4, "wl_setpsk.. ");
          rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_SEC_OPEN
        /* Store the PSK value. This call takes might take few seconds to return */
        do {
          DisplayLCD(LCD_LINE4, "wl_nosec..  " );
          rxMsgId = AtLibGs_SetAuthentictionMode(1);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_WPA
        // Set AT+WAUTH=0 for WPA or WPA2
        do {
          DisplayLCD(LCD_LINE4, "wl_wpa..   " );
          rxMsgId = AtLibGs_SetAuthentictionMode(0);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
      
        /* Store the PSK value. This call takes might take few seconds to return */
        do {
          DisplayLCD(LCD_LINE4, "wl_setpsk.. ");
          rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);   
      
        /* Security Configuration */
        do {
          DisplayLCD(LCD_LINE4, "wl_wpa..    ");
          rxMsgId = AtLibGs_SetSecurity(4);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif

#ifdef HOST_APP_WPA2
        // Set AT+WAUTH=0 for WPA or WPA2
        do {
          DisplayLCD(LCD_LINE4, "wl_wpa2..   " );
          rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
          
        /* Store the PSK value. This call takes might take few seconds to return */
        do {
          DisplayLCD(LCD_LINE4, "wl_setpsk.. ");
          rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);   

        /* Security Configuration */
        do {
          DisplayLCD(LCD_LINE4, "wl_setwpa..  ");
          rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMWPA2PSK);
        } while (ATLIBGS_MSG_ID_OK != rxMsgId);
#endif
      }
  
  return rxMsgId;
}
/*---------------------------------------------------------------------------*
 * Routine:  App_StartupADKDemo
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into a limited AP mode, enable XML parse, and setup mDNS
 *      
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_StartupADKDemo(void)
{
    ATLIBGS_MSG_ID_E r;

   // DisplayLCD(LCD_LINE3, "Limited AP");
   // DisplayLCD(LCD_LINE4, ATLIBGS_LIMITED_AP_SSID);   
   // VirginCheck();   
#if 1                     
    DisplayLCD(LCD_LINE3, (const uint8_t *) "192.168.240.");
    DisplayLCD(LCD_LINE4, (const uint8_t *) "1/rdk.html");  
#else   
    DisplayLCD(LCD_LINE3, (const uint8_t *) "192.168.1.1/");
    DisplayLCD(LCD_LINE4, (const uint8_t *) "rdk.html"); 
#endif
    
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Starting Limited AP: %s\n", ATLIBGS_LIMITED_AP_SSID);
#endif

    /* Try to disassociate if not already associated */
    AtLibGs_DisAssoc();
    while (1) {
        DisplayLCD(LCD_LINE6, " Setting up");

        r =AtLibGs_EnableRadio(1);                       // enable radio
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad Mode!");
            MSTimerDelay(2000);
            continue;
        }  
#if 0
        r = AtLibGs_ConfigAntenna(1);
         if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Configure Antenna Fail!");
            MSTimerDelay(2000);
            continue;
        }
#endif
        r = AtLibGs_Mode(ATLIBGS_STATIONMODE_LIMITED_AP);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad Mode!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_IPSet(ATLIBGS_ADK_IP, ATLIBGS_ADK_MASK,
                ATLIBGS_ADK_GATEWAY);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad IP!");
            MSTimerDelay(2000);
            continue;
        }
        AtLibGs_DisableDHCPServer();
        r = AtLibGs_EnableDHCPServer();
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad DHCPSrv!");
            MSTimerDelay(2000);
            continue;
        }
 #if 0
        r = AtLibGs_SetRegulatoryDomain(ATLIBGS_REGDOMAIN_TELEC);
         if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Set Domain Fail");
            MSTimerDelay(2000);
            continue;
        }
#endif
         r = AtLibGs_GetMAC(WiFiMAC);
         if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Get MAC Failed!");
            MSTimerDelay(2000);
            continue;
        } 

        if(r == ATLIBGS_MSG_ID_OK)
           AtLibGs_ParseGetMacResponse(WiFiMACStr);

        strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID); 
        strcat(str_config_ssid, &WiFiMACStr[6]);                     // concatenate last 6 digis of MAC as SSID                          
        DisplayLCD(LCD_LINE1, (const uint8_t *)str_config_ssid);
        r = AtLibGs_Assoc(str_config_ssid /*ATLIBGS_ADK_SSID*/, 0,
                ATLIBGS_ADK_CHANNEL);
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "AP Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_WebServer(1, "", "", "", "");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Server Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_SetXMLParse(1);;
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "XML Failed!");
            MSTimerDelay(2000);
            continue;
        }
#if 1 // mDNS_ENABLED
        // now start mNDS service 
        r = AtLibGs_StartMDNS();
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "MDNS1 Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_RegisterMDNSHost("xyz","local");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "MDNS2 Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_RegisterMDNSService(ATLIBGS_ADK_MDNS_SERVER,"","_http","_tcp","local","80","path=/gainspan/profile/mcu");
      //  r = AtLibGs_RegisterMDNSService(ATLIBGS_ADK_MDNS_SERVER,"","_http","_tcp","local","80","path=/rdk.html");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "MDNS3 Failed!");
            MSTimerDelay(2000);
            continue;
        }
        r = AtLibGs_AnnounceMDNS();
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "MDNS4 Failed!");
            MSTimerDelay(2000);
            continue;
        }
#endif
        break;
    }
    DisplayLCD(LCD_LINE6, "");
    MSTimerDelay(2000);
    AtLibGs_FlushIncomingMessage();
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("ADK Demo Started\n");
#endif
}
/*---------------------------------------------------------------------------*
 * Routine:  App_WebProvisioning
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into web provisioning mode and wait for the user to
 *      connect with a web browser, change the settings, and click Save.
 *      The settings will then be parsed by the AtLibGs library and
 *      get saved into the nv settings.
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_WebProvisioning(void)
{
    ATLIBGS_MSG_ID_E r;

    /* At power up, load up the default settings */
    if(NVSettingsLoad(&G_nvsettings))
       NVSettingsSave(&G_nvsettings);
    
    App_InitModule();
    while(1)
    {
       r = AtLibGs_GetMAC(WiFiMAC);
       if(r != ATLIBGS_MSG_ID_OK) 
       {
          DisplayLCD(LCD_LINE6, "Get MAC Failed!");
          MSTimerDelay(2000);
          continue;
       } 
       break;
    }; 
    
    if(r == ATLIBGS_MSG_ID_OK)
      AtLibGs_ParseGetMacResponse(WiFiMACStr);    
    strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID); 
    strcat(str_config_ssid, &WiFiMACStr[6]);                     // concatenate last 6 digis of MAC as SSID  
    
    App_StartupLimitedAP(str_config_ssid);
    
    /* Before going into web provisioning, provide DNS to give a link. */
    /* The user can then go to http://webprov.gainspan.com/gsclient.html to get */
    /* access to the web provisioning screen. */
    while (1) {
#if 0
        AtLibGs_DisableDNSServer();
        r = AtLibGs_EnableDNSServer("webprov.gainspan.com");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad DNS!");
            MSTimerDelay(2000);
            continue;
        }
#endif
        r = AtLibGs_WebProv(",", ",");
        if (r != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE6, "Bad WebProv!");
            MSTimerDelay(2000);
            continue;
        }
        break;
    }
    DisplayLCD(LCD_LINE6, "WebProv ON");
    DisplayLCD(LCD_LINE7, (const uint8_t *) "192.168.240.");
    DisplayLCD(LCD_LINE8, (const uint8_t *) "1/prov.html");
#if 0
    do {
        DisplayLCD(LCD_LINE7, "IP: ???.???.");
        DisplayLCD(LCD_LINE8, "    ???.???");
        r = AtLibGs_GetNetworkStatus(&network_status);
    } while (ATLIBGS_MSG_ID_OK != r);

    sprintf(text, "IP: " _F8_ "." _F8_ ".",
            network_status.addr.ipv4[0], network_status.addr.ipv4[1]);
    DisplayLCD(LCD_LINE7, (uint8_t *)text);
    sprintf(text, "    " _F8_ "." _F8_, network_status.addr.ipv4[2],
            network_status.addr.ipv4[3]);
    DisplayLCD(LCD_LINE8, (uint8_t *)text);
#endif
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Web Provisioning ON\n");
#endif

    /* Now wait for a list of responses until we get a blank line */
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Waiting for web provisioning response...\n");
#endif
    AtLibGs_GetWebProvSettings(&G_nvsettings.webprov, 0);

    /* Save the above settings */
    NVSettingsSave(&G_nvsettings);
#ifdef ATLIBGS_DEBUG_ENABLE
    ConsolePrintf("Web provisioning complete.\n");
#endif

    DisplayLCD(LCD_LINE6, "WebProv Done");
    DisplayLCD(LCD_LINE7, "");
    DisplayLCD(LCD_LINE8, "Press RESET");
    while (1)
        {}
}