|
|
@ -105,265 +105,266 @@ bool gtpu::init(std::string gtp_bind_addr_, std::string mme_addr_, srsenb::pdcp_
|
|
|
|
|
|
|
|
|
|
|
|
bool gtpu::init_m1u(srslte::log* gtpu_log_)
|
|
|
|
bool gtpu::init_m1u(srslte::log* gtpu_log_)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct sockaddr_in bindaddr;
|
|
|
|
struct sockaddr_in bindaddr;
|
|
|
|
// Set up sink socket
|
|
|
|
// Set up sink socket
|
|
|
|
m1u_sd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
m1u_sd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (m1u_sd < 0) {
|
|
|
|
if (m1u_sd < 0) {
|
|
|
|
gtpu_log->error("Failed to create M1-U sink socket\n");
|
|
|
|
gtpu_log->error("Failed to create M1-U sink socket\n");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Bind socket */
|
|
|
|
/* Bind socket */
|
|
|
|
bzero((char *)&bindaddr, sizeof(struct sockaddr_in));
|
|
|
|
bzero((char *)&bindaddr, sizeof(struct sockaddr_in));
|
|
|
|
bindaddr.sin_family = AF_INET;
|
|
|
|
bindaddr.sin_family = AF_INET;
|
|
|
|
bindaddr.sin_addr.s_addr = htonl(INADDR_ANY); //Multicast sockets require bind to INADDR_ANY
|
|
|
|
bindaddr.sin_addr.s_addr = htonl(INADDR_ANY); //Multicast sockets require bind to INADDR_ANY
|
|
|
|
bindaddr.sin_port = htons(GTPU_PORT+1);
|
|
|
|
bindaddr.sin_port = htons(GTPU_PORT+1);
|
|
|
|
size_t addrlen = sizeof(bindaddr);
|
|
|
|
size_t addrlen = sizeof(bindaddr);
|
|
|
|
|
|
|
|
|
|
|
|
if (bind(m1u_sd, (struct sockaddr *) &bindaddr, sizeof(bindaddr)) < 0) {
|
|
|
|
if (bind(m1u_sd, (struct sockaddr *) &bindaddr, sizeof(bindaddr)) < 0) {
|
|
|
|
gtpu_log->error("Failed to bind multicast socket\n");
|
|
|
|
gtpu_log->error("Failed to bind multicast socket\n");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Send an ADD MEMBERSHIP message via setsockopt */
|
|
|
|
/* Send an ADD MEMBERSHIP message via setsockopt */
|
|
|
|
struct ip_mreq mreq;
|
|
|
|
struct ip_mreq mreq;
|
|
|
|
mreq.imr_multiaddr.s_addr = inet_addr("239.255.0.1"); //Multicast address of the service
|
|
|
|
mreq.imr_multiaddr.s_addr = inet_addr("239.255.0.1"); //Multicast address of the service
|
|
|
|
mreq.imr_interface.s_addr = inet_addr("127.0.1.200"); //Address of the IF the socket will listen to.
|
|
|
|
mreq.imr_interface.s_addr = inet_addr("127.0.1.200"); //Address of the IF the socket will listen to.
|
|
|
|
if (setsockopt(m1u_sd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
|
|
|
if (setsockopt(m1u_sd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
|
|
|
&mreq, sizeof(mreq)) < 0) {
|
|
|
|
&mreq, sizeof(mreq)) < 0) {
|
|
|
|
gtpu_log->error("Register musticast group for M1-U\n");
|
|
|
|
gtpu_log->error("Register musticast group for M1-U\n");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gtpu_log->info("M1-U initialized\n");
|
|
|
|
gtpu_log->info("M1-U initialized\n");
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gtpu::run_mch_thread(){
|
|
|
|
void gtpu::run_mch_thread()
|
|
|
|
|
|
|
|
{
|
|
|
|
byte_buffer_t *pdu;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mch_run_enable = true;
|
|
|
|
byte_buffer_t *pdu;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
socklen_t addrlen;
|
|
|
|
|
|
|
|
sockaddr_in src_addr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bzero((char *)&src_addr, sizeof(src_addr));
|
|
|
|
mch_run_enable = true;
|
|
|
|
src_addr.sin_family = AF_INET;
|
|
|
|
int n;
|
|
|
|
src_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
socklen_t addrlen;
|
|
|
|
src_addr.sin_port = htons(GTPU_PORT+1);
|
|
|
|
sockaddr_in src_addr;
|
|
|
|
addrlen = sizeof(src_addr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pdu = pool->allocate();
|
|
|
|
bzero((char *)&src_addr, sizeof(src_addr));
|
|
|
|
mch_running=true;
|
|
|
|
src_addr.sin_family = AF_INET;
|
|
|
|
|
|
|
|
src_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
|
|
|
|
src_addr.sin_port = htons(GTPU_PORT+1);
|
|
|
|
|
|
|
|
addrlen = sizeof(src_addr);
|
|
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
pdu = pool->allocate();
|
|
|
|
uint16_t lcid = mch_lcid_counter;
|
|
|
|
mch_running=true;
|
|
|
|
mch_lcid_counter++;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(mch_run_enable) {
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
|
|
|
|
uint16_t lcid = mch_lcid_counter;
|
|
|
|
|
|
|
|
mch_lcid_counter++;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
|
|
|
|
pdu->reset();
|
|
|
|
while(mch_run_enable) {
|
|
|
|
do{
|
|
|
|
|
|
|
|
n = recvfrom(m1u_sd, pdu->msg, SRSENB_MAX_BUFFER_SIZE_BYTES - SRSENB_BUFFER_HEADER_OFFSET, 0, (struct sockaddr *) &src_addr, &addrlen);
|
|
|
|
|
|
|
|
} while (n == -1 && errno == EAGAIN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pdu->N_bytes = (uint32_t) n;
|
|
|
|
pdu->reset();
|
|
|
|
|
|
|
|
do{
|
|
|
|
|
|
|
|
n = recvfrom(m1u_sd, pdu->msg, SRSENB_MAX_BUFFER_SIZE_BYTES - SRSENB_BUFFER_HEADER_OFFSET, 0, (struct sockaddr *) &src_addr, &addrlen);
|
|
|
|
|
|
|
|
} while (n == -1 && errno == EAGAIN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pdu->N_bytes = (uint32_t) n;
|
|
|
|
|
|
|
|
|
|
|
|
gtpu_header_t header;
|
|
|
|
|
|
|
|
gtpu_read_header(pdu, &header);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t rnti = 0xFFFD;
|
|
|
|
gtpu_header_t header;
|
|
|
|
|
|
|
|
gtpu_read_header(pdu, &header);
|
|
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
uint16_t rnti = 0xFFFD;
|
|
|
|
bool user_exists = (rnti_bearers.count(rnti) > 0);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!user_exists) {
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
gtpu_log->error("Unrecognized RNTI for DL PDU: 0x%x - dropping packet\n", rnti);
|
|
|
|
bool user_exists = (rnti_bearers.count(rnti) > 0);
|
|
|
|
continue;
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(lcid == 0 || lcid >= SRSENB_N_RADIO_BEARERS) {
|
|
|
|
if(!user_exists) {
|
|
|
|
gtpu_log->error("Invalid LCID for DL PDU: %d - dropping packet\n", lcid);
|
|
|
|
gtpu_log->error("Unrecognized RNTI for DL PDU: 0x%x - dropping packet\n", rnti);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pdcp->write_sdu(rnti, lcid, pdu);
|
|
|
|
if(lcid == 0 || lcid >= SRSENB_N_RADIO_BEARERS) {
|
|
|
|
do {
|
|
|
|
gtpu_log->error("Invalid LCID for DL PDU: %d - dropping packet\n", lcid);
|
|
|
|
pdu = pool_allocate;
|
|
|
|
continue;
|
|
|
|
if (!pdu) {
|
|
|
|
|
|
|
|
gtpu_log->console("GTPU Buffer pool empty. Trying again...\n");
|
|
|
|
|
|
|
|
usleep(10000);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(!pdu);
|
|
|
|
|
|
|
|
}
|
|
|
|
pdcp->write_sdu(rnti, lcid, pdu);
|
|
|
|
mch_running=false;
|
|
|
|
do {
|
|
|
|
|
|
|
|
pdu = pool_allocate;
|
|
|
|
|
|
|
|
if (!pdu) {
|
|
|
|
|
|
|
|
gtpu_log->console("GTPU Buffer pool empty. Trying again...\n");
|
|
|
|
|
|
|
|
usleep(10000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(!pdu);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mch_running=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gtpu::stop()
|
|
|
|
void gtpu::stop()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (run_enable) {
|
|
|
|
if (run_enable) {
|
|
|
|
run_enable = false;
|
|
|
|
run_enable = false;
|
|
|
|
if(mch_run_enable)
|
|
|
|
if(mch_run_enable)
|
|
|
|
mch_run_enable = false;
|
|
|
|
mch_run_enable = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Wait thread to exit gracefully otherwise might leave a mutex locked
|
|
|
|
// Wait thread to exit gracefully otherwise might leave a mutex locked
|
|
|
|
int cnt=0;
|
|
|
|
int cnt=0;
|
|
|
|
while(running && cnt<100) {
|
|
|
|
while(running && cnt<100) {
|
|
|
|
usleep(10000);
|
|
|
|
usleep(10000);
|
|
|
|
cnt++;
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (running) {
|
|
|
|
if (running) {
|
|
|
|
thread_cancel();
|
|
|
|
thread_cancel();
|
|
|
|
if(mch_running)
|
|
|
|
if(mch_running)
|
|
|
|
pthread_cancel(mch_thread);
|
|
|
|
pthread_cancel(mch_thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wait_thread_finish();
|
|
|
|
wait_thread_finish();
|
|
|
|
pthread_join(mch_thread, NULL);
|
|
|
|
pthread_join(mch_thread, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (snk_fd) {
|
|
|
|
if (snk_fd) {
|
|
|
|
close(snk_fd);
|
|
|
|
close(snk_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (src_fd) {
|
|
|
|
if (src_fd) {
|
|
|
|
close(src_fd);
|
|
|
|
close(src_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// gtpu_interface_pdcp
|
|
|
|
// gtpu_interface_pdcp
|
|
|
|
void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu)
|
|
|
|
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;
|
|
|
|
header.flags = 0x30;
|
|
|
|
header.flags = 0x30;
|
|
|
|
header.message_type = 0xFF;
|
|
|
|
header.message_type = 0xFF;
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
|
|
struct sockaddr_in servaddr;
|
|
|
|
struct sockaddr_in servaddr;
|
|
|
|
servaddr.sin_family = AF_INET;
|
|
|
|
servaddr.sin_family = AF_INET;
|
|
|
|
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);
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pool->deallocate(pdu);
|
|
|
|
pool->deallocate(pdu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// gtpu_interface_rrc
|
|
|
|
// gtpu_interface_rrc
|
|
|
|
void gtpu::add_bearer(uint16_t rnti, uint32_t lcid, uint32_t addr, uint32_t teid_out, uint32_t *teid_in)
|
|
|
|
void gtpu::add_bearer(uint16_t rnti, uint32_t lcid, uint32_t addr, uint32_t teid_out, uint32_t *teid_in)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Allocate a TEID for the incoming tunnel
|
|
|
|
// Allocate a TEID for the incoming tunnel
|
|
|
|
rntilcid_to_teidin(rnti, lcid, teid_in);
|
|
|
|
rntilcid_to_teidin(rnti, lcid, teid_in);
|
|
|
|
//gtpu_log->info("Adding bearer for rnti: 0x%x, lcid: %d, addr: 0x%x, teid_out: 0x%x, teid_in: 0x%x\n", rnti, lcid, addr, teid_out, *teid_in);
|
|
|
|
//gtpu_log->info("Adding bearer for rnti: 0x%x, lcid: %d, addr: 0x%x, teid_out: 0x%x, teid_in: 0x%x\n", rnti, lcid, addr, teid_out, *teid_in);
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize maps if it's a new RNTI
|
|
|
|
// Initialize maps if it's a new RNTI
|
|
|
|
if(rnti_bearers.count(rnti) == 0) {
|
|
|
|
if(rnti_bearers.count(rnti) == 0) {
|
|
|
|
for(int i=0;i<SRSENB_N_RADIO_BEARERS;i++) {
|
|
|
|
for(int i=0;i<SRSENB_N_RADIO_BEARERS;i++) {
|
|
|
|
rnti_bearers[rnti].teids_in[i] = 0;
|
|
|
|
rnti_bearers[rnti].teids_in[i] = 0;
|
|
|
|
rnti_bearers[rnti].teids_out[i] = 0;
|
|
|
|
rnti_bearers[rnti].teids_out[i] = 0;
|
|
|
|
rnti_bearers[rnti].spgw_addrs[i] = 0;
|
|
|
|
rnti_bearers[rnti].spgw_addrs[i] = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rnti_bearers[rnti].teids_in[lcid] = *teid_in;
|
|
|
|
rnti_bearers[rnti].teids_in[lcid] = *teid_in;
|
|
|
|
rnti_bearers[rnti].teids_out[lcid] = teid_out;
|
|
|
|
rnti_bearers[rnti].teids_out[lcid] = teid_out;
|
|
|
|
rnti_bearers[rnti].spgw_addrs[lcid] = addr;
|
|
|
|
rnti_bearers[rnti].spgw_addrs[lcid] = addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gtpu::rem_bearer(uint16_t rnti, uint32_t lcid)
|
|
|
|
void gtpu::rem_bearer(uint16_t rnti, uint32_t lcid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gtpu_log->info("Removing bearer for rnti: 0x%x, lcid: %d\n", rnti, lcid);
|
|
|
|
gtpu_log->info("Removing bearer for rnti: 0x%x, lcid: %d\n", rnti, lcid);
|
|
|
|
|
|
|
|
|
|
|
|
rnti_bearers[rnti].teids_in[lcid] = 0;
|
|
|
|
rnti_bearers[rnti].teids_in[lcid] = 0;
|
|
|
|
rnti_bearers[rnti].teids_out[lcid] = 0;
|
|
|
|
rnti_bearers[rnti].teids_out[lcid] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Remove RNTI if all bearers are removed
|
|
|
|
// Remove RNTI if all bearers are removed
|
|
|
|
bool rem = true;
|
|
|
|
bool rem = true;
|
|
|
|
for(int i=0;i<SRSENB_N_RADIO_BEARERS; i++) {
|
|
|
|
for(int i=0;i<SRSENB_N_RADIO_BEARERS; i++) {
|
|
|
|
if(rnti_bearers[rnti].teids_in[i] != 0) {
|
|
|
|
if(rnti_bearers[rnti].teids_in[i] != 0) {
|
|
|
|
rem = false;
|
|
|
|
rem = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rem) {
|
|
|
|
|
|
|
|
rnti_bearers.erase(rnti);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rem) {
|
|
|
|
|
|
|
|
rnti_bearers.erase(rnti);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gtpu::rem_user(uint16_t rnti)
|
|
|
|
void gtpu::rem_user(uint16_t rnti)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
rnti_bearers.erase(rnti);
|
|
|
|
rnti_bearers.erase(rnti);
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gtpu::run_thread()
|
|
|
|
void gtpu::run_thread()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
byte_buffer_t *pdu = pool_allocate;
|
|
|
|
byte_buffer_t *pdu = pool_allocate;
|
|
|
|
|
|
|
|
|
|
|
|
if (!pdu) {
|
|
|
|
if (!pdu) {
|
|
|
|
gtpu_log->error("Fatal Error: Couldn't allocate buffer in gtpu::run_thread().\n");
|
|
|
|
gtpu_log->error("Fatal Error: Couldn't allocate buffer in gtpu::run_thread().\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
run_enable = true;
|
|
|
|
run_enable = true;
|
|
|
|
|
|
|
|
|
|
|
|
running=true;
|
|
|
|
running=true;
|
|
|
|
while(run_enable) {
|
|
|
|
while(run_enable) {
|
|
|
|
|
|
|
|
|
|
|
|
pdu->reset();
|
|
|
|
pdu->reset();
|
|
|
|
gtpu_log->debug("Waiting for read...\n");
|
|
|
|
gtpu_log->debug("Waiting for read...\n");
|
|
|
|
int n = 0;
|
|
|
|
int n = 0;
|
|
|
|
do{
|
|
|
|
do{
|
|
|
|
n = recv(src_fd, pdu->msg, SRSENB_MAX_BUFFER_SIZE_BYTES - SRSENB_BUFFER_HEADER_OFFSET, 0);
|
|
|
|
n = recv(src_fd, pdu->msg, SRSENB_MAX_BUFFER_SIZE_BYTES - SRSENB_BUFFER_HEADER_OFFSET, 0);
|
|
|
|
} while (n == -1 && errno == EAGAIN);
|
|
|
|
} while (n == -1 && errno == EAGAIN);
|
|
|
|
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
if (n < 0) {
|
|
|
|
gtpu_log->error("Failed to read from socket\n");
|
|
|
|
gtpu_log->error("Failed to read from socket\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t rnti = 0;
|
|
|
|
uint16_t rnti = 0;
|
|
|
|
uint16_t lcid = 0;
|
|
|
|
uint16_t lcid = 0;
|
|
|
|
teidin_to_rntilcid(header.teid, &rnti, &lcid);
|
|
|
|
teidin_to_rntilcid(header.teid, &rnti, &lcid);
|
|
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
bool user_exists = (rnti_bearers.count(rnti) > 0);
|
|
|
|
bool user_exists = (rnti_bearers.count(rnti) > 0);
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
|
|
|
|
if(!user_exists) {
|
|
|
|
if(!user_exists) {
|
|
|
|
gtpu_log->error("Unrecognized RNTI for DL PDU: 0x%x - dropping packet\n", rnti);
|
|
|
|
gtpu_log->error("Unrecognized RNTI for DL PDU: 0x%x - dropping packet\n", rnti);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(lcid < SRSENB_N_SRB || lcid >= SRSENB_N_RADIO_BEARERS) {
|
|
|
|
if(lcid < SRSENB_N_SRB || lcid >= SRSENB_N_RADIO_BEARERS) {
|
|
|
|
gtpu_log->error("Invalid LCID for DL PDU: %d - dropping packet\n", lcid);
|
|
|
|
gtpu_log->error("Invalid LCID for DL PDU: %d - dropping packet\n", lcid);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d, n_bytes=%d", rnti, lcid, pdu->N_bytes);
|
|
|
|
gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d, n_bytes=%d", rnti, lcid, pdu->N_bytes);
|
|
|
|
|
|
|
|
|
|
|
|
pdcp->write_sdu(rnti, lcid, pdu);
|
|
|
|
pdcp->write_sdu(rnti, lcid, pdu);
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
pdu = pool_allocate;
|
|
|
|
pdu = pool_allocate;
|
|
|
|
if (!pdu) {
|
|
|
|
if (!pdu) {
|
|
|
|
gtpu_log->console("GTPU Buffer pool empty. Trying again...\n");
|
|
|
|
gtpu_log->console("GTPU Buffer pool empty. Trying again...\n");
|
|
|
|
usleep(10000);
|
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(!pdu);
|
|
|
|
} while(!pdu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
running=false;
|
|
|
|
running=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
/****************************************************************************
|
|
|
@ -373,60 +374,60 @@ running=false;
|
|
|
|
|
|
|
|
|
|
|
|
bool gtpu::gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu)
|
|
|
|
bool gtpu::gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pdu->msg -= GTPU_HEADER_LEN;
|
|
|
|
pdu->msg -= GTPU_HEADER_LEN;
|
|
|
|
pdu->N_bytes += GTPU_HEADER_LEN;
|
|
|
|
pdu->N_bytes += GTPU_HEADER_LEN;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t *ptr = pdu->msg;
|
|
|
|
uint8_t *ptr = pdu->msg;
|
|
|
|
|
|
|
|
|
|
|
|
*ptr = header->flags;
|
|
|
|
*ptr = header->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);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool gtpu::gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header)
|
|
|
|
bool gtpu::gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint8_t *ptr = pdu->msg;
|
|
|
|
uint8_t *ptr = pdu->msg;
|
|
|
|
|
|
|
|
|
|
|
|
pdu->msg += GTPU_HEADER_LEN;
|
|
|
|
pdu->msg += GTPU_HEADER_LEN;
|
|
|
|
pdu->N_bytes -= GTPU_HEADER_LEN;
|
|
|
|
pdu->N_bytes -= GTPU_HEADER_LEN;
|
|
|
|
|
|
|
|
|
|
|
|
header->flags = *ptr;
|
|
|
|
header->flags = *ptr;
|
|
|
|
ptr++;
|
|
|
|
ptr++;
|
|
|
|
header->message_type = *ptr;
|
|
|
|
header->message_type = *ptr;
|
|
|
|
ptr++;
|
|
|
|
ptr++;
|
|
|
|
uint8_to_uint16(ptr, &header->length);
|
|
|
|
uint8_to_uint16(ptr, &header->length);
|
|
|
|
ptr += 2;
|
|
|
|
ptr += 2;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
/****************************************************************************
|
|
|
@ -434,13 +435,13 @@ return true;
|
|
|
|
***************************************************************************/
|
|
|
|
***************************************************************************/
|
|
|
|
void gtpu::teidin_to_rntilcid(uint32_t teidin, uint16_t *rnti, uint16_t *lcid)
|
|
|
|
void gtpu::teidin_to_rntilcid(uint32_t teidin, uint16_t *rnti, uint16_t *lcid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*lcid = teidin & 0xFFFF;
|
|
|
|
*lcid = teidin & 0xFFFF;
|
|
|
|
*rnti = (teidin >> 16) & 0xFFFF;
|
|
|
|
*rnti = (teidin >> 16) & 0xFFFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gtpu::rntilcid_to_teidin(uint16_t rnti, uint16_t lcid, uint32_t *teidin)
|
|
|
|
void gtpu::rntilcid_to_teidin(uint16_t rnti, uint16_t lcid, uint32_t *teidin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*teidin = (rnti << 16) | lcid;
|
|
|
|
*teidin = (rnti << 16) | lcid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace srsenb
|
|
|
|
} // namespace srsenb
|
|
|
|