Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

USB mass storage and MTP

Some dive computers do not run a download protocol at all: they show up as a USB drive (Mass Storage Class) or as a Media Transfer Protocol device, and each dive is a file. The host’s job is to find the files, decide which are new, and hand their bytes to the family parser.

In practice the operating system mounts these devices; a host application, including a browser page, then works with files. Section 1 is what a host needs in that normal case. Sections 2-4 describe the raw protocols for hosts that must drive the USB device themselves (for example an Android app without OS mounting).

1. File-level view

DeviceTransportLocation of dive filesNotes
Garmin Descent Mk1MSC (091E:0003, 091E:2B2B)GARMIN/ACTIVITY/*.FITone FIT file per activity; not every activity is a dive
Garmin Descent Mk2/Mk2i/Mk2S/Mk3/Mk3i/G1/G2/X50i, fēnix 8 and similarMTPstorage root → Garmin → Activity → *.fitsome devices show an extra top level Primary/
Divesoft Freedom (older USB access)MSCDIVELOG/*.DLFone dive per file
Genz / XDeep BlackMSCLBDATA/<one directory per dive>/SUMMARY.BIN + LOGBOOK.BINheader and profile in separate files
Suunto EON Steel familydevice file system reached through the HID/BLE protocol, not MSC0:/dives/<hex Unix seconds>.<ext>listed here because the naming carries the timestamp

Path matching SHOULD be case-insensitive (FAT is case-insensitive; devices differ in the case they report).

File names carrying timestamps. Garmin uses either long names YYYY-MM-DD-HH-MM-SS.fit or 8.3 short names ymdhMMSS.FIT where:

CharFieldEncoding
1year − 2010one base-36 digit (0-9, A-Z)
2monthbase-36 digit (1-9, A-C)
3daybase-36 digit (1-9, A-V)
4hourbase-36 digit (0-9, A-N)
5-6minutetwo decimal digits
7-8secondtwo decimal digits

Example: C4ND0302.FIT = 2022-04-23 13:03:02. Sorting by the decoded time gives the dive order; the decoded time (or the FIT file’s own timestamp) serves as the fingerprint.

Incremental download. Fingerprint-based: the host remembers the newest imported file’s timestamp (from the name or the file contents) and imports only newer files. File modification times on FAT are local time with 2 s resolution and SHOULD NOT be used.

Web notes. Use the File System Access API (showDirectoryPicker) on the mounted volume. Mass storage is a protected interface class in WebUSB and cannot be claimed. MTP devices are normally claimed by the OS; the user copies files out and picks them with a file input.

Confidence: likely.

2. USB Mass Storage, Bulk-Only Transport

Interface class 0x08, subclass 0x06 (SCSI transparent), protocol 0x50 (BOT); one bulk IN and one bulk OUT endpoint. (One source also accepts a vendor-class 0xFF interface with the same endpoints.)

Class requests on the interface:

RequestbmRequestTypebRequestData
Bulk-Only Mass Storage Reset0x210xFFnone
Get Max LUN0xA10xFE1 byte (highest LUN number)

Each command is three stages: Command Block Wrapper (OUT), optional data (IN or OUT), Command Status Wrapper (IN).

CBW (31 bytes, little-endian fields):

OffsetSizeField
04signature 55 53 42 43 (“USBC”)
44tag, echoed in the CSW
84data transfer length in bytes
121flags: 0x80 = data IN, 0x00 = data OUT / none
131LUN (bits 0-3)
141command block length (1-16)
1516SCSI command block, zero padded

CSW (13 bytes):

OffsetSizeField
04signature 55 53 42 53 (“USBS”)
44tag (must equal the CBW’s)
84data residue
121status: 0 passed, 1 failed (issue REQUEST SENSE), 2 phase error (reset recovery)

Hosts SHOULD check signature, tag and status. One source checks none of them and still works with the listed devices.

Confidence: verified (USB Mass Storage Class Bulk-Only Transport 1.0).

3. SCSI commands needed

All multi-byte SCSI fields are big-endian.

CommandOpcodeCDBData IN
TEST UNIT READY0000 00 00 00 00 00none
REQUEST SENSE0303 00 00 00 12 0018 bytes sense data
INQUIRY1212 00 00 00 24 0036 bytes
READ CAPACITY(10)2525 00 00 00 00 00 00 00 00 008 bytes: last LBA u32be, block length u32be
READ(10)2828 00 <LBA:u32be> 00 <blocks:u16be> 00blocks × block length bytes

A minimal reader needs only READ CAPACITY(10) and READ(10); one source uses only these, with one block per READ(10) and only the low 16 bits of the block length.

Worked example, READ(10) of one 512-byte block at LBA 0x800, tag 0x20304050:

H→D bulk  55 53 42 43  50 40 30 20  00 02 00 00  80  00  0A
          28 00 00 00 08 00 00 00 01 00  00 00 00 00 00 00
D→H bulk  <512 bytes>
D→H bulk  55 53 42 53  50 40 30 20  00 00 00 00  00

Confidence: verified (SCSI Block Commands, SPC).

4. FAT file system (summary)

Enough to locate files on these devices; the full rules are in the Microsoft FAT specification.

  1. Read sector 0. If it is a partition table (byte 13 of a boot sector, sectors-per-cluster, would be 0; or the 55 AA MBR signature with a partition entry), read the boot sector at the start LBA of the first partition entry (u32le at offset 0x1C6).
  2. Boot sector (BPB) fields (u16le/u32le): bytes per sector @0x0B, sectors per cluster @0x0D, reserved sectors @0x0E, number of FATs @0x10, root entries @0x11, total sectors @0x13 (16-bit) or @0x20 (32-bit), sectors per FAT @0x16 (FAT12/16) or @0x24 (FAT32), root cluster @0x2C (FAT32).
  3. FAT type from the number of data clusters: < 4085 → FAT12, < 65525 → FAT16, else FAT32.
  4. Directory entries are 32 bytes: name 8+3 @0, attributes @0x0B (0x10 directory, 0x0F long-name entry), first cluster high @0x14 (FAT32), first cluster low @0x1A, size u32le @0x1C. First name byte 0xE5 = deleted, 0x00 = end of directory.
  5. Follow cluster chains through the FAT (12-bit packed, 16-bit or 28-bit entries).

Confidence: verified (Microsoft FAT specification), as a summary.

5. MTP

MTP runs PTP containers over a still-image-class interface (class 0x06, subclass 0x01, protocol 0x01) with bulk IN, bulk OUT and interrupt IN endpoints.

Container (u32le length, u16le type, u16le code, u32le transaction id, then parameters/payload). Types: 1 command, 2 data, 3 response, 4 event.

Operations needed to fetch files:

CodeOperationParametersResult
0x1001GetDeviceInfo—device info dataset
0x1002OpenSessionsession id—
0x1003CloseSession——
0x1004GetStorageIDs—array of u32 storage ids
0x1007GetObjectHandlesstorage id, format (0 = any), parent (0xFFFFFFFF = root)array of handles
0x1008GetObjectInfohandledataset incl. format, size, parent, filename
0x1009GetObjecthandlefile bytes

Object formats of interest: 0x3001 association (folder), 0x3000 undefined (used for .fit files). Walk from the root: find the folder whose name matches the next path component (case-insensitive), list its children, and fetch every object whose name ends in .fit.

Garmin specifics: VID 0x091E; the MTP product ID is 0x4000 | <FIT product id> (examples: 0x4CBA → 3258 Descent Mk2(i); 0x51B6 → 4534 fēnix 8 43 mm). The mass-storage IDs of older devices appear to follow 0x2000 | <FIT product id> (0x2B2B → 2859 Descent Mk1); this second rule is an inference from one example. One source uses only the first storage id.

Confidence: verified for the PTP/MTP operation codes (MTP 1.1); likely for the Garmin rules.

Open questions

  • VID:PID ownership of the unidentified mass-storage IDs (040E:0568, 2544:0004, A600:E211): which belongs to Divesoft, Genz or XDeep?
  • Whether Garmin devices other than those listed expose Primary/ as an extra path level.

References

  • libdivecomputer (LGPL-2.1) and its Subsurface fork (Garmin and USB storage support), used as factual references; no code copied. https://www.libdivecomputer.org/, https://github.com/subsurface/libdc
  • USB Mass Storage Class Bulk-Only Transport 1.0, https://www.usb.org/document-library/mass-storage-bulk-only-10
  • SCSI Primary Commands and SCSI Block Commands (T10), https://www.t10.org/
  • Microsoft Extensible Firmware Initiative FAT32 File System Specification, https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc
  • USB Media Transfer Protocol 1.1, https://www.usb.org/document-library/media-transfer-protocol-v11-spec-and-mtp-v11-adopters-agreement
  • Garmin FIT SDK (product ids, file format), https://developer.garmin.com/fit/