Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
[toble] Enable ToBLE feature when third_party/openthread supports it.
Browse files Browse the repository at this point in the history
- Add logic to disable WoBLE when ToBLE is provisioned.
- Extend default logging to include OpenThread platform and debug.
- Increase GATT table size.
- Make woble and toble use same ble config tag.
  • Loading branch information
turon committed Oct 22, 2019
1 parent c2e12ab commit 6812470
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 2 deletions.
34 changes: 33 additions & 1 deletion main/include/OpenThreadConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef OPENTHREAD_PLATFORM_CONFIG_H
#define OPENTHREAD_PLATFORM_CONFIG_H

#include "ble_config.h"

// Disable the Nordic-supplied OpenThread logging facilities and use
// the facilities provided by the OpenWeave Device Layer (see
// openweave/src/adaptations/device-layer/nRF5/Logging.cpp).
Expand All @@ -33,6 +35,9 @@
// Turn on a moderate level of logging in OpenThread
#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_NOTE

// To turn on Nordic platform logs set this to 1
#define OPENTHREAD_CONFIG_LOG_PLATFORM 0

// Use the Nordic-supplied default platform configuration for remainder
// of OpenThread config options.
//
Expand All @@ -41,6 +46,33 @@
//
#include "openthread-core-nrf52840-config.h"

#endif // OPENTHREAD_PLATFORM_CONFIG_H
// ==============================================================
// CONFIG TOBLE
// ==============================================================

/**
* To enable the Thread-over-BLE feature set this to 1.
*/
#define OPENTHREAD_CONFIG_ENABLE_TOBLE 0

#define OPENTHREAD_CONFIG_ENABLE_BLE 1
#define OPENTHREAD_CONFIG_ENABLE_TOBLE_TO_BLE 1
#define OPENTHREAD_CONFIG_TOBLE_CENTRAL_ENABLE 0
#define OPENTHREAD_CONFIG_TOBLE_PERIPHERAL_ENABLE 1
#define OPENTHREAD_CONFIG_TOBLE_MULTI_RADIO_ENABLE 1
#define OPENTHREAD_CONFIG_TOBLE_154_ATTACH_ATTEMPT_RATIO 2

#define OPENTHREAD_DISABLE_TOBLE_GATT_ACKNOWLEDGEMENTS 0

#define OPENTHREAD_CONFIG_MAC_DATA_POLL_RESPONSE_TIMEOUT 500
#define OPENTHREAD_CONFIG_6LOWPAN_REASSEMBLY_TIMEOUT 60

#define OPENTHREAD_CONFIG_MLE_PARENT_REQUEST_ROUTER_TIMEOUT 1500
#define OPENTHREAD_CONFIG_MLE_PARENT_REQUEST_REED_TIMEOUT 3000
#define OPENTHREAD_CONFIG_MLE_UNICAST_RETRANSMISSION_DELAY 1500
#define OPENTHREAD_CONFIG_MLE_CHILD_ID_REQUEST_TIMEOUT 10000

#define OPENTHREAD_CONFIG_NORDIC_BLE_CFG_TAG NRF_BLE_CFG_TAG


#endif // OPENTHREAD_PLATFORM_CONFIG_H
13 changes: 13 additions & 0 deletions main/include/WeaveProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#ifndef WEAVE_PROJECT_CONFIG_H
#define WEAVE_PROJECT_CONFIG_H

#include "ble_config.h"


#define WEAVE_PROGRESS_LOGGING 1

/**
* WEAVE_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY
*
Expand Down Expand Up @@ -146,4 +151,12 @@
*/
#define WEAVE_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE nl::Weave::Profiles::DataManagement::Debug

/**
* WEAVE_DEVICE_LAYER_BLE_CONN_CFG_TAG
*
* The SoftDevice BLE connection configuration tag must be the same
* across both OpenWeave and OpenThread.
*/
#define WEAVE_DEVICE_LAYER_BLE_CONN_CFG_TAG NRF_BLE_CFG_TAG

