PcapPlusPlus  24.09
S7CommLayer.h
1 #pragma once
2 
3 #include "EthLayer.h"
4 #include "Layer.h"
5 
6 namespace pcpp
7 {
12 #pragma pack(push, 1)
13  typedef struct
14  {
16  uint8_t protocolId;
18  uint8_t msgType;
20  uint16_t reserved;
22  uint16_t pduRef;
24  uint16_t paramLength;
26  uint16_t dataLength;
27  } s7commhdr;
28 #pragma pack(pop)
29 
34 #pragma pack(push, 1)
36  {
38  uint8_t errorClass;
40  uint8_t errorCode;
41  };
42 #pragma pack(pop)
43 
49  {
50  friend class S7CommLayer;
51 
52  public:
54  {}
55 
56  virtual ~S7CommParameter()
57  {}
58 
62  uint8_t* getData() const
63  {
64  return m_Data;
65  }
69  size_t getDataLength() const
70  {
71  return m_DataLen;
72  }
73 
74  private:
75  S7CommParameter(uint8_t* data, size_t dataLen) : m_Data(data), m_DataLen(dataLen)
76  {}
77  uint8_t* m_Data;
78  size_t m_DataLen;
79  };
84  class S7CommLayer : public Layer
85  {
86  public:
96  S7CommLayer(uint8_t msgType, uint16_t pduRef, uint16_t paramLength, uint16_t dataLength, uint8_t errorClass = 0,
97  uint8_t errorCode = 0);
98 
106  S7CommLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
107  : Layer(data, dataLen, prevLayer, packet, S7COMM)
108  {
109  m_Parameter = nullptr;
110  }
111 
112  virtual ~S7CommLayer()
113  {
114  if (m_Parameter)
115  delete m_Parameter;
116  }
117 
121  uint8_t getProtocolId() const;
122 
126  uint8_t getMsgType() const;
127 
131  uint16_t getPduRef() const;
132 
136  uint16_t getParamLength() const;
137 
141  uint16_t getDataLength() const;
142 
146  uint8_t getErrorCode() const;
147 
151  uint8_t getErrorClass() const;
152 
157 
162  void setMsgType(uint8_t msgType) const;
163 
168  void setPduRef(uint16_t pduRef) const;
169 
174  void setErrorCode(uint8_t errorCode) const;
179  void setErrorClass(uint8_t errorClass) const;
180 
184  size_t getHeaderLen() const override
185  {
186  return m_DataLen;
187  }
188 
192  void computeCalculateFields() override
193  {}
194 
198  void parseNextLayer() override
199  {}
200 
207  static bool isDataValid(const uint8_t* data, size_t dataSize);
208 
209  std::string toString() const override;
210 
212  {
214  }
215 
216  private:
217  s7commhdr* getS7commHeader() const
218  {
219  return (s7commhdr*)m_Data;
220  }
221 
222  s7comm_ack_data_hdr* getS7commAckDataHeader() const
223  {
224  if (getS7commHeader()->msgType == 0x03)
225  {
226  return (s7comm_ack_data_hdr*)m_Data;
227  }
228  return nullptr;
229  }
230 
231  size_t getS7commHeaderLength() const;
232 
233  S7CommParameter* m_Parameter;
234  };
235 
236 } // namespace pcpp
Definition: Layer.h:70
Definition: Packet.h:27
Definition: S7CommLayer.h:85
void setErrorCode(uint8_t errorCode) const
uint16_t getPduRef() const
void computeCalculateFields() override
Definition: S7CommLayer.h:192
const S7CommParameter * getParameter()
uint8_t getProtocolId() const
void setErrorClass(uint8_t errorClass) const
static bool isDataValid(const uint8_t *data, size_t dataSize)
OsiModelLayer getOsiModelLayer() const override
Definition: S7CommLayer.h:211
void setPduRef(uint16_t pduRef) const
size_t getHeaderLen() const override
Definition: S7CommLayer.h:184
uint8_t getErrorClass() const
uint16_t getDataLength() const
S7CommLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: S7CommLayer.h:106
uint8_t getMsgType() const
uint8_t getErrorCode() const
void setMsgType(uint8_t msgType) const
S7CommLayer(uint8_t msgType, uint16_t pduRef, uint16_t paramLength, uint16_t dataLength, uint8_t errorClass=0, uint8_t errorCode=0)
std::string toString() const override
uint16_t getParamLength() const
void parseNextLayer() override
Definition: S7CommLayer.h:198
Definition: S7CommLayer.h:49
size_t getDataLength() const
Definition: S7CommLayer.h:69
uint8_t * getData() const
Definition: S7CommLayer.h:62
The main namespace for the PcapPlusPlus lib.
const ProtocolType S7COMM
Definition: ProtocolType.h:338
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelApplicationLayer
Definition: ProtocolType.h:368
Definition: S7CommLayer.h:36
uint8_t errorClass
Definition: S7CommLayer.h:38
uint8_t errorCode
Definition: S7CommLayer.h:40
Definition: S7CommLayer.h:14
uint16_t dataLength
Definition: S7CommLayer.h:26
uint16_t paramLength
Definition: S7CommLayer.h:24
uint8_t protocolId
Definition: S7CommLayer.h:16
uint8_t msgType
Definition: S7CommLayer.h:18
uint16_t reserved
Definition: S7CommLayer.h:20
uint16_t pduRef
Definition: S7CommLayer.h:22