libosmogsm  1.8.0
Osmocom GSM library
gsup.h
Go to the documentation of this file.
1 
18 /*
19  * (C) 2014 by sysmocom - s.f.m.c. GmbH, Author: Jacob Erlbeck
20  * (C) 2016 by Harald Welte <laforge@gnumonks.org>
21  * All Rights Reserved
22  *
23  * SPDX-License-Identifier: GPL-2.0+
24  *
25  * This program is free software; you can redistribute it and/or modify
26  * it under the terms of the GNU General Public License as published by
27  * the Free Software Foundation; either version 2 of the License, or
28  * (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License
36  * along with this program. If not, see <http://www.gnu.org/licenses/>.
37  *
38  */
39 #pragma once
40 
41 #include <stdint.h>
42 #include <osmocom/core/msgb.h>
43 #include <osmocom/gsm/gsup_sms.h>
48 #include <osmocom/gsm/gsm_utils.h>
49 #include <osmocom/crypt/auth.h>
50 
51 #define OSMO_GSUP_PORT 4222
52 
54 #define OSMO_GSUP_MAX_NUM_PDP_INFO 10 /* GSM 09.02 limits this to 50 */
55 
56 #define OSMO_GSUP_MAX_NUM_AUTH_INFO 5
57 
58 #define OSMO_GSUP_MAX_MSISDN_LEN 9
59 #define OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN 43 /* TS 24.008 10.5.4.7 */
60 
61 #define OSMO_GSUP_PDP_TYPE_SIZE 2
62 
83  /* 3G support */
90  OSMO_GSUP_SUPPORTED_RAT_TYPES_IE = 0x29, /* supported RAT types */
91  OSMO_GSUP_CURRENT_RAT_TYPE_IE = 0x2a, /* currently used RAT type */
92 
95 
98 
99  /* SM related IEs (see 3GPP TS 29.002, section 7.6.8) */
107 
111 
112  /* Inter-MSC handover related */
119 
121 };
122 
139 
143 
145 
149 
153 
157 
161 
165 
169 
173 
177 
181 
185 
189 
193 
196 
199 
201 };
202 
203 #define OSMO_GSUP_MSGT_E_ROUTING_ERROR OSMO_GSUP_MSGT_ROUTING_ERROR
204 
205 #define OSMO_GSUP_IS_MSGT_REQUEST(msgt) (((msgt) & 0b00000011) == 0b00)
206 #define OSMO_GSUP_IS_MSGT_ERROR(msgt) (((msgt) & 0b00000011) == 0b01)
207 #define OSMO_GSUP_IS_MSGT_RESULT(msgt) (((msgt) & 0b00000011) == 0b10)
208 #define OSMO_GSUP_TO_MSGT_REQUEST(msgt) (((msgt) & 0b11111100))
209 #define OSMO_GSUP_TO_MSGT_ERROR(msgt) (((msgt) & 0b11111100) | 0b01)
210 #define OSMO_GSUP_TO_MSGT_RESULT(msgt) (((msgt) & 0b11111100) | 0b10)
211 
212 extern const struct value_string osmo_gsup_message_type_names[];
213 static inline const char *
216 
218  OSMO_GSUP_CANCEL_TYPE_UPDATE = 1, /* on wire: 0 */
219  OSMO_GSUP_CANCEL_TYPE_WITHDRAW = 2, /* on wire: 1 */
220 };
221 
225 };
226 
228  OSMO_GSUP_IMEI_RESULT_ACK = 1, /* on wire: 0 */
229  OSMO_GSUP_IMEI_RESULT_NACK = 2, /* on wire: 1 */
230 };
231 
232 /* 3GPP 29.002 AccessNetworkProtocolId */
236 };
237 
248 };
249 
250 extern const struct value_string osmo_gsup_session_state_names[];
251 static inline const char *
254 
257  unsigned int context_id;
260  uint16_t pdp_type;
263  const uint8_t *apn_enc;
265  size_t apn_enc_len;
268  const uint8_t *qos_enc;
270  size_t qos_enc_len;
273  const uint8_t *pdp_charg_enc;
276 };
277 
284  /* Keep this as last entry with a value of max(enum osmo_gsup_message_class) + 1.
285  * This value shall serve as the size for an array to aid de-muxing all known GSUP classes. */
287 };
288 
289 extern const struct value_string osmo_gsup_message_class_names[];
290 static inline const char *osmo_gsup_message_class_name(enum osmo_gsup_message_class val)
292 
295  /* AccessNetworkProtocolId as in 3GPP TS 29.002. */
296  enum osmo_gsup_access_network_protocol access_network_proto;
297  const uint8_t *data;
298  size_t data_len;
299 };
300 
303  enum osmo_gsup_message_type message_type;
304  char imsi[OSMO_IMSI_BUF_SIZE];
306  enum osmo_gsup_cancel_type cancel_type;
313  const uint8_t *msisdn_enc;
315  const uint8_t *hlr_enc;
316  size_t hlr_enc_len;
317  const uint8_t *auts;
318  const uint8_t *rand;
319  enum osmo_gsup_cn_domain cn_domain;
320  const uint8_t *pdp_charg_enc;
322 
324  enum osmo_gsup_session_state session_state;
327  uint32_t session_id;
328 
330  uint8_t *ss_info;
331  size_t ss_info_len;
332 
336  const uint8_t *sm_rp_mr;
338  enum osmo_gsup_sms_sm_rp_oda_t sm_rp_da_type;
339  size_t sm_rp_da_len;
340  const uint8_t *sm_rp_da;
342  enum osmo_gsup_sms_sm_rp_oda_t sm_rp_oa_type;
343  size_t sm_rp_oa_len;
344  const uint8_t *sm_rp_oa;
346  const uint8_t *sm_rp_ui;
347  size_t sm_rp_ui_len;
349  const uint8_t *sm_rp_cause;
351  const uint8_t *sm_rp_mms;
353  enum osmo_gsup_sms_sm_alert_rsn_t sm_alert_rsn;
354 
355  const uint8_t *imei_enc;
356  size_t imei_enc_len;
357  enum osmo_gsup_imei_result imei_result;
358 
362  enum osmo_gsup_message_class message_class;
363 
365  const uint8_t *source_name;
370  const uint8_t *destination_name;
373 
375  struct osmo_gsup_an_apdu an_apdu;
376 
377  uint8_t cause_rr;
380  enum gsm0808_cause cause_bssap;
384  enum gsm48_gsm_cause cause_sm;
385 
386  enum osmo_rat_type current_rat_type;
387  enum osmo_rat_type supported_rat_types[8];
389 };
390 
391 int osmo_gsup_decode(const uint8_t *data, size_t data_len,
392  struct osmo_gsup_message *gsup_msg);
393 int osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message *gsup_msg);
395  OSMO_DEPRECATED("Use OSMO_GSUP_TO_MSGT_ERROR() instead");
396 
AccessNetworkSignalInfo as in 3GPP TS 29.002.
Definition: gsup.h:294
osmo_gsup_cancel_type
Definition: gsup.h:217
Definition: gsup.h:116
const uint8_t * auts
Definition: gsup.h:317
Definition: gsup.h:152
Definition: gsup.h:103
Definition: gsup.h:82
size_t sm_rp_oa_len
Definition: gsup.h:343
Definition: gsup.h:282
Definition: gsup.h:218
Indication of the session end.
Definition: gsup.h:247
Definition: gsup.h:120
#define OSMO_DEPRECATED(text)
Definition: gsup.h:224
Definition: gsup.h:110
const struct value_string osmo_gsup_message_type_names[]
Definition: gsup.c:39
const char * get_value_string(const struct value_string *vs, uint32_t val)
Definition: gsup.h:104
Definition: gsup.h:66
Definition: gsup.h:73
Definition: gsup.h:65
const uint8_t * sm_rp_mms
SM-RP-MMS (More Messages to Send), section 7.6.8.7.
Definition: gsup.h:351
Definition: gsup.h:229
size_t num_pdp_infos
Definition: gsup.h:312
#define OSMO_GSUP_MAX_NUM_AUTH_INFO
Maximum number of auth info inside osmo_gsup_message.
Definition: gsup.h:56
uint16_t pdp_type
Type of PDP context.
Definition: gsup.h:260
Definition: gsup.h:80
const uint8_t * pdp_charg_enc
Definition: gsup.h:320
int freeze_ptmsi
Definition: gsup.h:308
Definition: gsup.h:91
bool cause_rr_set
whether cause_rr is set
Definition: gsup.h:378
Definition: gsup.h:67
Definition: gsup.h:94
const uint8_t * sm_rp_oa
Definition: gsup.h:344
Definition: gsup.h:197
int have_info
Definition: gsup.h:258
int pdp_info_compl
Definition: gsup.h:307
Definition: gsup.h:283
size_t data_len
Definition: gsup.h:298
Definition: gsup.h:74
Definition: gsup.h:87
const uint8_t * msisdn_enc
Definition: gsup.h:313
const uint8_t * source_name
For messages routed via another GSUP entity (via HLR), the IPA name of the entity that sent this mess...
Definition: gsup.h:365
size_t hlr_enc_len
Definition: gsup.h:316
Definition: gsup.h:113
Initiation of a new session.
Definition: gsup.h:243
size_t ss_info_len
Definition: gsup.h:331
uint8_t cause
Definition: gsm_04_08.h:768
const uint8_t * sm_rp_da
Definition: gsup.h:340
osmo_gsup_sms_sm_rp_oda_t
Possible identity types for SM-RP-{OA|DA}.
Definition: gsup_sms.h:16
unsigned int context_id
Definition: gsup.h:257
osmo_gsup_access_network_protocol
Definition: gsup.h:233
osmo_gsup_session_state
TCAP-like session state.
Definition: gsup.h:239
size_t sm_rp_ui_len
Definition: gsup.h:347
osmo_gsup_message_type
GSUP message type Make sure that new messages follow this scheme:
Definition: gsup.h:135
Definition: gsup.h:146
Definition: gsup.h:117
Definition: gsup.h:89
Definition: gsup.h:144
const uint8_t * destination_name
For messages routed via another GSUP entity (via HLR), the IPA name of the entity that should ultimat...
Definition: gsup.h:370
const uint8_t * sm_rp_cause
SM-RP-Cause value (1 oct.) as per GSM TS 04.11, section 8.2.5.4.
Definition: gsup.h:349
static const char * osmo_gsup_message_type_name(enum osmo_gsup_message_type val)
Definition: gsup.h:214
Definition: gsup.h:81
Definition: gsup.h:76
osmo_gsup_iei
Information Element Identifiers for GSUP IEs.
Definition: gsup.h:64
size_t source_name_len
Number of bytes in source_name.
Definition: gsup.h:367
Definition: gsup.h:179
Definition: gsup.h:175
Definition: gsup.h:156
const uint8_t * hlr_enc
Definition: gsup.h:315
Definition: gsup.h:162
Definition: gsup.h:93
Definition: gsup.h:200
uint8_t * ss_info
ASN.1 encoded MAP payload for Supplementary Services.
Definition: gsup.h:330
size_t msisdn_enc_len
Definition: gsup.h:314
Definition: gsup.h:286
Definition: gsup.h:180
Definition: gsup.h:115
static const char * osmo_gsup_message_class_name(enum osmo_gsup_message_class val)
Definition: gsup.h:290
Definition: gsup.h:219
uint8_t data[0]
Definition: gsup.h:72
size_t qos_enc_len
length (in octets) of qos_enc
Definition: gsup.h:270
#define OSMO_IMSI_BUF_SIZE
The char[] buffer size to completely contain an IMSI including the optional checksum digit as well as...
Definition: gsm_23_003.h:10
osmo_gsup_message_class
Definition: gsup.h:278
int osmo_gsup_decode(const uint8_t *data, size_t data_len, struct osmo_gsup_message *gsup_msg)
Decode (parse) a GSUP message.
Definition: gsup.c:296
Definition: gsup.h:75
Definition: gsup.h:71
Definition: gsup.h:281
gsm48_gsm_cause
Definition: gsm_04_08_gprs.h:242
Definition: gsup.h:114
Definition: gsup.h:279
uint32_t session_id
Unique session identifier and origination flag.
Definition: gsup.h:327
Supplementary Services payload.
Definition: gsup.h:97
gsm0808_cause
Definition: gsm_08_08.h:363
Definition: gsup.h:164
#define OSMO_GSUP_MAX_NUM_PDP_INFO
Maximum nubmer of PDP inside osmo_gsup_message.
Definition: gsup.h:54
Definition: gsup.h:79
parsed/decoded PDP context information
Definition: gsup.h:256
Definition: gsup.h:70
size_t pdp_charg_enc_len
Definition: gsup.h:321
gsm48_gmm_cause
Definition: gsm_04_08_gprs.h:206
osmo_rat_type
Definition: gsm_utils.h:253
Definition: gsup.h:68
bool cause_bssap_set
whether cause_bssap is set
Definition: gsup.h:381
const struct value_string osmo_gsup_session_state_names[]
Definition: gsup.c:109
Definition: gsup.h:155
const uint8_t * sm_rp_ui
SM-RP-UI (see 3GPP TS 29.002, 7.6.8.4), SMS TPDU.
Definition: gsup.h:346
Definition: gsup.h:102
static const char * osmo_gsup_session_state_name(enum osmo_gsup_session_state val)
Definition: gsup.h:252
uint8_t cause_rr
0 is a valid cause
Definition: gsup.h:377
Definition: gsup.h:228
Definition: gsup.h:100
Definition: gsup.h:147
uint8_t msg[0]
Definition: gsm_08_08.h:530
Definition: gsup.h:178
parsed/decoded GSUP protocol message
Definition: gsup.h:302
Definition: gsup.h:118
const uint8_t * data
Definition: gsup.h:297
Definition: gsup.h:106
const uint8_t * apn_enc
APN information, still in encoded form.
Definition: gsup.h:263
size_t pdp_charg_enc_len
length (in octets) of pdp_charg_enc
Definition: gsup.h:275
Definition: gsup.h:85
Definition: gsup.h:223
Definition: gsup.h:109
Definition: gsup.h:69
const uint8_t * pdp_charg_enc
PDP Charging Characteristics, still in encoded form.
Definition: gsup.h:273
size_t sm_rp_da_len
Definition: gsup.h:339
const uint8_t * rand
Definition: gsup.h:318
Definition: gsup.h:163
Definition: gsup.h:88
const struct value_string osmo_gsup_message_class_names[]
Definition: gsup.c:908
Definition: gsup.h:84
int osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message *gsup_msg)
Encode a GSUP message.
Definition: gsup.c:698
const uint8_t * imei_enc
Definition: gsup.h:355
Definition: gsup.h:151
const uint8_t * qos_enc
QoS information, still in encoded form.
Definition: gsup.h:268
Definition: gsup.h:86
Definition: gsup.h:78
const uint8_t * sm_rp_mr
SM-RP-MR (see 3GPP TS 29.002, 7.6.1.1), Message Reference.
Definition: gsup.h:336
Definition: gsup.h:77
Undefined session state.
Definition: gsup.h:241
Definition: gsup.h:148
size_t imei_enc_len
Definition: gsup.h:356
GSM TS 03.40.
size_t apn_enc_len
length (in octets) of apn_enc
Definition: gsup.h:265
Definition: gsup.h:101
osmo_gsup_imei_result
Definition: gsup.h:227
size_t destination_name_len
Number of bytes in destination_name.
Definition: gsup.h:372
Communication of an existing session.
Definition: gsup.h:245
Definition: auth.h:60
Definition: gsup.h:198
Definition: gsup.h:105
Definition: gsup.h:108
int osmo_gsup_get_err_msg_type(enum osmo_gsup_message_type type_in) OSMO_DEPRECATED("Use OSMO_GSUP_TO_MSGT_ERROR() instead")
return the error message type corresponding to type_in.
Definition: gsup.c:120
GSM utility functions, e.g.
SMS (Short Message Service) extensions for Osmocom GSUP.
size_t supported_rat_types_len
Definition: gsup.h:388
osmo_gsup_sms_sm_alert_rsn_t
Alert reason values, see 7.6.8.8.
Definition: gsup_sms.h:26
osmo_gsup_cn_domain
Definition: gsup.h:222
size_t num_auth_vectors
Definition: gsup.h:310