/* ------------------------------------------------------------- */
static bool tlc_open_driver(void)
{
    bool ret = false;
    enum mc_result mc_ret;
    struct mc_uuid_t dr_uuid = DR_TUI_UUID;

    /* Allocate WSM buffer for the DCI */
    mc_ret = mc_malloc_wsm(DEVICE_ID, 0, sizeof(struct tui_dci_msg_t),
                           (uint8_t **)&dci, 0);
    if (MC_DRV_OK != mc_ret) {
        pr_debug("ERROR %s: Allocation of DCI WSM failed: %d\n",
                 __func__, mc_ret);
        return false;
    }

    /* Clear the session handle */
    memset(&dr_session_handle, 0, sizeof(dr_session_handle));
    /* The device ID (default device is used */
    dr_session_handle.device_id = DEVICE_ID;
    /* Open session with the Driver */
    mc_ret = mc_open_session(&dr_session_handle, &dr_uuid, (uint8_t *)dci,
                             (uint32_t)sizeof(struct tui_dci_msg_t));
    if (MC_DRV_OK != mc_ret) {
        pr_debug("ERROR %s: Open driver session failed: %d\n",
                 __func__, mc_ret);
        ret = false;
    } else {
        ret = true;
    }

    return ret;
}
/* ------------------------------------------------------------- */
static bool tlcOpenDriver(void)
{
	bool ret = false;
	enum mc_result mcRet;

	/* Allocate WSM buffer for the DCI */
	mcRet = mc_malloc_wsm(DEVICE_ID, 0, sizeof(tuiDciMsg_t),
			(uint8_t **)&pDci, 0);
	if (MC_DRV_OK != mcRet) {
		pr_debug("ERROR tlcOpenDriver: Allocation of DCI WSM failed: %d\n",
				mcRet);
		return false;
	}

	/* Clear the session handle */
	memset(&drSessionHandle, 0, sizeof(drSessionHandle));
	/* The device ID (default device is used */
	drSessionHandle.device_id = DEVICE_ID;
	/* Open session with the Driver */
	mcRet = mc_open_session(&drSessionHandle, &drUuid, (uint8_t *)pDci,
			(uint32_t)sizeof(tuiDciMsg_t));
	if (MC_DRV_OK != mcRet) {
		pr_debug("ERROR tlcOpenDriver: Open driver session failed: %d\n",
				mcRet);
		ret = false;
	} else {
		ret = true;
	}

	return ret;
}
Example #3
0
int32_t cmdq_sec_allocate_wsm_impl(uint32_t deviceId, uint8_t **ppWsm, uint32_t wsmSize)
{
	int32_t status = 0;
	enum mc_result mcRet = MC_DRV_OK;

	do {
		if ((*ppWsm) != NULL) {
			status = -1;
			CMDQ_ERR("[SEC]_WSM_ALLOC: err[pWsm is not NULL]");
			break;
		}

		/* because world shared mem(WSM) will ba managed by mobicore device, not linux kernel */
		/* instead of vmalloc/kmalloc, call mc_malloc_wasm to alloc WSM to prvent error such as */
		/* "can not resolve tci physicall address" etc */
		mcRet = mc_malloc_wsm(deviceId, 0, wsmSize, ppWsm, 0);
		if (MC_DRV_OK != mcRet) {
			CMDQ_ERR("[SEC]_WSM_ALLOC: err[0x%x]\n", mcRet);
			status = -1;
			break;
		}

		CMDQ_MSG("[SEC]_WSM_ALLOC: status[%d], *ppWsm: 0x%p\n", status, (*ppWsm));
	} while (0);

	return status;
}
/* DO NOT invoke this function unless you get HACC lock */
int open_sdriver_connection(void)
{
	enum mc_result mcRet = 0;
	int retryCnt = 0;

	do {
		/* Initialize session handle data */
		mcRet = mc_open_device(deviceId);
		if (MC_DRV_OK != mcRet) {
			retryCnt++;
			pr_debug("NWD HACC: mc_open_device failed: %d, retry count (%d)\n", mcRet,
				 retryCnt);
			continue;
		}
		pr_debug("NWD HACC: mc_open_device success: %d\n", mcRet);

		/* Allocating WSM for DCI */
		mcRet =
		    mc_malloc_wsm(deviceId, 0, sizeof(dapc_tciMessage_t), (uint8_t **) &pTci, 0);
		if (MC_DRV_OK != mcRet) {
			pr_debug("NWD HACC: mc_malloc_wsm failed: %d\n", mcRet);
			break;
		}

		/* Open session to the trustlet */
		memset(&drSessionHandle, 0, sizeof(drSessionHandle));
		drSessionHandle.device_id = deviceId;
		mcRet =
		    mc_open_session(&drSessionHandle, &MC_UUID_HACC, (uint8_t *) pTci,
				    (uint32_t) sizeof(dapc_tciMessage_t));

		if (MC_DRV_OK != mcRet) {
			pr_debug("NWD HACC: mc_open_session failed: %d\n", mcRet);
			break;
		}

		pr_debug("NWD HACC: mc_open_session success: %d\n", mcRet);
		break;
	} while (retryCnt < 30);

	if (MC_DRV_OK != mcRet)
		return -1;

	return 0;
}
Example #5
0
static int open_tplay_driver_connection(void)
{
    enum mc_result mcRet = MC_DRV_OK;

    if (tplaySessionHandle.session_id != 0)
    {
        DDPMSG("tplay TDriver session already created\n");
        return 0;
    }

    DDPDBG("=============== late init tplay TDriver session ===============\n");
    do
    {
        late_open_mobicore_device();

        /* Allocating WSM for DCI */
        mcRet = mc_malloc_wsm(mc_deviceId, 0, sizeof(tplay_tciMessage_t), (uint8_t **) &pTplayTci, 0);
        if (MC_DRV_OK != mcRet)
        {
            DDPERR("mc_malloc_wsm failed: %d @%s line %d\n", mcRet, __func__, __LINE__);
            return -1;
        }

        /* Open session the TDriver */
        memset(&tplaySessionHandle, 0, sizeof(tplaySessionHandle));
        tplaySessionHandle.device_id = mc_deviceId;
        mcRet = mc_open_session(&tplaySessionHandle,
                                &MC_UUID_TPLAY,
                                (uint8_t *) pTplayTci,
                                (uint32_t) sizeof(tplay_tciMessage_t));
        if (MC_DRV_OK != mcRet)
        {
            DDPERR("mc_open_session failed: %d @%s line %d\n", mcRet, __func__, __LINE__);
            // if failed clear session handle
            memset(&tplaySessionHandle, 0, sizeof(tplaySessionHandle));
            return -1;
        }
    } while (0);

    return (MC_DRV_OK == mcRet) ? 0 : -1;
}
Example #6
0
//Open driver in open
static int secwidevine_session_open(void)
{
    enum mc_result mc_ret = MC_DRV_OK;

    mutex_lock(&secwidevine_lock);

    do {
        /* sessions reach max numbers ? */
        if (secwidevine_session_ref > MAX_OPEN_SESSIONS)
        {
            MSG(WRN, "secwidevine_session > 0x%x\n", MAX_OPEN_SESSIONS);
            break;
        }

        if (secwidevine_session_ref > 0)
        {
            secwidevine_session_ref++;
            break;
        }
        
        /* open device */
        mc_ret = mc_open_device(secwidevine_devid);
        if (MC_DRV_OK != mc_ret)
        {
            MSG(ERR, "mc_open_device failed: %d\n", mc_ret);
            break;
        }

        /* allocating WSM for DCI */
        /*//open trustlet
        mc_ret = mc_malloc_wsm(secwidevine_devid, 0, sizeof(tci_t),
            (uint8_t **)&secwidevine_tci, 0);
        if (MC_DRV_OK != mc_ret) {
            mc_close_device(secwidevine_devid);
            MSG(ERR, "mc_malloc_wsm failed: %d\n", mc_ret);
            break;
        }

        // open session
        secwidevine_session.device_id = secwidevine_devid;
        mc_ret = mc_open_session(&secwidevine_session, &secwidevine_uuid,
            (uint8_t *)secwidevine_tci, sizeof(tci_t));

        if (MC_DRV_OK != mc_ret)
        {
            mc_free_wsm(secwidevine_devid, (uint8_t *)secwidevine_tci);
            secwidevine_tci = NULL;
            mc_close_device(secwidevine_devid);
            MSG(ERR, "mc_open_session failed: %d\n", mc_ret);
            break;
        }*/
        //open driver
        mc_ret = mc_malloc_wsm(secwidevine_devid, 0, sizeof(tci_t), (uint8_t **) &secwidevinedr_tci,
                0);
        if (MC_DRV_OK != mc_ret)
        {
            /*mc_free_wsm(secwidevine_devid, (uint8_t *) secwidevine_tci);
            secwidevine_tci = NULL;*/
            mc_close_device(secwidevine_devid);
            MSG(ERR, "2.mc_malloc_wsm failed: %d\n", mc_ret);
            break;
        }

        /* open session */
        secwidevinedr_session.device_id = secwidevine_devid;
        mc_ret = mc_open_session(&secwidevinedr_session, &secwidevinedr_uuid,
                (uint8_t *) secwidevinedr_tci, sizeof(tci_t));

        if (MC_DRV_OK != mc_ret)
        {
           /* mc_free_wsm(secwidevine_devid, (uint8_t *) secwidevine_tci);
            secwidevine_tci = NULL;*/
            mc_free_wsm(secwidevine_devid, (uint8_t *) secwidevinedr_tci);
            secwidevinedr_tci = NULL;
            mc_close_device(secwidevine_devid);
            MSG(ERR, "2.mc_open_session failed: %d\n", mc_ret);
            break;
        }
        secwidevine_session_ref = 1;

    } while(0);

    MSG(INFO, "secwidevine_session_open: ret=%d, ref=%d\n", mc_ret, secwidevine_session_ref);
    MSG(INFO, "driver sessionId = %d, deviceId = %d\n",
                secwidevinedr_session.session_id, secwidevinedr_session.device_id);

    mutex_unlock(&secwidevine_lock);

    if (MC_DRV_OK != mc_ret)
    {
        MSG(ERR, "secwidevine_session_open fail");
        return -ENXIO;
    }

    return 0;
}
Example #7
0
//Open driver in open
static int secwidevinemdw_session_open(void)
{
    enum mc_result mc_ret = MC_DRV_OK;
    mutex_lock(&secwidevinemdw_lock);

    do {
        /* sessions reach max numbers ? */
        if (secwidevinemdw_session_ref > MAX_OPEN_SESSIONS)
        {
            MSG(WRN, "secwidevinemdw_session > 0x%x\n", MAX_OPEN_SESSIONS);
            break;
        }

        if (secwidevinemdw_session_ref > 0)
        {
            MSG(WRN, "secwidevinemdw_session already open");
            secwidevinemdw_session_ref++;
            break;
        }

        /* open device */
        mc_ret = mc_open_device(secwidevinemdw_devid);
        if (MC_DRV_OK != mc_ret)
        {
            MSG(ERR, "mc_open_device failed: %d\n", mc_ret);
            break;
        }

        /* allocating WSM for DCI */
        mc_ret = mc_malloc_wsm(secwidevinemdw_devid, 0, sizeof(dciMessage_t),
                (uint8_t **)&secwidevinemdw_dci, 0);
        if (MC_DRV_OK != mc_ret) {
            mc_close_device(secwidevinemdw_devid);
            MSG(ERR, "mc_malloc_wsm failed: %d\n", mc_ret);
            break;
        }

        // open session
        secwidevinemdwdr_session.device_id = secwidevinemdw_devid;
        mc_ret = mc_open_session(&secwidevinemdwdr_session, &secwidevinemdw_uuid,
            (uint8_t *)secwidevinemdw_dci, sizeof(dciMessage_t));

        if (MC_DRV_OK != mc_ret)
        {
            mc_free_wsm(secwidevinemdw_devid, (uint8_t *)secwidevinemdw_dci);
            secwidevinemdw_dci = NULL;
            mc_close_device(secwidevinemdw_devid);
            MSG(ERR, "mc_open_session failed: %d\n", mc_ret);
            break;
        }
        /* create a thread for listening DCI signals */
        secwidevinemdwDci_th = kthread_run(secwidevinemdw_listenDci, NULL, "secwidevinemdw_Dci");
        if (IS_ERR(secwidevinemdwDci_th))
        {
            mc_close_session(&secwidevinemdwdr_session);
            mc_free_wsm(secwidevinemdw_devid, (uint8_t *) secwidevinemdw_dci);
            secwidevinemdw_dci = NULL;
            mc_close_device(secwidevinemdw_devid);
            MSG(ERR, "%s, init kthread_run failed!\n", __func__);
            break;
        }
        secwidevinemdw_session_ref = 1;

    } while(0);

    MSG(INFO, "secwidevinemdw_session_open: ret=%d, ref=%d\n", mc_ret, secwidevinemdw_session_ref);
    MSG(INFO, "driver sessionId = %d, deviceId = %d\n",
                secwidevinemdwdr_session.session_id, secwidevinemdwdr_session.device_id);

    mutex_unlock(&secwidevinemdw_lock);

    if (MC_DRV_OK != mc_ret)
    {
        MSG(ERR, "secwidevinemdw_session_open fail");
        return -ENXIO;
    }

    return 0;
}