33
33
#include < system/SystemLayer.h>
34
34
#include < system/SystemPacketBuffer.h>
35
35
36
+ #include < wifipaf/WiFiPAFError.h>
36
37
#include < wifipaf/WiFiPAFLayer.h>
37
38
#include < wifipaf/WiFiPAFLayerDelegate.h>
38
39
@@ -114,8 +115,9 @@ TEST_F(TestWiFiPAFLayer, CheckWiFiPAFTransportCapabilitiesResponseMessage)
114
115
115
116
TEST_F (TestWiFiPAFLayer, CheckPafSession)
116
117
{
118
+ InitialPafInfo ();
117
119
// Add the 1st session by giving node_id, discriminator
118
- WiFiPAF::WiFiPAFSession sessionInfo = { .role = WiFiPAF::WiFiPafRole:: kWiFiPafRole_Subscriber ,
120
+ WiFiPAF::WiFiPAFSession sessionInfo = { .role = kWiFiPafRole_Subscriber ,
119
121
.nodeId = 0x1 ,
120
122
.discriminator = 0xF01 };
121
123
EXPECT_EQ (AddPafSession (PafInfoAccess::kAccNodeInfo , sessionInfo), CHIP_NO_ERROR);
@@ -161,11 +163,14 @@ TEST_F(TestWiFiPAFLayer, CheckPafSession)
161
163
EXPECT_EQ (RmPafSession (PafInfoAccess::kAccSessionId , sessionInfo), CHIP_NO_ERROR);
162
164
sessionInfo.id = 0x2 ;
163
165
EXPECT_EQ (RmPafSession (PafInfoAccess::kAccSessionId , sessionInfo), CHIP_NO_ERROR);
166
+
167
+ EXPECT_EQ (RmPafSession (PafInfoAccess::kAccNodeInfo , sessionInfo), CHIP_ERROR_NOT_IMPLEMENTED);
168
+ EXPECT_EQ (RmPafSession (PafInfoAccess::kAccSessionId , sessionInfo), CHIP_ERROR_NOT_FOUND);
164
169
}
165
170
166
- TEST_F (TestWiFiPAFLayer, CheckNewEndpoint )
171
+ TEST_F (TestWiFiPAFLayer, CheckRunAsCommissioner )
167
172
{
168
- WiFiPAFSession SessionInfo = {
173
+ WiFiPAFSession sessionInfo = {
169
174
.role = kWiFiPafRole_Subscriber ,
170
175
.id = 1 ,
171
176
.peer_id = 1 ,
@@ -175,8 +180,109 @@ TEST_F(TestWiFiPAFLayer, CheckNewEndpoint)
175
180
};
176
181
177
182
WiFiPAFEndPoint * newEndPoint = nullptr ;
178
- EXPECT_EQ (NewEndPoint (&newEndPoint, SessionInfo, SessionInfo .role ), CHIP_NO_ERROR);
183
+ EXPECT_EQ (NewEndPoint (&newEndPoint, sessionInfo, sessionInfo .role ), CHIP_NO_ERROR);
179
184
EXPECT_NE (newEndPoint, nullptr );
185
+ newEndPoint->mState = WiFiPAFEndPoint::kState_Ready ;
186
+ SetWiFiPAFState (State::kInitialized );
187
+ EXPECT_EQ (GetWiFiPAFState (), State::kInitialized );
188
+
189
+ EXPECT_EQ (newEndPoint->StartConnect (), CHIP_NO_ERROR);
190
+ EXPECT_EQ (AddPafSession (PafInfoAccess::kAccSessionId , sessionInfo), CHIP_NO_ERROR);
191
+ newEndPoint->mState = WiFiPAFEndPoint::kState_Connected ;
192
+
193
+ // Send the capability request packet
194
+ constexpr uint8_t bufCapReq[] = { 0x65 , 0x6c , 0x04 , 0x00 , 0x00 , 0x00 , 0x5e , 0x01 , 0x06 };
195
+ auto packetCapReq = System::PacketBufferHandle::NewWithData (bufCapReq, sizeof (bufCapReq));
196
+ EXPECT_EQ (SendMessage (sessionInfo, std::move (packetCapReq)), CHIP_NO_ERROR);
197
+ EXPECT_EQ (HandleWriteConfirmed (sessionInfo, true ), CHIP_NO_ERROR);
198
+
199
+ // Receive the capability response packet
200
+ constexpr uint8_t bufCapResp[] = { 0x65 , 0x6c , 0x04 , 0x5b , 0x01 , 0x06 };
201
+ auto packetCapResp = System::PacketBufferHandle::NewWithData (bufCapResp, sizeof (bufCapResp));
202
+ newEndPoint->mState = WiFiPAFEndPoint::kState_Connecting ;
203
+ EXPECT_EQ (OnWiFiPAFMessageReceived (sessionInfo, std::move (packetCapResp)), true );
204
+
205
+ // Send a packet
206
+ auto buf = System::PacketBufferHandle::New (100 );
207
+ buf->SetDataLength (100 );
208
+ EXPECT_EQ (SendMessage (sessionInfo, std::move (buf)), CHIP_NO_ERROR);
209
+ EXPECT_EQ (HandleWriteConfirmed (sessionInfo, true ), CHIP_NO_ERROR);
210
+
211
+ constexpr uint8_t buf_rx[] = {
212
+ to_underlying (WiFiPAFTP::HeaderFlags::kStartMessage ) | to_underlying (WiFiPAFTP::HeaderFlags::kEndMessage ) | to_underlying (WiFiPAFTP::HeaderFlags::kFragmentAck ),
213
+ 0x01 ,
214
+ 0x01 ,
215
+ 0x00 ,
216
+ 0x00 , // payload
217
+ };
218
+
219
+ // Receive a pcaket
220
+ auto packet_rx = System::PacketBufferHandle::NewWithData (buf_rx, sizeof (buf_rx));
221
+ EXPECT_EQ (packet_rx->DataLength (), static_cast <size_t >(5 ));
222
+ EXPECT_EQ (newEndPoint->Receive (std::move (packet_rx)), CHIP_NO_ERROR);
223
+
224
+ EXPECT_EQ (newEndPoint->DriveStandAloneAck (), CHIP_NO_ERROR);
225
+ EXPECT_EQ (newEndPoint->DoSendStandAloneAck (), CHIP_NO_ERROR);
226
+
227
+ // Close the session
228
+ EXPECT_EQ (RmPafSession (PafInfoAccess::kAccSessionId , sessionInfo), CHIP_NO_ERROR);
229
+ newEndPoint->DoClose (kWiFiPAFCloseFlag_AbortTransmission , WIFIPAF_ERROR_APP_CLOSED_CONNECTION);
230
+ }
231
+
232
+ TEST_F (TestWiFiPAFLayer, CheckRunAsCommissionee)
233
+ {
234
+ WiFiPAFSession sessionInfo = {
235
+ .role = kWiFiPafRole_Publisher ,
236
+ .id = 1 ,
237
+ .peer_id = 1 ,
238
+ .peer_addr = { 0xd0 , 0x17 , 0x69 , 0xee , 0x7f , 0x3c },
239
+ .nodeId = 1 ,
240
+ .discriminator = 0xF00 ,
241
+ };
242
+
243
+ WiFiPAFEndPoint * newEndPoint = nullptr ;
244
+ EXPECT_EQ (NewEndPoint (&newEndPoint, sessionInfo, sessionInfo.role ), CHIP_NO_ERROR);
245
+ EXPECT_NE (newEndPoint, nullptr );
246
+ newEndPoint->mState = WiFiPAFEndPoint::kState_Ready ;
247
+
248
+ EXPECT_EQ (newEndPoint->StartConnect (), CHIP_NO_ERROR);
249
+ EXPECT_EQ (AddPafSession (PafInfoAccess::kAccSessionId , sessionInfo), CHIP_NO_ERROR);
250
+
251
+ newEndPoint->mState = WiFiPAFEndPoint::kState_Ready ;
252
+
253
+ // Receive the Capability_Request packet
254
+ constexpr uint8_t bufCapReq[] = { 0x65 , 0x6c , 0x04 , 0x00 , 0x00 , 0x00 , 0x5e , 0x01 , 0x06 };
255
+ auto packetCapReq = System::PacketBufferHandle::NewWithData (bufCapReq, sizeof (bufCapReq));
256
+ EXPECT_EQ (OnWiFiPAFMessageReceived (sessionInfo, std::move (packetCapReq)), true );
257
+
258
+ // Reply the Capability Response packet
259
+ constexpr uint8_t bufCapResp[] = { 0x65 , 0x6c , 0x04 , 0x5b , 0x01 , 0x06 };
260
+ auto packetCapResp = System::PacketBufferHandle::NewWithData (bufCapResp, sizeof (bufCapResp));
261
+ EXPECT_EQ (SendMessage (sessionInfo, std::move (packetCapResp)), CHIP_NO_ERROR);
262
+ EXPECT_EQ (HandleWriteConfirmed (sessionInfo, true ), CHIP_NO_ERROR);
263
+
264
+ // Send a packet
265
+ auto buf = System::PacketBufferHandle::New (100 );
266
+ buf->SetDataLength (100 );
267
+ EXPECT_EQ (SendMessage (sessionInfo, std::move (buf)), CHIP_NO_ERROR);
268
+ EXPECT_EQ (HandleWriteConfirmed (sessionInfo, true ), CHIP_NO_ERROR);
269
+
270
+ // Receive a packet
271
+ constexpr uint8_t buf_rx[] = {
272
+ to_underlying (WiFiPAFTP::HeaderFlags::kStartMessage ) | to_underlying (WiFiPAFTP::HeaderFlags::kEndMessage ) | to_underlying (WiFiPAFTP::HeaderFlags::kFragmentAck ),
273
+ 0x01 ,
274
+ 0x01 ,
275
+ 0x00 ,
276
+ 0x00 , // payload
277
+ };
278
+ auto packet_rx = System::PacketBufferHandle::NewWithData (buf_rx, sizeof (buf_rx));
279
+ EXPECT_EQ (packet_rx->DataLength (), static_cast <size_t >(5 ));
280
+ EXPECT_EQ (newEndPoint->Receive (std::move (packet_rx)), CHIP_NO_ERROR);
281
+
282
+ // Close the session
283
+ EXPECT_EQ (RmPafSession (PafInfoAccess::kAccSessionId , sessionInfo), CHIP_NO_ERROR);
284
+ newEndPoint->DoClose (kWiFiPAFCloseFlag_AbortTransmission , WIFIPAF_ERROR_APP_CLOSED_CONNECTION);
285
+
180
286
}
181
287
}; // namespace WiFiPAF
182
288
}; // namespace chip
0 commit comments