1、AUTOSAR_E2E
E2E的概念是在运行时对与安全相关的数据交互进行保护,以防止通信链路故障的影响。基本实现方式是在要保护的数据区添加额外的E2E Header。发送端负责添加E2E Header,接收端会对Header进行校验检查,保证数据的完整性。

参考 AUTOSAR_PRS_E2EProtocol Specification R20-11 ,规定了不同的E2E Profiles,如1,2,4,5,6,7,8,11,22等
以E2E Profile 4为例,规范中定义了Profile 4 包含的控制字段Length、Counter、CRC、DataID,以及Header的数据结构

1.1 E2E Profile 4 Header的数据结构

Length : 16位,为了支持可变长度引入此字段。
Length = user data + E2E Header(CRC + Counter + Length + DataID)
Counter :16位, 取值 0 ~ 0xFFFF
DataID :32位,必须是全局唯一的,用户定义
CRC :32位,应该使用 Crc_CalculateCRC32P4() 函数 [SWS CRCLibrary],CRC32 0x1F4ACFB13多项式 ,确保高检测率和高汉明距离
在 E2E Profile 4, CRC计算包含 整个 E2E Header(CRC字段除外) 和 user data(RS_E2E_08531)
整个Header字段被编码为:
(1)大端:(最重要的字节在前面) - 由Profile规定,PS:高字节在前,低字节在后
(2)LSB(字节内的最低有效位)先传输 - 由TCP/IP总线强制
1.2 Creation of E2E-Header
1.2.1 E2E_P04Project
E2E_P04Project函数执行图表所示的步骤

E2E_P04Protect() 中 ”Verify inputs of the protect function”执行如下的步骤:

"Compute offset" 执行如下步骤

“Write Length” 执行步骤

“Write Counter”执行步骤:

“Wirte DataID” 执行步骤:

“Compute CRC”步骤:

“Write CRC” 步骤:

“Increment Counter” 步骤:

1.2.2 E2E_P04Forward
E2E Profile 4的E2E_P04Forward()函数由SW-C调用,以保护其应用程序数据,并转发接收 到的E2E-Status,用于基于面向服务通信的信号转换等用例。 如果接收到的 E2E状态等于E2E_P_OK,那么函数的行为应该与E2E_P04Protect()相同。
1.3 Evaluation of the E2E-Header
目录
1.3 Evaluation of the E2E-Header
E2E_P04Check函数按照本节中的以下七个图和PRS_E2EProtocol_00367图指定的操作。

E2E_P04Check() 函数中 ”Verify inputs of the check function” 执行步骤

"Read Length" 步骤:

“Read Counter” 步骤:

“Read DataID” 步骤:

“Read CRC” 步骤:

“Do Checks” 步骤:
2、vsomeip E2E
2.1 概要
vsomeip中也实现了E2E的相关机制,包括 Profile 1、Profile 4 和 Profile custom,整体是以插件的形式执行。
e2e源码文件路径: vsomeip-x.x.xx.x/implementation/e2e_protection/
2.2 实现流程
vsomeip E2E的发送 protecter 和 接收checker 都是在routing中完成的。以E2E Profile 4 为例分析。
2.2.1 Protect
implementation/routing/routing_manager_impl.cpp
挂载e2e插件
void routing_manager_impl::init() {
...
...
...
if( configuration_->is_e2e_enabled()) {
VSOMEIP_INFO << "E2E protection enabled.";
const char *its_e2e_module = getenv(VSOMEIP_ENV_E2E_PROTECTION_MODULE);
std::string plugin_name = its_e2e_module != nullptr ? its_e2e_module : VSOMEIP_E2E_LIBRARY;
auto its_plugin = plugin_manager::get()->get_plugin(plugin_type_e::APPLICATION_PLUGIN, plugin_name);
if (its_plugin) {
VSOMEIP_INFO << "E2E module loaded.";
e2e_provider_ = std::dynamic_pointer_cast<e2e::e2e_provider>(its_plugin);
}
}
if(e2e_provider_) {
std::map<e2exf::data_identifier_t, std::shared_ptr<cfg::e2e>> its_e2e_configuration = configuration_->get_e2e_configuration();
for (auto &identifier : its_e2e_configuration) {
if(!e2e_provider_->add_configuration(identifier.second)) {
VSOMEIP_INFO << "Unknown E2E profile: " << identifier.second->profile << ", skipping ...";
}
}
}
#endif
}
在usr data 发送的时候,给数据添加E2E Header,对消息进行保护
bool routing_manager_impl::send(client_t _client, const byte_t *_data,
length_t _size, instance_t _instance, bool _reliable,
client_t _bound_client,
credentials_t _credentials,
uint8_t _status_check, bool _sent_from_remote)
e2e_buffer its_buffer;
if (e2e_provider_) {
if ( !is_service_discovery) {
service_t its_service = VSOMEIP_BYTES_TO_WORD(
_data[VSOMEIP_SERVICE_POS_MIN], _data[VSOMEIP_SERVICE_POS_MAX]);
method_t its_method = VSOMEIP_BYTES_TO_WORD(
_data[VSOMEIP_METHOD_POS_MIN], _data[VSOMEIP_METHOD_POS_MAX]);
#ifndef ANDROID
if (e2e_provider_->is_protected({its_service, its_method})) {
// Find out where the protected area starts 定位CRC计算起始位置
size_t its_base = e2e_provider_->get_protection_base({its_service, its_method});
// Build a corresponding buffer 将需要Protect的部分拷贝出来
its_buffer.assign(_data + its_base, _data + _size);
e2e_provider_->protect({ its_service, its_method }, its_buffer, _instance);

最低0.47元/天 解锁文章
1837

被折叠的 条评论
为什么被折叠?



