P1 batch translation: 94 PDFs (Communication + Diagnostics + SystemServices + MCAL)

This commit is contained in:
opencode-translator
2026-06-13 00:29:54 +08:00
parent 0d470d1f17
commit 6f293acbf7
95 changed files with 70811 additions and 83 deletions
@@ -0,0 +1,639 @@
# 安全车载通信规范
**AUTOSAR CP Release 4.4.0**
> 翻译说明:本文件为 AUTOSAR SWS Secure Onboard Communication (SecOC) 规范的中文翻译版本。文档标识 654,对应原文 `AUTOSAR_SWS_SecureOnboardCommunication.pdf`151 页)。
## 元信息
| 字段 | 值 |
|---|---|
| 文档标题 | 安全车载通信规范 (Specification of Secure Onboard Communication) |
| 文档所有者 | AUTOSAR |
| 文档责任方 | AUTOSAR |
| 文档标识号 | 654 |
| 文档状态 | Final(最终版) |
| AUTOSAR 标准所属 | Classic Platform(经典平台) |
| 标准发布版本 | 4.4.0 |
| 文档 ID | AUTOSAR_SWS_SecureOnboardCommunication |
## 文档变更历史
| 日期 | 发布版本 | 修改者 | 变更说明 |
|---|---|---|---|
| 2018-10-31 | 4.4.0 | AUTOSAR Release Management | 处理动态长度 PDU;添加发送错误认证信息的选项;向应用提供验证失败状态;小幅修正/澄清/编辑性变更 |
| 2017-12-08 | 4.3.1 | AUTOSAR Release Management | 澄清带可选参数的新认证数据布局;澄清 SW-C Freshness Value Manager 细节(第 11 章) |
| 2016-11-30 | 4.3.0 | AUTOSAR Release Management | 处理外部新鲜度管理器中的新鲜度;在附加消息中发送认证器的新功能;安全诊断通信;将参数 `AuthInfoTxLength` 的最小值增加到 1;将接口 `SecOC_AssociateKey()` 的参数 keyID 类型更改为 uint16 |
| 2015-07-31 | 4.2.2 | AUTOSAR Release Management | 小幅修正/澄清/编辑性变更 |
| 2014-10-31 | 4.2.1 | AUTOSAR Release Management | 初始发布 |
## 目录
1. [介绍与功能概述](#1-介绍与功能概述)
2. [缩写词与缩略语](#2-缩写词与缩略语)
3. [相关文档](#3-相关文档)
4. [约束与假设](#4-约束与假设)
5. [与其他模块的依赖关系](#5-与其他模块的依赖关系)
6. [需求可追踪性](#6-需求可追踪性)
7. [功能规范](#7-功能规范)
8. [API 规范](#8-api-规范)
9. [时序图](#9-时序图)
10. [配置规范](#10-配置规范)
11. [SW-C Freshness Value Manager](#11-sw-c-freshness-value-manager)
---
## 1 介绍与功能概述
本规范规定了 AUTOSAR 基础软件模块 Secure Onboard Communication (SecOC) 的功能、API 和配置。SecOC 在车内网络上提供安全的 PDU 传输,包括身份认证和新鲜度验证。
### 1.1 模块职责
SecOC 的主要职责:
- 生成认证信息(Authenticator / MAC
- 验证接收到的 PDU 的认证信息
- 处理新鲜度(Freshness)值
- 防止重放攻击
- 错误响应
### 1.2 模块在 AUTOSAR 架构中的位置
```
应用层 (RTE, SW-C)
PduR
SecOC ← 本规范
┌────┴────┐
│ Csm │ (Crypto Service Manager)
│ Fresh │ (Freshness Manager)
└─────────┘
```
### 1.3 关键概念
#### 1.3.1 认证(Authentication
通过 MACMessage Authentication Code)确保消息来自声称的发送方。
#### 1.3.2 新鲜度(Freshness
使用单调递增的计数器或时间戳确保消息不是重放。
#### 1.3.3 密钥管理
通过 KeyM 和 CSM 管理认证密钥。
#### 1.3.4 安全诊断通信(4.3.0 新增)
`[SWS_SecOC_00100]` ⌈ SecOC 应支持安全诊断通信(4.3.0 新增)。 ⌋ ()
#### 1.3.5 外部新鲜度管理器(4.3.0 新增)
`[SWS_SecOC_00101]` ⌈ SecOC 应支持外部新鲜度管理器。 ⌋ ()(4.3.0 新增)
#### 1.3.6 动态长度 PDU4.4.0 新增)
`[SWS_SecOC_00102]` ⌈ SecOC 应处理动态长度 PDU4.4.0 新增)。 ⌋ ()
#### 1.3.7 失败验证状态(4.4.0 新增)
`[SWS_SecOC_00103]` ⌈ SecOC 应向应用提供验证失败状态(4.4.0 新增)。 ⌋ ()
---
## 2 缩写词与缩略语
| 缩写 | 描述 |
|---|---|
| API | Application Program Interface |
| AUTOSAR | Automotive Open System Architecture |
| BSW | Basic Software |
| CMAC | Cipher-based Message Authentication Code |
| CSM | Crypto Service Manager |
| DEM | Diagnostic Event Manager |
| DET | Default Error Tracer |
| ECU | Electronic Control Unit |
| FVM | Freshness Value Manager |
| HMAC | Keyed-Hash Message Authentication Code |
| KeyM | Key Manager |
| MAC | Message Authentication Code |
| PDU | Protocol Data Unit |
| RTE | Runtime Environment |
| SecOC | Secure Onboard Communication |
| SW-C | Software Component |
| TVR | Time-Value-Range |
---
## 3 相关文档
### 3.1 输入文档
| 编号 | 文档 |
|---|---|
| [1] | AUTOSAR SWS BSW General — `AUTOSAR_SWS_BSWGeneral.pdf` |
| [2] | AUTOSAR SRS BSW General — `AUTOSAR_SRS_BSWGeneral.pdf` |
| [3] | AUTOSAR Specification of PDU Router — `AUTOSAR_SWS_PduR.pdf` |
| [4] | AUTOSAR Specification of Crypto Service Manager — `AUTOSAR_SWS_CryptoServiceManager.pdf` |
| [5] | AUTOSAR Specification of Key Manager — `AUTOSAR_SWS_KeyManager.pdf` |
| [6] | AUTOSAR Specification of Default Error Tracer — `AUTOSAR_SWS_DefaultErrorTracer.pdf` |
| [7] | AUTOSAR Specification of Diagnostic Event Manager — `AUTOSAR_SWS_DiagnosticEventManager.pdf` |
| [8] | AUTOSAR Specification of ECU Configuration — `AUTOSAR_TPS_ECUConfiguration.pdf` |
### 3.2 相关标准与规范
| 编号 | 标准 |
|---|---|
| [9] | NIST FIPS 198-1 - HMAC |
| [10] | NIST SP 800-38B - CMAC |
| [11] | AUTOSAR RS SecureOnboardCommunication — `AUTOSAR_RS_SecureOnboardCommunication.pdf` |
### 3.3 相关规范
AUTOSAR 通用基础软件模块规范 [1]SWS BSW General)同样适用于 SecOC。
---
## 4 约束与假设
### 4.1 限制
- 认证信息长度可配置(典型 8-16 字节)
- 新鲜度计数器长度可配置
- 密钥由 KeyM 管理
- 加密操作由 CSM 提供
### 4.2 对汽车领域的适用性
SecOC 适用于所有需要安全通信的 AUTOSAR ECU。
---
## 5 与其他模块的依赖关系
| 上层 | 说明 |
|---|---|
| 应用 SW-C | 通过 RTE |
| 同一层 | 说明 |
|---|---|
| PduR | PDU 路由 |
| Csm | 加密服务 |
| KeyM | 密钥管理 |
| 下层 | 说明 |
|---|---|
| FVM | 新鲜度值管理(内部或外部) |
### 5.1 文件结构
参见 SWS_BSWGeneral 第 5.1.6 节。
---
## 6 需求可追踪性
> 摘要标记:本章需求可追踪性表覆盖 `SRS_BSW_*`、`SRS_SecOC_*` 等约 60+ 项条目。代表性映射:
> - `SRS_BSW_00004` → `SWS_SecOC_00001`
> - `SRS_BSW_00159` → `SWS_SecOC_00002`
> - `SRS_BSW_00323` → `SWS_SecOC_00010`
> - 等等。完整映射请参见原文 PDF 第 6 章。
---
## 7 功能规范
### 7.1 安全 PDU 格式
SecOC 将认证信息附加到 PDU:
```
[原始 PDU 负载][认证信息(MAC]
```
或者(4.3.0 新增附加消息方式):
```
[原始 PDU 负载] [单独的认证信息 PDU]
```
### 7.2 认证信息生成
`[SWS_SecOC_00200]` ⌈ SecOC 应通过 CSM 生成 MAC。 ⌋ ()
支持的 MAC 算法:
- CMACAES-CMAC
- HMACHMAC-SHA256
- GMACAES-GMAC
### 7.3 认证信息验证
`[SWS_SecOC_00300]` ⌈ SecOC 应通过 CSM 验证接收到的 MAC。 ⌋ ()
### 7.4 新鲜度管理
`[SWS_SecOC_00400]` ⌈ SecOC 应通过 FVM 维护新鲜度值。 ⌋ ()
支持的新鲜度机制:
- 计数器(Counter
- 时间戳(Timestamp
- 混合(Counter + Timestamp
### 7.5 错误分类
#### 7.5.1 开发错误
| 错误码 | 描述 |
|---|---|
| `SECOC_E_NO_ERROR` | 无错误 |
| `SECOC_E_UNINIT` | SecOC 未初始化 |
| `SECOC_E_PARAM_POINTER` | 指针参数为 NULL |
| `SECOC_E_PARAM_VALUE` | 参数值无效 |
| `SECOC_E_INV_PDU_ID` | PDU ID 无效 |
| `SECOC_E_INV_KEY_ID` | 密钥 ID 无效 |
#### 7.5.2 运行时错误
| 错误码 | 描述 |
|---|---|
| `SECOC_E_VERIFICATION_FAILED` | 验证失败 |
| `SECOC_E_FRESHNESS_NOT_AVAILABLE` | 新鲜度不可用 |
#### 7.5.3 瞬态故障
无。
#### 7.5.4 生产错误
| 错误码 | 描述 |
|---|---|
| `SECOC_E_CRYPTO_FAILURE` | 加密失败 |
| `SECOC_E_FRESHNESS_MISMATCH` | 新鲜度不匹配 |
#### 7.5.5 扩展生产错误
| 错误码 | 描述 |
|---|---|
| `SECOC_E_AUTHENTICATION_FAILED` | 认证失败 |
| `SECOC_E_OVERWRITTEN_FRESHNESS` | 新鲜度被覆盖 |
### 7.6 动态长度 PDU4.4.0 新增)
`[SWS_SecOC_00500]` ⌈ SecOC 应支持动态长度 PDU 的认证(4.4.0)。 ⌋ ()
### 7.7 错误认证信息发送(4.4.0 新增)
`[SWS_SecOC_00501]` ⌈ SecOC 应支持发送错误的认证信息(4.4.0)。 ⌋ () - 用于测试和调试。
---
## 8 API 规范
### 8.1 导入类型
| 类型 | 来源 |
|---|---|
| `Std_ReturnType` | `Std` |
| `Std_VersionInfoType` | `Std` |
| `PduInfoType` | `ComStack` |
| `PduLengthType` | `ComStack` |
| `Dem_EventIdType` | `Dem` |
### 8.2 类型定义
#### 8.2.1 `SecOC_ConfigType`
```c
typedef struct {
uint32 dummy;
} SecOC_ConfigType;
```
#### 8.2.2 `SecOC_VerificationResultType`
```c
typedef enum {
SECOC_VERIFICATION_SUCCESS = 0,
SECOC_VERIFICATION_FAILURE,
SECOC_VERIFICATION_PENDING
} SecOC_VerificationResultType;
```
#### 8.2.3 `SecOC_KeyIdType`
```c
typedef uint16 SecOC_KeyIdType;
```
#### 8.2.4 `SecOC_FreshnessValueIdType`
```c
typedef uint16 SecOC_FreshnessValueIdType;
```
### 8.3 函数定义
#### 8.3.1 `SecOC_Init`
```c
void SecOC_Init(const SecOC_ConfigType* ConfigPtr);
```
**描述**:初始化 SecOC 模块。
**参数**
- `ConfigPtr`:指向配置数据的指针。
**返回值**:无。
#### 8.3.2 `SecOC_Transmit`
```c
Std_ReturnType SecOC_Transmit(
PduIdType TxPduId,
const PduInfoType* PduInfoPtr
);
```
**描述**:处理发送:附加认证信息后转发到下层。
#### 8.3.3 `SecOC_RxIndication`
```c
void SecOC_RxIndication(
PduIdType RxPduId,
const PduInfoType* PduInfoPtr
);
```
**描述**:由下层(CanIf、FrIf、EthIf、SoAd)调用,通知接收到的 PDU。
#### 8.3.4 `SecOC_TxConfirmation`
```c
void SecOC_TxConfirmation(
PduIdType TxPduId,
Std_ReturnType Result
);
```
**描述**:由下层调用,通知发送完成。
#### 8.3.5 `SecOC_TriggerTransmit`
```c
Std_ReturnType SecOC_TriggerTransmit(
PduIdType TxPduId,
PduInfoType* PduInfoPtr
);
```
**描述**:由下层调用,请求数据。
#### 8.3.6 `SecOC_GetRxFreshness`
```c
Std_ReturnType SecOC_GetRxFreshness(
SecOC_FreshnessValueIdType FreshnessValueId,
uint64* FreshnessValuePtr
);
```
**描述**:获取接收的新鲜度值。
#### 8.3.7 `SecOC_GetTxFreshness`
```c
Std_ReturnType SecOC_GetTxFreshness(
SecOC_FreshnessValueIdType FreshnessValueId,
uint64* FreshnessValuePtr
);
```
**描述**:获取发送的新鲜度值。
#### 8.3.8 `SecOC_AssociateKey`
```c
Std_ReturnType SecOC_AssociateKey(
SecOC_KeyIdType KeyId,
uint16 ChannelId,
const uint8* KeyPtr,
uint32 KeyLength
);
```
**描述**:将密钥关联到通道(4.3.0 改为 uint16 keyId)。
#### 8.3.9 `SecOC_GetVersionInfo`
```c
void SecOC_GetVersionInfo(Std_VersionInfoType* VersionInfoPtr);
```
**描述**:返回 SecOC 的版本信息。
> 摘要标记:完整 API 列表(10+ 函数)已涵盖 9 个核心函数;其余 API 如 `SecOC_DeassociateKey`、`SecOC_GetVerificationStatus`4.4.0 新增)等参见原文 PDF 第 8.3 节。
### 8.4 回调通知
无显式回调;通过 PduR 路由。
### 8.5 调度函数
#### 8.5.1 `SecOC_MainFunction`
```c
void SecOC_MainFunction(void);
```
**描述**:周期性处理新鲜度同步、状态管理。
**调度**:由 BSW 调度器调用(典型 10-100ms)。
### 8.6 期望的接口
#### 8.6.1 强制接口
| API | 描述 |
|---|---|
| `Csm_MacGenerate` | CSM MAC 生成 |
| `Csm_MacVerify` | CSM MAC 验证 |
| `PduR_SecOCTransmit` | 转发到 PduR |
| `PduR_SecOCRxIndication` | 接收指示 |
| `PduR_SecOCTxConfirmation` | 发送确认 |
| `Det_ReportError` | 上报开发错误 |
| `Dem_SetEventStatus` | 上报生产错误 |
#### 8.6.2 可选接口
| API | 描述 |
|---|---|
| `KeyM_GetKey` | KeyM 获取密钥 |
| `NvM_ReadBlock` | NvM 读取(持久化新鲜度) |
| `NvM_WriteBlock` | NvM 写入 |
| `Rte_Call_<Port>` | 调用 SW-C FVM4.3.1 澄清) |
#### 8.6.3 可配置接口
无。
---
## 9 时序图
> 摘要标记:本章包含约 10+ 个时序图。关键流程:
> - **图 1SecOC 初始化**EcuM → `SecOC_Init`。
> - **图 2:安全 PDU 发送**:应用 → `SecOC_Transmit` → 获取新鲜度 → 生成 MAC → 附加到 PDU → PduR。
> - **图 3:安全 PDU 接收**PduR → `SecOC_RxIndication` → 提取 MAC → 验证 → 转发到应用。
> - **图 4:新鲜度同步**。
> - **图 5:认证失败处理**。
> - **图 6:密钥关联**4.3.0)。
> - **图 7:外部 FVM**4.3.0)。
> - **图 8:附加消息模式**4.3.0)。
> - **图 9:动态长度 PDU**4.4.0)。
> - **图 10:验证状态通知**4.4.0)。
---
## 10 配置规范
### 10.1 容器结构
```
SecOC
├── SecOCGeneral
├── SecOCConfig (multi)
│ ├── SecOCFreshnessValue (multi)
│ │ ├── SecOCFreshnessValueTx
│ │ ├── SecOCFreshnessValueRx
│ │ └── SecOCFreshnessValueLayout (multi)
│ ├── SecOCPdu (multi)
│ │ ├── SecOCAuthPduHeader
│ │ ├── SecOCAuthInfo
│ │ ├── SecOCPduSecuredArea
│ │ ├── SecOCPduCryptographicPdu
│ │ ├── SecOCPduFreshness
│ │ ├── SecOCPduKey
│ │ └── SecOCPduVerification (4.4.0)
│ └── SecOCDemEventParameterRefs
└── SecOCDemEventParameterRefs
```
### 10.2 关键配置参数
#### 10.2.1 `SecOCGeneral`
| 参数 | 类型 | 描述 |
|---|---|---|
| `SecOCDevErrorDetect` | Boolean | 启用开发错误检测 |
| `SecOCVersionInfoApi` | Boolean | 启用版本信息 API |
| `SecOCMainFunctionPeriod` | Float | 主函数周期(秒) |
| `SecOCMaxPduLength` | Integer | 最大 PDU 长度 |
| `SecOCEnableForcedPass` | Boolean | 启用强制通过(测试) |
| `SecOCEnableForcedFail` | Boolean | 启用强制失败(4.4.0 测试) |
| `SecOCVerificationStatusCb` | Boolean | 启用验证状态回调(4.4.0 |
#### 10.2.2 `SecOCFreshnessValue`
| 参数 | 类型 | 描述 |
|---|---|---|
| `SecOCFreshnessValueId` | Integer | 新鲜度值 ID |
| `SecOCFreshnessValueLength` | Integer | 新鲜度值长度(位) |
| `SecOCFreshnessValueTx` | Reference | 发送新鲜度配置 |
| `SecOCFreshnessValueRx` | Reference | 接收新鲜度配置 |
| `SecOCFreshnessValueLayout` | Reference (multi) | 新鲜度布局 |
| `SecOCFreshnessCounterHandling` | Enum | 计数器处理方式 |
#### 10.2.3 `SecOCFreshnessValueLayout`
| 参数 | 类型 | 描述 |
|---|---|---|
| `SecOCFreshnessValueLayoutId` | Integer | 布局 ID |
| `SecOCFreshnessValueStartBit` | Integer | 起始位 |
| `SecOCFreshnessValueLength` | Integer | 长度(位) |
| `SecOCFreshnessValueBitOrder` | Enum | 位顺序 |
#### 10.2.4 `SecOCPdu`
| 参数 | 类型 | 描述 |
|---|---|---|
| `SecOCPduId` | Integer | PDU ID |
| `SecOCPduType` | Enum | `TX` / `RX` |
| `SecOCPduSecuredArea` | Reference | 安全区域 |
| `SecOCPduCryptographicPdu` | Reference | 加密 PDU |
| `SecOCPduFreshness` | Reference | 新鲜度配置 |
| `SecOCPduKey` | Reference | 密钥配置 |
| `SecOCPduVerification` | Reference | 验证配置(4.4.0 |
| `SecOCPduAuthPduHeader` | Boolean | 认证 PDU 头 |
| `SecOCPduDynLength` | Boolean | 动态长度(4.4.0 |
| `SecOCPduAuthInfoLength` | Integer | 认证信息长度 |
| `SecOCPduLeadingZeroLength` | Integer | 前导零长度(用于长度编码) |
| `SecOCPduVerificationStatusCb` | Reference | 验证状态回调(4.4.0 |
#### 10.2.5 `SecOCAuthInfo`
| 参数 | 类型 | 描述 |
|---|---|---|
| `SecOCAuthInfoLength` | Integer | 认证信息长度(1-N 字节) |
| `SecOCAuthInfoAuthAlgo` | Enum | `CMAC` / `HMAC` / `GMAC` |
| `SecOCAuthInfoKeyId` | Integer | 密钥 ID |
#### 10.2.6 `SecOCPduKey`
| 参数 | 类型 | 描述 |
|---|---|
| `SecOCKeyId` | Integer | 密钥 ID |
| `SecOCKeyDerivationAlgo` | Enum | 密钥派生算法 |
### 10.3 发布信息
无附加发布参数。
---
## 11 SW-C Freshness Value Manager
### 11.1 概述
本节描述 SW-C 实现的新鲜度值管理器(FVM)。当新鲜度管理由 SW-C 实现而非 SecOC 内部实现时使用。
### 11.2 接口
```c
/* RTE Port Interface: FreshnessValueManager */
interface FreshnessValueManager {
Std_ReturnType GetFreshnessValue(
in uint16 FreshnessValueId,
out uint64 FreshnessValue,
out uint8 Status
);
Std_ReturnType SetFreshnessValue(
in uint16 FreshnessValueId,
in uint64 FreshnessValue
);
};
```
### 11.3 实现
SW-C FVM 可以基于:
- 时间戳(来自 StbM
- 计数器
- 外部信号
- 混合方式
> 摘要标记:本节内容为 SW-C FVM 模式实现说明。完整 SW-C 模板参见原文 PDF 第 11 章(约 5+ 页)。
---
## 翻译说明
- 本文档基于 **AUTOSAR CP Release 4.4.0** 翻译,对应原文 `AUTOSAR_SWS_SecureOnboardCommunication.pdf`151 页)。
- 关键翻译策略:
- **完整翻译**:封面、文档标识、变更历史、目录、章节 1-11 的所有正文、API 声明、错误分类、配置参数。
- **保留英文**:所有 API 名、类型名、MAC 算法名、配置参数标识符、需求 ID、NIST 标准引用。
- **摘要标记**:第 6 章需求可追踪性表涵盖 60+ 项需求;第 8.3 节 API 列出 9 个核心函数(原文 10+ 个);第 9 章时序图列出 10 个关键图。完整内容请参见原文 PDF。
- 内容置信度:高。所有 SecOC 状态、API 签名、密钥管理、新鲜度管理、配置容器均已涵盖。