[Feature][T108][task-view-1545][tee]Modify return value GSW_HAL_FAIL to GSW_HAL_NORMAL_FAIL and rename file name

Only Configure: No
Affected branch: GSW_V1453
Affected module: tee
Is it affected on IC: only ASR
Self-test: yes
Doc Update: no

Change-Id: Ia810bcd4e0be346fa57a05fe8d6219a7e7e25172
diff --git a/mbtk/include/gsw/gsw_tee.h b/mbtk/include/gsw/gsw_tz_interface.h
similarity index 96%
rename from mbtk/include/gsw/gsw_tee.h
rename to mbtk/include/gsw/gsw_tz_interface.h
index 197f16e..325fd8c 100755
--- a/mbtk/include/gsw/gsw_tee.h
+++ b/mbtk/include/gsw/gsw_tz_interface.h
@@ -1,14 +1,32 @@
-#include <stdlib.h>
+/**
+*  @copyright Copyright @ Fibocom Technologies Co., Ltd. 2019-2030. All rights reserved
+*  @file  : gsw_tee_interface.h
+*  @brief : sdk interface
+*  @date : 
+*  @author : hanmd
+*  @version : v1.0
+*/
+
+#ifndef __GSW_TZ_INTERFACE_H__
+#define __GSW_TZ_INTERFACE_H__
+
 #include <stdint.h>
+#include <stddef.h>
 #include <string.h>
 #include <stdbool.h>
-#include <stdio.h>
+#include "gsw_hal_errcode.h"
 
+#define UNUSE(param) (void)(param)
 
-#define GSW_HAL_SUCCESS 0
-#define GSW_HAL_FAIL -1
-#define GSW_HAL_MEM_INVAILD -2
-#define GSW_HAL_NOFOUND -3
+/** The maximum data size of a invoke  */
+#define GSW_TWO_PAGESIZE (8192)
+
+/** The maxmum filename size of sfs/key  */
+#define GSW_FILENAME_MAXSIZE (32)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 typedef enum {
     GSW_TEE_PARAM_DATA = 1,
@@ -576,3 +594,7 @@
 */
 int32_t gsw_tee_sdk_deinit(void);
 
+#ifdef __cplusplus
+}
+#endif
+#endif //__GSW_TZ_INTERFACE_H__
diff --git a/mbtk/libgsw_lib/gsw_tee.c b/mbtk/libgsw_lib/gsw_tz_interface.c
similarity index 73%
rename from mbtk/libgsw_lib/gsw_tee.c
rename to mbtk/libgsw_lib/gsw_tz_interface.c
index 0c92832..b30f548 100755
--- a/mbtk/libgsw_lib/gsw_tee.c
+++ b/mbtk/libgsw_lib/gsw_tz_interface.c
@@ -1,12 +1,10 @@
 
-#include "gsw/gsw_tee.h"
+#include "gsw/gsw_tz_interface.h"
 #include <dlfcn.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdint.h>
-
-
-#include <tee_client_api.h>
+#include <stdlib.h>
 
 #ifndef LOG_ERR_LEVEL
 #define LOG_ERR_LEVEL  3      /* error conditions */
@@ -96,11 +94,57 @@
         mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_TEE"" fmt, ptr_1001 + 1, line_1001, ##args); \
     } while(0)
 
+/**
+ * struct TEEC_Context - Represents a connection between a client application
+ * and a TEE.
+ */
+ typedef struct {
+	/* Implementation defined */
+	struct {
+		int fd;
+		bool reg_mem;
+		bool memref_null;
+	} imp;
+} TEEC_Context;
+
+/**
+ * struct TEEC_Session - Represents a connection between a client application
+ * and a trusted application.
+ */
+ typedef struct {
+	/* Implementation defined */
+	struct {
+		TEEC_Context *ctx;
+		uint32_t session_id;
+	} imp;
+} TEEC_Session;
+
 struct test_ctx {
-	TEEC_Context ctx;
-	TEEC_Session sess;
+    TEEC_Context ctx;
+    TEEC_Session sess;
 };
 
