Skip to content

Commit

Permalink
Merge 326fc29 into 762a204
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinez-silabs authored Jul 23, 2021
2 parents 762a204 + 326fc29 commit 4542616
Show file tree
Hide file tree
Showing 12 changed files with 490 additions and 392 deletions.
3 changes: 0 additions & 3 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ int main(void)
MemMonitoring::startHeapMonitoring();
#endif

// Initialize mbedtls threading support on EFR32
THREADING_setup();

EFR32_LOG("==================================================");
EFR32_LOG("chip-efr32-lighting-example starting");
EFR32_LOG("==================================================");
Expand Down
3 changes: 0 additions & 3 deletions examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ int main(void)
init_efrPlatform();
mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree);

// Initialize mbedtls threading support on EFR32
THREADING_setup();

EFR32_LOG("==================================================");
EFR32_LOG("chip-efr32-lock-example starting");
EFR32_LOG("==================================================");
Expand Down
3 changes: 0 additions & 3 deletions examples/shell/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ int main(void)
MemMonitoring::startHeapMonitoring();
#endif

// Initialize mbedtls threading support on EFR32
THREADING_setup();

EFR32_LOG("==================================================");
EFR32_LOG("chip-efr32-shell-example starting");
EFR32_LOG("==================================================");
Expand Down
3 changes: 0 additions & 3 deletions examples/window-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ int main(void)

mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree);

// Initialize mbedtls threading support on EFR32
THREADING_setup();

EFR32_LOG("==================================================");
EFR32_LOG("chip-efr32-window-cover-example starting");
EFR32_LOG("==================================================");
Expand Down
16 changes: 13 additions & 3 deletions src/platform/EFR32/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <platform/internal/BLEManager.h>

#include "FreeRTOS.h"
#include "rail.h"
#include "sl_bt_api.h"
#include "sl_bt_stack_config.h"
#include "sl_bt_stack_init.h"
Expand All @@ -37,7 +38,6 @@
#include <platform/EFR32/freertos_bluetooth.h>
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>

using namespace ::chip;
using namespace ::chip::Ble;

