summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-05-20 10:52:52 (GMT)
committer Hanhui <sylixos@gmail.com>2019-04-18 15:50:22 (GMT)
commit869b827123371741d5bf8d5fbf4031883d792547 (patch)
treec38fd190f45febb6bbcf823f2665d96dae7d1e47
parenta1eb6418d5e40f0356852c1a3b02c80cec786863 (diff)
downloadAIC-OS-869b827123371741d5bf8d5fbf4031883d792547.zip
NAT map support INADDR_ANY map and update can device manage.
-rw-r--r--SylixOS/net/lwip/tools/nat/lwip_natlib.c14
-rw-r--r--SylixOS/system/device/can/can.c29
2 files changed, 36 insertions, 7 deletions
diff --git a/SylixOS/net/lwip/tools/nat/lwip_natlib.c b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
index 6f2f1a6..ef03ca3 100644
--- a/SylixOS/net/lwip/tools/nat/lwip_natlib.c
+++ b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
@@ -39,6 +39,7 @@
2018.04.06 NAT 支持提前分片重组.
2019.02.15 本地 TCP SYN, CLOSING 仅保持 1 分钟.
2019.04.09 NAT AP 端口支持主机安全隔离.
+2019.05.20 MAP 0.0.0.0 作为本机映射.
*********************************************************************************************************/
#define __SYLIXOS_STDIO
#define __SYLIXOS_KERNEL
@@ -768,11 +769,16 @@ static INT __natApInput (struct pbuf *p, struct netif *netifIn)
}
}
if (plineTemp == LW_NULL) {
- u32_t uiHost;
+ if (pnatmap->NATM_ipaddrLocalIp.addr == IPADDR_ANY) {
+ ipaddr.addr = netif_ip4_addr(netifIn)->addr; /* 本机映射 */
- uiHost = (u32_t)PP_NTOHL(pnatmap->NATM_ipaddrLocalIp.addr);
- uiHost += usSrcHash; /* 根据源地址散列做均衡 */
- ipaddr.addr = (u32_t)PP_HTONL(uiHost);
+ } else {
+ u32_t uiHost;
+
+ uiHost = (u32_t)PP_NTOHL(pnatmap->NATM_ipaddrLocalIp.addr);
+ uiHost += usSrcHash; /* 根据源地址散列做均衡 */
+ ipaddr.addr = (u32_t)PP_HTONL(uiHost);
+ }
pnatcb = __natNew(&ipaddr, /* 新建控制块 */
pnatmap->NATM_usLocalPort, ucProto);
diff --git a/SylixOS/system/device/can/can.c b/SylixOS/system/device/can/can.c
index 6636b7d..44d6a8f 100644
--- a/SylixOS/system/device/can/can.c
+++ b/SylixOS/system/device/can/can.c
@@ -33,6 +33,7 @@
pend(..., LW_OPTION_NOT_WAIT) 改为 clear() 操作.
2012.10.31 修正一些不合理的命名.
2017.03.13 支持 CAN FD 标准与发送完成同步.
+2019.05.20 总线异常唤醒读写阻塞线程.
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
@@ -536,9 +537,12 @@ static VOID __canSetBusState (__CAN_DEV *pcanDev, INT iState)
LW_SPIN_UNLOCK_QUICK(&pcanport->CANPORT_can.CAN_slLock, iregInterLevel);
if (pcanDev->CAN_uiBusState != CAN_DEV_BUS_ERROR_NONE) { /* 总线异常 */
- API_SemaphoreBFlush(pcanDev->CAN_ulSendSemB, LW_NULL); /* 激活写等待任务 */
- API_SemaphoreBFlush(pcanDev->CAN_ulRcvSemB, LW_NULL); /* 激活读等待任务 */
- SEL_WAKE_UP_ALL(&pcanDev->CAN_selwulList, SELEXCEPT); /* select() 激活 */
+ API_SemaphoreBPost(pcanDev->CAN_ulSendSemB); /* 激活写等待任务 */
+ API_SemaphoreBPost(pcanDev->CAN_ulRcvSemB); /* 激活读等待任务 */
+ SEL_WAKE_UP_ALL_BY_FLAGS(&pcanDev->CAN_selwulList,
+ LW_SEL_TYPE_FLAG_READ |
+ LW_SEL_TYPE_FLAG_WRITE |
+ LW_SEL_TYPE_FLAG_EXCEPT); /* select() 激活 */
}
}
/*********************************************************************************************************
@@ -967,6 +971,11 @@ static ssize_t __canWrite (__CAN_DEV *pcanDev, PVOID pvCanFrame, size_t stNBy
stNumber = stNBytes / stUnit; /* 转换为数据包个数 */
+ if (pcanDev->CAN_uiBusState != CAN_DEV_BUS_ERROR_NONE) { /* 总线错误 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
while (stNumber > 0) {
ulError = API_SemaphoreBPend(pcanDev->CAN_ulSendSemB,
pcanDev->CAN_ulSendTimeout);
@@ -978,12 +987,20 @@ static ssize_t __canWrite (__CAN_DEV *pcanDev, PVOID pvCanFrame, size_t stNBy
CANDEV_LOCK(pcanDev); /* 等待设备使用权 */
LW_SPIN_LOCK_QUICK(&pcanDev->CAN_slLock, &iregInterLevel);
+
if (pcanDev->CAN_uiBusState != CAN_DEV_BUS_ERROR_NONE) { /* 总线错误 */
LW_SPIN_UNLOCK_QUICK(&pcanDev->CAN_slLock, iregInterLevel);
CANDEV_UNLOCK(pcanDev);
_ErrorHandle(EIO);
return ((ssize_t)(i * stUnit));
}
+
+ if (__canQFreeNum(pcanDev->CAN_pcanqSendQueue) <= 0) { /* 发送队列是否有空闲空间 */
+ LW_SPIN_UNLOCK_QUICK(&pcanDev->CAN_slLock, iregInterLevel);
+ CANDEV_UNLOCK(pcanDev);
+ continue;
+ }
+
LW_SPIN_UNLOCK_QUICK(&pcanDev->CAN_slLock, iregInterLevel);
iFrameput = __canWriteQueue(pcanDev,
@@ -1053,6 +1070,11 @@ static ssize_t __canRead (__CAN_DEV *pcanDev, PVOID pvCanFrame, size_t stNByt
stNumber = stNBytes / stUnit; /* 转换为数据包个数 */
+ if (pcanDev->CAN_uiBusState != CAN_DEV_BUS_ERROR_NONE) { /* 总线错误 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
for (;;) {
ulError = API_SemaphoreBPend(pcanDev->CAN_ulRcvSemB,
pcanDev->CAN_ulRecvTimeout);
@@ -1076,6 +1098,7 @@ static ssize_t __canRead (__CAN_DEV *pcanDev, PVOID pvCanFrame, size_t stNByt
return (0);
}
}
+
LW_SPIN_UNLOCK_QUICK(&pcanDev->CAN_slLock, iregInterLevel);
/* 打开中断 */
CANDEV_UNLOCK(pcanDev); /* 释放设备使用权 */