Skip to content

Commit d5e92e8

Browse files
Stop using weak functions for Aliro command callbacks. (#33931)
We have a delegate; we should just make use of the delegate. This is not a breaking change because nothing implements Aliro bits yet. Also: * Fixes some incorrect early returns that did not respond to commands. * Fixes some validity checks that were not quite correct per spec. * Fixes some logging levels for errors. * Adds missing "mark these attributes dirty" bits. * Marks various functions that don't touch our members as static.
1 parent a12a0c0 commit d5e92e8

File tree

4 files changed

+108
-75
lines changed

4 files changed

+108
-75
lines changed

src/app/clusters/door-lock-server/door-lock-delegate.h

+18
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ class Delegate
125125
* @return The max number of Aliro endpoint keys supported.
126126
*/
127127
virtual uint16_t GetNumberOfAliroEndpointKeysSupported() = 0;
128+
129+
/**
130+
* Set the Aliro reader configuration for the lock. The various arguments
131+
* have already been checked for constraints and consistency with the
132+
* FeatureMap.
133+
*
134+
* @param[in] signingKey Signing key component of the Reader's key pair.
135+
* @param[in] verificationKey Verification key component of the Reader's key pair.
136+
* @param[in] groupIdentifier Reader group identifier for the lock.
137+
* @param[in] groupResolvingKey Group resolving key for the lock if Aliro BLE UWB feature is supported
138+
*/
139+
virtual CHIP_ERROR SetAliroReaderConfig(const ByteSpan & signingKey, const ByteSpan & verificationKey,
140+
const ByteSpan & groupIdentifier, const Optional<ByteSpan> & groupResolvingKey) = 0;
141+
142+
/**
143+
* Clear the Aliro reader configuration for the lock.
144+
*/
145+
virtual CHIP_ERROR ClearAliroReaderConfig() = 0;
128146
};
129147

130148
} // namespace DoorLock

