Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1 | /* OpenBSC Abis input driver for ip.access */ |
| 2 | |
| 3 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2010 by Holger Hans Peter Freyther |
| 5 | * (C) 2010 by On-Waves |
| 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
Harald Welte | 323d39d | 2017-11-13 01:09:21 +0900 | [diff] [blame] | 9 | * SPDX-License-Identifier: AGPL-3.0+ |
| 10 | * |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU Affero General Public License as published by |
| 13 | * the Free Software Foundation; either version 3 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU Affero General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Affero General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include "internal.h" |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <unistd.h> |
| 30 | #include <stdlib.h> |
Pablo Neira Ayuso | eb43413 | 2011-07-07 19:19:46 +0200 | [diff] [blame] | 31 | #include <stdbool.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 32 | #include <errno.h> |
Daniel Willmann | 8598072 | 2014-01-09 14:30:55 +0100 | [diff] [blame] | 33 | #include <netinet/tcp.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 34 | #include <string.h> |
| 35 | #include <time.h> |
Holger Hans Peter Freyther | 2547458 | 2017-01-23 19:49:07 +0100 | [diff] [blame] | 36 | #include <fcntl.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 37 | #include <sys/socket.h> |
| 38 | #include <sys/ioctl.h> |
| 39 | #include <arpa/inet.h> |
| 40 | |
| 41 | #include <osmocom/core/select.h> |
| 42 | #include <osmocom/gsm/tlv.h> |
| 43 | #include <osmocom/core/msgb.h> |
Harald Welte | f5efba4 | 2014-08-18 17:30:36 +0200 | [diff] [blame] | 44 | #include <osmocom/core/macaddr.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 45 | #include <osmocom/core/logging.h> |
Harald Welte | 71d87b2 | 2011-07-18 14:49:56 +0200 | [diff] [blame] | 46 | #include <osmocom/core/talloc.h> |
Pablo Neira Ayuso | 177094b | 2011-06-07 12:21:51 +0200 | [diff] [blame] | 47 | #include <osmocom/abis/e1_input.h> |
| 48 | #include <osmocom/abis/ipaccess.h> |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 49 | #include <osmocom/core/socket.h> |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 50 | #include <osmocom/abis/ipa.h> |
Pablo Neira Ayuso | ef13269 | 2013-07-08 01:17:27 +0200 | [diff] [blame] | 51 | #include <osmocom/core/backtrace.h> |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 52 | #include <osmocom/gsm/ipa.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 53 | |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 54 | static void *tall_ipa_ctx; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 55 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 56 | #define TS1_ALLOC_SIZE 900 |
| 57 | |
Daniel Willmann | 8598072 | 2014-01-09 14:30:55 +0100 | [diff] [blame] | 58 | #define DEFAULT_TCP_KEEPALIVE_IDLE_TIMEOUT 30 |
| 59 | #define DEFAULT_TCP_KEEPALIVE_INTERVAL 3 |
| 60 | #define DEFAULT_TCP_KEEPALIVE_RETRY_COUNT 10 |
| 61 | |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 62 | static inline struct e1inp_ts *ipaccess_line_ts(struct osmo_fd *bfd, struct e1inp_line *line) |
| 63 | { |
| 64 | if (bfd->priv_nr == E1INP_SIGN_OML) |
| 65 | return e1inp_line_ipa_oml_ts(line); |
| 66 | else |
| 67 | return e1inp_line_ipa_rsl_ts(line, bfd->priv_nr - E1INP_SIGN_RSL); |
| 68 | } |
| 69 | |
| 70 | static inline void ipaccess_keepalive_fsm_cleanup(struct e1inp_ts *e1i_ts) |
| 71 | { |
| 72 | struct osmo_fsm_inst *ka_fsm; |
| 73 | |
| 74 | ka_fsm = e1i_ts->driver.ipaccess.ka_fsm; |
| 75 | if (ka_fsm) { |
| 76 | ipa_keepalive_fsm_stop(ka_fsm); |
| 77 | e1i_ts->driver.ipaccess.ka_fsm = NULL; |
| 78 | } |
| 79 | } |
| 80 | |
Harald Welte | 10b4130 | 2013-06-30 14:05:49 +0200 | [diff] [blame] | 81 | static int ipaccess_drop(struct osmo_fd *bfd, struct e1inp_line *line) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 82 | { |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 83 | int ret = 1; |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 84 | struct e1inp_ts *e1i_ts = ipaccess_line_ts(bfd, line); |
Pau Espin Pedrol | deb5c4f | 2020-07-31 12:55:01 +0200 | [diff] [blame] | 85 | e1inp_line_get2(line, __func__); |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 86 | |
| 87 | ipaccess_keepalive_fsm_cleanup(e1i_ts); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 88 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 89 | /* Error case: we did not see any ID_RESP yet for this socket. */ |
| 90 | if (bfd->fd != -1) { |
Pau Espin Pedrol | 91314c1 | 2020-11-23 14:45:03 +0100 | [diff] [blame] | 91 | LOGPITS(e1i_ts, DLINP, LOGL_NOTICE, "Forcing socket shutdown\n"); |
Pablo Neira Ayuso | 9621b41 | 2011-07-07 16:19:21 +0200 | [diff] [blame] | 92 | osmo_fd_unregister(bfd); |
| 93 | close(bfd->fd); |
| 94 | bfd->fd = -1; |
Pau Espin Pedrol | 9af069d | 2020-11-23 14:54:00 +0100 | [diff] [blame] | 95 | switch (line->ops->cfg.ipa.role) { |
| 96 | case E1INP_LINE_R_BSC: |
| 97 | /* This is BSC code, ipaccess_drop() is only called for |
| 98 | accepted() sockets, hence the bfd holds a reference to |
| 99 | e1inp_line in ->data that needs to be released */ |
| 100 | OSMO_ASSERT(bfd->data == line); |
| 101 | bfd->data = NULL; |
| 102 | e1inp_line_put2(line, "ipa_bfd"); |
| 103 | break; |
| 104 | case E1INP_LINE_R_BTS: |
| 105 | /* BTS code: bfd->data contains pointer to struct |
| 106 | * ipa_client_conn. Leave it alive so it reconnects. |
| 107 | */ |
| 108 | break; |
| 109 | default: |
| 110 | break; |
| 111 | } |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 112 | ret = -ENOENT; |
Pau Espin Pedrol | 91314c1 | 2020-11-23 14:45:03 +0100 | [diff] [blame] | 113 | } else { |
| 114 | LOGPITS(e1i_ts, DLINP, LOGL_ERROR, |
| 115 | "Forcing socket shutdown with no signal link set\n"); |
Pablo Neira Ayuso | 9621b41 | 2011-07-07 16:19:21 +0200 | [diff] [blame] | 116 | } |
Pablo Neira Ayuso | 6cc3f92 | 2012-08-22 13:57:58 +0200 | [diff] [blame] | 117 | |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 118 | msgb_free(e1i_ts->pending_msg); |
| 119 | e1i_ts->pending_msg = NULL; |
| 120 | |
Pablo Neira Ayuso | 6cc3f92 | 2012-08-22 13:57:58 +0200 | [diff] [blame] | 121 | /* e1inp_sign_link_destroy releases the socket descriptors for us. */ |
| 122 | line->ops->sign_link_down(line); |
| 123 | |
Pau Espin Pedrol | deb5c4f | 2020-07-31 12:55:01 +0200 | [diff] [blame] | 124 | e1inp_line_put2(line, __func__); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 125 | return ret; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 128 | static void ipa_bsc_keepalive_write_server_cb(struct osmo_fsm_inst *fi, void *conn, struct msgb *msg) |
| 129 | { |
| 130 | struct osmo_fd *bfd = (struct osmo_fd *)conn; |
| 131 | write(bfd->fd, msg->data, msg->len); |
| 132 | msgb_free(msg); |
| 133 | } |
| 134 | |
| 135 | static int ipa_bsc_keepalive_timeout_cb(struct osmo_fsm_inst *fi, void *data) |
| 136 | { |
| 137 | struct osmo_fd *bfd = (struct osmo_fd *)data; |
| 138 | |
| 139 | if (bfd->fd == -1) |
| 140 | return 1; |
| 141 | |
| 142 | ipaccess_drop(bfd, (struct e1inp_line *)bfd->data); |
| 143 | return 1; |
| 144 | } |
| 145 | |
| 146 | static void ipaccess_bsc_keepalive_fsm_alloc(struct e1inp_ts *e1i_ts, struct osmo_fd *bfd, const char *id) |
| 147 | { |
| 148 | struct e1inp_line *line = e1i_ts->line; |
| 149 | struct osmo_fsm_inst *ka_fsm; |
| 150 | |
| 151 | ipaccess_keepalive_fsm_cleanup(e1i_ts); |
| 152 | if (!line->ipa_kap) |
| 153 | return; |
| 154 | |
| 155 | ka_fsm = ipa_generic_conn_alloc_keepalive_fsm(tall_ipa_ctx, bfd, line->ipa_kap, id); |
| 156 | e1i_ts->driver.ipaccess.ka_fsm = ka_fsm; |
| 157 | if (!ka_fsm) |
| 158 | return; |
| 159 | |
| 160 | ipa_keepalive_fsm_set_timeout_cb(ka_fsm, ipa_bsc_keepalive_timeout_cb); |
| 161 | ipa_keepalive_fsm_set_send_cb(ka_fsm, ipa_bsc_keepalive_write_server_cb); |
| 162 | ipa_keepalive_fsm_start(ka_fsm); |
| 163 | } |
| 164 | |
| 165 | static void ipa_bts_keepalive_write_client_cb(struct osmo_fsm_inst *fi, void *conn, struct msgb *msg) { |
| 166 | struct ipa_client_conn *link = (struct ipa_client_conn *)conn; |
| 167 | int ret = 0; |
| 168 | |
| 169 | ret = ipa_send(link->ofd->fd, msg->data, msg->len); |
| 170 | if (ret != msg->len) { |
| 171 | LOGP(DLINP, LOGL_ERROR, "cannot send message. Reason: %s\n", strerror(errno)); |
| 172 | } |
| 173 | msgb_free(msg); |
| 174 | } |
| 175 | |
| 176 | static void update_fd_settings(struct e1inp_line *line, int fd); |
| 177 | static void ipaccess_bts_updown_cb(struct ipa_client_conn *link, int up); |
| 178 | |
| 179 | static int ipa_bts_keepalive_timeout_cb(struct osmo_fsm_inst *fi, void *conn) { |
| 180 | ipaccess_bts_updown_cb(conn, false); |
| 181 | return 1; |
| 182 | } |
| 183 | |
| 184 | static void ipaccess_bts_keepalive_fsm_alloc(struct e1inp_ts *e1i_ts, struct ipa_client_conn *client, const char *id) |
| 185 | { |
| 186 | struct e1inp_line *line = e1i_ts->line; |
| 187 | struct osmo_fsm_inst *ka_fsm; |
| 188 | |
| 189 | ipaccess_keepalive_fsm_cleanup(e1i_ts); |
| 190 | if (!line->ipa_kap) |
| 191 | return; |
| 192 | |
| 193 | ka_fsm = ipa_client_conn_alloc_keepalive_fsm(client, line->ipa_kap, id); |
| 194 | e1i_ts->driver.ipaccess.ka_fsm = ka_fsm; |
| 195 | if (!ka_fsm) |
| 196 | return; |
| 197 | |
| 198 | ipa_keepalive_fsm_set_timeout_cb(ka_fsm, ipa_bts_keepalive_timeout_cb); |
| 199 | ipa_keepalive_fsm_set_send_cb(ka_fsm, ipa_bts_keepalive_write_client_cb); |
| 200 | } |
| 201 | |
Pau Espin Pedrol | 7edc25d | 2018-05-23 14:57:03 +0200 | [diff] [blame] | 202 | /* Returns -1 on error, and 0 or 1 on success. If -1 or 1 is returned, line has |
| 203 | * been released and should not be used anymore by the caller. */ |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 204 | static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, |
| 205 | struct osmo_fd *bfd) |
| 206 | { |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 207 | struct tlv_parsed tlvp; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 208 | uint8_t msg_type = *(msg->l2h); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 209 | struct ipaccess_unit unit_data = {}; |
| 210 | struct e1inp_sign_link *sign_link; |
| 211 | char *unitid; |
| 212 | int len, ret; |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 213 | struct e1inp_ts *e1i_ts; |
| 214 | struct osmo_fsm_inst *ka_fsm; |
| 215 | |
| 216 | /* peek the pong for our keepalive fsm */ |
| 217 | e1i_ts = ipaccess_line_ts(bfd, line); |
| 218 | ka_fsm = e1i_ts->driver.ipaccess.ka_fsm; |
| 219 | if (ka_fsm && msg_type == IPAC_MSGT_PONG) |
| 220 | ipa_keepalive_fsm_pong_received(ka_fsm); |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 221 | |
Pablo Neira Ayuso | eb43413 | 2011-07-07 19:19:46 +0200 | [diff] [blame] | 222 | /* Handle IPA PING, PONG and ID_ACK messages. */ |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 223 | ret = ipa_ccm_rcvmsg_base(msg, bfd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 224 | switch(ret) { |
| 225 | case -1: |
| 226 | /* error in IPA control message handling */ |
| 227 | goto err; |
| 228 | case 1: |
| 229 | /* this is an IPA control message, skip further processing */ |
Pablo Neira Ayuso | eb43413 | 2011-07-07 19:19:46 +0200 | [diff] [blame] | 230 | return 0; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 231 | case 0: |
| 232 | /* this is not an IPA control message, continue */ |
| 233 | break; |
| 234 | default: |
| 235 | LOGP(DLINP, LOGL_ERROR, "Unexpected return from " |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 236 | "ipa_ccm_rcvmsg_base " |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 237 | "(ret=%d)\n", ret); |
| 238 | goto err; |
| 239 | } |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 240 | |
| 241 | switch (msg_type) { |
| 242 | case IPAC_MSGT_ID_RESP: |
Pau Espin Pedrol | 30e80d5 | 2020-07-14 13:23:05 +0200 | [diff] [blame] | 243 | DEBUGP(DLMI, "ID_RESP "); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 244 | /* parse tags, search for Unit ID */ |
Harald Welte | 82eb55e | 2018-08-01 13:22:55 +0200 | [diff] [blame] | 245 | ret = ipa_ccm_id_resp_parse(&tlvp, (const uint8_t *)msg->l2h+1, msgb_l2len(msg)-1); |
Pau Espin Pedrol | 30e80d5 | 2020-07-14 13:23:05 +0200 | [diff] [blame] | 246 | DEBUGPC(DLMI, "\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 247 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 248 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 249 | "with malformed TLVs\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 250 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 251 | } |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 252 | if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT)) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 253 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 254 | "without unit ID\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 255 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 256 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 257 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 258 | len = TLVP_LEN(&tlvp, IPAC_IDTAG_UNIT); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 259 | if (len < 1) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 260 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 261 | "with too small unit ID\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 262 | goto err; |
| 263 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 264 | unitid = (char *) TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT); |
| 265 | unitid[len - 1] = '\0'; |
Vadim Yanitskiy | 1c94f6a | 2019-12-02 02:16:07 +0700 | [diff] [blame] | 266 | ret = ipa_parse_unitid(unitid, &unit_data); |
| 267 | if (ret) { |
| 268 | LOGP(DLINP, LOGL_ERROR, "Failed to parse unit ID '%s'\n", unitid); |
| 269 | goto err; |
| 270 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 271 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 272 | if (!line->ops->sign_link_up) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 273 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 274 | "Unable to set signal link, closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 275 | goto err; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 276 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 277 | /* the BSC creates the new sign links at this stage. */ |
| 278 | if (bfd->priv_nr == E1INP_SIGN_OML) { |
| 279 | sign_link = |
| 280 | line->ops->sign_link_up(&unit_data, line, |
| 281 | E1INP_SIGN_OML); |
| 282 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 283 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 284 | "Unable to set signal link, " |
| 285 | "closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 286 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 287 | } |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 288 | |
| 289 | ipaccess_bsc_keepalive_fsm_alloc(e1i_ts, bfd, "oml_bsc_to_bts"); |
| 290 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 291 | } else if (bfd->priv_nr == E1INP_SIGN_RSL) { |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 292 | struct e1inp_ts *ts; |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 293 | struct osmo_fd *newbfd; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 294 | struct e1inp_line *new_line; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 295 | |
| 296 | sign_link = |
| 297 | line->ops->sign_link_up(&unit_data, line, |
| 298 | E1INP_SIGN_RSL); |
| 299 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 300 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 301 | "Unable to set signal link, " |
| 302 | "closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 303 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 304 | } |
Pau Espin Pedrol | 8a4e3d9 | 2020-07-14 21:20:55 +0200 | [diff] [blame] | 305 | /* Finally, we know which OML link is associated with |
| 306 | * this RSL link, attach it to this socket. */ |
| 307 | new_line = sign_link->ts->line; |
Pablo Neira Ayuso | db1c8a7 | 2011-07-08 15:12:03 +0200 | [diff] [blame] | 308 | /* this is a bugtrap, the BSC should be using the |
| 309 | * virtual E1 line used by OML for this RSL link. */ |
Pau Espin Pedrol | 8a4e3d9 | 2020-07-14 21:20:55 +0200 | [diff] [blame] | 310 | if (new_line == line) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 311 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | db1c8a7 | 2011-07-08 15:12:03 +0200 | [diff] [blame] | 312 | "Fix your BSC, you should use the " |
| 313 | "E1 line used by the OML link for " |
| 314 | "your RSL link.\n"); |
| 315 | return 0; |
| 316 | } |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 317 | e1inp_line_get2(new_line, "ipa_bfd"); |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 318 | ts = e1inp_line_ipa_rsl_ts(new_line, unit_data.trx_id); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 319 | newbfd = &ts->driver.ipaccess.fd; |
Pau Espin Pedrol | 815117c | 2020-07-14 21:19:16 +0200 | [diff] [blame] | 320 | OSMO_ASSERT(newbfd != bfd); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 321 | |
Pau Espin Pedrol | 56ae85f | 2018-08-22 13:11:19 +0200 | [diff] [blame] | 322 | /* preserve 'newbfd->when' flags potentially set by sign_link_up() */ |
Pau Espin Pedrol | 67902bb | 2018-08-23 14:35:08 +0200 | [diff] [blame] | 323 | osmo_fd_setup(newbfd, bfd->fd, newbfd->when | bfd->when, bfd->cb, |
Pau Espin Pedrol | 8a4e3d9 | 2020-07-14 21:20:55 +0200 | [diff] [blame] | 324 | new_line, E1INP_SIGN_RSL + unit_data.trx_id); |
| 325 | |
| 326 | |
| 327 | /* now we can release the dummy RSL line (old temporary bfd). */ |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 328 | osmo_fd_unregister(bfd); |
| 329 | bfd->fd = -1; |
Pau Espin Pedrol | 8a4e3d9 | 2020-07-14 21:20:55 +0200 | [diff] [blame] | 330 | /* bfd->data holds a reference to line, drop it */ |
| 331 | OSMO_ASSERT(bfd->data == line); |
| 332 | bfd->data = NULL; |
| 333 | e1inp_line_put2(line, "ipa_bfd"); |
| 334 | |
Harald Welte | ae3a993 | 2016-11-26 09:25:23 +0100 | [diff] [blame] | 335 | ret = osmo_fd_register(newbfd); |
| 336 | if (ret < 0) { |
| 337 | LOGP(DLINP, LOGL_ERROR, |
| 338 | "could not register FD\n"); |
| 339 | goto err; |
| 340 | } |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 341 | |
| 342 | e1i_ts = ipaccess_line_ts(newbfd, new_line); |
| 343 | ipaccess_bsc_keepalive_fsm_alloc(e1i_ts, newbfd, "rsl_bsc_to_bts"); |
Pau Espin Pedrol | 7edc25d | 2018-05-23 14:57:03 +0200 | [diff] [blame] | 344 | return 1; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 345 | } |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 346 | break; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 347 | default: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 348 | LOGP(DLINP, LOGL_ERROR, "Unknown IPA message type\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 349 | goto err; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 350 | } |
| 351 | return 0; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 352 | err: |
Harald Welte | b4a7db0 | 2019-07-21 11:51:56 +0200 | [diff] [blame] | 353 | if (bfd->fd != -1) { |
Pau Espin Pedrol | dc55a5f | 2020-07-14 21:14:34 +0200 | [diff] [blame] | 354 | osmo_fd_unregister(bfd); |
Harald Welte | b4a7db0 | 2019-07-21 11:51:56 +0200 | [diff] [blame] | 355 | close(bfd->fd); |
| 356 | bfd->fd = -1; |
Pau Espin Pedrol | dc55a5f | 2020-07-14 21:14:34 +0200 | [diff] [blame] | 357 | /* This is a BSC accepted socket, bfd->data holds a reference to line, drop it */ |
| 358 | OSMO_ASSERT(bfd->data == line); |
| 359 | bfd->data = NULL; |
| 360 | e1inp_line_put2(line, "ipa_bfd"); |
Harald Welte | b4a7db0 | 2019-07-21 11:51:56 +0200 | [diff] [blame] | 361 | } |
Pau Espin Pedrol | 7edc25d | 2018-05-23 14:57:03 +0200 | [diff] [blame] | 362 | return -1; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 363 | } |
| 364 | |
Pau Espin Pedrol | 7edc25d | 2018-05-23 14:57:03 +0200 | [diff] [blame] | 365 | /* Returns -EBADF if bfd cannot be used by the caller anymore after return. */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 366 | static int handle_ts1_read(struct osmo_fd *bfd) |
| 367 | { |
| 368 | struct e1inp_line *line = bfd->data; |
| 369 | unsigned int ts_nr = bfd->priv_nr; |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 370 | struct e1inp_ts *e1i_ts; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 371 | struct e1inp_sign_link *link; |
| 372 | struct ipaccess_head *hh; |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 373 | struct msgb *msg = NULL; |
Max | c9fa25e | 2017-01-09 13:23:15 +0100 | [diff] [blame] | 374 | int ret, rc; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 375 | |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 376 | e1i_ts = ipaccess_line_ts(bfd, line); |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 377 | ret = ipa_msg_recv_buffered(bfd->fd, &msg, &e1i_ts->pending_msg); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 378 | if (ret < 0) { |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 379 | if (ret == -EAGAIN) |
| 380 | return 0; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 381 | LOGP(DLINP, LOGL_NOTICE, "Sign link problems, " |
Jacob Erlbeck | 98af3c3 | 2014-03-31 10:53:32 +0200 | [diff] [blame] | 382 | "closing socket. Reason: %s\n", strerror(-ret)); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 383 | goto err; |
| 384 | } else if (ret == 0) { |
| 385 | LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, dead socket\n"); |
| 386 | goto err; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 387 | } |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 388 | DEBUGP(DLMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 389 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 390 | hh = (struct ipaccess_head *) msg->data; |
| 391 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
Pau Espin Pedrol | 7edc25d | 2018-05-23 14:57:03 +0200 | [diff] [blame] | 392 | ret = ipaccess_rcvmsg(line, msg, bfd); |
| 393 | /* BIG FAT WARNING: bfd might no longer exist here (ret != 0), |
| 394 | * since ipaccess_rcvmsg() might have free'd it !!! */ |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 395 | msgb_free(msg); |
Pau Espin Pedrol | 7edc25d | 2018-05-23 14:57:03 +0200 | [diff] [blame] | 396 | return ret != 0 ? -EBADF : 0; |
Holger Hans Peter Freyther | 63ddf46 | 2013-12-28 21:19:19 +0100 | [diff] [blame] | 397 | } else if (e1i_ts->type == E1INP_TS_TYPE_NONE) { |
| 398 | /* this sign link is not know yet.. complain. */ |
| 399 | LOGP(DLINP, LOGL_ERROR, "Timeslot is not configured.\n"); |
Holger Hans Peter Freyther | 63ddf46 | 2013-12-28 21:19:19 +0100 | [diff] [blame] | 400 | goto err_msg; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 401 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 402 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 403 | link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 404 | if (!link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 405 | LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 406 | "hh->proto=0x%02x\n", hh->proto); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 407 | goto err_msg; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 408 | } |
| 409 | msg->dst = link; |
| 410 | |
| 411 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 412 | if (!e1i_ts->line->ops->sign_link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 413 | LOGP(DLINP, LOGL_ERROR, "Fix your application, " |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 414 | "no action set for signalling messages.\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 415 | goto err_msg; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 416 | } |
Max | c9fa25e | 2017-01-09 13:23:15 +0100 | [diff] [blame] | 417 | rc = e1i_ts->line->ops->sign_link(msg); |
| 418 | if (rc < 0) { |
Pablo Neira Ayuso | a49c24d | 2012-10-16 11:24:08 +0200 | [diff] [blame] | 419 | /* Don't close the signalling link if the upper layers report |
| 420 | * an error, that's too strict. BTW, the signalling layer is |
| 421 | * resposible for releasing the message. |
| 422 | */ |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 423 | LOGP(DLINP, LOGL_ERROR, "Bad signalling message," |
Max | c9fa25e | 2017-01-09 13:23:15 +0100 | [diff] [blame] | 424 | " sign_link returned error: %s.\n", strerror(-rc)); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 425 | } |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 426 | |
Pau Espin Pedrol | ed122f3 | 2018-08-28 18:25:02 +0200 | [diff] [blame] | 427 | return rc; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 428 | err_msg: |
| 429 | msgb_free(msg); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 430 | err: |
Harald Welte | 10b4130 | 2013-06-30 14:05:49 +0200 | [diff] [blame] | 431 | ipaccess_drop(bfd, line); |
Pau Espin Pedrol | 7edc25d | 2018-05-23 14:57:03 +0200 | [diff] [blame] | 432 | return -EBADF; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 435 | static int ts_want_write(struct e1inp_ts *e1i_ts) |
| 436 | { |
Harald Welte | 949b8a2 | 2020-10-18 23:01:53 +0200 | [diff] [blame] | 437 | osmo_fd_write_enable(&e1i_ts->driver.ipaccess.fd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
Pablo Neira Ayuso | add3ec8 | 2011-07-05 14:45:46 +0200 | [diff] [blame] | 442 | static void ipaccess_close(struct e1inp_sign_link *sign_link) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 443 | { |
Pablo Neira Ayuso | add3ec8 | 2011-07-05 14:45:46 +0200 | [diff] [blame] | 444 | struct e1inp_ts *e1i_ts = sign_link->ts; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 445 | struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd; |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 446 | struct e1inp_line *line = e1i_ts->line; |
| 447 | |
| 448 | /* line might not exist if != bsc||bts */ |
| 449 | if (line) { |
| 450 | /* depending on caller the fsm might be dead */ |
| 451 | struct osmo_fsm_inst* ka_fsm = ipaccess_line_ts(bfd, line)->driver.ipaccess.ka_fsm; |
| 452 | if (ka_fsm) |
| 453 | ipa_keepalive_fsm_stop(ka_fsm); |
| 454 | |
| 455 | } |
| 456 | |
Pau Espin Pedrol | 8737ad4 | 2020-07-14 21:11:56 +0200 | [diff] [blame] | 457 | e1inp_int_snd_event(e1i_ts, sign_link, S_L_INP_TEI_DN); |
| 458 | /* the first e1inp_sign_link_destroy call closes the socket. */ |
| 459 | if (bfd->fd != -1) { |
| 460 | osmo_fd_unregister(bfd); |
| 461 | close(bfd->fd); |
| 462 | bfd->fd = -1; |
| 463 | /* If The bfd holds a reference to e1inp_line in ->data (BSC |
| 464 | * accepted() sockets), then release it */ |
| 465 | if (bfd->data == line) { |
| 466 | bfd->data = NULL; |
| 467 | e1inp_line_put2(line, "ipa_bfd"); |
| 468 | } |
| 469 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 470 | } |
| 471 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 472 | static void timeout_ts1_write(void *data) |
| 473 | { |
| 474 | struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data; |
| 475 | |
| 476 | /* trigger write of ts1, due to tx delay timer */ |
| 477 | ts_want_write(e1i_ts); |
| 478 | } |
| 479 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 480 | static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 481 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 482 | unsigned int ts_nr = bfd->priv_nr; |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 483 | struct e1inp_ts *e1i_ts; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 484 | struct e1inp_sign_link *sign_link; |
| 485 | struct msgb *msg; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 486 | int ret; |
| 487 | |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 488 | e1i_ts = ipaccess_line_ts(bfd, line); |
Harald Welte | 949b8a2 | 2020-10-18 23:01:53 +0200 | [diff] [blame] | 489 | osmo_fd_write_disable(bfd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 490 | |
| 491 | /* get the next msg for this timeslot */ |
| 492 | msg = e1inp_tx_ts(e1i_ts, &sign_link); |
| 493 | if (!msg) { |
| 494 | /* no message after tx delay timer */ |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | switch (sign_link->type) { |
| 499 | case E1INP_SIGN_OML: |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 500 | case E1INP_SIGN_RSL: |
Harald Welte | 46fc7e2 | 2014-08-18 19:04:26 +0200 | [diff] [blame] | 501 | case E1INP_SIGN_OSMO: |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 502 | break; |
| 503 | default: |
Harald Welte | 949b8a2 | 2020-10-18 23:01:53 +0200 | [diff] [blame] | 504 | osmo_fd_write_enable(bfd); /* come back for more msg */ |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 505 | ret = -EINVAL; |
| 506 | goto out; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | msg->l2h = msg->data; |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 510 | ipa_prepend_header(msg, sign_link->tei); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 511 | |
Vadim Yanitskiy | 77a7cf4 | 2020-11-29 20:39:57 +0100 | [diff] [blame] | 512 | LOGPITS(e1i_ts, DLMI, LOGL_DEBUG, "TX %u: %s\n", ts_nr, |
Pau Espin Pedrol | 3bdf59b | 2020-11-23 13:47:16 +0100 | [diff] [blame] | 513 | osmo_hexdump(msg->l2h, msgb_l2len(msg))); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 514 | |
| 515 | ret = send(bfd->fd, msg->data, msg->len, 0); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 516 | if (ret != msg->len) { |
Pau Espin Pedrol | 3bdf59b | 2020-11-23 13:47:16 +0100 | [diff] [blame] | 517 | LOGPITS(e1i_ts, DLINP, LOGL_ERROR, "failed to send A-bis IPA signalling " |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 518 | "message. Reason: %s\n", strerror(errno)); |
| 519 | goto err; |
| 520 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 521 | |
| 522 | /* set tx delay timer for next event */ |
Pablo Neira Ayuso | b26f2fd | 2017-06-07 18:32:13 +0200 | [diff] [blame] | 523 | osmo_timer_setup(&e1i_ts->sign.tx_timer, timeout_ts1_write, e1i_ts); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 524 | |
| 525 | /* Reducing this might break the nanoBTS 900 init. */ |
| 526 | osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); |
| 527 | |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 528 | out: |
| 529 | msgb_free(msg); |
| 530 | return ret; |
| 531 | err: |
Harald Welte | 10b4130 | 2013-06-30 14:05:49 +0200 | [diff] [blame] | 532 | ipaccess_drop(bfd, line); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 533 | msgb_free(msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 534 | return ret; |
| 535 | } |
| 536 | |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 537 | static int handle_ts1_write(struct osmo_fd *bfd) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 538 | { |
| 539 | struct e1inp_line *line = bfd->data; |
| 540 | |
| 541 | return __handle_ts1_write(bfd, line); |
| 542 | } |
| 543 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 544 | static int ipaccess_bts_write_cb(struct ipa_client_conn *link) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 545 | { |
| 546 | struct e1inp_line *line = link->line; |
| 547 | |
| 548 | return __handle_ts1_write(link->ofd, line); |
| 549 | } |
| 550 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 551 | /* callback from select.c in case one of the fd's can be read/written */ |
Pablo Neira Ayuso | 495ddb6 | 2011-07-08 21:04:11 +0200 | [diff] [blame] | 552 | int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 553 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 554 | int rc = 0; |
| 555 | |
Harald Welte | de3959e | 2020-10-18 22:28:50 +0200 | [diff] [blame] | 556 | if (what & OSMO_FD_READ) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 557 | rc = handle_ts1_read(bfd); |
Harald Welte | de3959e | 2020-10-18 22:28:50 +0200 | [diff] [blame] | 558 | if (rc != -EBADF && (what & OSMO_FD_WRITE)) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 559 | rc = handle_ts1_write(bfd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 560 | |
| 561 | return rc; |
| 562 | } |
| 563 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 564 | static int ipaccess_line_update(struct e1inp_line *line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 565 | |
| 566 | struct e1inp_driver ipaccess_driver = { |
| 567 | .name = "ipa", |
| 568 | .want_write = ts_want_write, |
| 569 | .line_update = ipaccess_line_update, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 570 | .close = ipaccess_close, |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 571 | .default_delay = 0, |
Jacob Erlbeck | 8fe1571 | 2014-01-09 14:30:58 +0100 | [diff] [blame] | 572 | .has_keepalive = 1, |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 573 | }; |
| 574 | |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 575 | static void update_fd_settings(struct e1inp_line *line, int fd) |
| 576 | { |
| 577 | int ret; |
| 578 | int val; |
| 579 | |
Jacob Erlbeck | 8fe1571 | 2014-01-09 14:30:58 +0100 | [diff] [blame] | 580 | if (line->keepalive_num_probes) { |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 581 | /* Enable TCP keepalive to find out if the connection is gone */ |
| 582 | val = 1; |
| 583 | ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)); |
| 584 | if (ret < 0) |
| 585 | LOGP(DLINP, LOGL_NOTICE, "Failed to set keepalive: %s\n", |
| 586 | strerror(errno)); |
| 587 | else |
| 588 | LOGP(DLINP, LOGL_NOTICE, "Keepalive is set: %i\n", ret); |
| 589 | |
| 590 | #if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL) && defined(TCP_KEEPCNT) |
| 591 | /* The following options are not portable! */ |
Jacob Erlbeck | 8fe1571 | 2014-01-09 14:30:58 +0100 | [diff] [blame] | 592 | val = line->keepalive_idle_timeout > 0 ? |
| 593 | line->keepalive_idle_timeout : |
| 594 | DEFAULT_TCP_KEEPALIVE_IDLE_TIMEOUT; |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 595 | ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, |
| 596 | &val, sizeof(val)); |
| 597 | if (ret < 0) |
| 598 | LOGP(DLINP, LOGL_NOTICE, |
| 599 | "Failed to set keepalive idle time: %s\n", |
| 600 | strerror(errno)); |
Jacob Erlbeck | 8fe1571 | 2014-01-09 14:30:58 +0100 | [diff] [blame] | 601 | val = line->keepalive_probe_interval > -1 ? |
| 602 | line->keepalive_probe_interval : |
| 603 | DEFAULT_TCP_KEEPALIVE_INTERVAL; |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 604 | ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, |
| 605 | &val, sizeof(val)); |
| 606 | if (ret < 0) |
| 607 | LOGP(DLINP, LOGL_NOTICE, |
| 608 | "Failed to set keepalive interval: %s\n", |
| 609 | strerror(errno)); |
Jacob Erlbeck | 8fe1571 | 2014-01-09 14:30:58 +0100 | [diff] [blame] | 610 | val = line->keepalive_num_probes > 0 ? |
| 611 | line->keepalive_num_probes : |
| 612 | DEFAULT_TCP_KEEPALIVE_RETRY_COUNT; |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 613 | ret = setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, |
| 614 | &val, sizeof(val)); |
| 615 | if (ret < 0) |
| 616 | LOGP(DLINP, LOGL_NOTICE, |
| 617 | "Failed to set keepalive count: %s\n", |
| 618 | strerror(errno)); |
Eric Wild | 6eb186c | 2019-06-21 15:26:25 +0200 | [diff] [blame] | 619 | #if defined(TCP_USER_TIMEOUT) |
| 620 | val = 1000 * line->keepalive_num_probes * |
| 621 | line->keepalive_probe_interval + |
| 622 | line->keepalive_idle_timeout; |
| 623 | ret = setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, |
| 624 | &val, sizeof(val)); |
| 625 | if (ret < 0) |
| 626 | LOGP(DLINP, LOGL_NOTICE, |
| 627 | "Failed to set user timoeut: %s\n", |
| 628 | strerror(errno)); |
| 629 | #endif |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 630 | #endif |
Holger Hans Peter Freyther | f465a4c | 2014-02-03 09:34:02 +0100 | [diff] [blame] | 631 | } |
Oliver Smith | 62725d0 | 2020-04-17 10:57:46 +0200 | [diff] [blame] | 632 | |
| 633 | val = 1; |
| 634 | ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); |
| 635 | if (ret < 0) |
| 636 | LOGP(DLINP, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno)); |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 637 | } |
| 638 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 639 | /* callback of the OML listening filedescriptor */ |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 640 | static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 641 | { |
| 642 | int ret; |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 643 | int i; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 644 | struct e1inp_line *line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 645 | struct e1inp_ts *e1i_ts; |
| 646 | struct osmo_fd *bfd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 647 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 648 | /* clone virtual E1 line for this new OML link. */ |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 649 | line = e1inp_line_clone(tall_ipa_ctx, link->line, "ipa_bfd"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 650 | if (line == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 651 | LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 652 | return -ENOMEM; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 653 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 654 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 655 | /* create virrtual E1 timeslots for signalling */ |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 656 | e1inp_ts_config_sign(e1inp_line_ipa_oml_ts(line), line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 657 | |
| 658 | /* initialize the fds */ |
| 659 | for (i = 0; i < ARRAY_SIZE(line->ts); ++i) |
| 660 | line->ts[i].driver.ipaccess.fd.fd = -1; |
| 661 | |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 662 | e1i_ts = e1inp_line_ipa_oml_ts(line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 663 | |
Pablo Neira Ayuso | 93c6201 | 2011-06-26 19:12:47 +0200 | [diff] [blame] | 664 | bfd = &e1i_ts->driver.ipaccess.fd; |
Harald Welte | de3959e | 2020-10-18 22:28:50 +0200 | [diff] [blame] | 665 | osmo_fd_setup(bfd, fd, OSMO_FD_READ, ipaccess_fd_cb, line, E1INP_SIGN_OML); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 666 | ret = osmo_fd_register(bfd); |
| 667 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 668 | LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 669 | goto err_line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 670 | } |
| 671 | |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 672 | update_fd_settings(line, bfd->fd); |
Daniel Willmann | 8598072 | 2014-01-09 14:30:55 +0100 | [diff] [blame] | 673 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 674 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 675 | ret = ipa_ccm_send_id_req(bfd->fd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 676 | if (ret < 0) { |
| 677 | LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", |
| 678 | strerror(errno)); |
| 679 | goto err_socket; |
| 680 | } |
| 681 | return ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 682 | |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 683 | err_socket: |
| 684 | osmo_fd_unregister(bfd); |
| 685 | err_line: |
| 686 | close(bfd->fd); |
| 687 | bfd->fd = -1; |
Pau Espin Pedrol | a2ff733 | 2020-07-14 21:12:50 +0200 | [diff] [blame] | 688 | bfd->data = NULL; |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 689 | e1inp_line_put2(line, "ipa_bfd"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 690 | return ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 691 | } |
| 692 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 693 | static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 694 | { |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 695 | struct e1inp_line *line; |
| 696 | struct e1inp_ts *e1i_ts; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 697 | struct osmo_fd *bfd; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 698 | int i, ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 699 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 700 | /* We don't know yet which OML link to associate it with. Thus, we |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 701 | * allocate a temporary E1 line until we have received ID. */ |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 702 | line = e1inp_line_clone(tall_ipa_ctx, link->line, "ipa_bfd"); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 703 | if (line == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 704 | LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 705 | return -ENOMEM; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 706 | } |
| 707 | /* initialize the fds */ |
| 708 | for (i = 0; i < ARRAY_SIZE(line->ts); ++i) |
| 709 | line->ts[i].driver.ipaccess.fd.fd = -1; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 710 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 711 | /* we need this to initialize this in case to avoid crashes in case |
| 712 | * that the socket is closed before we've seen an ID_RESP. */ |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 713 | e1inp_ts_config_sign(e1inp_line_ipa_oml_ts(line), line); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 714 | |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 715 | e1i_ts = e1inp_line_ipa_rsl_ts(line, 0); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 716 | |
| 717 | bfd = &e1i_ts->driver.ipaccess.fd; |
Harald Welte | de3959e | 2020-10-18 22:28:50 +0200 | [diff] [blame] | 718 | osmo_fd_setup(bfd, fd, OSMO_FD_READ, ipaccess_fd_cb, line, E1INP_SIGN_RSL); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 719 | ret = osmo_fd_register(bfd); |
| 720 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 721 | LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 722 | goto err_line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 723 | } |
| 724 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 725 | ret = ipa_ccm_send_id_req(bfd->fd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 726 | if (ret < 0) { |
| 727 | LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", |
| 728 | strerror(errno)); |
| 729 | goto err_socket; |
| 730 | } |
Jacob Erlbeck | a4ec51e | 2014-01-09 14:30:56 +0100 | [diff] [blame] | 731 | update_fd_settings(line, bfd->fd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 732 | return ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 733 | |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 734 | err_socket: |
| 735 | osmo_fd_unregister(bfd); |
| 736 | err_line: |
| 737 | close(bfd->fd); |
| 738 | bfd->fd = -1; |
Pau Espin Pedrol | a2ff733 | 2020-07-14 21:12:50 +0200 | [diff] [blame] | 739 | bfd->data = NULL; |
Pau Espin Pedrol | 5196cd5 | 2020-07-14 17:52:09 +0200 | [diff] [blame] | 740 | e1inp_line_put2(line, "ipa_bfd"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 741 | return ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 742 | } |
| 743 | |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 744 | #define IPA_STRING_MAX 64 |
| 745 | |
| 746 | static struct msgb * |
Max | 7139352 | 2018-01-08 15:42:00 +0100 | [diff] [blame] | 747 | ipa_bts_id_resp(const struct ipaccess_unit *dev, uint8_t *data, int len, int trx_nr) |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 748 | { |
| 749 | struct msgb *nmsg; |
| 750 | char str[IPA_STRING_MAX]; |
| 751 | uint8_t *tag; |
| 752 | |
| 753 | memset(str, 0, sizeof(str)); |
| 754 | |
| 755 | nmsg = ipa_msg_alloc(0); |
| 756 | if (!nmsg) |
| 757 | return NULL; |
| 758 | |
| 759 | *msgb_put(nmsg, 1) = IPAC_MSGT_ID_RESP; |
| 760 | while (len) { |
| 761 | if (len < 2) { |
| 762 | LOGP(DLINP, LOGL_NOTICE, |
| 763 | "Short read of ipaccess tag\n"); |
| 764 | msgb_free(nmsg); |
| 765 | return NULL; |
| 766 | } |
| 767 | switch (data[1]) { |
| 768 | case IPAC_IDTAG_UNIT: |
| 769 | snprintf(str, sizeof(str), "%u/%u/%u", |
| 770 | dev->site_id, dev->bts_id, trx_nr); |
| 771 | break; |
| 772 | case IPAC_IDTAG_MACADDR: |
| 773 | snprintf(str, sizeof(str), |
| 774 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 775 | dev->mac_addr[0], dev->mac_addr[1], |
| 776 | dev->mac_addr[2], dev->mac_addr[3], |
| 777 | dev->mac_addr[4], dev->mac_addr[5]); |
| 778 | break; |
| 779 | case IPAC_IDTAG_LOCATION1: |
| 780 | if (dev->location1) |
Stefan Sperling | 961776a | 2018-12-06 13:09:48 +0100 | [diff] [blame] | 781 | osmo_strlcpy(str, dev->location1, sizeof(str)); |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 782 | break; |
| 783 | case IPAC_IDTAG_LOCATION2: |
| 784 | if (dev->location2) |
Stefan Sperling | 961776a | 2018-12-06 13:09:48 +0100 | [diff] [blame] | 785 | osmo_strlcpy(str, dev->location2, sizeof(str)); |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 786 | break; |
| 787 | case IPAC_IDTAG_EQUIPVERS: |
| 788 | if (dev->equipvers) |
Stefan Sperling | 961776a | 2018-12-06 13:09:48 +0100 | [diff] [blame] | 789 | osmo_strlcpy(str, dev->equipvers, sizeof(str)); |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 790 | break; |
| 791 | case IPAC_IDTAG_SWVERSION: |
| 792 | if (dev->swversion) |
Neels Hofmeyr | 4c57eef | 2018-07-26 17:28:24 +0200 | [diff] [blame] | 793 | osmo_strlcpy(str, dev->swversion, sizeof(str)); |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 794 | break; |
| 795 | case IPAC_IDTAG_UNITNAME: |
| 796 | snprintf(str, sizeof(str), |
| 797 | "%s-%02x-%02x-%02x-%02x-%02x-%02x", |
| 798 | dev->unit_name, |
| 799 | dev->mac_addr[0], dev->mac_addr[1], |
| 800 | dev->mac_addr[2], dev->mac_addr[3], |
| 801 | dev->mac_addr[4], dev->mac_addr[5]); |
| 802 | break; |
| 803 | case IPAC_IDTAG_SERNR: |
| 804 | if (dev->serno) |
Stefan Sperling | 961776a | 2018-12-06 13:09:48 +0100 | [diff] [blame] | 805 | osmo_strlcpy(str, dev->serno, sizeof(str)); |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 806 | break; |
| 807 | default: |
| 808 | LOGP(DLINP, LOGL_NOTICE, |
| 809 | "Unknown ipaccess tag 0x%02x\n", *data); |
| 810 | msgb_free(nmsg); |
| 811 | return NULL; |
| 812 | } |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 813 | |
| 814 | LOGP(DLINP, LOGL_INFO, " tag %d: %s\n", data[1], str); |
| 815 | tag = msgb_put(nmsg, 3 + strlen(str) + 1); |
| 816 | tag[0] = 0x00; |
| 817 | tag[1] = 1 + strlen(str) + 1; |
| 818 | tag[2] = data[1]; |
| 819 | memcpy(tag + 3, str, strlen(str) + 1); |
| 820 | data += 2; |
| 821 | len -= 2; |
| 822 | } |
| 823 | ipa_msg_push_header(nmsg, IPAC_PROTO_IPACCESS); |
| 824 | return nmsg; |
| 825 | } |
| 826 | |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 827 | static struct msgb *ipa_bts_id_ack(void) |
| 828 | { |
| 829 | struct msgb *nmsg2; |
| 830 | |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 831 | nmsg2 = ipa_msg_alloc(0); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 832 | if (!nmsg2) |
| 833 | return NULL; |
| 834 | |
| 835 | *msgb_put(nmsg2, 1) = IPAC_MSGT_ID_ACK; |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 836 | ipa_msg_push_header(nmsg2, IPAC_PROTO_IPACCESS); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 837 | |
| 838 | return nmsg2; |
| 839 | } |
| 840 | |
Harald Welte | 51de9ca | 2013-06-30 20:13:16 +0200 | [diff] [blame] | 841 | static void ipaccess_bts_updown_cb(struct ipa_client_conn *link, int up) |
| 842 | { |
| 843 | struct e1inp_line *line = link->line; |
| 844 | |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 845 | if (up) { |
| 846 | struct osmo_fsm_inst *ka_fsm = ipaccess_line_ts(link->ofd, line)->driver.ipaccess.ka_fsm; |
| 847 | |
| 848 | update_fd_settings(line, link->ofd->fd); |
| 849 | if (ka_fsm && line->ipa_kap) |
| 850 | ipa_keepalive_fsm_start(ka_fsm); |
| 851 | return; |
| 852 | } |
Harald Welte | 51de9ca | 2013-06-30 20:13:16 +0200 | [diff] [blame] | 853 | |
| 854 | if (line->ops->sign_link_down) |
| 855 | line->ops->sign_link_down(line); |
| 856 | } |
| 857 | |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 858 | /* handle incoming message to BTS, check if it is an IPA CCM, and if yes, |
| 859 | * handle it accordingly (PING/PONG/ID_REQ/ID_RESP/ID_ACK) */ |
| 860 | int ipaccess_bts_handle_ccm(struct ipa_client_conn *link, |
| 861 | struct ipaccess_unit *dev, struct msgb *msg) |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 862 | { |
| 863 | struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 864 | struct msgb *rmsg; |
| 865 | int ret = 0; |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 866 | /* line might not exist if != bsc||bts */ |
| 867 | struct e1inp_line *line = link->line; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 868 | |
| 869 | /* special handling for IPA CCM. */ |
| 870 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 871 | uint8_t msg_type = *(msg->l2h); |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 872 | struct osmo_fsm_inst* ka_fsm = NULL; |
| 873 | |
| 874 | /* peek the pong for our keepalive fsm */ |
| 875 | if (line && msg_type == IPAC_MSGT_PONG) { |
| 876 | ka_fsm = ipaccess_line_ts(link->ofd, line)->driver.ipaccess.ka_fsm; |
| 877 | ipa_keepalive_fsm_pong_received(ka_fsm); |
| 878 | } |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 879 | |
| 880 | /* ping, pong and acknowledgment cases. */ |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 881 | ret = ipa_ccm_rcvmsg_bts_base(msg, link->ofd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 882 | if (ret < 0) |
| 883 | goto err; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 884 | |
| 885 | /* this is a request for identification from the BSC. */ |
| 886 | if (msg_type == IPAC_MSGT_ID_GET) { |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 887 | uint8_t *data = msgb_l2(msg); |
| 888 | int len = msgb_l2len(msg); |
Andreas Eversberg | f422a75 | 2014-01-21 14:54:41 +0100 | [diff] [blame] | 889 | int trx_nr = 0; |
| 890 | |
| 891 | if (link->ofd->priv_nr >= E1INP_SIGN_RSL) |
| 892 | trx_nr = link->ofd->priv_nr - E1INP_SIGN_RSL; |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 893 | |
Vadim Yanitskiy | 69ae238 | 2019-12-02 02:42:43 +0700 | [diff] [blame] | 894 | LOGP(DLINP, LOGL_NOTICE, "received ID_GET for unit ID %u/%u/%u\n", |
Pau Espin Pedrol | dd95eb6 | 2018-10-02 20:05:28 +0200 | [diff] [blame] | 895 | dev->site_id, dev->bts_id, trx_nr); |
Harald Welte | e416e2e | 2017-05-26 13:11:59 +0200 | [diff] [blame] | 896 | rmsg = ipa_bts_id_resp(dev, data + 1, len - 1, trx_nr); |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 897 | ret = ipa_send(link->ofd->fd, rmsg->data, rmsg->len); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 898 | if (ret != rmsg->len) { |
| 899 | LOGP(DLINP, LOGL_ERROR, "cannot send ID_RESP " |
| 900 | "message. Reason: %s\n", strerror(errno)); |
| 901 | goto err_rmsg; |
| 902 | } |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 903 | msgb_free(rmsg); |
| 904 | |
| 905 | /* send ID_ACK. */ |
| 906 | rmsg = ipa_bts_id_ack(); |
Harald Welte | b65f58f | 2014-08-20 22:04:11 +0200 | [diff] [blame] | 907 | ret = ipa_send(link->ofd->fd, rmsg->data, rmsg->len); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 908 | if (ret != rmsg->len) { |
| 909 | LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " |
| 910 | "message. Reason: %s\n", strerror(errno)); |
| 911 | goto err_rmsg; |
| 912 | } |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 913 | msgb_free(rmsg); |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 914 | } |
| 915 | return 1; |
| 916 | } |
Harald Welte | 6eddd47 | 2013-06-30 20:18:53 +0200 | [diff] [blame] | 917 | |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 918 | return 0; |
| 919 | |
| 920 | err_rmsg: |
| 921 | msgb_free(rmsg); |
| 922 | err: |
| 923 | ipa_client_conn_close(link); |
| 924 | return -1; |
| 925 | } |
| 926 | |
| 927 | static int ipaccess_bts_read_cb(struct ipa_client_conn *link, struct msgb *msg) |
| 928 | { |
| 929 | struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; |
| 930 | struct e1inp_ts *e1i_ts = NULL; |
| 931 | struct e1inp_sign_link *sign_link; |
Neels Hofmeyr | fe67311 | 2018-08-24 17:43:45 +0200 | [diff] [blame] | 932 | uint8_t msg_type = *(msg->l2h); |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 933 | int ret = 0; |
| 934 | |
| 935 | /* special handling for IPA CCM. */ |
| 936 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 937 | /* this is a request for identification from the BSC. */ |
| 938 | if (msg_type == IPAC_MSGT_ID_GET) { |
| 939 | if (!link->line->ops->sign_link_up) { |
| 940 | LOGP(DLINP, LOGL_ERROR, |
| 941 | "Unable to set signal link, " |
| 942 | "closing socket.\n"); |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 943 | goto err; |
| 944 | } |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | /* core CCM handling */ |
| 949 | ret = ipaccess_bts_handle_ccm(link, link->line->ops->cfg.ipa.dev, msg); |
| 950 | if (ret < 0) |
| 951 | goto err; |
| 952 | |
| 953 | if (ret == 1 && hh->proto == IPAC_PROTO_IPACCESS) { |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 954 | if (msg_type == IPAC_MSGT_ID_GET) { |
Harald Welte | 6eddd47 | 2013-06-30 20:18:53 +0200 | [diff] [blame] | 955 | sign_link = link->line->ops->sign_link_up(msg, |
| 956 | link->line, |
| 957 | link->ofd->priv_nr); |
| 958 | if (sign_link == NULL) { |
| 959 | LOGP(DLINP, LOGL_ERROR, |
| 960 | "Unable to set signal link, " |
| 961 | "closing socket.\n"); |
Harald Welte | 6eddd47 | 2013-06-30 20:18:53 +0200 | [diff] [blame] | 962 | goto err; |
| 963 | } |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 964 | } |
Pablo Neira Ayuso | 84e5cb9 | 2012-08-23 23:41:54 +0200 | [diff] [blame] | 965 | msgb_free(msg); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 966 | return ret; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 967 | } else if (link->port == IPA_TCP_PORT_OML) |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 968 | e1i_ts = e1inp_line_ipa_oml_ts(link->line); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 969 | else if (link->port == IPA_TCP_PORT_RSL) |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 970 | e1i_ts = e1inp_line_ipa_rsl_ts(link->line, link->ofd->priv_nr - E1INP_SIGN_RSL); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 971 | |
Pablo Neira Ayuso | b948701 | 2013-07-05 14:38:43 +0200 | [diff] [blame] | 972 | OSMO_ASSERT(e1i_ts != NULL); |
| 973 | |
Neels Hofmeyr | fe67311 | 2018-08-24 17:43:45 +0200 | [diff] [blame] | 974 | if (e1i_ts->type == E1INP_TS_TYPE_NONE) { |
| 975 | LOGP(DLINP, LOGL_ERROR, "Signalling link not initialized. Discarding." |
| 976 | " port=%u msg_type=%u\n", link->port, msg_type); |
Neels Hofmeyr | fe67311 | 2018-08-24 17:43:45 +0200 | [diff] [blame] | 977 | goto err; |
| 978 | } |
Pau Espin Pedrol | 7ad2b15 | 2018-08-28 17:37:59 +0200 | [diff] [blame] | 979 | |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 980 | /* look up for some existing signaling link. */ |
| 981 | sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 982 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 983 | LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 984 | "hh->proto=0x%02x\n", hh->proto); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 985 | goto err; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 986 | } |
| 987 | msg->dst = sign_link; |
| 988 | |
| 989 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 990 | if (!link->line->ops->sign_link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 991 | LOGP(DLINP, LOGL_ERROR, "Fix your application, " |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 992 | "no action set for signalling messages.\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 993 | goto err; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 994 | } |
Pau Espin Pedrol | ed122f3 | 2018-08-28 18:25:02 +0200 | [diff] [blame] | 995 | return link->line->ops->sign_link(msg); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 996 | |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 997 | err: |
Harald Welte | 783715b | 2014-08-17 18:24:51 +0200 | [diff] [blame] | 998 | ipa_client_conn_close(link); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 999 | msgb_free(msg); |
Pau Espin Pedrol | 7ad2b15 | 2018-08-28 17:37:59 +0200 | [diff] [blame] | 1000 | return -EBADF; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
Pablo Neira Ayuso | d621640 | 2011-08-31 16:47:44 +0200 | [diff] [blame] | 1003 | struct ipaccess_line { |
Oliver Smith | 65ae42c | 2020-01-22 11:24:52 +0100 | [diff] [blame] | 1004 | bool line_already_initialized; |
Pablo Neira Ayuso | d621640 | 2011-08-31 16:47:44 +0200 | [diff] [blame] | 1005 | }; |
| 1006 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 1007 | static int ipaccess_line_update(struct e1inp_line *line) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1008 | { |
| 1009 | int ret = -ENOENT; |
Pablo Neira Ayuso | d621640 | 2011-08-31 16:47:44 +0200 | [diff] [blame] | 1010 | struct ipaccess_line *il; |
| 1011 | |
| 1012 | if (!line->driver_data) |
| 1013 | line->driver_data = talloc_zero(line, struct ipaccess_line); |
| 1014 | |
| 1015 | if (!line->driver_data) { |
| 1016 | LOGP(DLINP, LOGL_ERROR, "ipaccess: OOM in line update\n"); |
| 1017 | return -ENOMEM; |
| 1018 | } |
| 1019 | il = line->driver_data; |
| 1020 | |
| 1021 | /* We only initialize this line once. */ |
| 1022 | if (il->line_already_initialized) |
| 1023 | return 0; |
| 1024 | |
Oliver Smith | 65ae42c | 2020-01-22 11:24:52 +0100 | [diff] [blame] | 1025 | il->line_already_initialized = true; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1026 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 1027 | switch(line->ops->cfg.ipa.role) { |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1028 | case E1INP_LINE_R_BSC: { |
| 1029 | struct ipa_server_link *oml_link, *rsl_link; |
Max | 4c4a1c2 | 2016-12-30 15:10:47 +0100 | [diff] [blame] | 1030 | const char *ipa = e1inp_ipa_get_bind_addr(); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1031 | |
Max | 4c4a1c2 | 2016-12-30 15:10:47 +0100 | [diff] [blame] | 1032 | LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BSC mode on %s " |
| 1033 | "with OML %u and RSL %u TCP ports\n", ipa, |
| 1034 | IPA_TCP_PORT_OML, IPA_TCP_PORT_RSL); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1035 | |
Max | 4c4a1c2 | 2016-12-30 15:10:47 +0100 | [diff] [blame] | 1036 | oml_link = ipa_server_link_create(tall_ipa_ctx, line, ipa, |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 1037 | IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 1038 | ipaccess_bsc_oml_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1039 | if (oml_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 1040 | LOGP(DLINP, LOGL_ERROR, "cannot create OML " |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1041 | "BSC link: %s\n", strerror(errno)); |
| 1042 | return -ENOMEM; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 1043 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1044 | if (ipa_server_link_open(oml_link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 1045 | LOGP(DLINP, LOGL_ERROR, "cannot open OML BSC link: %s\n", |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1046 | strerror(errno)); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1047 | ipa_server_link_destroy(oml_link); |
| 1048 | return -EIO; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 1049 | } |
Max | 4c4a1c2 | 2016-12-30 15:10:47 +0100 | [diff] [blame] | 1050 | rsl_link = ipa_server_link_create(tall_ipa_ctx, line, ipa, |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 1051 | IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 1052 | ipaccess_bsc_rsl_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1053 | if (rsl_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 1054 | LOGP(DLINP, LOGL_ERROR, "cannot create RSL " |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1055 | "BSC link: %s\n", strerror(errno)); |
| 1056 | return -ENOMEM; |
| 1057 | } |
| 1058 | if (ipa_server_link_open(rsl_link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 1059 | LOGP(DLINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n", |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1060 | strerror(errno)); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1061 | ipa_server_link_destroy(rsl_link); |
| 1062 | return -EIO; |
| 1063 | } |
| 1064 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1065 | break; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 1066 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1067 | case E1INP_LINE_R_BTS: { |
Harald Welte | 84f67b2 | 2013-06-30 13:13:59 +0200 | [diff] [blame] | 1068 | struct ipa_client_conn *link; |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 1069 | struct e1inp_ts *e1i_ts; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1070 | |
Max | 4c4a1c2 | 2016-12-30 15:10:47 +0100 | [diff] [blame] | 1071 | LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BTS mode, " |
| 1072 | "OML connecting to %s:%u\n", line->ops->cfg.ipa.addr, |
| 1073 | IPA_TCP_PORT_OML); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1074 | |
Pau Espin Pedrol | b6e28bf | 2019-11-08 17:30:28 +0100 | [diff] [blame] | 1075 | link = ipa_client_conn_create2(tall_ipa_ctx, |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 1076 | e1inp_line_ipa_oml_ts(line), |
Pablo Neira Ayuso | 00af772 | 2011-09-08 12:47:06 +0200 | [diff] [blame] | 1077 | E1INP_SIGN_OML, |
Pau Espin Pedrol | b6e28bf | 2019-11-08 17:30:28 +0100 | [diff] [blame] | 1078 | NULL, 0, |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 1079 | line->ops->cfg.ipa.addr, |
| 1080 | IPA_TCP_PORT_OML, |
Harald Welte | 51de9ca | 2013-06-30 20:13:16 +0200 | [diff] [blame] | 1081 | ipaccess_bts_updown_cb, |
Harald Welte | a3e9dd5 | 2013-06-30 14:25:07 +0200 | [diff] [blame] | 1082 | ipaccess_bts_read_cb, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 1083 | ipaccess_bts_write_cb, |
Harald Welte | 10b4130 | 2013-06-30 14:05:49 +0200 | [diff] [blame] | 1084 | line); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1085 | if (link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 1086 | LOGP(DLINP, LOGL_ERROR, "cannot create OML " |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 1087 | "BTS link: %s\n", strerror(errno)); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1088 | return -ENOMEM; |
| 1089 | } |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 1090 | if (ipa_client_conn_open(link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 1091 | LOGP(DLINP, LOGL_ERROR, "cannot open OML BTS link: %s\n", |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 1092 | strerror(errno)); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 1093 | ipa_client_conn_close(link); |
| 1094 | ipa_client_conn_destroy(link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1095 | return -EIO; |
| 1096 | } |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 1097 | |
| 1098 | e1i_ts = e1inp_line_ipa_oml_ts(line); |
| 1099 | ipaccess_bts_keepalive_fsm_alloc(e1i_ts, link, "oml_bts_to_bsc"); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1100 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1101 | break; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1102 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1103 | default: |
| 1104 | break; |
| 1105 | } |
| 1106 | return ret; |
| 1107 | } |
| 1108 | |
Andreas Eversberg | f422a75 | 2014-01-21 14:54:41 +0100 | [diff] [blame] | 1109 | |
| 1110 | /* backwards compatibility */ |
Harald Welte | 84f67b2 | 2013-06-30 13:13:59 +0200 | [diff] [blame] | 1111 | int e1inp_ipa_bts_rsl_connect(struct e1inp_line *line, |
| 1112 | const char *rem_addr, uint16_t rem_port) |
| 1113 | { |
Andreas Eversberg | f422a75 | 2014-01-21 14:54:41 +0100 | [diff] [blame] | 1114 | return e1inp_ipa_bts_rsl_connect_n(line, rem_addr, rem_port, 0); |
| 1115 | } |
| 1116 | |
| 1117 | int e1inp_ipa_bts_rsl_connect_n(struct e1inp_line *line, |
| 1118 | const char *rem_addr, uint16_t rem_port, |
| 1119 | uint8_t trx_nr) |
| 1120 | { |
Harald Welte | 84f67b2 | 2013-06-30 13:13:59 +0200 | [diff] [blame] | 1121 | struct ipa_client_conn *rsl_link; |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 1122 | struct e1inp_ts *e1i_ts = e1inp_line_ipa_rsl_ts(line, trx_nr); |
Harald Welte | 84f67b2 | 2013-06-30 13:13:59 +0200 | [diff] [blame] | 1123 | |
Andreas Eversberg | f422a75 | 2014-01-21 14:54:41 +0100 | [diff] [blame] | 1124 | if (E1INP_SIGN_RSL+trx_nr-1 >= NUM_E1_TS) { |
| 1125 | LOGP(DLINP, LOGL_ERROR, "cannot create RSL BTS link: " |
| 1126 | "trx_nr (%d) out of range\n", trx_nr); |
| 1127 | return -EINVAL; |
| 1128 | } |
Andreas Eversberg | f422a75 | 2014-01-21 14:54:41 +0100 | [diff] [blame] | 1129 | |
Pau Espin Pedrol | b6e28bf | 2019-11-08 17:30:28 +0100 | [diff] [blame] | 1130 | rsl_link = ipa_client_conn_create2(tall_ipa_ctx, |
Pau Espin Pedrol | b5cfc6b | 2018-10-02 21:22:18 +0200 | [diff] [blame] | 1131 | e1inp_line_ipa_rsl_ts(line, trx_nr), |
Andreas Eversberg | f422a75 | 2014-01-21 14:54:41 +0100 | [diff] [blame] | 1132 | E1INP_SIGN_RSL+trx_nr, |
Pau Espin Pedrol | b6e28bf | 2019-11-08 17:30:28 +0100 | [diff] [blame] | 1133 | NULL, 0, |
Harald Welte | 84f67b2 | 2013-06-30 13:13:59 +0200 | [diff] [blame] | 1134 | rem_addr, rem_port, |
Harald Welte | 51de9ca | 2013-06-30 20:13:16 +0200 | [diff] [blame] | 1135 | ipaccess_bts_updown_cb, |
Harald Welte | a3e9dd5 | 2013-06-30 14:25:07 +0200 | [diff] [blame] | 1136 | ipaccess_bts_read_cb, |
Harald Welte | 84f67b2 | 2013-06-30 13:13:59 +0200 | [diff] [blame] | 1137 | ipaccess_bts_write_cb, |
Harald Welte | 10b4130 | 2013-06-30 14:05:49 +0200 | [diff] [blame] | 1138 | line); |
Harald Welte | 84f67b2 | 2013-06-30 13:13:59 +0200 | [diff] [blame] | 1139 | if (rsl_link == NULL) { |
| 1140 | LOGP(DLINP, LOGL_ERROR, "cannot create RSL " |
| 1141 | "BTS link: %s\n", strerror(errno)); |
| 1142 | return -ENOMEM; |
| 1143 | } |
| 1144 | if (ipa_client_conn_open(rsl_link) < 0) { |
| 1145 | LOGP(DLINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n", |
| 1146 | strerror(errno)); |
| 1147 | ipa_client_conn_close(rsl_link); |
| 1148 | ipa_client_conn_destroy(rsl_link); |
| 1149 | return -EIO; |
| 1150 | } |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 1151 | |
| 1152 | ipaccess_bts_keepalive_fsm_alloc(e1i_ts, rsl_link, "rsl_bts_to_bsc"); |
Harald Welte | 84f67b2 | 2013-06-30 13:13:59 +0200 | [diff] [blame] | 1153 | return 0; |
| 1154 | } |
| 1155 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1156 | void e1inp_ipaccess_init(void) |
| 1157 | { |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 1158 | tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1159 | e1inp_driver_register(&ipaccess_driver); |
| 1160 | } |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 1161 | |
| 1162 | void e1inp_ipa_set_bind_addr(const char *ip_bind_addr) |
| 1163 | { |
| 1164 | talloc_free((char*)ipaccess_driver.bind_addr); |
| 1165 | ipaccess_driver.bind_addr = NULL; |
| 1166 | |
| 1167 | if (ip_bind_addr) |
| 1168 | ipaccess_driver.bind_addr = talloc_strdup(tall_ipa_ctx, |
| 1169 | ip_bind_addr); |
| 1170 | } |
| 1171 | |
| 1172 | const char *e1inp_ipa_get_bind_addr(void) |
| 1173 | { |
| 1174 | return ipaccess_driver.bind_addr? |
| 1175 | ipaccess_driver.bind_addr |
| 1176 | : "0.0.0.0"; |
| 1177 | } |