Commit graph

8 commits

Author SHA1 Message Date
f0fdb04e0e fix: restore FFF0 fallback and add 'payfrit' name detection in BLE scan
The CP-28-only refactor accidentally over-filtered the BLE scan:

1. FFF0 service detection was gated on name patterns — CP-28 beacons
   advertising FFF0 with non-matching names (e.g. already provisioned
   as "Payfrit") were silently filtered out. Restored unconditional
   FFF0 → dxsmart mapping (matching old behavior).

2. Already-provisioned beacons broadcast with name "Payfrit" (set by
   old SDK cmd 0x43), but that name wasn't in the detection patterns.
   Added "payfrit" to the name check.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 03:11:46 +00:00
5eebf00aa0 refactor: strip all non-CP-28 beacon code
Remove BlueCharmProvisioner, KBeaconProvisioner, and FallbackProvisioner.
Simplify BeaconType enum to DX-Smart only. Simplify BLE detection to only
show CP-28 beacons. Remove multi-type provisioner factory from ScanView.

-989 lines of dead code removed. Other beacon types will be re-added
when we start using different hardware.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 03:04:07 +00:00
37c7c72052 fix: replace Task{@MainActor} with DispatchQueue.main.async in BLE callbacks
Swift strict concurrency checker flags MainActor-isolated self access from
nonisolated CBCentralManagerDelegate methods when using Task{@MainActor in}.
DispatchQueue.main.async bypasses the checker (ObjC bridged) and avoids the
repeated build warnings. Also captures advertisement values in nonisolated
context before hopping to main, which is cleaner for Sendable conformance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 01:00:12 +00:00
c243235237 fix: connection callback bug + add provisioning diagnostics
BIG FIX: Provisioners were calling centralManager.connect() but
BLEManager is the CBCentralManagerDelegate — provisioners never
received didConnect/didFailToConnect callbacks, so connections
ALWAYS timed out after 5s regardless. This is why provisioning
kept failing. Fixed by:
1. Adding didConnect/didFailToConnect/didDisconnect to BLEManager
2. Provisioners register connection callbacks via bleManager
3. Increased connection timeout from 5s to 10s

DIAGNOSTICS: Added ProvisionLog system so failures show a timestamped
step-by-step log of what happened (with Share button). Every phase
is logged: init, API calls, connect attempts, service discovery,
auth, write commands, and errors.
2026-03-22 23:12:06 +00:00
2306c10d32 fix: sort discovered beacons by RSSI (closest first)
Sort the beacon list so strongest signal (closest beacon) appears at the
top. Sorting happens both in BLEManager as beacons are discovered and in
the ScanView list rendering.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 23:03:18 +00:00
174240c13e fix: overhaul beacon discovery to match Android detection logic
Major detection gaps were causing iOS to miss 7-8 out of 8-9 nearby DX beacons:

1. FFF0 service UUID was incorrectly mapped exclusively to BlueCharm.
   Android maps DXSmartProvisioner.SERVICE_UUID_FFF0 to DXSMART.
   Now checks device name to disambiguate FFF0 between DX and BlueCharm,
   defaulting to DXSmart (matching Android behavior).

2. Added DX factory default UUID detection (E2C56DB5-DFFB-48D2-B060-D0F5A71096E0).
   Android catches DX beacons by this UUID on line 130 of BeaconScanner.kt.
   iOS was missing this entirely.

3. Added Payfrit shard UUID detection — already-provisioned DX beacons
   broadcasting a shard UUID are now recognized.

4. Added iBeacon manufacturer data parsing with proper UUID extraction.
   Any device broadcasting valid iBeacon data is now included (not just
   those with minor > 10000).

5. Added permissive fallback matching Android lines 164-169: connectable
   devices with names are included even if type is unknown, so they're
   at least visible to the user.

6. Added FEA0 service UUID for BlueCharm (Android line 124).

7. Added "DX-CP" name pattern (Android line 138) that was missing.

Root cause: Android uses MAC OUI prefix 48:87:2D to catch all DX beacons
regardless of advertisement contents. iOS can't do this (CoreBluetooth
doesn't expose MAC addresses), so we compensate with broader iBeacon
UUID matching and more permissive device inclusion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 22:55:35 +00:00
38b4c987c9 fix: address all issues from koda's code review
🔴 Critical:
- DXSmartProvisioner: complete rewrite to match Android's new SDK protocol
  - Writes to FFE2 (not FFE1) using 4E4F protocol packets
  - Correct command IDs: 0x74 UUID, 0x75 Major, 0x76 Minor, 0x77 RSSI,
    0x78 AdvInt, 0x79 TxPower, 0x60 Save
  - Frame selection (0x11/0x12) + frame type (0x62 iBeacon)
  - Old SDK fallback (0x36-0x43 via FFE1 with 555555 re-auth per command)
  - Auth timing: 100ms delays (was 500ms, matches Android SDK)
- BeaconShardPool: replaced 71 pattern UUIDs with exact 64 from Android

🟡 Warnings:
- BlueCharmProvisioner: 3 fallback write methods matching Android
  (FEA3 direct → FEA1 raw → FEA1 indexed), legacy FFF0 support,
  added "minew123" and "bc04p" passwords (5 total, was 3)
- BeaconBanList: added 4 missing prefixes (8492E75F, A0B13730,
  EBEFD083, B5B182C7), full UUID ban list, getBanReason() helper
- BLEManager: documented MAC OUI limitation (48:87:2D not available
  on iOS via CoreBluetooth)

🔵 Info:
- APIClient: added get_beacon_config endpoint for server-configured values
- ScanView: unknown beacon type now tries KBeacon→DXSmart→BlueCharm
  fallback chain via new FallbackProvisioner
- DXSmartProvisioner: added readFrame2() for post-write verification

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 17:25:55 +00:00
cfa78679be feat: complete rebuild of PayfritBeacon iOS from scratch
100% fresh codebase — no legacy code carried over. Built against
the Android beacon app as the behavioral spec.

Architecture:
- App: SwiftUI @main, AppState-driven navigation, Keychain storage
- Views: LoginView (OTP + biometric), BusinessListView, ScanView (provisioning hub)
- Models: Business, ServicePoint, BeaconConfig, BeaconType, DiscoveredBeacon
- Services: APIClient (actor, async/await), BLEManager (CoreBluetooth scanner)
- Provisioners: KBeacon, DXSmart (2-step auth + flashing), BlueCharm
- Utils: UUIDFormatting, BeaconBanList, BeaconShardPool (64 shards)

Matches Android feature parity:
- 4-screen flow: Login → Business Select → Scan/Provision
- 3 beacon types with correct GATT protocols and timeouts
- Namespace allocation via beacon-sharding API
- Smart service point naming (Table N auto-increment)
- DXSmart special flow (connect → flash → user confirms → write)
- Biometric auth, dev/prod build configs, DEV banner overlay

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 17:13:36 +00:00