Skip to content

Commit

Permalink
AP_Networking: add AutoIP support
Browse files Browse the repository at this point in the history
* This allows link local addressing for zero-config setup

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed May 14, 2024
1 parent 64e7964 commit cf752ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/AP_Networking/AP_Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const AP_Param::GroupInfo AP_Networking::var_info[] = {
// @Param: OPTIONS
// @DisplayName: Networking options
// @Description: Networking options
// @Bitmask: 0:EnablePPP Ethernet gateway
// @Bitmask: 0:EnablePPP Ethernet gateway,1:Enable AUTOIP (Link Local IPv4 Addressing)
// @RebootRequired: True
// @User: Advanced
AP_GROUPINFO("OPTIONS", 9, AP_Networking, param.options, 0),
Expand Down
15 changes: 15 additions & 0 deletions libraries/AP_Networking/AP_Networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ class AP_Networking
#endif
}


// returns true if AUTOIP is enabled
bool get_autoip_enabled() const
{
#if AP_NETWORKING_AUTOIP_AVAILABLE
return option_is_set(OPTION::AUTOIP);
#else
// AUTOIP is not available from our scope but could be enabled/controlled
// by the OS which is the case on Linux builds, including SITL
// TODO: ask the OS if link local IPv4 addressing is enabled
return false;
#endif
}

// Sets DHCP to be enabled or disabled
void set_dhcp_enable(const bool enable)
{
Expand Down Expand Up @@ -155,6 +169,7 @@ class AP_Networking

enum class OPTION {
PPP_ETHERNET_GATEWAY=(1U<<0),
AUTOIP=(1u<<1)
};
bool option_is_set(OPTION option) const {
return (param.options.get() & int32_t(option)) != 0;
Expand Down
10 changes: 10 additions & 0 deletions libraries/AP_Networking/AP_Networking_ChibiOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ void AP_Networking_ChibiOS::link_up_cb(void *p)
if (driver->frontend.get_dhcp_enabled()) {
dhcp_start(driver->thisif);
}
# if LWIP_AUTOIP
if(driver->frontend.get_autoip_enabled()) {
autoip_start(driver->thisif);
}
#endif // LWIP_AUTOIP
#endif
}

Expand All @@ -158,6 +163,11 @@ void AP_Networking_ChibiOS::link_down_cb(void *p)
if (driver->frontend.get_dhcp_enabled()) {
dhcp_stop(driver->thisif);
}
# if LWIP_AUTOIP
if(driver->frontend.get_autoip_enabled()) {
autoip_stop(driver->thisif);
}
#endif // LWIP_AUTOIP
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Networking/AP_Networking_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
#define AP_NETWORKING_DHCP_AVAILABLE (AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS_ENABLED || AP_NETWORKING_BACKEND_CHIBIOS)
#endif

#ifndef AP_NETWORKING_AUTOIP_AVAILABLE
#define AP_NETWORKING_AUTOIP_AVAILABLE AP_NETWORKING_DHCP_AVAILABLE
#endif

// ---------------------------
// Below are default params
Expand Down

0 comments on commit cf752ff

Please sign in to comment.