TEEC_Result TEEC_InitializeContext(const char *name,
				   TEEC_Context *context)
{
	int error;
	struct tf_connection *connection = NULL;

	error = tf_open(tf_get_device(), NULL, &connection);
	if (error != 0) {
		dprintk(KERN_ERR "TEEC_InitializeContext(%s): "
			"tf_open failed (error %d)!\n",
			(name == NULL ? "(null)" : name), error);
		goto error;
	}
	BUG_ON(connection == NULL);
	connection->owner = TF_CONNECTION_OWNER_KERNEL;

	error = tf_create_device_context(connection);
	if (error != 0) {
		dprintk(KERN_ERR "TEEC_InitializeContext(%s): "
			"tf_create_device_context failed (error %d)!\n",
			(name == NULL ? "(null)" : name), error);
		goto error;
	}

	context->imp._connection = connection;
	/*spin_lock_init(&context->imp._operations_lock);*/
	return S_SUCCESS;

error:
	tf_close(connection);
	return TEEC_encode_error(error);
}
Ejemplo n.º 2
0
static int tf_ctrl_device_open(struct inode *inode, struct file *file)
{
	int error;
	struct tf_connection *connection = NULL;

	dpr_info("%s(%u:%u, %p)\n",
		__func__, imajor(inode), iminor(inode), file);

	/* Dummy lseek for non-seekable driver */
	error = nonseekable_open(inode, file);
	if (error != 0) {
		dpr_err("%s(%p): "
			"nonseekable_open failed (error %d)!\n",
			__func__, file, error);
		goto error;
	}

#ifndef CONFIG_ANDROID
	/*
	 * Check file flags. We only autthorize the O_RDWR access
	 */
	if (file->f_flags != O_RDWR) {
		dpr_err("%s(%p): "
			"Invalid access mode %u\n",
			__func__, file, file->f_flags);
		error = -EACCES;
		goto error;
	}
#endif

	error = tf_ctrl_check_omap_type();
	if (error <= 0)
		return error;

	error = tf_open(tf_get_device(), file, &connection);
	if (error != 0) {
		dpr_err("%s(%p): tf_open failed (error %d)!\n",
			__func__, file, error);
		goto error;
	}

	file->private_data = connection;

	/*
	 * Successful completion.
	 */

	dpr_info("%s(%p): Success\n", __func__, file);
	return 0;

	/*
	 * Error handling.
	 */
error:
	tf_close(connection);
	dpr_info("%s(%p): Failure (error %d)\n",
		__func__, file, error);
	return error;
}
Ejemplo n.º 3
0
static int tf_device_open(struct inode *inode, struct file *file)
{
	int error;
	struct tf_device *dev = &g_tf_dev;
	struct tf_connection *connection = NULL;

	dprintk(KERN_INFO "tf_device_open(%u:%u, %p)\n",
		imajor(inode), iminor(inode), file);

	/* Dummy lseek for non-seekable driver */
	error = nonseekable_open(inode, file);
	if (error != 0) {
		dprintk(KERN_ERR "tf_device_open(%p): "
			"nonseekable_open failed (error %d)!\n",
			file, error);
		goto error;
	}

#ifndef CONFIG_ANDROID
	/*
	 * Check file flags. We only autthorize the O_RDWR access
	 */
	if (file->f_flags != O_RDWR) {
		dprintk(KERN_ERR "tf_device_open(%p): "
			"Invalid access mode %u\n",
			file, file->f_flags);
		error = -EACCES;
		goto error;
	}
#endif

	/*
	 * Open a new connection.
	 */

	error = tf_open(dev, file, &connection);
	if (error != 0) {
		dprintk(KERN_ERR "tf_device_open(%p): "
			"tf_open failed (error %d)!\n",
			file, error);
		goto error;
	}

	file->private_data = connection;

	/*
	 * Send the CreateDeviceContext command to the secure
	 */
	error = tf_create_device_context(connection);
	if (error != 0) {
		dprintk(KERN_ERR "tf_device_open(%p): "
			"tf_create_device_context failed (error %d)!\n",
			file, error);
		goto error1;
	}

	/*
	 * Successful completion.
	 */

	dprintk(KERN_INFO "tf_device_open(%p): Success (connection=%p)\n",
		file, connection);
	return 0;

	/*
	 * Error handling.
	 */

error1:
	tf_close(connection);
error:
	dprintk(KERN_INFO "tf_device_open(%p): Failure (error %d)\n",
		file, error);
	return error;
}
Ejemplo n.º 4
0
int fcache_read(FBLOCK ** cp, char *filename)
{
    int n, nmax, tchars, fd;
    char *buff;
    FBLOCK *fp, *tfp;
    /*
     * Free a prior buffer chain
     */
    fp = *cp;

    while (fp != NULL) {
	tfp = fp->hdr.nxt;
	free_mbuf(fp);
	fp = tfp;
    }

    *cp = NULL;

    /*
     * Read the text file into a new chain
     */

    if ((fd = tf_open(filename, O_RDONLY)) == -1) {
	/*
	 * Failure: log the event
	 */
	log_write(LOG_PROBLEMS, "FIL", "OPEN", "Couldn't open file '%s'.", filename);
	tf_close(fd);
	return -1;
    }

    buff = alloc_lbuf("fcache_read.temp");
    /*
     * Set up the initial cache buffer to make things easier
     */
    fp = (FBLOCK *) alloc_mbuf("fcache_read.first");
    fp->hdr.nxt = NULL;
    fp->hdr.nchars = 0;
    *cp = fp;
    tchars = 0;
    /*
     * Process the file, one lbuf at a time
     */
    nmax = read(fd, buff, LBUF_SIZE);

    while (nmax > 0) {
	for (n = 0; n < nmax; n++) {
	    switch (buff[n]) {
	    case '\n':
		fp = fcache_fill(fp, '\r');
		fp = fcache_fill(fp, '\n');
		tchars += 2;

	    case '\0':
	    case '\r':
		break;

	    default:
		fp = fcache_fill(fp, buff[n]);
		tchars++;
	    }
	}

	nmax = read(fd, buff, LBUF_SIZE);
    }

    free_lbuf(buff);
    tf_close(fd);

    /*
     * If we didn't read anything in, toss the initial buffer
     */

    if (fp->hdr.nchars == 0) {
	*cp = NULL;
	free_mbuf(fp);
    }

    return tchars;
}
Ejemplo n.º 5
0
static int tf_device_open(struct inode *inode, struct file *file)
{
	int error;
	struct tf_device *dev = &g_tf_dev;
	struct tf_connection *connection = NULL;

	dprintk(KERN_INFO "tf_device_open(%u:%u, %p)\n",
		imajor(inode), iminor(inode), file);

	/* Dummy lseek for non-seekable driver */
	error = nonseekable_open(inode, file);
	if (error != 0) {
		dprintk(KERN_ERR "tf_device_open(%p): "
			"nonseekable_open failed (error %d)!\n",
			file, error);
		goto error;
	}

	/*
	 * Open a new connection.
	 */

	error = tf_open(dev, file, &connection);
	if (error != 0) {
		dprintk(KERN_ERR "tf_device_open(%p): "
			"tf_open failed (error %d)!\n",
			file, error);
		goto error;
	}

	file->private_data = connection;

	/*
	 * Send the CreateDeviceContext command to the secure
	 */
	error = tf_create_device_context(connection);
	if (error != 0) {
		dprintk(KERN_ERR "tf_device_open(%p): "
			"tf_create_device_context failed (error %d)!\n",
			file, error);
		goto error1;
	}

	/*
	 * Successful completion.
	 */

	dprintk(KERN_INFO "tf_device_open(%p): Success (connection=%p)\n",
		file, connection);
	return 0;

	/*
	 * Error handling.
	 */

error1:
	tf_close(connection);
error:
	dprintk(KERN_INFO "tf_device_open(%p): Failure (error %d)\n",
		file, error);
	return error;
}