common_lib.c 4.8 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
/*! \file common_lib.c
 * \brief common APIs for different RF frontend device
24 25 26 27 28 29 30 31 32
 * \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 37
#include <strings.h>
#include <dlfcn.h>
#include <errno.h>
#include <string.h>

38
#include "common_lib.h"
39
#include "common/utils/load_module_shlib.h"
40
#include "targets/RT/USER/lte-softmodem.h"
41

42 43
int set_device(openair0_device *device) {
  switch (device->type) {
44
    case EXMIMO_DEV:
laurent's avatar
laurent committed
45
      LOG_I(HW,"[%s] has loaded EXPRESS MIMO device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
46 47 48
      break;

    case USRP_B200_DEV:
laurent's avatar
laurent committed
49
      LOG_I(HW,"[%s] has loaded USRP B200 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
50 51 52
      break;

    case USRP_X300_DEV:
laurent's avatar
laurent committed
53
      LOG_I(HW,"[%s] has loaded USRP X300 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
54 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 59 60
      break;

    case LMSSDR_DEV:
laurent's avatar
laurent committed
61
      LOG_I(HW,"[%s] has loaded LMSSDR device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
62 63 64
      break;

    case IRIS_DEV:
laurent's avatar
laurent committed
65
      LOG_I(HW,"[%s] has loaded Iris device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
66 67 68
      break;

    case NONE_DEV:
laurent's avatar
laurent committed
69
      LOG_I(HW,"[%s] has not loaded a HW device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
70 71 72
      break;

    default:
laurent's avatar
laurent committed
73
      LOG_E(HW,"[%s] invalid HW device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
74
      return -1;
75
  }
76

77
  return 0;
78 79 80 81
}

int set_transport(openair0_device *device) {
  switch (device->transp_type) {
82
    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 87
      return 0;
      break;

    case NONE_TP:
laurent's avatar
laurent committed
88
      LOG_I(HW,"[%s] has not loaded a transport protocol.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
89 90 91 92
      return 0;
      break;

    default:
laurent's avatar
laurent committed
93
      LOG_E(HW,"[%s] invalid transport protocol.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"));
94 95
      return -1;
      break;
96 97
  }
}
98
typedef int(*devfunc_t)(openair0_device *, openair0_config_t *, eth_params_t *);
99
/* look for the interface library and load it */
100
int load_lib(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t *cfg, uint8_t flag) {
101
  loader_shlibfunc_t shlib_fdesc[1];
102
  int ret=0;
103
  char *libname;
104

105
  if ( IS_SOFTMODEM_BASICSIM ) {
106 107
    libname=OAI_BASICSIM_LIBNAME;
    shlib_fdesc[0].fname="device_init";
laurent's avatar
laurent committed
108
  } else if ( IS_SOFTMODEM_RFSIM && flag == RAU_LOCAL_RADIO_HEAD) {
109 110
    libname=OAI_RFSIM_LIBNAME;
    shlib_fdesc[0].fname="device_init";
111
  } else if (flag == RAU_LOCAL_RADIO_HEAD) {
112 113
    libname=OAI_RF_LIBNAME;
    shlib_fdesc[0].fname="device_init";
114
  } else {
115 116 117 118
    libname=OAI_TP_LIBNAME;
    shlib_fdesc[0].fname="transport_init";
  }

119
  ret=load_module_shlib(libname,shlib_fdesc,1,NULL);
120

121
  if (ret < 0) {
laurent's avatar
laurent committed
122
    LOG_E(HW,"Library %s couldn't be loaded\n",libname);
123
  } else {
124 125 126 127
    ret=((devfunc_t)shlib_fdesc[0].fptr)(device,openair0_cfg,cfg);
  }

  return ret;
128
}
129 130 131 132



int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg) {
133
  int rc=0;
134
  rc=load_lib(device, openair0_cfg, NULL,RAU_LOCAL_RADIO_HEAD );
135

136 137
  if ( rc >= 0) {
    if ( set_device(device) < 0) {
laurent's avatar
laurent committed
138
      LOG_E(HW, "%s %d:Unsupported radio head\n",__FILE__, __LINE__);
139 140
      return -1;
    }
141
  }
142

143
  return rc;
144 145
}

146
int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t *eth_params) {
147
  int rc;
148
  rc=load_lib(device, openair0_cfg, eth_params, RAU_REMOTE_RADIO_HEAD);
149 150

  if ( rc >= 0) {
151
    if ( set_transport(device) < 0) {
laurent's avatar
laurent committed
152
      LOG_E(HW, "%s %d:Unsupported transport protocol\n",__FILE__, __LINE__);
153 154
      return -1;
    }
155
  }
156

157
  return rc;
158
}
159 160 161 162 163 164 165