common_lib.c 5.41 KB
Newer Older
navid's avatar
navid committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*******************************************************************************
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that 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 OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.

   Contact Information
   OpenAirInterface Admin: openair_admin@eurecom.fr
   OpenAirInterface Tech : openair_tech@eurecom.fr
24
   OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
navid's avatar
navid committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

   Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE

 *******************************************************************************/
/*! \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>
40
41
42
43
44
#include <strings.h>
#include <dlfcn.h>
#include <errno.h>
#include <string.h>

navid's avatar
navid committed
45
46
#include "common_lib.h"

47
48
49
50
51
52
53
int set_device(openair0_device *device) {

  switch (device->type) {
    
  case EXMIMO_DEV:
    printf("[%s] has loaded EXPRESS MIMO device.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"));
    break;
54
55
56
57
58
  case USRP_B200_DEV:
    printf("[%s] has loaded USRP B200 device.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH")); 
    break;
case USRP_X300_DEV:
    printf("[%s] has loaded USRP X300 device.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH")); 
59
60
61
62
    break;
  case BLADERF_DEV:
    printf("[%s] has loaded BLADERF device.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH")); 
    break;
63
64
65
  case LMSSDR_DEV:
    printf("[%s] has loaded LMSSDR device.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH")); 
    break;
66
67
68
69
70
71
72
  case NONE_DEV:
    printf("[%s] has not loaded a HW device.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"));
    break;    
  default:
    printf("[%s] invalid HW device.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH")); 
    return -1;
  }
73
  return 0;
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
}

int set_transport(openair0_device *device) {

  switch (device->transp_type) {
    
  case ETHERNET_TP:
    printf("[%s] has loaded ETHERNET trasport protocol.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"));
    return 0;     
    break;
  case NONE_TP:
    printf("[%s] has not loaded a transport protocol.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"));
    return 0; 
    break;    
  default:
    printf("[%s] invalid transport protocol.\n",((device->host_type == BBU_HOST) ? "BBU": "RRH")); 
    return -1;
    break;
  }
  
}
navid's avatar
navid committed
95

96
97
/* 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) {
navid's avatar
navid committed
98
  
99
  void *lib_handle;
100
101
  oai_device_initfunc_t dp ;
  oai_transport_initfunc_t tp ;
102

103
  if (flag == BBU_LOCAL_RADIO_HEAD) {
104
105
      lib_handle = dlopen(OAI_RF_LIBNAME, RTLD_LAZY);
      if (!lib_handle) {
106
107
108
	fprintf(stderr,"Unable to locate %s: HW device set to NONE_DEV.\n", OAI_RF_LIBNAME);
	fprintf(stderr,"%s\n",dlerror());
	return -1;
109
110
      } 
      
111
      dp = dlsym(lib_handle,"device_init");
112
      
113
      if (dp != NULL ) {
114
115
116
117
	if (dp(device,openair0_cfg)!=0) {
	  fprintf(stderr,"Error initializing device\n");
	  return -1;
	}
118
119
120
121
122
123
124
125
      } else {
	fprintf(stderr, "%s %d:oai device intializing function not found %s\n", __FILE__, __LINE__, dlerror());
	return -1;
      }
    } else {
      lib_handle = dlopen(OAI_TP_LIBNAME, RTLD_LAZY);
      if (!lib_handle) {
	printf( "Unable to locate %s: transport protocol set to NONE_TP.\n", OAI_TP_LIBNAME);
126
127
	printf( "%s\n",dlerror());
	return -1;
128
129
      } 
      
130
      tp = dlsym(lib_handle,"transport_init");
131
      
132
133
      if (tp != NULL ) {
	tp(device,openair0_cfg,cfg);
134
135
136
137
138
139
140
      } else {
	fprintf(stderr, "%s %d:oai device intializing function not found %s\n", __FILE__, __LINE__, dlerror());
	return -1;
      }
    } 
    
  return 0; 	       
navid's avatar
navid committed
141
}
142
143
144
145
146
147



int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg) {
  
  int rc;
148
149
  //ToDo: EXMIMO harmonization is not complete. That is the reason for this ifdef
  #ifdef EXMIMO
Cedric Roux's avatar
Cedric Roux committed
150
151
  int device_init(openair0_device *device, openair0_config_t *openair0_cfg);
  rc = device_init(device, openair0_cfg);
152
  #else
153
  rc=load_lib(device, openair0_cfg, NULL,BBU_LOCAL_RADIO_HEAD );
154
155
156
157
158
159
  if ( rc >= 0) {       
    if ( set_device(device) < 0) {
      fprintf(stderr, "%s %d:Unsupported radio head\n",__FILE__, __LINE__);
      return -1;		   
    }   
  }
160
  #endif
161
  return rc;
162
163
}

164
int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params) {
165
  int rc;
166
167
168
  rc=load_lib(device, openair0_cfg, eth_params, BBU_REMOTE_RADIO_HEAD);
  if ( rc >= 0) {       
    if ( set_transport(device) < 0) {
169
      fprintf(stderr, "%s %d:Unsupported transport protocol\n",__FILE__, __LINE__);
170
      return -1;		   
171
      }   
172
  }
173
  return rc;
174

navid's avatar
navid committed
175
}
176
177
178
179
180
181
182