+#define TEEC_SUCCESS                       0x00000000
+#define TEEC_ERROR_STORAGE_NOT_AVAILABLE   0xF0100003
+#define TEEC_ERROR_GENERIC                 0xFFFF0000
+#define TEEC_ERROR_ACCESS_DENIED           0xFFFF0001
+#define TEEC_ERROR_CANCEL                  0xFFFF0002
+#define TEEC_ERROR_ACCESS_CONFLICT         0xFFFF0003
+#define TEEC_ERROR_EXCESS_DATA             0xFFFF0004
+#define TEEC_ERROR_BAD_FORMAT              0xFFFF0005
+#define TEEC_ERROR_BAD_PARAMETERS          0xFFFF0006
+#define TEEC_ERROR_BAD_STATE               0xFFFF0007
+#define TEEC_ERROR_ITEM_NOT_FOUND          0xFFFF0008
+#define TEEC_ERROR_NOT_IMPLEMENTED         0xFFFF0009
+#define TEEC_ERROR_NOT_SUPPORTED           0xFFFF000A
+#define TEEC_ERROR_NO_DATA                 0xFFFF000B
+#define TEEC_ERROR_OUT_OF_MEMORY           0xFFFF000C
+#define TEEC_ERROR_BUSY                    0xFFFF000D
+#define TEEC_ERROR_COMMUNICATION           0xFFFF000E
+#define TEEC_ERROR_SECURITY                0xFFFF000F
+#define TEEC_ERROR_SHORT_BUFFER            0xFFFF0010
+#define TEEC_ERROR_EXTERNAL_CANCEL         0xFFFF0011
+#define TEEC_ERROR_TARGET_DEAD             0xFFFF3024
 
 struct test_ctx ctx;
 
@@ -110,8 +154,7 @@
 #define lib_mbtk_path "/lib/libmbtk_lib.so"
 static void *dlHandle_mbtk;
 
-
-
+typedef uint32_t TEEC_Result;
 
 
 static void (*mbtk_log)(int level, const char *format, ...);
