Dropping bitfields for now. Using #defines and uint8_t for the flags.

master
Pedro Alvarez 6 years ago
parent e320c33aef
commit c1f633c5c7

@ -56,10 +56,13 @@ namespace srslte {
#define GTPU_BASE_HEADER_LEN 8 #define GTPU_BASE_HEADER_LEN 8
#define GTPU_EXTENDED_HEADER_LEN 12 #define GTPU_EXTENDED_HEADER_LEN 12
#define GTPU_VERSION_V1 1 #define GTPU_FLAGS_VERSION_MASK 0xE0
#define GTPU_FLAGS_VERSION_V1 0x20
#define GTP_PRIME_PROTO 0 #define GTPU_FLAGS_GTP_PRIME_PROTOCOL 0x00
#define GTP_PROTO 1 #define GTPU_FLAGS_GTP_PROTOCOL 0x10
#define GTPU_FLAGS_EXTENDED_HDR 0x04
#define GTPU_FLAGS_SEQUENCE 0x02
#define GTPU_FLAGS_PACKET_NUM 0x01
#define GTPU_MSG_ECHO_REQUEST 0 #define GTPU_MSG_ECHO_REQUEST 0
#define GTPU_MSG_ECHO_RESPONSE 1 #define GTPU_MSG_ECHO_RESPONSE 1
@ -69,19 +72,7 @@ namespace srslte {
#define GTPU_MSG_DATA_PDU 255 #define GTPU_MSG_DATA_PDU 255
typedef struct{ typedef struct{
uint8_t version : 3;
uint8_t protocol_type : 1;
uint8_t star : 1;
uint8_t ext_header :1;
uint8_t sequence :1;
uint8_t pkt_number :1;
}gtpu_flags_t;
typedef struct{
union{
gtpu_flags_t flag_bits;
uint8_t flags; uint8_t flags;
} gtpu_flags;
uint8_t message_type; uint8_t message_type;
uint16_t length; uint16_t length;
uint32_t teid; uint32_t teid;
@ -94,35 +85,38 @@ typedef struct{
bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte::log *gtpu_log); bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte::log *gtpu_log);
bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log); bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log);
inline void uint8_to_uint32(uint8_t *buf, uint32_t *i) inline bool gtpu_supported_flags_check(gtpu_header_t *header, srslte::log *gtpu_log)
{
*i = (uint32_t)buf[0] << 24 |
(uint32_t)buf[1] << 16 |
(uint32_t)buf[2] << 8 |
(uint32_t)buf[3];
}
inline void uint32_to_uint8(uint32_t i, uint8_t *buf)
{ {
buf[0] = (i >> 24) & 0xFF; //flags
buf[1] = (i >> 16) & 0xFF; if( (header->flags & GTPU_FLAGS_VERSION_MASK) != GTPU_FLAGS_VERSION_V1 ) {
buf[2] = (i >> 8) & 0xFF; gtpu_log->error("gtpu_write_header - Unhandled GTP-U Version.\n");
buf[3] = i & 0xFF; return false;
}
if( !(header->flags & GTPU_FLAGS_GTP_PROTOCOL) ) {
gtpu_log->error("gtpu_write_header - Unhandled Protocol Type.\n");
return false;
}
if( !(header->flags & GTPU_FLAGS_EXTENDED_HDR) ) {
gtpu_log->error("gtpu_write_header - Unhandled Header Extensions.\n");
return false;
}
if( !(header->flags & GTPU_FLAGS_PACKET_NUM) ) {
gtpu_log->error("gtpu_write_header - Unhandled Packet Number.\n");
return false;
}
return true;
} }
inline void uint8_to_uint16(uint8_t *buf, uint16_t *i) inline bool gtpu_supported_msg_type_check(gtpu_header_t *header, srslte::log *gtpu_log)
{ {
*i = (uint32_t)buf[0] << 8 | //msg_tpye
(uint32_t)buf[1]; if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) {
gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type);
return false;
}
return true;
} }
inline void uint16_to_uint8(uint16_t i, uint8_t *buf)
{
buf[0] = (i >> 8) & 0xFF;
buf[1] = i & 0xFF;
}
}//namespace }//namespace
#endif #endif

