Skip to content

Commit

Permalink
[portinglayer] Implement error mapping support for matter sdk (#107)
Browse files Browse the repository at this point in the history
* error mapping part 1

* change checkexist return type back to bool

* add more wifi porting layer api

* more porting layer api for wifi and timers

* fix compile

* cleanup

* [wifi] split dhcp into ipv4 and ipv6

* [build] add AclStorage and DefaultAclStorage to build
  • Loading branch information
step0035 authored Jun 16, 2023
1 parent add2705 commit cd0a276
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern "C" {
#include <stddef.h> /* for size_t */
#include <stdarg.h>
#include <platform_opts_bt.h>
#include <dct.h>

#if defined(CONFIG_BT_MATTER_ADAPTER) && CONFIG_BT_MATTER_ADAPTER
/** @brief Config local address type: 0-pulic address, 1-static random address, 2-random resolvable private address */
Expand Down
88 changes: 41 additions & 47 deletions component/common/application/matter/common/port/matter_dcts.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ s32 initPref(void)
{
s32 ret;
ret = dct_init(DCT_BEGIN_ADDR_MATTER, MODULE_NUM, VARIABLE_NAME_SIZE, VARIABLE_VALUE_SIZE, ENABLE_BACKUP, ENABLE_WEAR_LEVELING);
if (ret != 0)
if (ret != DCT_SUCCESS)
printf("dct_init failed with error: %d\n", ret);
else
printf("dct_init success\n");

ret = dct_init2(DCT_BEGIN_ADDR_MATTER2, MODULE_NUM2, VARIABLE_NAME_SIZE2, VARIABLE_VALUE_SIZE2, ENABLE_BACKUP, ENABLE_WEAR_LEVELING);
if (ret != 0)
if (ret != DCT_SUCCESS)
printf("dct_init2 failed with error: %d\n", ret);
else
printf("dct_init2 success\n");
Expand All @@ -136,13 +136,13 @@ s32 deinitPref(void)
{
s32 ret;
ret = dct_format(DCT_BEGIN_ADDR_MATTER, MODULE_NUM, VARIABLE_NAME_SIZE, VARIABLE_VALUE_SIZE, ENABLE_BACKUP, ENABLE_WEAR_LEVELING);
if (ret != 0)
if (ret != DCT_SUCCESS)
printf("dct_format failed with error: %d\n", ret);
else
printf("dct_format success\n");

ret = dct_format2(DCT_BEGIN_ADDR_MATTER2, MODULE_NUM2, VARIABLE_NAME_SIZE2, VARIABLE_VALUE_SIZE2, ENABLE_BACKUP, ENABLE_WEAR_LEVELING);
if (ret != 0)
if (ret != DCT_SUCCESS)
printf("dct_format2 failed with error: %d\n", ret);
else
printf("dct_format2 success\n");
Expand All @@ -164,14 +164,14 @@ s32 registerPref()
{
snprintf(ns, 15, "matter_kvs1_%d", i+1);
ret = dct_register_module(ns);
if (ret != 0)
if (ret != DCT_SUCCESS)
goto exit;
else
printf("dct_register_module %s success\n", ns);
}

exit:
if (ret != 0)
if (ret != DCT_SUCCESS)
printf("DCT1 modules registration failed");
return ret;
}
Expand All @@ -185,14 +185,14 @@ s32 registerPref2()
{
snprintf(ns, 15, "matter_kvs2_%d", i+1);
ret = dct_register_module2(ns);
if (ret != 0)
if (ret != DCT_SUCCESS)
goto exit;
else
printf("dct_register_module2 %s success\n", ns);
}

exit:
if (ret != 0)
if (ret != DCT_SUCCESS)
printf("DCT2 modules registration failed");
return ret;
}
Expand All @@ -206,14 +206,14 @@ s32 clearPref()
{
snprintf(ns, 15, "matter_kvs1_%d", i+1);
ret = dct_unregister_module(ns);
if (ret != 0)
if (ret != DCT_SUCCESS)
goto exit;
else
printf("dct_unregister_module %s success\n", ns);
}

exit:
if (ret != 0)
if (ret != DCT_SUCCESS)
printf("DCT1 modules unregistration failed");
return ret;
}
Expand All @@ -227,37 +227,37 @@ s32 clearPref2()
{
snprintf(ns, 15, "matter_kvs2_%d", i+1);
ret = dct_unregister_module2(ns);
if (ret != 0)
if (ret != DCT_SUCCESS)
goto exit;
else
printf("dct_unregister_module2 %s success\n", ns);
}

exit:
if (ret != 0)
if (ret != DCT_SUCCESS)
printf("DCT2 modules unregistration failed");
return ret;
}

