gs fan / GSwifi

Dependents:   GSwifi_httpd GSwifi_websocket GSwifi_tcpclient GSwifi_tcpserver ... more

Fork of GSwifi by gs fan

Files at this revision

API Documentation at this revision

Comitter:
gsfan
Date:
Fri Jun 21 06:08:37 2013 +0000
Parent:
34:f5f40c92af00
Child:
36:a70b11e1560f
Commit message:
fix getMac, reconnect

Changed in this revision

GSwifi.cpp Show annotated file Show diff for this revision Revisions of this file
GSwifi.h Show annotated file Show diff for this revision Revisions of this file
GSwifi_conf.h Show annotated file Show diff for this revision Revisions of this file
GSwifi_http.cpp Show annotated file Show diff for this revision Revisions of this file
GSwifi_httpd.cpp Show annotated file Show diff for this revision Revisions of this file
GSwifi_smtp.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GSwifi.cpp	Fri Mar 29 14:58:07 2013 +0000
+++ b/GSwifi.cpp	Fri Jun 21 06:08:37 2013 +0000
@@ -36,11 +36,12 @@
 
     _reset.output(); // low
     _reset = 0;
-    _gs.baud(baud);
+    _baud = baud;
+    if (_baud) _gs.baud(_baud);
     _gs.attach(this, &GSwifi::isr_recv, Serial::RxIrq);
     _rts = false;
 
-    wait_ms(500);
+    wait_ms(100);
     reset();
 }
 
@@ -56,7 +57,8 @@
 
     _reset.output(); // low
     _reset = 0;
-    _gs.baud(baud);
+    _baud = baud;
+    if (_baud) _gs.baud(_baud);
     _gs.attach(this, &GSwifi::isr_recv, Serial::RxIrq);
     _rts = false;
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
@@ -85,7 +87,7 @@
     }
 #endif
 
-    wait_ms(500);
+    wait_ms(100);
     reset();
 }
 
@@ -102,6 +104,8 @@
     _reset.output(); // low
     _reset = 0;
 
+    memset(&_gs_sock, 0, sizeof(_gs_sock));
+    memset(&_mac, 0, sizeof(_mac));
     _connect = false;
     _status = GSSTAT_READY;
     _escape = 0;
@@ -110,15 +114,49 @@
     _ssid = NULL;
     _pass = NULL;
     _reconnect = 0;
-    _reconnect_count = 0;
     _buf_cmd.flush();
 
     wait_ms(100);
+    if (! _baud) autobaud(0);
     _reset.input(); // high
     _reset.mode(PullUp);
+    if (! _baud) autobaud(1);
     wait_ms(500);
 }
 
+int GSwifi::autobaud (int flg) {
+    int i;
+
+#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
+    if (flg == 0) {
+        LPC_UART1->ACR = (1<<2)|(1<<0); // auto-baud mode 0
+        return 0;
+    } else {
+        for (i = 0; i < 50; i ++) {
+            if (! (LPC_UART1->ACR & (1<<0))) {
+                return 0;
+            }
+            wait_ms(10);
+        }
+        LPC_UART1->ACR = 0;
+    }
+#elif defined(TARGET_LPC11U24)
+    if (flg == 0) {
+        LPC_USART->ACR = (1<<2)|(1<<0); // auto-baud mode 0
+        return 0;
+    } else {
+        for (i = 0; i < 50; i ++) {
+            if (! (LPC_USART->ACR & (1<<0))) {
+                return 0;
+            }
+            wait_ms(10);
+        }
+        LPC_USART->ACR = 0;
+    }
+#endif
+    return -1;
+}
+
 // uart interrupt
 void GSwifi::isr_recv () {
     static int len, mode;
@@ -394,7 +432,7 @@
     return -1;
 }
 
