Files
Momentum-Firmware/applications
jay candel 65df2e4d1f NFC: SmartRider Parser (#203)
* adding smartrider_parser

* adding SmartRider parser

new parser for SmartRider cards, a public transport smart card system used in Western Australia.
extracts and interprets key information from the card, including:
-Current balance
-Card serial number
-Concession type
-Purchase cost
-Details of the last two trips (including tag on/off status, cost, route, transaction number, and journey number)

* optimising

- removed all logging to simplify output.
- used early returns for clearer error handling.
- optimized setups outside loops to improve memory use.
- simplified flows by removing unnecessary loops.
- placed variables closer to their use for better readability.
- cached data blocks to streamline data handling.
- added a helper function for parsing trips, reducing redundancy.
- corrected loop counter types to avoid compile-time errors.

* cleaning displayed data

- removed transaction (txn) and journey (jrn) numbers to declutter the trip details.
- shortened "previous trip" to "prev trip" to optimize screen space usage.

* added and refined displayed data

added auto load field "threshold amount / reload amount"
changed serial to display first two digits as SR0 for consistency with physical card.

* Format

* Improved Verification Process

- Added definitions for STANDARD_KEY_2 and STANDARD_KEY_3
- Enhanced smartrider_verify function to check for all three specific keys:
  - STANDARD_KEY_1 in Sector 0 as Key A
  - STANDARD_KEY_2 in Sector 6 as Key A
  - STANDARD_KEY_3 in Sector 6 as Key B
- Implemented read operations to verify actual key values stored on the card
- Added comparisons between read key data and expected key values
- Improved debug logging for each step of the verification process

* Integrated Verification into Parse Function

- Added key verification for sectors 0 and 6
- Implemented do-while loop structure for early exit on verification failure
- Moved block readability checks inside verification process
- Added parsed flag to indicate successful parsing
- Updated return value to reflect parsing success
- Maintained existing parsing logic and output format

* fixed false positives

recieved some cuid cards today so was able to test for myself can confirm works... finally
changes made: 
-updated key assignment in smartrider_read
-simplified key verification in smartrider_parse
-improved error handling and logging
-streamlined data parsing process
-corrected key checking logic
-added checks for required block readability
-improved flow control with strategic breaks
-adjusted block data access method

* small optimizations

- refactored `smartrider_verify` and `smartrider_read` by abstracting repeated key operations into `authenticate_and_read` function for improved code maintainability.
- optimized `smartrider_read` by introducing a loop for key setup, reducing redundancy and improving efficiency.
- streamlined error handling in `smartrider_read` by replacing do-while loop with conditional checks.
- changed standard key references to use `standard_keys` array indices

* formatting

* Delete duplicate smartrider.c

* updated smartrider.c

* found 'fbt format'

* transaction parsing updates

-removed last trip/prev trip wording and replaced with "Trip History" header
-added date in front of each transaction 
-only shows transaction cost if it's higher than 0
-changed tag on/tag off to +/- to save room
-added 8 more transactions to Trip History
-verified still working and formatted with fbt

* fixed reboot with partially unlocked card

-added bounds checking for all block accesses to prevent out-of-range memory access
-implemented improved error handling with an error_occurred flag
-introduced a maximum iteration count for date calculation to prevent infinite loops
-used snprintf with size limits for all string operations to avoid buffer overflows
-added validation for trip count to ensure it doesn't exceed the maximum allowed
-implemented checks to skip unread or out-of-range blocks during trip parsing
-added safeguards against corrupted or invalid timestamp data

* optimized SmartRider card parsing and verification

- replaced do-while loop with direct error checks in smartrider_parse
- optimized key verification using direct memcmp in smartrider_verify
- introduced inline functions for common operations (e.g., set_key, read_le16)
- replaced bubble sort with insertion sort for trip data
- simplified date calculation using a lookup table for days in month
- used uint_fast8_t for loop counters to allow compiler optimization
- added __attribute__((hot)) to key functions for aggressive optimization
- removed redundant variable declarations and function calls
- optimized memory usage with static const arrays for required blocks
- simplified error handling in smartrider_read and authenticate_and_read
- used __builtin_memcpy and __builtin_memcmp for potential compiler optimizations
- tested and formatted with fbt

* small fixes

-renamed "Trip History" to "Tag On/Off History"
-fixed date calculation to account for leap years
-misc changes

* Update changelog

---------

Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com>
2024-09-18 03:00:49 +02:00
..
2024-09-18 03:00:49 +02:00

Structure

debug

Applications for factory testing the Flipper.

  • accessor - Wiegand server
  • battery_test_app - Battery debug app
  • blink_test - LED blinker
  • bt_debug_app - BT test app. Requires full BT stack installed
  • display_test - Various display tests & tweaks
  • file_browser_test - Test UI for file picker
  • keypad_test - Keypad test
  • lfrfid_debug - LF RFID debug tool
  • text_box_test - UI tests
  • uart_echo - UART mode test
  • unit_tests - Unit tests
  • usb_mouse - USB HID test
  • usb_test - Other USB tests
  • vibro_test - Vibro test

main

Applications for main Flipper menu.

  • archive - Archive and file manager
  • bad_kb - Bad KB application
  • gpio - GPIO application: includes USART bridge and GPIO control
  • ibutton - iButton application, onewire keys and more
  • infrared - Infrared application, controls your IR devices
  • lfrfid - LF RFID application
  • nfc - NFC application, HF rfid, EMV and etc
  • subghz - SubGhz application, 433 fobs and etc
  • u2f - U2F Application

External

External applications deployed to SD Card

  • clock - Clock application
  • dap_link - DAP Link OnChip debugger
  • hid_app - USB/BT Remote controller
  • music_player - Music player app (demo)
  • nfc_magic - NFC MFC Magic card application
  • picopass - Picopass reader / writer
  • signal_generator - Signal generator app: PWM and clock generator
  • snake_game - Snake game application
  • spi_mem_manager - SPI Memory reader / flasher
  • weather_station - SubGHz weather station

services

Background services providing system APIs to applications.

  • applications.h - Firmware application list header
  • bt - BLE service and application
  • cli - Console service and API
  • crypto - Crypto cli tools
  • desktop - Desktop service
  • dialogs - Dialogs service: GUI Dialogs for your app
  • dolphin - Dolphin service and supplementary apps
  • gui - GUI service and API
  • input - Input service
  • loader - Application loader service
  • notification - Notification service
  • power - Power service
  • rpc - RPC service and API
  • storage - Storage service, internal + sdcard

settings

Small applications providing configuration for basic firmware and its services.

  • about - Small About application that shows flipper info
  • bt_settings_app - Bluetooth options
  • desktop_settings - Desktop configuration
  • dolphin_passport - Dolphin passport app
  • notification_settings - LCD brightness, sound volume, etc configuration
  • power_settings_app - Basic power options
  • storage_settings - Storage settings app
  • system - System settings

system

Utility apps not visible in other menus, plus few external apps pre-packaged with the firmware.

  • hid_app - BLE & USB HID remote
  • js_app - JS engine runner
  • snake_game - Snake game
  • storage_move_to_sd - Data migration tool for internal storage
  • updater - Update service & application