s32 deleteKey(const char *domain, const char *key)
{
dct_handle_t handle;
s32 ret = -1;
s32 ret;
char ns[15];

// Loop over DCT1 modules
for (size_t i=0; i<MODULE_NUM; i++)
{
snprintf(ns, 15, "matter_kvs1_%d", i+1);
ret = dct_open_module(&handle, ns);
if (DCT_SUCCESS != ret)
if (ret != DCT_SUCCESS)
{
printf("%s : dct_open_module(%s) failed with error: %d\n" ,__FUNCTION__, ns, ret);
goto exit;
}
ret = dct_delete_variable(&handle, key);
dct_close_module(&handle);
if (DCT_SUCCESS == ret)
if (ret != DCT_SUCCESS)
return ret;
}

Expand All @@ -266,14 +266,14 @@ s32 deleteKey(const char *domain, const char *key)
{
snprintf(ns, 15, "matter_kvs2_%d", i+1);
ret = dct_open_module2(&handle, ns);
if (DCT_SUCCESS != ret)
if (ret != DCT_SUCCESS)
{
printf("%s : dct_open_module2(%s) failed with error: %d\n" ,__FUNCTION__, ns, ret);
goto exit;
}
ret = dct_delete_variable2(&handle, key);
dct_close_module2(&handle);
if (DCT_SUCCESS == ret)
if (ret != DCT_SUCCESS)
return ret;
}

Expand All @@ -284,7 +284,7 @@ s32 deleteKey(const char *domain, const char *key)
bool checkExist(const char *domain, const char *key)
{
dct_handle_t handle;
s32 ret = -1;
s32 ret;
uint16_t len = 0;
u8 *str = malloc(sizeof(u8) * VARIABLE_VALUE_SIZE2); // use the bigger buffer size
char ns[15];
Expand All @@ -306,8 +306,7 @@ bool checkExist(const char *domain, const char *key)
{
printf("checkExist key=%s found.\n", key);
dct_close_module(&handle);
free(str);
return true;
goto exit;
}

len = sizeof(u64);
Expand All @@ -316,8 +315,7 @@ bool checkExist(const char *domain, const char *key)
{
printf("checkExist key=%s found.\n", key);
dct_close_module(&handle);
free(str);
return true;
goto exit;
}

dct_close_module(&handle);
Expand All @@ -340,24 +338,22 @@ bool checkExist(const char *domain, const char *key)
{
printf("checkExist key=%s found.\n", key);
dct_close_module2(&handle);
free(str);
return true;
goto exit;
}

dct_close_module2(&handle);
}

exit:
free(str);
return false;
return (ret == DCT_SUCCESS) ? true : false;
}