#endif // WEAVE_PROJECT_CONFIG_H
26 changes: 26 additions & 0 deletions main/include/ble_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
*
* Copyright (c) 2019 Google LLC.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef BLE_CONFIG_H
#define BLE_CONFIG_H

// ---- BLE Config ----
#define NRF_BLE_CFG_TAG 1


#endif // BLE_CONFIG_H
43 changes: 43 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ using namespace ::nl::Weave::DeviceLayer;

extern "C" size_t GetHeapTotalSize(void);

static void DeviceEventHandler(const WeaveDeviceEvent * event, intptr_t arg);

// ================================================================================
// Logging Support
// ================================================================================
Expand Down Expand Up @@ -213,12 +215,19 @@ int main(void)

{
uint32_t appRAMStart = 0;
ble_cfg_t bleCfg;

// Configure the BLE stack using the default settings.
// Fetch the start address of the application RAM.
ret = nrf_sdh_ble_default_cfg_set(WEAVE_DEVICE_LAYER_BLE_CONN_CFG_TAG, &appRAMStart);
APP_ERROR_CHECK(ret);

// Increase the GATT table size to allow room for both WoBLE and ToBLE services.
memset(&bleCfg, 0, sizeof(bleCfg));
bleCfg.gatts_cfg.attr_tab_size.attr_tab_size = NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE * 2;
ret = sd_ble_cfg_set(BLE_GATTS_CFG_ATTR_TAB_SIZE, &bleCfg, appRAMStart);
APP_ERROR_CHECK(ret);

// Enable BLE stack.
ret = nrf_sdh_ble_enable(&appRAMStart);
APP_ERROR_CHECK(ret);
Expand All @@ -239,6 +248,10 @@ int main(void)
APP_ERROR_HANDLER(ret);
}

// Register a function to receive events from the Weave device layer. Note that calls to
// this function will happen on the Weave event loop thread, not the app_main thread.
PlatformMgr().AddEventHandler(DeviceEventHandler, 0);

NRF_LOG_INFO("Initializing OpenThread stack");

otSysInit(0, NULL);
Expand Down Expand Up @@ -285,6 +298,21 @@ int main(void)
}
}

#if OPENTHREAD_CONFIG_ENABLE_TOBLE
// Disable Weave Pairing if Thread network has already been provisioned.
// TODO: Change this to only disable WoBLE when *full provisioning* has completed,
// i.e. ConfigurationManager.IsPairedToAccount()
if (ConnectivityMgr().IsThreadProvisioned())
{
ConnectivityMgr().SetBLEAdvertisingEnabled(false);
NRF_LOG_INFO("WoBLE pairing is disabled, as Thread is provisioned");
}
else
#endif // OPENTHREAD_CONFIG_ENABLE_TOBLE
{
NRF_LOG_INFO("WoBLE pairing is enabled");
}

NRF_LOG_INFO("Starting Weave task");

ret = PlatformMgr().StartEventLoopTask();
Expand Down Expand Up @@ -329,3 +357,18 @@ int main(void)
NRF_LOG_INFO("vTaskStartScheduler() failed");
APP_ERROR_HANDLER(0);
}

