/* * Invokes a TEE command (secure service, sub-PA or whatever). */ TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t cmd_id, TEEC_Operation *operation, uint32_t *error_origin) { INMSG("session: [%p], cmd_id: [%d]", session, cmd_id); struct tee_cmd tc; TEEC_Operation dummy_op; TEEC_Result result = TEEC_SUCCESS; uint32_t origin = TEEC_ORIGIN_API; if (session == NULL) { origin = TEEC_ORIGIN_API; result = TEEC_ERROR_BAD_PARAMETERS; goto error; } if (operation == NULL) { /* * The code here exist because Global Platform API states that * it is allowed to give operation as a NULL pointer. In kernel * and secure world we in most cases don't want this to be NULL, * hence we use this dummy operation when a client doesn't * provide any operation. */ memset(&dummy_op, 0, sizeof(TEEC_Operation)); operation = &dummy_op; } teec_mutex_lock(&mutex); operation->session = session; teec_mutex_unlock(&mutex); memset(&tc, 0, sizeof(struct tee_cmd)); tc.cmd = cmd_id; tc.op = operation; if (ioctl(session->fd, TEE_INVOKE_COMMAND_IOC, &tc) != 0) EMSG("Ioctl(TEE_INVOKE_COMMAND_IOC) failed! (%s)\n", strerror(errno)); if (operation != NULL) { teec_mutex_lock(&mutex); operation->session = NULL; teec_mutex_unlock(&mutex); } origin = tc.origin; result = tc.err; error: if (error_origin != NULL) *error_origin = origin; OUTRMSG(result); }
void TEEC_RequestCancellation(TEEC_Operation *operation) { struct tee_cmd tc; TEEC_Session *session; if (operation == NULL) return; teec_mutex_lock(&mutex); session = operation->session; teec_mutex_unlock(&mutex); if (session == NULL) return; memset(&tc, 0, sizeof(struct tee_cmd)); tc.op = operation; if (ioctl(session->fd, TEE_REQUEST_CANCELLATION_IOC, &tc) != 0) EMSG("Ioctl(TEE_REQUEST_CANCELLATION_IOC) failed! (%s)\n", strerror(errno)); }
void TEEC_RequestCancellation(TEEC_Operation *operation) { struct tee_cmd_io cmd; TEEC_Session *session; if (operation == NULL) return; teec_mutex_lock(&mutex); session = operation->session; teec_mutex_unlock(&mutex); if (session == NULL) return; teec_resetTeeCmd(&cmd); cmd.op = operation; if (ioctl(session->fd, TEE_REQUEST_CANCELLATION_IOC, &cmd) != 0) EMSG("Ioctl(TEE_REQUEST_CANCELLATION_IOC) failed! (%s)\n", strerror(errno)); }