@vowifi-rs/vowifi 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +462 -27
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,47 +1,482 @@
1
1
  # @vowifi-rs/vowifi
2
2
 
3
- Node.js binding for the hardware-independent `vowifi-client` facade.
3
+ Hardware-independent VoWiFi SMS sessions for Node.js.
4
+
5
+ `@vowifi-rs/vowifi` connects a SIM subscription to its operator's ePDG, establishes an
6
+ IKEv2/EAP-AKA/IPsec tunnel, registers with IMS, and sends or receives SMS over Wi-Fi. The package
7
+ exposes a small session API and delegates only SIM authentication to the host application.
8
+
9
+ > **Project status:** experimental. Mobile-originated and mobile-terminated SMS have completed an
10
+ > end-to-end commercial-network verification. Interoperability still depends on the operator,
11
+ > subscription, provisioning, ePDG availability, and carrier profile.
12
+
13
+ ## Implementation Status
14
+
15
+ ### Implemented
16
+
17
+ **Carrier and network setup**
18
+
19
+ - Deterministic built-in carrier-profile selection from home MCC/MNC and optional IMSI, SPN, GID,
20
+ and ICCID matchers.
21
+ - Application-provided carrier profiles and explicit ePDG hostname overrides.
22
+ - Standard 3GPP ePDG FQDN discovery from the home PLMN.
23
+ - Direct UDP egress with optional local-address binding.
24
+ - SOCKS5 UDP egress with optional username/password authentication. A local Clash/Mihomo SOCKS
25
+ listener can bridge this to VLESS, AnyTLS, or another upstream protocol.
26
+
27
+ **IKEv2 and IPsec**
28
+
29
+ - IKE_SA_INIT, NAT detection, UDP/4500 NAT traversal, and retransmission handling.
30
+ - RFC 5998 EAP-only authentication with EAP-AKA and UICC synchronization-failure handling.
31
+ - Child SA negotiation and configuration-payload processing for tunnel address, DNS, and P-CSCF.
32
+ - Userspace ESP encryption/decryption, integrity verification, sequence handling, and anti-replay
33
+ protection.
34
+ - Userspace raw-IP data plane with DNS, ICMP, UDP, TCP, and inbound IP fragment reassembly.
35
+ - IKE INFORMATIONAL, DPD, peer/local Delete handling, and bounded session shutdown.
36
+
37
+ **IMS and SMS**
38
+
39
+ - IMS registration with IMS AKA and `ipsec-3gpp` security agreement.
40
+ - SIP over TCP and UDP as selected by the carrier profile.
41
+ - Registration refresh, explicit deregistration, `Retry-After` handling, and bounded recovery.
42
+ - Mobile-originated SMS with SIP transaction tracking and RP acknowledgement correlation.
43
+ - Mobile-terminated SMS with SIP 200, RP-ACK, retransmission deduplication, and delayed application
44
+ delivery until protocol acknowledgement is complete.
45
+ - GSM 7-bit and UCS-2 text encoding/decoding.
46
+ - Automatic outgoing multipart segmentation.
47
+ - Incoming 8-bit and 16-bit concatenated SMS reassembly, including duplicate and out-of-order
48
+ segment handling.
49
+ - Text and binary incoming SMS events.
50
+ - International numbers, national numbers, and operator short codes.
51
+
52
+ **Node.js API**
53
+
54
+ - Hardware-independent async AKA callback; the addon does not own a modem or serial port.
55
+ - Pull-based event delivery backed by a bounded queue.
56
+ - Structured session states and stable JavaScript error codes.
57
+ - Built-in carrier-profile inspection through `resolveCarrierProfile()`.
58
+ - Optional Rust `tracing` subscriber through `initLogging()`.
59
+ - TypeScript declarations and platform-specific prebuilt native packages.
60
+
61
+ ### Implemented but awaiting broader real-network validation
62
+
63
+ - Automatic IMS registration refresh across a full operator-issued registration lifetime.
64
+ - Recovery from transport, IKE, and IMS failures under real network outages and address changes.
65
+ - Long outgoing and incoming SMS against a real operator; multipart behavior currently has protocol
66
+ fixtures and local tests but no stable carrier regression source.
67
+ - RP-ACK/RP-ERROR terminal-result differences across operators. The verified deployment accepts MO
68
+ SMS at the SIP layer and returns the requested service response, but this does not cover every
69
+ operator's RP behavior.
70
+ - IPv6-only ePDG, Child SA, and IMS deployments. Current built-in profiles use IPv4.
71
+
72
+ ### Not implemented
73
+
74
+ - Emergency calling, supplementary services, USSD, MMS, RCS, or video calling.
75
+ - VoLTE or access through a cellular packet core; this package targets untrusted Wi-Fi access via
76
+ ePDG.
77
+ - EAP-AKA' and operator deployments that require it.
78
+ - Production-ready certificate-authenticated ePDG profiles, carrier trust-root distribution, OCSP,
79
+ and revocation caching. The currently verified path uses RFC 5998 EAP-only authentication.
80
+ - Full long-lived IKE/Child-SA rekey and every optional IPsec cipher suite, transform, or ESN mode.
81
+ - Automatic modem discovery, serial-port management, SIM identity reads, UICC APDU transport, or
82
+ SMSC discovery. These remain host responsibilities.
83
+ - Persistent SMS storage, offline queues, scheduled sending, cross-process deduplication, HTTP APIs,
84
+ authentication, or a user interface.
85
+ - Remote carrier-profile updates or a comprehensive carrier configuration database.
86
+ - Native binaries outside the platforms listed below.
87
+
88
+ ### Planned or possible future work
89
+
90
+ - MMTel voice calling, SIP call control, RTP/RTCP media, and host-provided audio-device bridging.
91
+ - Additional carrier profiles and real-network interoperability coverage.
92
+ - EAP-AKA', certificate-authenticated ePDG deployments, and broader IPsec transform support as
93
+ required by verified carrier configurations.
94
+ - Additional native platforms and higher-level integrations.
95
+
96
+ Voice is not part of the current API, but it is a potential extension of the existing ePDG, IPsec,
97
+ IMS registration, and session-lifecycle foundation rather than a permanently excluded feature.
98
+
99
+ ## Interoperability
100
+
101
+ The complete SMS path has been verified with a real UICC and a commercial Wi-Fi Calling network:
102
+ ePDG discovery, IKEv2/NAT-T, EAP-AKA, Child SA, P-CSCF communication, protected IMS registration,
103
+ MO SMS, MT SMS, protocol acknowledgements, recovery injection, and explicit deregistration.
104
+
105
+ This is evidence for one tested configuration, not a compatibility claim for every carrier, plan,
106
+ SIM generation, or roaming location. Carrier-specific test details are intentionally maintained
107
+ separately from the npm package overview.
108
+
109
+ ## Requirements
110
+
111
+ - Node.js 20 or newer.
112
+ - A SIM/eSIM subscription provisioned by its operator for Wi-Fi Calling.
113
+ - Access to the subscription identity: at minimum IMSI and home MCC/MNC.
114
+ - A host implementation capable of passing `RAND` and `AUTN` to the UICC and returning the AKA
115
+ result.
116
+ - Network access to the operator's ePDG. Some operators restrict access by source network or
117
+ geography.
118
+
119
+ Prebuilt packages are currently published for:
120
+
121
+ | Platform | Architecture | Runtime |
122
+ | --- | --- | --- |
123
+ | Windows | x64 | MSVC |
124
+ | Linux | x64 | glibc |
125
+ | Linux | arm64 | glibc |
126
+
127
+ Alpine/musl, macOS, Windows ARM64, and other targets are not currently published.
128
+
129
+ ## Installation
130
+
131
+ ```bash
132
+ npm install @vowifi-rs/vowifi
133
+ ```
134
+
135
+ ```bash
136
+ pnpm add @vowifi-rs/vowifi
137
+ ```
138
+
139
+ The root package selects and installs the matching native package through npm optional
140
+ dependencies. A Rust toolchain is not required for supported prebuilt targets.
141
+
142
+ ## Quick Start
4
143
 
