Skip to content

Commit

Permalink
[Linux] Pass advertising name directly to BluezAdvertisement
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Feb 1, 2024
1 parent b1bf11e commit 08ac1ce
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 36 deletions.
2 changes: 0 additions & 2 deletions src/app/tests/suites/certification/Test_TC_DD_2_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ tests:
[1657221603.350739][368108:368108] CHIP:SVR: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J048N01KA0648G00
[1657221603.350773][368108:368108] CHIP:SVR: Manual pairing code: [749701123365521327694]
[1657221603.350846][368108:368108] CHIP:DMG: Endpoint 0, Cluster 0x0000_001D update version to 4dd11284
[1657221603.353048][368108:368113] CHIP:DL: TRACE: Bluez mainloop starting Thread
[1657221603.353167][368108:368111] CHIP:DL: TRACE: Bus acquired for name MATTER-3841
disabled: true

- label:
Expand Down
1 change: 0 additions & 1 deletion src/app/tests/suites/certification/Test_TC_DD_3_11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ tests:
[1667888323.967841][3151:3151] CHIP:SVR: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J042C00KA0648G00
[1667888323.967940][3151:3151] CHIP:SVR: Manual pairing code: [34970112332]
[1667888323.968031][3151:3151] CHIP:DMG: Endpoint 0, Cluster 0x0000_001D update version to ea7ea7b8
[1667888323.981832][3151:3153] CHIP:DL: TRACE: Bus acquired for name MATTER-3840
disabled: true

- label: "Step 1b: Scan the QR code from the previous step using the DUT."
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Linux/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void BLEManagerImpl::DriveBLEState()
// Initializes the Bluez BLE layer if needed.
if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && !mFlags.Has(Flags::kBluezBLELayerInitialized))
{
SuccessOrExit(err = mEndpoint.Init(mAdapterId, mIsCentral, nullptr, mDeviceName));
SuccessOrExit(err = mEndpoint.Init(mAdapterId, mIsCentral, nullptr));
mFlags.Set(Flags::kBluezBLELayerInitialized);
}

Expand All @@ -595,7 +595,7 @@ void BLEManagerImpl::DriveBLEState()
// Configure advertising data if it hasn't been done yet.
if (!mFlags.Has(Flags::kAdvertisingConfigured))
{
SuccessOrExit(err = mBLEAdvertisement.Init(mEndpoint, mBLEAdvType, mpBLEAdvUUID, mBLEAdvDurationMs));
SuccessOrExit(err = mBLEAdvertisement.Init(mEndpoint, mBLEAdvType, mpBLEAdvUUID, mBLEAdvDurationMs, mDeviceName));
mFlags.Set(Flags::kAdvertisingConfigured);
}

Expand Down
14 changes: 7 additions & 7 deletions src/platform/Linux/bluez/BluezAdvertisement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ BluezLEAdvertisement1 * BluezAdvertisement::CreateLEAdvertisement()
g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, &mDeviceIdInfo, sizeof(mDeviceIdInfo), sizeof(uint8_t)));
g_variant_builder_add(&serviceUUIDsBuilder, "s", mpAdvUUID);

localNamePtr = mpAdapterName;
localNamePtr = mpAdvName;
if (localNamePtr == nullptr)
{
g_snprintf(localName, sizeof(localName), "%s%04x", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, getpid() & 0xffff);
Expand Down Expand Up @@ -134,21 +134,21 @@ CHIP_ERROR BluezAdvertisement::InitImpl()
}

