From 0ef69d52388a6c02198d055b7958b22e677b0dae Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Tue, 21 Feb 2023 00:25:02 +0800 Subject: [PATCH] [Ameba] init route hook after getting ipv6 (#25142) * [hook] init routehook when ipv6 assigned * [build] add route hook to other apps * restyle --- .../ameba/main/DeviceCallbacks.cpp | 24 ++++++++++++++++--- .../light-switch-app/ameba/chip_main.cmake | 3 +++ .../ameba/main/DeviceCallbacks.cpp | 22 +++++++++++++++++ examples/lighting-app/ameba/chip_main.cmake | 3 +++ .../ameba/main/DeviceCallbacks.cpp | 22 +++++++++++++++++ .../ota-requestor-app/ameba/chip_main.cmake | 3 +++ .../ameba/main/DeviceCallbacks.cpp | 22 +++++++++++++++++ 7 files changed, 96 insertions(+), 3 deletions(-) diff --git a/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp b/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp index 1a7a256bb144f4..f0be547259a2b8 100644 --- a/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp +++ b/examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp @@ -72,6 +72,18 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ OnInternetConnectivityChange(event); break; + case DeviceEventType::kCHIPoBLEConnectionEstablished: + ChipLogProgress(DeviceLayer, "CHIPoBLE Connection Established"); + break; + + case DeviceEventType::kCHIPoBLEConnectionClosed: + ChipLogProgress(DeviceLayer, "CHIPoBLE Connection Closed"); + break; + + case DeviceEventType::kCHIPoBLEAdvertisingChange: + ChipLogProgress(DeviceLayer, "CHIPoBLE advertising has changed"); + break; + case DeviceEventType::kInterfaceIpAddressChanged: if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) @@ -82,6 +94,15 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ // newly selected address. chip::app::DnssdServer::Instance().StartServer(); } + if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned) + { + ChipLogProgress(DeviceLayer, "Initializing route hook..."); + ameba_route_hook_init(); + } + break; + + case DeviceEventType::kCommissioningComplete: + ChipLogProgress(DeviceLayer, "Commissioning Complete"); break; } } @@ -122,9 +143,6 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event { ChipLogProgress(DeviceLayer, "IPv6 Server ready..."); chip::app::DnssdServer::Instance().StartServer(); - - ChipLogProgress(DeviceLayer, "Initializing route hook..."); - ameba_route_hook_init(); #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR // Init OTA requestor only when we have gotten IPv6 address if (!isOTAInitialized) diff --git a/examples/light-switch-app/ameba/chip_main.cmake b/examples/light-switch-app/ameba/chip_main.cmake index 4a23725ae121e4..0a7ff30b56501e 100755 --- a/examples/light-switch-app/ameba/chip_main.cmake +++ b/examples/light-switch-app/ameba/chip_main.cmake @@ -156,6 +156,9 @@ list( ${chip_dir}/examples/light-switch-app/ameba/main/Globals.cpp ${chip_dir}/examples/light-switch-app/ameba/main/LEDWidget.cpp + ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_hook.c + ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_table.c + ${chip_dir}/examples/providers/DeviceInfoProviderImpl.cpp ) diff --git a/examples/light-switch-app/ameba/main/DeviceCallbacks.cpp b/examples/light-switch-app/ameba/main/DeviceCallbacks.cpp index 4add42b4132550..babcc549eba3bb 100644 --- a/examples/light-switch-app/ameba/main/DeviceCallbacks.cpp +++ b/examples/light-switch-app/ameba/main/DeviceCallbacks.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,18 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ OnInternetConnectivityChange(event); break; + case DeviceEventType::kCHIPoBLEConnectionEstablished: + ChipLogProgress(DeviceLayer, "CHIPoBLE Connection Established"); + break; + + case DeviceEventType::kCHIPoBLEConnectionClosed: + ChipLogProgress(DeviceLayer, "CHIPoBLE Connection Closed"); + break; + + case DeviceEventType::kCHIPoBLEAdvertisingChange: + ChipLogProgress(DeviceLayer, "CHIPoBLE advertising has changed"); + break; + case DeviceEventType::kInterfaceIpAddressChanged: if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) @@ -81,6 +94,15 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ // newly selected address. chip::app::DnssdServer::Instance().StartServer(); } + if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned) + { + ChipLogProgress(DeviceLayer, "Initializing route hook..."); + ameba_route_hook_init(); + } + break; + + case DeviceEventType::kCommissioningComplete: + ChipLogProgress(DeviceLayer, "Commissioning Complete"); break; } } diff --git a/examples/lighting-app/ameba/chip_main.cmake b/examples/lighting-app/ameba/chip_main.cmake index 0a71784057ee32..86329e533eee65 100755 --- a/examples/lighting-app/ameba/chip_main.cmake +++ b/examples/lighting-app/ameba/chip_main.cmake @@ -149,6 +149,9 @@ list( ${chip_dir}/examples/lighting-app/ameba/main/Globals.cpp ${chip_dir}/examples/lighting-app/ameba/main/LEDWidget.cpp + ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_hook.c + ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_table.c + ${chip_dir}/examples/providers/DeviceInfoProviderImpl.cpp ) diff --git a/examples/lighting-app/ameba/main/DeviceCallbacks.cpp b/examples/lighting-app/ameba/main/DeviceCallbacks.cpp index 4ae9c49f1c88e6..957512f727ba1a 100644 --- a/examples/lighting-app/ameba/main/DeviceCallbacks.cpp +++ b/examples/lighting-app/ameba/main/DeviceCallbacks.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,18 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ OnInternetConnectivityChange(event); break; + case DeviceEventType::kCHIPoBLEConnectionEstablished: + ChipLogProgress(DeviceLayer, "CHIPoBLE Connection Established"); + break; + + case DeviceEventType::kCHIPoBLEConnectionClosed: + ChipLogProgress(DeviceLayer, "CHIPoBLE Connection Closed"); + break; + + case DeviceEventType::kCHIPoBLEAdvertisingChange: + ChipLogProgress(DeviceLayer, "CHIPoBLE advertising has changed"); + break; + case DeviceEventType::kInterfaceIpAddressChanged: if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) @@ -79,6 +92,15 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ // newly selected address. chip::app::DnssdServer::Instance().StartServer(); } + if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned) + { + ChipLogProgress(DeviceLayer, "Initializing route hook..."); + ameba_route_hook_init(); + } + break; + + case DeviceEventType::kCommissioningComplete: + ChipLogProgress(DeviceLayer, "Commissioning Complete"); break; } } diff --git a/examples/ota-requestor-app/ameba/chip_main.cmake b/examples/ota-requestor-app/ameba/chip_main.cmake index 11db9b502b8001..a7aecb06707370 100644 --- a/examples/ota-requestor-app/ameba/chip_main.cmake +++ b/examples/ota-requestor-app/ameba/chip_main.cmake @@ -26,6 +26,9 @@ list( ${chip_dir}/src/app/clusters/ota-requestor/ota-requestor-server.cpp ${chip_dir}/examples/platform/ameba/ota/OTAInitializer.cpp + ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_hook.c + ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_table.c + ${chip_dir}/examples/providers/DeviceInfoProviderImpl.cpp ) diff --git a/examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp b/examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp index 23030fead6f986..e2da60638d3d7d 100644 --- a/examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp +++ b/examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,18 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ OnInternetConnectivityChange(event); break; + case DeviceEventType::kCHIPoBLEConnectionEstablished: + ChipLogProgress(DeviceLayer, "CHIPoBLE Connection Established"); + break; + + case DeviceEventType::kCHIPoBLEConnectionClosed: + ChipLogProgress(DeviceLayer, "CHIPoBLE Connection Closed"); + break; + + case DeviceEventType::kCHIPoBLEAdvertisingChange: + ChipLogProgress(DeviceLayer, "CHIPoBLE advertising has changed"); + break; + case DeviceEventType::kInterfaceIpAddressChanged: if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) @@ -81,6 +94,15 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_ // newly selected address. chip::app::DnssdServer::Instance().StartServer(); } + if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned) + { + ChipLogProgress(DeviceLayer, "Initializing route hook..."); + ameba_route_hook_init(); + } + break; + + case DeviceEventType::kCommissioningComplete: + ChipLogProgress(DeviceLayer, "Commissioning Complete"); break; } }