blob: a6cca81d920e1abb9656d7c0ef3c0400ca22271e [file] [log] [blame]
Harald Welte936f6722016-05-03 18:51:18 +02001/* (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 Weltee72cf552016-04-28 07:18:49 +020020#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 Sperlingf83432c2018-05-03 14:26:59 +020027#include <osmocom/gsm/gsm48_ie.h>
Stefan Sperling93c5b102018-04-10 19:26:14 +020028#include <osmocom/gsm/apn.h>
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +010029#include <osmocom/gsm/gsm23003.h>
Harald Weltee72cf552016-04-28 07:18:49 +020030
Neels Hofmeyr2f758032019-11-20 00:37:07 +010031#include <osmocom/hlr/gsup_server.h>
32#include <osmocom/hlr/gsup_router.h>
Harald Weltee72cf552016-04-28 07:18:49 +020033
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +010034#define LOG_GSUP_CONN(conn, level, fmt, args...) \
35 LOGP(DLGSUP, level, "GSUP peer %s: " fmt, \
36 (conn) ? osmo_ipa_name_to_str(&(conn)->peer_name) : "NULL", ##args)
37
Neels Hofmeyra7d0f872019-10-30 02:08:28 +010038struct msgb *osmo_gsup_msgb_alloc(const char *label)
39{
40 struct msgb *msg = msgb_alloc_headroom(1024+16, 16, label);
41 OSMO_ASSERT(msg);
42 return msg;
43}
44
Harald Weltee72cf552016-04-28 07:18:49 +020045static void osmo_gsup_server_send(struct osmo_gsup_conn *conn,
46 int proto_ext, struct msgb *msg_tx)
47{
48 ipa_prepend_header_ext(msg_tx, proto_ext);
49 ipa_msg_push_header(msg_tx, IPAC_PROTO_OSMO);
50 ipa_server_conn_send(conn->conn, msg_tx);
51}
52
53int osmo_gsup_conn_send(struct osmo_gsup_conn *conn, struct msgb *msg)
54{
55 if (!conn) {
56 msgb_free(msg);
57 return -ENOTCONN;
58 }
59
60 osmo_gsup_server_send(conn, IPAC_PROTO_EXT_GSUP, msg);
61
62 return 0;
63}
64
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +010065static void gsup_server_send_req_response(struct osmo_gsup_req *req, struct osmo_gsup_message *response)
66{
67 struct osmo_gsup_server *server = req->cb_data;
68 struct osmo_gsup_conn *conn;
69 struct msgb *msg = osmo_gsup_msgb_alloc("GSUP Tx");
70 int rc;
71
72 conn = gsup_route_find_by_ipa_name(server, &req->source_name);
73 if (!conn) {
74 LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP client that sent this request was disconnected, cannot respond\n");
75 msgb_free(msg);
76 return;
77 }
78
79 rc = osmo_gsup_encode(msg, response);
80 if (rc) {
81 LOG_GSUP_REQ(req, LOGL_ERROR, "Unable to encode: {%s}\n",
82 osmo_gsup_message_to_str_c(OTC_SELECT, response));
83 msgb_free(msg);
84 return;
85 }
86
87 rc = osmo_gsup_conn_send(conn, msg);
88 if (rc)
89 LOG_GSUP_CONN(conn, LOGL_ERROR, "Unable to send: %s\n", osmo_gsup_message_to_str_c(OTC_SELECT, response));
90}
91
92struct osmo_gsup_req *osmo_gsup_conn_rx(struct osmo_gsup_conn *conn, struct msgb *msg)
93{
94 struct osmo_gsup_req *req = osmo_gsup_req_new(conn->server, &conn->peer_name, msg, gsup_server_send_req_response,
95 conn->server, NULL);
96 if (!req)
97 return NULL;
98
99 if (req->via_proxy.len) {
100 /* The source of the GSUP message is not the immediate GSUP peer, but that peer is our proxy for that
101 * source. Add it to the routes for this conn (so we can route responses back). */
102 if (gsup_route_add_ipa_name(conn, &req->source_name)) {
103 LOG_GSUP_REQ(req, LOGL_ERROR,
104 "GSUP message received from %s via peer %s, but there already exists a"
105 " different route to this source, message is not routable\n",
106 osmo_ipa_name_to_str(&req->source_name),
107 osmo_ipa_name_to_str(&conn->peer_name));
108 osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
109 return NULL;
110 }
111 }
112
113 return req;
114}
115
Harald Weltee72cf552016-04-28 07:18:49 +0200116static int osmo_gsup_conn_oap_handle(struct osmo_gsup_conn *conn,
117 struct msgb *msg_rx)
118{
Neels Hofmeyrec1b9592016-12-11 01:22:23 +0100119#if 0
Harald Weltee72cf552016-04-28 07:18:49 +0200120 int rc;
121 struct msgb *msg_tx;
Harald Weltee72cf552016-04-28 07:18:49 +0200122 rc = oap_handle(&conn->oap_state, msg_rx, &msg_tx);
123 msgb_free(msg_rx);
124 if (rc < 0)
125 return rc;
126
127 if (msg_tx)
128 osmo_gsup_conn_send(conn, IPAC_PROTO_EXT_OAP, msg_tx);
129#endif
130 return 0;
131}
132
Harald Weltee72cf552016-04-28 07:18:49 +0200133/* Data from a given client has arrived over the socket */
134static int osmo_gsup_server_read_cb(struct ipa_server_conn *conn,
135 struct msgb *msg)
136{
137 struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
138 struct ipaccess_head_ext *he = (struct ipaccess_head_ext *) msgb_l2(msg);
139 struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data;
140 int rc;
Harald Weltee72cf552016-04-28 07:18:49 +0200141
142 msg->l2h = &hh->data[0];
143
Harald Welte173afdb2016-04-28 08:53:25 +0200144 if (hh->proto == IPAC_PROTO_IPACCESS) {
145 rc = ipa_server_conn_ccm(conn, msg);
146 if (rc < 0) {
147 /* conn is already invalid here! */
Harald Welte173afdb2016-04-28 08:53:25 +0200148 return -1;
Harald Weltee72cf552016-04-28 07:18:49 +0200149 }
Harald Welte5341b5d2016-04-28 12:48:39 +0200150 msgb_free(msg);
Harald Weltee72cf552016-04-28 07:18:49 +0200151 return 0;
152 }
Harald Weltee72cf552016-04-28 07:18:49 +0200153
Harald Weltef2d96da2016-04-28 11:13:15 +0200154 if (hh->proto != IPAC_PROTO_OSMO) {
155 LOGP(DLGSUP, LOGL_NOTICE, "Unsupported IPA stream ID 0x%02x\n",
156 hh->proto);
Harald Weltee72cf552016-04-28 07:18:49 +0200157 goto invalid;
Harald Weltef2d96da2016-04-28 11:13:15 +0200158 }
Harald Weltee72cf552016-04-28 07:18:49 +0200159
Harald Weltef2d96da2016-04-28 11:13:15 +0200160 if (!he || msgb_l2len(msg) < sizeof(*he)) {
161 LOGP(DLGSUP, LOGL_NOTICE, "short IPA message\n");
Harald Weltee72cf552016-04-28 07:18:49 +0200162 goto invalid;
Harald Weltef2d96da2016-04-28 11:13:15 +0200163 }
Harald Weltee72cf552016-04-28 07:18:49 +0200164
165 msg->l2h = &he->data[0];
166
167 if (he->proto == IPAC_PROTO_EXT_GSUP) {
168 OSMO_ASSERT(clnt->server->read_cb != NULL);
169 clnt->server->read_cb(clnt, msg);
170 /* expecting read_cb() to free msg */
171 } else if (he->proto == IPAC_PROTO_EXT_OAP) {
172 return osmo_gsup_conn_oap_handle(clnt, msg);
173 /* osmo_gsup_client_oap_handle frees msg */
Harald Weltef2d96da2016-04-28 11:13:15 +0200174 } else {
175 LOGP(DLGSUP, LOGL_NOTICE, "Unsupported IPA Osmo Proto 0x%02x\n",
176 hh->proto);
Harald Weltee72cf552016-04-28 07:18:49 +0200177 goto invalid;
Harald Weltef2d96da2016-04-28 11:13:15 +0200178 }
Harald Weltee72cf552016-04-28 07:18:49 +0200179
180 return 0;
181
182invalid:
183 LOGP(DLGSUP, LOGL_NOTICE,
Harald Weltef2d96da2016-04-28 11:13:15 +0200184 "GSUP received an invalid IPA message from %s:%d: %s\n",
185 conn->addr, conn->port, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg)));
Harald Weltee72cf552016-04-28 07:18:49 +0200186 msgb_free(msg);
187 return -1;
188
189}
190
Harald Weltee687be52016-05-03 18:49:27 +0200191static void osmo_tlvp_dump(const struct tlv_parsed *tlvp,
192 int subsys, int level)
193{
194 unsigned int i;
195
196 for (i = 0; i < ARRAY_SIZE(tlvp->lv); i++) {
197 if (!TLVP_PRESENT(tlvp, i))
198 continue;
199
200 LOGP(subsys, level, "%u: %s\n", i,
201 TLVP_VAL(tlvp, i));
202 LOGP(subsys, level, "%u: %s\n", i,
203 osmo_hexdump(TLVP_VAL(tlvp, i),
204 TLVP_LEN(tlvp, i)));
205 }
206}
207
208/* FIXME: should this be parrt of ipas_server handling, not GSUP? */
209static void tlvp_copy(void *ctx, struct tlv_parsed *out, const struct tlv_parsed *in)
210{
211 unsigned int i;
212
213 for (i = 0; i < ARRAY_SIZE(out->lv); i++) {
214 if (!TLVP_PRESENT(in, i)) {
215 if (TLVP_PRESENT(out, i)) {
216 talloc_free((void *) out->lv[i].val);
217 out->lv[i].val = NULL;
218 out->lv[i].len = 0;
219 }
220 continue;
221 }
222 out->lv[i].val = talloc_memdup(ctx, in->lv[i].val, in->lv[i].len);
223 out->lv[i].len = in->lv[i].len;
224 }
225}
226
227int osmo_gsup_conn_ccm_get(const struct osmo_gsup_conn *clnt, uint8_t **addr,
228 uint8_t tag)
229{
230 if (!TLVP_PRESENT(&clnt->ccm, tag))
231 return -ENODEV;
232 *addr = (uint8_t *) TLVP_VAL(&clnt->ccm, tag);
233
234 return TLVP_LEN(&clnt->ccm, tag);
235}
236
Harald Welte173afdb2016-04-28 08:53:25 +0200237static int osmo_gsup_server_ccm_cb(struct ipa_server_conn *conn,
238 struct msgb *msg, struct tlv_parsed *tlvp,
239 struct ipaccess_unit *unit)
240{
Harald Weltee687be52016-05-03 18:49:27 +0200241 struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data;
Neels Hofmeyrec1b9592016-12-11 01:22:23 +0100242 uint8_t *addr = NULL;
Harald Weltee687be52016-05-03 18:49:27 +0200243 size_t addr_len;
244
Harald Welte173afdb2016-04-28 08:53:25 +0200245 LOGP(DLGSUP, LOGL_INFO, "CCM Callback\n");
Harald Weltee687be52016-05-03 18:49:27 +0200246
247 /* FIXME: should this be parrt of ipas_server handling, not
248 * GSUP? */
249 tlvp_copy(clnt, &clnt->ccm, tlvp);
250 osmo_tlvp_dump(tlvp, DLGSUP, LOGL_INFO);
251
252 addr_len = osmo_gsup_conn_ccm_get(clnt, &addr, IPAC_IDTAG_SERNR);
Neels Hofmeyr5ecdc562017-02-24 06:38:04 +0100253 if (addr_len <= 0) {
254 LOGP(DLGSUP, LOGL_ERROR, "GSUP client %s:%u has no %s IE and"
255 " cannot be routed\n",
256 conn->addr, conn->port,
257 ipa_ccm_idtag_name(IPAC_IDTAG_SERNR));
258 return -EINVAL;
259 }
Harald Weltee687be52016-05-03 18:49:27 +0200260
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100261 osmo_ipa_name_set(&clnt->peer_name, addr, addr_len);
262 gsup_route_add_ipa_name(clnt, &clnt->peer_name);
Harald Welte173afdb2016-04-28 08:53:25 +0200263 return 0;
264}
265
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100266static void osmo_gsup_conn_free(struct osmo_gsup_conn *conn)
267{
268 gsup_route_del_conn(conn);
269 llist_del(&conn->list);
270 talloc_free(conn);
271}
272
Harald Weltee72cf552016-04-28 07:18:49 +0200273static int osmo_gsup_server_closed_cb(struct ipa_server_conn *conn)
274{
275 struct osmo_gsup_conn *clnt = (struct osmo_gsup_conn *)conn->data;
276
277 LOGP(DLGSUP, LOGL_INFO, "Lost GSUP client %s:%d\n",
278 conn->addr, conn->port);
279
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100280 osmo_gsup_conn_free(clnt);
Harald Weltee72cf552016-04-28 07:18:49 +0200281 return 0;
282}
283
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +0100284/* Add conn to the clients list in a way that conn->auc_3g_ind takes the lowest
285 * unused integer and the list of clients remains sorted by auc_3g_ind.
286 * Keep this function non-static to allow linking in a unit test. */
287void osmo_gsup_server_add_conn(struct llist_head *clients,
288 struct osmo_gsup_conn *conn)
289{
290 struct osmo_gsup_conn *c;
291 struct osmo_gsup_conn *prev_conn;
292
293 c = llist_first_entry_or_null(clients, struct osmo_gsup_conn, list);
294
295 /* Is the first index, 0, unused? */
296 if (!c || c->auc_3g_ind > 0) {
297 conn->auc_3g_ind = 0;
298 llist_add(&conn->list, clients);
299 return;
300 }
301
302 /* Look for a gap later on */
303 prev_conn = NULL;
304 llist_for_each_entry(c, clients, list) {
305 /* skip first item, we know it has auc_3g_ind == 0. */
306 if (!prev_conn) {
307 prev_conn = c;
308 continue;
309 }
310 if (c->auc_3g_ind > prev_conn->auc_3g_ind + 1)
311 break;
312 prev_conn = c;
313 }
314
315 OSMO_ASSERT(prev_conn);
316
317 conn->auc_3g_ind = prev_conn->auc_3g_ind + 1;
318 llist_add(&conn->list, &prev_conn->list);
319}
320
Harald Weltee72cf552016-04-28 07:18:49 +0200321/* a client has connected to the server socket and we have accept()ed it */
322static int osmo_gsup_server_accept_cb(struct ipa_server_link *link, int fd)
323{
324 struct osmo_gsup_conn *conn;
325 struct osmo_gsup_server *gsups =
326 (struct osmo_gsup_server *) link->data;
Harald Welte173afdb2016-04-28 08:53:25 +0200327 int rc;
Harald Weltee72cf552016-04-28 07:18:49 +0200328
Harald Weltea7617e92016-04-28 12:57:10 +0200329 conn = talloc_zero(gsups, struct osmo_gsup_conn);
Harald Weltee72cf552016-04-28 07:18:49 +0200330 OSMO_ASSERT(conn);
331
Harald Weltea7617e92016-04-28 12:57:10 +0200332 conn->conn = ipa_server_conn_create(gsups, link, fd,
Harald Weltee72cf552016-04-28 07:18:49 +0200333 osmo_gsup_server_read_cb,
334 osmo_gsup_server_closed_cb, conn);
335 OSMO_ASSERT(conn->conn);
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +0100336 conn->conn->ccm_cb = osmo_gsup_server_ccm_cb;
Harald Weltee72cf552016-04-28 07:18:49 +0200337
338 /* link data structure with server structure */
339 conn->server = gsups;
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +0100340 osmo_gsup_server_add_conn(&gsups->clients, conn);
Harald Weltee72cf552016-04-28 07:18:49 +0200341
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +0100342 LOGP(DLGSUP, LOGL_INFO, "New GSUP client %s:%d (IND=%u)\n",
343 conn->conn->addr, conn->conn->port, conn->auc_3g_ind);
Harald Welte173afdb2016-04-28 08:53:25 +0200344
345 /* request the identity of the client */
346 rc = ipa_ccm_send_id_req(fd);
347 if (rc < 0)
348 goto failed;
Harald Weltee72cf552016-04-28 07:18:49 +0200349#if 0
350 rc = oap_init(&gsups->oap_config, &conn->oap_state);
351 if (rc != 0)
352 goto failed;
Harald Weltee72cf552016-04-28 07:18:49 +0200353#endif
354 return 0;
Harald Welte173afdb2016-04-28 08:53:25 +0200355failed:
356 ipa_server_conn_destroy(conn->conn);
357 return -1;
Harald Weltee72cf552016-04-28 07:18:49 +0200358}
359
360struct osmo_gsup_server *
Max9cacb6f2017-02-20 17:22:56 +0100361osmo_gsup_server_create(void *ctx, const char *ip_addr, uint16_t tcp_port,
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100362 osmo_gsup_read_cb_t read_cb, void *priv)
Harald Weltee72cf552016-04-28 07:18:49 +0200363{
364 struct osmo_gsup_server *gsups;
365 int rc;
366
367 gsups = talloc_zero(ctx, struct osmo_gsup_server);
368 OSMO_ASSERT(gsups);
369
370 INIT_LLIST_HEAD(&gsups->clients);
Harald Weltee687be52016-05-03 18:49:27 +0200371 INIT_LLIST_HEAD(&gsups->routes);
Harald Weltee72cf552016-04-28 07:18:49 +0200372
373 gsups->link = ipa_server_link_create(gsups,
374 /* no e1inp */ NULL,
375 ip_addr, tcp_port,
376 osmo_gsup_server_accept_cb,
377 gsups);
378 if (!gsups->link)
379 goto failed;
380
381 gsups->read_cb = read_cb;
Harald Welte32acace2018-06-16 17:07:28 +0200382 gsups->priv = priv;
Harald Weltee72cf552016-04-28 07:18:49 +0200383
384 rc = ipa_server_link_open(gsups->link);
385 if (rc < 0)
386 goto failed;
387
Harald Weltee72cf552016-04-28 07:18:49 +0200388 return gsups;
389
390failed:
391 osmo_gsup_server_destroy(gsups);
392 return NULL;
393}
394
395void osmo_gsup_server_destroy(struct osmo_gsup_server *gsups)
396{
397 if (gsups->link) {
398 ipa_server_link_close(gsups->link);
399 ipa_server_link_destroy(gsups->link);
400 gsups->link = NULL;
401 }
402 talloc_free(gsups);
403}
Stefan Sperling93c5b102018-04-10 19:26:14 +0200404
Neels Hofmeyr5aeb4382018-05-04 16:02:44 +0200405/* Set GSUP message's pdp_infos[0] to a wildcard APN.
406 * Use the provided apn_buf to store the produced APN data. This must remain valid until
Neels Hofmeyr1b8a1dc2018-05-04 16:46:47 +0200407 * osmo_gsup_encode() is done. Return 0 if an entry was added, -ENOMEM if the provided buffer is too
408 * small. */
409int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup,
410 uint8_t *apn_buf, size_t apn_buf_size)
Stefan Sperling93c5b102018-04-10 19:26:14 +0200411{
412 int l;
Stefan Sperling93c5b102018-04-10 19:26:14 +0200413
Neels Hofmeyr5aeb4382018-05-04 16:02:44 +0200414 l = osmo_apn_from_str(apn_buf, apn_buf_size, "*");
Stefan Sperling93c5b102018-04-10 19:26:14 +0200415 if (l <= 0)
Neels Hofmeyr1b8a1dc2018-05-04 16:46:47 +0200416 return -ENOMEM;
Stefan Sperling93c5b102018-04-10 19:26:14 +0200417
Neels Hofmeyr5aeb4382018-05-04 16:02:44 +0200418 gsup->pdp_infos[0].apn_enc = apn_buf;
Stefan Sperling93c5b102018-04-10 19:26:14 +0200419 gsup->pdp_infos[0].apn_enc_len = l;
420 gsup->pdp_infos[0].have_info = 1;
421 gsup->num_pdp_infos = 1;
422 /* FIXME: use real value: */
423 gsup->pdp_infos[0].context_id = 1;
Neels Hofmeyr1b8a1dc2018-05-04 16:46:47 +0200424
425 return 0;
Stefan Sperling93c5b102018-04-10 19:26:14 +0200426}
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200427
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100428
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200429/**
430 * Populate a gsup message structure with an Insert Subscriber Data Message.
431 * All required memory buffers for data pointed to by pointers in struct omso_gsup_message
432 * must be allocated by the caller and should have the same lifetime as the gsup parameter.
433 *
434 * \param[out] gsup The gsup message to populate.
435 * \param[in] imsi The subscriber's IMSI.
436 * \param[in] msisdn The subscriber's MSISDN.
437 * \param[out] msisdn_enc A buffer large enough to store the MSISDN in encoded form.
438 * \param[in] msisdn_enc_size Size of the buffer (must be >= OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN).
439 * \param[out] apn_buf A buffer large enough to store an APN (required if cn_domain is OSMO_GSUP_CN_DOMAIN_PS).
440 * \param[in] apn_buf_size Size of APN buffer (must be >= APN_MAXLEN).
441 * \param[in] cn_domain The CN Domain of the subscriber connection.
442 * \returns 0 on success, and negative on error.
443 */
444int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, const char *imsi, const char *msisdn,
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100445 uint8_t *msisdn_enc, size_t msisdn_enc_size,
446 uint8_t *apn_buf, size_t apn_buf_size,
447 enum osmo_gsup_cn_domain cn_domain)
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200448{
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100449 int len;
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200450
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100451 OSMO_ASSERT(gsup);
452 *gsup = (struct osmo_gsup_message){
453 .message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST,
454 };
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200455
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100456 osmo_strlcpy(gsup->imsi, imsi, sizeof(gsup->imsi));
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200457
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100458 if (msisdn_enc_size < OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN)
459 return -ENOSPC;
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200460
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100461 OSMO_ASSERT(msisdn_enc);
462 len = gsm48_encode_bcd_number(msisdn_enc, msisdn_enc_size, 0, msisdn);
463 if (len < 1) {
464 LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn);
465 return -ENOSPC;
466 }
467 gsup->msisdn_enc = msisdn_enc;
468 gsup->msisdn_enc_len = len;
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200469
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100470 #pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc"
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200471
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100472 gsup->cn_domain = cn_domain;
473 if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) {
474 OSMO_ASSERT(apn_buf_size >= APN_MAXLEN);
475 OSMO_ASSERT(apn_buf);
476 /* FIXME: PDP infos - use more fine-grained access control
477 instead of wildcard APN */
478 osmo_gsup_configure_wildcard_apn(gsup, apn_buf, apn_buf_size);
479 }
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200480
Neels Hofmeyrf13a8bc2019-11-20 02:36:45 +0100481 return 0;
Stefan Sperlingf83432c2018-05-03 14:26:59 +0200482}