/* Handle events from the Weave Device layer.
*
* NOTE: This function runs on the Weave event loop task.
*/
void DeviceEventHandler(const WeaveDeviceEvent * event, intptr_t arg)
{
if (event->Type == DeviceEventType::kSessionEstablished &&
event->SessionEstablished.IsCommissioner)
{
// Disable advertising when Commissioner connected over WoBLE
// so ToBLE connectivity checks can occur.
ConnectivityMgr().SetBLEAdvertisingEnabled(false);
}
}
2 changes: 1 addition & 1 deletion third_party/openweave-core
Submodule openweave-core updated 59 files
+21 −1 build/esp32/components/openweave/Kconfig
+2 −1 build/nrf5/nrf5-app.mk
+2 −0 build/nrf5/nrf5-openthread.mk
+12 −107 configure
+2 −11 configure.ac
+51 −7 doc/STYLE_GUIDE.md
+4 −4 doc/guides/tools/index.md
+39 −0 src/adaptations/device-layer/LwIP/WarmSupport.cpp
+7 −0 src/adaptations/device-layer/include/Weave/DeviceLayer/ConfigurationManager.h
+1 −0 src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/WeaveDevicePlatformConfig.h
+1 −0 src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/WeavePlatformConfig.h
+1 −0 src/adaptations/device-layer/include/Weave/DeviceLayer/LwIP/WarmSupport.h
+4 −4 src/adaptations/device-layer/include/Weave/DeviceLayer/OpenThread/GenericThreadStackManagerImpl_OpenThread.ipp
+12 −0 src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h
+3 −0 src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h
+166 −2 src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp
+5 −3 src/adaptations/device-layer/nRF5/BLEManagerImpl.cpp
+16 −1 src/device-manager/WeaveDeviceManager.cpp
+2 −0 src/device-manager/WeaveDeviceManager.h
+16 −3 src/device-manager/python/WeaveDeviceManager-ScriptBinding.cpp
+1 −1 src/device-manager/python/build-openweave-wheel.py
+4 −3 src/device-manager/python/openweave/WeaveDeviceMgr.py
+11 −3 src/device-manager/python/weave-device-mgr.py
+131 −47 src/inet/IPEndPointBasis.cpp
+25 −91 src/inet/IPEndPointBasis.h
+223 −4 src/inet/RawEndPoint.cpp
+3 −184 src/inet/RawEndPoint.h
+292 −81 src/inet/UDPEndPoint.cpp
+3 −143 src/inet/UDPEndPoint.h
+59 −2 src/lib/core/WeaveConfig.h
+31 −0 src/lib/core/WeaveMessageLayer.cpp
+3 −0 src/lib/core/WeaveMessageLayer.h
+10 −3 src/lib/profiles/data-management/Current/UpdateClient.h
+325 −9 src/lib/profiles/security/WeaveCert.cpp
+20 −1 src/lib/profiles/security/WeaveCert.h
+5 −3 src/lib/profiles/weave-tunneling/WeaveTunnelConnectionMgr.cpp
+4 −2 src/lib/support/Base64.h
+13 −0 src/lib/support/MathUtils.h
+13 −1 src/lib/support/crypto/EllipticCurve.h
+1 −1 src/test-apps/Makefile.am
+2 −1 src/test-apps/Makefile.in
+180 −0 src/test-apps/TestWeaveCert.cpp
+4 −3 src/test-apps/TestWeaveCertData.cpp
+2 −2 src/test-apps/TestWeaveCertData.h
+1 −1 src/test-apps/TestWeaveTunnelBR.cpp
+25 −0 src/test-apps/TestWeaveTunnelServer.cpp
+9 −1 src/test-apps/ToolCommon.cpp
+17 −1 src/test-apps/ToolCommonOptions.cpp
+2 −0 src/test-apps/ToolCommonOptions.h
+11 −3 src/test-apps/happy/lib/WeaveNodeConfigure.py
+32 −6 src/test-apps/happy/lib/WeaveState.py
+6 −4 src/test-apps/happy/test-templates/ServiceAccountManager.py
+19 −6 src/test-apps/happy/test-templates/WeavePairing.py
+66 −39 src/test-apps/happy/test-templates/WeaveTunnelStart.py
+17 −33 src/test-apps/happy/tests/standalone/tunnel/test_weave_tunnel_01.py
+7 −1 src/test-apps/happy/topologies/standalone/thread_wifi_on_tap_ap_service.sh
+4 −8 src/tools/simnet/lib/simnet/layouts/two-devices.py
+134 −52 src/tools/simnet/simnet.py
+7 −0 src/tools/weave/Cmd_ConvertProvisioningData.cpp

0 comments on commit 6812470

Please sign in to comment.