static void vProcessConnection( struct netconn *pxNetCon ) { static portCHAR cDynamicPage[webMAX_PAGE_SIZE]; struct netbuf *pxRxBuffer, *pxRxBuffer1 = NULL; portCHAR *pcRxString; unsigned portSHORT usLength; static portCHAR LocalBuf[LOCAL_BUF_SIZE]; u8_t bChanged = 0; int ret_recv = ERR_OK; int ret_accept = ERR_OK; char *ptr = NULL; /* Load WiFi Setting*/ LoadWifiSetting(); /* We expect to immediately get data. */ // Evan mopdified for adapt two version lwip api diff port_netconn_recv( pxNetCon , pxRxBuffer, ret_recv); if( pxRxBuffer != NULL && ret_recv == ERR_OK) { /* Where is the data? */ netbuf_data( pxRxBuffer, ( void * )&pcRxString, &usLength ); //printf("\r\nusLength=%d pcRxString = \n%s\n", usLength, pcRxString); /* Is this a GET? We don't handle anything else. */ if( !strncmp( pcRxString, "GET", 3 ) ) { //printf("\r\nusLength=%d pcRxString=%s \n", usLength, pcRxString); //pcRxString = cDynamicPage; /* Write out the HTTP OK header. */ netconn_write( pxNetCon, webHTTP_OK, ( u16_t ) strlen( webHTTP_OK ), NETCONN_COPY ); /* Generate index.html page. */ GenerateIndexHtmlPage(cDynamicPage, LocalBuf); /* Write out the dynamically generated page. */ netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY ); } else if(!strncmp( pcRxString, "POST", 4 ) ) { /* Write out the HTTP OK header. */ netconn_write( pxNetCon, webHTTP_OK, ( u16_t ) strlen( webHTTP_OK ), NETCONN_COPY ); bChanged = ProcessPostMessage(pxRxBuffer, LocalBuf); if(bChanged == 0){ port_netconn_recv( pxNetCon , pxRxBuffer1, ret_recv); if(pxRxBuffer != NULL && ret_recv == ERR_OK){ bChanged = ProcessPostMessage(pxRxBuffer1, LocalBuf); netbuf_delete( pxRxBuffer1 ); } } if(bChanged) { GenerateWaitHtmlPage(cDynamicPage); /* Write out the generated page. */ netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY ); #if CONFIG_READ_FLASH StoreApInfo(); #endif } else { /* Generate index.html page. */ GenerateIndexHtmlPage(cDynamicPage, LocalBuf); /* Write out the generated page. */ netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY ); } } netbuf_delete( pxRxBuffer ); } netconn_close( pxNetCon ); if(bChanged) { struct netconn *pxNewConnection; vTaskDelay(200/portTICK_RATE_MS); //printf("\r\n%d:before restart ap\n", xTaskGetTickCount()); RestartSoftAP(); //printf("\r\n%d:after restart ap\n", xTaskGetTickCount()); pxHTTPListener->recv_timeout = 1; // Evan mopdified for adapt two version lwip api diff port_netconn_accept( pxHTTPListener , pxNewConnection, ret_accept); if( pxNewConnection != NULL && ret_accept == ERR_OK) { //printf("\r\n%d: got a conn\n", xTaskGetTickCount()); netconn_close( pxNewConnection ); while( netconn_delete( pxNewConnection ) != ERR_OK ) { vTaskDelay( webSHORT_DELAY ); } } //printf("\r\n%d:end\n", xTaskGetTickCount()); pxHTTPListener->recv_timeout = 0; } }
void fATWA(void *arg){ #if CONFIG_LWIP_LAYER struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; struct netif * pnetif = &xnetif[0]; #endif int timeout = 20; printf("[ATWA]: _AT_WLAN_AP_ACTIVATE_\n\r"); if(ap.ssid.val[0] == 0){ printf("[ATWA]Error: SSID can't be empty\n\r"); return; } if(ap.password == NULL){ ap.security_type = RTW_SECURITY_OPEN; } else{ ap.security_type = RTW_SECURITY_WPA2_AES_PSK; } #if CONFIG_WEBSERVER //store into flash memset(wifi_setting.ssid, 0, sizeof(wifi_setting.ssid));; memcpy(wifi_setting.ssid, ap.ssid.val, strlen((char*)ap.ssid.val)); wifi_setting.ssid[ap.ssid.len] = '\0'; wifi_setting.security_type = ap.security_type; if(ap.security_type !=0) wifi_setting.security_type = 1; else wifi_setting.security_type = 0; if (ap.password) memcpy(wifi_setting.password, ap.password, strlen((char*)ap.password)); else memset(wifi_setting.password, 0, sizeof(wifi_setting.password));; wifi_setting.channel = ap.channel; #if CONFIG_READ_FLASH StoreApInfo(); #endif #endif #if CONFIG_LWIP_LAYER dhcps_deinit(); IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); netif_set_addr(pnetif, &ipaddr, &netmask,&gw); #ifdef CONFIG_DONT_CARE_TP pnetif->flags |= NETIF_FLAG_IPSWITCH; #endif #endif wifi_off(); vTaskDelay(20); if (wifi_on(RTW_MODE_AP) < 0){ printf("\n\rERROR: Wifi on failed!"); return; } printf("\n\rStarting AP ..."); #ifdef CONFIG_WPS_AP wpas_wps_dev_config(pnetif->hwaddr, 1); #endif if(wifi_start_ap((char*)ap.ssid.val, ap.security_type, (char*)ap.password, ap.ssid.len, ap.password_len, ap.channel) < 0) { printf("\n\rERROR: Operation failed!"); return; } while(1) { char essid[33]; if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) > 0) { if(strcmp((const char *) essid, (const char *)ap.ssid.val) == 0) { printf("\n\r%s started\n", ap.ssid.val); break; } } if(timeout == 0) { printf("\n\rERROR: Start AP timeout!"); break; } vTaskDelay(1 * configTICK_RATE_HZ); timeout --; } #if CONFIG_LWIP_LAYER //LwIP_UseStaticIP(pnetif); dhcps_init(pnetif); #endif init_wifi_struct( ); }