5
144
  ```js
6
- const { VowifiSession } = require('@vowifi-rs/vowifi')
145
+ const { VowifiSession, initLogging } = require('@vowifi-rs/vowifi')
146
+
147
+ initLogging(process.env.VOWIFI_LOG)
7
148
 
8
149
  const session = await VowifiSession.connect({
9
- subscription: { imsi, mcc, mnc, imei, imeisv },
10
- aka: async ({ rand, autn }) => device.authenticateAka(rand, autn),
150
+ subscription: {
151
+ imsi: '00101...',
152
+ mcc: '001',
153
+ mnc: '01',
154
+ imei: '...',
155
+ imeisv: '...',
156
+ },
157
+
158
+ // Forward the challenge to your modem, smart-card reader, Android UICC API,
159
+ // or another trusted hardware adapter.
160
+ aka: async ({ rand, autn }) => {
161
+ return uicc.authenticateAka(rand, autn)
162
+ },
11
163
  })
12
164
 
13
- const result = await session.sendSms({ recipient: '777', text: 'BAL', smsc })
14
- const event = await session.nextEvent()
15
- await session.shutdown()
165
+ try {
166
+ console.log('online using carrier profile:', session.carrierProfileId)
167
+
168
+ const result = await session.sendSms({
169
+ recipient: '+1555...',
170
+ text: 'Hello over VoWiFi',
171
+ // smsc: '+15550000000', // Optional RP destination address.
172
+ })
173
+
174
+ console.log('send result:', result)
175
+
176
+ for (;;) {
177
+ const event = await session.nextEvent()
178
+ if (!event) break
179
+
180
+ if (event.kind === 'incomingSms') {
181
+ const { sender, content } = event.message
182
+ if (content.kind === 'text') {
183
+ console.log(`SMS from ${sender}: ${content.text}`)
184
+ }
185
+ }
186
+ }
187
+ } finally {
188
+ await session.shutdown()
189
+ }
16
190
  ```
