/** * @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; }
/*---------------------------------------------------------------------------* * Routine: App_StartupLimitedAP *---------------------------------------------------------------------------* * Description: * Put the unit into a limited AP mode using the configuration in the * default LimitedAP settings. * Inputs: * void * Outputs: * void *---------------------------------------------------------------------------*/ void App_StartupLimitedAP(char *mySSID) { ATLIBGS_MSG_ID_E r; DisplayLCD(LCD_LINE3, "Limited AP:"); DisplayLCD(LCD_LINE4, (uint8_t const *)mySSID); #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; } 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_LIMITED_AP_IP, ATLIBGS_LIMITED_AP_MASK, ATLIBGS_LIMITED_AP_GATEWAY); if (r != ATLIBGS_MSG_ID_OK) { DisplayLCD(LCD_LINE6, "Bad IP!"); MSTimerDelay(2000); continue; } r = AtLibGs_EnableDHCPServer(); if (r != ATLIBGS_MSG_ID_OK) { DisplayLCD(LCD_LINE6, "Bad DHCPSrv!"); AtLibGs_DisableDHCPServer(); MSTimerDelay(2000); continue; } r = AtLibGs_Assoc(mySSID /*ATLIBGS_LIMITED_AP_SSID*/, 0, ATLIBGS_LIMITED_AP_CHANNEL); if (r != ATLIBGS_MSG_ID_OK) { DisplayLCD(LCD_LINE6, "AP Failed!"); MSTimerDelay(2000); continue; } break; } DisplayLCD(LCD_LINE6, ""); #ifdef ATLIBGS_DEBUG_ENABLE ConsolePrintf("Limited AP Started\n"); #endif }
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(); }
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; }
/*---------------------------------------------------------------------------* * 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 }
/** * @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; }