🌐

ISO-14229 UDSのまとめ

2025/01/29に公開

海洋ロボコンをやってた人です。

今回はISO-14229で国際標準規格として定義されているUDSの学習内容をアウトプットとして記載していきます。

2025/01の現状として、UDSの公開されている情報は海外勢のブログやpy-udsのドキュメントなどが多く、日本語以外が多数を占めています。
これではUDSを学ぶ参入障壁になりかねませんし、OSSでドキュメントも公開されているならもっと情報の民主化がされるべきでは?と思い備忘録としてまとめることにしました。

そのため

ディフェンス大事なので敢えて強調します。
調べれば出てくる内容を集約しただけであり、Google先生を隈なく検索すれば誰でもアクセス可能な情報です。

修正点等あればご遠慮なくご指摘ください。

どうぞ宜しくお願い致します。

0. What is UDS

Unified Diagnostic Services (UDS)ISO-14229で定義された統合診断サービスプロトコルです。
通信側 (クライアントまたはサーバー) のシミュレーション、診断通信の監視とデコードに役立ちます。
アーキテクチャにより、さまざまな通信バス (CAN、LIN など) で使用でき、最も可能性の高い使用例は下記になります。[1]

  • 車両との通信 (診断トラブル コードの読み取りなど)
  • UDS 通信の監視とデコード
  • オンボード ECU (サーバー) に対するテストの実行
  • OBD テスター (クライアント) に対するテストの実行

この使用例などで必要となる内容を下記に記載していきます。

1. Diagnostic System

1.1. System Architecture

外部テスターツールは、診断プラグ/ターミナルを介して車両ECUに接続し、UDSなどの診断プロトコルを介して通信するために使用されます。診断サービスは、車両の寿命全体にわたってさまざまなユースケースで使用されます。下記は引用 [2] をベースに作成。

1.2. Diagnositc Operations

  • Off-Board Diagnostic

オフボード診断は車両外で実行され、以下の場合に診断リクエストが処理される。

・ Ignition ON
・ Engine OFF
・ Vehicle standing still

  • On-Board Diagnostic

車両内で実行されるすべての診断タスクで、ECU が内部障害検出を実行します。
障害状態が検出されると Diagnostic Trouble Codes (DTC) を保存し、自己診断の関連情報を記録します。

下記は引用 [2] をベースに作成。

Diagnositc Operation Diagrams

2. Diagnostic Message

Diagnostic request:クライアントによって送信され、サーバーまたはサーバー グループを対象とする診断メッセージ。診断要求は、Service Identifier (SID) 値によって識別されます。

2.1. Positive Response Message

ポジティブレスポンス:肯定応答は、クライアント(テスター)からの要求に対して、処理を実行したことを知らせるためサーバー側(ECU)が ”何だかの応答をする” というメッセージです。

必ずしも正しい処理を実行したかはdata-parameterによって定義され、各SIDに対しポジレスを返す場合は SID + 0x40 されるということが大切。

Positive Response Table
Byte Description Value
1 Response SID SID + 0x40
2 data-parameter#1 XX
... ... ...
n data-parameter#n XX

2.2. Negative Response Message

サーバー側(ECU)が Negative Response Message:NRC (否定応答メッセージ)で応答した場合、サーバーは(何らかの理由で)クライアントから要求されたアクションを実行できなかったことを意味します。

NRCの否定応答を返す時は 0x7F, SID, NRC の形を取ります。

NRC Table
Byte Description Value
1 Negative Response SID 0x7F
2 Request SID SID
3 NRC XX

なお、NRC Code Valueは下記を参照すること(Descriptionは状況に応じて異なるので、下記は一般的なNRCの定義であることに注意)[1], [3]

UDS Knowledge Base/Diagnostic message/Negative Response Code

Negative Response Codes (NRC): UDS Protocol

2.3. Service Identifier list

UDSは機能単位ごとに以下のサービスを提供しています。[1], [2]

Diagnostic and Communication Management

診断と通信管理のSID。

