Interface: Change control param to uint32_t preprocessor

Define a uint32_t preprocessor to pack control params.

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I0992620af1c39ef6dba182cac88e81cd666be0c6
diff --git a/interface/src/tfm_psa_ns_api.c b/interface/src/tfm_psa_ns_api.c
index 9a677a2..9d60a11 100644
--- a/interface/src/tfm_psa_ns_api.c
+++ b/interface/src/tfm_psa_ns_api.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -8,6 +8,7 @@
 #include "psa/client.h"
 #include "tfm_ns_interface.h"
 #include "tfm_api.h"
+#include "tfm_psa_call_param.h"
 
 /**** API functions ****/
 
@@ -47,23 +48,18 @@
                       psa_outvec *out_vec,
                       size_t out_len)
 {
-    /* FixMe: sanity check can be added to offload some NS thread checks from
-     * TFM secure API
-     */
-
-    /* Due to v8M restrictions, TF-M NS API needs to add another layer of
-     * serialization in order for NS to pass arguments to S
-     */
-    const struct tfm_control_parameter_t ctrl_param = {
-        .type = type,
-        .in_len = in_len,
-        .out_len = out_len,
-    };
+    if ((type > INT16_MAX) ||
+        (type < INT16_MIN) ||
+        (in_len > PSA_MAX_IOVEC) ||
+        (out_len > PSA_MAX_IOVEC) ||
+        ((in_len + out_len) > PSA_MAX_IOVEC)) {
+        return PSA_ERROR_INVALID_ARGUMENT;
+    }
 
     return tfm_ns_interface_dispatch(
                                 (veneer_fn)tfm_psa_call_veneer,
                                 (uint32_t)handle,
-                                (uint32_t)&ctrl_param,
+                                PARAM_PACK(type, in_len, out_len),
                                 (uint32_t)in_vec,
                                 (uint32_t)out_vec);
 }