Hostname Attempt

Dependencies:   Socket lwip-eth lwip-sys lwip

Fork of EthernetInterface by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mmdonatti
Date:
Thu May 10 18:17:50 2018 +0000
Parent:
54:183490eb1b4a
Child:
56:0642ca02cebc
Commit message:
hostname tentative (not working yet)

Changed in this revision

EthernetInterface.cpp Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.h Show annotated file Show diff for this revision Revisions of this file
lwip-eth.lib Show annotated file Show diff for this revision Revisions of this file
lwip.lib Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.cpp	Wed May 11 22:18:04 2016 +0000
+++ b/EthernetInterface.cpp	Thu May 10 18:17:50 2018 +0000
@@ -27,6 +27,10 @@
 
 #include "mbed.h"
 
+#include "lpc_phy.h"
+
+
+
 /* TCP/IP and Network Interface Initialisation */
 static struct netif netif;
 
@@ -36,6 +40,9 @@
 static char networkmask[17] = "\0";
 static bool use_dhcp = false;
 
+static char myName[33];  // holds the name, when setName() is called.
+
+
 static Semaphore tcpip_inited(0);
 static Semaphore netif_linked(0);
 static Semaphore netif_up(0);
@@ -60,11 +67,14 @@
 }
 
 static void init_netif(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) {
+    
     tcpip_init(tcpip_init_done, NULL);
     tcpip_inited.wait();
     
     memset((void*) &netif, 0, sizeof(netif));
     netif_add(&netif, ipaddr, netmask, gw, NULL, eth_arch_enetif_init, tcpip_input);
+    
+    //netif.hostname=hostname;
     netif_set_default(&netif);
     
     netif_set_link_callback  (&netif, netif_link_callback);
@@ -104,6 +114,16 @@
     return 0;
 }
 
+uint32_t EthernetInterface::mii_read_data(void) {
+    return lpc_mii_read_data();  // 16-bit MRDD - address 0x2008 4030
+}
+
+bool EthernetInterface::is_connected(void) {
+    uint32_t tmp = lpc_mii_read_data();
+    
+    return (tmp & DP8_VALID_LINK) ? true : false;
+}
+
 int EthernetInterface::connect(unsigned int timeout_ms) {
     eth_arch_enable_interrupts();
 
@@ -153,4 +173,20 @@
     return networkmask;
 }
 
+int EthernetInterface::setName(const char * myname) {
+    int i;
+    
+    strcpy(myName, myname);
+    myName[32] = '\0';  // be sure it is NULL terminated.
+    // make the name 'safe'
+    for (i=0; i<32 && myName[i] != '\0'; i++) {
+        if(myName[i]<'0'||myName[i]>'z'||(myName[i]>'9'&&myName[i]<'A')||(myName[i]>'Z'&&myName[i]<'a'))
+            myName[i] = '-';
+    }
+    netif_set_hostname(&netif, myName);
+    return 0;
+}
 
+char* EthernetInterface::getName() {
+    return netif_get_hostname(&netif);
+}
--- a/EthernetInterface.h	Wed May 11 22:18:04 2016 +0000
+++ b/EthernetInterface.h	Thu May 10 18:17:50 2018 +0000
@@ -27,6 +27,8 @@
 #include "rtos.h"
 #include "lwip/netif.h"
 
+#define DP8_VALID_LINK     (1 << 0)   /**< 1=Link active */
+
  /** Interface using Ethernet to connect to an IP-based network
  *
  */
@@ -60,6 +62,20 @@
   */
   static int disconnect();
   
+  /** is_connected
+  *
+  * Determine if the interface is up and connected.
+  * 
+  * \example
+  *      if (eth.is_connected())
+  *         ethLED = 1;
+  *      else
+  *         ethLED = 0;
+  *
+  * \return true if connected, false if not connected.
+  */
+  static bool is_connected(void);
+  
   /** Get the MAC address of your Ethernet interface
    * \return a pointer to a string containing the MAC address
    */
@@ -79,6 +95,25 @@
    * \return a pointer to a string containing the Network mask
    */
   static char* getNetworkMask();
+  
+    /** setName 
+  *
+  * Set the network name for this device. Apply this before
+  * calling 'connect'.
+  *
+  * \param myname is the name to assign for this node. 
+  *        Only the first 32 characters will be used if the 
+  *        name is longer.
+  *        Only '0'-'9', 'A'-'Z', 'a'-'z' are accepted,
+  *        any others are converted to '-'.
+  * \return 0 on success, a negative number on failure.
+  */
+  static int setName(const char * myname);
+  
+  uint32_t mii_read_data(void);
+
+  char* getName();
+
 };
 
 #include "TCPSocketConnection.h"
--- a/lwip-eth.lib	Wed May 11 22:18:04 2016 +0000
+++ b/lwip-eth.lib	Thu May 10 18:17:50 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/lwip-eth/#da93f0f73711
+http://mbed.org/users/mbed_official/code/lwip-eth/#9de8bd8ca1c8
--- a/lwip.lib	Wed May 11 22:18:04 2016 +0000
+++ b/lwip.lib	Thu May 10 18:17:50 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/lwip/#1046f8be4d44
+http://mbed.org/users/mbed_official/code/lwip/#83acd30508d0