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

[toble] Enable Thread-over-BLE configuration. #38

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
PROJECT_ROOT := $(realpath .)

OPENWEAVE_ROOT ?= $(PROJECT_ROOT)/third_party/openweave-core
OPENTHREAD_ROOT ?= $(PROJECT_ROOT)/third_party/openthread

BUILD_SUPPORT_DIR = $(OPENWEAVE_ROOT)/build/nrf5

Expand Down Expand Up @@ -160,7 +161,8 @@ INC_DIRS = \
$(NRF5_SDK_ROOT)/modules/nrfx \
$(NRF5_SDK_ROOT)/modules/nrfx/drivers/include \
$(NRF5_SDK_ROOT)/modules/nrfx/hal \
$(NRF5_SDK_ROOT)/modules/nrfx/mdk
$(NRF5_SDK_ROOT)/modules/nrfx/mdk \
$(OPENTHREAD_ROOT)/examples/platforms/nrf52840

DEFINES = \
NRF52840_XXAA \
Expand Down
31 changes: 30 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 @@ -35,6 +37,12 @@
// issues with Thread.
#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

/// Turns on Child Supervision to properly recover network connectivity after device reset.
#define OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE 0

// When operating in a less than ideal RF environment, having a more forgiving configuration
// of OpenThread makes thread a great deal more reliable.
#define OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_DIRECT 15 // default is 3
Expand All @@ -49,6 +57,27 @@
//
#include "openthread-core-nrf52840-config.h"

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

#if OPENTHREAD_CONFIG_ENABLE_TOBLE

#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_6LOWPAN_REASSEMBLY_TIMEOUT 60
#define OPENTHREAD_CONFIG_MLE_PARENT_REQUEST_ROUTER_TIMEOUT 1500
#define OPENTHREAD_CONFIG_MLE_PARENT_REQUEST_REED_TIMEOUT 3000

#endif // OPENTHREAD_CONFIG_ENABLE_TOBLE

#define OPENTHREAD_CONFIG_NORDIC_BLE_CFG_TAG NRF_BLE_CFG_TAG

#endif // OPENTHREAD_PLATFORM_CONFIG_H
18 changes: 18 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,17 @@
*/
#define WEAVE_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE nl::Weave::Profiles::DataManagement::Debug


#define WEAVE_DEVICE_CONFIG_WOBLE_SINGLE_CONNECTION 1
#define WEAVE_DEVICE_CONFIG_WOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED 1
#define WEAVE_DEVICE_CONFIG_DISABLE_ACCOUNT_PAIRING 1

/**
* 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
3 changes: 2 additions & 1 deletion main/include/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef APP_CONFIG_H
#define APP_CONFIG_H

#include "ble_config.h"

// ----- Memory Config -----

#define MEM_MANAGER_ENABLED 1
Expand All @@ -39,7 +41,6 @@
#define NRF_SDH_ENABLED 1
#define NRF_SDH_SOC_ENABLED 1
#define NRF_SDH_BLE_ENABLED 1
#define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 1
#define NRF_SDH_BLE_VS_UUID_COUNT 2
#define NRF_BLE_GATT_ENABLED 1
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 251
Expand Down
40 changes: 40 additions & 0 deletions main/include/ble_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* 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

/**
* @file
* This file implements the BLE configuration shared by OpenThread and OpenWeave.
*/

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

/**
* Increase # of connections supported to two so both WoBLE and ToBLE can advertise.
*/
#define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 2

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

#endif // BLE_CONFIG_H
9 changes: 9 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ extern "C" {
#include <openthread/platform/platform-softdevice.h>
}

#include "OpenThreadConfig.h"

#include <Weave/DeviceLayer/WeaveDeviceLayer.h>
#include <Weave/DeviceLayer/ThreadStackManager.h>
#include <Weave/DeviceLayer/nRF5/GroupKeyStoreImpl.h>
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 Down
2 changes: 1 addition & 1 deletion third_party/openthread