Skip to content

BLE and session

Bench hardware only. Everything here can start or change insulin delivery. Use it only with pump hardware that is not connected to any living subject. See bench testing.

1. BLE surface

Advertising

  • Complete local name = the pump's serial (shape: eight digits + a letter, e.g. 00000000M).
  • Manufacturer company ID 0x026B plus a short status payload.
  • Advertising address is a rotating RPA. Lock by name / company ID, not by address.
  • The pump does not advertise while it is connected. On this unit it advertises after a successful button hold (about 5 seconds until the Ready Beep, cassette off for pairing), during alarms, and after a link drop; after a clean disconnect from the phone it was seen by every scan for 33 minutes.
  • A bonded phone reconnects with no scan and no button press: connect straight to the bonded address (§2.2). Measured on the bench: after a 5-minute link loss with no scan, the link came up in under half a second and the pump was armed and ready in about 8 seconds; after a 33-minute loss and after an app restart, likewise. Keep the link up while you can, and reconnect to the bond when it drops.
  • Nordic radio, BLE 5.x. Link upgrades to LE 2M, DLE, ~30 ms connection interval.
  • ATT MTU 247 is required. Without it the arm write is ignored and the pump never streams.
  • Exchange the MTU once per connection. The pump rejects a second MTU request on the same link with GATT status 4 (GATT_INVALID_PDU), and the link stays at the MTU already agreed. Android 12 and later answer a repeat request locally, so it never reaches the pump; Android 11 and earlier send it. Treat a rejected repeat request as success when the link is already at 247.
  • Pairing: LE Secure Connections, Passkey Entry, Bonding + MITM. The 6-digit PIN printed on the pump label is the BLE passkey. Encryption starts ~8 seconds after connect. After that, ATT on the air is ciphertext to a passive sniffer; a bonded peer (TwiistOff, or your own client) sees ATT in the clear because the stack already has the session keys.
  • The passkey authenticates the exchange; it is not enough for a passive sniffer to decrypt an LE SC session (Bluetooth Core Spec Vol. 3 Part H). To read post-bond ATT, be a bonded endpoint you control.
  • Also present: GAP, GATT, and Nordic Secure DFU service 0xFE59 (buttonless UUID 8ec90004-f315-4f60-9fb8-838830daea50, with-bond-sharing).

Custom GATT service

One custom 128-bit service: e5331fe0-977c-11e5-a837-0800200c9a66. Characteristic UUIDs share the form e533XXXX-977c-11e5-a837-0800200c9a66.

Suffix Properties Role (as used by TwiistOff)
e5332001 read / indicate RIS block: five u16 LE risMessagesMajor, risMessagesMinor, risEventsMajor, risEventsMinor, pumpOperatingMode (this unit: 13.76 / 14.32 / mode 1 = full app; mode 0 = bootloader). Re-indicated at a reboot and ~0.2 s before a cassette-detach status. TwiistOff reads it after every arm, warns on any firmware other than 13.76 / 14.32 (Tested firmware) and gates firmware-dependent commands on it (Command catalogue)
e5332018 write (no response) command channel — every sealed frame is written here
e533201c notify pump → app channel — sealed frames from the pump
e5332022 write / notify unused by TwiistOff; purpose ⛔ TBD
e5332023 read / write / notify session material: 16-byte salt + u32 start sequence; write 0x01 to arm. A notification here (20 bytes) mid-session means the pump has re-keyed the session (seen at every reboot): hold therapy and re-arm — see §2.1
e5332024 read session salt (16 bytes, rotates per connection)
e5332025 write / notify RPC channel. TwiistOff never writes it, but the pump pushes sealed frames here unprompted (a burst after startBasal, a stream while basal runs); contents ⛔ TBD (undecoded)
e5332026 read constant 32-byte value
e5332027 write / notify replacement / provisioning data (see below)

Replacement / provisioning data (e5332027)

The pump holds a cloud-issued replacement blob used to (re-)provision its registration material. It is not a fixed size:

info (538 B, big-endian header)
  off  0  u32  recoverVersion               = 0
  off  4  u32  recoverSigVersion            = 1
  off  8  u32  recoverCryptVersion          = 1
  off 12  u64  recoverExpirationDate_UTC    Unix seconds = issue time + exactly 180 days
  off 20  390  recoverBLOB                  opaque, pump-bound material
  off 410 128  reserved                     all zero
