-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
406 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "felica_listener_i.h" | ||
|
||
#include "nfc/protocols/nfc_listener_base.h" | ||
|
||
#define FELICA_LISTENER_MAX_BUFFER_SIZE (64) | ||
#define TAG "Felica" | ||
|
||
FelicaListener* felica_listener_alloc(Nfc* nfc, FelicaData* data) { | ||
furi_assert(nfc); | ||
furi_assert(data); | ||
|
||
FelicaListener* instance = malloc(sizeof(FelicaListener)); | ||
instance->nfc = nfc; | ||
instance->data = data; | ||
instance->tx_buffer = bit_buffer_alloc(FELICA_LISTENER_MAX_BUFFER_SIZE); | ||
instance->rx_buffer = bit_buffer_alloc(FELICA_LISTENER_MAX_BUFFER_SIZE); | ||
|
||
nfc_set_fdt_listen_fc(instance->nfc, FELICA_FDT_LISTEN_FC); | ||
|
||
nfc_config(instance->nfc, NfcModeListener, NfcTechFelica); | ||
nfc_felica_listener_set_sensf_res_data( | ||
nfc, data->idm.data, sizeof(data->idm), data->pmm.data, sizeof(data->pmm)); | ||
|
||
return instance; | ||
} | ||
|
||
void felica_listener_free(FelicaListener* instance) { | ||
furi_assert(instance); | ||
furi_assert(instance->tx_buffer); | ||
|
||
bit_buffer_free(instance->tx_buffer); | ||
bit_buffer_free(instance->rx_buffer); | ||
free(instance); | ||
} | ||
|
||
void felica_listener_set_callback( | ||
FelicaListener* listener, | ||
NfcGenericCallback callback, | ||
void* context) { | ||
UNUSED(listener); | ||
UNUSED(callback); | ||
UNUSED(context); | ||
} | ||
|
||
const FelicaData* felica_listener_get_data(const FelicaListener* instance) { | ||
furi_assert(instance); | ||
furi_assert(instance->data); | ||
|
||
return instance->data; | ||
} | ||
|
||
NfcCommand felica_listener_run(NfcGenericEvent event, void* context) { | ||
furi_assert(context); | ||
furi_assert(event.protocol == NfcProtocolInvalid); | ||
furi_assert(event.event_data); | ||
|
||
FelicaListener* instance = context; | ||
NfcEvent* nfc_event = event.event_data; | ||
NfcCommand command = NfcCommandContinue; | ||
|
||
if(nfc_event->type == NfcEventTypeListenerActivated) { | ||
instance->state = Felica_ListenerStateActivated; | ||
FURI_LOG_D(TAG, "Activated"); | ||
} else if(nfc_event->type == NfcEventTypeFieldOff) { | ||
instance->state = Felica_ListenerStateIdle; | ||
FURI_LOG_D(TAG, "Field Off"); | ||
} else if(nfc_event->type == NfcEventTypeRxEnd) { | ||
FURI_LOG_D(TAG, "Rx Done"); | ||
} | ||
return command; | ||
} | ||
|
||
const NfcListenerBase nfc_listener_felica = { | ||
.alloc = (NfcListenerAlloc)felica_listener_alloc, | ||
.free = (NfcListenerFree)felica_listener_free, | ||
.set_callback = (NfcListenerSetCallback)felica_listener_set_callback, | ||
.get_data = (NfcListenerGetData)felica_listener_get_data, | ||
.run = (NfcListenerRun)felica_listener_run, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include "felica.h" | ||
#include <lib/nfc/nfc.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct FelicaListener FelicaListener; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <nfc/protocols/nfc_listener_base.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern const NfcListenerBase nfc_listener_felica; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "felica_listener.h" | ||
|
||
#include <nfc/protocols/nfc_generic_event.h> | ||
|
||
typedef enum { | ||
Felica_ListenerStateIdle, | ||
Felica_ListenerStateActivated, | ||
} FelicaListenerState; | ||
|
||
struct FelicaListener { | ||
Nfc* nfc; | ||
FelicaData* data; | ||
FelicaListenerState state; | ||
|
||
BitBuffer* tx_buffer; | ||
BitBuffer* rx_buffer; | ||
|
||
NfcGenericEvent generic_event; | ||
NfcGenericCallback callback; | ||
void* context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.