From a8f75521d585129b95fcb40ecec0a335ec313818 Mon Sep 17 00:00:00 2001 From: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Date: Fri, 12 Jun 2026 10:25:54 +0200 Subject: [PATCH] nfc: add setting to change FeliCa PMm to read as FeliCa Mobile --- common/board/config.c | 1 + common/board/sg-nfc.c | 6 ++++-- common/board/sg-nfc.h | 1 + common/board/sg-reader-queue.c | 2 +- common/board/sg-reader.c | 2 +- common/board/sg-reader.h | 1 + common/iccard/felica.c | 4 ++-- common/iccard/felica.h | 4 +++- doc/config/common.md | 6 ++++++ 9 files changed, 20 insertions(+), 7 deletions(-) diff --git a/common/board/config.c b/common/board/config.c index cb2f948..9f915cb 100644 --- a/common/board/config.c +++ b/common/board/config.c @@ -80,6 +80,7 @@ void aime_config_load_bykey(struct aime_config *cfg, const wchar_t *filename, co cfg->high_baudrate = GetPrivateProfileIntW(config_key, L"highBaud", 1, filename); cfg->gen = GetPrivateProfileIntW(config_key, L"gen", 0, filename); cfg->proxy_flag = GetPrivateProfileIntW(config_key, L"proxyFlag", 2, filename); + cfg->mobile_felica = GetPrivateProfileIntW(config_key, L"mobileFelica", 0, filename); GetPrivateProfileStringW( config_key, diff --git a/common/board/sg-nfc.c b/common/board/sg-nfc.c index 82a01a6..cb51d66 100644 --- a/common/board/sg-nfc.c +++ b/common/board/sg-nfc.c @@ -125,6 +125,7 @@ void sg_nfc_init( unsigned int gen, unsigned int proxy_flag, const wchar_t* authdata_path, + bool mobile_felica, void *ops_ctx) { assert(nfc != NULL); @@ -136,6 +137,7 @@ void sg_nfc_init( nfc->gen = gen; nfc->proxy_flag = proxy_flag; nfc->authdata_path = authdata_path; + nfc->felica.is_mobile = mobile_felica; } #ifdef NDEBUG @@ -445,12 +447,12 @@ static HRESULT sg_nfc_poll_felica( felica->type = 0x20; felica->id_len = sizeof(felica->IDm) + sizeof(felica->PMm); felica->IDm = _byteswap_uint64(IDm); - felica->PMm = _byteswap_uint64(felica_get_amusement_ic_PMm()); + felica->PMm = _byteswap_uint64(felica_get_amusement_ic_PMm(nfc->felica.is_mobile)); /* Initialize FeliCa IC emulator */ nfc->felica.IDm = IDm; - nfc->felica.PMm = felica_get_amusement_ic_PMm(); + nfc->felica.PMm = felica_get_amusement_ic_PMm(nfc->felica.is_mobile); nfc->felica.system_code = 0x88b4; return S_OK; diff --git a/common/board/sg-nfc.h b/common/board/sg-nfc.h index 855d8cf..a3465c8 100644 --- a/common/board/sg-nfc.h +++ b/common/board/sg-nfc.h @@ -70,6 +70,7 @@ void sg_nfc_init( unsigned int gen, unsigned int proxy_flag, const wchar_t* authdata_path, + bool mobile_felica, void *ops_ctx); void sg_nfc_transact( diff --git a/common/board/sg-reader-queue.c b/common/board/sg-reader-queue.c index 29637e7..35f510b 100644 --- a/common/board/sg-reader-queue.c +++ b/common/board/sg-reader-queue.c @@ -82,7 +82,7 @@ HRESULT sg_reader_queue_hook_init( return E_INVALIDARG; } - sg_nfc_init(&sg_reader_nfc, 0x01, &sg_reader_nfc_ops, gen, cfg->proxy_flag, cfg->authdata_path, NULL); + sg_nfc_init(&sg_reader_nfc, 0x01, &sg_reader_nfc_ops, gen, cfg->proxy_flag, cfg->authdata_path, cfg->mobile_felica, NULL); sg_led_init(&sg_reader_led, 0x08, &sg_reader_led_ops, gen, NULL); InitializeCriticalSection(&sg_reader_lock); diff --git a/common/board/sg-reader.c b/common/board/sg-reader.c index c1935dd..ffa12a2 100644 --- a/common/board/sg-reader.c +++ b/common/board/sg-reader.c @@ -131,7 +131,7 @@ HRESULT sg_reader_hook_init( return E_INVALIDARG; } - sg_nfc_init(&sg_reader_nfc, 0x00, &sg_reader_nfc_ops, gen, cfg->proxy_flag, cfg->authdata_path, NULL); + sg_nfc_init(&sg_reader_nfc, 0x00, &sg_reader_nfc_ops, gen, cfg->proxy_flag, cfg->authdata_path, cfg->mobile_felica, NULL); sg_led_init(&sg_reader_led, 0x08, &sg_reader_led_ops, gen, NULL); InitializeCriticalSection(&sg_reader_lock); diff --git a/common/board/sg-reader.h b/common/board/sg-reader.h index 64de7e9..137fceb 100644 --- a/common/board/sg-reader.h +++ b/common/board/sg-reader.h @@ -14,6 +14,7 @@ struct aime_config { unsigned int gen; unsigned int proxy_flag; wchar_t authdata_path[MAX_PATH]; + bool mobile_felica; }; HRESULT sg_reader_hook_init( diff --git a/common/iccard/felica.c b/common/iccard/felica.c index 392f3b2..8f20e2a 100644 --- a/common/iccard/felica.c +++ b/common/iccard/felica.c @@ -37,14 +37,14 @@ static HRESULT felica_cmd_write_without_encryption( struct const_iobuf* req, struct iobuf* res); -uint64_t felica_get_amusement_ic_PMm(void) +uint64_t felica_get_amusement_ic_PMm(bool is_mobile) { /* * AIC Card PMm, if this is returned from the card, * the aimelib will access the actual blocks for authentication. */ - return 0x00F1000000014300; + return is_mobile ? 0x0018000000014300 : 0x00F1000000014300; } HRESULT felica_transact( diff --git a/common/iccard/felica.h b/common/iccard/felica.h index b55cc87..f6b1410 100644 --- a/common/iccard/felica.h +++ b/common/iccard/felica.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -19,6 +20,7 @@ struct felica { uint64_t IDm; uint64_t PMm; uint16_t system_code; + bool is_mobile; }; HRESULT felica_transact( @@ -26,4 +28,4 @@ HRESULT felica_transact( struct const_iobuf *req, struct iobuf *res); -uint64_t felica_get_amusement_ic_PMm(void); +uint64_t felica_get_amusement_ic_PMm(bool is_mobile); diff --git a/doc/config/common.md b/doc/config/common.md index 7fb5f62..a295c47 100644 --- a/doc/config/common.md +++ b/doc/config/common.md @@ -113,6 +113,12 @@ Default: `DEVICE\authdata.bin` Path to the binary file containing data for a Thinca authentication card (see `emoney.txt`) +### `mobileFelica` + +Default: `0` + +Whether to simulate the scanned FeliCa being a mobile device (1) or an IC card (0). Changes behavior of Aime DB and the card registration flow slightly. + ## `[vfd]` Controls emulation of the VFD GP1232A02A FUTABA assembly.