PcapPlusPlus  24.09
GtpLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
11 namespace pcpp
12 {
13 
14 #pragma pack(push, 1)
19  struct gtpv1_header
20  {
21 #if (BYTE_ORDER == LITTLE_ENDIAN)
23  uint8_t npduNumberFlag : 1,
29  reserved : 1,
33  version : 3;
34 #else
36  uint8_t version : 3,
38  protocolType : 1,
40  reserved : 1,
46  npduNumberFlag : 1;
47 #endif
49  uint8_t messageType;
50 
53  uint16_t messageLength;
54 
57  uint32_t teid;
58  };
59 
60 #pragma pack(pop)
61 
68  {
206  GtpV1_GPDU = 255
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,
226  uint8_t npduNum);
227 
228  public:
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:
253 
258  GtpExtension(const GtpExtension& other);
259 
266 
271  bool isNull() const;
272 
276  uint8_t getExtensionType() const;
277 
282  size_t getTotalLength() const;
283 
288  size_t getContentLength() const;
289 
294  uint8_t* getContent() const;
295 
300  uint8_t getNextExtensionHeaderType() const;
301 
308  }; // GtpExtension
309 
310  virtual ~GtpV1Layer()
311  {}
312 
319  GtpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
320  : Layer(data, dataLen, prevLayer, packet, GTPv1)
321  {}
322 
328  GtpV1Layer(GtpV1MessageType messageType, uint32_t teid);
329 
343  GtpV1Layer(GtpV1MessageType messageType, uint32_t teid, bool setSeqNum, uint16_t seqNum, bool setNpduNum,
344  uint8_t npduNum);
345 
352  static bool isGTPv1(const uint8_t* data, size_t dataSize);
353 
359  {
360  return (gtpv1_header*)m_Data;
361  }
362 
369  bool getSequenceNumber(uint16_t& seqNumber) const;
370 
377  bool setSequenceNumber(const uint16_t seqNumber);
378 
385  bool getNpduNumber(uint8_t& npduNum) const;
386 
393  bool setNpduNumber(const uint8_t npduNum);
394 
402  bool getNextExtensionHeaderType(uint8_t& nextExtType) const;
403 
409 
420  GtpExtension addExtension(uint8_t extensionType, uint16_t extensionContent);
421 
426 
430  std::string getMessageTypeAsString() const;
431 
435  bool isGTPUMessage() const;
436 
440  bool isGTPCMessage() const;
441 
447  static bool isGTPv1Port(uint16_t port)
448  {
449  return port == 2152 /* GTP-U */ || port == 2123 /* GTP-C */;
450  }
451 
452  // implement abstract methods
453 
458 
465  size_t getHeaderLen() const;
466 
472 
473  std::string toString() const;
474 
476  {
477  return OsiModelTransportLayer;
478  }
479  };
480 } // namespace pcpp
Definition: GtpLayer.h:234
uint8_t getNextExtensionHeaderType() const
GtpExtension & operator=(const GtpExtension &other)
uint8_t getExtensionType() const
GtpExtension(const GtpExtension &other)
uint8_t * getContent() const
GtpExtension getNextExtension() const
Definition: GtpLayer.h:214
bool isGTPCMessage() const
void computeCalculateFields()
bool getSequenceNumber(uint16_t &seqNumber) const
bool isGTPUMessage() const
GtpV1Layer(GtpV1MessageType messageType, uint32_t teid)
bool setNpduNumber(const uint8_t npduNum)
std::string toString() const
GtpV1MessageType getMessageType() const
GtpExtension addExtension(uint8_t extensionType, uint16_t extensionContent)
GtpV1Layer(GtpV1MessageType messageType, uint32_t teid, bool setSeqNum, uint16_t seqNum, bool setNpduNum, uint8_t npduNum)
GtpExtension getNextExtension() const
gtpv1_header * getHeader() const
Definition: GtpLayer.h:358
size_t getHeaderLen() const
bool getNextExtensionHeaderType(uint8_t &nextExtType) const
static bool isGTPv1Port(uint16_t port)
Definition: GtpLayer.h:447
bool setSequenceNumber(const uint16_t seqNumber)
OsiModelLayer getOsiModelLayer() const
Definition: GtpLayer.h:475
static bool isGTPv1(const uint8_t *data, size_t dataSize)
GtpV1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GtpLayer.h:319
std::string getMessageTypeAsString() const
bool getNpduNumber(uint8_t &npduNum) const
Definition: Layer.h:70
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelTransportLayer
Definition: ProtocolType.h:362
const ProtocolType GTPv1
Definition: ProtocolType.h:218
GtpV1MessageType
Definition: GtpLayer.h:68
@ GtpV1_MessageTypeUnknown
Definition: GtpLayer.h:70
@ GtpV1_MBMSNotificationResponse
Definition: GtpLayer.h:158
@ GtpV1_DeletePDPContextResponse
Definition: GtpLayer.h:94
@ GtpV1_InitiatePDPContextActivationResponse
Definition: GtpLayer.h:98
@ GtpV1_RANInformationRelay
Definition: GtpLayer.h:154
@ GtpV1_MBMSSessionStopRequest
Definition: GtpLayer.h:188
@ GtpV1_MBMSSessionUpdateRequest
Definition: GtpLayer.h:192
@ GtpV1_SupportedExtensionsHeaderNotification
Definition: GtpLayer.h:110
@ GtpV1_PDUNotificationRejectRequest
Definition: GtpLayer.h:106
@ GtpV1_GPDU
Definition: GtpLayer.h:206
@ GtpV1_MBMSSessionUpdateResponse
Definition: GtpLayer.h:194
@ GtpV1_DeletePDPContextRequest
Definition: GtpLayer.h:92
@ GtpV1_InitiatePDPContextActivationRequest
Definition: GtpLayer.h:96
@ GtpV1_PDUNotificationRequest
Definition: GtpLayer.h:102
@ GtpV1_EchoRequest
Definition: GtpLayer.h:72
@ GtpV1_ForwardRelocationComplete
Definition: GtpLayer.h:138
@ GtpV1_MBMSRegistrationRequest
Definition: GtpLayer.h:176
@ GtpV1_MBMSNotificationRejectRequest
Definition: GtpLayer.h:160
@ GtpV1_SGSNContextAcknowledge
Definition: GtpLayer.h:132
@ GtpV1_MBMSSessionStartRequest
Definition: GtpLayer.h:184
@ GtpV1_DeleteMBMSNotificationRequest
Definition: GtpLayer.h:172
@ GtpV1_ForwardRelocationResponse
Definition: GtpLayer.h:136
@ GtpV1_NodeAliveResponse
Definition: GtpLayer.h:80
@ GtpV1_UERegistrationRequest
Definition: GtpLayer.h:150
@ GtpV1_ForwardSRNSContextAcknowledge
Definition: GtpLayer.h:148
@ GtpV1_MBMSNotificationRejectResponse
Definition: GtpLayer.h:162
@ GtpV1_UERegistrationResponse
Definition: GtpLayer.h:152
@ GtpV1_CreatePDPContextResponse
Definition: GtpLayer.h:86
@ GtpV1_FailureReportResponse
Definition: GtpLayer.h:118
@ GtpV1_NoteMSPresentResponse
Definition: GtpLayer.h:122
@ GtpV1_IdentificationRequest
Definition: GtpLayer.h:124
@ GtpV1_MBMSDeRegistrationResponse
Definition: GtpLayer.h:182
@ GtpV1_MSInfoChangeResponse
Definition: GtpLayer.h:198
@ GtpV1_ForwardRelocationCompleteAcknowledge
Definition: GtpLayer.h:146
@ GtpV1_UpdatePDPContextRequest
Definition: GtpLayer.h:88
@ GtpV1_SendRoutingforGPRSRequest
Definition: GtpLayer.h:112
@ GtpV1_PDUNotificationRejectResponse
Definition: GtpLayer.h:108
@ GtpV1_UpdatePDPContextResponse
Definition: GtpLayer.h:90
@ GtpV1_SendRoutingforGPRSResponse
Definition: GtpLayer.h:114
@ GtpV1_VersionNotSupported
Definition: GtpLayer.h:76
@ GtpV1_MSInfoChangeRequest
Definition: GtpLayer.h:196
@ GtpV1_ErrorIndication
Definition: GtpLayer.h:100
@ GtpV1_UpdateMBMSNotificationResponse
Definition: GtpLayer.h:170
@ GtpV1_RelocationCancelResponse
Definition: GtpLayer.h:142
@ GtpV1_DataRecordTransferRequest
Definition: GtpLayer.h:200
@ GtpV1_MBMSNotificationRequest
Definition: GtpLayer.h:156
@ GtpV1_MBMSSessionStartResponse
Definition: GtpLayer.h:186
@ GtpV1_FailureReportRequest
Definition: GtpLayer.h:116
@ GtpV1_CreateMBMSNotificationResponse
Definition: GtpLayer.h:166
@ GtpV1_MBMSDeRegistrationRequest
Definition: GtpLayer.h:180
@ GtpV1_CreateMBMSNotificationRequest
Definition: GtpLayer.h:164
@ GtpV1_DataRecordTransferResponse
Definition: GtpLayer.h:202
@ GtpV1_MBMSSessionStopResponse
Definition: GtpLayer.h:190
@ GtpV1_UpdateMBMSNotificationRequest
Definition: GtpLayer.h:168
@ GtpV1_SGSNContextRequest
Definition: GtpLayer.h:128
@ GtpV1_RedirectionRequest
Definition: GtpLayer.h:82
@ GtpV1_EndMarker
Definition: GtpLayer.h:204
@ GtpV1_IdentificationResponse
Definition: GtpLayer.h:126
@ GtpV1_EchoResponse
Definition: GtpLayer.h:74
@ GtpV1_RelocationCancelRequest
Definition: GtpLayer.h:140
@ GtpV1_NodeAliveRequest
Definition: GtpLayer.h:78
@ GtpV1_SGSNContextResponse
Definition: GtpLayer.h:130
@ GtpV1_ForwardRelocationRequest
Definition: GtpLayer.h:134
@ GtpV1_NoteMSPresentRequest
Definition: GtpLayer.h:120
@ GtpV1_MBMSRegistrationResponse
Definition: GtpLayer.h:178
@ GtpV1_DeleteMBMSNotificationResponse
Definition: GtpLayer.h:174
@ GtpV1_CreatePDPContextRequest
Definition: GtpLayer.h:84
@ GtpV1_ForwardSRNSContext
Definition: GtpLayer.h:144
@ GtpV1_PDUNotificationResponse
Definition: GtpLayer.h:104
Definition: GtpLayer.h:20
uint8_t version
Definition: GtpLayer.h:33
uint8_t messageType
Definition: GtpLayer.h:49
uint16_t messageLength
Definition: GtpLayer.h:53
uint8_t reserved
Definition: GtpLayer.h:29
uint8_t npduNumberFlag
Definition: GtpLayer.h:23
uint32_t teid
Definition: GtpLayer.h:57
uint8_t sequenceNumberFlag
Definition: GtpLayer.h:25
uint8_t extensionHeaderFlag
Definition: GtpLayer.h:27
uint8_t protocolType
Definition: GtpLayer.h:31