sgx_uae_service.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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 <oal/uae_oal_api.h>
  32. #include <aesm_error.h>
  33. #include "sgx_uae_service.h"
  34. #include "uae_service_internal.h"
  35. #include "config.h"
  36. #include "stdint.h"
  37. #include "se_sig_rl.h"
  38. #if !defined(ntohl)
  39. #define ntohl(u32) \
  40. ((uint32_t)(((((const unsigned char*)&(u32))[0]) << 24) \
  41. + ((((const unsigned char*)&(u32))[1]) << 16) \
  42. + ((((const unsigned char*)&(u32))[2]) << 8) \
  43. + (((const unsigned char*)&(u32))[3])))
  44. #endif
  45. #define GET_LAUNCH_TOKEN_TIMEOUT_MSEC (IPC_LATENCY)
  46. #define SE_INIT_QUOTE_TIMEOUT_MSEC (IPC_LATENCY)
  47. //add 3 millisecond per sig_rl entry
  48. #define SE_GET_QUOTE_TIMEOUT_MSEC(p_sig_rl) (IPC_LATENCY + ((p_sig_rl) ? 3*ntohl(((const se_sig_rl_t*)p_sig_rl)->sig_rl.n2) : 0))
  49. #define SE_GET_PS_CAP_TIMEOUT_MSEC (IPC_LATENCY)
  50. #define SE_REPORT_REMOTE_ATTESTATION_FAILURE_TIMEOUT_MSEC (IPC_LATENCY)
  51. #define GET_WHITE_LIST_SIZE_MSEC (IPC_LATENCY)
  52. #define GET_WHITE_LIST_MSEC (IPC_LATENCY)
  53. #define SGX_GET_EXTENDED_GROUP_ID_MSEC (IPC_LATENCY)
  54. #define SGX_SWITCH_EXTENDED_GROUP_MSEC (IPC_LATENCY)
  55. extern "C" {
  56. sgx_status_t get_launch_token(
  57. const enclave_css_t* signature,
  58. const sgx_attributes_t* attribute,
  59. sgx_launch_token_t* launch_token)
  60. {
  61. if (signature == NULL || attribute == NULL || launch_token == NULL)
  62. return SGX_ERROR_INVALID_PARAMETER;
  63. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  64. uae_oal_status_t status = oal_get_launch_token(signature, attribute, launch_token, GET_LAUNCH_TOKEN_TIMEOUT_MSEC*1000, &result);
  65. /*common mappings */
  66. sgx_status_t mapped = oal_map_status(status);
  67. if (mapped != SGX_SUCCESS)
  68. return mapped;
  69. mapped = oal_map_result(result);
  70. if (mapped != SGX_SUCCESS)
  71. {
  72. /*operation specific mapping */
  73. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  74. {
  75. switch (result)
  76. {
  77. case AESM_NO_DEVICE_ERROR:
  78. mapped = SGX_ERROR_NO_DEVICE;
  79. break;
  80. case AESM_GET_LICENSETOKEN_ERROR:
  81. mapped = SGX_ERROR_SERVICE_INVALID_PRIVILEGE;
  82. break;
  83. case AESM_OUT_OF_EPC:
  84. mapped = SGX_ERROR_OUT_OF_EPC;
  85. break;
  86. default:
  87. mapped = SGX_ERROR_UNEXPECTED;
  88. }
  89. }
  90. }
  91. return mapped;
  92. }
  93. sgx_status_t sgx_init_quote(
  94. sgx_target_info_t *p_target_info,
  95. sgx_epid_group_id_t *p_gid)
  96. {
  97. if (p_target_info == NULL || p_gid == NULL)
  98. return SGX_ERROR_INVALID_PARAMETER;
  99. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  100. uae_oal_status_t status = oal_init_quote(p_target_info, p_gid, SE_INIT_QUOTE_TIMEOUT_MSEC*1000, &result);
  101. sgx_status_t mapped = oal_map_status(status);
  102. if (mapped != SGX_SUCCESS)
  103. return mapped;
  104. mapped = oal_map_result(result);
  105. if (mapped != SGX_SUCCESS)
  106. {
  107. /*operation specific mapping */
  108. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  109. {
  110. switch (result)
  111. {
  112. case AESM_EPIDBLOB_ERROR:
  113. mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
  114. break;
  115. case AESM_EPID_REVOKED_ERROR:
  116. mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
  117. break;
  118. case AESM_BACKEND_SERVER_BUSY:
  119. mapped = SGX_ERROR_BUSY;
  120. break;
  121. case AESM_SGX_PROVISION_FAILED:
  122. mapped = SGX_ERROR_UNEXPECTED;
  123. break;
  124. case AESM_OUT_OF_EPC:
  125. mapped = SGX_ERROR_OUT_OF_EPC;
  126. break;
  127. default:
  128. mapped = SGX_ERROR_UNEXPECTED;
  129. }
  130. }
  131. }
  132. return mapped;
  133. }
  134. sgx_status_t sgx_get_quote(
  135. const sgx_report_t *p_report,
  136. sgx_quote_sign_type_t quote_type,
  137. const sgx_spid_t *p_spid,
  138. const sgx_quote_nonce_t *p_nonce,
  139. const uint8_t *p_sig_rl,
  140. uint32_t sig_rl_size,
  141. sgx_report_t *p_qe_report,
  142. sgx_quote_t *p_quote,
  143. uint32_t quote_size)
  144. {
  145. if (p_report == NULL || p_spid == NULL || p_quote == NULL || quote_size == 0 )
  146. return SGX_ERROR_INVALID_PARAMETER;
  147. if ((p_sig_rl == NULL && sig_rl_size != 0) ||
  148. (p_sig_rl != NULL && sig_rl_size == 0) )
  149. return SGX_ERROR_INVALID_PARAMETER;
  150. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  151. uae_oal_status_t status = oal_get_quote(p_report, quote_type, p_spid, p_nonce, p_sig_rl, sig_rl_size, p_qe_report,
  152. p_quote, quote_size, SE_GET_QUOTE_TIMEOUT_MSEC(p_sig_rl)*1000, &result);
  153. sgx_status_t mapped = oal_map_status(status);
  154. if (mapped != SGX_SUCCESS)
  155. return mapped;
  156. mapped = oal_map_result(result);
  157. if (mapped != SGX_SUCCESS)
  158. {
  159. /*operation specific mapping */
  160. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  161. {
  162. switch (result)
  163. {
  164. case AESM_EPIDBLOB_ERROR:
  165. mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
  166. break;
  167. case AESM_EPID_REVOKED_ERROR:
  168. mapped = SGX_ERROR_EPID_MEMBER_REVOKED;
  169. break;
  170. case AESM_BACKEND_SERVER_BUSY:
  171. mapped = SGX_ERROR_BUSY;
  172. break;
  173. case AESM_SGX_PROVISION_FAILED:
  174. mapped = SGX_ERROR_UNEXPECTED;
  175. break;
  176. case AESM_OUT_OF_EPC:
  177. mapped = SGX_ERROR_OUT_OF_EPC;
  178. break;
  179. default:
  180. mapped = SGX_ERROR_UNEXPECTED;
  181. }
  182. }
  183. }
  184. return mapped;
  185. }
  186. sgx_status_t sgx_get_ps_cap(sgx_ps_cap_t* p_sgx_ps_cap)
  187. {
  188. if (p_sgx_ps_cap == NULL)
  189. return SGX_ERROR_INVALID_PARAMETER;
  190. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  191. uint64_t ps_cap = 0;
  192. uae_oal_status_t status = oal_get_ps_cap(&ps_cap, SE_GET_PS_CAP_TIMEOUT_MSEC*1000, &result);
  193. p_sgx_ps_cap->ps_cap0 = (uint32_t)ps_cap;
  194. p_sgx_ps_cap->ps_cap1 = (uint32_t)(ps_cap >> 32);
  195. sgx_status_t mapped = oal_map_status(status);
  196. if (mapped != SGX_SUCCESS)
  197. return mapped;
  198. mapped = oal_map_result(result);
  199. if (mapped != SGX_SUCCESS)
  200. {
  201. /*operation specific mapping */
  202. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  203. {
  204. switch (result)
  205. {
  206. case AESM_LONG_TERM_PAIRING_FAILED:
  207. case AESM_EPH_SESSION_FAILED:
  208. case AESM_PSDA_UNAVAILABLE:
  209. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  210. break;
  211. default:
  212. mapped = SGX_ERROR_UNEXPECTED;
  213. }
  214. }
  215. }
  216. return mapped;
  217. }
  218. sgx_status_t sgx_report_attestation_status(
  219. const sgx_platform_info_t* p_platform_info,
  220. int attestation_status,
  221. sgx_update_info_bit_t* p_update_info)
  222. {
  223. if (p_platform_info == NULL || p_update_info == NULL)
  224. return SGX_ERROR_INVALID_PARAMETER;
  225. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  226. uae_oal_status_t status = oal_report_attestation_status(p_platform_info, attestation_status, p_update_info, SE_REPORT_REMOTE_ATTESTATION_FAILURE_TIMEOUT_MSEC*1000, &result);
  227. sgx_status_t mapped = oal_map_status(status);
  228. if (mapped != SGX_SUCCESS)
  229. return mapped;
  230. mapped = oal_map_result(result);
  231. if (mapped != SGX_SUCCESS)
  232. {
  233. /*operation specific mapping */
  234. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  235. {
  236. switch (result)
  237. {
  238. case AESM_BACKEND_SERVER_BUSY:
  239. mapped = SGX_ERROR_BUSY;
  240. break;
  241. case AESM_PLATFORM_INFO_BLOB_INVALID_SIG:
  242. mapped = SGX_ERROR_INVALID_PARAMETER;
  243. break;
  244. case AESM_EPIDBLOB_ERROR:
  245. mapped = SGX_ERROR_AE_INVALID_EPIDBLOB;
  246. break;
  247. case AESM_OUT_OF_EPC:
  248. mapped = SGX_ERROR_OUT_OF_EPC;
  249. break;
  250. case AESM_SGX_PROVISION_FAILED:
  251. default:
  252. mapped = SGX_ERROR_UNEXPECTED;
  253. }
  254. }
  255. }
  256. return mapped;
  257. }
  258. sgx_status_t create_session_ocall(
  259. uint32_t *session_id,
  260. uint8_t *se_dh_msg1,
  261. uint32_t dh_msg1_size,
  262. uint32_t timeout)
  263. {
  264. if(!session_id || !se_dh_msg1)
  265. return SGX_ERROR_INVALID_PARAMETER;
  266. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  267. uae_oal_status_t status = oal_create_session(session_id, se_dh_msg1, dh_msg1_size, timeout*1000, &result);
  268. sgx_status_t mapped = oal_map_status(status);
  269. if (mapped != SGX_SUCCESS)
  270. return mapped;
  271. mapped = oal_map_result(result);
  272. if (mapped != SGX_SUCCESS)
  273. {
  274. /*operation specific mapping */
  275. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  276. {
  277. switch (result)
  278. {
  279. case AESM_MAX_NUM_SESSION_REACHED:
  280. mapped = SGX_ERROR_BUSY;
  281. break;
  282. case AESM_EPH_SESSION_FAILED:
  283. case AESM_LONG_TERM_PAIRING_FAILED:
  284. case AESM_PSDA_UNAVAILABLE:
  285. case AESM_SERVICE_NOT_AVAILABLE:
  286. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  287. break;
  288. case AESM_OUT_OF_EPC:
  289. mapped = SGX_ERROR_OUT_OF_EPC;
  290. break;
  291. case AESM_MSG_ERROR:
  292. default:
  293. mapped = SGX_ERROR_UNEXPECTED;
  294. }
  295. }
  296. }
  297. return mapped;
  298. }
  299. sgx_status_t exchange_report_ocall(
  300. uint32_t session_id,
  301. const uint8_t *se_dh_msg2,
  302. uint32_t dh_msg2_size,
  303. uint8_t *se_dh_msg3,
  304. uint32_t dh_msg3_size,
  305. uint32_t timeout)
  306. {
  307. if (!se_dh_msg2 || !se_dh_msg3)
  308. return SGX_ERROR_INVALID_PARAMETER;
  309. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  310. uae_oal_status_t status = oal_exchange_report(session_id, se_dh_msg2, dh_msg2_size, se_dh_msg3, dh_msg3_size, timeout*1000, &result);
  311. sgx_status_t mapped = oal_map_status(status);
  312. if (mapped != SGX_SUCCESS)
  313. return mapped;
  314. mapped = oal_map_result(result);
  315. if (mapped != SGX_SUCCESS)
  316. {
  317. /*operation specific mapping */
  318. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  319. {
  320. switch (result)
  321. {
  322. case AESM_SESSION_INVALID:
  323. mapped = SGX_ERROR_AE_SESSION_INVALID;
  324. break;
  325. case AESM_KDF_MISMATCH:
  326. mapped = SGX_ERROR_KDF_MISMATCH;
  327. break;
  328. case AESM_EPH_SESSION_FAILED:
  329. case AESM_LONG_TERM_PAIRING_FAILED:
  330. case AESM_PSDA_UNAVAILABLE:
  331. case AESM_SERVICE_NOT_AVAILABLE:
  332. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  333. break;
  334. case AESM_OUT_OF_EPC:
  335. mapped = SGX_ERROR_OUT_OF_EPC;
  336. break;
  337. default:
  338. mapped = SGX_ERROR_UNEXPECTED;
  339. }
  340. }
  341. }
  342. return mapped;
  343. }
  344. sgx_status_t close_session_ocall(
  345. uint32_t session_id,
  346. uint32_t timeout)
  347. {
  348. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  349. uae_oal_status_t status = oal_close_session(session_id, timeout*1000, &result);
  350. sgx_status_t mapped = oal_map_status(status);
  351. if (mapped != SGX_SUCCESS)
  352. return mapped;
  353. mapped = oal_map_result(result);
  354. if (mapped != SGX_SUCCESS)
  355. {
  356. /*operation specific mapping */
  357. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  358. {
  359. switch (result)
  360. {
  361. case AESM_SESSION_INVALID:
  362. mapped = SGX_ERROR_AE_SESSION_INVALID;
  363. break;
  364. case AESM_EPH_SESSION_FAILED:
  365. case AESM_LONG_TERM_PAIRING_FAILED:
  366. case AESM_SERVICE_NOT_AVAILABLE:
  367. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  368. break;
  369. case AESM_OUT_OF_EPC:
  370. mapped = SGX_ERROR_OUT_OF_EPC;
  371. break;
  372. default:
  373. mapped = SGX_ERROR_UNEXPECTED;
  374. }
  375. }
  376. }
  377. return mapped;
  378. }
  379. sgx_status_t invoke_service_ocall(
  380. const uint8_t *pse_message_req,
  381. uint32_t pse_message_req_size,
  382. uint8_t *pse_message_resp,
  383. uint32_t pse_message_resp_size,
  384. uint32_t timeout)
  385. {
  386. if (pse_message_req == NULL || pse_message_resp == NULL)
  387. return SGX_ERROR_INVALID_PARAMETER;
  388. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  389. uae_oal_status_t status = oal_invoke_service(pse_message_req, pse_message_req_size, pse_message_resp, pse_message_resp_size, timeout*1000, &result);
  390. sgx_status_t mapped = oal_map_status(status);
  391. if (mapped != SGX_SUCCESS)
  392. return mapped;
  393. mapped = oal_map_result(result);
  394. if (mapped != SGX_SUCCESS)
  395. {
  396. /*operation specific mapping */
  397. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  398. {
  399. switch (result)
  400. {
  401. case AESM_SESSION_INVALID:
  402. mapped = SGX_ERROR_AE_SESSION_INVALID;
  403. break;
  404. case AESM_EPH_SESSION_FAILED:
  405. case AESM_LONG_TERM_PAIRING_FAILED:
  406. case AESM_PSDA_UNAVAILABLE:
  407. case AESM_SERVICE_NOT_AVAILABLE:
  408. mapped = SGX_ERROR_SERVICE_UNAVAILABLE;
  409. break;
  410. case AESM_OUT_OF_EPC:
  411. mapped = SGX_ERROR_OUT_OF_EPC;
  412. break;
  413. case AESM_MSG_ERROR:
  414. default:
  415. mapped = SGX_ERROR_UNEXPECTED;
  416. }
  417. }
  418. }
  419. return mapped;
  420. }
  421. sgx_status_t sgx_get_whitelist_size(
  422. uint32_t* p_whitelist_size)
  423. {
  424. if (p_whitelist_size == NULL)
  425. return SGX_ERROR_INVALID_PARAMETER;
  426. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  427. uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
  428. ret = oal_get_whitelist_size(p_whitelist_size, GET_WHITE_LIST_SIZE_MSEC*1000, &result);
  429. //common mappings
  430. sgx_status_t mapped = oal_map_status(ret);
  431. if (mapped != SGX_SUCCESS)
  432. return mapped;
  433. mapped = oal_map_result(result);
  434. if (mapped != SGX_SUCCESS)
  435. {
  436. //operation specific mapping
  437. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  438. {
  439. switch (result)
  440. {
  441. default:
  442. mapped = SGX_ERROR_UNEXPECTED;
  443. }
  444. }
  445. }
  446. return mapped;
  447. }
  448. sgx_status_t sgx_get_whitelist(
  449. uint8_t* p_whitelist,
  450. uint32_t whitelist_size)
  451. {
  452. if (p_whitelist == NULL || whitelist_size == 0)
  453. return SGX_ERROR_INVALID_PARAMETER;
  454. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  455. uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
  456. ret = oal_get_whitelist(p_whitelist, whitelist_size, GET_WHITE_LIST_MSEC*1000, &result);
  457. //common mappings
  458. sgx_status_t mapped = oal_map_status(ret);
  459. if (mapped != SGX_SUCCESS)
  460. return mapped;
  461. mapped = oal_map_result(result);
  462. if (mapped != SGX_SUCCESS)
  463. {
  464. //operation specific mapping
  465. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  466. {
  467. switch (result)
  468. {
  469. default:
  470. mapped = SGX_ERROR_UNEXPECTED;
  471. }
  472. }
  473. }
  474. return mapped;
  475. }
  476. sgx_status_t sgx_get_extended_epid_group_id(
  477. uint32_t* p_extended_epid_group_id)
  478. {
  479. if (p_extended_epid_group_id == NULL)
  480. return SGX_ERROR_INVALID_PARAMETER;
  481. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  482. uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
  483. ret = oal_get_extended_epid_group_id(p_extended_epid_group_id, SGX_GET_EXTENDED_GROUP_ID_MSEC*1000, &result);
  484. //common mappings
  485. sgx_status_t mapped = oal_map_status(ret);
  486. if (mapped != SGX_SUCCESS)
  487. return mapped;
  488. mapped = oal_map_result(result);
  489. if (mapped != SGX_SUCCESS)
  490. {
  491. //operation specific mapping
  492. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  493. {
  494. switch (result)
  495. {
  496. default:
  497. mapped = SGX_ERROR_UNEXPECTED;
  498. }
  499. }
  500. }
  501. return mapped;
  502. }
  503. sgx_status_t sgx_switch_extended_epid_group(uint32_t extended_epid_group_id)
  504. {
  505. aesm_error_t result = AESM_UNEXPECTED_ERROR;
  506. uae_oal_status_t ret = UAE_OAL_ERROR_UNEXPECTED;
  507. ret = oal_switch_extended_epid_group(extended_epid_group_id, SGX_SWITCH_EXTENDED_GROUP_MSEC*1000, &result);
  508. //common mappings
  509. sgx_status_t mapped = oal_map_status(ret);
  510. if (mapped != SGX_SUCCESS)
  511. return mapped;
  512. mapped = oal_map_result(result);
  513. if (mapped != SGX_SUCCESS)
  514. {
  515. //operation specific mapping
  516. if (mapped == SGX_ERROR_UNEXPECTED && result != AESM_UNEXPECTED_ERROR)
  517. {
  518. switch (result)
  519. {
  520. default:
  521. mapped = SGX_ERROR_UNEXPECTED;
  522. }
  523. }
  524. }
  525. return mapped;
  526. }
  527. // common mapper function for all OAL specific error codes
  528. sgx_status_t oal_map_status(uae_oal_status_t status)
  529. {
  530. sgx_status_t retVal;
  531. switch (status)
  532. {
  533. case UAE_OAL_SUCCESS:
  534. retVal = SGX_SUCCESS;
  535. break;
  536. case UAE_OAL_ERROR_UNEXPECTED:
  537. retVal = SGX_ERROR_UNEXPECTED;
  538. break;
  539. case UAE_OAL_ERROR_AESM_UNAVAILABLE:
  540. retVal = SGX_ERROR_SERVICE_UNAVAILABLE;
  541. break;
  542. case UAE_OAL_ERROR_TIMEOUT:
  543. retVal = SGX_ERROR_SERVICE_TIMEOUT;
  544. break;
  545. default:
  546. retVal = SGX_ERROR_UNEXPECTED;
  547. }
  548. return retVal;
  549. }
  550. sgx_status_t oal_map_result(aesm_error_t result)
  551. {
  552. sgx_status_t retVal = SGX_ERROR_UNEXPECTED;
  553. switch (result)
  554. {
  555. case AESM_SUCCESS:
  556. retVal = SGX_SUCCESS;
  557. break;
  558. case AESM_UPDATE_AVAILABLE:
  559. retVal = SGX_ERROR_UPDATE_NEEDED;
  560. break;
  561. case AESM_UNEXPECTED_ERROR:
  562. retVal = SGX_ERROR_UNEXPECTED;
  563. break;
  564. case AESM_PARAMETER_ERROR:
  565. retVal = SGX_ERROR_INVALID_PARAMETER;
  566. break;
  567. case AESM_SERVICE_STOPPED:
  568. case AESM_SERVICE_UNAVAILABLE:
  569. retVal = SGX_ERROR_SERVICE_UNAVAILABLE;
  570. break;
  571. case AESM_OUT_OF_MEMORY_ERROR:
  572. retVal = SGX_ERROR_OUT_OF_MEMORY;
  573. break;
  574. case AESM_BUSY:
  575. retVal = SGX_ERROR_BUSY;
  576. break;
  577. case AESM_UNRECOGNIZED_PLATFORM:
  578. retVal = SGX_ERROR_UNRECOGNIZED_PLATFORM;
  579. break;
  580. case AESM_NETWORK_ERROR:
  581. case AESM_NETWORK_BUSY_ERROR:
  582. case AESM_PROXY_SETTING_ASSIST:
  583. retVal = SGX_ERROR_NETWORK_FAILURE;
  584. break;
  585. case AESM_NO_DEVICE_ERROR:
  586. retVal = SGX_ERROR_NO_DEVICE;
  587. break;
  588. default:
  589. retVal = SGX_ERROR_UNEXPECTED;
  590. }
  591. return retVal;
  592. }
  593. } /* extern "C" */