libosmogsm  0.11.0-dirty
Osmocom GSM library
include/osmocom/gsm/gsup.h
Go to the documentation of this file.
00001 
00018 /*
00019  * (C) 2014 by sysmocom - s.f.m.c. GmbH, Author: Jacob Erlbeck
00020  * (C) 2016 by Harald Welte <laforge@gnumonks.org>
00021  * All Rights Reserved
00022  *
00023  * SPDX-License-Identifier: GPL-2.0+
00024  *
00025  * This program is free software; you can redistribute it and/or modify
00026  * it under the terms of the GNU General Public License as published by
00027  * the Free Software Foundation; either version 2 of the License, or
00028  * (at your option) any later version.
00029  *
00030  * This program is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00033  * GNU General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU General Public License
00036  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00037  *
00038  */
00039 #pragma once
00040 
00041 #include <stdint.h>
00042 #include <osmocom/core/msgb.h>
00043 #include <osmocom/gsm/protocol/gsm_23_003.h>
00044 #include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
00045 #include <osmocom/crypt/auth.h>
00046 
00047 #define OSMO_GSUP_PORT 4222
00048 
00050 #define OSMO_GSUP_MAX_NUM_PDP_INFO              10 /* GSM 09.02 limits this to 50 */
00051 
00052 #define OSMO_GSUP_MAX_NUM_AUTH_INFO             5
00053 
00054 #define OSMO_GSUP_MAX_MSISDN_LEN                9
00055 #define OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN      43 /* TS 24.008 10.5.4.7 */
00056 
00057 #define OSMO_GSUP_PDP_TYPE_SIZE                 2
00058 
00060 enum osmo_gsup_iei {
00061         OSMO_GSUP_IMSI_IE                       = 0x01,
00062         OSMO_GSUP_CAUSE_IE                      = 0x02,
00063         OSMO_GSUP_AUTH_TUPLE_IE                 = 0x03,
00064         OSMO_GSUP_PDP_INFO_COMPL_IE             = 0x04,
00065         OSMO_GSUP_PDP_INFO_IE                   = 0x05,
00066         OSMO_GSUP_CANCEL_TYPE_IE                = 0x06,
00067         OSMO_GSUP_FREEZE_PTMSI_IE               = 0x07,
00068         OSMO_GSUP_MSISDN_IE                     = 0x08,
00069         OSMO_GSUP_HLR_NUMBER_IE                 = 0x09,
00070         OSMO_GSUP_PDP_CONTEXT_ID_IE             = 0x10,
00071         OSMO_GSUP_PDP_TYPE_IE                   = 0x11,
00072         OSMO_GSUP_ACCESS_POINT_NAME_IE          = 0x12,
00073         OSMO_GSUP_PDP_QOS_IE                    = 0x13,
00074         OSMO_GSUP_CHARG_CHAR_IE                 = 0x14,
00075         OSMO_GSUP_RAND_IE                       = 0x20,
00076         OSMO_GSUP_SRES_IE                       = 0x21,
00077         OSMO_GSUP_KC_IE                         = 0x22,
00078         /* 3G support */
00079         OSMO_GSUP_IK_IE                         = 0x23,
00080         OSMO_GSUP_CK_IE                         = 0x24,
00081         OSMO_GSUP_AUTN_IE                       = 0x25,
00082         OSMO_GSUP_AUTS_IE                       = 0x26,
00083         OSMO_GSUP_RES_IE                        = 0x27,
00084         OSMO_GSUP_CN_DOMAIN_IE                  = 0x28,
00085 };
00086 
00088 enum osmo_gsup_message_type {
00089         OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST  = 0b00000100,
00090         OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR    = 0b00000101,
00091         OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT   = 0b00000110,
00092 
00093         OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST   = 0b00001000,
00094         OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR     = 0b00001001,
00095         OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT    = 0b00001010,
00096 
00097         OSMO_GSUP_MSGT_AUTH_FAIL_REPORT         = 0b00001011,
00098 
00099         OSMO_GSUP_MSGT_PURGE_MS_REQUEST         = 0b00001100,
00100         OSMO_GSUP_MSGT_PURGE_MS_ERROR           = 0b00001101,
00101         OSMO_GSUP_MSGT_PURGE_MS_RESULT          = 0b00001110,
00102 
00103         OSMO_GSUP_MSGT_INSERT_DATA_REQUEST      = 0b00010000,
00104         OSMO_GSUP_MSGT_INSERT_DATA_ERROR        = 0b00010001,
00105         OSMO_GSUP_MSGT_INSERT_DATA_RESULT       = 0b00010010,
00106 
00107         OSMO_GSUP_MSGT_DELETE_DATA_REQUEST      = 0b00010100,
00108         OSMO_GSUP_MSGT_DELETE_DATA_ERROR        = 0b00010101,
00109         OSMO_GSUP_MSGT_DELETE_DATA_RESULT       = 0b00010110,
00110 
00111         OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST  = 0b00011100,
00112         OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR    = 0b00011101,
00113         OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT   = 0b00011110,
00114 };
00115 
00116 #define OSMO_GSUP_IS_MSGT_REQUEST(msgt) (((msgt) & 0b00000011) == 0b00)
00117 #define OSMO_GSUP_IS_MSGT_ERROR(msgt)   (((msgt) & 0b00000011) == 0b01)
00118 #define OSMO_GSUP_TO_MSGT_ERROR(msgt)   (((msgt) & 0b11111100) | 0b01)
00119 
00120 extern const struct value_string osmo_gsup_message_type_names[];
00121 static inline const char *
00122 osmo_gsup_message_type_name(enum osmo_gsup_message_type val)
00123 {       return get_value_string(osmo_gsup_message_type_names, val); }
00124 
00125 enum osmo_gsup_cancel_type {
00126         OSMO_GSUP_CANCEL_TYPE_UPDATE            = 1, /* on wire: 0 */
00127         OSMO_GSUP_CANCEL_TYPE_WITHDRAW          = 2, /* on wire: 1 */
00128 };
00129 
00130 enum osmo_gsup_cn_domain {
00131         OSMO_GSUP_CN_DOMAIN_PS                  = 1,
00132         OSMO_GSUP_CN_DOMAIN_CS                  = 2,
00133 };
00134 
00136 struct osmo_gsup_pdp_info {
00137         unsigned int                    context_id;
00138         int                             have_info;
00140         uint16_t                        pdp_type;
00143         const uint8_t                   *apn_enc;
00145         size_t                          apn_enc_len;
00148         const uint8_t                   *qos_enc;
00150         size_t                          qos_enc_len;
00153         const uint8_t                   *pdp_charg_enc;
00155         size_t                          pdp_charg_enc_len;
00156 };
00157 
00159 struct osmo_gsup_message {
00160         enum osmo_gsup_message_type     message_type;
00161         char                            imsi[GSM23003_IMSI_MAX_DIGITS+2];
00162         enum gsm48_gmm_cause            cause;
00163         enum osmo_gsup_cancel_type      cancel_type;
00164         int                             pdp_info_compl;
00165         int                             freeze_ptmsi;
00166         struct osmo_auth_vector         auth_vectors[OSMO_GSUP_MAX_NUM_AUTH_INFO];
00167         size_t                          num_auth_vectors;
00168         struct osmo_gsup_pdp_info       pdp_infos[OSMO_GSUP_MAX_NUM_PDP_INFO];
00169         size_t                          num_pdp_infos;
00170         const uint8_t                   *msisdn_enc;
00171         size_t                          msisdn_enc_len;
00172         const uint8_t                   *hlr_enc;
00173         size_t                          hlr_enc_len;
00174         const uint8_t                   *auts;
00175         const uint8_t                   *rand;
00176         enum osmo_gsup_cn_domain        cn_domain;
00177         const uint8_t                   *pdp_charg_enc;
00178         size_t                          pdp_charg_enc_len;
00179 };
00180 
00181 int osmo_gsup_decode(const uint8_t *data, size_t data_len,
00182                      struct osmo_gsup_message *gsup_msg);
00183 int osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message *gsup_msg);
00184 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines