blob: 0ca5b52e2bdbe67384fd86c3db444f21512c5d13 [file] [log] [blame]
Philipp Maiere190e032018-12-07 12:31:08 +01001/* (C) 2018 by sysmocom s.f.m.c. GmbH
2 * All Rights Reserved
3 *
4 * Author: Harald Welte, Philipp Maier
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Philipp Maiere190e032018-12-07 12:31:08 +010017 */
18
Harald Welte67211442018-10-07 20:10:57 +020019#include <osmocom/core/utils.h>
20#include <osmocom/gsm/tlv.h>
21
22#include <osmocom/gsm/protocol/gsm_29_118.h>
Philipp Maiere190e032018-12-07 12:31:08 +010023#include <osmocom/gsm/gsm29118.h>
24#include <osmocom/gsm/apn.h>
25#include <osmocom/gsm/gsm48.h>
Harald Welte67211442018-10-07 20:10:57 +020026
27const struct value_string sgsap_msg_type_names[] = {
28 { SGSAP_MSGT_PAGING_REQ, "PAGING-REQUEST" },
29 { SGSAP_MSGT_PAGING_REJ, "PAGING-REJECT" },
30 { SGSAP_MSGT_SERVICE_REQ, "SERVICE-REQUEST" },
31 { SGSAP_MSGT_DL_UD, "DOWNLINK-UNITDATA" },
32 { SGSAP_MSGT_UL_UD, "UPLINK-UNITDATA" },
33 { SGSAP_MSGT_LOC_UPD_REQ, "LOCATION-UPDATE-REQUEST" },
34 { SGSAP_MSGT_LOC_UPD_ACK, "LOCATION-UPDATE-ACCEPT" },
35 { SGSAP_MSGT_LOC_UPD_REJ, "LOCATION-UPDATE-REJECT" },
36 { SGSAP_MSGT_TMSI_REALL_CMPL, "TMSI-REALLOCATION-COMPLETE" },
37 { SGSAP_MSGT_ALERT_REQ, "ALERT-REQQUEST" },
38 { SGSAP_MSGT_ALERT_ACK, "ALERT-ACK" },
39 { SGSAP_MSGT_ALERT_REJ, "ALERT-REJECT" },
40 { SGSAP_MSGT_UE_ACT_IND, "UE-ACTIVITY-INDICATION" },
41 { SGSAP_MSGT_EPS_DET_IND, "EPS-DETACH-INDICATION" },
42 { SGSAP_MSGT_EPS_DET_ACK, "EPS-DETACH-ACK" },
43 { SGSAP_MSGT_IMSI_DET_IND, "IMSI-DETACH-INDICATION" },
44 { SGSAP_MSGT_IMSI_DET_ACK, "IMSI-DETACH-ACK" },
45 { SGSAP_MSGT_RESET_IND, "RESET-INDICATION" },
46 { SGSAP_MSGT_RESET_ACK, "RESET-ACK" },
47 { SGSAP_MSGT_SERVICE_ABORT_REQ, "SERVICE-ABORT-REQUEST" },
48 { SGSAP_MSGT_MO_CSFB_IND, "MO-CSFB-INDICATION" },
49 { SGSAP_MSGT_MM_INFO_REQ, "MM-INFO-REQUEST" },
50 { SGSAP_MSGT_RELEASE_REQ, "RELEASE-REQUEST" },
51 { SGSAP_MSGT_STATUS, "STATUS" },
52 { SGSAP_MSGT_UE_UNREACHABLE, "UE-UNREACHABLE" },
53 { 0, NULL }
54};
55
Philipp Maier086b3452018-11-15 15:04:29 +010056const struct value_string sgsap_iei_names[] = {
57 { SGSAP_IE_IMSI, "IMSI" },
58 { SGSAP_IE_VLR_NAME, "VLR-NAME" },
59 { SGSAP_IE_TMSI, "TMSI" },
60 { SGSAP_IE_LAI, "LAI" },
61 { SGSAP_IE_CHAN_NEEDED, "CHAN-NEEDED" },
62 { SGSAP_IE_EMLPP_PRIORITY, "EMLPP-PRIORITY" },
63 { SGSAP_IE_TMSI_STATUS, "TMSI-STATUS" },
64 { SGSAP_IE_SGS_CAUSE, "SGS-CAUSE" },
65 { SGSAP_IE_MME_NAME, "MME-NAME" },
66 { SGSAP_IE_EPS_LU_TYPE, "EPS-LU-TYPE" },
67 { SGSAP_IE_GLOBAL_CN_ID, "GLOBAL-CN-ID" },
68 { SGSAP_IE_MOBILE_ID, "MOBILE-ID" },
69 { SGSAP_IE_REJECT_CAUSE, "REJECT-CAUSE" },
70 { SGSAP_IE_IMSI_DET_EPS_TYPE, "IMSI-DET-EPS-TYPE" },
71 { SGSAP_IE_IMSI_DET_NONEPS_TYPE, "IMSI-DET-NONEPS-TYPE" },
72 { SGSAP_IE_IMEISV, "IMEISV" },
73 { SGSAP_IE_NAS_MSG_CONTAINER, "NAS-MSG-CONTAINER" },
74 { SGSAP_IE_MM_INFO, "MM-INFO" },
75 { SGSAP_IE_ERR_MSG, "ERR-MSG" },
76 { SGSAP_IE_CLI, "CLI" },
77 { SGSAP_IE_LCS_CLIENT_ID, "LCS-CLIENT-ID" },
78 { SGSAP_IE_LCS_INDICATOR, "LCS-INDICATOR" },
79 { SGSAP_IE_SS_CODE, "SS-CODE" },
80 { SGSAP_IE_SERVICE_INDICATOR, "SERVICE-INDICATOR" },
81 { SGSAP_IE_UE_TIMEZONE, "UE-TIMEZONE" },
82 { SGSAP_IE_MS_CLASSMARK2, "MS-CLASSMARK2" },
83 { SGSAP_IE_TAI, "TAI" },
84 { SGSAP_IE_EUTRAN_CGI, "EUTRAN-CGI" },
85 { SGSAP_IE_UE_EMM_MODE, "UE-EMM-MODE" },
86 { SGSAP_IE_ADDL_PAGING_INDICATORS, "ADDL-PAGING-INDICATORS" },
87 { SGSAP_IE_TMSI_BASED_NRI_CONT, "TMSI-BASED-NRI-CONT" },
Omar Ramadan76bbcbc2019-05-09 10:13:46 -070088 { SGSAP_IE_MO_FALLBACK_VALUE, "MO-FALLBACK-VALUE" },
Philipp Maier086b3452018-11-15 15:04:29 +010089 { 0, NULL }
90};
91
Harald Welte67211442018-10-07 20:10:57 +020092const struct value_string sgsap_eps_lu_type_names[] = {
93 { SGSAP_EPS_LUT_IMSI_ATTACH, "IMSI Attach" },
94 { SGSAP_EPS_LUT_NORMAL, "Normal" },
95 { 0, NULL }
96};
97
98const struct value_string sgsap_ismi_det_eps_type_names[] = {
99 { SGSAP_ID_EPS_T_NETWORK_INITIATED, "Network initiated IMSI detach from EPS" },
100 { SGSAP_ID_EPS_T_UE_INITIATED, "UE initiated IMSI detach from EPS" },
101 { SGSAP_ID_EPS_T_EPS_NOT_ALLOWED, "EPS not allowed" },
102 { 0, NULL }
103};
104
105const struct value_string sgsap_ismi_det_noneps_type_names[] = {
106 { SGSAP_ID_NONEPS_T_EXPLICIT_UE_NONEPS,
107 "Explicit UE initiated IMSI detach from non-EPS" },
108 { SGSAP_ID_NONEPS_T_COMBINED_UE_EPS_NONEPS,
109 "Combined UE initiated IMSI detach from EPS and non-EPS" },
110 { SGSAP_ID_NONEPS_T_IMPLICIT_UE_EPS_NONEPS,
111 "Implicit network initiated IMSI detach from EPS and non-EPS" },
112 { 0, NULL }
113};
114
115const struct value_string sgsap_service_ind_names[] = {
116 { SGSAP_SERV_IND_CS_CALL, "CS Call" },
117 { SGSAP_SERV_IND_SMS, "SMS" },
118 { 0, NULL }
119};
120
121const struct value_string sgsap_sgs_cause_names[] = {
122 { SGSAP_SGS_CAUSE_IMSI_DET_EPS, "IMSI detached for EPS" },
123 { SGSAP_SGS_CAUSE_IMSI_DET_EPS_NONEPS, "IMSI detached for EPS and non-EPS" },
124 { SGSAP_SGS_CAUSE_IMSI_UNKNOWN, "IMSI unknown" },
125 { SGSAP_SGS_CAUSE_IMSI_DET_NON_EPS, "IMSI detached for non-EPS" },
126 { SGSAP_SGS_CAUSE_IMSI_IMPL_DET_NON_EPS,"IMSI implicitly detached for non-EPS" },
127 { SGSAP_SGS_CAUSE_UE_UNREACHABLE, "UE unreachable" },
128 { SGSAP_SGS_CAUSE_MSG_INCOMP_STATE, "Message not compatible with protocol state" },
129 { SGSAP_SGS_CAUSE_MISSING_MAND_IE, "Missing mandatory IE" },
130 { SGSAP_SGS_CAUSE_INVALID_MAND_IE, "Invalid mandatory IE" },
131 { SGSAP_SGS_CAUSE_COND_IE_ERROR, "Conditional IE error" },
132 { SGSAP_SGS_CAUSE_SEMANT_INCORR_MSG, "Semantically incorrect message" },
133 { SGSAP_SGS_CAUSE_MSG_UNKNOWN, "Message unknown" },
134 { SGSAP_SGS_CAUSE_MT_CSFB_REJ_USER, "MT CSFB call rejected by user" },
135 { SGSAP_SGS_CAUSE_UE_TEMP_UNREACHABLE, "UE temporarily unreachable" },
136 { 0, NULL }
137};
138
139
140const struct value_string sgsap_ue_emm_mode_names[] = {
141 { SGSAP_UE_EMM_MODE_IDLE, "EMM-IDLE" },
142 { SGSAP_UE_EMM_MODE_CONNECTED, "EMM-CONNECTED" },
143 { 0, NULL }
144};
145
146const struct tlv_definition sgsap_ie_tlvdef = {
147 .def = {
148 [SGSAP_IE_IMSI] = { TLV_TYPE_TLV },
149 [SGSAP_IE_VLR_NAME] = { TLV_TYPE_TLV },
150 [SGSAP_IE_TMSI] = { TLV_TYPE_TLV },
151 [SGSAP_IE_LAI] = { TLV_TYPE_TLV },
152 [SGSAP_IE_CHAN_NEEDED] = { TLV_TYPE_TLV },
153 [SGSAP_IE_EMLPP_PRIORITY] = { TLV_TYPE_TLV },
154 [SGSAP_IE_TMSI_STATUS] = { TLV_TYPE_TLV },
155 [SGSAP_IE_SGS_CAUSE] = { TLV_TYPE_TLV },
156 [SGSAP_IE_MME_NAME] = { TLV_TYPE_TLV },
157 [SGSAP_IE_EPS_LU_TYPE] = { TLV_TYPE_TLV },
158 [SGSAP_IE_GLOBAL_CN_ID] = { TLV_TYPE_TLV },
159 [SGSAP_IE_MOBILE_ID] = { TLV_TYPE_TLV },
160 [SGSAP_IE_REJECT_CAUSE] = { TLV_TYPE_TLV },
161 [SGSAP_IE_IMSI_DET_EPS_TYPE] = { TLV_TYPE_TLV },
162 [SGSAP_IE_IMSI_DET_NONEPS_TYPE] = { TLV_TYPE_TLV },
163 [SGSAP_IE_IMEISV] = { TLV_TYPE_TLV },
164 [SGSAP_IE_NAS_MSG_CONTAINER] = { TLV_TYPE_TLV },
165 [SGSAP_IE_MM_INFO] = { TLV_TYPE_TLV },
166 [SGSAP_IE_ERR_MSG] = { TLV_TYPE_TLV },
167 [SGSAP_IE_CLI] = { TLV_TYPE_TLV },
168 [SGSAP_IE_LCS_CLIENT_ID] = { TLV_TYPE_TLV },
169 [SGSAP_IE_LCS_INDICATOR] = { TLV_TYPE_TLV },
170 [SGSAP_IE_SS_CODE] = { TLV_TYPE_TLV },
171 [SGSAP_IE_SERVICE_INDICATOR] = { TLV_TYPE_TLV },
172 [SGSAP_IE_UE_TIMEZONE] = { TLV_TYPE_TLV },
173 [SGSAP_IE_MS_CLASSMARK2] = { TLV_TYPE_TLV },
174 [SGSAP_IE_TAI] = { TLV_TYPE_TLV },
175 [SGSAP_IE_EUTRAN_CGI] = { TLV_TYPE_TLV },
176 [SGSAP_IE_UE_EMM_MODE] = { TLV_TYPE_TLV },
177 [SGSAP_IE_ADDL_PAGING_INDICATORS]={ TLV_TYPE_TLV },
178 [SGSAP_IE_TMSI_BASED_NRI_CONT] = { TLV_TYPE_TLV },
Omar Ramadan76bbcbc2019-05-09 10:13:46 -0700179 [SGSAP_IE_MO_FALLBACK_VALUE] = { TLV_TYPE_TLV },
Harald Welte67211442018-10-07 20:10:57 +0200180 },
181};
Philipp Maiere190e032018-12-07 12:31:08 +0100182
183
184/* Allocate an empty message buffer, suitable to hold a complete SGsAP msg. */
185struct msgb *gsm29118_msgb_alloc(void)
186{
187 /* by far sufficient for the maximum size message of 298 bytes
188 * (9+7+5+3+10+253+10+1) SGsAP-UP-UD */
189 return msgb_alloc_headroom(1024, 512, "SGsAP");
190}
191
192/* Encode VLR/MME name from string and append to SGsAP msg */
193static int msgb_sgsap_name_put(struct msgb *msg, enum sgsap_iei iei, const char *name)
194{
195 uint8_t buf[APN_MAXLEN];
196 uint8_t len;
Philipp Maierd6ef6f12019-01-08 10:40:18 +0100197 int rc;
198
Philipp Maiere190e032018-12-07 12:31:08 +0100199 /* encoding is like DNS names, which is like APN fields */
200 memset(buf, 0, sizeof(buf));
Philipp Maierd6ef6f12019-01-08 10:40:18 +0100201 rc = osmo_apn_from_str(buf, sizeof(buf), name);
202 if (rc < 0)
203 return -1;
204 len = (uint8_t)rc;
Philipp Maiere190e032018-12-07 12:31:08 +0100205
206 /* Note: While the VLR-Name (see 3GPP TS 29.118, chapter 9.4.22) has
207 * a flexible length, the MME-Name has a fixed size of 55 octets. (see
208 * 3GPP TS 29.118, chapter 9.4.13). */
209 if (iei == SGSAP_IE_MME_NAME && len != SGS_MME_NAME_LEN)
210 return -1;
211 msgb_tlv_put(msg, iei, len, buf);
212 return 0;
213}
214
215/* Encode IMSI from string representation and append to SGSaAP msg */
216static void msgb_sgsap_imsi_put(struct msgb *msg, const char *imsi)
217{
Harald Weltea13fb752020-06-16 08:44:42 +0200218 uint8_t buf[16];
219 uint8_t len;
220 /* encoding is just like TS 04.08 */
221 len = gsm48_generate_mid_from_imsi(buf, imsi);
222 /* skip first two bytes (tag+length) so we can use msgb_tlv_put */
223 msgb_tlv_put(msg, SGSAP_IE_IMSI, len - 2, buf + 2);
Philipp Maiere190e032018-12-07 12:31:08 +0100224}
225
226/* Encode LAI from struct representation and append to SGSaAP msg */
227static void msgb_sgsap_lai_put(struct msgb *msg, const struct osmo_location_area_id *lai)
228{
229 struct gsm48_loc_area_id lai_enc;
230 gsm48_generate_lai2(&lai_enc, lai);
231 msgb_tlv_put(msg, SGSAP_IE_LAI, sizeof(lai_enc), (uint8_t *) & lai_enc);
232}
233
234/* Many messages consist only of a message type and an imsi */
235static struct msgb *create_simple_msg(enum sgsap_msg_type msg_type, const char *imsi)
236{
237 struct msgb *msg = gsm29118_msgb_alloc();
238 msgb_sgsap_imsi_put(msg, imsi);
239 msgb_push_u8(msg, msg_type);
240 return msg;
241}
242
243/* 8.3 SGsAP-ALERT-REQUEST.
244 * \param[in] imsi IMSI of the subscriber.
245 * \returns callee-allocated msgb with the encoded message.*/
246struct msgb *gsm29118_create_alert_req(const char *imsi)
247{
248 return create_simple_msg(SGSAP_MSGT_ALERT_REQ, imsi);
249}
250
251/* 8.4 SGsAP-DOWNLINK-UNITDATA.
252 * \param[in] imsi IMSI of the subscriber.
253 * \param[in] nas_msg user provided message buffer with L3 message.
254 * \returns callee-allocated msgb with the encoded message. */
255struct msgb *gsm29118_create_dl_ud(const char *imsi, struct msgb *nas_msg)
256{
257 struct msgb *msg = gsm29118_msgb_alloc();
258 msgb_sgsap_imsi_put(msg, imsi);
259 msgb_tlv_put(msg, SGSAP_IE_NAS_MSG_CONTAINER, nas_msg->len, nas_msg->data);
260 msgb_push_u8(msg, SGSAP_MSGT_DL_UD);
261 return msg;
262}
263
264/* 8.5 SGsAP-EPS-DETACH-ACK.
265 * \param[in] imsi IMSI of the subscriber.
266 * \returns callee-allocated msgb with the encoded message. */
267struct msgb *gsm29118_create_eps_det_ack(const char *imsi)
268{
269 return create_simple_msg(SGSAP_MSGT_EPS_DET_ACK, imsi);
270}
271
272/* 8.7 SGsAP-IMSI-DETACH-ACK.
273 * \param[in] imsi IMSI of the subscriber.
274 * \returns callee-allocated msgb with the encoded message. */
275struct msgb *gsm29118_create_imsi_det_ack(const char *imsi)
276{
277 return create_simple_msg(SGSAP_MSGT_IMSI_DET_ACK, imsi);
278}
279
280/*! 8.9 SGsAP-LOCATION-UPDATE-ACCEPT.
281 * \param[in] imsi IMSI of the subscriber.
282 * \param[in] lai Location Area Identity (optional, may be NULL).
283 * \param[in] new_id value part of new Mobile Identity (optional, may be NULL).
284 * \param[in] new_id_len length of \a new_id in octets.
285 * \returns callee-allocated msgb with the encoded message */
286struct msgb *gsm29118_create_lu_ack(const char *imsi, const struct osmo_location_area_id *lai, const uint8_t *new_id,
287 unsigned int new_id_len)
288{
289 struct msgb *msg = gsm29118_msgb_alloc();
290 msgb_sgsap_imsi_put(msg, imsi);
291 msgb_sgsap_lai_put(msg, lai);
292 if (new_id && new_id_len)
293 msgb_tlv_put(msg, SGSAP_IE_MOBILE_ID, new_id_len, new_id);
294 msgb_push_u8(msg, SGSAP_MSGT_LOC_UPD_ACK);
295 return msg;
296}
297
298/* 8.10 SGsAP-LOCATION-UPDATE-REJECT.
299 * \param[in] imsi IMSI of the subscriber.
300 * \param[in] rej_cause LU cause code, see also 3GPP TS 29.018, subclause 18.4.21.
301 * \param[in] lai location area identifier.
302 * \returns callee-allocated msgb with the encoded message */
303struct msgb *gsm29118_create_lu_rej(const char *imsi, uint8_t rej_cause, const struct osmo_location_area_id *lai)
304{
305 struct msgb *msg = gsm29118_msgb_alloc();
306 msgb_sgsap_imsi_put(msg, imsi);
307 msgb_tlv_put(msg, SGSAP_IE_REJECT_CAUSE, 1, &rej_cause);
308 if (lai)
309 msgb_sgsap_lai_put(msg, lai);
310 msgb_push_u8(msg, SGSAP_MSGT_LOC_UPD_REJ);
311 return msg;
312}
313
314/* 8.12 SGsAP-MM-INFORMATION-REQUEST.
315 * \param[in] imsi IMSI of the subscriber.
316 * \param[in] mm_info MM information, see also 3GPP TS 29.018, subclause 18.4.16.
317 * \param[in] mm_info_len length of \a mm_info in octets.
318 * \returns callee-allocated msgb with the encoded message. */
319struct msgb *gsm29118_create_mm_info_req(const char *imsi, const uint8_t *mm_info, uint8_t mm_info_len)
320{
321 struct msgb *msg = gsm29118_msgb_alloc();
322 msgb_sgsap_imsi_put(msg, imsi);
323 msgb_tlv_put(msg, SGSAP_IE_MM_INFO, mm_info_len, mm_info);
324 msgb_push_u8(msg, SGSAP_MSGT_MM_INFO_REQ);
325 return msg;
326}
327
328/* 8.14 SGsAP-PAGING-REQUEST.
329 * \param[in] params user provided memory with message contents to encode.
330 * \returns callee-allocated msgb with the encoded message or NULL on error. */
331struct msgb *gsm29118_create_paging_req(struct gsm29118_paging_req *params)
332{
333 int rc;
334 struct msgb *msg = gsm29118_msgb_alloc();
335 msgb_sgsap_imsi_put(msg, params->imsi);
336 rc = msgb_sgsap_name_put(msg, SGSAP_IE_VLR_NAME, params->vlr_name);
337 if (rc < 0)
338 goto error;
339 msgb_tlv_put(msg, SGSAP_IE_SERVICE_INDICATOR, 1, &params->serv_ind);
340 if (params->lai_present)
341 msgb_sgsap_lai_put(msg, &params->lai);
342 msgb_push_u8(msg, SGSAP_MSGT_PAGING_REQ);
343 return msg;
344error:
345 msgb_free(msg);
346 return NULL;
347}
348
349/* 8.15 SGsAP-RESET-ACK.
350 * \param[in] params user provided memory with message contents to encode.
351 * \returns callee-allocated msgb with the encoded message or NULL on error. */
352struct msgb *gsm29118_create_reset_ack(struct gsm29118_reset_msg *params)
353{
354 int rc;
355 struct msgb *msg = gsm29118_msgb_alloc();
356 if (params->vlr_name_present && params->mme_name_present == false)
357 rc = msgb_sgsap_name_put(msg, SGSAP_IE_VLR_NAME, params->vlr_name);
358 else if (params->mme_name_present && params->vlr_name_present == false)
359 rc = msgb_sgsap_name_put(msg, SGSAP_IE_MME_NAME, params->mme_name);
360 else
361 goto error;
362 if (rc < 0)
363 goto error;
364 msgb_push_u8(msg, SGSAP_MSGT_RESET_ACK);
365 return msg;
366error:
367 msgb_free(msg);
368 return NULL;
369}
370
371/* 8.16 SGsAP-RESET-INDICATION.
372 * \param[in] params user provided memory with message contents to encode.
373 * \returns callee-allocated msgb with the encoded message or NULL on error. */
374struct msgb *gsm29118_create_reset_ind(struct gsm29118_reset_msg *params)
375{
376 int rc;
377 struct msgb *msg = gsm29118_msgb_alloc();
378 if (params->vlr_name_present && params->mme_name_present == false)
379 rc = msgb_sgsap_name_put(msg, SGSAP_IE_VLR_NAME, params->vlr_name);
380 else if (params->mme_name_present && params->vlr_name_present == false)
381 rc = msgb_sgsap_name_put(msg, SGSAP_IE_MME_NAME, params->mme_name);
382 else
383 goto error;
384 if (rc < 0)
385 goto error;
386 msgb_push_u8(msg, SGSAP_MSGT_RESET_IND);
387 return msg;
388error:
389 msgb_free(msg);
390 return NULL;
391}
392
393/* 8.18 SGsAP-STATUS.
394 * \param[in] imsi IMSI of the subscriber.
395 * \param[in] cause sgs related cause code.
396 * \param[in] err_msg user provided message buffer containing the errornous message.
397 * \returns callee-allocated msgb with the encoded message */
398struct msgb *gsm29118_create_status(const char *imsi, enum sgsap_sgs_cause cause, const struct msgb *err_msg)
399{
400 struct msgb *msg = gsm29118_msgb_alloc();
401 uint8_t c8 = cause;
402 unsigned int err_msg_len;
403 msgb_tlv_put(msg, SGSAP_IE_SGS_CAUSE, 1, &c8);
404 if (imsi)
405 msgb_sgsap_imsi_put(msg, imsi);
406 if (err_msg) {
407 err_msg_len = msgb_l2len(err_msg);
408 if (err_msg_len > 255)
409 err_msg_len = 255;
410 msgb_tlv_put(msg, SGSAP_IE_ERR_MSG, err_msg_len, msgb_l2(err_msg));
411 }
412 msgb_push_u8(msg, SGSAP_MSGT_STATUS);
413 return msg;
414}
415
416/* 8.23 SGsAP-RELEASE-REQUEST.
417 * \param[in] imsi IMSI of the subscriber.
418 * \param[in] cause sgs related cause code.
419 * \returns callee-allocated msgb with the encoded message. */
420struct msgb *gsm29118_create_release_req(const char *imsi, const uint8_t sgs_cause)
421{
422 struct msgb *msg = gsm29118_msgb_alloc();
423 msgb_sgsap_imsi_put(msg, imsi);
424 if (sgs_cause)
425 msgb_tlv_put(msg, SGSAP_IE_SGS_CAUSE, 1, &sgs_cause);
426 msgb_push_u8(msg, SGSAP_MSGT_RELEASE_REQ);
427 return msg;
428}
429
430/* 8.24 SGsAP-SERVICE-ABORT-REQUEST.
431 * \param[in] imsi IMSI of the subscriber.
432 * \returns callee-allocated msgb with the encoded message. */
433struct msgb *gsm29118_create_service_abort_req(const char *imsi)
434{
435 return create_simple_msg(SGSAP_MSGT_SERVICE_ABORT_REQ, imsi);
436}