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 | |
Vadim Yanitskiy | 30cfeeb | 2018-08-03 05:44:00 +0700 | [diff] [blame] | 7 | #include <osmocom/core/msgb.h> |
| 8 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 9 | #include <osmocom/gsm/tlv.h> |
| 10 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 11 | #include <osmocom/gsm/gsm48_ie.h> |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 12 | #include <osmocom/gsm/gsm23003.h> |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 13 | |
Harald Welte | 276ca4b | 2014-08-24 17:35:19 +0200 | [diff] [blame] | 14 | /* reserved according to GSM 03.03 ยง 2.4 */ |
| 15 | #define GSM_RESERVED_TMSI 0xFFFFFFFF |
| 16 | |
Neels Hofmeyr | ccfc387 | 2018-02-20 15:14:14 +0100 | [diff] [blame] | 17 | /* Valid MCC and MNC range from 0 to 999. |
| 18 | * To mark an invalid / unset MNC, this value shall be used. */ |
| 19 | #define GSM_MCC_MNC_INVALID 0xFFFF |
| 20 | |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 21 | /* A parsed GPRS routing area */ |
| 22 | struct gprs_ra_id { |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 23 | uint16_t mcc; |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 24 | uint16_t mnc; |
| 25 | bool mnc_3_digits; |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 26 | uint16_t lac; |
| 27 | uint8_t rac; |
| 28 | }; |
| 29 | |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 30 | extern const struct tlv_definition gsm48_att_tlvdef; |
Andreas Eversberg | 014cb87 | 2010-07-12 09:11:00 +0200 | [diff] [blame] | 31 | extern const struct tlv_definition gsm48_rr_att_tlvdef; |
| 32 | extern const struct tlv_definition gsm48_mm_att_tlvdef; |
Harald Welte | 9eb6d88 | 2010-03-25 12:00:54 +0800 | [diff] [blame] | 33 | const char *gsm48_cc_state_name(uint8_t state); |
| 34 | const char *gsm48_cc_msg_name(uint8_t msgtype); |
Philipp | 72e43f0 | 2016-10-27 13:35:20 +0200 | [diff] [blame] | 35 | const char *gsm48_rr_msg_name(uint8_t msgtype); |
Harald Welte | 4fb2075 | 2010-03-02 23:17:33 +0100 | [diff] [blame] | 36 | const char *rr_cause_name(uint8_t cause); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 37 | const char *osmo_rai_name(const struct gprs_ra_id *rai); |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 38 | 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] | 39 | 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] | 40 | |
Harald Welte | 774a9de | 2012-07-13 21:35:13 +0200 | [diff] [blame] | 41 | 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] | 42 | uint16_t *mnc, uint16_t *lac) |
| 43 | 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] | 44 | 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] | 45 | 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] | 46 | uint16_t mnc, uint16_t lac) |
| 47 | 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] | 48 | void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai); |
| 49 | |
Harald Welte | 1c3bae1 | 2019-01-20 10:37:49 +0100 | [diff] [blame] | 50 | #define GSM48_MID_MAX_SIZE 11 |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 51 | int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi); |
| 52 | int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi); |
Max | ebf1492 | 2018-02-15 11:42:11 +0100 | [diff] [blame] | 53 | uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type); |
Harald Welte | 61e2bfc | 2010-03-04 10:53:03 +0100 | [diff] [blame] | 54 | |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 55 | /* Convert Mobile Identity (10.5.1.4) to string */ |
| 56 | int gsm48_mi_to_string(char *string, const int str_len, |
Harald Welte | 163d0ea | 2010-04-09 07:57:40 +0200 | [diff] [blame] | 57 | const uint8_t *mi, const int mi_len); |
Harald Welte | 1a8c4e0 | 2015-08-16 17:56:25 +0200 | [diff] [blame] | 58 | const char *gsm48_mi_type_name(uint8_t mi); |
Neels Hofmeyr | 02fd83d | 2019-01-05 00:38:54 +0100 | [diff] [blame] | 59 | const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len); |
Harald Welte | 4a62eda | 2019-03-18 18:27:00 +0100 | [diff] [blame] | 60 | char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len); |
Harald Welte | 179f357 | 2019-03-18 18:38:47 +0100 | [diff] [blame] | 61 | char *osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len); |
Harald Welte | 9bb553e | 2010-03-28 18:14:50 +0800 | [diff] [blame] | 62 | |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 63 | /* Parse Routeing Area Identifier */ |
| 64 | void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 65 | 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] | 66 | int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) OSMO_DEPRECATED("Use gsm48_encode_ra() instead"); |
Harald Welte | a1c4f76 | 2010-05-01 11:59:42 +0200 | [diff] [blame] | 67 | |
Harald Welte | 2aee7b1 | 2011-06-26 14:20:04 +0200 | [diff] [blame] | 68 | 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] | 69 | |
Neels Hofmeyr | bd6c8b5 | 2018-03-22 14:05:21 +0100 | [diff] [blame] | 70 | void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc) |
| 71 | OSMO_DEPRECATED("Use osmo_plmn_to_bcd() instead, to not lose leading zeros in the MNC"); |
| 72 | void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc) |
| 73 | 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] | 74 | |
| 75 | struct gsm48_hdr *gsm48_push_l3hdr(struct msgb *msg, |
| 76 | uint8_t pdisc, uint8_t msg_type); |
| 77 | |
| 78 | #define gsm48_push_l3hdr_tid(msg, pdisc, tid, msg_type) \ |
| 79 | gsm48_push_l3hdr(msg, (pdisc & 0x0f) | (tid << 4), msg_type) |