Only increase rps if it is not an update.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -205,6 +205,7 @@ int credential_store(const uint8_t *cred_id, size_t cred_id_len, const uint8_t *
|
|||||||
int sloti = -1;
|
int sloti = -1;
|
||||||
Credential cred = {0};
|
Credential cred = {0};
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
bool new_record = true;
|
||||||
ret = credential_load(cred_id, cred_id_len, rp_id_hash, &cred);
|
ret = credential_load(cred_id, cred_id_len, rp_id_hash, &cred);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
credential_free(&cred);
|
credential_free(&cred);
|
||||||
@@ -228,6 +229,7 @@ int credential_store(const uint8_t *cred_id, size_t cred_id_len, const uint8_t *
|
|||||||
if (memcmp(rcred.userId.data, cred.userId.data, MIN(rcred.userId.len, cred.userId.len)) == 0) {
|
if (memcmp(rcred.userId.data, cred.userId.data, MIN(rcred.userId.len, cred.userId.len)) == 0) {
|
||||||
sloti = i;
|
sloti = i;
|
||||||
credential_free(&rcred);
|
credential_free(&rcred);
|
||||||
|
new_record = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
credential_free(&rcred);
|
credential_free(&rcred);
|
||||||
@@ -241,37 +243,39 @@ int credential_store(const uint8_t *cred_id, size_t cred_id_len, const uint8_t *
|
|||||||
flash_write_data_to_file(ef, data, cred_id_len + 32);
|
flash_write_data_to_file(ef, data, cred_id_len + 32);
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
sloti = -1;
|
if (new_record == true) { //increase rps
|
||||||
for (int i = 0; i < MAX_RESIDENT_CREDENTIALS; i++) {
|
sloti = -1;
|
||||||
ef = search_dynamic_file(EF_RP + i);
|
for (int i = 0; i < MAX_RESIDENT_CREDENTIALS; i++) {
|
||||||
if (!file_has_data(ef)) {
|
ef = search_dynamic_file(EF_RP + i);
|
||||||
if (sloti == -1)
|
if (!file_has_data(ef)) {
|
||||||
|
if (sloti == -1)
|
||||||
|
sloti = i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (memcmp(file_get_data(ef)+1, rp_id_hash, 32) == 0) {
|
||||||
sloti = i;
|
sloti = i;
|
||||||
continue;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (memcmp(file_get_data(ef)+1, rp_id_hash, 32) == 0) {
|
if (sloti == -1)
|
||||||
sloti = i;
|
return -1;
|
||||||
break;
|
ef = search_dynamic_file(EF_RP + sloti);
|
||||||
|
if (file_has_data(ef)) {
|
||||||
|
data = (uint8_t *)calloc(1, file_get_size(ef));
|
||||||
|
memcpy(data, file_get_data(ef), file_get_size(ef));
|
||||||
|
data[0] += 1;
|
||||||
|
flash_write_data_to_file(ef, data, file_get_size(ef));
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ef = file_new(EF_RP+sloti);
|
||||||
|
data = (uint8_t *)calloc(1, 1 + 32 + cred.rpId.len);
|
||||||
|
data[0] = 1;
|
||||||
|
memcpy(data+1, rp_id_hash, 32);
|
||||||
|
memcpy(data + 1 + 32, cred.rpId.data, cred.rpId.len);
|
||||||
|
flash_write_data_to_file(ef, data, 1 + 32 + cred.rpId.len);
|
||||||
|
free(data);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (sloti == -1)
|
|
||||||
return -1;
|
|
||||||
ef = search_dynamic_file(EF_RP + sloti);
|
|
||||||
if (file_has_data(ef)) {
|
|
||||||
data = (uint8_t *)calloc(1, file_get_size(ef));
|
|
||||||
memcpy(data, file_get_data(ef), file_get_size(ef));
|
|
||||||
data[0] += 1;
|
|
||||||
flash_write_data_to_file(ef, data, file_get_size(ef));
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ef = file_new(EF_RP+sloti);
|
|
||||||
data = (uint8_t *)calloc(1, 1 + 32 + cred.rpId.len);
|
|
||||||
data[0] = 0;
|
|
||||||
memcpy(data+1, rp_id_hash, 32);
|
|
||||||
memcpy(data + 1 + 32, cred.rpId.data, cred.rpId.len);
|
|
||||||
flash_write_data_to_file(ef, data, 1 + 32 + cred.rpId.len);
|
|
||||||
free(data);
|
|
||||||
}
|
}
|
||||||
credential_free(&cred);
|
credential_free(&cred);
|
||||||
low_flash_available();
|
low_flash_available();
|
||||||
|
|||||||
Reference in New Issue
Block a user