@ -26,7 +26,7 @@
#include "srslte/upper/gtpu.h" #include "srslte/upper/gtpu.h"
#include "srslte/common/int_helpers.h"
namespace srslte { namespace srslte {
@ -37,40 +37,45 @@ namespace srslte {
bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log) bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log)
{ {
//flags
if(header->gtpu_flags.flag_bits.version != GTPU_VERSION_V1) { if(!gtpu_supported_flags_check(header,gtpu_log)){
gtpu_log->error("gtpu_write_header - Unhandled GTP-U Version.\n");
return false;
}
if(header->gtpu_flags.flag_bits.protocol_type != GTP_PROTO) {
gtpu_log->error("gtpu_write_header - Unhandled Protocol Type.\n");
return false; return false;
} }
if(header->gtpu_flags.flag_bits.ext_header) {
gtpu_log->error("gtpu_write_header - Unhandled Header Extensions.\n"); //msg type
if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) {
gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type);
return false; return false;
} }
if(header->message_type != GTPU_MSG_DATA_PDU) {
gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type); //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; return false;
} }
pdu->msg -= GTPU_EXTENDED_HEADER_LEN;
pdu->N_bytes += GTPU_EXTENDED_HEADER_LEN;
} else {
if(pdu->get_headroom() < GTPU_BASE_HEADER_LEN) { if(pdu->get_headroom() < GTPU_BASE_HEADER_LEN) {
gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); gtpu_log->error("gtpu_write_header - No room in PDU for header\n");
return false; return false;
} }
pdu->msg -= GTPU_BASE_HEADER_LEN; pdu->msg -= GTPU_BASE_HEADER_LEN;
pdu->N_bytes += GTPU_BASE_HEADER_LEN; pdu->N_bytes += GTPU_BASE_HEADER_LEN;
}
//write mandatory fields
uint8_t *ptr = pdu->msg; uint8_t *ptr = pdu->msg;
*ptr = header->flags;
*ptr = header->gtpu_flags.flags;
ptr++; ptr++;
*ptr = header->message_type; *ptr = header->message_type;
ptr++; ptr++;
uint16_to_uint8(header->length, ptr); uint16_to_uint8(header->length, ptr);
ptr += 2; ptr += 2;
uint32_to_uint8(header->teid, ptr); uint32_to_uint8(header->teid, ptr);
//write optional fields
return true; return true;
} }
@ -79,7 +84,7 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte:
{ {
uint8_t *ptr = pdu->msg; uint8_t *ptr = pdu->msg;
header->gtpu_flags.flags = *ptr; header->flags = *ptr;
ptr++; ptr++;
header->message_type = *ptr; header->message_type = *ptr;
ptr++; ptr++;
@ -87,21 +92,18 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte:
ptr += 2; ptr += 2;
uint8_to_uint32(ptr, &header->teid); uint8_to_uint32(ptr, &header->teid);
if(header->gtpu_flags.flag_bits.version != GTPU_VERSION_V1) { //flags
gtpu_log->error("gtpu_read_header - Unhandled GTP-U version. Flags: 0x%x\n", header->gtpu_flags.flags); if(!gtpu_supported_flags_check(header,gtpu_log)){
return false;
}
if(header->gtpu_flags.flag_bits.protocol_type != GTP_PROTO) {
gtpu_log->error("gtpu_read_header - Unhandled GTP Protocol. Flags: 0x%x\n", header->gtpu_flags.flags);
return false; return false;
} }
if(header->gtpu_flags.flag_bits.ext_header) {
gtpu_log->error("gtpu_read_header - Unhandled GTP-U Header Extensions. Flags: 0x%x\n", header->gtpu_flags.flags); //message_type
if(!gtpu_supported_msg_type_check(header,gtpu_log)){
return false; return false;
} }
//If E, S or PN are set, header is longer //If E, S or PN are set, header is longer
if(header->gtpu_flags.flag_bits.sequence || header->gtpu_flags.flag_bits.ext_header || header->gtpu_flags.flag_bits.ext_header) { if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) {
pdu->msg += GTPU_EXTENDED_HEADER_LEN; pdu->msg += GTPU_EXTENDED_HEADER_LEN;
pdu->N_bytes -= GTPU_EXTENDED_HEADER_LEN; pdu->N_bytes -= GTPU_EXTENDED_HEADER_LEN;
@ -118,15 +120,6 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte:
pdu->N_bytes -= GTPU_BASE_HEADER_LEN; pdu->N_bytes -= GTPU_BASE_HEADER_LEN;
} }
if(header->gtpu_flags.flag_bits.sequence){
ptr+=2;
}
if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) {
gtpu_log->error("gtpu_read_header - Unhandled message type: 0x%x\n", header->message_type);
return false;
}
return true; return true;
} }

