tae_ocall_api.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. 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
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #include <AEServicesProvider.h>
  32. #include <AEServices.h>
  33. #include <oal/uae_oal_api.h>
  34. #include <aesm_error.h>
  35. #include <AECreateSessionRequest.h>
  36. #include <AECreateSessionResponse.h>
  37. #include <AEInvokeServiceRequest.h>
  38. #include <AEInvokeServiceResponse.h>
  39. #include <AEExchangeReportRequest.h>
  40. #include <AEExchangeReportResponse.h>
  41. #include <AECloseSessionRequest.h>
  42. #include <AECloseSessionResponse.h>
  43. #include <new>
  44. #define TRY_CATCH_BAD_ALLOC(block) \
  45. try{ \
  46. block; \
  47. } \
  48. catch(std::bad_alloc& e) \
  49. { \
  50. *result = AESM_OUT_OF_MEMORY_ERROR; \
  51. return UAE_OAL_SUCCESS; \
  52. }
  53. extern "C"
  54. {
  55. uae_oal_status_t oal_create_session(
  56. uint32_t *sid,
  57. uint8_t* dh_msg1,
  58. uint32_t dh_msg1_size,
  59. uint32_t timeout_usec,
  60. aesm_error_t *result)
  61. {
  62. TRY_CATCH_BAD_ALLOC({
  63. //get services provider
  64. AEServices* servicesProvider = AEServicesProvider::GetServicesProvider();
  65. if (servicesProvider == NULL)
  66. return UAE_OAL_ERROR_UNEXPECTED;
  67. AECreateSessionRequest createSessionRequest(dh_msg1_size, timeout_usec / 1000);
  68. AECreateSessionResponse createSessionResponse;
  69. uae_oal_status_t ret = servicesProvider->InternalInterface(&createSessionRequest, &createSessionResponse, timeout_usec / 1000);
  70. if (ret == UAE_OAL_SUCCESS)
  71. {
  72. bool valid = createSessionResponse.GetValues((uint32_t*)result, sid, dh_msg1_size, dh_msg1);
  73. if (!valid)
  74. ret = UAE_OAL_ERROR_UNEXPECTED;
  75. }
  76. return ret;
  77. });
  78. }
  79. uae_oal_status_t oal_close_session(uint32_t sid,
  80. uint32_t timeout_usec,
  81. aesm_error_t *result)
  82. {
  83. TRY_CATCH_BAD_ALLOC({
  84. AEServices* servicesProvider = AEServicesProvider::GetServicesProvider();
  85. if (servicesProvider == NULL)
  86. return UAE_OAL_ERROR_UNEXPECTED;
  87. AECloseSessionRequest closeSessionRequest(sid, timeout_usec / 1000);
  88. AECloseSessionResponse closeSessionResponse;
  89. uae_oal_status_t ret = servicesProvider->InternalInterface(&closeSessionRequest, &closeSessionResponse, timeout_usec / 1000);
  90. if (ret == UAE_OAL_SUCCESS)
  91. {
  92. bool valid = closeSessionResponse.GetValues((uint32_t*)result);
  93. if (!valid)
  94. ret = UAE_OAL_ERROR_UNEXPECTED;
  95. }
  96. return ret;
  97. });
  98. }
  99. uae_oal_status_t oal_exchange_report(uint32_t sid,
  100. const uint8_t* dh_msg2,
  101. uint32_t dh_msg2_size,
  102. uint8_t* dh_msg3,
  103. uint32_t dh_msg3_size,
  104. uint32_t timeout_usec,
  105. aesm_error_t *result)
  106. {
  107. TRY_CATCH_BAD_ALLOC({
  108. AEServices* servicesProvider = AEServicesProvider::GetServicesProvider();
  109. if (servicesProvider == NULL)
  110. return UAE_OAL_ERROR_UNEXPECTED;
  111. AEExchangeReportRequest exchangeReportRequest(sid, dh_msg2_size, dh_msg2, dh_msg3_size, timeout_usec / 1000);
  112. AEExchangeReportResponse exchangeReportResponse;
  113. uae_oal_status_t ret = servicesProvider->InternalInterface(&exchangeReportRequest, &exchangeReportResponse, timeout_usec / 1000);
  114. if (ret == UAE_OAL_SUCCESS)
  115. {
  116. bool valid = exchangeReportResponse.GetValues((uint32_t*)result, dh_msg3_size, dh_msg3);
  117. if (!valid)
  118. ret = UAE_OAL_ERROR_UNEXPECTED;
  119. }
  120. return ret;
  121. });
  122. }
  123. uae_oal_status_t oal_invoke_service(const uint8_t* pse_message_req,
  124. uint32_t pse_message_req_size,
  125. uint8_t* pse_message_resp,
  126. uint32_t pse_message_resp_size,
  127. uint32_t timeout_usec,
  128. aesm_error_t *result)
  129. {
  130. TRY_CATCH_BAD_ALLOC({
  131. AEServices* servicesProvider = AEServicesProvider::GetServicesProvider();
  132. if (servicesProvider == NULL)
  133. return UAE_OAL_ERROR_UNEXPECTED;
  134. AEInvokeServiceRequest invokeServiceRequest(pse_message_req_size, pse_message_req, pse_message_resp_size, timeout_usec / 1000);
  135. AEInvokeServiceResponse invokeServiceResponse;
  136. uae_oal_status_t ret = servicesProvider->InternalInterface(&invokeServiceRequest, &invokeServiceResponse, timeout_usec / 1000);
  137. if (ret == UAE_OAL_SUCCESS)
  138. {
  139. bool valid = invokeServiceResponse.GetValues((uint32_t*)result, pse_message_resp_size, pse_message_resp);
  140. if (!valid)
  141. ret = UAE_OAL_ERROR_UNEXPECTED;
  142. }
  143. return ret;
  144. });
  145. }
  146. } //end of extern block