void GAgent_WiFiInit( pgcontext pgc ) { int8 ret=0; //strcpy( pgc->gc.wifi_ssid,SSID ); //strcpy( pgc->gc.wifi_key,KEY ); ret = GAgent_DRVGetWiFiMode(pgc); if( ((pgc->gc.flag)&XPG_CFG_FLAG_CONNECTED) == XPG_CFG_FLAG_CONNECTED ) { GAgent_Printf( GAGENT_INFO,"In Station mode"); GAgent_Printf( GAGENT_INFO,"SSID:%s,KEY:%s",pgc->gc.wifi_ssid,pgc->gc.wifi_key ); pgc->rtinfo.GAgentStatus |=WIFI_MODE_STATION; pgc->rtinfo.GAgentStatus |= GAgent_DRVWiFi_StationCustomModeStart( pgc->gc.wifi_ssid,pgc->gc.wifi_key,pgc->rtinfo.GAgentStatus ); } else { GAgent_Printf( GAGENT_CRITICAL,"In AP mode"); pgc->rtinfo.GAgentStatus |=WIFI_MODE_AP; pgc->rtinfo.GAgentStatus |= GAgent_DRV_WiFi_SoftAPModeStart( pgc->minfo.ap_name,AP_PASSWORD,pgc->rtinfo.GAgentStatus ); } }
int32 handleWebConfig( pgcontext pgc,int32 fd) { int32 read_len; int8 *buf_head, *buf_body, *index_ssid, *index_pass, *p; pgconfig pConfigData=NULL; pConfigData = &(pgc->gc); if(fd <= 0) return -1; buf_head = (char *)malloc(1024); if (buf_head == NULL) { return -1; } memset(buf_head, 0, 1024); read_len = read(fd, buf_head, 1024); if(read_len <= 0) { free(buf_head); return -1; } buf_body = (char *)malloc(1024); if (buf_body == NULL) { free(buf_head); return -1; } memset(buf_body, 0, 1024); if( strstr(buf_head, "web_config.cgi") == NULL) { snprintf(buf_body, 1024, "%s", "<html><body><form action=\"web_config.cgi\" method=\"get\">" "<div align=\"center\" style=\"font-size:30px; padding-top:100px;\">" "<p>[0~9],[a~z],[A~Z],[-],[_],[.]</p>" "<p>SSID:<input type=\"text\" name=\"ssid\" style=\"font-size:30px;\"/></p>" "<p>PASS:<input type=\"text\" name=\"pass\" style=\"font-size:30px;\"/></p>" "<p><input type=\"submit\" value=\"OK\" style=\"font-size:30px;\"/></p>" "</form></body></html>"); memset(buf_head, 0, 1024); snprintf(buf_head, 1024, "HTTP/1.1 200 OK\r\n" "Content-Type: text/html;charset=gb2312\r\n" "Content-Length: %d\r\n" "Cache-Control: no-cache\r\n" "Connection: close\r\n\r\n", strlen(buf_body)); send(fd, buf_head, strlen(buf_head), 0); send(fd, buf_body, strlen(buf_body), 0); } else { //GET /web_config.cgi?fname=chensf&lname=pinelinda HTTP/1.1 index_ssid = strstr(buf_head, "ssid="); index_pass = strstr(buf_head, "pass="******"ssid="); index_pass += strlen("pass="******"web_config SSID and pass too length !" ); } GAgent_Printf( GAGENT_CRITICAL,"web_config SSID and pass !" ); memset(pConfigData->wifi_ssid, 0, SSID_LEN_MAX ); memset(pConfigData->wifi_key, 0, WIFIKEY_LEN_MAX); memcpy(pConfigData->wifi_ssid, index_ssid, strlen(index_ssid)); memcpy(pConfigData->wifi_key, index_pass, strlen(index_pass)); pConfigData->wifi_ssid[ strlen(index_ssid) ] = '\0'; pConfigData->wifi_key[ strlen(index_pass) ] = '\0'; pConfigData->flag |= XPG_CFG_FLAG_CONNECTED; pConfigData->flag |= XPG_CFG_FLAG_CONFIG; GAgent_DevSaveConfigData( pConfigData ); snprintf(buf_body, 1024, "%s", "<html><body>" "<div align=\"center\" style=\"font-size:40px; padding-top:100px;\">" "<p>Config the wifi module success</p>" "</body></html>"); memset(buf_head, 0, 1024); snprintf(buf_head, 1024, "HTTP/1.1 200 OK\r\n" "Content-Type: text/html;charset=gb2312\r\n" "Content-Length: %d\r\n" "Cache-Control: no-cache\r\n" "Connection: close\r\n\r\n", strlen(buf_body)); send(fd, buf_head, strlen(buf_head), 0); send(fd, buf_body, strlen(buf_body), 0); pgc->rtinfo.GAgentStatus &=~ WIFI_MODE_AP; pgc->rtinfo.GAgentStatus |= GAgent_DRVWiFi_StationCustomModeStart( pgc->gc.wifi_ssid,pgc->gc.wifi_key,pgc->rtinfo.GAgentStatus ); msleep(100); } } free(buf_head); free(buf_body); msleep(100); return 0; }
void GAgent_WiFiEventTick( pgcontext pgc,uint32 dTime_s ) { uint16 newStatus=0; uint16 gagentWiFiStatus=0; gagentWiFiStatus = ( (pgc->rtinfo.GAgentStatus)&(LOCAL_GAGENTSTATUS_MASK) ) ; newStatus = GAgent_DevCheckWifiStatus( pgc->rtinfo.GAgentStatus ); if( (gagentWiFiStatus&WIFI_MODE_AP) != (newStatus&WIFI_MODE_AP) ) { if( newStatus&WIFI_MODE_AP ) { //WIFI_MODE_AP UP GAgent_SetWiFiStatus( pgc,WIFI_MODE_AP,1 ); } else { //WIFI_MODE_AP DOWN GAgent_SetWiFiStatus( pgc,WIFI_MODE_AP,0 ); } pgc->rtinfo.waninfo.wanclient_num=0; pgc->ls.tcpClientNums=0; GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START ); GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_CONNECTED,0 ); } if( (gagentWiFiStatus&WIFI_MODE_STATION) != (newStatus&WIFI_MODE_STATION) ) { if( newStatus&WIFI_MODE_STATION ) { //WIFI_MODE_STATION UP GAgent_SetWiFiStatus( pgc,WIFI_MODE_STATION,1 ); } else { //WIFI_MODE_STATION DOWN GAgent_SetWiFiStatus( pgc,WIFI_MODE_STATION,0 ); GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START ); GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_CONNECTED,0 ); } pgc->rtinfo.waninfo.wanclient_num=0; pgc->ls.tcpClientNums=0; } if( (gagentWiFiStatus&WIFI_MODE_ONBOARDING) != (newStatus&WIFI_MODE_ONBOARDING) ) { if( newStatus&WIFI_MODE_ONBOARDING ) { //WIFI_MODE_ONBOARDING UP GAgent_SetWiFiStatus( pgc,WIFI_MODE_ONBOARDING,1 ); } else { //WIFI_MODE_ONBOARDING DOWN GAgent_SetWiFiStatus( pgc,WIFI_MODE_ONBOARDING,0 ); } pgc->rtinfo.waninfo.wanclient_num=0; pgc->ls.tcpClientNums=0; GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START ); GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_CONNECTED,0 ); } if( (gagentWiFiStatus&WIFI_STATION_CONNECTED) != (newStatus & WIFI_STATION_CONNECTED) ) { if( newStatus&WIFI_STATION_CONNECTED ) { //WIFI_STATION_CONNECTED UP GAgent_SetWiFiStatus( pgc,WIFI_STATION_CONNECTED,1 ); } else { //WIFI_STATION_CONNECTED DOWN GAgent_SetWiFiStatus( pgc,WIFI_STATION_CONNECTED,0 ); GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START ); GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_CONNECTED,0 ); GAgent_SetWiFiStatus( pgc,WIFI_CLIENT_ON,0 ); } pgc->rtinfo.waninfo.wanclient_num=0; pgc->ls.tcpClientNums=0; } if( (gagentWiFiStatus&WIFI_CLOUD_CONNECTED) != (newStatus & WIFI_CLOUD_CONNECTED) ) { if( newStatus&WIFI_CLOUD_CONNECTED ) { //WIFI_CLOUD_CONNECTED UP GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_CONNECTED,1 ); } else { //WIFI_CLOUD_CONNECTED DOWN pgc->rtinfo.waninfo.wanclient_num=0; GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START ); GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_CONNECTED,0 ); } } if( gagentWiFiStatus&WIFI_MODE_TEST )//test mode { static int8 cnt=0; int8 ret =0; NetHostList_str *aplist; pgc->rtinfo.testLastTimeStamp+=dTime_s; if( cnt>=18 && 0 == pgc->rtinfo.scanWifiFlag ) { cnt=0; GAgent_SetWiFiStatus( pgc,WIFI_MODE_TEST,0 ); GAgent_DRVWiFiStopScan( ); } if( pgc->rtinfo.testLastTimeStamp >= 10 && 0 == pgc->rtinfo.scanWifiFlag ) { cnt++; pgc->rtinfo.testLastTimeStamp = 0; GAgent_DRVWiFiStartScan(); } aplist = GAgentDRVWiFiScanResult( aplist ); ret = GAgentFindTestApHost( aplist ); if( ret>0 ) { pgc->rtinfo.scanWifiFlag = 1; cnt=0; if( 1==ret ) pgc->rtinfo.GAgentStatus |= GAgent_DRVWiFi_StationCustomModeStart( GAGENT_TEST_AP1,GAGENT_TEST_AP_PASS,pgc->rtinfo.GAgentStatus ); else pgc->rtinfo.GAgentStatus |= GAgent_DRVWiFi_StationCustomModeStart( GAGENT_TEST_AP2,GAGENT_TEST_AP_PASS,pgc->rtinfo.GAgentStatus ); } } GAgent_LocalSendGAgentstatus(pgc,dTime_s); GAgentSetLedStatus( gagentWiFiStatus ); return ; }