RNDISAggregationTests.cpp 41 KB

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