Socket interface for C027Interface. Implements the NetworkSocketAPI

Dependencies:   C027_Support

Dependents:   HelloC027Interface U_Blox_DeviceConnector U_Blox_DeviceConnector U-Blox_Client

Fork of LWIPInterface by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
geky
Date:
Wed Mar 02 17:21:54 2016 +0000
Parent:
4:a7349bd7776c
Child:
6:ebba105e893b
Child:
7:08d5a40ae448
Commit message:
Matched changes to NetworkSocketAPI

Changed in this revision

LWIPInterface.cpp Show annotated file Show diff for this revision Revisions of this file
LWIPInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/LWIPInterface.cpp	Mon Feb 29 23:01:54 2016 +0000
+++ b/LWIPInterface.cpp	Wed Mar 02 17:21:54 2016 +0000
@@ -31,9 +31,9 @@
 
 
 /* TCP/IP and Network Interface Initialisation */
-static LWIPInterface *iface = 0;
 static struct netif netif;
 
+static char ip_addr[NS_IP_SIZE] = "\0";
 static char mac_addr[NS_MAC_SIZE] = "\0";
 
 static Semaphore tcpip_inited(0);
@@ -52,9 +52,7 @@
 
 static void netif_status_callback(struct netif *netif) {
     if (netif_is_up(netif)) {
-        iface->setIPAddress  (inet_ntoa(netif->ip_addr));
-        iface->setNetworkMask(inet_ntoa(netif->netmask));
-        iface->setGateway    (inet_ntoa(netif->gw));
+        strcpy(ip_addr, inet_ntoa(netif->ip_addr));
         netif_up.release();
     }
 }
@@ -86,44 +84,19 @@
 // LWIPInterface implementation
 int32_t LWIPInterface::connect()
 {
-    // Only one instance of LWIP is currently supported
-    if (iface) {
-        return NS_ERROR_DEVICE_ERROR;
-    }
-
-    iface = this;
-
     // Set up network
     set_mac_address();
-
-    if (getDHCP()) {
-        init_netif(0, 0, 0);
-    } else {
-        ip_addr_t ip_n, mask_n, gateway_n;
-        inet_aton(getIPAddress(), &ip_n);
-        inet_aton(getNetworkMask(), &mask_n);
-        inet_aton(getGateway(), &gateway_n);
-        init_netif(&ip_n, &mask_n, &gateway_n);
-    }
+    init_netif(0, 0, 0);
 
     // Connect to network
     eth_arch_enable_interrupts();
 
-    if (getDHCP()) {
-        dhcp_start(&netif);
+    dhcp_start(&netif);
         
-        // Wait for an IP Address
-        // -1: error, 0: timeout
-        if (netif_up.wait(LWIP_TIMEOUT) < 0) {
-            return NS_ERROR_TIMEOUT;
-        }
-    } else {
-        netif_set_up(&netif);
-        
-        // Wait for the link up
-        if (netif_linked.wait(LWIP_TIMEOUT) < 0) {
-            return NS_ERROR_TIMEOUT;
-        }
+    // Wait for an IP Address
+    // -1: error, 0: timeout
+    if (netif_up.wait(LWIP_TIMEOUT) < 0) {
+        return NS_ERROR_TIMEOUT;
     }
 
     return 0;
@@ -131,18 +104,19 @@
 
 int32_t LWIPInterface::disconnect()
 {
-    if (getDHCP()) {
-        dhcp_release(&netif);
-        dhcp_stop(&netif);
-    } else {
-        netif_set_down(&netif);
-    }
+    dhcp_release(&netif);
+    dhcp_stop(&netif);
     
     eth_arch_disable_interrupts();
     
     return 0;
 }
 
+const char *LWIPInterface::getIPAddress()
+{
+    return ip_addr;
+}
+
 const char *LWIPInterface::getMACAddress() 
 {
     return mac_addr;
--- a/LWIPInterface.h	Mon Feb 29 23:01:54 2016 +0000
+++ b/LWIPInterface.h	Wed Mar 02 17:21:54 2016 +0000
@@ -33,6 +33,7 @@
     virtual int32_t disconnect();
 
     // Implementation of NetworkInterface
+    virtual const char *getIPAddress();
     virtual const char *getMACAddress();
 
     virtual SocketInterface *createSocket(ns_protocol_t proto);