-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support for RADIUS configuration options to Wi-SUN #13412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,21 @@ | |
| #include "WisunBorderRouter.h" | ||
| #include "MeshInterfaceNanostack.h" | ||
| #include "net_interface.h" | ||
| #include "ip6string.h" | ||
|
|
||
| extern "C" { | ||
| #include "ws_bbr_api.h" | ||
| } | ||
|
|
||
| #define TRACE_GROUP "WSBR" | ||
|
|
||
|
|
||
| WisunBorderRouter::WisunBorderRouter() | ||
| { | ||
| // Apply mbed configuration to Wi-SUN BBR | ||
| configure(); | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, NetworkInterface *backbone_if) | ||
| { | ||
| if (mesh_if == NULL || backbone_if == NULL) { | ||
|
|
@@ -53,6 +61,8 @@ mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, NetworkInterfac | |
| return MESH_ERROR_UNKNOWN; | ||
| } | ||
|
|
||
| apply_configuration(mesh_if_id); | ||
|
|
||
| int ret = ws_bbr_start(mesh_if_id, backbone_if_id); | ||
| if (ret < 0) { | ||
| return MESH_ERROR_UNKNOWN; | ||
|
|
@@ -76,6 +86,8 @@ mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, OnboardNetworkS | |
| return MESH_ERROR_UNKNOWN; | ||
| } | ||
|
|
||
| apply_configuration(mesh_if_id); | ||
|
|
||
| int ret = ws_bbr_start(mesh_if_id, backbone_if_id); | ||
| if (ret < 0) { | ||
| return MESH_ERROR_UNKNOWN; | ||
|
|
@@ -95,6 +107,55 @@ void WisunBorderRouter::stop() | |
| _mesh_if_id = -1; | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::configure() | ||
| { | ||
| #if defined(MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET) || defined(MBED_CONF_MBED_MESH_API_RADIUS_SERVER_IPV6_ADDRESS) | ||
| mesh_error_t status; | ||
| #endif | ||
|
|
||
| if (_configured) { | ||
| // Already configured | ||
| return MESH_ERROR_NONE; | ||
| } | ||
|
|
||
| _configured = true; | ||
|
|
||
| #ifdef MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET | ||
| const char radius_shared_secret[] = {MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET}; | ||
| #ifdef MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET_LEN | ||
| const uint16_t radius_shared_secret_len = MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET_LEN; | ||
| #else | ||
| uint16_t radius_shared_secret_len = strlen(radius_shared_secret); | ||
| #endif | ||
| status = set_radius_shared_secret(radius_shared_secret_len, (uint8_t *) radius_shared_secret); | ||
| if (status != MESH_ERROR_NONE) { | ||
| tr_error("Failed to set RADIUS shared secret!"); | ||
| return status; | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef MBED_CONF_MBED_MESH_API_RADIUS_SERVER_IPV6_ADDRESS | ||
| const char radius_server_ipv6_addr[] = {MBED_CONF_MBED_MESH_API_RADIUS_SERVER_IPV6_ADDRESS}; | ||
| status = set_radius_server_ipv6_address(radius_server_ipv6_addr); | ||
| if (status != MESH_ERROR_NONE) { | ||
| tr_error("Failed to set RADIUS server IPv6 address!"); | ||
| return status; | ||
| } | ||
| #endif | ||
|
|
||
| return MESH_ERROR_NONE; | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::apply_configuration(int8_t mesh_if_id) | ||
| { | ||
| mesh_error_t status = set_bbr_radius_address(); | ||
| if (status != MESH_ERROR_NONE) { | ||
| tr_error("Failed to apply RADIUS server IPv6 address!"); | ||
| return MESH_ERROR_PARAM; | ||
| } | ||
| return MESH_ERROR_NONE; | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::set_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant) | ||
| { | ||
| int status = ws_bbr_rpl_parameters_set(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant); | ||
|
|
@@ -188,3 +249,78 @@ int WisunBorderRouter::routing_table_get(ws_br_route_info_t *table_ptr, uint16_t | |
|
|
||
| return ws_bbr_routing_table_get(_mesh_if_id, (bbr_route_info_t *)table_ptr, table_len); | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::set_radius_server_ipv6_address(const char *address) | ||
| { | ||
| if (address) { | ||
| uint8_t ipv6_addr[16]; | ||
| if (!stoip6(address, strlen(address), ipv6_addr)) { | ||
| return MESH_ERROR_PARAM; | ||
| } | ||
| // Stored address (returned by get) is in the format given by user of the interface | ||
| strcpy(_radius_ipv6_addr, address); | ||
| _radius_ipv6_addr_set = true; | ||
| } else { | ||
| _radius_ipv6_addr_set = false; | ||
| } | ||
|
|
||
| return set_bbr_radius_address(); | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::get_radius_server_ipv6_address(char *address) | ||
| { | ||
| if (!_radius_ipv6_addr_set) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would not need these booleans if you would always read these variables from the Mbed json in the begining? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The RADIUS configuration could be unspecified in the .json (use internal TLS) and then later enabled by configuration function calls. |
||
| return MESH_ERROR_UNKNOWN; | ||
| } | ||
| strcpy(address, _radius_ipv6_addr); | ||
|
|
||
| return MESH_ERROR_NONE; | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::set_bbr_radius_address(void) | ||
| { | ||
| int status; | ||
|
|
||
| if (_radius_ipv6_addr_set) { | ||
| uint8_t ipv6_addr[16]; | ||
| if (!stoip6(_radius_ipv6_addr, strlen(_radius_ipv6_addr), ipv6_addr)) { | ||
| return MESH_ERROR_PARAM; | ||
| } | ||
| status = ws_bbr_radius_address_set(_mesh_if_id, ipv6_addr); | ||
| } else { | ||
| status = ws_bbr_radius_address_set(_mesh_if_id, NULL); | ||
| } | ||
| if (status != 0) { | ||
| return MESH_ERROR_UNKNOWN; | ||
| } | ||
|
|
||
| return MESH_ERROR_NONE; | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::set_radius_shared_secret(uint16_t shared_secret_len, const uint8_t *shared_secret) | ||
| { | ||
| if (shared_secret_len == 0 || !shared_secret) { | ||
| return MESH_ERROR_PARAM; | ||
| } | ||
|
|
||
| int status = ws_bbr_radius_shared_secret_set(_mesh_if_id, shared_secret_len, shared_secret); | ||
| if (status != 0) { | ||
| return MESH_ERROR_UNKNOWN; | ||
| } | ||
|
|
||
| return MESH_ERROR_NONE; | ||
| } | ||
|
|
||
| mesh_error_t WisunBorderRouter::get_radius_shared_secret(uint16_t *shared_secret_len, uint8_t *shared_secret) | ||
| { | ||
| if (shared_secret_len == NULL) { | ||
| return MESH_ERROR_PARAM; | ||
| } | ||
|
|
||
| int status = ws_bbr_radius_shared_secret_get(_mesh_if_id, shared_secret_len, shared_secret); | ||
| if (status != 0) { | ||
| return MESH_ERROR_UNKNOWN; | ||
| } | ||
|
|
||
| return MESH_ERROR_NONE; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the GET interfaces for these
Could this be combined in the higher level api to have radius_configure(address,password)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can add the get interface. There are no defaults for these, so the application must always program these first, but it might be easier for application, if the values could also be read from Nanostack.
I would prefer having the two functions for this since either one can be changed individually.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added get interfaces. Added storing of IP address and shared secret to border router class. Changed configuration to two phases, on class init the .json configuration is applied (if set) and then on BBR start the BBR is configured with the address and shared secret using the then defined (mesh) interface id.