BugID:21997086:[hal]del kv when set value len = 0 to enalbe dynamic register test
@@ -26,40 +26,68 @@ static const char *demo_iv = "f165u329c054k637";
int HAL_SetProductKey(char *product_key)
{
- int len = strlen(product_key);
+ int len;
+ if(product_key == NULL) {
+ return -1;
+ }
+ memset(_product_key, 0x0, IOTX_PRODUCT_KEY_LEN + 1);
+ len = strlen(product_key);
if (len > IOTX_PRODUCT_KEY_LEN) {
return -1;
+ } else if (len == 0) {
+ aos_kv_del(DEVINFO_PK);
+ return 0;
}
- memset(_product_key, 0x0, IOTX_PRODUCT_KEY_LEN + 1);
+
strncpy(_product_key, product_key, len);
aos_kv_set(DEVINFO_PK, product_key, len, 1);
+
return len;
}
int HAL_SetDeviceName(char *device_name)
{
- int len = strlen(device_name);
- if (len > IOTX_DEVICE_NAME_LEN) {
+ int len;
+ if(device_name == NULL) {
return -1;
}
+
memset(_device_name, 0x0, IOTX_DEVICE_NAME_LEN + 1);
+ len = strlen(device_name);
+ if (len > IOTX_DEVICE_NAME_LEN) {
+ return -1;
+ } else if (len == 0) {
+ aos_kv_del(DEVINFO_DN);
+ return 0;
+ }
+
strncpy(_device_name, device_name, len);
aos_kv_set(DEVINFO_DN, device_name, len, 1);
+
return len;
}
int HAL_SetProductSecret(char *product_secret)
{
int res;
- int len = strlen(product_secret);
+ int len;
- if (len > IOTX_PRODUCT_SECRET_LEN) {
+ if(product_secret == NULL) {
return -1;
}
+
memset(_product_secret, 0x0, IOTX_PRODUCT_SECRET_LEN + 1);
+ len = strlen(product_secret);
+ if (len > IOTX_PRODUCT_SECRET_LEN) {
+ return -1;
+ } else if (len == 0) {
+ aos_kv_del(DEVINFO_PS);
+ return 0;
+ }
+
strncpy(_product_secret, product_secret, len);
do {
@@ -76,7 +104,6 @@ int HAL_SetProductSecret(char *product_secret)
break;
}
aos_kv_set(DEVINFO_PS, dec_secret, len, 1);
-
} while(0);
return len;
@@ -84,13 +111,23 @@ int HAL_SetProductSecret(char *product_secret)
int HAL_SetDeviceSecret(char *device_secret)
{
- int res;
- int len = strlen(device_secret);
+ int res, len;
+ if(device_secret == NULL) {
+ return -1;
+ }
+
+ memset(_device_secret, 0x0, IOTX_DEVICE_SECRET_LEN + 1);
+ len = strlen(device_secret);
+ if (len > IOTX_DEVICE_SECRET_LEN) {
+ return -1;
+ } else if (len == 0) {
+ aos_kv_del(DEVINFO_DS);
+ return 0;
+ }
if (len > IOTX_DEVICE_SECRET_LEN) {
return -1;
}
- memset(_device_secret, 0x0, IOTX_DEVICE_SECRET_LEN + 1);
strncpy(_device_secret, device_secret, len);
do {
