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