Pipe.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #ifndef _PIPE_H_
  30. #define _PIPE_H_
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <unistd.h>
  35. #include <fcntl.h>
  36. #include <stdint.h>
  37. #include "linux/msm_ipa.h"
  38. #include "Constants.h"
  39. #include "Logger.h"
  40. using namespace std;
  41. /*This class will be used to interact with the system pipes
  42. *by only referring to Client type.
  43. *It will allow "raw" data transfer to/from the IPA and
  44. *will allow a encapsulation of the header addition/
  45. *removal of a packets thus allowing
  46. *the test to deal only with IP packet.
  47. */
  48. class Pipe
  49. {
  50. public:
  51. /* see Constants.h for nClientType / eConfiguration */
  52. Pipe(enum ipa_client_type nClientType,
  53. IPATestConfiguration eConfiguration);
  54. /* exception pipe Ctor */
  55. Pipe(IPATestConfiguration eConfiguration);
  56. ~Pipe();
  57. /*In this method the actual inode openning will occur.*/
  58. bool Init();
  59. /*The close of the inode*/
  60. void Destroy();
  61. /*Send the pBuffer(which is an ip[ packet)
  62. *after adding the header to the packet.*/
  63. int AddHeaderAndSend(
  64. unsigned char *pBuffer,
  65. size_t nIPPacketSize);
  66. /*Send raw data as is - no header removal
  67. *- nBytesToSend bytes will be added*/
  68. int Send(
  69. unsigned char *pBuffer,
  70. size_t nBytesToSend);
  71. /*Receive data from the IPA and remove its header*/
  72. int ReceiveAndRemoveHeader(
  73. unsigned char *pBuffer,
  74. size_t nIPPacketSize);
  75. /*Receive data from the IPA as is*/
  76. int Receive(unsigned char *pBuffer, size_t nBytesToReceive);
  77. /*return the Client type of this pipe.*/
  78. enum ipa_client_type GetClientType();
  79. /*Return the length of the header to be added to an
  80. *IP packet before it is being sent to the pipe
  81. *(This length will be determine by the Pipe's ClientType).
  82. */
  83. int GetHeaderLengthAdd();
  84. /*Return the length of the header to be removed from a
  85. *packet before it is being sent to the user
  86. *(thus returning only the IP packet).
  87. *(This length will be determine by the Pipe's ClientType).
  88. */
  89. int GetHeaderLengthRemove();
  90. bool EnableHolb(unsigned timerValue);
  91. bool DisableHolb();
  92. private:
  93. void SetSpecificClientParameters(
  94. enum ipa_client_type nClientType,
  95. IPATestConfiguration eConfiguration);
  96. bool ConfigureHolb(unsigned short enable, unsigned timerValue);
  97. public:
  98. /*efault Headers(Can be changed in Derived classes).*/
  99. static unsigned char m_pUsbHeader[];
  100. static unsigned char m_pHSICHeader[];
  101. static unsigned char m_pA2DUNHeader[];
  102. static unsigned char m_pA2NDUNHeader[];
  103. static unsigned char m_pQ6LANHeader[];
  104. private:
  105. int m_Fd;
  106. /*The file descriptor which will be used to transfer data
  107. * via the inode(this inode will be created by the ITAKEM)
  108. */
  109. enum ipa_client_type m_nClientType;
  110. int m_nHeaderLengthRemove;
  111. /*this length will be set in the
  112. * constructor in corresponds to m_nClientType
  113. */
  114. int m_nHeaderLengthAdd;
  115. /*this length will be set in the constructor
  116. * in corresponds to m_nClientType
  117. */
  118. unsigned char *m_pHeader;
  119. /*this pointer will be set to the current pipe used*/
  120. const char *m_pInodePath;
  121. /*this pointer will be set to the current pipe used*/
  122. bool m_bInitialized;
  123. IPATestConfiguration m_eConfiguration;
  124. /*The Pipes configuration env*/
  125. bool m_ExceptionPipe;
  126. /* Is this the exception pipe */
  127. };
  128. #endif