blob: 7664a8df8349eeb5e74f92f6b4d03697a430bd54 [file] [log] [blame]
Ilia Linf1c1fb32021-05-04 15:55:34 +03001/*
2 * Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <unistd.h>
33#include <string.h>
34#include <stdint.h>
35#include "hton.h" /* for htonl*/
36#include "RNDISAggregationTestFixture.h"
37#include "Constants.h"
38#include "TestsUtils.h"
39#include "linux/msm_ipa.h"
40
41#define IPV4_DST_ADDR_OFFSET (16)
42#define IPV4_DST_ADDR_OFFSET_IN_ETH \
43 (16 /* IP */ + 14 /* ethernet */)
44#define IPV4_DST_ADDR_OFFSET_IN_RNDIS \
45 (IPV4_DST_ADDR_OFFSET_IN_ETH + \
46 sizeof(struct RndisHeader))
47
48#define NUM_PACKETS (4)
49
50class RNDISAggregationSanityTest: public RNDISAggregationTestFixture {
51public:
52
53 /////////////////////////////////////////////////////////////////////////////////
54
55 RNDISAggregationSanityTest()
56 {
57 m_name = "RNDISAggregationSanityTest";
58 m_description = "RNDISAggregationSanityTest - Send one packet "
59 "and expect same packet.";
60 }
61
62 /////////////////////////////////////////////////////////////////////////////////
63
64 virtual bool AddRules()
65 {
66 return AddRulesNoAgg();
67 } // AddRules()
68
69 /////////////////////////////////////////////////////////////////////////////////
70
71 bool TestLogic()
72 {
73 //The packets that will be sent
74 Byte pPacket[MAX_PACKET_SIZE];
75 //Buffer for the packet that will be received
76 Byte pReceivedPacket[2*MAX_PACKET_SIZE];
77 //Total size of all sent packets (this is the max size of the aggregated
78 //packet minus the size of the header and the NDP)
79 //int nTotalPacketsSize = MAX_PACKET_SIZE - (4 * NUM_PACKETS) - 24;
80 uint32_t nIPv4DSTAddr;
81 size_t pIpPacketsSize;
82
83 //initialize the packets
84 // Load input data (Ethernet packet) from file
85 pIpPacketsSize = MAX_PACKET_SIZE;
86 if (!RNDISAggregationHelper::LoadEtherPacket(m_eIP, pPacket, pIpPacketsSize))
87 {
88 LOG_MSG_ERROR("Failed default Packet");
89 return false;
90 }
91 nIPv4DSTAddr = ntohl(0x7F000001);
92 memcpy (&pPacket[IPV4_DST_ADDR_OFFSET_IN_ETH],&nIPv4DSTAddr,
93 sizeof(nIPv4DSTAddr));
94
95
96 //send the packet
97 LOG_MSG_DEBUG("Sending packet into the A2 EMB pipe(%d bytes)\n",
98 pIpPacketsSize);
99 size_t nBytesSent = m_UsbToIpaPipe.Send(pPacket, pIpPacketsSize);
100 if (pIpPacketsSize != nBytesSent)
101 {
102 LOG_MSG_ERROR("Sending packet into the A2 EMB pipe(%d bytes) "
103 "failed!\n", pIpPacketsSize);
104 return false;
105 }
106
107 //receive the packet
108 LOG_MSG_DEBUG("Reading packet from the A2 EMB pipe(%d bytes should be there)"
109 "\n", pIpPacketsSize);
110 size_t nBytesReceived = m_IpaToUsbPipe.Receive(pReceivedPacket, MAX_PACKET_SIZE);
111 if (pIpPacketsSize != nBytesReceived)
112 {
113 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
114 "failed!\n", pIpPacketsSize);
115 print_buff(pReceivedPacket, nBytesReceived);
116 return false;
117 }
118 return RNDISAggregationHelper::ComparePackets(pReceivedPacket, nBytesReceived,
119 pPacket, pIpPacketsSize);
120 }
121
122 /////////////////////////////////////////////////////////////////////////////////
123};
124
125class RNDISAggregationDeaggregation1PacketTest: public RNDISAggregationTestFixture {
126public:
127
128 /////////////////////////////////////////////////////////////////////////////////
129
130 RNDISAggregationDeaggregation1PacketTest()
131 {
132 m_name = "RNDISAggregationDeaggregation1PacketTest";
133 m_description = "RNDISAggregationDeaggregation1PacketTest - Send 1 RNDIS packet "
134 "and expect Ethernet packet.";
135 }
136
137 /////////////////////////////////////////////////////////////////////////////////
138
139 virtual bool AddRules()
140 {
141 return AddRulesDeAggEther();
142 } // AddRules()
143
144 /////////////////////////////////////////////////////////////////////////////////
145
146 bool TestLogic()
147 {
148 //The packets that will be sent
149 Byte pPacket[MAX_PACKET_SIZE];
150 //Buffer for the packet that will be received
151 Byte pReceivedPacket[2*MAX_PACKET_SIZE];
152 //Total size of all sent packets (this is the max size of the aggregated
153 //packet minus the size of the header and the NDP)
154 //int nTotalPacketsSize = MAX_PACKET_SIZE - (4 * NUM_PACKETS) - 24;
155 uint32_t nIPv4DSTAddr;
156 size_t pIpPacketsSize;
157
158 //initialize the packets
159 // Load input data (IP packet) from file
160 pIpPacketsSize = MAX_PACKET_SIZE;
161 if (!RNDISAggregationHelper::LoadRNDISPacket(m_eIP, pPacket, pIpPacketsSize))
162 {
163 LOG_MSG_ERROR("Failed to load RNDIS Packet");
164 return false;
165 }
166 nIPv4DSTAddr = ntohl(0x7F000001);
167 memcpy (&pPacket[IPV4_DST_ADDR_OFFSET_IN_RNDIS],&nIPv4DSTAddr,
168 sizeof(nIPv4DSTAddr));
169
170 //send the packet
171 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
172 pIpPacketsSize);
173 size_t nBytesSent = m_UsbToIpaPipeDeagg.Send(pPacket, pIpPacketsSize);
174 if (pIpPacketsSize != nBytesSent)
175 {
176 LOG_MSG_ERROR("Sending packet into the A2 EMB pipe(%d bytes) "
177 "failed!\n", pIpPacketsSize);
178 return false;
179 }
180
181 //receive the packet
182 LOG_MSG_DEBUG("Reading packet from the A2 TETH pipe(%d bytes should be there)"
183 "\n", pIpPacketsSize);
184 size_t nBytesReceived = m_IpaToUsbPipe.Receive(pReceivedPacket, MAX_PACKET_SIZE);
185 if (pIpPacketsSize - sizeof(struct RndisHeader) != nBytesReceived)
186 {
187 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
188 "failed!\n", pIpPacketsSize);
189 print_buff(pReceivedPacket, nBytesReceived);
190 return false;
191 }
192 return RNDISAggregationHelper::CompareEthervsRNDISPacket(pReceivedPacket, nBytesReceived,
193 pPacket, pIpPacketsSize);
194 }
195
196 /////////////////////////////////////////////////////////////////////////////////
197};
198
199class RNDISAggregation1PacketTest: public RNDISAggregationTestFixture {
200public:
201
202 /////////////////////////////////////////////////////////////////////////////////
203
204 RNDISAggregation1PacketTest()
205 {
206 m_name = "RNDISAggregation1PacketTest";
207 m_description = "RNDISAggregation1PacketTest - Send 1 IP packet "
208 "and expect RNDIS packet.";
209 }
210
211 /////////////////////////////////////////////////////////////////////////////////
212
213 virtual bool AddRules()
214 {
215 return AddRulesAggTimeLimit();
216 } // AddRules()
217
218 /////////////////////////////////////////////////////////////////////////////////
219
220 bool TestLogic()
221 {
222 //The packets that will be sent
223 Byte pPacket[MAX_PACKET_SIZE];
224 //Buffer for the packet that will be received
225 Byte pReceivedPacket[2*MAX_PACKET_SIZE];
226 //Total size of all sent packets (this is the max size of the aggregated
227 //packet minus the size of the header and the NDP)
228 //int nTotalPacketsSize = MAX_PACKET_SIZE - (4 * NUM_PACKETS) - 24;
229 uint32_t nIPv4DSTAddr;
230 size_t pIpPacketsSize;
231
232 //initialize the packets
233 // Load input data (IP packet) from file
234 pIpPacketsSize = MAX_PACKET_SIZE;
235 if (!LoadDefaultPacket(m_eIP, pPacket, pIpPacketsSize))
236 {
237 LOG_MSG_ERROR("Failed to load Ethernet Packet");
238 return false;
239 }
240 nIPv4DSTAddr = ntohl(0x7F000001);
241 memcpy (&pPacket[IPV4_DST_ADDR_OFFSET],&nIPv4DSTAddr,
242 sizeof(nIPv4DSTAddr));
243
244 //send the packet
245 LOG_MSG_DEBUG("Sending packet into the USB pipe(%d bytes)\n",
246 pIpPacketsSize);
247 size_t nBytesSent = m_HsicToIpaPipe.Send(pPacket, pIpPacketsSize);
248 if (pIpPacketsSize != nBytesSent)
249 {
250 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
251 "failed!\n", pIpPacketsSize);
252 return false;
253 }
254
255 //receive the packet
256 LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be there)"
257 "\n", pIpPacketsSize);
258 size_t nBytesReceived = m_IpaToUsbPipeAggTime.Receive(pReceivedPacket, MAX_PACKET_SIZE);
259 if (pIpPacketsSize != nBytesReceived - sizeof(struct RndisEtherHeader))
260 {
261 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
262 "failed!\n", pIpPacketsSize);
263 print_buff(pReceivedPacket, nBytesReceived);
264 return false;
265 }
266
267
268 return RNDISAggregationHelper::CompareIPvsRNDISPacket(pPacket, pIpPacketsSize,
269 pReceivedPacket, nBytesReceived);
270 }
271
272 /////////////////////////////////////////////////////////////////////////////////
273};
274
275class RNDISAggregationSuspendWaTest: public RNDISAggregationTestFixture {
276public:
277 /////////////////////////////////////////////////////////////////////////////////
278
279 RNDISAggregationSuspendWaTest()
280 {
281 m_name = "RNDISAggregationSuspendWaTest";
282 m_description = "RNDISAggregationSuspendWaTest - Send 3 IP packet instead 4, suspend the pipe"
283 " and expect aggregation to be closed.";
284 m_minIPAHwType = IPA_HW_v3_0;
285
286 // WA not needed in IPA_3_5
287 m_maxIPAHwType = IPA_HW_v3_1;
288 }
289
290 /////////////////////////////////////////////////////////////////////////////////
291
292 virtual bool AddRules()
293 {
294 return AddRulesAggByteLimit();
295 } // AddRules()
296
297 /////////////////////////////////////////////////////////////////////////////////
298
299 bool Setup()
300 {
301 bool bRetVal = true;
302
303 bRetVal = RNDISAggregationTestFixture::Setup();
304 if (bRetVal == false) {
305 return bRetVal;
306 }
307
308 /* register test framework suspend handler to from_ipa_devs */
309 bRetVal = RegSuspendHandler(false, true, 0);
310
311 return bRetVal;
312 }
313
314 bool TestLogic()
315 {
316 /*The packets that will be sent*/
317
318 Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
319 /*Buffer for the packet that will be received*/
320 Byte pReceivedPacket[2*MAX_PACKET_SIZE];
321 /*
322 *Total size of all sent packets
323 * (this is the max size of the aggregated
324 *packet minus the size of the header and the NDP)
325 */
326 uint32_t nIPv4DSTAddr;
327 size_t pIpPacketsSizes[NUM_PACKETS];
328 size_t ExpectedPacketSize = (NUM_PACKETS - 1) * sizeof(struct RndisEtherHeader);
329
330 struct ipa_test_ep_ctrl ep_ctrl;
331
332 /* send one packet less than aggregation size in order to see the force close */
333 for(int i = 0; i < (NUM_PACKETS - 1); i++) {
334 /*
335 *initialize the packets
336 *Load input data (IP packet) from file
337 */
338 pIpPacketsSizes[i] = MAX_PACKET_SIZE;
339 if (!LoadDefaultPacket(m_eIP, pPackets[i], pIpPacketsSizes[i]))
340 {
341 LOG_MSG_ERROR("Failed to load Ethernet Packet");
342 return false;
343 }
344 nIPv4DSTAddr = ntohl(0x7F000001);
345 memcpy (&pPackets[i][IPV4_DST_ADDR_OFFSET],&nIPv4DSTAddr,
346 sizeof(nIPv4DSTAddr));
347 for(int j = pIpPacketsSizes[i]; j < MAX_PACKET_SIZE / NUM_PACKETS + 1; j++) {
348 pPackets[i][j] = j & 0xFF;
349 }
350 pIpPacketsSizes[i] = MAX_PACKET_SIZE / NUM_PACKETS + 1;
351
352 /* send the packet */
353 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
354 pIpPacketsSizes[i]);
355 size_t nBytesSent = m_HsicToIpaPipe.Send(pPackets[i], pIpPacketsSizes[i]);
356 if (pIpPacketsSizes[i] != nBytesSent)
357 {
358 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
359 "failed!\n", pIpPacketsSizes[i]);
360 return false;
361 }
362 ExpectedPacketSize += pIpPacketsSizes[i];
363 }
364
365 /* suspend the pipe */
366 ep_ctrl.from_dev_num = 0;
367 ep_ctrl.ipa_ep_delay = false;
368 ep_ctrl.ipa_ep_suspend = true;
369 configure_ep_ctrl(&ep_ctrl);
370
371 /* receive the packet */
372 LOG_MSG_DEBUG(
373 "Reading packet from the USB pipe(%d bytes should be there)"
374 "\n", ExpectedPacketSize);
375 size_t nBytesReceived = m_IpaToUsbPipeAgg
376 .Receive(pReceivedPacket, MAX_PACKET_SIZE);
377 if (ExpectedPacketSize != nBytesReceived)
378 {
379 LOG_MSG_ERROR(
380 "Receiving aggregated packet from the USB pipe(%d bytes) "
381 "failed!\n", nBytesReceived);
382 print_buff(pReceivedPacket, nBytesReceived);
383 return false;
384 }
385
386
387 for(int i = 0; i < (NUM_PACKETS - 1); i++) {
388 if (!RNDISAggregationHelper::
389 CompareIPvsRNDISPacket(pPackets[i], pIpPacketsSizes[i],
390 pReceivedPacket + (i * ExpectedPacketSize / (NUM_PACKETS - 1)),
391 ExpectedPacketSize / (NUM_PACKETS - 1)))
392 return false;
393 }
394
395 return true;
396 }
397
398 bool Teardown()
399 {
400 bool bRetVal = true;
401
402 bRetVal = RNDISAggregationTestFixture::Teardown();
403 if (bRetVal == false) {
404 return bRetVal;
405 }
406
407 /* unregister the test framework suspend handler */
408 bRetVal = RegSuspendHandler(false, false, 0);
409
410 return bRetVal;
411 }
412};
413
414class RNDISAggregationByteLimitTest: public RNDISAggregationTestFixture {
415public:
416
417 /////////////////////////////////////////////////////////////////////////////////
418
419 RNDISAggregationByteLimitTest()
420 {
421 m_name = "RNDISAggregationByteLimitTest";
422 m_description = "RNDISAggregationByteLimitTest - Send 2 IP packet "
423 "and expect aggregated RNDIS packet.";
424 }
425
426 /////////////////////////////////////////////////////////////////////////////////
427
428 virtual bool AddRules()
429 {
430 return AddRulesAggByteLimit();
431 } // AddRules()
432
433 /////////////////////////////////////////////////////////////////////////////////
434
435 bool TestLogic()
436 {
437 /*The packets that will be sent*/
438
439 Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
440 /*Buffer for the packet that will be received*/
441 Byte pReceivedPacket[2*MAX_PACKET_SIZE];
442 /*Total size of all sent packets
443 * (this is the max size of the aggregated
444 *packet minus the size of the header and the NDP)
445 */
446 uint32_t nIPv4DSTAddr;
447 size_t pIpPacketsSizes[NUM_PACKETS];
448 size_t ExpectedPacketSize = NUM_PACKETS * sizeof(struct RndisEtherHeader);
449
450 for(int i = 0; i < NUM_PACKETS; i++) {
451 /*
452 *initialize the packets
453 *Load input data (IP packet) from file
454 */
455 pIpPacketsSizes[i] = MAX_PACKET_SIZE;
456 if (!LoadDefaultPacket(m_eIP, pPackets[i], pIpPacketsSizes[i]))
457 {
458 LOG_MSG_ERROR("Failed to load Ethernet Packet");
459 return false;
460 }
461 nIPv4DSTAddr = ntohl(0x7F000001);
462 memcpy (&pPackets[i][IPV4_DST_ADDR_OFFSET],&nIPv4DSTAddr,
463 sizeof(nIPv4DSTAddr));
464 for(int j = pIpPacketsSizes[i]; j < MAX_PACKET_SIZE / NUM_PACKETS + 1; j++) {
465 pPackets[i][j] = j & 0xFF;
466 }
467 pIpPacketsSizes[i] = MAX_PACKET_SIZE / NUM_PACKETS + 1;
468
469 /* send the packet */
470 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
471 pIpPacketsSizes[i]);
472 size_t nBytesSent = m_HsicToIpaPipe.Send(pPackets[i], pIpPacketsSizes[i]);
473 if (pIpPacketsSizes[i] != nBytesSent)
474 {
475 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
476 "failed!\n", pIpPacketsSizes[i]);
477 return false;
478 }
479 ExpectedPacketSize += pIpPacketsSizes[i];
480 }
481
482 /* receive the packet */
483 LOG_MSG_DEBUG(
484 "Reading packet from the USB pipe(%d bytes should be there)"
485 "\n", ExpectedPacketSize);
486 size_t nBytesReceived = m_IpaToUsbPipeAgg
487 .Receive(pReceivedPacket, MAX_PACKET_SIZE);
488 if (ExpectedPacketSize != nBytesReceived)
489 {
490 LOG_MSG_ERROR(
491 "Receiving aggregated packet from the USB pipe(%d bytes) "
492 "failed!\n", nBytesReceived);
493 print_buff(pReceivedPacket, nBytesReceived);
494 return false;
495 }
496
497
498 for(int i = 0; i < NUM_PACKETS; i++) {
499 if (!RNDISAggregationHelper::
500 CompareIPvsRNDISPacket(pPackets[i], pIpPacketsSizes[i],
501 pReceivedPacket + (i * ExpectedPacketSize / NUM_PACKETS),
502 ExpectedPacketSize / NUM_PACKETS))
503 return false;
504 }
505
506 return true;
507 }
508};
509
510class RNDISAggregationByteLimitTestFC : public RNDISAggregationTestFixture {
511public:
512
513 /////////////////////////////////////////////////////////////////////////////////
514
515 RNDISAggregationByteLimitTestFC() {
516 m_name = "RNDISAggregationByteLimitTestFC";
517 m_description = "RNDISAggregationByteLimitTestFC - Send 4 IP packet with FC"
518 "and expect 4 aggregated RNDIS packets.";
519 }
520
521 /////////////////////////////////////////////////////////////////////////////////
522
523 virtual bool AddRules() {
524 return AddRulesAggByteLimit(true);
525 } // AddRules()
526
527 /////////////////////////////////////////////////////////////////////////////////
528
529 bool TestLogic() {
530 /*The packets that will be sent*/
531
532 Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
533 /*Buffer for the packets that will be received*/
534 Byte pReceivedPacket[NUM_PACKETS][MAX_PACKET_SIZE];
535 /*Total size of all sent packets
536 * (this is the max size of the aggregated
537 *packet minus the size of the header and the NDP)
538 */
539 uint32_t nIPv4DSTAddr;
540 size_t pIpPacketsSizes[NUM_PACKETS];
541 size_t ExpectedPacketSize =
542 sizeof(struct RndisEtherHeader) + MAX_PACKET_SIZE / NUM_PACKETS + 1;
543
544 for (int i = 0; i < NUM_PACKETS; i++) {
545 /*
546 *initialize the packets
547 *Load input data (IP packet) from file
548 */
549 pIpPacketsSizes[i] = MAX_PACKET_SIZE;
550 if (!LoadDefaultPacket(m_eIP, pPackets[i], pIpPacketsSizes[i])) {
551 LOG_MSG_ERROR("Failed to load Ethernet Packet");
552 return false;
553 }
554 nIPv4DSTAddr = ntohl(0x7F000001);
555 memcpy(&pPackets[i][IPV4_DST_ADDR_OFFSET], &nIPv4DSTAddr,
556 sizeof(nIPv4DSTAddr));
557 for (int j = pIpPacketsSizes[i]; j < MAX_PACKET_SIZE / NUM_PACKETS + 1; j++) {
558 pPackets[i][j] = j & 0xFF;
559 }
560 pIpPacketsSizes[i] = MAX_PACKET_SIZE / NUM_PACKETS + 1;
561
562 /* send the packet */
563 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
564 pIpPacketsSizes[i]);
565 size_t nBytesSent = m_HsicToIpaPipe.Send(pPackets[i], pIpPacketsSizes[i]);
566 if (pIpPacketsSizes[i] != nBytesSent) {
567 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
568 "failed!\n", pIpPacketsSizes[i]);
569 return false;
570 }
571 }
572
573 /* receive the packet */
574 LOG_MSG_DEBUG(
575 "Reading packets from the USB pipe(%d bytes for each)"
576 "\n", ExpectedPacketSize);
577 for (int i = 0; i < NUM_PACKETS; i++) {
578 size_t nBytesReceived = m_IpaToUsbPipeAgg
579 .Receive(pReceivedPacket[i], MAX_PACKET_SIZE);
580 if (ExpectedPacketSize != nBytesReceived) {
581 LOG_MSG_ERROR(
582 "Receiving aggregated packet from the USB pipe(%d bytes) "
583 "failed!\n", nBytesReceived);
584 print_buff(pReceivedPacket[i], nBytesReceived);
585 return false;
586 }
587 print_buff(pReceivedPacket, nBytesReceived);
588 }
589
590
591 for (int i = 0; i < NUM_PACKETS; i++) {
592 if (!RNDISAggregationHelper::CompareIPvsRNDISPacket(
593 pPackets[i],
594 pIpPacketsSizes[i],
595 pReceivedPacket[i],
596 ExpectedPacketSize)) return false;
597 }
598
599 return true;
600 }
601};
602
603class RNDISAggregationDualDpTestFC : public RNDISAggregationTestFixture {
604public:
605
606 /////////////////////////////////////////////////////////////////////////////////
607
608 RNDISAggregationDualDpTestFC() {
609 m_name = "RNDISAggregationDualDpTestFC";
610 m_description = "RNDISAggregationDualDpTestFC - Send IP packets "
611 "on two datapathes: one with FC and one without. "
612 "Expect 2 aggregated RNDIS packets on pipe with FC. "
613 "Expect one aggregated RNDIS packet on pipe without FC. ";
614 }
615
616 /////////////////////////////////////////////////////////////////////////////////
617
618 virtual bool AddRules() {
619 return AddRulesAggDualFC();
620 }
621
622 /////////////////////////////////////////////////////////////////////////////////
623
624 bool TestLogic() {
625 int i;
626 /* The packets that will be sent */
627 Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
628 /* Buffer for the packets that will be received */
629 Byte pReceivedPacket[(NUM_PACKETS / 2) * MAX_PACKET_SIZE];
630 Byte pReceivedPacketFC[NUM_PACKETS / 2][MAX_PACKET_SIZE];
631 /*
632 * Total size of all sent packets
633 * (this is the max size of the aggregated
634 * packet minus the size of the header and the NDP)
635 */
636 uint32_t nIPv4DSTAddr;
637 size_t nBytesReceived;
638 size_t pIpPacketsSizes[NUM_PACKETS];
639 size_t ExpectedPacketSize =
640 sizeof(struct RndisEtherHeader) + MAX_PACKET_SIZE / NUM_PACKETS + 1;
641
642 for (i = 0; i < NUM_PACKETS; i++) {
643 /*
644 * Initialize the packets
645 * Load input data (IP packet) from file
646 */
647 pIpPacketsSizes[i] = MAX_PACKET_SIZE;
648 if (!LoadDefaultPacket(m_eIP, pPackets[i], pIpPacketsSizes[i])) {
649 LOG_MSG_ERROR("Failed to load Ethernet Packet");
650 return false;
651 }
652 /*
653 * Half of the packets will go to 127.0.0.1
654 * and the other half to 127.0.0.2
655 */
656 nIPv4DSTAddr = ntohl(0x7F000001 + (i & 0x1));
657 memcpy(&pPackets[i][IPV4_DST_ADDR_OFFSET], &nIPv4DSTAddr,
658 sizeof(nIPv4DSTAddr));
659 for (int j = pIpPacketsSizes[i]; j < MAX_PACKET_SIZE / NUM_PACKETS + 1; j++) {
660 pPackets[i][j] = j & 0xFF;
661 }
662 pIpPacketsSizes[i] = MAX_PACKET_SIZE / NUM_PACKETS + 1;
663
664 /* send the packet */
665 LOG_MSG_DEBUG("Sending packet into the m_HsicToIpaPipe pipe (%d bytes)\n",
666 pIpPacketsSizes[i]);
667 print_buff(pPackets[i], pIpPacketsSizes[i]);
668 size_t nBytesSent = m_HsicToIpaPipe.Send(pPackets[i], pIpPacketsSizes[i]);
669 if (pIpPacketsSizes[i] != nBytesSent) {
670 LOG_MSG_ERROR("Sending packet into the m_HsicToIpaPipe pipe (%d bytes) "
671 "failed!\n", pIpPacketsSizes[i]);
672 return false;
673 }
674 }
675
676 /* receive the packets from FC pipe */
677 LOG_MSG_DEBUG(
678 "Reading packets from the m_IpaToUsbPipeAgg pipe (%d bytes for each)"
679 "\n", ExpectedPacketSize);
680 for (i = 0; i < NUM_PACKETS / 2; i++) {
681 nBytesReceived = m_IpaToUsbPipeAgg
682 .Receive(pReceivedPacketFC[i], MAX_PACKET_SIZE);
683 if (ExpectedPacketSize != nBytesReceived) {
684 LOG_MSG_ERROR(
685 "Receiving aggregated packet from the m_IpaToUsbPipeAgg pipe (%d bytes) "
686 "failed!\n", nBytesReceived);
687 print_buff(pReceivedPacketFC[i], nBytesReceived);
688 return false;
689 }
690 }
691
692 for (i = 0; i < NUM_PACKETS / 2; i++) {
693 if (!RNDISAggregationHelper::CompareIPvsRNDISPacket(
694 pPackets[i * 2],
695 pIpPacketsSizes[i * 2],
696 pReceivedPacketFC[i],
697 ExpectedPacketSize)) return false;
698 }
699
700 /* receive the packet from non-FC pipe */
701 LOG_MSG_DEBUG(
702 "Reading packet from the m_IpaToUsbPipeAggPktLimit pipe (%d bytes)"
703 "\n", ExpectedPacketSize * 2);
704 nBytesReceived = m_IpaToUsbPipeAggPktLimit
705 .Receive(pReceivedPacket, MAX_PACKET_SIZE);
706 if (ExpectedPacketSize * 2 != nBytesReceived) {
707 LOG_MSG_ERROR(
708 "Receiving aggregated packets from the m_IpaToUsbPipeAggPktLimit pipe (%d bytes) "
709 "failed!\n", nBytesReceived);
710 print_buff(pReceivedPacket, nBytesReceived);
711 return false;
712 }
713
714 for (int i = 0; i < NUM_PACKETS; i += 2) {
715 if (!RNDISAggregationHelper::CompareIPvsRNDISPacket(
716 pPackets[i + 1], // Odd packets are in the second pipe
717 pIpPacketsSizes[i + 1],
718 pReceivedPacket + (i * ExpectedPacketSize / 2),
719 ExpectedPacketSize))
720 return false;
721 }
722
723 return true;
724 }
725};
726
727class RNDISAggregationDualDpTestFcRoutingBased : public RNDISAggregationTestFixture {
728public:
729
730 /////////////////////////////////////////////////////////////////////////////////
731
732 RNDISAggregationDualDpTestFcRoutingBased() {
733 m_name = "RNDISAggregationDualDpTestFcRoutingBased";
734 m_description = "RNDISAggregationDualDpTestFcRoutingBased - Send IP packets "
735 "on two datapathes: one with RT based FC and one without. "
736 "Expect 2 aggregated RNDIS packets on pipe with RT based FC. "
737 "Expect one aggregated RNDIS packet on pipe without RT based FC. ";
738 }
739
740 /////////////////////////////////////////////////////////////////////////////////
741
742 virtual bool AddRules() {
743 return AddRulesAggDualFcRoutingBased();
744 }
745
746 /////////////////////////////////////////////////////////////////////////////////
747
748 bool TestLogic() {
749 int i;
750 /* The packets that will be sent */
751 Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
752 /* Buffer for the packets that will be received */
753 Byte pReceivedPacket[(NUM_PACKETS / 2) * MAX_PACKET_SIZE];
754 Byte pReceivedPacketFC[NUM_PACKETS / 2][MAX_PACKET_SIZE];
755 /*
756 * Total size of all sent packets
757 * (this is the max size of the aggregated
758 * packet minus the size of the header and the NDP)
759 */
760 uint32_t nIPv4DSTAddr;
761 size_t nBytesReceived;
762 size_t pIpPacketsSizes[NUM_PACKETS];
763 size_t ExpectedPacketSize =
764 sizeof(struct RndisEtherHeader) + MAX_PACKET_SIZE / NUM_PACKETS + 1;
765
766 for (i = 0; i < NUM_PACKETS; i++) {
767 /*
768 * Initialize the packets
769 * Load input data (IP packet) from file
770 */
771 pIpPacketsSizes[i] = MAX_PACKET_SIZE;
772 if (!LoadDefaultPacket(m_eIP, pPackets[i], pIpPacketsSizes[i])) {
773 LOG_MSG_ERROR("Failed to load Ethernet Packet");
774 return false;
775 }
776 /*
777 * Half of the packets will go to 127.0.0.1
778 * and the other half to 127.0.0.2
779 */
780 nIPv4DSTAddr = ntohl(0x7F000001 + (i & 0x1));
781 memcpy(&pPackets[i][IPV4_DST_ADDR_OFFSET], &nIPv4DSTAddr,
782 sizeof(nIPv4DSTAddr));
783 for (int j = pIpPacketsSizes[i]; j < MAX_PACKET_SIZE / NUM_PACKETS + 1; j++) {
784 pPackets[i][j] = j & 0xFF;
785 }
786 pIpPacketsSizes[i] = MAX_PACKET_SIZE / NUM_PACKETS + 1;
787
788 /* send the packet */
789 LOG_MSG_DEBUG("Sending packet into the m_HsicToIpaPipe pipe (%d bytes)\n",
790 pIpPacketsSizes[i]);
791 print_buff(pPackets[i], pIpPacketsSizes[i]);
792 size_t nBytesSent = m_HsicToIpaPipe.Send(pPackets[i], pIpPacketsSizes[i]);
793 if (pIpPacketsSizes[i] != nBytesSent) {
794 LOG_MSG_ERROR("Sending packet into the m_HsicToIpaPipe pipe (%d bytes) "
795 "failed!\n", pIpPacketsSizes[i]);
796 return false;
797 }
798 }
799
800 /* receive the packets from FC pipe */
801 LOG_MSG_DEBUG(
802 "Reading packets from the m_IpaToUsbPipeAgg pipe (%d bytes for each)"
803 "\n", ExpectedPacketSize);
804 for (i = 0; i < NUM_PACKETS / 2; i++) {
805 nBytesReceived = m_IpaToUsbPipeAgg
806 .Receive(pReceivedPacketFC[i], MAX_PACKET_SIZE);
807 if (ExpectedPacketSize != nBytesReceived) {
808 LOG_MSG_ERROR(
809 "Receiving aggregated packet from the m_IpaToUsbPipeAgg pipe (%d bytes) "
810 "failed!\n", nBytesReceived);
811 print_buff(pReceivedPacketFC[i], nBytesReceived);
812 return false;
813 }
814 }
815
816 for (i = 0; i < NUM_PACKETS / 2; i++) {
817 if (!RNDISAggregationHelper::CompareIPvsRNDISPacket(
818 pPackets[i * 2],
819 pIpPacketsSizes[i * 2],
820 pReceivedPacketFC[i],
821 ExpectedPacketSize)) return false;
822 }
823
824 /* receive the packet from non-FC pipe */
825 LOG_MSG_DEBUG(
826 "Reading packet from the m_IpaToUsbPipeAggPktLimit pipe (%d bytes)"
827 "\n", ExpectedPacketSize * 2);
828 nBytesReceived = m_IpaToUsbPipeAggPktLimit
829 .Receive(pReceivedPacket, MAX_PACKET_SIZE);
830 if (ExpectedPacketSize * 2 != nBytesReceived) {
831 LOG_MSG_ERROR(
832 "Receiving aggregated packets from the m_IpaToUsbPipeAggPktLimit pipe (%d bytes) "
833 "failed!\n", nBytesReceived);
834 print_buff(pReceivedPacket, nBytesReceived);
835 return false;
836 }
837
838 for (int i = 0; i < NUM_PACKETS; i += 2) {
839 if (!RNDISAggregationHelper::CompareIPvsRNDISPacket(
840 pPackets[i + 1], // Odd packets are in the second pipe
841 pIpPacketsSizes[i + 1],
842 pReceivedPacket + (i * ExpectedPacketSize / 2),
843 ExpectedPacketSize))
844 return false;
845 }
846
847 return true;
848 }
849};
850
851class RNDISAggregationDeaggregationNumPacketsTest:
852 public RNDISAggregationTestFixture {
853public:
854
855 RNDISAggregationDeaggregationNumPacketsTest()
856 {
857 m_name = "RNDISAggregationDeaggregationNumPacketsTest";
858 m_description = "RNDISAggregationByteLimitTest - Send on IP packet "
859 "and expect aggregated RNDIS packet.";
860 }
861
862 virtual bool AddRules()
863 {
864 return AddRulesDeAggEther();
865 } /* AddRules()*/
866
867 bool TestLogic()
868 {
869 /*the packets that will be sent*/
870 Byte pPacket[MAX_PACKET_SIZE];
871 //Buffer for the packet that will be received
872 Byte pReceivedPacket[2*MAX_PACKET_SIZE];
873 //Total size of all sent packets (this is the max size of the aggregated
874 //packet minus the size of the header and the NDP)
875 uint32_t nIPv4DSTAddr;
876 size_t pIpPacketsSize;
877 size_t pAggrPacketsSize = 0;
878
879 for(int i = 0; i < NUM_PACKETS; i++) {
880 //initialize the packets
881 // Load input data (RNDIS packet) from file
882 pIpPacketsSize = MAX_PACKET_SIZE;
883 if (!RNDISAggregationHelper::LoadRNDISPacket(m_eIP, pPacket + pAggrPacketsSize, pIpPacketsSize))
884 {
885 LOG_MSG_ERROR("Failed to load Ethernet Packet");
886 return false;
887 }
888 pAggrPacketsSize += pIpPacketsSize;
889 nIPv4DSTAddr = ntohl(0x7F000001);
890 memcpy (&((pPacket + i * pIpPacketsSize)[IPV4_DST_ADDR_OFFSET_IN_RNDIS]),&nIPv4DSTAddr,
891 sizeof(nIPv4DSTAddr));
892 }
893 print_buff(pPacket, pAggrPacketsSize);
894
895 /*send the packet*/
896 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
897 pIpPacketsSize * NUM_PACKETS);
898 size_t nBytesSent = m_UsbToIpaPipeDeagg.Send(pPacket, pAggrPacketsSize);
899 if (pAggrPacketsSize != nBytesSent)
900 {
901 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
902 "failed!\n", pIpPacketsSize * NUM_PACKETS);
903 return false;
904 }
905 for(int i = 0; i < NUM_PACKETS; i++) {
906 //receive the packet, one by one
907 LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be there)"
908 "\n", pIpPacketsSize - sizeof(struct RndisHeader));
909 size_t nBytesReceived = m_IpaToUsbPipe.Receive(pReceivedPacket, MAX_PACKET_SIZE);
910 if (pIpPacketsSize - sizeof(struct RndisHeader) != nBytesReceived)
911 {
912 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
913 "failed!\n", nBytesReceived);
914 print_buff(pReceivedPacket, nBytesReceived);
915 return false;
916 }
917 if (!RNDISAggregationHelper::CompareEthervsRNDISPacket(pReceivedPacket,
918 nBytesReceived,
919 pPacket + i * pIpPacketsSize,
920 pIpPacketsSize))
921 return false;
922 }
923
924 return true;
925 }
926
927 /////////////////////////////////////////////////////////////////////////////////
928};
929
930class RNDISAggregationDeaggregationExceptionPacketsTest:
931 public RNDISAggregationTestFixture {
932public:
933
934 RNDISAggregationDeaggregationExceptionPacketsTest()
935 {
936 m_name = "RNDISAggregationDeaggregationExceptionPacketsTest";
937 m_description = "RNDISAggregationDeaggregationExceptionPacketsTest - Send 5 frames "
938 "of size 43 bytes, 1025 bytes, 43 bytes, 981 bytes, and 1024 bytes "
939 "and expect aggregated RNDIS packet.";
940 }
941
942 virtual bool AddRules()
943 {
944 return AddRulesDeAggEther();
945 } /* AddRules()*/
946
947 bool TestLogic()
948 {
949 /*the packets that will be sent*/
950 Byte pPacket[MAX_PACKET_SIZE];
951 Byte pPacket1[MAX_PACKET_SIZE +1];
952 Byte pPacket2[MAX_PACKET_SIZE];
953 Byte pPacket3[MAX_PACKET_SIZE];
954
955 //Buffer for the packet that will be received
956 Byte pReceivedPacket[2*MAX_PACKET_SIZE];
957 //Total size of all sent packets (this is the max size of the aggregated
958 //packet minus the size of the header and the NDP)
959 uint32_t nIPv4DSTAddr;
960 size_t pIpPacketsSize;
961 size_t pAggrPacketsSize = 0;
962 size_t nBytesSent;
963 size_t nBytesReceived;
964
965 /* Create the frame of size 43 bytes which is one less byte than RNDIS header */
966 pAggrPacketsSize = sizeof(struct RndisHeader) - 1;
967 struct RndisHeader *pRndisHeader = (struct RndisHeader*)pPacket;
968 memset(pRndisHeader, 0, (sizeof(struct RndisHeader) - 1));
969 pRndisHeader->MessageType = 0x01;
970 pRndisHeader->MessageLength = pAggrPacketsSize;
971 pRndisHeader->DataOffset = 0x24;
972 pRndisHeader->DataLength = 0;
973
974 nIPv4DSTAddr = ntohl(0x7F000001);
975 memcpy (&((pPacket)[IPV4_DST_ADDR_OFFSET_IN_RNDIS]),&nIPv4DSTAddr,
976 sizeof(nIPv4DSTAddr));
977 print_buff(pPacket, pAggrPacketsSize);
978
979 /* Send the first frame */
980 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
981 pAggrPacketsSize);
982 nBytesSent = m_UsbToIpaPipeDeagg.Send(pPacket, pAggrPacketsSize);
983 if (pAggrPacketsSize != nBytesSent)
984 {
985 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
986 "failed!\n", pAggrPacketsSize);
987 return false;
988 }
989 /* This is deaggregation exception packet, this packet should not arrive at this pipe */
990 LOG_MSG_DEBUG("Reading packet from the USB pipe(0 bytes should be there)\n");
991 nBytesReceived = m_IpaToUsbPipe.Receive(pReceivedPacket, MAX_PACKET_SIZE);
992 if (0 != nBytesReceived)
993 {
994 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
995 "failed!\n", nBytesReceived);
996 print_buff(pReceivedPacket, nBytesReceived);
997 return false;
998 }
999
1000 /* Create a frame of size 1025 bytes */
1001 pAggrPacketsSize = 0;
1002 for(int i = 0; i < 8; i++) {
1003 //initialize the packets
1004 // Load input data (RNDIS packet) from file
1005 pIpPacketsSize = MAX_PACKET_SIZE;
1006 if (!RNDISAggregationHelper::LoadRNDISPacket(m_eIP, pPacket1 + pAggrPacketsSize, pIpPacketsSize))
1007 {
1008 LOG_MSG_ERROR("Failed to load Ethernet Packet");
1009 return false;
1010 }
1011 pAggrPacketsSize += pIpPacketsSize;
1012 nIPv4DSTAddr = ntohl(0x7F000001);
1013 memcpy (&((pPacket1 + i * pIpPacketsSize)[IPV4_DST_ADDR_OFFSET_IN_RNDIS]),&nIPv4DSTAddr,
1014 sizeof(nIPv4DSTAddr));
1015 }
1016
1017 pPacket1[pAggrPacketsSize] = 0xdd;
1018 pAggrPacketsSize = pAggrPacketsSize + 1;
1019
1020 print_buff(pPacket1, pAggrPacketsSize);
1021
1022 /* Send the 2nd frame */
1023 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
1024 pAggrPacketsSize);
1025 nBytesSent = m_UsbToIpaPipeDeagg.Send(pPacket1, pAggrPacketsSize);
1026 if (pAggrPacketsSize != nBytesSent)
1027 {
1028 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
1029 "failed!\n", pAggrPacketsSize);
1030 return false;
1031 }
1032
1033 for(int i = 0; i < 8; i++) {
1034 //Receive the packet, one by one
1035 LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be there)"
1036 "\n", pIpPacketsSize - sizeof(struct RndisHeader));
1037 size_t nBytesReceived = m_IpaToUsbPipe.Receive(pReceivedPacket, MAX_PACKET_SIZE);
1038 if (pIpPacketsSize - sizeof(struct RndisHeader) != nBytesReceived)
1039 {
1040 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
1041 "failed!\n", nBytesReceived);
1042 print_buff(pReceivedPacket, nBytesReceived);
1043 return false;
1044 }
1045 if (!RNDISAggregationHelper::CompareEthervsRNDISPacket(pReceivedPacket,
1046 nBytesReceived,
1047 pPacket1 + i * pIpPacketsSize,
1048 pIpPacketsSize))
1049 return false;
1050 }
1051
1052 /* Create a frame of size 1024 bytes and send as 2 frames */
1053 pAggrPacketsSize = 0;
1054 for(int i = 0; i < 8; i++) {
1055 //initialize the packets
1056 // Load input data (RNDIS packet) from file
1057 pIpPacketsSize = MAX_PACKET_SIZE;
1058 if (!RNDISAggregationHelper::LoadRNDISPacket(m_eIP, pPacket2 + pAggrPacketsSize, pIpPacketsSize))
1059 {
1060 LOG_MSG_ERROR("Failed to load Ethernet Packet");
1061 return false;
1062 }
1063 pAggrPacketsSize += pIpPacketsSize;
1064 nIPv4DSTAddr = ntohl(0x7F000001);
1065 memcpy (&((pPacket2 + i * pIpPacketsSize)[IPV4_DST_ADDR_OFFSET_IN_RNDIS]),&nIPv4DSTAddr,
1066 sizeof(nIPv4DSTAddr));
1067 }
1068 print_buff(pPacket2, pAggrPacketsSize);
1069
1070 /* Send the 3rd frame */
1071 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n", 43);
1072 nBytesSent = m_UsbToIpaPipeDeagg.Send(pPacket2, 43);
1073 if (43 != nBytesSent)
1074 {
1075 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
1076 "failed!\n", 43);
1077
1078 return false;
1079 }
1080 /* This is deaggregation exception packet, this packet should not arrive at this pipe */
1081 LOG_MSG_DEBUG("Reading packet from the USB pipe(0 bytes should be there)\n");
1082 nBytesReceived = m_IpaToUsbPipe.Receive(pReceivedPacket, MAX_PACKET_SIZE);
1083 if (0 != nBytesReceived)
1084 {
1085 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
1086 "failed!\n", nBytesReceived);
1087 print_buff(pReceivedPacket, nBytesReceived);
1088 return false;
1089 }
1090 /* Send the 4rd frame */
1091 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
1092 pAggrPacketsSize - 43 );
1093 nBytesSent = m_UsbToIpaPipeDeagg.Send((pPacket2 + 43), pAggrPacketsSize - 43);
1094 if ((pAggrPacketsSize - 43) != nBytesSent)
1095 {
1096 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
1097 "failed!\n", pAggrPacketsSize - 43);
1098 return false;
1099 }
1100 /* This is deaggregation exception packet, this packet should not arrive at this pipe */
1101 LOG_MSG_DEBUG("Reading packet from the USB pipe(0 bytes should be there)\n");
1102 nBytesReceived = m_IpaToUsbPipe.Receive(pReceivedPacket, MAX_PACKET_SIZE);
1103 if (0 != nBytesReceived)
1104 {
1105 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
1106 "failed!\n", nBytesReceived);
1107 print_buff(pReceivedPacket, nBytesReceived);
1108 return false;
1109 }
1110
1111 /* Create a frame of size 1024 bytes */
1112 pAggrPacketsSize = 0;
1113 for(int i = 0; i < 8; i++) {
1114 //initialize the packets
1115 //Load input data (RNDIS packet) from file
1116 pIpPacketsSize = MAX_PACKET_SIZE;
1117 if (!RNDISAggregationHelper::LoadRNDISPacket(m_eIP, pPacket3 + pAggrPacketsSize, pIpPacketsSize))
1118 {
1119 LOG_MSG_ERROR("Failed to load Ethernet Packet");
1120 return false;
1121 }
1122 pAggrPacketsSize += pIpPacketsSize;
1123 nIPv4DSTAddr = ntohl(0x7F000001);
1124 memcpy (&((pPacket3 + i * pIpPacketsSize)[IPV4_DST_ADDR_OFFSET_IN_RNDIS]),&nIPv4DSTAddr,
1125 sizeof(nIPv4DSTAddr));
1126 }
1127 print_buff(pPacket3, pAggrPacketsSize);
1128
1129 /* Send the 5th frame */
1130 LOG_MSG_ERROR("blend-3 Sending packet into the A2 TETH pipe(%d bytes)\n",
1131 pAggrPacketsSize);
1132 nBytesSent = m_UsbToIpaPipeDeagg.Send(pPacket3, pAggrPacketsSize);
1133 if (pAggrPacketsSize != nBytesSent)
1134 {
1135 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
1136 "failed!\n", pAggrPacketsSize);
1137 return false;
1138 }
1139
1140 for(int i = 0; i < 8; i++) {
1141 //Receive the packet, one by one
1142 LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be there)"
1143 "\n", pIpPacketsSize - sizeof(struct RndisHeader));
1144 size_t nBytesReceived = m_IpaToUsbPipe.Receive(pReceivedPacket, MAX_PACKET_SIZE);
1145 if (pIpPacketsSize - sizeof(struct RndisHeader) != nBytesReceived)
1146 {
1147 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
1148 "failed!\n", nBytesReceived);
1149 print_buff(pReceivedPacket, nBytesReceived);
1150 return false;
1151 }
1152 if (!RNDISAggregationHelper::CompareEthervsRNDISPacket(pReceivedPacket,
1153 nBytesReceived,
1154 pPacket3 + i * pIpPacketsSize,
1155 pIpPacketsSize))
1156 return false;
1157 }
1158
1159 return true;
1160 }
1161
1162};
1163
1164class RNDISAggregationPacketLimitTest: public RNDISAggregationTestFixture {
1165public:
1166
1167 /////////////////////////////////////////////////////////////////////////////////
1168
1169 RNDISAggregationPacketLimitTest()
1170 {
1171 m_name = "RNDISAggregationPacketLimitTest";
1172 m_description = "RNDISAggregationPacketLimitTest - Send 2 IP packet "
1173 "and expect aggregated RNDIS packet.";
1174 }
1175
1176 /////////////////////////////////////////////////////////////////////////////////
1177
1178 virtual bool AddRules()
1179 {
1180 return AddRulesAggPacketLimit();
1181 } // AddRules()
1182
1183 /////////////////////////////////////////////////////////////////////////////////
1184
1185 bool TestLogic()
1186 {
1187 //The packets that will be sent
1188
1189 Byte pPackets[2][MAX_PACKET_SIZE];
1190 //Buffer for the packet that will be received
1191 Byte pReceivedPacket[2*MAX_PACKET_SIZE];
1192 //Total size of all sent packets (this is the max size of the aggregated
1193 //packet minus the size of the header and the NDP)
1194 uint32_t nIPv4DSTAddr;
1195 size_t pIpPacketsSizes[2];
1196 size_t ExpectedPacketSize = 2 * sizeof(struct RndisEtherHeader);
1197
1198 for(int i = 0; i < 2; i++) {
1199 //initialize the packets
1200 // Load input data (IP packet) from file
1201 pIpPacketsSizes[i] = MAX_PACKET_SIZE;
1202 if (!LoadDefaultPacket(m_eIP, pPackets[i], pIpPacketsSizes[i]))
1203 {
1204 LOG_MSG_ERROR("Failed to load Ethernet Packet");
1205 return false;
1206 }
1207 nIPv4DSTAddr = ntohl(0x7F000001);
1208 memcpy (&pPackets[i][IPV4_DST_ADDR_OFFSET],&nIPv4DSTAddr,
1209 sizeof(nIPv4DSTAddr));
1210
1211 //send the packet
1212 LOG_MSG_DEBUG("Sending packet into the A2 TETH pipe(%d bytes)\n",
1213 pIpPacketsSizes[i]);
1214 size_t nBytesSent = m_HsicToIpaPipe.Send(pPackets[i], pIpPacketsSizes[i]);
1215 if (pIpPacketsSizes[i] != nBytesSent)
1216 {
1217 LOG_MSG_ERROR("Sending packet into the USB pipe(%d bytes) "
1218 "failed!\n", pIpPacketsSizes[i]);
1219 return false;
1220 }
1221 ExpectedPacketSize += pIpPacketsSizes[i];
1222 }
1223
1224 //receive the packet
1225 LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be there)"
1226 "\n", ExpectedPacketSize);
1227 size_t nBytesReceived = m_IpaToUsbPipeAggPktLimit.Receive(pReceivedPacket, MAX_PACKET_SIZE);
1228 if (ExpectedPacketSize != nBytesReceived)
1229 {
1230 LOG_MSG_ERROR("Receiving aggregated packet from the USB pipe(%d bytes) "
1231 "failed!\n", nBytesReceived);
1232 print_buff(pReceivedPacket, nBytesReceived);
1233 return false;
1234 }
1235
1236
1237 for(int i = 0; i < 2; i++) {
1238 if (!RNDISAggregationHelper::CompareIPvsRNDISPacket(pPackets[i], pIpPacketsSizes[i],
1239 pReceivedPacket + (i * ExpectedPacketSize / 2), ExpectedPacketSize / 2))
1240 return false;
1241 }
1242
1243 return true;
1244 }
1245
1246 /////////////////////////////////////////////////////////////////////////////////
1247};
1248
1249
1250
1251static RNDISAggregationSanityTest aRNDISAggregationSanityTest;
1252static RNDISAggregationDeaggregation1PacketTest aRNDISAggregationDeaggregation1PacketTest;
1253static RNDISAggregation1PacketTest aRNDISAggregation1PacketTest;
1254static RNDISAggregationSuspendWaTest aRNDISAggregationSuspendWaTest;
1255static RNDISAggregationByteLimitTest aRNDISAggregationByteLimitTest;
1256static RNDISAggregationByteLimitTestFC aRNDISAggregationByteLimitTestFC;
1257static RNDISAggregationDualDpTestFC aRNDISAggregationDualDpTestFC;
1258static RNDISAggregationDualDpTestFcRoutingBased aRNDISAggregationDualDpTestFcRoutingBased;
1259static RNDISAggregationDeaggregationNumPacketsTest aRNDISAggregationDeaggregationNumPacketsTest;
1260static RNDISAggregationDeaggregationExceptionPacketsTest aRNDISAggregationDeaggregationExceptionPacketsTest;
1261static RNDISAggregationPacketLimitTest aRNDISAggregationPacketLimitTest;
1262
1263/////////////////////////////////////////////////////////////////////////////////
1264// EOF ////
1265/////////////////////////////////////////////////////////////////////////////////