CAPL 自动化脚本 - UDS 安全解锁 Lv1

本文介绍了一种使用CANoeDiagnostic和capl脚本进行UDS27号功能自动解锁的方法,包括获取种子、计算密钥并发送到ECU,虽然简单但不适用于所有通用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一种简易的UDS$27解锁方式,使用capl脚本去实行自动化。

利用CANoe自己的Diagnostic去诊断,返回。

首先:声明2701 2702

拿到种子后,使用diagGenerateKeyFromSeed函数去调用工程里面的DLL文件去计算。

再将计算好的密钥发送到ECU。

void SecurityAccess_Lv1()
{
  diagRequest DCM.request Seed_1; // 27 01
  diagRequest DCM.request Key_2; // 27 02 
  const dword Response_time = 50; // diagnostic response time
  byte SeedArray[4]; // Actual Seed length
  byte KeyArray[4]; // Actual key length
  dword KeyActualSize; // Actual key length
  int i;
  
  diagSendRequest(Seed_1);// send 27 01 request
  if(testWaitForDiagResponse(Seed_1,Response_time)) // Waiting for 2701 response, Waiting for 2701 response, place the seed in array
  {
    for(i=0;i<elcount(SeedArray);i++)
      {
        SeedArray[i]=diagGetRespPrimitiveByte(Seed_1,i+2); 
        // write("%d",SeedArray[i]);
      }
  }
/* if there is no response within the defined time, consider adding testfail function */
//  else
//  {
//    testStepFail("");
//  }
  if(0==diagGenerateKeyFromSeed("ecuQualifier",SeedArray,elcount(SeedArray),1,"","",KeyArray,elcount(KeyArray),KeyActualSize))
  {
    // write("%d, %d, %d, %d",KeyArray[0],KeyArray[1],KeyArray[2],KeyArray[3]);
    diagSetParameterRaw(Key_2,"SecurityKey",KeyArray,elcount(KeyArray)); // set 27 02 raw
    diagSendRequest(Key_2); // send key to ECU
  }
}

这种方式简单,可以快速的去操作。

如果想要做一个通用库,不一定适用。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值