s32 setPref_new(const char *domain, const char *key, u8 *value, size_t byteCount)
{
dct_handle_t handle;
s32 ret = -1;
s32 ret;
char ns[15];
bool set_success = false;

if (byteCount <= 64)
{
Expand All @@ -379,13 +375,12 @@ s32 setPref_new(const char *domain, const char *key, u8 *value, size_t byteCount
#else
ret = dct_set_variable_new(&handle, key, (char *)value, (uint16_t)byteCount);
#endif
if (DCT_SUCCESS != ret)
if (ret != DCT_SUCCESS)
{
printf("%s : dct_set_variable(%s) failed with error: %d\n" ,__FUNCTION__, key, ret);
dct_close_module(&handle);
goto exit;
}
set_success = true;
dct_close_module(&handle);
break;
}
Expand All @@ -412,13 +407,12 @@ s32 setPref_new(const char *domain, const char *key, u8 *value, size_t byteCount
#else
ret = dct_set_variable_new2(&handle, key, (char *)value, (uint16_t)byteCount);
#endif
if (DCT_SUCCESS != ret)
if (ret != DCT_SUCCESS)
{
printf("%s : dct_set_variable2(%s) failed with error: %d\n" ,__FUNCTION__, key, ret);
dct_close_module2(&handle);
goto exit;
}
set_success = true;
dct_close_module2(&handle);
break;
}
Expand All @@ -427,13 +421,13 @@ s32 setPref_new(const char *domain, const char *key, u8 *value, size_t byteCount
}

exit:
return (set_success == true ? 1 : 0);
return ret;
}

s32 getPref_bool_new(const char *domain, const char *key, u8 *val)
{
dct_handle_t handle;
s32 ret = -1;
s32 ret;
uint16_t len = sizeof(u8);
char ns[15];

Expand All @@ -453,7 +447,7 @@ s32 getPref_bool_new(const char *domain, const char *key, u8 *val)
ret = dct_get_variable_new(&handle, key, (char *)val, &len);
#endif
dct_close_module(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
return ret;
}
Expand All @@ -475,7 +469,7 @@ s32 getPref_bool_new(const char *domain, const char *key, u8 *val)
ret = dct_get_variable_new2(&handle, key, (char *)val, &len);
#endif
dct_close_module2(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
return ret;
}
Expand All @@ -488,7 +482,7 @@ s32 getPref_bool_new(const char *domain, const char *key, u8 *val)
s32 getPref_u32_new(const char *domain, const char *key, u32 *val)
{
dct_handle_t handle;
s32 ret = -1;
s32 ret;
uint16_t len = sizeof(u32);
char ns[15];

Expand All @@ -508,7 +502,7 @@ s32 getPref_u32_new(const char *domain, const char *key, u32 *val)
ret = dct_get_variable_new(&handle, key, (char *)val, &len);
#endif
dct_close_module(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
return ret;
}
Expand All @@ -530,7 +524,7 @@ s32 getPref_u32_new(const char *domain, const char *key, u32 *val)
ret = dct_get_variable_new2(&handle, key, (char *)val, &len);
#endif
dct_close_module2(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
return ret;
}
Expand All @@ -543,7 +537,7 @@ s32 getPref_u32_new(const char *domain, const char *key, u32 *val)
s32 getPref_u64_new(const char *domain, const char *key, u64 *val)
{
dct_handle_t handle;
s32 ret = -1;
s32 ret;
uint16_t len = sizeof(u64);
char ns[15];

Expand All @@ -563,7 +557,7 @@ s32 getPref_u64_new(const char *domain, const char *key, u64 *val)
ret = dct_get_variable_new(&handle, key, (char *)val, &len);
#endif
dct_close_module(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
return ret;
}
Expand All @@ -585,7 +579,7 @@ s32 getPref_u64_new(const char *domain, const char *key, u64 *val)
ret = dct_get_variable_new2(&handle, key, (char *)val, &len);
#endif
dct_close_module2(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
return ret;
}
Expand All @@ -598,7 +592,7 @@ s32 getPref_u64_new(const char *domain, const char *key, u64 *val)
s32 getPref_str_new(const char *domain, const char *key, char * buf, size_t bufSize, size_t *outLen)
{
dct_handle_t handle;
s32 ret = -1;
s32 ret;
char ns[15];

// Loop over DCT1 modules
Expand All @@ -617,7 +611,7 @@ s32 getPref_str_new(const char *domain, const char *key, char * buf, size_t bufS
ret = dct_get_variable_new(&handle, key, buf, &bufSize);
#endif
dct_close_module(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
*outLen = bufSize;
return ret;
Expand All @@ -640,7 +634,7 @@ s32 getPref_str_new(const char *domain, const char *key, char * buf, size_t bufS
ret = dct_get_variable_new2(&handle, key, buf, &bufSize);
#endif
dct_close_module2(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
*outLen = bufSize;
return ret;
Expand All @@ -654,7 +648,7 @@ s32 getPref_str_new(const char *domain, const char *key, char * buf, size_t bufS
s32 getPref_bin_new(const char *domain, const char *key, u8 * buf, size_t bufSize, size_t *outLen)
{
dct_handle_t handle;
s32 ret = -1;
s32 ret;
char ns[15];

// Loop over DCT1 modules
Expand All @@ -673,7 +667,7 @@ s32 getPref_bin_new(const char *domain, const char *key, u8 * buf, size_t bufSiz
ret = dct_get_variable_new(&handle, key, (char *)buf, &bufSize);
#endif
dct_close_module(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
*outLen = bufSize;
return ret;
Expand All @@ -696,7 +690,7 @@ s32 getPref_bin_new(const char *domain, const char *key, u8 * buf, size_t bufSiz
ret = dct_get_variable_new2(&handle, key, (char *)buf, &bufSize);
#endif
dct_close_module2(&handle);
if (DCT_SUCCESS == ret)
if (ret == DCT_SUCCESS)
{
*outLen = bufSize;
return ret;
Expand Down
Loading

0 comments on commit cd0a276

Please sign in to comment.