src/app/clusters/door-lock-server/door-lock-server-callback.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,3 @@ emberAfPluginDoorLockGetFaceCredentialLengthConstraints(chip::EndpointId endpoin
242242
{
243243
return false;
244244
}
245-
246-
bool __attribute__((weak))
247-
emberAfPluginDoorLockSetAliroReaderConfig(EndpointId endpointId, const ByteSpan & signingKey, const ByteSpan & verificationKey,
248-
const ByteSpan & groupIdentifier, const Optional<ByteSpan> groupResolvingKey)
249-
{
250-
return false;
251-
}
252-
253-
bool __attribute__((weak)) emberAfPluginDoorLockClearAliroReaderConfig(chip::EndpointId endpointId)
254-
{
255-
return false;
256-
}

src/app/clusters/door-lock-server/door-lock-server.cpp

+67-17
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class DoorLockClusterFabricDelegate : public chip::FabricTable::Delegate
9090
{
9191
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) override
9292
{
93-
for (auto endpointId : EnabledEndpointsWithServerCluster(chip::app::Clusters::DoorLock::Id))
93+
for (auto endpointId : EnabledEndpointsWithServerCluster(Clusters::DoorLock::Id))
9494
{
9595
if (!DoorLockServer::Instance().OnFabricRemoved(endpointId, fabricIndex))
9696
{
@@ -3641,7 +3641,7 @@ void DoorLockServer::SendEvent(chip::EndpointId endpointId, T & event)
36413641

36423642
template <typename T>
36433643
bool DoorLockServer::GetAttribute(chip::EndpointId endpointId, chip::AttributeId attributeId,
3644-
Status (*getFn)(chip::EndpointId endpointId, T * value), T & value) const
3644+
Status (*getFn)(chip::EndpointId endpointId, T * value), T & value)
36453645
{
36463646
Status status = getFn(endpointId, &value);
36473647
bool success = (Status::Success == status);
@@ -3927,12 +3927,26 @@ void DoorLockServer::setAliroReaderConfigCommandHandler(CommandHandler * command
39273927
}
39283928

39293929
Delegate * delegate = GetDelegate(endpointID);
3930-
VerifyOrReturn(delegate != nullptr, ChipLogError(Zcl, "Delegate is null"));
3930+
if (!delegate)
3931+
{
3932+
ChipLogError(Zcl, "Door Lock delegate is null");
3933+
commandObj->AddStatus(commandPath, Status::Failure);
3934+
return;
3935+
}
39313936

3932-
// If Aliro BLE UWB feature is supported and groupResolvingKey is not provided in the command, return INVALID_COMMAND.
3933-
if (SupportsAliroBLEUWB(endpointID) && !groupResolvingKey.HasValue())
3937+
// The GroupResolvingKey must be provided if and only if the Aliro BLE UWB
3938+
// feature is supported. Otherwise, return INVALID_COMMAND
3939+
const bool supportsAliroBLEUWB = SupportsAliroBLEUWB(endpointID);
3940+
if (supportsAliroBLEUWB != groupResolvingKey.HasValue())
39343941
{
3935-
ChipLogProgress(Zcl, "[SetAliroReaderConfig] Aliro BLE UWB supported but Group Resolving Key is not provided");
3942+
if (supportsAliroBLEUWB)
3943+
{
3944+
ChipLogError(Zcl, "[SetAliroReaderConfig] Aliro BLE UWB supported but Group Resolving Key is not provided");
3945+
}
3946+
else
3947+
{
3948+
ChipLogError(Zcl, "[SetAliroReaderConfig] Aliro BLE UWB not supported but Group Resolving Key is provided");
3949+
}
39363950
commandObj->AddStatus(commandPath, Status::InvalidCommand);
39373951
return;
39383952
}
@@ -3959,19 +3973,27 @@ void DoorLockServer::setAliroReaderConfigCommandHandler(CommandHandler * command
39593973
// INVALID_IN_STATE.
39603974
if (err != CHIP_NO_ERROR || !readerVerificationKey.empty())
39613975
{
3962-
ChipLogProgress(
3963-
Zcl, "[SetAliroReaderConfig] Aliro reader verification key was not read or is not null. Return INVALID_IN_STATE");
3976+
ChipLogError(Zcl, "[SetAliroReaderConfig] Aliro reader verification key was not read or is not null.");
39643977
commandObj->AddStatus(commandPath, Status::InvalidInState);
39653978
return;
39663979
}
39673980

3968-
Status status = Status::Success;
3969-
if (!emberAfPluginDoorLockSetAliroReaderConfig(endpointID, signingKey, verificationKey, groupIdentifier, groupResolvingKey))
3981+
err = delegate->SetAliroReaderConfig(signingKey, verificationKey, groupIdentifier, groupResolvingKey);
3982+
if (err != CHIP_NO_ERROR)
39703983
{
39713984
ChipLogProgress(Zcl, "[SetAliroReaderConfig] Unable to set aliro reader config [endpointId=%d]", endpointID);
3972-
status = Status::Failure;
39733985
}
3974-
sendClusterResponse(commandObj, commandPath, ClusterStatusCode(status));
3986+
else
3987+
{
3988+
// Various attributes changed; mark them dirty.
3989+
MatterReportingAttributeChangeCallback(endpointID, Clusters::DoorLock::Id, AliroReaderVerificationKey::Id);
3990+
MatterReportingAttributeChangeCallback(endpointID, Clusters::DoorLock::Id, AliroReaderGroupIdentifier::Id);
3991+
if (supportsAliroBLEUWB)
3992+
{
3993+
MatterReportingAttributeChangeCallback(endpointID, Clusters::DoorLock::Id, AliroGroupResolvingKey::Id);
3994+
}
3995+
}
3996+
sendClusterResponse(commandObj, commandPath, ClusterStatusCode(StatusIB(err).mStatus));
39753997
}
39763998

39773999
void DoorLockServer::clearAliroReaderConfigCommandHandler(CommandHandler * commandObj, const ConcreteCommandPath & commandPath)
@@ -3987,13 +4009,41 @@ void DoorLockServer::clearAliroReaderConfigCommandHandler(CommandHandler * comma
39874009
return;
39884010
}
39894011

3990-
Status status = Status::Success;
3991-
if (!emberAfPluginDoorLockClearAliroReaderConfig(endpointID))
4012+
Delegate * delegate = GetDelegate(endpointID);
4013+
if (!delegate)
39924014
{
3993-
ChipLogProgress(Zcl, "[SetAliroReaderConfig] Unable to set aliro reader config [endpointId=%d]", endpointID);
3994-
status = Status::Failure;
4015+
ChipLogError(Zcl, "Door Lock delegate is null");
4016+
commandObj->AddStatus(commandPath, Status::Failure);
4017+
return;
4018+
}
4019+
4020+
uint8_t buffer[kAliroReaderVerificationKeySize];
4021+
MutableByteSpan readerVerificationKey(buffer);
4022+
CHIP_ERROR err = delegate->GetAliroReaderVerificationKey(readerVerificationKey);
4023+
if (err != CHIP_NO_ERROR && readerVerificationKey.empty())
4024+
{
4025+
// No reader config to start with. Just return without marking any
4026+
// attributes as dirty.
4027+
commandObj->AddStatus(commandPath, Status::Success);
4028+
return;
4029+
}
4030+
4031+
err = delegate->ClearAliroReaderConfig();
4032+
if (err != CHIP_NO_ERROR)
4033+
{
4034+
ChipLogError(Zcl, "[SetAliroReaderConfig] Unable to set aliro reader config [endpointId=%d]", endpointID);
4035+
}
4036+
else
4037+
{
4038+
// Various attributes changed; mark them dirty.
4039+
MatterReportingAttributeChangeCallback(endpointID, Clusters::DoorLock::Id, AliroReaderVerificationKey::Id);
4040+
MatterReportingAttributeChangeCallback(endpointID, Clusters::DoorLock::Id, AliroReaderGroupIdentifier::Id);
4041+
if (SupportsAliroBLEUWB(endpointID))
4042+
{
4043+
MatterReportingAttributeChangeCallback(endpointID, Clusters::DoorLock::Id, AliroGroupResolvingKey::Id);
4044+
}
39954045
}
3996-
sendClusterResponse(commandObj, commandPath, ClusterStatusCode(status));
4046+
sendClusterResponse(commandObj, commandPath, ClusterStatusCode(StatusIB(err).mStatus));
39974047
}
39984048

39994049
// =============================================================================

src/app/clusters/door-lock-server/door-lock-server.h

+23-46
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <app/AttributeAccessInterface.h>
3030
#include <app/CommandHandler.h>
3131
#include <app/ConcreteCommandPath.h>
32+
#include <app/reporting/reporting.h>
3233
#include <app/util/attribute-storage.h>
3334
#include <app/util/config.h>
3435
#include <platform/CHIPDeviceConfig.h>
@@ -174,57 +175,60 @@ class DoorLockServer : public chip::app::AttributeAccessInterface
174175

175176
bool SendLockAlarmEvent(chip::EndpointId endpointId, AlarmCodeEnum alarmCode);
176177

177-
chip::BitFlags<Feature> GetFeatures(chip::EndpointId endpointId);
178+
static chip::BitFlags<Feature> GetFeatures(chip::EndpointId endpointId);
178179

179-
inline bool SupportsPIN(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kPinCredential); }
180+
static inline bool SupportsPIN(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kPinCredential); }
180181

181-
inline bool SupportsRFID(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kRfidCredential); }
182+
static inline bool SupportsRFID(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kRfidCredential); }
182183

