Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gsm48.h */ |
| 2 | |
Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 3 | #pragma once |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 4 | |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 5 | #include <stdbool.h> |
| 6 | |
Neels Hofmeyr | 83025bf | 2020-05-26 02:45:23 +0200 | [diff] [blame] | 7 | #include <osmocom/core/defs.h> |
Vadim Yanitskiy | 30cfeeb | 2018-08-03 05:44:00 +0700 | [diff] [blame] | 8 | #include <osmocom/core/msgb.h> |
| 9 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 10 | #include <osmocom/gsm/tlv.h> |
| 11 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Neels Hofmeyr | 83025bf | 2020-05-26 02:45:23 +0200 | [diff] [blame] | 12 | #include <osmocom/gsm/protocol/gsm_23_003.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 13 | #include <osmocom/gsm/gsm48_ie.h> |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 14 | #include <osmocom/gsm/gsm23003.h> |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 15 | |
Harald Welte | 276ca4b | 2014-08-24 17:35:19 +0200 | [diff] [blame] | 16 | /* reserved according to GSM 03.03 ยง 2.4 */ |
| 17 | #define GSM_RESERVED_TMSI 0xFFFFFFFF |
| 18 | |
Neels Hofmeyr | ccfc387 | 2018-02-20 15:14:14 +0100 | [diff] [blame] | 19 | /* 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 Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 23 | /* A parsed GPRS routing area */ |
| 24 | struct gprs_ra_id { |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 25 | uint16_t mcc; |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 26 | uint16_t mnc; |
| 27 | bool mnc_3_digits; |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 28 | uint16_t lac; |
| 29 | uint8_t rac; |
| 30 | }; |
| 31 | |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 32 | extern const struct tlv_definition gsm48_att_tlvdef; |
Andreas Eversberg | 014cb87 | 2010-07-12 09:11:00 +0200 | [diff] [blame] | 33 | extern const struct tlv_definition gsm48_rr_att_tlvdef; |
| 34 | extern const struct tlv_definition gsm48_mm_att_tlvdef; |
Harald Welte | 9eb6d88 | 2010-03-25 12:00:54 +0800 | [diff] [blame] | 35 | const char *gsm48_cc_state_name(uint8_t state); |
| 36 | const char *gsm48_cc_msg_name(uint8_t msgtype); |
Philipp | 72e43f0 | 2016-10-27 13:35:20 +0200 | [diff] [blame] | 37 | const char *gsm48_rr_msg_name(uint8_t msgtype); |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 38 | const char *rr_cause_name(uint8_t cause); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 39 | const char *osmo_rai_name(const struct gprs_ra_id *rai); |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 40 | char *osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai); |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 41 | char *osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai); |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 42 | |
Harald Welte | 774a9de | 2012-07-13 21:35:13 +0200 | [diff] [blame] | 43 | int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc, |
Neels Hofmeyr | bd6c8b5 | 2018-03-22 14:05:21 +0100 | [diff] [blame] | 44 | uint16_t *mnc, uint16_t *lac) |
| 45 | OSMO_DEPRECATED("Use gsm48_decode_lai2() instead, to not lose leading zeros in the MNC"); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 46 | void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded); |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 47 | void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc, |
Neels Hofmeyr | bd6c8b5 | 2018-03-22 14:05:21 +0100 | [diff] [blame] | 48 | uint16_t mnc, uint16_t lac) |
| 49 | OSMO_DEPRECATED("Use gsm48_generate_lai2() instead, to not lose leading zeros in the MNC"); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 50 | void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai); |
| 51 | |
Harald Welte | 1c3bae1 | 2019-01-20 10:37:49 +0100 | [diff] [blame] | 52 | #define GSM48_MID_MAX_SIZE 11 |
Neels Hofmeyr | 83025bf | 2020-05-26 02:45:23 +0200 | [diff] [blame] | 53 | int 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(...)"); |
| 56 | int 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(...)"); |
| 59 | uint8_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 Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 62 | |
Harald Welte | 1a8c4e0 | 2015-08-16 17:56:25 +0200 | [diff] [blame] | 63 | const char *gsm48_mi_type_name(uint8_t mi); |
Neels Hofmeyr | 83025bf | 2020-05-26 02:45:23 +0200 | [diff] [blame] | 64 | /* Convert encoded Mobile Identity (10.5.1.4) to string */ |
| 65 | int 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()"); |
| 67 | const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len) |
| 68 | OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()"); |
| 69 | char *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()"); |
| 71 | char *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(). */ |
| 76 | struct 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 | |
| 93 | int osmo_mobile_identity_to_str_buf(char *buf, size_t buflen, const struct osmo_mobile_identity *mi); |
| 94 | char *osmo_mobile_identity_to_str_c(void *ctx, const struct osmo_mobile_identity *mi); |
| 95 | int osmo_mobile_identity_cmp(const struct osmo_mobile_identity *a, const struct osmo_mobile_identity *b); |
| 96 | int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t *mi_data, uint8_t mi_len, |
| 97 | bool allow_hex); |
| 98 | int osmo_mobile_identity_decode_from_l3(struct osmo_mobile_identity *mi, struct msgb *msg, bool allow_hex); |
| 99 | int osmo_mobile_identity_encoded_len(const struct osmo_mobile_identity *mi, int *mi_digits); |
| 100 | int osmo_mobile_identity_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_mobile_identity *mi, bool allow_hex); |
| 101 | int osmo_mobile_identity_encode_msgb(struct msgb *msg, const struct osmo_mobile_identity *mi, bool allow_hex); |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 102 | |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 103 | /* Parse Routeing Area Identifier */ |
| 104 | void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 105 | void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid); |
Max | 309d0e5 | 2018-01-05 14:21:25 +0100 | [diff] [blame] | 106 | int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) OSMO_DEPRECATED("Use gsm48_encode_ra() instead"); |
Philipp Maier | d11a5d5 | 2021-02-03 22:11:46 +0100 | [diff] [blame] | 107 | bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2); |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 108 | |
Harald Welte | 2aee7b1 | 2011-06-26 14:20:04 +0200 | [diff] [blame] | 109 | int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc); |
Neels Hofmeyr | bdccc1b | 2016-03-15 13:28:10 +0100 | [diff] [blame] | 110 | |
Neels Hofmeyr | bd6c8b5 | 2018-03-22 14:05:21 +0100 | [diff] [blame] | 111 | void 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"); |
| 113 | void 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 Yanitskiy | 30cfeeb | 2018-08-03 05:44:00 +0700 | [diff] [blame] | 115 | |
| 116 | struct 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 Hofmeyr | a9da9f7 | 2021-04-16 15:36:58 +0200 | [diff] [blame] | 121 | |
| 122 | enum gsm48_chan_mode gsm48_chan_mode_to_vamos(enum gsm48_chan_mode mode); |
| 123 | enum gsm48_chan_mode gsm48_chan_mode_to_non_vamos(enum gsm48_chan_mode mode); |