#automotive #ecu #client-server #doip #do-ip

doip-tokio

DoIP (通过IP的故障诊断通信) 的客户端和服务器实现,用于汽车领域

1个不稳定版本

0.1.0 2024年7月26日

#6#ecu

Download history 93/week @ 2024-07-22 33/week @ 2024-07-29

每月126次下载

MIT 许可证

32KB
608

DoIP - ISO13400-2 是用于汽车领域的IP故障诊断通信协议。

DoIP只处理诊断数据包的传输。实际的诊断消息使用UDS(统一诊断服务)协议编码,该协议由ISO14229指定。

客户端示例

use std::net::Ipv4Addr;
use doip::{ActivationType, RoutingActivationResponseCode};
use doip_tokio::{DoIpClient, DoIpTokioError};
use futures::StreamExt;
use openssl::{
    pkey::PKey,
    ssl::{SslConnector, SslMethod},
    x509::X509,
};
use tls_api::TlsConnectorBuilder;
use tls_api_openssl::TlsConnector;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Configure TLS setup
    const CERT_PEM: &[u8] =  b"-----BEGIN CERTIFICATE-----...";
    const CERT_PRIVATE_KEY: &[u8] = b"-----BEGIN RSA PRIVATE KEY-----...";

    let x509 = X509::from_pem(CERT_PEM)?;
    let pkey = PKey::private_key_from_pem(CERT_PRIVATE_KEY)?;

    let mut builder = SslConnector::builder(SslMethod::tls())?;

    builder.set_cipher_list(doip::TLS_V1_2_CIPHER_SUITES_OPENSSL)?;
    // TLSv1.3
    builder.set_ciphersuites(doip::TLS_V1_3_CIPHER_SUITES)?;
    builder.set_private_key(&pkey)?;
    builder.cert_store_mut().add_cert(x509)?;
    let tls_connector = tls_api_openssl::TlsConnectorBuilder {
        builder,
        verify_hostname: false,
    }
    .build()?;

    let addr = Ipv4Addr::new(127, 0, 0, 1);
    let mut client = DoIpClient::connect(addr, 0x0E80, tls_connector, "localhost").await?;

    let response = client
        .routing_activation([0x00, 0x00], ActivationType::Default)
        .await?;
    Ok(())
}

依赖项

~5–15MB
~195K SLoC