Fix TCP/IP udp support.

Change-Id: I819c54e13b5198d11b9e526e8eb2ca8bccc069f8
diff --git a/mbtk/mbtk_lib/src/mbtk_tcpip_at.c b/mbtk/mbtk_lib/src/mbtk_tcpip_at.c
index 76dc526..2ecef9d 100755
--- a/mbtk/mbtk_lib/src/mbtk_tcpip_at.c
+++ b/mbtk/mbtk_lib/src/mbtk_tcpip_at.c
@@ -175,13 +175,13 @@
     }
 }
 
-static void tcpip_sock_cb_func(int handle, int fd, int event)
+static void tcpip_sock_cb_func(int handle, mbtk_sock_cb_info_s *sock_info)
 {
     if(tcpip_inited && tcpip_handle == handle/* && http_fd == fd*/) {
-        if(event & (EPOLLIN | EPOLLOUT)) { // Cand read or write.
+        if(sock_info->event & (EPOLLIN | EPOLLOUT)) { // Cand read or write.
             int sock_error = 0;
             socklen_t socklen = sizeof(sock_error);
-            if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &sock_error, (socklen_t*)&socklen) == 0) {
+            if(getsockopt(sock_info->sock_fd, SOL_SOCKET, SO_ERROR, &sock_error, (socklen_t*)&socklen) == 0) {
                 LOGD("Socket error:%d", sock_error);
             }
 
@@ -190,39 +190,41 @@
                 return;
             }
 
-            struct tcp_info info;
-            int len = sizeof(info);
-            if(getsockopt(fd, IPPROTO_TCP, TCP_INFO, &info, (socklen_t*)&len) == 0) {
-                LOGD("State : %d", info.tcpi_state);
+            if(sock_info->sock_type == MBTK_SOCK_TCP) {
+                struct tcp_info info;
+                int len = sizeof(info);
+                if(getsockopt(sock_info->sock_fd, IPPROTO_TCP, TCP_INFO, &info, (socklen_t*)&len) == 0) {
+                    LOGD("State : %d", info.tcpi_state);
 #if TCPIP_DEBUG
-                tcp_info_print(&info);
+                    tcp_info_print(&info);
 #endif
-            }
-
-            if(TCP_ESTABLISHED != info.tcpi_state) {
-                LOGW("errno = %d", errno);
-                int link_id = tcpip_fd_2_link(fd);
-                if(link_id >= 0) {
-                    // Socket disconnected?
-                    mbtk_tcpip_sock_close(link_id);
-
-                    if(tcpip_sock_cb) {
-                        tcpip_sock_cb(link_id, 0);
-                    }
                 }
-                return;
+
+                if(TCP_ESTABLISHED != info.tcpi_state) {
+                    LOGW("errno = %d", errno);
+                    int link_id = tcpip_fd_2_link(sock_info->sock_fd);
+                    if(link_id >= 0) {
+                        // Socket disconnected?
+                        mbtk_tcpip_sock_close(link_id);
+
+                        if(tcpip_sock_cb) {
+                            tcpip_sock_cb(link_id, 0);
+                        }
+                    }
+                    return;
+                }
             }
         }
 
-        if(event & EPOLLIN) { // READ
-            LOGD("fd[%d] can read.", fd);
-            int link_id = tcpip_fd_2_link(fd);
+        if(sock_info->event & EPOLLIN) { // READ
+            LOGD("fd[%d] can read.", sock_info->sock_fd);
+            int link_id = tcpip_fd_2_link(sock_info->sock_fd);
             if(link_id >= 0) {
                 if(tcpip_link[link_id].type == MBTK_TCPIP_TYPE_CLIENT) {
                     if(tcpip_link[link_id].tcpip_info.cli_info.read_cb) {
                         char buff[MBTK_TCPIP_READ_BUFF_SIZE];
                         memset(buff, 0x0, MBTK_TCPIP_READ_BUFF_SIZE);
-                        int read_len = mbtk_sock_read_async(tcpip_handle, fd, buff, MBTK_TCPIP_READ_BUFF_SIZE);
+                        int read_len = mbtk_sock_read_async(tcpip_handle, sock_info->sock_fd, buff, MBTK_TCPIP_READ_BUFF_SIZE);
                         if(read_len > 0) {
                             tcpip_link[link_id].tcpip_info.cli_info.data_traffic_recv += read_len;
                             tcpip_link[link_id].tcpip_info.cli_info.read_cb(link_id, (const char*)buff, read_len);
@@ -240,7 +242,7 @@
 #endif
                         while(read_len > 0) {
                             memset(buff, 0x0, MBTK_TCPIP_READ_BUFF_SIZE);
-                            read_len = mbtk_sock_read_async(tcpip_handle, fd, buff, MBTK_TCPIP_READ_BUFF_SIZE);
+                            read_len = mbtk_sock_read_async(tcpip_handle, sock_info->sock_fd, buff, MBTK_TCPIP_READ_BUFF_SIZE);
                             // LOGD("read_len = %d", read_len);
                             if(read_len > 0) {
                                 tcpip_link[link_id].tcpip_info.cli_info.data_traffic_recv += read_len;
@@ -253,24 +255,24 @@
 
                 }
             }
-        } else if(event & EPOLLRDHUP) { // Close
-            LOGD("fd[%d] Closed?", fd);
+        } else if(sock_info->event & EPOLLRDHUP) { // Close
+            LOGD("fd[%d] Closed?", sock_info->sock_fd);
         } else {
-            LOGW("Unknown event:%x",event);
+            LOGW("Unknown event:%x",sock_info->event);
         }
     }
 }
 
-static void tcpip_net_cb_func(mbtk_sock_handle handle, int state, const char* addr, const char* if_name)
+static void tcpip_net_cb_func(mbtk_sock_handle handle, mbtk_net_cb_info_s *info)
 {
     if(tcpip_inited && tcpip_handle == handle) {
-        LOGD("Net state : %d, %s, %s", state, if_name, addr);
-        if(state == 0) {
+        LOGD("Net state : %d, %s, %s", info->state, info->if_name, info->addr);
+        if(info->state == 0) {
             mbtk_tcpip_net_close();
         }
 
         if(tcpip_net_cb) {
-            tcpip_net_cb(state, addr);
+            tcpip_net_cb(info->state, info->addr);
         }
     }
 }