VW TP 2.0 and KWP2000¶
Volkswagen-group modules (VW, Audi, Seat, Škoda) of roughly 2000 to 2011 are diagnosed with KWP2000 (Keyword Protocol 2000, ISO 14230-3) over VW TP 2.0, a VW transport protocol on CAN — not over ISO-TP, so the UDS view cannot reach them. CANExplorer provides:
- the VW TP 2.0 page of a connection: a channel to a module, the module scan, measuring blocks read once or live, coding edited field by field, security access and raw requests;
- a TP 2.0 transport (
can_explorer.core.tp20) and a KWP2000 client (can_explorer.core.kwp2000_client) over TP 2.0, ISO-TP or a K-Line bus, for scripts; - label files you supply for module names, measuring-block scaling and coding layouts;
- a VW TP 2.0 trace decoder, and MCP tools for AI agents.
Vehicles you own or are authorised to work on
Reading measuring blocks and identification only reads (after switching to a diagnostic session, which ends when the channel closes or times out), but a routine, a write or a reset changes the module — and a module's coding is the vehicle's configuration. Know what a request does before you send it, and keep the backup of every coding you change.
How TP 2.0 works¶
A module is addressed by its logical address (0x01 is the engine). The tester opens a channel to it, and all further traffic travels on the two identifiers the module assigns:
| Step | Frames (from the example below) | |
|---|---|---|
| Channel setup | 200: 01 C0 00 10 00 03 01 → 201: 00 D0 00 03 40 07 01 |
The tester asks module 0x01 to transmit on 0x300; the module answers on 0x200 + 0x01 and tells the tester to transmit on 0x740 |
| Parameters | 740: A0 0F 8A FF 32 FF → 300: A1 0F 8A FF 4A FF |
Block size (packets before an ACK), T1 (wait for an ACK), T3 (interval between packets) |
| Data | 740: 10 00 02 10 89 → 300: B1 |
Packet opcode and sequence number, then — in a message's first packet — its two-byte length; the receiver ACKs with the next sequence number |
| Keep-alive | A3 → A1 … |
A channel test, answered with the parameters |
| Disconnect | A8 → A8 |
Either end closes the channel |
The VW TP 2.0 page¶
Each CAN connection that can send has a VW TP 2.0 page. Enter the module's logical address and the session
(89 by default, as on VW-group modules; empty for none) and Open channel. While the channel is open, TP 2.0
channel tests keep it open and a TesterPresent after two seconds without a request keeps the diagnostic session
open. Load labels… loads a label file for names, scaling and coding layouts. The tabs:
| Tab | |
|---|---|
| Modules | The module scan. Click a module found to put its address in the channel bar |
| Measuring blocks | Read a group, or Live to read it twice a second. Each value shows its name and scaled value from the label file, or its raw formula byte, a and b |
| Coding | Read a coding record — one of the label file's for this module, or any local identifier as raw bytes — edit its fields or bytes, and Write… it. See coding |
| Requests | Security access with a key file (compute_key(level, seed)) or a keystore:<entry> of the security manager, raw KWP2000 requests, and the history of both |
Scanning for modules¶
The scan sends a channel setup to each logical address in turn (01-FF by default; ranges and lists such as
01-0F, 17, 56 work too) and waits 0.1 s for an answer, so a full scan takes about half a minute. A module that
answers gets its channel parameters exchanged and, if you enter an Identification option, a
StartDiagnosticSession and a ReadECUIdentification with that option; then the channel is closed again. Nothing
else is sent. The scan needs the channel closed, as it opens channels of its own.
Which identification option holds what, and which logical address is which module, are the manufacturer's: none is assumed, and names come from the label file. A module that refuses the channel is listed with its refusal.
From a script, scan_modules(session, addresses) (can_explorer.core.tp20_scan) yields a ModuleScanResult for
each address; parse_addresses('01-FF') turns the text into addresses. For UDS-era vehicles, which do not use
TP 2.0, use the UDS discovery instead.
Measuring blocks¶
A measuring block (group) is ReadDataByLocalIdentifier with the group number. Its answer is 61, the group, then
one three-byte value after another — a formula byte and two data bytes, a and b:
21 01 → 61 01 | 01 00 00 | 27 00 00 | 22 00 80 | 1A 32 4B | 25 02 7A | 25 00 00 | 25 00 00 | 25 00 00
read_measuring_block(kwp, group, table=None) returns a MeasuringBlock with its values (formula, a, b,
and with a table name, value, unit); describe() and as_dict() format it. An answer whose length is not a
whole number of values keeps the bytes after the last whole value in rest (shown as unparsed) instead of forcing
them into values.
How a formula byte turns a and b into a value is VW's own, undocumented, and the community tables disagree between
sources and module generations — so CANExplorer has no built-in formulas. They come from the formulas of a
label file. A value whose formula byte is not there is shown raw (formula 0x27, a=0, b=0); an
expression that fails reports its error on that value only.
Label files¶
A label file is a JSON file you write — your transcription of the source you trust — with what CANExplorer does not build in: module names, measuring-block formulas and value names, and coding records.
{
"formulas": {
"0x01": {"expression": "a * b / 5", "unit": "/min"},
"0x05": "a * (b - 100) / 10"
},
"modules": {
"01": {
"name": "Engine",
"formulas": {"0x10": "a + b"},
"groups": {"1": ["Engine speed", "Coolant temperature"]},
"coding": {
"Coding": {
"protocol": "kwp",
"identifier": "0x9A",
"length": 3,
"fields": [
{"name": "Option A", "byte": 0, "bit": 0, "values": {"0": "off", "1": "on"}},
{"name": "Variant", "byte": 1, "bit": 4, "width": 4, "description": "Shown as a tooltip"},
{"name": "Region", "byte": 2}
]
}
}
}
}
}
All values in this example are illustrative — the formulas, the identifier and the fields are not VW's.
formulas— formula byte (hex:"0x01"or"01") → anexpressionoveraandbwith an optionalunit, or the expression alone as a string. Expressions are evaluated safely, like an A2L formula: arithmetic, comparisons,x if c else y,piand the math functions, nothing else. Top-level formulas apply to every module; a module's own override them.modules— by logical address in hex ("01","0x17"): aname, its ownformulas, itsgroups(group number, decimal as testers number them, → the names of its values in order) and itscodingrecords.coding— named records, see coding.
A file with only formulas and groups (no modules) is a label file too. Ross-Tech's label files are not read.
Coding¶
A coding record is a block of bytes a module keeps at a diagnostic identifier:
protocol |
Read / written with | identifier |
|---|---|---|
kwp (default) |
KWP2000 ReadDataByLocalIdentifier (0x21) / WriteDataByLocalIdentifier (0x3B) | Local identifier, 00–FF |
uds |
UDS ReadDataByIdentifier (0x22) / WriteDataByIdentifier (0x2E) | Data identifier, 0000–FFFF |
Where a module keeps its coding and what its bits mean are the manufacturer's and are not built in: the
label file says so. length (optional) is checked before a write. A field is a whole byte (0-based), or width
bits (default 1) from bit (0 = least significant) of one byte, with optional names for its values and a
description. Without fields — or for a local identifier entered on the page — the record is edited as raw bytes.
Writing is careful: CANExplorer reads the record again just before writing and refuses when it changed since you read it, refuses another length, writes, reads it back and tells you whether the module kept it. The record as it was before the write is shown as the backup — copy it before you go on. Many modules need a particular session or security access before they accept coding; do that first (the session field and the Requests tab).
The page edits KWP2000 records over its TP 2.0 channel; UDS records are read and written with the MCP tools or a
script (can_explorer.core.coding: CodingRecord.read, write_record).
Talking to a module¶
import asyncio
from can_explorer.core.diagnostic_labels import LabelFile
from can_explorer.core.kwp2000_client import KwpClient, KwpKeepAlive
from can_explorer.core.measuring_blocks import read_measuring_block
from can_explorer.core.session import BusSession
from can_explorer.core.sources import BusConfig, LiveSource
from can_explorer.core.tp20 import Tp20Client
async def main():
labels = LabelFile.load('labels.json')
session = BusSession(LiveSource(BusConfig('socketcan', 'can0', bitrate=500_000)))
session.start()
try:
async with Tp20Client(session, module=0x01) as channel: # The engine
kwp = KwpClient(channel)
await kwp.start_diagnostic_session(0x89)
keep_alive = KwpKeepAlive(kwp) # TesterPresent while idle
keep_alive.start()
block = await read_measuring_block(kwp, 1, labels.formula_table(0x01))
print(block.describe())
keep_alive.stop()
finally:
session.stop()
asyncio.run(main())
Tp20Client options:
| Option | Default | |
|---|---|---|
module |
— | The module's logical address, 0x00–0xFF |
rx_id |
0x300 |
The identifier the module is asked to transmit on |
parameters |
block size 15, T1 100 ms, T3 5 ms | ChannelParameters sent to the module. When sending, the smaller of the two ends' block sizes and the longer T3 are used |
timeout |
1 s | The wait for an ACK or a response (and for the setup answer, unless setup_timeout is given) |
setup_timeout |
timeout |
The wait for the channel setup answer alone (the scan uses 0.1 s) |
keep_alive |
1 s | Silence after which a channel test is sent (0: never) |
open() raises Tp20NoAnswer when nothing answers the setup and Tp20Refused when the module refuses it.
KwpClient takes any transport with send(payload) and receive(timeout) coroutines, so the same calls work on
other links:
- ISO-TP:
KwpClient(IsoTpClient(session, 0x7E0, 0x7E8))(can_explorer.core.isotp_client). - K-Line: on an
elm327_klineconnection,KwpClient(KLineTransport(session, target=0x01)): the request goes totargetfrom the tester address 0xF1 (source), with the ISO 14230-2 format byte (physical, orfunctional=True) and the length; at most 63 bytes a request.
KWP2000 services¶
| Method | Service | Returns |
|---|---|---|
start_diagnostic_session(session, baud_rate=None) |
0x10 StartDiagnosticSession, e.g. 0x89 on VW-group modules |
The bytes after the echoed session |
stop_diagnostic_session() |
0x20 | — |
ecu_reset(mode=0x01) |
0x11 ECUReset | — |
tester_present() |
0x3E TesterPresent | — |
read_ecu_identification(option) |
0x1A ReadECUIdentification | The data after the echoed option |
security_access(level, compute_key) |
0x27 SecurityAccess: seed of an odd level, then compute_key(level, seed) as level + 1 |
False if the level was already unlocked (zero seed) |
read_local_identifier(identifier) |
0x21 ReadDataByLocalIdentifier | The data after the echoed identifier |
write_local_identifier(identifier, data) |
0x3B WriteDataByLocalIdentifier | — |
start_routine / stop_routine / routine_results |
0x31 / 0x32 / 0x33, by local identifier | The bytes after the echoed identifier |
request(payload) |
Any request | A KwpResult (response, description, error); never raises |
Every method skips "response pending" (0x78) answers and raises KwpNegativeResponse (with service and code)
for a negative response; call(payload) is the raw form that raises. Answers that do not match the request —
stale traffic on a shared identifier — are skipped and passed to the unsolicited callbacks. One request runs at a
time, so a KwpKeepAlive (TesterPresent after interval seconds, 2 by default, without a request) can run beside
your own requests.
KWP2000 is not UDS with other names: UDS reads bit 7 of a sub-function byte as "suppress the positive response", but KWP2000 session and routine identifiers use the whole byte (the VW session 0x89 has bit 7 set). That is why this is a client of its own rather than the UDS client.
security_access contains no seed/key algorithm: compute_key is your function, e.g. a key script from the
security manager.
Trouble codes are raw requests
The trouble-code services — 0x18 ReadDTCByStatus, 0x17 ReadStatusOfDTC, 0x14 ClearDiagnosticInformation — have
no structured method: their request and response layouts are in the paywalled ISO 14230-3 and could not be
confirmed from an open source, so CANExplorer does not guess them. Send them with request() (the Requests
tab, or the MCP kwp_request tool) using the bytes your module's documentation gives.
Trace decoding¶
Choose the VW TP 2.0 protocol for the connection (protocol decoding). The decoder learns the channel's identifiers from the module's setup response, so start the capture before the tester opens the channel:
200 TP2.0 channel setup request to module 0x01: listen on any, transmit on 0x300, application 0x01
201 TP2.0 channel setup accepted (to 0x00): listen on 0x300, transmit on 0x740, application 0x01
740 TP2.0 tester to 0x01 parameters request: block size 15, T1 100 ms, T3 5 ms
740 TP2.0 tester to 0x01 data #0 (last, ACK requested), 2 B message | KWP StartDiagnosticSession 89
300 TP2.0 0x01 to tester ACK, ready, next sequence 1
300 TP2.0 0x01 to tester data #1 (more follow), 26 B message
300 TP2.0 0x01 to tester data #4 (last, ACK requested) | KWP Positive response to ReadDataByLocalIdentifier: 01 01 00 …
740 TP2.0 tester to 0x01 disconnect
A gap in the sequence numbers drops the message being reassembled (sequence gap).
MCP tools¶
| Tier | Tools |
|---|---|
| Diagnostics | kwp_scan_modules (addresses, identification, labels), kwp_read_measuring_block (group, module, formulas — a formula table or label file), kwp_read_identification (option, module), coding_read (module, record, labels) |
| Control | kwp_request (any raw request), coding_write (changes by field name, or the whole record as data) |
The KWP2000 tools open a TP 2.0 channel to module and close it afterwards (transport="isotp" uses
request/response instead); the measuring-block and identification tools first send StartDiagnosticSession 0x89
(session="" skips it), the coding tools only the session you give. A coding record is named from a label file
(labels, record), or given raw as "kwp:9A" or "uds:0600"; UDS records go over ISO-TP. key and level
unlock security access before reading or writing. coding_write returns the record before the write — the
backup — and whether the read-back verified it. See the tool reference.
Sources and limits¶
TP 2.0 has no public specification. The transport follows the community description at jazdw.net/tp20, worked out by its author from logged traffic, and the unit tests replay its example exchange — including its measuring-block answer. Some points that page states only through its example frames are inferred from them:
- the two bytes of a channel identifier (low byte, then a validity nibble and the high bits);
- the timing bytes (a unit in the top two bits — 0.1 ms, 1 ms, 10 ms, 100 ms — times a six-bit scale);
- an ACK carries the next expected sequence number;
- the block size counts the packets before an ACK (the example sends 0x0F and calls it 16; the smaller reading is used, which is safe either way).
Not covered:
- a refused channel setup (0xD6–0xD8) is reported without a reason, and broadcast frames (0x23/0x24) are only labelled — the source documents neither;
- the source gives no keep-alive interval (1 s here, configurable) and no retransmission rule: a missing ACK fails the send, a lost packet drops the message being received;
- the trouble-code services are raw requests (see above);
- no manufacturer data is built in — module names, formulas, coding locations and layouts all come from your label file; coding fields are within one byte (a value across bytes is edited as bytes), and VW's adaptation channels and login are not modelled as such (a record at a known identifier, or raw requests, reach them).
This support has been checked against the source's example exchange and simulated modules, not yet against a real vehicle. Please report what your modules do differently.