blob: c1ca6308524dd7e5885086044ade895b37b26237 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gsm48.h */
2
Sylvain Munaut12ba7782014-06-16 10:13:40 +02003#pragma once
Harald Welte4fb20752010-03-02 23:17:33 +01004
Neels Hofmeyrc4fce142018-02-20 13:47:08 +01005#include <stdbool.h>
6
Neels Hofmeyr83025bf2020-05-26 02:45:23 +02007#include <osmocom/core/defs.h>
Vadim Yanitskiy30cfeeb2018-08-03 05:44:00 +07008#include <osmocom/core/msgb.h>
9
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010010#include <osmocom/gsm/tlv.h>
11#include <osmocom/gsm/protocol/gsm_04_08.h>
Neels Hofmeyr83025bf2020-05-26 02:45:23 +020012#include <osmocom/gsm/protocol/gsm_23_003.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010013#include <osmocom/gsm/gsm48_ie.h>
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010014#include <osmocom/gsm/gsm23003.h>
Harald Welte4fb20752010-03-02 23:17:33 +010015
Harald Welte276ca4b2014-08-24 17:35:19 +020016/* reserved according to GSM 03.03 ยง 2.4 */
17#define GSM_RESERVED_TMSI 0xFFFFFFFF
18
Neels Hofmeyrccfc3872018-02-20 15:14:14 +010019/* Valid MCC and MNC range from 0 to 999.
20 * To mark an invalid / unset MNC, this value shall be used. */
21#define GSM_MCC_MNC_INVALID 0xFFFF
22
Harald Weltea1c4f762010-05-01 11:59:42 +020023/* A parsed GPRS routing area */
24struct gprs_ra_id {
Harald Weltea1c4f762010-05-01 11:59:42 +020025 uint16_t mcc;
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010026 uint16_t mnc;
27 bool mnc_3_digits;
Harald Weltea1c4f762010-05-01 11:59:42 +020028 uint16_t lac;
29 uint8_t rac;
30};
31
Harald Welte4fb20752010-03-02 23:17:33 +010032extern const struct tlv_definition gsm48_att_tlvdef;
Andreas Eversberg014cb872010-07-12 09:11:00 +020033extern const struct tlv_definition gsm48_rr_att_tlvdef;
34extern const struct tlv_definition gsm48_mm_att_tlvdef;
Harald Welte9eb6d882010-03-25 12:00:54 +080035const char *gsm48_cc_state_name(uint8_t state);
36const char *gsm48_cc_msg_name(uint8_t msgtype);
Philipp72e43f02016-10-27 13:35:20 +020037const char *gsm48_rr_msg_name(uint8_t msgtype);
Harald Welte4fb20752010-03-02 23:17:33 +010038const char *rr_cause_name(uint8_t cause);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010039const char *osmo_rai_name(const struct gprs_ra_id *rai);
Harald Welte4a62eda2019-03-18 18:27:00 +010040char *osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai);
Harald Welte179f3572019-03-18 18:38:47 +010041char *osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai);
Harald Welte4fb20752010-03-02 23:17:33 +010042
Harald Welte774a9de2012-07-13 21:35:13 +020043int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010044 uint16_t *mnc, uint16_t *lac)
45 OSMO_DEPRECATED("Use gsm48_decode_lai2() instead, to not lose leading zeros in the MNC");
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010046void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded);
Harald Welte61e2bfc2010-03-04 10:53:03 +010047void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010048 uint16_t mnc, uint16_t lac)
49 OSMO_DEPRECATED("Use gsm48_generate_lai2() instead, to not lose leading zeros in the MNC");
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010050void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai);
51
Harald Welte1c3bae12019-01-20 10:37:49 +010052#define GSM48_MID_MAX_SIZE 11
Neels Hofmeyr83025bf2020-05-26 02:45:23 +020053int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi)
54 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
55 " *l = osmo_mobile_identity_encode_msgb(...)");
56int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi)
57 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
58 " *l = osmo_mobile_identity_encode_msgb(...)");
59uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type)
60 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
61 " *l = osmo_mobile_identity_encode_msgb(...)");
Harald Welte61e2bfc2010-03-04 10:53:03 +010062
Harald Welte1a8c4e02015-08-16 17:56:25 +020063const char *gsm48_mi_type_name(uint8_t mi);
Neels Hofmeyr83025bf2020-05-26 02:45:23 +020064/* Convert encoded Mobile Identity (10.5.1.4) to string */
65int gsm48_mi_to_string(char *string, int str_len, const uint8_t *mi, int mi_len)
66 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_decode()");
67const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len)
68 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()");
69char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len)
70 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_buf()");
71char *osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len)
72 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()");
73
74/*! Decoded representation of a Mobile Identity (3GPP TS 24.008 10.5.1.4).
75 * See osmo_mobile_identity_decode() and osmo_mobile_identity_from_l3(). */
76struct osmo_mobile_identity {
77 /*! A GSM_MI_TYPE_* constant (like GSM_MI_TYPE_IMSI). */
78 uint8_t type;
79 /*! Decoded Mobile Identity digits or TMSI value. IMSI, IMEI and IMEISV as digits like
80 * "12345678", and TMSI is represented as raw uint32_t. */
81 union {
82 /*! type == GSM_MI_TYPE_IMSI. */
83 char imsi[GSM23003_IMSI_MAX_DIGITS + 1];
84 /*! type == GSM_MI_TYPE_IMEI. */
85 char imei[GSM23003_IMEI_NUM_DIGITS + 1];
86 /*! type == GSM_MI_TYPE_IMEISV. */
87 char imeisv[GSM23003_IMEISV_NUM_DIGITS + 1];
88 /*! TMSI / P-TMSI / M-TMSI integer value if type == GSM_MI_TYPE_TMSI. */
89 uint32_t tmsi;
90 };
91};
92
93int osmo_mobile_identity_to_str_buf(char *buf, size_t buflen, const struct osmo_mobile_identity *mi);
94char *osmo_mobile_identity_to_str_c(void *ctx, const struct osmo_mobile_identity *mi);
95int osmo_mobile_identity_cmp(const struct osmo_mobile_identity *a, const struct osmo_mobile_identity *b);
96int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t *mi_data, uint8_t mi_len,
97 bool allow_hex);
98int osmo_mobile_identity_decode_from_l3(struct osmo_mobile_identity *mi, struct msgb *msg, bool allow_hex);
99int osmo_mobile_identity_encoded_len(const struct osmo_mobile_identity *mi, int *mi_digits);
100int osmo_mobile_identity_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_mobile_identity *mi, bool allow_hex);
101int osmo_mobile_identity_encode_msgb(struct msgb *msg, const struct osmo_mobile_identity *mi, bool allow_hex);
Harald Welte9bb553e2010-03-28 18:14:50 +0800102
Harald Weltea1c4f762010-05-01 11:59:42 +0200103/* Parse Routeing Area Identifier */
104void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
Maxf1ad60e2018-01-05 14:19:33 +0100105void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid);
Max309d0e52018-01-05 14:21:25 +0100106int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) OSMO_DEPRECATED("Use gsm48_encode_ra() instead");
Philipp Maierd11a5d52021-02-03 22:11:46 +0100107bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2);
Harald Weltea1c4f762010-05-01 11:59:42 +0200108
Harald Welte2aee7b12011-06-26 14:20:04 +0200109int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc);
Neels Hofmeyrbdccc1b2016-03-15 13:28:10 +0100110
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +0100111void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc)
112 OSMO_DEPRECATED("Use osmo_plmn_to_bcd() instead, to not lose leading zeros in the MNC");
113void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc)
114 OSMO_DEPRECATED("Use osmo_plmn_from_bcd() instead, to not lose leading zeros in the MNC");
Vadim Yanitskiy30cfeeb2018-08-03 05:44:00 +0700115
116struct gsm48_hdr *gsm48_push_l3hdr(struct msgb *msg,
117 uint8_t pdisc, uint8_t msg_type);
118
119#define gsm48_push_l3hdr_tid(msg, pdisc, tid, msg_type) \
120 gsm48_push_l3hdr(msg, (pdisc & 0x0f) | (tid << 4), msg_type)
Neels Hofmeyra9da9f72021-04-16 15:36:58 +0200121
122enum gsm48_chan_mode gsm48_chan_mode_to_vamos(enum gsm48_chan_mode mode);
123enum gsm48_chan_mode gsm48_chan_mode_to_non_vamos(enum gsm48_chan_mode mode);