2020-11-26 01:25:22 -08:00
|
|
|
/**
|
2017-12-07 09:09:31 -08:00
|
|
|
*
|
2020-11-26 01:25:22 -08:00
|
|
|
* \section COPYRIGHT
|
2017-12-07 09:09:31 -08:00
|
|
|
*
|
2020-11-26 01:25:22 -08:00
|
|
|
* Copyright 2013-2020 Software Radio Systems Limited
|
2017-12-07 09:09:31 -08:00
|
|
|
*
|
2020-11-26 01:25:22 -08:00
|
|
|
* By using this file, you agree to the terms and conditions set
|
|
|
|
* forth in the LICENSE file which can be found at the top level of
|
|
|
|
* the distribution.
|
2017-12-07 09:09:31 -08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRSLTE_GTPU_H
|
|
|
|
#define SRSLTE_GTPU_H
|
|
|
|
|
|
|
|
#include "srslte/common/common.h"
|
2020-03-25 07:57:29 -07:00
|
|
|
#include "srslte/common/logmap.h"
|
2019-12-16 07:04:22 -08:00
|
|
|
#include <stdint.h>
|
2017-12-07 09:09:31 -08:00
|
|
|
|
|
|
|
namespace srslte {
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* GTPU Header
|
|
|
|
* Ref: 3GPP TS 29.281 v10.1.0 Section 5
|
|
|
|
*
|
|
|
|
* | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
|
|
|
|
*
|
|
|
|
* 1 | Version |PT | * | E | S |PN |
|
2018-09-28 05:46:13 -07:00
|
|
|
* 2 | Message Type |
|
|
|
|
* 3 | Length (1st Octet) |
|
|
|
|
* 4 | Length (2nd Octet) |
|
|
|
|
* 5 | TEID (1st Octet) |
|
|
|
|
* 6 | TEID (2nd Octet) |
|
|
|
|
* 7 | TEID (3rd Octet) |
|
|
|
|
* 8 | TEID (4th Octet) |
|
|
|
|
* 9 | Seq Number (1st Octet) |
|
|
|
|
* 10 | Seq Number (2st Octet) |
|
|
|
|
* 11 | N-PDU |
|
|
|
|
* 12 | Next Extension Header Type |
|
2017-12-07 09:09:31 -08:00
|
|
|
***************************************************************************/
|
|
|
|
|
2018-09-28 05:46:13 -07:00
|
|
|
#define GTPU_BASE_HEADER_LEN 8
|
|
|
|
#define GTPU_EXTENDED_HEADER_LEN 12
|
|
|
|
|
2018-10-01 07:17:26 -07:00
|
|
|
#define GTPU_FLAGS_VERSION_MASK 0xE0
|
|
|
|
#define GTPU_FLAGS_VERSION_V1 0x20
|
|
|
|
#define GTPU_FLAGS_GTP_PRIME_PROTOCOL 0x00
|
|
|
|
#define GTPU_FLAGS_GTP_PROTOCOL 0x10
|
|
|
|
#define GTPU_FLAGS_EXTENDED_HDR 0x04
|
|
|
|
#define GTPU_FLAGS_SEQUENCE 0x02
|
|
|
|
#define GTPU_FLAGS_PACKET_NUM 0x01
|
2018-09-28 05:46:13 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
#define GTPU_MSG_ECHO_REQUEST 1
|
|
|
|
#define GTPU_MSG_ECHO_RESPONSE 2
|
|
|
|
#define GTPU_MSG_ERROR_INDICATION 26
|
|
|
|
#define GTPU_MSG_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION 31
|
|
|
|
#define GTPU_MSG_END_MARKER 254
|
|
|
|
#define GTPU_MSG_DATA_PDU 255
|
2017-12-07 09:09:31 -08:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
typedef struct {
|
|
|
|
uint8_t flags;
|
|
|
|
uint8_t message_type;
|
|
|
|
uint16_t length;
|
|
|
|
uint32_t teid;
|
|
|
|
uint16_t seq_number;
|
|
|
|
uint8_t n_pdu;
|
|
|
|
uint8_t next_ext_hdr_type;
|
|
|
|
} gtpu_header_t;
|
2017-12-07 09:09:31 -08:00
|
|
|
|
2020-03-25 07:57:29 -07:00
|
|
|
bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslte::log_ref gtpu_log);
|
|
|
|
bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslte::log_ref gtpu_log);
|
2019-04-29 07:37:13 -07:00
|
|
|
std::string gtpu_ntoa(uint32_t addr);
|
2017-12-07 09:09:31 -08:00
|
|
|
|
2020-03-25 07:57:29 -07:00
|
|
|
inline bool gtpu_supported_flags_check(gtpu_header_t* header, srslte::log_ref gtpu_log)
|
2017-12-07 09:09:31 -08:00
|
|
|
{
|
2019-12-16 07:04:22 -08:00
|
|
|
// flags
|
|
|
|
if ((header->flags & GTPU_FLAGS_VERSION_MASK) != GTPU_FLAGS_VERSION_V1) {
|
2018-10-01 09:34:02 -07:00
|
|
|
gtpu_log->error("gtpu_header - Unhandled GTP-U Version. Flags: 0x%x\n", header->flags);
|
2018-10-01 07:17:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-16 07:04:22 -08:00
|
|
|
if (!(header->flags & GTPU_FLAGS_GTP_PROTOCOL)) {
|
2018-10-01 09:34:02 -07:00
|
|
|
gtpu_log->error("gtpu_header - Unhandled Protocol Type. Flags: 0x%x\n\n", header->flags);
|
2018-10-01 07:17:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-16 07:04:22 -08:00
|
|
|
if (header->flags & GTPU_FLAGS_EXTENDED_HDR) {
|
2018-10-01 09:34:02 -07:00
|
|
|
gtpu_log->error("gtpu_header - Unhandled Header Extensions. Flags: 0x%x\n\n", header->flags);
|
2018-10-01 07:17:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-16 07:04:22 -08:00
|
|
|
if (header->flags & GTPU_FLAGS_PACKET_NUM) {
|
2018-10-01 09:34:02 -07:00
|
|
|
gtpu_log->error("gtpu_header - Unhandled Packet Number. Flags: 0x%x\n\n", header->flags);
|
2018-10-01 07:17:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-12-07 09:09:31 -08:00
|
|
|
}
|
|
|
|
|
2020-03-25 07:57:29 -07:00
|
|
|
inline bool gtpu_supported_msg_type_check(gtpu_header_t* header, srslte::log_ref gtpu_log)
|
2017-12-07 09:09:31 -08:00
|
|
|
{
|
2019-12-16 07:04:22 -08:00
|
|
|
// msg_tpye
|
|
|
|
if (header->message_type != GTPU_MSG_DATA_PDU && header->message_type != GTPU_MSG_ECHO_REQUEST &&
|
2020-11-27 09:28:06 -08:00
|
|
|
header->message_type != GTPU_MSG_ECHO_RESPONSE && header->message_type != GTPU_MSG_ERROR_INDICATION &&
|
|
|
|
header->message_type != GTPU_MSG_END_MARKER) {
|
2018-10-01 09:34:02 -07:00
|
|
|
gtpu_log->error("gtpu_header - Unhandled message type: 0x%x\n", header->message_type);
|
2018-10-01 07:17:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-12-07 09:09:31 -08:00
|
|
|
}
|
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
} // namespace srslte
|
2017-12-07 09:09:31 -08:00
|
|
|
|
|
|
|
#endif
|