Harald Welte | 936f672 | 2016-05-03 18:51:18 +0200 | [diff] [blame] | 1 | /* (C) 2016 by Harald Welte <laforge@gnumonks.org> |
| 2 | * |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU Affero General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 20 | #include <errno.h> |
| 21 | |
| 22 | #include <osmocom/core/msgb.h> |
| 23 | #include <osmocom/core/logging.h> |
| 24 | #include <osmocom/core/linuxlist.h> |
| 25 | #include <osmocom/abis/ipa.h> |
| 26 | #include <osmocom/abis/ipaccess.h> |
Stefan Sperling | f83432c | 2018-05-03 14:26:59 +0200 | [diff] [blame] | 27 | #include <osmocom/gsm/gsm48_ie.h> |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 28 | #include <osmocom/gsm/apn.h> |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 29 | |
| 30 | #include "gsup_server.h" |
Neels Hofmeyr | 6eed322 | 2016-12-11 01:21:49 +0100 | [diff] [blame] | 31 | #include "gsup_router.h" |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 32 | |
| 33 | static void osmo_gsup_server_send(struct osmo_gsup_conn *conn, |
| 34 | int proto_ext, struct msgb *msg_tx) |
| 35 | { |
| 36 | ipa_prepend_header_ext(msg_tx, proto_ext); |
| 37 | ipa_msg_push_header(msg_tx, IPAC_PROTO_OSMO); |
| 38 | ipa_server_conn_send(conn->conn, msg_tx); |
| 39 | } |
| 40 | |
| 41 | int osmo_gsup_conn_send(struct osmo_gsup_conn *conn, struct msgb *msg) |
| 42 | { |
| 43 | if (!conn) { |
| 44 | msgb_free(msg); |
| 45 | return -ENOTCONN; |
| 46 | } |
| 47 | |
| 48 | osmo_gsup_server_send(conn, IPAC_PROTO_EXT_GSUP, msg); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int osmo_gsup_conn_oap_handle(struct osmo_gsup_conn *conn, |
| 54 | struct msgb *msg_rx) |
| 55 | { |
Neels Hofmeyr | ec1b959 | 2016-12-11 01:22:23 +0100 | [diff] [blame] | 56 | #if 0 |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 57 | int rc; |
| 58 | struct msgb *msg_tx; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 59 | rc = oap_handle(&conn->oap_state, msg_rx, &msg_tx); |
| 60 | msgb_free(msg_rx); |
| 61 | if (rc < 0) |
| 62 | return rc; |
| 63 | |
| 64 | if (msg_tx) |
| 65 | osmo_gsup_conn_send(conn, IPAC_PROTO_EXT_OAP, msg_tx); |
| 66 | #endif |
| 67 | return 0; |
| 68 | } |
| 69 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 70 | /* Data from a given client has arrived over the socket */ |
| 71 | static int osmo_gsup_server_read_cb(struct ipa_server_conn *conn, |
| 72 | struct msgb *msg) |
| 73 | { |
| 74 | struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; |
| 75 | struct ipaccess_head_ext *he = (struct ipaccess_head_ext *) msgb_l2(msg); |
| 76 | struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data; |
| 77 | int rc; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 78 | |
| 79 | msg->l2h = &hh->data[0]; |
| 80 | |
Harald Welte | 173afdb | 2016-04-28 08:53:25 +0200 | [diff] [blame] | 81 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 82 | rc = ipa_server_conn_ccm(conn, msg); |
| 83 | if (rc < 0) { |
| 84 | /* conn is already invalid here! */ |
Harald Welte | 173afdb | 2016-04-28 08:53:25 +0200 | [diff] [blame] | 85 | return -1; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 86 | } |
Harald Welte | 5341b5d | 2016-04-28 12:48:39 +0200 | [diff] [blame] | 87 | msgb_free(msg); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 90 | |
Harald Welte | f2d96da | 2016-04-28 11:13:15 +0200 | [diff] [blame] | 91 | if (hh->proto != IPAC_PROTO_OSMO) { |
| 92 | LOGP(DLGSUP, LOGL_NOTICE, "Unsupported IPA stream ID 0x%02x\n", |
| 93 | hh->proto); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 94 | goto invalid; |
Harald Welte | f2d96da | 2016-04-28 11:13:15 +0200 | [diff] [blame] | 95 | } |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 96 | |
Harald Welte | f2d96da | 2016-04-28 11:13:15 +0200 | [diff] [blame] | 97 | if (!he || msgb_l2len(msg) < sizeof(*he)) { |
| 98 | LOGP(DLGSUP, LOGL_NOTICE, "short IPA message\n"); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 99 | goto invalid; |
Harald Welte | f2d96da | 2016-04-28 11:13:15 +0200 | [diff] [blame] | 100 | } |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 101 | |
| 102 | msg->l2h = &he->data[0]; |
| 103 | |
| 104 | if (he->proto == IPAC_PROTO_EXT_GSUP) { |
| 105 | OSMO_ASSERT(clnt->server->read_cb != NULL); |
| 106 | clnt->server->read_cb(clnt, msg); |
| 107 | /* expecting read_cb() to free msg */ |
| 108 | } else if (he->proto == IPAC_PROTO_EXT_OAP) { |
| 109 | return osmo_gsup_conn_oap_handle(clnt, msg); |
| 110 | /* osmo_gsup_client_oap_handle frees msg */ |
Harald Welte | f2d96da | 2016-04-28 11:13:15 +0200 | [diff] [blame] | 111 | } else { |
| 112 | LOGP(DLGSUP, LOGL_NOTICE, "Unsupported IPA Osmo Proto 0x%02x\n", |
| 113 | hh->proto); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 114 | goto invalid; |
Harald Welte | f2d96da | 2016-04-28 11:13:15 +0200 | [diff] [blame] | 115 | } |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | |
| 119 | invalid: |
| 120 | LOGP(DLGSUP, LOGL_NOTICE, |
Harald Welte | f2d96da | 2016-04-28 11:13:15 +0200 | [diff] [blame] | 121 | "GSUP received an invalid IPA message from %s:%d: %s\n", |
| 122 | conn->addr, conn->port, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 123 | msgb_free(msg); |
| 124 | return -1; |
| 125 | |
| 126 | } |
| 127 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 128 | static void osmo_tlvp_dump(const struct tlv_parsed *tlvp, |
| 129 | int subsys, int level) |
| 130 | { |
| 131 | unsigned int i; |
| 132 | |
| 133 | for (i = 0; i < ARRAY_SIZE(tlvp->lv); i++) { |
| 134 | if (!TLVP_PRESENT(tlvp, i)) |
| 135 | continue; |
| 136 | |
| 137 | LOGP(subsys, level, "%u: %s\n", i, |
| 138 | TLVP_VAL(tlvp, i)); |
| 139 | LOGP(subsys, level, "%u: %s\n", i, |
| 140 | osmo_hexdump(TLVP_VAL(tlvp, i), |
| 141 | TLVP_LEN(tlvp, i))); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /* FIXME: should this be parrt of ipas_server handling, not GSUP? */ |
| 146 | static void tlvp_copy(void *ctx, struct tlv_parsed *out, const struct tlv_parsed *in) |
| 147 | { |
| 148 | unsigned int i; |
| 149 | |
| 150 | for (i = 0; i < ARRAY_SIZE(out->lv); i++) { |
| 151 | if (!TLVP_PRESENT(in, i)) { |
| 152 | if (TLVP_PRESENT(out, i)) { |
| 153 | talloc_free((void *) out->lv[i].val); |
| 154 | out->lv[i].val = NULL; |
| 155 | out->lv[i].len = 0; |
| 156 | } |
| 157 | continue; |
| 158 | } |
| 159 | out->lv[i].val = talloc_memdup(ctx, in->lv[i].val, in->lv[i].len); |
| 160 | out->lv[i].len = in->lv[i].len; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | int osmo_gsup_conn_ccm_get(const struct osmo_gsup_conn *clnt, uint8_t **addr, |
| 165 | uint8_t tag) |
| 166 | { |
| 167 | if (!TLVP_PRESENT(&clnt->ccm, tag)) |
| 168 | return -ENODEV; |
| 169 | *addr = (uint8_t *) TLVP_VAL(&clnt->ccm, tag); |
| 170 | |
| 171 | return TLVP_LEN(&clnt->ccm, tag); |
| 172 | } |
| 173 | |
Harald Welte | 173afdb | 2016-04-28 08:53:25 +0200 | [diff] [blame] | 174 | static int osmo_gsup_server_ccm_cb(struct ipa_server_conn *conn, |
| 175 | struct msgb *msg, struct tlv_parsed *tlvp, |
| 176 | struct ipaccess_unit *unit) |
| 177 | { |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 178 | struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data; |
Neels Hofmeyr | ec1b959 | 2016-12-11 01:22:23 +0100 | [diff] [blame] | 179 | uint8_t *addr = NULL; |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 180 | size_t addr_len; |
| 181 | |
Harald Welte | 173afdb | 2016-04-28 08:53:25 +0200 | [diff] [blame] | 182 | LOGP(DLGSUP, LOGL_INFO, "CCM Callback\n"); |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 183 | |
| 184 | /* FIXME: should this be parrt of ipas_server handling, not |
| 185 | * GSUP? */ |
| 186 | tlvp_copy(clnt, &clnt->ccm, tlvp); |
| 187 | osmo_tlvp_dump(tlvp, DLGSUP, LOGL_INFO); |
| 188 | |
| 189 | addr_len = osmo_gsup_conn_ccm_get(clnt, &addr, IPAC_IDTAG_SERNR); |
Neels Hofmeyr | 5ecdc56 | 2017-02-24 06:38:04 +0100 | [diff] [blame] | 190 | if (addr_len <= 0) { |
| 191 | LOGP(DLGSUP, LOGL_ERROR, "GSUP client %s:%u has no %s IE and" |
| 192 | " cannot be routed\n", |
| 193 | conn->addr, conn->port, |
| 194 | ipa_ccm_idtag_name(IPAC_IDTAG_SERNR)); |
| 195 | return -EINVAL; |
| 196 | } |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 197 | |
Neels Hofmeyr | 5ecdc56 | 2017-02-24 06:38:04 +0100 | [diff] [blame] | 198 | gsup_route_add(clnt, addr, addr_len); |
Harald Welte | 173afdb | 2016-04-28 08:53:25 +0200 | [diff] [blame] | 199 | return 0; |
| 200 | } |
| 201 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 202 | static int osmo_gsup_server_closed_cb(struct ipa_server_conn *conn) |
| 203 | { |
| 204 | struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data; |
| 205 | |
| 206 | LOGP(DLGSUP, LOGL_INFO, "Lost GSUP client %s:%d\n", |
| 207 | conn->addr, conn->port); |
| 208 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 209 | gsup_route_del_conn(clnt); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 210 | llist_del(&clnt->list); |
Harald Welte | a7617e9 | 2016-04-28 12:57:10 +0200 | [diff] [blame] | 211 | talloc_free(clnt); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 216 | /* Add conn to the clients list in a way that conn->auc_3g_ind takes the lowest |
| 217 | * unused integer and the list of clients remains sorted by auc_3g_ind. |
| 218 | * Keep this function non-static to allow linking in a unit test. */ |
| 219 | void osmo_gsup_server_add_conn(struct llist_head *clients, |
| 220 | struct osmo_gsup_conn *conn) |
| 221 | { |
| 222 | struct osmo_gsup_conn *c; |
| 223 | struct osmo_gsup_conn *prev_conn; |
| 224 | |
| 225 | c = llist_first_entry_or_null(clients, struct osmo_gsup_conn, list); |
| 226 | |
| 227 | /* Is the first index, 0, unused? */ |
| 228 | if (!c || c->auc_3g_ind > 0) { |
| 229 | conn->auc_3g_ind = 0; |
| 230 | llist_add(&conn->list, clients); |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | /* Look for a gap later on */ |
| 235 | prev_conn = NULL; |
| 236 | llist_for_each_entry(c, clients, list) { |
| 237 | /* skip first item, we know it has auc_3g_ind == 0. */ |
| 238 | if (!prev_conn) { |
| 239 | prev_conn = c; |
| 240 | continue; |
| 241 | } |
| 242 | if (c->auc_3g_ind > prev_conn->auc_3g_ind + 1) |
| 243 | break; |
| 244 | prev_conn = c; |
| 245 | } |
| 246 | |
| 247 | OSMO_ASSERT(prev_conn); |
| 248 | |
| 249 | conn->auc_3g_ind = prev_conn->auc_3g_ind + 1; |
| 250 | llist_add(&conn->list, &prev_conn->list); |
| 251 | } |
| 252 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 253 | /* a client has connected to the server socket and we have accept()ed it */ |
| 254 | static int osmo_gsup_server_accept_cb(struct ipa_server_link *link, int fd) |
| 255 | { |
| 256 | struct osmo_gsup_conn *conn; |
| 257 | struct osmo_gsup_server *gsups = |
| 258 | (struct osmo_gsup_server *) link->data; |
Harald Welte | 173afdb | 2016-04-28 08:53:25 +0200 | [diff] [blame] | 259 | int rc; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 260 | |
Harald Welte | a7617e9 | 2016-04-28 12:57:10 +0200 | [diff] [blame] | 261 | conn = talloc_zero(gsups, struct osmo_gsup_conn); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 262 | OSMO_ASSERT(conn); |
| 263 | |
Harald Welte | a7617e9 | 2016-04-28 12:57:10 +0200 | [diff] [blame] | 264 | conn->conn = ipa_server_conn_create(gsups, link, fd, |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 265 | osmo_gsup_server_read_cb, |
| 266 | osmo_gsup_server_closed_cb, conn); |
| 267 | OSMO_ASSERT(conn->conn); |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 268 | conn->conn->ccm_cb = osmo_gsup_server_ccm_cb; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 269 | |
| 270 | /* link data structure with server structure */ |
| 271 | conn->server = gsups; |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 272 | osmo_gsup_server_add_conn(&gsups->clients, conn); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 273 | |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 274 | LOGP(DLGSUP, LOGL_INFO, "New GSUP client %s:%d (IND=%u)\n", |
| 275 | conn->conn->addr, conn->conn->port, conn->auc_3g_ind); |
Harald Welte | 173afdb | 2016-04-28 08:53:25 +0200 | [diff] [blame] | 276 | |
| 277 | /* request the identity of the client */ |
| 278 | rc = ipa_ccm_send_id_req(fd); |
| 279 | if (rc < 0) |
| 280 | goto failed; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 281 | #if 0 |
| 282 | rc = oap_init(&gsups->oap_config, &conn->oap_state); |
| 283 | if (rc != 0) |
| 284 | goto failed; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 285 | #endif |
| 286 | return 0; |
Harald Welte | 173afdb | 2016-04-28 08:53:25 +0200 | [diff] [blame] | 287 | failed: |
| 288 | ipa_server_conn_destroy(conn->conn); |
| 289 | return -1; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | struct osmo_gsup_server * |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 293 | osmo_gsup_server_create(void *ctx, const char *ip_addr, uint16_t tcp_port, |
| 294 | osmo_gsup_read_cb_t read_cb, |
Harald Welte | 32acace | 2018-06-16 17:07:28 +0200 | [diff] [blame] | 295 | struct llist_head *lu_op_lst, void *priv) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 296 | { |
| 297 | struct osmo_gsup_server *gsups; |
| 298 | int rc; |
| 299 | |
| 300 | gsups = talloc_zero(ctx, struct osmo_gsup_server); |
| 301 | OSMO_ASSERT(gsups); |
| 302 | |
| 303 | INIT_LLIST_HEAD(&gsups->clients); |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 304 | INIT_LLIST_HEAD(&gsups->routes); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 305 | |
| 306 | gsups->link = ipa_server_link_create(gsups, |
| 307 | /* no e1inp */ NULL, |
| 308 | ip_addr, tcp_port, |
| 309 | osmo_gsup_server_accept_cb, |
| 310 | gsups); |
| 311 | if (!gsups->link) |
| 312 | goto failed; |
| 313 | |
| 314 | gsups->read_cb = read_cb; |
Harald Welte | 32acace | 2018-06-16 17:07:28 +0200 | [diff] [blame] | 315 | gsups->priv = priv; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 316 | |
| 317 | rc = ipa_server_link_open(gsups->link); |
| 318 | if (rc < 0) |
| 319 | goto failed; |
| 320 | |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 321 | gsups->luop = lu_op_lst; |
| 322 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 323 | return gsups; |
| 324 | |
| 325 | failed: |
| 326 | osmo_gsup_server_destroy(gsups); |
| 327 | return NULL; |
| 328 | } |
| 329 | |
| 330 | void osmo_gsup_server_destroy(struct osmo_gsup_server *gsups) |
| 331 | { |
| 332 | if (gsups->link) { |
| 333 | ipa_server_link_close(gsups->link); |
| 334 | ipa_server_link_destroy(gsups->link); |
| 335 | gsups->link = NULL; |
| 336 | } |
| 337 | talloc_free(gsups); |
| 338 | } |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 339 | |
Neels Hofmeyr | 5aeb438 | 2018-05-04 16:02:44 +0200 | [diff] [blame] | 340 | /* Set GSUP message's pdp_infos[0] to a wildcard APN. |
| 341 | * Use the provided apn_buf to store the produced APN data. This must remain valid until |
Neels Hofmeyr | 1b8a1dc | 2018-05-04 16:46:47 +0200 | [diff] [blame] | 342 | * osmo_gsup_encode() is done. Return 0 if an entry was added, -ENOMEM if the provided buffer is too |
| 343 | * small. */ |
| 344 | int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, |
| 345 | uint8_t *apn_buf, size_t apn_buf_size) |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 346 | { |
| 347 | int l; |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 348 | |
Neels Hofmeyr | 5aeb438 | 2018-05-04 16:02:44 +0200 | [diff] [blame] | 349 | l = osmo_apn_from_str(apn_buf, apn_buf_size, "*"); |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 350 | if (l <= 0) |
Neels Hofmeyr | 1b8a1dc | 2018-05-04 16:46:47 +0200 | [diff] [blame] | 351 | return -ENOMEM; |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 352 | |
Neels Hofmeyr | 5aeb438 | 2018-05-04 16:02:44 +0200 | [diff] [blame] | 353 | gsup->pdp_infos[0].apn_enc = apn_buf; |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 354 | gsup->pdp_infos[0].apn_enc_len = l; |
| 355 | gsup->pdp_infos[0].have_info = 1; |
| 356 | gsup->num_pdp_infos = 1; |
| 357 | /* FIXME: use real value: */ |
| 358 | gsup->pdp_infos[0].context_id = 1; |
Neels Hofmeyr | 1b8a1dc | 2018-05-04 16:46:47 +0200 | [diff] [blame] | 359 | |
| 360 | return 0; |
Stefan Sperling | 93c5b10 | 2018-04-10 19:26:14 +0200 | [diff] [blame] | 361 | } |
Stefan Sperling | f83432c | 2018-05-03 14:26:59 +0200 | [diff] [blame] | 362 | |
| 363 | /** |
| 364 | * Populate a gsup message structure with an Insert Subscriber Data Message. |
| 365 | * All required memory buffers for data pointed to by pointers in struct omso_gsup_message |
| 366 | * must be allocated by the caller and should have the same lifetime as the gsup parameter. |
| 367 | * |
| 368 | * \param[out] gsup The gsup message to populate. |
| 369 | * \param[in] imsi The subscriber's IMSI. |
| 370 | * \param[in] msisdn The subscriber's MSISDN. |
| 371 | * \param[out] msisdn_enc A buffer large enough to store the MSISDN in encoded form. |
| 372 | * \param[in] msisdn_enc_size Size of the buffer (must be >= OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN). |
| 373 | * \param[out] apn_buf A buffer large enough to store an APN (required if cn_domain is OSMO_GSUP_CN_DOMAIN_PS). |
| 374 | * \param[in] apn_buf_size Size of APN buffer (must be >= APN_MAXLEN). |
| 375 | * \param[in] cn_domain The CN Domain of the subscriber connection. |
| 376 | * \returns 0 on success, and negative on error. |
| 377 | */ |
| 378 | int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, const char *imsi, const char *msisdn, |
| 379 | uint8_t *msisdn_enc, size_t msisdn_enc_size, |
| 380 | uint8_t *apn_buf, size_t apn_buf_size, |
| 381 | enum osmo_gsup_cn_domain cn_domain) |
| 382 | { |
| 383 | int len; |
| 384 | |
| 385 | OSMO_ASSERT(gsup); |
| 386 | |
| 387 | gsup->message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST; |
| 388 | osmo_strlcpy(gsup->imsi, imsi, sizeof(gsup->imsi)); |
| 389 | |
| 390 | if (msisdn_enc_size < OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN) |
| 391 | return -ENOSPC; |
| 392 | |
| 393 | OSMO_ASSERT(msisdn_enc); |
| 394 | len = gsm48_encode_bcd_number(msisdn_enc, msisdn_enc_size, 0, msisdn); |
| 395 | if (len < 1) { |
| 396 | LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn); |
| 397 | return -ENOSPC; |
| 398 | } |
| 399 | gsup->msisdn_enc = msisdn_enc; |
| 400 | gsup->msisdn_enc_len = len; |
| 401 | |
| 402 | #pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc" |
| 403 | |
| 404 | gsup->cn_domain = cn_domain; |
| 405 | if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) { |
| 406 | OSMO_ASSERT(apn_buf_size >= APN_MAXLEN); |
| 407 | OSMO_ASSERT(apn_buf); |
| 408 | /* FIXME: PDP infos - use more fine-grained access control |
| 409 | instead of wildcard APN */ |
| 410 | osmo_gsup_configure_wildcard_apn(gsup, apn_buf, apn_buf_size); |
| 411 | } |
| 412 | |
| 413 | return 0; |
| 414 | } |