For Wifi personal security mode. It is always cumbersome to change the password whenever there is a breach in the network. and even more annoying is to distribute the passwords to the clients/guests. WifiFlexManager is a project that can change the password (with a random predefined length string) whenever the admin sends a specific IR code (through android app) and can retrieve the current password or the connected users (Through Bluetooth screen). So as a client who wants to get connected to the router, you only need to point your phone's IR towards the mbed and press a button, and the current password will be shown at your phone's screen.
Dependencies: EthernetInterface HTTPServer RemoteIR SDFileSystem mbed-rpc mbed-rtos mbed
Diff: main.cpp
- Revision:
- 4:779396fc3f76
- Parent:
- 3:e8334a5aeeff
--- a/main.cpp Mon May 04 02:19:07 2015 +0000 +++ b/main.cpp Mon May 04 03:39:37 2015 +0000 @@ -35,7 +35,7 @@ //Function that calls the function that lists users TCPSocketConnection socket; -char username[]=" root\r\n"; +char username[]="root\r\n"; char password[]="password\r\n"; char chngpwd[]="nvram set wl_wpa_psk=PleaseVote1forkamoona\r\n"; char getusers[]="cat /proc/net/arp\r\n"; @@ -96,7 +96,6 @@ int n; //End DB init - //IR Init uint8_t buf1[32]; uint8_t buf2[32]; @@ -185,54 +184,89 @@ printf("sd = %d\n", sd); printf("c = %c\n", c); char BTbuf[100], title[100]; - char shift[]=" "; // 7 Characters string + char shift[strlen(check)]; char buf[] = " "; bool res=false; FILE *fp; if (sd) - { + { if (c=='u') fp=fopen("/sd/Wifi/users.txt", "w"); else if (c=='p') fp=fopen("/sd/Wifi/pass.txt", "w"); - if(fp == NULL) { + if(fp == NULL) + { error("Could not open file for write\n"); - } } + } + int negState = 0; + int negCnt = 0; + char negAns[3]; + while (res==false) { int n = socket.receive(buf, 1); - if (sd) - { - fprintf(fp, "%c",buf[0]); - + + if (negState == 1 && negCnt < 3) + { + if (buf[0] == DO) + { + negAns[negCnt] = WONT; + negCnt ++; + } + else + { + negAns[negCnt] = buf[0]; + negCnt ++; } - printf("%c",buf[0]); - HC06.printf("%c",buf[0]); - for (int k=0;k<6;k++) - shift[k]=shift[k+1]; - shift[6]=buf[0]; - if (strcmp(shift,check) == 0) + } + else if (negCnt >= 3) + { + negCnt = 0; + negState = 0; + socket.send_all(negAns, sizeof(negAns)); + } + + if (buf[0] == IAC) { - printf("Prompt Reached!\n"); - res = true; + negCnt = 0; + negState = 1; + negAns[negCnt] = IAC; + negCnt ++; + } + + printf("Last received is %s\n",buf); + + if (negState == 0) + { + if (sd) + { + fprintf(fp, "%c",buf[0]); + } + printf("%c",buf[0]); + HC06.printf("%c",buf[0]); + for (int k=0;k<strlen(check);k++) + shift[k]=shift[k+1]; + shift[strlen(check)]=buf[0]; + if (strcmp(shift,check) == 0) + { + printf("Prompt Reached!\n"); + res = true; + } } } + if (sd) { printf("Closing file on SD...\n"); - fgets(BTbuf, sizeof BTbuf, fp); /* expect string like "title: TITLE WITH SPACES" */ sscanf(buf, "%*s %99[^\n]", title); - HC06.printf("%s",BTbuf); printf("%s",BTbuf); HC06.printf("%s",title); printf("%s",title); - fclose(fp); } - } /*void lsusrsf(void) //callstring is a sting passed to be sent by the TCP socket @@ -247,22 +281,27 @@ printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); wait(1); } - char negot[]={255,253,1,255,254,31}; - socket.send_all(negot, sizeof(negot) - 1); + //char negot[]={255,253,1,255,254,31}; + //socket.send_all(negot, sizeof(negot) - 1); + + int requirelogin = 1; - printf("Entering function: \n"); - char log[] = login; - cursor(&log[0],false,'a'); - printf("Exiting function: \n"); - socket.send_all(username, sizeof(username) - 1); - printf("Sent username!\n"); + if (requirelogin == 1) + { + printf("Entering function: \n"); + char log[] = login; + cursor(&log[0],false,'a'); + printf("Exiting function: \n"); + socket.send_all(username, sizeof(username) - 1); + printf("Sent username!\n"); - printf("Entering function: \n"); - char paspmt[] = passcurs; - cursor(&paspmt[0],false,'a'); - printf("Exiting function: \n"); - socket.send_all(password, sizeof(password) - 1); - printf("Sent password!\n"); + printf("Entering function: \n"); + char paspmt[] = passcurs; + cursor(&paspmt[0],false,'a'); + printf("Exiting function: \n"); + socket.send_all(password, sizeof(password) - 1); + printf("Sent password!\n"); + } printf("Entering function: \n"); char curspmt[] = cursr;