1 /*
2  * Copyright (C) 2015-2019 Alibaba Group Holding Limited
3  */
4 
5 #define CONFIG_LOGMACRO_DETAILS
6 
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include "board_info.h"
13 #include "board_mgr.h"
14 #ifdef AMP_KV_ENABLE
15 #include "aos/kv.h"
16 #endif
17 
board_setDeviceInfo(char * deviceKey,char * deviceName,char * deviceSecret)18 int8_t board_setDeviceInfo(char *deviceKey, char *deviceName,
19                            char *deviceSecret)
20 {
21 #ifdef AMP_KV_ENABLE
22     if (NULL != deviceKey) {
23         aos_kv_set(DEVICE_KEY_TAG, (void *)deviceKey, strlen(deviceKey),
24                           1);
25     }
26 
27     if (NULL != deviceName) {
28         aos_kv_set(DEVICE_NAME_TAG, (void *)deviceName,
29                           strlen(deviceName), 1);
30     }
31 
32     if (NULL != deviceSecret) {
33         aos_kv_set(DEVICE_SECRET_TAG, (void *)deviceSecret,
34                           strlen(deviceSecret), 1);
35     }
36 #endif
37     return (0);
38 }
39 
board_getDeviceInfo(char ** productKey,char ** deviceName,char ** deviceSecret)40 int8_t board_getDeviceInfo(char **productKey, char **deviceName,
41                            char **deviceSecret)
42 {
43 #ifdef AMP_KV_ENABLE
44     char tmp[64] = {0x00};
45     uint32_t len      = 0;
46     int8_t ret   = -1;
47     if (NULL != productKey) {
48         len = 64;
49         ret = aos_kv_get(DEVICE_KEY_TAG, tmp, &len);
50         if (0 == ret) {
51             tmp[len]    = 0x00;
52             *productKey = strdup(tmp);
53         } else {
54             *productKey = NULL;
55         }
56     }
57 
58     if (NULL != deviceName) {
59         len = 64;
60         ret = aos_kv_get(DEVICE_NAME_TAG, tmp, &len);
61         if (0 == ret) {
62             tmp[len]    = 0x00;
63             *deviceName = strdup(tmp);
64         } else {
65             *deviceName = NULL;
66         }
67     }
68     if (NULL != deviceSecret) {
69         len = 64;
70         ret = aos_kv_get(DEVICE_SECRET_TAG, tmp, &len);
71         if (0 == ret) {
72             tmp[len]      = 0x00;
73             *deviceSecret = strdup(tmp);
74         } else {
75             *deviceSecret = NULL;
76         }
77     }
78 #endif
79     return (0);
80 }
81