static int tpm_usermode_resmgr_connect()

in src/tpm_comm_linux.c [247:283]


static int tpm_usermode_resmgr_connect(TPM_COMM_INFO* handle)
{
    bool result;
    bool oldTrm, newTrm;

    // First check the presence of the latest user mode TRM variety
    handle->dev_info.tcti.ctx_handle = load_abrmd(&handle->dev_info.tcti.dylib);
    if (handle->dev_info.tcti.ctx_handle) {
        handle->conn_info = TCI_TCTI | TCI_TRM;
        result = 0;
    }
    else
    {
        oldTrm = access(TPM_OLD_USERMODE_RESOURCE_MGR_64, F_OK) != -1
                   || access(TPM_OLD_USERMODE_RESOURCE_MGR_32, F_OK) != -1
                   || access(TPM_OLD_USERMODE_RESOURCE_MGR_ARM, F_OK) != -1;
        newTrm = access(TPM_NEW_USERMODE_RESOURCE_MGR_64, F_OK) != -1
                   || access(TPM_NEW_USERMODE_RESOURCE_MGR_32, F_OK) != -1
                   || access(TPM_NEW_USERMODE_RESOURCE_MGR_ARM, F_OK) != -1;
        if (!(oldTrm || newTrm))
        {
            LogError("Failure: No user mode TRM found.");
            result = MU_FAILURE;
        }
        else if ((handle->dev_info.socket_conn = tpm_socket_create(TPM_UM_RM_ADDRESS, TPM_UM_RM_PORT)) == NULL)
        {
            LogError("Failure: connecting to user mode TRM.");
            result = MU_FAILURE;
        }
        else
        {
            handle->conn_info = TCI_SOCKET | (oldTrm ? TCI_OLD_UM_TRM : TCI_TRM);
            result = 0;
        }
    }
    return result;
}