Skip to content

Commit

Permalink
[Ameba] init route hook after getting ipv6 (#25142)
Browse files Browse the repository at this point in the history
* [hook] init routehook when ipv6 assigned

* [build] add route hook to other apps

* restyle
  • Loading branch information
pankore authored and pull[bot] committed Nov 22, 2023
1 parent 6cd9092 commit 0ef69d5
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 3 deletions.
24 changes: 21 additions & 3 deletions examples/all-clusters-app/ameba/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions examples/light-switch-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
22 changes: 22 additions & 0 deletions examples/light-switch-app/ameba/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <app/util/basic-types.h>
#include <app/util/util.h>
#include <lib/dnssd/Advertiser.h>
#include <route_hook/ameba_route_hook.h>
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <support/logging/Constants.h>
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}
}
Expand Down
3 changes: 3 additions & 0 deletions examples/lighting-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
22 changes: 22 additions & 0 deletions examples/lighting-app/ameba/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <app/util/basic-types.h>
#include <app/util/util.h>
#include <lib/dnssd/Advertiser.h>
#include <route_hook/ameba_route_hook.h>
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <support/logging/Constants.h>
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}
}
Expand Down
3 changes: 3 additions & 0 deletions examples/ota-requestor-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
22 changes: 22 additions & 0 deletions examples/ota-requestor-app/ameba/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <app/util/basic-types.h>
#include <app/util/util.h>
#include <lib/dnssd/Advertiser.h>
#include <route_hook/ameba_route_hook.h>
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <support/logging/Constants.h>
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 0ef69d5

Please sign in to comment.