From 355893b1e41e9c9049998bb48c4117db9b2cf2ba Mon Sep 17 00:00:00 2001 From: shgutte <102281713+shgutte@users.noreply.github.com> Date: Tue, 9 May 2023 18:19:19 +0530 Subject: [PATCH] [Silabs] [EFR32] Refactor 917 NCP and 917 SoC Bluetooth to use the same implementation (#26390) * Refactor 917 NCP and 917 SoC bluetooth to use the same implementation file * Restyled by gn * Added changes for coding standard --------- Co-authored-by: Restyled.io --- .../silabs/SiWx917/BLEManagerImpl.cpp | 1023 ----------------- src/platform/silabs/SiWx917/BUILD.gn | 8 +- src/platform/silabs/efr32/BUILD.gn | 8 +- .../silabs/efr32/rs911x/rsi_ble_config.h | 270 ----- .../silabs/efr32/rs911x/wfx_sl_ble_init.c | 422 ------- .../silabs/efr32/rs911x/wfx_sl_ble_init.h | 130 --- .../{efr32 => }/rs911x/BLEManagerImpl.cpp | 36 +- .../bluetooth => rs911x}/rsi_ble_config.h | 2 + .../bluetooth => rs911x}/wfx_sl_ble_init.c | 8 +- .../bluetooth => rs911x}/wfx_sl_ble_init.h | 14 +- third_party/silabs/SiWx917_sdk.gni | 1 + third_party/silabs/efr32_sdk.gni | 1 + 12 files changed, 60 insertions(+), 1863 deletions(-) delete mode 100644 src/platform/silabs/SiWx917/BLEManagerImpl.cpp delete mode 100644 src/platform/silabs/efr32/rs911x/rsi_ble_config.h delete mode 100644 src/platform/silabs/efr32/rs911x/wfx_sl_ble_init.c delete mode 100644 src/platform/silabs/efr32/rs911x/wfx_sl_ble_init.h rename src/platform/silabs/{efr32 => }/rs911x/BLEManagerImpl.cpp (97%) rename src/platform/silabs/{SiWx917/bluetooth => rs911x}/rsi_ble_config.h (96%) rename src/platform/silabs/{SiWx917/bluetooth => rs911x}/wfx_sl_ble_init.c (95%) rename src/platform/silabs/{SiWx917/bluetooth => rs911x}/wfx_sl_ble_init.h (90%) diff --git a/src/platform/silabs/SiWx917/BLEManagerImpl.cpp b/src/platform/silabs/SiWx917/BLEManagerImpl.cpp deleted file mode 100644 index 04bf47f85400d0..00000000000000 --- a/src/platform/silabs/SiWx917/BLEManagerImpl.cpp +++ /dev/null @@ -1,1023 +0,0 @@ -/* - * - * Copyright (c) 2020-2021 Project CHIP Authors - * Copyright (c) 2019 Nest Labs, Inc. - * - * 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. - */ - -/** - * @file - * Provides an implementation of the BLEManager singleton object - * for the Silicon Labs EFR32 platforms. - */ - -/* this file behaves like a config.h, comes first */ -#include -#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - -#include -#define RSI_BLE_ENABLE 1 - -//#include "rail.h" -extern "C" { -#include "FreeRTOS.h" -#include "event_groups.h" -#include "task.h" -#include "timers.h" -#include "wfx_host_events.h" -#include "wfx_rsi.h" -#include "wfx_sl_ble_init.h" -#include -#include -#include -} -#include -#include -#include -#include -#include -#include - -#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING -#include -#endif - -// static int32_t handleTxConfirmationFlag = 0; -extern uint16_t rsi_ble_measurement_hndl; -extern rsi_ble_event_conn_status_t conn_event_to_app; -extern sl_wfx_msg_t event_msg; - -StaticTask_t rsiBLETaskStruct; -rsi_semaphore_handle_t sl_rs_ble_init_sem; -rsi_semaphore_handle_t sl_ble_event_sem; - -/* wfxRsi Task will use as its stack */ -StackType_t wfxBLETaskStack[WFX_RSI_TASK_SZ] = { 0 }; - -using namespace ::chip; -using namespace ::chip::Ble; - -void sl_ble_init() -{ - ChipLogProgress(DeviceLayer, "%s starting", __func__); - - // registering the GAP callback functions - rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event, - NULL, NULL, NULL); - - // registering the GATT call back functions - rsi_ble_gatt_register_callbacks(NULL, NULL, NULL, NULL, NULL, NULL, NULL, rsi_ble_on_gatt_write_event, NULL, NULL, NULL, - rsi_ble_on_mtu_event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - rsi_ble_on_event_indication_confirmation, NULL); - rsi_semaphore_create(&sl_ble_event_sem, 0); - ChipLogProgress(DeviceLayer, "registering rsi_ble_add_service"); - - // Exchange of GATT info with BLE stack - rsi_ble_add_matter_service(); - - // initializing the application events map - rsi_ble_app_init_events(); - - ChipLogProgress(DeviceLayer, "StartAdvertising"); - chip::DeviceLayer::Internal::BLEManagerImpl().StartAdvertising(); // TODO:: Called on after init of module - ChipLogProgress(DeviceLayer, "%s Ended", __func__); -} - -void sl_ble_event_handling_task(void) -{ - int32_t event_id; - - ChipLogProgress(DeviceLayer, "%s starting", __func__); - rsi_semaphore_create(&sl_rs_ble_init_sem, 0); - //! This semaphore is waiting for wifi module initialization. - rsi_semaphore_wait(&sl_rs_ble_init_sem, 0); - - // Initialize BLE and starts BLE Advertisement - sl_ble_init(); - - // Application event map - while (1) - { - // checking for events list - event_id = rsi_ble_app_get_event(); - if (event_id == -1) - { - rsi_semaphore_wait(&sl_ble_event_sem, 0); - continue; - } - switch (event_id) - { - case RSI_BLE_CONN_EVENT: { - rsi_ble_app_clear_event(RSI_BLE_CONN_EVENT); - chip::DeviceLayer::Internal::BLEMgrImpl().HandleConnectEvent(); - ChipLogProgress(DeviceLayer, "%s Module got connected", __func__); - // Requests the connection parameters change with the remote device - rsi_ble_conn_params_update(event_msg.resp_enh_conn.dev_addr, BLE_MIN_CONNECTION_INTERVAL_MS, - BLE_MAX_CONNECTION_INTERVAL_MS, BLE_SLAVE_LATENCY_MS, BLE_TIMEOUT_MS); - } - break; - case RSI_BLE_DISCONN_EVENT: { - // event invokes when disconnection was completed - ChipLogProgress(DeviceLayer, "%s Module got Disconnected", __func__); - chip::DeviceLayer::Internal::BLEMgrImpl().HandleConnectionCloseEvent(event_msg.reason); - // clear the served event - rsi_ble_app_clear_event(RSI_BLE_DISCONN_EVENT); - } - break; - case RSI_BLE_MTU_EVENT: { - // event invokes when write/notification events received - ChipLogProgress(DeviceLayer, "%s RSI_BLE_MTU_EVENT", __func__); - chip::DeviceLayer::Internal::BLEMgrImpl().UpdateMtu(event_msg.rsi_ble_mtu); - // clear the served event - rsi_ble_app_clear_event(RSI_BLE_MTU_EVENT); - } - break; - case RSI_BLE_GATT_WRITE_EVENT: { - // event invokes when write/notification events received - ChipLogProgress(DeviceLayer, "%s RSI_BLE_GATT_WRITE_EVENT", __func__); - chip::DeviceLayer::Internal::BLEMgrImpl().HandleWriteEvent(event_msg.rsi_ble_write); - // clear the served event - rsi_ble_app_clear_event(RSI_BLE_GATT_WRITE_EVENT); - } - break; - case RSI_BLE_GATT_INDICATION_CONFIRMATION: { - ChipLogProgress(DeviceLayer, "%s indication confirmation", __func__); - chip::DeviceLayer::Internal::BLEMgrImpl().HandleTxConfirmationEvent(1); - rsi_ble_app_clear_event(RSI_BLE_GATT_INDICATION_CONFIRMATION); - } - break; - - case RSI_BLE_RESP_ATT_VALUE: { - ChipLogProgress(DeviceLayer, "RSI_BLE : RESP_ATT confirmation"); - } - default: - break; - } - } - - ChipLogProgress(DeviceLayer, "%s Ended", __func__); -} - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -namespace { - -#define CHIP_ADV_DATA_TYPE_FLAGS (0x01) -#define CHIP_ADV_DATA_TYPE_UUID (0x03) -#define CHIP_ADV_DATA_TYPE_NAME (0x09) -#define CHIP_ADV_DATA_TYPE_SERVICE_DATA (0x16) - -#define CHIP_ADV_DATA_FLAGS (0x06) - -#define CHIP_ADV_DATA (0) -#define CHIP_ADV_SCAN_RESPONSE_DATA (1) -#define CHIP_ADV_SHORT_UUID_LEN (2) - -#define MAX_RESPONSE_DATA_LEN (31) -#define MAX_ADV_DATA_LEN (31) - -// Timer Frequency used. -#define TIMER_CLK_FREQ ((uint32_t) 32768) - -// Convert msec to timer ticks. -#define TIMER_MS_2_TIMERTICK(ms) ((TIMER_CLK_FREQ * ms) / 1000) -#define TIMER_S_2_TIMERTICK(s) (TIMER_CLK_FREQ * s) - -#define BLE_MAX_BUFFER_SIZE (3076) -#define BLE_MAX_ADVERTISERS (1) -#define BLE_CONFIG_MAX_PERIODIC_ADVERTISING_SYNC (0) -#define BLE_CONFIG_MAX_SOFTWARE_TIMERS (4) -#define BLE_CONFIG_MIN_TX_POWER (-30) -#define BLE_CONFIG_MAX_TX_POWER (80) -#define BLE_CONFIG_RF_PATH_GAIN_TX (0) -#define BLE_CONFIG_RF_PATH_GAIN_RX (0) - -// Default Connection parameters -#define BLE_CONFIG_MIN_INTERVAL (16) // Time = Value x 1.25 ms = 30ms -#define BLE_CONFIG_MAX_INTERVAL (80) // Time = Value x 1.25 ms = 100ms -#define BLE_CONFIG_LATENCY (0) -#define BLE_CONFIG_TIMEOUT (100) // Time = Value x 10 ms = 1s -#define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value -#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value - -#define BLE_DEFAULT_TIMER_PERIOD_MS (1) - -TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer. - -const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00 }; -const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; -const ChipBleUUID ChipUUID_CHIPoBLEChar_RX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, - 0x9D, 0x11 } }; -const ChipBleUUID ChipUUID_CHIPoBLEChar_TX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, - 0x9D, 0x12 } }; - -} // namespace - -BLEManagerImpl BLEManagerImpl::sInstance; - -CHIP_ERROR BLEManagerImpl::_Init() -{ - CHIP_ERROR err; - ChipLogProgress(DeviceLayer, "%s Start ", __func__); - - wfx_rsi.ble_task = xTaskCreateStatic((TaskFunction_t) sl_ble_event_handling_task, "rsi_ble", WFX_RSI_TASK_SZ, NULL, 1, - wfxBLETaskStack, &rsiBLETaskStruct); - - if (wfx_rsi.ble_task == NULL) - { - ChipLogProgress(DeviceLayer, "%s: error: failed to create ble task.", __func__); - } - - // Initialize the CHIP BleLayer. - err = BleLayer::Init(this, this, &DeviceLayer::SystemLayer()); - SuccessOrExit(err); - - memset(mBleConnections, 0, sizeof(mBleConnections)); - memset(mIndConfId, kUnusedIndex, sizeof(mIndConfId)); - mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; - - // Create FreeRTOS sw timer for BLE timeouts and interval change. - sbleAdvTimeoutTimer = xTimerCreate("BleAdvTimer", // Just a text name, not used by the RTOS kernel - pdMS_TO_TICKS(BLE_DEFAULT_TIMER_PERIOD_MS), // == default timer period - false, // no timer reload (==one-shot) - (void *) this, // init timer id = ble obj context - BleAdvTimeoutHandler // timer callback handler - ); - - mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART); - mFlags.Set(Flags::kFastAdvertisingEnabled, true); - PlatformMgr().ScheduleWork(DriveBLEState, 0); - -exit: - ChipLogProgress(DeviceLayer, "%s END ", __func__); - return err; -} - -uint16_t BLEManagerImpl::_NumConnections(void) -{ - uint16_t numCons = 0; - for (uint16_t i = 0; i < kMaxConnections; i++) - { - if (mBleConnections[i].allocated) - { - numCons++; - } - } - - return numCons; -} - -CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); - - if (mFlags.Has(Flags::kAdvertisingEnabled) != val) - { - mFlags.Set(Flags::kAdvertisingEnabled, val); - PlatformMgr().ScheduleWork(DriveBLEState, 0); - } - -exit: - return err; -} - -CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode) -{ - switch (mode) - { - case BLEAdvertisingMode::kFastAdvertising: - mFlags.Set(Flags::kFastAdvertisingEnabled, true); - break; - case BLEAdvertisingMode::kSlowAdvertising: - mFlags.Set(Flags::kFastAdvertisingEnabled, false); - break; - default: - return CHIP_ERROR_INVALID_ARGUMENT; - } - mFlags.Set(Flags::kRestartAdvertising); - PlatformMgr().ScheduleWork(DriveBLEState, 0); - return CHIP_NO_ERROR; -} - -CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize) -{ - if (strlen(mDeviceName) >= bufSize) - { - return CHIP_ERROR_BUFFER_TOO_SMALL; - } - strcpy(buf, mDeviceName); - return CHIP_NO_ERROR; -} - -CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName) -{ - ChipLogProgress(DeviceLayer, "_SetDeviceName Started"); - if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported) - { - ChipLogProgress(DeviceLayer, "_SetDeviceName CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE"); - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - } - if (deviceName != NULL && deviceName[0] != 0) - { - if (strlen(deviceName) >= kMaxDeviceNameLength) - { - ChipLogProgress(DeviceLayer, "_SetDeviceName CHIP_ERROR_INVALID_ARGUMENT"); - return CHIP_ERROR_INVALID_ARGUMENT; - } - strcpy(mDeviceName, deviceName); - mFlags.Set(Flags::kDeviceNameSet); - mFlags.Set(Flags::kRestartAdvertising); - ChipLogProgress(DeviceLayer, "Setting device name to : \"%s\"", mDeviceName); - } - else - { - mDeviceName[0] = 0; - } - PlatformMgr().ScheduleWork(DriveBLEState, 0); - ChipLogProgress(DeviceLayer, "_SetDeviceName Ended"); - return CHIP_NO_ERROR; -} - -void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) -{ - switch (event->Type) - { - case DeviceEventType::kCHIPoBLESubscribe: { - ChipDeviceEvent connEstEvent; - - ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLESubscribe"); - HandleSubscribeReceived(event->CHIPoBLESubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX); - connEstEvent.Type = DeviceEventType::kCHIPoBLEConnectionEstablished; - PlatformMgr().PostEventOrDie(&connEstEvent); - } - break; - - case DeviceEventType::kCHIPoBLEUnsubscribe: { - ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEUnsubscribe"); - HandleUnsubscribeReceived(event->CHIPoBLEUnsubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX); - } - break; - - case DeviceEventType::kCHIPoBLEWriteReceived: { - ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEWriteReceived"); - HandleWriteReceived(event->CHIPoBLEWriteReceived.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_RX, - PacketBufferHandle::Adopt(event->CHIPoBLEWriteReceived.Data)); - } - break; - - case DeviceEventType::kCHIPoBLEConnectionError: { - ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEConnectionError"); - HandleConnectionError(event->CHIPoBLEConnectionError.ConId, event->CHIPoBLEConnectionError.Reason); - } - break; - - case DeviceEventType::kCHIPoBLEIndicateConfirm: { - ChipLogProgress(DeviceLayer, "_OnPlatformEvent kCHIPoBLEIndicateConfirm"); - HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX); - } - break; - - default: - ChipLogProgress(DeviceLayer, "_OnPlatformEvent default: event->Type = %d", event->Type); - break; - } -} - -bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) -{ - ChipLogProgress(DeviceLayer, "BLEManagerImpl::SubscribeCharacteristic() not supported"); - return false; -} - -bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) -{ - ChipLogProgress(DeviceLayer, "BLEManagerImpl::UnsubscribeCharacteristic() not supported"); - return false; -} - -bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - ChipLogProgress(DeviceLayer, "Closing BLE GATT connection (con %u)", conId); - - if (err != CHIP_NO_ERROR) - { - ChipLogError(DeviceLayer, "sl_bt_connection_close() failed: %s", ErrorStr(err)); - } - - return true; //(err == CHIP_NO_ERROR); -} - -uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const -{ - CHIPoBLEConState * conState = const_cast(this)->GetConnectionState(conId); - return (conState != NULL) ? conState->mtu : 0; -} - -bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, - PacketBufferHandle data) -{ - int32_t status = 0; - ChipLogProgress(DeviceLayer, "In send indication"); - status = rsi_ble_indicate_value(event_msg.resp_enh_conn.dev_addr, event_msg.rsi_ble_measurement_hndl, (data->DataLength()), - data->Start()); - if (status != RSI_SUCCESS) - { - ChipLogProgress(DeviceLayer, "indication failed with error code %lx ", status); - return false; - } - - return true; -} - -bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, - PacketBufferHandle pBuf) -{ - ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendWriteRequest() not supported"); - return false; -} - -bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId, - PacketBufferHandle pBuf) -{ - ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendReadRequest() not supported"); - return false; -} - -bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, - const ChipBleUUID * svcId, const ChipBleUUID * charId) -{ - ChipLogProgress(DeviceLayer, "BLEManagerImpl::SendReadResponse() not supported"); - return false; -} - -void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) -{ - // Nothing to do : Placeholder -} - -CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr) -{ - switch (bleErr) - { - case SL_STATUS_OK: - return CHIP_NO_ERROR; - case SL_STATUS_BT_ATT_INVALID_ATT_LENGTH: - return CHIP_ERROR_INVALID_STRING_LENGTH; - case SL_STATUS_INVALID_PARAMETER: - return CHIP_ERROR_INVALID_ARGUMENT; - case SL_STATUS_INVALID_STATE: - return CHIP_ERROR_INCORRECT_STATE; - case SL_STATUS_NOT_SUPPORTED: - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; - default: - return CHIP_ERROR(ChipError::Range::kPlatform, bleErr + CHIP_DEVICE_CONFIG_SILABS_BLE_ERROR_MIN); - } -} - -void BLEManagerImpl::DriveBLEState(void) -{ - ChipLogProgress(DeviceLayer, "DriveBLEState starting"); - CHIP_ERROR err = CHIP_NO_ERROR; - - // Check if BLE stack is initialized ( TODO ) - // VerifyOrExit(mFlags.Has(Flags::kEFRBLEStackInitialized),); - - ChipLogProgress(DeviceLayer, "Start advertising if needed..."); - // Start advertising if needed... - if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && mFlags.Has(Flags::kAdvertisingEnabled) && - NumConnections() < kMaxConnections) - { - - ChipLogProgress(DeviceLayer, "Start/re-start advertising if not already started, or if there is a pending change"); - // Start/re-start advertising if not already started, or if there is a pending change - // to the advertising configuration. - if (!mFlags.Has(Flags::kAdvertising) || mFlags.Has(Flags::kRestartAdvertising)) - { - err = StartAdvertising(); - SuccessOrExit(err); - } - } - - // Otherwise, stop advertising if it is enabled. - else if (mFlags.Has(Flags::kAdvertising)) - { - err = StopAdvertising(); - SuccessOrExit(err); - } - -exit: - ChipLogProgress(DeviceLayer, "DriveBLEState End"); - if (err != CHIP_NO_ERROR) - { - ChipLogError(DeviceLayer, "Disabling CHIPoBLE service due to error: %s", ErrorStr(err)); - mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Disabled; - } -} - -CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) -{ - - ChipBLEDeviceIdentificationInfo mDeviceIdInfo; - CHIP_ERROR err; - int32_t result; - uint8_t responseData[MAX_RESPONSE_DATA_LEN]; - uint8_t advData[MAX_ADV_DATA_LEN]; - uint32_t index = 0; - uint32_t mDeviceNameLength = 0; - uint8_t mDeviceIdInfoLength = 0; - - ChipLogProgress(DeviceLayer, "ConfigureAdvertisingData start"); - - VerifyOrExit((kMaxDeviceNameLength + 1) < UINT8_MAX, err = CHIP_ERROR_INVALID_ARGUMENT); - - memset(responseData, 0, MAX_RESPONSE_DATA_LEN); - memset(advData, 0, MAX_ADV_DATA_LEN); - - err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo); - SuccessOrExit(err); - - if (!mFlags.Has(Flags::kDeviceNameSet)) - { - uint16_t discriminator; - SuccessOrExit(err = GetCommissionableDataProvider()->GetSetupDiscriminator(discriminator)); - - snprintf(mDeviceName, sizeof(mDeviceName), "%s%04u", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, discriminator); - - mDeviceName[kMaxDeviceNameLength] = 0; - mDeviceNameLength = strlen(mDeviceName); - - VerifyOrExit(mDeviceNameLength < kMaxDeviceNameLength, err = CHIP_ERROR_INVALID_ARGUMENT); - } - - mDeviceNameLength = strlen(mDeviceName); // Device Name length + length field - VerifyOrExit(mDeviceNameLength < kMaxDeviceNameLength, err = CHIP_ERROR_INVALID_ARGUMENT); - - mDeviceIdInfoLength = sizeof(mDeviceIdInfo); // Servicedatalen + length+ UUID (Short) - static_assert(sizeof(mDeviceIdInfo) + CHIP_ADV_SHORT_UUID_LEN + 1 <= UINT8_MAX, "Our length won't fit in a uint8_t"); - static_assert(2 + CHIP_ADV_SHORT_UUID_LEN + sizeof(mDeviceIdInfo) + 1 <= MAX_ADV_DATA_LEN, "Our buffer is not big enough"); - - index = 0; - advData[index++] = 0x02; // length - advData[index++] = CHIP_ADV_DATA_TYPE_FLAGS; // AD type : flags - advData[index++] = CHIP_ADV_DATA_FLAGS; // AD value - advData[index++] = static_cast(mDeviceIdInfoLength + CHIP_ADV_SHORT_UUID_LEN + 1); // AD length - advData[index++] = CHIP_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data - advData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value - advData[index++] = ShortUUID_CHIPoBLEService[1]; - - memcpy(&advData[index], (void *) &mDeviceIdInfo, mDeviceIdInfoLength); // AD value - index += mDeviceIdInfoLength; - -#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING - ReturnErrorOnFailure(EncodeAdditionalDataTlv()); -#endif - - result = rsi_ble_set_advertise_data(advData, index); - if (result != SL_STATUS_OK) - { - err = MapBLEError(result); - ChipLogError(DeviceLayer, "rsi_ble_set_advertise_data() failed: %ld", result); - ExitNow(); - } - else - { - ChipLogError(DeviceLayer, "rsi_ble_set_advertise_data() success: %ld", result); - } - - err = MapBLEError(result); - - ChipLogProgress(DeviceLayer, "ConfigureAdvertisingData End"); -exit: - return CHIP_NO_ERROR; -} - -CHIP_ERROR BLEManagerImpl::StartAdvertising(void) -{ - CHIP_ERROR err; - int32_t status = 0; - - ChipLogProgress(DeviceLayer, "StartAdvertising start"); - - // If already advertising, stop it, before changing values - if (mFlags.Has(Flags::kAdvertising)) - { - // sl_bt_advertiser_stop(advertising_set_handle); - } - else - { - ChipLogDetail(DeviceLayer, "Start BLE advertissement"); - } - - err = ConfigureAdvertisingData(); - SuccessOrExit(err); - - mFlags.Clear(Flags::kRestartAdvertising); - - sl_wfx_mac_address_t macaddr; - wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &macaddr); - - //! Set local name - status = rsi_ble_start_advertising(); - if (status == RSI_SUCCESS) - { - ChipLogProgress(DeviceLayer, "rsi_ble_start_advertising Success"); - - if (mFlags.Has(Flags::kFastAdvertisingEnabled)) - { - StartBleAdvTimeoutTimer(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME); - } - mFlags.Set(Flags::kAdvertising); - } - else - { - ChipLogProgress(DeviceLayer, "rsi_ble_start_advertising Failed with status: %lx", status); - } - -exit: - ChipLogError(DeviceLayer, "StartAdvertising() End error: %s", ErrorStr(err)); - return CHIP_NO_ERROR; // err; -} - -// TODO:: Implementation need to be done. -CHIP_ERROR BLEManagerImpl::StopAdvertising(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - // sl_status_t ret; - - if (mFlags.Has(Flags::kAdvertising)) - { - mFlags.Clear(Flags::kAdvertising).Clear(Flags::kRestartAdvertising); - mFlags.Set(Flags::kFastAdvertisingEnabled, true); - advertising_set_handle = 0xff; - CancelBleAdvTimeoutTimer(); - } - - // exit: - return err; -} - -void BLEManagerImpl::UpdateMtu(rsi_ble_event_mtu_t evt) -{ - CHIPoBLEConState * bleConnState = GetConnectionState(event_msg.connectionHandle); - if (bleConnState != NULL) - { - // bleConnState->MTU is a 10-bit field inside a uint16_t. We're - // assigning to it from a uint16_t, and compilers warn about - // possibly not fitting. There's no way to suppress that warning - // via explicit cast; we have to disable the warning around the - // assignment. - // - // TODO: https://github.com/project-chip/connectedhomeip/issues/2569 - // tracks making this safe with a check or explaining why no check - // is needed. - ChipLogProgress(DeviceLayer, "DriveBLEState UpdateMtu %d", evt.mtu_size); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" - bleConnState->mtu = evt.mtu_size; -#pragma GCC diagnostic pop - ; - } -} - -void BLEManagerImpl::HandleBootEvent(void) -{ - mFlags.Set(Flags::kEFRBLEStackInitialized); - PlatformMgr().ScheduleWork(DriveBLEState, 0); -} - -void BLEManagerImpl::HandleConnectEvent(void) -{ - ChipLogProgress(DeviceLayer, "Connect Event for handle : %d", event_msg.connectionHandle); - AddConnection(event_msg.connectionHandle, event_msg.bondingHandle); - - PlatformMgr().ScheduleWork(DriveBLEState, 0); -} - -// TODO:: Implementation need to be done. -void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason) -{ - uint8_t connHandle = 1; - - ChipLogProgress(DeviceLayer, "Disconnect Event for handle : %d", connHandle); - - if (RemoveConnection(connHandle)) - { - ChipDeviceEvent event; - event.Type = DeviceEventType::kCHIPoBLEConnectionError; - event.CHIPoBLEConnectionError.ConId = connHandle; - - switch (reason) - { - - case RSI_BT_CTRL_REMOTE_USER_TERMINATED: - case RSI_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES: - case RSI_BT_CTRL_REMOTE_POWERING_OFF: - event.CHIPoBLEConnectionError.Reason = BLE_ERROR_REMOTE_DEVICE_DISCONNECTED; - break; - default: - event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT; - } - - ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %x)", connHandle, reason); - - PlatformMgr().PostEventOrDie(&event); - - // Arrange to re-enable connectable advertising in case it was disabled due to the - // maximum connection limit being reached. - mFlags.Set(Flags::kRestartAdvertising); - mFlags.Set(Flags::kFastAdvertisingEnabled); - PlatformMgr().ScheduleWork(DriveBLEState, 0); - } -} - -void BLEManagerImpl::HandleWriteEvent(rsi_ble_event_write_t evt) -{ - // RSI_BLE_WRITE_REQUEST_EVENT - ChipLogProgress(DeviceLayer, "Char Write Req, packet type %d", evt.pkt_type); - // uint8_t attribute = (uint8_t) event_msg.rsi_ble_measurement_hndl; - - ChipLogProgress(DeviceLayer, "event_msg.rsi_ble_gatt_server_client_config_hndl = %d", - event_msg.rsi_ble_gatt_server_client_config_hndl); - - if (evt.handle[0] == (uint8_t) event_msg.rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly - { - ChipLogProgress(DeviceLayer, "Inside HandleTXCharCCCDWrite "); - HandleTXCharCCCDWrite(&evt); - } - else - { - HandleRXCharWrite(&evt); - } -} - -// TODO:: Need to implement this -void BLEManagerImpl::HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - bool isIndicationEnabled = false; - ChipDeviceEvent event; - - // Determine if the client is enabling or disabling notification/indication. - if (evt->att_value[0] != 0) - { - isIndicationEnabled = true; - } - ChipLogProgress(DeviceLayer, "HandleTXcharCCCDWrite - Config Flags value : %d", evt->att_value[0]); - ChipLogProgress(DeviceLayer, "CHIPoBLE %s received", isIndicationEnabled ? "subscribe" : "unsubscribe"); - - if (isIndicationEnabled) - { - // Post an event to the CHIP queue to process either a CHIPoBLE Subscribe or Unsubscribe based on - // whether the client is enabling or disabling indications. - { - event.Type = DeviceEventType::kCHIPoBLESubscribe; - event.CHIPoBLESubscribe.ConId = 1; - err = PlatformMgr().PostEvent(&event); - } - } - else - { - event.Type = DeviceEventType::kCHIPoBLEUnsubscribe; - event.CHIPoBLESubscribe.ConId = 1; - err = PlatformMgr().PostEvent(&event); - } -} - -void BLEManagerImpl::HandleRXCharWrite(rsi_ble_event_write_t * evt) -{ - uint8_t conId = 1; - CHIP_ERROR err = CHIP_NO_ERROR; - System::PacketBufferHandle buf; - uint16_t writeLen = evt->length; - uint8_t * data = (uint8_t *) evt->att_value; - - // Copy the data to a packet buffer. - buf = System::PacketBufferHandle::NewWithData(data, writeLen, 0, 0); - VerifyOrExit(!buf.IsNull(), err = CHIP_ERROR_NO_MEMORY); - - ChipLogDetail(DeviceLayer, "Write request/command received for CHIPoBLE RX characteristic ( len %d)", writeLen); - - // Post an event to the CHIP queue to deliver the data into the CHIP stack. - { - ChipDeviceEvent event; - event.Type = DeviceEventType::kCHIPoBLEWriteReceived; - event.CHIPoBLEWriteReceived.ConId = conId; - event.CHIPoBLEWriteReceived.Data = std::move(buf).UnsafeRelease(); - err = PlatformMgr().PostEvent(&event); - } - -exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(DeviceLayer, "HandleRXCharWrite() failed: %s", ErrorStr(err)); - } -} - -void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId) -{ - ChipDeviceEvent event; - event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm; - event.CHIPoBLEIndicateConfirm.ConId = conId; - PlatformMgr().PostEventOrDie(&event); -} - -// TODO:: Need to Implement -void BLEManagerImpl::HandleSoftTimerEvent(void) -{ - // TODO:: Need to Implement -} - -bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle) -{ - CHIPoBLEConState * bleConnState = GetConnectionState(connectionHandle, true); - bool status = false; - - if (bleConnState != NULL) - { - memset(bleConnState, 0, sizeof(CHIPoBLEConState)); - status = true; - } - - return status; -} - -void BLEManagerImpl::AddConnection(uint8_t connectionHandle, uint8_t bondingHandle) -{ - CHIPoBLEConState * bleConnState = GetConnectionState(connectionHandle, true); - - if (bleConnState != NULL) - { - memset(bleConnState, 0, sizeof(CHIPoBLEConState)); - bleConnState->allocated = 1; - bleConnState->connectionHandle = connectionHandle; - bleConnState->bondingHandle = bondingHandle; - } -} - -BLEManagerImpl::CHIPoBLEConState * BLEManagerImpl::GetConnectionState(uint8_t connectionHandle, bool allocate) -{ - uint8_t freeIndex = kMaxConnections; - - for (uint8_t i = 0; i < kMaxConnections; i++) - { - if (mBleConnections[i].allocated == 1) - { - if (mBleConnections[i].connectionHandle == connectionHandle) - { - return &mBleConnections[i]; - } - } - - else if (i < freeIndex) - { - freeIndex = i; - } - } - - if (allocate) - { - if (freeIndex < kMaxConnections) - { - return &mBleConnections[freeIndex]; - } - - ChipLogError(DeviceLayer, "Failed to allocate CHIPoBLEConState"); - } - - return NULL; -} - -#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING -CHIP_ERROR BLEManagerImpl::EncodeAdditionalDataTlv() -{ - CHIP_ERROR err = CHIP_NO_ERROR; - BitFlags additionalDataFields; - AdditionalDataPayloadGeneratorParams additionalDataPayloadParams; - -#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) - uint8_t rotatingDeviceIdUniqueId[ConfigurationManager::kRotatingDeviceIDUniqueIDLength] = {}; - MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId); - - err = DeviceLayer::GetDeviceInstanceInfoProvider()->GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); - SuccessOrExit(err); - err = ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter); - SuccessOrExit(err); - additionalDataPayloadParams.rotatingDeviceIdUniqueId = rotatingDeviceIdUniqueIdSpan; - additionalDataFields.Set(AdditionalDataFields::RotatingDeviceId); -#endif /* CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) */ - - err = AdditionalDataPayloadGenerator().generateAdditionalDataPayload(additionalDataPayloadParams, c3AdditionalDataBufferHandle, - additionalDataFields); - -exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(DeviceLayer, "Failed to generate TLV encoded Additional Data (%s)", __func__); - } - - return err; -} - -// TODO:: Need to do the correct implementation -void BLEManagerImpl::HandleC3ReadRequest(void) -{ - // TODO - // if (ret != SL_STATUS_OK) - // { - // ChipLogDetail(DeviceLayer, "Failed to send read response, err:%ld", ret); - // } -} -#endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING - -uint8_t BLEManagerImpl::GetTimerHandle(uint8_t connectionHandle, bool allocate) -{ - uint8_t freeIndex = kMaxConnections; - - for (uint8_t i = 0; i < kMaxConnections; i++) - { - if (mIndConfId[i] == connectionHandle) - { - return i; - } - else if (allocate) - { - if (i < freeIndex) - { - freeIndex = i; - } - } - } - - if (freeIndex < kMaxConnections) - { - mIndConfId[freeIndex] = connectionHandle; - } - else - { - ChipLogError(DeviceLayer, "Failed to Save Conn Handle for indication"); - } - - return freeIndex; -} - -void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer) -{ - if (BLEMgrImpl().mFlags.Has(Flags::kFastAdvertisingEnabled)) - { - ChipLogDetail(DeviceLayer, "bleAdv Timeout : Start slow advertissment"); - BLEMgr().SetAdvertisingMode(BLEAdvertisingMode::kSlowAdvertising); - } -} - -void BLEManagerImpl::CancelBleAdvTimeoutTimer(void) -{ - if (xTimerStop(sbleAdvTimeoutTimer, pdMS_TO_TICKS(0)) == pdFAIL) - { - ChipLogError(DeviceLayer, "Failed to stop BledAdv timeout timer"); - } -} - -void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs) -{ - if (xTimerIsTimerActive(sbleAdvTimeoutTimer)) - { - CancelBleAdvTimeoutTimer(); - } - - // timer is not active, change its period to required value (== restart). - // FreeRTOS- Block for a maximum of 100 ticks if the change period command - // cannot immediately be sent to the timer command queue. - if (xTimerChangePeriod(sbleAdvTimeoutTimer, pdMS_TO_TICKS(aTimeoutInMs), pdMS_TO_TICKS(100)) != pdPASS) - { - ChipLogError(DeviceLayer, "Failed to start BledAdv timeout timer"); - } -} - -void BLEManagerImpl::DriveBLEState(intptr_t arg) -{ - sInstance.DriveBLEState(); -} - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index db98b116c98507..8aea32914594db 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -58,12 +58,12 @@ static_library("SiWx917") { "${silabs_platform_dir}/platformAbstraction/WiseMcuSpam.cpp", "../../FreeRTOS/SystemTimeSupport.cpp", "../../SingletonConfigurationManager.cpp", - "BLEManagerImpl.cpp", + "../rs911x/BLEManagerImpl.cpp", + "../rs911x/rsi_ble_config.h", + "../rs911x/wfx_sl_ble_init.c", + "../rs911x/wfx_sl_ble_init.h", "ConfigurationManagerImpl.cpp", "PlatformManagerImpl.cpp", - "bluetooth/rsi_ble_config.h", - "bluetooth/wfx_sl_ble_init.c", - "bluetooth/wfx_sl_ble_init.h", ] # TODO: OTA on CCP platform diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index 1a848e54820bed..d6efa34ad7388f 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -68,10 +68,10 @@ static_library("efr32") { if (chip_enable_ble_rs911x) { sources += [ - "rs911x/BLEManagerImpl.cpp", - "rs911x/rsi_ble_config.h", - "rs911x/wfx_sl_ble_init.c", - "rs911x/wfx_sl_ble_init.h", + "../rs911x/BLEManagerImpl.cpp", + "../rs911x/rsi_ble_config.h", + "../rs911x/wfx_sl_ble_init.c", + "../rs911x/wfx_sl_ble_init.h", ] } else { sources += [ "BLEManagerImpl.cpp" ] diff --git a/src/platform/silabs/efr32/rs911x/rsi_ble_config.h b/src/platform/silabs/efr32/rs911x/rsi_ble_config.h deleted file mode 100644 index 8fa5097d37ea53..00000000000000 --- a/src/platform/silabs/efr32/rs911x/rsi_ble_config.h +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * @file rsi_ble_config.h - * @brief - ******************************************************************************* - * # License - * Copyright 2020 Silicon Laboratories Inc. www.silabs.com - ******************************************************************************* - * - * The licensor of this software is Silicon Laboratories Inc. Your use of this - * software is governed by the terms of Silicon Labs Master Software License - * Agreement (MSLA) available at - * www.silabs.com/about-us/legal/master-software-license-agreement. This - * software is distributed to you in Source Code format and is governed by the - * sections of the MSLA applicable to Source Code. - * - ******************************************************************************/ - -#ifndef RSI_BLE_CONFIG_H -#define RSI_BLE_CONFIG_H - -#include "rsi_ble_apis.h" -#include - -/****************************************************** - * * Macros - * ******************************************************/ -//! application event list -#define RSI_BLE_CONN_EVENT 0x01 -#define RSI_BLE_DISCONN_EVENT 0x02 -#define RSI_BLE_GATT_WRITE_EVENT 0x03 -#define RSI_BLE_MTU_EVENT 0x04 -#define RSI_BLE_GATT_INDICATION_CONFIRMATION 0x05 -#define RSI_BLE_RESP_ATT_VALUE 0x06 -#define RSI_SSID 0x0D -#define RSI_SECTYPE 0x0E -#define RSI_BLE_WLAN_DISCONN_NOTIFY 0x0F -#define RSI_WLAN_ALREADY 0x10 -#define RSI_WLAN_NOT_ALREADY 0x11 -#define RSI_BLE_WLAN_TIMEOUT_NOTIFY 0x12 -#define RSI_BLE_WLAN_JOIN_STATUS 0x15 -#define RSI_APP_FW_VERSION 0x13 -#define RSI_BLE_WLAN_DISCONNECT_STATUS 0x14 - -#define RSI_REM_DEV_ADDR_LEN 18 -#define RSI_REM_DEV_NAME_LEN 31 - -#define RSI_BLE_DEV_NAME "CCP_DEVICE" -#define RSI_BLE_SET_RAND_ADDR "00:23:A7:12:34:56" - -#define CLEAR_WHITELIST 0x00 -#define ADD_DEVICE_TO_WHITELIST 0x01 -#define DELETE_DEVICE_FROM_WHITELIST 0x02 - -#define ALL_PHYS 0x00 - -#define RSI_BLE_DEV_ADDR_RESOLUTION_ENABLE 0 - -#define RSI_OPERMODE_WLAN_BLE 13 - -/***********************************************************************************************************************************************/ -//! Characteristic Presenatation Format Fields -/***********************************************************************************************************************************************/ -#define RSI_BLE_UINT8_FORMAT 0x04 -#define RSI_BLE_EXPONENT 0x00 -#define RSI_BLE_PERCENTAGE_UNITS_UUID 0x27AD -#define RSI_BLE_NAME_SPACE 0x01 -#define RSI_BLE_DESCRIPTION 0x010B - -//! BLE characteristic custom service uuid -#define RSI_BLE_CUSTOM_SERVICE_UUID 0xFFF6 -#define RSI_BLE_CUSTOM_LEVEL_UUID 0x1FF1 - -#ifdef RSI_M4_INTERFACE -#define RSI_BLE_MAX_NBR_ATT_REC 20 -#define RSI_BLE_MAX_NBR_SLAVES 1 -#define RSI_BLE_NUM_CONN_EVENTS 2 -#else -#define RSI_BLE_MAX_NBR_ATT_REC 80 -#define RSI_BLE_MAX_NBR_SLAVES 3 -#define RSI_BLE_NUM_CONN_EVENTS 20 -#endif - -#define RSI_BLE_MAX_NBR_ATT_SERV 10 - -#define RSI_BLE_MAX_NBR_MASTERS 1 -#define RSI_BLE_GATT_ASYNC_ENABLE 1 -#define RSI_BLE_GATT_INIT 0 - -#define RSI_BLE_START_SCAN 0x01 -#define RSI_BLE_STOP_SCAN 0x00 - -#define RSI_BLE_SCAN_TYPE SCAN_TYPE_ACTIVE -#define RSI_BLE_SCAN_FILTER_TYPE SCAN_FILTER_TYPE_ALL -/* Number of BLE GATT RECORD SIZE IN (n*16 BYTES), eg:(0x40*16)=1024 bytes */ -#define RSI_BLE_NUM_REC_BYTES 0x40 - -#define RSI_BLE_INDICATE_CONFIRMATION_FROM_HOST 0 - -/*=======================================================================*/ -//! Advertising command parameters -/*=======================================================================*/ - -#define RSI_BLE_ADV_TYPE UNDIR_CONN -#define RSI_BLE_ADV_FILTER_TYPE ALLOW_SCAN_REQ_ANY_CONN_REQ_ANY -#define RSI_BLE_ADV_DIR_ADDR_TYPE LE_PUBLIC_ADDRESS -#define RSI_BLE_ADV_DIR_ADDR "00:15:83:6A:64:17" - -#define RSI_BLE_ADV_INT_MIN 0x20 -#define RSI_BLE_ADV_INT_MAX 0x20 -#define RSI_BLE_ADV_CHANNEL_MAP 0x07 - -//! Advertise status -//! Start the advertising process -#define RSI_BLE_START_ADV 0x01 -//! Stop the advertising process -#define RSI_BLE_STOP_ADV 0x00 - -//! BLE Tx Power Index On Air -#define RSI_BLE_PWR_INX 30 - -//! BLE Active H/w Pwr Features -#define BLE_DISABLE_DUTY_CYCLING 0 -#define BLE_DUTY_CYCLING 1 -#define BLR_DUTY_CYCLING 2 -#define BLE_4X_PWR_SAVE_MODE 4 -#define RSI_BLE_PWR_SAVE_OPTIONS BLE_DISABLE_DUTY_CYCLING - -//! Advertise types - -/* Advertising will be visible(discoverable) to all the devices. - * Scanning/Connection is also accepted from all devices - * */ -#define UNDIR_CONN 0x80 - -/* Advertising will be visible(discoverable) to the particular device - * mentioned in RSI_BLE_ADV_DIR_ADDR only. - * Scanning and Connection will be accepted from that device only. - * */ -#define DIR_CONN 0x81 - -/* Advertising will be visible(discoverable) to all the devices. - * Scanning will be accepted from all the devices. - * Connection will be not be accepted from any device. - * */ -#define UNDIR_SCAN 0x82 - -/* Advertising will be visible(discoverable) to all the devices. - * Scanning and Connection will not be accepted from any device - * */ -#define UNDIR_NON_CONN 0x83 - -/* Advertising will be visible(discoverable) to the particular device - * mentioned in RSI_BLE_ADV_DIR_ADDR only. - * Scanning and Connection will be accepted from that device only. - * */ -#define DIR_CONN_LOW_DUTY_CYCLE 0x84 - -//! Advertising flags -#define LE_LIMITED_DISCOVERABLE 0x01 -#define LE_GENERAL_DISCOVERABLE 0x02 -#define LE_BR_EDR_NOT_SUPPORTED 0x04 - -//! Advertise filters -#define ALLOW_SCAN_REQ_ANY_CONN_REQ_ANY 0x00 -#define ALLOW_SCAN_REQ_WHITE_LIST_CONN_REQ_ANY 0x01 -#define ALLOW_SCAN_REQ_ANY_CONN_REQ_WHITE_LIST 0x02 -#define ALLOW_SCAN_REQ_WHITE_LIST_CONN_REQ_WHITE_LIST 0x03 - -//! Address types -#define LE_PUBLIC_ADDRESS 0x00 -#define LE_RANDOM_ADDRESS 0x01 -#define LE_RESOLVABLE_PUBLIC_ADDRESS 0x02 -#define LE_RESOLVABLE_RANDOM_ADDRESS 0x03 - -/*=======================================================================*/ - -/*=======================================================================*/ -//! Connection parameters -/*=======================================================================*/ -#define LE_SCAN_INTERVAL 0x0100 -#define LE_SCAN_WINDOW 0x0050 - -#define CONNECTION_INTERVAL_MIN 0x00A0 -#define CONNECTION_INTERVAL_MAX 0x00A0 - -#define CONNECTION_LATENCY 0x0000 -#define SUPERVISION_TIMEOUT 0x07D0 // 2000 - -/*=======================================================================*/ - -/*=======================================================================*/ -//! Scan command parameters -/*=======================================================================*/ - -#define SL_WFX_BLE_SCAN_TYPE SCAN_TYPE_ACTIVE -#define SL_WFX_BLE_SCAN_FILTER_TYPE SCAN_FILTER_TYPE_ALL - -//! Scan status -#define SL_WFX_BLE_START_SCAN 0x01 -#define SL_WFX_BLE_STOP_SCAN 0x00 - -//! Scan types -#define SCAN_TYPE_ACTIVE 0x01 -#define SCAN_TYPE_PASSIVE 0x00 - -//! Scan filters -#define SCAN_FILTER_TYPE_ALL 0x00 -#define SCAN_FILTER_TYPE_ONLY_WHITE_LIST 0x01 - -#define SL_WFX_SEL_INTERNAL_ANTENNA 0x00 -#define SL_WFX_SEL_EXTERNAL_ANTENNA 0x01 - -#define SL_WFX_BT_CTRL_REMOTE_USER_TERMINATED 0x4E13 -#define SL_WFX_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES 0x4E14 -#define SL_WFX_BT_CTRL_REMOTE_POWERING_OFF 0x4E15 -#define SL_WFX_BT_CTRL_TERMINATED_MIC_FAILURE 0x4E3D -#define SL_WFX_BT_FAILED_TO_ESTABLISH_CONN 0x4E3E -#define SL_WFX_BT_INVALID_RANGE 0x4E60 - -/***********************************************************************************************************************************************/ -//! RS9116 Firmware Configurations -/***********************************************************************************************************************************************/ - -/*=======================================================================*/ -//! Opermode command parameters -/*=======================================================================*/ -/* -#define RSI_FEATURE_BIT_MAP \ - (FEAT_ULP_GPIO_BASED_HANDSHAKE | FEAT_DEV_TO_HOST_ULP_GPIO_1) //! To set wlan feature select bit map -#define RSI_TCP_IP_BYPASS RSI_DISABLE //! TCP IP BYPASS feature check -#define RSI_TCP_IP_FEATURE_BIT_MAP \ - (TCP_IP_FEAT_DHCPV4_CLIENT) //! TCP/IP feature select bitmap for selecting TCP/IP features -#define RSI_EXT_TCPIP_FEATURE_BITMAP 0 - -#define RSI_CUSTOM_FEATURE_BIT_MAP FEAT_CUSTOM_FEAT_EXTENTION_VALID //! To set custom feature select bit map - -#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP (EXT_FEAT_LOW_POWER_MODE | EXT_FEAT_XTAL_CLK_ENABLE | EXT_FEAT_384K_MODE) - -#define RSI_BT_FEATURE_BITMAP (BT_RF_TYPE | ENABLE_BLE_PROTOCOL) -*/ -/*=======================================================================*/ -//! Power save command parameters -/*=======================================================================*/ -//! set handshake type of power mode -#define RSI_HAND_SHAKE_TYPE GPIO_BASED - -#define BLE_ATT_REC_SIZE 500 -#define NO_OF_VAL_ATT 5 //! Attribute value count - -/***********************************************************************************************************************************************/ -//! user defined structure -/***********************************************************************************************************************************************/ -typedef struct rsi_ble_att_list_s -{ - uuid_t char_uuid; - uint16_t handle; - uint16_t value_len; - uint16_t max_value_len; - uint8_t char_val_prop; - void * value; -} rsi_ble_att_list_t; -typedef struct rsi_ble_s -{ - uint8_t DATA[BLE_ATT_REC_SIZE]; - uint16_t DATA_ix; - uint16_t att_rec_list_count; - rsi_ble_att_list_t att_rec_list[NO_OF_VAL_ATT]; -} rsi_ble_t; - -#endif diff --git a/src/platform/silabs/efr32/rs911x/wfx_sl_ble_init.c b/src/platform/silabs/efr32/rs911x/wfx_sl_ble_init.c deleted file mode 100644 index d93e173cef9d36..00000000000000 --- a/src/platform/silabs/efr32/rs911x/wfx_sl_ble_init.c +++ /dev/null @@ -1,422 +0,0 @@ -/******************************************************************************* - * @file wfx_sl_ble_init.c - * @brief - ******************************************************************************* - * # License - * Copyright 2021 Silicon Laboratories Inc. www.silabs.com - ******************************************************************************* - * - * The licensor of this software is Silicon Laboratories Inc. Your use of this - * software is governed by the terms of Silicon Labs Master Software License - * Agreement (MSLA) available at - * www.silabs.com/about-us/legal/master-software-license-agreement. This - * software is distributed to you in Source Code format and is governed by the - * sections of the MSLA applicable to Source Code. - * - ******************************************************************************/ -/************************************************************************* - * - */ - -/*================================================================================ -* @brief : This file contains example application for Wlan Station BLE -* Provisioning -* @section Description : -* This application explains how to get the WLAN connection functionality using -* BLE provisioning. -* Silicon Labs Module starts advertising and with BLE Provisioning the Access Point -* details are fetched. -* Silicon Labs device is configured as a WiFi station and connects to an Access Point. -=================================================================================*/ - -#include "wfx_sl_ble_init.h" -#include "rsi_ble_config.h" - -// application defines -rsi_ble_event_conn_status_t conn_event_to_app; -rsi_ble_t att_list; -sl_wfx_msg_t event_msg; -extern rsi_semaphore_handle_t sl_ble_event_sem; - -// Memory to initialize driver -uint8_t bt_global_buf[BT_GLOBAL_BUFF_LEN]; -const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF }; - -/*==============================================*/ -/** - * @fn rsi_ble_app_init_events - * @brief initializes the event parameter. - * @param[in] none. - * @return none. - * @section description - * This function is used during BLE initialization. - */ -void rsi_ble_app_init_events() -{ - SILABS_LOG("%s: starting", __func__); - event_msg.ble_app_event_map = 0; - event_msg.ble_app_event_mask = 0xFFFFFFFF; - event_msg.ble_app_event_mask = event_msg.ble_app_event_mask; // To suppress warning while compiling - return; -} - -/*==============================================*/ -/** - * @fn rsi_ble_app_clear_event - * @brief clears the specific event. - * @param[in] event_num, specific event number. - * @return none. - * @section description - * This function is used to clear the specific event. - */ -void rsi_ble_app_clear_event(uint32_t event_num) -{ - SILABS_LOG("%s: starting", __func__); - event_msg.event_num = event_num; - event_msg.ble_app_event_map &= ~BIT(event_num); - return; -} - -/*==============================================*/ -/** - * @fn rsi_ble_on_mtu_event - * @brief its invoked when mtu exhange event is received. - * @param[in] rsi_ble_mtu, mtu event paramaters. - * @return none. - * @section description - * This callback function is invoked when mtu exhange event is received - */ -void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu) -{ - SILABS_LOG("%s: starting", __func__); - memcpy(&event_msg.rsi_ble_mtu, rsi_ble_mtu, sizeof(rsi_ble_event_mtu_t)); - rsi_ble_app_set_event(RSI_BLE_MTU_EVENT); -} - -/*==============================================*/ -/** - * @fn rsi_ble_on_gatt_write_event - * @brief its invoked when write/notify/indication events are received. - * @param[in] event_id, it indicates write/notification event id. - * @param[in] rsi_ble_write, write event parameters. - * @return none. - * @section description - * This callback function is invoked when write/notify/indication events are received - */ -void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write) -{ - SILABS_LOG("%s: starting", __func__); - event_msg.event_id = event_id; - memcpy(&event_msg.rsi_ble_write, rsi_ble_write, sizeof(rsi_ble_event_write_t)); - rsi_ble_app_set_event(RSI_BLE_GATT_WRITE_EVENT); -} - -/*==============================================*/ -/** - * @fn rsi_ble_on_enhance_conn_status_event - * @brief invoked when enhanced connection complete event is received - * @param[out] resp_conn, connected remote device information - * @return none. - * @section description - * This callback function indicates the status of the connection - */ -void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn) -{ - SILABS_LOG("%s: starting", __func__); - event_msg.connectionHandle = 1; - event_msg.bondingHandle = 255; - memcpy(event_msg.resp_enh_conn.dev_addr, resp_enh_conn->dev_addr, RSI_DEV_ADDR_LEN); - rsi_ble_app_set_event(RSI_BLE_CONN_EVENT); -} - -/*==============================================*/ -/** - * @fn rsi_ble_on_disconnect_event - * @brief invoked when disconnection event is received - * @param[in] resp_disconnect, disconnected remote device information - * @param[in] reason, reason for disconnection. - * @return none. - * @section description - * This callback function indicates disconnected device information and status - */ -void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason) -{ - SILABS_LOG("%s: starting", __func__); - event_msg.reason = reason; - rsi_ble_app_set_event(RSI_BLE_DISCONN_EVENT); -} - -/*==============================================*/ -/** - * @fn rsi_ble_on_event_indication_confirmation - * @brief this function will invoke when received indication confirmation event - * @param[out] resp_id, response id - * @param[out] status, status of the response - * @return none - * @section description - */ -void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp) -{ - SILABS_LOG("%s: starting", __func__); - event_msg.resp_status = resp_status; - memcpy(&event_msg.rsi_ble_event_set_att_rsp, rsi_ble_event_set_att_rsp, sizeof(rsi_ble_set_att_resp_t)); - rsi_ble_app_set_event(RSI_BLE_GATT_INDICATION_CONFIRMATION); -} - -/*==============================================*/ -/** - * @fn rsi_ble_app_get_event - * @brief returns the first set event based on priority - * @param[in] none. - * @return int32_t - * > 0 = event number - * -1 = not received any event - * @section description - * This function returns the highest priority event among all the set events - */ -int32_t rsi_ble_app_get_event(void) -{ - uint32_t ix; - - for (ix = 0; ix < 32; ix++) - { - if (event_msg.ble_app_event_map & (1 << ix)) - { - return ix; - } - } - - return (-1); -} - -/*==============================================*/ -/** - * @fn rsi_ble_app_set_event - * @brief set the specific event. - * @param[in] event_num, specific event number. - * @return none. - * @section description - * This function is used to set/raise the specific event. - */ -void rsi_ble_app_set_event(uint32_t event_num) -{ - SILABS_LOG("%s: starting", __func__); - event_msg.ble_app_event_map |= BIT(event_num); - rsi_semaphore_post(&sl_ble_event_sem); - return; -} - -/*==============================================*/ -/** - * @fn rsi_gatt_add_attribute_to_list - * @brief This function is used to store characteristic service attribute. - * @param[in] p_val, pointer to homekit structure - * @param[in] handle, characteristic service attribute handle. - * @param[in] data_len, characteristic value length - * @param[in] data, characteristic value pointer - * @param[in] uuid, characteristic value uuid - * @return none. - * @section description - * This function is used to store all attribute records - */ -void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, - uint8_t char_prop) -{ - if ((p_val->DATA_ix + data_len) >= BLE_ATT_REC_SIZE) - { //! Check for max data length for the characteristic value - LOG_PRINT("\r\n no data memory for att rec values \r\n"); - return; - } - - p_val->att_rec_list[p_val->att_rec_list_count].char_uuid = uuid; - p_val->att_rec_list[p_val->att_rec_list_count].handle = handle; - p_val->att_rec_list[p_val->att_rec_list_count].value_len = data_len; - p_val->att_rec_list[p_val->att_rec_list_count].max_value_len = data_len; - p_val->att_rec_list[p_val->att_rec_list_count].char_val_prop = char_prop; - memcpy(p_val->DATA + p_val->DATA_ix, data, data_len); - p_val->att_rec_list[p_val->att_rec_list_count].value = p_val->DATA + p_val->DATA_ix; - p_val->att_rec_list_count++; - p_val->DATA_ix += p_val->att_rec_list[p_val->att_rec_list_count].max_value_len; - - return; -} - -/*==============================================*/ -/** - * @fn rsi_ble_add_char_serv_att - * @brief this function is used to add characteristic service attribute.. - * @param[in] serv_handler, service handler. - * @param[in] handle, characteristic service attribute handle. - * @param[in] val_prop, characteristic value property. - * @param[in] att_val_handle, characteristic value handle - * @param[in] att_val_uuid, characteristic value uuid - * @return none. - * @section description - * This function is used at application to add characteristic attribute - */ -void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, uuid_t att_val_uuid) -{ - rsi_ble_req_add_att_t new_att = { 0 }; - - //! preparing the attribute service structure - new_att.serv_handler = serv_handler; - new_att.handle = handle; - new_att.att_uuid.size = 2; - new_att.att_uuid.val.val16 = RSI_BLE_CHAR_SERV_UUID; - new_att.property = RSI_BLE_ATT_PROPERTY_READ; - - //! preparing the characteristic attribute value - new_att.data_len = att_val_uuid.size + 4; - new_att.data[0] = val_prop; - rsi_uint16_to_2bytes(&new_att.data[2], att_val_handle); - if (new_att.data_len == 6) - { - rsi_uint16_to_2bytes(&new_att.data[4], att_val_uuid.val.val16); - } - else if (new_att.data_len == 8) - { - rsi_uint32_to_4bytes(&new_att.data[4], att_val_uuid.val.val32); - } - else if (new_att.data_len == 20) - { - memcpy(&new_att.data[4], &att_val_uuid.val.val128, att_val_uuid.size); - } - //! Add attribute to the service - rsi_ble_add_attribute(&new_att); - - return; -} - -/*==============================================*/ -/** - * @fn rsi_ble_add_char_val_att - * @brief this function is used to add characteristic value attribute. - * @param[in] serv_handler, new service handler. - * @param[in] handle, characteristic value attribute handle. - * @param[in] att_type_uuid, attribute uuid value. - * @param[in] val_prop, characteristic value property. - * @param[in] data, characteristic value data pointer. - * @param[in] data_len, characteristic value length. - * @return none. - * @section description - * This function is used at application to create new service. - */ - -void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data, - uint8_t data_len, uint8_t auth_read) -{ - rsi_ble_req_add_att_t new_att = { 0 }; - - //! preparing the attributes - new_att.serv_handler = serv_handler; - new_att.handle = handle; - new_att.config_bitmap = auth_read; - memcpy(&new_att.att_uuid, &att_type_uuid, sizeof(uuid_t)); - new_att.property = val_prop; - - if (data != NULL) - memcpy(new_att.data, data, RSI_MIN(sizeof(new_att.data), data_len)); - - //! preparing the attribute value - new_att.data_len = data_len; - - //! add attribute to the service - rsi_ble_add_attribute(&new_att); - - if ((auth_read == ATT_REC_MAINTAIN_IN_HOST) || (data_len > 20)) - { - if (data != NULL) - { - rsi_gatt_add_attribute_to_list(&att_list, handle, data_len, data, att_type_uuid, val_prop); - } - } - - //! check the attribute property with notification/Indication - if ((val_prop & RSI_BLE_ATT_PROPERTY_NOTIFY) || (val_prop & RSI_BLE_ATT_PROPERTY_INDICATE)) - { - //! if notification/indication property supports then we need to add client characteristic service. - - //! preparing the client characteristic attribute & values - memset(&new_att, 0, sizeof(rsi_ble_req_add_att_t)); - new_att.serv_handler = serv_handler; - new_att.handle = handle + 1; - new_att.att_uuid.size = 2; - new_att.att_uuid.val.val16 = RSI_BLE_CLIENT_CHAR_UUID; - new_att.property = RSI_BLE_ATT_PROPERTY_READ | RSI_BLE_ATT_PROPERTY_WRITE; - new_att.data_len = 2; - - //! add attribute to the service - rsi_ble_add_attribute(&new_att); - } - - return; -} - -/*==============================================*/ -/** - * @fn rsi_ble_add_matter_service - * @brief this function is used to add service for matter - * @return status (uint32_t) 0 for success. - * @section description - * This function is used at application to create new service. - */ - -uint32_t rsi_ble_add_matter_service(void) -{ - uuid_t custom_service = { RSI_BLE_MATTER_CUSTOM_SERVICE_UUID }; - custom_service.size = RSI_BLE_MATTER_CUSTOM_SERVICE_SIZE; - custom_service.val.val16 = RSI_BLE_MATTER_CUSTOM_SERVICE_VALUE_16; - uint8_t data[230] = { RSI_BLE_MATTER_CUSTOM_SERVICE_DATA }; - - static const uuid_t custom_characteristic_RX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE, - .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED }, - .val.val128.data1 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1, - .val.val128.data2 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2, - .val.val128.data3 = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3, - .val.val128.data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } }; - - rsi_ble_resp_add_serv_t new_serv_resp = { 0 }; - rsi_ble_add_service(custom_service, &new_serv_resp); - - // Adding custom characteristic declaration to the custom service - rsi_ble_add_char_serv_att( - new_serv_resp.serv_handler, new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_ATTRIBUTE_HANDLE_LOCATION, - RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response - new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_VALUE_HANDLE_LOCATION, custom_characteristic_RX); - - // Adding characteristic value attribute to the service - rsi_ble_add_char_val_att(new_serv_resp.serv_handler, - new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_VALUE_HANDLE_LOCATION, custom_characteristic_RX, - RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response - data, sizeof(data), ATT_REC_IN_HOST); - - static const uuid_t custom_characteristic_TX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE, - .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED }, - .val.val128.data1 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1, - .val.val128.data2 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2, - .val.val128.data3 = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3, - .val.val128.data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } }; - - // Adding custom characteristic declaration to the custom service - rsi_ble_add_char_serv_att( - new_serv_resp.serv_handler, new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_ATTRIBUTE_HANDLE_LOCATION, - RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE | RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ | - RSI_BLE_ATT_PROPERTY_NOTIFY | RSI_BLE_ATT_PROPERTY_INDICATE, // Set read, write, write without response - new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION, custom_characteristic_TX); - - // Adding characteristic value attribute to the service - event_msg.rsi_ble_measurement_hndl = new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION; - - // Adding characteristic value attribute to the service - event_msg.rsi_ble_gatt_server_client_config_hndl = - new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION; - - rsi_ble_add_char_val_att(new_serv_resp.serv_handler, event_msg.rsi_ble_measurement_hndl, custom_characteristic_TX, - RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE | RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ | - RSI_BLE_ATT_PROPERTY_NOTIFY | - RSI_BLE_ATT_PROPERTY_INDICATE, // Set read, write, write without response - data, sizeof(data), ATT_REC_MAINTAIN_IN_HOST); - - memset(&data, 0, sizeof(data)); - return 0; -} diff --git a/src/platform/silabs/efr32/rs911x/wfx_sl_ble_init.h b/src/platform/silabs/efr32/rs911x/wfx_sl_ble_init.h deleted file mode 100644 index e52e1553de540d..00000000000000 --- a/src/platform/silabs/efr32/rs911x/wfx_sl_ble_init.h +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * @file wfx_sl_ble_init.h - * @brief - ******************************************************************************* - * # License - * Copyright 2021 Silicon Laboratories Inc. www.silabs.com - ******************************************************************************* - * - * The licensor of this software is Silicon Laboratories Inc. Your use of this - * software is governed by the terms of Silicon Labs Master Software License - * Agreement (MSLA) available at - * www.silabs.com/about-us/legal/master-software-license-agreement. This - * software is distributed to you in Source Code format and is governed by the - * sections of the MSLA applicable to Source Code. - * - ******************************************************************************/ -/************************************************************************* - * - */ - -/** - * Include files - * */ - -#ifndef WFX_SL_BLE_INIT -#define WFX_SL_BLE_INIT -#define RSI_BLE_ENABLE 1 - -// BLE include file to refer BLE APIs -#include "FreeRTOS.h" -#include "event_groups.h" -#include "rsi_ble_config.h" -#include "task.h" -#include "timers.h" -#include "wfx_host_events.h" -#include "wfx_rsi.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef RSI_M4_INTERFACE -#include "rsi_board.h" -#endif - -typedef struct sl_wfx_msg_s -{ - uint8_t connectionHandle; - uint8_t bondingHandle; - uint32_t event_num; - uint16_t reason; - uint16_t event_id; - uint16_t resp_status; - rsi_ble_event_mtu_t rsi_ble_mtu; - rsi_ble_event_write_t rsi_ble_write; - rsi_ble_event_enhance_conn_status_t resp_enh_conn; - rsi_ble_event_disconnect_t * resp_disconnect; - rsi_ble_set_att_resp_t rsi_ble_event_set_att_rsp; - uint32_t ble_app_event_map; - uint32_t ble_app_event_mask; - uint16_t rsi_ble_measurement_hndl; - uint16_t rsi_ble_gatt_server_client_config_hndl; - uint16_t subscribed; - -} sl_wfx_msg_t; - -#define ATT_REC_IN_HOST 0 - -#define RSI_BT_CTRL_REMOTE_USER_TERMINATED 0x4E13 -#define RSI_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES 0x4E14 -#define RSI_BT_CTRL_REMOTE_POWERING_OFF 0x4E15 -#define RSI_BT_CTRL_TERMINATED_MIC_FAILURE 0x4E3D -#define RSI_BT_FAILED_TO_ESTABLISH_CONN 0x4E3E -#define RSI_BT_INVALID_RANGE 0x4E60 - -#define RSI_BLE_MATTER_CUSTOM_SERVICE_UUID 0 -#define RSI_BLE_MATTER_CUSTOM_SERVICE_SIZE 2 -#define RSI_BLE_MATTER_CUSTOM_SERVICE_VALUE_16 0xFFF6 -#define RSI_BLE_MATTER_CUSTOM_SERVICE_DATA 0x00 - -#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE 16 -#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED 0x00, 0x00, 0x00 -#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1 0x18EE2EF5 -#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2 0x263D -#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3 0x4559 -#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 0x9F, 0x95, 0x9C, 0x4F, 0x11, 0x9D, 0x9F, 0x42 -#define RSI_BLE_CHARACTERISTIC_RX_ATTRIBUTE_HANDLE_LOCATION 1 -#define RSI_BLE_CHARACTERISTIC_RX_VALUE_HANDLE_LOCATION 2 - -#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE 16 -#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED 0x00, 0x00, 0x00 -#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1 0x18EE2EF5 -#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2 0x263D -#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3 0x4559 -#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 0x9F, 0x95, 0x9C, 0x4F, 0x12, 0x9D, 0x9F, 0x42 -#define RSI_BLE_CHARACTERISTIC_TX_ATTRIBUTE_HANDLE_LOCATION 3 -#define RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION 4 -#define RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION 5 - -// ALL Ble functions -void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn); -void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason); -void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn); -void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write); -void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu); -void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp); -void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid, - uint8_t char_prop); -void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle, - uuid_t att_val_uuid); -void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop, uint8_t * data, - uint8_t data_len, uint8_t auth_read); -uint32_t rsi_ble_add_matter_service(void); -void rsi_ble_app_set_event(uint32_t event_num); -int32_t rsi_ble_app_get_event(void); -void rsi_ble_app_clear_event(uint32_t event_num); -void rsi_ble_app_init_events(); -void rsi_ble_event_handling_task(void); - -#endif \ No newline at end of file diff --git a/src/platform/silabs/efr32/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp similarity index 97% rename from src/platform/silabs/efr32/rs911x/BLEManagerImpl.cpp rename to src/platform/silabs/rs911x/BLEManagerImpl.cpp index 4a910e0a29aae5..ecedc1cd9dfb24 100644 --- a/src/platform/silabs/efr32/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -28,7 +28,9 @@ #include +#ifndef SIWX_917 #include "rail.h" +#endif #ifdef __cplusplus extern "C" { @@ -160,10 +162,6 @@ void sl_ble_event_handling_task(void) rsi_ble_app_clear_event(RSI_BLE_GATT_INDICATION_CONFIRMATION); } break; - - case RSI_BLE_RESP_ATT_VALUE: { - SILABS_LOG("%s RESP_ATT confirmation", __func__); - } default: break; } @@ -265,6 +263,9 @@ CHIP_ERROR BLEManagerImpl::_Init() mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART); mFlags.Set(Flags::kFastAdvertisingEnabled, true); +#ifdef SIWX_917 + PlatformMgr().ScheduleWork(DriveBLEState, 0); +#endif exit: ChipLogProgress(DeviceLayer, "%s END ", __func__); @@ -294,6 +295,9 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) if (mFlags.Has(Flags::kAdvertisingEnabled) != val) { mFlags.Set(Flags::kAdvertisingEnabled, val); +#ifdef SIWX_917 + PlatformMgr().ScheduleWork(DriveBLEState, 0); +#endif } exit: @@ -314,7 +318,9 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode) return CHIP_ERROR_INVALID_ARGUMENT; } mFlags.Set(Flags::kRestartAdvertising); - +#ifdef SIWX_917 + PlatformMgr().ScheduleWork(DriveBLEState, 0); +#endif return CHIP_NO_ERROR; } @@ -352,6 +358,9 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName) { mDeviceName[0] = 0; } +#ifdef SIWX_917 + PlatformMgr().ScheduleWork(DriveBLEState, 0); +#endif ChipLogProgress(DeviceLayer, "_SetDeviceName Ended"); return CHIP_NO_ERROR; } @@ -497,10 +506,12 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr) void BLEManagerImpl::DriveBLEState(void) { - ChipLogProgress(DeviceLayer, "DriveBLEState starting"); CHIP_ERROR err = CHIP_NO_ERROR; + // Check if BLE stack is initialized ( TODO ) + // VerifyOrExit(mFlags.Has(Flags::kEFRBLEStackInitialized),); + ChipLogProgress(DeviceLayer, "Start advertising if needed..."); // Start advertising if needed... if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && mFlags.Has(Flags::kAdvertisingEnabled) && @@ -661,6 +672,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) return CHIP_NO_ERROR; // err; } +// TODO:: Implementation need to be done. CHIP_ERROR BLEManagerImpl::StopAdvertising(void) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -707,14 +719,21 @@ void BLEManagerImpl::UpdateMtu(rsi_ble_event_mtu_t evt) void BLEManagerImpl::HandleBootEvent(void) { mFlags.Set(Flags::kEFRBLEStackInitialized); +#ifdef SIWX_917 + PlatformMgr().ScheduleWork(DriveBLEState, 0); +#endif } void BLEManagerImpl::HandleConnectEvent(void) { ChipLogProgress(DeviceLayer, "Connect Event for handle : %d", event_msg.connectionHandle); AddConnection(event_msg.connectionHandle, event_msg.bondingHandle); +#ifdef SIWX_917 + PlatformMgr().ScheduleWork(DriveBLEState, 0); +#endif } +// TODO:: Implementation need to be done. void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason) { uint8_t connHandle = 1; @@ -770,6 +789,7 @@ void BLEManagerImpl::HandleWriteEvent(rsi_ble_event_write_t evt) } } +// TODO:: Need to implement this void BLEManagerImpl::HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -840,6 +860,7 @@ void BLEManagerImpl::HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId) PlatformMgr().PostEventOrDie(&event); } +// TODO:: Need to Implement void BLEManagerImpl::HandleSoftTimerEvent(void) { // TODO:: Need to Implement @@ -936,8 +957,9 @@ CHIP_ERROR BLEManagerImpl::EncodeAdditionalDataTlv() return err; } -// TODO:: Need the +// TODO:: Need to do the correct implementation void BLEManagerImpl::HandleC3ReadRequest(void) {} + #endif // CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING uint8_t BLEManagerImpl::GetTimerHandle(uint8_t connectionHandle, bool allocate) diff --git a/src/platform/silabs/SiWx917/bluetooth/rsi_ble_config.h b/src/platform/silabs/rs911x/rsi_ble_config.h similarity index 96% rename from src/platform/silabs/SiWx917/bluetooth/rsi_ble_config.h rename to src/platform/silabs/rs911x/rsi_ble_config.h index 7b257895fd1d84..550e29fda03ed2 100644 --- a/src/platform/silabs/SiWx917/bluetooth/rsi_ble_config.h +++ b/src/platform/silabs/rs911x/rsi_ble_config.h @@ -224,6 +224,8 @@ /*=======================================================================*/ //! Power save command parameters /*=======================================================================*/ +//! set handshake type of power mode +#define RSI_HAND_SHAKE_TYPE GPIO_BASED #define BLE_ATT_REC_SIZE (500) #define NO_OF_VAL_ATT (5) //! Attribute value count diff --git a/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.c b/src/platform/silabs/rs911x/wfx_sl_ble_init.c similarity index 95% rename from src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.c rename to src/platform/silabs/rs911x/wfx_sl_ble_init.c index 579ed35a48e6f2..4429dc9277c3c7 100644 --- a/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.c +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.c @@ -1,4 +1,10 @@ -/* +/******************************************************************************* + * @file wfx_sl_ble_init.c + * @brief + ******************************************************************************* + * # License + * Copyright 2021 Silicon Laboratories Inc. www.silabs.com + ******************************************************************************* * * Copyright (c) 2022 Project CHIP Authors * diff --git a/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.h b/src/platform/silabs/rs911x/wfx_sl_ble_init.h similarity index 90% rename from src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.h rename to src/platform/silabs/rs911x/wfx_sl_ble_init.h index bdc93f3a3ccbf9..435cfe00225699 100644 --- a/src/platform/silabs/SiWx917/bluetooth/wfx_sl_ble_init.h +++ b/src/platform/silabs/rs911x/wfx_sl_ble_init.h @@ -1,4 +1,10 @@ -/* +/******************************************************************************* + * @file wfx_sl_ble_init.h + * @brief + ******************************************************************************* + * # License + * Copyright 2021 Silicon Laboratories Inc. www.silabs.com + ******************************************************************************* * * Copyright (c) 2022 Project CHIP Authors * @@ -15,6 +21,10 @@ * limitations under the License. */ +/** + * Include files + * */ + #ifndef WFX_SL_BLE_INIT #define WFX_SL_BLE_INIT #ifndef RSI_BLE_ENABLE @@ -122,4 +132,4 @@ void rsi_ble_app_clear_event(uint32_t event_num); void rsi_ble_app_init_events(); void rsi_ble_event_handling_task(void); -#endif +#endif \ No newline at end of file diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 75d776b720b8fe..13fe8c987870b1 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -69,6 +69,7 @@ template("siwx917_sdk") { "${wisemcu_sdk_root}/third_party/freertos/include", "${wisemcu_sdk_root}/third_party/freertos/portable/GCC/ARM_CM4F", "${examples_plat_dir}/device/inc", + "${chip_root}/src/platform/silabs/rs911x", ] # Note that we're setting the mbedTLS and PSA configuration files through a diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 9c3f6bf8ed9026..507fde96fee71a 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -193,6 +193,7 @@ template("efr32_sdk") { if (chip_enable_ble_rs911x) { _include_dirs += [ "${wifi_sapi_root}/sapi/include" ] + _include_dirs += [ "${chip_root}/src/platform/silabs/rs911x" ] } # Note that we're setting the mbedTLS and PSA configuration files through a