tlk: 6/19 update
[3rdparty/ote_partner/tlk.git] / kernel / ote_intf.c
index e525ae6..5bf03a3 100644 (file)
@@ -68,7 +68,7 @@ typedef struct {
        thread_t *thread;
 } session_t;
 
-struct te_command {
+typedef struct te_command {
        struct list_node node;
 
        te_entry_point_message_t msg;
@@ -79,7 +79,7 @@ struct te_command {
        task_t *requesting_task;
 
        uint32_t returning_cmd;
-};
+} te_command_t;
 
 /* Check if client is restriced access.
  * 'task_issued' is true when client is secure task.
@@ -100,6 +100,19 @@ static bool check_restrict_access(task_t *task, bool task_issued)
                                __func__);
                return true;
        }
+
+       if (task->task_state == TASK_STATE_BLOCKED) {
+               dprintf(INFO, "%s: Task administratively blocked -- access denied\n",
+                       __func__);
+               return true;
+       }
+
+       if (task->task_state != TASK_STATE_ACTIVE) {
+               dprintf(INFO, "%s: Task is not in active state (%d) -- access denied\n",
+                       __func__, task->task_state);
+               return true;
+       }
+
        return false;
 }
 
@@ -938,7 +951,7 @@ int te_get_current_ta_property(te_get_property_args_t *args)
               sizeof(te_service_id_t));
 
        args->result = OTE_SUCCESS;
-       return 1;
+       return 0;
 }
 
 int te_get_current_client_property(te_get_property_args_t *args)
@@ -972,7 +985,7 @@ int te_get_current_client_property(te_get_property_args_t *args)
               sizeof(te_service_id_t));
 
        args->result = OTE_SUCCESS;
-       return 1;
+       return 0;
 }
 
 int te_get_implementation_property(te_get_property_args_t *args)
@@ -981,3 +994,37 @@ int te_get_implementation_property(te_get_property_args_t *args)
        args->result = OTE_ERROR_NOT_IMPLEMENTED;
        return -EINVAL;
 }
+
+void te_session_cancel_thread(thread_t *t)
+{
+       session_t *session = NULL;
+       session_t *s_tmp = NULL;
+
+       enter_critical_section();
+
+       /* Delete any session referring to the thread being canceled. */
+       list_for_every_entry_safe(&session_list, session, s_tmp, session_t, node) {
+               if (session->thread == t) {
+                       task_t *task = NULL;
+                       struct te_command *cmd = NULL;
+                       struct te_command *cmd_tmp = NULL;
+
+                       list_delete(&session->node);
+
+                       task = session->thread->arch.task;
+
+                       list_for_every_entry_safe(&session->cmd_node, cmd, cmd_tmp,
+                                                 te_command_t, node) {
+                               while (cmd->maps--) {
+                                       arch_task_unmap_memory(task, cmd->mptr[cmd->maps]);
+                               }
+                               list_delete(&cmd->node);
+                               free(cmd);
+                               cmd = NULL;
+                       }
+                       free(session);
+                       session = NULL;
+               }
+       }
+       exit_critical_section();
+}