CHIP_ERROR BluezAdvertisement::Init(const BluezEndpoint & aEndpoint, ChipAdvType aAdvType, const char * aAdvUUID,
uint32_t aAdvDurationMs)
uint32_t aAdvDurationMs, const char * aAdvName)
{
GAutoPtr<char> rootPath;
CHIP_ERROR err;

VerifyOrExit(mpAdv == nullptr, err = CHIP_ERROR_INCORRECT_STATE;
ChipLogError(DeviceLayer, "FAIL: BLE advertisement already initialized in %s", __func__));

mpRoot = reinterpret_cast<GDBusObjectManagerServer *>(g_object_ref(aEndpoint.GetGattApplicationObjectManager()));
mpAdapter = reinterpret_cast<BluezAdapter1 *>(g_object_ref(aEndpoint.GetAdapter()));
mpAdapterName = g_strdup(aEndpoint.GetAdapterName());
mpRoot = reinterpret_cast<GDBusObjectManagerServer *>(g_object_ref(aEndpoint.GetGattApplicationObjectManager()));
mpAdapter = reinterpret_cast<BluezAdapter1 *>(g_object_ref(aEndpoint.GetAdapter()));

g_object_get(G_OBJECT(mpRoot), "object-path", &MakeUniquePointerReceiver(rootPath).Get(), nullptr);
mpAdvPath = g_strdup_printf("%s/advertising", rootPath.get());
mAdvType = aAdvType;
mpAdvName = g_strdup(aAdvName);
mpAdvUUID = g_strdup(aAdvUUID);
mAdvDurationMs = aAdvDurationMs;

Expand Down Expand Up @@ -209,8 +209,8 @@ void BluezAdvertisement::Shutdown()

g_free(mpAdvPath);
mpAdvPath = nullptr;
g_free(mpAdapterName);
mpAdapterName = nullptr;
g_free(mpAdvName);
mpAdvName = nullptr;
g_free(mpAdvUUID);
mpAdvUUID = nullptr;

Expand Down
9 changes: 5 additions & 4 deletions src/platform/Linux/bluez/BluezAdvertisement.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class BluezAdvertisement
BluezAdvertisement() = default;
~BluezAdvertisement() { Shutdown(); }

CHIP_ERROR Init(const BluezEndpoint & aEndpoint, ChipAdvType aAdvType, const char * aAdvUUID, uint32_t aAdvDurationMs);
CHIP_ERROR Init(const BluezEndpoint & aEndpoint, ChipAdvType aAdvType, const char * aAdvUUID, uint32_t aAdvDurationMs,
const char * aAdvName);
void Shutdown();

/// Start BLE advertising.
Expand Down Expand Up @@ -77,9 +78,9 @@ class BluezAdvertisement
bool mIsAdvertising = false;

Ble::ChipBLEDeviceIdentificationInfo mDeviceIdInfo;
char * mpAdvPath = nullptr;
char * mpAdapterName = nullptr;
char * mpAdvUUID = nullptr;
char * mpAdvPath = nullptr;
char * mpAdvName = nullptr;
char * mpAdvUUID = nullptr;
ChipAdvType mAdvType;
uint16_t mAdvDurationMs = 0;
};
Expand Down
16 changes: 2 additions & 14 deletions src/platform/Linux/bluez/BluezEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,6 @@ CHIP_ERROR BluezEndpoint::StartupEndpointBindings()
VerifyOrReturnError(conn != nullptr, CHIP_ERROR_INTERNAL,
ChipLogError(DeviceLayer, "FAIL: get bus sync in %s, error: %s", __func__, err->message));

if (mpAdapterName != nullptr)
mpOwningName = g_strdup_printf("%s", mpAdapterName);
else
mpOwningName = g_strdup_printf("C-%04x", getpid() & 0xffff);
ChipLogDetail(DeviceLayer, "TRACE: Bus acquired for name %s", mpOwningName);

SetupGattServer(conn.get());

mpObjMgr = g_dbus_object_manager_client_new_sync(
Expand Down Expand Up @@ -662,7 +656,7 @@ CHIP_ERROR BluezEndpoint::RegisterGattApplication()
return err;
}

CHIP_ERROR BluezEndpoint::Init(uint32_t aAdapterId, bool aIsCentral, const char * apBleAddr, const char * apBleName)
CHIP_ERROR BluezEndpoint::Init(uint32_t aAdapterId, bool aIsCentral, const char * apBleAddr)
{
CHIP_ERROR err;

Expand All @@ -672,11 +666,7 @@ CHIP_ERROR BluezEndpoint::Init(uint32_t aAdapterId, bool aIsCentral, const char
if (apBleAddr != nullptr)
mpAdapterAddr = g_strdup(apBleAddr);

if (!aIsCentral)
{
mpAdapterName = g_strdup(apBleName);
}
else
if (aIsCentral)
{
mpConnectCancellable = g_cancellable_new();
}
Expand Down Expand Up @@ -723,8 +713,6 @@ void BluezEndpoint::Shutdown()
},
this);

g_free(mpOwningName);
g_free(mpAdapterName);
g_free(mpAdapterAddr);
g_free(mpRootPath);
g_free(mpServicePath);
Expand Down
7 changes: 1 addition & 6 deletions src/platform/Linux/bluez/BluezEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ class BluezEndpoint
BluezEndpoint() = default;
~BluezEndpoint() = default;

CHIP_ERROR Init(uint32_t aAdapterId, bool aIsCentral, const char * apBleAddr, const char * apBleName);
CHIP_ERROR Init(uint32_t aAdapterId, bool aIsCentral, const char * apBleAddr);
void Shutdown();

BluezAdapter1 * GetAdapter() const { return mpAdapter; }
const char * GetAdapterName() const { return mpAdapterName; }

CHIP_ERROR RegisterGattApplication();
GDBusObjectManagerServer * GetGattApplicationObjectManager() const { return mpRoot; }
Expand Down Expand Up @@ -127,12 +126,8 @@ class BluezEndpoint
bool mIsCentral = false;
bool mIsInitialized = false;

// Bus owning name
char * mpOwningName = nullptr;

// Adapter properties
uint32_t mAdapterId = 0;
char * mpAdapterName = nullptr;
char * mpAdapterAddr = nullptr;

// Paths for objects published by this service
Expand Down

0 comments on commit 08ac1ce

Please sign in to comment.