Expand Down Expand Up @@ -117,6 +117,10 @@ BLEManagerImpl BLEManagerImpl::sInstance;
******************************************************************************/
extern "C" sl_status_t initialize_bluetooth()
{
#if !defined(SL_CATALOG_KERNEL_PRESENT)
NVIC_ClearPendingIRQ(PendSV_IRQn);
NVIC_EnableIRQ(PendSV_IRQn);
#endif
sl_status_t ret = sl_bt_init_stack(&config);
sl_bt_init_classes(bt_class_table);
sl_bt_init_multiprotocol();
Expand All @@ -131,7 +135,7 @@ static void initBleConfig(void)
config.bluetooth.max_advertisers = BLE_MAX_ADVERTISERS;
config.bluetooth.max_periodic_sync = BLE_CONFIG_MAX_PERIODIC_ADVERTISING_SYNC;
config.bluetooth.max_buffer_memory = BLE_MAX_BUFFER_SIZE;
config.gattdb = &bg_gattdb_data; /* Pointer to GATT database */
config.gattdb = &gattdb; /* Pointer to GATT database */
config.scheduler_callback = BluetoothLLCallback;
config.stack_schedule_callback = BluetoothUpdate;
config.max_timers = BLE_CONFIG_MAX_SOFTWARE_TIMERS;
Expand Down Expand Up @@ -236,10 +240,15 @@ void BLEManagerImpl::bluetoothStackEventHandler(void * p_arg)
switch (SL_BT_MSG_ID(bluetooth_evt->header))
{
case sl_bt_evt_system_boot_id: {
ChipLogProgress(DeviceLayer, "Bluetooth stack booted: v%d.%d.%d-b%d\n", bluetooth_evt->data.evt_system_boot.major,
ChipLogProgress(DeviceLayer, "Bluetooth stack booted: v%d.%d.%d-b%d", bluetooth_evt->data.evt_system_boot.major,
bluetooth_evt->data.evt_system_boot.minor, bluetooth_evt->data.evt_system_boot.patch,
bluetooth_evt->data.evt_system_boot.build);
sInstance.HandleBootEvent();

RAIL_Version_t railVer;
RAIL_GetVersion(&railVer, true);
ChipLogProgress(DeviceLayer, "RAIL version:, v%d.%d.%d-b%d", railVer.major, railVer.minor, railVer.rev,
railVer.build);
}
break;

Expand Down Expand Up @@ -741,6 +750,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
err = MapBLEError(ret);
SuccessOrExit(err);

sl_bt_advertiser_set_configuration(advertising_set_handle, 1);
ret = sl_bt_advertiser_start(advertising_set_handle, sl_bt_advertiser_user_data, connectableAdv);

if (SL_STATUS_OK == ret)
Expand Down
19 changes: 4 additions & 15 deletions src/platform/EFR32/efr32-chip-mbedtls-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@
#include "em_se.h"
#include "sl_malloc.h"

/**
* Enable FreeRTOS threading support
*/
#define MBEDTLS_FREERTOS
#define MBEDTLS_THREADING_C
#define MBEDTLS_THREADING_ALT

#define SL_CATALOG_FREERTOS_KERNEL_PRESENT

/**
Expand All @@ -53,13 +46,8 @@
#define MBEDTLS_ECDH_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_CIPHER_MODE_CTR
#define MBEDTLS_TRNG_C

#if defined(MBEDTLS_ECP_ALT) && !defined(MBEDTLS_ECP_RESTARTABLE)
typedef void mbedtls_ecp_restart_ctx;
#endif

#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf

#define MBEDTLS_AES_ROM_TABLES
Expand All @@ -69,8 +57,6 @@ typedef void mbedtls_ecp_restart_ctx;
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_CIPHER_MODE_CFB
#define MBEDTLS_CMAC_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_ECDH_LEGACY_CONTEXT
Expand Down Expand Up @@ -103,7 +89,6 @@ typedef void mbedtls_ecp_restart_ctx;
#define MBEDTLS_PSA_CRYPTO_C
#define MBEDTLS_PSA_CRYPTO_CONFIG
#define MBEDTLS_PSA_CRYPTO_DRIVERS
#define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
#define MBEDTLS_PSA_CRYPTO_STORAGE_C
#define MBEDTLS_SHA256_SMALLER
#define MBEDTLS_SHA512_C
Expand Down Expand Up @@ -143,5 +128,9 @@ typedef void mbedtls_ecp_restart_ctx;

#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8

#define MBEDTLS_CIPHER_MODE_WITH_PADDING

#include "check_crypto_config.h"
#include "config-device-acceleration.h"
#include "mbedtls/check_config.h"
#include "mbedtls/config_psa.h"
66 changes: 66 additions & 0 deletions src/platform/EFR32/efr32-mbedtls-psa-crypto-config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
* 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.
*/

#pragma once

// ADD USER PSA CRYPTO CONFIG HERE
#define SL_PSA_KEY_USER_SLOT_COUNT (4)

#define SL_PSA_ITS_USER_MAX_FILES (128)
// end of user configuration section >>>

// AUTO GENERATED PSA CONFIG SECTION BELOW. **KEEP AS IS FUTURE GSDK UPDATE**
#define PSA_WANT_KEY_TYPE_AES
#define PSA_WANT_ALG_CMAC
#define MBEDTLS_PSA_BUILTIN_ALG_CMAC 1
#define PSA_WANT_ALG_SHA_224
#define PSA_WANT_ALG_SHA_256
#define PSA_WANT_ALG_CCM
#define PSA_WANT_ALG_CBC_NO_PADDING
#define PSA_WANT_ALG_ECB_NO_PADDING
#define PSA_WANT_ALG_ECDSA
#define PSA_WANT_ALG_ECDH
#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
#define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
#define PSA_WANT_ECC_SECP_R1_256
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY 1
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR 1
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_256 1
#define MBEDTLS_PSA_BUILTIN_ALG_ECDH 1
#define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1
#define PSA_WANT_ALG_HKDF
#define PSA_WANT_ALG_HMAC
#define PSA_WANT_KEY_TYPE_HMAC
#define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
#define MBEDTLS_PSA_ACCEL_ALG_SHA_1
#define MBEDTLS_PSA_ACCEL_ALG_SHA_224
#define MBEDTLS_PSA_ACCEL_ALG_SHA_256
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_AES
#define MBEDTLS_PSA_ACCEL_ALG_ECB_NO_PADDING
#define MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING
#define MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7
#define MBEDTLS_PSA_ACCEL_ALG_CTR
#define MBEDTLS_PSA_ACCEL_ALG_CFB
#define MBEDTLS_PSA_ACCEL_ALG_OFB
#define MBEDTLS_PSA_ACCEL_ALG_GCM
#define MBEDTLS_PSA_ACCEL_ALG_CCM
#define MBEDTLS_PSA_ACCEL_ALG_CMAC

#define MBEDTLS_PSA_KEY_SLOT_COUNT (15 + 1 + SL_PSA_KEY_USER_SLOT_COUNT)
#define SL_PSA_ITS_MAX_FILES (1 + SL_PSA_ITS_USER_MAX_FILES)
2 changes: 2 additions & 0 deletions src/platform/EFR32/freertos_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void BluetoothTask(void * p)
vRaiseEventFlagBasedOnContext(bluetooth_event_flags, BLUETOOTH_EVENT_FLAG_RSP_WAITING);
}

// Run Bluetooth stack. Pop the next event for application
sl_bt_run();
// Bluetooth stack needs updating, and evt can be used
if (sl_bt_event_pending() && (flags & BLUETOOTH_EVENT_FLAG_EVT_HANDLED))
{ // update bluetooth & read event
Expand Down
Loading

0 comments on commit 4542616

Please sign in to comment.