Skip to content

Commit

Permalink
[Silabs] BLE bug fixes for Wi-Fi devices (#27842)
Browse files Browse the repository at this point in the history
* ble bug fixes with NCP and SOC

* Restyled by clang-format

* Added changes for BLEManager event

* Added changes according to comments

* Added TODO for RSI_ERROR define

* removed the semaphore changes

* applied retyled patch

---------

Co-authored-by: bhmanda-silabs <bhavani.manda@silabs.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people authored and pull[bot] committed Sep 13, 2023
1 parent 6d994eb commit 097bd09
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
48 changes: 40 additions & 8 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ extern "C" {
#include <setup_payload/AdditionalDataPayloadGenerator.h>
#endif

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;
Expand Down Expand Up @@ -589,8 +587,21 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
{
ChipLogError(DeviceLayer, "rsi_ble_set_advertise_data() success: %ld", result);
}

// err = MapBLEError(result);
index = 0;
responseData[index++] = 0x02; // length
responseData[index++] = CHIP_ADV_DATA_TYPE_FLAGS; // AD type : flags
responseData[index++] = CHIP_ADV_DATA_FLAGS;
responseData[index++] = CHIP_ADV_SHORT_UUID_LEN + 1; // AD length
responseData[index++] = CHIP_ADV_DATA_TYPE_UUID; // AD type : uuid
responseData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value
responseData[index++] = ShortUUID_CHIPoBLEService[1];

responseData[index++] = static_cast<uint8_t>(mDeviceNameLength + 1); // length
responseData[index++] = CHIP_ADV_DATA_TYPE_NAME; // AD type : name
memcpy(&responseData[index], mDeviceName, mDeviceNameLength); // AD value
index += mDeviceNameLength;

rsi_ble_set_scan_response_data(responseData, index);

ChipLogProgress(DeviceLayer, "ConfigureAdvertisingData End");
exit:
Expand Down Expand Up @@ -659,8 +670,16 @@ int32_t BLEManagerImpl::SendBLEAdvertisementCommand(void)
ble_adv.filter_type = RSI_BLE_ADV_FILTER_TYPE;
ble_adv.direct_addr_type = RSI_BLE_ADV_DIR_ADDR_TYPE;
rsi_ascii_dev_address_to_6bytes_rev(ble_adv.direct_addr, (int8_t *) RSI_BLE_ADV_DIR_ADDR);
ble_adv.adv_int_min = RSI_BLE_ADV_INT_MIN;
ble_adv.adv_int_max = RSI_BLE_ADV_INT_MAX;
if (mFlags.Has(Flags::kFastAdvertisingEnabled))
{
ble_adv.adv_int_min = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN;
ble_adv.adv_int_max = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MAX;
}
else
{
ble_adv.adv_int_min = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN;
ble_adv.adv_int_max = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX;
}
ble_adv.own_addr_type = LE_RANDOM_ADDRESS;
ble_adv.adv_channel_map = RSI_BLE_ADV_CHANNEL_MAP;
return rsi_ble_start_advertising_with_values(&ble_adv);
Expand Down Expand Up @@ -781,6 +800,10 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt)
CHIP_ERROR err = CHIP_NO_ERROR;
bool isIndicationEnabled = false;
ChipDeviceEvent event;
CHIPoBLEConState * bleConnState;

bleConnState = GetConnectionState(event_msg.connectionHandle);
VerifyOrExit(bleConnState != NULL, err = CHIP_ERROR_NO_MEMORY);

// Determine if the client is enabling or disabling notification/indication.
if (evt->att_value[0] != 0)
Expand All @@ -792,20 +815,29 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt)

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.
// If indications are not already enabled for the connection...
if (!bleConnState->subscribed)
{
bleConnState->subscribed = 1;
// 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; // TODO:: To be replaced by device mac address
err = PlatformMgr().PostEvent(&event);
}
}
else
{
bleConnState->subscribed = 0;
event.Type = DeviceEventType::kCHIPoBLEUnsubscribe;
event.CHIPoBLESubscribe.ConId = 1; // TODO:: To be replaced by device mac address
err = PlatformMgr().PostEvent(&event);
}
exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "HandleTXCharCCCDWrite() failed: %s", ErrorStr(err));
}
}

void BLEManagerImpl::HandleRXCharWrite(rsi_ble_event_write_t * evt)
Expand Down
6 changes: 6 additions & 0 deletions src/platform/silabs/rs911x/rsi_ble_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
* * Macros
* ******************************************************/
//! application event list
// TODO: remove this define after integration of the new wifi sdk
#ifndef RSI_FAILURE
// failure return value
#define RSI_FAILURE -1
#endif

#define RSI_BLE_CONN_EVENT (0x01)
#define RSI_BLE_DISCONN_EVENT (0x02)
#define RSI_BLE_GATT_WRITE_EVENT (0x03)
Expand Down

0 comments on commit 097bd09

Please sign in to comment.