SID Service Name Mnemonic Description Available in Default Session Has Sub-Function
0x10 Diagnostic Session Control DSC Used to enable different diagnostic sessions in the ECU(s); each session enables a specific set of diagnostic services and/or functionality.
0x11 ECU Reset ER Requests the ECU to effectively perform a specific type of reset.
0x27 Security Access SA Enable access to data and diagnostic services of ECU(s), which have restricted access for security, emissions, or safety reasons.
0x28 Communication Control CC Switch on/off the transmission, reception of certain messages of ECU(s).
0x29 Authentication A Prove client identity, allowing it to access data, diagnostic services, which have restricted access such as security, emissions, or safety reasons.
0x3E Tester Present TP Indicates to the ECU(s) that Tester client is still present and maintain the diagnostic service/communication that has been previously activated.
0x84 Secured Data Transmission SDT Perform data transmission with an extended data link security.
0x85 Control DTC Setting CDTCS Stop or resume the updating of DTC status bits (fault monitoring, failsafe functionalities still operate in the ECU(s)).
0x86 Response On Event ROE Requests ECU to start or stop transmission of responses (automatically execute a diagnostic service) on a specified event.
0x87 Link Control LC Used to transition the data link layer (between ECU(s) and Tester client) into a certain state which allows utilizing higher diagnostic bandwidth.

Data Transmission

データ転送関連のSID。
DataIdentifiers: DIDのReadとWriteがSID 0x22, 0x2E
メモリアドレスのReadとWriteがSID 0x23, 0x3D
になります。 詳しくはSection 5へ。

SID Service Name Mnemonic Description Available in Default Session Has Sub-Function
0x22 Read Data By Identifier RDBI Requests data record values from the ECU by one or more DataIdentifiers.
0x23 Read Memory By Address RMBA Request memory data from the ECU via provided starting address and size of memory to be read.
0x24 Read Scaling Data By Identifier RSDBI Request scaling data record information from the ECU by provide a DataIdentifiers.
0x2A Read Data By Periodic Identifier RDBPI Requests the periodic transmission of data record values from the ECU(s) by one or more periodic DataIdentifiers.
0x2C Dynamically Define Data Identifier DDDI Group one or more data elements into a data superset that can be requested en masse via the Read Data By Identifier or Read Data By Periodic Identifier service.
0x2E Write Data By Identifier WDBI Write information into the ECU in an internal location specified by the provided data identifier.
0x3D Write Memory By Address WMBA Write information into the ECU at specified memory locations.

Stored Data Transmission

格納データ転送のSID。

SID Service Name Mnemonic Description Available in Default Session Has Sub-Function
0x14 Clear Diagnostic Information CDTICI Clear diagnostic information from the ECU(s) (including DTC status byte, snapshot, extended data, etc.).
0x19 Read DTC Information RDTICI Read the status of ECU resident Diagnostic Trouble Code (DTC) information (including DTC status byte, snapshot, extended data, etc.).

Input Output Control

I/O制御のSID。

SID Service Name Mnemonic Description Available in Default Session Has Sub-Function
0x2F Input Output Control By Identifier IOCBI Requests the control of an input/output specific to the ECU(s).

Remote Activation of Routine

ルーチンのリモート起動のSID。

SID Service Name Mnemonic Description Available in Default Session Has Sub-Function
0x31 Routine Control RC Requests to start, stop a routine in the ECU(s) or requests the routine results.

Upload Download

SID Service Name Mnemonic Description Available in Default Session Has Sub-Function
0x34 Request Download RD Requests the negotiation of a data transfer from the client to the server.
0x35 Request Upload RU Requests the negotiation of a data transfer from the server to the client.
0x36 Transfer Data TD Transmits data to the server (download) or requests data from the server (upload).
0x37 Request Transfer Exit RTE Requests the termination of a data transfer.
0x38 Request File Transfer RFT Requests the negotiation of a file transfer between server and client.

3. Message timing

UDS Session layerにおける通信タイミングの設定について、主にテスター側とECU側それぞれのタイマー設定が含まれます。

