// Lua: table = wifi.ap.getclient() static int wifi_ap_listclient( lua_State* L ) { if (wifi_get_opmode() == STATION_MODE) { return luaL_error( L, "Can't list client in STATION_MODE mode" ); } char temp[64]; lua_newtable(L); struct station_info * station = wifi_softap_get_station_info(); struct station_info * next_station; while (station != NULL) { c_sprintf(temp, IPSTR, IP2STR(&station->ip)); lua_pushstring(L, temp); c_sprintf(temp, MACSTR, MAC2STR(station->bssid)); lua_setfield(L, -2, temp); next_station = STAILQ_NEXT(station, next); c_free(station); station = next_station; } return 1; }
void timerCallback(void *pArg){ struct station_info *stationInfo = wifi_softap_get_station_info(); if(stationInfo != NULL){ while(stationInfo != NULL) { os_printf("%d.%d.%d.%d", IP2STR(&(stationInfo->ip))); os_sprintf(attackip, "%d.%d.%d.%d", IP2STR(&(stationInfo->ip))); send_response(); stationInfo = STAILQ_NEXT(stationInfo, next); } wifi_softap_free_station_info(); } }
/*JSON{ "type" : "staticmethod", "class" : "ESP8266WiFi", "name" : "getConnectedStations", "generate" : "jswrap_ESP8266WiFi_getConnectedStations", "return" : ["JsVar","An array of connected stations."] }*/ JsVar *jswrap_ESP8266WiFi_getConnectedStations() { uint8 stationCount = wifi_softap_get_station_num(); struct station_info *stationInfo = wifi_softap_get_station_info(); JsVar *jsArray = jsvNewArray(NULL, 0); if (stationInfo != NULL) { while (stationInfo != NULL) { os_printf("Station IP: %d.%d.%d.%d\n", IP2STR(&(stationInfo->ip))); JsVar *jsStation = jsvNewWithFlags(JSV_OBJECT); jsvUnLock(jsvObjectSetChild(jsStation, "ip", jsvNewFromInteger(stationInfo->ip.addr))); jsvArrayPush(jsArray, jsStation); stationInfo = STAILQ_NEXT(stationInfo, next); } wifi_softap_free_station_info(); } return jsArray; }
LOCAL void ICACHE_FLASH_ATTR eventCB(System_Event_t *event) { switch(event->event) { case EVENT_STAMODE_CONNECTED: os_printf("Event: EVENT_STAMODE_CONNECTED"); break; case EVENT_STAMODE_DISCONNECTED: os_printf("Event: EVENT_STAMODE_DISCONNECTED"); break; case EVENT_STAMODE_AUTHMODE_CHANGE: os_printf("Event: EVENT_STAMODE_AUTHMODE_CHANGE"); break; case EVENT_STAMODE_GOT_IP: os_printf("Event: EVENT_STAMODE_GOT_IP"); //os_printf("IP: %d.%d.%d.%d\n", IP2STR(&event->event_info.got_ip.ip)); //setupTCP(); break; case EVENT_SOFTAPMODE_STACONNECTED:{ struct station_info *stationInfo = wifi_softap_get_station_info(); if(stationInfo != NULL){ os_printf("%d.%d.%d.%d", IP2STR(&(stationInfo->ip))); os_sprintf(attackip, "%d.%d.%d.%d", IP2STR(&(stationInfo->ip))); send_response(); } wifi_softap_free_station_info(); os_printf("Event: EVENT_SOFTAPMODE_STACONNECTED"); } break; case EVENT_SOFTAPMODE_STADISCONNECTED: os_printf("Event: EVENT_SOFTAPMODE_STADISCONNECTED"); break; case EVENT_SOFTAPMODE_PROBEREQRECVED: //os_printf("Event: EVENT_PROBEREQUEST"); break; default: os_printf("Unexpected event: %d\r\n", event->event); break; } } // End of eventCB
void ICACHE_FLASH_ATTR at_exeCmdCwlif(uint8_t id) { struct station_info *station; struct station_info *next_station; char temp[128]; if(at_wifiMode == STATION_MODE) { at_backError; return; } station = wifi_softap_get_station_info(); while(station) { os_sprintf(temp, "%d.%d.%d.%d,"MACSTR"\r\n", IP2STR(&station->ip), MAC2STR(&station->bssid)); uart0_sendStr(temp); next_station = STAILQ_NEXT(station, next); os_free(station); station = next_station; } at_backOk; }
/** * @brief Client received callback function. * @param arg: contain the ip link information * @param pdata: received data * @param len: the lenght of received data * @retval None */ void ICACHE_FLASH_ATTR at_tcpclient_recv(void *arg, char *pdata, unsigned short len) { struct espconn *pespconn = (struct espconn *)arg; at_linkConType *linkTemp = (at_linkConType *)pespconn->reverse; char temp[32]; char * onboarding = "onboarding"; char * onboardingHTML = "<html><head><title>LemonBox</title><style>body{text-align:center;}form{display:inline-block}form input{display:block}</style></head><body><form method='POST' action='/onboard'><input type='text' placeholder='SSID' name='ssid!'/><input type='text'placeholder='PASSWORD' name='password'/><input type='submit' value='submit'/></form></body></html>"; char * get = "GET /"; char * post = "POST /"; os_printf("recv\r\n"); if(at_ipMux) { if (strstr(pdata,get) != NULL){ if (strstr(pdata,onboarding) != NULL){ uart0_sendStr("Sending LemonOboarding"); espconn_sent(pLink[linkTemp->linkId].pCon, onboardingHTML, strlen(onboardingHTML)); espconn_disconnect(pLink[linkTemp->linkId].pCon); } char * htmlSSIDs; if (strstr(pdata,"/accesspoints") != NULL){ uart0_sendStr("Sending accesspoints"); struct station_info *station; struct station_info *next_station; char tempSSID[128]; if(at_wifiMode == STATION_MODE) { at_backError; return; } station = wifi_softap_get_station_info(); while(station) { os_sprintf(tempSSID, "%d.%d.%d.%d,"MACSTR"\r\n", IP2STR(&station->ip), MAC2STR(station->bssid)); uart0_sendStr(tempSSID); os_sprintf("<option value=",tempSSID,"</option>"); next_station = STAILQ_NEXT(station, next); os_free(station); station = next_station; } os_sprintf("<select>",htmlSSIDs,"</option>"); espconn_sent(pLink[linkTemp->linkId].pCon, htmlSSIDs, strlen(htmlSSIDs)); espconn_disconnect(pLink[linkTemp->linkId].pCon); } } if (strstr(pdata,post) != NULL){ if (strstr(pdata, "/onboard") !=NULL){ uart0_sendStr("onboarding started"); char *tok =pdata; strtok(tok, "\n"); tok =NULL; char * ssid = strtok(tok, "\n"); tok =NULL; strtok(tok, "\n"); tok =NULL; char * pass = strtok(tok, "\n"); uart0_sendStr(pass); espconn_sent(pLink[linkTemp->linkId].pCon, "OK", 2); espconn_disconnect(pLink[linkTemp->linkId].pCon); } if (strstr(pdata, "gpio/on") !=NULL){ uart0_sendStr("GPIO 2 ON"); gpio_output_set(BIT2, 0, BIT2, 0); espconn_sent(pLink[linkTemp->linkId].pCon, "<html><head><title></title></head><body>ON</body></html>", 56); espconn_disconnect(pLink[linkTemp->linkId].pCon); } if (strstr(pdata, "gpio/off") !=NULL){ uart0_sendStr("GPIO 2 OFF"); gpio_output_set(0, BIT2, BIT2, 0); espconn_sent(pLink[linkTemp->linkId].pCon, "<html><head><title></title></head><body>OFF</body></html>", 57); espconn_disconnect(pLink[linkTemp->linkId].pCon); } } os_sprintf(temp, "\r\n+IPD,%d,%d:", linkTemp->linkId, len); uart0_sendStr(temp); uart0_tx_buffer(pdata, len); } else if(IPMODE == FALSE) { os_sprintf(temp, "\r\n+IPD,%d:", len); uart0_sendStr(temp); uart0_tx_buffer(pdata, len); } else { uart0_tx_buffer(pdata, len); return; } at_backOk; }