#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <tee_client_api.h>

TEEC_UUID uuid = {
    .timeLow = 0x666d392c,
    .timeMid = 0x87ae,
    .timeHiAndVersion = 0x4307,
    .clockSeqAndNode = {0x9c, 0xdb, 0x6d, 0x5d, 0xc9, 0xd6, 0xeb, 0x70}
};

int main(void)
{
    TEEC_Context context;
    TEEC_Session session;
    TEEC_Operation operation;
    uint32_t returnOrigin;
    TEEC_Result res = TEEC_InitializeContext(NULL, &context);

    if (res != TEEC_SUCCESS) {
        fprintf(stderr,"InitializeContext failed: %x\n", res);
        return 1;
    }

    res = TEEC_OpenSession(&context, &session, &uuid, 0, NULL, NULL, \
                           &returnOrigin);
    if (res != TEEC_SUCCESS) {
        fprintf(stderr,"TEEC_OpenSession returned %x from %x\n", res,
                returnOrigin);
        return 1;
    }
    operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE,
                                            TEEC_NONE,
                                            TEEC_NONE,
                                            TEEC_NONE);

    res = TEEC_InvokeCommand(&session, 0x0, &operation, &returnOrigin);
    if (res != TEEC_SUCCESS) {
        fprintf(stderr,"Error %x from %x occured during digest test\n", res,
                returnOrigin);
    } else {
        fprintf(stdout,"SWd digest test succeeded!\n");
    }

    TEEC_CloseSession(&session);
    TEEC_FinalizeContext(&context);
    return (res != TEEC_SUCCESS);
}