183-
inline bool SupportsFingers(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kFingerCredentials); }
184+
static inline bool SupportsFingers(chip::EndpointId endpointId)
185+
{
186+
return GetFeatures(endpointId).Has(Feature::kFingerCredentials);
187+
}
184188

185-
inline bool SupportsFace(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kFaceCredentials); }
189+
static inline bool SupportsFace(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kFaceCredentials); }
186190

187-
inline bool SupportsWeekDaySchedules(chip::EndpointId endpointId)
191+
static inline bool SupportsWeekDaySchedules(chip::EndpointId endpointId)
188192
{
189193
return GetFeatures(endpointId).Has(Feature::kWeekDayAccessSchedules);
190194
}
191195

192-
inline bool SupportsYearDaySchedules(chip::EndpointId endpointId)
196+
static inline bool SupportsYearDaySchedules(chip::EndpointId endpointId)
193197
{
194198
return GetFeatures(endpointId).Has(Feature::kYearDayAccessSchedules);
195199
}
196200

197-
inline bool SupportsHolidaySchedules(chip::EndpointId endpointId)
201+
static inline bool SupportsHolidaySchedules(chip::EndpointId endpointId)
198202
{
199203
return GetFeatures(endpointId).Has(Feature::kHolidaySchedules);
200204
}
201205

202-
inline bool SupportsAnyCredential(chip::EndpointId endpointId)
206+
static inline bool SupportsAnyCredential(chip::EndpointId endpointId)
203207
{
204208
return GetFeatures(endpointId)
205209
.HasAny(Feature::kPinCredential, Feature::kRfidCredential, Feature::kFingerCredentials, Feature::kFaceCredentials,
206210
Feature::kAliroProvisioning);
207211
}
208212

209-
inline bool SupportsCredentialsOTA(chip::EndpointId endpointId)
213+
static inline bool SupportsCredentialsOTA(chip::EndpointId endpointId)
210214
{
211215
return GetFeatures(endpointId).Has(Feature::kCredentialsOverTheAirAccess);
212216
}
213217

