/**
*  @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;
}
/**
*  @brief  Set up keep alive socket options for desired socket
*
*  @param  Connection id
*  @param  Keep alive in seconds
*
*  @return True if successful
*/
bool GS_Api_SetUpSocket_TcpKeepAlive(uint8_t cid, uint32_t keepalive){

	if (!gs_api_handle_cmd_resp(AtLib_SetSocketOptions(cid, ATLIB_SOCKET_OPTION_TYPE_SOCK, ATLIB_SOCKET_OPTION_PARAM_SO_KEEPALIVE, 1)))
		return false;

	if (!gs_api_handle_cmd_resp(AtLib_SetSocketOptions(cid, ATLIB_SOCKET_OPTION_TYPE_TCP, ATLIB_SOCKET_OPTION_PARAM_TCP_KEEPALIVE_COUNT, 1)))
		return false;

	return gs_api_handle_cmd_resp(AtLib_SetSocketOptions(cid, ATLIB_SOCKET_OPTION_TYPE_TCP, ATLIB_SOCKET_OPTION_PARAM_TCP_KEEPALIVE, keepalive));
}
/**
*  @brief  Create Tcp Server Connection
*
*  @param  Host port (string)
*  @param  Function pointer to data handler function
*
*  @return Connection id
*/
uint8_t GS_API_CreateTcpServerConnection(char* port, GS_API_DataHandler cidDataHandler){
     uint8_t cidStr[] = " ";
     uint16_t cid = GS_API_INVALID_CID;
 	 unsigned int response_timeout_temp;

   	 response_timeout_temp = GS_Api_GetResponseTimeoutHandle();
 	 GS_Api_SetResponseTimeoutHandle(TIMEOUT_RESPONSE_INTERVAL_HIGH);

     if(!gs_api_handle_cmd_resp(AtLibGs_TcpServer_Start((int8_t*)port)))
     {
    	  GS_Api_SetResponseTimeoutHandle(response_timeout_temp);
          return cid;
     }

     if(AtLib_ParseTcpServerStartResponse(cidStr)){
          // need to convert from ASCII to numeric
          cid = gs_api_parseCidStr(cidStr);
          if(cid != GS_API_INVALID_CID){
               cidDataHandlers[cid] = cidDataHandler;
          }
     }

     GS_Api_SetResponseTimeoutHandle(response_timeout_temp);
     return cid;
}
/**
*  @brief  Returns system time from GS module
*
*  Calls AT+GETTIME=? command and parses response.
*
*  @param  Return time string. Time will be in milliseconds since epoch
*
*  @return True if successful
*/
bool GS_Api_GetSystemTime(char* timeStr){

	if (gs_api_handle_cmd_resp(AtLib_GetTime()))
		if (AtLib_ParseSystemTime(timeStr) == 1)
		{
			return true;
		}
	return false;
}
/**
*  @brief  Open SSL secured connection
*
*  Calls AT+SSLOPEN=<cid>,<cert name> command, and parses standard response.
*  Open SSL secured connection on desired tcp socket
*
*  @param  Connection id
*  @param  Certificate name
*
*  @return True if successful
*/
bool GS_API_OpenSSLconnection(uint8_t cid, uint8_t* cert_name){
	unsigned int response_timeout_temp;
	bool result;

 	response_timeout_temp = GS_Api_GetResponseTimeoutHandle();
	GS_Api_SetResponseTimeoutHandle(TIMEOUT_RESPONSE_INTERVAL_HIGH);

	result = gs_api_handle_cmd_resp(AtLib_SSLOpen(cid, (char*) cert_name));
	GS_Api_SetResponseTimeoutHandle(response_timeout_temp);

	return result;
}
Esempio n. 7
0
uint8_t GS_API_CreateUdpClientConnection(char* serverIp, char* serverPort, char* localPort, GS_API_DataHandler cidDataHandler){
     uint8_t cidStr[] = " ";
     uint16_t cid = GS_API_INVALID_CID;

     if(!gs_api_handle_cmd_resp(AtLibGs_UdpClientStart((int8_t*) serverIp, (int8_t*) serverPort, (int8_t*) localPort)))
          return cid;

     if(AtLib_ParseUdpServerStartResponse(cidStr)){
          // need to convert from ASCII to numeric
          cid = gs_api_parseCidStr(cidStr);
          if(cid != GS_API_INVALID_CID){
               cidDataHandlers[cid] = cidDataHandler;
          }
     }

     return cid;
}
Esempio n. 8
0
uint8_t GS_API_CreateTcpServerConnection(char* port, GS_API_DataHandler cidDataHandler){
     uint8_t cidStr[] = " ";
     uint16_t cid = GS_API_INVALID_CID;

     if(!gs_api_handle_cmd_resp(AtLibGs_TcpServer_Start((int8_t*)port))) {
          return cid;
	}
   
     if(AtLib_ParseTcpServerStartResponse(cidStr)){
          // need to convert from ASCII to numeric
          cid = gs_api_parseCidStr(cidStr);
          if(cid != GS_API_INVALID_CID){
               cidDataHandlers[cid] = cidDataHandler;
         }
     }
  
     return cid;
}
/**
*  @brief  Open http client connection
*
*  Calls AT+HTTPOPEN=<host >[, <Port Number>, <SSL Flag>, <certificate name>,<proxy>,<Connection Timeout>,<client certificate name>,<client key name>]
*  command in order to open http client connection.
*  Parses for OK response from GS module and returns connection id.
*
*  @param  Host ip string
*  @param  Host port
*  @param  Function pointer to data handler
*
*  @return Connection id
*/
uint8_t GS_Api_HttpClientOpen(char* host, int hostPort, GS_API_DataHandler cidDataHandler){
    uint8_t cid = GS_API_INVALID_CID;
	 unsigned int response_timeout_temp;

  	 response_timeout_temp = GS_Api_GetResponseTimeoutHandle();
	 GS_Api_SetResponseTimeoutHandle(TIMEOUT_RESPONSE_INTERVAL_HIGH);

	if (!gs_api_handle_cmd_resp(AtLibGs_HTTPOpen(host, hostPort, &cid)))
	{
		GS_Api_SetResponseTimeoutHandle(response_timeout_temp);
		return GS_API_INVALID_CID;
	}
	if (GS_Api_IsCidValid(cid))
		cidDataHandlers[cid] = cidDataHandler;

	GS_Api_SetResponseTimeoutHandle(response_timeout_temp);
    return cid;
}
Esempio n. 10
0
uint8_t GS_API_CreateTcpClientConnection(char* serverIp, char* serverPort, GS_API_DataHandler cidDataHandler){
     uint8_t cidStr[] = " ";
     uint16_t cid = GS_API_INVALID_CID;

     if(!gs_api_handle_cmd_resp(AtLibGs_TcpClientStart((int8_t*) serverIp, (int8_t*) serverPort))) {
	  printf("ERROR: WIFI TCP CLIENT SETUP ERROR.\n");
          return cid;
	}

     if(AtLib_ParseTcpServerStartResponse(cidStr)){
          // need to convert from ASCII to numeric
          cid = gs_api_parseCidStr(cidStr);
          if(cid != GS_API_INVALID_CID){
               cidDataHandlers[cid] = cidDataHandler;
          }
     }

     return cid;
}
Esempio n. 11
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();

}
Esempio n. 12
0
bool GS_API_IsAssociated(void){
     if (!gs_api_handle_cmd_resp(AtLibGs_WlanConnStat()))
          return false;

     return AtLib_ParseWlanConnStat();
}
Esempio n. 13
0
void GS_API_StopProvisioning(void){
     // Web client can't be shut off, so just reset the device
     gs_api_handle_cmd_resp(AtLibGs_Reset());     
}
bool GS_Api_EnableSoftFlowControl(char mode){
	return (gs_api_handle_cmd_resp(AtLib_EnableSoftFlowControl((uint32_t) mode)));
}
/**
*  @brief  Set Gpio output pins on GS module (drive led)
*
*  Calls AT+DGPIO=<GPIO-NO>,<SET/RESET(0/1) command and parses standard response
*
*  @param  GPIO number
*  @param  GPIO state
*
*  @return True if successful
*/
static bool GS_Api_GpioSetState( ATLIB_GPIO_PIN_E gpio, ATLIB_GPIO_STATE_E state ){
	return (gs_api_handle_cmd_resp(AtLib_SetGPIO(gpio, state)));
}
/**
*  @brief  Close http client connection
*
*  Calls AT+HTTPCLOSE=<CID> command, and parses standard response.
*  Will close http connection with desired cid.
*
*  @param  Connection id
*
*  @return True if successful
*/
bool GS_Api_HttpCloseConn(uint8_t cid){
	return (gs_api_handle_cmd_resp(AtLib_HTTPClose(cid)));
}
/**
*  @brief  Load certificate into GS module
*
*  Calls AT+TCERTADD=<Name>,<Format>,<Size>,<Location><CR><ESC>W<data of size above> command,
*  and parses standard response.
*  Load desired certificate with desired name into GS module
*
*  @param  Desired cert name
*  @param  Certificate size
*  @param  Certificate array
*
*  @return True if successful
*/
bool GS_API_LoadCertificate(uint8_t* cert_name, uint32_t cert_size, uint8_t* cacert){
	return gs_api_handle_cmd_resp(AtLib_AddSSLCertificate((char *) cert_name, 0 /*binary*/, cert_size, 1 /*RAM*/, (char *) cacert));
}
/**
*  @brief  Http config function
*
*  Calls AT+HTTPCONF=<Param>,<Value> command and parses standard response
*
*  @param  Http parameter type
*  @param  Parameter string
*
*  @return True if successful
*/
bool GS_Api_HttpClientConfig(int parm, char* val){

	return (gs_api_handle_cmd_resp(AtLib_HTTPConf(parm, val)));
}
/**
*  @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;
}
/**
*  @brief  Set up max retries socket options for desired socket
*
*  @param  Connection id
*  @param  Max retries in seconds
*
*  @return True if successful
*/
bool GS_Api_SetUpSocket_MaxRT(uint8_t cid, uint32_t max_rt){

	return gs_api_handle_cmd_resp(AtLib_SetSocketOptions(cid, ATLIB_SOCKET_OPTION_TYPE_TCP, ATLIB_SOCKET_OPTION_PARAM_TCP_MAXRT, max_rt));
}
/**
*  @brief  Get cid info
*
*  Calls AT+CID=? command
*  Send get cid info command.
*  Does not parse result.
*
*  @return True if successful
*/
bool GS_Api_GetCidInfo(){
	return gs_api_handle_cmd_resp(AtLib_GetCIDInfo());
}
/**
*  @brief  Remove certificate from GS module
*
*  Calls AT+TCERTDEL=<certificate name> command, and parses standard response.
*  removes certificate from GS module memory
*
*  @param  Desired cert name
*
*  @return True if successful
*/
bool GS_API_RemoveCertificate(uint8_t* cert_name){
	return gs_api_handle_cmd_resp(AtLib_DeleteSSLCertificate((char *) cert_name));
}
/**
*  @brief  Checks WiFi network status
*
*  Calls AT+WSTATUS command and parses standard response.
*  After this call, AtLib_ParseSSIDResponse or AtLib_ParseNodeIpAddress
*  should be called to parse node ip or target ssid
*
*  @return True if successful
*/
bool GS_API_WlanStatus(){
     return (gs_api_handle_cmd_resp(AtLibGs_WlanConnStatShort()));
}
/**
*  @brief  Close SSL secured connection
*
*  Calls AT+SSLCLOSE=<cid> command, and parses standard response.
*  Close SSL secured connection on desired tcp socket
*
*  @param  Connection id
*
*  @return True if successful
*/
bool GS_API_CloseSSLconnection(uint8_t cid){
	return gs_api_handle_cmd_resp(AtLib_SSLClose(cid));
}
/**
*  @brief  Get memory trace info
*
*  Calls AT+MEMTRACE command
*  Send get memory trace info command.
*  Does not parse result.
*
*  @return True if successful
*/
bool GS_Api_getMemoryInfo(){
	return gs_api_handle_cmd_resp(AtLib_GetMemoryInfo());
}
Esempio n. 26
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;
}
/**
*  @brief  Set time into GS module
*
*  Calls AT+SETTIME=[<dd/mm/yyyy>,<HH:MM:SS>],[ System time in milliseconds since epoch(1970)]
*  command, and parses standard response.
*
*  @param  Desired time string in format
*  "dd/mm/yyyy,HH:MM:SS" or
*  ",xxxxxxxxxxxxx"
*
*  @return True if successful
*/
bool GS_API_SetTime(uint8_t* time){
	return gs_api_handle_cmd_resp(AtLibGs_SetTime((int8_t *) time));
}