2010-04-30 18:26:32 +00:00
|
|
|
/* OpenBSC sokcet code, taken from Abis input driver for ip.access */
|
|
|
|
|
|
|
|
/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* (C) 2010 by Holger Hans Peter Freyther
|
|
|
|
* (C) 2010 by On-Waves
|
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2010-04-30 18:26:32 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2010-04-30 18:26:32 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-04-30 18:26:32 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/select.h>
|
|
|
|
#include <osmocom/gsm/tlv.h>
|
|
|
|
#include <osmocom/core/msgb.h>
|
2010-04-30 18:26:32 +00:00
|
|
|
#include <openbsc/debug.h>
|
|
|
|
#include <openbsc/gsm_data.h>
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2011-05-06 10:11:23 +00:00
|
|
|
int make_sock(struct osmo_fd *bfd, int proto,
|
2011-04-18 15:04:00 +00:00
|
|
|
uint32_t ip, uint16_t port, int priv_nr,
|
2011-05-06 10:11:23 +00:00
|
|
|
int (*cb)(struct osmo_fd *fd, unsigned int what), void *data)
|
2010-04-30 18:26:32 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
int ret, on = 1;
|
|
|
|
int type = SOCK_STREAM;
|
|
|
|
|
2010-05-19 12:11:05 +00:00
|
|
|
switch (proto) {
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
type = SOCK_STREAM;
|
|
|
|
break;
|
|
|
|
case IPPROTO_UDP:
|
2010-04-30 18:26:32 +00:00
|
|
|
type = SOCK_DGRAM;
|
2010-05-19 12:11:05 +00:00
|
|
|
break;
|
2012-04-08 13:56:00 +00:00
|
|
|
#ifdef IPPROTO_GRE
|
2010-05-19 12:11:05 +00:00
|
|
|
case IPPROTO_GRE:
|
|
|
|
type = SOCK_RAW;
|
|
|
|
break;
|
2012-04-08 13:56:00 +00:00
|
|
|
#endif
|
2010-05-19 12:11:05 +00:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-04-30 18:26:32 +00:00
|
|
|
|
|
|
|
bfd->fd = socket(AF_INET, type, proto);
|
|
|
|
bfd->cb = cb;
|
|
|
|
bfd->when = BSC_FD_READ;
|
2011-04-05 16:33:24 +00:00
|
|
|
bfd->data = data;
|
|
|
|
bfd->priv_nr = priv_nr;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
|
|
|
if (bfd->fd < 0) {
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
LOGP(DLINP, LOGL_ERROR, "could not create socket.\n");
|
2010-04-30 18:26:32 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = htons(port);
|
2011-04-05 16:33:24 +00:00
|
|
|
if (ip != INADDR_ANY)
|
2010-05-19 12:38:50 +00:00
|
|
|
addr.sin_addr.s_addr = htonl(ip);
|
|
|
|
else
|
|
|
|
addr.sin_addr.s_addr = INADDR_ANY;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
|
|
|
setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
|
|
|
|
|
|
|
ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
|
|
|
|
if (ret < 0) {
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
LOGP(DLINP, LOGL_ERROR, "could not bind socket %s\n",
|
2010-04-30 18:26:32 +00:00
|
|
|
strerror(errno));
|
|
|
|
close(bfd->fd);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2010-05-19 12:11:05 +00:00
|
|
|
if (proto == IPPROTO_TCP) {
|
2010-04-30 18:26:32 +00:00
|
|
|
ret = listen(bfd->fd, 1);
|
|
|
|
if (ret < 0) {
|
|
|
|
perror("listen");
|
2010-10-12 21:19:37 +00:00
|
|
|
close(bfd->fd);
|
2010-04-30 18:26:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 10:11:23 +00:00
|
|
|
ret = osmo_fd_register(bfd);
|
2010-04-30 18:26:32 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
perror("register_listen_fd");
|
|
|
|
close(bfd->fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|