libosmogsm 1.9.0.196-9975
Osmocom GSM library
gsm48.h
Go to the documentation of this file.
1
3#pragma once
4
5#include <stdbool.h>
6
7#include <osmocom/core/defs.h>
8#include <osmocom/core/msgb.h>
9
10#include <osmocom/gsm/tlv.h>
15
16/* reserved according to GSM 03.03 § 2.4 */
17#define GSM_RESERVED_TMSI 0xFFFFFFFF
18
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
23/* A parsed GPRS routing area.
24 * Preferably use struct osmo_routing_area_id, it is better integrated with API like osmo_plmn_cmp().
25 */
26struct gprs_ra_id {
27 uint16_t mcc;
28 uint16_t mnc;
30 uint16_t lac;
31 uint8_t rac;
32};
33
34extern const struct tlv_definition gsm48_att_tlvdef;
35extern const struct tlv_definition gsm48_rr_att_tlvdef;
36extern const struct tlv_definition gsm48_mm_att_tlvdef;
37const char *gsm48_cc_state_name(uint8_t state);
38const char *gsm48_cc_msg_name(uint8_t msgtype);
39const char *gsm48_rr_msg_name(uint8_t msgtype);
40const char *gsm48_rr_short_pd_msg_name(uint8_t msgtype);
41const char *rr_cause_name(uint8_t cause);
42const char *osmo_rai_name(const struct gprs_ra_id *rai);
43char *osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai);
44char *osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai);
45
46int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc,
47 uint16_t *mnc, uint16_t *lac)
48 OSMO_DEPRECATED("Use gsm48_decode_lai2() instead, to not lose leading zeros in the MNC");
49void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded);
50void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc,
51 uint16_t mnc, uint16_t lac)
52 OSMO_DEPRECATED("Use gsm48_generate_lai2() instead, to not lose leading zeros in the MNC");
53void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai);
54
55#define GSM48_MID_MAX_SIZE 11
56int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi)
57 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
58 " *l = osmo_mobile_identity_encode_msgb(...)");
59int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi)
60 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
61 " *l = osmo_mobile_identity_encode_msgb(...)");
62uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type)
63 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
64 " *l = osmo_mobile_identity_encode_msgb(...)");
65
66const char *gsm48_mi_type_name(uint8_t mi);
67/* Convert encoded Mobile Identity (10.5.1.4) to string */
68int gsm48_mi_to_string(char *string, int str_len, const uint8_t *mi, int mi_len)
69 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_decode()");
70const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len)
71 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()");
72char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len)
73 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_buf()");
74char *osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len)
75 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()");
76
79struct osmo_mobile_identity {
81 uint8_t type;
84 union {
86 char imsi[GSM23003_IMSI_MAX_DIGITS + 1];
88 char imei[GSM23003_IMEI_NUM_DIGITS + 1];
90 char imeisv[GSM23003_IMEISV_NUM_DIGITS + 1];
92 uint32_t tmsi;
93 };
94};
95
96int osmo_mobile_identity_to_str_buf(char *buf, size_t buflen, const struct osmo_mobile_identity *mi);
97char *osmo_mobile_identity_to_str_c(void *ctx, const struct osmo_mobile_identity *mi);
98int osmo_mobile_identity_cmp(const struct osmo_mobile_identity *a, const struct osmo_mobile_identity *b);
99int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t *mi_data, uint8_t mi_len,
100 bool allow_hex);
101int osmo_mobile_identity_decode_from_l3_buf(struct osmo_mobile_identity *mi, const uint8_t *l3_data, size_t l3_len,
102 bool allow_hex);
103int osmo_mobile_identity_decode_from_l3(struct osmo_mobile_identity *mi, struct msgb *msg, bool allow_hex);
104int osmo_mobile_identity_encoded_len(const struct osmo_mobile_identity *mi, int *mi_digits);
105int osmo_mobile_identity_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_mobile_identity *mi, bool allow_hex);
106int osmo_mobile_identity_encode_msgb(struct msgb *msg, const struct osmo_mobile_identity *mi, bool allow_hex);
107
108/* Parse Routeing Area Identifier */
109int osmo_routing_area_id_decode(struct osmo_routing_area_id *dst, const uint8_t *ra_data, size_t ra_data_len);
110int osmo_routing_area_id_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_routing_area_id *src);
111int osmo_routing_area_id_encode_msgb(struct msgb *msg, const struct osmo_routing_area_id *src);
112void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
113void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid);
114int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) OSMO_DEPRECATED("Use gsm48_encode_ra() instead");
115bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2);
116
118
119void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc)
120 OSMO_DEPRECATED("Use osmo_plmn_to_bcd() instead, to not lose leading zeros in the MNC");
121void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc)
122 OSMO_DEPRECATED("Use osmo_plmn_from_bcd() instead, to not lose leading zeros in the MNC");
123
124struct gsm48_hdr *gsm48_push_l3hdr(struct msgb *msg,
125 uint8_t pdisc, uint8_t msg_type);
126
127#define gsm48_push_l3hdr_tid(msg, pdisc, tid, msg_type) \
128 gsm48_push_l3hdr(msg, (pdisc & 0x0f) | (tid << 4), msg_type)
129
const char * rr_cause_name(uint8_t cause)
return string representation of RR Cause value
Definition: gsm48.c:183
void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc)
Definition: gsm48.c:1114
int osmo_mobile_identity_encode_msgb(struct msgb *msg, const struct osmo_mobile_identity *mi, bool allow_hex)
Encode Mobile Identity type and BCD digits, appended to a msgb.
Definition: gsm48.c:854
int osmo_mobile_identity_to_str_buf(char *buf, size_t buflen, const struct osmo_mobile_identity *mi)
Return a human readable representation of a struct osmo_mobile_identity.
Definition: gsm48.c:1020
char * osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:554
char * osmo_mobile_identity_to_str_c(void *ctx, const struct osmo_mobile_identity *mi)
Like osmo_mobile_identity_to_str_buf(), but return the string in a talloc buffer.
Definition: gsm48.c:1050
int osmo_routing_area_id_encode_msgb(struct msgb *msg, const struct osmo_routing_area_id *src)
Encode struct osmo_routing_area_id to a 3GPP TS 24.008 § 10.5.5.15 Routing area identification: appen...
Definition: gsm48.c:1397
const char * gsm48_rr_msg_name(uint8_t msgtype)
return string representation of RR Message Type
Definition: gsm48.c:418
int osmo_mobile_identity_cmp(const struct osmo_mobile_identity *a, const struct osmo_mobile_identity *b)
Compare two osmo_mobile_identity structs, returning typical cmp() result.
Definition: gsm48.c:1060
const char * osmo_rai_name(const struct gprs_ra_id *rai)
Return MCC-MNC-LAC-RAC as string, in a static buffer.
Definition: gsm48.c:206
const char * osmo_mi_name(const uint8_t *mi, uint8_t mi_len)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:592
char * osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai)
Return MCC-MNC-LAC-RAC as string, in dynamically-allocated output buffer.
Definition: gsm48.c:217
const char * gsm48_mi_type_name(uint8_t mi)
return string representation of Mobile Identity Type
Definition: gsm48.c:541
int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:1294
int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:1244
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf)
Parse TS 04.08 Routing Area Identifier.
Definition: gsm48.c:1411
int osmo_routing_area_id_decode(struct osmo_routing_area_id *dst, const uint8_t *ra_data, size_t ra_data_len)
Decode to struct osmo_routing_area_id from a 3GPP TS 24.008 § 10.5.5.15 Routing area identification.
Definition: gsm48.c:1357
bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2)
Compare a TS 04.08 Routing Area Identifier.
Definition: gsm48.c:1470
void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid)
Encode a 3GPP TS 24.008 § 10.5.5.15 Routing area identification.
Definition: gsm48.c:1438
int osmo_mobile_identity_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_mobile_identity *mi, bool allow_hex)
Encode Mobile Identity from uint32_t (TMSI) or digits string (all others) (3GPP TS 24....
Definition: gsm48.c:792
const struct tlv_definition gsm48_rr_att_tlvdef
TLV parser definitions for TS 04.08 RR.
Definition: gsm48.c:95
void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai)
Encode TS 04.08 Location Area Identifier.
Definition: gsm48.c:1158
void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded)
Decode TS 04.08 Location Area Identifier.
Definition: gsm48.c:1189
const char * gsm48_rr_short_pd_msg_name(uint8_t msgtype)
return string representation of RR Message Type using the RR short protocol discriminator
Definition: gsm48.c:442
int osmo_mobile_identity_decode_from_l3(struct osmo_mobile_identity *mi, struct msgb *msg, bool allow_hex)
Extract Mobile Identity from a Complete Layer 3 message.
Definition: gsm48.c:1008
int osmo_mobile_identity_decode_from_l3_buf(struct osmo_mobile_identity *mi, const uint8_t *l3_data, size_t l3_len, bool allow_hex)
Extract Mobile Identity from a Complete Layer 3 message.
Definition: gsm48.c:874
enum gsm48_chan_mode gsm48_chan_mode_to_vamos(enum gsm48_chan_mode mode)
Translate GSM48_CMODE_SPEECH_* to its corresponding GSM48_CMODE_SPEECH_*_VAMOS mode.
Definition: gsm48.c:481
const struct tlv_definition gsm48_mm_att_tlvdef
TLV parser definitions for TS 04.08 MM.
Definition: gsm48.c:141
const char * gsm48_cc_msg_name(uint8_t msgtype)
return string representation of CC Message Type
Definition: gsm48.c:310
char * osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:606
uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:1262
int osmo_mobile_identity_encoded_len(const struct osmo_mobile_identity *mi, int *mi_digits)
Return the number of encoded Mobile Identity octets, without actually encoding.
Definition: gsm48.c:745
const char * gsm48_cc_state_name(uint8_t state)
return string representation of CC State
Definition: gsm48.c:262
struct gsm48_hdr * gsm48_push_l3hdr(struct msgb *msg, uint8_t pdisc, uint8_t msg_type)
Wrap a given msg with gsm48_hdr structure.
Definition: gsm48.c:1861
int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t *mi_data, uint8_t mi_len, bool allow_hex)
Extract Mobile Identity from encoded bytes (3GPP TS 24.008 10.5.1.4).
Definition: gsm48.c:636
int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid)
Encode a TS 04.08 Routing Area Identifier.
Definition: gsm48.c:1459
int gsm48_number_of_paging_subchannels(const struct gsm48_control_channel_descr *chan_desc)
Determine number of paging sub-channels.
Definition: gsm48.c:1492
const struct tlv_definition gsm48_att_tlvdef
TLV parser definitions for TS 04.08 CC.
Definition: gsm48.c:53
int gsm48_mi_to_string(char *string, int str_len, const uint8_t *mi, int mi_len)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:1312
int osmo_routing_area_id_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_routing_area_id *src)
Encode struct osmo_routing_area_id to a 3GPP TS 24.008 § 10.5.5.15 Routing area identification: write...
Definition: gsm48.c:1377
enum gsm48_chan_mode gsm48_chan_mode_to_non_vamos(enum gsm48_chan_mode mode)
Translate GSM48_CMODE_SPEECH_*_VAMOS to its corresponding GSM48_CMODE_SPEECH_* non-vamos mode.
Definition: gsm48.c:503
char * osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai)
Return MCC-MNC-LAC-RAC as string, in a caller-provided output buffer.
Definition: gsm48.c:194
#define OSMO_DEPRECATED_OUTSIDE(text)
#define OSMO_DEPRECATED(text)
void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc) OSMO_DEPRECATED("Use osmo_plmn_from_bcd() instead
void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc, uint16_t mnc, uint16_t lac) OSMO_DEPRECATED("Use gsm48_generate_lai2() instead
int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc, uint16_t *mnc, uint16_t *lac) OSMO_DEPRECATED("Use gsm48_decode_lai2() instead
int to not lose leading zeros in the MNC
Definition: gsm48.h:48
GSM TS 04.08 definitions.
uint8_t cause
Definition: gsm_04_08.h:2
gsm48_chan_mode
10.5.2.6 Channel Mode value
Definition: gsm_04_08.h:750
uint8_t mode
Definition: gsm_04_08.h:1
uint16_t lac
Definition: gsm_04_08.h:1
uint8_t mi_len
Definition: gsm_04_08.h:1
struct gsm48_loc_area_id lai
Definition: gsm_04_08.h:2
struct gsm48_chan_desc chan_desc
Definition: gsm_04_08.h:0
uint8_t mi[0]
Definition: gsm_04_08.h:2
uint8_t msg_type
Definition: gsm_04_08.h:2
uint8_t type
Definition: gsm_04_08_gprs.h:7
uint8_t msg[0]
Definition: gsm_08_08.h:8
#define GSM23003_IMEI_NUM_DIGITS
Definition: gsm_23_003.h:30
#define GSM23003_IMEISV_NUM_DIGITS
Definition: gsm_23_003.h:32
#define GSM23003_IMSI_MAX_DIGITS
Definition: gsm_23_003.h:6
_parse instead
Definition: ipa.h:30
Definition: gsm48.h:26
bool mnc_3_digits
Definition: gsm48.h:29
uint16_t mcc
Definition: gsm48.h:27
uint16_t lac
Definition: gsm48.h:30
uint8_t rac
Definition: gsm48.h:31
uint16_t mnc
Definition: gsm48.h:28
Definition: gsm_04_08.h:992
Definition: gsm_04_08.h:941
Definition: gsm_04_08.h:898
Definition: gsm_04_08.h:2255
Definition: gsm23003.h:16
Definition: gsm23003.h:22
Definition of All 256 IE / TLV.
Definition: tlv.h:527