/src/PcapPlusPlus/Packet++/header/SomeIpSdLayer.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "EndianPortable.h" |
4 | | #include "IpAddress.h" |
5 | | #include "Layer.h" |
6 | | #include "SomeIpLayer.h" |
7 | | #include <cstring> |
8 | | #include <iterator> |
9 | | #include <unordered_map> |
10 | | #include <memory> |
11 | | #include <stdexcept> |
12 | | #include <vector> |
13 | | |
14 | | /// @file |
15 | | |
16 | | /** |
17 | | * \namespace pcpp |
18 | | * \brief The main namespace for the PcapPlusPlus lib |
19 | | */ |
20 | | namespace pcpp |
21 | | { |
22 | | /** |
23 | | * Types of protocols that can be referenced in SOME/IP-SD |
24 | | */ |
25 | | enum SomeIpSdProtocolType : uint8_t |
26 | | { |
27 | | /** TCP */ |
28 | | SD_TCP = 0x06, |
29 | | /** UDP */ |
30 | | SD_UDP = 0x11 |
31 | | }; |
32 | | |
33 | | class SomeIpSdLayer; |
34 | | |
35 | | /** |
36 | | * @class SomeIpSdOption |
37 | | * Base class of the SOME/IP-SD options. Cannot be instantiated. |
38 | | */ |
39 | | class SomeIpSdOption |
40 | | { |
41 | | public: |
42 | | friend class SomeIpSdLayer; |
43 | | |
44 | | /** |
45 | | * Types of options currently available for the SOME/IP-SD protocol |
46 | | */ |
47 | | enum class OptionType : uint8_t |
48 | | { |
49 | | /** Unknown Option Type */ |
50 | | Unknown = 0x00, |
51 | | /** Configuration Option */ |
52 | | ConfigurationString = 0x01, |
53 | | /** Load Balancing Option */ |
54 | | LoadBalancing = 0x02, |
55 | | /** IPv4 Endpoint Option */ |
56 | | IPv4Endpoint = 0x04, |
57 | | /** IPv6 Endpoint Option */ |
58 | | IPv6Endpoint = 0x06, |
59 | | /** IPv4 Multicast Option */ |
60 | | IPv4Multicast = 0x14, |
61 | | /** IPv6 Multicast Option */ |
62 | | IPv6Multicast = 0x16, |
63 | | /** IPv4 SD Endpoint Option */ |
64 | | IPv4SdEndpoint = 0x24, |
65 | | /** IPv6 SD Endpoint Option */ |
66 | | IPv6SdEndpoint = 0x26 |
67 | | }; |
68 | | |
69 | | /** |
70 | | * @struct someipsdhdroptionsbase |
71 | | * Represents the common base for SOME/IP-SD header options |
72 | | */ |
73 | | #pragma pack(push, 1) |
74 | | struct someipsdhdroptionsbase |
75 | | { |
76 | | /** Length - excluding the 16 bit Length field and the 8 bit type flag */ |
77 | | uint16_t length; |
78 | | /** Type */ |
79 | | uint8_t type; |
80 | | /** Reserved */ |
81 | | uint8_t reserved; |
82 | | }; |
83 | | #pragma pack(pop) |
84 | | |
85 | | /** |
86 | | * Destroy the SOME/IP-SD Option object and delete allocated data if it has been allocated by a constructor |
87 | | */ |
88 | | virtual ~SomeIpSdOption(); |
89 | | |
90 | | /** |
91 | | * Get the Option Type |
92 | | * @return OptionType |
93 | | */ |
94 | | OptionType getType() const; |
95 | | |
96 | | /** |
97 | | * Get the Length of the SOME/IP-SD option |
98 | | * @return size_t |
99 | | */ |
100 | 0 | size_t getLength() const { return m_DataLen; } |
101 | | |
102 | | /** |
103 | | * Get the internal data of the SOME/IP-SD Option |
104 | | * @return uint8_t* |
105 | | */ |
106 | | uint8_t *getDataPtr() const; |
107 | | |
108 | | /** |
109 | | * Get a pointer to the SOME/IP-SD Option base header |
110 | | * @return someipsdhdroptionsbase* |
111 | | */ |
112 | | someipsdhdroptionsbase *getSomeIpSdOptionHeader() const; |
113 | | |
114 | | protected: |
115 | | const IDataContainer *m_DataContainer; |
116 | | size_t m_Offset; |
117 | | uint8_t *m_ShadowData; |
118 | | size_t m_DataLen; |
119 | | |
120 | 0 | SomeIpSdOption() : m_DataContainer(nullptr), m_Offset(0), m_ShadowData(nullptr), m_DataLen(0) {} |
121 | | |
122 | | SomeIpSdOption(const IDataContainer *dataContainer, size_t offset) |
123 | 1.49k | : m_DataContainer(dataContainer), m_Offset(offset), m_ShadowData(nullptr), m_DataLen(0) {} |
124 | | |
125 | | void initStdFields(OptionType type); |
126 | | |
127 | | SomeIpSdOption(const SomeIpSdOption &) = delete; |
128 | | SomeIpSdOption &operator=(const SomeIpSdOption &) = delete; |
129 | | }; |
130 | | |
131 | | /** |
132 | | * @class SomeIpSdIPv4Option |
133 | | * Implements the following SOME/IP-SD Options: IPv4 Endpoint, IPv4 Multicast, IPv4 SD Endpoint |
134 | | */ |
135 | | class SomeIpSdIPv4Option : public SomeIpSdOption |
136 | | { |
137 | | public: |
138 | | friend class SomeIpSdLayer; |
139 | | |
140 | | /** |
141 | | * Types of options which are implemented with this class |
142 | | */ |
143 | | enum IPv4OptionType |
144 | | { |
145 | | /** IPv4 Endpoint Option */ |
146 | | IPv4Endpoint, |
147 | | /** IPv4 Multicast Option */ |
148 | | IPv4Multicast, |
149 | | /** IPv4 SD Endpoint Option */ |
150 | | IPv4SdEndpoint, |
151 | | }; |
152 | | |
153 | | /** |
154 | | * Construct a new SomeIpSdIPv4 Option object |
155 | | * @param[in] type IPv4 Option type |
156 | | * @param[in] ipAddress Ipv4 address to use |
157 | | * @param[in] port Port to use |
158 | | * @param[in] l4Protocol Protocol to use |
159 | | */ |
160 | | SomeIpSdIPv4Option(IPv4OptionType type, IPv4Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol); |
161 | | |
162 | | /** |
163 | | * Construct a new SomeIpSdIPv4 Option object from already existing memory |
164 | | * @param[in] dataContainer Data containing the SomeIpSdIPv4 Option object |
165 | | * @param[in] offset Offset for dataContainer |
166 | | */ |
167 | | SomeIpSdIPv4Option(const IDataContainer *dataContainer, size_t offset); |
168 | | |
169 | | /** |
170 | | * Get the Ip Address |
171 | | * @return IPv4Address |
172 | | */ |
173 | | IPv4Address getIpAddress() const; |
174 | | |
175 | | /** |
176 | | * Get the Port |
177 | | * @return uint16_t |
178 | | */ |
179 | | uint16_t getPort() const; |
180 | | |
181 | | /** |
182 | | * Get the Protocol |
183 | | * @return SomeIpSdProtocolType |
184 | | */ |
185 | | SomeIpSdProtocolType getProtocol() const; |
186 | | |
187 | | private: |
188 | | /** |
189 | | * @struct someipsdhdroptionsipv4 |
190 | | * Represents the IPv4 option types for the SOME/IP-SD header |
191 | | */ |
192 | | #pragma pack(push, 1) |
193 | | struct someipsdhdroptionsipv4 : someipsdhdroptionsbase |
194 | | { |
195 | | /* IPv4-Address field */ |
196 | | uint32_t ipv4Address; |
197 | | /* Reserved */ |
198 | | // cppcheck-suppress duplInheritedMember |
199 | | uint8_t reserved; |
200 | | /* Layer 4 Protocol field (L4-Proto) - Either UDP or TCP */ |
201 | | SomeIpSdProtocolType l4Protocol; |
202 | | /* Port number of UDP or TCP */ |
203 | | uint16_t portNumber; |
204 | | }; |
205 | | #pragma pack(pop) |
206 | | }; |
207 | | |
208 | | /** |
209 | | * @class SomeIpSdIPv6Option |
210 | | * Implements the following SOME/IP-SD Options: IPv6 Endpoint, IPv6 Multicast, IPv6 SD Endpoint |
211 | | */ |
212 | | class SomeIpSdIPv6Option : public SomeIpSdOption |
213 | | { |
214 | | public: |
215 | | friend class SomeIpSdLayer; |
216 | | |
217 | | /** |
218 | | * Types of options which are implemented with this class |
219 | | */ |
220 | | enum IPv6OptionType |
221 | | { |
222 | | /** IPv6 Endpoint Option */ |
223 | | IPv6Endpoint, |
224 | | /** IPv6 Multicast Option */ |
225 | | IPv6Multicast, |
226 | | /** IPv6 SD Endpoint Option */ |
227 | | IPv6SdEndpoint, |
228 | | }; |
229 | | |
230 | | /** |
231 | | * Construct a new SomeIpSdIPv6 Option object |
232 | | * @param[in] type IPv6 Option type |
233 | | * @param[in] ipAddress Ipv6 address to use |
234 | | * @param[in] port Port to use |
235 | | * @param[in] l4Protocol Protocol to use |
236 | | */ |
237 | | SomeIpSdIPv6Option(IPv6OptionType type, IPv6Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol); |
238 | | |
239 | | /** |
240 | | * Construct a new SomeIpSdIPv6 Option object from already existing memory |
241 | | * @param[in] dataContainer Data containing the SomeIpSdIPv6 Option object |
242 | | * @param[in] offset Offset for dataContainer |
243 | | */ |
244 | | SomeIpSdIPv6Option(const IDataContainer *dataContainer, size_t offset); |
245 | | |
246 | | /** |
247 | | * Get the Ip Address |
248 | | * @return IPv6Address |
249 | | */ |
250 | | IPv6Address getIpAddress() const; |
251 | | |
252 | | /** |
253 | | * Get the Port |
254 | | * @return uint16_t |
255 | | */ |
256 | | uint16_t getPort() const; |
257 | | |
258 | | /** |
259 | | * Get the Protocol |
260 | | * @return SomeIpSdProtocolType |
261 | | */ |
262 | | SomeIpSdProtocolType getProtocol() const; |
263 | | |
264 | | private: |
265 | | /** |
266 | | * @struct someipsdhdroptionsipv6 |
267 | | * Represents the IPv6 option types for the SOME/IP-SD header |
268 | | */ |
269 | | #pragma pack(push, 1) |
270 | | struct someipsdhdroptionsipv6 : someipsdhdroptionsbase |
271 | | { |
272 | | /* IPv6-Address field */ |
273 | | uint8_t ipv6Address[16]; |
274 | | /* Reserved */ |
275 | | // cppcheck-suppress duplInheritedMember |
276 | | uint8_t reserved; |
277 | | /* Layer 4 Protocol field (L4-Proto) - Either UDP or TCP */ |
278 | | SomeIpSdProtocolType l4Protocol; |
279 | | /* Port number of UDP or TCP */ |
280 | | uint16_t portNumber; |
281 | | }; |
282 | | #pragma pack(pop) |
283 | | }; |
284 | | |
285 | | /** |
286 | | * @class SomeIpSdConfigurationOption |
287 | | * Implements the Configuration option of SOME/IP-SD protocol |
288 | | */ |
289 | | class SomeIpSdConfigurationOption : public SomeIpSdOption |
290 | | { |
291 | | public: |
292 | | friend class SomeIpSdLayer; |
293 | | |
294 | | /** |
295 | | * Construct a new Configuration Option object |
296 | | * @param[in] configurationString the configuration string |
297 | | */ |
298 | | explicit SomeIpSdConfigurationOption(const std::string &configurationString); |
299 | | |
300 | | /** |
301 | | * Construct a new Configuration Option object from already existing memory |
302 | | * @param[in] dataContainer Data containing the Configuration Option object |
303 | | * @param[in] offset Offset for dataContainer |
304 | | */ |
305 | | SomeIpSdConfigurationOption(const IDataContainer *dataContainer, size_t offset); |
306 | | |
307 | | /** |
308 | | * Get the configuration string |
309 | | * @return std::string |
310 | | */ |
311 | | std::string getConfigurationString() const; |
312 | | }; |
313 | | |
314 | | /** |
315 | | * @class SomeIpSdLoadBalancingOption |
316 | | * Implements the Load Balancing option of SOME/IP-SD protocol |
317 | | */ |
318 | | class SomeIpSdLoadBalancingOption : public SomeIpSdOption |
319 | | { |
320 | | public: |
321 | | friend class SomeIpSdLayer; |
322 | | |
323 | | /** |
324 | | * Construct a new Load Balancing object |
325 | | * @param[in] priority Priority of this instance |
326 | | * @param[in] weight Weight of this instance |
327 | | */ |
328 | | SomeIpSdLoadBalancingOption(uint16_t priority, uint16_t weight); |
329 | | |
330 | | /** |
331 | | * Construct a new Option object from already existing memory |
332 | | * @param[in] dataContainer Data containing the option object |
333 | | * @param[in] offset Offset for dataContainer |
334 | | */ |
335 | | SomeIpSdLoadBalancingOption(const IDataContainer *dataContainer, size_t offset); |
336 | | |
337 | | /** |
338 | | * Get the priority fild |
339 | | * @return uint16_t |
340 | | */ |
341 | | uint16_t getPriority() const; |
342 | | |
343 | | /** |
344 | | * Get the weight field |
345 | | * @return uint16_t |
346 | | */ |
347 | | uint16_t getWeight() const; |
348 | | |
349 | | private: |
350 | | /** |
351 | | * @struct someipsdhdroptionsload |
352 | | * Represents the Load Balancing option header for SOME/IP-SD |
353 | | */ |
354 | | #pragma pack(push, 1) |
355 | | struct someipsdhdroptionsload : someipsdhdroptionsbase |
356 | | { |
357 | | /* Priority field */ |
358 | | uint16_t priority; |
359 | | /* Weight field */ |
360 | | uint16_t weight; |
361 | | }; |
362 | | #pragma pack(pop) |
363 | | }; |
364 | | |
365 | | /** |
366 | | * @class SomeIpSdEntry |
367 | | * Implementation of the SOME/IP-SD Service Entry and Eventgroup Entry Type |
368 | | */ |
369 | | class SomeIpSdEntry |
370 | | { |
371 | | public: |
372 | | friend class SomeIpSdLayer; |
373 | | |
374 | | /** |
375 | | * Types of entries that can occur in SOME/IP-SD |
376 | | */ |
377 | | enum class EntryType : uint8_t |
378 | | { |
379 | | /** Find Service */ |
380 | | FindService, |
381 | | /** Offer Service */ |
382 | | OfferService, |
383 | | /** Stop Offer Service */ |
384 | | StopOfferService, |
385 | | /** Subscribe Eventgroup */ |
386 | | SubscribeEventgroup, |
387 | | /** Stop Subscribe Eventgroup */ |
388 | | StopSubscribeEventgroup, |
389 | | /** Subscribe Eventgroup Acknowledgment */ |
390 | | SubscribeEventgroupAck, |
391 | | /** Subscribe Eventgroup Negative Acknowledgement */ |
392 | | SubscribeEventgroupNack, |
393 | | /** Unknown Entry Type */ |
394 | | UnknownEntryType |
395 | | }; |
396 | | |
397 | | /** |
398 | | * @struct someipsdhdrentry |
399 | | * Represents the Service Entry Type and Eventgroup Entry Type |
400 | | */ |
401 | | #pragma pack(push, 1) |
402 | | struct someipsdhdrentry |
403 | | { |
404 | | /** Type */ |
405 | | uint8_t type; |
406 | | /** Index 1st option */ |
407 | | uint8_t indexFirstOption; |
408 | | /** Index 2nd option */ |
409 | | uint8_t indexSecondOption; |
410 | | #if (BYTE_ORDER == LITTLE_ENDIAN) |
411 | | uint8_t |
412 | | /** Numbers of Option #2 (4bit) */ |
413 | | nrOpt2 : 4, |
414 | | /** Numbers of Option #1 (4bit) */ |
415 | | nrOpt1 : 4; |
416 | | #else |
417 | | uint8_t |
418 | | /** Numbers of Option #1 (4bit) */ |
419 | | nrOpt1 : 4, |
420 | | /** Numbers of Option #2 (4bit) */ |
421 | | nrOpt2 : 4; |
422 | | #endif |
423 | | /** Service ID */ |
424 | | uint16_t serviceID; |
425 | | /** Instance ID */ |
426 | | uint16_t instanceID; |
427 | | /** Major Version (8 bit) + TTL (24 bit) */ |
428 | | uint32_t majorVersion_ttl; |
429 | | /** Minor Version (Service Entry Type) or Counter + Eventgroup ID (Eventgroup Entry Type) */ |
430 | | uint32_t data; |
431 | | }; |
432 | | #pragma pack(pop) |
433 | | |
434 | | /** |
435 | | * Construct a new SOME/IP-SD Service Entry Type |
436 | | * @param[in] type Type to create |
437 | | * @param[in] serviceID ServiceID to use |
438 | | * @param[in] instanceID InstanceID to use |
439 | | * @param[in] majorVersion MajorVersion to use |
440 | | * @param[in] TTL TTL to use. Has to be 0 for all Stop* entry types |
441 | | * @param[in] minorVersion MinorVersion to use |
442 | | */ |
443 | | SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL, |
444 | | uint32_t minorVersion); |
445 | | |
446 | | /** |
447 | | * Construct a new SOME/IP-SD Eventgroup Entry Type |
448 | | * @param[in] type Type to create |
449 | | * @param[in] serviceID ServiceID to use |
450 | | * @param[in] instanceID InstanceID to use |
451 | | * @param[in] majorVersion MajorVersion to use |
452 | | * @param[in] TTL TTL to use. Has to be 0 for all Stop* entry types |
453 | | * @param[in] counter Counter value to use |
454 | | * @param[in] eventGroupID EventgroupId to use |
455 | | */ |
456 | | SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL, |
457 | | uint8_t counter, uint16_t eventGroupID); |
458 | | |
459 | | /** |
460 | | * Construct a new SomeIpSdEntry object from existing data |
461 | | * @param[in] pSomeIpSdLayer Layer that this entry is created for |
462 | | * @param[in] offset Offset for pSomeIpSdLayer |
463 | | */ |
464 | | SomeIpSdEntry(const SomeIpSdLayer *pSomeIpSdLayer, size_t offset); |
465 | | |
466 | | /** |
467 | | * Destroy the SomeIpSd Entry object and delete allocated data if it has been allocated by a constructor |
468 | | */ |
469 | | ~SomeIpSdEntry(); |
470 | | |
471 | | /** |
472 | | * Get the internal data of the SOME/IP-SD Entry |
473 | | * @return uint8_t* |
474 | | */ |
475 | | uint8_t *getDataPtr() const; |
476 | | |
477 | | /** |
478 | | * Get a pointer to the SOME/IP-SD Entry header |
479 | | * @return someipsdhdrentry* |
480 | | */ |
481 | | someipsdhdrentry *getSomeIpSdEntryHeader() const; |
482 | | |
483 | | /** |
484 | | * Get the Entry Type |
485 | | * @return EntryType |
486 | | */ |
487 | 0 | EntryType getType() const { return m_EntryType; } |
488 | | |
489 | | /** |
490 | | * Get the Length of the SomeIpSd Entry |
491 | | * @return size_t |
492 | | */ |
493 | 3.86k | size_t getLength() const { return sizeof(someipsdhdrentry); } |
494 | | |
495 | | /** |
496 | | * Get the number of Options of this Entry |
497 | | * @return uint32_t |
498 | | */ |
499 | | uint32_t getNumOptions() const; |
500 | | |
501 | | /** |
502 | | * Get the Service Id in host endianness |
503 | | * @return uint16_t |
504 | | */ |
505 | | uint16_t getServiceId() const; |
506 | | |
507 | | /** |
508 | | * Set the Service Id |
509 | | * @param[in] serviceId |
510 | | */ |
511 | | void setServiceId(uint16_t serviceId); |
512 | | |
513 | | /** |
514 | | * Get the Instance Id in host endianness |
515 | | * @return uint16_t |
516 | | */ |
517 | | uint16_t getInstanceId() const; |
518 | | |
519 | | /** |
520 | | * Set the Instance Id |
521 | | * @param[in] instanceId |
522 | | */ |
523 | | void setInstanceId(uint16_t instanceId); |
524 | | |
525 | | /** |
526 | | * Get the Major version field in host endianness |
527 | | * @return uint16_t |
528 | | */ |
529 | | uint8_t getMajorVersion() const; |
530 | | |
531 | | /** |
532 | | * Set the Major Version |
533 | | * @param[in] majorVersion |
534 | | */ |
535 | | void setMajorVersion(uint8_t majorVersion); |
536 | | |
537 | | /** |
538 | | * Get the Ttl field |
539 | | * @return uint32_t |
540 | | */ |
541 | | uint32_t getTtl() const; |
542 | | |
543 | | /** |
544 | | * Set the Ttl field |
545 | | * @param[in] ttl |
546 | | */ |
547 | | void setTtl(uint32_t ttl); |
548 | | |
549 | | /** |
550 | | * Get the minor version |
551 | | * @return uint32_t |
552 | | */ |
553 | | uint32_t getMinorVersion() const; |
554 | | |
555 | | /** |
556 | | * Set the minor version |
557 | | * @param[in] minorVersion |
558 | | */ |
559 | | void setMinorVersion(uint32_t minorVersion); |
560 | | |
561 | | /** |
562 | | * Get the counter value |
563 | | * @return uint32_t |
564 | | */ |
565 | | uint8_t getCounter() const; |
566 | | |
567 | | /** |
568 | | * Set the counter value |
569 | | * @param[in] counter |
570 | | */ |
571 | | void setCounter(uint8_t counter); |
572 | | |
573 | | /** |
574 | | * Get the eventgroup id |
575 | | * @return uint32_t |
576 | | */ |
577 | | uint16_t getEventgroupId() const; |
578 | | |
579 | | /** |
580 | | * Set the eventgroup id |
581 | | * @param[in] eventgroupID |
582 | | */ |
583 | | void setEventgroupId(uint16_t eventgroupID); |
584 | | |
585 | | private: |
586 | | /** |
587 | | * These are the entry types used by SOME/IP-SD. They cannot be used for parameter passing since the values |
588 | | * are not unique. |
589 | | */ |
590 | | enum class TypeInternal : uint8_t |
591 | | { |
592 | | /** Find Service */ |
593 | | FindService_Internal = 0x00, |
594 | | /** Offer Service / Stop Offer Service */ |
595 | | OfferService_Internal = 0x01, |
596 | | /** Subscribe Eventgroup & Stop Subscribe Eventgroup */ |
597 | | SubscribeEventgroup_Internal = 0x06, |
598 | | /** Subscribe Eventgroup Acknowledgment / Negative Acknowledgement */ |
599 | | SubscribeEventgroupAck_Internal = 0x07, |
600 | | }; |
601 | | |
602 | | EntryType m_EntryType; |
603 | | const SomeIpSdLayer *m_Layer; |
604 | | size_t m_Offset; |
605 | | uint8_t *m_ShadowData; |
606 | | |
607 | | void initStdFields(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL); |
608 | | |
609 | | SomeIpSdEntry(const SomeIpSdEntry &) = delete; |
610 | | SomeIpSdEntry &operator=(const SomeIpSdEntry &) = delete; |
611 | | |
612 | | static const uint32_t SOMEIPSD_HDR_ENTRY_MASK_TTL = 0x00FFFFFF; |
613 | | }; |
614 | | |
615 | | /** |
616 | | * @class SomeIpSdLayer |
617 | | * Implementation of the SOME/IP-SD protocol |
618 | | */ |
619 | | class SomeIpSdLayer : public SomeIpLayer |
620 | | { |
621 | | public: |
622 | | friend class SomeIpSdEntry; |
623 | | |
624 | | typedef SomeIpSdEntry* EntryPtr; |
625 | | typedef std::vector<EntryPtr> EntriesVec; |
626 | | typedef SomeIpSdOption* OptionPtr; |
627 | | typedef std::vector<OptionPtr> OptionsVec; |
628 | | |
629 | | /** |
630 | | * A constructor that creates the layer from an existing packet raw data |
631 | | * @param[in] data A pointer to the raw data |
632 | | * @param[in] dataLen Size of the data in bytes |
633 | | * @param[in] prevLayer A pointer to the previous layer |
634 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
635 | | */ |
636 | | SomeIpSdLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet); |
637 | | |
638 | | /** |
639 | | * Construct a new SomeIpSdLayer object |
640 | | * @param[in] serviceID Service ID |
641 | | * @param[in] methodID Method ID |
642 | | * @param[in] clientID Client ID |
643 | | * @param[in] sessionID Session ID |
644 | | * @param[in] interfaceVersion Interface Version |
645 | | * @param[in] type Type of the message |
646 | | * @param[in] returnCode Return Code |
647 | | * @param[in] flags Flags that shall be used in the header |
648 | | */ |
649 | | SomeIpSdLayer(uint16_t serviceID, uint16_t methodID, uint16_t clientID, uint16_t sessionID, |
650 | | uint8_t interfaceVersion, MsgType type, uint8_t returnCode, uint8_t flags); |
651 | | |
652 | | /** |
653 | | * Destroy the layer object |
654 | | */ |
655 | 0 | ~SomeIpSdLayer() {} |
656 | | |
657 | | /** |
658 | | * Checks if given port is a SOME/IP-SD protocol port |
659 | | * @param[in] port Port to check |
660 | | * @return true if SOME/IP-SD protocol port, false if not |
661 | | */ |
662 | 342k | static bool isSomeIpSdPort(uint16_t port) { return port == 30490; } |
663 | | |
664 | | /** |
665 | | * The static method makes validation of input data |
666 | | * @param[in] data The pointer to the beginning of byte stream of IP packet |
667 | | * @param[in] dataLen The length of byte stream |
668 | | * @return True if the data is valid and can represent the packet |
669 | | */ |
670 | | static bool isDataValid(const uint8_t* data, size_t dataLen); |
671 | | |
672 | | /** |
673 | | * Get the Flags of the layer |
674 | | * @return uint8_t Flags |
675 | | */ |
676 | | uint8_t getFlags() const; |
677 | | |
678 | | /** |
679 | | * Set the Flags of the layer |
680 | | * @param[in] flags Flags to set |
681 | | */ |
682 | | void setFlags(uint8_t flags); |
683 | | |
684 | | /** |
685 | | * Get the number of entries in this layer |
686 | | * @return uint32_t |
687 | | */ |
688 | | uint32_t getNumEntries() const; |
689 | | |
690 | | /** |
691 | | * Get the number of options in this layer |
692 | | * @return uint32_t |
693 | | */ |
694 | | uint32_t getNumOptions() const; |
695 | | |
696 | | /** |
697 | | * Get the Entries from this layer |
698 | | * @return EntriesVec Vector holding pointers to the options |
699 | | */ |
700 | | const EntriesVec getEntries() const; |
701 | | |
702 | | /** |
703 | | * Get the Options from this layer |
704 | | * @return OptionsVec Vector holding pointers to the options |
705 | | */ |
706 | | const OptionsVec getOptions() const; |
707 | | |
708 | | /** |
709 | | * Get the Options from a specific Entry |
710 | | * @param[in] index Index of the Entry, starting with 0. |
711 | | * @return OptionsVec Vector holding pointers to the options |
712 | | */ |
713 | | const OptionsVec getOptionsFromEntry(uint32_t index) const; |
714 | | |
715 | | /** |
716 | | * Adds a given entry to the layer and returns the index of the entry |
717 | | * @param[in] entry Pointer to the entry that shall be added to the layer |
718 | | * @return uint32_t Returns the index of the entry starting with 0 |
719 | | */ |
720 | | uint32_t addEntry(const SomeIpSdEntry &entry); |
721 | | |
722 | | /** |
723 | | * Adds an option to an entry that has already been added to the layer by using addEntry(). The option |
724 | | * is also added to the layer itself. If the option cannot by assigned to the entry, the option is not |
725 | | * copied into the layer. |
726 | | * @param[in] indexEntry Index of the entry where the option shall be added. First Entry has index 0 |
727 | | * @param[in] option Pointer to the option that shall be added |
728 | | * @return True if the option could be assigned to the entry and was copied into the layer, false otherwise |
729 | | */ |
730 | | bool addOptionTo(uint32_t indexEntry, const SomeIpSdOption &option); |
731 | | |
732 | | /** |
733 | | * Does nothing for this layer |
734 | | */ |
735 | 3.59k | void computeCalculateFields() {}; |
736 | | |
737 | | /** |
738 | | * @return The string representation of the SOME/IP-SD layer |
739 | | */ |
740 | | std::string toString() const; |
741 | | |
742 | | private: |
743 | | /** |
744 | | * @struct someipsdhdr |
745 | | * Represents an SOME/IP-SD protocol header |
746 | | */ |
747 | | #pragma pack(push, 1) |
748 | | struct someipsdhdr : someiphdr |
749 | | { |
750 | | /** Flags (8 bit) */ |
751 | | uint8_t flags; |
752 | | /** Reserved1 field (Bits 0-7 of 24-bits reserved field) */ |
753 | | uint8_t reserved1; |
754 | | /** Reserved2 field (Bits 8-15 of 24-bits reserved field) */ |
755 | | uint8_t reserved2; |
756 | | /** Reserved3 field (Bits 16-23 of 24-bits reserved field) */ |
757 | | uint8_t reserved3; |
758 | | }; |
759 | | #pragma pack(pop) |
760 | | |
761 | | uint32_t m_NumOptions; |
762 | | |
763 | | static bool countOptions(uint32_t& count, const uint8_t* data); |
764 | | uint32_t findOption(const SomeIpSdOption &option); |
765 | | void addOption(const SomeIpSdOption &option); |
766 | | bool addOptionIndex(uint32_t indexEntry, uint32_t indexOffset); |
767 | | OptionPtr parseOption(SomeIpSdOption::OptionType type, size_t offset) const; |
768 | | |
769 | | static size_t getLenEntries(const uint8_t* data); |
770 | | size_t getLenEntries() const; |
771 | | static size_t getLenOptions(const uint8_t* data); |
772 | | size_t getLenOptions() const; |
773 | | void setLenEntries(uint32_t length); |
774 | | void setLenOptions(uint32_t length); |
775 | | }; |
776 | | |
777 | | } // namespace pcpp |