BugID:22289248:[dynamic register]use HAL_SetDeviceSecret to save ds directly
@@ -75,24 +75,13 @@ int HAL_Kv_Get(const char *key, void *val, int *buffer_len);
static int _iotx_dynamic_register(iotx_http_region_types_t region, iotx_dev_meta_info_t *meta_info)
{
- char device_secret_kv[IOTX_DEVICE_SECRET_LEN + 1] = {0};
+ char device_secret[IOTX_DEVICE_SECRET_LEN + 1] = {0};
int device_secret_len = IOTX_DEVICE_SECRET_LEN;
- char kv_key[IOTX_DEVICE_NAME_LEN + DYNAMIC_REG_KV_PREFIX_LEN] = DYNAMIC_REG_KV_PREFIX;
int res = FAIL_RETURN;
- memcpy(kv_key + strlen(kv_key), meta_info->device_name, strlen(meta_info->device_name));
-
+ HAL_GetDeviceSecret(device_secret);
/* Check if Device Secret exist in KV */
- if (HAL_Kv_Get(kv_key, device_secret_kv, &device_secret_len) == 0) {
- mqtt_info("Get DeviceSecret from KV succeed");
-
- *(device_secret_kv + device_secret_len) = 0;
- HAL_SetDeviceSecret(device_secret_kv);
- memset(meta_info->device_secret, 0, IOTX_DEVICE_SECRET_LEN + 1);
- memcpy(meta_info->device_secret, device_secret_kv, strlen(device_secret_kv));
- } else {
- char product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = {0};
-
+ if (strlen(device_secret) == 0) {
/* KV not exit, goto dynamic register */
mqtt_info("DeviceSecret KV not exist, Now We Need Dynamic Register...");
@@ -101,14 +90,11 @@ static int _iotx_dynamic_register(iotx_http_region_types_t region, iotx_dev_meta
mqtt_err("Dynamic Register Failed");
return FAIL_RETURN;
}
-
- device_secret_len = strlen(meta_info->device_secret);
- if (HAL_Kv_Set(kv_key, meta_info->device_secret, device_secret_len, 1) != 0) {
+ res = HAL_SetDeviceSecret(meta_info->device_secret);
+ if(res < 0) {
mqtt_err("Save Device Secret to KV Failed");
return FAIL_RETURN;
}
-
- HAL_SetDeviceSecret(meta_info->device_secret);
}
return SUCCESS_RETURN;
