From 98d949b02f9ebcc50b45158103eb891945d76911 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 16 Sep 2010 00:01:43 +0800 Subject: bsc: Rename the RF Ctl interface to match master --- openbsc/include/openbsc/Makefile.am | 2 +- openbsc/include/openbsc/bsc_msc_rf.h | 22 --- openbsc/include/openbsc/gsm_data.h | 4 +- openbsc/include/openbsc/osmo_bsc_rf.h | 22 +++ openbsc/src/Makefile.am | 2 +- openbsc/src/bsc_msc_grace.c | 2 +- openbsc/src/bsc_msc_ip.c | 4 +- openbsc/src/bsc_msc_rf.c | 266 ---------------------------------- openbsc/src/osmo_bsc_rf.c | 266 ++++++++++++++++++++++++++++++++++ 9 files changed, 295 insertions(+), 295 deletions(-) delete mode 100644 openbsc/include/openbsc/bsc_msc_rf.h create mode 100644 openbsc/include/openbsc/osmo_bsc_rf.h delete mode 100644 openbsc/src/bsc_msc_rf.c create mode 100644 openbsc/src/osmo_bsc_rf.c diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am index fdf2f42c7..b44c9954e 100644 --- a/openbsc/include/openbsc/Makefile.am +++ b/openbsc/include/openbsc/Makefile.am @@ -6,7 +6,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \ bsc_rll.h mncc.h transaction.h ussd.h gsm_04_80.h \ silent_call.h mgcp.h meas_rep.h rest_octets.h \ system_information.h handover.h mgcp_internal.h \ - vty.h bssap.h bsc_msc.h bsc_nat.h bsc_msc_rf.h \ + vty.h bssap.h bsc_msc.h bsc_nat.h osmo_bsc_rf.h \ bsc_msc_grace.h openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h diff --git a/openbsc/include/openbsc/bsc_msc_rf.h b/openbsc/include/openbsc/bsc_msc_rf.h deleted file mode 100644 index f72309923..000000000 --- a/openbsc/include/openbsc/bsc_msc_rf.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef BSC_MSC_RF -#define BSC_MSC_RF - -#include - -struct gsm_network; - -struct bsc_msc_rf { - /* the value of signal.h */ - int policy; - struct bsc_fd listen; - struct gsm_network *gsm_network; -}; - -struct bsc_msc_rf_conn { - struct write_queue queue; - struct bsc_msc_rf *rf; -}; - -struct bsc_msc_rf *bsc_msc_rf_create(const char *path, struct gsm_network *net); - -#endif diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h index 5d5993364..c52229a81 100644 --- a/openbsc/include/openbsc/gsm_data.h +++ b/openbsc/include/openbsc/gsm_data.h @@ -88,7 +88,7 @@ typedef int gsm_cbfn(unsigned int hooknum, struct msgb *msg, void *data, void *param); -struct bsc_msc_rf; +struct osmo_bsc_rf; struct sccp_connection; /* Real authentication information containing Ki */ @@ -700,7 +700,7 @@ struct gsm_network { struct bsc_msc_connection *msc_con; int ping_timeout; int pong_timeout; - struct bsc_msc_rf *rf; + struct osmo_bsc_rf *rf; char *ussd_grace_txt; }; diff --git a/openbsc/include/openbsc/osmo_bsc_rf.h b/openbsc/include/openbsc/osmo_bsc_rf.h new file mode 100644 index 000000000..0c9ba32f5 --- /dev/null +++ b/openbsc/include/openbsc/osmo_bsc_rf.h @@ -0,0 +1,22 @@ +#ifndef BSC_MSC_RF +#define BSC_MSC_RF + +#include + +struct gsm_network; + +struct osmo_bsc_rf { + /* the value of signal.h */ + int policy; + struct bsc_fd listen; + struct gsm_network *gsm_network; +}; + +struct osmo_bsc_rf_conn { + struct write_queue queue; + struct osmo_bsc_rf *rf; +}; + +struct osmo_bsc_rf *osmo_bsc_rf_create(const char *path, struct gsm_network *net); + +#endif diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am index cd38c69a4..cba8832f1 100644 --- a/openbsc/src/Makefile.am +++ b/openbsc/src/Makefile.am @@ -30,7 +30,7 @@ bsc_hack_LDADD = libmsc.a libbsc.a libmsc.a libvty.a -ldl -ldbi $(LIBCRYPT) bs11_config_SOURCES = bs11_config.c abis_nm.c gsm_data.c debug.c \ rs232.c bts_siemens_bs11.c bsc_msc_ip_SOURCES = bssap.c bsc_msc_ip.c bsc_init.c vty_interface.c vty_interface_bsc.c \ - bsc_msc.c bsc_msc_rf.c bsc_msc_grace.c gsm_04_80.c + bsc_msc.c osmo_bsc_rf.c bsc_msc_grace.c gsm_04_80.c bsc_msc_ip_LDADD = libbsc.a libvty.a $(LIBOSMOSCCP_LIBS) diff --git a/openbsc/src/bsc_msc_grace.c b/openbsc/src/bsc_msc_grace.c index f8aed7ba9..441cab9f0 100644 --- a/openbsc/src/bsc_msc_grace.c +++ b/openbsc/src/bsc_msc_grace.c @@ -20,7 +20,7 @@ */ #include -#include +#include #include #include diff --git a/openbsc/src/bsc_msc_ip.c b/openbsc/src/bsc_msc_ip.c index 7cbe9e1a2..002c58152 100644 --- a/openbsc/src/bsc_msc_ip.c +++ b/openbsc/src/bsc_msc_ip.c @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include @@ -1249,7 +1249,7 @@ int main(int argc, char **argv) } if (rf_ctl) { - bsc_gsmnet->rf = bsc_msc_rf_create(rf_ctl, bsc_gsmnet); + bsc_gsmnet->rf = osmo_bsc_rf_create(rf_ctl, bsc_gsmnet); if (!bsc_gsmnet->rf) { fprintf(stderr, "Failed to create the RF service.\n"); exit(1); diff --git a/openbsc/src/bsc_msc_rf.c b/openbsc/src/bsc_msc_rf.c deleted file mode 100644 index b6901cc53..000000000 --- a/openbsc/src/bsc_msc_rf.c +++ /dev/null @@ -1,266 +0,0 @@ -/* RF Ctl handling socket */ - -/* (C) 2010 by Harald Welte - * (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 - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (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 - * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include - -#define RF_CMD_QUERY '?' -#define RF_CMD_OFF '0' -#define RF_CMD_ON '1' -#define RF_CMD_GRACE 'g' - -static int lock_each_trx(struct gsm_network *net, int lock) -{ - struct gsm_bts *bts; - - llist_for_each_entry(bts, &net->bts_list, list) { - struct gsm_bts_trx *trx; - llist_for_each_entry(trx, &bts->trx_list, list) { - gsm_trx_lock_rf(trx, lock); - } - } - - return 0; -} - -/* - * Send a '1' when one TRX is online, otherwise send 0 - */ -static void handle_query(struct bsc_msc_rf_conn *conn) -{ - struct msgb *msg; - struct gsm_bts *bts; - char send = RF_CMD_OFF; - - llist_for_each_entry(bts, &conn->rf->gsm_network->bts_list, list) { - struct gsm_bts_trx *trx; - llist_for_each_entry(trx, &bts->trx_list, list) { - if (trx->nm_state.availability == NM_AVSTATE_OK && - trx->nm_state.operational != NM_STATE_LOCKED) { - send = RF_CMD_ON; - break; - } - } - } - - msg = msgb_alloc(10, "RF Query"); - if (!msg) { - LOGP(DINP, LOGL_ERROR, "Failed to allocate response msg.\n"); - return; - } - - msg->l2h = msgb_put(msg, 1); - msg->l2h[0] = send; - - if (write_queue_enqueue(&conn->queue, msg) != 0) { - LOGP(DINP, LOGL_ERROR, "Failed to enqueue the answer.\n"); - msgb_free(msg); - return; - } - - return; -} - -static void send_signal(struct bsc_msc_rf_conn *conn, int val) -{ - struct rf_signal_data sig; - sig.net = conn->rf->gsm_network; - - conn->rf->policy = val; - dispatch_signal(SS_RF, val, &sig); -} - -static int rf_read_cmd(struct bsc_fd *fd) -{ - struct bsc_msc_rf_conn *conn = fd->data; - char buf[1]; - int rc; - - rc = read(fd->fd, buf, sizeof(buf)); - if (rc != sizeof(buf)) { - LOGP(DINP, LOGL_ERROR, "Short read %d/%s\n", errno, strerror(errno)); - bsc_unregister_fd(fd); - close(fd->fd); - write_queue_clear(&conn->queue); - talloc_free(conn); - return -1; - } - - switch (buf[0]) { - case RF_CMD_QUERY: - handle_query(conn); - break; - case RF_CMD_OFF: - lock_each_trx(conn->rf->gsm_network, 1); - send_signal(conn, S_RF_OFF); - break; - case RF_CMD_ON: - lock_each_trx(conn->rf->gsm_network, 0); - send_signal(conn, S_RF_ON); - break; - case RF_CMD_GRACE: - send_signal(conn, S_RF_GRACE); - break; - default: - LOGP(DINP, LOGL_ERROR, "Unknown command %d\n", buf[0]); - break; - } - - return 0; -} - -static int rf_write_cmd(struct bsc_fd *fd, struct msgb *msg) -{ - int rc; - - rc = write(fd->fd, msg->data, msg->len); - if (rc != msg->len) { - LOGP(DINP, LOGL_ERROR, "Short write %d/%s\n", errno, strerror(errno)); - return -1; - } - - return 0; -} - -static int rf_ctl_accept(struct bsc_fd *bfd, unsigned int what) -{ - struct bsc_msc_rf_conn *conn; - struct bsc_msc_rf *rf = bfd->data; - struct sockaddr_un addr; - socklen_t len = sizeof(addr); - int fd; - - fd = accept(bfd->fd, (struct sockaddr *) &addr, &len); - if (fd < 0) { - LOGP(DINP, LOGL_ERROR, "Failed to accept. errno: %d/%s\n", - errno, strerror(errno)); - return -1; - } - - conn = talloc_zero(rf, struct bsc_msc_rf_conn); - if (!conn) { - LOGP(DINP, LOGL_ERROR, "Failed to allocate mem.\n"); - close(fd); - return -1; - } - - write_queue_init(&conn->queue, 10); - conn->queue.bfd.data = conn; - conn->queue.bfd.fd = fd; - conn->queue.bfd.when = BSC_FD_READ | BSC_FD_WRITE; - conn->queue.read_cb = rf_read_cmd; - conn->queue.write_cb = rf_write_cmd; - conn->rf = rf; - - if (bsc_register_fd(&conn->queue.bfd) != 0) { - close(fd); - talloc_free(conn); - return -1; - } - - return 0; -} - -struct bsc_msc_rf *bsc_msc_rf_create(const char *path, struct gsm_network *net) -{ - unsigned int namelen; - struct sockaddr_un local; - struct bsc_fd *bfd; - struct bsc_msc_rf *rf; - int rc; - - rf = talloc_zero(NULL, struct bsc_msc_rf); - if (!rf) { - LOGP(DINP, LOGL_ERROR, "Failed to create bsc_msc_rf.\n"); - return NULL; - } - - bfd = &rf->listen; - bfd->fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (bfd->fd < 0) { - LOGP(DINP, LOGL_ERROR, "Can not create socket. %d/%s\n", - errno, strerror(errno)); - return NULL; - } - - local.sun_family = AF_UNIX; - strncpy(local.sun_path, path, sizeof(local.sun_path)); - local.sun_path[sizeof(local.sun_path) - 1] = '\0'; - unlink(local.sun_path); - - /* we use the same magic that X11 uses in Xtranssock.c for - * calculating the proper length of the sockaddr */ -#if defined(BSD44SOCKETS) || defined(__UNIXWARE__) - local.sun_len = strlen(local.sun_path); -#endif -#if defined(BSD44SOCKETS) || defined(SUN_LEN) - namelen = SUN_LEN(&local); -#else - namelen = strlen(local.sun_path) + - offsetof(struct sockaddr_un, sun_path); -#endif - - rc = bind(bfd->fd, (struct sockaddr *) &local, namelen); - if (rc != 0) { - LOGP(DINP, LOGL_ERROR, "Failed to bind '%s' errno: %d/%s\n", - local.sun_path, errno, strerror(errno)); - close(bfd->fd); - talloc_free(rf); - return NULL; - } - - if (listen(bfd->fd, 0) != 0) { - LOGP(DINP, LOGL_ERROR, "Failed to listen: %d/%s\n", errno, strerror(errno)); - close(bfd->fd); - talloc_free(rf); - return NULL; - } - - bfd->when = BSC_FD_READ; - bfd->cb = rf_ctl_accept; - bfd->data = rf; - - if (bsc_register_fd(bfd) != 0) { - LOGP(DINP, LOGL_ERROR, "Failed to register bfd.\n"); - close(bfd->fd); - talloc_free(rf); - return NULL; - } - - rf->gsm_network = net; - rf->policy = S_RF_ON; - - return rf; -} - diff --git a/openbsc/src/osmo_bsc_rf.c b/openbsc/src/osmo_bsc_rf.c new file mode 100644 index 000000000..06c84666c --- /dev/null +++ b/openbsc/src/osmo_bsc_rf.c @@ -0,0 +1,266 @@ +/* RF Ctl handling socket */ + +/* (C) 2010 by Harald Welte + * (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 + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (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 + * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#define RF_CMD_QUERY '?' +#define RF_CMD_OFF '0' +#define RF_CMD_ON '1' +#define RF_CMD_GRACE 'g' + +static int lock_each_trx(struct gsm_network *net, int lock) +{ + struct gsm_bts *bts; + + llist_for_each_entry(bts, &net->bts_list, list) { + struct gsm_bts_trx *trx; + llist_for_each_entry(trx, &bts->trx_list, list) { + gsm_trx_lock_rf(trx, lock); + } + } + + return 0; +} + +/* + * Send a '1' when one TRX is online, otherwise send 0 + */ +static void handle_query(struct osmo_bsc_rf_conn *conn) +{ + struct msgb *msg; + struct gsm_bts *bts; + char send = RF_CMD_OFF; + + llist_for_each_entry(bts, &conn->rf->gsm_network->bts_list, list) { + struct gsm_bts_trx *trx; + llist_for_each_entry(trx, &bts->trx_list, list) { + if (trx->nm_state.availability == NM_AVSTATE_OK && + trx->nm_state.operational != NM_STATE_LOCKED) { + send = RF_CMD_ON; + break; + } + } + } + + msg = msgb_alloc(10, "RF Query"); + if (!msg) { + LOGP(DINP, LOGL_ERROR, "Failed to allocate response msg.\n"); + return; + } + + msg->l2h = msgb_put(msg, 1); + msg->l2h[0] = send; + + if (write_queue_enqueue(&conn->queue, msg) != 0) { + LOGP(DINP, LOGL_ERROR, "Failed to enqueue the answer.\n"); + msgb_free(msg); + return; + } + + return; +} + +static void send_signal(struct osmo_bsc_rf_conn *conn, int val) +{ + struct rf_signal_data sig; + sig.net = conn->rf->gsm_network; + + conn->rf->policy = val; + dispatch_signal(SS_RF, val, &sig); +} + +static int rf_read_cmd(struct bsc_fd *fd) +{ + struct osmo_bsc_rf_conn *conn = fd->data; + char buf[1]; + int rc; + + rc = read(fd->fd, buf, sizeof(buf)); + if (rc != sizeof(buf)) { + LOGP(DINP, LOGL_ERROR, "Short read %d/%s\n", errno, strerror(errno)); + bsc_unregister_fd(fd); + close(fd->fd); + write_queue_clear(&conn->queue); + talloc_free(conn); + return -1; + } + + switch (buf[0]) { + case RF_CMD_QUERY: + handle_query(conn); + break; + case RF_CMD_OFF: + lock_each_trx(conn->rf->gsm_network, 1); + send_signal(conn, S_RF_OFF); + break; + case RF_CMD_ON: + lock_each_trx(conn->rf->gsm_network, 0); + send_signal(conn, S_RF_ON); + break; + case RF_CMD_GRACE: + send_signal(conn, S_RF_GRACE); + break; + default: + LOGP(DINP, LOGL_ERROR, "Unknown command %d\n", buf[0]); + break; + } + + return 0; +} + +static int rf_write_cmd(struct bsc_fd *fd, struct msgb *msg) +{ + int rc; + + rc = write(fd->fd, msg->data, msg->len); + if (rc != msg->len) { + LOGP(DINP, LOGL_ERROR, "Short write %d/%s\n", errno, strerror(errno)); + return -1; + } + + return 0; +} + +static int rf_ctl_accept(struct bsc_fd *bfd, unsigned int what) +{ + struct osmo_bsc_rf_conn *conn; + struct osmo_bsc_rf *rf = bfd->data; + struct sockaddr_un addr; + socklen_t len = sizeof(addr); + int fd; + + fd = accept(bfd->fd, (struct sockaddr *) &addr, &len); + if (fd < 0) { + LOGP(DINP, LOGL_ERROR, "Failed to accept. errno: %d/%s\n", + errno, strerror(errno)); + return -1; + } + + conn = talloc_zero(rf, struct osmo_bsc_rf_conn); + if (!conn) { + LOGP(DINP, LOGL_ERROR, "Failed to allocate mem.\n"); + close(fd); + return -1; + } + + write_queue_init(&conn->queue, 10); + conn->queue.bfd.data = conn; + conn->queue.bfd.fd = fd; + conn->queue.bfd.when = BSC_FD_READ | BSC_FD_WRITE; + conn->queue.read_cb = rf_read_cmd; + conn->queue.write_cb = rf_write_cmd; + conn->rf = rf; + + if (bsc_register_fd(&conn->queue.bfd) != 0) { + close(fd); + talloc_free(conn); + return -1; + } + + return 0; +} + +struct osmo_bsc_rf *osmo_bsc_rf_create(const char *path, struct gsm_network *net) +{ + unsigned int namelen; + struct sockaddr_un local; + struct bsc_fd *bfd; + struct osmo_bsc_rf *rf; + int rc; + + rf = talloc_zero(NULL, struct osmo_bsc_rf); + if (!rf) { + LOGP(DINP, LOGL_ERROR, "Failed to create osmo_bsc_rf.\n"); + return NULL; + } + + bfd = &rf->listen; + bfd->fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (bfd->fd < 0) { + LOGP(DINP, LOGL_ERROR, "Can not create socket. %d/%s\n", + errno, strerror(errno)); + return NULL; + } + + local.sun_family = AF_UNIX; + strncpy(local.sun_path, path, sizeof(local.sun_path)); + local.sun_path[sizeof(local.sun_path) - 1] = '\0'; + unlink(local.sun_path); + + /* we use the same magic that X11 uses in Xtranssock.c for + * calculating the proper length of the sockaddr */ +#if defined(BSD44SOCKETS) || defined(__UNIXWARE__) + local.sun_len = strlen(local.sun_path); +#endif +#if defined(BSD44SOCKETS) || defined(SUN_LEN) + namelen = SUN_LEN(&local); +#else + namelen = strlen(local.sun_path) + + offsetof(struct sockaddr_un, sun_path); +#endif + + rc = bind(bfd->fd, (struct sockaddr *) &local, namelen); + if (rc != 0) { + LOGP(DINP, LOGL_ERROR, "Failed to bind '%s' errno: %d/%s\n", + local.sun_path, errno, strerror(errno)); + close(bfd->fd); + talloc_free(rf); + return NULL; + } + + if (listen(bfd->fd, 0) != 0) { + LOGP(DINP, LOGL_ERROR, "Failed to listen: %d/%s\n", errno, strerror(errno)); + close(bfd->fd); + talloc_free(rf); + return NULL; + } + + bfd->when = BSC_FD_READ; + bfd->cb = rf_ctl_accept; + bfd->data = rf; + + if (bsc_register_fd(bfd) != 0) { + LOGP(DINP, LOGL_ERROR, "Failed to register bfd.\n"); + close(bfd->fd); + talloc_free(rf); + return NULL; + } + + rf->gsm_network = net; + rf->policy = S_RF_ON; + + return rf; +} + -- cgit v1.2.3