メッセージタイミングを適切に設定することで以下を実現できます。[2]

  1. テスター側とECU側で適切なタイマー値を設定することで、安定した診断通信を実現
  2. 処理時間が長い場合は、NRC=0x78を使用して継続処理中であることをテスターに通知
  3. 各タイマーは診断サービスの要件に応じて適切な値を設定する必要がある

3.1. Tester

P2Client

要求メッセージの送信が成功した後、受信応答メッセージの開始までクライアントが待機するタイムアウト値(Timeout value for the client)。

  • P2Client_max

P2Clientの初期値/デフォルト値

  • P2*Client_max

否定応答メッセージ(NRC: negative response message)を受信した後、クライアントが待機するタイムアウトが拡張され、次の受信応答メッセージの開始に否定応答コード 0x78 (requestCorrectlyReceived-ResponsePending) が設定される。

S3 Client time

テスターが「テスタープレゼント」リクエストを送信するまでの待機時間を管理する。

3.2. ECU

P2Server

ECUの処理性能を管理するタイマーです。

  • P2Server_max

    • 通常の処理時間の最大値
    • この時間内に処理が完了しない場合、ECUは「処理中(NRC=0x78)」という否定応答を返します
  • P2*Server_max

    • 拡張処理時間の最大値でNRC=0x78の否定応答を送信した後の、追加処理時間
    • この時間を超えても処理が完了しない場合、再度NRC=0x78の否定応答を送信可能

S3 server time

非デフォルトセッション(non-default session)を終了するまでのタイムアウト時間を管理。

P4Server

リクエスト受信から最終レスポンス送信開始までの要求処理時間を管理します。

  • P4Server_max
    • P4Serverの最大値
    • 最終レスポンスは以下のいずれか:
      • 肯定応答
      • NRC≠0x78の否定応答
    • 周期的レスポンスのスケジューリング要求の場合、初回のUSDT(非確認分割データ転送)レスポンスが最終レスポンスとなる
    • P4Server_max = P2Server_maxの場合、そのサービスではNRC=0x78の否定応答が許可されていないことを示す

4. Session Mgmt (0x10, 0x11, 0x3E)

診断セッションでは、ECU 内の特定の診断サービスや機能のセットが有効になります。システムは、異なる機能を持つ複数のセッション タイプをサポートします。[4]

4.1. Session Types

Session Control 0x10 のタイプは以下の4つです。

Session Table
Session ID Type
01 Default Session
02 Programming Session
03 Extended Diagnostic Session
04 Safety System Diagnostic System
  1. Default Session (0x01)
    デフォルトセッションは、ECU の電源がオンになるとアクティブになります。このセッションでは、実行時に実行できる基本的な診断機能のみがアクセスできます。

  2. Programming Session (0x02)
    プログラミングセッションはソフトウェアアップデートで使用されます。

  3. Extended Diagnostic Session(0x03)

拡張診断セッションは追加の診断機能のロックを解除するため=追加診断機能を使用するときに遷移・使用されます。

  1. Safety System Diagnostic System (0x04)
    すべての安全上重要な診断機能をテストするために使用されます。

4.2. Service Control IDs

診断要求となるSIDは下記の3つです。

Service Table
Service ID Description
10 Diagnostic Session Control
11 ECU Reset
3E Tester Present

4.3. Session Rules

セッション管理は以下のルールに従って動作します。

  1. Session Activation
    サーバー(ECU)は、電源投入時に常にデフォルトの診断セッションを開始します。これによりいつでもECUの診断が可能になるということです。
    他のセッションが開始されていない場合、サーバーの電源がオンになっている間は、デフォルトのセッションが継続的に実行されます。

  2. Transition to Non-default Session
    Default Sessionで ResponseOnEvent(0x86) によって構成されたすべてのイベントを停止します。
    Security accessが再ロックされ、すべてのセキュリティ依存の診断機能がリセットされますが、セキュリティに依存しない診断機能は維持されます。

  3. Session Maintenance
    テスターは、デフォルトセッション以外のセッション維持をするために、定期的に TesterPresent (3E) を送信する必要があります。
    セッションはメンテナンスメッセージが受信されない場合はタイムアウト(S3)し、デフォルトに戻ります。

