Răsfoiți Sursa

Merge branch 'master' of https://gitee.com/openLuat/LuatOS

# Conflicts:
#	components/lcd/luat_lcd.c
#	components/lcd/luat_lcd_jd9261t.c
alienwalker 1 an în urmă
părinte
comite
9d741485fb

+ 0 - 4
components/iconv/iconv.c

@@ -13,17 +13,13 @@ typedef struct builtin_iconv_map_tag
 static const builtin_iconv_map iconv_map[] =
 {
     {"ucs2",    "gb2312",   iconv_ucs2_to_gb2312},
-/*+\NEW\liweiqiang\2013.11.26\完善gb2312<->ucs2(ucs2be)编码转换*/
     {"ucs2be",  "gb2312",   iconv_ucs2be_to_gb2312},
     {"gb2312",  "ucs2",     iconv_gb2312_to_ucs2},
     {"gb2312",  "ucs2be",   iconv_gb2312_to_ucs2be},
-/*-\NEW\liweiqiang\2013.11.26\完善gb2312<->ucs2(ucs2be)编码转换*/
-/*+\NEW\liweiqiang\2013.7.19\增加utf8<->ucs2,ucs2be编码转换*/
     {"utf8",    "ucs2",     iconv_utf8_to_ucs2},
     {"utf8",    "ucs2be",   iconv_utf8_to_ucs2be},
     {"ucs2",    "utf8",     iconv_ucs2_to_utf8},
     {"ucs2be",    "utf8",     iconv_ucs2be_to_utf8},
-/*-\NEW\liweiqiang\2013.7.19\增加utf8<->ucs2,ucs2be编码转换*/
 };
 
 iconv_t iconv_open (const char * to_code, const char * from_code)

+ 19 - 3
components/lcd/luat_lcd.c

