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 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "internal.h" |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <unistd.h> |
| 28 | #include <stdlib.h> |
Pablo Neira Ayuso | eb43413 | 2011-07-07 19:19:46 +0200 | [diff] [blame] | 29 | #include <stdbool.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 30 | #include <errno.h> |
| 31 | #include <string.h> |
| 32 | #include <time.h> |
| 33 | #include <sys/fcntl.h> |
| 34 | #include <sys/socket.h> |
| 35 | #include <sys/ioctl.h> |
| 36 | #include <arpa/inet.h> |
| 37 | |
| 38 | #include <osmocom/core/select.h> |
| 39 | #include <osmocom/gsm/tlv.h> |
| 40 | #include <osmocom/core/msgb.h> |
| 41 | #include <osmocom/core/logging.h> |
Harald Welte | 71d87b2 | 2011-07-18 14:49:56 +0200 | [diff] [blame] | 42 | #include <osmocom/core/talloc.h> |
Pablo Neira Ayuso | 177094b | 2011-06-07 12:21:51 +0200 | [diff] [blame] | 43 | #include <osmocom/abis/e1_input.h> |
| 44 | #include <osmocom/abis/ipaccess.h> |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 45 | #include <osmocom/core/socket.h> |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 46 | #include <osmocom/abis/ipa.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 47 | |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 48 | static void *tall_ipa_ctx; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 49 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 50 | #define TS1_ALLOC_SIZE 900 |
| 51 | |
| 52 | /* |
| 53 | * Common propietary IPA messages: |
| 54 | * - PONG: in reply to PING. |
| 55 | * - ID_REQUEST: first messages once OML has been established. |
| 56 | * - ID_ACK: in reply to ID_ACK. |
| 57 | */ |
| 58 | const uint8_t ipa_pong_msg[] = { |
| 59 | 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG |
| 60 | }; |
| 61 | |
| 62 | const uint8_t ipa_id_ack_msg[] = { |
| 63 | 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK |
| 64 | }; |
| 65 | |
| 66 | const uint8_t ipa_id_req_msg[] = { |
| 67 | 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET, |
| 68 | 0x01, IPAC_IDTAG_UNIT, |
| 69 | 0x01, IPAC_IDTAG_MACADDR, |
| 70 | 0x01, IPAC_IDTAG_LOCATION1, |
| 71 | 0x01, IPAC_IDTAG_LOCATION2, |
| 72 | 0x01, IPAC_IDTAG_EQUIPVERS, |
| 73 | 0x01, IPAC_IDTAG_SWVERSION, |
| 74 | 0x01, IPAC_IDTAG_UNITNAME, |
| 75 | 0x01, IPAC_IDTAG_SERNR, |
| 76 | }; |
| 77 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 78 | static const char *idtag_names[] = { |
| 79 | [IPAC_IDTAG_SERNR] = "Serial_Number", |
| 80 | [IPAC_IDTAG_UNITNAME] = "Unit_Name", |
| 81 | [IPAC_IDTAG_LOCATION1] = "Location_1", |
| 82 | [IPAC_IDTAG_LOCATION2] = "Location_2", |
| 83 | [IPAC_IDTAG_EQUIPVERS] = "Equipment_Version", |
| 84 | [IPAC_IDTAG_SWVERSION] = "Software_Version", |
| 85 | [IPAC_IDTAG_IPADDR] = "IP_Address", |
| 86 | [IPAC_IDTAG_MACADDR] = "MAC_Address", |
| 87 | [IPAC_IDTAG_UNIT] = "Unit_ID", |
| 88 | }; |
| 89 | |
| 90 | const char *ipaccess_idtag_name(uint8_t tag) |
| 91 | { |
| 92 | if (tag >= ARRAY_SIZE(idtag_names)) |
| 93 | return "unknown"; |
| 94 | |
| 95 | return idtag_names[tag]; |
| 96 | } |
| 97 | |
| 98 | int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len) |
| 99 | { |
| 100 | uint8_t t_len; |
| 101 | uint8_t t_tag; |
| 102 | uint8_t *cur = buf; |
| 103 | |
| 104 | memset(dec, 0, sizeof(*dec)); |
| 105 | |
| 106 | while (len >= 2) { |
| 107 | len -= 2; |
| 108 | t_len = *cur++; |
| 109 | t_tag = *cur++; |
| 110 | |
| 111 | if (t_len > len + 1) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 112 | LOGP(DLMI, LOGL_ERROR, "The tag does not fit: %d\n", t_len); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 113 | return -EINVAL; |
| 114 | } |
| 115 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 116 | DEBUGPC(DLMI, "%s='%s' ", ipaccess_idtag_name(t_tag), cur); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 117 | |
| 118 | dec->lv[t_tag].len = t_len; |
| 119 | dec->lv[t_tag].val = cur; |
| 120 | |
| 121 | cur += t_len; |
| 122 | len -= t_len; |
| 123 | } |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | int ipaccess_parse_unitid(const char *str, struct ipaccess_unit *unit_data) |
| 128 | { |
| 129 | unsigned long ul; |
| 130 | char *endptr; |
| 131 | const char *nptr; |
| 132 | |
| 133 | nptr = str; |
| 134 | ul = strtoul(nptr, &endptr, 10); |
| 135 | if (endptr <= nptr) |
| 136 | return -EINVAL; |
Pablo Neira Ayuso | 62d345a | 2011-07-05 16:37:37 +0200 | [diff] [blame] | 137 | unit_data->site_id = ul & 0xffff; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 138 | |
| 139 | if (*endptr++ != '/') |
| 140 | return -EINVAL; |
| 141 | |
| 142 | nptr = endptr; |
| 143 | ul = strtoul(nptr, &endptr, 10); |
| 144 | if (endptr <= nptr) |
| 145 | return -EINVAL; |
Pablo Neira Ayuso | 62d345a | 2011-07-05 16:37:37 +0200 | [diff] [blame] | 146 | unit_data->bts_id = ul & 0xffff; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 147 | |
| 148 | if (*endptr++ != '/') |
| 149 | return -EINVAL; |
| 150 | |
| 151 | nptr = endptr; |
| 152 | ul = strtoul(nptr, &endptr, 10); |
| 153 | if (endptr <= nptr) |
| 154 | return -EINVAL; |
Pablo Neira Ayuso | 62d345a | 2011-07-05 16:37:37 +0200 | [diff] [blame] | 155 | unit_data->trx_id = ul & 0xffff; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 160 | static int ipaccess_send(int fd, const void *msg, size_t msglen) |
| 161 | { |
| 162 | int ret; |
| 163 | |
| 164 | ret = write(fd, msg, msglen); |
| 165 | if (ret < 0) |
| 166 | return ret; |
| 167 | if (ret < msglen) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 168 | LOGP(DLINP, LOGL_ERROR, "ipaccess_send: short write\n"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 169 | return -EIO; |
| 170 | } |
| 171 | return ret; |
| 172 | } |
| 173 | |
| 174 | int ipaccess_send_pong(int fd) |
| 175 | { |
| 176 | return ipaccess_send(fd, ipa_pong_msg, sizeof(ipa_pong_msg)); |
| 177 | } |
| 178 | |
| 179 | int ipaccess_send_id_ack(int fd) |
| 180 | { |
| 181 | return ipaccess_send(fd, ipa_id_ack_msg, sizeof(ipa_id_ack_msg)); |
| 182 | } |
| 183 | |
| 184 | int ipaccess_send_id_req(int fd) |
| 185 | { |
| 186 | return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg)); |
| 187 | } |
| 188 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 189 | /* base handling of the ip.access protocol */ |
Harald Welte | bc25bca | 2011-08-19 22:32:38 +0200 | [diff] [blame] | 190 | int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd) |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 191 | { |
| 192 | uint8_t msg_type = *(msg->l2h); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 193 | int ret; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 194 | |
| 195 | switch (msg_type) { |
| 196 | case IPAC_MSGT_PING: |
| 197 | ret = ipaccess_send_pong(bfd->fd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 198 | if (ret < 0) { |
| 199 | LOGP(DLINP, LOGL_ERROR, "Cannot send PING " |
| 200 | "message. Reason: %s\n", strerror(errno)); |
| 201 | break; |
| 202 | } |
| 203 | ret = 1; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 204 | break; |
| 205 | case IPAC_MSGT_PONG: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 206 | DEBUGP(DLMI, "PONG!\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 207 | ret = 1; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 208 | break; |
| 209 | case IPAC_MSGT_ID_ACK: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 210 | DEBUGP(DLMI, "ID_ACK? -> ACK!\n"); |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 211 | ret = ipaccess_send_id_ack(bfd->fd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 212 | if (ret < 0) { |
| 213 | LOGP(DLINP, LOGL_ERROR, "Cannot send ID_ACK " |
| 214 | "message. Reason: %s\n", strerror(errno)); |
| 215 | break; |
| 216 | } |
| 217 | ret = 1; |
| 218 | break; |
| 219 | default: |
| 220 | /* This is not an IPA PING, PONG or ID_ACK message */ |
| 221 | ret = 0; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 222 | break; |
| 223 | } |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 224 | return ret; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 227 | /* base handling of the ip.access protocol */ |
| 228 | int ipaccess_rcvmsg_bts_base(struct msgb *msg, |
| 229 | struct osmo_fd *bfd) |
| 230 | { |
| 231 | uint8_t msg_type = *(msg->l2h); |
| 232 | int ret = 0; |
| 233 | |
| 234 | switch (msg_type) { |
| 235 | case IPAC_MSGT_PING: |
| 236 | ret = ipaccess_send_pong(bfd->fd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 237 | if (ret < 0) { |
| 238 | LOGP(DLINP, LOGL_ERROR, "Cannot send PONG " |
| 239 | "message. Reason: %s\n", strerror(errno)); |
| 240 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 241 | break; |
| 242 | case IPAC_MSGT_PONG: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 243 | DEBUGP(DLMI, "PONG!\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 244 | break; |
| 245 | case IPAC_MSGT_ID_ACK: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 246 | DEBUGP(DLMI, "ID_ACK\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 247 | break; |
| 248 | } |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 249 | return ret; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 250 | } |
| 251 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 252 | static int ipaccess_drop(struct osmo_fd *bfd) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 253 | { |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 254 | int ret = 1; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 255 | struct e1inp_line *line = bfd->data; |
| 256 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 257 | /* Error case: we did not see any ID_RESP yet for this socket. */ |
| 258 | if (bfd->fd != -1) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 259 | LOGP(DLINP, LOGL_ERROR, "Forcing socket shutdown with " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 260 | "no signal link set\n"); |
Pablo Neira Ayuso | 9621b41 | 2011-07-07 16:19:21 +0200 | [diff] [blame] | 261 | osmo_fd_unregister(bfd); |
| 262 | close(bfd->fd); |
| 263 | bfd->fd = -1; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 264 | ret = -ENOENT; |
Pablo Neira Ayuso | 9621b41 | 2011-07-07 16:19:21 +0200 | [diff] [blame] | 265 | } |
Pablo Neira Ayuso | 6cc3f92 | 2012-08-22 13:57:58 +0200 | [diff] [blame] | 266 | |
| 267 | /* e1inp_sign_link_destroy releases the socket descriptors for us. */ |
| 268 | line->ops->sign_link_down(line); |
| 269 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 270 | return ret; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 273 | static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, |
| 274 | struct osmo_fd *bfd) |
| 275 | { |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 276 | struct tlv_parsed tlvp; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 277 | uint8_t msg_type = *(msg->l2h); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 278 | struct ipaccess_unit unit_data = {}; |
| 279 | struct e1inp_sign_link *sign_link; |
| 280 | char *unitid; |
| 281 | int len, ret; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 282 | |
Pablo Neira Ayuso | eb43413 | 2011-07-07 19:19:46 +0200 | [diff] [blame] | 283 | /* Handle IPA PING, PONG and ID_ACK messages. */ |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 284 | ret = ipaccess_rcvmsg_base(msg, bfd); |
| 285 | switch(ret) { |
| 286 | case -1: |
| 287 | /* error in IPA control message handling */ |
| 288 | goto err; |
| 289 | case 1: |
| 290 | /* this is an IPA control message, skip further processing */ |
Pablo Neira Ayuso | eb43413 | 2011-07-07 19:19:46 +0200 | [diff] [blame] | 291 | return 0; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 292 | case 0: |
| 293 | /* this is not an IPA control message, continue */ |
| 294 | break; |
| 295 | default: |
| 296 | LOGP(DLINP, LOGL_ERROR, "Unexpected return from " |
| 297 | "ipaccess_rcvmsg_base " |
| 298 | "(ret=%d)\n", ret); |
| 299 | goto err; |
| 300 | } |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 301 | |
| 302 | switch (msg_type) { |
| 303 | case IPAC_MSGT_ID_RESP: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 304 | DEBUGP(DLMI, "ID_RESP\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 305 | /* parse tags, search for Unit ID */ |
| 306 | ret = ipaccess_idtag_parse(&tlvp, (uint8_t *)msg->l2h + 2, |
| 307 | msgb_l2len(msg)-2); |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 308 | DEBUGP(DLMI, "\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 309 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 310 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 311 | "with malformed TLVs\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 312 | ret = -EINVAL; |
| 313 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 314 | } |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 315 | if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT)) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 316 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 317 | "without unit ID\n"); |
| 318 | ret = -EINVAL; |
| 319 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 320 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 321 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 322 | len = TLVP_LEN(&tlvp, IPAC_IDTAG_UNIT); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 323 | if (len < 1) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 324 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 325 | "with too small unit ID\n"); |
| 326 | ret = -EINVAL; |
| 327 | goto err; |
| 328 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 329 | unitid = (char *) TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT); |
| 330 | unitid[len - 1] = '\0'; |
| 331 | ipaccess_parse_unitid(unitid, &unit_data); |
| 332 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 333 | if (!line->ops->sign_link_up) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 334 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 335 | "Unable to set signal link, closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 336 | ret = -EINVAL; |
| 337 | goto err; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 338 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 339 | /* the BSC creates the new sign links at this stage. */ |
| 340 | if (bfd->priv_nr == E1INP_SIGN_OML) { |
| 341 | sign_link = |
| 342 | line->ops->sign_link_up(&unit_data, line, |
| 343 | E1INP_SIGN_OML); |
| 344 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 345 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 346 | "Unable to set signal link, " |
| 347 | "closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 348 | ret = -EINVAL; |
| 349 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 350 | } |
| 351 | } else if (bfd->priv_nr == E1INP_SIGN_RSL) { |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 352 | struct e1inp_ts *ts; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 353 | struct osmo_fd *newbfd; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 354 | struct e1inp_line *new_line; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 355 | |
| 356 | sign_link = |
| 357 | line->ops->sign_link_up(&unit_data, line, |
| 358 | E1INP_SIGN_RSL); |
| 359 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 360 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 361 | "Unable to set signal link, " |
| 362 | "closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 363 | ret = -EINVAL; |
| 364 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 365 | } |
Pablo Neira Ayuso | db1c8a7 | 2011-07-08 15:12:03 +0200 | [diff] [blame] | 366 | /* this is a bugtrap, the BSC should be using the |
| 367 | * virtual E1 line used by OML for this RSL link. */ |
| 368 | if (sign_link->ts->line == line) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 369 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | db1c8a7 | 2011-07-08 15:12:03 +0200 | [diff] [blame] | 370 | "Fix your BSC, you should use the " |
| 371 | "E1 line used by the OML link for " |
| 372 | "your RSL link.\n"); |
| 373 | return 0; |
| 374 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 375 | /* Finally, we know which OML link is associated with |
| 376 | * this RSL link, attach it to this socket. */ |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 377 | bfd->data = new_line = sign_link->ts->line; |
| 378 | e1inp_line_get(new_line); |
| 379 | ts = &new_line->ts[E1INP_SIGN_RSL+unit_data.trx_id-1]; |
| 380 | newbfd = &ts->driver.ipaccess.fd; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 381 | |
| 382 | /* get rid of our old temporary bfd */ |
| 383 | memcpy(newbfd, bfd, sizeof(*newbfd)); |
| 384 | newbfd->priv_nr = E1INP_SIGN_RSL + unit_data.trx_id; |
| 385 | osmo_fd_unregister(bfd); |
| 386 | bfd->fd = -1; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 387 | osmo_fd_register(newbfd); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 388 | /* now we can release the dummy RSL line. */ |
| 389 | e1inp_line_put(line); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 390 | } |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 391 | break; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 392 | default: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 393 | LOGP(DLINP, LOGL_ERROR, "Unknown IPA message type\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 394 | ret = -EINVAL; |
| 395 | goto err; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 396 | } |
| 397 | return 0; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 398 | err: |
| 399 | osmo_fd_unregister(bfd); |
| 400 | close(bfd->fd); |
| 401 | bfd->fd = -1; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 402 | e1inp_line_put(line); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 403 | return ret; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 406 | static int handle_ts1_read(struct osmo_fd *bfd) |
| 407 | { |
| 408 | struct e1inp_line *line = bfd->data; |
| 409 | unsigned int ts_nr = bfd->priv_nr; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 410 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 411 | struct e1inp_sign_link *link; |
| 412 | struct ipaccess_head *hh; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 413 | struct msgb *msg; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 414 | int ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 415 | |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 416 | ret = ipa_msg_recv(bfd->fd, &msg); |
| 417 | if (ret < 0) { |
| 418 | LOGP(DLINP, LOGL_NOTICE, "Sign link problems, " |
| 419 | "closing socket. Reason: %s\n", strerror(errno)); |
| 420 | goto err; |
| 421 | } else if (ret == 0) { |
| 422 | LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, dead socket\n"); |
| 423 | goto err; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 424 | } |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 425 | 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] | 426 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 427 | hh = (struct ipaccess_head *) msg->data; |
| 428 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 429 | ipaccess_rcvmsg(line, msg, bfd); |
| 430 | msgb_free(msg); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 431 | return 0; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 432 | } |
| 433 | /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg() |
| 434 | * might have free'd it !!! */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 435 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 436 | link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 437 | if (!link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 438 | LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 439 | "hh->proto=0x%02x\n", hh->proto); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 440 | ret = -EINVAL; |
| 441 | goto err_msg; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 442 | } |
| 443 | msg->dst = link; |
| 444 | |
| 445 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 446 | if (!e1i_ts->line->ops->sign_link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 447 | LOGP(DLINP, LOGL_ERROR, "Fix your application, " |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 448 | "no action set for signalling messages.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 449 | ret = -EINVAL; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 450 | goto err_msg; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 451 | } |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 452 | if (e1i_ts->line->ops->sign_link(msg) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 453 | LOGP(DLINP, LOGL_ERROR, "Bad signalling message," |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 454 | "sign_link returned error\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 455 | ret = -EINVAL; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 456 | goto err; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 457 | } |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 458 | |
| 459 | return 0; |
| 460 | err_msg: |
| 461 | msgb_free(msg); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 462 | err: |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 463 | ipaccess_drop(bfd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 464 | return ret; |
| 465 | } |
| 466 | |
| 467 | void ipaccess_prepend_header_ext(struct msgb *msg, int proto) |
| 468 | { |
| 469 | struct ipaccess_head_ext *hh_ext; |
| 470 | |
| 471 | /* prepend the osmo ip.access header extension */ |
| 472 | hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext)); |
| 473 | hh_ext->proto = proto; |
| 474 | } |
| 475 | |
| 476 | void ipaccess_prepend_header(struct msgb *msg, int proto) |
| 477 | { |
| 478 | struct ipaccess_head *hh; |
| 479 | |
| 480 | /* prepend the ip.access header */ |
| 481 | hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh)); |
| 482 | hh->len = htons(msg->len - sizeof(*hh)); |
| 483 | hh->proto = proto; |
| 484 | } |
| 485 | |
| 486 | static int ts_want_write(struct e1inp_ts *e1i_ts) |
| 487 | { |
| 488 | e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE; |
| 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
Pablo Neira Ayuso | add3ec8 | 2011-07-05 14:45:46 +0200 | [diff] [blame] | 493 | static void ipaccess_close(struct e1inp_sign_link *sign_link) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 494 | { |
Pablo Neira Ayuso | add3ec8 | 2011-07-05 14:45:46 +0200 | [diff] [blame] | 495 | struct e1inp_ts *e1i_ts = sign_link->ts; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 496 | struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd; |
Holger Hans Peter Freyther | 55467f0 | 2011-12-28 19:47:07 +0100 | [diff] [blame] | 497 | return e1inp_close_socket(e1i_ts, sign_link, bfd); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 498 | } |
| 499 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 500 | static void timeout_ts1_write(void *data) |
| 501 | { |
| 502 | struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data; |
| 503 | |
| 504 | /* trigger write of ts1, due to tx delay timer */ |
| 505 | ts_want_write(e1i_ts); |
| 506 | } |
| 507 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 508 | 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] | 509 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 510 | unsigned int ts_nr = bfd->priv_nr; |
| 511 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 512 | struct e1inp_sign_link *sign_link; |
| 513 | struct msgb *msg; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 514 | int ret; |
| 515 | |
| 516 | bfd->when &= ~BSC_FD_WRITE; |
| 517 | |
| 518 | /* get the next msg for this timeslot */ |
| 519 | msg = e1inp_tx_ts(e1i_ts, &sign_link); |
| 520 | if (!msg) { |
| 521 | /* no message after tx delay timer */ |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | switch (sign_link->type) { |
| 526 | case E1INP_SIGN_OML: |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 527 | break; |
| 528 | case E1INP_SIGN_RSL: |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 529 | break; |
| 530 | default: |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 531 | bfd->when |= BSC_FD_WRITE; /* come back for more msg */ |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 532 | ret = -EINVAL; |
| 533 | goto out; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | msg->l2h = msg->data; |
Pablo Neira Ayuso | b9ed7e3 | 2011-07-05 18:31:59 +0200 | [diff] [blame] | 537 | ipaccess_prepend_header(msg, sign_link->tei); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 538 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 539 | DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 540 | |
| 541 | ret = send(bfd->fd, msg->data, msg->len, 0); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 542 | if (ret != msg->len) { |
| 543 | LOGP(DLINP, LOGL_ERROR, "failed to send A-bis IPA signalling " |
| 544 | "message. Reason: %s\n", strerror(errno)); |
| 545 | goto err; |
| 546 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 547 | |
| 548 | /* set tx delay timer for next event */ |
| 549 | e1i_ts->sign.tx_timer.cb = timeout_ts1_write; |
| 550 | e1i_ts->sign.tx_timer.data = e1i_ts; |
| 551 | |
| 552 | /* Reducing this might break the nanoBTS 900 init. */ |
| 553 | osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); |
| 554 | |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 555 | out: |
| 556 | msgb_free(msg); |
| 557 | return ret; |
| 558 | err: |
| 559 | ipaccess_drop(bfd); |
| 560 | msgb_free(msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 561 | return ret; |
| 562 | } |
| 563 | |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 564 | static int handle_ts1_write(struct osmo_fd *bfd) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 565 | { |
| 566 | struct e1inp_line *line = bfd->data; |
| 567 | |
| 568 | return __handle_ts1_write(bfd, line); |
| 569 | } |
| 570 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 571 | static int ipaccess_bts_write_cb(struct ipa_client_conn *link) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 572 | { |
| 573 | struct e1inp_line *line = link->line; |
| 574 | |
| 575 | return __handle_ts1_write(link->ofd, line); |
| 576 | } |
| 577 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 578 | /* 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] | 579 | int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 580 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 581 | int rc = 0; |
| 582 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 583 | if (what & BSC_FD_READ) |
| 584 | rc = handle_ts1_read(bfd); |
| 585 | if (what & BSC_FD_WRITE) |
| 586 | rc = handle_ts1_write(bfd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 587 | |
| 588 | return rc; |
| 589 | } |
| 590 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 591 | static int ipaccess_line_update(struct e1inp_line *line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 592 | |
| 593 | struct e1inp_driver ipaccess_driver = { |
| 594 | .name = "ipa", |
| 595 | .want_write = ts_want_write, |
| 596 | .line_update = ipaccess_line_update, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 597 | .close = ipaccess_close, |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 598 | .default_delay = 0, |
| 599 | }; |
| 600 | |
| 601 | /* callback of the OML listening filedescriptor */ |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 602 | 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] | 603 | { |
| 604 | int ret; |
| 605 | int idx = 0; |
| 606 | int i; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 607 | struct e1inp_line *line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 608 | struct e1inp_ts *e1i_ts; |
| 609 | struct osmo_fd *bfd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 610 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 611 | /* clone virtual E1 line for this new OML link. */ |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 612 | line = e1inp_line_clone(tall_ipa_ctx, link->line); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 613 | if (line == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 614 | LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 615 | return -ENOMEM; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 616 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 617 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 618 | /* create virrtual E1 timeslots for signalling */ |
Pablo Neira Ayuso | 5930185 | 2011-06-27 15:44:23 +0200 | [diff] [blame] | 619 | e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 620 | |
| 621 | /* initialize the fds */ |
| 622 | for (i = 0; i < ARRAY_SIZE(line->ts); ++i) |
| 623 | line->ts[i].driver.ipaccess.fd.fd = -1; |
| 624 | |
| 625 | e1i_ts = &line->ts[idx]; |
| 626 | |
Pablo Neira Ayuso | 93c6201 | 2011-06-26 19:12:47 +0200 | [diff] [blame] | 627 | bfd = &e1i_ts->driver.ipaccess.fd; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 628 | bfd->fd = fd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 629 | bfd->data = line; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 630 | bfd->priv_nr = E1INP_SIGN_OML; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 631 | bfd->cb = ipaccess_fd_cb; |
| 632 | bfd->when = BSC_FD_READ; |
| 633 | ret = osmo_fd_register(bfd); |
| 634 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 635 | LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 636 | goto err_line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 640 | ret = ipaccess_send_id_req(bfd->fd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 641 | if (ret < 0) { |
| 642 | LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", |
| 643 | strerror(errno)); |
| 644 | goto err_socket; |
| 645 | } |
| 646 | return ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 647 | |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 648 | err_socket: |
| 649 | osmo_fd_unregister(bfd); |
| 650 | err_line: |
| 651 | close(bfd->fd); |
| 652 | bfd->fd = -1; |
| 653 | e1inp_line_put(line); |
| 654 | return ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 655 | } |
| 656 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 657 | 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] | 658 | { |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 659 | struct e1inp_line *line; |
| 660 | struct e1inp_ts *e1i_ts; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 661 | struct osmo_fd *bfd; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 662 | int i, ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 663 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 664 | /* 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] | 665 | * allocate a temporary E1 line until we have received ID. */ |
| 666 | line = e1inp_line_clone(tall_ipa_ctx, link->line); |
| 667 | if (line == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 668 | LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 669 | return -ENOMEM; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 670 | } |
| 671 | /* initialize the fds */ |
| 672 | for (i = 0; i < ARRAY_SIZE(line->ts); ++i) |
| 673 | line->ts[i].driver.ipaccess.fd.fd = -1; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 674 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 675 | /* we need this to initialize this in case to avoid crashes in case |
| 676 | * that the socket is closed before we've seen an ID_RESP. */ |
| 677 | e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line); |
| 678 | |
| 679 | e1i_ts = &line->ts[E1INP_SIGN_RSL-1]; |
| 680 | |
| 681 | bfd = &e1i_ts->driver.ipaccess.fd; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 682 | bfd->fd = fd; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 683 | bfd->data = line; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 684 | bfd->priv_nr = E1INP_SIGN_RSL; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 685 | bfd->cb = ipaccess_fd_cb; |
| 686 | bfd->when = BSC_FD_READ; |
| 687 | ret = osmo_fd_register(bfd); |
| 688 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 689 | LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 690 | goto err_line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 691 | } |
| 692 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 693 | ret = ipaccess_send_id_req(bfd->fd); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 694 | if (ret < 0) { |
| 695 | LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", |
| 696 | strerror(errno)); |
| 697 | goto err_socket; |
| 698 | } |
| 699 | return ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 700 | |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 701 | err_socket: |
| 702 | osmo_fd_unregister(bfd); |
| 703 | err_line: |
| 704 | close(bfd->fd); |
| 705 | bfd->fd = -1; |
| 706 | e1inp_line_put(line); |
| 707 | return ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 708 | } |
| 709 | |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 710 | static struct msgb * |
| 711 | ipa_bts_id_resp(struct ipaccess_unit *dev, uint8_t *data, int len) |
| 712 | { |
| 713 | struct msgb *nmsg; |
| 714 | char str[64]; |
| 715 | uint8_t *tag; |
| 716 | |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 717 | nmsg = ipa_msg_alloc(0); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 718 | if (!nmsg) |
| 719 | return NULL; |
| 720 | |
| 721 | *msgb_put(nmsg, 1) = IPAC_MSGT_ID_RESP; |
| 722 | while (len) { |
| 723 | if (len < 2) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 724 | LOGP(DLINP, LOGL_NOTICE, |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 725 | "Short read of ipaccess tag\n"); |
| 726 | msgb_free(nmsg); |
| 727 | return NULL; |
| 728 | } |
| 729 | switch (data[1]) { |
| 730 | case IPAC_IDTAG_UNIT: |
| 731 | sprintf(str, "%u/%u/%u", |
| 732 | dev->site_id, dev->bts_id, dev->trx_id); |
| 733 | break; |
| 734 | case IPAC_IDTAG_MACADDR: |
| 735 | sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 736 | dev->mac_addr[0], dev->mac_addr[1], |
| 737 | dev->mac_addr[2], dev->mac_addr[3], |
| 738 | dev->mac_addr[4], dev->mac_addr[5]); |
| 739 | break; |
| 740 | case IPAC_IDTAG_LOCATION1: |
| 741 | strcpy(str, dev->location1); |
| 742 | break; |
| 743 | case IPAC_IDTAG_LOCATION2: |
| 744 | strcpy(str, dev->location2); |
| 745 | break; |
| 746 | case IPAC_IDTAG_EQUIPVERS: |
| 747 | strcpy(str, dev->equipvers); |
| 748 | break; |
| 749 | case IPAC_IDTAG_SWVERSION: |
| 750 | strcpy(str, dev->swversion); |
| 751 | break; |
| 752 | case IPAC_IDTAG_UNITNAME: |
| 753 | sprintf(str, "%s-%02x-%02x-%02x-%02x-%02x-%02x", |
| 754 | dev->unit_name, |
| 755 | dev->mac_addr[0], dev->mac_addr[1], |
| 756 | dev->mac_addr[2], dev->mac_addr[3], |
| 757 | dev->mac_addr[4], dev->mac_addr[5]); |
| 758 | break; |
| 759 | case IPAC_IDTAG_SERNR: |
| 760 | strcpy(str, dev->serno); |
| 761 | break; |
| 762 | default: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 763 | LOGP(DLINP, LOGL_NOTICE, |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 764 | "Unknown ipaccess tag 0x%02x\n", *data); |
| 765 | msgb_free(nmsg); |
| 766 | return NULL; |
| 767 | } |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 768 | LOGP(DLINP, LOGL_INFO, " tag %d: %s\n", data[1], str); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 769 | tag = msgb_put(nmsg, 3 + strlen(str) + 1); |
| 770 | tag[0] = 0x00; |
| 771 | tag[1] = 1 + strlen(str) + 1; |
| 772 | tag[2] = data[1]; |
| 773 | memcpy(tag + 3, str, strlen(str) + 1); |
| 774 | data += 2; |
| 775 | len -= 2; |
| 776 | } |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 777 | ipa_msg_push_header(nmsg, IPAC_PROTO_IPACCESS); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 778 | return nmsg; |
| 779 | } |
| 780 | |
| 781 | static struct msgb *ipa_bts_id_ack(void) |
| 782 | { |
| 783 | struct msgb *nmsg2; |
| 784 | |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 785 | nmsg2 = ipa_msg_alloc(0); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 786 | if (!nmsg2) |
| 787 | return NULL; |
| 788 | |
| 789 | *msgb_put(nmsg2, 1) = IPAC_MSGT_ID_ACK; |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 790 | ipa_msg_push_header(nmsg2, IPAC_PROTO_IPACCESS); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 791 | |
| 792 | return nmsg2; |
| 793 | } |
| 794 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 795 | static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 796 | { |
| 797 | struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; |
| 798 | struct e1inp_ts *e1i_ts = NULL; |
| 799 | struct e1inp_sign_link *sign_link; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 800 | struct msgb *rmsg; |
| 801 | int ret = 0; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 802 | |
| 803 | /* special handling for IPA CCM. */ |
| 804 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 805 | uint8_t msg_type = *(msg->l2h); |
| 806 | |
| 807 | /* ping, pong and acknowledgment cases. */ |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 808 | ret = ipaccess_rcvmsg_bts_base(msg, link->ofd); |
| 809 | if (ret < 0) |
| 810 | goto err; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 811 | |
| 812 | /* this is a request for identification from the BSC. */ |
| 813 | if (msg_type == IPAC_MSGT_ID_GET) { |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 814 | struct e1inp_sign_link *sign_link; |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 815 | uint8_t *data = msgb_l2(msg); |
| 816 | int len = msgb_l2len(msg); |
| 817 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 818 | LOGP(DLINP, LOGL_NOTICE, "received ID get\n"); |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 819 | if (!link->line->ops->sign_link_up) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 820 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 821 | "Unable to set signal link, " |
| 822 | "closing socket.\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 823 | ret = -EINVAL; |
| 824 | goto err; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 825 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 826 | sign_link = link->line->ops->sign_link_up(msg, |
| 827 | link->line, |
| 828 | link->ofd->priv_nr); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 829 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 830 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 831 | "Unable to set signal link, " |
| 832 | "closing socket.\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 833 | ret = -EINVAL; |
| 834 | goto err; |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 835 | } |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 836 | rmsg = ipa_bts_id_resp(link->line->ops->cfg.ipa.dev, |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 837 | data + 1, len - 1); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 838 | ret = ipaccess_send(link->ofd->fd, rmsg->data, |
| 839 | rmsg->len); |
| 840 | if (ret != rmsg->len) { |
| 841 | LOGP(DLINP, LOGL_ERROR, "cannot send ID_RESP " |
| 842 | "message. Reason: %s\n", strerror(errno)); |
| 843 | goto err_rmsg; |
| 844 | } |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 845 | msgb_free(rmsg); |
| 846 | |
| 847 | /* send ID_ACK. */ |
| 848 | rmsg = ipa_bts_id_ack(); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 849 | ret = ipaccess_send(link->ofd->fd, rmsg->data, |
| 850 | rmsg->len); |
| 851 | if (ret != rmsg->len) { |
| 852 | LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " |
| 853 | "message. Reason: %s\n", strerror(errno)); |
| 854 | goto err_rmsg; |
| 855 | } |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 856 | msgb_free(rmsg); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 857 | } |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 858 | return ret; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 859 | } else if (link->port == IPA_TCP_PORT_OML) |
| 860 | e1i_ts = &link->line->ts[0]; |
| 861 | else if (link->port == IPA_TCP_PORT_RSL) |
| 862 | e1i_ts = &link->line->ts[1]; |
| 863 | |
| 864 | /* look up for some existing signaling link. */ |
| 865 | sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 866 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 867 | LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 868 | "hh->proto=0x%02x\n", hh->proto); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 869 | ret = -EIO; |
| 870 | goto err; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 871 | } |
| 872 | msg->dst = sign_link; |
| 873 | |
| 874 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 875 | if (!link->line->ops->sign_link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 876 | LOGP(DLINP, LOGL_ERROR, "Fix your application, " |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 877 | "no action set for signalling messages.\n"); |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 878 | ret = -ENOENT; |
| 879 | goto err; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 880 | } |
Pablo Neira Ayuso | dbd82fb | 2011-07-05 15:29:23 +0200 | [diff] [blame] | 881 | link->line->ops->sign_link(msg); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 882 | return 0; |
Pablo Neira Ayuso | 1e40194 | 2012-08-22 14:16:24 +0200 | [diff] [blame] | 883 | |
| 884 | err_rmsg: |
| 885 | msgb_free(rmsg); |
| 886 | err: |
| 887 | osmo_fd_unregister(link->ofd); |
| 888 | close(link->ofd->fd); |
| 889 | link->ofd->fd = -1; |
| 890 | msgb_free(msg); |
| 891 | return ret; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Pablo Neira Ayuso | d621640 | 2011-08-31 16:47:44 +0200 | [diff] [blame] | 894 | struct ipaccess_line { |
| 895 | int line_already_initialized; |
| 896 | }; |
| 897 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 898 | static int ipaccess_line_update(struct e1inp_line *line) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 899 | { |
| 900 | int ret = -ENOENT; |
Pablo Neira Ayuso | d621640 | 2011-08-31 16:47:44 +0200 | [diff] [blame] | 901 | struct ipaccess_line *il; |
| 902 | |
| 903 | if (!line->driver_data) |
| 904 | line->driver_data = talloc_zero(line, struct ipaccess_line); |
| 905 | |
| 906 | if (!line->driver_data) { |
| 907 | LOGP(DLINP, LOGL_ERROR, "ipaccess: OOM in line update\n"); |
| 908 | return -ENOMEM; |
| 909 | } |
| 910 | il = line->driver_data; |
| 911 | |
| 912 | /* We only initialize this line once. */ |
| 913 | if (il->line_already_initialized) |
| 914 | return 0; |
| 915 | |
| 916 | il->line_already_initialized = 1; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 917 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 918 | switch(line->ops->cfg.ipa.role) { |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 919 | case E1INP_LINE_R_BSC: { |
| 920 | struct ipa_server_link *oml_link, *rsl_link; |
| 921 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 922 | LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n"); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 923 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 924 | oml_link = ipa_server_link_create(tall_ipa_ctx, line, |
| 925 | "0.0.0.0", IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 926 | ipaccess_bsc_oml_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 927 | if (oml_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 928 | LOGP(DLINP, LOGL_ERROR, "cannot create OML " |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 929 | "BSC link: %s\n", strerror(errno)); |
| 930 | return -ENOMEM; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 931 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 932 | if (ipa_server_link_open(oml_link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 933 | LOGP(DLINP, LOGL_ERROR, "cannot open OML BSC link: %s\n", |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 934 | strerror(errno)); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 935 | ipa_server_link_destroy(oml_link); |
| 936 | return -EIO; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 937 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 938 | rsl_link = ipa_server_link_create(tall_ipa_ctx, line, |
| 939 | "0.0.0.0", IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 940 | ipaccess_bsc_rsl_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 941 | if (rsl_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 942 | LOGP(DLINP, LOGL_ERROR, "cannot create RSL " |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 943 | "BSC link: %s\n", strerror(errno)); |
| 944 | return -ENOMEM; |
| 945 | } |
| 946 | if (ipa_server_link_open(rsl_link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 947 | LOGP(DLINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n", |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 948 | strerror(errno)); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 949 | ipa_server_link_destroy(rsl_link); |
| 950 | return -EIO; |
| 951 | } |
| 952 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 953 | break; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 954 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 955 | case E1INP_LINE_R_BTS: { |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 956 | struct ipa_client_conn *link, *rsl_link; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 957 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 958 | LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BTS mode\n"); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 959 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 960 | link = ipa_client_conn_create(tall_ipa_ctx, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 961 | &line->ts[E1INP_SIGN_OML-1], |
Pablo Neira Ayuso | 00af772 | 2011-09-08 12:47:06 +0200 | [diff] [blame] | 962 | E1INP_SIGN_OML, |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 963 | line->ops->cfg.ipa.addr, |
| 964 | IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 965 | NULL, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 966 | ipaccess_bts_cb, |
| 967 | ipaccess_bts_write_cb, |
| 968 | NULL); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 969 | if (link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 970 | LOGP(DLINP, LOGL_ERROR, "cannot create OML " |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 971 | "BTS link: %s\n", strerror(errno)); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 972 | return -ENOMEM; |
| 973 | } |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 974 | if (ipa_client_conn_open(link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 975 | LOGP(DLINP, LOGL_ERROR, "cannot open OML BTS link: %s\n", |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 976 | strerror(errno)); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 977 | ipa_client_conn_close(link); |
| 978 | ipa_client_conn_destroy(link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 979 | return -EIO; |
| 980 | } |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 981 | rsl_link = ipa_client_conn_create(tall_ipa_ctx, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 982 | &line->ts[E1INP_SIGN_RSL-1], |
Pablo Neira Ayuso | 00af772 | 2011-09-08 12:47:06 +0200 | [diff] [blame] | 983 | E1INP_SIGN_RSL, |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 984 | line->ops->cfg.ipa.addr, |
| 985 | IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 986 | NULL, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 987 | ipaccess_bts_cb, |
| 988 | ipaccess_bts_write_cb, |
| 989 | NULL); |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 990 | if (rsl_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 991 | LOGP(DLINP, LOGL_ERROR, "cannot create RSL " |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 992 | "BTS link: %s\n", strerror(errno)); |
| 993 | return -ENOMEM; |
| 994 | } |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 995 | if (ipa_client_conn_open(rsl_link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 996 | LOGP(DLINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n", |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 997 | strerror(errno)); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 998 | ipa_client_conn_close(rsl_link); |
| 999 | ipa_client_conn_destroy(rsl_link); |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 1000 | return -EIO; |
| 1001 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1002 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1003 | break; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 1004 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1005 | default: |
| 1006 | break; |
| 1007 | } |
| 1008 | return ret; |
| 1009 | } |
| 1010 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1011 | void e1inp_ipaccess_init(void) |
| 1012 | { |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 1013 | tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1014 | e1inp_driver_register(&ipaccess_driver); |
| 1015 | } |