| 1 | // SPDX-License-Identifier: BSD-2-Clausecxx . . $ `<file>/src/utils.c`/ |
| 2 | /* |
| 3 | * Copyright (C) 2020-2024 Linutronix GmbH |
| 4 | * Author Kurt Kanzenbach <[email protected]> |
| 5 | */ |
| 6 | |
| 7 | #include <endian.h> |
| 8 | #include <errno.h> |
| 9 | #include <fcntl.h> |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <unistd.h> |
| 14 | |
| 15 | #include <arpa/inet.h> |
| 16 | |
| 17 | #include <sys/stat.h> |
| 18 | #include <sys/types.h> |
| 19 | |
| 20 | #include <linux/if_ether.h> |
| 21 | |
| 22 | #include "config.h"cxx . . $ `<file>/src/config.h`/ |
| 23 | #include "log.h"cxx . . $ `<file>/src/log.h`/ |
| 24 | #include "net.h"cxx . . $ `<file>/src/net.h`/ |
| 25 | #include "net_def.h"cxx . . $ `<file>/src/net_def.h`/ |
| 26 | #include "security.h"cxx . . $ `<file>/src/security.h`/ |
| 27 | #include "stat.h"cxx . . $ `<file>/src/stat.h`/ |
| 28 | #include "thread.h"cxx . . $ `<file>/src/thread.h`/ |
| 29 | #include "utils.h"cxx . . $ `<file>/src/utils.h`/ |
| 30 | #include "xdp.h"cxx . . $ `<file>/src/xdp.h`/ |
| 31 | |
| 32 | void increment_periodcxx . . $ increment_period(4d7c74d32dea27cd).(struct timespeccxx . . $ timespec# *time, int64_tcxx . . $ int64_t# period_ns) |
| 33 | { |
| 34 | time->tv_nseccxx . . $ timespec#tv_nsec. += period_ns; |
| 35 | |
| 36 | while (time->tv_nseccxx . . $ timespec#tv_nsec. >= NSEC_PER_SECcxx . . $ `src/utils.h:26:9`!) { |
| 37 | /* timespec nsec overflow */ |
| 38 | time->tv_seccxx . . $ timespec#tv_sec.++; |
| 39 | time->tv_nseccxx . . $ timespec#tv_nsec. -= NSEC_PER_SECcxx . . $ `src/utils.h:26:9`!; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void pthread_errorcxx . . $ pthread_error(66835f578de1bcb3).(int ret, const char *message) |
| 44 | { |
| 45 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: %s\n", message, strerrorcxx . . $ strerror(ff224f080444ee45).(ret)); |
| 46 | } |
| 47 | |
| 48 | void swap_mac_addressescxx . . $ swap_mac_addresses(5500c4293b1bbef0).(void *buffer, size_t len) |
| 49 | { |
| 50 | unsigned char tmp[ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!]; |
| 51 | struct ethhdrcxx . . $ ethhdr# *eth = buffer; |
| 52 | |
| 53 | if (len < sizeof(*eth)) |
| 54 | return; |
| 55 | |
| 56 | memcpycxx . . $ memcpy(cc817cb175f282d).(tmp, eth->h_sourcecxx . . $ ethhdr#h_source., sizeof(tmp)); |
| 57 | memcpycxx . . $ memcpy(cc817cb175f282d).(eth->h_sourcecxx . . $ ethhdr#h_source., eth->h_destcxx . . $ ethhdr#h_dest., sizeof(tmp)); |
| 58 | memcpycxx . . $ memcpy(cc817cb175f282d).(eth->h_destcxx . . $ ethhdr#h_dest., tmp, sizeof(tmp)); |
| 59 | } |
| 60 | |
| 61 | void insert_vlan_tagcxx . . $ insert_vlan_tag(136eef189baebb4d).(void *buffer, size_t len, uint16_tcxx . . $ uint16_t# vlan_tci) |
| 62 | { |
| 63 | struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *veth; |
| 64 | |
| 65 | if (len + sizeof(struct vlan_headercxx . . $ vlan_header#) > XDP_FRAME_SIZEcxx . . $ `src/xdp.h:34:9`!) |
| 66 | return; |
| 67 | |
| 68 | memmovecxx . . $ memmove(cc817cb175f282d).(buffer + 2 * ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`! + sizeof(struct vlan_headercxx . . $ vlan_header#), buffer + 2 * ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!, |
| 69 | len - 2 * ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 70 | |
| 71 | veth = buffer; |
| 72 | |
| 73 | veth->vlan_encapsulated_protocxx . . $ vlan_ethernet_header#vlan_encapsulated_proto. = htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_PROFINET_RTcxx . . $ `src/net_def.h:14:9`!); |
| 74 | veth->vlan_protocxx . . $ vlan_ethernet_header#vlan_proto. = htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_8021Qcxx . . $ `<external>/15209105680615352250/if_ether.h:71:9`!); |
| 75 | veth->vlantcicxx . . $ vlan_ethernet_header#vlantci. = htonscxx . . $ htons(a18c05e4017afb3d).(vlan_tci); |
| 76 | } |
| 77 | |
| 78 | void build_vlan_frame_from_rxcxx . . $ build_vlan_frame_from_rx(ba210f13e41aa3ab).(const unsigned char *old_frame, size_t old_frame_len, |
| 79 | unsigned char *new_frame, size_t new_frame_len, uint16_tcxx . . $ uint16_t# ether_type, |
| 80 | uint16_tcxx . . $ uint16_t# vlan_tci) |
| 81 | { |
| 82 | struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *eth_new, *eth_old; |
| 83 | |
| 84 | if (new_frame_len < old_frame_len + sizeof(struct vlan_headercxx . . $ vlan_header#)) |
| 85 | return; |
| 86 | |
| 87 | /* Copy payload */ |
| 88 | memcpycxx . . $ memcpy(cc817cb175f282d).(new_frame + ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`! * 2 + sizeof(struct vlan_headercxx . . $ vlan_header#), old_frame + ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`! * 2, |
| 89 | old_frame_len - ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`! * 2); |
| 90 | |
| 91 | /* Swap source destination */ |
| 92 | eth_new = (struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *)new_frame; |
| 93 | eth_old = (struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *)old_frame; |
| 94 | |
| 95 | memcpycxx . . $ memcpy(cc817cb175f282d).(eth_new->destinationcxx . . $ vlan_ethernet_header#destination., eth_old->sourcecxx . . $ vlan_ethernet_header#source., ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 96 | memcpycxx . . $ memcpy(cc817cb175f282d).(eth_new->sourcecxx . . $ vlan_ethernet_header#source., eth_old->destinationcxx . . $ vlan_ethernet_header#destination., ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 97 | |
| 98 | /* Inject VLAN info */ |
| 99 | eth_new->vlan_protocxx . . $ vlan_ethernet_header#vlan_proto. = htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_8021Qcxx . . $ `<external>/15209105680615352250/if_ether.h:71:9`!); |
| 100 | eth_new->vlantcicxx . . $ vlan_ethernet_header#vlantci. = htonscxx . . $ htons(a18c05e4017afb3d).(vlan_tci); |
| 101 | eth_new->vlan_encapsulated_protocxx . . $ vlan_ethernet_header#vlan_encapsulated_proto. = htonscxx . . $ htons(a18c05e4017afb3d).(ether_type); |
| 102 | } |
| 103 | |
| 104 | static void initialize_secure_profinet_framecxx . . $ initialize_secure_profinet_frame(305659cd59e50ce5).(enum security_modecxx . . $ security_mode# mode, unsigned char *frame_data, |
| 105 | size_t frame_length, const unsigned char *source, |
| 106 | const unsigned char *destination, |
| 107 | const char *payload_pattern, |
| 108 | size_t payload_pattern_length, uint16_tcxx . . $ uint16_t# vlan_tci, |
| 109 | uint16_tcxx . . $ uint16_t# frame_id) |
| 110 | { |
| 111 | struct profinet_secure_headercxx . . $ profinet_secure_header# *rt; |
| 112 | struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *eth; |
| 113 | uint16_tcxx . . $ uint16_t# security_length; |
| 114 | size_t payload_offset; |
| 115 | |
| 116 | /* Initialize to zero */ |
| 117 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(frame_data, '\0', frame_length); |
| 118 | |
| 119 | /* |
| 120 | * Profinet Frame: |
| 121 | * Destination |
| 122 | * Source |
| 123 | * VLAN tag: tpid 8100, id 0x00/0x101/102, dei 0, prio 6/5/4/3/2 |
| 124 | * Ether type: 8892 |
| 125 | * Frame id: TSN, RTC, RTA, DCP |
| 126 | * SecurityHeader |
| 127 | * Cycle counter |
| 128 | * Payload |
| 129 | * Padding to maxFrame - Checksum |
| 130 | * security_checksum |
| 131 | */ |
| 132 | |
| 133 | eth = (struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *)frame_data; |
| 134 | rt = (struct profinet_secure_headercxx . . $ profinet_secure_header# *)(frame_data + sizeof(*eth)); |
| 135 | |
| 136 | /* Ethernet header */ |
| 137 | memcpycxx . . $ memcpy(cc817cb175f282d).(eth->destinationcxx . . $ vlan_ethernet_header#destination., destination, ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 138 | memcpycxx . . $ memcpy(cc817cb175f282d).(eth->sourcecxx . . $ vlan_ethernet_header#source., source, ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 139 | |
| 140 | /* VLAN Header */ |
| 141 | eth->vlan_protocxx . . $ vlan_ethernet_header#vlan_proto. = htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_8021Qcxx . . $ `<external>/15209105680615352250/if_ether.h:71:9`!); |
| 142 | eth->vlantcicxx . . $ vlan_ethernet_header#vlantci. = htonscxx . . $ htons(a18c05e4017afb3d).(vlan_tci); |
| 143 | eth->vlan_encapsulated_protocxx . . $ vlan_ethernet_header#vlan_encapsulated_proto. = htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_PROFINET_RTcxx . . $ `src/net_def.h:14:9`!); |
| 144 | |
| 145 | /* Profinet Secure header */ |
| 146 | security_length = frame_length - sizeof(*eth) - sizeof(struct security_checksumcxx . . $ security_checksum#); |
| 147 | rt->frame_idcxx . . $ profinet_secure_header#frame_id. = htonscxx . . $ htons(a18c05e4017afb3d).(frame_id); |
| 148 | rt->security_meta_datacxx . . $ profinet_secure_header#security_meta_data..security_informationcxx . . $ security_meta_data#security_information. = mode == SECURITY_MODE_AOcxx . . $ SECURITY_MODE_AO. ? 0x00 : 0x01; |
| 149 | rt->security_meta_datacxx . . $ profinet_secure_header#security_meta_data..security_lengthcxx . . $ security_meta_data#security_length. = htobe16cxx . . $ `<external>/15855202785537844739/endian.h:39:11`!(security_length); |
| 150 | rt->meta_datacxx . . $ profinet_secure_header#meta_data..frame_countercxx . . $ reference_meta_data#frame_counter. = 0; |
| 151 | rt->meta_datacxx . . $ profinet_secure_header#meta_data..cycle_countercxx . . $ reference_meta_data#cycle_counter. = 0; |
| 152 | |
| 153 | /* Payload */ |
| 154 | payload_offset = sizeof(*eth) + sizeof(*rt); |
| 155 | memcpycxx . . $ memcpy(cc817cb175f282d).(frame_data + payload_offset, payload_pattern, payload_pattern_length); |
| 156 | |
| 157 | /* security_checksum is set to zero and calculated for each frame on Tx */ |
| 158 | } |
| 159 | |
| 160 | static void initialize_rt_profinet_framecxx . . $ initialize_rt_profinet_frame(733468d41246e4dd).(unsigned char *frame_data, size_t frame_length, |
| 161 | const unsigned char *source, |
| 162 | const unsigned char *destination, |
| 163 | const char *payload_pattern, size_t payload_pattern_length, |
| 164 | uint16_tcxx . . $ uint16_t# vlan_tci, uint16_tcxx . . $ uint16_t# frame_id) |
| 165 | { |
| 166 | struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *eth; |
| 167 | struct profinet_rt_headercxx . . $ profinet_rt_header# *rt; |
| 168 | size_t payload_offset; |
| 169 | |
| 170 | /* Initialize to zero */ |
| 171 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(frame_data, '\0', frame_length); |
| 172 | |
| 173 | /* |
| 174 | * Profinet Frame: |
| 175 | * Destination |
| 176 | * Source |
| 177 | * VLAN tag: tpid 8100, id 0x00/0x101/102, dei 0, prio 6/5/4/3/2 |
| 178 | * Ether type: 8892 |
| 179 | * Frame id: TSN, RTC, RTA, DCP |
| 180 | * Cycle counter |
| 181 | * Payload |
| 182 | * Padding to maxFrame |
| 183 | */ |
| 184 | |
| 185 | eth = (struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *)frame_data; |
| 186 | rt = (struct profinet_rt_headercxx . . $ profinet_rt_header# *)(frame_data + sizeof(*eth)); |
| 187 | |
| 188 | /* Ethernet header */ |
| 189 | memcpycxx . . $ memcpy(cc817cb175f282d).(eth->destinationcxx . . $ vlan_ethernet_header#destination., destination, ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 190 | memcpycxx . . $ memcpy(cc817cb175f282d).(eth->sourcecxx . . $ vlan_ethernet_header#source., source, ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!); |
| 191 | |
| 192 | /* VLAN Header */ |
| 193 | eth->vlan_protocxx . . $ vlan_ethernet_header#vlan_proto. = htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_8021Qcxx . . $ `<external>/15209105680615352250/if_ether.h:71:9`!); |
| 194 | eth->vlantcicxx . . $ vlan_ethernet_header#vlantci. = htonscxx . . $ htons(a18c05e4017afb3d).(vlan_tci); |
| 195 | eth->vlan_encapsulated_protocxx . . $ vlan_ethernet_header#vlan_encapsulated_proto. = htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_PROFINET_RTcxx . . $ `src/net_def.h:14:9`!); |
| 196 | |
| 197 | /* Profinet RT header */ |
| 198 | rt->frame_idcxx . . $ profinet_rt_header#frame_id. = htonscxx . . $ htons(a18c05e4017afb3d).(frame_id); |
| 199 | rt->meta_datacxx . . $ profinet_rt_header#meta_data..frame_countercxx . . $ reference_meta_data#frame_counter. = 0; |
| 200 | rt->meta_datacxx . . $ profinet_rt_header#meta_data..cycle_countercxx . . $ reference_meta_data#cycle_counter. = 0; |
| 201 | |
| 202 | /* Payload */ |
| 203 | payload_offset = sizeof(*eth) + sizeof(*rt); |
| 204 | memcpycxx . . $ memcpy(cc817cb175f282d).(frame_data + payload_offset, payload_pattern, payload_pattern_length); |
| 205 | } |
| 206 | |
| 207 | void initialize_profinet_framecxx . . $ initialize_profinet_frame(305659cd59e50ce5).(enum security_modecxx . . $ security_mode# mode, unsigned char *frame_data, |
| 208 | size_t frame_length, const unsigned char *source, |
| 209 | const unsigned char *destination, const char *payload_pattern, |
| 210 | size_t payload_pattern_length, uint16_tcxx . . $ uint16_t# vlan_tci, uint16_tcxx . . $ uint16_t# frame_id) |
| 211 | { |
| 212 | switch (mode) { |
| 213 | case SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE.: |
| 214 | initialize_rt_profinet_framecxx . . $ initialize_rt_profinet_frame(733468d41246e4dd).(frame_data, frame_length, source, destination, |
| 215 | payload_pattern, payload_pattern_length, vlan_tci, |
| 216 | frame_id); |
| 217 | break; |
| 218 | case SECURITY_MODE_AEcxx . . $ SECURITY_MODE_AE.: |
| 219 | case SECURITY_MODE_AOcxx . . $ SECURITY_MODE_AO.: |
| 220 | initialize_secure_profinet_framecxx . . $ initialize_secure_profinet_frame(305659cd59e50ce5).(mode, frame_data, frame_length, source, |
| 221 | destination, payload_pattern, |
| 222 | payload_pattern_length, vlan_tci, frame_id); |
| 223 | break; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | int receive_profinet_framecxx . . $ receive_profinet_frame(ddfd8079f1f43689).(void *data, unsigned char *frame_data, size_t len) |
| 228 | { |
| 229 | struct thread_contextcxx . . $ thread_context# *thread_context = data; |
| 230 | const struct traffic_class_configcxx . . $ traffic_class_config# *class_config = thread_context->confcxx . . $ thread_context#conf.; |
| 231 | const unsigned char *expected_pattern = |
| 232 | (const unsigned char *)class_config->payload_patterncxx . . $ traffic_class_config#payload_pattern.; |
| 233 | struct security_contextcxx . . $ security_context# *security_context = thread_context->rx_security_contextcxx . . $ thread_context#rx_security_context.; |
| 234 | const size_t expected_pattern_length = class_config->payload_pattern_lengthcxx . . $ traffic_class_config#payload_pattern_length.; |
| 235 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mirror_enabled = class_config->rx_mirror_enabledcxx . . $ traffic_class_config#rx_mirror_enabled.; |
| 236 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ignore_rx_errors = class_config->ignore_rx_errorscxx . . $ traffic_class_config#ignore_rx_errors.; |
| 237 | size_t expected_frame_length = class_config->frame_lengthcxx . . $ traffic_class_config#frame_length.; |
| 238 | uint64_tcxx . . $ uint64_t# tx_timestamp, rx_hw_timestamp, rx_sw_timestamp; |
| 239 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! out_of_order, payload_mismatch, frame_id_mismatch; |
| 240 | unsigned char plaintext[MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!]; |
| 241 | unsigned char new_frame[MAX_FRAME_SIZEcxx . . $ `src/thread.h:23:9`!]; |
| 242 | struct profinet_secure_headercxx . . $ profinet_secure_header# *srt; |
| 243 | struct profinet_rt_headercxx . . $ profinet_rt_header# *rt; |
| 244 | uint64_tcxx . . $ uint64_t# sequence_counter; |
| 245 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! vlan_tag_missing; |
| 246 | void *p = frame_data; |
| 247 | struct ethhdrcxx . . $ ethhdr# *eth; |
| 248 | uint16_tcxx . . $ uint16_t# frame_id; |
| 249 | uint16_tcxx . . $ uint16_t# proto; |
| 250 | |
| 251 | if (len < sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#)) { |
| 252 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "%sRx: Too small frame received!\n", |
| 253 | thread_context->traffic_classcxx . . $ thread_context#traffic_class.); |
| 254 | return -EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 255 | } |
| 256 | |
| 257 | eth = p; |
| 258 | if (eth->h_protocxx . . $ ethhdr#h_proto. == htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_8021Qcxx . . $ `<external>/15209105680615352250/if_ether.h:71:9`!)) { |
| 259 | struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *veth = p; |
| 260 | |
| 261 | proto = veth->vlan_encapsulated_protocxx . . $ vlan_ethernet_header#vlan_encapsulated_proto.; |
| 262 | p += sizeof(*veth); |
| 263 | vlan_tag_missing = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 264 | } else { |
| 265 | proto = eth->h_protocxx . . $ ethhdr#h_proto.; |
| 266 | p += sizeof(*eth); |
| 267 | expected_frame_length -= sizeof(struct vlan_headercxx . . $ vlan_header#); |
| 268 | vlan_tag_missing = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 269 | } |
| 270 | |
| 271 | if (proto != htonscxx . . $ htons(a18c05e4017afb3d).(ETH_P_PROFINET_RTcxx . . $ `src/net_def.h:14:9`!)) { |
| 272 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "%sRx: Not a Profinet frame received!\n", |
| 273 | thread_context->traffic_classcxx . . $ thread_context#traffic_class.); |
| 274 | return -EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 275 | } |
| 276 | |
| 277 | /* Check frame length: VLAN tag might be stripped or not. Check it. */ |
| 278 | if (len != expected_frame_length) { |
| 279 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "%sRx: Frame with wrong length received!\n", |
| 280 | thread_context->traffic_classcxx . . $ thread_context#traffic_class.); |
| 281 | return -EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 282 | } |
| 283 | |
| 284 | /* Check cycle counter, frame id range and payload. */ |
| 285 | if (class_config->security_modecxx . . $ traffic_class_config#security_mode. == SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE.) { |
| 286 | rt = p; |
| 287 | p += sizeof(*rt); |
| 288 | |
| 289 | frame_id = be16tohcxx . . $ `<external>/15855202785537844739/endian.h:41:11`!(rt->frame_id); |
| 290 | sequence_counter = meta_data_to_sequence_countercxx . . $ meta_data_to_sequence_counter(85d454852c71d7b9).( |
| 291 | &rt->meta_datacxx . . $ profinet_rt_header#meta_data., class_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 292 | |
| 293 | tx_timestamp = meta_data_to_tx_timestampcxx . . $ meta_data_to_tx_timestamp(e17106d766bd017c).(&rt->meta_datacxx . . $ profinet_rt_header#meta_data.); |
| 294 | set_mirror_tx_timestampcxx . . $ set_mirror_tx_timestamp(457bf14cd1570296).(&rt->meta_datacxx . . $ profinet_rt_header#meta_data.); |
| 295 | |
| 296 | } else if (class_config->security_modecxx . . $ traffic_class_config#security_mode. == SECURITY_MODE_AOcxx . . $ SECURITY_MODE_AO.) { |
| 297 | |
| 298 | unsigned char *begin_of_security_checksum; |
| 299 | unsigned char *begin_of_aad_data; |
| 300 | size_t size_of_eth_header; |
| 301 | size_t size_of_aad_data; |
| 302 | struct security_ivcxx . . $ security_iv# iv; |
| 303 | int ret; |
| 304 | |
| 305 | srt = p; |
| 306 | p += sizeof(*srt); |
| 307 | |
| 308 | frame_id = be16tohcxx . . $ `<external>/15855202785537844739/endian.h:41:11`!(srt->frame_id); |
| 309 | sequence_counter = meta_data_to_sequence_countercxx . . $ meta_data_to_sequence_counter(85d454852c71d7b9).( |
| 310 | &srt->meta_datacxx . . $ profinet_secure_header#meta_data., class_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 311 | |
| 312 | tx_timestamp = meta_data_to_tx_timestampcxx . . $ meta_data_to_tx_timestamp(e17106d766bd017c).(&srt->meta_datacxx . . $ profinet_secure_header#meta_data.); |
| 313 | |
| 314 | /* Authenticate received Profinet Frame */ |
| 315 | size_of_eth_header = vlan_tag_missing ? sizeof(struct ethhdrcxx . . $ ethhdr#) |
| 316 | : sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#); |
| 317 | |
| 318 | begin_of_aad_data = frame_data + size_of_eth_header; |
| 319 | size_of_aad_data = len - size_of_eth_header - sizeof(struct security_checksumcxx . . $ security_checksum#); |
| 320 | begin_of_security_checksum = frame_data + (len - sizeof(struct security_checksumcxx . . $ security_checksum#)); |
| 321 | |
| 322 | prepare_ivcxx . . $ prepare_iv(717f525d724fe2d8).((const unsigned char *)class_config->security_iv_prefixcxx . . $ traffic_class_config#security_iv_prefix., |
| 323 | sequence_counter, &iv); |
| 324 | |
| 325 | ret = security_decryptcxx . . $ security_decrypt(7be7b758f68f59b2).(security_context, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, begin_of_aad_data, |
| 326 | size_of_aad_data, begin_of_security_checksum, |
| 327 | (unsigned char *)&iv, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 328 | if (ret) |
| 329 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., |
| 330 | "%sRx: frame[%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! "] Not authentificated\n", |
| 331 | thread_context->traffic_classcxx . . $ thread_context#traffic_class., sequence_counter); |
| 332 | |
| 333 | set_mirror_tx_timestampcxx . . $ set_mirror_tx_timestamp(457bf14cd1570296).(&srt->meta_datacxx . . $ profinet_secure_header#meta_data.); |
| 334 | |
| 335 | security_encryptcxx . . $ security_encrypt(9b35fdd6c8552c6f).(security_context, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, begin_of_aad_data, size_of_aad_data, |
| 336 | (unsigned char *)&iv, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, begin_of_security_checksum); |
| 337 | |
| 338 | } else { |
| 339 | unsigned char *begin_of_security_checksum; |
| 340 | unsigned char *begin_of_ciphertext; |
| 341 | unsigned char *begin_of_aad_data; |
| 342 | size_t size_of_ciphertext; |
| 343 | size_t size_of_eth_header; |
| 344 | size_t size_of_aad_data; |
| 345 | struct security_ivcxx . . $ security_iv# iv; |
| 346 | int ret; |
| 347 | |
| 348 | srt = p; |
| 349 | |
| 350 | frame_id = be16tohcxx . . $ `<external>/15855202785537844739/endian.h:41:11`!(srt->frame_id); |
| 351 | sequence_counter = meta_data_to_sequence_countercxx . . $ meta_data_to_sequence_counter(85d454852c71d7b9).( |
| 352 | &srt->meta_datacxx . . $ profinet_secure_header#meta_data., class_config->num_frames_per_cyclecxx . . $ traffic_class_config#num_frames_per_cycle.); |
| 353 | |
| 354 | tx_timestamp = meta_data_to_tx_timestampcxx . . $ meta_data_to_tx_timestamp(e17106d766bd017c).(&srt->meta_datacxx . . $ profinet_secure_header#meta_data.); |
| 355 | |
| 356 | /* Authenticate received Profinet Frame */ |
| 357 | size_of_eth_header = vlan_tag_missing ? sizeof(struct ethhdrcxx . . $ ethhdr#) |
| 358 | : sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#); |
| 359 | |
| 360 | begin_of_aad_data = frame_data + size_of_eth_header; |
| 361 | size_of_aad_data = sizeof(*srt); |
| 362 | begin_of_security_checksum = frame_data + (len - sizeof(struct security_checksumcxx . . $ security_checksum#)); |
| 363 | begin_of_ciphertext = frame_data + size_of_eth_header + sizeof(*srt); |
| 364 | size_of_ciphertext = len - sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) - |
| 365 | sizeof(struct profinet_secure_headercxx . . $ profinet_secure_header#) - |
| 366 | sizeof(struct security_checksumcxx . . $ security_checksum#); |
| 367 | |
| 368 | prepare_ivcxx . . $ prepare_iv(717f525d724fe2d8).((const unsigned char *)class_config->security_iv_prefixcxx . . $ traffic_class_config#security_iv_prefix., |
| 369 | sequence_counter, &iv); |
| 370 | |
| 371 | ret = security_decryptcxx . . $ security_decrypt(7be7b758f68f59b2).(security_context, begin_of_ciphertext, size_of_ciphertext, |
| 372 | begin_of_aad_data, size_of_aad_data, |
| 373 | begin_of_security_checksum, (unsigned char *)&iv, plaintext); |
| 374 | if (ret) |
| 375 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., |
| 376 | "%sRx: frame[%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! "] Not authentificated and decrypted\n", |
| 377 | thread_context->traffic_classcxx . . $ thread_context#traffic_class., sequence_counter); |
| 378 | |
| 379 | /* plaintext points to the decrypted payload */ |
| 380 | p = plaintext; |
| 381 | |
| 382 | set_mirror_tx_timestampcxx . . $ set_mirror_tx_timestamp(457bf14cd1570296).(&srt->meta_datacxx . . $ profinet_secure_header#meta_data.); |
| 383 | |
| 384 | security_encryptcxx . . $ security_encrypt(9b35fdd6c8552c6f).(security_context, thread_context->payload_patterncxx . . $ thread_context#payload_pattern., |
| 385 | thread_context->payload_pattern_lengthcxx . . $ thread_context#payload_pattern_length., begin_of_aad_data, |
| 386 | size_of_aad_data, (unsigned char *)&iv, begin_of_ciphertext, |
| 387 | begin_of_security_checksum); |
| 388 | } |
| 389 | |
| 390 | xdp_get_timestamp_metadatacxx . . $ xdp_get_timestamp_metadata(cb618da060df1bcb).(frame_data, &rx_hw_timestamp, &rx_sw_timestamp); |
| 391 | out_of_order = sequence_counter != thread_context->rx_sequence_countercxx . . $ thread_context#rx_sequence_counter.; |
| 392 | payload_mismatch = memcmpcxx . . $ memcmp(36f949851efa3055).(p, expected_pattern, expected_pattern_length); |
| 393 | frame_id_mismatch = frame_id != thread_context->frame_idcxx . . $ thread_context#frame_id.; |
| 394 | |
| 395 | stat_frame_receivedcxx . . $ stat_frame_received(5534a29e0120fff).(thread_context->frame_typecxx . . $ thread_context#frame_type., sequence_counter, out_of_order, |
| 396 | payload_mismatch, frame_id_mismatch, tx_timestamp, rx_hw_timestamp, |
| 397 | rx_sw_timestamp); |
| 398 | |
| 399 | if (frame_id_mismatch) |
| 400 | log_messagecxx . . $ log_message(171546b8a219727a).( |
| 401 | LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "%sRx: frame[%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! "] FrameId mismatch: 0x%4x!\n", |
| 402 | thread_context->traffic_classcxx . . $ thread_context#traffic_class., sequence_counter, thread_context->frame_idcxx . . $ thread_context#frame_id.); |
| 403 | |
| 404 | if (out_of_order) { |
| 405 | if (!ignore_rx_errors) |
| 406 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., |
| 407 | "%sRx: frame[%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! "] SequenceCounter mismatch: %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 408 | "!\n", |
| 409 | thread_context->traffic_classcxx . . $ thread_context#traffic_class., sequence_counter, |
| 410 | thread_context->rx_sequence_countercxx . . $ thread_context#rx_sequence_counter.); |
| 411 | thread_context->rx_sequence_countercxx . . $ thread_context#rx_sequence_counter.++; |
| 412 | } |
| 413 | |
| 414 | if (payload_mismatch) |
| 415 | log_messagecxx . . $ log_message(171546b8a219727a).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., |
| 416 | "%sRx: frame[%" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! "] Payload Pattern mismatch!\n", |
| 417 | thread_context->traffic_classcxx . . $ thread_context#traffic_class., sequence_counter); |
| 418 | |
| 419 | thread_context->rx_sequence_countercxx . . $ thread_context#rx_sequence_counter.++; |
| 420 | |
| 421 | /* |
| 422 | * If mirror enabled, assemble and store the frame for Tx later. |
| 423 | * |
| 424 | * In case of XDP the Rx umem area will be reused for Tx. |
| 425 | */ |
| 426 | if (!mirror_enabled) |
| 427 | return 0; |
| 428 | |
| 429 | if (class_config->xdp_enabledcxx . . $ traffic_class_config#xdp_enabled.) { |
| 430 | /* Re-add vlan tag */ |
| 431 | if (vlan_tag_missing) |
| 432 | insert_vlan_tagcxx . . $ insert_vlan_tag(136eef189baebb4d).(frame_data, len, |
| 433 | class_config->vidcxx . . $ traffic_class_config#vid. | class_config->pcpcxx . . $ traffic_class_config#pcp. << VLAN_PCP_SHIFTcxx . . $ `src/net_def.h:26:9`!); |
| 434 | |
| 435 | /* Swap mac addresses inline */ |
| 436 | swap_mac_addressescxx . . $ swap_mac_addresses(5500c4293b1bbef0).(frame_data, len); |
| 437 | } else { |
| 438 | /* Build new frame for Tx with VLAN info. */ |
| 439 | build_vlan_frame_from_rxcxx . . $ build_vlan_frame_from_rx(ba210f13e41aa3ab).(frame_data, len, new_frame, sizeof(new_frame), |
| 440 | ETH_P_PROFINET_RTcxx . . $ `src/net_def.h:14:9`!, |
| 441 | class_config->vidcxx . . $ traffic_class_config#vid. | class_config->pcpcxx . . $ traffic_class_config#pcp. << VLAN_PCP_SHIFTcxx . . $ `src/net_def.h:26:9`!); |
| 442 | |
| 443 | /* Store the new frame. */ |
| 444 | ring_buffer_addcxx . . $ ring_buffer_add(5f1d237704bb7e40).(thread_context->mirror_buffercxx . . $ thread_context#mirror_buffer., new_frame, |
| 445 | len + sizeof(struct vlan_headercxx . . $ vlan_header#)); |
| 446 | } |
| 447 | |
| 448 | /* RTA is a burst traffic class and needs to update num_frames_available */ |
| 449 | if (thread_context->frame_typecxx . . $ thread_context#frame_type. == RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE.) { |
| 450 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 451 | thread_context->num_frames_availablecxx . . $ thread_context#num_frames_available.++; |
| 452 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&thread_context->data_mutexcxx . . $ thread_context#data_mutex.); |
| 453 | } |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | int prepare_frame_for_txcxx . . $ prepare_frame_for_tx(f7c7fe1588440d5a).(const struct prepare_frame_configcxx . . $ prepare_frame_config# *frame_config) |
| 459 | { |
| 460 | /* mode == NONE may be called from PROFINET or GenericL2 */ |
| 461 | if (frame_config->modecxx . . $ prepare_frame_config#mode. == SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE.) { |
| 462 | /* Adjust meta data in frame */ |
| 463 | struct reference_meta_datacxx . . $ reference_meta_data# *meta_data = |
| 464 | (struct reference_meta_datacxx . . $ reference_meta_data# *)(frame_config->frame_datacxx . . $ prepare_frame_config#frame_data. + |
| 465 | frame_config->meta_data_offsetcxx . . $ prepare_frame_config#meta_data_offset.); |
| 466 | |
| 467 | sequence_counter_to_meta_datacxx . . $ sequence_counter_to_meta_data(9318332f0006d3bc).(meta_data, frame_config->sequence_countercxx . . $ prepare_frame_config#sequence_counter., |
| 468 | frame_config->num_frames_per_cyclecxx . . $ prepare_frame_config#num_frames_per_cycle.); |
| 469 | |
| 470 | tx_timestamp_to_meta_datacxx . . $ tx_timestamp_to_meta_data(d237292223698be2).(meta_data, frame_config->tx_timestampcxx . . $ prepare_frame_config#tx_timestamp.); |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | /* mode == AO is PROFINET specific */ |
| 475 | else if (frame_config->modecxx . . $ prepare_frame_config#mode. == SECURITY_MODE_AOcxx . . $ SECURITY_MODE_AO.) { |
| 476 | unsigned char *begin_of_security_checksum; |
| 477 | struct profinet_secure_headercxx . . $ profinet_secure_header# *srt; |
| 478 | struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *eth; |
| 479 | unsigned char *begin_of_aad_data; |
| 480 | struct security_ivcxx . . $ security_iv# iv; |
| 481 | size_t size_of_aad_data; |
| 482 | |
| 483 | /* Adjust meta data first */ |
| 484 | srt = (struct profinet_secure_headercxx . . $ profinet_secure_header# *)(frame_config->frame_datacxx . . $ prepare_frame_config#frame_data. + sizeof(*eth)); |
| 485 | sequence_counter_to_meta_datacxx . . $ sequence_counter_to_meta_data(9318332f0006d3bc).(&srt->meta_datacxx . . $ profinet_secure_header#meta_data., frame_config->sequence_countercxx . . $ prepare_frame_config#sequence_counter., |
| 486 | frame_config->num_frames_per_cyclecxx . . $ prepare_frame_config#num_frames_per_cycle.); |
| 487 | |
| 488 | tx_timestamp_to_meta_datacxx . . $ tx_timestamp_to_meta_data(d237292223698be2).(&srt->meta_datacxx . . $ profinet_secure_header#meta_data., frame_config->tx_timestampcxx . . $ prepare_frame_config#tx_timestamp.); |
| 489 | |
| 490 | /* |
| 491 | * Then, calculate checksum over data and store it at the end of the frame. The |
| 492 | * authenfication spans begins with the FrameID and ends before the final security |
| 493 | * checksum. |
| 494 | */ |
| 495 | prepare_ivcxx . . $ prepare_iv(717f525d724fe2d8).(frame_config->iv_prefixcxx . . $ prepare_frame_config#iv_prefix., frame_config->sequence_countercxx . . $ prepare_frame_config#sequence_counter., &iv); |
| 496 | begin_of_aad_data = frame_config->frame_datacxx . . $ prepare_frame_config#frame_data. + sizeof(*eth); |
| 497 | size_of_aad_data = frame_config->frame_lengthcxx . . $ prepare_frame_config#frame_length. - sizeof(*eth) - |
| 498 | sizeof(struct security_checksumcxx . . $ security_checksum#); |
| 499 | begin_of_security_checksum = |
| 500 | frame_config->frame_datacxx . . $ prepare_frame_config#frame_data. + |
| 501 | (frame_config->frame_lengthcxx . . $ prepare_frame_config#frame_length. - sizeof(struct security_checksumcxx . . $ security_checksum#)); |
| 502 | return security_encryptcxx . . $ security_encrypt(9b35fdd6c8552c6f).(frame_config->security_contextcxx . . $ prepare_frame_config#security_context., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, begin_of_aad_data, |
| 503 | size_of_aad_data, (unsigned char *)&iv, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 504 | begin_of_security_checksum); |
| 505 | } |
| 506 | /* mode == AE is PROFINET specific too */ |
| 507 | else { |
| 508 | unsigned char *begin_of_security_checksum; |
| 509 | unsigned char *begin_of_ciphertext; |
| 510 | struct profinet_secure_headercxx . . $ profinet_secure_header# *srt; |
| 511 | struct vlan_ethernet_headercxx . . $ vlan_ethernet_header# *eth; |
| 512 | unsigned char *begin_of_aad_data; |
| 513 | struct security_ivcxx . . $ security_iv# iv; |
| 514 | size_t size_of_aad_data; |
| 515 | |
| 516 | /* Adjust cycle counter first */ |
| 517 | srt = (struct profinet_secure_headercxx . . $ profinet_secure_header# *)(frame_config->frame_datacxx . . $ prepare_frame_config#frame_data. + sizeof(*eth)); |
| 518 | sequence_counter_to_meta_datacxx . . $ sequence_counter_to_meta_data(9318332f0006d3bc).(&srt->meta_datacxx . . $ profinet_secure_header#meta_data., frame_config->sequence_countercxx . . $ prepare_frame_config#sequence_counter., |
| 519 | frame_config->num_frames_per_cyclecxx . . $ prepare_frame_config#num_frames_per_cycle.); |
| 520 | |
| 521 | tx_timestamp_to_meta_datacxx . . $ tx_timestamp_to_meta_data(d237292223698be2).(&srt->meta_datacxx . . $ profinet_secure_header#meta_data., frame_config->tx_timestampcxx . . $ prepare_frame_config#tx_timestamp.); |
| 522 | |
| 523 | /* |
| 524 | * Then, calculate checksum over data and store it at the end of the frame. The |
| 525 | * authenfication spans begins with the FrameID and ends before the final security |
| 526 | * checksum. In addition, the payload pattern in encrypted and stored in the frame. |
| 527 | */ |
| 528 | prepare_ivcxx . . $ prepare_iv(717f525d724fe2d8).(frame_config->iv_prefixcxx . . $ prepare_frame_config#iv_prefix., frame_config->sequence_countercxx . . $ prepare_frame_config#sequence_counter., &iv); |
| 529 | begin_of_aad_data = frame_config->frame_datacxx . . $ prepare_frame_config#frame_data. + sizeof(*eth); |
| 530 | size_of_aad_data = sizeof(*srt); |
| 531 | begin_of_security_checksum = |
| 532 | frame_config->frame_datacxx . . $ prepare_frame_config#frame_data. + |
| 533 | (frame_config->frame_lengthcxx . . $ prepare_frame_config#frame_length. - sizeof(struct security_checksumcxx . . $ security_checksum#)); |
| 534 | begin_of_ciphertext = frame_config->frame_datacxx . . $ prepare_frame_config#frame_data. + sizeof(*eth) + sizeof(*srt); |
| 535 | return security_encryptcxx . . $ security_encrypt(9b35fdd6c8552c6f).( |
| 536 | frame_config->security_contextcxx . . $ prepare_frame_config#security_context., frame_config->payload_patterncxx . . $ prepare_frame_config#payload_pattern., |
| 537 | frame_config->payload_pattern_lengthcxx . . $ prepare_frame_config#payload_pattern_length., begin_of_aad_data, size_of_aad_data, |
| 538 | (unsigned char *)&iv, begin_of_ciphertext, begin_of_security_checksum); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | void prepare_ivcxx . . $ prepare_iv(717f525d724fe2d8).(const unsigned char *iv_prefix, uint64_tcxx . . $ uint64_t# sequence_counter, struct security_ivcxx . . $ security_iv# *iv) |
| 543 | { |
| 544 | /* |
| 545 | * The initial vector is constructed by concatenating IvPrefix | sequenceCounter. The prefix |
| 546 | * and the counter consist of six bytes each. Therefore, the sequenceCounter is converted to |
| 547 | * LE to ignore the last two upper bytes. That leaves 2^48 possible counter values to create |
| 548 | * unique IVs. |
| 549 | */ |
| 550 | |
| 551 | memcpycxx . . $ memcpy(cc817cb175f282d).(iv->iv_prefixcxx . . $ security_iv#iv_prefix., iv_prefix, SECURITY_IV_PREFIX_LENcxx . . $ `src/security.h:58:9`!); |
| 552 | iv->countercxx . . $ security_iv#counter. = htole64cxx . . $ `<external>/15855202785537844739/endian.h:50:11`!(sequence_counter); |
| 553 | } |
| 554 | |
| 555 | void prepare_opensslcxx . . $ prepare_openssl(180fdc1b6a791d79).(struct security_contextcxx . . $ security_context# *context) |
| 556 | { |
| 557 | unsigned char iv[SECURITY_IV_LENcxx . . $ `src/security.h:57:9`!] = "012345678901"; |
| 558 | unsigned char dummy_frame[2048] = {5}; |
| 559 | |
| 560 | if (!context) |
| 561 | return; |
| 562 | |
| 563 | security_encryptcxx . . $ security_encrypt(9b35fdd6c8552c6f).(context, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, dummy_frame, |
| 564 | sizeof(dummy_frame) - sizeof(struct security_checksumcxx . . $ security_checksum#), iv, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 565 | dummy_frame + sizeof(dummy_frame) - sizeof(struct security_checksumcxx . . $ security_checksum#)); |
| 566 | |
| 567 | security_decryptcxx . . $ security_decrypt(7be7b758f68f59b2).(context, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, dummy_frame, |
| 568 | sizeof(dummy_frame) - sizeof(struct security_checksumcxx . . $ security_checksum#), |
| 569 | dummy_frame + sizeof(dummy_frame) - sizeof(struct security_checksumcxx . . $ security_checksum#), iv, |
| 570 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 571 | } |
| 572 | |
| 573 | int get_thread_start_timecxx . . $ get_thread_start_time(72e9d11157e5bc5a).(uint64_tcxx . . $ uint64_t# base_offset, struct timespeccxx . . $ timespec# *wakeup_time) |
| 574 | { |
| 575 | const uint64_tcxx . . $ uint64_t# base_start_offset = app_configcxx . . $ app_config..application_base_start_offset_nscxx . . $ application_config#application_base_start_offset_ns.; |
| 576 | const uint64_tcxx . . $ uint64_t# base_start_time = app_configcxx . . $ app_config..application_base_start_time_nscxx . . $ application_config#application_base_start_time_ns.; |
| 577 | const clockid_tcxx . . $ clockid_t# profinet_clock_id = app_configcxx . . $ app_config..application_clock_idcxx . . $ application_config#application_clock_id.; |
| 578 | int ret = 0; |
| 579 | |
| 580 | if (base_start_time) |
| 581 | ns_to_tscxx . . $ ns_to_ts(18e44028df9850c9).(base_start_time + base_start_offset + base_offset, wakeup_time); |
| 582 | else |
| 583 | ret = clock_gettimecxx . . $ clock_gettime(65aaefb2502b4987).(profinet_clock_id, wakeup_time); |
| 584 | |
| 585 | return ret; |
| 586 | } |
| 587 | |
| 588 | static int latency_fdcxx . . $ latency_fd. = -1; |
| 589 | |
| 590 | void configure_cpu_latencycxx . . $ configure_cpu_latency(49f6e7a06ebc5aa8).(void) |
| 591 | { |
| 592 | /* Avoid the CPU to enter deep sleep states */ |
| 593 | int32_tcxx . . $ int32_t# lat = 0; |
| 594 | ssize_tcxx . . $ ssize_t# ret; |
| 595 | int fd; |
| 596 | |
| 597 | fd = opencxx . . $ open(e156e3aa1e5c4ad1).("/dev/cpu_dma_latency", O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!); |
| 598 | if (fd == -1) |
| 599 | return; |
| 600 | |
| 601 | ret = writecxx . . $ write(41184a59d38b4f65).(fd, &lat, sizeof(lat)); |
| 602 | if (ret != sizeof(lat)) { |
| 603 | closecxx . . $ close(7864480464b09eea).(latency_fdcxx . . $ latency_fd.); |
| 604 | return; |
| 605 | } |
| 606 | |
| 607 | latency_fdcxx . . $ latency_fd. = fd; |
| 608 | } |
| 609 | |
| 610 | void restore_cpu_latencycxx . . $ restore_cpu_latency(49f6e7a06ebc5aa8).(void) |
| 611 | { |
| 612 | if (latency_fdcxx . . $ latency_fd. > 0) |
| 613 | closecxx . . $ close(7864480464b09eea).(latency_fdcxx . . $ latency_fd.); |
| 614 | } |
| 615 | |
| 616 | void print_mac_addresscxx . . $ print_mac_address(28caea9380bfac8a).(const unsigned char *mac_address) |
| 617 | { |
| 618 | int i; |
| 619 | |
| 620 | for (i = 0; i < ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`!; ++i) { |
| 621 | printfcxx . . $ printf(581fddd72a8db8fc).("%02x", mac_address[i]); |
| 622 | if (i != ETH_ALENcxx . . $ `<external>/15209105680615352250/if_ether.h:32:9`! - 1) |
| 623 | printfcxx . . $ printf(581fddd72a8db8fc).("-"); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | void print_payload_patterncxx . . $ print_payload_pattern(7cafb6e0818eff3b).(const char *payload_pattern, size_t payload_pattern_length) |
| 628 | { |
| 629 | size_t i; |
| 630 | |
| 631 | for (i = 0; i < payload_pattern_length; ++i) |
| 632 | printfcxx . . $ printf(581fddd72a8db8fc).("0x%02x ", payload_pattern[i]); |
| 633 | } |
| 634 | |
| 635 | uint32_tcxx . . $ uint32_t# get_meta_data_offsetcxx . . $ get_meta_data_offset(16cb9e606c8e3615).(enum stat_frame_typecxx . . $ stat_frame_type# frame_type, enum security_modecxx . . $ security_mode# security_mode) |
| 636 | { |
| 637 | uint32_tcxx . . $ uint32_t# meta_data_offset = 0; |
| 638 | |
| 639 | switch (frame_type) { |
| 640 | /* PROFINET Frames w/o security headers */ |
| 641 | case TSN_HIGH_FRAME_TYPEcxx . . $ TSN_HIGH_FRAME_TYPE.: |
| 642 | case TSN_LOW_FRAME_TYPEcxx . . $ TSN_LOW_FRAME_TYPE.: |
| 643 | case RTC_FRAME_TYPEcxx . . $ RTC_FRAME_TYPE.: |
| 644 | case RTA_FRAME_TYPEcxx . . $ RTA_FRAME_TYPE.: |
| 645 | case DCP_FRAME_TYPEcxx . . $ DCP_FRAME_TYPE.: |
| 646 | switch (security_mode) { |
| 647 | case SECURITY_MODE_NONEcxx . . $ SECURITY_MODE_NONE.: |
| 648 | meta_data_offset = sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + |
| 649 | offsetofcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:431:9`!(struct profinet_rt_header, meta_data); |
| 650 | break; |
| 651 | default: |
| 652 | meta_data_offset = sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + |
| 653 | offsetofcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:431:9`!(struct profinet_secure_header, meta_data); |
| 654 | } |
| 655 | break; |
| 656 | /* LLDP without VLAN */ |
| 657 | case LLDP_FRAME_TYPEcxx . . $ LLDP_FRAME_TYPE.: |
| 658 | meta_data_offset = sizeof(struct ethhdrcxx . . $ ethhdr#); |
| 659 | break; |
| 660 | /* UDP without any headers */ |
| 661 | case UDP_HIGH_FRAME_TYPEcxx . . $ UDP_HIGH_FRAME_TYPE.: |
| 662 | case UDP_LOW_FRAME_TYPEcxx . . $ UDP_LOW_FRAME_TYPE.: |
| 663 | meta_data_offset = 0; |
| 664 | break; |
| 665 | /* GenericL2 has its own frame layout */ |
| 666 | case GENERICL2_FRAME_TYPEcxx . . $ GENERICL2_FRAME_TYPE.: |
| 667 | meta_data_offset = sizeof(struct vlan_ethernet_headercxx . . $ vlan_ethernet_header#) + |
| 668 | offsetofcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:431:9`!(struct generic_l2_header, meta_data); |
| 669 | break; |
| 670 | case NUM_FRAME_TYPEScxx . . $ NUM_FRAME_TYPES.: |
| 671 | meta_data_offset = 0; |
| 672 | break; |
| 673 | } |
| 674 | |
| 675 | return meta_data_offset; |
| 676 | } |