Commit 39e7839f authored by Robert Schmidt's avatar Robert Schmidt

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
parent 3a99fb82
...@@ -19,52 +19,25 @@ ...@@ -19,52 +19,25 @@
* contact@openairinterface.org * 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 <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 <errno.h>
#include "common/platform_constants.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/if.h> #include <linux/if.h>
#include <linux/if_tun.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; int nas_sock_mbms_fd;
struct msghdr nas_msg_tx; static int tun_alloc(char *dev)
struct msghdr nas_msg_rx; {
static int tun_alloc(char *dev) {
struct ifreq ifr; struct ifreq ifr;
int fd, err; int fd, err;
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) { if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
LOG_E(PDCP, "[TUN] failed to open /dev/net/tun\n"); LOG_E(UTIL, "failed to open /dev/net/tun\n");
return -1; return -1;
} }
...@@ -76,10 +49,10 @@ static int tun_alloc(char *dev) { ...@@ -76,10 +49,10 @@ static int tun_alloc(char *dev) {
*/ */
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
if( *dev ) if (*dev)
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)-1); 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); close(fd);
return err; return err;
} }
...@@ -88,8 +61,8 @@ static int tun_alloc(char *dev) { ...@@ -88,8 +61,8 @@ static int tun_alloc(char *dev) {
return fd; return fd;
} }
int netlink_init_mbms_tun(char *ifprefix, int id)
int netlink_init_mbms_tun(char *ifprefix, int id) {//for UE, id = 1, 2, ..., {
int ret; int ret;
char ifname[64]; char ifname[64];
...@@ -97,23 +70,23 @@ int netlink_init_mbms_tun(char *ifprefix, int id) {//for UE, id = 1, 2, ..., ...@@ -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); nas_sock_mbms_fd = tun_alloc(ifname);
if (nas_sock_mbms_fd == -1) { 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); exit(1);
} }
printf("[NETLINK]Opened socket %s with fd %d\n",ifname,nas_sock_mbms_fd); 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); ret = fcntl(nas_sock_mbms_fd, F_SETFL, O_NONBLOCK);
if (ret == -1) { if (ret == -1) {
LOG_E(PDCP, "[NETLINK] Error fcntl (%d:%s)\n",errno, strerror(errno)); LOG_E(UTIL, "Error fcntl (%d:%s)\n", errno, strerror(errno));
return 0; return 0;
} }
memset(&nas_src_addr, 0, sizeof(nas_src_addr)); struct sockaddr_nl nas_src_addr = {0};
nas_src_addr.nl_family = AF_NETLINK; nas_src_addr.nl_family = AF_NETLINK;
nas_src_addr.nl_pid = 1;//getpid(); /* self pid */ nas_src_addr.nl_pid = 1;
nas_src_addr.nl_groups = 0; /* not in mcast groups */ 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)); ret = bind(nas_sock_mbms_fd, (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr));
return 1; return 1;
} }
...@@ -130,20 +103,19 @@ int netlink_init_tun(const char *ifprefix, int num_if, int id) ...@@ -130,20 +103,19 @@ int netlink_init_tun(const char *ifprefix, int num_if, int id)
nas_sock_fd[i] = tun_alloc(ifname); nas_sock_fd[i] = tun_alloc(ifname);
if (nas_sock_fd[i] == -1) { 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; return 0;
} }
LOG_I(PDCP, "TUN: Opened socket %s with fd nas_sock_fd[%d]=%d\n", LOG_I(UTIL, "Opened socket %s with fd nas_sock_fd[%d]=%d\n", ifname, i, nas_sock_fd[i]);
ifname, i, nas_sock_fd[i]); ret = fcntl(nas_sock_fd[i], F_SETFL, O_NONBLOCK);
ret = fcntl(nas_sock_fd[i],F_SETFL,O_NONBLOCK);
if (ret == -1) { 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; return 0;
} }
} /* for */ }
return 1; return 1;
} }
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
#define PDCP_FIFO_C #define PDCP_FIFO_C
extern int otg_enabled; extern int otg_enabled;
#include "pdcp.h" #include "pdcp.h"
...@@ -63,21 +61,11 @@ extern int otg_enabled; ...@@ -63,21 +61,11 @@ extern int otg_enabled;
#include <sys/socket.h> #include <sys/socket.h>
#include <linux/netlink.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_fd[MAX_MOBILES_PER_ENB];
extern int nas_sock_mbms_fd; extern int nas_sock_mbms_fd;
extern struct msghdr nas_msg_tx; static char nl_rx_buf[NL_MAX_PAYLOAD];
extern struct msghdr nas_msg_rx;
# include "openair3/ocp-gtpu/gtp_itf.h" # include "openair3/ocp-gtpu/gtp_itf.h"
...@@ -411,6 +399,7 @@ int pdcp_fifo_read_input_sdus_fromnetlinksock (const protocol_ctxt_t *const ctx ...@@ -411,6 +399,7 @@ int pdcp_fifo_read_input_sdus_fromnetlinksock (const protocol_ctxt_t *const ctx
rb_id_t rab_id = 0; 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, 1 );
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 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); 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 ); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment