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