Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 1 | /* Routines to talk to the MSC using the IPA Protocol */ |
| 2 | /* |
| 3 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Hans Peter Freyther | 98e49d4 | 2010-06-15 18:46:56 +0800 | [diff] [blame] | 4 | * (C) 2010 by On-Waves |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 16 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <openbsc/bsc_msc.h> |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 23 | #include <openbsc/debug.h> |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 24 | #include <osmocom/abis/ipaccess.h> |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 25 | |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 26 | #include <osmocom/core/write_queue.h> |
| 27 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 28 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 29 | #include <osmocom/gsm/tlv.h> |
| 30 | |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 31 | #include <arpa/inet.h> |
| 32 | #include <sys/socket.h> |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 33 | #include <errno.h> |
| 34 | #include <fcntl.h> |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 35 | #include <stdio.h> |
| 36 | #include <string.h> |
| 37 | #include <unistd.h> |
| 38 | |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 39 | static void connection_loss(struct bsc_msc_connection *con) |
| 40 | { |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 41 | struct osmo_fd *fd; |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 42 | |
| 43 | fd = &con->write_queue.bfd; |
| 44 | |
Jacob Erlbeck | 1a5c246 | 2014-03-31 13:42:11 +0200 | [diff] [blame] | 45 | if (con->pending_msg) { |
| 46 | LOGP(DMSC, LOGL_ERROR, |
| 47 | "MSC(%s) dropping incomplete message.\n", con->name); |
| 48 | msgb_free(con->pending_msg); |
| 49 | con->pending_msg = NULL; |
| 50 | } |
| 51 | |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 52 | close(fd->fd); |
| 53 | fd->fd = -1; |
Pablo Neira Ayuso | da08850 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 54 | fd->cb = osmo_wqueue_bfd_cb; |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 55 | fd->when = 0; |
| 56 | |
| 57 | con->is_connected = 0; |
Holger Hans Peter Freyther | 8fd9775 | 2010-07-05 14:14:18 +0800 | [diff] [blame] | 58 | con->first_contact = 0; |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 59 | con->connection_loss(con); |
| 60 | } |
| 61 | |
Holger Hans Peter Freyther | 9b6f999 | 2010-05-05 22:48:56 +0800 | [diff] [blame] | 62 | static void msc_con_timeout(void *_con) |
| 63 | { |
| 64 | struct bsc_msc_connection *con = _con; |
| 65 | |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 66 | LOGP(DMSC, LOGL_ERROR, |
| 67 | "MSC(%s) Connection timeout.\n", con->name); |
Holger Hans Peter Freyther | 9b6f999 | 2010-05-05 22:48:56 +0800 | [diff] [blame] | 68 | bsc_msc_lost(con); |
| 69 | } |
| 70 | |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 71 | /* called in the case of a non blocking connect */ |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 72 | static int msc_connection_connect(struct osmo_fd *fd, unsigned int what) |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 73 | { |
| 74 | int rc; |
| 75 | int val; |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 76 | struct bsc_msc_connection *con; |
Pablo Neira Ayuso | da08850 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 77 | struct osmo_wqueue *queue; |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 78 | |
| 79 | socklen_t len = sizeof(val); |
| 80 | |
Pablo Neira Ayuso | da08850 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 81 | queue = container_of(fd, struct osmo_wqueue, bfd); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 82 | con = container_of(queue, struct bsc_msc_connection, write_queue); |
| 83 | |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 84 | if ((what & BSC_FD_WRITE) == 0) { |
| 85 | LOGP(DMSC, LOGL_ERROR, |
| 86 | "MSC(%s) Callback but not writable.\n", con->name); |
| 87 | return -1; |
| 88 | } |
| 89 | |
Holger Hans Peter Freyther | 58aba05 | 2010-10-07 04:42:03 +0800 | [diff] [blame] | 90 | /* From here on we will either be connected or reconnect */ |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 91 | osmo_timer_del(&con->timeout_timer); |
Holger Hans Peter Freyther | 58aba05 | 2010-10-07 04:42:03 +0800 | [diff] [blame] | 92 | |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 93 | /* check the socket state */ |
| 94 | rc = getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, &val, &len); |
| 95 | if (rc != 0) { |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 96 | LOGP(DMSC, LOGL_ERROR, |
| 97 | "getsockopt for the MSC(%s) socket failed.\n", con->name); |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 98 | goto error; |
| 99 | } |
| 100 | if (val != 0) { |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 101 | LOGP(DMSC, LOGL_ERROR, |
| 102 | "Not connected to the MSC(%s): %d\n", |
| 103 | con->name, val); |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 104 | goto error; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /* go to full operation */ |
Pablo Neira Ayuso | da08850 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 109 | fd->cb = osmo_wqueue_bfd_cb; |
Holger Hans Peter Freyther | 1f9d511 | 2010-04-08 11:12:32 +0200 | [diff] [blame] | 110 | fd->when = BSC_FD_READ | BSC_FD_EXCEPT; |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 111 | |
| 112 | con->is_connected = 1; |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 113 | LOGP(DMSC, LOGL_NOTICE, |
| 114 | "(Re)Connected to the MSC(%s).\n", con->name); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 115 | if (con->connected) |
| 116 | con->connected(con); |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 117 | return 0; |
| 118 | |
| 119 | error: |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 120 | osmo_fd_unregister(fd); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 121 | connection_loss(con); |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 122 | return -1; |
| 123 | } |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 124 | static void setnonblocking(struct osmo_fd *fd) |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 125 | { |
| 126 | int flags; |
| 127 | |
| 128 | flags = fcntl(fd->fd, F_GETFL); |
| 129 | if (flags < 0) { |
| 130 | perror("fcntl get failed"); |
| 131 | close(fd->fd); |
| 132 | fd->fd = -1; |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | flags |= O_NONBLOCK; |
| 137 | flags = fcntl(fd->fd, F_SETFL, flags); |
| 138 | if (flags < 0) { |
| 139 | perror("fcntl get failed"); |
| 140 | close(fd->fd); |
| 141 | fd->fd = -1; |
| 142 | return; |
| 143 | } |
| 144 | } |
| 145 | |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 146 | int bsc_msc_connect(struct bsc_msc_connection *con) |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 147 | { |
Holger Hans Peter Freyther | 47a9f4b | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 148 | struct bsc_msc_dest *dest; |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 149 | struct osmo_fd *fd; |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 150 | struct sockaddr_in sin; |
| 151 | int on = 1, ret; |
| 152 | |
Holger Hans Peter Freyther | 47a9f4b | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 153 | if (llist_empty(con->dests)) { |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 154 | LOGP(DMSC, LOGL_ERROR, |
| 155 | "No MSC(%s) connections configured.\n", |
| 156 | con->name); |
Holger Hans Peter Freyther | 47a9f4b | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 157 | connection_loss(con); |
| 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | /* move to the next connection */ |
| 162 | dest = (struct bsc_msc_dest *) con->dests->next; |
| 163 | llist_del(&dest->list); |
| 164 | llist_add_tail(&dest->list, con->dests); |
| 165 | |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 166 | LOGP(DMSC, LOGL_NOTICE, |
| 167 | "Attempting to connect MSC(%s) at %s:%d\n", |
| 168 | con->name, dest->ip, dest->port); |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 169 | |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 170 | con->is_connected = 0; |
| 171 | |
Jacob Erlbeck | 1a5c246 | 2014-03-31 13:42:11 +0200 | [diff] [blame] | 172 | msgb_free(con->pending_msg); |
| 173 | con->pending_msg = NULL; |
| 174 | |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 175 | fd = &con->write_queue.bfd; |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 176 | fd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 177 | fd->priv_nr = 1; |
| 178 | |
| 179 | if (fd->fd < 0) { |
| 180 | perror("Creating TCP socket failed"); |
| 181 | return fd->fd; |
| 182 | } |
| 183 | |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 184 | /* make it non blocking */ |
| 185 | setnonblocking(fd); |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 186 | |
Holger Hans Peter Freyther | 7ba0c54 | 2010-06-15 18:52:38 +0800 | [diff] [blame] | 187 | /* set the socket priority */ |
| 188 | ret = setsockopt(fd->fd, IPPROTO_IP, IP_TOS, |
Holger Hans Peter Freyther | 47a9f4b | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 189 | &dest->dscp, sizeof(dest->dscp)); |
Holger Hans Peter Freyther | 7ba0c54 | 2010-06-15 18:52:38 +0800 | [diff] [blame] | 190 | if (ret != 0) |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 191 | LOGP(DMSC, LOGL_ERROR, |
| 192 | "Failed to set DSCP to %d on MSC(%s). %s\n", |
| 193 | dest->dscp, con->name, strerror(errno)); |
Holger Hans Peter Freyther | 7ba0c54 | 2010-06-15 18:52:38 +0800 | [diff] [blame] | 194 | |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 195 | memset(&sin, 0, sizeof(sin)); |
| 196 | sin.sin_family = AF_INET; |
Holger Hans Peter Freyther | 47a9f4b | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 197 | sin.sin_port = htons(dest->port); |
| 198 | inet_aton(dest->ip, &sin.sin_addr); |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 199 | |
| 200 | setsockopt(fd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
| 201 | ret = connect(fd->fd, (struct sockaddr *) &sin, sizeof(sin)); |
| 202 | |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 203 | if (ret == -1 && errno == EINPROGRESS) { |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 204 | LOGP(DMSC, LOGL_ERROR, |
| 205 | "MSC(%s) Connection in progress\n", con->name); |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 206 | fd->when = BSC_FD_WRITE; |
| 207 | fd->cb = msc_connection_connect; |
Holger Hans Peter Freyther | 9b6f999 | 2010-05-05 22:48:56 +0800 | [diff] [blame] | 208 | con->timeout_timer.cb = msc_con_timeout; |
| 209 | con->timeout_timer.data = con; |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 210 | osmo_timer_schedule(&con->timeout_timer, 20, 0); |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 211 | } else if (ret < 0) { |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 212 | perror("Connection failed"); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 213 | connection_loss(con); |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 214 | return ret; |
Holger Hans Peter Freyther | 8b901fa | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 215 | } else { |
Holger Hans Peter Freyther | 1f9d511 | 2010-04-08 11:12:32 +0200 | [diff] [blame] | 216 | fd->when = BSC_FD_READ | BSC_FD_EXCEPT; |
Pablo Neira Ayuso | da08850 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 217 | fd->cb = osmo_wqueue_bfd_cb; |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 218 | con->is_connected = 1; |
| 219 | if (con->connected) |
| 220 | con->connected(con); |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 221 | } |
| 222 | |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 223 | ret = osmo_fd_register(fd); |
Holger Hans Peter Freyther | 9e16ba5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 224 | if (ret < 0) { |
| 225 | perror("Registering the fd failed"); |
| 226 | close(fd->fd); |
| 227 | return ret; |
| 228 | } |
| 229 | |
| 230 | return ret; |
| 231 | } |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 232 | |
Holger Hans Peter Freyther | 47a9f4b | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 233 | struct bsc_msc_connection *bsc_msc_create(void *ctx, struct llist_head *dests) |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 234 | { |
| 235 | struct bsc_msc_connection *con; |
| 236 | |
| 237 | con = talloc_zero(NULL, struct bsc_msc_connection); |
| 238 | if (!con) { |
Holger Hans Peter Freyther | 323d2f5 | 2013-09-04 08:45:48 +0200 | [diff] [blame] | 239 | LOGP(DMSC, LOGL_FATAL, "Failed to create the MSC connection.\n"); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 240 | return NULL; |
| 241 | } |
| 242 | |
Holger Hans Peter Freyther | 47a9f4b | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 243 | con->dests = dests; |
| 244 | con->write_queue.bfd.fd = -1; |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 245 | con->name = ""; |
Pablo Neira Ayuso | da08850 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 246 | osmo_wqueue_init(&con->write_queue, 100); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 247 | return con; |
| 248 | } |
| 249 | |
| 250 | void bsc_msc_lost(struct bsc_msc_connection *con) |
| 251 | { |
Pablo Neira Ayuso | da08850 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 252 | osmo_wqueue_clear(&con->write_queue); |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 253 | osmo_timer_del(&con->timeout_timer); |
Holger Hans Peter Freyther | bac47a2 | 2013-09-03 14:21:48 +0200 | [diff] [blame] | 254 | osmo_timer_del(&con->reconnect_timer); |
Holger Hans Peter Freyther | 88b3012 | 2010-10-07 06:07:57 +0800 | [diff] [blame] | 255 | |
| 256 | if (con->write_queue.bfd.fd >= 0) |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 257 | osmo_fd_unregister(&con->write_queue.bfd); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 258 | connection_loss(con); |
| 259 | } |
| 260 | |
| 261 | static void reconnect_msc(void *_msc) |
| 262 | { |
| 263 | struct bsc_msc_connection *con = _msc; |
| 264 | |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 265 | LOGP(DMSC, LOGL_NOTICE, |
| 266 | "Attempting to reconnect to the MSC(%s).\n", con->name); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 267 | bsc_msc_connect(con); |
| 268 | } |
| 269 | |
| 270 | void bsc_msc_schedule_connect(struct bsc_msc_connection *con) |
| 271 | { |
Holger Hans Peter Freyther | 7be0e60 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 272 | LOGP(DMSC, LOGL_NOTICE, |
| 273 | "Attempting to reconnect to the MSC(%s)\n", con->name); |
Holger Hans Peter Freyther | 4a860a0 | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 274 | con->reconnect_timer.cb = reconnect_msc; |
| 275 | con->reconnect_timer.data = con; |
Pablo Neira Ayuso | 840ccf6 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 276 | osmo_timer_schedule(&con->reconnect_timer, 5, 0); |
Holger Hans Peter Freyther | afe60c0 | 2010-06-15 18:52:05 +0800 | [diff] [blame] | 277 | } |
| 278 | |
Holger Hans Peter Freyther | 1f93da7 | 2015-06-08 18:02:10 +0200 | [diff] [blame] | 279 | struct msgb *bsc_msc_id_get_resp(int fixed, const char *token, const uint8_t *res, int len) |
Holger Hans Peter Freyther | afe60c0 | 2010-06-15 18:52:05 +0800 | [diff] [blame] | 280 | { |
| 281 | struct msgb *msg; |
| 282 | |
| 283 | if (!token) { |
| 284 | LOGP(DMSC, LOGL_ERROR, "No token specified.\n"); |
| 285 | return NULL; |
| 286 | } |
| 287 | |
| 288 | msg = msgb_alloc_headroom(4096, 128, "id resp"); |
| 289 | if (!msg) { |
| 290 | LOGP(DMSC, LOGL_ERROR, "Failed to create the message.\n"); |
| 291 | return NULL; |
| 292 | } |
| 293 | |
Holger Hans Peter Freyther | b4b23c7 | 2015-06-10 11:51:16 +0200 | [diff] [blame] | 294 | /* |
| 295 | * The situation is bizarre. The encoding doesn't follow the |
| 296 | * TLV structure. It is more like a LV and old versions had |
| 297 | * it wrong but we want new versions to old servers so we |
| 298 | * introduce the quirk here. |
| 299 | */ |
Holger Hans Peter Freyther | afe60c0 | 2010-06-15 18:52:05 +0800 | [diff] [blame] | 300 | msg->l2h = msgb_v_put(msg, IPAC_MSGT_ID_RESP); |
Holger Hans Peter Freyther | b4b23c7 | 2015-06-10 11:51:16 +0200 | [diff] [blame] | 301 | if (fixed) { |
| 302 | msgb_put_u8(msg, 0); |
| 303 | msgb_put_u8(msg, strlen(token) + 2); |
| 304 | msgb_tv_fixed_put(msg, IPAC_IDTAG_UNITNAME, strlen(token) + 1, (uint8_t *) token); |
Holger Hans Peter Freyther | 1f93da7 | 2015-06-08 18:02:10 +0200 | [diff] [blame] | 305 | if (len > 0) { |
| 306 | msgb_put_u8(msg, 0); |
| 307 | msgb_put_u8(msg, len + 1); |
| 308 | msgb_tv_fixed_put(msg, 0x24, len, res); |
| 309 | } |
Holger Hans Peter Freyther | b4b23c7 | 2015-06-10 11:51:16 +0200 | [diff] [blame] | 310 | } else { |
| 311 | msgb_l16tv_put(msg, strlen(token) + 1, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 312 | IPAC_IDTAG_UNITNAME, (uint8_t *) token); |
Holger Hans Peter Freyther | b4b23c7 | 2015-06-10 11:51:16 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Holger Hans Peter Freyther | afe60c0 | 2010-06-15 18:52:05 +0800 | [diff] [blame] | 315 | return msg; |
Holger Hans Peter Freyther | 8fd9775 | 2010-07-05 14:14:18 +0800 | [diff] [blame] | 316 | } |