blob: 8663f449e6bd7a4a7720e7f6a5f43eeabe72ca60 [file] [log] [blame]
Harald Welte3b6fb082016-04-25 18:46:22 +02001/*
Harald Weltee08da972017-11-13 01:00:26 +09002 * (C) 2014 by sysmocom - s.f.m.c. GmbH
3 * Author: Jacob Erlbeck
Harald Welte3b6fb082016-04-25 18:46:22 +02004 * (C) 2015 by Holger Hans Peter Freyther
5 * (C) 2016 by Harald Welte <laforge@gnumonks.org>
6 * All Rights Reserved
7 *
Harald Weltee08da972017-11-13 01:00:26 +09008 * SPDX-License-Identifier: GPL-2.0+
Harald Welte3b6fb082016-04-25 18:46:22 +02009 *
10 * This program is free software; you can redistribute it and/or modify
Neels Hofmeyr5f460de2016-12-08 16:23:05 +010011 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
Harald Welte3b6fb082016-04-25 18:46:22 +020013 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Neels Hofmeyr5f460de2016-12-08 16:23:05 +010018 * GNU General Public License for more details.
Harald Welte3b6fb082016-04-25 18:46:22 +020019 *
Neels Hofmeyr5f460de2016-12-08 16:23:05 +010020 * You should have received a copy of the GNU General Public License
Harald Welte3b6fb082016-04-25 18:46:22 +020021 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#include <osmocom/gsm/tlv.h>
26#include <osmocom/core/msgb.h>
27#include <osmocom/core/logging.h>
28#include <osmocom/gsm/gsm48_ie.h>
29#include <osmocom/gsm/gsup.h>
30
31#include <stdint.h>
32
Harald Welte96e2a002017-06-12 21:44:18 +020033/*! \addtogroup gsup
34 * @{
Harald Welte381a1aa2017-10-16 18:31:20 +020035 * \file gsup.c
Neels Hofmeyr87e45502017-06-20 00:17:59 +020036 * Osmocom Generic Subscriber Update Protocol
Harald Welte96e2a002017-06-12 21:44:18 +020037 */
38
Neels Hofmeyr10f5fb42017-02-09 02:09:09 +010039const struct value_string osmo_gsup_message_type_names[] = {
40 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST),
41 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR),
42 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT),
43
44 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST),
45 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR),
46 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT),
47
48 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_AUTH_FAIL_REPORT),
49
50 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_PURGE_MS_REQUEST),
51 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_PURGE_MS_ERROR),
52 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_PURGE_MS_RESULT),
53
54 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_INSERT_DATA_REQUEST),
55 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_INSERT_DATA_ERROR),
56 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_INSERT_DATA_RESULT),
57
58 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_DELETE_DATA_REQUEST),
59 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_DELETE_DATA_ERROR),
60 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_DELETE_DATA_RESULT),
61
62 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST),
63 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR),
64 OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT),
65 { 0, NULL }
66};
67
Harald Welte3b6fb082016-04-25 18:46:22 +020068static int decode_pdp_info(uint8_t *data, size_t data_len,
69 struct osmo_gsup_pdp_info *pdp_info)
70{
71 int rc;
72 uint8_t tag;
73 uint8_t *value;
74 size_t value_len;
75
76 /* specific parts */
77 while (data_len > 0) {
78 enum osmo_gsup_iei iei;
79
80 rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
81 if (rc < 0)
82 return -GMM_CAUSE_PROTO_ERR_UNSPEC;
83
84 iei = tag;
85
86 switch (iei) {
87 case OSMO_GSUP_PDP_CONTEXT_ID_IE:
88 pdp_info->context_id = osmo_decode_big_endian(value, value_len);
89 break;
90
91 case OSMO_GSUP_PDP_TYPE_IE:
92 pdp_info->pdp_type =
93 osmo_decode_big_endian(value, value_len) & 0x0fff;
94 break;
95
96 case OSMO_GSUP_ACCESS_POINT_NAME_IE:
97 pdp_info->apn_enc = value;
98 pdp_info->apn_enc_len = value_len;
99 break;
100
101 case OSMO_GSUP_PDP_QOS_IE:
102 pdp_info->qos_enc = value;
103 pdp_info->qos_enc_len = value_len;
104 break;
105
Holger Hans Peter Freythereb55c0d2017-07-07 16:53:30 +0200106 case OSMO_GSUP_CHARG_CHAR_IE:
107 pdp_info->pdp_charg_enc = value;
108 pdp_info->pdp_charg_enc_len = value_len;
109 break;
110
Harald Welte3b6fb082016-04-25 18:46:22 +0200111 default:
112 LOGP(DLGSUP, LOGL_ERROR,
113 "GSUP IE type %d not expected in PDP info\n", iei);
114 continue;
115 }
116 }
117
118 return 0;
119}
120
121static int decode_auth_info(uint8_t *data, size_t data_len,
122 struct osmo_auth_vector *auth_vector)
123{
124 int rc;
125 uint8_t tag;
126 uint8_t *value;
127 size_t value_len;
128 enum osmo_gsup_iei iei;
129 uint8_t presence = 0;
130
131 /* specific parts */
132 while (data_len > 0) {
133 rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
134 if (rc < 0)
135 return -GMM_CAUSE_PROTO_ERR_UNSPEC;
136
137 iei = tag;
138
139 switch (iei) {
140 case OSMO_GSUP_RAND_IE:
141 if (value_len != sizeof(auth_vector->rand))
142 goto parse_error;
143
144 memcpy(auth_vector->rand, value, value_len);
145 presence |= (1 << 0);
146 break;
147
148 case OSMO_GSUP_SRES_IE:
149 if (value_len != sizeof(auth_vector->sres))
150 goto parse_error;
151
152 memcpy(auth_vector->sres, value, value_len);
153 presence |= (1 << 1);
154 break;
155
156 case OSMO_GSUP_KC_IE:
157 if (value_len != sizeof(auth_vector->kc))
158 goto parse_error;
159
160 memcpy(auth_vector->kc, value, value_len);
161 presence |= (1 << 2);
162 break;
163
164 case OSMO_GSUP_IK_IE:
165 if (value_len != sizeof(auth_vector->ik))
166 goto parse_error;
167 memcpy(auth_vector->ik, value, value_len);
168 presence |= (1 << 4);
169 break;
170
171 case OSMO_GSUP_CK_IE:
172 if (value_len != sizeof(auth_vector->ck))
173 goto parse_error;
174 memcpy(auth_vector->ck, value, value_len);
175 presence |= (1 << 5);
176 break;
177
178 case OSMO_GSUP_AUTN_IE:
179 if (value_len != sizeof(auth_vector->autn))
180 goto parse_error;
181 memcpy(auth_vector->autn, value, value_len);
182 presence |= (1 << 6);
183 break;
184 case OSMO_GSUP_RES_IE:
185 if (value_len > sizeof(auth_vector->res))
186 goto parse_error;
187 memcpy(auth_vector->res, value, value_len);
188 auth_vector->res_len = value_len;
189 presence |= (1 << 7);
190 break;
191
192 default:
193 LOGP(DLGSUP, LOGL_ERROR,
194 "GSUP IE type %d not expected in PDP info\n", iei);
195 continue;
196 }
197 }
198
199 if (presence & 0x07)
200 auth_vector->auth_types |= OSMO_AUTH_TYPE_GSM;
201 if (presence & 0xf0)
202 auth_vector->auth_types |= OSMO_AUTH_TYPE_UMTS;
203
204 return 0;
205
206parse_error:
207 LOGP(DLGSUP, LOGL_ERROR,
208 "GSUP IE type %d, length %zu invalid in PDP info\n", iei, value_len);
209
210 return -1;
211}
212
213/*! Decode (parse) a GSUP message
214 * \param[in] const_data input data to be parsed
215 * \param[in] data_len length of input (\a const_data)
216 * \param[out] gsup_msg callee-allocated output data structure
217 * \returns 0 on success; negative otherwise
218 */
219int osmo_gsup_decode(const uint8_t *const_data, size_t data_len,
220 struct osmo_gsup_message *gsup_msg)
221{
222 int rc;
223 uint8_t tag;
224 /* the shift/match functions expect non-const pointers, but we'll
225 * either copy the data or cast pointers back to const before returning
226 * them
227 */
228 uint8_t *data = (uint8_t *)const_data;
229 uint8_t *value;
230 size_t value_len;
231 static const struct osmo_gsup_pdp_info empty_pdp_info = {0};
Neels Hofmeyr505adee2016-07-13 16:55:43 +0200232 static const struct osmo_auth_vector empty_auth_info = {{0}};
Harald Welte3b6fb082016-04-25 18:46:22 +0200233 static const struct osmo_gsup_message empty_gsup_message = {0};
234
235 *gsup_msg = empty_gsup_message;
236
237 /* generic part */
238 rc = osmo_shift_v_fixed(&data, &data_len, 1, &value);
239 if (rc < 0)
240 return -GMM_CAUSE_INV_MAND_INFO;
241
242 gsup_msg->message_type = osmo_decode_big_endian(value, 1);
243
244 rc = osmo_match_shift_tlv(&data, &data_len, OSMO_GSUP_IMSI_IE,
245 &value, &value_len);
246
247 if (rc <= 0)
248 return -GMM_CAUSE_INV_MAND_INFO;
249
250 if (value_len * 2 + 1 > sizeof(gsup_msg->imsi))
251 return -GMM_CAUSE_INV_MAND_INFO;
252
253 /* Note that gsm48_decode_bcd_number expects the number of encoded IMSI
254 * octets in the first octet. By coincidence (the TLV encoding) the byte
255 * before the value part already contains this length so we can use it
256 * here.
257 */
258 OSMO_ASSERT(value[-1] == value_len);
259 gsm48_decode_bcd_number(gsup_msg->imsi, sizeof(gsup_msg->imsi),
260 value - 1, 0);
261
262 /* specific parts */
263 while (data_len > 0) {
264 enum osmo_gsup_iei iei;
265 struct osmo_gsup_pdp_info pdp_info;
266 struct osmo_auth_vector auth_info;
267
268 rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
269 if (rc < 0)
270 return -GMM_CAUSE_PROTO_ERR_UNSPEC;
271
272 iei = tag;
273
274 switch (iei) {
275 case OSMO_GSUP_IMSI_IE:
276 case OSMO_GSUP_PDP_TYPE_IE:
277 case OSMO_GSUP_ACCESS_POINT_NAME_IE:
Harald Welte3b6fb082016-04-25 18:46:22 +0200278 case OSMO_GSUP_SRES_IE:
279 case OSMO_GSUP_KC_IE:
280 LOGP(DLGSUP, LOGL_NOTICE,
281 "GSUP IE type %d not expected (ignored)\n", iei);
282 continue;
283
284 case OSMO_GSUP_CAUSE_IE:
285 gsup_msg->cause = osmo_decode_big_endian(value, value_len);
286 break;
287
288 case OSMO_GSUP_CANCEL_TYPE_IE:
289 gsup_msg->cancel_type =
290 osmo_decode_big_endian(value, value_len) + 1;
291 break;
292
293 case OSMO_GSUP_PDP_INFO_COMPL_IE:
294 gsup_msg->pdp_info_compl = 1;
295 break;
296
297 case OSMO_GSUP_FREEZE_PTMSI_IE:
298 gsup_msg->freeze_ptmsi = 1;
299 break;
300
301 case OSMO_GSUP_PDP_CONTEXT_ID_IE:
302 /* When these IE appear in the top-level part of the
303 * message, they are used by Delete Subscr Info to delete
304 * single entries. We don't have an extra list for
305 * these but use the PDP info list instead */
306
307 /* fall through */
308
309 case OSMO_GSUP_PDP_INFO_IE:
310 if (gsup_msg->num_pdp_infos >= OSMO_GSUP_MAX_NUM_PDP_INFO) {
311 LOGP(DLGSUP, LOGL_ERROR,
312 "GSUP IE type %d (PDP_INFO) max exceeded\n",
313 iei);
314 return -GMM_CAUSE_COND_IE_ERR;
315 }
316
317 pdp_info = empty_pdp_info;
318
319 if (iei == OSMO_GSUP_PDP_INFO_IE) {
320 rc = decode_pdp_info(value, value_len, &pdp_info);
321 if (rc < 0)
322 return rc;
323 pdp_info.have_info = 1;
324 } else {
325 pdp_info.context_id =
326 osmo_decode_big_endian(value, value_len);
327 }
328
329 gsup_msg->pdp_infos[gsup_msg->num_pdp_infos++] =
330 pdp_info;
331 break;
332
333 case OSMO_GSUP_AUTH_TUPLE_IE:
334 if (gsup_msg->num_auth_vectors >= OSMO_GSUP_MAX_NUM_AUTH_INFO) {
335 LOGP(DLGSUP, LOGL_ERROR,
336 "GSUP IE type %d (AUTH_INFO) max exceeded\n",
337 iei);
338 return -GMM_CAUSE_INV_MAND_INFO;
339 }
340
341 auth_info = empty_auth_info;
342
343 rc = decode_auth_info(value, value_len, &auth_info);
344 if (rc < 0)
345 return rc;
346
347 gsup_msg->auth_vectors[gsup_msg->num_auth_vectors++] =
348 auth_info;
349 break;
350
351 case OSMO_GSUP_AUTS_IE:
Neels Hofmeyr3a5ca642017-02-21 15:53:20 +0100352 if (value_len != 14) {
Harald Welte3b6fb082016-04-25 18:46:22 +0200353 LOGP(DLGSUP, LOGL_ERROR,
Neels Hofmeyr3a5ca642017-02-21 15:53:20 +0100354 "AUTS length != 14 received\n");
Harald Welte3b6fb082016-04-25 18:46:22 +0200355 return -GMM_CAUSE_COND_IE_ERR;
356 }
357 gsup_msg->auts = value;
358 break;
359
Harald Welte766da862016-05-06 11:18:15 +0200360 case OSMO_GSUP_RAND_IE:
361 if (value_len != 16) {
362 LOGP(DLGSUP, LOGL_ERROR,
363 "RAND length != 16 received\n");
364 return -GMM_CAUSE_COND_IE_ERR;
365 }
366 gsup_msg->rand = value;
367 break;
368
Harald Welte3b6fb082016-04-25 18:46:22 +0200369 case OSMO_GSUP_MSISDN_IE:
370 gsup_msg->msisdn_enc = value;
371 gsup_msg->msisdn_enc_len = value_len;
372 break;
373
374 case OSMO_GSUP_HLR_NUMBER_IE:
375 gsup_msg->hlr_enc = value;
376 gsup_msg->hlr_enc_len = value_len;
377 break;
378
Harald Welte48dc1a52016-05-05 18:46:42 +0200379 case OSMO_GSUP_CN_DOMAIN_IE:
380 gsup_msg->cn_domain = *value;
381 break;
382
Holger Hans Peter Freythereb55c0d2017-07-07 16:53:30 +0200383 case OSMO_GSUP_CHARG_CHAR_IE:
384 gsup_msg->pdp_charg_enc = value;
385 gsup_msg->pdp_charg_enc_len = value_len;
386 break;
387
Vadim Yanitskiy72696042018-04-07 02:34:55 +0700388 case OSMO_GSUP_SESSION_ID_IE:
389 gsup_msg->session_id = osmo_decode_big_endian(value, value_len);
390 break;
391
392 case OSMO_GSUP_SESSION_STATE_IE:
393 gsup_msg->session_state = *value;
394 break;
395
Harald Welte3b6fb082016-04-25 18:46:22 +0200396 default:
397 LOGP(DLGSUP, LOGL_NOTICE,
398 "GSUP IE type %d unknown\n", iei);
399 continue;
400 }
401 }
402
403 return 0;
404}
405
406static void encode_pdp_info(struct msgb *msg, enum osmo_gsup_iei iei,
407 const struct osmo_gsup_pdp_info *pdp_info)
408{
409 uint8_t *len_field;
410 size_t old_len;
411 uint8_t u8;
412
413 len_field = msgb_tlv_put(msg, iei, 0, NULL) - 1;
414 old_len = msgb_length(msg);
415
416 u8 = pdp_info->context_id;
417 msgb_tlv_put(msg, OSMO_GSUP_PDP_CONTEXT_ID_IE, sizeof(u8), &u8);
418
419 if (pdp_info->pdp_type) {
420 msgb_tlv_put(msg, OSMO_GSUP_PDP_TYPE_IE,
421 OSMO_GSUP_PDP_TYPE_SIZE,
422 osmo_encode_big_endian(pdp_info->pdp_type | 0xf000,
423 OSMO_GSUP_PDP_TYPE_SIZE));
424 }
425
426 if (pdp_info->apn_enc) {
427 msgb_tlv_put(msg, OSMO_GSUP_ACCESS_POINT_NAME_IE,
428 pdp_info->apn_enc_len, pdp_info->apn_enc);
429 }
430
431 if (pdp_info->qos_enc) {
432 msgb_tlv_put(msg, OSMO_GSUP_PDP_QOS_IE,
433 pdp_info->qos_enc_len, pdp_info->qos_enc);
434 }
435
Holger Hans Peter Freythereb55c0d2017-07-07 16:53:30 +0200436 if (pdp_info->pdp_charg_enc) {
437 msgb_tlv_put(msg, OSMO_GSUP_CHARG_CHAR_IE,
438 pdp_info->pdp_charg_enc_len, pdp_info->pdp_charg_enc);
439 }
440
Harald Welte3b6fb082016-04-25 18:46:22 +0200441 /* Update length field */
442 *len_field = msgb_length(msg) - old_len;
443}
444
445static void encode_auth_info(struct msgb *msg, enum osmo_gsup_iei iei,
446 const struct osmo_auth_vector *auth_vector)
447{
448 uint8_t *len_field;
449 size_t old_len;
450
451 len_field = msgb_tlv_put(msg, iei, 0, NULL) - 1;
452 old_len = msgb_length(msg);
453
Harald Weltedb78d212016-06-06 13:47:07 +0200454 if (auth_vector->auth_types & OSMO_AUTH_TYPE_GSM) {
455 msgb_tlv_put(msg, OSMO_GSUP_RAND_IE,
456 sizeof(auth_vector->rand), auth_vector->rand);
Harald Welte3b6fb082016-04-25 18:46:22 +0200457
Harald Weltedb78d212016-06-06 13:47:07 +0200458 msgb_tlv_put(msg, OSMO_GSUP_SRES_IE,
459 sizeof(auth_vector->sres), auth_vector->sres);
Harald Welte3b6fb082016-04-25 18:46:22 +0200460
Harald Weltedb78d212016-06-06 13:47:07 +0200461 msgb_tlv_put(msg, OSMO_GSUP_KC_IE,
462 sizeof(auth_vector->kc), auth_vector->kc);
463 }
464
465 if (auth_vector->auth_types & OSMO_AUTH_TYPE_UMTS) {
466 msgb_tlv_put(msg, OSMO_GSUP_IK_IE,
467 sizeof(auth_vector->ik), auth_vector->ik);
468
469 msgb_tlv_put(msg, OSMO_GSUP_CK_IE,
470 sizeof(auth_vector->ck), auth_vector->ck);
471
472 msgb_tlv_put(msg, OSMO_GSUP_AUTN_IE,
473 sizeof(auth_vector->autn), auth_vector->autn);
474
475 msgb_tlv_put(msg, OSMO_GSUP_RES_IE,
476 auth_vector->res_len, auth_vector->res);
477 }
Harald Welte3b6fb082016-04-25 18:46:22 +0200478
479 /* Update length field */
480 *len_field = msgb_length(msg) - old_len;
481}
482
483/*! Encode a GSUP message
484 * \param[out] msg message buffer to which encoded message is written
485 * \param[in] gsup_msg \ref osmo_gsup_message data to be encoded
Max80f4c4e2018-01-24 12:33:05 +0100486 * \returns 0 on success; negative otherwise
Harald Welte3b6fb082016-04-25 18:46:22 +0200487 */
Max80f4c4e2018-01-24 12:33:05 +0100488int osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message *gsup_msg)
Harald Welte3b6fb082016-04-25 18:46:22 +0200489{
490 uint8_t u8;
491 int idx;
492 uint8_t bcd_buf[GSM48_MI_SIZE] = {0};
493 size_t bcd_len;
494
495 /* generic part */
Max80f4c4e2018-01-24 12:33:05 +0100496 if(!gsup_msg->message_type)
497 return -ENOMEM;
498
Harald Welte3b6fb082016-04-25 18:46:22 +0200499 msgb_v_put(msg, gsup_msg->message_type);
500
501 bcd_len = gsm48_encode_bcd_number(bcd_buf, sizeof(bcd_buf), 0,
502 gsup_msg->imsi);
503
Max80f4c4e2018-01-24 12:33:05 +0100504 if (bcd_len <= 0 || bcd_len > sizeof(bcd_buf))
505 return -EINVAL;
Harald Welte3b6fb082016-04-25 18:46:22 +0200506
507 /* Note that gsm48_encode_bcd_number puts the length into the first
508 * octet. Since msgb_tlv_put will add this length byte, we'll have to
509 * skip it */
510 msgb_tlv_put(msg, OSMO_GSUP_IMSI_IE, bcd_len - 1, &bcd_buf[1]);
511
512 /* specific parts */
513 if (gsup_msg->msisdn_enc)
514 msgb_tlv_put(msg, OSMO_GSUP_MSISDN_IE,
515 gsup_msg->msisdn_enc_len, gsup_msg->msisdn_enc);
516 if (gsup_msg->hlr_enc)
517 msgb_tlv_put(msg, OSMO_GSUP_HLR_NUMBER_IE,
518 gsup_msg->hlr_enc_len, gsup_msg->hlr_enc);
519
520 if ((u8 = gsup_msg->cause))
521 msgb_tlv_put(msg, OSMO_GSUP_CAUSE_IE, sizeof(u8), &u8);
522
523 if ((u8 = gsup_msg->cancel_type)) {
524 u8 -= 1;
525 msgb_tlv_put(msg, OSMO_GSUP_CANCEL_TYPE_IE, sizeof(u8), &u8);
526 }
527
528 if (gsup_msg->pdp_info_compl)
529 msgb_tlv_put(msg, OSMO_GSUP_PDP_INFO_COMPL_IE, 0, &u8);
530
531 if (gsup_msg->freeze_ptmsi)
532 msgb_tlv_put(msg, OSMO_GSUP_FREEZE_PTMSI_IE, 0, &u8);
533
534 for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) {
535 const struct osmo_gsup_pdp_info *pdp_info;
536
537 pdp_info = &gsup_msg->pdp_infos[idx];
538
539 if (pdp_info->context_id == 0)
540 continue;
541
542 if (pdp_info->have_info) {
543 encode_pdp_info(msg, OSMO_GSUP_PDP_INFO_IE, pdp_info);
544 } else {
545 u8 = pdp_info->context_id;
546 msgb_tlv_put(msg, OSMO_GSUP_PDP_CONTEXT_ID_IE,
547 sizeof(u8), &u8);
548 }
549 }
550
551 for (idx = 0; idx < gsup_msg->num_auth_vectors; idx++) {
552 const struct osmo_auth_vector *auth_vector;
553
554 auth_vector = &gsup_msg->auth_vectors[idx];
555
556 encode_auth_info(msg, OSMO_GSUP_AUTH_TUPLE_IE, auth_vector);
557 }
558
559 if (gsup_msg->auts)
Neels Hofmeyr8352d312017-02-02 20:05:14 +0100560 msgb_tlv_put(msg, OSMO_GSUP_AUTS_IE, 14, gsup_msg->auts);
Harald Welte48dc1a52016-05-05 18:46:42 +0200561
Harald Welte766da862016-05-06 11:18:15 +0200562 if (gsup_msg->rand)
563 msgb_tlv_put(msg, OSMO_GSUP_RAND_IE, 16, gsup_msg->rand);
564
Harald Welte48dc1a52016-05-05 18:46:42 +0200565 if (gsup_msg->cn_domain) {
566 uint8_t dn = gsup_msg->cn_domain;
567 msgb_tlv_put(msg, OSMO_GSUP_CN_DOMAIN_IE, 1, &dn);
568 }
Holger Hans Peter Freythereb55c0d2017-07-07 16:53:30 +0200569
570 if (gsup_msg->pdp_charg_enc) {
571 msgb_tlv_put(msg, OSMO_GSUP_CHARG_CHAR_IE,
572 gsup_msg->pdp_charg_enc_len, gsup_msg->pdp_charg_enc);
573 }
Max80f4c4e2018-01-24 12:33:05 +0100574
Vadim Yanitskiy72696042018-04-07 02:34:55 +0700575 if ((u8 = gsup_msg->session_state)) {
576 size_t len = sizeof(gsup_msg->session_id);
577 uint8_t *sid = osmo_encode_big_endian(gsup_msg->session_id, len);
578
579 msgb_tlv_put(msg, OSMO_GSUP_SESSION_ID_IE, len, sid);
580 msgb_tlv_put(msg, OSMO_GSUP_SESSION_STATE_IE, sizeof(u8), &u8);
581 }
582
Max80f4c4e2018-01-24 12:33:05 +0100583 return 0;
Harald Welte3b6fb082016-04-25 18:46:22 +0200584}
Harald Welte96e2a002017-06-12 21:44:18 +0200585
586/*! @} */