|
|
|
@ -26,7 +26,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "srslte/upper/gtpu.h"
|
|
|
|
|
|
|
|
|
|
#include "srslte/common/int_helpers.h"
|
|
|
|
|
|
|
|
|
|
namespace srslte {
|
|
|
|
|
|
|
|
|
@ -37,24 +37,37 @@ namespace srslte {
|
|
|
|
|
|
|
|
|
|
bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log)
|
|
|
|
|
{
|
|
|
|
|
if(header->flags != 0x30) {
|
|
|
|
|
gtpu_log->error("gtpu_write_header - Unhandled header flags: 0x%x\n", header->flags);
|
|
|
|
|
//flags
|
|
|
|
|
if(!gtpu_supported_flags_check(header,gtpu_log)){
|
|
|
|
|
gtpu_log->error("gtpu_write_header - Unhandled GTP-U Flags. Flags: 0x%x\n", header->flags);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(header->message_type != 0xFF) {
|
|
|
|
|
gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type);
|
|
|
|
|
|
|
|
|
|
//msg type
|
|
|
|
|
if(!gtpu_supported_msg_type_check(header,gtpu_log)){
|
|
|
|
|
gtpu_log->error("gtpu_write_header - Unhandled GTP-U Message Type. Message Type: 0x%x\n", header->message_type);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(pdu->get_headroom() < GTPU_HEADER_LEN) {
|
|
|
|
|
|
|
|
|
|
//If E, S or PN are set, the header is longer
|
|
|
|
|
if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) {
|
|
|
|
|
if(pdu->get_headroom() < GTPU_EXTENDED_HEADER_LEN) {
|
|
|
|
|
gtpu_log->error("gtpu_write_header - No room in PDU for header\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
pdu->msg -= GTPU_EXTENDED_HEADER_LEN;
|
|
|
|
|
pdu->N_bytes += GTPU_EXTENDED_HEADER_LEN;
|
|
|
|
|
} else {
|
|
|
|
|
if(pdu->get_headroom() < GTPU_BASE_HEADER_LEN) {
|
|
|
|
|
gtpu_log->error("gtpu_write_header - No room in PDU for header\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
pdu->msg -= GTPU_BASE_HEADER_LEN;
|
|
|
|
|
pdu->N_bytes += GTPU_BASE_HEADER_LEN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pdu->msg -= GTPU_HEADER_LEN;
|
|
|
|
|
pdu->N_bytes += GTPU_HEADER_LEN;
|
|
|
|
|
|
|
|
|
|
//write mandatory fields
|
|
|
|
|
uint8_t *ptr = pdu->msg;
|
|
|
|
|
|
|
|
|
|
*ptr = header->flags;
|
|
|
|
|
ptr++;
|
|
|
|
|
*ptr = header->message_type;
|
|
|
|
@ -62,7 +75,30 @@ bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte
|
|
|
|
|
uint16_to_uint8(header->length, ptr);
|
|
|
|
|
ptr += 2;
|
|
|
|
|
uint32_to_uint8(header->teid, ptr);
|
|
|
|
|
|
|
|
|
|
//write optional fields, if E, S or PN are set.
|
|
|
|
|
if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) {
|
|
|
|
|
//S
|
|
|
|
|
if (header->flags & GTPU_FLAGS_SEQUENCE ) {
|
|
|
|
|
uint16_to_uint8(header->seq_number, ptr);
|
|
|
|
|
} else {
|
|
|
|
|
uint16_to_uint8(0, ptr);
|
|
|
|
|
}
|
|
|
|
|
ptr+=2;
|
|
|
|
|
//PN
|
|
|
|
|
if (header->flags & GTPU_FLAGS_PACKET_NUM ) {
|
|
|
|
|
*ptr = header->n_pdu;
|
|
|
|
|
} else {
|
|
|
|
|
header->n_pdu = 0;
|
|
|
|
|
}
|
|
|
|
|
ptr++;
|
|
|
|
|
//E
|
|
|
|
|
if (header->flags & GTPU_FLAGS_EXTENDED_HDR ) {
|
|
|
|
|
*ptr = header->next_ext_hdr_type;
|
|
|
|
|
} else {
|
|
|
|
|
*ptr = 0;
|
|
|
|
|
}
|
|
|
|
|
ptr++;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -70,9 +106,6 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte:
|
|
|
|
|
{
|
|
|
|
|
uint8_t *ptr = pdu->msg;
|
|
|
|
|
|
|
|
|
|
pdu->msg += GTPU_HEADER_LEN;
|
|
|
|
|
pdu->N_bytes -= GTPU_HEADER_LEN;
|
|
|
|
|
|
|
|
|
|
header->flags = *ptr;
|
|
|
|
|
ptr++;
|
|
|
|
|
header->message_type = *ptr;
|
|
|
|
@ -81,15 +114,36 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte:
|
|
|
|
|
ptr += 2;
|
|
|
|
|
uint8_to_uint32(ptr, &header->teid);
|
|
|
|
|
|
|
|
|
|
if(header->flags != 0x30) {
|
|
|
|
|
gtpu_log->error("gtpu_read_header - Unhandled header flags: 0x%x\n", header->flags);
|
|
|
|
|
//flags
|
|
|
|
|
if(!gtpu_supported_flags_check(header,gtpu_log)){
|
|
|
|
|
gtpu_log->error("gtpu_read_header - Unhandled GTP-U Flags. Flags: 0x%x\n", header->flags);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(header->message_type != 0xFF) {
|
|
|
|
|
gtpu_log->error("gtpu_read_header - Unhandled message type: 0x%x\n", header->message_type);
|
|
|
|
|
|
|
|
|
|
//message_type
|
|
|
|
|
if(!gtpu_supported_msg_type_check(header,gtpu_log)){
|
|
|
|
|
gtpu_log->error("gtpu_read_header - Unhandled GTP-U Message Type. Flags: 0x%x\n", header->message_type);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//If E, S or PN are set, header is longer
|
|
|
|
|
if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) {
|
|
|
|
|
pdu->msg += GTPU_EXTENDED_HEADER_LEN;
|
|
|
|
|
pdu->N_bytes -= GTPU_EXTENDED_HEADER_LEN;
|
|
|
|
|
|
|
|
|
|
uint8_to_uint16(ptr, &header->seq_number);
|
|
|
|
|
ptr+=2;
|
|
|
|
|
|
|
|
|
|
header->n_pdu = *ptr;
|
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
|
|
header->next_ext_hdr_type = *ptr;
|
|
|
|
|
ptr++;
|
|
|
|
|
} else {
|
|
|
|
|
pdu->msg += GTPU_BASE_HEADER_LEN;
|
|
|
|
|
pdu->N_bytes -= GTPU_BASE_HEADER_LEN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|