17
191
 
18
- The package does not scan serial ports or own a modem. The host supplies subscription identity and
19
- one asynchronous AKA callback. `examples/serial-uicc-aka.js` demonstrates a development adapter
20
- using the `serialport` dev dependency; it is not part of the production API.
192
+ `VowifiSession.connect()` resolves only after IMS registration succeeds. Call `shutdown()` during
193
+ normal application shutdown so the library can deregister IMS and release network resources.
21
194
 
22
- Run the local checks with:
195
+ ## Supplying AKA Authentication
23
196
 
24
- ```powershell
25
- pnpm install
26
- pnpm run build
27
- pnpm test
197
+ The package deliberately does not depend on a serial-port library or own a modem. The host supplies
198
+ one asynchronous AKA callback:
199
+
200
+ ```ts
201
+ interface AkaRequest {
202
+ rand: Buffer
203
+ autn: Buffer
204
+ }
205
+
206
+ type AkaResult =
207
+ | { kind: 'success'; res: Buffer; ck: Buffer; ik: Buffer; kc?: Buffer }
208
+ | { kind: 'synchronizationFailure'; auts: Buffer }
209
+ | { kind: 'rejected'; sw1: number; sw2: number }
28
210
  ```
29
211
 
30
- `examples/one-nz-balance.js` is an opt-in real-network regression. It reads its identity and port
31
- from `VOWIFI_*` environment variables, sends `BAL` to One NZ short code `777`, waits for the reply,
32
- and performs an explicit IMS deregistration.
212
+ The callback should perform a 3GPP USIM authentication operation and return:
213
+
214
+ - `success` when the UICC returns `RES`, `CK`, and `IK`.
215
+ - `synchronizationFailure` when the UICC returns `AUTS` for sequence-number resynchronization.
216
+ - `rejected` when the UICC rejects the command with status words.
217
+
218
+ Transport failures should reject the Promise with an `Error`. Calls may occur during initial tunnel
219
+ authentication, IMS authentication, or session recovery, so the adapter must remain available for
220
+ the full session lifetime and serialize access if the underlying UICC transport requires it.
221
+
222
+ The repository contains a development-only serial implementation in
223
+ [`examples/serial-uicc-aka.js`](examples/serial-uicc-aka.js). It uses `serialport` and AT/APDU
224
+ commands as an example; it is not required by or bundled into the production API.
225
+
226
+ ## Subscription Identity
227
+
228
+ ```ts
229
+ interface SubscriptionIdentity {
230
+ imsi: string
231
+ mcc: string
232
+ mnc: string
233
+ imei?: string
234
+ imeisv?: string
235
+ spn?: string
236
+ gid1?: string
237
+ gid2?: string
238
+ iccid?: string
239
+ }
240
+ ```
241
+
242
+ `imsi`, `mcc`, and `mnc` are required. MCC/MNC must describe the **home subscription**, not the
243
+ currently visited cellular network. Optional SPN, GID, ICCID, and IMSI-prefix data can disambiguate
244
+ MVNO or carrier-specific profiles. IMEI/IMEISV may be used in IMS identity headers where required.
245
+
246
+ Create a new session after changing the physical SIM or active eSIM profile.
247
+
248
+ ## Carrier Profiles
249
+
250
+ By default, the package selects a built-in profile from the subscription identity:
251
+
252
+ ```js
253
+ const session = await VowifiSession.connect({
254
+ subscription,
255
+ carrierProfile: 'auto',
256
+ aka,
257
+ })
258
+ ```
259
+
260
+ The registry includes a generic 3GPP fallback and carrier-specific profiles. Automatic matching
261
+ uses deterministic priority and specificity rules. Unknown operators fall back to the conservative
262
+ generic profile, which does not guarantee interoperability.
263
+
264
+ Inspect the selected profile before connecting:
265
+
266
+ ```js
267
+ const { resolveCarrierProfile } = require('@vowifi-rs/vowifi')
268
+
269
+ const resolved = resolveCarrierProfile({
270
+ subscription,
271
+ carrierProfile: 'auto',
272
+ })
273
+
274
+ console.log(resolved.profile.id)
275
+ console.log(resolved.source) // builtin, override, custom, or fallback
276
+ console.log(resolved.matchedBy) // fields responsible for the match
277
+ ```
33
278
 
34
- ## Release
279
+ Applications may select a profile by ID or pass versioned profile objects through
280
+ `carrierOverrides`. Carrier profiles describe protocol policy, not subscriber secrets or live
281
+ session state.
35
282
 
36
- Releases are published by GitHub Actions from tags matching `v*.*.*`. Update
37
- the version in `package.json`, push the commit, then push the matching tag:
283
+ ## ePDG Discovery and Network Egress
284
+
285
+ The library normally derives standard 3GPP ePDG hostnames from the home MCC/MNC. Override discovery
286
+ when testing or when an operator publishes a non-standard hostname:
287
+
288
+ ```js
289
+ const session = await VowifiSession.connect({
290
+ subscription,
291
+ explicitEpdgHostnames: ['epdg.example.operator'],
292
+ aka,
293
+ })
294
+ ```
295
+
296
+ Direct egress is the default. A local source address can be selected when the host already has the
297
+ required routing configuration:
298
+
299
+ ```js
300
+ egress: {
301
+ kind: 'direct',
302
+ localAddress: '192.0.2.10',
303
+ }
304
+ ```
305
+
306
+ SOCKS5 egress is useful when the operator's ePDG must be reached through a specific network exit.
307
+ It can point to a local Clash/Mihomo SOCKS listener even when the upstream proxy uses VLESS,
308
+ AnyTLS, or another protocol:
309
+
310
+ ```js
311
+ egress: {
312
+ kind: 'socks5',
313
+ proxy: '127.0.0.1:7891',
314
+ username: 'optional',
315
+ password: 'optional',
316
+ }
317
+ ```
318
+
319
+ The proxy must support the SOCKS5 UDP association needed by IKE/IPsec traffic.
320
+
321
+ ## Receiving Events
322
+
323
+ `nextEvent()` waits for the next event and returns `null` after the event stream closes:
324
+
325
+ ```ts
326
+ type VowifiEvent =
327
+ | { kind: 'registered'; expiresSeconds: number }
328
+ | { kind: 'refreshed'; expiresSeconds: number; securityReplaced: boolean }
329
+ | { kind: 'deregistered' }
330
+ | { kind: 'incomingSms'; message: SmsMessage }
331
+ ```
332
+
333
+ Incoming SMS messages contain the sender, PID, DCS, the raw service-centre timestamp, and either
334
+ decoded text or binary content:
335
+
336
+ ```ts
337
+ interface SmsMessage {
338
+ sender: string
339
+ protocolIdentifier: number
340
+ dataCodingScheme: number
341
+ serviceCentreTimestamp: Buffer
342
+ content:
343
+ | { kind: 'text'; text: string }
344
+ | { kind: 'binary'; data: Buffer }
345
+ }
346
+ ```
347
+
348
+ Multipart incoming messages are reassembled before `incomingSms` is emitted. Consume events
349
+ continuously while the session is online so application processing does not fill the bounded event
350
+ queue.
351
+
352
+ ## Sending SMS
353
+
354
+ ```js
355
+ const result = await session.sendSms({
356
+ recipient: '12345',
357
+ text: 'STATUS',
358
+ smsc: '+1234567890', // Optional; operator dependent.
359
+ })
360
+ ```
361
+
362
+ International numbers, national numbers, and operator short codes are accepted. Long text is split
363
+ into multipart SMS automatically.
364
+
365
+ The result distinguishes network-layer acceptance from an RP-level confirmation:
366
+
367
+ ```ts
368
+ type SmsSendResult =
369
+ | { kind: 'rpConfirmed'; parts: number; statuses: [] }
370
+ | { kind: 'sipAcceptedUnconfirmed'; parts: number; statuses: number[] }
371
+ ```
372
+
373
+ `rpConfirmed` means all parts received the expected RP acknowledgement. `sipAcceptedUnconfirmed`
374
+ means SIP accepted the message but no matching RP confirmation was observed; inspect `statuses` and
375
+ apply application-specific delivery semantics.
376
+
377
+ ## Session State and Recovery
378
+
379
+ ```js
380
+ const state = session.status()
381
+ ```
382
+
383
+ Possible states are `stopped`, `connecting`, `online`, `recovering`, `stopping`, and `failed`.
384
+ Failures may include a diagnostic `message`.
385
+
386
+ The session automatically refreshes IMS registration and can recover from transient transport or
387
+ protocol failures. Timing and recovery behavior can be tuned with `operational`:
388
+
389
+ ```js
390
+ operational: {
391
+ ioTimeoutMs: 10_000,
392
+ ikeInitialTimeoutMs: 1_000,
393
+ ikeAttempts: 3,
394
+ registrationTimeoutMs: 120_000,
395
+ refreshAtPercent: 80,
396
+ recoveryAttempts: 3,
397
+ recoveryInitialDelayMs: 1_000,
398
+ recoveryMaxDelayMs: 30_000,
399
+ }
400
+ ```
401
+
402
+ Most applications should keep the defaults. Use overrides primarily for diagnostics or known
403
+ operator behavior.
404
+
405
+ ## Logging
406
+
407
+ Logging is opt-in and backed by Rust `tracing`:
408
+
409
+ ```js
410
+ const installed = initLogging(
411
+ 'vowifi_client=debug,vowifi_runtime=info,vowifi_transport=info,vowifi_ipsec=warn,vowifi_ims=info',
412
+ )
413
+ ```
414
+
415
+ If no argument is provided, `VOWIFI_LOG` is used, followed by the package default filter. The
416
+ function returns `true` when it installs the global subscriber and `false` when another subscriber
417
+ is already installed. Call it once, before connecting.
418
+
419
+ Do not enable verbose protocol logs in production without reviewing their contents. Authentication
420
+ material and subscriber identifiers require the same handling as other credentials.
421
+
422
+ ## Errors
423
+
424
+ Rejected operations throw JavaScript `Error` objects with a stable `code` property:
425
+
426
+ ```js
427
+ try {
428
+ await session.sendSms({ recipient, text })
429
+ } catch (error) {
430
+ if (error.code === 'SESSION_OFFLINE') {
431
+ // Decide whether to wait for recovery or report the failure.
432
+ }
433
+ throw error
434
+ }
435
+ ```
436
+
437
+ Current error codes:
438
+
439
+ - `INVALID_CONFIG`
440
+ - `CARRIER_PROFILE_NOT_FOUND`
441
+ - `EPDG_DISCOVERY_FAILED`
442
+ - `AKA_FAILED`
443
+ - `SESSION_OFFLINE`
444
+ - `IMS_REGISTRATION_FAILED`
445
+ - `SMS_SEND_FAILED`
446
+ - `SHUTDOWN_FAILED`
447
+
448
+ Use `code` for program flow. Error messages are diagnostic text and may change between releases.
449
+
450
+ ## API Summary
451
+
452
+ ```ts
453
+ class VowifiSession {
454
+ static connect(options: ConnectOptions): Promise<VowifiSession>
455
+ readonly carrierProfileId: string
456
+ status(): SessionState
457
+ nextEvent(): Promise<VowifiEvent | null>
458
+ sendSms(message: SmsSendOptions): Promise<SmsSendResult>
459
+ shutdown(): Promise<void>
460
+ }
461
+
462
+ function resolveCarrierProfile(options: ResolveCarrierProfileOptions): ResolvedCarrierProfile
463
+ function initLogging(filter?: string): boolean
464
+ ```
465
+
466
+ See the bundled [`index.d.ts`](index.d.ts) for the complete TypeScript contract.
467
+
468
+ ## Local Development
38
469
 
39
470
  ```bash