Session Rules Diagrams

5. Read DID (0x22)

識別子によるデータの読み取りの機能を担う RDBI SID 0x22 があります。
このサービスは、0 ~ 65535 (0xFFFF) の 2 バイト値でデータ識別子 (DID:Data Identifier) を使用します。
DID は要求と応答の両方のパラメータ識別子として機能し、以下のパラメータを読み出す際に使用されます。 [5]

DIDを用いることで、ECUのアドレス情報に依存せずに、特定の機能を読み書きできます。

再掲になりますがReadは0x22, Writeは0x2Eです。

DID Table
DID Description
0xF180 Boot software identification
0xF181 Application software identification
0xF182 Application data identification
0xF183 Boot software fingerprint
0xF184 Application software fingerprint
0xF185 Application data fingerprint
0xF186 Active diagnostic session
0xF187 Manufacturer spare part number
0xF188 Manufacturer ECU software number
0xF189 Manufacturer ECU software version
0xF18A Identifier of system supplier
0xF18B ECU manufacturing date
0xF18C ECU serial number
0xF18D Supported functional units
0xF18E Manufacturer kit assembly part number
0xF190 Vehicle Identification Number (VIN)
0xF192 System supplier ECU hardware number
0xF193 System supplier ECU hardware version number
0xF194 System supplier ECU software number
0xF195 System supplier ECU software version number
0xF196 Exhaust regulation/type approval number
0xF197 System name / engine type
0xF198 Repair shop code / tester serial number
0xF199 Programming date
0xF19D ECU installation date
0xF19E ODX file

データ識別子は独自のものであり、OEM のみが知っている場合もありますが、一部の DID は標準化されています。

6. Security Access (0x27)

セキュリティアクセスは以下のフローに沿って実行されます。
Security Access SID 0x27 は主にExtended Diagnostic Session:拡張診断セッションをサポートしているため、要求する前に、診断セッションと、デフォルト セッションから拡張診断セッションにジャンプする方法を調べておく必要があります。[6]

イメージは「Challenge-response authentication:チャレンジレスポンス認証」です。

Security Access Sequence Diagramは下記になります。

Security Access Sequence Diagram

7. Routine Control (0x31)

決まり切った手順、動作を意味する「ルーチン」で制御するためのSIDで[7]より要点を引用して説明します。

このルーチンは「決まった動作の制御」なので、それぞれの制御を RoutineIdentifier: RID として識別します。

SID 0x31 RID xx に対して、ECUの入出力テスト、特定機能の有効/無効検証などと動作を割り当て診断タスクを実行します。

RID_SBFはSub-Function ParametersでRIDの操作内容を指定します。

下記ではともにRID_SBF = 0x01 なのでStartRoutine: STRになります。

RID_B1, RID_B2は特定のルーチンを識別するためのRIDです。

下記では 0x20, 0x25 (2025_{16}に年のイベント関する制御とした場合)がRIDとなり、イベントによってこの値を独自に定義します。

Client -> Server Request

Field PCI_H RIDSID RID_SBF RID_B1 RID_B2
Value 0x02 0x31 0x01 0x20 0x25

Server -> Client Response

Field PCI_H RIDSID RID_SBF RID_B1 RID_B2
Value 0x04 0x71 0x01 0x20 0x25

Reference

[1] UDS Knowledge Base

[2] Overview of Unified Diagnostic Services Protocol

[3] UDS Protocol Tutorial: Exploring the Automotive Diagnostic Protocol

[4] UDS Unified Diagnostic Services – ISO 14229 1.Diagnostic Session Control (0x10):

[5] UDS Explained - A Simple Intro (Unified Diagnostic Services)

[6] Security Access Service Identifier (0x27): UDS Protocol

[7] RoutineControl (0x31) Service: UDS Protocol


以上、UDSのまとめでした。
CAN-FD のキットがあるので、py-udsをインストールしてUDSで遊んでみたいですが、時間がないので有志の方いましたら、是非お話伺えると嬉しいです。

また、Likeいただけると大変励みになりますので、よろしくお願いいたします。

Discussion