|
|
@@ -1,4 +1,32 @@
|
|
|
#include "../esubghz_chat_i.h"
|
|
|
+#include "../nfc_helpers.h"
|
|
|
+
|
|
|
+struct ReplayDictNfcWriterContext {
|
|
|
+ uint8_t *cur;
|
|
|
+ uint8_t *max;
|
|
|
+};
|
|
|
+
|
|
|
+static bool replay_dict_nfc_writer(uint64_t run_id, uint32_t counter, void
|
|
|
+ *context)
|
|
|
+{
|
|
|
+ struct ReplayDictNfcWriterContext *ctx = (struct
|
|
|
+ ReplayDictNfcWriterContext *) context;
|
|
|
+
|
|
|
+ struct ReplayDictNfcEntry entry = {
|
|
|
+ .run_id = run_id,
|
|
|
+ .counter = __htonl(counter),
|
|
|
+ .unused = 0
|
|
|
+ };
|
|
|
+
|
|
|
+ if (ctx->cur + sizeof(entry) > ctx->max) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ memcpy(ctx->cur, &entry, sizeof(entry));
|
|
|
+ ctx->cur += sizeof(entry);
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
|
|
|
static void prepare_nfc_dev_data(ESubGhzChatState *state)
|
|
|
{
|
|
|
@@ -21,9 +49,22 @@ static void prepare_nfc_dev_data(ESubGhzChatState *state)
|
|
|
dev_data->mf_ul_data.version.storage_size = 0x11;
|
|
|
dev_data->mf_ul_data.version.protocol_type = 0x03;
|
|
|
|
|
|
- /* Add 16 to the size for config pages */
|
|
|
- dev_data->mf_ul_data.data_size = (KEY_BITS / 8) + 16;
|
|
|
+ /* write key */
|
|
|
crypto_ctx_get_key(state->crypto_ctx, dev_data->mf_ul_data.data);
|
|
|
+
|
|
|
+ /* write the replay dict */
|
|
|
+ struct ReplayDictNfcWriterContext wr_ctx = {
|
|
|
+ .cur = dev_data->mf_ul_data.data + (KEY_BITS / 8),
|
|
|
+ .max = dev_data->mf_ul_data.data + NFC_MAX_BYTES
|
|
|
+ };
|
|
|
+
|
|
|
+ size_t n_entries = crypto_ctx_dump_replay_dict(state->crypto_ctx,
|
|
|
+ replay_dict_nfc_writer, &wr_ctx);
|
|
|
+
|
|
|
+ /* calculate size of data, add 16 for config pages */
|
|
|
+ dev_data->mf_ul_data.data_size = (KEY_BITS / 8) + (n_entries *
|
|
|
+ sizeof(struct ReplayDictNfcEntry)) + (NFC_CONFIG_PAGES
|
|
|
+ * 4);
|
|
|
}
|
|
|
|
|
|
/* Prepares the key share popup scene. */
|