/**
 * @file uuid_utils.c
 * @brief Multibuild's UUID-related utils implementation
 * @author Iaroslav Makarchuk (i.makarchuk@samsung.com)
 * @date Created Oct 3, 2016
 * @par In Samsung Ukraine R&D Center (SURC) under a contract between
 * @par LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine) and
 * @par "Samsung Elecrtronics Co", Ltd (Seoul, Republic of Korea)
 * @par Copyright: (c) Samsung Electronics Co, Ltd 2015. All rights reserved.
 *
 * This software is proprietary of Samsung Electronics.
 * No part of this software, either material or conceptual may be copied
 * or distributed, transmitted, transcribed, stored in a retrieval system
 * or translated into any human or computer language in any form by any means,
 * electronic, mechanical, manual or otherwise, or disclosed to third parties
 * without the express written permission of Samsung Electronics.
 */
#include <uuid_utils.h>

TEE_Result TeeUuidToUuid(const TEE_UUID *tee_uuid,
                         uint8_t *uuid, uint32_t uuid_len) {
  uint32_t i = 0, j = 0;
  uint8_t *uuid_data_ptr = uuid;
  TEE_Result result = TEE_ERROR_BAD_PARAMETERS;

  if (uuid_len != sizeof(TEE_UUID) || !tee_uuid || !uuid) {
    goto exit;
  }

  uuid_data_ptr[i++] = (tee_uuid->timeLow & 0xFF000000) >> 24;
  uuid_data_ptr[i++] = (tee_uuid->timeLow & 0xFF0000) >> 16;
  uuid_data_ptr[i++] = (tee_uuid->timeLow & 0xFF00) >> 8;
  uuid_data_ptr[i++] = (tee_uuid->timeLow & 0xFF);

  uuid_data_ptr[i++] = (tee_uuid->timeMid & 0xFF00) >> 8;
  uuid_data_ptr[i++] = (tee_uuid->timeMid & 0xFF);

  uuid_data_ptr[i++] = (tee_uuid->timeHiAndVersion & 0xFF00) >> 8;
  uuid_data_ptr[i++] = (tee_uuid->timeHiAndVersion & 0xFF);

  for (j = 0; j < (uint32_t)sizeof(tee_uuid->clockSeqAndNode); j++) {
    uuid_data_ptr[i++] = tee_uuid->clockSeqAndNode[j];
  }

  result = TEE_SUCCESS;

exit:
  return result;
}

