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 | { |
Harald Welte | bc25bca | 2011-08-19 22:32:38 +0200 | [diff] [blame] | 192 | int ipa_ccm = 0; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 193 | uint8_t msg_type = *(msg->l2h); |
| 194 | int ret = 0; |
| 195 | |
| 196 | switch (msg_type) { |
| 197 | case IPAC_MSGT_PING: |
Harald Welte | bc25bca | 2011-08-19 22:32:38 +0200 | [diff] [blame] | 198 | ipa_ccm = 1; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 199 | ret = ipaccess_send_pong(bfd->fd); |
| 200 | break; |
| 201 | case IPAC_MSGT_PONG: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 202 | DEBUGP(DLMI, "PONG!\n"); |
Harald Welte | bc25bca | 2011-08-19 22:32:38 +0200 | [diff] [blame] | 203 | ipa_ccm = 1; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 204 | break; |
| 205 | case IPAC_MSGT_ID_ACK: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 206 | DEBUGP(DLMI, "ID_ACK? -> ACK!\n"); |
Harald Welte | bc25bca | 2011-08-19 22:32:38 +0200 | [diff] [blame] | 207 | ipa_ccm = 1; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 208 | ret = ipaccess_send_id_ack(bfd->fd); |
| 209 | break; |
| 210 | } |
Pablo Neira Ayuso | eb43413 | 2011-07-07 19:19:46 +0200 | [diff] [blame] | 211 | return ipa_ccm; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 214 | /* base handling of the ip.access protocol */ |
| 215 | int ipaccess_rcvmsg_bts_base(struct msgb *msg, |
| 216 | struct osmo_fd *bfd) |
| 217 | { |
| 218 | uint8_t msg_type = *(msg->l2h); |
| 219 | int ret = 0; |
| 220 | |
| 221 | switch (msg_type) { |
| 222 | case IPAC_MSGT_PING: |
| 223 | ret = ipaccess_send_pong(bfd->fd); |
| 224 | break; |
| 225 | case IPAC_MSGT_PONG: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 226 | DEBUGP(DLMI, "PONG!\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 227 | break; |
| 228 | case IPAC_MSGT_ID_ACK: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 229 | DEBUGP(DLMI, "ID_ACK\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 230 | break; |
| 231 | } |
| 232 | return 0; |
| 233 | } |
| 234 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 235 | static int ipaccess_drop(struct osmo_fd *bfd) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 236 | { |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 237 | int ret = 0; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 238 | struct e1inp_line *line = bfd->data; |
| 239 | |
| 240 | /* e1inp_sign_link_destroy releases the socket descriptors for us. */ |
| 241 | line->ops->sign_link_down(line); |
| 242 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 243 | /* Error case: we did not see any ID_RESP yet for this socket. */ |
| 244 | if (bfd->fd != -1) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 245 | LOGP(DLINP, LOGL_ERROR, "Forcing socket shutdown with " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 246 | "no signal link set\n"); |
Pablo Neira Ayuso | 9621b41 | 2011-07-07 16:19:21 +0200 | [diff] [blame] | 247 | osmo_fd_unregister(bfd); |
| 248 | close(bfd->fd); |
| 249 | bfd->fd = -1; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 250 | ret = -ENOENT; |
Pablo Neira Ayuso | 9621b41 | 2011-07-07 16:19:21 +0200 | [diff] [blame] | 251 | } |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 252 | /* put the virtual E1 line that we cloned for this socket, if |
| 253 | * it becomes unused, it gets released. */ |
| 254 | e1inp_line_put(line); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 255 | return ret; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 258 | static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, |
| 259 | struct osmo_fd *bfd) |
| 260 | { |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 261 | struct tlv_parsed tlvp; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 262 | uint8_t msg_type = *(msg->l2h); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 263 | struct ipaccess_unit unit_data = {}; |
| 264 | struct e1inp_sign_link *sign_link; |
| 265 | char *unitid; |
| 266 | int len, ret; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 267 | |
Pablo Neira Ayuso | eb43413 | 2011-07-07 19:19:46 +0200 | [diff] [blame] | 268 | /* Handle IPA PING, PONG and ID_ACK messages. */ |
| 269 | if (ipaccess_rcvmsg_base(msg, bfd)) |
| 270 | return 0; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 271 | |
| 272 | switch (msg_type) { |
| 273 | case IPAC_MSGT_ID_RESP: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 274 | DEBUGP(DLMI, "ID_RESP\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 275 | /* parse tags, search for Unit ID */ |
| 276 | ret = ipaccess_idtag_parse(&tlvp, (uint8_t *)msg->l2h + 2, |
| 277 | msgb_l2len(msg)-2); |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 278 | DEBUGP(DLMI, "\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 279 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 280 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 281 | "with malformed TLVs\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 282 | ret = -EINVAL; |
| 283 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 284 | } |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 285 | if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT)) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 286 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 287 | "without unit ID\n"); |
| 288 | ret = -EINVAL; |
| 289 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 290 | |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 291 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 292 | len = TLVP_LEN(&tlvp, IPAC_IDTAG_UNIT); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 293 | if (len < 1) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 294 | LOGP(DLINP, LOGL_ERROR, "IPA response message " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 295 | "with too small unit ID\n"); |
| 296 | ret = -EINVAL; |
| 297 | goto err; |
| 298 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 299 | unitid = (char *) TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT); |
| 300 | unitid[len - 1] = '\0'; |
| 301 | ipaccess_parse_unitid(unitid, &unit_data); |
| 302 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 303 | if (!line->ops->sign_link_up) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 304 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 305 | "Unable to set signal link, closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 306 | ret = -EINVAL; |
| 307 | goto err; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 308 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 309 | /* the BSC creates the new sign links at this stage. */ |
| 310 | if (bfd->priv_nr == E1INP_SIGN_OML) { |
| 311 | sign_link = |
| 312 | line->ops->sign_link_up(&unit_data, line, |
| 313 | E1INP_SIGN_OML); |
| 314 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 315 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 316 | "Unable to set signal link, " |
| 317 | "closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 318 | ret = -EINVAL; |
| 319 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 320 | } |
| 321 | } else if (bfd->priv_nr == E1INP_SIGN_RSL) { |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 322 | struct e1inp_ts *ts; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 323 | struct osmo_fd *newbfd; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 324 | struct e1inp_line *new_line; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 325 | |
| 326 | sign_link = |
| 327 | line->ops->sign_link_up(&unit_data, line, |
| 328 | E1INP_SIGN_RSL); |
| 329 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 330 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 331 | "Unable to set signal link, " |
| 332 | "closing socket.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 333 | ret = -EINVAL; |
| 334 | goto err; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 335 | } |
Pablo Neira Ayuso | db1c8a7 | 2011-07-08 15:12:03 +0200 | [diff] [blame] | 336 | /* this is a bugtrap, the BSC should be using the |
| 337 | * virtual E1 line used by OML for this RSL link. */ |
| 338 | if (sign_link->ts->line == line) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 339 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | db1c8a7 | 2011-07-08 15:12:03 +0200 | [diff] [blame] | 340 | "Fix your BSC, you should use the " |
| 341 | "E1 line used by the OML link for " |
| 342 | "your RSL link.\n"); |
| 343 | return 0; |
| 344 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 345 | /* Finally, we know which OML link is associated with |
| 346 | * this RSL link, attach it to this socket. */ |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 347 | bfd->data = new_line = sign_link->ts->line; |
| 348 | e1inp_line_get(new_line); |
| 349 | ts = &new_line->ts[E1INP_SIGN_RSL+unit_data.trx_id-1]; |
| 350 | newbfd = &ts->driver.ipaccess.fd; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 351 | |
| 352 | /* get rid of our old temporary bfd */ |
| 353 | memcpy(newbfd, bfd, sizeof(*newbfd)); |
| 354 | newbfd->priv_nr = E1INP_SIGN_RSL + unit_data.trx_id; |
| 355 | osmo_fd_unregister(bfd); |
| 356 | bfd->fd = -1; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 357 | osmo_fd_register(newbfd); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 358 | /* now we can release the dummy RSL line. */ |
| 359 | e1inp_line_put(line); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 360 | } |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 361 | break; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 362 | default: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 363 | LOGP(DLINP, LOGL_ERROR, "Unknown IPA message type\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 364 | ret = -EINVAL; |
| 365 | goto err; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 366 | } |
| 367 | return 0; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 368 | err: |
| 369 | osmo_fd_unregister(bfd); |
| 370 | close(bfd->fd); |
| 371 | bfd->fd = -1; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 372 | e1inp_line_put(line); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 373 | return ret; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 374 | } |
| 375 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 376 | static int handle_ts1_read(struct osmo_fd *bfd) |
| 377 | { |
| 378 | struct e1inp_line *line = bfd->data; |
| 379 | unsigned int ts_nr = bfd->priv_nr; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 380 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 381 | struct e1inp_sign_link *link; |
| 382 | struct ipaccess_head *hh; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 383 | struct msgb *msg; |
| 384 | int ret = 0, error; |
| 385 | |
Pablo Neira Ayuso | 7a24940 | 2011-06-21 14:15:46 +0200 | [diff] [blame] | 386 | error = ipa_msg_recv(bfd->fd, &msg); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 387 | if (error < 0) |
| 388 | return error; |
| 389 | else if (error == 0) { |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 390 | if (ipaccess_drop(bfd) >= 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 391 | LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, " |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 392 | "dead socket\n"); |
| 393 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 394 | return error; |
| 395 | } |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 396 | 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] | 397 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 398 | hh = (struct ipaccess_head *) msg->data; |
| 399 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 400 | ipaccess_rcvmsg(line, msg, bfd); |
| 401 | msgb_free(msg); |
| 402 | return ret; |
| 403 | } |
| 404 | /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg() |
| 405 | * might have free'd it !!! */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 406 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 407 | link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 408 | if (!link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 409 | LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 410 | "hh->proto=0x%02x\n", hh->proto); |
| 411 | msgb_free(msg); |
| 412 | return -EIO; |
| 413 | } |
| 414 | msg->dst = link; |
| 415 | |
| 416 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 417 | if (!e1i_ts->line->ops->sign_link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 418 | LOGP(DLINP, LOGL_ERROR, "Fix your application, " |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 419 | "no action set for signalling messages.\n"); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 420 | ret = -EINVAL; |
| 421 | goto err; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 422 | } |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 423 | if (e1i_ts->line->ops->sign_link(msg) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 424 | LOGP(DLINP, LOGL_ERROR, "Bad signalling message," |
Harald Welte | 36a85a4 | 2012-03-18 18:45:52 +0100 | [diff] [blame] | 425 | "sign_link returned error: %s\n", |
| 426 | osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 427 | ret = -EINVAL; |
Pablo Neira Ayuso | 466c546 | 2011-07-07 19:17:20 +0200 | [diff] [blame] | 428 | } |
| 429 | return ret; |
| 430 | err: |
| 431 | osmo_fd_unregister(bfd); |
| 432 | close(bfd->fd); |
| 433 | bfd->fd = -1; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 434 | e1inp_line_put(line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 435 | return ret; |
| 436 | } |
| 437 | |
| 438 | void ipaccess_prepend_header_ext(struct msgb *msg, int proto) |
| 439 | { |
| 440 | struct ipaccess_head_ext *hh_ext; |
| 441 | |
| 442 | /* prepend the osmo ip.access header extension */ |
| 443 | hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext)); |
| 444 | hh_ext->proto = proto; |
| 445 | } |
| 446 | |
| 447 | void ipaccess_prepend_header(struct msgb *msg, int proto) |
| 448 | { |
| 449 | struct ipaccess_head *hh; |
| 450 | |
| 451 | /* prepend the ip.access header */ |
| 452 | hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh)); |
| 453 | hh->len = htons(msg->len - sizeof(*hh)); |
| 454 | hh->proto = proto; |
| 455 | } |
| 456 | |
| 457 | static int ts_want_write(struct e1inp_ts *e1i_ts) |
| 458 | { |
| 459 | e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE; |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
Pablo Neira Ayuso | add3ec8 | 2011-07-05 14:45:46 +0200 | [diff] [blame] | 464 | static void ipaccess_close(struct e1inp_sign_link *sign_link) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 465 | { |
Pablo Neira Ayuso | add3ec8 | 2011-07-05 14:45:46 +0200 | [diff] [blame] | 466 | struct e1inp_ts *e1i_ts = sign_link->ts; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 467 | struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd; |
Holger Hans Peter Freyther | 55467f0 | 2011-12-28 19:47:07 +0100 | [diff] [blame] | 468 | return e1inp_close_socket(e1i_ts, sign_link, bfd); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 471 | static void timeout_ts1_write(void *data) |
| 472 | { |
| 473 | struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data; |
| 474 | |
| 475 | /* trigger write of ts1, due to tx delay timer */ |
| 476 | ts_want_write(e1i_ts); |
| 477 | } |
| 478 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 479 | 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] | 480 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 481 | unsigned int ts_nr = bfd->priv_nr; |
| 482 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 483 | struct e1inp_sign_link *sign_link; |
| 484 | struct msgb *msg; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 485 | int ret; |
| 486 | |
| 487 | bfd->when &= ~BSC_FD_WRITE; |
| 488 | |
| 489 | /* get the next msg for this timeslot */ |
| 490 | msg = e1inp_tx_ts(e1i_ts, &sign_link); |
| 491 | if (!msg) { |
| 492 | /* no message after tx delay timer */ |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | switch (sign_link->type) { |
| 497 | case E1INP_SIGN_OML: |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 498 | break; |
| 499 | case E1INP_SIGN_RSL: |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 500 | break; |
| 501 | default: |
| 502 | msgb_free(msg); |
| 503 | bfd->when |= BSC_FD_WRITE; /* come back for more msg */ |
| 504 | return -EINVAL; |
| 505 | } |
| 506 | |
| 507 | msg->l2h = msg->data; |
Pablo Neira Ayuso | b9ed7e3 | 2011-07-05 18:31:59 +0200 | [diff] [blame] | 508 | ipaccess_prepend_header(msg, sign_link->tei); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 509 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 510 | 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] | 511 | |
| 512 | ret = send(bfd->fd, msg->data, msg->len, 0); |
| 513 | msgb_free(msg); |
| 514 | |
| 515 | /* set tx delay timer for next event */ |
| 516 | e1i_ts->sign.tx_timer.cb = timeout_ts1_write; |
| 517 | e1i_ts->sign.tx_timer.data = e1i_ts; |
| 518 | |
| 519 | /* Reducing this might break the nanoBTS 900 init. */ |
| 520 | osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); |
| 521 | |
| 522 | return ret; |
| 523 | } |
| 524 | |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 525 | static int handle_ts1_write(struct osmo_fd *bfd) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 526 | { |
| 527 | struct e1inp_line *line = bfd->data; |
| 528 | |
| 529 | return __handle_ts1_write(bfd, line); |
| 530 | } |
| 531 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 532 | static int ipaccess_bts_write_cb(struct ipa_client_conn *link) |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 533 | { |
| 534 | struct e1inp_line *line = link->line; |
| 535 | |
| 536 | return __handle_ts1_write(link->ofd, line); |
| 537 | } |
| 538 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 539 | /* 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] | 540 | int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 541 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 542 | int rc = 0; |
| 543 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 544 | if (what & BSC_FD_READ) |
| 545 | rc = handle_ts1_read(bfd); |
| 546 | if (what & BSC_FD_WRITE) |
| 547 | rc = handle_ts1_write(bfd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 548 | |
| 549 | return rc; |
| 550 | } |
| 551 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 552 | static int ipaccess_line_update(struct e1inp_line *line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 553 | |
| 554 | struct e1inp_driver ipaccess_driver = { |
| 555 | .name = "ipa", |
| 556 | .want_write = ts_want_write, |
| 557 | .line_update = ipaccess_line_update, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 558 | .close = ipaccess_close, |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 559 | .default_delay = 0, |
| 560 | }; |
| 561 | |
| 562 | /* callback of the OML listening filedescriptor */ |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 563 | 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] | 564 | { |
| 565 | int ret; |
| 566 | int idx = 0; |
| 567 | int i; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 568 | struct e1inp_line *line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 569 | struct e1inp_ts *e1i_ts; |
| 570 | struct osmo_fd *bfd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 571 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 572 | /* clone virtual E1 line for this new OML link. */ |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 573 | line = e1inp_line_clone(tall_ipa_ctx, link->line); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 574 | if (line == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 575 | LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 576 | return -1; |
| 577 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 578 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 579 | /* create virrtual E1 timeslots for signalling */ |
Pablo Neira Ayuso | 5930185 | 2011-06-27 15:44:23 +0200 | [diff] [blame] | 580 | e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 581 | |
| 582 | /* initialize the fds */ |
| 583 | for (i = 0; i < ARRAY_SIZE(line->ts); ++i) |
| 584 | line->ts[i].driver.ipaccess.fd.fd = -1; |
| 585 | |
| 586 | e1i_ts = &line->ts[idx]; |
| 587 | |
Pablo Neira Ayuso | 93c6201 | 2011-06-26 19:12:47 +0200 | [diff] [blame] | 588 | bfd = &e1i_ts->driver.ipaccess.fd; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 589 | bfd->fd = fd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 590 | bfd->data = line; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 591 | bfd->priv_nr = E1INP_SIGN_OML; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 592 | bfd->cb = ipaccess_fd_cb; |
| 593 | bfd->when = BSC_FD_READ; |
| 594 | ret = osmo_fd_register(bfd); |
| 595 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 596 | LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 597 | close(bfd->fd); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 598 | e1inp_line_put(line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 599 | return ret; |
| 600 | } |
| 601 | |
| 602 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 603 | ret = ipaccess_send_id_req(bfd->fd); |
| 604 | |
| 605 | return ret; |
| 606 | } |
| 607 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 608 | 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] | 609 | { |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 610 | struct e1inp_line *line; |
| 611 | struct e1inp_ts *e1i_ts; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 612 | struct osmo_fd *bfd; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 613 | int i, ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 614 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 615 | /* 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] | 616 | * allocate a temporary E1 line until we have received ID. */ |
| 617 | line = e1inp_line_clone(tall_ipa_ctx, link->line); |
| 618 | if (line == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 619 | LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 620 | return -1; |
| 621 | } |
| 622 | /* initialize the fds */ |
| 623 | for (i = 0; i < ARRAY_SIZE(line->ts); ++i) |
| 624 | line->ts[i].driver.ipaccess.fd.fd = -1; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 625 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 626 | /* we need this to initialize this in case to avoid crashes in case |
| 627 | * that the socket is closed before we've seen an ID_RESP. */ |
| 628 | e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line); |
| 629 | |
| 630 | e1i_ts = &line->ts[E1INP_SIGN_RSL-1]; |
| 631 | |
| 632 | bfd = &e1i_ts->driver.ipaccess.fd; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 633 | bfd->fd = fd; |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 634 | bfd->data = line; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 635 | bfd->priv_nr = E1INP_SIGN_RSL; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 636 | bfd->cb = ipaccess_fd_cb; |
| 637 | bfd->when = BSC_FD_READ; |
| 638 | ret = osmo_fd_register(bfd); |
| 639 | if (ret < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 640 | LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 641 | close(bfd->fd); |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 642 | e1inp_line_put(line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 643 | return ret; |
| 644 | } |
| 645 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 646 | ret = ipaccess_send_id_req(bfd->fd); |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 651 | static struct msgb * |
| 652 | ipa_bts_id_resp(struct ipaccess_unit *dev, uint8_t *data, int len) |
| 653 | { |
| 654 | struct msgb *nmsg; |
| 655 | char str[64]; |
| 656 | uint8_t *tag; |
| 657 | |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 658 | nmsg = ipa_msg_alloc(0); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 659 | if (!nmsg) |
| 660 | return NULL; |
| 661 | |
| 662 | *msgb_put(nmsg, 1) = IPAC_MSGT_ID_RESP; |
| 663 | while (len) { |
| 664 | if (len < 2) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 665 | LOGP(DLINP, LOGL_NOTICE, |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 666 | "Short read of ipaccess tag\n"); |
| 667 | msgb_free(nmsg); |
| 668 | return NULL; |
| 669 | } |
| 670 | switch (data[1]) { |
| 671 | case IPAC_IDTAG_UNIT: |
| 672 | sprintf(str, "%u/%u/%u", |
| 673 | dev->site_id, dev->bts_id, dev->trx_id); |
| 674 | break; |
| 675 | case IPAC_IDTAG_MACADDR: |
| 676 | sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 677 | dev->mac_addr[0], dev->mac_addr[1], |
| 678 | dev->mac_addr[2], dev->mac_addr[3], |
| 679 | dev->mac_addr[4], dev->mac_addr[5]); |
| 680 | break; |
| 681 | case IPAC_IDTAG_LOCATION1: |
| 682 | strcpy(str, dev->location1); |
| 683 | break; |
| 684 | case IPAC_IDTAG_LOCATION2: |
| 685 | strcpy(str, dev->location2); |
| 686 | break; |
| 687 | case IPAC_IDTAG_EQUIPVERS: |
| 688 | strcpy(str, dev->equipvers); |
| 689 | break; |
| 690 | case IPAC_IDTAG_SWVERSION: |
| 691 | strcpy(str, dev->swversion); |
| 692 | break; |
| 693 | case IPAC_IDTAG_UNITNAME: |
| 694 | sprintf(str, "%s-%02x-%02x-%02x-%02x-%02x-%02x", |
| 695 | dev->unit_name, |
| 696 | dev->mac_addr[0], dev->mac_addr[1], |
| 697 | dev->mac_addr[2], dev->mac_addr[3], |
| 698 | dev->mac_addr[4], dev->mac_addr[5]); |
| 699 | break; |
| 700 | case IPAC_IDTAG_SERNR: |
| 701 | strcpy(str, dev->serno); |
| 702 | break; |
| 703 | default: |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 704 | LOGP(DLINP, LOGL_NOTICE, |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 705 | "Unknown ipaccess tag 0x%02x\n", *data); |
| 706 | msgb_free(nmsg); |
| 707 | return NULL; |
| 708 | } |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 709 | LOGP(DLINP, LOGL_INFO, " tag %d: %s\n", data[1], str); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 710 | tag = msgb_put(nmsg, 3 + strlen(str) + 1); |
| 711 | tag[0] = 0x00; |
| 712 | tag[1] = 1 + strlen(str) + 1; |
| 713 | tag[2] = data[1]; |
| 714 | memcpy(tag + 3, str, strlen(str) + 1); |
| 715 | data += 2; |
| 716 | len -= 2; |
| 717 | } |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 718 | ipa_msg_push_header(nmsg, IPAC_PROTO_IPACCESS); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 719 | return nmsg; |
| 720 | } |
| 721 | |
| 722 | static struct msgb *ipa_bts_id_ack(void) |
| 723 | { |
| 724 | struct msgb *nmsg2; |
| 725 | |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 726 | nmsg2 = ipa_msg_alloc(0); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 727 | if (!nmsg2) |
| 728 | return NULL; |
| 729 | |
| 730 | *msgb_put(nmsg2, 1) = IPAC_MSGT_ID_ACK; |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 731 | ipa_msg_push_header(nmsg2, IPAC_PROTO_IPACCESS); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 732 | |
| 733 | return nmsg2; |
| 734 | } |
| 735 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 736 | 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] | 737 | { |
| 738 | struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; |
| 739 | struct e1inp_ts *e1i_ts = NULL; |
| 740 | struct e1inp_sign_link *sign_link; |
| 741 | |
| 742 | /* special handling for IPA CCM. */ |
| 743 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 744 | uint8_t msg_type = *(msg->l2h); |
| 745 | |
| 746 | /* ping, pong and acknowledgment cases. */ |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 747 | ipaccess_rcvmsg_bts_base(msg, link->ofd); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 748 | |
| 749 | /* this is a request for identification from the BSC. */ |
| 750 | if (msg_type == IPAC_MSGT_ID_GET) { |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 751 | struct e1inp_sign_link *sign_link; |
| 752 | struct msgb *rmsg; |
| 753 | uint8_t *data = msgb_l2(msg); |
| 754 | int len = msgb_l2len(msg); |
| 755 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 756 | LOGP(DLINP, LOGL_NOTICE, "received ID get\n"); |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 757 | if (!link->line->ops->sign_link_up) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 758 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 759 | "Unable to set signal link, " |
| 760 | "closing socket.\n"); |
| 761 | osmo_fd_unregister(link->ofd); |
| 762 | close(link->ofd->fd); |
| 763 | link->ofd->fd = -1; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 764 | return -EINVAL; |
| 765 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 766 | sign_link = link->line->ops->sign_link_up(msg, |
| 767 | link->line, |
| 768 | link->ofd->priv_nr); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 769 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 770 | LOGP(DLINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 771 | "Unable to set signal link, " |
| 772 | "closing socket.\n"); |
| 773 | osmo_fd_unregister(link->ofd); |
| 774 | close(link->ofd->fd); |
| 775 | link->ofd->fd = -1; |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 776 | return -EINVAL; |
| 777 | } |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 778 | rmsg = ipa_bts_id_resp(link->line->ops->cfg.ipa.dev, |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 779 | data + 1, len - 1); |
| 780 | ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); |
| 781 | msgb_free(rmsg); |
| 782 | |
| 783 | /* send ID_ACK. */ |
| 784 | rmsg = ipa_bts_id_ack(); |
| 785 | ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); |
| 786 | msgb_free(rmsg); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 787 | } |
| 788 | return 0; |
| 789 | } else if (link->port == IPA_TCP_PORT_OML) |
| 790 | e1i_ts = &link->line->ts[0]; |
| 791 | else if (link->port == IPA_TCP_PORT_RSL) |
| 792 | e1i_ts = &link->line->ts[1]; |
| 793 | |
| 794 | /* look up for some existing signaling link. */ |
| 795 | sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 796 | if (sign_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 797 | LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 798 | "hh->proto=0x%02x\n", hh->proto); |
| 799 | msgb_free(msg); |
| 800 | return -EIO; |
| 801 | } |
| 802 | msg->dst = sign_link; |
| 803 | |
| 804 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 805 | if (!link->line->ops->sign_link) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 806 | LOGP(DLINP, LOGL_ERROR, "Fix your application, " |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 807 | "no action set for signalling messages.\n"); |
| 808 | return -ENOENT; |
| 809 | } |
Pablo Neira Ayuso | dbd82fb | 2011-07-05 15:29:23 +0200 | [diff] [blame] | 810 | link->line->ops->sign_link(msg); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 811 | return 0; |
| 812 | } |
| 813 | |
Pablo Neira Ayuso | d621640 | 2011-08-31 16:47:44 +0200 | [diff] [blame] | 814 | struct ipaccess_line { |
| 815 | int line_already_initialized; |
| 816 | }; |
| 817 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 818 | static int ipaccess_line_update(struct e1inp_line *line) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 819 | { |
| 820 | int ret = -ENOENT; |
Pablo Neira Ayuso | d621640 | 2011-08-31 16:47:44 +0200 | [diff] [blame] | 821 | struct ipaccess_line *il; |
| 822 | |
| 823 | if (!line->driver_data) |
| 824 | line->driver_data = talloc_zero(line, struct ipaccess_line); |
| 825 | |
| 826 | if (!line->driver_data) { |
| 827 | LOGP(DLINP, LOGL_ERROR, "ipaccess: OOM in line update\n"); |
| 828 | return -ENOMEM; |
| 829 | } |
| 830 | il = line->driver_data; |
| 831 | |
| 832 | /* We only initialize this line once. */ |
| 833 | if (il->line_already_initialized) |
| 834 | return 0; |
| 835 | |
| 836 | il->line_already_initialized = 1; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 837 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 838 | switch(line->ops->cfg.ipa.role) { |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 839 | case E1INP_LINE_R_BSC: { |
| 840 | struct ipa_server_link *oml_link, *rsl_link; |
| 841 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 842 | LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n"); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 843 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 844 | oml_link = ipa_server_link_create(tall_ipa_ctx, line, |
| 845 | "0.0.0.0", IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 846 | ipaccess_bsc_oml_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 847 | if (oml_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 848 | LOGP(DLINP, LOGL_ERROR, "cannot create OML " |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 849 | "BSC link: %s\n", strerror(errno)); |
| 850 | return -ENOMEM; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 851 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 852 | if (ipa_server_link_open(oml_link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 853 | LOGP(DLINP, LOGL_ERROR, "cannot open OML BSC link: %s\n", |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 854 | strerror(errno)); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 855 | ipa_server_link_destroy(oml_link); |
| 856 | return -EIO; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 857 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 858 | rsl_link = ipa_server_link_create(tall_ipa_ctx, line, |
| 859 | "0.0.0.0", IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 860 | ipaccess_bsc_rsl_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 861 | if (rsl_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 862 | LOGP(DLINP, LOGL_ERROR, "cannot create RSL " |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 863 | "BSC link: %s\n", strerror(errno)); |
| 864 | return -ENOMEM; |
| 865 | } |
| 866 | if (ipa_server_link_open(rsl_link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 867 | LOGP(DLINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n", |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 868 | strerror(errno)); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 869 | ipa_server_link_destroy(rsl_link); |
| 870 | return -EIO; |
| 871 | } |
| 872 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 873 | break; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 874 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 875 | case E1INP_LINE_R_BTS: { |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 876 | struct ipa_client_conn *link, *rsl_link; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 877 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 878 | LOGP(DLINP, LOGL_NOTICE, "enabling ipaccess BTS mode\n"); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 879 | |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 880 | link = ipa_client_conn_create(tall_ipa_ctx, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 881 | &line->ts[E1INP_SIGN_OML-1], |
Pablo Neira Ayuso | 00af772 | 2011-09-08 12:47:06 +0200 | [diff] [blame] | 882 | E1INP_SIGN_OML, |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 883 | line->ops->cfg.ipa.addr, |
| 884 | IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 885 | NULL, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 886 | ipaccess_bts_cb, |
| 887 | ipaccess_bts_write_cb, |
| 888 | NULL); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 889 | if (link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 890 | LOGP(DLINP, LOGL_ERROR, "cannot create OML " |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 891 | "BTS link: %s\n", strerror(errno)); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 892 | return -ENOMEM; |
| 893 | } |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 894 | if (ipa_client_conn_open(link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 895 | LOGP(DLINP, LOGL_ERROR, "cannot open OML BTS link: %s\n", |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 896 | strerror(errno)); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 897 | ipa_client_conn_close(link); |
| 898 | ipa_client_conn_destroy(link); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 899 | return -EIO; |
| 900 | } |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 901 | rsl_link = ipa_client_conn_create(tall_ipa_ctx, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 902 | &line->ts[E1INP_SIGN_RSL-1], |
Pablo Neira Ayuso | 00af772 | 2011-09-08 12:47:06 +0200 | [diff] [blame] | 903 | E1INP_SIGN_RSL, |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 904 | line->ops->cfg.ipa.addr, |
| 905 | IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | 88136fc | 2011-07-08 16:21:55 +0200 | [diff] [blame] | 906 | NULL, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 907 | ipaccess_bts_cb, |
| 908 | ipaccess_bts_write_cb, |
| 909 | NULL); |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 910 | if (rsl_link == NULL) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 911 | LOGP(DLINP, LOGL_ERROR, "cannot create RSL " |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 912 | "BTS link: %s\n", strerror(errno)); |
| 913 | return -ENOMEM; |
| 914 | } |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 915 | if (ipa_client_conn_open(rsl_link) < 0) { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 916 | LOGP(DLINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n", |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 917 | strerror(errno)); |
Pablo Neira Ayuso | f099567 | 2011-09-08 12:58:38 +0200 | [diff] [blame] | 918 | ipa_client_conn_close(rsl_link); |
| 919 | ipa_client_conn_destroy(rsl_link); |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 920 | return -EIO; |
| 921 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 922 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 923 | break; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 924 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 925 | default: |
| 926 | break; |
| 927 | } |
| 928 | return ret; |
| 929 | } |
| 930 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 931 | void e1inp_ipaccess_init(void) |
| 932 | { |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 933 | tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 934 | e1inp_driver_register(&ipaccess_driver); |
| 935 | } |