iccard/aime.c: Add (incomplete) AiMe card formatter

This commit is contained in:
Tau 2019-10-19 15:50:36 -04:00
parent 87af39a269
commit 225a889b34
3 changed files with 62 additions and 0 deletions

47
iccard/aime.c Normal file
View File

@ -0,0 +1,47 @@
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#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;
}

13
iccard/aime.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include <windows.h>
#include <stddef.h>
#include <stdint.h>
#include "iccard/mifare.h"
HRESULT aime_card_populate(
struct mifare *mifare,
const uint8_t *luid,
size_t nbytes);

View File

@ -7,6 +7,8 @@ iccard_lib = static_library(
capnhook.get_variable('hook_dep'), capnhook.get_variable('hook_dep'),
], ],
sources : [ sources : [
'aime.c',
'aime.h',
'felica.c', 'felica.c',
'felica.h', 'felica.h',
'mifare.h', 'mifare.h',