214-
inline bool SupportsUSR(chip::EndpointId endpointId)
218+
static inline bool SupportsUSR(chip::EndpointId endpointId)
215219
{
216220
// appclusters, 5.2.2: USR feature has conformance [PIN | RID | FGP | FACE]
217221
return GetFeatures(endpointId).Has(Feature::kUser) && SupportsAnyCredential(endpointId);
218222
}
219223

220-
inline bool SupportsUnbolt(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kUnbolt); }
224+
static bool SupportsUnbolt(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kUnbolt); }
221225

222226
/**
223227
* @brief Checks if Aliro Provisioning feature is supported on the given endpoint
224228
*
225229
* @param endpointId endpointId ID of the endpoint which contains the lock.
226230
*/
227-
inline bool SupportsAliroProvisioning(chip::EndpointId endpointId)
231+
static inline bool SupportsAliroProvisioning(chip::EndpointId endpointId)
228232
{
229233
return GetFeatures(endpointId).Has(Feature::kAliroProvisioning);
230234
}
@@ -234,7 +238,10 @@ class DoorLockServer : public chip::app::AttributeAccessInterface
234238
*
235239
* @param endpointId endpointId ID of the endpoint which contains the lock.
236240
*/
237-
inline bool SupportsAliroBLEUWB(chip::EndpointId endpointId) { return GetFeatures(endpointId).Has(Feature::kAliroBLEUWB); }
241+
static inline bool SupportsAliroBLEUWB(chip::EndpointId endpointId)
242+
{
243+
return GetFeatures(endpointId).Has(Feature::kAliroBLEUWB);
244+
}
238245

239246
/**
240247
* @brief Allows the application to register a custom callback which will be called after the default DoorLock
@@ -545,8 +552,8 @@ class DoorLockServer : public chip::app::AttributeAccessInterface
545552
* @return false if attribute reading failed (value is kept unchanged)
546553
*/
547554
template <typename T>
548-
bool GetAttribute(chip::EndpointId endpointId, chip::AttributeId attributeId,
549-
chip::Protocols::InteractionModel::Status (*getFn)(chip::EndpointId endpointId, T * value), T & value) const;
555+
static bool GetAttribute(chip::EndpointId endpointId, chip::AttributeId attributeId,
556+
chip::Protocols::InteractionModel::Status (*getFn)(chip::EndpointId endpointId, T * value), T & value);
550557

551558
/**
552559
* @brief Set generic attribute value
@@ -1273,33 +1280,3 @@ bool emberAfPluginDoorLockGetFingerVeinCredentialLengthConstraints(chip::Endpoin
12731280
* @return false on failure, true on success.
12741281
*/
12751282
bool emberAfPluginDoorLockGetFaceCredentialLengthConstraints(chip::EndpointId endpointId, uint8_t & minLen, uint8_t & maxLen);
1276-
1277-
/**
1278-
* @brief This callback is called when Door Lock cluster needs to communicate the Aliro reader configuration to the door lock.
1279-
*
1280-
* @note This function is used for communicating the Aliro signing key, verification key, group identifier and group resolving key
1281-
* to the lock.
1282-
*
1283-
* @param endpointId ID of the endpoint which contains the lock.
1284-
* @param[in] signingKey Signing key component of the Reader's key pair.
1285-
* @param[in] verificationKey Verification key component of the Reader's key pair.
1286-
* @param[in] groupIdentifier Reader group identifier for the lock.
1287-
* @param[in] groupResolvingKey Group resolving key for the lock if Aliro BLE UWB feature is supported
1288-
*
1289-
* @retval true, if the Aliro reader config was successfully communicated to the door lock.
1290-
* @retval false, if error occurred while communicating the Aliro reader config.
1291-
*/
1292-
bool emberAfPluginDoorLockSetAliroReaderConfig(chip::EndpointId endpointId, const chip::ByteSpan & signingKey,
1293-
const chip::ByteSpan & verificationKey, const chip::ByteSpan & groupIdentifier,
1294-
const Optional<chip::ByteSpan> & groupResolvingKey);
1295-
1296-
/**
1297-
* @brief This callback is called when Door Lock cluster needs to clear an existing Aliro reader configuration from the door lock.
1298-
*
1299-
*
1300-
* @param endpointId ID of the endpoint which contains the lock.
1301-
*
1302-
* @retval true, if the Aliro reader config was successfully cleared from the door lock.
1303-
* @retval false, if error occurred while clearing the Aliro reader config.
1304-
*/
1305-
bool emberAfPluginDoorLockClearAliroReaderConfig(chip::EndpointId endpointId);

0 commit comments

Comments
 (0)