void TEEC_FinalizeContext(TEEC_Context *context)
{
    mcResult_t      mcRet;

    LOG_I("== %s() ==============", __func__);

    //The parameter context MUST point to an initialized TEE Context.
    //Just realized: The function implementation MUST do nothing if context is NULL.
    if (context == NULL) {
        LOG_E("context is NULL");
        return;
    }

    //The implementation of this function MUST NOT be able to fail: after this function returns the Client
    //Application must be able to consider that the Context has been closed.
    mcRet = mcCloseDevice(context->imp.reserved);
    if (mcRet != MC_DRV_OK) {
        LOG_E("mcCloseDevice failed (%08x)", mcRet);
        /* continue even in case of error */;
    }
}
Esempio n. 2
0
// -------------------------------------------------------------
void tlcClose(void)
{
    mcResult_t ret;

    LOG_I("Closing the session");
    ret = mcCloseSession(&sessionHandle);
    if (MC_DRV_OK != ret) 
    {
        LOG_E("Closing session failed: %d", ret);
        /* continue even in case of error */
    }

    LOG_I("Closing <t-base device");
    ret = mcCloseDevice(DEVICE_ID);
    if (MC_DRV_OK != ret) 
    {
        LOG_E("Closing <t-base device failed: %d", ret);
        /* continue even in case of error */;
    }
    free(tci);
    tci = NULL;
}
mcResult_t tlc_close(mc_comm_ctx *comm_ctx) {
	mcResult_t	mcRet;

	LOG_I("close() called");
	do {

		// -------------------------------------------------------------
		// Step 1: Free WSM
		LOG_I("Free WSM");
		mcRet = mcFreeWsm((comm_ctx->device_id), (uint8_t *)(comm_ctx->tci_msg));
		if (MC_DRV_OK != mcRet) {
			LOG_E("Free WSM failed: %d", mcRet);
			break;
		}

		// -------------------------------------------------------------
		// Step 2: Close session with the Trustlet
		LOG_I("Closing the session");
		mcRet = mcCloseSession(&(comm_ctx->handle));
		if (MC_DRV_OK != mcRet) {
			LOG_E("Closing session failed: %d", mcRet);
			break;
		}

		// -------------------------------------------------------------
		// Step 3: Close the MobiCore device
		LOG_I("Closing MobiCore device");
		mcRet = mcCloseDevice(comm_ctx->device_id);
		if (MC_DRV_OK != mcRet) {
			LOG_E("Closing MobiCore device failed: %d", mcRet);
			break;
		}

		LOG_I("tlc_close() succeeded");
	} while (false);

	return mcRet;
}
Esempio n. 4
0
// -------------------------------------------------------------
mcResult_t tlcOpen(void)
{
    mcResult_t mcRet;
    mcVersionInfo_t versionInfo;
    uint8_t* pTrustletData = NULL;
    uint32_t nTrustletSize;

    printf("Opening <t-base device\n");
    mcRet = mcOpenDevice(DEVICE_ID);
    if (MC_DRV_OK != mcRet) 
    {
	    printf("Error opening device: %d\n", mcRet);
	    return mcRet;
    }

    mcRet = mcGetMobiCoreVersion(MC_DEVICE_ID_DEFAULT, &versionInfo);
    if (MC_DRV_OK != mcRet) 
    {
        printf("mcGetMobiCoreVersion failed %d\n", mcRet);
        mcCloseDevice(DEVICE_ID);
        return mcRet;
    }
    LOG_I("productId        = %s", versionInfo.productId);
    LOG_I("versionMci       = 0x%08X", versionInfo.versionMci);
    LOG_I("versionSo        = 0x%08X", versionInfo.versionSo);
    LOG_I("versionMclf      = 0x%08X", versionInfo.versionMclf);
    LOG_I("versionContainer = 0x%08X", versionInfo.versionContainer);
    LOG_I("versionMcConfig  = 0x%08X", versionInfo.versionMcConfig);
    LOG_I("versionTlApi     = 0x%08X", versionInfo.versionTlApi);
    LOG_I("versionDrApi     = 0x%08X", versionInfo.versionDrApi);
    LOG_I("versionCmp       = 0x%08X", versionInfo.versionCmp);

    tci = (dapc_tciMessage_t*)malloc(sizeof(dapc_tciMessage_t));
    dci = (dapc_tciMessage_t*)malloc(sizeof(dapc_tciMessage_t));
    
    if (tci == NULL) 
    {
        printf("Allocation of TCI failed\n");
        mcCloseDevice(DEVICE_ID);
        return MC_DRV_ERR_NO_FREE_MEMORY;
    }
    memset(tci, 0, sizeof(dapc_tciMessage_t));
    
    if (dci == NULL) 
    {
        printf("Allocation of DCI failed\n");
        mcCloseDevice(DEVICE_ID);
        return MC_DRV_ERR_NO_FREE_MEMORY;
    }
    memset(dci, 0, sizeof(dapc_tciMessage_t));      

    nTrustletSize = getFileContent(
                        "05200000000000000000000000000000.tlbin",
                        &pTrustletData);                      
                        
    if (nTrustletSize == 0) 
    {
        printf("Trustlet not found\n");
        free(tci);
        tci = NULL;
        mcCloseDevice(DEVICE_ID);
        return MC_DRV_ERR_TRUSTLET_NOT_FOUND;
    }

    printf("Opening the session\n");
    memset(&sessionHandle, 0, sizeof(sessionHandle));
    sessionHandle.deviceId = DEVICE_ID; // The device ID (default device is used)
    mcRet = mcOpenTrustlet(
            &sessionHandle,
            MC_SPID_RESERVED_TEST, /* mcSpid_t */
            pTrustletData,
            nTrustletSize,
            (uint8_t *) tci,
            sizeof(dapc_tciMessage_t));
            
    if (MC_DRV_OK != mcRet) 
    {
        printf("Open session failed: %d\n", mcRet);
        free(tci);
        tci = NULL;
        mcCloseDevice(DEVICE_ID);
    }
    else 
    {
        printf("open() succeeded\n");
    }
            
    nTrustletSize = getFileContent(
                        "05190000000000000000000000000000.drbin",
                        &pTrustletData);                      
                        
    if (nTrustletSize == 0) 
    {
        printf("Driver not found\n");
        free(tci);
        tci = NULL;
        mcCloseDevice(DEVICE_ID);
        return MC_DRV_ERR_TRUSTLET_NOT_FOUND;
    }
	
    // Whatever the result is, free the buffer
    free(pTrustletData);

    if (MC_DRV_OK != mcRet) 
    {
        printf("Open session failed: %d\n", mcRet);
        free(tci);
        tci = NULL;
        mcCloseDevice(DEVICE_ID);
    }
    else 
    {
        printf("open() succeeded\n");
    }

    return mcRet;
}