#include "platform_driver_api.h"

#ifdef assert
#undef assert
#endif

#include "driver_ipc.h"

#include "tlStd.h"
#include "TlApi/TlApiCommon.h"
#include "serialize.h"

/** tlApi function to call driver via IPC.
 * Sends a MSG_RQ message via IPC to a MobiCore driver.
 *
 * @param driverID The driver to send the IPC to.
 * @param payload MPointer to marshaling parameters to send to the driver.
 * @param payloadSize the size of the payload that will be sent to the driver
 *
 * @return TLAPI_OK
 * @return E_TLAPI_COM_ERROR in case of an IPC error.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApi_callDriverEx(
    uint32_t driver_ID,
    void* payload,
    uint32_t payloadSize);

/**
 * TBase uses one buffer as input and output for IPC, so we will set max allowed
 * buffer size to protect from situation where output size is greater than input size
 */
PaTzResult PlatformCallDriver(uint32_t id_driver, uint32_t ioctl_cmd,
                              void *params, uint32_t size_params) {
  tlApiResult_t ret = tlApi_callDriverEx(id_driver, params, kSerializedDataMaxSize);

  return (ret == TLAPI_OK ? PA_TZ_SUCCESS: PA_TZ_GENERAL_ERROR);
}

void PlatformRegisterTrustletOutputBuffer(void *data, size_t size) {
}

void PlatformRegisterTrustletInputBuffer(const void *data, size_t size) {
}
