1 /*
2 * Copyright (c) 2020 Linumiz
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include "hawkbit_device.h"
7 #include <string.h>
8 #include <zephyr/mgmt/hawkbit/hawkbit.h>
9
10 static bool hawkbit_get_device_identity_default(char *id, int id_max_len);
11
12 static hawkbit_get_device_identity_cb_handler_t hawkbit_get_device_identity_cb_handler =
13 hawkbit_get_device_identity_default;
14
hawkbit_get_device_identity(char * id,int id_max_len)15 bool hawkbit_get_device_identity(char *id, int id_max_len)
16 {
17 return hawkbit_get_device_identity_cb_handler(id, id_max_len);
18 }
19
hawkbit_get_device_identity_default(char * id,int id_max_len)20 static bool hawkbit_get_device_identity_default(char *id, int id_max_len)
21 {
22 #ifdef CONFIG_HWINFO
23 uint8_t hwinfo_id[DEVICE_ID_BIN_MAX_SIZE];
24 ssize_t length;
25
26 length = hwinfo_get_device_id(hwinfo_id, DEVICE_ID_BIN_MAX_SIZE);
27 if (length <= 0) {
28 return false;
29 }
30
31 memset(id, 0, id_max_len);
32 length = bin2hex(hwinfo_id, (size_t)length, id, id_max_len);
33
34 return length > 0;
35 #else /* CONFIG_HWINFO */
36 ARG_UNUSED(id);
37 ARG_UNUSED(id_max_len);
38
39 return false;
40 #endif /* CONFIG_HWINFO */
41 }
42
43 #ifdef CONFIG_HAWKBIT_CUSTOM_DEVICE_ID
hawkbit_set_device_identity_cb(hawkbit_get_device_identity_cb_handler_t cb)44 int hawkbit_set_device_identity_cb(hawkbit_get_device_identity_cb_handler_t cb)
45 {
46 if (cb == NULL) {
47 return -EINVAL;
48 }
49
50 hawkbit_get_device_identity_cb_handler = cb;
51
52 return 0;
53 }
54 #endif /* CONFIG_HAWKBIT_CUSTOM_DEVICE_ID */
55