40
- git tag v0.1.1
41
- git push origin v0.1.1
471
+ pnpm install
472
+ pnpm run build
473
+ pnpm test
42
474
  ```
43
475
 
44
- The repository secret `NPM_TOKEN` must be an npm token with publish access to
45
- the `@vowifi-rs` scope. The workflow builds the Windows x64, Linux x64, and
46
- Linux arm64 native packages, then publishes the root package and its optional
47
- platform packages.
476
+ The repository also contains opt-in real-network regression examples. They require an eligible SIM,
477
+ explicit environment configuration, and deliberate execution; they are not part of the default test
478
+ suite.
479
+
480
+ ## License
481
+
482
+ Licensed under either of Apache License 2.0 or the MIT license, at your option.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vowifi-rs/vowifi",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Hardware-independent VoWiFi SMS session for Node.js",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": {
@@ -45,8 +45,8 @@
45
45
  ]
46
46
  },
47
47
  "optionalDependencies": {
48
- "@vowifi-rs/vowifi-win32-x64-msvc": "0.1.9",
49
- "@vowifi-rs/vowifi-linux-x64-gnu": "0.1.9",
50
- "@vowifi-rs/vowifi-linux-arm64-gnu": "0.1.9"
48
+ "@vowifi-rs/vowifi-win32-x64-msvc": "0.1.11",
49
+ "@vowifi-rs/vowifi-linux-x64-gnu": "0.1.11",
50
+ "@vowifi-rs/vowifi-linux-arm64-gnu": "0.1.11"
51
51
  }
52
52
  }