Skip to content
Snippets Groups Projects
Commit 102d5a93 authored by Filip Matusiak's avatar Filip Matusiak
Browse files

wsc: Add function to read WSC M2 md5sum from file

parent ced27ba4
No related branches found
No related tags found
No related merge requests found
...@@ -283,11 +283,12 @@ int autoconfig_write_hash_to_file(uint8_t *macaddr, uint8_t *sha256) ...@@ -283,11 +283,12 @@ int autoconfig_write_hash_to_file(uint8_t *macaddr, uint8_t *sha256)
} }
/* Create sha256 string */ /* Create sha256 string */
sha256_str = calloc(sizeof(sha256) * 2 + 1, sizeof(char)); sha256_str = calloc(SHA256_LENGTH * 2 + 1, sizeof(char));
if (!sha256_str) if (!sha256_str)
goto out_radio; goto out_radio;
btostr(sha256, sizeof(sha256), sha256_str); btostr(sha256, SHA256_LENGTH, sha256_str);
sha256_obj = json_object_new_string(sha256_str); sha256_obj = json_object_new_string(sha256_str);
if (!sha256_obj) { if (!sha256_obj) {
json_object_put(radio_obj); json_object_put(radio_obj);
...@@ -312,3 +313,77 @@ out_radio: ...@@ -312,3 +313,77 @@ out_radio:
return 0; return 0;
} }
int autoconfig_read_hash_from_file(uint8_t *macaddr, uint8_t *sha256_out)
{
struct blob_buf radios = { 0 };
struct blob_attr *b;
static const struct blobmsg_policy attr[] = {
[0] = { .name = "radios", .type = BLOBMSG_TYPE_ARRAY },
};
struct blob_attr *tb[ARRAY_SIZE(attr)];
int rem;
int ret = 0;
blob_buf_init(&radios, 0);
if (!blobmsg_add_json_from_file(&radios, AUTOCFG_FILE)) {
agnt_dbg(LOG_APCFG, "Failed to parse %s\n", AUTOCFG_FILE);
ret = -1;
goto out;
}
blobmsg_parse(attr, ARRAY_SIZE(attr), tb, blob_data(radios.head), blob_len(radios.head));
if (!tb[0]) {
ret = -1;
goto out;
}
blobmsg_for_each_attr(b, tb[0], rem) {
static const struct blobmsg_policy radio_attr[2] = {
[0] = { .name = "macaddr", .type = BLOBMSG_TYPE_STRING },
[1] = { .name = "sha256", .type = BLOBMSG_TYPE_STRING },
};
struct blob_attr *tb1[ARRAY_SIZE(radio_attr)];
char radio_str[18] = {0};
uint8_t radio_mac[6] = {0};
char *sh256_str;
int blen;
//char * data;
blobmsg_parse(radio_attr, ARRAY_SIZE(radio_attr), tb1, blobmsg_data(b), blob_len(b));
if (!tb1[0] || !tb1[1])
continue;
strncpy(radio_str, blobmsg_data(tb1[0]), sizeof(radio_str) - 1);
if (!hwaddr_aton(radio_str, radio_mac)) {
agnt_dbg(LOG_APCFG, "Failed to convert macaddr %s\n", radio_str);
continue;
}
if (memcmp(macaddr, radio_mac, 6))
continue;
sh256_str = blobmsg_get_string(tb1[1]);
if (!sh256_str) {
agnt_err(LOG_APCFG, "%s: No valid sha256\n", __func__);
ret = -1;
break;
}
blen = strlen(sh256_str) / 2;
if (blen > SHA256_LENGTH) {
agnt_err(LOG_APCFG, "%s: SHA256 string too long\n", __func__);
ret = -1;
break;
}
strtob(sh256_str, blen, sha256_out);
}
out:
blob_buf_free(&radios);
return ret;
}
...@@ -29,4 +29,5 @@ bool autoconfig_has_wsc_changed(struct wsc_data *wsc, ...@@ -29,4 +29,5 @@ bool autoconfig_has_wsc_changed(struct wsc_data *wsc,
size_t tlvs_size, size_t tlvs_size,
uint8_t *sha256_out); uint8_t *sha256_out);
int autoconfig_write_hash_to_file(uint8_t *macaddr, uint8_t *sha256); int autoconfig_write_hash_to_file(uint8_t *macaddr, uint8_t *sha256);
int autoconfig_read_hash_from_file(uint8_t *macaddr, uint8_t *sha256_out);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment