Cleanup netlink_init.c and pdcp_fifo.c
- Remove globals, declare where they are used - Cleanup pdcp_fifo.c - Remove unnecessary headers from netlink_init.c - Reformat netlink_init.c
This commit is contained in:
@@ -19,52 +19,25 @@
|
||||
* contact@openairinterface.org
|
||||
*/
|
||||
|
||||
/*! \file netlink_init.c
|
||||
* \brief initiate the netlink socket for communication with nas dirver
|
||||
* \author Navid Nikaein and Raymomd Knopp
|
||||
* \date 2011
|
||||
* \version 1.0
|
||||
* \company Eurecom
|
||||
* \email: navid.nikaein@eurecom.fr
|
||||
*/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "common/platform_constants.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include "common/openairinterface5g_limits.h"
|
||||
|
||||
#include "pdcp.h"
|
||||
|
||||
char nl_rx_buf[NL_MAX_PAYLOAD];
|
||||
|
||||
struct sockaddr_nl nas_src_addr, nas_dest_addr;
|
||||
|
||||
int nas_sock_fd[MAX_MOBILES_PER_ENB*2]; //Allocated for both LTE UE and NR UE.
|
||||
#include "common/platform_constants.h"
|
||||
#include "common/utils/LOG/log.h"
|
||||
|
||||
int nas_sock_fd[MAX_MOBILES_PER_ENB * 2]; // Allocated for both LTE UE and NR UE.
|
||||
int nas_sock_mbms_fd;
|
||||
|
||||
struct msghdr nas_msg_tx;
|
||||
struct msghdr nas_msg_rx;
|
||||
|
||||
static int tun_alloc(char *dev) {
|
||||
static int tun_alloc(char *dev)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int fd, err;
|
||||
|
||||
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
|
||||
LOG_E(PDCP, "[TUN] failed to open /dev/net/tun\n");
|
||||
if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
|
||||
LOG_E(UTIL, "failed to open /dev/net/tun\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -76,10 +49,10 @@ static int tun_alloc(char *dev) {
|
||||
*/
|
||||
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
|
||||
|
||||
if( *dev )
|
||||
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)-1);
|
||||
if (*dev)
|
||||
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1);
|
||||
|
||||
if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) {
|
||||
if ((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) {
|
||||
close(fd);
|
||||
return err;
|
||||
}
|
||||
@@ -88,8 +61,8 @@ static int tun_alloc(char *dev) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
int netlink_init_mbms_tun(char *ifprefix, int id) {//for UE, id = 1, 2, ...,
|
||||
int netlink_init_mbms_tun(char *ifprefix, int id)
|
||||
{
|
||||
int ret;
|
||||
char ifname[64];
|
||||
|
||||
@@ -97,23 +70,23 @@ int netlink_init_mbms_tun(char *ifprefix, int id) {//for UE, id = 1, 2, ...,
|
||||
nas_sock_mbms_fd = tun_alloc(ifname);
|
||||
|
||||
if (nas_sock_mbms_fd == -1) {
|
||||
LOG_E(PDCP, "[NETLINK] Error opening mbms socket %s (%d:%s)\n", ifname, errno, strerror(errno));
|
||||
LOG_E(UTIL, "Error opening mbms socket %s (%d:%s)\n", ifname, errno, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
printf("[NETLINK]Opened socket %s with fd %d\n",ifname,nas_sock_mbms_fd);
|
||||
ret = fcntl(nas_sock_mbms_fd,F_SETFL,O_NONBLOCK);
|
||||
LOG_D(UTIL, "Opened socket %s with fd %d\n", ifname, nas_sock_mbms_fd);
|
||||
ret = fcntl(nas_sock_mbms_fd, F_SETFL, O_NONBLOCK);
|
||||
|
||||
if (ret == -1) {
|
||||
LOG_E(PDCP, "[NETLINK] Error fcntl (%d:%s)\n",errno, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
if (ret == -1) {
|
||||
LOG_E(UTIL, "Error fcntl (%d:%s)\n", errno, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&nas_src_addr, 0, sizeof(nas_src_addr));
|
||||
nas_src_addr.nl_family = AF_NETLINK;
|
||||
nas_src_addr.nl_pid = 1;//getpid(); /* self pid */
|
||||
nas_src_addr.nl_groups = 0; /* not in mcast groups */
|
||||
ret = bind(nas_sock_mbms_fd, (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr));
|
||||
struct sockaddr_nl nas_src_addr = {0};
|
||||
nas_src_addr.nl_family = AF_NETLINK;
|
||||
nas_src_addr.nl_pid = 1;
|
||||
nas_src_addr.nl_groups = 0; /* not in mcast groups */
|
||||
ret = bind(nas_sock_mbms_fd, (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr));
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -130,20 +103,19 @@ int netlink_init_tun(const char *ifprefix, int num_if, int id)
|
||||
nas_sock_fd[i] = tun_alloc(ifname);
|
||||
|
||||
if (nas_sock_fd[i] == -1) {
|
||||
LOG_E(PDCP, "TUN: Error opening socket %s (%d:%s)\n",ifname,errno, strerror(errno));
|
||||
LOG_E(UTIL, "Error opening socket %s (%d:%s)\n", ifname, errno, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_I(PDCP, "TUN: Opened socket %s with fd nas_sock_fd[%d]=%d\n",
|
||||
ifname, i, nas_sock_fd[i]);
|
||||
ret = fcntl(nas_sock_fd[i],F_SETFL,O_NONBLOCK);
|
||||
LOG_I(UTIL, "Opened socket %s with fd nas_sock_fd[%d]=%d\n", ifname, i, nas_sock_fd[i]);
|
||||
ret = fcntl(nas_sock_fd[i], F_SETFL, O_NONBLOCK);
|
||||
|
||||
if (ret == -1) {
|
||||
LOG_E(PDCP, "TUN: Error fcntl (%d:%s)\n",errno, strerror(errno));
|
||||
LOG_E(UTIL, "Error fcntl (%d:%s)\n", errno, strerror(errno));
|
||||
|
||||
return 0;
|
||||
}
|
||||
} /* for */
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
|
||||
#define PDCP_FIFO_C
|
||||
|
||||
|
||||
|
||||
extern int otg_enabled;
|
||||
|
||||
#include "pdcp.h"
|
||||
@@ -63,21 +61,11 @@ extern int otg_enabled;
|
||||
#include <sys/socket.h>
|
||||
#include <linux/netlink.h>
|
||||
|
||||
extern char nl_rx_buf[NL_MAX_PAYLOAD];
|
||||
extern struct sockaddr_nl nas_src_addr, nas_dest_addr;
|
||||
extern struct nlmsghdr *nas_nlh_tx;
|
||||
extern struct nlmsghdr *nas_nlh_rx;
|
||||
extern struct iovec nas_iov_tx;
|
||||
extern struct iovec nas_iov_rx;
|
||||
|
||||
extern int nas_sock_fd[MAX_MOBILES_PER_ENB];
|
||||
|
||||
extern int nas_sock_mbms_fd;
|
||||
|
||||
extern struct msghdr nas_msg_tx;
|
||||
extern struct msghdr nas_msg_rx;
|
||||
|
||||
|
||||
static char nl_rx_buf[NL_MAX_PAYLOAD];
|
||||
|
||||
# include "openair3/ocp-gtpu/gtp_itf.h"
|
||||
|
||||
@@ -411,6 +399,7 @@ int pdcp_fifo_read_input_sdus_fromnetlinksock (const protocol_ctxt_t *const ctx
|
||||
rb_id_t rab_id = 0;
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 1 );
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 1 );
|
||||
struct msghdr nas_msg_rx;
|
||||
len = recvmsg(nas_sock_fd[0], &nas_msg_rx, 0);
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user