-int GSwifi::connect (GSSECURITY sec, const char *ssid, const char *pass, int dhcp, int reconnect) {
+int GSwifi::connect (GSSECURITY sec, const char *ssid, const char *pass, int dhcp, int reconnect, char *name) {
     int r;
     char cmd[GS_CMD_SIZE];
     
@@ -405,7 +443,7 @@
     if (_rts) {
         command("AT&R1", GSRES_NORMAL);
     }
-    command("AT+NMAC=?", GSRES_MACADDRESS);
+    if (getMacAddress(_mac)) return -1;
 #ifdef GS_BULK
     command("AT+BDATA=1", GSRES_NORMAL);
 #endif
@@ -414,7 +452,12 @@
     command("AT+WM=0", GSRES_NORMAL); // infrastructure
     wait_ms(100);
     if (dhcp && sec != GSSEC_WPS_BUTTON) {
-        command("AT+NDHCP=1", GSRES_NORMAL);
+        if (name) {
+            sprintf(cmd, "AT+NDHCP=1,%s", name);
+        } else {
+            strcpy(cmd, "AT+NDHCP=1," GS_DHCPNAME);
+        }
+        command(cmd, GSRES_NORMAL);
     } else {
         command("AT+NDHCP=0", GSRES_NORMAL);
     }
@@ -460,7 +503,7 @@
         r = command("AT+WWPS=1", GSRES_WPS, GS_TIMEOUT2);
         if (r) break;
         if (dhcp) {
-            r = command("AT+NDHCP=1", GSRES_DHCP, GS_TIMEOUT2);
+            r = setAddress(name);
         }
         break;
     case GSSEC_WPS_PIN:
@@ -469,7 +512,7 @@
         r = command(cmd, GSRES_WPS, GS_TIMEOUT2);
         if (r) break;
         if (dhcp) {
-            r = command("AT+NDHCP=1", GSRES_DHCP, GS_TIMEOUT2);
+            r = setAddress(name);
         }
         break;
     default:
@@ -489,12 +532,12 @@
         _reconnect = reconnect;
         _reconnect_count = 0;
         _sec = sec;
-        if (ssid) {
-            if (!_ssid) _ssid = new char[strlen(ssid) + 1];
+        if (_reconnect && ssid) {
+            if (!_ssid) _ssid = (char*)malloc(strlen(ssid) + 1);
             strcpy(_ssid, ssid);
         }
-        if (pass) {
-            if (!_pass) _pass = new char[strlen(pass) + 1];
+        if (_reconnect && pass) {
+            if (!_pass) _pass = (char*)malloc(strlen(pass) + 1);
             strcpy(_pass, pass);
         }
     }
@@ -512,12 +555,12 @@
     if (_rts) {
         command("AT&R1", GSRES_NORMAL);
     }
-    disconnect();
-    command("AT+NMAC=?", GSRES_MACADDRESS);
+    if (getMacAddress(_mac)) return -1;
 #ifdef GS_BULK
     command("AT+BDATA=1", GSRES_NORMAL);
 #endif
 
+    disconnect();
     command("AT+WM=1", GSRES_NORMAL); // adhock
     wait_ms(100);
     command("AT+NDHCP=0", GSRES_NORMAL);
@@ -558,12 +601,12 @@
     if (_rts) {
         command("AT&R1", GSRES_NORMAL);
     }
-    disconnect();
-    command("AT+NMAC=?", GSRES_MACADDRESS);
+    if (getMacAddress(_mac)) return -1;
 #ifdef GS_BULK
     command("AT+BDATA=1", GSRES_NORMAL);
 #endif
 
+    disconnect();
     command("AT+WM=2", GSRES_NORMAL); // limited ap
     wait_ms(100);
     command("AT+NDHCP=0", GSRES_NORMAL);
@@ -642,12 +685,20 @@
         r = -1;
         break;
     }
+
+    if (r == 0) _connect = true;
     return r;
 }
 
-int GSwifi::setAddress () {
+int GSwifi::setAddress (char *name) {
+    char cmd[GS_CMD_SIZE];
 
-    if (command("AT+NDHCP=1", GSRES_DHCP), GS_TIMEOUT2) return -1;
+    if (name) {
+        sprintf(cmd, "AT+NDHCP=1,%s", name);
+    } else {
+        strcpy(cmd, "AT+NDHCP=1," GS_DHCPNAME);
+    }
+    if (command(cmd, GSRES_DHCP), GS_TIMEOUT2) return -1;
     if (_ipaddr.isNull()) return -1;
     return 0;
 }
@@ -686,8 +737,13 @@
 }
 
 int GSwifi::getMacAddress (char *mac) {
-    memcpy(mac, _mac, 6);
-    return 0;
+
+    command("AT+NMAC=?", GSRES_MACADDRESS);
+    if (_mac[0] || _mac[1] || _mac[2] || _mac[3] || _mac[4] || _mac[5]) {
+        memcpy(mac, _mac, 6);
+        return 0;
+    }
+    return -1;
 }
 
 int GSwifi::getHostByName (const char* name, IpAddr &addr) {
@@ -915,6 +971,7 @@
           strncmp(buf, "UnExpected Warm Boot", 20) == 0 ||
           strncmp(buf, "APP Reset-APP SW Reset", 22) == 0 ||
           strncmp(buf, "APP Reset-Wlan Except", 21) == 0 ) {
+            DBG("disassociate\r\n");
             _connect = false;
             for (i = 0; i < 16; i ++) {
                 _gs_sock[i].connect = false;
@@ -937,7 +994,6 @@
 
 void GSwifi::parseCmdResponse (char *buf) {
     if (_gs_res == GSRES_NONE) return;
-    DBG("cmd\r\n");
 
     if (strcmp(buf, "OK") == 0) {
         _gs_ok = true;
@@ -952,7 +1008,7 @@
         break;
     case GSRES_WPS:
         if (_gs_flg == 0 && strncmp(buf, "SSID=", 5) == 0) {
-            if (!_ssid) _ssid = new char[strlen(&buf[5]) + 1];
+            if (!_ssid) _ssid = (char*)malloc(strlen(&buf[5]) + 1);
             strcpy(_ssid, &buf[5]);
             _gs_flg ++;
         } else
@@ -960,7 +1016,7 @@
             _gs_flg ++;
         } else
         if (_gs_flg == 2 && strncmp(buf, "PASSPHRASE=", 11) == 0) {
-            if (!_pass) _pass = new char[strlen(&buf[11]) + 1];
+            if (!_pass) _pass = (char*)malloc(strlen(&buf[11]) + 1);
             strcpy(_pass, &buf[11]);
             _gs_flg = -1;
         }
@@ -1046,23 +1102,26 @@
     int i, j;
 
     for (i = 0; i < 16; i ++) {
-        if (_gs_sock[i].received && (! _gs_sock[i].data->isEmpty())) {
+        if (_gs_sock[i].connect && _gs_sock[i].received) {
+          if (_gs_sock[i].data && ! _gs_sock[i].data->isEmpty()) {
             // recv interrupt
             _gs_sock[i].received = false;
             for (j = 0; j < 1500 / GS_DATA_SIZE + 1; j ++) {
                 if (! _gs_sock[i].connect || _gs_sock[i].data->isEmpty()) break;
                 _gs_sock[i].onGsReceive.call(i, _gs_sock[i].data->available());
             }
+          }
         }
     }
-    
-    if ((!_connect) && _reconnect_count < _reconnect && _ssid) {
-        // re-connrct
-        _reconnect_count ++;
-        DBG("re-connect %d\r\n", _reconnect_count);
-        if (reconnect() == 0) {
-            _connect = true;
-            _reconnect_count = 0;
+
+    if (_reconnect && ! _connect) {
+        if (_reconnect_count == 0 || (_reconnect_count < _reconnect && _reconnect_time < time(NULL))) {
+            _reconnect_count ++;
+            DBG("reconnect %d/%d\r\n", _reconnect_count, _reconnect);
+            if (reconnect() == 0) {
+                _reconnect_count = 0;
+            }
+            _reconnect_time = time(NULL) + GS_RECONTIME;
         }
     }
 }
@@ -1155,10 +1214,15 @@
     
     DBG("GS mode=%d, escape=%d, cid=%d\r\n", _gs_mode, _escape, _cid);
     for (i = 0; i < 16; i ++) {
-        DBG("%d: connect=%d, type=%d, protocol=%d, len=%d\r\n", i, _gs_sock[i].connect, _gs_sock[i].type, _gs_sock[i].protocol, _gs_sock[i].data->available());
+        DBG("[%d] ", i);
+        DBG("connect=%d, type=%d, protocol=%d, len=%d\r\n", _gs_sock[i].connect, _gs_sock[i].type, _gs_sock[i].protocol, _gs_sock[i].data->available());
+        DBG("  %x, %x\r\n", &_gs_sock[i], _gs_sock[i].data);
+#ifdef GS_ENABLE_HTTPD
         if (_gs_sock[i].protocol == GSPROT_HTTPD) {
             DBG("  mode=%d, type=%d, len=%d\r\n", i, _httpd[i].mode, _httpd[i].type, _httpd[i].len);
+            DBG("  %x, %x\r\n", &_httpd[i], _httpd[i].buf);
         }
+#endif
     }
 }
 
--- a/GSwifi.h	Fri Mar 29 14:58:07 2013 +0000
+++ b/GSwifi.h	Fri Jun 21 06:08:37 2013 +0000
@@ -30,6 +30,7 @@
 #include "host.h"
 #include "ipaddr.h"
 #include "GSwifi_conf.h"
+#include <stdlib.h>
 #include <ctype.h>
 
 
@@ -142,7 +143,7 @@
     GSFunctionPointer onGsReceive;
 };
 
-#ifdef GS_USE_HTTPD
+#ifdef GS_ENABLE_HTTPD
 enum GSHTTPDMODE {
     GSHTTPDMODE_REQUEST,
     GSHTTPDMODE_HEAD,
@@ -165,7 +166,7 @@
     int length;  // content-length
     int keepalive;
     Host host;
-#ifdef GS_USE_WEBSOCKET
+#ifdef GS_ENABLE_WEBSOCKET
     int websocket;
     char *websocket_key;
     int websocket_flg;
@@ -181,7 +182,7 @@
     char *dir;
     onHttpdCgiFunc onHttpCgi;
 };
-#endif // GS_USE_HTTPD
+#endif // GS_ENABLE_HTTPD
 
     // ----- GSwifi.cpp -----
     /**
@@ -193,10 +194,6 @@
      */
     GSwifi (PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts, PinName p_reset, PinName p_alarm = NC, int baud = GS_BAUD);
     /**
-     * reset module
-     */
-    void reset ();
-    /**
      * send command
      */
     int command (const char *cmd, GSRESPONCE res, int timeout = GS_TIMEOUT);
@@ -218,7 +215,7 @@
      * @retval 0 success
      * @retval -1 failure
      */
-    int connect (GSSECURITY sec, const char *ssid, const char *pass, int dhcp = 1, int reconnect = 0);
+    int connect (GSSECURITY sec, const char *ssid, const char *pass, int dhcp = 1, int reconnect = 0, char *name = NULL);
     /**
      * adhock
      * @param sec GSSEC_OPEN or GSSEC_WEP
@@ -254,7 +251,7 @@
     /**
      * use DHCP
      */
-    int setAddress ();
+    int setAddress (char *name = NULL);
     /**
      * use static ip address
      */
@@ -424,6 +421,7 @@
      */
     bool isConnected (int cid);
 
+#ifdef GS_ENABLE_HTTP
 // ----- GSwifi_http.cpp -----
     /**
      * http request (GET method)
@@ -463,8 +461,9 @@
      * url decode
      */
     int urldecode (char *str, char *buf, int len);
+#endif
 
-#ifdef GS_USE_SMTP
+#ifdef GS_ENABLE_SMTP
 // ----- GSwifi_smtp.cpp -----
     /**
      * send mail (smtp)
@@ -481,7 +480,7 @@
     int mail (Host &host, const char *to, const char *from, const char *subject, const char *mesg, const char *user = NULL, const char *pwd = NULL);
 #endif
 
-#ifdef GS_USE_HTTPD
+#ifdef GS_ENABLE_HTTPD
 // ----- GSwifi_httpd.cpp -----
     /**
      * start http server
@@ -511,6 +510,9 @@
 #endif
 
 protected:
+    void reset ();
+    int autobaud (int flg);
+
     void parseResponse ();
     void parseCmdResponse (char *buf);
 
@@ -534,11 +536,11 @@
 
     int wait_ws (int cid, int code);
 
-#ifdef GS_USE_SMTP
+#ifdef GS_ENABLE_SMTP
     int wait_smtp (int cid, int code);
 #endif
 
-#ifdef GS_USE_HTTPD
+#ifdef GS_ENABLE_HTTPD
     int get_handler (char *uri);
     int httpd_request (int cid, GS_httpd *gshttpd, char *dir);
     char *mimetype (char *file);
@@ -547,6 +549,7 @@
 
 private:
     Serial _gs;
+    int _baud;
     bool _rts;
     DigitalInOut _reset;
     DigitalInOut *_alarm;
@@ -555,9 +558,9 @@
     volatile bool _gs_ok, _gs_failure;
     volatile int _gs_flg;
     volatile GSRESPONCE _gs_res;
-    GSMODE _gs_mode;
-    bool _escape;
-    int _cid, _rssi;
+    volatile GSMODE _gs_mode;
+    volatile bool _escape;
+    volatile int _cid, _rssi;
     IpAddr _ipaddr, _netmask, _gateway, _nameserver, _resolv;
     Host _from, _to;
     char _mac[6];
@@ -567,14 +570,15 @@
     GSSECURITY _sec;
     char *_ssid, *_pass;
     int _reconnect, _reconnect_count;
+    time_t _reconnect_time;
     
-#ifdef GS_USE_HTTPD
+#ifdef GS_ENABLE_HTTPD
     struct GS_httpd _httpd[16];
     struct GS_httpd_handler _handler[10];
     int _handler_count;
 
     void poll_httpd (int cid, int len);
-#ifdef GS_USE_WEBSOCKET
+#ifdef GS_ENABLE_WEBSOCKET
     void poll_websocket (int cid, int len);
     void send_websocket_accept (int cid);
 #endif
--- a/GSwifi_conf.h	Fri Mar 29 14:58:07 2013 +0000
+++ b/GSwifi_conf.h	Fri Jun 21 06:08:37 2013 +0000
@@ -6,18 +6,21 @@
 //#define GS_UART_DIRECT
 #define GS_BULK
 
+#define GS_DHCPNAME "mbed-gs"
 #define GS_DNSNAME "setup.local"
 #define GS_WREGDOMAIN 2 // 0:FCC, 1:ETSI, 2:TELEC
 
 #define GS_TIMEOUT 10000 // ms
 #define GS_TIMEOUT2 130000 // ms
+#define GS_RECONTIME 60 // s
+
 #define GS_CMD_SIZE 100
 
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
 //#define GS_DATA_SIZE 1500
 #define GS_DATA_SIZE 1024
 #elif defined(TARGET_LPC11U24)
-#define GS_DATA_SIZE 512
+#define GS_DATA_SIZE 256
 #elif defined(TARGET_KL25Z)
 #define GS_DATA_SIZE 512
 #endif
@@ -26,14 +29,18 @@
 
 // ----- GSwifi_smtp.cpp -----
 
-#define GS_USE_SMTP  // use smtp client
+#define GS_ENABLE_SMTP  // use smtp client
 
 #define SMTP_TIMEOUT 15000
 
 // ----- GSwifi_http.cpp -----
 
-#define GS_USE_HTTPD  // use http server
-//#define GS_USE_WEBSOCKET  // use websocket server (need httpd)
+#define GS_ENABLE_HTTP  // use http client
+
+// ----- GSwifi_httpd.cpp -----
+
+//#define GS_ENABLE_HTTPD  // use http server
+//#define GS_ENABLE_WEBSOCKET  // use websocket server (need httpd)
 
 #define HTTPD_TIMEOUT 15000
 #define HTTPD_HANDLE 10
--- a/GSwifi_http.cpp	Fri Mar 29 14:58:07 2013 +0000
+++ b/GSwifi_http.cpp	Fri Jun 21 06:08:37 2013 +0000
@@ -20,6 +20,9 @@
  * GS1011MIC, GS1011MIP, GainSpan WiFi Breakout, etc.
  */
 
+#include "GSwifi_conf.h"
+#ifdef GS_ENABLE_HTTP
+
 #include "dbg.h"
 #include "mbed.h"
 #include "GSwifi.h"
@@ -340,3 +343,5 @@
     *pbuf = '\0';
     return 0;
 }
+
+#endif
--- a/GSwifi_httpd.cpp	Fri Mar 29 14:58:07 2013 +0000
+++ b/GSwifi_httpd.cpp	Fri Jun 21 06:08:37 2013 +0000
@@ -20,14 +20,15 @@
  * GS1011MIC, GS1011MIP, GainSpan WiFi Breakout, etc.
  */
 
+#include "GSwifi_conf.h"
+#ifdef GS_ENABLE_HTTPD
+
 #include "dbg.h"
 #include "mbed.h"
 #include "GSwifi.h"
 #include "sha1.h"
 #include <string.h>
 
-#ifdef GS_USE_HTTPD
-
 #define MIMETABLE_NUM 9
 static const struct {
     char ext[5];
@@ -72,13 +73,13 @@
         _httpd[cid].mode = GSHTTPDMODE_REQUEST;
         _httpd[cid].len = 0;
         _httpd[cid].keepalive = 0;
-#ifdef GS_USE_WEBSOCKET
+#ifdef GS_ENABLE_WEBSOCKET
         _httpd[cid].websocket = 0;
 #endif
         return;
     }
 
-#ifdef GS_USE_WEBSOCKET
+#ifdef GS_ENABLE_WEBSOCKET
     if (_httpd[cid].mode >= GSHTTPDMODE_WEBSOCKET) {
         poll_websocket(cid, len);
         return;
@@ -88,7 +89,7 @@
   while (_gs_sock[cid].connect && (! _gs_sock[cid].data->isEmpty())) {
     flg = 0;
     if (_httpd[cid].buf == NULL) {
-        _httpd[cid].buf = new char[HTTPD_BUF_SIZE];
+        _httpd[cid].buf = (char*)malloc(HTTPD_BUF_SIZE);
     }
     // get 1 line
     for (j = 0; j < len; j ++) {
@@ -130,7 +131,7 @@
         i = i - j;
         if (i) {
             if (_httpd[cid].uri == NULL) {
-                _httpd[cid].uri = new char[HTTPD_URI_SIZE];
+                _httpd[cid].uri = (char*)malloc(HTTPD_URI_SIZE);
             }
             strncpy(_httpd[cid].uri, &_httpd[cid].buf[j], i);
             _httpd[cid].uri[i] = 0;
@@ -145,7 +146,7 @@
             // blank line (end of header)
             _httpd[cid].mode = GSHTTPDMODE_BODY;
             if (_httpd[cid].length == 0) flg = 1; // no body
-#ifdef GS_USE_WEBSOCKET
+#ifdef GS_ENABLE_WEBSOCKET
             if (_httpd[cid].websocket && _httpd[cid].websocket_key) {
                 // enter websocket
                 _httpd[cid].mode = GSHTTPDMODE_WEBSOCKET;
@@ -161,7 +162,7 @@
             if (! _httpd[cid].keepalive) {
                 _httpd[cid].keepalive = HTTPD_KEEPALIVE;
             }
-#ifdef GS_USE_WEBSOCKET
+#ifdef GS_ENABLE_WEBSOCKET
         } else
         if (strnicmp(_httpd[cid].buf, "Upgrade: websocket", 18) == 0) {
             if (! _httpd[cid].websocket) _httpd[cid].websocket = 1;
@@ -171,7 +172,7 @@
         } else
         if (strnicmp(_httpd[cid].buf, "Sec-WebSocket-Key: ", 19) == 0) {
             if (_httpd[cid].websocket_key == NULL) {
-                _httpd[cid].websocket_key = new char[30];
+                _httpd[cid].websocket_key = (char*)malloc(30);
             }
             strncpy(_httpd[cid].websocket_key, &_httpd[cid].buf[19], 30);
 #endif
@@ -187,7 +188,7 @@
 
     }
 
-#ifdef GS_USE_WEBSOCKET
+#ifdef GS_ENABLE_WEBSOCKET
     if (flg && _httpd[cid].mode == GSHTTPDMODE_WEBSOCKET) {
         // websocket
         i = get_handler(_httpd[cid].uri);
@@ -393,9 +394,9 @@
 
 int GSwifi::attach_httpd (const char *uri, const char *dir) {
     if (_handler_count < HTTPD_HANDLE) {
-        _handler[_handler_count].uri = new char[strlen(uri) + 1];
+        _handler[_handler_count].uri = (char*)malloc(strlen(uri) + 1);
         strcpy(_handler[_handler_count].uri, uri);
-        _handler[_handler_count].dir = new char[strlen(dir) + 1];
+        _handler[_handler_count].dir = (char*)malloc(strlen(dir) + 1);
         strcpy(_handler[_handler_count].dir, dir);
         _handler[_handler_count].onHttpCgi = NULL;
         _handler_count ++;
@@ -407,7 +408,7 @@
 
 int GSwifi::attach_httpd (const char *uri, onHttpdCgiFunc ponHttpCgi) {
     if (_handler_count < HTTPD_HANDLE) {
-        _handler[_handler_count].uri = new char[strlen(uri) + 1];
+        _handler[_handler_count].uri = (char*)malloc(strlen(uri) + 1);
         strcpy(_handler[_handler_count].uri, uri);
         _handler[_handler_count].dir = NULL;
         _handler[_handler_count].onHttpCgi = ponHttpCgi;
@@ -418,7 +419,7 @@
     }
 }
 
-#ifdef GS_USE_WEBSOCKET
+#ifdef GS_ENABLE_WEBSOCKET
 void GSwifi::poll_websocket (int cid, int len) {
     int i, j, flg;
     unsigned char c;
@@ -576,6 +577,6 @@
     LOG("%d.%d.%d.%d ", _httpd[cid].host.getIp()[0], _httpd[cid].host.getIp()[1], _httpd[cid].host.getIp()[2], _httpd[cid].host.getIp()[3]);
     LOG("%s %s %d 101 - %s\r\n", _httpd[cid].type == GSPROT_HTTPGET ? "GET" : "POST", _httpd[cid].uri, _httpd[cid].length, buf);
 }
-#endif
+#endif // GS_ENABLE_WEBSOCKET
 
 #endif
--- a/GSwifi_smtp.cpp	Fri Mar 29 14:58:07 2013 +0000
+++ b/GSwifi_smtp.cpp	Fri Jun 21 06:08:37 2013 +0000
@@ -20,12 +20,13 @@
  * GS1011MIC, GS1011MIP, GainSpan WiFi Breakout, etc.
  */
 
+#include "GSwifi_conf.h"
+#ifdef GS_ENABLE_SMTP
+
 #include "dbg.h"
 #include "mbed.h"
 #include "GSwifi.h"
 
-#ifdef GS_USE_SMTP
-
 int GSwifi::mail (Host &host, const char *to, const char *from, const char *subject, const char *mesg, const char *user, const char *pwd) {
     int ret = -1;
     int cid;