@@ -31,29 +31,51 @@ using namespace chip;
31
31
using namespace chip ::app;
32
32
using namespace chip ::app::Clusters;
33
33
using namespace chip ::app::Clusters::WiFiNetworkManagement::Attributes;
34
+ using namespace chip ::app::Clusters::WiFiNetworkManagement::Commands;
34
35
using namespace std ::placeholders;
35
36
36
37
namespace chip {
37
38
namespace app {
38
39
namespace Clusters {
39
- namespace WiFiNetworkManagement {
40
40
41
- Global<Server> gServerInstance ;
41
+ namespace {
42
42
43
- Server & Server::Instance ()
43
+ // TODO: Move this into lib/support somewhere and also use it network-commissioning.cpp
44
+ bool IsValidWpaPersonalCredential (ByteSpan credential)
45
+ {
46
+ // As per spec section 11.9.7.3. AddOrUpdateWiFiNetwork Command
47
+ if (8 <= credential.size () && credential.size () <= 63 ) // passphrase
48
+ {
49
+ return true ;
50
+ }
51
+ if (credential.size () == 64 ) // raw hex psk
52
+ {
53
+ return std::all_of (credential.begin (), credential.end (), [](auto c) { return std::isxdigit (c); });
54
+ }
55
+ return false ;
56
+ }
57
+
58
+ Global<WiFiNetworkManagementServer> gWiFiNetworkManagementServerInstance ;
59
+
60
+ } // namespace
61
+
62
+ WiFiNetworkManagementServer & WiFiNetworkManagementServer::Instance ()
44
63
{
45
- return gServerInstance .get ();
64
+ return gWiFiNetworkManagementServerInstance .get ();
46
65
}
47
66
48
- Server::Server () : AttributeAccessInterface(NullOptional, Id), CommandHandlerInterface(NullOptional, Id) {}
67
+ WiFiNetworkManagementServer::WiFiNetworkManagementServer () :
68
+ AttributeAccessInterface (NullOptional, WiFiNetworkManagement::Id),
69
+ CommandHandlerInterface (NullOptional, WiFiNetworkManagement::Id)
70
+ {}
49
71
50
- Server ::~Server ()
72
+ WiFiNetworkManagementServer ::~WiFiNetworkManagementServer ()
51
73
{
52
74
unregisterAttributeAccessOverride (this );
53
75
InteractionModelEngine::GetInstance ()->UnregisterCommandHandler (this );
54
76
}
55
77
56
- CHIP_ERROR Server ::Init (EndpointId endpoint)
78
+ CHIP_ERROR WiFiNetworkManagementServer ::Init (EndpointId endpoint)
57
79
{
58
80
VerifyOrReturnError (endpoint != kInvalidEndpointId , CHIP_ERROR_INVALID_ARGUMENT);
59
81
VerifyOrReturnError (mEndpointId == kInvalidEndpointId , CHIP_ERROR_INCORRECT_STATE);
@@ -64,32 +86,17 @@ CHIP_ERROR Server::Init(EndpointId endpoint)
64
86
return CHIP_NO_ERROR;
65
87
}
66
88
67
- CHIP_ERROR Server ::ClearNetworkCredentials ()
89
+ CHIP_ERROR WiFiNetworkManagementServer ::ClearNetworkCredentials ()
68
90
{
69
91
VerifyOrReturnError (HaveNetworkCredentials (), CHIP_NO_ERROR);
70
92
71
93
mSsidLen = 0 ;
72
94
mPassphrase .SetLength (0 );
73
- MatterReportingAttributeChangeCallback (mEndpointId , Id, Ssid::Id);
95
+ MatterReportingAttributeChangeCallback (mEndpointId , WiFiNetworkManagement:: Id, Ssid::Id);
74
96
return CHIP_NO_ERROR;
75
97
}
76
98
77
- // TODO: Move this into lib/support somewhere and also use it network-commissioning.cpp
78
- bool IsValidWpaPersonalCredential (ByteSpan credential)
79
- {
80
- // As per spec section 11.9.7.3. AddOrUpdateWiFiNetwork Command
81
- if (8 <= credential.size () && credential.size () <= 63 ) // passphrase
82
- {
83
- return true ;
84
- }
85
- if (credential.size () == 64 ) // raw hex psk
86
- {
87
- return std::all_of (credential.begin (), credential.end (), [](auto c) { return std::isxdigit (c); });
88
- }
89
- return false ;
90
- }
91
-
92
- CHIP_ERROR Server::SetNetworkCredentials (ByteSpan ssid, ByteSpan passphrase)
99
+ CHIP_ERROR WiFiNetworkManagementServer::SetNetworkCredentials (ByteSpan ssid, ByteSpan passphrase)
93
100
{
94
101
VerifyOrReturnError (1 <= ssid.size () && ssid.size () <= sizeof (mSsid ), CHIP_ERROR_INVALID_ARGUMENT);
95
102
VerifyOrReturnError (IsValidWpaPersonalCredential (passphrase), CHIP_ERROR_INVALID_ARGUMENT);
@@ -107,12 +114,12 @@ CHIP_ERROR Server::SetNetworkCredentials(ByteSpan ssid, ByteSpan passphrase)
107
114
// Note: The spec currently defines no way to signal a passphrase change
108
115
if (ssidChanged)
109
116
{
110
- MatterReportingAttributeChangeCallback (mEndpointId , Id, Ssid::Id);
117
+ MatterReportingAttributeChangeCallback (mEndpointId , WiFiNetworkManagement:: Id, Ssid::Id);
111
118
}
112
119
return CHIP_NO_ERROR;
113
120
}
114
121
115
- CHIP_ERROR Server ::Read (const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
122
+ CHIP_ERROR WiFiNetworkManagementServer ::Read (const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
116
123
{
117
124
switch (aPath.mAttributeId )
118
125
{
@@ -122,22 +129,23 @@ CHIP_ERROR Server::Read(const ConcreteReadAttributePath & aPath, AttributeValueE
122
129
return CHIP_NO_ERROR;
123
130
}
124
131
125
- void Server ::InvokeCommand (HandlerContext & ctx)
132
+ void WiFiNetworkManagementServer ::InvokeCommand (HandlerContext & ctx)
126
133
{
127
134
switch (ctx.mRequestPath .mCommandId )
128
135
{
129
- case Commands:: NetworkPassphraseRequest::Id:
130
- HandleCommand<Commands:: NetworkPassphraseRequest::DecodableType>(
136
+ case NetworkPassphraseRequest::Id:
137
+ HandleCommand<NetworkPassphraseRequest::DecodableType>(
131
138
ctx, [this ](HandlerContext & aCtx, const auto & req) { HandleNetworkPassphraseRequest (aCtx, req); });
132
139
return ;
133
140
}
134
141
}
135
142
136
- void Server::HandleNetworkPassphraseRequest (HandlerContext & ctx, const Commands::NetworkPassphraseRequest::DecodableType & req)
143
+ void WiFiNetworkManagementServer::HandleNetworkPassphraseRequest (HandlerContext & ctx,
144
+ const NetworkPassphraseRequest::DecodableType & req)
137
145
{
138
146
if (HaveNetworkCredentials ())
139
147
{
140
- Commands:: NetworkPassphraseResponse::Type response;
148
+ NetworkPassphraseResponse::Type response;
141
149
response.passphrase = mPassphrase .Span ();
142
150
ctx.mCommandHandler .AddResponse (ctx.mRequestPath , response);
143
151
}
@@ -148,7 +156,6 @@ void Server::HandleNetworkPassphraseRequest(HandlerContext & ctx, const Commands
148
156
}
149
157
}
150
158
151
- } // namespace WiFiNetworkManagement
152
159
} // namespace Clusters
153
160
} // namespace app
154
161
} // namespace chip
@@ -165,5 +172,5 @@ void emberAfWiFiNetworkManagementClusterServerInitCallback(EndpointId endpoint)
165
172
// We could delay constructing the instance until this point; however it's not
166
173
// clear if this is inconvenient in terms of forcing the application to initialize
167
174
// the network credentials later than it otherwise would.
168
- LogErrorOnFailure (chip::app::Clusters::WiFiNetworkManagement::Server ::Instance ().Init (endpoint));
175
+ LogErrorOnFailure (chip::app::Clusters::WiFiNetworkManagementServer ::Instance ().Init (endpoint));
169
176
}
0 commit comments