From 865e34650c8c631151412672d5177eafca368c2b Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Mon, 12 Apr 2021 18:11:37 +0800 Subject: [PATCH] [add] the function of set [internet up] status, activate the callback. --- components/net/netdev/include/netdev.h | 1 + components/net/netdev/src/netdev.c | 28 ++++++++++++++++++++++ components/net/sal_socket/src/sal_socket.c | 4 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/components/net/netdev/include/netdev.h b/components/net/netdev/include/netdev.h index 16da0e502c..91f68ba3ea 100644 --- a/components/net/netdev/include/netdev.h +++ b/components/net/netdev/include/netdev.h @@ -186,6 +186,7 @@ void netdev_low_level_set_gw(struct netdev *netdev, const ip_addr_t *gw); 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_status(struct netdev *netdev, rt_bool_t is_up); void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up); +void netdev_low_level_set_internet_status(struct netdev *netdev, rt_bool_t is_up); void netdev_low_level_set_dhcp_status(struct netdev *netdev, rt_bool_t is_enable); #ifdef __cplusplus diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c index 3f7aa401c1..f722909cc8 100644 --- a/components/net/netdev/src/netdev.c +++ b/components/net/netdev/src/netdev.c @@ -828,6 +828,34 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up) } } +/** + * This function will set network interface device active internet status. + * @NOTE it can only be called in the network interface device driver. + * + * @param netdev the network interface device to change + * @param is_up the new internet status + */ +void netdev_low_level_set_internet_status(struct netdev *netdev, rt_bool_t is_up) +{ + if (netdev && netdev_is_internet_up(netdev) != is_up) + { + if (is_up) + { + netdev->flags |= NETDEV_FLAG_INTERNET_UP; + } + else + { + netdev->flags &= ~NETDEV_FLAG_INTERNET_UP; + } + + /* execute network interface device status change callback function */ + if (netdev->status_callback) + { + netdev->status_callback(netdev, is_up ? NETDEV_CB_STATUS_INTERNET_UP : NETDEV_CB_STATUS_INTERNET_DOWN); + } + } +} + /** * This function will set network interface device DHCP status. * @NOTE it can only be called in the network interface device driver. diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index e7142fae94..982ab2d08d 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -261,12 +261,12 @@ __exit: if (result > 0) { LOG_D("Set network interface device(%s) internet status up.", netdev->name); - netdev->flags |= NETDEV_FLAG_INTERNET_UP; + netdev_low_level_set_internet_status(netdev, RT_TRUE); } else { LOG_D("Set network interface device(%s) internet status down.", netdev->name); - netdev->flags &= ~NETDEV_FLAG_INTERNET_UP; + netdev_low_level_set_internet_status(netdev, RT_FALSE); } if (sockfd >= 0)