common_lib.c 4.76 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22 23 24 25 26 27 28 29 30 31 32
/*! \file common_lib.c 
 * \brief common APIs for different RF frontend device 
 * \author HongliangXU, Navid Nikaein
 * \date 2015
 * \version 0.2
 * \company Eurecom
 * \maintainer:  navid.nikaein@eurecom.fr
 * \note
 * \warning
 */
#include <stdio.h>
33 34 35 36
#include <strings.h>
#include <dlfcn.h>
#include <errno.h>
#include <string.h>
laurent's avatar
laurent committed
37
#include <stdlib.h>
38

39
#include "common_lib.h"
40
#include "common/utils/load_module_shlib.h"
laurent's avatar
laurent committed
41
#include <common/utils/LOG/log.h>
42

43 44 45 46 47
int set_device(openair0_device *device) {

  switch (device->type) {
    
  case EXMIMO_DEV:
laurent's avatar
laurent committed
48
    LOG_I(HW,"[%s] has loaded EXPRESS MIMO device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
49
    break;
50
  case USRP_B200_DEV:
laurent's avatar
laurent committed
51
    LOG_I(HW,"[%s] has loaded USRP B200 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
52
    break;
laurent's avatar
laurent committed
53 54
  case USRP_X300_DEV:
    LOG_I(HW,"[%s] has loaded USRP X300 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
55 56
    break;
  case BLADERF_DEV:
laurent's avatar
laurent committed
57
    LOG_I(HW,"[%s] has loaded BLADERF device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
58
    break;
59
  case LMSSDR_DEV:
laurent's avatar
laurent committed
60
    LOG_I(HW,"[%s] has loaded LMSSDR device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
61
    break;
62
  case NONE_DEV:
laurent's avatar
laurent committed
63
    LOG_W(HW,"[%s] has not loaded a HW device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
64
    break;    
root's avatar
root committed
65
  case ADRV9371_ZC706_DEV:
laurent's avatar
laurent committed
66
    LOG_I(HW,"[%s] has loaded ADRV9371_ZC706 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
root's avatar
root committed
67 68
    break;
  case UEDv2_DEV:
laurent's avatar
laurent committed
69
    LOG_I(HW,"[%s] has loaded UEDv2 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
root's avatar
root committed
70
    break;
71
  default:
laurent's avatar
laurent committed
72
    LOG_E(HW,"[%s] invalid HW device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
73 74
    return -1;
  }
75
  return 0;
76 77 78 79 80 81 82
}

int set_transport(openair0_device *device) {

  switch (device->transp_type) {
    
  case ETHERNET_TP:
laurent's avatar
laurent committed
83
    LOG_I(HW,"[%s] has loaded ETHERNET trasport protocol.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
84 85 86
    return 0;     
    break;
  case NONE_TP:
laurent's avatar
laurent committed
87
    LOG_W(HW,"[%s] has not loaded a transport protocol.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
88 89 90
    return 0; 
    break;    
  default:
laurent's avatar
laurent committed
91
    LOG_E(HW,"[%s] invalid transport protocol.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); 
92 93 94 95 96
    return -1;
    break;
  }
  
}
97
typedef int(*devfunc_t)(openair0_device *, openair0_config_t *, eth_params_t *);
98 99
/* look for the interface library and load it */
int load_lib(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * cfg, uint8_t flag) {
100
  
101
  loader_shlibfunc_t shlib_fdesc[1];
102
  int ret=0;
103
  char *libname;
104
  if (flag == RAU_LOCAL_RADIO_HEAD) {
laurent's avatar
laurent committed
105 106 107
	  if (getenv("RFSIMULATOR") != NULL) 
     	  libname="rfsimulator";
	  else 
108 109
      libname=OAI_RF_LIBNAME;
      shlib_fdesc[0].fname="device_init";
110
    } else {
111 112
      libname=OAI_TP_LIBNAME;
      shlib_fdesc[0].fname="transport_init";      
113
    } 
114
  ret=load_module_shlib(libname,shlib_fdesc,1,NULL);
115
  if (ret < 0) {
laurent's avatar
laurent committed
116
       LOG_E(HW,"Library %s couldn't be loaded\n",libname);
117 118 119
  } else {
       ret=((devfunc_t)shlib_fdesc[0].fptr)(device,openair0_cfg,cfg);
  }    
120
  return ret; 	       
121
}
122 123 124 125 126



int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg) {
  
127
  int rc=0;
128
  rc=load_lib(device, openair0_cfg, NULL,RAU_LOCAL_RADIO_HEAD );
129

130
  if ( rc >= 0) {       
131
	if ( set_device(device) < 0) {
laurent's avatar
laurent committed
132
      LOG_E(HW,"Unsupported radio head\n");
133 134 135
      return -1;		   
    }   
  }
136
  return rc;
137 138
}

139
int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params) {
140
  int rc;
141
  rc=load_lib(device, openair0_cfg, eth_params, RAU_REMOTE_RADIO_HEAD);
142 143
  if ( rc >= 0) {       
    if ( set_transport(device) < 0) {
laurent's avatar
laurent committed
144
      LOG_E(HW,"Unsupported transport protocol\n");
145
      return -1;		   
146
      }   
147
  }
148
  return rc;
149

150
}
151 152 153 154 155 156 157