then a DER ECDSA P-256 signature (70-72 B) appends => total 608-610 B.
  • Write: the blob is followed by its CRC32 (IEEE, little-endian) and sent as packet-numbered writes with response, [n | up to 243 B data], n = 1, 2, 3 — 244/244/127-129 bytes for a 608-610-byte blob. After the last packet the pump sends one standalone notification FF|status: FF 00 accepted, FF 02 the transfer failed its check (a write without the CRC32 gets it), FF 01 the signature is wrong. Without the packet numbers the write fails early: its first byte 00 reads as packet 0, the readback trigger, and the pump pushes its stored blob instead. A wrong or foreign blob can de-provision the unit — bench-only, user-approved experiments only.
  • Read back: a plain GATT read is refused. With the notify CCCD on e5332027 enabled, a write-without-response to e5332027 (the readback trigger) makes the pump push [packetNum(1 B) | up to 243 B data], packets 1..N, then packet 255 with a 1-byte status (0 = success). At MTU 247 this returns the complete stored blob; at MTU 23 it is truncated.
  • The blob rotates on every cloud re-registration; the LTSS is not recoverable from it with public material. Established by bench analysis of the blob's own structure; TwiistOff implements preview/write and notification-based readback in pump/ReplacementData.kt and PumpLink, exposed as POST /pump/replacement and GET /pump/replacement/readback (REST API).

State — write format known; TwiistOff's write 🧪 not yet bench-tested. A correctly framed write is answered FF 00, and the readback afterwards returns the written blob: the pump has adopted it. The stored blob reads back byte-for-byte at MTU 247. TwiistOff sends the framed format (ReplacementData.framedChunks) and reads the pump's answer by sequence (the FF|status that ends a stored-blob push is not the ack), but its framed write has not been run on the bench pump yet; its earlier unframed writes were never adopted. Whether the pump binds its credentials to one unit is open (see Pairing and setup §9). Do not treat "write acked" as "pump provisioned" until the readback matches.

Pre-bond you can connect, exchange MTU 247, discover GATT, read the Device Name and e5332001. Enabling notify on some characteristics (notably e5332027) returns Insufficient Authentication and triggers bonding.

Bonding in TwiistOff

