From 225a889b34ee1172b6ce0d95346a53320549b489 Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 19 Oct 2019 15:50:36 -0400 Subject: [PATCH] iccard/aime.c: Add (incomplete) AiMe card formatter --- iccard/aime.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ iccard/aime.h | 13 +++++++++++++ iccard/meson.build | 2 ++ 3 files changed, 62 insertions(+) create mode 100644 iccard/aime.c create mode 100644 iccard/aime.h diff --git a/iccard/aime.c b/iccard/aime.c new file mode 100644 index 0000000..5d2b1cd --- /dev/null +++ b/iccard/aime.c @@ -0,0 +1,47 @@ +#include +#include +#include + +#include "iccard/aime.h" +#include "iccard/mifare.h" + +#include "util/dprintf.h" + +HRESULT aime_card_populate( + struct mifare *mifare, + const uint8_t *luid, + size_t nbytes) +{ + uint8_t b; + size_t i; + + assert(mifare != NULL); + assert(luid != NULL); + + memset(mifare, 0, sizeof(*mifare)); + + if (nbytes != 10) { + dprintf("AiMe IC: LUID must be 10 bytes\n"); + + return E_INVALIDARG; + } + + for (i = 0 ; i < 10 ; i++) { + b = luid[i]; + + if ((b & 0xF0) > 0x90 || (b & 0x0F) > 0x09) { + dprintf("AiMe IC: LUID must be binary-coded decimal\n"); + return E_INVALIDARG; + } + + mifare->sectors[0].blocks[2].bytes[6 + i] = b; + } + + /* TODO An authentic Aime pass has a checksum of the LUID in the last few + bytes of block 1. The output of this function fails authenticity check + in its current form. */ + + dprintf("AiMe IC: WARNING: Authenticity hash not yet implemented!\n"); + + return S_OK; +} diff --git a/iccard/aime.h b/iccard/aime.h new file mode 100644 index 0000000..34857ef --- /dev/null +++ b/iccard/aime.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +#include +#include + +#include "iccard/mifare.h" + +HRESULT aime_card_populate( + struct mifare *mifare, + const uint8_t *luid, + size_t nbytes); diff --git a/iccard/meson.build b/iccard/meson.build index 08c5a3f..e068ae0 100644 --- a/iccard/meson.build +++ b/iccard/meson.build @@ -7,6 +7,8 @@ iccard_lib = static_library( capnhook.get_variable('hook_dep'), ], sources : [ + 'aime.c', + 'aime.h', 'felica.c', 'felica.h', 'mifare.h',