karasevIA 2 лет назад
Родитель
Сommit
58bd123333

+ 1 - 0
eth_save_process.c

@@ -292,6 +292,7 @@ void ehternet_save_process_print(EthernetSaveConfig* config, const char* str) {
 }
 
 void ehternet_save_process_free(EthernetSaveConfig* config) {
+    FURI_LOG_E(TAG, "ehternet_save_process_free");
     ethernet_save_process_write(config);
     storage_file_close(config->log_file);
     storage_file_free(config->log_file);

+ 25 - 6
eth_worker.c

@@ -119,6 +119,19 @@ void eth_log(EthWorkerProcess process, const char* format, ...) {
     furi_string_free(fstring);
 }
 
+void eth_printf(const char* format, ...) {
+    furi_assert(static_worker);
+    va_list args;
+    va_start(args, format);
+    FuriString* fstring = furi_string_alloc_vprintf(format, args);
+    const char* string = furi_string_get_cstr(fstring);
+    va_end(args);
+
+    FURI_LOG_I(TAG, "%s", string);
+    //ehternet_save_process_print(static_worker->config, string);
+    furi_string_free(fstring);
+}
+
 static void eth_set_force_state(EthWorkerState state) {
     EthWorker* worker = static_worker;
     furi_assert(worker);
@@ -338,7 +351,7 @@ int32_t eth_worker_task(void* context) {
 
     furi_hal_spi_acquire(&furi_hal_spi_bus_handle_external);
     uint8_t W5500FifoSize[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
-    uint8_t dhcp_buffer[2000];
+    uint8_t dhcp_buffer[2048];
 
     reg_wizchip_spi_cbfunc(W5500_ReadByte, W5500_WriteByte);
     reg_wizchip_spiburst_cbfunc(W5500_ReadBuff, W5500_WriteBuff);
@@ -417,8 +430,14 @@ int32_t eth_worker_task(void* context) {
             }
             reg_dhcp_cbfunc(Callback_IPAssigned, Callback_IPAssigned, Callback_IPConflict);
             DHCP_init(DHCP_SOCKET, dhcp_buffer);
+            {
+                // DHCP_run();
+                // eth_log(EthWorkerProcessDHCP, "DHCP Send Discover");
+                // furi_delay_ms(1000);
+                // DHCP_stop();
+            }
             uint8_t next_cycle = 1;
-            uint8_t divider = 0;
+            uint16_t divider = 0;
             while(next_cycle && worker->state == EthWorkerStateDHCP) {
                 uint8_t dhcp_ret = DHCP_run();
                 switch(dhcp_ret) {
@@ -438,10 +457,10 @@ int32_t eth_worker_task(void* context) {
                     eth_log(EthWorkerProcessDHCP, "DHCP Failed");
                     break;
                 }
-                furi_delay_ms(100);
-                if(divider++ % 10 == 0) {
-                    eth_log(EthWorkerProcessDHCP, "DHCP process %d", divider / 10);
-                    if(divider > 250) {
+                furi_delay_ms(10);
+                if(divider++ % 100 == 0) {
+                    eth_log(EthWorkerProcessDHCP, "DHCP process %d", divider / 100);
+                    if(divider > 400) {
                         DHCP_stop();
                         eth_log(EthWorkerProcessDHCP, "DHCP Stop by timer");
                         eth_set_force_state(EthWorkerStateInited);

+ 2 - 1
eth_worker_ping.c

@@ -11,5 +11,6 @@ void ping_wait_ms(int ms) {
 }
 
 uint8_t ping_auto_interface(uint8_t* adress) {
-    return ping_count(PING_SOCKET, 20, adress);
+    return ping_auto(PING_SOCKET, adress);
+    //    return ping_count(PING_SOCKET, 20, adress);
 }

Разница между файлами не показана из-за своего большого размера
+ 571 - 571
lib/ioLibrary_Driver/Internet/DHCP/dhcp.c


+ 40 - 42
lib/ioLibrary_Driver/Internet/DHCP/dhcp.h

@@ -16,30 +16,30 @@
 //!
 //! Copyright (c)  2013, WIZnet Co., LTD.
 //! All rights reserved.
-//! 
-//! Redistribution and use in source and binary forms, with or without 
-//! modification, are permitted provided that the following conditions 
-//! are met: 
-//! 
-//!     * Redistributions of source code must retain the above copyright 
-//! notice, this list of conditions and the following disclaimer. 
+//!
+//! Redistribution and use in source and binary forms, with or without
+//! modification, are permitted provided that the following conditions
+//! are met:
+//!
+//!     * Redistributions of source code must retain the above copyright
+//! notice, this list of conditions and the following disclaimer.
 //!     * Redistributions in binary form must reproduce the above copyright
 //! notice, this list of conditions and the following disclaimer in the
-//! documentation and/or other materials provided with the distribution. 
-//!     * Neither the name of the <ORGANIZATION> nor the names of its 
-//! contributors may be used to endorse or promote products derived 
-//! from this software without specific prior written permission. 
-//! 
+//! documentation and/or other materials provided with the distribution.
+//!     * Neither the name of the <ORGANIZATION> nor the names of its
+//! contributors may be used to endorse or promote products derived
+//! from this software without specific prior written permission.
+//!
 //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
-//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
-//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
-//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
-//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
+//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 //! THE POSSIBILITY OF SUCH DAMAGE.
 //
 //*****************************************************************************
@@ -57,32 +57,28 @@ extern "C" {
  */
 #define _DHCP_DEBUG_
 
-
 /* Retry to processing DHCP */
-#define	MAX_DHCP_RETRY          2        ///< Maximum retry count
-#define	DHCP_WAIT_TIME          10       ///< Wait Time 10s
-
+#define MAX_DHCP_RETRY 2 ///< Maximum retry count
+#define DHCP_WAIT_TIME 10 ///< Wait Time 10s
 
 /* UDP port numbers for DHCP */
-#define DHCP_SERVER_PORT      	67	      ///< DHCP server port number
-#define DHCP_CLIENT_PORT         68	      ///< DHCP client port number
+#define DHCP_SERVER_PORT 67 ///< DHCP server port number
+#define DHCP_CLIENT_PORT 68 ///< DHCP client port number
 
+#define MAGIC_COOKIE 0x63825363 ///< You should not modify it number.
 
-#define MAGIC_COOKIE             0x63825363  ///< You should not modify it number.
-
-#define DCHP_HOST_NAME           "WIZnet\0"
+#define DCHP_HOST_NAME "WIZnet\0"
 
 /* 
  * @brief return value of @ref DHCP_run()
  */
-enum
-{
-   DHCP_FAILED = 0,  ///< Processing Fail
-   DHCP_RUNNING,     ///< Processing DHCP protocol
-   DHCP_IP_ASSIGN,   ///< First Occupy IP from DHPC server      (if cbfunc == null, act as default default_ip_assign)
-   DHCP_IP_CHANGED,  ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
-   DHCP_IP_LEASED,   ///< Stand by 
-   DHCP_STOPPED      ///< Stop processing DHCP protocol
+enum {
+    DHCP_FAILED = 0, ///< Processing Fail
+    DHCP_RUNNING, ///< Processing DHCP protocol
+    DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server      (if cbfunc == null, act as default default_ip_assign)
+    DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
+    DHCP_IP_LEASED, ///< Stand by
+    DHCP_STOPPED ///< Stop processing DHCP protocol
 };
 
 /*
@@ -90,7 +86,7 @@ enum
  * @param s   - socket number
  * @param buf - buffer for processing DHCP message
  */
-void DHCP_init(uint8_t s, uint8_t * buf);
+void DHCP_init(uint8_t s, uint8_t* buf);
 
 /*
  * @brief DHCP 1s Tick Timer handler
@@ -104,7 +100,7 @@ void DHCP_time_handler(void);
  * @param ip_update   - callback func when IP is changed
  * @param ip_conflict - callback func when the assigned IP is conflict with others.
  */
-void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
+void reg_dhcp_cbfunc(void (*ip_assign)(void), void (*ip_update)(void), void (*ip_conflict)(void));
 
 /*
  * @brief DHCP client in the main loop
@@ -117,14 +113,14 @@ void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_co
  *            @ref DHCP_STOPPED    \n
  *
  * @note This function is always called by you main task.
- */ 
+ */
 uint8_t DHCP_run(void);
 
 /*
  * @brief Stop DHCP processing
  * @note If you want to restart. call DHCP_init() and DHCP_run()
- */ 
-void    DHCP_stop(void);
+ */
+void DHCP_stop(void);
 
 /* Get Network information assigned from DHCP server */
 /*
@@ -154,8 +150,10 @@ void getDNSfromDHCP(uint8_t* ip);
  */
 uint32_t getDHCPLeasetime(void);
 
+void eth_printf(const char* format, ...);
+
 #ifdef __cplusplus
 }
 #endif
 
-#endif	/* _DHCP_H_ */
+#endif /* _DHCP_H_ */

+ 47 - 22
lib/ioLibrary_Driver/Internet/ICMP/ping.c

@@ -17,16 +17,17 @@ uint8_t ping_auto(uint8_t s, uint8_t* addr) {
     int32_t len = 0;
     uint8_t cnt = 0;
     int ret = 0;
+    rep = req = 0;
     for(i = 0; i <= 3; i++) {
         uint8_t sr = getSn_SR(s);
-        //logger("SR: %02X\r\n", sr);
+        eth_printf("SR: %02X", sr);
         switch(sr) {
         case SOCK_CLOSED:
             close(s);
             IINCHIP_WRITE(Sn_PROTO(s), IPPROTO_ICMP); // set ICMP Protocol
             if((ret = socket(s, Sn_MR_IPRAW, 3000, 0)) !=
                s) { // open the SOCKET with IPRAW mode, if fail then Error
-                //logger( "\r\n socket %d fail %d\r\n", s, ret);
+                eth_printf("  socket %d fail %d", s, ret);
 #ifdef PING_DEBUG
                 return SOCKET_ERROR;
 #endif
@@ -46,7 +47,7 @@ uint8_t ping_auto(uint8_t s, uint8_t* addr) {
                     rep++;
                     break;
                 } else if(cnt > 100) {
-                    //logger("Request Time out. \r\n");
+                    eth_printf("Request Time out.");
                     cnt = 0;
                     break;
                 } else {
@@ -61,7 +62,7 @@ uint8_t ping_auto(uint8_t s, uint8_t* addr) {
         }
 #ifdef PING_DEBUG
         if(req >= 3) {
-            //logger("Ping Request = %d, PING_Reply = %d\r\n", req, rep);
+            eth_printf("Ping Request = %d, PING_Reply = %d", req, rep);
 
             if(rep == req)
                 return PING_SUCCESS;
@@ -80,11 +81,11 @@ uint8_t ping_count(uint8_t s, uint16_t pCount, uint8_t* addr) {
     for(i = 0; i < pCount + 1; i++) {
         if(i != 0) {
             /* Output count number */
-            //logger( "\r\nNo.%d\r\n", (i-1));
+            eth_printf("No.%d", (i - 1));
         }
 
         uint8_t sr = getSn_SR(s);
-        //logger("SR: %d\r\n", sr);
+        eth_printf("SR: %d", sr);
         switch(sr) {
         case SOCK_CLOSED:
             close(s);
@@ -93,7 +94,7 @@ uint8_t ping_count(uint8_t s, uint16_t pCount, uint8_t* addr) {
             IINCHIP_WRITE(Sn_PROTO(s), IPPROTO_ICMP); // set ICMP Protocol
             if(socket(s, Sn_MR_IPRAW, 3000, 0) !=
                s) { // open the SOCKET with IPRAW mode, if fail then Error
-                //logger( "\r\n socket %d fail r\n", (s));
+                eth_printf(" socket %d fail ", (s));
 #ifdef PING_DEBUG
                 return SOCKET_ERROR;
 #endif
@@ -114,7 +115,7 @@ uint8_t ping_count(uint8_t s, uint16_t pCount, uint8_t* addr) {
                 }
                 /* wait_time for 2 seconds, Break on fail*/
                 if((cnt > 100)) {
-                    //logger( "\r\nRequest Time out. \r\n") ;
+                    eth_printf("Request Time out.");
                     cnt = 0;
                     break;
                 } else {
@@ -128,7 +129,7 @@ uint8_t ping_count(uint8_t s, uint16_t pCount, uint8_t* addr) {
         }
 #ifdef PING_DEBUG
         if(req >= pCount) {
-            //logger("Ping Request = %d, PING_Reply = %d\r\n", req, rep);
+            eth_printf("Ping Request = %d, PING_Reply = %d", req, rep);
             if(rep == req)
                 return PING_SUCCESS;
             else
@@ -165,11 +166,19 @@ uint8_t ping_request(uint8_t s, uint8_t* addr) {
     /* sendto ping_request to destination */
     if(sendto(s, (uint8_t*)&PingRequest, sizeof(PingRequest), addr, 3000) ==
        0) { // Send Ping-Request to the specified peer.
-        //logger( "\r\n Fail to send ping-reply packet  r\n") ;
+        eth_printf(" Fail to send ping-reply packet ");
     } else {
-        //logger( "Send Ping Request  to Destination (") ;
-        //logger( "%d.%d.%d.%d )",   (addr[0]),  (addr[1]),  (addr[2]),  (addr[3])) ;
-        //logger( " ID:%x  SeqNum:%x CheckSum:%x\r\n",   htons(PingRequest.ID),  htons(PingRequest.SeqNum),  htons(PingRequest.CheckSum)) ;
+        eth_printf(
+            "Send Ping Request  to Destination (%d.%d.%d.%d )",
+            (addr[0]),
+            (addr[1]),
+            (addr[2]),
+            (addr[3]));
+        eth_printf(
+            " ID:%x  SeqNum:%x CheckSum:%x",
+            htons(PingRequest.ID),
+            htons(PingRequest.SeqNum),
+            htons(PingRequest.CheckSum));
     }
     return 0;
 } // ping request
@@ -196,12 +205,18 @@ uint8_t ping_reply(uint8_t s, uint8_t* addr, uint16_t rlen) {
         /* check Checksum of Ping Reply */
         tmp_checksum = ~checksum(data_buf, len);
         if(tmp_checksum != 0xffff) {
-            //logger("tmp_checksum = %x\r\n",tmp_checksum);
+            eth_printf("tmp_checksum = %x", tmp_checksum);
         } else {
             /*  Output the Destination IP and the size of the Ping Reply Message*/
-            //logger("Reply from %d.%d.%d.%d  ID:%x SeqNum:%x  :data size %d bytes\r\n",
-            //  (addr[0]),  (addr[1]),  (addr[2]),  (addr[3]),  htons(PingReply.ID),  htons(PingReply.SeqNum),  (rlen+6) );
-            //logger("\r\n");
+            eth_printf(
+                "Reply from %d.%d.%d.%d  ID:%x SeqNum:%x  :data size %d bytes",
+                (addr[0]),
+                (addr[1]),
+                (addr[2]),
+                (addr[3]),
+                htons(PingReply.ID),
+                htons(PingReply.SeqNum),
+                (rlen + 6));
             /*  SET ping_reply_receiver to '1' and go out the while_loop (waitting for ping reply)*/
             ping_reply_received = 1;
         }
@@ -221,18 +236,28 @@ uint8_t ping_reply(uint8_t s, uint8_t* addr, uint16_t rlen) {
         PingReply.CheckSum = htons(checksum((uint8_t*)&PingReply, len));
 
         if(tmp_checksum != PingReply.CheckSum) {
-            //logger( " \n CheckSum is in correct %x shold be %x \n", (tmp_checksum), htons(PingReply.CheckSum));
+            eth_printf(
+                "CheckSum is in correct %x shold be %x",
+                (tmp_checksum),
+                htons(PingReply.CheckSum));
         } else {
-            //logger( "\r\n Checksum is correct  \r\n") ;
+            eth_printf("Checksum is correct");
         }
 
         /*  Output the Destination IP and the size of the Ping Reply Message*/
-        //logger("Request from %d.%d.%d.%d  ID:%x SeqNum:%x  :data size %d bytes\r\n",
-        //    (addr[0]),  (addr[1]),  (addr[2]),  (addr[3]),  (PingReply.ID),  (PingReply.SeqNum),  (rlen+6) );
+        eth_printf(
+            "Request from %d.%d.%d.%d  ID:%x SeqNum:%x  :data size %d bytes",
+            (addr[0]),
+            (addr[1]),
+            (addr[2]),
+            (addr[3]),
+            (PingReply.ID),
+            (PingReply.SeqNum),
+            (rlen + 6));
         /*  SET ping_reply_receiver to '1' and go out the while_loop (waitting for ping reply)*/
         ping_reply_received = 1;
     } else {
-        //logger(" Unkonwn msg. \n");
+        eth_printf(" Unkonwn msg.");
     }
 
     return 0;

+ 2 - 0
lib/ioLibrary_Driver/Internet/ICMP/ping.h

@@ -33,4 +33,6 @@ uint16_t htons(
     uint16_t
         hostshort); /* htons function converts a unsigned short from host to TCP/IP network byte order (which is big-endian).*/
 
+void eth_printf(const char* format, ...);
+
 #endif /* PING_H */

Некоторые файлы не были показаны из-за большого количества измененных файлов