12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814 |
- /*
- * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of The Linux Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/ioctl.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <time.h>
- #include <errno.h>
- #include "TestsUtils.h"
- #include "InterfaceAbstraction.h"
- #include "Constants.h"
- #include "Pipe.h"
- using namespace std;
- ///////////////////////////////////////////////////////////////////////////////
- extern Logger g_Logger;
- static uint8_t IPv4Packet[IP4_PACKET_SIZE] = {
- 0x45, 0x00, 0x00, 0x2e,
- 0x00, 0x00, 0x40, 0x00,
- 0xff, 0x06, 0xf5, 0xfd,// Protocol = 06 (TCP)
- 0xc0, 0xa8, 0x02, 0x13,// IPv4 SRC Addr 192.168.2.19
- 0xc0, 0xa8, 0x02, 0x68,// IPv4 DST Addr 192.168.2.104
- 0x04, 0x57, 0x08, 0xae,
- 0x00, 0x00, 0x30, 0x34,
- 0x00, 0x00, 0x00, 0x50,
- 0x50, 0xc1, 0x40, 0x00,
- 0xab, 0xc9, 0x00, 0x00,
- 0x00, 0xaa, 0xaa, 0xaa,
- 0xbb, 0xbb, 0xbb, 0xbb,
- 0xbb, 0xbb, 0xbb, 0xbb,
- 0xbb, 0xbb, 0xbb, 0xbb,
- 0xbb, 0xbb, 0xbb, 0xbb,
- 0xbb, 0xbb, 0xbb, 0xbb,
- 0xbb, 0xbb, 0xbb, 0xbb,
- 0xbb, 0xbb
- };
- static uint8_t IPv6Packet[] = {
- 0x60, 0x00, 0x00, 0x00,
- 0x00, 0x1c, 0x06, 0x01, // Protocol = 6 (TCP)
- 0xfe, 0x80, 0x00, 0x00, // source address (16B)
- 0x00, 0x00, 0x00, 0x00,
- 0xd9, 0xf9, 0xce, 0x5e,
- 0x02, 0xec, 0x32, 0x99,
- 0xff, 0x02, 0x00, 0x00, // dst address (16B)
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x0c,
- 0x12, 0x34, 0x12, 0x34, // port src = 0x1234 dest = 0x1234
- 0x00, 0x14, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x60, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, // options
- 0xda, 0x7a, 0xda, 0x7a // payload
- };
- static uint8_t IPv6PacketFragExtHdr[] = {
- 0x60, 0x00, 0x00, 0x00,
- 0x00, 0x0c, 0x2C, 0x01, // Next header = FRAGMENT HEADER(44)
- 0xfe, 0x80, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0xd9, 0xf9, 0xce, 0x5e,
- 0x02, 0xec, 0x32, 0x99,
- 0xff, 0x02, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x0c,
- 0x06, 0x00, 0x00, 0x00, // fragment header, Protocol = 6 (TCP)
- 0x00, 0x00, 0x00, 0x00,
- 0x12, 0x34, 0x12, 0x34, // port src = 0x1234 dest = 0x1234
- 0x00, 0x14, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x60, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0xda, 0x7a, 0xda, 0x7a // payload
- };
- static const uint8_t Eth2IPv4Packet[] =
- {
- // ETH2 - 14 bytes
- 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x11, // ETH2 DST
- 0x22, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, // ETH2 SRC
- 0x08, 0x00, // ETH2 TYPE IPv4 - ETH_P_IP 0x0800
- // IPv4
- 0x45, 0x00, 0x00, 0x2e,
- 0x00, 0x00, 0x40, 0x00,
- 0xff, 0x06, 0xf5, 0xfd, // Protocol = 06 (TCP)
- 0xc0, 0xa8, 0x02, 0x13, // IPv4 SRC Addr 192.168.2.19
- 0xc0, 0xa8, 0x02, 0x68, // IPv4 DST Addr 192.168.2.104
- 0x04, 0x57, 0x08, 0xae,
- 0x00, 0x00, 0x30, 0x34,
- 0x00, 0x00, 0x00, 0x50,
- 0x50, 0xc1, 0x40, 0x00,
- 0xab, 0xc9, 0x00, 0x00,
- 0x00
- };
- static const uint8_t Eth2IPv6Packet[] =
- {
- // ETH2 - 14 bytes
- 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x11, // ETH2 DST
- 0x22, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, // ETH2 SRC
- 0x86, 0xdd, // ETH2 TYPE IPv6 - ETH_P_IPV6 x86DD
- // IPv6
- 0x60, 0x00, 0x00, 0x00,
- 0x02, 0x12, 0x11, 0x01,
- 0xfe, 0x80, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0xd9, 0xf9, 0xce, 0x5e,
- 0x02, 0xec, 0x32, 0x99,
- 0xff, 0x02, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x0c
- };
- static const uint8_t WLANEth2IPv4Packet[] =
- {
- // WLAN
- 0xa1, 0xb2, 0xc3, 0xd4, // WLAN hdr
- // ETH2 - 14 bytes
- 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x11, // ETH2 DST
- 0x22, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, // ETH2 SRC
- 0x08, 0x00, // ETH2 TYPE IPv4 - ETH_P_IP 0x0800
- // IPv4
- 0x45, 0x00, 0x00, 0x2e,
- 0x00, 0x00, 0x40, 0x00,
- 0xff, 0x06, 0xf5, 0xfd, // Protocol = 06 (TCP)
- 0xc0, 0xa8, 0x02, 0x13, // IPv4 SRC Addr 192.168.2.19
- 0xc0, 0xa8, 0x02, 0x68, // IPv4 DST Addr 192.168.2.104
- 0x04, 0x57, 0x08, 0xae,
- 0x00, 0x00, 0x30, 0x34,
- 0x00, 0x00, 0x00, 0x50,
- 0x50, 0xc1, 0x40, 0x00,
- 0xab, 0xc9, 0x00, 0x00,
- 0x00
- };
- static const uint8_t WLAN802_3IPv4Packet[] =
- {
- // WLAN
- 0xa1, 0xb2, 0xc3, 0xd4, // WLAN hdr
- // 802_3 - 26 bytes
- 0xa5, 0xb6, 0xc7, 0xd8, // ROME proprietary header
- 0xa0, 0xb1, 0xc2, 0xd3, 0xe4, 0x33, // 802_3 DST
- 0x44, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6, // 802_3 SRC
- 0x00, IP4_PACKET_SIZE, // 802_3 length
- 0x04, 0x15, 0x26, 0x37, 0x48, 0x59, // LLC/SNAP
- 0x08, 0x00, // Ethrtype - 0x0800
- // IPv4
- 0x45, 0x00, 0x00, 0x2e,
- 0x00, 0x00, 0x40, 0x00,
- 0xff, 0x06, 0xf5, 0xfd, // Protocol = 06 (TCP)
- 0xc0, 0xa8, 0x02, 0x13, // IPv4 SRC Addr 192.168.2.19
- 0xc0, 0xa8, 0x02, 0x68, // IPv4 DST Addr 192.168.2.104
- 0x04, 0x57, 0x08, 0xae,
- 0x00, 0x00, 0x30, 0x34,
- 0x00, 0x00, 0x00, 0x50,
- 0x50, 0xc1, 0x40, 0x00,
- 0xab, 0xc9, 0x00, 0x00,
- 0x00
- };
- static uint8_t IPv4_TCP_No_Payload_Packet[] = {
- 0x45, 0x00, 0x00, 0x28, // Total length is 40
- 0x00, 0x00, 0x40, 0x00,
- 0xff, 0x06, 0xf5, 0xfd, // Protocol = 06 (TCP)
- 0xc0, 0xa8, 0x02, 0x13, // IPv4 SRC Addr 192.168.2.19
- 0xc0, 0xa8, 0x02, 0xc8, // IPv4 DST Addr 192.168.2.200
- 0x04, 0x57, 0x08, 0xae,
- 0x00, 0x00, 0x30, 0x34,
- 0x00, 0x00, 0x00, 0x50,
- 0x50, 0xc1, 0x40, 0x00,
- 0xab, 0xc9, 0x00, 0x00,
- };
- static uint8_t IPv6_TCP_No_Payload_Packet[] = {
- 0x60, 0x00, 0x00, 0x00,
- 0x00, 0x14, 0x06, 0x01, // Payload is 20 Bytes (TCP header only)
- 0xfe, 0x80, 0x00, 0x00, // SRC Addr
- 0x00, 0x00, 0x00, 0x00,
- 0xd9, 0xf9, 0xce, 0x5e,
- 0x02, 0xec, 0x32, 0x99,
- 0xff, 0x02, 0x00, 0x00, // DST Addr
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x4b,
- 0x04, 0x57, 0x08, 0xae, // TCP header
- 0x00, 0x00, 0x30, 0x34,
- 0x00, 0x00, 0x00, 0x50,
- 0x50, 0xc1, 0x40, 0x00,
- 0xab, 0xc9, 0x00, 0x00,
- };
- static const uint8_t Eth2IPv4Packet802_1Q_tag[] =
- {
- // ETH2 + 8021Q - 14 + 4 bytes
- 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x11, // ETH2 DST
- 0x22, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, // ETH2 SRC
- 0x81, 0x00, 0x20, 0x03, // 802.1Q header with VLAN ID = 3
- 0x08, 0x00, // ETH2 TYPE IPv4 - ETH_P_IP 0x0800
- // IPv4
- 0x45, 0x00, 0x00, 0x2e,
- 0x00, 0x00, 0x40, 0x00,
- 0xff, 0x06, 0xf5, 0xfd, // Protocol = 06 (TCP)
- 0xc0, 0xa8, 0x02, 0x13, // IPv4 SRC Addr 192.168.2.19
- 0xc0, 0xa8, 0x02, 0x68, // IPv4 DST Addr 192.168.2.104
- 0x04, 0x57, 0x08, 0xae,
- 0x00, 0x00, 0x30, 0x34,
- 0x00, 0x00, 0x00, 0x50,
- 0x50, 0xc1, 0x40, 0x00,
- 0xab, 0xc9, 0x00, 0x00,
- 0x00
- };
- static struct ipa_test_config_header *current_configuration = NULL;
- ///////////////////////////////////////////////////////////////////////////////
- /**
- *@brief Function loads a default IPv4 / IPv6 Packet
- *
- *@param [in] eIP - Type of Packet to load (IPA_IP_v4 / IPA_IP_v6)
- *@param [in] pBuffer - pointer to the destination buffer
- *@param [in,out] nMaxSize - The size of the buffer.*Upon function return,
- * the total number of bytes copied will be stored in this parameter.
- *@return boolean indicating whether the operation completed successfully or not.
- *@details Function loads a default IPv4 / IPv6 packet into pBuffer.
- */
- bool LoadDefaultPacket(
- enum ipa_ip_type eIP,
- enum ipv6_ext_hdr_type extHdrType,
- uint8_t *pBuffer,
- size_t &nMaxSize)
- {
- if (IPA_IP_v4 == eIP) {
- if (nMaxSize < sizeof(IPv4Packet))
- {
- LOG_MSG_ERROR("Buffer is smaller than %d, no Data was copied.",sizeof(IPv4Packet));
- return false;
- }
- memcpy(pBuffer,IPv4Packet, sizeof(IPv4Packet));
- nMaxSize = sizeof(IPv4Packet);
- return true;
- } else {
- if (extHdrType == FRAGMENT)
- {
- if (nMaxSize < sizeof(IPv6PacketFragExtHdr))
- {
- LOG_MSG_ERROR("Buffer is smaller than %d, no Data was copied.",sizeof(IPv6PacketFragExtHdr));
- return false;
- }
- memcpy(pBuffer,IPv6PacketFragExtHdr, sizeof(IPv6PacketFragExtHdr));
- nMaxSize = sizeof(IPv6PacketFragExtHdr);
- }
- else
- {
- if (nMaxSize < sizeof(IPv6Packet))
- {
- LOG_MSG_ERROR("Buffer is smaller than %d, no Data was copied.",sizeof(IPv6Packet));
- return false;
- }
- memcpy(pBuffer,IPv6Packet, sizeof(IPv6Packet));
- nMaxSize = sizeof(IPv6Packet);
- }
- return true;
- }
- }
- bool LoadDefaultPacket(enum ipa_ip_type eIP, uint8_t *pBuffer, size_t &nMaxSize)
- {
- return LoadDefaultPacket(eIP, NONE, pBuffer, nMaxSize);
- }
- bool LoadNoPayloadPacket(enum ipa_ip_type eIP, uint8_t *pBuffer, size_t &nMaxSize)
- {
- if (IPA_IP_v4 == eIP) {
- if (nMaxSize < sizeof(IPv4_TCP_No_Payload_Packet))
- {
- LOG_MSG_ERROR("Buffer is smaller than %zu, no Data was copied.",
- sizeof(IPv4_TCP_No_Payload_Packet));
- return false;
- }
- memcpy(pBuffer, IPv4_TCP_No_Payload_Packet, sizeof(IPv4_TCP_No_Payload_Packet));
- nMaxSize = sizeof(IPv4_TCP_No_Payload_Packet);
- } else {
- if (nMaxSize < sizeof(IPv6_TCP_No_Payload_Packet))
- {
- LOG_MSG_ERROR("Buffer is smaller than %zu, no Data was copied.",
- sizeof(IPv6_TCP_No_Payload_Packet));
- return false;
- }
- memcpy(pBuffer, IPv6_TCP_No_Payload_Packet, sizeof(IPv6_TCP_No_Payload_Packet));
- nMaxSize = sizeof(IPv6_TCP_No_Payload_Packet);
- }
- return true;
- }
- bool LoadDefaultEth2Packet(
- enum ipa_ip_type eIP,
- uint8_t *pBuffer,
- size_t &nMaxSize)
- {
- if (IPA_IP_v4 == eIP) {
- if (nMaxSize < sizeof(Eth2IPv4Packet))
- {
- LOG_MSG_ERROR(
- "Buffer is smaller than %d, "
- "no data was copied.",
- sizeof(Eth2IPv4Packet));
- return false;
- }
- memcpy(pBuffer,Eth2IPv4Packet,
- sizeof(Eth2IPv4Packet));
- nMaxSize = sizeof(Eth2IPv4Packet);
- }
- else
- {
- if (nMaxSize < sizeof(Eth2IPv6Packet))
- {
- LOG_MSG_ERROR(
- "Buffer is smaller than %d, "
- "no data was copied.",
- sizeof(Eth2IPv6Packet));
- return false;
- }
- memcpy(pBuffer,Eth2IPv6Packet,
- sizeof(Eth2IPv6Packet));
- nMaxSize = sizeof(Eth2IPv6Packet);
- }
- return true;
- }
- bool LoadDefaultWLANEth2Packet(
- enum ipa_ip_type eIP,
- uint8_t *pBuffer,
- size_t &nMaxSize)
- {
- if (IPA_IP_v4 == eIP) {
- if (nMaxSize < sizeof(WLANEth2IPv4Packet))
- {
- LOG_MSG_ERROR(
- "Buffer is smaller than %d, "
- "no data was copied.",
- sizeof(WLANEth2IPv4Packet));
- return false;
- }
- memcpy(pBuffer,WLANEth2IPv4Packet,
- sizeof(WLANEth2IPv4Packet));
- nMaxSize = sizeof(WLANEth2IPv4Packet);
- }
- else
- {
- LOG_MSG_ERROR("%s isn't implemented "
- "for IPv6 - do it yourself :-)",
- __FUNCTION__);
- return false;
- }
- return true;
- }
- bool LoadDefaultWLAN802_32Packet(
- enum ipa_ip_type eIP,
- uint8_t *pBuffer,
- size_t &nMaxSize)
- {
- if (IPA_IP_v4 == eIP) {
- if (nMaxSize < sizeof(WLAN802_3IPv4Packet))
- {
- LOG_MSG_ERROR(
- "Buffer is smaller than %d, "
- "no data was copied.",
- sizeof(WLAN802_3IPv4Packet));
- return false;
- }
- memcpy(pBuffer,WLAN802_3IPv4Packet,
- sizeof(WLAN802_3IPv4Packet));
- nMaxSize = sizeof(WLAN802_3IPv4Packet);
- }
- else
- {
- LOG_MSG_ERROR("%s isn't implemented"
- " for IPv6 - do it yourself :-)",
- __FUNCTION__);
- return false;
- }
- return true;
- }
- bool LoadDefault802_1Q(
- enum ipa_ip_type eIP,
- uint8_t *pBuffer,
- size_t &nMaxSize)
- {
- if (IPA_IP_v4 == eIP) {
- if (nMaxSize < sizeof(Eth2IPv4Packet802_1Q_tag)) {
- LOG_MSG_ERROR(
- "Buffer is smaller than %d, "
- "no data was copied.",
- sizeof(Eth2IPv4Packet802_1Q_tag));
- return false;
- }
- memcpy(pBuffer, Eth2IPv4Packet802_1Q_tag,
- sizeof(Eth2IPv4Packet802_1Q_tag));
- nMaxSize = sizeof(Eth2IPv4Packet802_1Q_tag);
- } else {
- LOG_MSG_ERROR("%s isn't implemented"
- " for IPv6 - do it yourself :-)",
- __FUNCTION__);
- return false;
- }
- return true;
- }
- bool SendReceiveAndCompare(InterfaceAbstraction *pSink, uint8_t* pSendBuffer, size_t nSendBuffSize,
- InterfaceAbstraction *pSource, uint8_t* pExpectedBuffer, size_t nExpectedBuffSize)
- {
- LOG_MSG_STACK("Entering Function");
- bool bRetVal = true;
- uint8_t * pRxBuff = new uint8_t[2*(nExpectedBuffSize+1)];
- size_t nReceivedBuffSize = 0;
- size_t j;
- // Send buffer to pSink
- bRetVal = pSink->SendData((Byte *) pSendBuffer, nSendBuffSize);
- if (!bRetVal)
- {
- LOG_MSG_ERROR("SendData (pOutputBuffer=0x%p) failed",pSendBuffer);
- goto bail;
- }
- // Receive buffer from pSource
- if (NULL == pRxBuff)
- {
- LOG_MSG_ERROR("Failed to allocated pRxBuff[%d]",2*(nExpectedBuffSize+1));
- goto bail;
- }
- nReceivedBuffSize = pSource->ReceiveData(pRxBuff, 2*(nExpectedBuffSize+1)); // We cannot overflow here.
- LOG_MSG_INFO("Received %d bytes on %s.", nReceivedBuffSize, pSource->m_fromChannelName.c_str());
- if (0 > nReceivedBuffSize)
- {
- bRetVal = false;
- goto bail;
- }
- {// Logging Expected and Received buffers
- char aExpectedBufferStr[3*nExpectedBuffSize+1];
- char aRecievedBufferStr[3*nReceivedBuffSize+1];
- memset(aExpectedBufferStr,0,3*nExpectedBuffSize+1);
- memset(aRecievedBufferStr,0,3*nReceivedBuffSize+1);
- for(j = 0; j < nExpectedBuffSize; j++)
- snprintf(&aExpectedBufferStr[3*j], 3*nExpectedBuffSize+1 - (3*j + 1), " %02X", pExpectedBuffer[j]);
- for(j = 0; j < nReceivedBuffSize; j++)
- snprintf(&aRecievedBufferStr[3*j], 3*nReceivedBuffSize+1 - (3*j + 1), " %02X", pRxBuff[j]);
- LOG_MSG_INFO("\nExpected Value (%d)\n%s\n, Received Value(%d)\n%s\n",nExpectedBuffSize,aExpectedBufferStr,nReceivedBuffSize,aRecievedBufferStr);
- }
- //Comparing Expected and received sizes
- if (nExpectedBuffSize != nReceivedBuffSize)
- {
- LOG_MSG_INFO("Buffers' Size differ: expected(%d), Received(%d)",nExpectedBuffSize,nReceivedBuffSize);
- bRetVal = false;
- goto bail;
- }
- bRetVal = !memcmp((void*)pRxBuff, (void*)pExpectedBuffer, nExpectedBuffSize);
- LOG_MSG_INFO("Buffers %s ",bRetVal?"MATCH":"MISMATCH");
- LOG_MSG_INFO("Verify that pipe is Empty");
- nReceivedBuffSize = pSource->ReceiveData(pRxBuff, 2*(nExpectedBuffSize+1)); // We cannot overflow here.
- while (nReceivedBuffSize){
- char aRecievedBufferStr[3*nReceivedBuffSize+1];
- bRetVal = false;
- LOG_MSG_ERROR("More Data in Pipe!\nReceived %d bytes on %s.", nReceivedBuffSize, pSource->m_fromChannelName.c_str());
- memset(aRecievedBufferStr,0,3*nReceivedBuffSize+1);
- for(j = 0; j < nReceivedBuffSize; j++) {
- snprintf(&aRecievedBufferStr[3*j], 3*nReceivedBuffSize+1 - (3*j + 1), " %02X", pRxBuff[j]);
- }
- LOG_MSG_ERROR("\nReceived Value(%d)\n%s\n",nReceivedBuffSize,aRecievedBufferStr);
- nReceivedBuffSize = pSource->ReceiveData(pRxBuff, 2*(nExpectedBuffSize+1)); // We cannot overflow here.
- }
- bail:
- delete (pRxBuff);
- LOG_MSG_STACK("Leaving Function (Returning %s)",bRetVal?"True":"False");
- return bRetVal;
- }
- bool CreateBypassRoutingTable (RoutingDriverWrapper * pRouting,enum ipa_ip_type eIP,
- const char * pTableName, enum ipa_client_type eRuleDestination,
- uint32_t uHeaderHandle, uint32_t * pTableHdl)
- {
- bool bRetVal = true;
- struct ipa_ioc_add_rt_rule *pRoutingRule = NULL;
- struct ipa_rt_rule_add *pRoutingRuleEntry = NULL;
- struct ipa_ioc_get_rt_tbl sRoutingTable;
- LOG_MSG_STACK("Entering Function");
- memset(&sRoutingTable,0,sizeof(sRoutingTable));
- pRoutingRule = (struct ipa_ioc_add_rt_rule *)
- calloc(1,
- sizeof(struct ipa_ioc_add_rt_rule) +
- 1*sizeof(struct ipa_rt_rule_add)
- );
- if(!pRoutingRule) {
- LOG_MSG_ERROR("calloc failed to allocate pRoutingRule");
- bRetVal = false;
- goto bail;
- }
- pRoutingRule->num_rules = 1;
- pRoutingRule->ip = ((IPA_IP_v4 == eIP)? IPA_IP_v4 : IPA_IP_v6);
- pRoutingRule->commit = true;
- strlcpy(pRoutingRule->rt_tbl_name, pTableName, sizeof(pRoutingRule->rt_tbl_name));
- pRoutingRuleEntry = &(pRoutingRule->rules[0]);
- pRoutingRuleEntry->at_rear = 1;
- pRoutingRuleEntry->rule.dst = eRuleDestination;// Setting Rule's Destination Pipe
- pRoutingRuleEntry->rule.hdr_hdl = uHeaderHandle; // Header handle
- pRoutingRuleEntry->rule.attrib.attrib_mask = 0;// All Packets will get a "Hit"
- if (false == pRouting->AddRoutingRule(pRoutingRule))
- {
- LOG_MSG_ERROR("Routing rule addition(pRoutingRule) failed!");
- bRetVal = false;
- goto bail;
- }
- if (!pRoutingRuleEntry->rt_rule_hdl)
- {
- LOG_MSG_ERROR("pRoutingRuleEntry->rt_rule_hdl == 0, Routing rule addition(pRoutingRule) failed!");
- bRetVal = false;
- goto bail;
- }
- LOG_MSG_INFO("pRoutingRuleEntry->rt_rule_hdl == 0x%x added to Table %s",pRoutingRuleEntry->rt_rule_hdl,pTableName);
- sRoutingTable.ip = eIP;
- strlcpy(sRoutingTable.name, pTableName, sizeof(sRoutingTable.name));
- if (!pRouting->GetRoutingTable(&sRoutingTable)) {
- LOG_MSG_ERROR(
- "m_routing.GetRoutingTable(&sRoutingTable=0x%p) Failed.", &sRoutingTable);
- bRetVal = false;
- goto bail;
- }
- if(NULL != pTableHdl){
- (* pTableHdl ) = sRoutingTable.hdl;
- LOG_MSG_DEBUG("Table Handle =0x%x will be returned.",(*pTableHdl));
- }
- bail:
- Free (pRoutingRule);
- LOG_MSG_STACK("Leaving Function (Returning %s)",bRetVal?"True":"False");
- return bRetVal;
- }
- bool CreateBypassRoutingTable_v2 (RoutingDriverWrapper * pRouting,enum ipa_ip_type eIP,
- const char * pTableName, enum ipa_client_type eRuleDestination,
- uint32_t uHeaderHandle, uint32_t * pTableHdl, uint8_t uClsAggrIrqMod)
- {
- bool bRetVal = true;
- struct ipa_ioc_add_rt_rule_v2 *pRoutingRule = NULL;
- struct ipa_rt_rule_add_v2 *pRoutingRuleEntry = NULL;
- struct ipa_ioc_get_rt_tbl sRoutingTable;
- LOG_MSG_STACK("Entering Function");
- memset(&sRoutingTable,0,sizeof(sRoutingTable));
- pRoutingRule = (struct ipa_ioc_add_rt_rule_v2 *)
- calloc(1, sizeof(struct ipa_ioc_add_rt_rule_v2));
- if(!pRoutingRule) {
- LOG_MSG_ERROR("calloc failed to allocate pRoutingRule");
- bRetVal = false;
- goto bail;
- }
- pRoutingRule->rules = (uint64_t)calloc(1, sizeof(struct ipa_rt_rule_add_v2));
- if (!pRoutingRule->rules) {
- LOG_MSG_ERROR("calloc failed to allocate pRoutingRule->rules");
- bRetVal = false;
- goto bail;
- }
- pRoutingRule->num_rules = 1;
- pRoutingRule->rule_add_size = sizeof(struct ipa_rt_rule_add_v2);
- printf("%s(), Nadav: Adding rule_add_size\n", __FUNCTION__);
- pRoutingRule->ip = ((IPA_IP_v4 == eIP)? IPA_IP_v4 : IPA_IP_v6);
- pRoutingRule->commit = true;
- strlcpy(pRoutingRule->rt_tbl_name, pTableName, sizeof(pRoutingRule->rt_tbl_name));
- pRoutingRuleEntry = &(((struct ipa_rt_rule_add_v2 *)pRoutingRule->rules)[0]);
- pRoutingRuleEntry->at_rear = 1;
- pRoutingRuleEntry->rule.dst = eRuleDestination;// Setting Rule's Destination Pipe
- printf("%s(), Nadav: Destination = %d\n", __FUNCTION__, pRoutingRuleEntry->rule.dst);
- pRoutingRuleEntry->rule.hdr_hdl = uHeaderHandle; // Header handle
- pRoutingRuleEntry->rule.attrib.attrib_mask = 0;// All Packets will get a "Hit"
- pRoutingRuleEntry->rule.close_aggr_irq_mod = uClsAggrIrqMod;
- if (false == pRouting->AddRoutingRule(pRoutingRule))
- {
- LOG_MSG_ERROR("Routing rule addition(pRoutingRule) failed!");
- bRetVal = false;
- goto bail;
- }
- if (!pRoutingRuleEntry->rt_rule_hdl)
- {
- LOG_MSG_ERROR("pRoutingRuleEntry->rt_rule_hdl == 0, Routing rule addition(pRoutingRule) failed!");
- bRetVal = false;
- goto bail;
- }
- LOG_MSG_INFO("pRoutingRuleEntry->rt_rule_hdl == 0x%x added to Table %s",pRoutingRuleEntry->rt_rule_hdl,pTableName);
- sRoutingTable.ip = eIP;
- strlcpy(sRoutingTable.name, pTableName, sizeof(sRoutingTable.name));
- if (!pRouting->GetRoutingTable(&sRoutingTable)) {
- LOG_MSG_ERROR(
- "m_routing.GetRoutingTable(&sRoutingTable=0x%p) Failed.", &sRoutingTable);
- bRetVal = false;
- goto bail;
- }
- if(NULL != pTableHdl){
- (* pTableHdl ) = sRoutingTable.hdl;
- LOG_MSG_DEBUG("Table Handle =0x%x will be returned.",(*pTableHdl));
- }
- bail:
- Free (pRoutingRule);
- LOG_MSG_STACK("Leaving Function (Returning %s)",bRetVal?"True":"False");
- return bRetVal;
- }
- //Don't use these methods directly. use MACROs instead
- void __log_msg(enum msgType logType, const char* filename, int line, const char* function, const char* format, ... )
- {
- va_list args;
- switch (logType) {
- case ERROR:
- fprintf( stderr, "ERROR!");
- break;
- case DEBUG:
- fprintf( stderr, "DEBUG:");
- break;
- case INFO:
- fprintf( stderr, "INFO :");
- break;
- case STACK:
- fprintf( stderr, "STACK:");
- break;
- default:
- fprintf( stderr, "BUG!!!");
- break;
- }
- fprintf( stderr, " [%s:%d, %s()] ",filename,line,function);
- va_start( args, format );
- vfprintf( stderr, format, args );
- va_end( args );
- fprintf( stderr, "\n" );
- }
- bool file_exists(const char* filename)
- {
- return (access(filename, F_OK) == 0);
- }
- int ConfigureSystem(int testConfiguration, int fd)
- {
- return ConfigureSystem(testConfiguration, fd, NULL);
- }
- int ConfigureSystem(int testConfiguration, int fd, const char* params)
- {
- char testConfigurationStr[10];
- int ret;
- char *pSendBuffer;
- char str[10];
- int iter_cnt = 2000;
- if(params != NULL)
- pSendBuffer = new char[strlen(params) + 10];
- else
- pSendBuffer = new char[10];
- if (NULL == pSendBuffer)
- {
- LOG_MSG_ERROR("Failed to allocated pSendBuffer");
- return -1;
- }
- if(params != NULL)
- snprintf(pSendBuffer, strlen(params) + 10, "%d %s", testConfiguration, params);
- else
- snprintf(pSendBuffer, 10, "%d", testConfiguration);
- ret = write(fd, pSendBuffer, sizeof(pSendBuffer) );
- if (ret < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s Write operation failed.\n", __FUNCTION__);
- goto bail;
- }
- // Wait until the system is fully configured
- // Convert testConfiguration to string
- snprintf(testConfigurationStr, sizeof(testConfigurationStr), "%d", testConfiguration);
- // Read the configuration index from the device node
- ret = read(fd, str, sizeof(str));
- if (ret < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s Read operation failed.\n", __FUNCTION__);
- goto bail;
- }
- while ( strcmp(str, testConfigurationStr) ) {
- // Sleep for 5 msec
- struct timespec time;
- time.tv_sec = 0;
- time.tv_nsec = 50e6;
- nanosleep(&time, NULL);
- ret = read(fd, str, sizeof(str));
- if (ret < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s Read operation failed.\n", __FUNCTION__);
- goto bail;
- }
- if (!--iter_cnt) {
- g_Logger.AddMessage(LOG_ERROR, "%s timeout waiting for test driver.\n", __FUNCTION__);
- ret = -1;
- goto bail;
- }
- }
- bail:
- delete[] pSendBuffer;
- return ret;
- }
- void ConfigureScenario(int testConfiguration)
- {
- ConfigureScenario(testConfiguration, NULL);
- }
- void ConfigureScenario(int testConfiguration, const char* params)
- {
- int fd, ret;
- char str[10];
- int currentConf;
- // Open /dev/ipa_test device node. This will allow to configure the system
- // and read its current configuration.
- fd = open(CONFIGURATION_NODE_PATH, O_RDWR);
- if (fd < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s Could not open configuration device node.\n", __FUNCTION__);
- exit(0);
- }
- // Read the current configuration.
- ret = read(fd, str, sizeof(str));
- if (ret < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s Read operation failed.\n", __FUNCTION__);
- return;
- }
- currentConf = atoi(str);
- // Do not reconfigure to the same configuration
- if (currentConf == testConfiguration) {
- g_Logger.AddMessage(LOG_DEVELOPMENT,"%s System was already configured as required(%d)\n",
- __FUNCTION__, currentConf);
- return;
- }
- /* in case the system is not "clean"*/
- if (-1 != currentConf) {
- g_Logger.AddMessage(LOG_DEVELOPMENT,"%s System has other configuration (%d) - cleanup\n", __FUNCTION__, currentConf);
- ret = ConfigureSystem(-1, fd);
- if (ret < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s Configure operation failed.\n",
- __FUNCTION__);
- return;
- }
- }
- // Start system configuration.
- g_Logger.AddMessage(LOG_DEVELOPMENT,"%s Setting system to the required configuration (%d)\n", __FUNCTION__, testConfiguration);
- ret = ConfigureSystem(testConfiguration, fd, params);
- if (ret < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s configure operation failed.\n",
- __FUNCTION__);
- return;
- }
- ret = system("mdev -s");
- if (ret < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s system(\"mdev -s\") returned %d\n",
- __FUNCTION__, ret);
- }
- close(fd);
- }//func
- void clean_old_stashed_config()
- {
- if (current_configuration == NULL)
- return;
- for (int i = 0 ; i < current_configuration->from_ipa_channels_num ; i++) {
- delete((struct test_ipa_ep_cfg*)
- current_configuration->from_ipa_channel_config[i]->cfg);
- delete((struct test_ipa_ep_cfg*)
- current_configuration->from_ipa_channel_config[i]);
- }
- for (int i = 0 ; i < current_configuration->to_ipa_channels_num ; i++) {
- delete((struct test_ipa_ep_cfg*)
- current_configuration->to_ipa_channel_config[i]->cfg);
- delete((struct test_ipa_ep_cfg*)
- current_configuration->to_ipa_channel_config[i]);
- }
- delete(current_configuration);
- current_configuration = NULL;
- }
- void stash_new_configuration(struct ipa_test_config_header *header)
- {
- clean_old_stashed_config();
- /*
- * We will start by shallow copying each level, and afterwards,
- * override the pointers
- */
- current_configuration = new ipa_test_config_header();
- *current_configuration = *header;
- current_configuration->from_ipa_channel_config =
- new ipa_channel_config*[header->from_ipa_channels_num]();
- current_configuration->to_ipa_channel_config =
- new ipa_channel_config*[header->to_ipa_channels_num]();
- for (int i = 0 ; i < current_configuration->from_ipa_channels_num ; i++) {
- current_configuration->from_ipa_channel_config[i] =
- new ipa_channel_config;
- *current_configuration->from_ipa_channel_config[i] =
- *header->from_ipa_channel_config[i];
- current_configuration->from_ipa_channel_config[i]->cfg =
- new test_ipa_ep_cfg();
- memcpy(current_configuration->from_ipa_channel_config[i]->cfg,
- header->from_ipa_channel_config[i]->cfg,
- header->from_ipa_channel_config[i]->config_size);
- }
- for (int i = 0 ; i < current_configuration->to_ipa_channels_num ; i++) {
- current_configuration->to_ipa_channel_config[i] =
- new ipa_channel_config;
- *current_configuration->to_ipa_channel_config[i] =
- *header->to_ipa_channel_config[i];
- current_configuration->to_ipa_channel_config[i]->cfg = new test_ipa_ep_cfg();
- memcpy(current_configuration->to_ipa_channel_config[i]->cfg,
- header->to_ipa_channel_config[i]->cfg,
- header->to_ipa_channel_config[i]->config_size);
- }
- }
- bool is_prev_configuration_generic()
- {
- int fd;
- char str[10] = {0};
- int retval;
- int current_conf_num;
- fd = open(CONFIGURATION_NODE_PATH, O_RDWR);
- if (fd < 0) {
- g_Logger.AddMessage(LOG_ERROR ,"%s Could not open configuration device node.\n", __FUNCTION__);
- exit(0);
- }
- retval = read(fd, str, sizeof(str));
- close(fd);
- if (retval < 0) {
- g_Logger.AddMessage(LOG_ERROR ,"%s Read operation failed.\n", __FUNCTION__);
- return true;
- }
- current_conf_num = atoi(str);
- if (current_conf_num == GENERIC_TEST_CONFIGURATION_IDX)
- return true;
- return false;
- }
- static bool is_reconfigure_required(struct ipa_test_config_header *header)
- {
- // Is reconfiguration not required flag (current conf is cool)
- bool flag = true;
- if (is_prev_configuration_generic() == false) {
- g_Logger.AddMessage(LOG_DEVELOPMENT ,
- "prev configuration didn't use generic configuration\n");
- return true;
- }
- if (current_configuration == NULL) {
- g_Logger.AddMessage(LOG_DEVELOPMENT ,
- "no prev generic configuration found in the test app data-base\n");
- return true;
- }
- flag &= (header->from_ipa_channels_num ==
- current_configuration->from_ipa_channels_num);
- flag &= (header->to_ipa_channels_num ==
- current_configuration->to_ipa_channels_num);
- if (flag == false) {
- g_Logger.AddMessage(LOG_DEVELOPMENT ,
- "not same number of pipes\n");
- return true;
- }
- for (int i = 0 ; i < header->from_ipa_channels_num ; i++) {
- flag &= (header->from_ipa_channel_config[i]->client ==
- current_configuration->from_ipa_channel_config[i]->client);
- flag &= (header->from_ipa_channel_config[i]->index ==
- current_configuration->from_ipa_channel_config[i]->index);
- flag &= !memcmp(header->from_ipa_channel_config[i]->cfg,
- current_configuration->from_ipa_channel_config[i]->cfg,
- header->from_ipa_channel_config[i]->config_size);
- flag &= (header->from_ipa_channel_config[i]->en_status ==
- current_configuration->from_ipa_channel_config[i]->en_status);
- }
- if (flag == false) {
- g_Logger.AddMessage(LOG_DEVELOPMENT ,
- "\"from\" endpoint configuration is different from prev\n");
- return true;
- }
- for (int i = 0 ; i < header->to_ipa_channels_num ; i++) {
- flag &= (header->to_ipa_channel_config[i]->client ==
- current_configuration->to_ipa_channel_config[i]->client);
- flag &= (header->to_ipa_channel_config[i]->index ==
- current_configuration->to_ipa_channel_config[i]->index);
- flag &= !memcmp(header->to_ipa_channel_config[i]->cfg,
- current_configuration->to_ipa_channel_config[i]->cfg,
- header->to_ipa_channel_config[i]->config_size);
- flag &= (header->to_ipa_channel_config[i]->en_status ==
- current_configuration->to_ipa_channel_config[i]->en_status);
- }
- if (flag == false) {
- g_Logger.AddMessage(LOG_DEVELOPMENT ,
- "\"to\" endpoint configuration is different from prev\n");
- return true;
- }
- return false;
- }
- int GenericConfigureScenario(struct ipa_test_config_header *header)
- {
- int fd;
- int retval;
- if (is_reconfigure_required(header) == false) {
- g_Logger.AddMessage(LOG_DEVELOPMENT ,
- "No need to reconfigure, we are all good :)\n");
- return true;
- } else {
- g_Logger.AddMessage(LOG_DEVELOPMENT ,
- "Need to run configuration again\n");
- }
- g_Logger.AddMessage(LOG_DEVELOPMENT, "configuration has started, parameters:\n");
- g_Logger.AddMessage(LOG_DEVELOPMENT, "header->head_marker=0x%x\n", header->head_marker);
- g_Logger.AddMessage(LOG_DEVELOPMENT, "header->from_ipa_channels_num=%d\n", header->from_ipa_channels_num);
- g_Logger.AddMessage(LOG_DEVELOPMENT, "header->to_ipa_channels_num=%d\n", header->to_ipa_channels_num);
- g_Logger.AddMessage(LOG_DEVELOPMENT, "header->tail_marker=0x%x\n", header->tail_marker);
- for (int i = 0 ; i < header->from_ipa_channels_num ; i++) {
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->from_ipa_channel_config[%d]->head_marker=0x%x\n", i,
- header->from_ipa_channel_config[i]->head_marker);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->from_ipa_channel_config[%d]->index=%d\n", i,
- header->from_ipa_channel_config[i]->index);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->from_ipa_channel_config[%d]->client=%d\n", i,
- header->from_ipa_channel_config[i]->client);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->from_ipa_channel_config[%d]->config_size=%d\n", i,
- header->from_ipa_channel_config[i]->config_size);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->from_ipa_channel_config[%d]->en_status=%d\n", i,
- header->from_ipa_channel_config[i]->en_status);
- }
- for (int i = 0 ; i < header->to_ipa_channels_num ; i++) {
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->to_ipa_channel_config[%d]->head_marker=0x%x\n", i,
- header->to_ipa_channel_config[i]->head_marker);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->to_ipa_channel_config[%d]->index=%d\n", i,
- header->to_ipa_channel_config[i]->index);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->to_ipa_channel_config[%d]->client=%d\n", i,
- header->to_ipa_channel_config[i]->client);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->to_ipa_channel_config[%d]->config_size=%d\n", i,
- header->to_ipa_channel_config[i]->config_size);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "header->to_ipa_channel_config[%d]->en_status=%d\n", i,
- header->to_ipa_channel_config[i]->en_status);
- }
- fd = open(CONFIGURATION_NODE_PATH, O_RDWR);
- if (fd == -1) {
- g_Logger.AddMessage(LOG_ERROR,
- "%s - open %s failed (fd=%d,errno=%s)\n",
- __FUNCTION__, CONFIGURATION_NODE_PATH, fd, strerror(errno));
- return false;
- }
- retval = ioctl(fd, IPA_TEST_IOC_CONFIGURE, header);
- if (retval) {
- g_Logger.AddMessage(LOG_ERROR, "fail to configure the system (%d)\n", retval);
- close(fd);
- return false;
- } else {
- g_Logger.AddMessage(LOG_DEVELOPMENT, "system was successfully configured\n");
- }
- retval = close(fd);
- if (retval) {
- g_Logger.AddMessage(LOG_ERROR,
- "%s - fail to close the fd (path=%s,retval=%d,fd=%d,errno=%s)\n",
- __FUNCTION__, CONFIGURATION_NODE_PATH, retval, fd, strerror(errno));
- return false;
- }
- g_Logger.AddMessage(LOG_DEVELOPMENT ,"stashing new configuration\n");
- stash_new_configuration(header);
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "Running mdev in order to create the device nodes.\n");
- retval = system("mdev -s");
- if (retval < 0) {
- g_Logger.AddMessage(LOG_ERROR, "%s system(\"mdev -s\") returned %d\n",
- __FUNCTION__, retval);
- }
- return true;
- }
- int GenericConfigureScenarioDestory(void)
- {
- int fd;
- int retval;
- g_Logger.AddMessage(LOG_DEVELOPMENT, "cleanup started\n");
- fd = open(CONFIGURATION_NODE_PATH, O_RDWR);
- if (fd == -1) {
- g_Logger.AddMessage(LOG_ERROR,
- "%s - open %s failed (retval=%d,fd=%d,errno=%s)\n",
- __FUNCTION__, CONFIGURATION_NODE_PATH, fd, strerror(errno));
- return false;
- }
- retval = ioctl(fd, IPA_TEST_IOC_CLEAN);
- if (retval)
- g_Logger.AddMessage(LOG_ERROR, "fail to clean the system (%d)\n", retval);
- else
- g_Logger.AddMessage(LOG_DEVELOPMENT, "system was successfully cleaned\n");
- retval = close(fd);
- if (retval) {
- g_Logger.AddMessage(LOG_ERROR, "fail to close the fd - %d\n", retval);
- return false;
- }
- return true;
- }
- bool configure_ep_ctrl(struct ipa_test_ep_ctrl *ep_ctrl)
- {
- int fd;
- int retval = 0;
- g_Logger.AddMessage(LOG_DEVELOPMENT, "ep ctrl started \n");
- fd = open(CONFIGURATION_NODE_PATH, O_RDWR);
- if (fd == -1) {
- g_Logger.AddMessage(LOG_ERROR,
- "%s - open %s failed (retval=%d,fd=%d,errno=%s)\n",
- __FUNCTION__, CONFIGURATION_NODE_PATH, fd, strerror(errno));
- return false;
- }
- retval = ioctl(fd, IPA_TEST_IOC_EP_CTRL, ep_ctrl);
- if (retval)
- g_Logger.AddMessage(LOG_ERROR, "fail to perform ep ctrl (%d)\n", retval);
- else
- g_Logger.AddMessage(LOG_DEVELOPMENT, "ep ctrl was successfully executed\n");
- retval = close(fd);
- if (retval) {
- g_Logger.AddMessage(LOG_ERROR, "fail to close the fd - %d\n", retval);
- }
- return true;
- }
- bool configure_holb(struct ipa_test_holb_config *test_holb_config)
- {
- int fd;
- int retval = 0;
- g_Logger.AddMessage(LOG_DEVELOPMENT, "holb config started \n");
- if (!test_holb_config) {
- g_Logger.AddMessage(LOG_ERROR, "Null pointer argument!");
- return false;
- }
- fd = open(CONFIGURATION_NODE_PATH, O_RDWR);
- if (fd == -1) {
- g_Logger.AddMessage(LOG_ERROR,
- "%s - open %s failed (retval=%d,fd=%d,errno=%s)\n",
- __FUNCTION__, CONFIGURATION_NODE_PATH, fd, strerror(errno));
- return false;
- }
- retval = ioctl(fd, IPA_TEST_IOC_HOLB_CONFIG, test_holb_config);
- if (retval)
- g_Logger.AddMessage(LOG_ERROR,
- "fail to perform holb config (%d)\n",
- retval);
- else
- g_Logger.AddMessage(LOG_DEVELOPMENT,
- "holb config was successfully executed\n");
- retval = close(fd);
- if (retval) {
- g_Logger.AddMessage(LOG_ERROR, "fail to close the fd - %d\n", retval);
- }
- return true;
- }
- void prepare_channel_struct(struct ipa_channel_config *channel,
- int index,
- enum ipa_client_type client,
- void *cfg,
- size_t config_size,
- bool en_status)
- {
- channel->head_marker = IPA_TEST_CHANNEL_CONFIG_MARKER;
- channel->index = index;
- channel->client = client;
- channel->cfg = (char*)cfg;
- channel->config_size = config_size;
- channel->tail_marker = IPA_TEST_CHANNEL_CONFIG_MARKER;
- channel->en_status = en_status;
- }
- void prepare_header_struct(struct ipa_test_config_header *header,
- struct ipa_channel_config **from,
- struct ipa_channel_config **to)
- {
- header->head_marker = IPA_TEST_CONFIG_MARKER;
- header->from_ipa_channel_config = from;
- header->to_ipa_channel_config = to;
- header->tail_marker = IPA_TEST_CONFIG_MARKER;
- }
- bool CompareResultVsGolden(Byte *goldenBuffer, unsigned int goldenSize,
- Byte *receivedBuffer, unsigned int receivedSize)
- {
- if (receivedSize != goldenSize) {
- g_Logger.AddMessage(LOG_VERBOSE, "%s File sizes are different.\n", __FUNCTION__);
- return false;
- }
- return !memcmp((void*)receivedBuffer, (void*)goldenBuffer, goldenSize);
- }
- bool CompareResultVsGolden_w_Status(Byte *goldenBuffer, unsigned int goldenSize,
- Byte *receivedBuffer, unsigned int receivedSize)
- {
- size_t stts_size = sizeof(struct ipa3_hw_pkt_status);
- if (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) {
- stts_size = sizeof(struct ipa3_hw_pkt_status_hw_v5_0);
- }
- if ((receivedSize - stts_size) != goldenSize) {
- g_Logger.AddMessage(LOG_VERBOSE, "%s Buffer sizes are different.\n", __FUNCTION__);
- return false;
- }
- printf("comparison is made considering %zu status bytes!\n", stts_size);
- return !memcmp((void*)((unsigned char *)receivedBuffer +
- stts_size), (void*)goldenBuffer, goldenSize);
- }
- Byte *LoadFileToMemory(const string &name, unsigned int *sizeLoaded)
- {
- FILE *file;
- Byte *buffer;
- size_t fileLen;
- // Open file
- file = fopen(name.c_str(), "rb");
- if (!file) {
- g_Logger.AddMessage(LOG_ERROR, "Unable to open file %s\n", name.c_str());
- return NULL;
- }
- // Get file length
- fseek(file, 0, SEEK_END);
- fileLen = ftell(file);
- fseek(file, 0, SEEK_SET);
- // Allocate memory
- buffer=(Byte*)malloc(fileLen+1);
- if (!buffer) {
- fprintf(stderr, "Memory error!\n");
- fclose(file);
- return NULL;
- }
- // Read file contents into buffer
- *sizeLoaded = fread(buffer, 1, fileLen, file);
- fclose(file);
- return buffer;
- }
- void print_buff(void *data, size_t size)
- {
- uint8_t bytes_in_line = 16;
- uint i, j, num_lines;
- char str[1024], tmp[4];
- num_lines = size / bytes_in_line;
- if (size % bytes_in_line > 0)
- num_lines++;
- printf("Printing buffer at address 0x%p, size = %zu: \n", data, size);
- for (i = 0 ; i < num_lines; i++) {
- str[0] = '\0';
- for (j = 0; (j < bytes_in_line) && ((i * bytes_in_line + j) < size); j++) {
- snprintf(tmp, sizeof(tmp), "%02x ",
- ((unsigned char*)data)[i * bytes_in_line + j]);
- strlcpy(str + strlen(str), tmp, sizeof(str) - strlen(str));
- }
- printf("%s\n", str);
- }
- }
- void add_buff(uint8_t *data, size_t size, uint8_t val)
- {
- for (int i = 0; i < static_cast<int>(size); i++)
- data[i]+=val;
- }
- bool RegSuspendHandler(bool deferred_flag, bool reg, int DevNum)
- {
- int fd = 0;
- int retval = 0;
- struct ipa_test_reg_suspend_handler RegData;
- fd = open(CONFIGURATION_NODE_PATH, O_RDWR);
- if (fd == -1) {
- g_Logger.AddMessage(LOG_ERROR,
- "%s - open %s failed (fd=%d,errno=%s)\n",
- __FUNCTION__, CONFIGURATION_NODE_PATH, fd, strerror(errno));
- return false;
- }
- RegData.DevNum = DevNum;
- RegData.reg = reg;
- RegData.deferred_flag = deferred_flag;
- retval = ioctl(fd, IPA_TEST_IOC_REG_SUSPEND_HNDL, &RegData);
- if (retval) {
- g_Logger.AddMessage(LOG_ERROR, "fail to reg suspend handler (%d)\n", retval);
- close(fd);
- return false;
- } else {
- g_Logger.AddMessage(LOG_DEVELOPMENT, "suspend handler was successfully configured\n");
- }
- close(fd);
- return true;
- }
- const Byte Eth2Helper::m_ETH2_IP4_HDR[ETH_HLEN] =
- {
- 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, // ETH2 DST
- 0xA7, 0xA8, 0xA9, 0xB0, 0xB1, 0xB2, // ETH2 SRC
- 0x08, 0x00, // ETH2 TYPE IPv4 - ETH_P_IP 0x0800
- };
- bool Eth2Helper::LoadEth2IP4Header(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t *pLen)
- {
- if (bufferSize < ETH_HLEN)
- {
- LOG_MSG_ERROR("Buffer too small\n");
- return false;
- }
- memcpy(pBuffer, m_ETH2_IP4_HDR, ETH_HLEN);
- *pLen = ETH_HLEN;
- return true;
- }
- bool Eth2Helper::LoadEth2IP6Header(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t *pLen)
- {
- if (bufferSize < ETH_HLEN)
- {
- LOG_MSG_ERROR("Buffer too small\n");
- return false;
- }
- // copy eth2 ip4 header
- memcpy(pBuffer, m_ETH2_IP4_HDR, ETH_HLEN);
- // change ethtype to ip6
- pBuffer[ETH2_ETH_TYPE_OFFSET] = 0x86;
- pBuffer[ETH2_ETH_TYPE_OFFSET+1] = 0xdd;
- *pLen = ETH_HLEN;
- return true;
- }
- bool Eth2Helper::LoadEth2IP4Packet(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t *pLen)
- {
- size_t cnt = 0;
- size_t len = 0;
- if (!LoadEth2IP4Header(pBuffer, bufferSize, &cnt))
- return false;
- len = bufferSize - cnt;
- if (!LoadDefaultPacket(IPA_IP_v4, pBuffer + cnt, len))
- return false;
- *pLen = len + cnt;
- return true;
- }
- bool Eth2Helper::LoadEth2IP6Packet(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t *pLen)
- {
- size_t cnt = 0;
- size_t len = 0;
- if (!LoadEth2IP6Header(pBuffer, bufferSize, &cnt))
- return false;
- len = bufferSize - cnt;
- if (!LoadDefaultPacket(IPA_IP_v6, pBuffer + cnt, len))
- return false;
- *pLen = len + cnt;
- return true;
- }
- const Byte WlanHelper::m_WLAN_HDR[WLAN_HDR_SIZE] =
- {
- // WLAN hdr - 4 bytes
- 0x01, 0x02, 0x03, 0x04
- };
- bool WlanHelper::LoadWlanHeader(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t *pLen)
- {
- if (bufferSize < WLAN_HDR_SIZE)
- {
- LOG_MSG_ERROR("Buffer too small\n");
- return false;
- }
- memcpy(pBuffer, m_WLAN_HDR, WLAN_HDR_SIZE);
- *pLen = WLAN_HDR_SIZE;
- return true;
- }
- bool WlanHelper::LoadWlanEth2IP4Header(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t *pLen)
- {
- size_t cnt = 0;
- size_t len = 0;
- if (!LoadWlanHeader(pBuffer, bufferSize, &cnt))
- return false;
- if (!Eth2Helper::LoadEth2IP4Header(
- pBuffer + cnt,
- bufferSize - cnt,
- &len))
- return false;
- *pLen = len + cnt;
- return true;
- }
- bool WlanHelper::LoadWlanEth2IP6Header(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t *pLen)
- {
- size_t cnt = 0;
- size_t len = 0;
- if (!LoadWlanHeader(pBuffer, bufferSize, &cnt))
- return false;
- if (!Eth2Helper::LoadEth2IP6Header(
- pBuffer + cnt,
- bufferSize - cnt,
- &len))
- return false;
- *pLen = len + cnt;
- return true;
- }
- bool WlanHelper::LoadWlanEth2IP4Packet(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t *pLen)
- {
- size_t cnt = 0;
- size_t len = 0;
- if (!LoadWlanHeader(pBuffer, bufferSize, &cnt))
- return false;
- if (!Eth2Helper::LoadEth2IP4Packet(
- pBuffer + cnt,
- bufferSize - cnt,
- &len))
- return false;
- *pLen = len + cnt;
- return true;
- }
- bool PadByLength(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t len,
- uint8_t padValue)
- {
- if (bufferSize < len)
- {
- LOG_MSG_ERROR("bufferSize < len.\n");
- return false;
- }
- memset(pBuffer, padValue, len);
- return true;
- }
- bool WlanHelper::LoadWlanEth2IP4PacketByLength(
- uint8_t *pBuffer,
- size_t bufferSize,
- size_t len,
- uint8_t padValue)
- {
- size_t cnt = 0;
- if (!LoadWlanEth2IP4Packet(pBuffer, bufferSize, &cnt))
- return false;
- if (!PadByLength(pBuffer + cnt, bufferSize - cnt, len - cnt, padValue))
- return false;
- return true;
- }
- bool RNDISAggregationHelper::LoadRNDISHeader(
- uint8_t *pBuffer,
- size_t bufferSize,
- uint32_t messageLength,
- size_t *pLen)
- {
- if (bufferSize < RNDIS_HDR_SIZE)
- {
- LOG_MSG_ERROR("Buffer too small\n");
- return false;
- }
- struct RndisHeader *pRndisHeader =
- reinterpret_cast<struct RndisHeader*>(pBuffer);
- memset(pRndisHeader, 0, sizeof(struct RndisHeader));
- pRndisHeader->MessageType = 0x01;
- pRndisHeader->DataOffset = 0x24;
- if (messageLength > RNDIS_HDR_SIZE)
- {
- pRndisHeader->MessageLength = messageLength;
- pRndisHeader->DataLength = messageLength - RNDIS_HDR_SIZE;
- }
- else
- {
- // This handles a case where we use the header
- // in IPA headers table
- // IPA needs to set these values
- pRndisHeader->MessageLength = 0;
- pRndisHeader->DataLength = 0;
- }
- *pLen = RNDIS_HDR_SIZE;
- return true;
- }
- bool RNDISAggregationHelper::LoadRNDISEth2IP4Header(
- uint8_t *pBuffer,
- size_t bufferSize,
- uint32_t messageLength,
- size_t *pLen)
- {
- size_t cnt = 0;
- size_t len = 0;
- if (!LoadRNDISHeader(pBuffer, bufferSize, messageLength, &cnt))
- return 0;
- if (!Eth2Helper::LoadEth2IP4Header(pBuffer + cnt, bufferSize - cnt, &len))
- return false;
- *pLen = cnt + len;
- return true;
- }
- bool RNDISAggregationHelper::LoadRNDISPacket(
- enum ipa_ip_type eIP,
- uint8_t *pBuffer,
- size_t &nMaxSize)
- {
- if (nMaxSize < sizeof(struct RndisHeader))
- {
- LOG_MSG_ERROR("Buffer too small\n");
- return false;
- }
- size_t nMaxSizeForDefaultPacket = nMaxSize - sizeof(struct RndisHeader);
- if (!LoadEtherPacket(eIP, pBuffer + sizeof(struct RndisHeader),
- nMaxSizeForDefaultPacket))
- {
- LOG_MSG_ERROR("LoadEtherPacket() failed\n");
- return false;
- }
- nMaxSize = nMaxSizeForDefaultPacket + sizeof(struct RndisHeader);
- struct RndisHeader *pRndisHeader = (struct RndisHeader*)pBuffer;
- memset(pRndisHeader, 0, sizeof(struct RndisHeader));
- pRndisHeader->MessageType = 0x01;
- pRndisHeader->MessageLength = nMaxSize;
- pRndisHeader->DataOffset = 0x24;
- pRndisHeader->DataLength = nMaxSizeForDefaultPacket;
- return true;
- }
- bool RNDISAggregationHelper::LoadEtherPacket(
- enum ipa_ip_type eIP,
- uint8_t *pBuffer,
- size_t &nMaxSize)
- {
- if (nMaxSize < sizeof(struct ethhdr))
- {
- LOG_MSG_ERROR("Buffer too small\n");
- return false;
- }
- size_t nMaxSizeForDefaultPacket = nMaxSize - sizeof(struct ethhdr);
- if (!LoadDefaultPacket(eIP, pBuffer + sizeof(struct ethhdr),
- nMaxSizeForDefaultPacket))
- {
- LOG_MSG_ERROR("LoadDefaultPacket() failed\n");
- return false;
- }
- nMaxSize = nMaxSizeForDefaultPacket + sizeof(struct ethhdr);
- struct ethhdr *pEtherHeader = (struct ethhdr*)pBuffer;
- memcpy(pEtherHeader, Eth2Helper::m_ETH2_IP4_HDR, sizeof(struct ethhdr));
- print_buff(pBuffer, nMaxSize);
- return true;
- }
- bool RNDISAggregationHelper::CompareIPvsRNDISPacket(
- Byte *pIPPacket,
- int ipPacketSize,
- Byte *pRNDISPacket,
- size_t rndisPacketSize)
- {
- struct RndisHeader *pRndisHeader = (struct RndisHeader*)pRNDISPacket;
- if (pRndisHeader->MessageType != 0x01)
- {
- LOG_MSG_ERROR("Wrong MessageType 0x%8x\n",
- pRndisHeader->MessageType);
- return false;
- }
- if (pRndisHeader->MessageLength != rndisPacketSize)
- {
- LOG_MSG_ERROR(
- "Packet sizes do not match 0x%8x expected 0x%8x\n",
- pRndisHeader->MessageLength, rndisPacketSize);
- return false;
- }
- // Create Ethernet packet from the IP packet and compare it to RNDIS payload
- size_t EtherPacketSize = ipPacketSize + sizeof(struct ethhdr);
- Byte* pEtherPacket = (Byte *) malloc(EtherPacketSize);
- if (pEtherPacket == NULL) {
- LOG_MSG_ERROR("Memory allocation failure.\n");
- return false;
- }
- memcpy(pEtherPacket, Eth2Helper::m_ETH2_IP4_HDR, sizeof(struct ethhdr));
- memcpy(pEtherPacket + sizeof(struct ethhdr), pIPPacket, ipPacketSize);
- if (pRndisHeader->DataLength != EtherPacketSize)
- {
- LOG_MSG_ERROR(
- "Packet sizes do not match 0x%8x expected 0x%8x\n",
- pRndisHeader->DataLength, EtherPacketSize);
- Free(pEtherPacket);
- return false;
- }
- if(!ComparePackets(
- (Byte*)&pRndisHeader->DataOffset + pRndisHeader->DataOffset,
- EtherPacketSize, pEtherPacket, EtherPacketSize))
- {
- LOG_MSG_ERROR("Packets do not match\n");
- Free(pEtherPacket);
- return false;
- }
- Free(pEtherPacket);
- return true;
- }
- bool RNDISAggregationHelper::CompareEthervsRNDISPacket(
- Byte *pIPPacket,
- size_t ipPacketSize,
- Byte *pRNDISPacket,
- size_t rndisPacketSize)
- {
- struct RndisHeader *pRndisHeader = (struct RndisHeader*)pRNDISPacket;
- if (pRndisHeader->MessageType != 0x01)
- {
- LOG_MSG_ERROR("Wrong MessageType 0x%8x\n",
- pRndisHeader->MessageType);
- return false;
- }
- if (pRndisHeader->MessageLength != rndisPacketSize)
- {
- LOG_MSG_ERROR(
- "Packet sizes do not match 0x%8x expected 0x%8x\n",
- pRndisHeader->MessageLength, rndisPacketSize);
- return false;
- }
- if (pRndisHeader->DataLength != ipPacketSize)
- {
- LOG_MSG_ERROR(
- "Packet sizes do not match 0x%8x expected 0x%8x\n",
- pRndisHeader->DataLength, ipPacketSize);
- return false;
- }
- return ComparePackets(
- (Byte*)&pRndisHeader->DataOffset + pRndisHeader->DataOffset,
- ipPacketSize, pIPPacket, ipPacketSize);
- }
- bool RNDISAggregationHelper::ComparePackets(
- Byte *pPacket,
- int packetSize,
- Byte *pExpectedPacket,
- int expectedPacketSize)
- {
- bool res = true;
- if (packetSize != expectedPacketSize)
- {
- LOG_MSG_ERROR("Packet sizes do not match\n");
- res = false;
- }
- for (int i = 0; i < packetSize; i++)
- {
- if (pPacket[i] != pExpectedPacket[i])
- {
- LOG_MSG_ERROR(
- "Byte %d not match 0x%2x != 0x%2x\n",
- i, pPacket[i], pExpectedPacket[i]);
- res = false;
- }
- }
- if (!res)
- {
- LOG_MSG_ERROR("Packet:\n");
- print_buff(pPacket, packetSize);
- LOG_MSG_ERROR("Expected Packet:\n");
- print_buff(pExpectedPacket, expectedPacketSize);
- }
- return res;
- }
- #if !defined(MSM_IPA_TESTS) && !defined(USE_GLIB) && !defined(FEATURE_IPA_ANDROID)
- size_t strlcpy(char* dst, const char* src, size_t size)
- {
- size_t i;
- if (size == 0)
- return strlen(src);
- for (i = 0; i < (size - 1) && src[i] != '\0'; ++i)
- dst[i] = src[i];
- dst[i] = '\0';
- return i + strlen(src + i);
- }
- #endif
|