Skip to content
Snippets Groups Projects
Commit 0bd3c9ec authored by Lionel Gauthier's avatar Lionel Gauthier
Browse files

Old rev code

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7371 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent e1e61893
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
/*******************************************************************************
Eurecom OpenAirInterface
Copyright(c) 1999 - 2011 Eurecom
This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
Contact Information
Openair Admin: openair_admin@eurecom.fr
Openair Tech : openair_tech@eurecom.fr
Forums : http://forums.eurecom.fsr/openairinterface
Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France
*******************************************************************************/
/*! \file pdcp.c
* \brief pdcp interface with RLC
* \author Lionel GAUTHIER and Navid Nikaein
* \date 2009
* \version 0.5
*/
#define PDCP_C
//#include "rtos_header.h"
#ifndef USER_MODE
#include <rtai_fifos.h>
#endif
#include "pdcp.h"
#include "LAYER2/RLC/rlc.h"
#include "LAYER2/MAC/extern.h"
//#include "mpls.h"
//#include "w3g4free_extern.h"
#define PDCP_DATA_REQ_DEBUG 1
#define PDCP_DATA_IND_DEBUG 1
//#define IDROMEL_NEMO 1
extern rlc_op_status_t rlc_data_req (module_id_t, rb_id_t, mui_t, confirm_t, sdu_size_t, mem_block_t*);
//-----------------------------------------------------------------------------
void
pdcp_data_req (module_id_t module_idP, rb_id_t rab_idP, sdu_size_t data_sizeP, char* sduP)
{
//-----------------------------------------------------------------------------
mem_block_t* new_sdu = NULL;
// int i;
if ((data_sizeP > 0)) {
if(data_sizeP > MAX_IP_PACKET_SIZE) {
msg("[PDCP] REQ FOR SIZE %d !!!Abort\n",data_sizeP);
mac_xface->macphy_exit("");
}
new_sdu = get_free_mem_block (data_sizeP);
if (new_sdu) {
#ifdef PDCP_DATA_REQ_DEBUG
msg("[PDCP] TTI %d, INST %d: PDCP_DATA_REQ size %d RAB %d:\n",Mac_rlc_xface->frame,module_idP,data_sizeP,rab_idP);
// for (i=0;i<20;i++)
// msg("%02X.",((unsigned char*)sduP)[i]);
// msg("\n");
#endif //PDCP_DATA_REQ_DEBUG
// PROCESS OF DECOMPRESSION HERE:
memcpy (&new_sdu->data[0], sduP, data_sizeP);
rlc_data_req(module_idP, rab_idP, RLC_MUI_UNDEFINED, RLC_SDU_CONFIRM_NO, data_sizeP, new_sdu);
if(Mac_rlc_xface->Is_cluster_head[module_idP]==1) {
Pdcp_stats_tx[module_idP][(rab_idP & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_idP & RAB_OFFSET)-DTCH]++;
Pdcp_stats_tx_bytes[module_idP][(rab_idP & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_idP & RAB_OFFSET)-DTCH]+=data_sizeP;
} else {
Pdcp_stats_tx[module_idP][(rab_idP & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_idP & RAB_OFFSET)-DTCH]++;
Pdcp_stats_tx_bytes[module_idP][(rab_idP & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_idP & RAB_OFFSET)-DTCH]+=data_sizeP;
}
} else {
msg("[PDCP][RAB %d][ERROR] PDCP_DATA_REQ OUT OF MEMORY\n", rab_idP);
}
// free_mem_block (sduP);
} else {
msg("[PDCP][RAB %d][ERROR] PDCP_DATA_REQ SDU SIZE %d\n", rab_idP, data_sizeP);
}
}
//-----------------------------------------------------------------------------
void
pdcp_data_ind (module_id_t module_idP, rb_id_t rab_idP, sdu_size_t data_sizeP, mem_block_t* sduP)
{
//-----------------------------------------------------------------------------
mem_block_t* new_sdu = NULL;
int i;
if ((data_sizeP > 0)) {
// if(Mac_rlc_xface->Is_cluster_head[0]==1 && Mac_rlc_xface->frame%10==0)
//msg("[PDCP][RAB %d][INST %d] PDCP_DATA_IND size %d\n", rab_idP,module_idP,data_sizeP);
#ifdef PDCP_DATA_IND_DEBUG
msg("[PDCP][RAB %d][INST %d] TTI %d PDCP_DATA_IND size %d\n",
rab_idP,module_idP,Mac_rlc_xface->frame,data_sizeP);
for (i=0; i<20; i++) {
msg("%02X.",(unsigned char)sduP->data[i]);
}
msg("\n");
#endif //PDCP_DATA_IND_DEBUG
new_sdu = get_free_mem_block (data_sizeP + sizeof (pdcp_data_ind_header_t));
if (new_sdu) {
memset (new_sdu->data, 0, sizeof (pdcp_data_ind_header_t));
((pdcp_data_ind_header_t*) new_sdu->data)->rb_id = rab_idP;
((pdcp_data_ind_header_t*) new_sdu->data)->data_size = data_sizeP;
// Here there is no virtualization possible
#ifdef IDROMEL_NEMO
if (Mac_rlc_xface->Is_cluster_head[module_idP] == 0) {
((pdcp_data_ind_header_t*) new_sdu->data)->inst = rab_idP/8;
}
else {
((pdcp_data_ind_header_t*) new_sdu->data)->inst = 0;
}
#else
((pdcp_data_ind_header_t*) new_sdu->data)->inst = module_idP;
#endif
// PROCESS OF DECOMPRESSION HERE:
memcpy (&new_sdu->data[sizeof (pdcp_data_ind_header_t)], &sduP->data[0], data_sizeP);
list_add_tail_eurecom (new_sdu, &pdcp_sdu_list);
if(Mac_rlc_xface->Is_cluster_head[module_idP]==1) {
Pdcp_stats_rx[module_idP][(rab_idP & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_idP & RAB_OFFSET)-DTCH]++;
Pdcp_stats_rx_bytes[module_idP][(rab_idP & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_idP & RAB_OFFSET)-DTCH]+=data_sizeP;
} else {
Pdcp_stats_rx[module_idP][(rab_idP & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_idP & RAB_OFFSET)-DTCH]++;
Pdcp_stats_rx_bytes[module_idP][(rab_idP & RAB_OFFSET2 )>> RAB_SHIFT2][(rab_idP & RAB_OFFSET)-DTCH]+=data_sizeP;
}
}
free_mem_block (sduP);
}
}
//-----------------------------------------------------------------------------
void
pdcp_run (void)
{
//-----------------------------------------------------------------------------
// NAS -> PDCP traffic
#ifndef PDCP_USE_NETLINK
#ifdef USER_MODE
//#define PDCP_DUMMY_BUFFER_SIZE 38
// unsigned char pdcp_dummy_buffer[PDCP_DUMMY_BUFFER_SIZE];
//msg("[PDCP] PDCP Run Id %d\n",modId);
/*
if(Mac_rlc_xface->frame %1 == 0 && (Mac_rlc_xface->frame > 30)) {
if (Mac_rlc_xface->Is_cluster_head[0] ==0){
pdcp_data_req(0,5,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
pdcp_data_req(0,4,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
// pdcp_data_req(0,4,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
// pdcp_data_req(3,4,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
//pdcp_data_req(4,4,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
}
// if (Mac_rlc_xface->Is_cluster_head[modId] == 1 && Mac_rlc_xface->frame %20 == 0) {
else{
pdcp_data_req(0,20,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
pdcp_data_req(0,21,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
pdcp_data_req(0,12,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
pdcp_data_req(0,13,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
//pdcp_data_req(0,20,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
}
// pdcp_data_req(0,28,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
// pdcp_data_req(0,36,PDCP_DUMMY_BUFFER_SIZE,pdcp_dummy_buffer);
}*/
#endif
#endif
unsigned int diff,i,k,j;
if((Mac_rlc_xface->frame%128)==0) {
// for(i=0;i<NB_INST;i++)
for(i=0; i<NB_UE_INST; i++)
for (j=0; j<NB_CNX_CH; j++)
for(k=0; k<NB_RAB_MAX; k++) {
diff = Pdcp_stats_tx_bytes[i][j][k];
Pdcp_stats_tx_bytes[i][j][k]=0;
Pdcp_stats_tx_rate[i][j][k] = (diff*8)>>7;// (Pdcp_stats_tx_rate[i][k]*1+(7*diff*8)>>7)/8;
diff = Pdcp_stats_rx_bytes[i][j][k];
Pdcp_stats_rx_bytes[i][j][k]=0;
Pdcp_stats_rx_rate[i][j][k] =(diff*8)>>7;//(Pdcp_stats_rx_rate[i][k]*1 + (7*diff*8)>>7)/8;
}
}
// printf("[PDCP]Read sdus from NAS\n");
pdcp_fifo_read_input_sdus();
// PDCP -> NAS traffic
pdcp_fifo_flush_sdus();
/*printf("PDCP TTI %d\n", Mac_rlc_xface->frame);
for (i = 0; i < 3; i++) {
printf("[RLC_RRC][MOD ID %d] AM:", i);
for (j = 0; j < RLC_MAX_NUM_INSTANCES_RLC_AM; j++) {
printf("%d", rlc[i].m_rlc_am_array[j].allocation);
}
printf("\n[RLC_RRC][MOD ID %d] UM:", i);
for (j = 0; j < RLC_MAX_NUM_INSTANCES_RLC_UM; j++) {
printf("%d", rlc[i].m_rlc_um_array[j].allocation);
}
printf("\n");
}*/
}
//-----------------------------------------------------------------------------
void
pdcp_config_req (module_id_t module_idP, rb_id_t rab_idP)
{
//-----------------------------------------------------------------------------
//msg ("[PDCP] pdcp_confiq_req()\n");
}
//-----------------------------------------------------------------------------
void
pdcp_config_release (module_id_t module_idP, rb_id_t rab_idP)
{
//-----------------------------------------------------------------------------
//msg ("[PDCP] pdcp_config_release()\n");
}
//-----------------------------------------------------------------------------
int
pdcp_module_init ()
{
//-----------------------------------------------------------------------------
#ifndef USER_MODE
int ret;
ret=rtf_create(PDCP2NW_DRIVER_FIFO,32768);
if (ret < 0) {
printk("[openair][MAC][INIT] Cannot create PDCP2NAS fifo %d (ERROR %d)\n",PDCP2NW_DRIVER_FIFO,ret);
return(-1);
} else {
printk("[openair][MAC][INIT] Created PDCP2NAS fifo %d\n",PDCP2NW_DRIVER_FIFO);
rtf_reset(PDCP2NW_DRIVER_FIFO);
}
ret=rtf_create(NW_DRIVER2PDCP_FIFO,32768);
if (ret < 0) {
printk("[openair][MAC][INIT] Cannot create NAS2PDCP fifo %d (ERROR %d)\n",NW_DRIVER2PDCP_FIFO,ret);
return(-1);
} else {
printk("[openair][MAC][INIT] Created NAS2PDCP fifo %d\n",NW_DRIVER2PDCP_FIFO);
rtf_reset(NW_DRIVER2PDCP_FIFO);
}
pdcp_2_nas_irq = 0;
pdcp_input_sdu_remaining_size_to_read=0;
pdcp_input_sdu_size_read=0;
#endif
return(0);
}
//-----------------------------------------------------------------------------
void
pdcp_module_cleanup ()
//-----------------------------------------------------------------------------
{
#ifndef USER_MODE
rtf_destroy(NW_DRIVER2PDCP_FIFO);
rtf_destroy(PDCP2NW_DRIVER_FIFO);
#endif
}
//-----------------------------------------------------------------------------
void
pdcp_layer_init ()
{
//-----------------------------------------------------------------------------
unsigned int i,j,k;
list_init (&pdcp_sdu_list, NULL);
msg("[PDCP] pdcp_layer_init \n ");
pdcp_output_sdu_bytes_to_write=0;
pdcp_output_header_bytes_to_write=0;
pdcp_input_sdu_remaining_size_to_read=0;
// for (i=0;i<NB_INST;i++)
for (i=0; i<NB_UE_INST; i++)
for (k=0; k<NB_CNX_CH; k++)
for(j=0; j<NB_RAB_MAX; j++) {
Pdcp_stats_tx[i][k][j]=0;
Pdcp_stats_tx_bytes[i][k][j]=0;
Pdcp_stats_tx_bytes_last[i][k][j]=0;
Pdcp_stats_tx_rate[i][k][j]=0;
Pdcp_stats_rx[i][k][j]=0;
Pdcp_stats_rx_bytes[i][k][j]=0;
Pdcp_stats_rx_bytes_last[i][k][j]=0;
Pdcp_stats_rx_rate[i][k][j]=0;
}
}
//-----------------------------------------------------------------------------
void
pdcp_layer_cleanup ()
//-----------------------------------------------------------------------------
{
list_free (&pdcp_sdu_list);
}
#ifndef USER_MODE
EXPORT_SYMBOL(pdcp_2_nas_irq);
#endif //USER_MODE
/*
pdcp.h
-------------------
AUTHOR : Lionel GAUTHIER
COMPANY : EURECOM
EMAIL : Lionel.Gauthier@eurecom.fr
***************************************************************************/
#ifndef __PDCP_H__
# define __PDCP_H__
//-----------------------------------------------------------------------------
# ifdef PDCP_C
# define private_pdcp(x) x
# define protected_pdcp(x) x
# define public_pdcp(x) x
# else
# define private_pdcp(x)
# define public_pdcp(x) extern x
# ifdef PDCP_FIFO_C
# define protected_pdcp(x) extern x
# else
# define protected_pdcp(x)
# endif
# endif
# ifdef PDCP_FIFO_C
# define private_pdcp_fifo(x) x
# define protected_pdcp_fifo(x) x
# define public_pdcp_fifo(x) x
# else
# define private_pdcp_fifo(x)
# define public_pdcp_fifo(x) extern x
# ifdef PDCP_C
# define protected_pdcp_fifo(x) extern x
# else
# define protected_pdcp_fifo(x)
# endif
# endif
//-----------------------------------------------------------------------------
#ifndef NON_ACCESS_STRATUM
//#include "rtos_header.h"
//#include "openair_defs.h"
//#include "platform_types.h"
//#include "platform_constants.h"
#include "UTIL/MEM/mem_block.h"
#include "UTIL/LISTS/list.h"
#include "COMMON/mac_rrc_primitives.h"
#endif //NON_ACCESS_STRATUM
//-----------------------------------------------------------------------------
public_pdcp(unsigned int Pdcp_stats_tx[NB_MODULES_MAX][NB_CNX_CH][NB_RAB_MAX]);
public_pdcp(unsigned int Pdcp_stats_tx_bytes[NB_MODULES_MAX][NB_CNX_CH][NB_RAB_MAX]);
public_pdcp(unsigned int Pdcp_stats_tx_bytes_last[NB_MODULES_MAX][NB_CNX_CH][NB_RAB_MAX]);
public_pdcp(unsigned int Pdcp_stats_tx_rate[NB_MODULES_MAX][NB_CNX_CH][NB_RAB_MAX]);
public_pdcp(unsigned int Pdcp_stats_rx[NB_MODULES_MAX][NB_CNX_CH][NB_RAB_MAX]);
public_pdcp(unsigned int Pdcp_stats_rx_bytes[NB_MODULES_MAX][NB_CNX_CH][NB_RAB_MAX]);
public_pdcp(unsigned int Pdcp_stats_rx_bytes_last[NB_MODULES_MAX][NB_CNX_CH][NB_RAB_MAX]);
public_pdcp(unsigned int Pdcp_stats_rx_rate[NB_MODULES_MAX][NB_CNX_CH][NB_RAB_MAX]);
public_pdcp(void pdcp_data_req (module_id_t, rb_id_t, sdu_size_t, char*);)
public_pdcp(void pdcp_data_ind (module_id_t, rb_id_t, sdu_size_t, mem_block_t*);)
public_pdcp(void pdcp_config_req (module_id_t, rb_id_t);)
public_pdcp(void pdcp_config_release (module_id_t, rb_id_t);)
public_pdcp(void pdcp_run (void);)
public_pdcp(int pdcp_module_init ();)
public_pdcp(void pdcp_module_cleanup ();)
public_pdcp(void pdcp_layer_init ();)
public_pdcp(void pdcp_layer_cleanup ();)
#define PDCP2NW_DRIVER_FIFO 21
#define NW_DRIVER2PDCP_FIFO 22
protected_pdcp_fifo(int pdcp_fifo_flush_sdus ();)
protected_pdcp_fifo(int pdcp_fifo_read_input_sdus_remaining_bytes ();)
protected_pdcp_fifo(int pdcp_fifo_read_input_sdus();)
//-----------------------------------------------------------------------------
typedef struct pdcp_data_req_header_t {
rb_id_t rb_id;
sdu_size_t data_size;
int inst;
} pdcp_data_req_header_t;
typedef struct pdcp_data_ind_header_t {
rb_id_t rb_id;
sdu_size_t data_size;
int inst;
} pdcp_data_ind_header_t;
typedef struct pdcp_t {
char allocation;
// here ROHC variables for header compression/decompression
} pdcp_t;
protected_pdcp(signed int pdcp_2_nas_irq;)
protected_pdcp(pdcp_t pdcp_array[MAX_MODULES][MAX_RAB];)
protected_pdcp(sdu_size_t pdcp_output_sdu_bytes_to_write;)
protected_pdcp(sdu_size_t pdcp_output_header_bytes_to_write;)
protected_pdcp(list_t pdcp_sdu_list;)
protected_pdcp(int pdcp_sent_a_sdu;)
protected_pdcp(pdcp_data_req_header_t pdcp_input_header;)
protected_pdcp(char pdcp_input_sdu_buffer[MAX_IP_PACKET_SIZE];)
protected_pdcp(sdu_size_t pdcp_input_index_header;)
protected_pdcp(sdu_size_t pdcp_input_sdu_size_read;)
protected_pdcp(sdu_size_t pdcp_input_sdu_remaining_size_to_read;)
#endif
/***************************************************************************
pdcp_control_primitives.c
-------------------
begin : Mon Dec 10 2001
copyright : (C) 2001 by EURECOM
email : Lionel.Gauthier@eurecom.fr
-------------------
description
This file contains the functions used for configuration of pdcp
***************************************************************************/
#include "rtos_header.h"
#include "platform.h"
#include "protocol_vars_extern.h"
#include "print.h"
//-----------------------------------------------------------------------------
#include "rlc.h"
#include "pdcp.h"
#include "debug_l2.h"
//-----------------------------------------------------------------------------
void
configure_pdcp_req (struct pdcp_entity *pdcpP, void *rlcP, uint8_t rlc_sap_typeP, uint8_t header_compression_typeP)
{
//-----------------------------------------------------------------------------
mem_block *mb;
mb = get_free_mem_block (sizeof (struct cpdcp_primitive));
((struct cpdcp_primitive *) mb->data)->type = CPDCP_CONFIG_REQ;
((struct cpdcp_primitive *) mb->data)->primitive.config_req.rlc_sap = rlcP;
((struct cpdcp_primitive *) mb->data)->primitive.config_req.rlc_type_sap = rlc_sap_typeP;
((struct cpdcp_primitive *) mb->data)->primitive.config_req.header_compression_type = header_compression_typeP;
send_pdcp_control_primitive (pdcpP, mb);
}
/***************************************************************************
pdcp_control_primitives_proto_extern.h
-------------------
begin : Mon Dec 10 2001
copyright : (C) 2001 by EURECOM
email : Lionel.Gauthier@eurecom.fr
-------------------
description
This file contains the prototypes of functions used for configuration of pdcp
***************************************************************************/
#ifndef PDCP_CONTROL_PRIMITIVES_PROTO_EXTERN_H
# define PDCP_CONTROL_PRIMITIVES_PROTO_EXTERN_H
# include "pdcp.h"
void rrc_configure_pdcp (struct pdcp_entity *pdcpP, void *rlcP, uint8_t rlc_sap_typeP, uint8_t header_compression_typeP);
#endif
/*
pdcp_entity.h
-------------------
AUTHOR : Lionel GAUTHIER
COMPANY : EURECOM
EMAIL : Lionel.Gauthier@eurecom.fr
***************************************************************************/
#ifndef __PDCP_ENTITY_H__
# define __PDCP_ENTITY_H__
# include "list.h"
struct pdcp_entity {
unsigned short id; // for resource management purpose
unsigned char allocation;
void *rlc_sap;
//-----------------------------
// C-SAP
//-----------------------------
list c_sap;
//-----------------------------
// tranmission
//-----------------------------
list input_sdu_list;
void *rlc;
//-----------------------------
// receiver
//-----------------------------
//struct list output_sdu_list;
#ifdef ROHC
void (*pdcp_process_input_sdus) (struct pdcp_entity *pdcpP, uint16_t data_sizeP, mem_block * sduP);
#else
void (*pdcp_process_input_sdus) (struct pdcp_entity *pdcpP);
#endif
unsigned char rb_id; // for traces
unsigned char rlc_type_sap; // am, um, tr
struct rb_dispatcher *rb_dispatch;
};
#endif
/*******************************************************************************
Eurecom OpenAirInterface
Copyright(c) 1999 - 2011 Eurecom
This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
Contact Information
Openair Admin: openair_admin@eurecom.fr
Openair Tech : openair_tech@eurecom.fr
Forums : http://forums.eurecom.fsr/openairinterface
Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France
*******************************************************************************/
/*! \file pdcp_fifo.c
* \brief pdcp interface with linux IP interface
* \author Lionel GAUTHIER and Navid Nikaein
* \date 2009
* \version 0.5
* \warning This component can be runned only in user-space
* @ingroup pdcp
*/
#define PDCP_FIFO_C
#include "pdcp.h"
#ifdef USER_MODE
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define rtf_put write
#define rtf_get read
#else
#include <rtai_fifos.h>
#endif //USER_MODE
#include "../MAC/extern.h"
#include "SIMULATION/ETH_TRANSPORT/extern.h"
#define PDCP_DEBUG 1
//#define IDROMEL_NEMO 1
#ifdef USER_MODE
#include "UTIL/OCG/OCG.h"
#include "UTIL/OCG/OCG_extern.h"
#endif
#ifdef PDCP_USE_NETLINK
#include <sys/socket.h>
#include <linux/netlink.h>
extern struct sockaddr_nl nas_src_addr, nas_dest_addr;
extern struct nlmsghdr* nas_nlh;
extern struct iovec nas_iov;
extern int nas_sock_fd;
extern struct msghdr nas_msg;
#define MAX_PAYLOAD 1600 /* maximum payload size*/
unsigned char pdcp_read_state = 0;
char pdcp_read_payload[MAX_PAYLOAD];
#endif
pdcp_data_req_header_t pdcp_read_header;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
int
pdcp_fifo_flush_sdus ()
{
//-----------------------------------------------------------------------------
mem_block_t* sdu = list_get_head (&pdcp_sdu_list);
int bytes_wrote = 0;
int pdcp_nb_sdu_sent = 0;
uint8_t cont = 1;
int ret;
while ((sdu) && (cont)) {
#ifdef USER_MODE
// asjust the instance id when passing sdu to IP
((pdcp_data_ind_header_t*)(sdu->data))->inst = (((pdcp_data_ind_header_t*)(sdu->data))->inst >= NB_eNB_INST) ?
((pdcp_data_ind_header_t*)(sdu->data))->inst - NB_eNB_INST +oai_emulation.info.nb_enb_local - oai_emulation.info.first_ue_local : // UE
((pdcp_data_ind_header_t*)(sdu->data))->inst - oai_emulation.info.first_ue_local; // ENB
#else
((pdcp_data_ind_header_t*)(sdu->data))->inst = 0;
#endif
#ifdef PDCP_DEBUG
msg("[PDCP][INFO] PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
Mac_rlc_xface->frame,
((pdcp_data_ind_header_t*)(sdu->data))->inst,
((pdcp_data_ind_header_t*)(sdu->data))->data_size,
((pdcp_data_ind_header_t*)(sdu->data))->rb_id);
#endif //PDCP_DEBUG
cont = 0;
if (!pdcp_output_sdu_bytes_to_write) {
if (!pdcp_output_header_bytes_to_write) {
pdcp_output_header_bytes_to_write = sizeof (pdcp_data_ind_header_t);
}
#ifndef USER_MODE
bytes_wrote = rtf_put (PDCP2NW_DRIVER_FIFO,
&(((uint8_t*) sdu->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
pdcp_output_header_bytes_to_write);
#else
#ifdef PDCP_USE_NETLINK
#ifdef LINUX
memcpy(NLMSG_DATA(nas_nlh), &(((uint8_t*) sdu->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
pdcp_output_header_bytes_to_write);
nas_nlh->nlmsg_len = pdcp_output_header_bytes_to_write;
#endif //LINUX
#endif //PDCP_USE_NETLINK
bytes_wrote = pdcp_output_header_bytes_to_write;
#endif //USER_MODE
#ifdef PDCP_DEBUG
msg("[PDCP][INFO] TTI %d Sent %d Bytes of header to Nas_mesh\n",
Mac_rlc_xface->frame,
bytes_wrote);
#endif //PDCP_DEBUG
if (bytes_wrote > 0) {
pdcp_output_header_bytes_to_write = pdcp_output_header_bytes_to_write - bytes_wrote;
if (!pdcp_output_header_bytes_to_write) { // continue with sdu
pdcp_output_sdu_bytes_to_write = ((pdcp_data_ind_header_t*) sdu->data)->data_size;
#ifndef USER_MODE
bytes_wrote = rtf_put (PDCP2NW_DRIVER_FIFO, &(sdu->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
#else
#ifdef PDCP_USE_NETLINK
#ifdef LINUX
memcpy(NLMSG_DATA(nas_nlh)+sizeof(pdcp_data_ind_header_t), &(sdu->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
nas_nlh->nlmsg_len += pdcp_output_sdu_bytes_to_write;
ret = sendmsg(nas_sock_fd,&nas_msg,0);
if (ret<0) {
msg("[PDCP_FIFOS] sendmsg returns %d\n",ret);
perror("error code:");
mac_xface->macphy_exit("");
break;
}
#endif // LINUX
#endif //PDCP_USE_NETLINK
bytes_wrote= pdcp_output_sdu_bytes_to_write;
#endif // USER_MODE
#ifdef PDCP_DEBUG
msg("[PDCP][INFO] PDCP->IP TTI %d INST %d: Sent %d Bytes of data from rab %d to Nas_mesh\n",
Mac_rlc_xface->frame,
((pdcp_data_ind_header_t*)(sdu->data))->inst,
bytes_wrote,
((pdcp_data_ind_header_t*)(sdu->data))->rb_id);
#endif //PDCP_DEBUG
if (bytes_wrote > 0) {
pdcp_output_sdu_bytes_to_write -= bytes_wrote;
if (!pdcp_output_sdu_bytes_to_write) { // OK finish with this SDU
// msg("rb sent a sdu qos_sap %d\n",sapiP);
list_remove_head (&pdcp_sdu_list);
free_mem_block (sdu);
cont = 1;
pdcp_nb_sdu_sent += 1;
sdu = list_get_head (&pdcp_sdu_list);
}
} else {
msg ("[PDCP] RADIO->IP SEND SDU CONGESTION!\n");
}
} else {
msg ("[PDCP] RADIO->IP SEND SDU CONGESTION!\n");
}
}
} else {
// continue writing sdu
#ifndef USER_MODE
bytes_wrote = rtf_put (PDCP2NW_DRIVER_FIFO,
(uint8_t*) (&(sdu->data[sizeof (pdcp_data_ind_header_t) + ((pdcp_data_ind_header_t*) sdu->data)->data_size - pdcp_output_sdu_bytes_to_write])),
pdcp_output_sdu_bytes_to_write);
#else // USER_MODE
bytes_wrote = pdcp_output_sdu_bytes_to_write;
#endif // USER_MODE
if (bytes_wrote > 0) {
pdcp_output_sdu_bytes_to_write -= bytes_wrote;
if (!pdcp_output_sdu_bytes_to_write) { // OK finish with this SDU
//PRINT_RB_SEND_OUTPUT_SDU ("[PDCP] RADIO->IP SEND SDU\n");
list_remove_head (&pdcp_sdu_list);
free_mem_block (sdu);
cont = 1;
pdcp_nb_sdu_sent += 1;
sdu = list_get_head (&pdcp_sdu_list);
// msg("rb sent a sdu from rab\n");
}
}
}
}
#ifndef USER_MODE
if ((pdcp_nb_sdu_sent)) {
if ((pdcp_2_nas_irq > 0)) {
#ifdef PDCP_DEBUG
msg("[PDCP][INFO] TTI %d : Trigger NAS RX interrupt\n",
Mac_rlc_xface->frame);
#endif //PDCP_DEBUG
rt_pend_linux_srq (pdcp_2_nas_irq);
} else {
msg ("[PDCP] TTI %d: ERROR IF IP STACK WANTED : NOTIF PACKET(S) pdcp_2_nas_irq not initialized : %d\n",
Mac_rlc_xface->frame,
pdcp_2_nas_irq);
}
}
#endif //USER_MODE
return pdcp_nb_sdu_sent;
}
//-----------------------------------------------------------------------------
/*
* returns a positive value if whole bytes that had to be read were read
* returns zero value if whole bytes that had to be read were not read at all
* returns a negative value if an error was encountered while reading the rt fifo
*/
int
pdcp_fifo_read_input_sdus_remaining_bytes ()
{
//-----------------------------------------------------------------------------
sdu_size_t bytes_read=0;
if (pdcp_input_sdu_remaining_size_to_read > 0) {
// printk("[PDCP][INFO] read_input_sdus pdcp_input_sdu_remaining_size_to_read = %d \n", pdcp_input_sdu_remaining_size_to_read);
bytes_read = rtf_get (NW_DRIVER2PDCP_FIFO,
&(pdcp_input_sdu_buffer[pdcp_input_sdu_size_read]),
pdcp_input_sdu_remaining_size_to_read);
//printk("[PDCP][INFO] read fifo returned %d \n", bytes_read);
if (bytes_read > 0) {
//msg("[PDCP_FIFOS] Read %d remaining Bytes of data from Nas_mesh\n",bytes_read);
pdcp_input_sdu_remaining_size_to_read = pdcp_input_sdu_remaining_size_to_read - bytes_read;
pdcp_input_sdu_size_read = pdcp_input_sdu_size_read + bytes_read;
if (pdcp_input_sdu_remaining_size_to_read != 0) {
return 0;
} else {
#ifdef PDCP_DEBUG
msg("[PDCP][INFO] TTI %d: IP->RADIO RECEIVED COMPLETE SDU size %d inst %d rb %d\n",
Mac_rlc_xface->frame,
pdcp_input_sdu_size_read,
pdcp_input_header.inst,
pdcp_input_header.rb_id);
#endif //PDCP_DEBUG
pdcp_input_sdu_size_read = 0;
#ifdef IDROMEL_NEMO
pdcp_read_header.inst = 0;
#endif
pdcp_data_req (pdcp_input_header.inst,
pdcp_input_header.rb_id,
pdcp_input_header.data_size,
pdcp_input_sdu_buffer);
// not necessary
//memset(pdcp_input_sdu_buffer, 0, MAX_IP_PACKET_SIZE);
return 1;
}
} else {
return bytes_read;
}
}
return 1;
}
#ifndef PDCP_USE_NETLINK
//-----------------------------------------------------------------------------
int
pdcp_fifo_read_input_sdus ()
{
//-----------------------------------------------------------------------------
int cont;
int bytes_read;
// if remaining bytes to read
if (pdcp_fifo_read_input_sdus_remaining_bytes () > 0) {
// all bytes that had to be read for a SDU were read
// if not overflow of list, try to get new sdus from rt fifo
cont = 1;
while (cont > 0) {
bytes_read = rtf_get (NW_DRIVER2PDCP_FIFO,
&(((uint8_t*) & pdcp_input_header)[pdcp_input_index_header]),
sizeof (pdcp_data_req_header_t) - pdcp_input_index_header);
if (bytes_read > 0) {
#ifdef PDCP_DEBUG
msg("[PDCP_FIFOS] TTI %d Read %d Bytes of data (header %d) from Nas_mesh\n",
Mac_rlc_xface->frame,
bytes_read,
sizeof(pdcp_data_req_header_t));
#endif
pdcp_input_index_header += bytes_read;
if (pdcp_input_index_header == sizeof (pdcp_data_req_header_t)) {
#ifdef PDCP_DEBUG
msg("[PDCP] TTI %d IP->RADIO READ HEADER sdu size %d\n",
Mac_rlc_xface->frame,
pdcp_input_header.data_size);
#endif
pdcp_input_index_header = 0;
if (pdcp_input_header.data_size < 0) {
msg("[PDCP][FATAL ERROR] READ_FIFO: DATA_SIZE %d < 0\n",pdcp_input_header.data_size);
mac_xface->macphy_exit("");
return 0;
}
pdcp_input_sdu_remaining_size_to_read = pdcp_input_header.data_size;
pdcp_input_sdu_size_read = 0;
// we know the size of the sdu, so read the sdu;
cont = pdcp_fifo_read_input_sdus_remaining_bytes ();
} else {
cont = 0;
}
// error while reading rt fifo
} else {
cont = 0;
}
}
}
return 0;
}
#else //PDCP_USE_NETLINK
//-----------------------------------------------------------------------------
int
pdcp_fifo_read_input_sdus ()
{
//-----------------------------------------------------------------------------
int cont;
int bytes_read;
int len;
if (pdcp_read_state == 0) {
#ifdef LINUX
len = recvmsg(nas_sock_fd, &nas_msg, 0);
#else
len = -1;
#endif
if (len<0) {
//printf("[PDCP][NETLINK %d] nothing in pdcp NAS socket\n", nas_sock_fd);
} else {
#ifdef PDCP_DEBUG
#ifdef LINUX
printf("[PDCP][NETLINK] Received socket with length %d (nlmsg_len = %d)\n",len,nas_nlh->nlmsg_len-sizeof(struct nlmsghdr));
#endif PDCP_DEBUG
#ifdef PDCP_DEBUG
printf("[PDCP][NETLINK] nlmsg_len = %d (%d,%d)\n",nas_nlh->nlmsg_len,
sizeof(pdcp_data_req_header_t),
sizeof(struct nlmsghdr));
#endif LINUX
#endif PDCP_DEBUG
}
#ifdef LINUX
if (nas_nlh->nlmsg_len == sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)) {
pdcp_read_state = 1; //get
memcpy((void*)&pdcp_read_header,
(void*)NLMSG_DATA(nas_nlh),
sizeof(pdcp_data_req_header_t));
}
#else //LINUX
pdcp_read_state = 1;
#endif //LINUX
}
if (pdcp_read_state == 1) {
#ifdef LINUX
len = recvmsg(nas_sock_fd, &nas_msg, 0);
#else
len = -1;
#endif //LINUX
if (len<0) {
// nothing in pdcp NAS socket
} else {
pdcp_read_state = 0;
//print_active_requests()
#ifdef LINUX
memcpy(pdcp_read_payload,
(unsigned char*)NLMSG_DATA(nas_nlh),
nas_nlh->nlmsg_len - sizeof(struct nlmsghdr));
#endif
#ifdef IDROMEL_NEMO
pdcp_read_header.inst = 0;
#endif
pdcp_read_header.inst = (pdcp_read_header.inst >= oai_emulation.info.nb_enb_local) ?
pdcp_read_header.inst - oai_emulation.info.nb_enb_local+ NB_eNB_INST + oai_emulation.info.first_ue_local :
pdcp_read_header.inst + oai_emulation.info.first_enb_local;
#ifdef PDCP_DEBUG
printf("[PDCP][NETLINK][IP->PDCP] TTI %d, INST %d: Received socket with length %d (nlmsg_len = %d) on Rab %d \n",
Mac_rlc_xface->frame,
pdcp_read_header.inst,
len,
nas_nlh->nlmsg_len-sizeof(struct nlmsghdr),
pdcp_read_header.rb_id);
#endif PDCP_DEBUG
pdcp_data_req(pdcp_read_header.inst,
pdcp_read_header.rb_id,
pdcp_read_header.data_size,
pdcp_read_payload);
}
}
}
#endif
/*
pdcp_primitives.h
-------------------
AUTHOR : Lionel GAUTHIER
COMPANY : EURECOM
EMAIL : Lionel.Gauthier@eurecom.fr
***************************************************************************/
#ifndef __PDCP_PRIMITIVES_H__
# define __PDCP_PRIMITIVES_H__
# include "platform.h"
//----------------------------------------------------------
// primitives
//----------------------------------------------------------
# define PDCP_DATA_REQ 0x01
# define PDCP_DATA_IND 0x02
//----------------------------------------------------------
// control primitives
//----------------------------------------------------------
# define CPDCP_CONFIG_REQ 0x04
# define CPDCP_RELEASE_REQ 0x08
# define CPDCP_SN_REQ 0x10
# define CPDCP_RELOC_REQ 0x20
# define CPDCP_RELOC_CNF 0x40
//----------------------------------------------------------
// primitives definition
//----------------------------------------------------------
struct pdcp_data_req {
uint16_t rb_id;
uint16_t data_size;
};
struct pdcp_data_ind {
uint16_t rb_id;
uint16_t data_size;
};
//----------------------------------------------------------
// control primitives definition
//----------------------------------------------------------
// TO DO
struct cpdcp_config_req {
void *rlc_sap;
uint8_t rlc_type_sap; // am, um, tr
uint8_t header_compression_type;
};
struct cpdcp_release_req {
void *rlc_sap;
};
struct cpdcp_sn_req {
uint32_t sn;
};
struct cpdcp_relloc_req {
uint32_t receive_sn;
};
struct cpdcp_relloc_conf {
uint32_t receive_sn;
uint32_t send_sn;
};
struct cpdcp_primitive {
uint8_t type;
union {
struct cpdcp_config_req config_req;
struct cpdcp_release_req release_req;
struct cpdcp_sn_req sn_req;
struct cpdcp_relloc_req relloc_req;
struct cpdcp_relloc_conf relloc_conf;
} primitive;
};
#endif
/*
pdcp_proto_extern.h
-------------------
AUTHOR : Lionel GAUTHIER
COMPANY : EURECOM
EMAIL : Lionel.Gauthier@eurecom.fr
***************************************************************************/
#ifndef __PDCP_PROTO_EXTERN_H__
# define __PDCP_PROTO_EXTERN_H__
//# include "pdcp_entity.h"
//# include "rb_mux.h"
# include "mem_block.h"
#ifdef ROHC
extern void pdcp_data_ind (module_id_t module_idP, rb_id_t rab_idP, sdu_size_t data_sizeP, mem_block_t * sduP);
extern void pdcp_data_req (struct pdcp_entity *pdcpP, mem_block * sduP);
extern void send_pdcp_control_primitive (struct pdcp_entity *pdcpP, mem_block * cprimitiveP);
extern void control_pdcp (struct pdcp_entity *pdcpP);
extern void pdcp_process_input_sdus_high(struct pdcp_entity *pdcpP);
extern void pdcp_process_input_sdus_am (struct pdcp_entity *pdcpP, uint16_t data_sizeP, mem_block * sduP);
extern void pdcp_process_output_sdus (struct pdcp_entity *pdcpP, mem_block * sduP, uint8_t rb_idP);
extern void pdcp_process_output_sdus_high (struct pdcp_entity *pdcpP, mem_block * sduP, uint16_t data_sizeP, uint16_t rb_idP);
extern void pdcp_process_input_sdus_um (struct pdcp_entity *pdcpP, uint16_t data_sizeP, mem_block * sduP);
extern void pdcp_process_input_sdus_tr (struct pdcp_entity *pdcpP, uint16_t data_sizeP, mem_block * sduP);
extern void init_pdcp (struct pdcp_entity *pdcpP, struct rb_dispatcher *rbP, uint8_t rb_idP);
extern void *pdcp_tx (struct pdcp_entity *pdcpP, uint16_t data_sizeP, mem_block * sduP);
extern int reception_from_rohc_mt(void);
extern int reception_from_rohc_bs(void);
#else
extern void pdcp_data_ind (module_id_t module_idP, rb_id_t rab_idP, sdu_size_t data_sizeP, mem_block_t * sduP);
extern void pdcp_data_req (struct pdcp_entity *pdcpP, mem_block * sduP);
extern void send_pdcp_control_primitive (struct pdcp_entity *pdcpP, mem_block * cprimitiveP);
extern void control_pdcp (struct pdcp_entity *pdcpP);
extern void pdcp_process_input_sdus_am (struct pdcp_entity *pdcpP);
extern void pdcp_process_output_sdus (struct pdcp_entity *pdcpP, mem_block * sduP, uint8_t rb_idP);
extern void pdcp_process_input_sdus_um (struct pdcp_entity *pdcpP);
extern void pdcp_process_input_sdus_tr (struct pdcp_entity *pdcpP);
extern void init_pdcp (struct pdcp_entity *pdcpP, struct rb_dispatcher *rbP, uint8_t rb_idP);
extern void *pdcp_tx (void *argP);
#endif
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment