Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逝缘~
rt-thread
提交
0d8a2162
R
rt-thread
项目概览
逝缘~
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0d8a2162
编写于
8月 22, 2019
作者:
Lawlieta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[network][netdev] Improve the default netdev operation and format code
Signed-off-by:
chenyong
<
1521761801@qq.com
>
上级
d588940d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
105 addition
and
71 deletion
+105
-71
components/net/lwip-1.4.1/src/netif/ethernetif.c
components/net/lwip-1.4.1/src/netif/ethernetif.c
+8
-0
components/net/lwip-2.0.2/src/netif/ethernetif.c
components/net/lwip-2.0.2/src/netif/ethernetif.c
+8
-0
components/net/lwip-2.1.0/src/netif/ethernetif.c
components/net/lwip-2.1.0/src/netif/ethernetif.c
+8
-0
components/net/netdev/include/netdev.h
components/net/netdev/include/netdev.h
+3
-0
components/net/netdev/src/netdev.c
components/net/netdev/src/netdev.c
+78
-71
未找到文件。
components/net/lwip-1.4.1/src/netif/ethernetif.c
浏览文件 @
0d8a2162
...
@@ -253,6 +253,12 @@ void lwip_netdev_netstat(struct netdev *netif)
...
@@ -253,6 +253,12 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_USING_FINSH */
#endif
/* RT_USING_FINSH */
static
int
lwip_netdev_set_default
(
struct
netdev
*
netif
)
{
netif_set_default
((
struct
netif
*
)
netif
->
user_data
);
return
ERR_OK
;
}
const
struct
netdev_ops
lwip_netdev_ops
=
const
struct
netdev_ops
lwip_netdev_ops
=
{
{
lwip_netdev_set_up
,
lwip_netdev_set_up
,
...
@@ -282,6 +288,8 @@ const struct netdev_ops lwip_netdev_ops =
...
@@ -282,6 +288,8 @@ const struct netdev_ops lwip_netdev_ops =
lwip_netdev_netstat
,
lwip_netdev_netstat
,
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_USING_FINSH */
#endif
/* RT_USING_FINSH */
lwip_netdev_set_default
,
};
};
static
int
netdev_add
(
struct
netif
*
lwip_netif
)
static
int
netdev_add
(
struct
netif
*
lwip_netif
)
...
...
components/net/lwip-2.0.2/src/netif/ethernetif.c
浏览文件 @
0d8a2162
...
@@ -261,6 +261,12 @@ void lwip_netdev_netstat(struct netdev *netif)
...
@@ -261,6 +261,12 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_USING_FINSH */
#endif
/* RT_USING_FINSH */
static
int
lwip_netdev_set_default
(
struct
netdev
*
netif
)
{
netif_set_default
((
struct
netif
*
)
netif
->
user_data
);
return
ERR_OK
;
}
const
struct
netdev_ops
lwip_netdev_ops
=
const
struct
netdev_ops
lwip_netdev_ops
=
{
{
lwip_netdev_set_up
,
lwip_netdev_set_up
,
...
@@ -290,6 +296,8 @@ const struct netdev_ops lwip_netdev_ops =
...
@@ -290,6 +296,8 @@ const struct netdev_ops lwip_netdev_ops =
lwip_netdev_netstat
,
lwip_netdev_netstat
,
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_USING_FINSH */
#endif
/* RT_USING_FINSH */
lwip_netdev_set_default
,
};
};
static
int
netdev_add
(
struct
netif
*
lwip_netif
)
static
int
netdev_add
(
struct
netif
*
lwip_netif
)
...
...
components/net/lwip-2.1.0/src/netif/ethernetif.c
浏览文件 @
0d8a2162
...
@@ -262,6 +262,12 @@ void lwip_netdev_netstat(struct netdev *netif)
...
@@ -262,6 +262,12 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_USING_FINSH */
#endif
/* RT_USING_FINSH */
static
int
lwip_netdev_set_default
(
struct
netdev
*
netif
)
{
netif_set_default
((
struct
netif
*
)
netif
->
user_data
);
return
ERR_OK
;
}
const
struct
netdev_ops
lwip_netdev_ops
=
const
struct
netdev_ops
lwip_netdev_ops
=
{
{
lwip_netdev_set_up
,
lwip_netdev_set_up
,
...
@@ -291,6 +297,8 @@ const struct netdev_ops lwip_netdev_ops =
...
@@ -291,6 +297,8 @@ const struct netdev_ops lwip_netdev_ops =
lwip_netdev_netstat
,
lwip_netdev_netstat
,
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_LWIP_TCP || RT_LWIP_UDP */
#endif
/* RT_USING_FINSH */
#endif
/* RT_USING_FINSH */
lwip_netdev_set_default
,
};
};
static
int
netdev_add
(
struct
netif
*
lwip_netif
)
static
int
netdev_add
(
struct
netif
*
lwip_netif
)
...
...
components/net/netdev/include/netdev.h
浏览文件 @
0d8a2162
...
@@ -137,6 +137,9 @@ struct netdev_ops
...
@@ -137,6 +137,9 @@ struct netdev_ops
int
(
*
ping
)(
struct
netdev
*
netdev
,
const
char
*
host
,
size_t
data_len
,
uint32_t
timeout
,
struct
netdev_ping_resp
*
ping_resp
);
int
(
*
ping
)(
struct
netdev
*
netdev
,
const
char
*
host
,
size_t
data_len
,
uint32_t
timeout
,
struct
netdev_ping_resp
*
ping_resp
);
void
(
*
netstat
)(
struct
netdev
*
netdev
);
void
(
*
netstat
)(
struct
netdev
*
netdev
);
#endif
#endif
/* set default network interface device in current network stack*/
int
(
*
set_default
)(
struct
netdev
*
netdev
);
};
};
/* The network interface device registered and unregistered*/
/* The network interface device registered and unregistered*/
...
...
components/net/netdev/src/netdev.c
浏览文件 @
0d8a2162
...
@@ -34,11 +34,11 @@ struct netdev *netdev_default;
...
@@ -34,11 +34,11 @@ struct netdev *netdev_default;
/**
/**
* This function will register network interface device and
* This function will register network interface device and
* add it to network interface device list.
* add it to network interface device list.
*
*
* @param netdev the network interface device object
* @param netdev the network interface device object
* @param name the network interface device name
* @param name the network interface device name
* @param user_data user-specific data
* @param user_data user-specific data
*
*
* @return 0: registered successfully
* @return 0: registered successfully
* -1: registered failed
* -1: registered failed
*/
*/
...
@@ -105,9 +105,9 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
...
@@ -105,9 +105,9 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
/**
/**
* This function will unregister network interface device and
* This function will unregister network interface device and
* delete it from network interface device list.
* delete it from network interface device list.
*
*
* @param netdev the network interface device object
* @param netdev the network interface device object
*
*
* @return 0: unregistered successfully
* @return 0: unregistered successfully
* -1: unregistered failed
* -1: unregistered failed
*/
*/
...
@@ -164,11 +164,11 @@ int netdev_unregister(struct netdev *netdev)
...
@@ -164,11 +164,11 @@ int netdev_unregister(struct netdev *netdev)
/**
/**
* This function will get the first network interface device
* This function will get the first network interface device
* with the flags in network interface device list.
* with the flags in network interface device list.
*
*
* @param flags the network interface device flags
* @param flags the network interface device flags
*
*
* @return != NULL: network interface device object
* @return != NULL: network interface device object
* NULL: get failed
* NULL: get failed
*/
*/
struct
netdev
*
netdev_get_first_by_flags
(
uint16_t
flags
)
struct
netdev
*
netdev_get_first_by_flags
(
uint16_t
flags
)
{
{
...
@@ -201,11 +201,11 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
...
@@ -201,11 +201,11 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
/**
/**
* This function will get the first network interface device
* This function will get the first network interface device
* in network interface device list by IP address.
* in network interface device list by IP address.
*
*
* @param addr the network interface device IP address
* @param addr the network interface device IP address
*
*
* @return != NULL: network interface device object
* @return != NULL: network interface device object
* NULL: get failed
* NULL: get failed
*/
*/
struct
netdev
*
netdev_get_by_ipaddr
(
ip_addr_t
*
ip_addr
)
struct
netdev
*
netdev_get_by_ipaddr
(
ip_addr_t
*
ip_addr
)
{
{
...
@@ -238,11 +238,11 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
...
@@ -238,11 +238,11 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
/**
/**
* This function will get network interface device
* This function will get network interface device
* in network interface device list by netdev name.
* in network interface device list by netdev name.
*
*
* @param name the network interface device name
* @param name the network interface device name
*
*
* @return != NULL: network interface device object
* @return != NULL: network interface device object
* NULL: get failed
* NULL: get failed
*/
*/
struct
netdev
*
netdev_get_by_name
(
const
char
*
name
)
struct
netdev
*
netdev_get_by_name
(
const
char
*
name
)
{
{
...
@@ -276,11 +276,11 @@ struct netdev *netdev_get_by_name(const char *name)
...
@@ -276,11 +276,11 @@ struct netdev *netdev_get_by_name(const char *name)
/**
/**
* This function will get the first network interface device
* This function will get the first network interface device
* in network interface device list by protocol family type.
* in network interface device list by protocol family type.
*
*
* @param family the network interface device protocol family type
* @param family the network interface device protocol family type
*
*
* @return != NULL: network interface device object
* @return != NULL: network interface device object
* NULL: get failed
* NULL: get failed
*/
*/
struct
netdev
*
netdev_get_by_family
(
int
family
)
struct
netdev
*
netdev_get_by_family
(
int
family
)
{
{
...
@@ -325,15 +325,15 @@ struct netdev *netdev_get_by_family(int family)
...
@@ -325,15 +325,15 @@ struct netdev *netdev_get_by_family(int family)
/**
/**
* This function will get the family type from network interface device
* This function will get the family type from network interface device
*
*
* @param netdev network interface device object
* @param netdev network interface device object
*
*
* @return the network interface device family type
* @return the network interface device family type
*/
*/
int
netdev_family_get
(
struct
netdev
*
netdev
)
int
netdev_family_get
(
struct
netdev
*
netdev
)
{
{
RT_ASSERT
(
netdev
);
RT_ASSERT
(
netdev
);
return
((
struct
sal_proto_family
*
)
netdev
->
sal_user_data
)
->
family
;
return
((
struct
sal_proto_family
*
)
netdev
->
sal_user_data
)
->
family
;
}
}
...
@@ -341,7 +341,7 @@ int netdev_family_get(struct netdev *netdev)
...
@@ -341,7 +341,7 @@ int netdev_family_get(struct netdev *netdev)
/**
/**
* This function will set default network interface device.
* This function will set default network interface device.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
*/
*/
void
netdev_set_default
(
struct
netdev
*
netdev
)
void
netdev_set_default
(
struct
netdev
*
netdev
)
...
@@ -349,15 +349,21 @@ void netdev_set_default(struct netdev *netdev)
...
@@ -349,15 +349,21 @@ void netdev_set_default(struct netdev *netdev)
if
(
netdev
)
if
(
netdev
)
{
{
netdev_default
=
netdev
;
netdev_default
=
netdev
;
if
(
netdev
->
ops
->
set_default
)
{
/* set default network interface device in the current network stack */
netdev
->
ops
->
set_default
(
netdev
);
}
LOG_D
(
"Setting default network interface device name(%s) successfully."
,
netdev
->
name
);
LOG_D
(
"Setting default network interface device name(%s) successfully."
,
netdev
->
name
);
}
}
}
}
/**
/**
* This function will enable network interface device .
* This function will enable network interface device .
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
*
*
* @return 0: set status successfully
* @return 0: set status successfully
* -1: set status failed
* -1: set status failed
*/
*/
...
@@ -370,7 +376,7 @@ int netdev_set_up(struct netdev *netdev)
...
@@ -370,7 +376,7 @@ int netdev_set_up(struct netdev *netdev)
LOG_E
(
"The network interface device(%s) not support to set status."
,
netdev
->
name
);
LOG_E
(
"The network interface device(%s) not support to set status."
,
netdev
->
name
);
return
-
RT_ERROR
;
return
-
RT_ERROR
;
}
}
/* network interface device status flags check */
/* network interface device status flags check */
if
(
netdev_is_up
(
netdev
))
if
(
netdev_is_up
(
netdev
))
{
{
...
@@ -382,9 +388,9 @@ int netdev_set_up(struct netdev *netdev)
...
@@ -382,9 +388,9 @@ int netdev_set_up(struct netdev *netdev)
}
}
/**
/**
* This function will disable network interface device.
* This function will disable network interface device.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
*
*
* @return 0: set status successfully
* @return 0: set status successfully
* -1: set sttaus failed
* -1: set sttaus failed
*/
*/
...
@@ -397,7 +403,7 @@ int netdev_set_down(struct netdev *netdev)
...
@@ -397,7 +403,7 @@ int netdev_set_down(struct netdev *netdev)
LOG_E
(
"The network interface device(%s) not support to set status."
,
netdev
->
name
);
LOG_E
(
"The network interface device(%s) not support to set status."
,
netdev
->
name
);
return
-
RT_ERROR
;
return
-
RT_ERROR
;
}
}
/* network interface device status flags check */
/* network interface device status flags check */
if
(
!
netdev_is_up
(
netdev
))
if
(
!
netdev_is_up
(
netdev
))
{
{
...
@@ -410,10 +416,10 @@ int netdev_set_down(struct netdev *netdev)
...
@@ -410,10 +416,10 @@ int netdev_set_down(struct netdev *netdev)
/**
/**
* This function will control network interface device DHCP capability enable or disable.
* This function will control network interface device DHCP capability enable or disable.
*
*
* @param netdev the network interface device device to change
* @param netdev the network interface device device to change
* @param is_enable the new DHCP status
* @param is_enable the new DHCP status
*
*
* @return 0: set DHCP status successfully
* @return 0: set DHCP status successfully
* -1: set DHCP status failed
* -1: set DHCP status failed
*/
*/
...
@@ -432,17 +438,17 @@ int netdev_dhcp_enabled(struct netdev *netdev, rt_bool_t is_enabled)
...
@@ -432,17 +438,17 @@ int netdev_dhcp_enabled(struct netdev *netdev, rt_bool_t is_enabled)
{
{
return
RT_EOK
;
return
RT_EOK
;
}
}
/* execute network interface device DHCP capability control operations */
/* execute network interface device DHCP capability control operations */
return
netdev
->
ops
->
set_dhcp
(
netdev
,
is_enabled
);
return
netdev
->
ops
->
set_dhcp
(
netdev
,
is_enabled
);
}
}
/**
/**
* This function will set network interface device IP address.
* This function will set network interface device IP address.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param ipaddr the new IP address
* @param ipaddr the new IP address
*
*
* @return 0: set IP address successfully
* @return 0: set IP address successfully
* -1: set IP address failed
* -1: set IP address failed
*/
*/
...
@@ -456,7 +462,7 @@ int netdev_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr)
...
@@ -456,7 +462,7 @@ int netdev_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr)
LOG_E
(
"The network interface device(%s) not support to set IP address."
,
netdev
->
name
);
LOG_E
(
"The network interface device(%s) not support to set IP address."
,
netdev
->
name
);
return
-
RT_ERROR
;
return
-
RT_ERROR
;
}
}
if
(
netdev_is_dhcp_enabled
(
netdev
))
if
(
netdev_is_dhcp_enabled
(
netdev
))
{
{
LOG_E
(
"The network interface device(%s) DHCP capability is enable, not support set IP address."
,
netdev
->
name
);
LOG_E
(
"The network interface device(%s) DHCP capability is enable, not support set IP address."
,
netdev
->
name
);
...
@@ -469,10 +475,10 @@ int netdev_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr)
...
@@ -469,10 +475,10 @@ int netdev_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr)
/**
/**
* This function will set network interface device netmask address.
* This function will set network interface device netmask address.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param netmask the new netmask address
* @param netmask the new netmask address
*
*
* @return 0: set netmask address successfully
* @return 0: set netmask address successfully
* -1: set netmask address failed
* -1: set netmask address failed
*/
*/
...
@@ -486,7 +492,7 @@ int netdev_set_netmask(struct netdev *netdev, const ip_addr_t *netmask)
...
@@ -486,7 +492,7 @@ int netdev_set_netmask(struct netdev *netdev, const ip_addr_t *netmask)
LOG_E
(
"The network interface device(%s) not support to set netmask address."
,
netdev
->
name
);
LOG_E
(
"The network interface device(%s) not support to set netmask address."
,
netdev
->
name
);
return
-
RT_ERROR
;
return
-
RT_ERROR
;
}
}
if
(
netdev_is_dhcp_enabled
(
netdev
))
if
(
netdev_is_dhcp_enabled
(
netdev
))
{
{
LOG_E
(
"The network interface device(%s) DHCP capability is enable, not support set netmask address."
,
netdev
->
name
);
LOG_E
(
"The network interface device(%s) DHCP capability is enable, not support set netmask address."
,
netdev
->
name
);
...
@@ -499,10 +505,10 @@ int netdev_set_netmask(struct netdev *netdev, const ip_addr_t *netmask)
...
@@ -499,10 +505,10 @@ int netdev_set_netmask(struct netdev *netdev, const ip_addr_t *netmask)
/**
/**
* This function will set network interface device gateway address.
* This function will set network interface device gateway address.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param gateway the new gateway address
* @param gateway the new gateway address
*
*
* @return 0: set gateway address successfully
* @return 0: set gateway address successfully
* -1: set gateway address failed
* -1: set gateway address failed
*/
*/
...
@@ -516,7 +522,7 @@ int netdev_set_gw(struct netdev *netdev, const ip_addr_t *gw)
...
@@ -516,7 +522,7 @@ int netdev_set_gw(struct netdev *netdev, const ip_addr_t *gw)
LOG_E
(
"The network interface device(%s) not support to set gateway address."
,
netdev
->
name
);
LOG_E
(
"The network interface device(%s) not support to set gateway address."
,
netdev
->
name
);
return
-
RT_ERROR
;
return
-
RT_ERROR
;
}
}
if
(
netdev_is_dhcp_enabled
(
netdev
))
if
(
netdev_is_dhcp_enabled
(
netdev
))
{
{
LOG_E
(
"The network interface device(%s) DHCP capability is enable, not support set gateway address."
,
netdev
->
name
);
LOG_E
(
"The network interface device(%s) DHCP capability is enable, not support set gateway address."
,
netdev
->
name
);
...
@@ -529,10 +535,10 @@ int netdev_set_gw(struct netdev *netdev, const ip_addr_t *gw)
...
@@ -529,10 +535,10 @@ int netdev_set_gw(struct netdev *netdev, const ip_addr_t *gw)
/**
/**
* This function will set network interface device DNS server address.
* This function will set network interface device DNS server address.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param dns_server the new DNS server address
* @param dns_server the new DNS server address
*
*
* @return 0: set netmask address successfully
* @return 0: set netmask address successfully
* -1: set netmask address failed
* -1: set netmask address failed
*/
*/
...
@@ -559,7 +565,7 @@ int netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_
...
@@ -559,7 +565,7 @@ int netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_
/**
/**
* This function will set callback to be called when the network interface device status has been changed.
* This function will set callback to be called when the network interface device status has been changed.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param status_callback the callback be called when the status has been changed.
* @param status_callback the callback be called when the status has been changed.
*/
*/
...
@@ -573,7 +579,7 @@ void netdev_set_status_callback(struct netdev *netdev, netdev_callback_fn status
...
@@ -573,7 +579,7 @@ void netdev_set_status_callback(struct netdev *netdev, netdev_callback_fn status
/**
/**
* This function will set callback to be called when the network interface device address has been changed.
* This function will set callback to be called when the network interface device address has been changed.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param addr_callback the callback be called when the address has been changed.
* @param addr_callback the callback be called when the address has been changed.
*/
*/
...
@@ -589,7 +595,7 @@ void netdev_set_addr_callback(struct netdev *netdev, netdev_callback_fn addr_cal
...
@@ -589,7 +595,7 @@ void netdev_set_addr_callback(struct netdev *netdev, netdev_callback_fn addr_cal
/**
/**
* This function will set network interface device IP address.
* This function will set network interface device IP address.
* @NOTE it can only be called in the network interface device driver.
* @NOTE it can only be called in the network interface device driver.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param ipaddr the new IP address
* @param ipaddr the new IP address
*/
*/
...
@@ -620,7 +626,7 @@ void netdev_low_level_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr
...
@@ -620,7 +626,7 @@ void netdev_low_level_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr
/**
/**
* This function will set network interface device netmask address.
* This function will set network interface device netmask address.
* @NOTE it can only be called in the network interface device driver.
* @NOTE it can only be called in the network interface device driver.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param netmask the new netmask address
* @param netmask the new netmask address
*/
*/
...
@@ -634,7 +640,7 @@ void netdev_low_level_set_netmask(struct netdev *netdev, const ip_addr_t *netmas
...
@@ -634,7 +640,7 @@ void netdev_low_level_set_netmask(struct netdev *netdev, const ip_addr_t *netmas
#ifdef RT_USING_SAL
#ifdef RT_USING_SAL
/* set network interface device flags to internet up */
/* set network interface device flags to internet up */
if
(
netdev_is_up
(
netdev
)
&&
netdev_is_link_up
(
netdev
)
&&
if
(
netdev_is_up
(
netdev
)
&&
netdev_is_link_up
(
netdev
)
&&
!
ip_addr_isany
(
&
(
netdev
->
ip_addr
)))
!
ip_addr_isany
(
&
(
netdev
->
ip_addr
)))
{
{
sal_check_netdev_internet_up
(
netdev
);
sal_check_netdev_internet_up
(
netdev
);
...
@@ -652,7 +658,7 @@ void netdev_low_level_set_netmask(struct netdev *netdev, const ip_addr_t *netmas
...
@@ -652,7 +658,7 @@ void netdev_low_level_set_netmask(struct netdev *netdev, const ip_addr_t *netmas
/**
/**
* This function will set network interface device gateway address.
* This function will set network interface device gateway address.
* @NOTE it can only be called in the network interface device driver.
* @NOTE it can only be called in the network interface device driver.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param gateway the new gateway address
* @param gateway the new gateway address
*/
*/
...
@@ -666,7 +672,7 @@ void netdev_low_level_set_gw(struct netdev *netdev, const ip_addr_t *gw)
...
@@ -666,7 +672,7 @@ void netdev_low_level_set_gw(struct netdev *netdev, const ip_addr_t *gw)
#ifdef RT_USING_SAL
#ifdef RT_USING_SAL
/* set network interface device flags to internet up */
/* set network interface device flags to internet up */
if
(
netdev_is_up
(
netdev
)
&&
netdev_is_link_up
(
netdev
)
&&
if
(
netdev_is_up
(
netdev
)
&&
netdev_is_link_up
(
netdev
)
&&
!
ip_addr_isany
(
&
(
netdev
->
ip_addr
)))
!
ip_addr_isany
(
&
(
netdev
->
ip_addr
)))
{
{
sal_check_netdev_internet_up
(
netdev
);
sal_check_netdev_internet_up
(
netdev
);
...
@@ -684,10 +690,10 @@ void netdev_low_level_set_gw(struct netdev *netdev, const ip_addr_t *gw)
...
@@ -684,10 +690,10 @@ void netdev_low_level_set_gw(struct netdev *netdev, const ip_addr_t *gw)
/**
/**
* This function will set network interface device DNS server address.
* This function will set network interface device DNS server address.
* @NOTE it can only be called in the network interface device driver.
* @NOTE it can only be called in the network interface device driver.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param dns_server the new DNS server address
* @param dns_server the new DNS server address
*
*
*/
*/
void
netdev_low_level_set_dns_server
(
struct
netdev
*
netdev
,
uint8_t
dns_num
,
const
ip_addr_t
*
dns_server
)
void
netdev_low_level_set_dns_server
(
struct
netdev
*
netdev
,
uint8_t
dns_num
,
const
ip_addr_t
*
dns_server
)
{
{
...
@@ -740,7 +746,7 @@ static void netdev_auto_change_default(struct netdev *netdev)
...
@@ -740,7 +746,7 @@ static void netdev_auto_change_default(struct netdev *netdev)
/**
/**
* This function will set network interface device status.
* This function will set network interface device status.
* @NOTE it can only be called in the network interface device driver.
* @NOTE it can only be called in the network interface device driver.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param is_up the new status
* @param is_up the new status
*/
*/
...
@@ -773,14 +779,14 @@ void netdev_low_level_set_status(struct netdev *netdev, rt_bool_t is_up)
...
@@ -773,14 +779,14 @@ void netdev_low_level_set_status(struct netdev *netdev, rt_bool_t is_up)
/**
/**
* This function will set network interface device active link status.
* This function will set network interface device active link status.
* @NOTE it can only be called in the network interface device driver.
* @NOTE it can only be called in the network interface device driver.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param is_up the new link status
* @param is_up the new link status
*/
*/
void
netdev_low_level_set_link_status
(
struct
netdev
*
netdev
,
rt_bool_t
is_up
)
void
netdev_low_level_set_link_status
(
struct
netdev
*
netdev
,
rt_bool_t
is_up
)
{
{
if
(
netdev
&&
netdev_is_link_up
(
netdev
)
!=
is_up
)
if
(
netdev
&&
netdev_is_link_up
(
netdev
)
!=
is_up
)
{
{
if
(
is_up
)
if
(
is_up
)
{
{
netdev
->
flags
|=
NETDEV_FLAG_LINK_UP
;
netdev
->
flags
|=
NETDEV_FLAG_LINK_UP
;
...
@@ -796,7 +802,7 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
...
@@ -796,7 +802,7 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
else
else
{
{
netdev
->
flags
&=
~
NETDEV_FLAG_LINK_UP
;
netdev
->
flags
&=
~
NETDEV_FLAG_LINK_UP
;
/* set network interface device flags to internet down */
/* set network interface device flags to internet down */
netdev
->
flags
&=
~
NETDEV_FLAG_INTERNET_UP
;
netdev
->
flags
&=
~
NETDEV_FLAG_INTERNET_UP
;
...
@@ -817,7 +823,7 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
...
@@ -817,7 +823,7 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
/**
/**
* This function will set network interface device DHCP status.
* This function will set network interface device DHCP status.
* @NOTE it can only be called in the network interface device driver.
* @NOTE it can only be called in the network interface device driver.
*
*
* @param netdev the network interface device to change
* @param netdev the network interface device to change
* @param is_up the new DHCP status
* @param is_up the new DHCP status
*/
*/
...
@@ -889,7 +895,7 @@ static void netdev_list_if(void)
...
@@ -889,7 +895,7 @@ static void netdev_list_if(void)
/* two numbers are displayed at one time*/
/* two numbers are displayed at one time*/
if
(
netdev
->
hwaddr
[
index
]
<
10
&&
index
!=
netdev
->
hwaddr_len
-
1
)
if
(
netdev
->
hwaddr
[
index
]
<
10
&&
index
!=
netdev
->
hwaddr_len
-
1
)
rt_kprintf
(
"0"
);
rt_kprintf
(
"0"
);
rt_kprintf
(
"%d"
,
netdev
->
hwaddr
[
index
]);
rt_kprintf
(
"%d"
,
netdev
->
hwaddr
[
index
]);
}
}
}
}
...
@@ -915,9 +921,9 @@ static void netdev_list_if(void)
...
@@ -915,9 +921,9 @@ static void netdev_list_if(void)
{
{
ip_addr_t
*
addr
;
ip_addr_t
*
addr
;
int
i
;
int
i
;
addr
=
&
netdev
->
ip6_addr
[
0
];
addr
=
&
netdev
->
ip6_addr
[
0
];
if
(
!
ip_addr_isany
(
addr
))
if
(
!
ip_addr_isany
(
addr
))
{
{
rt_kprintf
(
"ipv6 link-local: %s %s
\n
"
,
inet_ntoa
(
*
addr
),
rt_kprintf
(
"ipv6 link-local: %s %s
\n
"
,
inet_ntoa
(
*
addr
),
...
@@ -929,7 +935,7 @@ static void netdev_list_if(void)
...
@@ -929,7 +935,7 @@ static void netdev_list_if(void)
rt_kprintf
(
"ipv6[%d] address: %s %s
\n
"
,
i
,
inet_ntoa
(
*
addr
),
rt_kprintf
(
"ipv6[%d] address: %s %s
\n
"
,
i
,
inet_ntoa
(
*
addr
),
!
ip_addr_isany
(
addr
)
?
"VALID"
:
"INVALID"
);
!
ip_addr_isany
(
addr
)
?
"VALID"
:
"INVALID"
);
}
}
}
}
}
}
#endif
/* NETDEV_IPV6 */
#endif
/* NETDEV_IPV6 */
...
@@ -937,7 +943,7 @@ static void netdev_list_if(void)
...
@@ -937,7 +943,7 @@ static void netdev_list_if(void)
{
{
rt_kprintf
(
"dns server #%d: %s
\n
"
,
index
,
inet_ntoa
(
netdev
->
dns_servers
[
index
]));
rt_kprintf
(
"dns server #%d: %s
\n
"
,
index
,
inet_ntoa
(
netdev
->
dns_servers
[
index
]));
}
}
if
(
rt_slist_next
(
node
))
if
(
rt_slist_next
(
node
))
{
{
rt_kprintf
(
"
\n
"
);
rt_kprintf
(
"
\n
"
);
...
@@ -1016,7 +1022,7 @@ int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
...
@@ -1016,7 +1022,7 @@ int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
struct
netdev
*
netdev
=
RT_NULL
;
struct
netdev
*
netdev
=
RT_NULL
;
struct
netdev_ping_resp
ping_resp
;
struct
netdev_ping_resp
ping_resp
;
int
index
,
ret
=
0
;
int
index
,
ret
=
0
;
if
(
size
==
0
)
if
(
size
==
0
)
{
{
size
=
NETDEV_PING_DATA_SIZE
;
size
=
NETDEV_PING_DATA_SIZE
;
...
@@ -1044,7 +1050,7 @@ int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
...
@@ -1044,7 +1050,7 @@ int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
ret
=
netdev
->
ops
->
ping
(
netdev
,
(
const
char
*
)
target_name
,
size
,
NETDEV_PING_RECV_TIMEO
,
&
ping_resp
);
ret
=
netdev
->
ops
->
ping
(
netdev
,
(
const
char
*
)
target_name
,
size
,
NETDEV_PING_RECV_TIMEO
,
&
ping_resp
);
if
(
ret
==
-
RT_ETIMEOUT
)
if
(
ret
==
-
RT_ETIMEOUT
)
{
{
rt_kprintf
(
"ping: from %s icmp_seq=%d timeout
\n
"
,
rt_kprintf
(
"ping: from %s icmp_seq=%d timeout
\n
"
,
(
ip_addr_isany
(
&
(
ping_resp
.
ip_addr
)))
?
target_name
:
inet_ntoa
(
ping_resp
.
ip_addr
),
index
);
(
ip_addr_isany
(
&
(
ping_resp
.
ip_addr
)))
?
target_name
:
inet_ntoa
(
ping_resp
.
ip_addr
),
index
);
}
}
else
if
(
ret
==
-
RT_ERROR
)
else
if
(
ret
==
-
RT_ERROR
)
...
@@ -1057,16 +1063,16 @@ int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
...
@@ -1057,16 +1063,16 @@ int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
{
{
if
(
ping_resp
.
ttl
==
0
)
if
(
ping_resp
.
ttl
==
0
)
{
{
rt_kprintf
(
"%d bytes from %s icmp_seq=%d time=%d ms
\n
"
,
rt_kprintf
(
"%d bytes from %s icmp_seq=%d time=%d ms
\n
"
,
ping_resp
.
data_len
,
inet_ntoa
(
ping_resp
.
ip_addr
),
index
,
ping_resp
.
ticks
);
ping_resp
.
data_len
,
inet_ntoa
(
ping_resp
.
ip_addr
),
index
,
ping_resp
.
ticks
);
}
}
else
else
{
{
rt_kprintf
(
"%d bytes from %s icmp_seq=%d ttl=%d time=%d ms
\n
"
,
rt_kprintf
(
"%d bytes from %s icmp_seq=%d ttl=%d time=%d ms
\n
"
,
ping_resp
.
data_len
,
inet_ntoa
(
ping_resp
.
ip_addr
),
index
,
ping_resp
.
ttl
,
ping_resp
.
ticks
);
ping_resp
.
data_len
,
inet_ntoa
(
ping_resp
.
ip_addr
),
index
,
ping_resp
.
ttl
,
ping_resp
.
ticks
);
}
}
}
}
rt_thread_mdelay
(
NETDEV_PING_DELAY
);
rt_thread_mdelay
(
NETDEV_PING_DELAY
);
}
}
...
@@ -1107,7 +1113,7 @@ static void netdev_list_dns(void)
...
@@ -1107,7 +1113,7 @@ static void netdev_list_dns(void)
{
{
rt_kprintf
(
"dns server #%d: %s
\n
"
,
index
,
inet_ntoa
(
netdev
->
dns_servers
[
index
]));
rt_kprintf
(
"dns server #%d: %s
\n
"
,
index
,
inet_ntoa
(
netdev
->
dns_servers
[
index
]));
}
}
if
(
rt_slist_next
(
node
))
if
(
rt_slist_next
(
node
))
{
{
rt_kprintf
(
"
\n
"
);
rt_kprintf
(
"
\n
"
);
...
@@ -1128,9 +1134,10 @@ static void netdev_set_dns(char *netdev_name, uint8_t dns_num, char *dns_server)
...
@@ -1128,9 +1134,10 @@ static void netdev_set_dns(char *netdev_name, uint8_t dns_num, char *dns_server)
}
}
inet_aton
(
dns_server
,
&
dns_addr
);
inet_aton
(
dns_server
,
&
dns_addr
);
netdev_set_dns_server
(
netdev
,
dns_num
,
&
dns_addr
);
if
(
netdev_set_dns_server
(
netdev
,
dns_num
,
&
dns_addr
)
==
RT_EOK
)
{
rt_kprintf
(
"set network interface device(%s) dns server #0: %s
\n
"
,
netdev_name
,
dns_server
);
rt_kprintf
(
"set network interface device(%s) dns server #%d: %s
\n
"
,
netdev_name
,
dns_num
,
dns_server
);
}
}
}
int
netdev_dns
(
int
argc
,
char
**
argv
)
int
netdev_dns
(
int
argc
,
char
**
argv
)
...
@@ -1196,7 +1203,7 @@ int netdev_netstat(int argc, char **argv)
...
@@ -1196,7 +1203,7 @@ int netdev_netstat(int argc, char **argv)
{
{
rt_kprintf
(
"Please input: netstat
\n
"
);
rt_kprintf
(
"Please input: netstat
\n
"
);
}
}
else
else
{
{
netdev_cmd_netstat
();
netdev_cmd_netstat
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录