PcapPlusPlus  20.08
GtpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_GTP_LAYER
2 #define PACKETPP_GTP_LAYER
3 
4 #include "Layer.h"
5 
7 
8 
13 namespace pcpp
14 {
15 
16 #pragma pack(push, 1)
17 
21  struct gtpv1_header
22  {
23 #if (BYTE_ORDER == LITTLE_ENDIAN)
24 
25  uint8_t npduNumberFlag:1,
36 #else
37 
38  uint8_t version:3,
40  protocolType:1,
42  reserved:1,
49 #endif
50 
51  uint8_t messageType;
52 
54  uint16_t messageLength;
55 
57  uint32_t teid;
58  };
59 
60 #pragma pack(pop)
61 
67  {
206  };
207 
208 
213  class GtpV1Layer : public Layer
214  {
215  private:
216  struct gtpv1_header_extra
217  {
218  uint16_t sequenceNumber;
219  uint8_t npduNumber;
220  uint8_t nextExtensionHeader;
221  };
222 
223  gtpv1_header_extra* getHeaderExtra() const;
224 
225  void init(GtpV1MessageType messageType, uint32_t teid, bool setSeqNum, uint16_t seqNum, bool setNpduNum, uint8_t npduNum);
226 
227  public:
228 
234  {
235  friend class GtpV1Layer;
236 
237  private:
238  uint8_t* m_Data;
239  size_t m_DataLen;
240  uint8_t m_ExtType;
241 
242  GtpExtension(uint8_t* data, size_t dataLen, uint8_t type);
243 
244  void setNextHeaderType(uint8_t nextHeaderType);
245 
246  static GtpExtension createGtpExtension(uint8_t* data, size_t dataLen, uint8_t extType, uint16_t content);
247 
248  public:
249 
253  GtpExtension();
254 
258  GtpExtension(const GtpExtension& other);
259 
263  GtpExtension& operator=(const GtpExtension& other);
264 
269  bool isNull() const;
270 
274  uint8_t getExtensionType() const;
275 
280  size_t getTotalLength() const;
281 
286  size_t getContentLength() const;
287 
292  uint8_t* getContent() const;
293 
298  uint8_t getNextExtensionHeaderType() const;
299 
306  }; // GtpExtension
307 
308  virtual ~GtpV1Layer() {}
309 
316  GtpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = GTPv1; }
317 
323  GtpV1Layer(GtpV1MessageType messageType, uint32_t teid);
324 
334  GtpV1Layer(GtpV1MessageType messageType, uint32_t teid, bool setSeqNum, uint16_t seqNum, bool setNpduNum, uint8_t npduNum);
335 
342  static bool isGTPv1(const uint8_t* data, size_t dataSize);
343 
347  gtpv1_header* getHeader() const { return (gtpv1_header*)m_Data; }
348 
355  bool getSequenceNumber(uint16_t& seqNumber) const;
356 
362  bool setSequenceNumber(const uint16_t seqNumber);
363 
370  bool getNpduNumber(uint8_t& npduNum) const;
371 
377  bool setNpduNumber(const uint8_t npduNum);
378 
385  bool getNextExtensionHeaderType(uint8_t& nextExtType) const;
386 
391  GtpExtension getNextExtension() const;
392 
402  GtpExtension addExtension(uint8_t extensionType, uint16_t extensionContent);
403 
408 
412  std::string getMessageTypeAsString() const;
413 
417  bool isGTPUMessage() const;
418 
422  bool isGTPCMessage() const;
423 
428  static bool isGTPv1Port(uint16_t port) { return port == 2152 /* GTP-U */ || port == 2123 /* GTP-C */; }
429 
430 
431  // implement abstract methods
432 
436  void parseNextLayer();
437 
444  size_t getHeaderLen() const;
445 
450  void computeCalculateFields();
451 
452  std::string toString() const;
453 
455  };
456 }
457 
458 #endif //PACKETPP_GTP_LAYER
pcpp::GtpV1Layer::isGTPv1Port
static bool isGTPv1Port(uint16_t port)
Definition: GtpLayer.h:428
pcpp::GtpV1Layer::isGTPv1
static bool isGTPv1(const uint8_t *data, size_t dataSize)
pcpp::GtpV1_MBMSSessionUpdateRequest
@ GtpV1_MBMSSessionUpdateRequest
Definition: GtpLayer.h:191
pcpp::GtpV1_ForwardRelocationCompleteAcknowledge
@ GtpV1_ForwardRelocationCompleteAcknowledge
Definition: GtpLayer.h:145
pcpp::GtpV1_DeletePDPContextRequest
@ GtpV1_DeletePDPContextRequest
Definition: GtpLayer.h:91
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:233
pcpp::GtpV1Layer::getNpduNumber
bool getNpduNumber(uint8_t &npduNum) const
pcpp::GtpV1_InitiatePDPContextActivationResponse
@ GtpV1_InitiatePDPContextActivationResponse
Definition: GtpLayer.h:97
pcpp::GtpV1Layer::GtpExtension::GtpExtension
GtpExtension()
pcpp::GtpV1_ForwardRelocationResponse
@ GtpV1_ForwardRelocationResponse
Definition: GtpLayer.h:135
pcpp::Packet
Definition: Packet.h:26
pcpp::GtpV1_UpdatePDPContextResponse
@ GtpV1_UpdatePDPContextResponse
Definition: GtpLayer.h:89
pcpp::GtpV1_RANInformationRelay
@ GtpV1_RANInformationRelay
Definition: GtpLayer.h:153
pcpp::GtpV1_NodeAliveResponse
@ GtpV1_NodeAliveResponse
Definition: GtpLayer.h:79
pcpp::GtpV1_EchoResponse
@ GtpV1_EchoResponse
Definition: GtpLayer.h:73
pcpp::GtpV1_MessageTypeUnknown
@ GtpV1_MessageTypeUnknown
Definition: GtpLayer.h:69
pcpp::GtpV1_MSInfoChangeResponse
@ GtpV1_MSInfoChangeResponse
Definition: GtpLayer.h:197
pcpp::GtpV1_UERegistrationRequest
@ GtpV1_UERegistrationRequest
Definition: GtpLayer.h:149
pcpp::GtpV1Layer::getMessageType
GtpV1MessageType getMessageType() const
pcpp::GtpV1Layer::getMessageTypeAsString
std::string getMessageTypeAsString() const
pcpp::GtpV1_SendRoutingforGPRSRequest
@ GtpV1_SendRoutingforGPRSRequest
Definition: GtpLayer.h:111
pcpp::GtpV1_DeletePDPContextResponse
@ GtpV1_DeletePDPContextResponse
Definition: GtpLayer.h:93
pcpp::GtpV1_ForwardRelocationComplete
@ GtpV1_ForwardRelocationComplete
Definition: GtpLayer.h:137
Layer.h
pcpp::gtpv1_header::messageLength
uint16_t messageLength
Definition: GtpLayer.h:54
pcpp::GtpV1_FailureReportResponse
@ GtpV1_FailureReportResponse
Definition: GtpLayer.h:117
pcpp::GtpV1_RelocationCancelResponse
@ GtpV1_RelocationCancelResponse
Definition: GtpLayer.h:141
pcpp::GtpV1_DataRecordTransferResponse
@ GtpV1_DataRecordTransferResponse
Definition: GtpLayer.h:201
pcpp::GtpV1_MBMSSessionUpdateResponse
@ GtpV1_MBMSSessionUpdateResponse
Definition: GtpLayer.h:193
pcpp::GtpV1_MBMSNotificationRejectRequest
@ GtpV1_MBMSNotificationRejectRequest
Definition: GtpLayer.h:159
pcpp::gtpv1_header
Definition: GtpLayer.h:21
pcpp::GtpV1_MBMSSessionStartRequest
@ GtpV1_MBMSSessionStartRequest
Definition: GtpLayer.h:183
pcpp::GtpV1_MBMSNotificationRequest
@ GtpV1_MBMSNotificationRequest
Definition: GtpLayer.h:155
pcpp::gtpv1_header::messageType
uint8_t messageType
Definition: GtpLayer.h:51
pcpp::GtpV1Layer::GtpExtension::operator=
GtpExtension & operator=(const GtpExtension &other)
pcpp::GtpV1_SGSNContextRequest
@ GtpV1_SGSNContextRequest
Definition: GtpLayer.h:127
pcpp::GtpV1_CreateMBMSNotificationResponse
@ GtpV1_CreateMBMSNotificationResponse
Definition: GtpLayer.h:165
pcpp::GtpV1_DataRecordTransferRequest
@ GtpV1_DataRecordTransferRequest
Definition: GtpLayer.h:199
pcpp::GtpV1Layer::addExtension
GtpExtension addExtension(uint8_t extensionType, uint16_t extensionContent)
pcpp::GtpV1_PDUNotificationRejectRequest
@ GtpV1_PDUNotificationRejectRequest
Definition: GtpLayer.h:105
pcpp::GtpV1_UpdateMBMSNotificationRequest
@ GtpV1_UpdateMBMSNotificationRequest
Definition: GtpLayer.h:167
pcpp::GtpV1_MBMSRegistrationRequest
@ GtpV1_MBMSRegistrationRequest
Definition: GtpLayer.h:175
pcpp::GtpV1_CreatePDPContextResponse
@ GtpV1_CreatePDPContextResponse
Definition: GtpLayer.h:85
pcpp::GtpV1Layer::GtpExtension::isNull
bool isNull() const
pcpp::GtpV1Layer::GtpExtension::getContentLength
size_t getContentLength() const
pcpp::GtpV1_EndMarker
@ GtpV1_EndMarker
Definition: GtpLayer.h:203
pcpp::GtpV1Layer::GtpExtension::getExtensionType
uint8_t getExtensionType() const
pcpp::GtpV1_VersionNotSupported
@ GtpV1_VersionNotSupported
Definition: GtpLayer.h:75
pcpp::GtpV1_RedirectionRequest
@ GtpV1_RedirectionRequest
Definition: GtpLayer.h:81
pcpp::GtpV1_DeleteMBMSNotificationResponse
@ GtpV1_DeleteMBMSNotificationResponse
Definition: GtpLayer.h:173
pcpp::GtpV1_ErrorIndication
@ GtpV1_ErrorIndication
Definition: GtpLayer.h:99
pcpp::gtpv1_header::version
uint8_t version
Definition: GtpLayer.h:35
pcpp::GtpV1_MBMSSessionStopRequest
@ GtpV1_MBMSSessionStopRequest
Definition: GtpLayer.h:187
pcpp::gtpv1_header::reserved
uint8_t reserved
Definition: GtpLayer.h:31
pcpp::GtpV1_CreateMBMSNotificationRequest
@ GtpV1_CreateMBMSNotificationRequest
Definition: GtpLayer.h:163
pcpp::GtpV1Layer::GtpV1Layer
GtpV1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GtpLayer.h:316
pcpp::GtpV1Layer::setSequenceNumber
bool setSequenceNumber(const uint16_t seqNumber)
pcpp::GtpV1_IdentificationRequest
@ GtpV1_IdentificationRequest
Definition: GtpLayer.h:123
pcpp::GtpV1_MBMSSessionStopResponse
@ GtpV1_MBMSSessionStopResponse
Definition: GtpLayer.h:189
pcpp::GTPv1
const ProtocolType GTPv1
Definition: ProtocolType.h:213
pcpp::GtpV1_GPDU
@ GtpV1_GPDU
Definition: GtpLayer.h:205
pcpp::GtpV1Layer::parseNextLayer
void parseNextLayer()
pcpp::GtpV1Layer::getNextExtensionHeaderType
bool getNextExtensionHeaderType(uint8_t &nextExtType) const
pcpp::GtpV1MessageType
GtpV1MessageType
Definition: GtpLayer.h:66
pcpp::gtpv1_header::extensionHeaderFlag
uint8_t extensionHeaderFlag
Definition: GtpLayer.h:29
pcpp::GtpV1_FailureReportRequest
@ GtpV1_FailureReportRequest
Definition: GtpLayer.h:115
pcpp::GtpV1_PDUNotificationResponse
@ GtpV1_PDUNotificationResponse
Definition: GtpLayer.h:103
pcpp::GtpV1Layer::getHeaderLen
size_t getHeaderLen() const
pcpp::GtpV1Layer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: GtpLayer.h:454
pcpp::GtpV1_ForwardSRNSContextAcknowledge
@ GtpV1_ForwardSRNSContextAcknowledge
Definition: GtpLayer.h:147
pcpp::GtpV1_UERegistrationResponse
@ GtpV1_UERegistrationResponse
Definition: GtpLayer.h:151
pcpp::GtpV1_SupportedExtensionsHeaderNotification
@ GtpV1_SupportedExtensionsHeaderNotification
Definition: GtpLayer.h:109
pcpp::GtpV1_MBMSDeRegistrationResponse
@ GtpV1_MBMSDeRegistrationResponse
Definition: GtpLayer.h:181
pcpp::GtpV1Layer::GtpExtension::getNextExtensionHeaderType
uint8_t getNextExtensionHeaderType() const
pcpp::GtpV1Layer::setNpduNumber
bool setNpduNumber(const uint8_t npduNum)
pcpp::gtpv1_header::npduNumberFlag
uint8_t npduNumberFlag
Definition: GtpLayer.h:25
pcpp::GtpV1_UpdateMBMSNotificationResponse
@ GtpV1_UpdateMBMSNotificationResponse
Definition: GtpLayer.h:169
pcpp::GtpV1_NoteMSPresentRequest
@ GtpV1_NoteMSPresentRequest
Definition: GtpLayer.h:119
pcpp::GtpV1_RelocationCancelRequest
@ GtpV1_RelocationCancelRequest
Definition: GtpLayer.h:139
pcpp::GtpV1Layer::GtpExtension::getTotalLength
size_t getTotalLength() const
pcpp::GtpV1_MBMSNotificationResponse
@ GtpV1_MBMSNotificationResponse
Definition: GtpLayer.h:157
pcpp::OsiModelTransportLayer
@ OsiModelTransportLayer
Definition: ProtocolType.h:242
pcpp::GtpV1_DeleteMBMSNotificationRequest
@ GtpV1_DeleteMBMSNotificationRequest
Definition: GtpLayer.h:171
pcpp::GtpV1Layer
Definition: GtpLayer.h:213
pcpp::gtpv1_header::teid
uint32_t teid
Definition: GtpLayer.h:57
pcpp::GtpV1_NodeAliveRequest
@ GtpV1_NodeAliveRequest
Definition: GtpLayer.h:77
pcpp::GtpV1_MSInfoChangeRequest
@ GtpV1_MSInfoChangeRequest
Definition: GtpLayer.h:195
pcpp::GtpV1_MBMSSessionStartResponse
@ GtpV1_MBMSSessionStartResponse
Definition: GtpLayer.h:185
pcpp::GtpV1_UpdatePDPContextRequest
@ GtpV1_UpdatePDPContextRequest
Definition: GtpLayer.h:87
pcpp::GtpV1Layer::GtpExtension::getNextExtension
GtpExtension getNextExtension() const
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::GtpV1_PDUNotificationRejectResponse
@ GtpV1_PDUNotificationRejectResponse
Definition: GtpLayer.h:107
pcpp::GtpV1Layer::isGTPUMessage
bool isGTPUMessage() const
pcpp::GtpV1_MBMSDeRegistrationRequest
@ GtpV1_MBMSDeRegistrationRequest
Definition: GtpLayer.h:179
pcpp::GtpV1_PDUNotificationRequest
@ GtpV1_PDUNotificationRequest
Definition: GtpLayer.h:101
pcpp::GtpV1_InitiatePDPContextActivationRequest
@ GtpV1_InitiatePDPContextActivationRequest
Definition: GtpLayer.h:95
pcpp::Layer
Definition: Layer.h:70
pcpp::GtpV1Layer::toString
std::string toString() const
pcpp::GtpV1_SGSNContextResponse
@ GtpV1_SGSNContextResponse
Definition: GtpLayer.h:129
pcpp::GtpV1Layer::getNextExtension
GtpExtension getNextExtension() const
pcpp::GtpV1_CreatePDPContextRequest
@ GtpV1_CreatePDPContextRequest
Definition: GtpLayer.h:83
pcpp::GtpV1_MBMSNotificationRejectResponse
@ GtpV1_MBMSNotificationRejectResponse
Definition: GtpLayer.h:161
pcpp::GtpV1_MBMSRegistrationResponse
@ GtpV1_MBMSRegistrationResponse
Definition: GtpLayer.h:177
pcpp::GtpV1Layer::isGTPCMessage
bool isGTPCMessage() const
pcpp::GtpV1Layer::getSequenceNumber
bool getSequenceNumber(uint16_t &seqNumber) const
pcpp::GtpV1Layer::computeCalculateFields
void computeCalculateFields()
pcpp::GtpV1Layer::GtpExtension::getContent
uint8_t * getContent() const
pcpp::gtpv1_header::sequenceNumberFlag
uint8_t sequenceNumberFlag
Definition: GtpLayer.h:27
pcpp::GtpV1_SendRoutingforGPRSResponse
@ GtpV1_SendRoutingforGPRSResponse
Definition: GtpLayer.h:113
pcpp::GtpV1_IdentificationResponse
@ GtpV1_IdentificationResponse
Definition: GtpLayer.h:125
pcpp::GtpV1Layer::getHeader
gtpv1_header * getHeader() const
Definition: GtpLayer.h:347
pcpp::GtpV1_SGSNContextAcknowledge
@ GtpV1_SGSNContextAcknowledge
Definition: GtpLayer.h:131
pcpp::GtpV1_ForwardSRNSContext
@ GtpV1_ForwardSRNSContext
Definition: GtpLayer.h:143
pcpp::GtpV1_NoteMSPresentResponse
@ GtpV1_NoteMSPresentResponse
Definition: GtpLayer.h:121
pcpp::GtpV1Layer::GtpExtension
Definition: GtpLayer.h:233
pcpp::GtpV1_ForwardRelocationRequest
@ GtpV1_ForwardRelocationRequest
Definition: GtpLayer.h:133
pcpp::GtpV1_EchoRequest
@ GtpV1_EchoRequest
Definition: GtpLayer.h:71
pcpp::gtpv1_header::protocolType
uint8_t protocolType
Definition: GtpLayer.h:33