blob: e820b5a172f399931091e19db0b479aa63bfa198 [file] [log] [blame]
Harald Weltee2b53492016-04-25 14:53:43 +02001/* Osmocom Subscriber Update Protocol message encoder/decoder */
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +01002
3/*
4 * (C) 2014 by Sysmocom s.f.m.c. GmbH
Holger Hans Peter Freyther04662742015-04-22 23:09:41 -04005 * (C) 2015 by Holger Hans Peter Freyther
Harald Welte34ef4c52016-04-20 13:13:19 +02006 * (C) 2016 by Harald Welte <laforge@gnumonks.org>
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +01007 * All Rights Reserved
8 *
9 * Author: Jacob Erlbeck
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Affero General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 */
25
Harald Weltee2b53492016-04-25 14:53:43 +020026#include <openbsc/osmo_gsup_messages.h>
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010027
28#include <openbsc/debug.h>
Neels Hofmeyr72092772015-10-12 11:57:33 +020029#include <openbsc/utils.h>
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010030
31#include <osmocom/gsm/tlv.h>
32#include <osmocom/core/msgb.h>
Harald Welte02884f22016-04-20 17:50:17 +020033#include <osmocom/gsm/gsm48_ie.h>
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010034
35#include <stdint.h>
36
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010037static int decode_pdp_info(uint8_t *data, size_t data_len,
Harald Weltee2b53492016-04-25 14:53:43 +020038 struct osmo_gsup_pdp_info *pdp_info)
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010039{
40 int rc;
41 uint8_t tag;
42 uint8_t *value;
43 size_t value_len;
44
45 /* specific parts */
46 while (data_len > 0) {
Harald Weltee2b53492016-04-25 14:53:43 +020047 enum osmo_gsup_iei iei;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010048
Harald Welte8f4b2b82016-04-25 15:14:01 +020049 rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010050 if (rc < 0)
Jacob Erlbeck092bbc82015-01-05 18:57:32 +010051 return -GMM_CAUSE_PROTO_ERR_UNSPEC;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010052
53 iei = tag;
54
55 switch (iei) {
Harald Weltee2b53492016-04-25 14:53:43 +020056 case OSMO_GSUP_PDP_CONTEXT_ID_IE:
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010057 pdp_info->context_id = decode_big_endian(value, value_len);
58 break;
59
Harald Weltee2b53492016-04-25 14:53:43 +020060 case OSMO_GSUP_PDP_TYPE_IE:
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010061 pdp_info->pdp_type =
62 decode_big_endian(value, value_len) & 0x0fff;
63 break;
64
Harald Weltee2b53492016-04-25 14:53:43 +020065 case OSMO_GSUP_ACCESS_POINT_NAME_IE:
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010066 pdp_info->apn_enc = value;
67 pdp_info->apn_enc_len = value_len;
68 break;
69
Harald Weltee2b53492016-04-25 14:53:43 +020070 case OSMO_GSUP_PDP_QOS_IE:
Holger Hans Peter Freyther2944e212015-04-23 09:13:01 -040071 pdp_info->qos_enc = value;
72 pdp_info->qos_enc_len = value_len;
73 break;
74
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010075 default:
76 LOGP(DGPRS, LOGL_ERROR,
77 "GSUP IE type %d not expected in PDP info\n", iei);
78 continue;
79 }
80 }
81
82 return 0;
83}
84
85static int decode_auth_info(uint8_t *data, size_t data_len,
Harald Welte34ef4c52016-04-20 13:13:19 +020086 struct osmo_auth_vector *auth_vector)
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010087{
88 int rc;
89 uint8_t tag;
90 uint8_t *value;
91 size_t value_len;
Harald Weltee2b53492016-04-25 14:53:43 +020092 enum osmo_gsup_iei iei;
Harald Weltef53cc962016-04-25 15:36:08 +020093 uint8_t presence = 0;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010094
95 /* specific parts */
96 while (data_len > 0) {
Harald Welte8f4b2b82016-04-25 15:14:01 +020097 rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +010098 if (rc < 0)
Jacob Erlbeck092bbc82015-01-05 18:57:32 +010099 return -GMM_CAUSE_PROTO_ERR_UNSPEC;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100100
101 iei = tag;
102
103 switch (iei) {
Harald Weltee2b53492016-04-25 14:53:43 +0200104 case OSMO_GSUP_RAND_IE:
Harald Welte34ef4c52016-04-20 13:13:19 +0200105 if (value_len != sizeof(auth_vector->rand))
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100106 goto parse_error;
107
Harald Welte34ef4c52016-04-20 13:13:19 +0200108 memcpy(auth_vector->rand, value, value_len);
Harald Weltef53cc962016-04-25 15:36:08 +0200109 presence |= (1 << 0);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100110 break;
111
Harald Weltee2b53492016-04-25 14:53:43 +0200112 case OSMO_GSUP_SRES_IE:
Harald Welte34ef4c52016-04-20 13:13:19 +0200113 if (value_len != sizeof(auth_vector->sres))
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100114 goto parse_error;
115
Harald Welte34ef4c52016-04-20 13:13:19 +0200116 memcpy(auth_vector->sres, value, value_len);
Harald Weltef53cc962016-04-25 15:36:08 +0200117 presence |= (1 << 1);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100118 break;
119
Harald Weltee2b53492016-04-25 14:53:43 +0200120 case OSMO_GSUP_KC_IE:
Harald Welte34ef4c52016-04-20 13:13:19 +0200121 if (value_len != sizeof(auth_vector->kc))
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100122 goto parse_error;
123
Harald Welte34ef4c52016-04-20 13:13:19 +0200124 memcpy(auth_vector->kc, value, value_len);
Harald Weltef53cc962016-04-25 15:36:08 +0200125 presence |= (1 << 2);
126 break;
127
128 case OSMO_GSUP_IK_IE:
129 if (value_len != sizeof(auth_vector->ik))
130 goto parse_error;
131 memcpy(auth_vector->ik, value, value_len);
132 presence |= (1 << 4);
133 break;
134
135 case OSMO_GSUP_CK_IE:
136 if (value_len != sizeof(auth_vector->ck))
137 goto parse_error;
138 memcpy(auth_vector->ck, value, value_len);
139 presence |= (1 << 5);
140 break;
141
142 case OSMO_GSUP_AUTN_IE:
143 if (value_len != sizeof(auth_vector->autn))
144 goto parse_error;
145 memcpy(auth_vector->autn, value, value_len);
146 presence |= (1 << 6);
147 break;
148 case OSMO_GSUP_RES_IE:
149 if (value_len > sizeof(auth_vector->res))
150 goto parse_error;
151 memcpy(auth_vector->res, value, value_len);
152 auth_vector->res_len = value_len;
153 presence |= (1 << 7);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100154 break;
155
156 default:
157 LOGP(DGPRS, LOGL_ERROR,
158 "GSUP IE type %d not expected in PDP info\n", iei);
159 continue;
160 }
161 }
162
Harald Weltef53cc962016-04-25 15:36:08 +0200163 if (presence & 0x07)
164 auth_vector->auth_types |= OSMO_AUTH_TYPE_GSM;
165 if (presence & 0xf0)
166 auth_vector->auth_types |= OSMO_AUTH_TYPE_UMTS;
167
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100168 return 0;
169
170parse_error:
171 LOGP(DGPRS, LOGL_ERROR,
Holger Hans Peter Freyther844f4b82015-04-23 11:55:23 -0400172 "GSUP IE type %d, length %zu invalid in PDP info\n", iei, value_len);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100173
174 return -1;
175}
176
Harald Weltee2b53492016-04-25 14:53:43 +0200177int osmo_gsup_decode(const uint8_t *const_data, size_t data_len,
178 struct osmo_gsup_message *gsup_msg)
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100179{
180 int rc;
181 uint8_t tag;
182 /* the shift/match functions expect non-const pointers, but we'll
183 * either copy the data or cast pointers back to const before returning
184 * them
185 */
186 uint8_t *data = (uint8_t *)const_data;
187 uint8_t *value;
188 size_t value_len;
Harald Weltee2b53492016-04-25 14:53:43 +0200189 static const struct osmo_gsup_pdp_info empty_pdp_info = {0};
Harald Welte34ef4c52016-04-20 13:13:19 +0200190 static const struct osmo_auth_vector empty_auth_info = {0};
Harald Weltee2b53492016-04-25 14:53:43 +0200191 static const struct osmo_gsup_message empty_gsup_message = {0};
Jacob Erlbeck6aa8b452015-01-12 13:54:39 +0100192
193 *gsup_msg = empty_gsup_message;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100194
195 /* generic part */
Harald Welte8f4b2b82016-04-25 15:14:01 +0200196 rc = osmo_shift_v_fixed(&data, &data_len, 1, &value);
Jacob Erlbecke27bc6c2015-01-12 13:23:05 +0100197 if (rc < 0)
198 return -GMM_CAUSE_INV_MAND_INFO;
199
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100200 gsup_msg->message_type = decode_big_endian(value, 1);
201
Harald Welte8f4b2b82016-04-25 15:14:01 +0200202 rc = osmo_match_shift_tlv(&data, &data_len, OSMO_GSUP_IMSI_IE,
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100203 &value, &value_len);
204
205 if (rc <= 0)
206 return -GMM_CAUSE_INV_MAND_INFO;
207
208 if (value_len * 2 + 1 > sizeof(gsup_msg->imsi))
209 return -GMM_CAUSE_INV_MAND_INFO;
210
211 /* Note that gsm48_decode_bcd_number expects the number of encoded IMSI
212 * octets in the first octet. By coincidence (the TLV encoding) the byte
213 * before the value part already contains this length so we can use it
214 * here.
215 */
216 OSMO_ASSERT(value[-1] == value_len);
217 gsm48_decode_bcd_number(gsup_msg->imsi, sizeof(gsup_msg->imsi),
218 value - 1, 0);
219
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100220 /* specific parts */
221 while (data_len > 0) {
Harald Weltee2b53492016-04-25 14:53:43 +0200222 enum osmo_gsup_iei iei;
223 struct osmo_gsup_pdp_info pdp_info;
Harald Welte34ef4c52016-04-20 13:13:19 +0200224 struct osmo_auth_vector auth_info;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100225
Harald Welte8f4b2b82016-04-25 15:14:01 +0200226 rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100227 if (rc < 0)
228 return -GMM_CAUSE_PROTO_ERR_UNSPEC;
229
230 iei = tag;
231
232 switch (iei) {
Harald Weltee2b53492016-04-25 14:53:43 +0200233 case OSMO_GSUP_IMSI_IE:
234 case OSMO_GSUP_PDP_TYPE_IE:
235 case OSMO_GSUP_ACCESS_POINT_NAME_IE:
236 case OSMO_GSUP_RAND_IE:
237 case OSMO_GSUP_SRES_IE:
238 case OSMO_GSUP_KC_IE:
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100239 LOGP(DGPRS, LOGL_NOTICE,
240 "GSUP IE type %d not expected (ignored)\n", iei);
241 continue;
242
Harald Weltee2b53492016-04-25 14:53:43 +0200243 case OSMO_GSUP_CAUSE_IE:
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100244 gsup_msg->cause = decode_big_endian(value, value_len);
245 break;
246
Harald Weltee2b53492016-04-25 14:53:43 +0200247 case OSMO_GSUP_CANCEL_TYPE_IE:
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100248 gsup_msg->cancel_type =
249 decode_big_endian(value, value_len) + 1;
250 break;
251
Harald Weltee2b53492016-04-25 14:53:43 +0200252 case OSMO_GSUP_PDP_INFO_COMPL_IE:
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100253 gsup_msg->pdp_info_compl = 1;
254 break;
255
Harald Weltee2b53492016-04-25 14:53:43 +0200256 case OSMO_GSUP_FREEZE_PTMSI_IE:
Jacob Erlbeckcd1b0552015-01-15 11:50:08 +0100257 gsup_msg->freeze_ptmsi = 1;
258 break;
259
Harald Weltee2b53492016-04-25 14:53:43 +0200260 case OSMO_GSUP_PDP_CONTEXT_ID_IE:
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100261 /* When these IE appear in the top-level part of the
262 * message, they are used by Delete Subscr Info to delete
263 * single entries. We don't have an extra list for
264 * these but use the PDP info list instead */
265
266 /* fall through */
267
Harald Weltee2b53492016-04-25 14:53:43 +0200268 case OSMO_GSUP_PDP_INFO_IE:
269 if (gsup_msg->num_pdp_infos >= OSMO_GSUP_MAX_NUM_PDP_INFO) {
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100270 LOGP(DGPRS, LOGL_ERROR,
271 "GSUP IE type %d (PDP_INFO) max exceeded\n",
272 iei);
273 return -GMM_CAUSE_COND_IE_ERR;
274 }
275
Jacob Erlbeck6aa8b452015-01-12 13:54:39 +0100276 pdp_info = empty_pdp_info;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100277
Harald Weltee2b53492016-04-25 14:53:43 +0200278 if (iei == OSMO_GSUP_PDP_INFO_IE) {
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100279 rc = decode_pdp_info(value, value_len, &pdp_info);
280 if (rc < 0)
281 return rc;
282 pdp_info.have_info = 1;
283 } else {
284 pdp_info.context_id =
285 decode_big_endian(value, value_len);
286 }
287
288 gsup_msg->pdp_infos[gsup_msg->num_pdp_infos++] =
289 pdp_info;
290 break;
291
Harald Weltee2b53492016-04-25 14:53:43 +0200292 case OSMO_GSUP_AUTH_TUPLE_IE:
293 if (gsup_msg->num_auth_vectors >= OSMO_GSUP_MAX_NUM_AUTH_INFO) {
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100294 LOGP(DGPRS, LOGL_ERROR,
295 "GSUP IE type %d (AUTH_INFO) max exceeded\n",
296 iei);
297 return -GMM_CAUSE_INV_MAND_INFO;
298 }
299
Jacob Erlbeck6aa8b452015-01-12 13:54:39 +0100300 auth_info = empty_auth_info;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100301
302 rc = decode_auth_info(value, value_len, &auth_info);
303 if (rc < 0)
304 return rc;
305
Harald Welte34ef4c52016-04-20 13:13:19 +0200306 gsup_msg->auth_vectors[gsup_msg->num_auth_vectors++] =
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100307 auth_info;
308 break;
Holger Hans Peter Freyther04662742015-04-22 23:09:41 -0400309
Harald Weltef53cc962016-04-25 15:36:08 +0200310 case OSMO_GSUP_AUTS_IE:
311 if (value_len != 16) {
312 LOGP(DGPRS, LOGL_ERROR,
313 "AUTS length != 16 received\n");
314 return -GMM_CAUSE_COND_IE_ERR;
315 }
316 gsup_msg->auts = value;
317 break;
318
Harald Weltee2b53492016-04-25 14:53:43 +0200319 case OSMO_GSUP_MSISDN_IE:
Holger Hans Peter Freyther04662742015-04-22 23:09:41 -0400320 gsup_msg->msisdn_enc = value;
321 gsup_msg->msisdn_enc_len = value_len;
322 break;
323
Harald Weltee2b53492016-04-25 14:53:43 +0200324 case OSMO_GSUP_HLR_NUMBER_IE:
Holger Hans Peter Freytherf0bfe382015-05-17 19:56:38 +0200325 gsup_msg->hlr_enc = value;
326 gsup_msg->hlr_enc_len = value_len;
327 break;
328
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100329 default:
330 LOGP(DGPRS, LOGL_NOTICE,
331 "GSUP IE type %d unknown\n", iei);
332 continue;
333 }
334 }
335
336 return 0;
337}
338
Harald Weltee2b53492016-04-25 14:53:43 +0200339static void encode_pdp_info(struct msgb *msg, enum osmo_gsup_iei iei,
340 const struct osmo_gsup_pdp_info *pdp_info)
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100341{
342 uint8_t *len_field;
343 size_t old_len;
344 uint8_t u8;
345
346 len_field = msgb_tlv_put(msg, iei, 0, NULL) - 1;
347 old_len = msgb_length(msg);
348
349 u8 = pdp_info->context_id;
Harald Weltee2b53492016-04-25 14:53:43 +0200350 msgb_tlv_put(msg, OSMO_GSUP_PDP_CONTEXT_ID_IE, sizeof(u8), &u8);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100351
352 if (pdp_info->pdp_type) {
Harald Weltee2b53492016-04-25 14:53:43 +0200353 msgb_tlv_put(msg, OSMO_GSUP_PDP_TYPE_IE,
354 OSMO_GSUP_PDP_TYPE_SIZE,
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100355 encode_big_endian(pdp_info->pdp_type | 0xf000,
Harald Weltee2b53492016-04-25 14:53:43 +0200356 OSMO_GSUP_PDP_TYPE_SIZE));
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100357 }
358
359 if (pdp_info->apn_enc) {
Harald Weltee2b53492016-04-25 14:53:43 +0200360 msgb_tlv_put(msg, OSMO_GSUP_ACCESS_POINT_NAME_IE,
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100361 pdp_info->apn_enc_len, pdp_info->apn_enc);
362 }
363
Holger Hans Peter Freyther2944e212015-04-23 09:13:01 -0400364 if (pdp_info->qos_enc) {
Harald Weltee2b53492016-04-25 14:53:43 +0200365 msgb_tlv_put(msg, OSMO_GSUP_PDP_QOS_IE,
Holger Hans Peter Freyther2944e212015-04-23 09:13:01 -0400366 pdp_info->qos_enc_len, pdp_info->qos_enc);
367 }
368
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100369 /* Update length field */
370 *len_field = msgb_length(msg) - old_len;
371}
372
Harald Weltee2b53492016-04-25 14:53:43 +0200373static void encode_auth_info(struct msgb *msg, enum osmo_gsup_iei iei,
Harald Welte34ef4c52016-04-20 13:13:19 +0200374 const struct osmo_auth_vector *auth_vector)
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100375{
376 uint8_t *len_field;
377 size_t old_len;
378
379 len_field = msgb_tlv_put(msg, iei, 0, NULL) - 1;
380 old_len = msgb_length(msg);
381
Harald Weltee2b53492016-04-25 14:53:43 +0200382 msgb_tlv_put(msg, OSMO_GSUP_RAND_IE,
Harald Welte34ef4c52016-04-20 13:13:19 +0200383 sizeof(auth_vector->rand), auth_vector->rand);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100384
Harald Weltee2b53492016-04-25 14:53:43 +0200385 msgb_tlv_put(msg, OSMO_GSUP_SRES_IE,
Harald Welte34ef4c52016-04-20 13:13:19 +0200386 sizeof(auth_vector->sres), auth_vector->sres);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100387
Harald Weltee2b53492016-04-25 14:53:43 +0200388 msgb_tlv_put(msg, OSMO_GSUP_KC_IE,
Harald Welte34ef4c52016-04-20 13:13:19 +0200389 sizeof(auth_vector->kc), auth_vector->kc);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100390
391 /* Update length field */
392 *len_field = msgb_length(msg) - old_len;
393}
394
Harald Weltee2b53492016-04-25 14:53:43 +0200395void osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message *gsup_msg)
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100396{
397 uint8_t u8;
398 int idx;
399 uint8_t bcd_buf[GSM48_MI_SIZE] = {0};
400 size_t bcd_len;
401
402 /* generic part */
403 OSMO_ASSERT(gsup_msg->message_type);
404 msgb_v_put(msg, gsup_msg->message_type);
405
406 bcd_len = gsm48_encode_bcd_number(bcd_buf, sizeof(bcd_buf), 0,
407 gsup_msg->imsi);
408
409 OSMO_ASSERT(bcd_len > 1);
410
411 /* Note that gsm48_encode_bcd_number puts the length into the first
412 * octet. Since msgb_tlv_put will add this length byte, we'll have to
413 * skip it */
Harald Weltee2b53492016-04-25 14:53:43 +0200414 msgb_tlv_put(msg, OSMO_GSUP_IMSI_IE, bcd_len - 1, &bcd_buf[1]);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100415
416 /* specific parts */
Holger Hans Peter Freyther04662742015-04-22 23:09:41 -0400417 if (gsup_msg->msisdn_enc)
Harald Weltee2b53492016-04-25 14:53:43 +0200418 msgb_tlv_put(msg, OSMO_GSUP_MSISDN_IE,
Holger Hans Peter Freyther04662742015-04-22 23:09:41 -0400419 gsup_msg->msisdn_enc_len, gsup_msg->msisdn_enc);
Holger Hans Peter Freytherf0bfe382015-05-17 19:56:38 +0200420 if (gsup_msg->hlr_enc)
Harald Weltee2b53492016-04-25 14:53:43 +0200421 msgb_tlv_put(msg, OSMO_GSUP_HLR_NUMBER_IE,
Holger Hans Peter Freytherf0bfe382015-05-17 19:56:38 +0200422 gsup_msg->hlr_enc_len, gsup_msg->hlr_enc);
Holger Hans Peter Freyther04662742015-04-22 23:09:41 -0400423
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100424 if ((u8 = gsup_msg->cause))
Harald Weltee2b53492016-04-25 14:53:43 +0200425 msgb_tlv_put(msg, OSMO_GSUP_CAUSE_IE, sizeof(u8), &u8);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100426
427 if ((u8 = gsup_msg->cancel_type)) {
428 u8 -= 1;
Harald Weltee2b53492016-04-25 14:53:43 +0200429 msgb_tlv_put(msg, OSMO_GSUP_CANCEL_TYPE_IE, sizeof(u8), &u8);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100430 }
431
432 if (gsup_msg->pdp_info_compl)
Harald Weltee2b53492016-04-25 14:53:43 +0200433 msgb_tlv_put(msg, OSMO_GSUP_PDP_INFO_COMPL_IE, 0, &u8);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100434
Jacob Erlbeckcd1b0552015-01-15 11:50:08 +0100435 if (gsup_msg->freeze_ptmsi)
Harald Weltee2b53492016-04-25 14:53:43 +0200436 msgb_tlv_put(msg, OSMO_GSUP_FREEZE_PTMSI_IE, 0, &u8);
Jacob Erlbeckcd1b0552015-01-15 11:50:08 +0100437
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100438 for (idx = 0; idx < gsup_msg->num_pdp_infos; idx++) {
Harald Weltee2b53492016-04-25 14:53:43 +0200439 const struct osmo_gsup_pdp_info *pdp_info;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100440
441 pdp_info = &gsup_msg->pdp_infos[idx];
442
443 if (pdp_info->context_id == 0)
444 continue;
445
446 if (pdp_info->have_info) {
Harald Weltee2b53492016-04-25 14:53:43 +0200447 encode_pdp_info(msg, OSMO_GSUP_PDP_INFO_IE, pdp_info);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100448 } else {
449 u8 = pdp_info->context_id;
Harald Weltee2b53492016-04-25 14:53:43 +0200450 msgb_tlv_put(msg, OSMO_GSUP_PDP_CONTEXT_ID_IE,
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100451 sizeof(u8), &u8);
452 }
453 }
454
Harald Welte34ef4c52016-04-20 13:13:19 +0200455 for (idx = 0; idx < gsup_msg->num_auth_vectors; idx++) {
456 const struct osmo_auth_vector *auth_vector;
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100457
Harald Welte34ef4c52016-04-20 13:13:19 +0200458 auth_vector = &gsup_msg->auth_vectors[idx];
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100459
Harald Weltee2b53492016-04-25 14:53:43 +0200460 encode_auth_info(msg, OSMO_GSUP_AUTH_TUPLE_IE, auth_vector);
Jacob Erlbeckef8e30a2014-12-11 16:54:14 +0100461 }
462}