update main WIZnetInterface library for supporting honeypot server

Fork of WIZnetInterface by Shlomi Ruder

Update WIZnetInterface for supporting Honeypot server

/media/uploads/proxytype/honeypot.png

Update sockets handling.

//add new type to enum status
 SOCK_TIMEOUT     = 0x23,

Files at this revision

API Documentation at this revision

Comitter:
proxytype
Date:
Fri Sep 01 23:36:01 2017 +0000
Parent:
29:c91884bd2713
Commit message:

Changed in this revision

Socket/TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketServer.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketServer.h Show annotated file Show diff for this revision Revisions of this file
arch/int/W7500x_toe.h Show annotated file Show diff for this revision Revisions of this file
diff -r c91884bd2713 -r 58f7cd21cf37 Socket/TCPSocketConnection.cpp
--- a/Socket/TCPSocketConnection.cpp	Tue Nov 17 06:35:55 2015 +0000
+++ b/Socket/TCPSocketConnection.cpp	Fri Sep 01 23:36:01 2017 +0000
@@ -80,6 +80,8 @@
 	if(_sock_fd<0)
 		return -1;
 
+	//printf("writtenLen: %i length: %i\n\r", writtenLen, length); 
+
     while (writtenLen < length) {
 
 		if(!(eth->is_connected(_sock_fd)))
@@ -92,6 +94,9 @@
         if (size > (length-writtenLen)) {
             size = (length-writtenLen);
         }
+        
+        //printf("Size: %i \n\r", size); 
+        
         int ret = eth->send(_sock_fd, data + writtenLen, size);
         if (ret < 0) {
             return -1;
diff -r c91884bd2713 -r 58f7cd21cf37 Socket/TCPSocketServer.cpp
--- a/Socket/TCPSocketServer.cpp	Tue Nov 17 06:35:55 2015 +0000
+++ b/Socket/TCPSocketServer.cpp	Fri Sep 01 23:36:01 2017 +0000
@@ -23,8 +23,8 @@
 // Server initialization
 int TCPSocketServer::bind(int port)
 {
-   // set the listen_port for next connection. 
-   listen_port = port;
+    // set the listen_port for next connection.
+    listen_port = port;
     if (_sock_fd < 0) {
         _sock_fd = eth->new_socket();
         if (_sock_fd < 0) {
@@ -37,6 +37,8 @@
     eth->sreg<uint16_t>(_sock_fd, Sn_PORT, port);
     // connect the network
     eth->scmd(_sock_fd, WIZnet_Chip::OPEN);
+
+
     return 0;
 }
 
@@ -56,6 +58,7 @@
 int TCPSocketServer::accept(TCPSocketConnection& connection)
 {
     if (_sock_fd < 0) {
+        printf("socket closed");
         return -1;
     }
     Timer t;
@@ -63,11 +66,25 @@
     t.start();
     while(1) {
         if (t.read_ms() > _timeout && _blocking == false) {
-            return -1;
+             //nothing in the queue keep pooling
+             return WIZnet_Chip::SOCK_TIMEOUT;
+        }
+
+        //should rebinding again.
+        if (eth->sreg<uint8_t>(_sock_fd, Sn_SR) == WIZnet_Chip::SOCK_CLOSED) {
+            return WIZnet_Chip::SOCK_CLOSED;
         }
+        
+        //should rebinding again.
+        if (eth->sreg<uint8_t>(_sock_fd, Sn_SR) == WIZnet_Chip::SOCK_CLOSE_WAIT) {
+             break;
+        }
+
+        //connection establish, start processing
         if (eth->sreg<uint8_t>(_sock_fd, Sn_SR) == WIZnet_Chip::SOCK_ESTABLISHED) {
             break;
         }
+
     }
     uint32_t ip = eth->sreg<uint32_t>(_sock_fd, Sn_DIPR);
     char host[16];
@@ -83,16 +100,21 @@
     _sock_fd = -1; // want to assign new available _sock_fd.
     if(bind(listen_port) < 0) {
         // modified by Patrick Pollet
-        error("No more socket for listening, bind error");
+        printf("No more socket for listening, bind error");
         return -1;
     } else {
         //return -1;
         if(listen(1) < 0) {
             // modified by Patrick Pollet
-            error("No more socket for listening, listen error");
+            printf("No more socket for listening, listen error");
             return -1;
         }
     }
 
-    return 0;
+    return WIZnet_Chip::SOCK_ESTABLISHED;
 }
+
+int TCPSocketServer::getPort()
+{
+    return listen_port;
+}
diff -r c91884bd2713 -r 58f7cd21cf37 Socket/TCPSocketServer.h
--- a/Socket/TCPSocketServer.h	Tue Nov 17 06:35:55 2015 +0000
+++ b/Socket/TCPSocketServer.h	Fri Sep 01 23:36:01 2017 +0000
@@ -28,6 +28,7 @@
 public:
     /** Instantiate a TCP Server.
     */
+
     TCPSocketServer();
 
     /** Bind a socket to a specific port.
@@ -48,6 +49,7 @@
     \return 0 on success, -1 on failure.
     */
     int accept(TCPSocketConnection& connection);
+    int getPort();
 
 private :
     int listen_port;
diff -r c91884bd2713 -r 58f7cd21cf37 arch/int/W7500x_toe.h
--- a/arch/int/W7500x_toe.h	Tue Nov 17 06:35:55 2015 +0000
+++ b/arch/int/W7500x_toe.h	Fri Sep 01 23:36:01 2017 +0000
@@ -104,6 +104,7 @@
     SOCK_ESTABLISHED = 0x17,
     SOCK_CLOSE_WAIT  = 0x1c,
     SOCK_UDP         = 0x22,
+    SOCK_TIMEOUT     = 0x23,
 };
 enum Mode {
 	MR_RST           = 0x80,