@ -122,9 +122,7 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu)
{ {
gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d, n_bytes=%d", rnti, lcid, pdu->N_bytes); gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d, n_bytes=%d", rnti, lcid, pdu->N_bytes);
gtpu_header_t header; gtpu_header_t header;
bzero(&header,sizeof(header)); header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL;
header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1;
header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO;
header.message_type = GTPU_MSG_DATA_PDU; header.message_type = GTPU_MSG_DATA_PDU;
header.length = pdu->N_bytes; header.length = pdu->N_bytes;
header.teid = rnti_bearers[rnti].teids_out[lcid]; header.teid = rnti_bearers[rnti].teids_out[lcid];
@ -280,19 +278,16 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq)
gtpu_log->info("TX GTPU Echo Response, Seq: %d\n", seq); gtpu_log->info("TX GTPU Echo Response, Seq: %d\n", seq);
gtpu_header_t header; gtpu_header_t header;
bzero(&header, sizeof(header));
srslte::byte_buffer_t *pdu = pool_allocate; srslte::byte_buffer_t *pdu = pool_allocate;
//flags //header
header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL | GTPU_FLAGS_SEQUENCE;
header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO;
header.gtpu_flags.flag_bits.sequence = 1;
header.message_type = GTPU_MSG_ECHO_RESPONSE; header.message_type = GTPU_MSG_ECHO_RESPONSE;
header.teid = 0; header.teid = 0;
header.length = 4; header.length = 4;
header.seq_number = seq; header.seq_number = seq;
header.n_pdu = 0;
header.next_ext_hdr_type = 0;
gtpu_write_header(&header,pdu,gtpu_log); gtpu_write_header(&header,pdu,gtpu_log);

@ -285,11 +285,9 @@ mbms_gw::handle_sgi_md_pdu(srslte::byte_buffer_t *msg)
{ {
uint8_t version; uint8_t version;
srslte::gtpu_header_t header; srslte::gtpu_header_t header;
bzero(&header, sizeof(srslte::gtpu_header_t));
//Setup GTP-U header //Setup GTP-U header
header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL;
header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO;
header.message_type = GTPU_MSG_DATA_PDU; header.message_type = GTPU_MSG_DATA_PDU;
header.length = msg->N_bytes; header.length = msg->N_bytes;
header.teid = 0xAAAA; //FIXME Harcoded TEID for now header.teid = 0xAAAA; //FIXME Harcoded TEID for now

@ -359,9 +359,7 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg)
//Setup GTP-U header //Setup GTP-U header
srslte::gtpu_header_t header; srslte::gtpu_header_t header;
bzero(&header,sizeof(srslte::gtpu_header_t)); header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL;
header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1;
header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO;
header.message_type = GTPU_MSG_DATA_PDU; header.message_type = GTPU_MSG_DATA_PDU;
header.length = msg->N_bytes; header.length = msg->N_bytes;
header.teid = enb_fteid.teid; header.teid = enb_fteid.teid;

Loading…
Cancel
Save