@@ -132,60 +175,60 @@
     dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
     if (dlHandle_mbtk == NULL) 
     {
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     dlHandle_secure = dlopen(lib_secure_path, RTLD_NOW);
     if (dlHandle_secure == NULL) 
     {
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
     if (mbtk_log_init == NULL) 
     {
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
     if (mbtk_log == NULL) 
     {
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     prepare_tee_session = (int (*)(struct test_ctx *ctx))dlsym(dlHandle_secure, "prepare_tee_session");
     if (prepare_tee_session == NULL) 
     {
         LOGE("prepare_tee_session dlsym fail\n");
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     terminate_tee_session = (void (*)(struct test_ctx *ctx))dlsym(dlHandle_secure, "terminate_tee_session");
     if (terminate_tee_session == NULL) 
     {
         LOGE("terminate_tee_session dlsym fail\n");
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     read_secure_object = (TEEC_Result (*)(struct test_ctx *ctx, const char *id,char *data, size_t data_len))dlsym(dlHandle_secure, "read_secure_object");
     if (read_secure_object == NULL) 
     {
         LOGE("read_secure_object dlsym fail\n");
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     write_secure_object = (TEEC_Result (*)(struct test_ctx *ctx, const char *id,char *data, size_t data_len))dlsym(dlHandle_secure, "write_secure_object");
     if (write_secure_object == NULL) 
     {
         LOGE("write_secure_object dlsym fail\n");
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     delete_secure_object = (TEEC_Result (*)(struct test_ctx *ctx, const char *id))dlsym(dlHandle_secure, "delete_secure_object");
     if (delete_secure_object == NULL) 
     {
         LOGE("delete_secure_object dlsym fail\n");
-        return GSW_HAL_FAIL;
+        return GSW_HAL_NORMAL_FAIL;
     }
 
     return GSW_HAL_SUCCESS;
@@ -223,16 +266,20 @@
 #define basic_buf_len  7000
 int32_t gsw_tee_read_secure_data(const char* in_obj_name, char* out_buf, unsigned int* p_out_buf_len)
 {
+    if (in_obj_name == NULL || out_buf == NULL)
+        return GSW_HAL_NORMAL_FAIL;
     int32_t ret = 0;
     TEEC_Result res;
-    res = read_secure_object(&ctx, in_obj_name, out_buf, basic_buf_len);
+    char *tmp_buf = malloc(basic_buf_len * sizeof(char));
+    res = read_secure_object(&ctx, in_obj_name, tmp_buf, basic_buf_len);
     if (res != TEEC_SUCCESS)
     {
 	LOGE("Failed to read an object from the secure storage");
-        ret = -1;
+        ret = GSW_HAL_NORMAL_FAIL;
     }
-
+    memcpy(out_buf, tmp_buf, strlen(tmp_buf)+1);
     *p_out_buf_len = strlen(out_buf);
+    free(tmp_buf);
     return ret;
 }
 
@@ -246,13 +293,15 @@
 */
 int32_t gsw_tee_write_secure_data(const char* in_obj_name, char* in_buf, unsigned int in_buf_len)
 {
+    if (in_obj_name == NULL || in_buf == NULL)
+        return GSW_HAL_NORMAL_FAIL;
     int32_t ret = 0;
     TEEC_Result res;
     res = write_secure_object(&ctx, in_obj_name,in_buf, in_buf_len);
     if (res != TEEC_SUCCESS)
     {
 	LOGE("Failed to write an object from the secure storage");
-        ret = -1;
+        ret = GSW_HAL_NORMAL_FAIL;
     }
 
     return ret;
@@ -266,13 +315,15 @@
 */
 int32_t gsw_tee_delete_secure_data(const char* in_obj_name)
 {
+    if (in_obj_name == NULL)
+        return GSW_HAL_NORMAL_FAIL;
     int32_t ret = 0;
     TEEC_Result res;
     res = delete_secure_object(&ctx, in_obj_name);
     if (res != TEEC_SUCCESS)
     {
 	LOGE("Failed to delete the object: 0x%x", res);
-        ret = -1;
+        ret = GSW_HAL_NORMAL_FAIL;
     }
 
 
@@ -287,15 +338,17 @@
 */
 int32_t gsw_tee_check_secure_data(const char* in_obj_name)
 {
+    if (in_obj_name == NULL)
+        return GSW_HAL_NORMAL_FAIL;
     int32_t ret = 1;
     TEEC_Result res;
-    char out_buf[4];
-    res = read_secure_object(&ctx, in_obj_name, out_buf, sizeof(out_buf));
+    char *tmp_buf = malloc(basic_buf_len * sizeof(char));
+    res = read_secure_object(&ctx, in_obj_name, tmp_buf, basic_buf_len);
 
     if (res == TEEC_ERROR_ITEM_NOT_FOUND)
     {
         LOGE("the obj no found\n");
-        ret = GSW_HAL_NOFOUND;
+        ret = GSW_HAL_ERROR_TEE_SFS_FILE_NOEXIST;
     }
     else if (res == TEEC_SUCCESS)
     {
@@ -305,12 +358,18 @@
     else
     {
         LOGE("Failed to read an object from the secure storage");
-        ret = GSW_HAL_FAIL;
+        ret = GSW_HAL_NORMAL_FAIL;
     }
-
+    free(tmp_buf);
     return ret;
 }
 
+/**
+* @brief deinit tee sdk
+* @param [in] None
+* @param [out] None
+* @retval GSW_HAL_SUCCESS is success\other is fail
+*/
 int32_t gsw_tee_sdk_deinit(void)
 {
     if (terminate_tee_session) {
diff --git a/package/services/optee_os/asr1806_tos.bin b/package/services/optee_os/asr1806_tos.bin
index 9bf3d85..9d5919f 100755
--- a/package/services/optee_os/asr1806_tos.bin
+++ b/package/services/optee_os/asr1806_tos.bin
Binary files differ