mirror of https://github.com/PentHertz/srsLTE.git
Starting to change gtpu_read_header and gtpu_write_header to lib.
This commit is contained in:
parent
27dbbcca02
commit
0e135adc6f
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "srslte/common/common.h"
|
#include "srslte/common/common.h"
|
||||||
|
#include "srslte/common/log.h"
|
||||||
|
|
||||||
namespace srslte {
|
namespace srslte {
|
||||||
|
|
||||||
|
@ -58,8 +59,8 @@ typedef struct{
|
||||||
}gtpu_header_t;
|
}gtpu_header_t;
|
||||||
|
|
||||||
|
|
||||||
bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header);
|
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);
|
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 void uint8_to_uint32(uint8_t *buf, uint32_t *i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,18 +35,18 @@ namespace srslte {
|
||||||
* Ref: 3GPP TS 29.281 v10.1.0 Section 5
|
* Ref: 3GPP TS 29.281 v10.1.0 Section 5
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu)
|
bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log)
|
||||||
{
|
{
|
||||||
if(header->flags != 0x30) {
|
if(header->flags != 0x30) {
|
||||||
//gtpu_log->error("gtpu_write_header - Unhandled header flags: 0x%x\n", header->flags);
|
gtpu_log->error("gtpu_write_header - Unhandled header flags: 0x%x\n", header->flags);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(header->message_type != 0xFF) {
|
if(header->message_type != 0xFF) {
|
||||||
//gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type);
|
gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(pdu->get_headroom() < GTPU_HEADER_LEN) {
|
if(pdu->get_headroom() < GTPU_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header)
|
bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte::log *gtpu_log)
|
||||||
{
|
{
|
||||||
uint8_t *ptr = pdu->msg;
|
uint8_t *ptr = pdu->msg;
|
||||||
|
|
||||||
|
@ -82,11 +82,11 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header)
|
||||||
uint8_to_uint32(ptr, &header->teid);
|
uint8_to_uint32(ptr, &header->teid);
|
||||||
|
|
||||||
if(header->flags != 0x30) {
|
if(header->flags != 0x30) {
|
||||||
//gtpu_log->error("gtpu_read_header - Unhandled header flags: 0x%x\n", header->flags);
|
gtpu_log->error("gtpu_read_header - Unhandled header flags: 0x%x\n", header->flags);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(header->message_type != 0xFF) {
|
if(header->message_type != 0xFF) {
|
||||||
//gtpu_log->error("gtpu_read_header - Unhandled message type: 0x%x\n", header->message_type);
|
gtpu_log->error("gtpu_read_header - Unhandled message type: 0x%x\n", header->message_type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,14 +58,6 @@ namespace srsenb {
|
||||||
|
|
||||||
#define GTPU_HEADER_LEN 8
|
#define GTPU_HEADER_LEN 8
|
||||||
|
|
||||||
typedef struct{
|
|
||||||
uint8_t flags; // Only support 0x30 - v1, PT1 (GTP), no other flags
|
|
||||||
uint8_t message_type; // Only support 0xFF - T-PDU type
|
|
||||||
uint16_t length;
|
|
||||||
uint32_t teid;
|
|
||||||
}gtpu_header_t;
|
|
||||||
|
|
||||||
|
|
||||||
class gtpu
|
class gtpu
|
||||||
:public gtpu_interface_rrc
|
:public gtpu_interface_rrc
|
||||||
,public gtpu_interface_pdcp
|
,public gtpu_interface_pdcp
|
||||||
|
@ -93,8 +85,6 @@ private:
|
||||||
bool running;
|
bool running;
|
||||||
bool run_enable;
|
bool run_enable;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool enable_mbsfn;
|
bool enable_mbsfn;
|
||||||
std::string gtp_bind_addr;
|
std::string gtp_bind_addr;
|
||||||
std::string mme_addr;
|
std::string mme_addr;
|
||||||
|
@ -143,13 +133,6 @@ private:
|
||||||
|
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Header pack/unpack helper functions
|
|
||||||
* Ref: 3GPP TS 29.281 v10.1.0 Section 5
|
|
||||||
***************************************************************************/
|
|
||||||
bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu);
|
|
||||||
bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* TEID to RNIT/LCID helper functions
|
* TEID to RNIT/LCID helper functions
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
* and at http://www.gnu.org/licenses/.
|
* and at http://www.gnu.org/licenses/.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#include "srslte/upper/gtpu.h"
|
||||||
#include "srsenb/hdr/upper/gtpu.h"
|
#include "srsenb/hdr/upper/gtpu.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -31,12 +31,11 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
using namespace srslte;
|
using namespace srslte;
|
||||||
|
|
||||||
namespace srsenb {
|
namespace srsenb {
|
||||||
|
|
||||||
gtpu::gtpu():mchthread()
|
gtpu::gtpu():mchthread()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gtpu::init(std::string gtp_bind_addr_, std::string mme_addr_, srsenb::pdcp_interface_gtpu* pdcp_, srslte::log* gtpu_log_, bool enable_mbsfn)
|
bool gtpu::init(std::string gtp_bind_addr_, std::string mme_addr_, srsenb::pdcp_interface_gtpu* pdcp_, srslte::log* gtpu_log_, bool enable_mbsfn)
|
||||||
{
|
{
|
||||||
|
@ -148,7 +147,7 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu)
|
||||||
servaddr.sin_addr.s_addr = htonl(rnti_bearers[rnti].spgw_addrs[lcid]);
|
servaddr.sin_addr.s_addr = htonl(rnti_bearers[rnti].spgw_addrs[lcid]);
|
||||||
servaddr.sin_port = htons(GTPU_PORT);
|
servaddr.sin_port = htons(GTPU_PORT);
|
||||||
|
|
||||||
gtpu_write_header(&header, pdu);
|
gtpu_write_header(&header, pdu, gtpu_log);
|
||||||
if (sendto(snk_fd, pdu->msg, pdu->N_bytes, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in))<0) {
|
if (sendto(snk_fd, pdu->msg, pdu->N_bytes, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in))<0) {
|
||||||
perror("sendto");
|
perror("sendto");
|
||||||
}
|
}
|
||||||
|
@ -230,7 +229,7 @@ void gtpu::run_thread()
|
||||||
pdu->N_bytes = (uint32_t) n;
|
pdu->N_bytes = (uint32_t) n;
|
||||||
|
|
||||||
gtpu_header_t header;
|
gtpu_header_t header;
|
||||||
gtpu_read_header(pdu, &header);
|
gtpu_read_header(pdu, &header,gtpu_log);
|
||||||
|
|
||||||
uint16_t rnti = 0;
|
uint16_t rnti = 0;
|
||||||
uint16_t lcid = 0;
|
uint16_t lcid = 0;
|
||||||
|
@ -265,69 +264,6 @@ void gtpu::run_thread()
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Header pack/unpack helper functions
|
|
||||||
* Ref: 3GPP TS 29.281 v10.1.0 Section 5
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
bool gtpu::gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu)
|
|
||||||
{
|
|
||||||
if(header->flags != 0x30) {
|
|
||||||
gtpu_log->error("gtpu_write_header - Unhandled header 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);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(pdu->get_headroom() < GTPU_HEADER_LEN) {
|
|
||||||
gtpu_log->error("gtpu_write_header - No room in PDU for header\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pdu->msg -= GTPU_HEADER_LEN;
|
|
||||||
pdu->N_bytes += GTPU_HEADER_LEN;
|
|
||||||
|
|
||||||
uint8_t *ptr = pdu->msg;
|
|
||||||
|
|
||||||
*ptr = header->flags;
|
|
||||||
ptr++;
|
|
||||||
*ptr = header->message_type;
|
|
||||||
ptr++;
|
|
||||||
uint16_to_uint8(header->length, ptr);
|
|
||||||
ptr += 2;
|
|
||||||
uint32_to_uint8(header->teid, ptr);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool gtpu::gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header)
|
|
||||||
{
|
|
||||||
uint8_t *ptr = pdu->msg;
|
|
||||||
|
|
||||||
pdu->msg += GTPU_HEADER_LEN;
|
|
||||||
pdu->N_bytes -= GTPU_HEADER_LEN;
|
|
||||||
|
|
||||||
header->flags = *ptr;
|
|
||||||
ptr++;
|
|
||||||
header->message_type = *ptr;
|
|
||||||
ptr++;
|
|
||||||
uint8_to_uint16(ptr, &header->length);
|
|
||||||
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);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(header->message_type != 0xFF) {
|
|
||||||
gtpu_log->error("gtpu_read_header - Unhandled message type: 0x%x\n", header->message_type);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* TEID to RNIT/LCID helper functions
|
* TEID to RNIT/LCID helper functions
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
@ -429,7 +365,7 @@ void gtpu::mch_thread::run_thread()
|
||||||
pdu->N_bytes = (uint32_t) n;
|
pdu->N_bytes = (uint32_t) n;
|
||||||
|
|
||||||
gtpu_header_t header;
|
gtpu_header_t header;
|
||||||
gtpu_read_header(pdu, &header);
|
gtpu_read_header(pdu, &header, gtpu_log);
|
||||||
|
|
||||||
pdcp->write_sdu(SRSLTE_MRNTI, lcid, pdu);
|
pdcp->write_sdu(SRSLTE_MRNTI, lcid, pdu);
|
||||||
do {
|
do {
|
||||||
|
|
Loading…
Reference in New Issue