|
17 | 17 | */
|
18 | 18 | #include "LockEndpoint.h"
|
19 | 19 | #include <app-common/zap-generated/attributes/Accessors.h>
|
| 20 | +#include <app-common/zap-generated/cluster-enums.h> |
20 | 21 | #include <cstring>
|
| 22 | +#include <lib/core/CHIPEncoding.h> |
21 | 23 | #include <platform/CHIPDeviceLayer.h>
|
22 | 24 | #include <platform/internal/CHIPDeviceLayerInternal.h>
|
23 | 25 |
|
| 26 | +using chip::ByteSpan; |
| 27 | +using chip::MutableByteSpan; |
| 28 | +using chip::Optional; |
24 | 29 | using chip::to_underlying;
|
25 | 30 | using chip::app::DataModel::MakeNullable;
|
26 | 31 |
|
@@ -204,7 +209,8 @@ bool LockEndpoint::GetCredential(uint16_t credentialIndex, CredentialTypeEnum cr
|
204 | 209 | if (credentialIndex >= mLockCredentials.at(to_underlying(credentialType)).size() ||
|
205 | 210 | (0 == credentialIndex && CredentialTypeEnum::kProgrammingPIN != credentialType))
|
206 | 211 | {
|
207 |
| - ChipLogError(Zcl, "Cannot get the credential - index out of range [endpoint=%d,index=%d]", mEndpointId, credentialIndex); |
| 212 | + ChipLogError(Zcl, "Cannot get the credential - index out of range [endpoint=%d,index=%d]: %d", mEndpointId, credentialIndex, |
| 213 | + static_cast<int>(mLockCredentials.at(to_underlying(credentialType)).size())); |
208 | 214 | return false;
|
209 | 215 | }
|
210 | 216 |
|
@@ -407,6 +413,149 @@ DlStatus LockEndpoint::SetSchedule(uint8_t holidayIndex, DlScheduleStatus status
|
407 | 413 | return DlStatus::kSuccess;
|
408 | 414 | }
|
409 | 415 |
|
| 416 | +CHIP_ERROR LockEndpoint::GetAliroReaderVerificationKey(MutableByteSpan & verificationKey) |
| 417 | +{ |
| 418 | + if (!mAliroStateInitialized) |
| 419 | + { |
| 420 | + verificationKey.reduce_size(0); |
| 421 | + return CHIP_NO_ERROR; |
| 422 | + } |
| 423 | + |
| 424 | + return chip::CopySpanToMutableSpan(ByteSpan(mAliroReaderVerificationKey), verificationKey); |
| 425 | +} |
| 426 | + |
| 427 | +CHIP_ERROR LockEndpoint::GetAliroReaderGroupIdentifier(MutableByteSpan & groupIdentifier) |
| 428 | +{ |
| 429 | + if (!mAliroStateInitialized) |
| 430 | + { |
| 431 | + groupIdentifier.reduce_size(0); |
| 432 | + return CHIP_NO_ERROR; |
| 433 | + } |
| 434 | + |
| 435 | + return CopySpanToMutableSpan(ByteSpan(mAliroReaderGroupIdentifier), groupIdentifier); |
| 436 | +} |
| 437 | + |
| 438 | +CHIP_ERROR LockEndpoint::GetAliroReaderGroupSubIdentifier(MutableByteSpan & groupSubIdentifier) |
| 439 | +{ |
| 440 | + return CopySpanToMutableSpan(ByteSpan(mAliroReaderGroupSubIdentifier), groupSubIdentifier); |
| 441 | +} |
| 442 | + |
| 443 | +namespace { |
| 444 | + |
| 445 | +CHIP_ERROR CopyProtocolVersionIntoSpan(uint16_t protocolVersionValue, MutableByteSpan & protocolVersion) |
| 446 | +{ |
| 447 | + using namespace chip::app::Clusters::DoorLock; |
| 448 | + |
| 449 | + static_assert(sizeof(protocolVersionValue) == kAliroProtocolVersionSize); |
| 450 | + |
| 451 | + if (protocolVersion.size() < kAliroProtocolVersionSize) |
| 452 | + { |
| 453 | + return CHIP_ERROR_INVALID_ARGUMENT; |
| 454 | + } |
| 455 | + |
| 456 | + // Per Aliro spec, protocol version encoding is big-endian |
| 457 | + chip::Encoding::BigEndian::Put16(protocolVersion.data(), protocolVersionValue); |
| 458 | + protocolVersion.reduce_size(kAliroProtocolVersionSize); |
| 459 | + return CHIP_NO_ERROR; |
| 460 | +} |
| 461 | + |
| 462 | +} // anonymous namespace |
| 463 | + |
| 464 | +CHIP_ERROR LockEndpoint::GetAliroExpeditedTransactionSupportedProtocolVersionAtIndex(size_t index, |
| 465 | + MutableByteSpan & protocolVersion) |
| 466 | +{ |
| 467 | + // Only claim support for the one known protocol version for now: 0x0100. |
| 468 | + constexpr uint16_t knownProtocolVersion = 0x0100; |
| 469 | + |
| 470 | + if (index > 0) |
| 471 | + { |
| 472 | + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; |
| 473 | + } |
| 474 | + |
| 475 | + return CopyProtocolVersionIntoSpan(knownProtocolVersion, protocolVersion); |
| 476 | +} |
| 477 | + |
| 478 | +CHIP_ERROR LockEndpoint::GetAliroGroupResolvingKey(MutableByteSpan & groupResolvingKey) |
| 479 | +{ |
| 480 | + if (!mAliroStateInitialized) |
| 481 | + { |
| 482 | + groupResolvingKey.reduce_size(0); |
| 483 | + return CHIP_NO_ERROR; |
| 484 | + } |
| 485 | + |
| 486 | + return CopySpanToMutableSpan(ByteSpan(mAliroGroupResolvingKey), groupResolvingKey); |
| 487 | +} |
| 488 | + |
| 489 | +CHIP_ERROR LockEndpoint::GetAliroSupportedBLEUWBProtocolVersionAtIndex(size_t index, MutableByteSpan & protocolVersion) |
| 490 | +{ |
| 491 | + // Only claim support for the one known protocol version for now: 0x0100. |
| 492 | + constexpr uint16_t knownProtocolVersion = 0x0100; |
| 493 | + |
| 494 | + if (index > 0) |
| 495 | + { |
| 496 | + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; |
| 497 | + } |
| 498 | + |
| 499 | + return CopyProtocolVersionIntoSpan(knownProtocolVersion, protocolVersion); |
| 500 | +} |
| 501 | + |
| 502 | +uint8_t LockEndpoint::GetAliroBLEAdvertisingVersion() |
| 503 | +{ |
| 504 | + // For now the only define value of the BLE advertising version for Aliro is 0. |
| 505 | + return 0; |
| 506 | +} |
| 507 | + |
| 508 | +uint16_t LockEndpoint::GetNumberOfAliroCredentialIssuerKeysSupported() |
| 509 | +{ |
| 510 | + using namespace chip::app::Clusters::DoorLock; |
| 511 | + |
| 512 | + // Our vector has an extra entry at index 0 that is not a valid entry, so |
| 513 | + // the actual number of credentials supported is one length than the length. |
| 514 | + return static_cast<uint16_t>(mLockCredentials.at(to_underlying(CredentialTypeEnum::kAliroCredentialIssuerKey)).size() - 1); |
| 515 | +} |
| 516 | + |
| 517 | +uint16_t LockEndpoint::GetNumberOfAliroEndpointKeysSupported() |
| 518 | +{ |
| 519 | + using namespace chip::app::Clusters::DoorLock; |
| 520 | + |
| 521 | + // Our vector has an extra entry at index 0 that is not a valid entry, so |
| 522 | + // the actual number of credentials supported is one length than the length. |
| 523 | + // |
| 524 | + // Also, our arrays are the same size, so we just return the size of one of |
| 525 | + // the arrays: that is the cap on the total number of endpoint keys |
| 526 | + // supported, which can be of either type. |
| 527 | + return static_cast<uint16_t>(mLockCredentials.at(to_underlying(CredentialTypeEnum::kAliroEvictableEndpointKey)).size() - 1); |
| 528 | +} |
| 529 | + |
| 530 | +CHIP_ERROR LockEndpoint::SetAliroReaderConfig(const ByteSpan & signingKey, const ByteSpan & verificationKey, |
| 531 | + const ByteSpan & groupIdentifier, const Optional<ByteSpan> & groupResolvingKey) |
| 532 | +{ |
| 533 | + // We ignore the signing key, since we never do anything with it. |
| 534 | + |
| 535 | + VerifyOrReturnError(verificationKey.size() == sizeof(mAliroReaderVerificationKey), CHIP_ERROR_INVALID_ARGUMENT); |
| 536 | + memcpy(mAliroReaderVerificationKey, verificationKey.data(), sizeof(mAliroReaderVerificationKey)); |
| 537 | + |
| 538 | + VerifyOrReturnError(groupIdentifier.size() == sizeof(mAliroReaderGroupIdentifier), CHIP_ERROR_INVALID_ARGUMENT); |
| 539 | + memcpy(mAliroReaderGroupIdentifier, groupIdentifier.data(), sizeof(mAliroReaderGroupIdentifier)); |
| 540 | + |
| 541 | + if (groupResolvingKey.HasValue()) |
| 542 | + { |
| 543 | + VerifyOrReturnError(groupResolvingKey.Value().size() == sizeof(mAliroGroupResolvingKey), CHIP_ERROR_INVALID_ARGUMENT); |
| 544 | + memcpy(mAliroGroupResolvingKey, groupResolvingKey.Value().data(), sizeof(mAliroGroupResolvingKey)); |
| 545 | + } |
| 546 | + |
| 547 | + mAliroStateInitialized = true; |
| 548 | + return CHIP_NO_ERROR; |
| 549 | +} |
| 550 | + |
| 551 | +CHIP_ERROR LockEndpoint::ClearAliroReaderConfig() |
| 552 | +{ |
| 553 | + // A real implementation would clear out key data from the other parts of |
| 554 | + // the application that might use it. |
| 555 | + mAliroStateInitialized = false; |
| 556 | + return CHIP_NO_ERROR; |
| 557 | +} |
| 558 | + |
410 | 559 | bool LockEndpoint::setLockState(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
|
411 | 560 | DlLockState lockState, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
|
412 | 561 | OperationSourceEnum opSource)
|
|
0 commit comments