/*---------------------------------------------------------------------------*
 * Routine:  App_OverTheAirProgramming
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into over the air programming mode after connecting to an
 *      access point in infrastructure mode.
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_OverTheAirProgramming(void)
{
    char buf[12] = "           ";
    int i;

    /* OTA Firmware update demo */
    /* Connect to AP first, then do FW upgrade with PC application */
    AtLibGs_Mode(ATLIBGS_STATIONMODE_INFRASTRUCTURE); /* set to connect to AP mode */
    AtLibGs_DHCPSet(1); /* turn on DHCP client */
    AtLibGs_SetPassPhrase(ATLIBGS_AP_SEC_PSK);
    AtLibGs_Assoc(ATLIBGS_AP_SSID, 0, 0);
    AtLibGs_EnableRadio(1); /* radio always on */

    DisplayLCD(LCD_LINE6, "Start Update");
    DisplayLCD(LCD_LINE7, "on server IP");
    /* print last 12 (of 15) char of server IP address */

    for (i = 0; i < 12; i++) {
        buf[i] = (char)ATLIBGS_FWUPGRADE_SERVER[i + 3];
    }
    DisplayLCD(LCD_LINE8, (uint8_t *)buf);

    /* start FW update on remote port 8010 with 100 retries */
    AtLibGs_FWUpgrade(ATLIBGS_FWUPGRADE_SERVER, 8010, 3000, "100");
}
/**
*  @brief Start provisioning
*
*  Used to start Limited Access Point
*
*  @param  AP ssid
*  @param  AP WiFi channel
*  @param  AP Host IP (string)
*  @param  AP Host subnet mask (string)
*  @param  AP Host name
*
*  @return True if successful
*/
bool GS_API_StartProvisioning(char* provSsid, char* provChannel, char* ip,
								char* subnetMask, char* hostName) {

	 GS_Api_SetResponseTimeoutHandle(TIMEOUT_RESPONSE_INTERVAL_HIGH);

     // Disable DHCP
     if (!gs_api_handle_cmd_resp(AtLibGs_DHCPSet(0)))
          return false;

     // Set Static IP
     if (!gs_api_handle_cmd_resp(
              AtLibGs_IPSet((int8_t*) ip, (int8_t*) subnetMask, (int8_t*) ip)))
          return false;

     // Enable DHCP Server
     if (!gs_api_handle_cmd_resp(AtLibGs_SetDHCPServerMode(1)))
    	 return false;

     // Enable Limited AP
     if (!gs_api_handle_cmd_resp(AtLibGs_Mode(2)))
          return false;

     // Set SSID and Channel
     if (!gs_api_handle_cmd_resp(
              AtLibGs_Assoc((int8_t*) provSsid, (int8_t*) "",
                            (int8_t*) provChannel)))
          return false;

     /* Reset the receive buffer */
     AtLib_FlushRxBuffer();

     GS_Api_SetResponseTimeoutHandle(TIMEOUT_RESPONSE_INTERVAL_LOW);

     return true;
}
/**
*  @brief  Join WiFi netwrk
*
*  @param  Network Configuration struct
*
*  @return True if successfully joined
*/
bool GS_API_JoinWiFiNetwork(HOST_APP_NETWORK_CONFIG_T* apiNetCfg){
	bool joined = false;
	unsigned int response_timeout_temp;

	response_timeout_temp = GS_Api_GetResponseTimeoutHandle();
	GS_Api_SetResponseTimeoutHandle(TIMEOUT_RESPONSE_INTERVAL_HIGH);

	AtLib_FlushIncomingMessage();
	// Associate
	if(gs_api_handle_cmd_resp(AtLibGs_Assoc((int8_t *) apiNetCfg->ssid,(int8_t*)"", (int8_t *) apiNetCfg->channel)))
	{
	     if (gs_api_handle_cmd_resp(AtLibGs_DHCPSet(1)))
	     {
	    	 char ip[16];

	    	 if (AtLib_ParseWlanConnIp((uint8_t *) ip) == true)
	    		 joined = true;
	     }
	     // Clear all data handler functions
	     memset(cidDataHandlers, 0, sizeof(cidDataHandlers));
	}

	GS_Api_SetResponseTimeoutHandle(response_timeout_temp);
	return joined;
}
/*---------------------------------------------------------------------------*
 * Routine:  App_StartWPS
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the unit into WPS pushbutton mode. After pushing the button on the 
 *      AP the unit will retrieve its SSID and pass phrase, then connect to it
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void App_StartWPS(void)
{
    ATLIBGS_MSG_ID_E rxMsgId;
    ATLIBGS_NetworkStatus network;
    AtLibGs_WPSResult result;
    char text[20];
    
    while (1) {
        // Ensure we are not connected to any network (from previous runs)
        AtLibGs_DisAssoc();

        /* Pushbutton WPS demo */
        /* Use Wi-Fi Protected Setup (WPS) FW */
        /* turn on DHCP client */
        AtLibGs_DHCPSet(1);

        /* set to connect to AP mode */
        AtLibGs_Mode(ATLIBGS_STATIONMODE_INFRASTRUCTURE);
        DisplayLCD(LCD_LINE5, "  Push the  ");
        DisplayLCD(LCD_LINE6, "button on AP");

        /* push the button on the AP so the GS module can connect */
        while (AtLibGs_StartWPSPUSH(&result) != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE8, " Not found!");
            MSTimerDelay(1000);
            DisplayLCD(LCD_LINE8, " Retrying...");
            MSTimerDelay(1000);
            DisplayLCD(LCD_LINE8, "");
        }

        /* Connect to AP (found from pushbutton) after setting pass phrase */
        AtLibGs_SetPassPhrase(result.password);
        AtLibGs_Assoc(result.ssid, "", result.channel);

        rxMsgId = AtLibGs_GetNetworkStatus(&network);
        if (rxMsgId != ATLIBGS_MSG_ID_OK) {
            DisplayLCD(LCD_LINE8, "Bad Network!");
            MSTimerDelay(2000);
            DisplayLCD(LCD_LINE8, "");
            continue;
        } else {
            strncpy(text, network.ssid, 12);
            DisplayLCD(LCD_LINE4, (const uint8_t *)text);
        }
        break;
    }

    DisplayLCD(LCD_LINE5, "");
    DisplayLCD(LCD_LINE6, "");
}
Esempio n. 5
0
void GS_API_StartProvisioning(char* provSsid, char* provChannel, char* username,
                              char* password, char* ip, char* subnetMask, char* hostName) {


     // Disable DHCP
     if (!gs_api_handle_cmd_resp(AtLibGs_DHCPSet(0)))
          return;

     // Set Static IP
     if (!gs_api_handle_cmd_resp(
              AtLibGs_IPSet((int8_t*) ip, (int8_t*) subnetMask, (int8_t*) ip)))
          return;

     // Enable Limited AP
     if (!gs_api_handle_cmd_resp(AtLibGs_Mode(2)))
          return;

     // Set SSID and Channel
     if (!gs_api_handle_cmd_resp(
              AtLibGs_Assoc((int8_t*) provSsid, (int8_t*) "",
                            (int8_t*) provChannel)))
          return;

     // Enable DHCP Server
     gs_api_handle_cmd_resp(AtLibGs_SetDHCPServerMode(1));

     // Enable DNS Server
     //if (!gs_api_handle_cmd_resp(AtLibGs_SetDNSServerMode(1, hostName)))
     //     return;

     if (!gs_api_handle_cmd_resp(AtLibGs_BData (1)))
		return;
     // Enable Provisioning
     //if (!gs_api_handle_cmd_resp(AtLibGs_StartProv(username, password)))
     //     return;

     //GS_API_Printf("Prov Up SSID:%s", provSsid);
     //GS_API_Printf("%s/gsclient.html", ip);

     /* Reset the receive buffer */
     AtLib_FlushRxBuffer();

}
/*---------------------------------------------------------------------------*
 * 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;
}
Esempio n. 7
0
bool GS_API_JoinNetwork() {
     bool joined = false;
     uint8_t security = atoi(apiNetworkConfig.security);
     // Set all the configuration options

     // Check for DHCP Enabled
     if (atoi(apiNetworkConfig.dhcpEnabled)) {
          if (!gs_api_handle_cmd_resp(AtLibGs_DHCPSet(1)))
               return joined;
     } else {
          if (!gs_api_handle_cmd_resp(AtLibGs_DHCPSet(0)))
               return joined;

          if (!gs_api_handle_cmd_resp(
                   AtLibGs_IPSet((int8_t*)apiNetworkConfig.staticIp,
                                 (int8_t*)apiNetworkConfig.subnetMask,
                                 (int8_t*)apiNetworkConfig.gatewayIp)))
               return joined;
     }

     // Check security
     switch (security) {
     case 0:
          // Set all
          // Don't check these since some might not be valid anyway
          AtLibGs_SetPassPhrase((int8_t*)apiNetworkConfig.passphrase);

          AtLibGs_SetWepKey(atoi(apiNetworkConfig.wepId), apiNetworkConfig.wepKey);


          AtLibGs_SetAuthMode(0);
          break;

     case 1:
          // Set none
          break;

     case 2:
          // Set WEP
          if (!gs_api_handle_cmd_resp(
                   AtLibGs_SetWepKey(atoi(apiNetworkConfig.wepId),
                                     apiNetworkConfig.wepKey)))
               return joined;

          if (!gs_api_handle_cmd_resp(AtLibGs_SetAuthMode(0)))
               return joined;
          break;

     case 4:
     case 8:
     case 16:
     case 32:
     case 64:
          // Set WPA
          if (!gs_api_handle_cmd_resp(AtLibGs_SetPassPhrase((int8_t*)apiNetworkConfig.passphrase)))
               return joined;
          break;

     default:
          // nothing
          break;
     }

     // Set the security mode
     if(!gs_api_handle_cmd_resp(AtLibGs_SetSecurity(security)))
          return joined;

     // Set adhoc or infrastructure
     if(!gs_api_handle_cmd_resp(AtLibGs_Mode(atoi(apiNetworkConfig.connType))))
          return joined;


     // Associate
     if(gs_api_handle_cmd_resp(AtLibGs_Assoc((int8_t*)apiNetworkConfig.ssid,(int8_t*)"", (int8_t*)apiNetworkConfig.channel))){
          joined = true;
          // Clear all data handler functions
          memset(cidDataHandlers, 0, sizeof(cidDataHandlers));
     }

     return joined;
}
Esempio n. 8
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;
}
/**
*  @brief  Set up WiFi network
*
*  initialize and set up WiFi parameters for desired WiFi network
*
*  @param  Network Configuration struct
*
*  @return True if successful
*/
bool GS_API_SetupWifiNetwork(HOST_APP_NETWORK_CONFIG_T* apiNetCfg) {
     bool set = false;
     uint8_t security = atoi(apiNetCfg->security);
     // Set all the configuration options

     // Check for DHCP Enabled
     if (atoi(apiNetCfg->dhcpEnabled)) {
          if (!gs_api_handle_cmd_resp(AtLibGs_DHCPSet(1)))
          {
        	  return set;
          }
     } else {
          if (!gs_api_handle_cmd_resp(AtLibGs_DHCPSet(0)))
               return set;

          if (!gs_api_handle_cmd_resp(
                   AtLibGs_IPSet((int8_t *) apiNetCfg->staticIp,
                                 (int8_t *) apiNetCfg->subnetMask,
                                 (int8_t *) apiNetCfg->gatewayIp)))
               return set;
     }

     // Check security
     switch (security) {
     case 0:
          // Set all
          // Don't check these since some might not be valid anyway
          if (!gs_api_handle_cmd_resp(
        		  AtLibGs_SetPassPhrase((int8_t *) apiNetCfg->passphrase)))
        	  return set;

          if (!gs_api_handle_cmd_resp(AtLibGs_SetAuthMode(0)))
        	  return set;
          break;

     case 1:
          // Set none
          break;

     case 2:
          // Set WEP
          if (!gs_api_handle_cmd_resp(
                   AtLibGs_SetWepKey(atoi(apiNetCfg->wepId),
                		   	   	   	   	   apiNetCfg->wepKey)))
               return set;

          if (!gs_api_handle_cmd_resp(AtLibGs_SetAuthMode(0)))
               return set;
          break;

     case 4:
     case 8:
     case 16:
     case 32:
     case 64:
          // Set WPA
          if (!gs_api_handle_cmd_resp(AtLibGs_SetPassPhrase((int8_t *) apiNetCfg->passphrase)))
               return set;
          break;

     default:
          // nothing
          break;
     }

     // Set the security mode
     if(!gs_api_handle_cmd_resp(AtLibGs_SetSecurity(security)))
          return set;

     // Set adhoc or infrastructure
     if(!gs_api_handle_cmd_resp(AtLibGs_Mode(atoi(apiNetCfg->connType))))
          return set;

     return set;
}