Skip to content

Commit

Permalink
Merge branch 'master' into feature/wifinetworkdiagnostics_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
chirag-silabs authored Jul 1, 2022
2 parents 9e4389f + a295bec commit c40001c
Show file tree
Hide file tree
Showing 28 changed files with 565 additions and 128 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@
"random": "cpp",
"thread": "cpp"
},
// Configure paths or glob patterns to exclude from file watching.
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"out/": true,
"**/third_party/**": true
},
"files.eol": "\n",
"editor.formatOnSave": true,
"better-comments.tags": [
Expand Down
10 changes: 10 additions & 0 deletions examples/all-clusters-app/nxp/mw320/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ Note:
2. "source third_party/connectedhomeip/scripts/activate.sh" can be omitted if
your environment is already setup without issues.

Tinycrypt ECC operations:

Note: This solution is temporary.

In order to use the tinycrypt ecc operations, use the following build arguments:

```
$ gn gen out/debug --args='treat_warnings_as_errors=false mbedtls_repo="//third_party/connectedhomeip/third_party/nxp/libs/mbedtls" mbedtls_use_tinycrypt=true'
```

<a name="flashdebug"></a>

## Flashing
Expand Down
3 changes: 1 addition & 2 deletions examples/all-clusters-app/nxp/mw320/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,8 +1411,7 @@ static void OnSwitchAttributeChangeCallback(EndpointId endpointId, AttributeId a
/*
Callback to receive the cluster modification event
*/
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & path, uint8_t mask, uint8_t type, uint16_t size,
uint8_t * value)
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & path, uint8_t type, uint16_t size, uint8_t * value)
{
PRINTF("==> MatterPostAttributeChangeCallback, cluster: %x, attr: %x, size: %d \r\n", path.mClusterId, path.mAttributeId, size);
// path.mEndpointId, path.mClusterId, path.mAttributeId, mask, type, size, value
Expand Down
45 changes: 12 additions & 33 deletions examples/lighting-app/bouffalolab/bl602/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,7 @@ The steps in this document were validated on Ubuntu 18.04 and 20.04.
source ./scripts/activate.sh
```
## Build the image
- Build the example application:
```
connectedhomeip$ ./scripts/build/build_examples.py --target bl602-light build
```
Generated files
```
connectedhomeip/out/bl602-light/chip-bl602-lighting-example.bin
```
To delete generated executable, libraries and object files use:
```
cd ~/connectedhomeip/
rm -rf out/
```
## Flash the board
## Build the image and flash the board
- Build the
[lighting-app](https://github.com/project-chip/connectedhomeip/tree/master/examples/lighting-app/bouffalolab/bl602)
Expand Down Expand Up @@ -94,7 +73,7 @@ The steps in this document were validated on Ubuntu 18.04 and 20.04.
`/dev/ttyACM0`:
```
picocom -b 2000000 /dev/ttyACM0
picocom -b 115200 /dev/ttyACM0
```
2.To reset the board, press the RESET button, and you will see the log in the
Expand All @@ -113,16 +92,16 @@ remote device, as well as the network credentials to use.
The command below uses the default values hard-coded into the debug versions of
the BL602 lighting-app to commission it onto a Wi-Fi network:
```
$ sudo ./chip-tool pairing ble-wifi 1 ${SSID} ${PASSWORD} 20202021 3840

Parameters:
1. Discriminator: 3840
2. Setup-pin-code: 20202021
3. Node ID: 1
4. SSID : Wi-Fi SSID
5. PASSWORD : Wi-Fi Password
```
```
$ sudo ./chip-tool pairing ble-wifi 1 ${SSID} ${PASSWORD} 20202021 3840
Parameters:
1. Discriminator: 3840
2. Setup-pin-code: 20202021
3. Node ID: 1
4. SSID : Wi-Fi SSID
5. PASSWORD : Wi-Fi Password
```
### Cluster control
Expand Down
12 changes: 12 additions & 0 deletions examples/lock-app/nrfconnect/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
#
mainmenu "Matter nRF Connect Lock Example Application"

config LOCK_NUM_USERS
int "Maximum number of users supported by lock"
default 10

config LOCK_NUM_CREDENTIALS
int "Maximum number of credentials supported by lock"
default 20

config LOCK_NUM_CREDENTIALS_PER_USER
int "Maximum number of credentials per user supported by lock"
default 3

config STATE_LEDS
bool "Use LEDs to indicate the device state"
default y
Expand Down
114 changes: 114 additions & 0 deletions examples/lock-app/nrfconnect/main/BoltLockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "AppEvent.h"
#include "AppTask.h"

using namespace chip;

BoltLockManager BoltLockManager::sLock;

void BoltLockManager::Init(StateChangeCallback callback)
Expand All @@ -33,6 +35,118 @@ void BoltLockManager::Init(StateChangeCallback callback)
k_timer_user_data_set(&mActuatorTimer, this);
}

bool BoltLockManager::GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const
{
// userIndex is guaranteed by the caller to be between 1 and CONFIG_LOCK_NUM_USERS
user = mUsers[userIndex - 1];

ChipLogProgress(Zcl, "Getting lock user %u: %s", static_cast<unsigned>(userIndex),
user.userStatus == DlUserStatus::kAvailable ? "available" : "occupied");

return true;
}

bool BoltLockManager::SetUser(uint16_t userIndex, FabricIndex creator, FabricIndex modifier, const CharSpan & userName,
uint32_t uniqueId, DlUserStatus userStatus, DlUserType userType, DlCredentialRule credentialRule,
const DlCredential * credentials, size_t totalCredentials)
{
// userIndex is guaranteed by the caller to be between 1 and CONFIG_LOCK_NUM_USERS
UserData & userData = mUserData[userIndex - 1];
auto & user = mUsers[userIndex - 1];

VerifyOrReturnError(userName.size() <= DOOR_LOCK_MAX_USER_NAME_SIZE, false);
VerifyOrReturnError(totalCredentials <= CONFIG_LOCK_NUM_CREDENTIALS_PER_USER, false);

Platform::CopyString(userData.mName, userName);
memcpy(userData.mCredentials, credentials, totalCredentials * sizeof(DlCredential));

user.userName = CharSpan(userData.mName, userName.size());
user.credentials = Span<const DlCredential>(userData.mCredentials, totalCredentials);
user.userUniqueId = uniqueId;
user.userStatus = userStatus;
user.userType = userType;
user.credentialRule = credentialRule;
user.creationSource = DlAssetSource::kMatterIM;
user.createdBy = creator;
user.modificationSource = DlAssetSource::kMatterIM;
user.lastModifiedBy = modifier;

ChipLogProgress(Zcl, "Setting lock user %u: %s", static_cast<unsigned>(userIndex),
userStatus == DlUserStatus::kAvailable ? "available" : "occupied");

return true;
}

bool BoltLockManager::GetCredential(uint16_t credentialIndex, DlCredentialType credentialType,
EmberAfPluginDoorLockCredentialInfo & credential) const
{
VerifyOrReturnError(credentialIndex > 0 && credentialIndex <= CONFIG_LOCK_NUM_CREDENTIALS, false);

credential = mCredentials[credentialIndex - 1];

ChipLogProgress(Zcl, "Getting lock credential %u: %s", static_cast<unsigned>(credentialIndex),
credential.status == DlCredentialStatus::kAvailable ? "available" : "occupied");

return true;
}

bool BoltLockManager::SetCredential(uint16_t credentialIndex, FabricIndex creator, FabricIndex modifier,
DlCredentialStatus credentialStatus, DlCredentialType credentialType, const ByteSpan & secret)
{
VerifyOrReturnError(credentialIndex > 0 && credentialIndex <= CONFIG_LOCK_NUM_CREDENTIALS, false);
VerifyOrReturnError(secret.size() <= kMaxCredentialLength, false);

CredentialData & credentialData = mCredentialData[credentialIndex - 1];
auto & credential = mCredentials[credentialIndex - 1];

if (!secret.empty())
{
memcpy(credentialData.mSecret.Alloc(secret.size()).Get(), secret.data(), secret.size());
}

credential.status = credentialStatus;
credential.credentialType = credentialType;
credential.credentialData = ByteSpan(credentialData.mSecret.Get(), secret.size());
credential.creationSource = DlAssetSource::kMatterIM;
credential.createdBy = creator;
credential.modificationSource = DlAssetSource::kMatterIM;
credential.lastModifiedBy = modifier;

ChipLogProgress(Zcl, "Setting lock credential %u: %s", static_cast<unsigned>(credentialIndex),
credential.status == DlCredentialStatus::kAvailable ? "available" : "occupied");

return true;
}

bool BoltLockManager::ValidatePIN(const Optional<ByteSpan> & pinCode, DlOperationError & err) const
{
// Optionality of the PIN code is validated by the caller, so assume it is OK not to provide the PIN code.
if (!pinCode.HasValue())
{
return true;
}

// Check the PIN code
for (const auto & credential : mCredentials)
{
if (credential.status == DlCredentialStatus::kAvailable || credential.credentialType != DlCredentialType::kPin)
{
continue;
}

if (credential.credentialData.data_equal(pinCode.Value()))
{
ChipLogDetail(Zcl, "Valid lock PIN code provided");
return true;
}
}

ChipLogDetail(Zcl, "Invalid lock PIN code provided");
err = DlOperationError::kInvalidCredential;

return false;
}

void BoltLockManager::Lock(OperationSource source)
{
VerifyOrReturn(mState != State::kLockingCompleted);
Expand Down
61 changes: 45 additions & 16 deletions examples/lock-app/nrfconnect/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,63 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
}
}

bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Optional<ByteSpan> & pinCode, DlOperationError & err)
bool emberAfPluginDoorLockGetUser(EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user)
{
return true;
return BoltLockMgr().GetUser(userIndex, user);
}

bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Optional<ByteSpan> & pinCode,
DlOperationError & err)
bool emberAfPluginDoorLockSetUser(EndpointId endpointId, uint16_t userIndex, FabricIndex creator, FabricIndex modifier,
const CharSpan & userName, uint32_t uniqueId, DlUserStatus userStatus, DlUserType userType,
DlCredentialRule credentialRule, const DlCredential * credentials, size_t totalCredentials)
{
return true;
return BoltLockMgr().SetUser(userIndex, creator, modifier, userName, uniqueId, userStatus, userType, credentialRule,
credentials, totalCredentials);
}

bool emberAfPluginDoorLockGetCredential(EndpointId endpointId, uint16_t credentialIndex, DlCredentialType credentialType,
EmberAfPluginDoorLockCredentialInfo & credential)
{
return BoltLockMgr().GetCredential(credentialIndex, credentialType, credential);
}

bool emberAfPluginDoorLockSetCredential(EndpointId endpointId, uint16_t credentialIndex, FabricIndex creator, FabricIndex modifier,
DlCredentialStatus credentialStatus, DlCredentialType credentialType,
const ByteSpan & secret)
{
return BoltLockMgr().SetCredential(credentialIndex, creator, modifier, credentialStatus, credentialType, secret);
}

bool emberAfPluginDoorLockOnDoorLockCommand(EndpointId endpointId, const Optional<ByteSpan> & pinCode, DlOperationError & err)
{
return BoltLockMgr().ValidatePIN(pinCode, err);
}

bool emberAfPluginDoorLockOnDoorUnlockCommand(EndpointId endpointId, const Optional<ByteSpan> & pinCode, DlOperationError & err)
{
return BoltLockMgr().ValidatePIN(pinCode, err);
}

void emberAfDoorLockClusterInitCallback(EndpointId endpoint)
{
DoorLockServer::Instance().InitServer(endpoint);

EmberAfStatus status = DoorLock::Attributes::LockType::Set(endpoint, DlLockType::kDeadBolt);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
LOG_ERR("Updating type %x", status);
}
const auto logOnFailure = [](EmberAfStatus status, const char * attributeName) {
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(Zcl, "Failed to set DoorLock %s: %x", attributeName, status);
}
};

logOnFailure(DoorLock::Attributes::LockType::Set(endpoint, DlLockType::kDeadBolt), "type");
logOnFailure(DoorLock::Attributes::NumberOfTotalUsersSupported::Set(endpoint, CONFIG_LOCK_NUM_USERS), "number of users");
logOnFailure(DoorLock::Attributes::NumberOfPINUsersSupported::Set(endpoint, CONFIG_LOCK_NUM_USERS), "number of PIN users");
logOnFailure(DoorLock::Attributes::NumberOfRFIDUsersSupported::Set(endpoint, 0), "number of RFID users");
logOnFailure(DoorLock::Attributes::NumberOfCredentialsSupportedPerUser::Set(endpoint, CONFIG_LOCK_NUM_CREDENTIALS_PER_USER),
"number of credentials per user");

// Set FeatureMap to 0, default is:
// Set FeatureMap to (kUsersManagement|kPINCredentials), default is:
// (kUsersManagement|kAccessSchedules|kRFIDCredentials|kPINCredentials) 0x113
status = DoorLock::Attributes::FeatureMap::Set(endpoint, 0);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
LOG_ERR("Updating feature map %x", status);
}
logOnFailure(DoorLock::Attributes::FeatureMap::Set(endpoint, 0x101), "feature map");

GetAppTask().UpdateClusterState(BoltLockMgr().GetState(), BoltLockManager::OperationSource::kUnspecified);
}
Loading

0 comments on commit c40001c

Please sign in to comment.