for TwitterMbed

Fork of GSwifi_old by gs fan

Revision:
22:9b077e2823ce
Parent:
20:151b5a4fdd29
Child:
23:a783c62c36d0
diff -r 1270827d431a -r 9b077e2823ce GSwifi.cpp
--- a/GSwifi.cpp	Thu Nov 08 01:35:37 2012 +0000
+++ b/GSwifi.cpp	Wed Dec 26 08:41:43 2012 +0000
@@ -494,6 +494,7 @@
 #endif
 
     disconnect();
+    command("AT+WREGDOMAIN=" GS_WREGDOMAIN, GSRES_NORMAL);
     command("AT+WM=0", GSRES_NORMAL); // infrastructure
     wait_ms(100);
     if (dhcp && sec != GSSEC_WPS_BUTTON) {
@@ -504,21 +505,15 @@
 
     switch (sec) {
     case GSSEC_NONE:
-        command("AT+WAUTH=0", GSRES_NORMAL);
-        sprintf(cmd, "AT+WA=%s", ssid);
-        r = command(cmd, GSRES_DHCP, GS_TIMEOUT2);
-        if (r) {
-            DBG("retry\r\n");
-            r = command(cmd, GSRES_DHCP, GS_TIMEOUT2); // retry
-        }
-        break;
     case GSSEC_OPEN:
     case GSSEC_WEP:
         sprintf(cmd, "AT+WAUTH=%d", sec);
         command(cmd, GSRES_NORMAL);
-        sprintf(cmd, "AT+WWEP1=%s", pass);
-        command(cmd, GSRES_NORMAL);
-        wait_ms(100);
+        if (sec != GSSEC_NONE) {
+            sprintf(cmd, "AT+WWEP1=%s", pass);
+            command(cmd, GSRES_NORMAL);
+            wait_ms(100);
+        }
         sprintf(cmd, "AT+WA=%s", ssid);
         r = command(cmd, GSRES_DHCP, GS_TIMEOUT2);
         if (r) {
@@ -583,6 +578,7 @@
     command("AT+BDATA=1", GSRES_NORMAL);
 #endif
 
+    command("AT+WREGDOMAIN=" GS_WREGDOMAIN, GSRES_NORMAL);
     command("AT+WM=1", GSRES_NORMAL); // adhock
     wait_ms(100);
     command("AT+NDHCP=0", GSRES_NORMAL);
@@ -590,17 +586,15 @@
 
     switch (sec) {
     case GSSEC_NONE:
-        command("AT+WAUTH=0", GSRES_NORMAL);
-        sprintf(cmd, "AT+WA=%s", ssid);
-        r = command(cmd, GSRES_NORMAL, GS_TIMEOUT2);
-        break;
     case GSSEC_OPEN:
     case GSSEC_WEP:
         sprintf(cmd, "AT+WAUTH=%d", sec);
         command(cmd, GSRES_NORMAL);
-        sprintf(cmd, "AT+WWEP1=%s", pass);
-        command(cmd, GSRES_NORMAL);
-        wait_ms(100);
+        if (sec != GSSEC_NONE) {
+            sprintf(cmd, "AT+WWEP1=%s", pass);
+            command(cmd, GSRES_NORMAL);
+            wait_ms(100);
+        }
         sprintf(cmd, "AT+WA=%s", ssid);
         r = command(cmd, GSRES_NORMAL, GS_TIMEOUT2);
         break;
@@ -614,7 +608,7 @@
     return r;
 }
 
-int GSwifi::limitedap (GSSECURITY sec, const char *ssid, const char *pass, IpAddr ipaddr, IpAddr netmask, bool prov) {
+int GSwifi::limitedap (GSSECURITY sec, const char *ssid, const char *pass, IpAddr ipaddr, IpAddr netmask, char *dns) {
     int r;
     char cmd[GS_CMD_SIZE];
     
@@ -632,26 +626,30 @@
     command("AT+BDATA=1", GSRES_NORMAL);
 #endif
 
+    command("AT+WREGDOMAIN=" GS_WREGDOMAIN, GSRES_NORMAL);
     command("AT+WM=2", GSRES_NORMAL); // limited ap
     wait_ms(1000);
     command("AT+NDHCP=0", GSRES_NORMAL);
     setAddress(ipaddr, netmask, ipaddr, ipaddr);
     if (command("AT+DHCPSRVR=1", GSRES_NORMAL)) return -1;
-    if (command("AT+DNS=1,setup.local", GSRES_NORMAL)) return -1;
+    if (dns) {
+        sprintf(cmd, "AT+DNS=1,%s", dns);
+    } else {
+        strcpy(cmd, "AT+DNS=1," GS_DNSNAME);
+    }
+    if (command(cmd, GSRES_NORMAL)) return -1;
 
     switch (sec) {
     case GSSEC_NONE:
-        command("AT+WAUTH=0", GSRES_NORMAL);
-        sprintf(cmd, "AT+WA=%s", ssid);
-        r = command(cmd, GSRES_NORMAL, GS_TIMEOUT2);
-        break;
     case GSSEC_OPEN:
     case GSSEC_WEP:
         sprintf(cmd, "AT+WAUTH=%d", sec);
         command(cmd, GSRES_NORMAL);
-        sprintf(cmd, "AT+WWEP1=%s", pass);
-        command(cmd, GSRES_NORMAL);
-        wait_ms(100);
+        if (sec != GSSEC_NONE) {
+            sprintf(cmd, "AT+WWEP1=%s", pass);
+            command(cmd, GSRES_NORMAL);
+            wait_ms(100);
+        }
         sprintf(cmd, "AT+WA=%s", ssid);
         r = command(cmd, GSRES_NORMAL, GS_TIMEOUT2);
         break;
@@ -661,10 +659,6 @@
         break;
     }
 
-    if (r == 0 && prov) {
-        command("AT+WEBPROV=admin,password", GSRES_NORMAL);
-    }
-
     if (r == 0) _connect = true;
     return r;
 }
@@ -1299,6 +1293,30 @@
     return cmdResponse(GSRES_NORMAL, GS_TIMEOUT);
 }
 
+int GSwifi::provisioning (char *user, char *pass) {
+    char cmd[GS_CMD_SIZE];
+
+    if (_status != GSSTAT_READY) return -1;
+
+    sprintf(cmd, "AT+WEBPROV=%s,%s", user, pass);
+    return command(cmd, GSRES_NORMAL);
+}
+
+int GSwifi::setBaud (int baud) {
+    char cmd[GS_CMD_SIZE];
+
+    if (_status != GSSTAT_READY) return -1;
+
+    _gs.printf("ATB=%d\r\n", baud);
+    _gs.baud(baud);
+    for (int i = 0; i < 10; i ++) {
+        wait_ms(10);
+        poll_cmd();
+        _buf_cmd.clear();
+    }
+    return 0;
+}
+
 int GSwifi::base64encode (char *input, int length, char *output, int len) {
     // code from 
     // Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
@@ -1401,7 +1419,7 @@
 }
 
 
-#ifdef DEBUF
+#ifdef DEBUG
 // for test
 
 void GSwifi::test () {