blob: 8d845aee259dbea57e7deedbdd4c3ebe18aebb37 [file] [log] [blame]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdint.h>
#define TEST_OBJECT_SIZE 7000
void *dlHandle_tee;
char *lynqLib_tee = "/lib/libgsw_lib.so";
int32_t (*gsw_tee_sdk_init)(void);
int32_t (*gsw_tee_write_secure_data)(const char* in_obj_name, char* in_buf, unsigned int in_buf_len);
int32_t (*gsw_tee_read_secure_data)(const char* in_obj_name, char* out_buf, unsigned int* p_out_buf_len);
int32_t (*gsw_tee_delete_secure_data)(const char* in_obj_name);
int32_t (*gsw_tee_check_secure_data)(const char* in_obj_name);
int32_t (*gsw_tee_sdk_deinit)(void);
int tee_init(void)
{
dlHandle_tee = dlopen(lynqLib_tee, RTLD_NOW);
if(dlHandle_tee == NULL)
{
printf("dlHandle_tee is NULL\n");
return -1;
}
printf("dlHandle_tee is success\n");
gsw_tee_sdk_init=(int32_t(*)())dlsym(dlHandle_tee, "gsw_tee_sdk_init");
if(gsw_tee_sdk_init == NULL)
{
printf("gsw_tee_sdk_init is NULL\n");
return -1;
}
printf("gsw_tee_sdk_init is success\n");
gsw_tee_write_secure_data=(int32_t(*)(const char* in_obj_name, char* in_buf, unsigned int in_buf_len))dlsym(dlHandle_tee, "gsw_tee_write_secure_data");
if(gsw_tee_write_secure_data == NULL)
{
printf("gsw_tee_write_secure_data is NULL\n");
return -1;
}
gsw_tee_read_secure_data=(int32_t(*)(const char* in_obj_name, char* in_buf, unsigned int* p_out_buf_len))dlsym(dlHandle_tee, "gsw_tee_read_secure_data");
if(gsw_tee_read_secure_data == NULL)
{
printf("gsw_tee_read_secure_data is NULL\n");
return -1;
}
gsw_tee_delete_secure_data=(int32_t(*)(const char* in_obj_name))dlsym(dlHandle_tee, "gsw_tee_delete_secure_data");
if(gsw_tee_delete_secure_data == NULL)
{
printf("gsw_tee_delete_secure_data is NULL\n");
return -1;
}
gsw_tee_check_secure_data=(int32_t(*)(const char* in_obj_name))dlsym(dlHandle_tee, "gsw_tee_check_secure_data");
if(gsw_tee_check_secure_data == NULL)
{
printf("gsw_tee_check_secure_data is NULL\n");
return -1;
}
gsw_tee_sdk_deinit=(int32_t(*)())dlsym(dlHandle_tee, "gsw_tee_sdk_deinit");
if(gsw_tee_sdk_deinit == NULL)
{
printf("gsw_tee_sdk_deinit is NULL\n");
return -1;
}
return 0;
}
int main(void)
{
int ret;
unsigned int len;
char obj1_id[] = "object#1";
char obj1_data[] = "123456789";
char read_data[TEST_OBJECT_SIZE];
printf("gsw_optee_test start\n");
ret = tee_init();
if(ret != 0)
{
printf("tee_init fail\n");
}
ret = gsw_tee_sdk_init();
if(ret != 0)
{
printf("gsw_tee_sdk_init fail\n");
return ret;
}
ret = gsw_tee_write_secure_data(obj1_id, obj1_data, sizeof(obj1_data));
if(ret != 0)
{
printf("gsw_tee_write_secure_data fail\n");
return ret;
}
ret = gsw_tee_read_secure_data(obj1_id, read_data, &len);
if(ret != 0)
{
printf("gsw_tee_read_secure_data fail\n");
return ret;
}
printf("read_data: %s\n", read_data);
ret = gsw_tee_delete_secure_data(obj1_id);
if(ret != 0)
{
printf("gsw_tee_delete_secure_data fail\n");
return ret;
}
ret = gsw_tee_check_secure_data(obj1_id);
printf("gsw_tee_check_secure_data ret = %d\n", ret);
ret = gsw_tee_sdk_deinit();
printf("gsw_tee_sdk_deinit ret = %d\n", ret);
return 0;
}