Skip to content

Commit

Permalink
Add Wi-Fi Network Management Cluster and use correct NIM device type …
Browse files Browse the repository at this point in the history
…id (#33519)

* Add Wi-Fi Network Management Cluster and use correct NIM device type id

* zap_regen_all

* Change minimal CI job to build network-manager-app

* Keep the minimal all-clusters-app build since it's required for merge

* Cluster ID should be 0x0451

* zap_regen_all

* Address review comments and other small tweaks

- Factor out HaveNetworkCredentials() helper and use it consistently
- Validate WPA credential in SetNetworkCredentials()
- Don't emit an SSID change when only the passphrase changes
- Use CHIPSafeCasts
- Avoid std::bind (and we can't use std::bind_front yet)
- Add a destructor that unregisters handlers

* Address review comments

- Rename Server -> WiFiNetworkManagementServer and move it up a namespace.
- Move internal definitions into an anonymous namespace.
  • Loading branch information
ksperling-apple committed May 29, 2024
1 parent 8c8889b commit fc3591d
Show file tree
Hide file tree
Showing 57 changed files with 4,515 additions and 15 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/minimal-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ concurrency:
cancel-in-progress: true

jobs:
minimal:
minimal-all-clusters:
name: Linux / configure build of all-clusters-app

if: github.actor != 'restyled-io[bot]'
Expand All @@ -47,3 +47,25 @@ jobs:
- name: Configure and build All Clusters App
run: |
CC=gcc CXX=g++ scripts/configure --project=examples/all-clusters-app/linux && ./ninja-build
minimal-network-manager:
name: Linux / configure build of network-manager-app

if: github.actor != 'restyled-io[bot]'
runs-on: ubuntu-latest

container:
image: ghcr.io/project-chip/chip-build-minimal:50

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Checkout submodules # but don't bootstrap!
uses: ./.github/actions/checkout-submodules
with:
platform: linux

- name: Configure and build Network Manager App
run: |
CC=gcc CXX=g++ scripts/configure --project=examples/network-manager-app/linux && ./ninja-build
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ jobs:
src/app/zap-templates/zcl/data-model/chip/wake-on-lan-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/washer-controls-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/wifi-network-diagnostics-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/wifi-network-management-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/window-covering.xml \
src/app/zap-templates/zcl/data-model/chip/temperature-control-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/matter-devices.xml \
Expand Down
1 change: 1 addition & 0 deletions docs/zap_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Generally regenerate using one of:
| 1069 | 0x42D | Pm10ConcentrationMeasurement |
| 1070 | 0x42E | TotalVolatileOrganicCompoundsConcentrationMeasurement |
| 1071 | 0x42F | RadonConcentrationMeasurement |
| 1105 | 0x451 | WiFiNetworkManagement |
| 1283 | 0x503 | WakeOnLan |
| 1284 | 0x504 | Channel |
| 1285 | 0x505 | TargetNavigator |
Expand Down
12 changes: 12 additions & 0 deletions examples/network-manager-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,32 @@
*/

#include <AppMain.h>
#include <app/clusters/wifi-network-management-server/wifi-network-management-server.h>
#include <lib/core/CHIPSafeCasts.h>
#include <lib/support/Span.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;

void ApplicationInit() {}
void ApplicationShutdown() {}

ByteSpan ByteSpanFromCharSpan(CharSpan span)
{
return ByteSpan(Uint8::from_const_char(span.data()), span.size());
}

int main(int argc, char * argv[])
{
if (ChipLinuxAppInit(argc, argv) != 0)
{
return -1;
}

WiFiNetworkManagementServer::Instance().SetNetworkCredentials(ByteSpanFromCharSpan("MatterAP"_span),
ByteSpanFromCharSpan("Setec Astronomy"_span));

ChipLinuxAppMainLoop();
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,26 @@ cluster GroupKeyManagement = 63 {
fabric command access(invoke: administer) KeySetReadAllIndices(): KeySetReadAllIndicesResponse = 4;
}

/** Functionality to retrieve operational information about a managed Wi-Fi network. */
cluster WiFiNetworkManagement = 1105 {
revision 1;

readonly attribute nullable octet_string<32> ssid = 1;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

response struct NetworkPassphraseResponse = 1 {
octet_string<64> passphrase = 0;
}

/** Request the current WPA-Personal passphrase or PSK associated with the managed Wi-Fi network. */
command access(invoke: administer) NetworkPassphraseRequest(): NetworkPassphraseResponse = 0;
}

endpoint 0 {
device type ma_rootdevice = 22, version 1;

Expand Down Expand Up @@ -1280,7 +1300,7 @@ endpoint 0 {
callback attribute acceptedCommandList;
callback attribute attributeList;
callback attribute featureMap default = 0;
ram attribute clusterRevision default = 1;
callback attribute clusterRevision default = 0;
}

server cluster GeneralDiagnostics {
Expand Down Expand Up @@ -1425,7 +1445,7 @@ endpoint 0 {
}
}
endpoint 1 {
device type ma_network_infrastructure_manager = 4293984272, version 1;
device type ma_network_infrastructure_manager = 144, version 1;


server cluster Descriptor {
Expand All @@ -1440,6 +1460,19 @@ endpoint 1 {
callback attribute featureMap;
callback attribute clusterRevision;
}

server cluster WiFiNetworkManagement {
callback attribute ssid;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0;
ram attribute clusterRevision default = 1;

handle command NetworkPassphraseRequest;
handle command NetworkPassphraseResponse;
}
}


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"fileFormat": 2,
"featureLevel": 100,
"featureLevel": 102,
"creator": "zap",
"keyValuePairs": [
{
Expand All @@ -13,7 +13,7 @@
},
{
"key": "manufacturerCodes",
"value": "0x1002"
"value": "0xFFF1"
}
],
"package": [
Expand All @@ -29,6 +29,7 @@
"pathRelativity": "relativeToZap",
"path": "../../../src/app/zap-templates/app-templates.json",
"type": "gen-templates-json",
"category": "matter",
"version": "chip-v1"
}
],
Expand Down Expand Up @@ -1352,10 +1353,10 @@
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"defaultValue": "0",
"reportable": 1,
"minInterval": 0,
"maxInterval": 65344,
Expand Down Expand Up @@ -3016,14 +3017,14 @@
"id": 2,
"name": "Anonymous Endpoint Type",
"deviceTypeRef": {
"code": 4293984272,
"code": 144,
"profileId": 259,
"label": "MA-network-infrastructure-manager",
"name": "MA-network-infrastructure-manager"
},
"deviceTypes": [
{
"code": 4293984272,
"code": 144,
"profileId": 259,
"label": "MA-network-infrastructure-manager",
"name": "MA-network-infrastructure-manager"
Expand All @@ -3033,10 +3034,10 @@
1
],
"deviceIdentifiers": [
4293984272
144
],
"deviceTypeName": "MA-network-infrastructure-manager",
"deviceTypeCode": 4293984272,
"deviceTypeCode": 144,
"deviceTypeProfileId": 259,
"clusters": [
{
Expand Down Expand Up @@ -3208,6 +3209,146 @@
"reportableChange": 0
}
]
},
{
"name": "Wi-Fi Network Management",
"code": 1105,
"mfgCode": null,
"define": "WIFI_NETWORK_MANAGEMENT_CLUSTER",
"side": "server",
"enabled": 1,
"commands": [
{
"name": "NetworkPassphraseRequest",
"code": 0,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "NetworkPassphraseResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
{
"name": "SSID",
"code": 1,
"mfgCode": null,
"side": "server",
"type": "octet_string",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AcceptedCommandList",
"code": 65529,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "EventList",
"code": 65530,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AttributeList",
"code": 65531,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
"mfgCode": null,
"side": "server",
"type": "bitmap32",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
}
]
}
]
}
Expand Down
1 change: 1 addition & 0 deletions scripts/rules.matterlint
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ load "../src/app/zap-templates/zcl/data-model/chip/user-label-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/wake-on-lan-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/washer-controls-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/wifi-network-diagnostics-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/wifi-network-management-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/window-covering.xml";
load "../src/app/zap-templates/zcl/data-model/chip/temperature-control-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/refrigerator-alarm.xml";
Expand Down
2 changes: 2 additions & 0 deletions src/app/CommandHandlerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#include <app/ConcreteCommandPath.h>
#include <app/data-model/Decode.h>
#include <app/data-model/List.h> // So we can encode lists
#include <functional>
#include <lib/core/DataModelTypes.h>
#include <lib/support/Iterators.h>
#include <type_traits>

namespace chip {
namespace app {
Expand Down
Loading

0 comments on commit fc3591d

Please sign in to comment.