openthread: support 1.3 border routing features
- Support ICMPv6 auto config - Support SRP service delegation - Publish _meshcop._mdns service
This commit is contained in:
@@ -146,3 +146,80 @@ I(552749) OPENTHREAD:[INFO]-UTIL----: Starting Child Supervision
|
||||
```
|
||||
|
||||
The device has now joined the same Thread network based on the key set by the commissioner.
|
||||
|
||||
## Bidirectional IPv6 connectivity
|
||||
|
||||
The border router will automatically publish the prefix and the route table rule to the WiFi network via ICMPv6 router advertisment packages.
|
||||
|
||||
### Host configuration
|
||||
|
||||
The automatically configure your host's route table rules you need to set these sysctl options:
|
||||
|
||||
Please relace `wlan0` with the real name of your WiFi network interface.
|
||||
```
|
||||
sudo sysctl -w net/ipv6/conf/wlan0/accept_ra=2
|
||||
sudo sysctl -w net/ipv6/conf/wlan0/accept_ra_rt_info_max_plen=128
|
||||
```
|
||||
|
||||
For mobile devices, the route table rules will be automatically configured after iOS 14 and Android 8.1.
|
||||
|
||||
|
||||
### Testing IPv6 connecitivity
|
||||
|
||||
Now in the joining device, check the IP addresses:
|
||||
|
||||
```
|
||||
> ipaddr
|
||||
fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5
|
||||
fdde:ad00:beef:0:0:ff:fe00:c402
|
||||
fdde:ad00:beef:0:ad4a:9a9a:3cd6:e423
|
||||
fe80:0:0:0:f011:2951:569e:9c4a
|
||||
```
|
||||
|
||||
You'll notice an IPv6 global prefix with only on address assigned under it. This is the routable address of this Thread node.
|
||||
You can ping this address on your host:
|
||||
|
||||
``` bash
|
||||
$ ping fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5
|
||||
PING fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5(fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5) 56 data bytes
|
||||
64 bytes from fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5: icmp_seq=1 ttl=63 time=459 ms
|
||||
64 bytes from fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5: icmp_seq=2 ttl=63 time=109 ms
|
||||
64 bytes from fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5: icmp_seq=3 ttl=63 time=119 ms
|
||||
64 bytes from fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5: icmp_seq=4 ttl=63 time=117 ms
|
||||
```
|
||||
|
||||
## Service discovery
|
||||
|
||||
The newly introduced service registration protocol([SRP](https://datatracker.ietf.org/doc/html/draft-ietf-dnssd-srp-10)) allows devices in the Thread network to register a service. The border router will forward the service to the WiFi network via mDNS.
|
||||
|
||||
Now we'll publish the service `my-service._test._udp` with hostname `test0` and port 12345
|
||||
|
||||
```
|
||||
> srp client host name test0
|
||||
Done
|
||||
> srp client host address fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5
|
||||
Done
|
||||
> srp client service add my-service _test._udp 12345
|
||||
Done
|
||||
> srp client autostart enable
|
||||
Done
|
||||
```
|
||||
|
||||
This service will also become visible on the WiFi network:
|
||||
|
||||
```bash
|
||||
$ avahi-browse -r _test._udp -t
|
||||
|
||||
+ enp1s0 IPv6 my-service _test._udp local
|
||||
= enp1s0 IPv6 my-service _test._udp local
|
||||
hostname = [test0.local]
|
||||
address = [fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5]
|
||||
port = [12345]
|
||||
txt = []
|
||||
+ enp1s0 IPv4 my-service _test._udp local
|
||||
= enp1s0 IPv4 my-service _test._udp local
|
||||
hostname = [test0.local]
|
||||
address = [fde6:75ff:def4:3bc3:9e9e:3ef:4245:28b5]
|
||||
port = [12345]
|
||||
txt = []
|
||||
```
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "esp_ot_config.h"
|
||||
#include "esp_vfs_eventfd.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "mdns.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "protocol_examples_common.h"
|
||||
#include "sdkconfig.h"
|
||||
@@ -109,18 +110,19 @@ static void create_config_network(otInstance *instance)
|
||||
abort();
|
||||
}
|
||||
dataset.mComponents.mIsExtendedPanIdPresent = true;
|
||||
if (hex_string_to_binary(CONFIG_OPENTHREAD_NETWORK_MASTERKEY, dataset.mMasterKey.m8,
|
||||
sizeof(dataset.mMasterKey.m8)) != sizeof(dataset.mMasterKey.m8)) {
|
||||
if (hex_string_to_binary(CONFIG_OPENTHREAD_NETWORK_MASTERKEY, dataset.mNetworkKey.m8,
|
||||
sizeof(dataset.mNetworkKey.m8)) != sizeof(dataset.mNetworkKey.m8)) {
|
||||
ESP_LOGE(TAG, "Cannot convert OpenThread master key. Please double-check your config.");
|
||||
abort();
|
||||
}
|
||||
dataset.mComponents.mIsMasterKeyPresent = true;
|
||||
dataset.mComponents.mIsNetworkKeyPresent = true;
|
||||
if (hex_string_to_binary(CONFIG_OPENTHREAD_NETWORK_PSKC, dataset.mPskc.m8, sizeof(dataset.mPskc.m8)) !=
|
||||
sizeof(dataset.mPskc.m8)) {
|
||||
ESP_LOGE(TAG, "Cannot convert OpenThread pre-shared commissioner key. Please double-check your config.");
|
||||
abort();
|
||||
}
|
||||
dataset.mComponents.mIsPskcPresent = true;
|
||||
dataset.mComponents.mIsMeshLocalPrefixPresent = false;
|
||||
if (otDatasetSetActive(instance, &dataset) != OT_ERROR_NONE) {
|
||||
ESP_LOGE(TAG, "Failed to set OpenThread active dataset.");
|
||||
abort();
|
||||
@@ -188,5 +190,7 @@ void app_main(void)
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(example_connect());
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
|
||||
ESP_ERROR_CHECK(mdns_init());
|
||||
ESP_ERROR_CHECK(mdns_hostname_set("esp-ot-br"));
|
||||
xTaskCreate(ot_task_worker, "ot_br_main", 20480, xTaskGetCurrentTaskHandle(), 5, NULL);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,16 @@ CONFIG_OPENTHREAD_BORDER_ROUTER=y
|
||||
#
|
||||
# lwIP
|
||||
#
|
||||
CONFIG_LWIP_IPV6_FORWARD=y
|
||||
CONFIG_LWIP_IPV6_NUM_ADDRESSES=8
|
||||
CONFIG_LWIP_MULTICAST_PING=y
|
||||
CONFIG_LWIP_NETIF_STATUS_CALLBACK=y
|
||||
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
|
||||
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
|
||||
# end of lwIP
|
||||
|
||||
#
|
||||
# mDNS
|
||||
#
|
||||
CONFIG_MDNS_STRICT_MODE=y
|
||||
# end of mDNS
|
||||
|
||||
Reference in New Issue
Block a user