123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- /*
- * Copyright (c) 2017 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.
- *
- * Changes from Qualcomm Innovation Center are provided under the following license:
- *
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the
- * disclaimer below) 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 Qualcomm Innovation Center, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
- * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
- * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 "RoutingDriverWrapper.h"
- #include "HeaderInsertion.h"
- #include "Filtering.h"
- #include "IPAFilteringTable.h"
- #include "TestsUtils.h"
- #include "ExceptionsTestFixture.h"
- #include "IPv4Packet.h"
- #include <string.h>
- #define MAX_SENT_BUFFER_SIZE 1500
- #define MAX_RECEIVE_BUFFER_SIZE 1500
- #define VALIDATE_WITH_MSG_AND_RETVAL(bRetVal,msg) \
- if (false == bRetVal){ \
- LOG_MSG_ERROR(msg); \
- return false; \
- }
- using namespace IPA;
- ///////////////////////////////////////////////////////////////////////////////
- class ExceptionsTestNonIpPacket: public ExceptionsTestFixture {
- public:
- //The packet size to be sent
- size_t m_nPacketSize;
- //A buffer to hold the non-IP(V4/V6) packet
- Byte *m_pSendBuffer;
- ///////////////////////////////////////////////////////////////////////////
- //Set the tests name and description
- ExceptionsTestNonIpPacket() :
- m_nPacketSize(0), m_pSendBuffer(NULL) {
- m_name = "ExceptionsTestNonIpPacket";
- m_description =
- "Create a non-IP packet(version!=4 && version !=6) and \
- expect exception from Filter block";
- }
- ///////////////////////////////////////////////////////////////////////////
- virtual bool Run() {
- bool bRetVal = true;
- Byte *pReceiveBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
- //Send the non-IPV4/IPV6 packet to the IPA
- LOG_MSG_DEBUG("Send the non-IPV4/IPV6 packet to the IPA");
- size_t nBytesSent = m_USB1ToIpaPipe.Send(m_pSendBuffer, m_nPacketSize);
- if (nBytesSent != m_nPacketSize) {
- LOG_MSG_ERROR("Not all data was sent into the IPA");
- return false;
- }
- //Read from the exception pipe(from IPA to A5) - try to read as much as we can
- size_t nBytesRead = m_IpaToA5ExceptionPipe.Receive(pReceiveBuffer,
- MAX_RECEIVE_BUFFER_SIZE);
- if (nBytesRead != nBytesSent) {
- LOG_MSG_ERROR("Not all data was read:");
- print_buff(pReceiveBuffer, nBytesRead);
- return false;
- }
- //check the exception packet against the one that we sent
- bRetVal = !memcmp(m_pSendBuffer, pReceiveBuffer, nBytesSent);
- if (false == bRetVal) {
- LOG_MSG_ERROR("Received packet is not equal, Received:");
- print_buff(pReceiveBuffer, nBytesRead);
- LOG_MSG_ERROR("Received packet is not equal, Sent:");
- print_buff(m_pSendBuffer, m_nPacketSize);
- return false;
- }
- return true;
- }
- ///////////////////////////////////////////////////////////////////////////
- //build the non-IP packet
- virtual bool Setup() {
- bool bRetVal = true;
- m_pSendBuffer = new Byte[MAX_SENT_BUFFER_SIZE];
- //Load some default IPV4 packet and save its size
- m_nPacketSize = MAX_SENT_BUFFER_SIZE; //This parameter is In/Out
- bRetVal = LoadDefaultPacket(IPA_IP_v4, m_pSendBuffer, m_nPacketSize);
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Load failed");
- //Set the version field to non-IPV4/IPV6(version = 5)
- m_pSendBuffer[0] &= 0x0F;
- m_pSendBuffer[0] |= 0x50;
- //initialize Pipes
- bRetVal = m_USB1ToIpaPipe.Init();
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
- bRetVal = m_IpaToA5ExceptionPipe.Init();
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
- return true;
- }
- ///////////////////////////////////////////////////////////////////////////
- virtual bool Teardown() {
- bool bRetVal = true;
- delete[] m_pSendBuffer;
- m_USB1ToIpaPipe.Destroy();
- m_IpaToA5ExceptionPipe.Destroy();
- return bRetVal;
- }
- ///////////////////////////////////////////////////////////////////////////
- };
- //ExceptionTestNoneIpPacket
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- class ExceptionsTestFragmentedException: public ExceptionsTestFixture {
- public:
- //The packet size to be sent
- size_t m_nPacketSize;
- //A buffer to hold the non-IP(V4/V6) packet
- Byte *m_pSendBuffer;
- Byte *m_pReceiveBuffer;
- ///////////////////////////////////////////////////////////////////////////
- //Set the tests name and description
- ExceptionsTestFragmentedException():m_nPacketSize(0), m_pSendBuffer(NULL),
- m_pReceiveBuffer(NULL){
- m_name = "ExceptionsTestFragmentedException";
- m_description =
- "Send IP packet with MF set, create global Filter rule \
- that will hit it as Exception";
- }
- ///////////////////////////////////////////////////////////////////////////
- virtual bool Run() {
- bool bRetVal = true;
- //configuring the Filter block to catch the fragmented packet:
- ConfigureFilterGlobalRuleForMF();
- //Send the non-IPV4/IPV6 packet to the IPA
- LOG_MSG_DEBUG("Send the IP packet with the MF bit set(size = %d)", m_nPacketSize);
- size_t nBytesSent = m_USB1ToIpaPipe.Send(m_pSendBuffer, m_nPacketSize);
- if (nBytesSent != m_nPacketSize) {
- LOG_MSG_ERROR("Not all data was sent into the IPA(only %d)", nBytesSent);
- return false;
- }
- //Read from the exception pipe(from IPA to A5) - try to read as much as we can
- size_t nBytesRead = m_IpaToA5ExceptionPipe.Receive(m_pReceiveBuffer,
- MAX_RECEIVE_BUFFER_SIZE);
- if (nBytesRead != nBytesSent) {
- LOG_MSG_ERROR("Not all data was read:");
- print_buff(m_pReceiveBuffer, nBytesRead);
- return false;
- }
- //check the exception packet against the one that we sent
- bRetVal = !memcmp(m_pSendBuffer, m_pReceiveBuffer, nBytesSent);
- if (false == bRetVal) {
- LOG_MSG_ERROR("Received packet is not equal, Received:");
- print_buff(m_pReceiveBuffer, nBytesRead);
- LOG_MSG_ERROR("Received packet is not equal, Sent:");
- print_buff(m_pSendBuffer, m_nPacketSize);
- return false;
- }
- return true;
- }
- ///////////////////////////////////////////////////////////////////////////
- //build the non-IP packet
- virtual bool Setup() {
- bool bRetVal = true;
- m_pReceiveBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
- m_pSendBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
- //Load some default TCP packet
- TCPPacket tcpPacket;
- //Set the MF bit
- tcpPacket.SetMF(true);
- //copy the packet to the send buffer
- m_nPacketSize = tcpPacket.GetSize();
- tcpPacket.ToNetworkByteStream(m_pSendBuffer);
- //initialize Pipes
- bRetVal = m_USB1ToIpaPipe.Init();
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
- bRetVal = m_IpaToA5ExceptionPipe.Init();
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
- return true;
- }
- ///////////////////////////////////////////////////////////////////////////
- virtual bool Teardown() {
- bool bRetVal = true;
- delete[] m_pSendBuffer;
- m_USB1ToIpaPipe.Destroy();
- m_IpaToA5ExceptionPipe.Destroy();
- return bRetVal;
- }
- ///////////////////////////////////////////////////////////////////////////
- void ConfigureFilterGlobalRuleForMF(){
- //struct ipa_ioc_add_flt_rule *pRuleTable;
- //Allocate memory for a table with one rule.
- //Instruct the Driver to write this table(with its one rule) to the HW
- //Continue from here - build the rule to catch the fragmented packet
- }
- ///////////////////////////////////////////////////////////////////////////
- };
- //ExceptionsTestFragmentedException
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- class ExceptionsTestNonTCPUDP: public ExceptionsTestFixture {
- };
- ///////////////////////////////////////////////////////////////////////////////
- //Classes instances:
- static ExceptionsTestNonIpPacket exceptionsTestNonIpPacket;
- static ExceptionsTestFragmentedException exceptionsTestFragmentedException;
- ///////////////////////////////////////////////////////////////////////////////
- ////////////// EOF ////////
- ///////////////////////////////////////////////////////////////////////////////
|