@@ -136,13 +136,17 @@ LUAT_WEAK int luat_lcd_init_default(luat_lcd_conf_t* conf) {
     if (conf->pin_pwr != LUAT_GPIO_NONE)
         luat_gpio_mode(conf->pin_pwr, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
     if (conf->interface_mode==LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_I || conf->interface_mode==LUAT_LCD_IM_4_WIRE_8_BIT_INTERFACE_II){
-        if (conf->pin_dc != LUAT_GPIO_NONE) luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+        if (conf->pin_dc != LUAT_GPIO_NONE) {
+            luat_gpio_mode(conf->pin_dc, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // DC
+        }
     }
     luat_gpio_mode(conf->pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // RST
-    if (conf->tp_pin_rst != LUAT_GPIO_NONE)
+    if (conf->tp_pin_rst != LUAT_GPIO_NONE) {
         luat_gpio_mode(conf->tp_pin_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_LOW); // POWER
-    if (conf->pin_pwr != LUAT_GPIO_NONE)
+    }
+    if (conf->pin_pwr != LUAT_GPIO_NONE) {
         luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
+    }
 	if (conf->opts->user_ctrl_init)
 	{
 		conf->opts->user_ctrl_init(conf);
@@ -534,3 +538,15 @@ int luat_lcd_draw_circle(luat_lcd_conf_t* conf,int16_t x0, int16_t y0, uint8_t r
     return 0;
 }
 
+#ifndef LUAT_COMPILER_NOWEAK
+
+LUAT_WEAK int luat_lcd_qspi_config(luat_lcd_conf_t* conf, luat_lcd_qspi_conf_t *qspi_config) {
+    return -1;
+};
+
+LUAT_WEAK int luat_lcd_qspi_auto_flush_on_off(luat_lcd_conf_t* conf, uint8_t on_off) {
+    return -1;
+}
+
+#endif
+

+ 1 - 1
components/lcd/luat_lcd_jd9261t.c

@@ -34,7 +34,7 @@ static void jd9261t_get_tp_point(void *param, uint32_t param_len)
 			return;
 		}
 	}
-	luat_rtos_task_sleep(1);
+	luat_timer_us_delay(15);
 	res = luat_i2c_recv(jd9261t_tp.lcd->tp_i2c_id, 0x68, buff, 60);
 	if (res)
 	{

+ 10 - 17
components/network/netdrv/include/luat_netdrv_napt.h

@@ -3,23 +3,8 @@
 
 #include "lwip/pbuf.h"
 
-// typedef struct napt_map_item
-// {
-//     uint8_t adapter_id;
-//     uint16_t port;
-//     uint32_t ipv4;
-//     uint8_t mac[6];
-// }napt_map_item_t;
-
-
-// typedef struct luat_netdrv_napt_item
-// {
-//     uint8_t     is_vaild;
-//     // uint8_t     tp; // tcp, udp, icmp
-//     napt_map_item_t inet;  // 内网信息
-//     napt_map_item_t wnet; // 外网信息
-//     uint64_t tm_ms; // 最后通信时间
-// }luat_netdrv_napt_item_t;
+// #define IP_NAPT_TIMEOUT_MS_TCP (30*60*1000)
+#define IP_NAPT_TIMEOUT_MS_TCP_DISCON (20*1000)
 
 typedef struct luat_netdrv_napt_icmp
 {
@@ -44,6 +29,14 @@ typedef struct luat_netdrv_napt_tcpudp
     uint32_t wnet_ip;
     uint8_t  inet_mac[6];
     uint64_t tm_ms; // 最后通信时间
+
+    // TCP状态记录
+    unsigned int fin1 : 1;
+    unsigned int fin2 : 1;
+    unsigned int finack1 : 1;
+    unsigned int finack2 : 1;
+    unsigned int synack : 1;
+    unsigned int rst : 1;
 }luat_netdrv_napt_tcpudp_t;
 
 typedef struct napt_ctx

+ 2 - 2
components/network/netdrv/src/luat_netdrv_napt.c

@@ -58,12 +58,12 @@ int luat_netdrv_napt_pkg_input(int id, uint8_t* buff, size_t len) {
         if (memcmp(ctx.eth->dest.addr, "\xFF\xFF\xFF\xFF\xFF\xFF", 6) == 0 ||
             ctx.eth->dest.addr[0] == 0x01
         ) {
-            LLOGD("是广播包,不需要执行napt");
+            // LLOGD("是广播包,不需要执行napt");
             return 0;
         }
         // LLOGD("ETH包 " MACFMT " -> " MACFMT " %04X", MAC_ARG(ctx.eth->src.addr), MAC_ARG(ctx.eth->dest.addr), ctx.eth->type);
         if (ctx.eth->type != PP_HTONS(ETHTYPE_IP)) {
-            LLOGD("不是IP包, 不需要执行napt");
+            // LLOGD("不是IP包, 不需要执行napt");
             return 0;
         }
     }

+ 2 - 2
components/network/netdrv/src/luat_netdrv_napt_icmp.c

@@ -121,9 +121,9 @@ int luat_napt_icmp_handle(napt_ctx_t* ctx) {
                 LLOGE("能找到ICMP映射关系, 但目标netdrv不支持dataout!!");
             }
             icmps[i].is_vaild = 0;
-            return 1; // 全部修改完成,
+            return 1; // 全部修改完成
         }
-        LLOGD("没有找到ICMP映射关系, 不是非内网PING");
+        // LLOGD("没有找到ICMP映射关系, 不是非内网PING");
         return 0;
     }
     else {

+ 37 - 1
components/network/netdrv/src/luat_netdrv_napt_tcp.c

@@ -74,6 +74,28 @@ static void print_item(const char* tag, luat_netdrv_napt_tcpudp_t* it) {
     );
 }
 
+static void update_tcp_stat_wnet(struct tcp_hdr *tcphdr, luat_netdrv_napt_tcpudp_t* t) {
+      if ((TCPH_FLAGS(tcphdr) & (TCP_SYN|TCP_ACK)) == (TCP_SYN|TCP_ACK))
+        t->synack = 1;
+      if ((TCPH_FLAGS(tcphdr) & TCP_FIN))
+        t->fin1 = 1;
+      if (t->fin2 && (TCPH_FLAGS(tcphdr) & TCP_ACK))
+        t->finack2 = 1; /* FIXME: Currently ignoring ACK seq... */
+      if (TCPH_FLAGS(tcphdr) & TCP_RST)
+        t->rst = 1;
+    // LLOGD("TCP链路状态 synack %d fin1 %d finack2 %d rst %d", t->synack, t->fin1, t->finack2, t->rst);
+}
+
+static void update_tcp_stat_inet(struct tcp_hdr *tcphdr, luat_netdrv_napt_tcpudp_t* t) {
+    if ((TCPH_FLAGS(tcphdr) & TCP_FIN))
+        t->fin2 = 1;
+    if (t->fin1 && (TCPH_FLAGS(tcphdr) & TCP_ACK))
+        t->finack1 = 1; /* FIXME: Currently ignoring ACK seq... */
+    if (TCPH_FLAGS(tcphdr) & TCP_RST)
+        t->rst = 1;
+    // LLOGD("TCP链路状态 synack %d fin1 %d finack2 %d rst %d", t->synack, t->fin1, t->finack2, t->rst);
+}
+
 static uint8_t tcp_buff[1600];
 int luat_napt_tcp_handle(napt_ctx_t* ctx) {
     uint16_t iphdr_len = (ctx->iphdr->_v_hl & 0x0F) * 4;
@@ -138,6 +160,7 @@ int luat_napt_tcp_handle(napt_ctx_t* ctx) {
                 memcpy(ctx->eth->src.addr, ctx->net->netif->hwaddr, 6);
                 memcpy(ctx->eth->dest.addr, tcps[i].inet_mac, 6);
             }
+            update_tcp_stat_wnet(tcp_hdr, &tcps[i]);
             luat_netdrv_t* dst = luat_netdrv_get(tcps[i].adapter_id);
             if (dst == NULL) {
                 LLOGE("能找到TCP映射关系, 但目标netdrv不存在, 这肯定是BUG啊!!");
@@ -164,7 +187,7 @@ int luat_napt_tcp_handle(napt_ctx_t* ctx) {
             }
             return 1; // 全部修改完成
         }
-        LLOGD("没有找到TCP映射关系, 放行给LWIP处理");
+        // LLOGD("没有找到TCP映射关系, 放行给LWIP处理");
         return 0;
     }
     else {
@@ -187,6 +210,15 @@ int luat_napt_tcp_handle(napt_ctx_t* ctx) {
                 it->tm_ms = 0;
                 continue;
             }
+
+            // 判断TCP链路状态
+            if ((((it->finack1 && it->finack2) || !it->synack) &&
+                  tnow - it->tm_ms > IP_NAPT_TIMEOUT_MS_TCP_DISCON)) {
+                LLOGD("映射的TCP链路已经断开%lldms, 超过 %ld ms, 设置为无效", tnow - it->tm_ms, IP_NAPT_TIMEOUT_MS_TCP_DISCON);
+                it->is_vaild = 0;
+                it->tm_ms = 0;
+                continue;
+            }
             
             // print_item("inet.search", it);
             // 几个要素都要相同 源IP/源端口/目标IP/目标端口, 如果是MAC包, 源MAC也要相同
@@ -230,6 +262,7 @@ int luat_napt_tcp_handle(napt_ctx_t* ctx) {
                 LLOGE("没有空闲的TCP映射了!!!!");
                 return 0;
             }
+            memset(it_map, 0, sizeof(luat_netdrv_napt_tcpudp_t));
             it->adapter_id = ctx->net->id;
             it->inet_port = tcp_hdr->src;
             it->wnet_port = tcp_hdr->dest;
@@ -243,6 +276,9 @@ int luat_napt_tcp_handle(napt_ctx_t* ctx) {
             it->is_vaild = 1;
             LLOGD("分配新的TCP映射 inet %d wnet %d", it->inet_port, it->wnet_local_port);
         }
+        else {
+            update_tcp_stat_inet(tcp_hdr, it_map);
+        }
         // 2. 修改信息
         ip_hdr->src.addr = ip_addr_get_ip4_u32(&gw->netif->ip_addr);
         tcp_hdr->src = it_map->wnet_local_port;

+ 1 - 1
components/network/netdrv/src/luat_netdrv_napt_udp.c

@@ -134,7 +134,7 @@ int luat_napt_udp_handle(napt_ctx_t* ctx) {
                 return 1; // 全部修改完成,
             }
         }
-        LLOGD("没有找到UDP映射关系, 放行给LWIP处理");
+        // LLOGD("没有找到UDP映射关系, 放行给LWIP处理");
         return 0;
     }
     else {

+ 2 - 3
script/libs/dnsproxy.lua

@@ -79,9 +79,8 @@ end
 
 --[[
 创建UDP服务器
-@api dnsproxy.create(port, topic, adapter)
-@int 端口号, 必填, 必须大于0小于65525
-@string 收取UDP数据的topic,必填
+@api dnsproxy.create(adapter, main_adapter)
+@int 监听的网络适配器id
 @int 网络适配编号, 默认为nil,可选
 @return table UDP服务的实体, 若创建失败会返回nil
 ]]