@@ -90,14 +90,6 @@ CHIP_ERROR RendezvousSession::Init(const RendezvousParameters & params, Messagin
90
90
91
91
RendezvousSession::~RendezvousSession ()
92
92
{
93
- ReleasePairingSessionHandle ();
94
-
95
- if (mTransport != nullptr )
96
- {
97
- chip::Platform::Delete (mTransport );
98
- mTransport = nullptr ;
99
- }
100
-
101
93
mDelegate = nullptr ;
102
94
}
103
95
@@ -122,32 +114,45 @@ void RendezvousSession::OnSessionEstablished()
122
114
123
115
CHIP_ERROR err = mSecureSessionMgr ->NewPairing (
124
116
Optional<Transport::PeerAddress>::Value (mPairingSession .PeerConnection ().GetPeerAddress ()),
125
- mPairingSession .PeerConnection ().GetPeerNodeId (), &mPairingSession , direction, mAdmin ->GetAdminId (), mTransport );
117
+ mPairingSession .PeerConnection ().GetPeerNodeId (), &mPairingSession , direction, mAdmin ->GetAdminId (), nullptr );
126
118
if (err != CHIP_NO_ERROR)
127
119
{
128
120
ChipLogError (Ble, " Failed in setting up secure channel: err %s" , ErrorStr (err));
121
+ OnRendezvousError (err);
129
122
return ;
130
123
}
131
124
132
- InitPairingSessionHandle ();
125
+ Cleanup ();
133
126
134
- UpdateState (State::kRendezvousComplete );
135
- if (!mParams .IsController ())
127
+ if (mParams .HasAdvertisementDelegate ())
136
128
{
137
- OnRendezvousConnectionClosed ();
129
+ mParams . GetAdvertisementDelegate ()-> RendezvousComplete ();
138
130
}
139
- }
140
131
141
- void RendezvousSession::OnNetworkProvisioningError (CHIP_ERROR err)
142
- {
143
- OnRendezvousError (err);
132
+ if (mDelegate != nullptr )
133
+ {
134
+ mDelegate ->OnRendezvousStatusUpdate (RendezvousSessionDelegate::SecurePairingSuccess, CHIP_NO_ERROR);
135
+ mDelegate ->OnRendezvousComplete ();
136
+ }
144
137
}
145
138
146
- void RendezvousSession::OnNetworkProvisioningComplete ()
139
+ void RendezvousSession::Cleanup ()
147
140
{
148
- UpdateState (State::kRendezvousComplete );
141
+ if (!mParams .IsController ())
142
+ {
143
+ mExchangeManager ->UnregisterUnsolicitedMessageHandlerForType (Protocols::SecureChannel::MsgType::PBKDFParamRequest);
144
+ }
145
+
146
+ if (mParams .HasAdvertisementDelegate ())
147
+ {
148
+ mParams .GetAdvertisementDelegate ()->StopAdvertisement ();
149
+ }
149
150
}
150
151
152
+ void RendezvousSession::OnNetworkProvisioningError (CHIP_ERROR err) {}
153
+
154
+ void RendezvousSession::OnNetworkProvisioningComplete () {}
155
+
151
156
void RendezvousSession::OnRendezvousConnectionOpened ()
152
157
{
153
158
if (!mParams .IsController ())
@@ -158,135 +163,36 @@ void RendezvousSession::OnRendezvousConnectionOpened()
158
163
CHIP_ERROR err = Pair (mParams .GetSetupPINCode ());
159
164
if (err != CHIP_NO_ERROR)
160
165
{
161
- OnSessionEstablishmentError (err);
166
+ OnRendezvousError (err);
162
167
}
163
168
}
164
169
165
- void RendezvousSession::OnRendezvousConnectionClosed ()
166
- {
167
- UpdateState (State::kInit , CHIP_NO_ERROR);
168
- }
170
+ void RendezvousSession::OnRendezvousConnectionClosed () {}
169
171
170
172
void RendezvousSession::OnRendezvousError (CHIP_ERROR err)
171
173
{
172
- UpdateState (State::kInit , err);
173
- }
174
+ Cleanup ();
174
175
175
- void RendezvousSession::UpdateState (RendezvousSession::State newState, CHIP_ERROR err)
176
- {
177
176
if (mDelegate != nullptr )
178
177
{
179
- switch (mCurrentState )
180
- {
181
- case State::kSecurePairing :
182
- mExchangeManager ->UnregisterUnsolicitedMessageHandlerForType (Protocols::SecureChannel::MsgType::PBKDFParamRequest);
183
- if (CHIP_NO_ERROR == err)
184
- {
185
- mDelegate ->OnRendezvousStatusUpdate (RendezvousSessionDelegate::SecurePairingSuccess, err);
186
- }
187
- else
188
- {
189
- mDelegate ->OnRendezvousStatusUpdate (RendezvousSessionDelegate::SecurePairingFailed, err);
190
- }
191
- break ;
192
-
193
- default :
194
- break ;
195
- };
178
+ mDelegate ->OnRendezvousStatusUpdate (RendezvousSessionDelegate::SecurePairingFailed, err);
179
+ mDelegate ->OnRendezvousError (err);
196
180
}
197
-
198
- mCurrentState = newState;
199
-
200
- switch (mCurrentState )
201
- {
202
- case State::kRendezvousComplete :
203
- if (mParams .HasAdvertisementDelegate ())
204
- {
205
- mParams .GetAdvertisementDelegate ()->RendezvousComplete ();
206
- }
207
-
208
- if (mDelegate != nullptr )
209
- {
210
- mDelegate ->OnRendezvousComplete ();
211
- }
212
- break ;
213
-
214
- case State::kSecurePairing :
215
- // Release the previous session handle
216
- ReleasePairingSessionHandle ();
217
- break ;
218
-
219
- case State::kInit :
220
- // Release the previous session handle
221
- ReleasePairingSessionHandle ();
222
-
223
- // Disable rendezvous advertisement
224
- if (mParams .HasAdvertisementDelegate ())
225
- {
226
- mParams .GetAdvertisementDelegate ()->StopAdvertisement ();
227
- }
228
- if (mTransport )
229
- {
230
- // Free the transport
231
- chip::Platform::Delete (mTransport );
232
- mTransport = nullptr ;
233
- }
234
-
235
- if (CHIP_NO_ERROR != err && mDelegate != nullptr )
236
- {
237
- mDelegate ->OnRendezvousError (err);
238
- }
239
- break ;
240
-
241
- default :
242
- break ;
243
- };
244
181
}
245
182
246
183
void RendezvousSession::OnMessageReceived (const PacketHeader & header, const Transport::PeerAddress & source,
247
184
System::PacketBufferHandle msgBuf)
248
185
{}
249
186
250
- void RendezvousSession::InitPairingSessionHandle ()
251
- {
252
- ReleasePairingSessionHandle ();
253
- mPairingSessionHandle = chip::Platform::New<SecureSessionHandle>(
254
- mPairingSession .PeerConnection ().GetPeerNodeId (), mPairingSession .PeerConnection ().GetPeerKeyID (), mAdmin ->GetAdminId ());
255
- }
256
-
257
- void RendezvousSession::ReleasePairingSessionHandle ()
258
- {
259
- VerifyOrReturn (mPairingSessionHandle != nullptr );
260
-
261
- Transport::PeerConnectionState * state = mSecureSessionMgr ->GetPeerConnectionState (*mPairingSessionHandle );
262
- if (state != nullptr )
263
- {
264
- // Reset the transport and peer address in the active secure channel
265
- // This will allow the regular transport (e.g. UDP) to take over the existing secure channel
266
- state->SetTransport (nullptr );
267
- state->SetPeerAddress (PeerAddress{});
268
-
269
- // When the remote node ID is not specified in the initial rendezvous parameters, the connection state
270
- // is created with undefined peer node ID. Update it now.
271
- if (state->GetPeerNodeId () == kUndefinedNodeId )
272
- state->SetPeerNodeId (mParams .GetRemoteNodeId ().ValueOr (kUndefinedNodeId ));
273
- }
274
-
275
- chip::Platform::Delete (mPairingSessionHandle );
276
- mPairingSessionHandle = nullptr ;
277
- }
278
-
279
187
CHIP_ERROR RendezvousSession::WaitForPairing (uint32_t setupPINCode)
280
188
{
281
- UpdateState (State::kSecurePairing );
282
189
return mPairingSession .WaitForPairing (setupPINCode, kSpake2p_Iteration_Count ,
283
190
reinterpret_cast <const unsigned char *>(kSpake2pKeyExchangeSalt ),
284
191
strlen (kSpake2pKeyExchangeSalt ), mNextKeyId ++, this );
285
192
}
286
193
287
194
CHIP_ERROR RendezvousSession::WaitForPairing (const PASEVerifier & verifier)
288
195
{
289
- UpdateState (State::kSecurePairing );
290
196
return mPairingSession .WaitForPairing (verifier, mNextKeyId ++, this );
291
197
}
292
198
@@ -295,21 +201,9 @@ CHIP_ERROR RendezvousSession::Pair(uint32_t setupPINCode)
295
201
Messaging::ExchangeContext * ctxt = mExchangeManager ->NewContext (SecureSessionHandle (), &mPairingSession );
296
202
ReturnErrorCodeIf (ctxt == nullptr , CHIP_ERROR_INTERNAL);
297
203
298
- UpdateState (State::kSecurePairing );
299
204
CHIP_ERROR err = mPairingSession .Pair (mParams .GetPeerAddress (), setupPINCode, mNextKeyId ++, ctxt, this );
300
205
ctxt->Release ();
301
206
return err;
302
207
}
303
208
304
- void RendezvousSession::SendNetworkCredentials (const char * ssid, const char * passwd)
305
- {
306
- mNetworkProvision .SendNetworkCredentials (ssid, passwd);
307
- }
308
-
309
- void RendezvousSession::SendThreadCredentials (ByteSpan threadData)
310
- {
311
- mNetworkProvision .SendThreadCredentials (threadData);
312
- }
313
-
314
- void RendezvousSession::SendOperationalCredentials () {}
315
209
} // namespace chip
0 commit comments