PcapPlusPlus  Next
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() = default;
57 
61  uint8_t* getData() const
62  {
63  return m_Data;
64  }
68  size_t getDataLength() const
69  {
70  return m_DataLen;
71  }
72 
73  private:
74  S7CommParameter(uint8_t* data, size_t dataLen) : m_Data(data), m_DataLen(dataLen)
75  {}
76  uint8_t* m_Data;
77  size_t m_DataLen;
78  };
83  class S7CommLayer : public Layer
84  {
85  public:
95  S7CommLayer(uint8_t msgType, uint16_t pduRef, uint16_t paramLength, uint16_t dataLength, uint8_t errorClass = 0,
96  uint8_t errorCode = 0);
97 
105  S7CommLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
106  : Layer(data, dataLen, prevLayer, packet, S7COMM)
107  {
108  m_Parameter = nullptr;
109  }
110 
111  ~S7CommLayer() override
112  {
113  if (m_Parameter)
114  delete m_Parameter;
115  }
116 
120  uint8_t getProtocolId() const;
121 
125  uint8_t getMsgType() const;
126 
130  uint16_t getPduRef() const;
131 
135  uint16_t getParamLength() const;
136 
140  uint16_t getDataLength() const;
141 
145  uint8_t getErrorCode() const;
146 
150  uint8_t getErrorClass() const;
151 
156 
161  void setMsgType(uint8_t msgType) const;
162 
167  void setPduRef(uint16_t pduRef) const;
168 
173  void setErrorCode(uint8_t errorCode) const;
178  void setErrorClass(uint8_t errorClass) const;
179 
183  size_t getHeaderLen() const override
184  {
185  return m_DataLen;
186  }
187 
191  void computeCalculateFields() override
192  {}
193 
197  void parseNextLayer() override
198  {}
199 
206  static bool isDataValid(const uint8_t* data, size_t dataSize);
207 
208  std::string toString() const override;
209 
211  {
213  }
214 
215  private:
216  s7commhdr* getS7commHeader() const
217  {
218  return reinterpret_cast<s7commhdr*>(m_Data);
219  }
220 
221  s7comm_ack_data_hdr* getS7commAckDataHeader() const
222  {
223  if (getS7commHeader()->msgType == 0x03)
224  {
225  return reinterpret_cast<s7comm_ack_data_hdr*>(m_Data);
226  }
227  return nullptr;
228  }
229 
230  size_t getS7commHeaderLength() const;
231 
232  S7CommParameter* m_Parameter;
233  };
234 
235 } // namespace pcpp
Definition: Layer.h:69
Definition: Packet.h:27
Definition: S7CommLayer.h:84
void setErrorCode(uint8_t errorCode) const
uint16_t getPduRef() const
void computeCalculateFields() override
Definition: S7CommLayer.h:191
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:210
void setPduRef(uint16_t pduRef) const
size_t getHeaderLen() const override
Definition: S7CommLayer.h:183
uint8_t getErrorClass() const
uint16_t getDataLength() const
S7CommLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: S7CommLayer.h:105
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:197
Definition: S7CommLayer.h:49
size_t getDataLength() const
Definition: S7CommLayer.h:68
uint8_t * getData() const
Definition: S7CommLayer.h:61
The main namespace for the PcapPlusPlus lib.
const ProtocolType S7COMM
Definition: ProtocolType.h:338
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelApplicationLayer
Definition: ProtocolType.h:378
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