Holger Hans Peter Freyther | eef86b5 | 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 | df6143a | 2010-06-15 18:46:56 +0800 | [diff] [blame] | 4 | * (C) 2010 by On-Waves |
Holger Hans Peter Freyther | eef86b5 | 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 | 9af6ddf | 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 | eef86b5 | 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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 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 | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <openbsc/bsc_msc.h> |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 23 | #include <openbsc/debug.h> |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 24 | #include <osmocom/abis/ipaccess.h> |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 25 | |
Pablo Neira Ayuso | 136f453 | 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 | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 28 | |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 29 | #include <osmocom/gsm/tlv.h> |
| 30 | |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 31 | #include <arpa/inet.h> |
| 32 | #include <sys/socket.h> |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 33 | #include <errno.h> |
| 34 | #include <fcntl.h> |
Holger Hans Peter Freyther | eef86b5 | 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 | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 39 | static void connection_loss(struct bsc_msc_connection *con) |
| 40 | { |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 41 | struct osmo_fd *fd; |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 42 | |
| 43 | fd = &con->write_queue.bfd; |
| 44 | |
| 45 | close(fd->fd); |
| 46 | fd->fd = -1; |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 47 | fd->cb = osmo_wqueue_bfd_cb; |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 48 | fd->when = 0; |
| 49 | |
| 50 | con->is_connected = 0; |
Holger Hans Peter Freyther | bec411b | 2010-07-05 14:14:18 +0800 | [diff] [blame] | 51 | con->first_contact = 0; |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 52 | con->connection_loss(con); |
| 53 | } |
| 54 | |
Holger Hans Peter Freyther | e47a91b | 2010-05-05 22:48:56 +0800 | [diff] [blame] | 55 | static void msc_con_timeout(void *_con) |
| 56 | { |
| 57 | struct bsc_msc_connection *con = _con; |
| 58 | |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 59 | LOGP(DMSC, LOGL_ERROR, |
| 60 | "MSC(%s) Connection timeout.\n", con->name); |
Holger Hans Peter Freyther | e47a91b | 2010-05-05 22:48:56 +0800 | [diff] [blame] | 61 | bsc_msc_lost(con); |
| 62 | } |
| 63 | |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 64 | /* called in the case of a non blocking connect */ |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 65 | static int msc_connection_connect(struct osmo_fd *fd, unsigned int what) |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 66 | { |
| 67 | int rc; |
| 68 | int val; |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 69 | struct bsc_msc_connection *con; |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 70 | struct osmo_wqueue *queue; |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 71 | |
| 72 | socklen_t len = sizeof(val); |
| 73 | |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 74 | queue = container_of(fd, struct osmo_wqueue, bfd); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 75 | con = container_of(queue, struct bsc_msc_connection, write_queue); |
| 76 | |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 77 | if ((what & BSC_FD_WRITE) == 0) { |
| 78 | LOGP(DMSC, LOGL_ERROR, |
| 79 | "MSC(%s) Callback but not writable.\n", con->name); |
| 80 | return -1; |
| 81 | } |
| 82 | |
Holger Hans Peter Freyther | d4eed52 | 2010-10-07 04:42:03 +0800 | [diff] [blame] | 83 | /* From here on we will either be connected or reconnect */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 84 | osmo_timer_del(&con->timeout_timer); |
Holger Hans Peter Freyther | d4eed52 | 2010-10-07 04:42:03 +0800 | [diff] [blame] | 85 | |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 86 | /* check the socket state */ |
| 87 | rc = getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, &val, &len); |
| 88 | if (rc != 0) { |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 89 | LOGP(DMSC, LOGL_ERROR, |
| 90 | "getsockopt for the MSC(%s) socket failed.\n", con->name); |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 91 | goto error; |
| 92 | } |
| 93 | if (val != 0) { |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 94 | LOGP(DMSC, LOGL_ERROR, |
| 95 | "Not connected to the MSC(%s): %d\n", |
| 96 | con->name, val); |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 97 | goto error; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /* go to full operation */ |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 102 | fd->cb = osmo_wqueue_bfd_cb; |
Holger Hans Peter Freyther | 0176eb4 | 2010-04-08 11:12:32 +0200 | [diff] [blame] | 103 | fd->when = BSC_FD_READ | BSC_FD_EXCEPT; |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 104 | |
| 105 | con->is_connected = 1; |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 106 | LOGP(DMSC, LOGL_NOTICE, |
| 107 | "(Re)Connected to the MSC(%s).\n", con->name); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 108 | if (con->connected) |
| 109 | con->connected(con); |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 110 | return 0; |
| 111 | |
| 112 | error: |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 113 | osmo_fd_unregister(fd); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 114 | connection_loss(con); |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 115 | return -1; |
| 116 | } |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 117 | static void setnonblocking(struct osmo_fd *fd) |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 118 | { |
| 119 | int flags; |
| 120 | |
| 121 | flags = fcntl(fd->fd, F_GETFL); |
| 122 | if (flags < 0) { |
| 123 | perror("fcntl get failed"); |
| 124 | close(fd->fd); |
| 125 | fd->fd = -1; |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | flags |= O_NONBLOCK; |
| 130 | flags = fcntl(fd->fd, F_SETFL, flags); |
| 131 | if (flags < 0) { |
| 132 | perror("fcntl get failed"); |
| 133 | close(fd->fd); |
| 134 | fd->fd = -1; |
| 135 | return; |
| 136 | } |
| 137 | } |
| 138 | |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 139 | int bsc_msc_connect(struct bsc_msc_connection *con) |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 140 | { |
Holger Hans Peter Freyther | e1880105 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 141 | struct bsc_msc_dest *dest; |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 142 | struct osmo_fd *fd; |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 143 | struct sockaddr_in sin; |
| 144 | int on = 1, ret; |
| 145 | |
Holger Hans Peter Freyther | e1880105 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 146 | if (llist_empty(con->dests)) { |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 147 | LOGP(DMSC, LOGL_ERROR, |
| 148 | "No MSC(%s) connections configured.\n", |
| 149 | con->name); |
Holger Hans Peter Freyther | e1880105 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 150 | connection_loss(con); |
| 151 | return -1; |
| 152 | } |
| 153 | |
| 154 | /* move to the next connection */ |
| 155 | dest = (struct bsc_msc_dest *) con->dests->next; |
| 156 | llist_del(&dest->list); |
| 157 | llist_add_tail(&dest->list, con->dests); |
| 158 | |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 159 | LOGP(DMSC, LOGL_NOTICE, |
| 160 | "Attempting to connect MSC(%s) at %s:%d\n", |
| 161 | con->name, dest->ip, dest->port); |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 162 | |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 163 | con->is_connected = 0; |
| 164 | |
| 165 | fd = &con->write_queue.bfd; |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 166 | fd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 167 | fd->priv_nr = 1; |
| 168 | |
| 169 | if (fd->fd < 0) { |
| 170 | perror("Creating TCP socket failed"); |
| 171 | return fd->fd; |
| 172 | } |
| 173 | |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 174 | /* make it non blocking */ |
| 175 | setnonblocking(fd); |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 176 | |
Holger Hans Peter Freyther | ca999a9 | 2010-06-15 18:52:38 +0800 | [diff] [blame] | 177 | /* set the socket priority */ |
| 178 | ret = setsockopt(fd->fd, IPPROTO_IP, IP_TOS, |
Holger Hans Peter Freyther | e1880105 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 179 | &dest->dscp, sizeof(dest->dscp)); |
Holger Hans Peter Freyther | ca999a9 | 2010-06-15 18:52:38 +0800 | [diff] [blame] | 180 | if (ret != 0) |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 181 | LOGP(DMSC, LOGL_ERROR, |
| 182 | "Failed to set DSCP to %d on MSC(%s). %s\n", |
| 183 | dest->dscp, con->name, strerror(errno)); |
Holger Hans Peter Freyther | ca999a9 | 2010-06-15 18:52:38 +0800 | [diff] [blame] | 184 | |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 185 | memset(&sin, 0, sizeof(sin)); |
| 186 | sin.sin_family = AF_INET; |
Holger Hans Peter Freyther | e1880105 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 187 | sin.sin_port = htons(dest->port); |
| 188 | inet_aton(dest->ip, &sin.sin_addr); |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 189 | |
| 190 | setsockopt(fd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
| 191 | ret = connect(fd->fd, (struct sockaddr *) &sin, sizeof(sin)); |
| 192 | |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 193 | if (ret == -1 && errno == EINPROGRESS) { |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 194 | LOGP(DMSC, LOGL_ERROR, |
| 195 | "MSC(%s) Connection in progress\n", con->name); |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 196 | fd->when = BSC_FD_WRITE; |
| 197 | fd->cb = msc_connection_connect; |
Holger Hans Peter Freyther | e47a91b | 2010-05-05 22:48:56 +0800 | [diff] [blame] | 198 | con->timeout_timer.cb = msc_con_timeout; |
| 199 | con->timeout_timer.data = con; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 200 | osmo_timer_schedule(&con->timeout_timer, 20, 0); |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 201 | } else if (ret < 0) { |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 202 | perror("Connection failed"); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 203 | connection_loss(con); |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 204 | return ret; |
Holger Hans Peter Freyther | 6c0a04e | 2010-03-26 10:41:20 +0100 | [diff] [blame] | 205 | } else { |
Holger Hans Peter Freyther | 0176eb4 | 2010-04-08 11:12:32 +0200 | [diff] [blame] | 206 | fd->when = BSC_FD_READ | BSC_FD_EXCEPT; |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 207 | fd->cb = osmo_wqueue_bfd_cb; |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 208 | con->is_connected = 1; |
| 209 | if (con->connected) |
| 210 | con->connected(con); |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 211 | } |
| 212 | |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 213 | ret = osmo_fd_register(fd); |
Holger Hans Peter Freyther | eef86b5 | 2010-06-15 18:45:06 +0800 | [diff] [blame] | 214 | if (ret < 0) { |
| 215 | perror("Registering the fd failed"); |
| 216 | close(fd->fd); |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | return ret; |
| 221 | } |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 222 | |
Holger Hans Peter Freyther | e1880105 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 223 | struct bsc_msc_connection *bsc_msc_create(void *ctx, struct llist_head *dests) |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 224 | { |
| 225 | struct bsc_msc_connection *con; |
| 226 | |
| 227 | con = talloc_zero(NULL, struct bsc_msc_connection); |
| 228 | if (!con) { |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 229 | LOGP(DMSC, LOGL_FATAL, |
| 230 | "Failed to create the MSC(%s) connection.\n", |
| 231 | con->name); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 232 | return NULL; |
| 233 | } |
| 234 | |
Holger Hans Peter Freyther | e1880105 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 235 | con->dests = dests; |
| 236 | con->write_queue.bfd.fd = -1; |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 237 | con->name = ""; |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 238 | osmo_wqueue_init(&con->write_queue, 100); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 239 | return con; |
| 240 | } |
| 241 | |
| 242 | void bsc_msc_lost(struct bsc_msc_connection *con) |
| 243 | { |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 244 | osmo_wqueue_clear(&con->write_queue); |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 245 | osmo_timer_del(&con->timeout_timer); |
Holger Hans Peter Freyther | 33eb587 | 2013-09-03 14:21:48 +0200 | [diff] [blame] | 246 | osmo_timer_del(&con->reconnect_timer); |
Holger Hans Peter Freyther | fad0753 | 2010-10-07 06:07:57 +0800 | [diff] [blame] | 247 | |
| 248 | if (con->write_queue.bfd.fd >= 0) |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 249 | osmo_fd_unregister(&con->write_queue.bfd); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 250 | connection_loss(con); |
| 251 | } |
| 252 | |
| 253 | static void reconnect_msc(void *_msc) |
| 254 | { |
| 255 | struct bsc_msc_connection *con = _msc; |
| 256 | |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 257 | LOGP(DMSC, LOGL_NOTICE, |
| 258 | "Attempting to reconnect to the MSC(%s).\n", con->name); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 259 | bsc_msc_connect(con); |
| 260 | } |
| 261 | |
| 262 | void bsc_msc_schedule_connect(struct bsc_msc_connection *con) |
| 263 | { |
Holger Hans Peter Freyther | c1a8687 | 2013-09-02 13:07:45 +0200 | [diff] [blame] | 264 | LOGP(DMSC, LOGL_NOTICE, |
| 265 | "Attempting to reconnect to the MSC(%s)\n", con->name); |
Holger Hans Peter Freyther | baf2abe | 2010-06-15 18:47:29 +0800 | [diff] [blame] | 266 | con->reconnect_timer.cb = reconnect_msc; |
| 267 | con->reconnect_timer.data = con; |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 268 | osmo_timer_schedule(&con->reconnect_timer, 5, 0); |
Holger Hans Peter Freyther | f76e7ef | 2010-06-15 18:52:05 +0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | struct msgb *bsc_msc_id_get_resp(const char *token) |
| 272 | { |
| 273 | struct msgb *msg; |
| 274 | |
| 275 | if (!token) { |
| 276 | LOGP(DMSC, LOGL_ERROR, "No token specified.\n"); |
| 277 | return NULL; |
| 278 | } |
| 279 | |
| 280 | msg = msgb_alloc_headroom(4096, 128, "id resp"); |
| 281 | if (!msg) { |
| 282 | LOGP(DMSC, LOGL_ERROR, "Failed to create the message.\n"); |
| 283 | return NULL; |
| 284 | } |
| 285 | |
| 286 | msg->l2h = msgb_v_put(msg, IPAC_MSGT_ID_RESP); |
| 287 | msgb_l16tv_put(msg, strlen(token) + 1, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 288 | IPAC_IDTAG_UNITNAME, (uint8_t *) token); |
Holger Hans Peter Freyther | f76e7ef | 2010-06-15 18:52:05 +0800 | [diff] [blame] | 289 | return msg; |
Holger Hans Peter Freyther | bec411b | 2010-07-05 14:14:18 +0800 | [diff] [blame] | 290 | } |