-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* slix: add unlock option * slix: add features for nxp get info and signature commands * slix: working unlock * nfc app: rewrite slix unlock * slix poller: simplify unlock state handler * nfc app: fix slix key setting * nfc app: fix navigation * slix poller: code clean up * slix: resolve TODO, clean code * nfc app: fix naming * nfc app: rework slix unlock success scene * slix poller: add documentation * slix listener: fix password comparison Co-authored-by: あく <[email protected]>
- Loading branch information
Showing
22 changed files
with
576 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "slix_unlock.h" | ||
|
||
#include <furi/furi.h> | ||
|
||
#define SLIX_UNLOCK_PASSWORD_NUM_MAX (2) | ||
|
||
struct SlixUnlock { | ||
SlixUnlockMethod method; | ||
SlixPassword password_arr[SLIX_UNLOCK_PASSWORD_NUM_MAX]; | ||
size_t password_arr_len; | ||
size_t password_idx; | ||
}; | ||
|
||
static const SlixPassword tonie_box_pass_arr[] = {0x5B6EFD7F, 0x0F0F0F0F}; | ||
|
||
SlixUnlock* slix_unlock_alloc() { | ||
SlixUnlock* instance = malloc(sizeof(SlixUnlock)); | ||
|
||
return instance; | ||
} | ||
|
||
void slix_unlock_free(SlixUnlock* instance) { | ||
furi_assert(instance); | ||
|
||
free(instance); | ||
} | ||
|
||
void slix_unlock_reset(SlixUnlock* instance) { | ||
furi_assert(instance); | ||
|
||
memset(instance, 0, sizeof(SlixUnlock)); | ||
} | ||
|
||
void slix_unlock_set_method(SlixUnlock* instance, SlixUnlockMethod method) { | ||
furi_assert(instance); | ||
|
||
instance->method = method; | ||
if(method == SlixUnlockMethodTonieBox) { | ||
instance->password_arr_len = COUNT_OF(tonie_box_pass_arr); | ||
memcpy(instance->password_arr, tonie_box_pass_arr, sizeof(tonie_box_pass_arr)); | ||
} | ||
} | ||
|
||
void slix_unlock_set_password(SlixUnlock* instance, SlixPassword password) { | ||
furi_assert(instance); | ||
furi_assert(instance->method == SlixUnlockMethodManual); | ||
|
||
instance->password_arr[0] = password; | ||
instance->password_arr_len = 1; | ||
} | ||
|
||
bool slix_unlock_get_next_password(SlixUnlock* instance, SlixPassword* password) { | ||
furi_assert(instance); | ||
furi_assert(password); | ||
|
||
bool password_set = false; | ||
if(instance->password_arr_len) { | ||
*password = instance->password_arr[instance->password_idx++]; | ||
instance->password_idx %= instance->password_arr_len; | ||
password_set = true; | ||
} | ||
|
||
return password_set; | ||
} |
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,30 @@ | ||
#pragma once | ||
|
||
#include <nfc/protocols/slix/slix.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef enum { | ||
SlixUnlockMethodManual, | ||
SlixUnlockMethodTonieBox, | ||
} SlixUnlockMethod; | ||
|
||
typedef struct SlixUnlock SlixUnlock; | ||
|
||
SlixUnlock* slix_unlock_alloc(); | ||
|
||
void slix_unlock_free(SlixUnlock* instance); | ||
|
||
void slix_unlock_reset(SlixUnlock* instance); | ||
|
||
void slix_unlock_set_method(SlixUnlock* instance, SlixUnlockMethod method); | ||
|
||
void slix_unlock_set_password(SlixUnlock* instance, SlixPassword password); | ||
|
||
bool slix_unlock_get_next_password(SlixUnlock* instance, SlixPassword* password); | ||
|
||
#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
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,48 @@ | ||
#include "../nfc_app_i.h" | ||
|
||
#include <nfc/helpers/nfc_util.h> | ||
|
||
void nfc_scene_slix_key_input_byte_input_callback(void* context) { | ||
NfcApp* instance = context; | ||
|
||
SlixPassword password = nfc_util_bytes2num(instance->byte_input_store, sizeof(SlixPassword)); | ||
slix_unlock_set_password(instance->slix_unlock, password); | ||
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventByteInputDone); | ||
} | ||
|
||
void nfc_scene_slix_key_input_on_enter(void* context) { | ||
NfcApp* instance = context; | ||
|
||
// Setup view | ||
ByteInput* byte_input = instance->byte_input; | ||
byte_input_set_header_text(byte_input, "Enter the password in hex"); | ||
byte_input_set_result_callback( | ||
byte_input, | ||
nfc_scene_slix_key_input_byte_input_callback, | ||
NULL, | ||
instance, | ||
instance->byte_input_store, | ||
sizeof(SlixPassword)); | ||
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewByteInput); | ||
} | ||
|
||
bool nfc_scene_slix_key_input_on_event(void* context, SceneManagerEvent event) { | ||
NfcApp* instance = context; | ||
bool consumed = false; | ||
|
||
if(event.type == SceneManagerEventTypeCustom) { | ||
if(event.event == NfcCustomEventByteInputDone) { | ||
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixUnlock); | ||
consumed = true; | ||
} | ||
} | ||
return consumed; | ||
} | ||
|
||
void nfc_scene_slix_key_input_on_exit(void* context) { | ||
NfcApp* instance = context; | ||
|
||
// Clear view | ||
byte_input_set_result_callback(instance->byte_input, NULL, NULL, NULL, NULL, 0); | ||
byte_input_set_header_text(instance->byte_input, ""); | ||
} |
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,70 @@ | ||
#include "../nfc_app_i.h" | ||
|
||
#include <nfc/protocols/slix/slix_poller.h> | ||
|
||
NfcCommand nfc_scene_slix_unlock_worker_callback(NfcGenericEvent event, void* context) { | ||
furi_assert(event.protocol == NfcProtocolSlix); | ||
|
||
NfcCommand command = NfcCommandContinue; | ||
|
||
NfcApp* instance = context; | ||
SlixPollerEvent* slix_event = event.event_data; | ||
if(slix_event->type == SlixPollerEventTypePrivacyUnlockRequest) { | ||
SlixPassword pwd = 0; | ||
bool get_password_success = slix_unlock_get_next_password(instance->slix_unlock, &pwd); | ||
slix_event->data->privacy_password.password = pwd; | ||
slix_event->data->privacy_password.password_set = get_password_success; | ||
} else if(slix_event->type == SlixPollerEventTypeError) { | ||
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerFailure); | ||
} else if(slix_event->type == SlixPollerEventTypeReady) { | ||
nfc_device_set_data( | ||
instance->nfc_device, NfcProtocolSlix, nfc_poller_get_data(instance->poller)); | ||
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerSuccess); | ||
command = NfcCommandStop; | ||
} | ||
|
||
return command; | ||
} | ||
|
||
void nfc_scene_slix_unlock_on_enter(void* context) { | ||
NfcApp* instance = context; | ||
|
||
popup_set_icon(instance->popup, 0, 8, &I_NFC_manual_60x50); | ||
popup_set_header(instance->popup, "Unlocking", 97, 15, AlignCenter, AlignTop); | ||
popup_set_text( | ||
instance->popup, "Apply card to\nFlipper's back", 97, 27, AlignCenter, AlignTop); | ||
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewPopup); | ||
|
||
instance->poller = nfc_poller_alloc(instance->nfc, NfcProtocolSlix); | ||
nfc_poller_start(instance->poller, nfc_scene_slix_unlock_worker_callback, instance); | ||
} | ||
|
||
bool nfc_scene_slix_unlock_on_event(void* context, SceneManagerEvent event) { | ||
NfcApp* instance = context; | ||
UNUSED(instance); | ||
bool consumed = false; | ||
|
||
if(event.type == SceneManagerEventTypeCustom) { | ||
if(event.event == NfcCustomEventPollerFailure) { | ||
consumed = true; | ||
} else if(event.event == NfcCustomEventPollerSuccess) { | ||
notification_message(instance->notifications, &sequence_success); | ||
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixUnlockSuccess); | ||
consumed = true; | ||
} | ||
} else if(event.type == SceneManagerEventTypeBack) { | ||
consumed = scene_manager_search_and_switch_to_previous_scene( | ||
instance->scene_manager, NfcSceneSlixUnlockMenu); | ||
} | ||
|
||
return consumed; | ||
} | ||
|
||
void nfc_scene_slix_unlock_on_exit(void* context) { | ||
NfcApp* instance = context; | ||
|
||
nfc_poller_stop(instance->poller); | ||
nfc_poller_free(instance->poller); | ||
|
||
popup_reset(instance->popup); | ||
} |
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,60 @@ | ||
#include "../nfc_app_i.h" | ||
|
||
enum SubmenuIndex { | ||
SubmenuIndexSlixUnlockMenuManual, | ||
SubmenuIndexSlixUnlockMenuTonieBox, | ||
}; | ||
|
||
void nfc_scene_slix_unlock_menu_submenu_callback(void* context, uint32_t index) { | ||
NfcApp* instance = context; | ||
|
||
view_dispatcher_send_custom_event(instance->view_dispatcher, index); | ||
} | ||
|
||
void nfc_scene_slix_unlock_menu_on_enter(void* context) { | ||
NfcApp* instance = context; | ||
Submenu* submenu = instance->submenu; | ||
|
||
uint32_t state = | ||
scene_manager_get_scene_state(instance->scene_manager, NfcSceneSlixUnlockMenu); | ||
submenu_add_item( | ||
submenu, | ||
"Enter Password Manually", | ||
SubmenuIndexSlixUnlockMenuManual, | ||
nfc_scene_slix_unlock_menu_submenu_callback, | ||
instance); | ||
submenu_add_item( | ||
submenu, | ||
"Auth As TommyBox", | ||
SubmenuIndexSlixUnlockMenuTonieBox, | ||
nfc_scene_slix_unlock_menu_submenu_callback, | ||
instance); | ||
submenu_set_selected_item(submenu, state); | ||
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewMenu); | ||
} | ||
|
||
bool nfc_scene_slix_unlock_menu_on_event(void* context, SceneManagerEvent event) { | ||
NfcApp* instance = context; | ||
bool consumed = false; | ||
|
||
if(event.type == SceneManagerEventTypeCustom) { | ||
if(event.event == SubmenuIndexSlixUnlockMenuManual) { | ||
slix_unlock_set_method(instance->slix_unlock, SlixUnlockMethodManual); | ||
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixKeyInput); | ||
consumed = true; | ||
} else if(event.event == SubmenuIndexSlixUnlockMenuTonieBox) { | ||
slix_unlock_set_method(instance->slix_unlock, SlixUnlockMethodTonieBox); | ||
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixUnlock); | ||
consumed = true; | ||
} | ||
scene_manager_set_scene_state( | ||
instance->scene_manager, NfcSceneSlixUnlockMenu, event.event); | ||
} | ||
return consumed; | ||
} | ||
|
||
void nfc_scene_slix_unlock_menu_on_exit(void* context) { | ||
NfcApp* instance = context; | ||
|
||
submenu_reset(instance->submenu); | ||
} |
Oops, something went wrong.