Kojto CC3000 Hostdriver With Mbed Socket interface

Dependents:   WiFiDip-KitchenSink WiFiDip-UsbKitchenSink WiFiDipCortexSensor WifiDipCortex-UDPDemo

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Revision:
42:bd2c631a031a
Parent:
41:eb1999bd50fb
Child:
44:960b73df5981
--- a/cc3000.cpp	Sat Oct 12 21:03:45 2013 +0000
+++ b/cc3000.cpp	Sat Oct 12 21:53:28 2013 +0000
@@ -93,41 +93,6 @@
     return networkmask;
 }
 
-/* Copied from lwip , modified to accept an uint32*/
-static char *inet_ntoa_r(uint32_t s_addr, char *buf, int buflen)
-{
-  char inv[3];
-  char *rp;
-  uint8_t *ap;
-  uint8_t rem;
-  uint8_t n;
-  uint8_t i;
-  int len = 0;
-
-  rp = buf;
-  ap = (uint8_t *)&s_addr;
-  for(n = 0; n < 4; n++) {
-    i = 0;
-    do {
-      rem = *ap % (uint8_t)10;
-      *ap /= (uint8_t)10;
-      inv[i++] = '0' + rem;
-    } while(*ap);
-    while(i--) {
-      if (len++ >= buflen) {
-        return NULL;
-      }
-      *rp++ = inv[i];
-    }
-    if (len++ >= buflen) {
-      return NULL;
-    }
-    *rp++ = '.';
-    ap++;
-  }
-  *--rp = 0;
-  return buf;
-}
 #endif
 
 void cc3000::usync_callback(int32_t event_type, uint8_t * data, uint8_t length) {
@@ -158,10 +123,10 @@
     {
         #ifdef CC3000_ETH_COMPAT
         
-        inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_IP_OFFSET]))), ip_addr, 17);
-        inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_GW_OFFSET]))), gateway, 17);
-        inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_SUBNET_OFFSET]))), networkmask, 17);
-        inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_MAC_OFFSET]))), mac_addr, 19);
+        _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_IP_OFFSET]))), ip_addr, 17);
+        _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_GW_OFFSET]))), gateway, 17);
+        _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_SUBNET_OFFSET]))), networkmask, 17);
+        _socket.inet_ntoa_r( htonl(*((uint32_t *)(&data[NETAPP_IPCONFIG_MAC_OFFSET]))), mac_addr, 19);
         
         #endif
         
@@ -169,7 +134,7 @@
             _status.dhcp = 1;
             DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP %i.%i.%i.%i", data[3], data[2], data[1], data[0]);
         } else {
-            DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP - Disconnected");
+            DBG_CC("Callback : HCI_EVNT_WLAN_UNSOL_DHCP - Disconnecting");
             _status.dhcp = 0;
         }
     }
@@ -201,6 +166,11 @@
 
     _status.smart_config_complete = 0;
     _wlan.ioctl_set_connection_policy(0, 0, 0);
+    
+    if (_status.connected == 1)
+    {
+        disconnect();
+    }
 
     //Wait until CC3000 is disconected
     while (_status.connected == 1)
@@ -251,7 +221,7 @@
 bool cc3000::connect_secure(const uint8_t *ssid, const uint8_t *key, int32_t security_mode) {
     uint32_t ret;
 
-    _wlan.disconnect();
+    //_wlan.disconnect();
     wait_ms(3);
     ret = _wlan.connect(security_mode, ssid, strlen((const char *)ssid), 0, (uint8_t *)key, strlen((const char *)key));
     if (ret == 0) { /* TODO static internal cc3000 state 0 to TRUE */
@@ -364,7 +334,14 @@
 }
 
 bool cc3000::is_connected() {
-    return _status.connected;
+    if (( _status.connected ) && ( _status.dhcp ))
+    {
+        return( 1 );
+    }
+    else
+    {
+        return( 0 );
+    }
 }
 
 bool cc3000::is_dhcp_configured() {