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