See Pairing and setup for the complete pairing/re-pairing procedure (including what still requires the vendor's app) and Bonding and export for the bond mechanics in detail. Summary: Connect tab → Scan → tap the serial → Bond (or Advanced → GATT explorer → Subscribe all) → enter the label PIN; then arm with the LTSS on the same page (or POST /pump/arm over the bridge). The Connect page and GET /setup share one state machine (pump/PairingFlow.kt).

2. Session setup (arming)

Order matters:

  1. Connect and request MTU 247.
  2. Enable notifications on the e533* characteristics (at least 201c, 2023, 2025, 2027, 2001).
  3. Read e5332024 → 16-byte session salt.
  4. Read e5332023 → 16-byte salt + u32 start sequence (last 4 bytes, little-endian).
  5. Write a single byte 0x01 to e5332023 (arm).
  6. The pump starts streaming sealed status frames on e533201c (about every 5 s on an armed TwiistOff link, measured 2026-12-02).

TwiistOff does this in pump/PumpLink.arm. A new BLE connection means a new salt, a new start sequence and a new numbering chain; the salt does not change just because you re-arm on an existing connection. Restart the session whenever the link drops.

Inherited-link trap (measured 2026-11-30). An app update / reinstall kills the app while the pump link is up, and the restarted process can attach to the inherited BLE link. The pump never sees a new connection, keeps serving the old session (same e5332024 salt), and an arm on that link reports the previous salt as a fresh session; when the orphaned link finally goes away the session collapses (armed:false, commands get no response). TwiistOff therefore:

  • recycles the inherited link on the first connect after the app process starts (establish, tear the client down, establish the real connection), so the pump issues fresh session material;
  • clears every piece of cached session material on connect, on a link transition, and at the start of every arm;
  • treats an arm as successful only after a pumpStatus frame sealed with the new session keys has arrived (the sealed frame is the proof the handshake worked).

A /pump/arm that cannot get such a frame fails with an explicit "arm handshake not confirmed" error instead of reporting a previous session as freshly armed. See REST API §5.6.

2.1 Re-key, reboot and re-arm

Measured on the bench 2026-12-02 (✅ Verified).

  • A pump reboot leaves the old session half-alive. After an alarmReset reboot the BLE link stays up and status frames keep decrypting under the old keys, but commands are no longer answered. (A battery change drops BLE anyway, so it always needs a fresh connect and arm.)
  • Re-arming on the existing link is enough — no disconnect: arm again with the same LTSS (new start sequence 1), and the command path works again.
  • The reboot signature on the link, in order: a 20-byte notification on e5332023 (the pump publishing new session material — treat it as a re-key and restart the counters), one or more e5332001 RIS indications, then the status frame seq restarts at 1 and resetCount (bytes 30–31) goes up by one. With a cassette attached the boot self-test then runs by itself.
  • Driver rule: on a re-key notification, or on a status-seq restart / resetCount change → re-arm on the same link → prove the command path with a read-only getLogRecord → only then send therapy commands.

An e5332023 notification mid-session means the pump re-keyed the session. Commands sealed with the old session material go unanswered from then on, so hold therapy at once and re-arm on the same link before the next command; do not wait for the status seq restart.

The arm handshake itself reads and writes e5332023, so a driver must not mistake its own arm for a re-key. TwiistOff treats a notification there as a re-key only when all of these hold (RekeyRule in pump/PumpReadiness.kt):

  • the session is armed, no arm or re-arm is running, and the command path is not already held for a re-arm;
  • at least 3 s have passed since the last arm finished;
  • the notification carries the full 20 bytes;
  • its 20 bytes differ from the session material the last arm read.

Re-arm once per restart. Re-arming several times for one restart can itself leave a session that answers no command while status keeps decrypting, so a driver must re-arm once per restart and then prove the path. Single-flight: a second restart signal (the re-key notification and the status restart are two signals of the same restart), a manual arm or a reconnect while a re-arm runs is not a second arm. Status that still decrypts says nothing about commands.

A command left unanswered means the path is not proven, whatever answered before it: hold therapy and re-arm once more on the same link. If commands still go unanswered after that one extra re-arm, stop re-arming and tell the user; a reconnect or a manual re-arm starts afresh.

TwiistOff: on a re-key notification, or on a status seq restart / resetCount change (fed before the restarted status is published), it holds therapy commands, re-arms once on the same link with the stored LTSS, reads the e5332001 version block again, sends one read-only log read, and refuses therapy commands until that read is answered (commandPath REBOOTED → REARMING → UNPROVEN_AFTER_REARM → PROVEN). Further restart signals for the same restart (same resetCount) are dropped and logged (GET /pump/observed). Any command left unanswered moves the path to UNANSWERED and triggers one extra re-arm; when that does not bring answers back the path is REARM_FAILED and the app says so. Reconnect, Re-arm with the stored key (Pump tools, the Pump restarted wizard) or POST /pump/rearm then re-arm on the existing link by hand; each waits for an automatic re-arm that is still running instead of starting a second one.

2.2 Reconnecting after the app restarts

The pump keeps running its therapy (basal, a temp basal, an alarm state) while the controlling app is closed, updated or restarted; only the link and the session end. A driver that remembers its pump can bring the session back without the user, as pure link set-up:

  1. Connect to the bonded device. After bonding, the phone's Bluetooth stack holds the pump's identity address and resolves its rotating advertising address, so a direct connect to the bonded address works. Scan only if that fails, and then accept only a pump advertising the remembered name, never the first pump in range.
  2. Wait for GATT service discovery before arming: arming reads e5332024 and e5332023 by UUID, and discovery finishes a few tens of milliseconds after the link reports connected.
  3. Arm as in §2 with the stored LTSS (one MTU request, the sealed-status proof).
  4. Observe the first pumpStatus and read readiness from it. Send nothing that changes delivery or settings; verifyTherapySettings (read-only) answers whether the pump still holds the app's settings.

Measured 2026-12-03 on Android 11, with basal running at 2.00 U/h: after an app update (adb install -r) and after a force-stop, the relaunched app connected to the bonded address, armed and read CAN DELIVER; delivering basal 2.00 U/h within about 10 s of starting, and verify answered 01. The first connect after the process starts recycles the inherited link (§2) on the way. Measured since: after a 5-minute link loss with no scan in between, the direct connect to the bonded address came up in 0.44 s and the pump was armed and ready in 8.1 s; after a 33-minute loss, in about 10 s.

TwiistOff: AutoReconnect (pump/AutoReconnect.kt) runs these steps through SetupRunner at app start-up when a pump is remembered and a key is stored, and on demand (Reconnect on Connect, POST /setup/reconnect). The pump's address and name are remembered on every successful arm. One attempt, then waits of 20 s, 60 s and 180 s, and it stops after four attempts with the reason shown. An unconfigured or unprimed pump is handed over to the cassette set-up wizard. Pairing and setup §8.3 has the user's view.

When the stored session no longer fits. Some failures are not retried, because no retry fixes them, and an app that keeps reconnecting would fight a fresh pairing:

  • Android holds no bond with the pump (check the bond state before connecting, with Bluetooth on: with Bluetooth off every device reads as unbonded), or the pump sends a pairing request on connect (pairing mode, reset, or bonded to another phone).
  • A GATT read or write fails with insufficient authentication or insufficient encryption.
  • The arm handshake gets no pumpStatus sealed with the new session keys on two consecutive attempts (the pump does not hold this LTSS). A single miss is treated as transient, since a link still serving a previous session gives the same symptom once.

Out of range, a connect timeout, slow discovery, a link drop or a late first status are transient and follow the back-off.

TwiistOff: on an invalid state the run stops with phase STOPPED_INVALID, turns the start-up reconnect off with the reason (shown in a banner with Turn back on, and as reconnect.offReason over REST), declines a pending pairing request and drops the link it made. Out-of-range failures never change the setting.