Loading...
Searching...
No Matches
gsm0808_utils.c File Reference
`#include "config.h"`
`#include <osmocom/core/utils.h>`
`#include <osmocom/core/msgb.h>`
`#include <osmocom/core/byteswap.h>`
`#include <string.h>`
`#include <errno.h>`
`#include <osmocom/gsm/protocol/gsm_08_08.h>`
`#include <osmocom/gsm/gsm48.h>`
`#include <osmocom/gsm/gsm0808.h>`
`#include <osmocom/gsm/gsm0808_utils.h>`

## Macros

#define | IP_V4_ADDR_LEN 4
#define | IP_V6_ADDR_LEN 16
#define | IP_PORT_LEN 2
#define | CHANNEL_TYPE_ELEMENT_MAXLEN 11
#define | CHANNEL_TYPE_ELEMENT_MINLEN 3
#define | ENCRYPT_INFO_ELEMENT_MINLEN 1
#define | APPEND_THING(func, args...)
#define | APPEND_STR(fmt, args...) APPEND_THING(snprintf, fmt, ##args)
#define | APPEND_CELL_ID_U(DISCR, U) APPEND_THING(gsm0808_cell_id_u_name, DISCR, U)

## Functions

static void | decode_lai (const uint8_t *data, struct osmo_location_area_id *decoded)
static uint8_t | enc_speech_codec (struct msgb *msg, const struct gsm0808_speech_codec *sc)
uint8_t | gsm0808_enc_speech_codec (struct msgb *msg, const struct gsm0808_speech_codec *sc)
| Encode TS 08.08 Speech Codec IE.
int | gsm0808_dec_speech_codec (struct gsm0808_speech_codec *sc, const uint8_t *elem, uint8_t len)
| Decode TS 08.08 Speech Codec IE.
uint8_t | gsm0808_enc_speech_codec_list (struct msgb *msg, const struct gsm0808_speech_codec_list *scl)
| Encode TS 08.08 Speech Codec list.
int | gsm0808_dec_speech_codec_list (struct gsm0808_speech_codec_list *scl, const uint8_t *elem, uint8_t len)
| Decode TS 08.08 Speech Codec list IE.
uint8_t | gsm0808_enc_channel_type (struct msgb *msg, const struct gsm0808_channel_type *ct)
| Encode TS 08.08 Channel Type IE.
int | gsm0808_dec_channel_type (struct gsm0808_channel_type *ct, const uint8_t *elem, uint8_t len)
| Decode TS 08.08 Channel Type IE.
static uint8_t | gsm0808_enc_gcr (struct msgb *msg, const struct osmo_gcr_parsed *g)
| Create BSSMAP Global Call Reference, 3GPP TS 48.008 §3.2.2.115.
static int | gsm0808_dec_gcr (struct osmo_gcr_parsed *gcr, const struct tlv_parsed *tp)
| Decode BSSMAP Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1.
uint8_t | gsm0808_enc_lcls (struct msgb *msg, const struct osmo_lcls *lcls)
| Add LCLS parameters to a given msgb, 3GPP TS 48.008 §3.2.2.115 - 3.2.2.120.
int | gsm0808_dec_lcls (struct osmo_lcls *lcls, const struct tlv_parsed *tp)
| Decode LCLS parameters to a given msgb, 3GPP TS 48.008 §3.2.2.115 - 3.2.2.120.
char * | osmo_lcls_dump_buf (char *buf, size_t buf_len, const struct osmo_lcls *lcls)
| Dump LCLS parameters (GCR excluded) into string for printing.
char * | osmo_lcls_dump (const struct osmo_lcls *lcls)
| Dump LCLS parameters (GCR excluded) into static string buffer for printing.
char * | osmo_lcls_dump_c (void *ctx, const struct osmo_lcls *lcls)
char * | osmo_gcr_dump_buf (char *buf, size_t buf_len, const struct osmo_lcls *lcls)
| Dump GCR struct into string for printing.
char * | osmo_gcr_dump (const struct osmo_lcls *lcls)
| Dump GCR struct into static string buffer for printing.
uint8_t | gsm0808_enc_encrypt_info (struct msgb *msg, const struct gsm0808_encrypt_info *ei)
| Encode TS 08.08 Encryption Information IE.
int | gsm0808_dec_encrypt_info (struct gsm0808_encrypt_info *ei, const uint8_t *elem, uint8_t len)
| Decode TS 08.08 Encryption Information IE.
int | gsm0808_enc_kc128 (struct msgb *msg, const uint8_t *kc128)
| Encode TS 48.008 Kc128 IE.
int | gsm0808_dec_kc128 (uint8_t *kc128, const uint8_t *elem, uint8_t len)
| Decode TS 48.008 Kc128 IE.
static void | cell_id_to_cgi (struct osmo_cell_global_id *dst, enum CELL_IDENT discr, const union gsm0808_cell_id_u *u)
int | gsm0808_cell_id_size (enum CELL_IDENT discr)
int | gsm0808_decode_cell_id_u (union gsm0808_cell_id_u *out, enum CELL_IDENT discr, const uint8_t *buf, unsigned int len)
| Decode a single GSM 08.08 Cell ID list element payload.
void | gsm0808_msgb_put_cell_id_u (struct msgb *msg, enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u)
uint8_t | gsm0808_enc_cell_id_list2 (struct msgb *msg, const struct gsm0808_cell_id_list2 *cil)
| Encode TS 08.08 Cell Identifier List IE.
uint8_t | gsm0808_enc_cell_id_list (struct msgb *msg, const struct gsm0808_cell_id_list *cil)
| DEPRECATED: Use gsm0808_enc_cell_id_list2 instead.
static int | parse_cell_id_global_list (struct gsm0808_cell_id_list2 *cil, const uint8_t *data, size_t remain, size_t *consumed)
static int | parse_cell_id_lac_and_ci_list (struct gsm0808_cell_id_list2 *cil, const uint8_t *data, size_t remain, size_t *consumed)
static int | parse_cell_id_ci_list (struct gsm0808_cell_id_list2 *cil, const uint8_t *data, size_t remain, size_t *consumed)
static int | parse_cell_id_lai_and_lac (struct gsm0808_cell_id_list2 *cil, const uint8_t *data, size_t remain, size_t *consumed)
static int | parse_cell_id_lac_list (struct gsm0808_cell_id_list2 *cil, const uint8_t *data, size_t remain, size_t *consumed)
static int | parse_cell_id_sai_list (struct gsm0808_cell_id_list2 *cil, const uint8_t *data, size_t remain, size_t *consumed)
int | gsm0808_dec_cell_id_list2 (struct gsm0808_cell_id_list2 *cil, const uint8_t *elem, uint8_t len)
| Decode Cell Identifier List IE.
int | gsm0808_dec_cell_id_list (struct gsm0808_cell_id_list *cil, const uint8_t *elem, uint8_t len)
| DEPRECATED: Use gsm0808_dec_cell_id_list2 instead.
static bool | same_cell_id_list_entries (const struct gsm0808_cell_id_list2 *a, int ai, const struct gsm0808_cell_id_list2 *b, int bi)
int | gsm0808_cell_id_list_add (struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id_list2 *src)
| Append entries from one Cell Identifier List to another.
void | gsm0808_cell_id_to_list (struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id *src)
| Convert a single Cell Identifier to a Cell Identifier List with one entry.
uint8_t | gsm0808_enc_cell_id (struct msgb *msg, const struct gsm0808_cell_id *ci)
| Encode Cell Identifier IE (3GPP TS 48.008 3.2.2.17).
int | gsm0808_dec_cell_id (struct gsm0808_cell_id *ci, const uint8_t *elem, uint8_t len)
| Decode Cell Identifier IE (3GPP TS 48.008 3.2.2.17).
int | gsm0808_chan_type_to_speech_codec (uint8_t perm_spch)
| Convert the representation of the permitted speech codec identifier that is used in struct gsm0808_channel_type to the speech codec representation we use in struct gsm0808_speech_codec.
int | gsm0808_speech_codec_from_chan_type (struct gsm0808_speech_codec *sc, uint8_t perm_spch)
| Extrapolate a speech codec field from a given permitted speech parameter (channel type).
uint16_t | gsm0808_sc_cfg_from_gsm48_mr_cfg (const struct gsm48_multi_rate_conf *cfg, bool fr)
| Determine a set of AMR speech codec configuration bits (S0-S15) from a given GSM 04.08 AMR configuration struct.
int | gsm48_mr_cfg_from_gsm0808_sc_cfg (struct gsm48_multi_rate_conf *cfg, uint16_t s15_s0)
| Determine a GSM 04.08 AMR configuration struct from a set of speech codec configuration bits (S0-S15)
int | gsm0808_get_cipher_reject_cause (const struct tlv_parsed *tp)
int | gsm0808_cell_id_u_name (char *buf, size_t buflen, enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u)
| Print a human readable name of the cell identifier to the char buffer.
static bool | gsm0808_cell_id_u_match (enum CELL_IDENT discr1, const union gsm0808_cell_id_u *u1, enum CELL_IDENT discr2, const union gsm0808_cell_id_u *u2, bool exact_match)
| Return true if the common information between the two Cell Identifiers match.
bool | gsm0808_cell_ids_match (const struct gsm0808_cell_id *id1, const struct gsm0808_cell_id *id2, bool exact_match)
| Return true if the common information between the two Cell Identifiers match.
int | gsm0808_cell_id_matches_list (const struct gsm0808_cell_id *id, const struct gsm0808_cell_id_list2 *list, unsigned int match_nr, bool exact_match)
| Find an index in a Cell Identifier list that matches a given single Cell Identifer.
void | gsm0808_cell_id_from_cgi (struct gsm0808_cell_id *cid, enum CELL_IDENT id_discr, const struct osmo_cell_global_id *cgi)
| Copy information from a CGI to form a Cell Identifier of the specified kind.
int | gsm0808_cell_id_to_cgi (struct osmo_cell_global_id *cgi, const struct gsm0808_cell_id *cid)
| Overwrite parts of cgi with values from a Cell Identifier.
char * | gsm0808_cell_id_name_buf (char *buf, size_t buflen, const struct gsm0808_cell_id *cid)
const char * | gsm0808_cell_id_name (const struct gsm0808_cell_id *cid)
| Return a human readable representation of a Cell Identifier, like "LAC:123" or "CGI:001-01-42-23".
const char * | gsm0808_cell_id_name2 (const struct gsm0808_cell_id *cid)
| Like gsm0808_cell_id_name() but uses a different static buffer.
char * | gsm0808_cell_id_name_c (const void *ctx, const struct gsm0808_cell_id *cid)
int | gsm0808_cell_id_list_name_buf (char *buf, size_t buflen, const struct gsm0808_cell_id_list2 *cil)
| Return a human readable representation of the Cell Identifier List, like "LAC[2]:{123, 456}".
const char * | gsm0808_cell_id_list_name (const struct gsm0808_cell_id_list2 *cil)
| Return a human-readable representation of cil in a static buffer.
char * | gsm0808_cell_id_list_name_c (const void *ctx, const struct gsm0808_cell_id_list2 *cil)
char * | gsm0808_channel_type_name_buf (char *buf, size_t buf_len, const struct gsm0808_channel_type *ct)
const char * | gsm0808_channel_type_name (const struct gsm0808_channel_type *ct)
char * | gsm0808_channel_type_name_c (const void *ctx, const struct gsm0808_channel_type *ct)

## Variables

static __thread char | dbuf [256]
const struct value_string | gsm0808_cell_id_discr_names []
| value_string[] for enum CELL_IDENT.

## Macro Definition Documentation

## APPEND_CELL_ID_U

#define APPEND_CELL_ID_U | ( |  | DISCR,
|  |  | U
| ) |  | APPEND_THING(gsm0808_cell_id_u_name, DISCR, U)

## APPEND_STR

#define APPEND_STR | ( |  | fmt,
|  |  | args...
| ) |  | APPEND_THING(snprintf, fmt, ##args)

## APPEND_THING

#define APPEND_THING | ( |  | func,
|  |  | args...
| ) |  |

Value:
do { \
int remain = buflen - (pos - buf); \
int l = func(pos, remain, ##args); \
if (l < 0 || l > remain) \
pos = buf + buflen; \
else \
pos += l; \
if (l > 0) \
total_len += l; \
} while(0)
l
int gsm48_generate_mid_from_tmsi *(uint8_t *buf, uint32_t tmsi) OSMO_DEPRECATED_OUTSIDE("Instead us l)
Definition gsm48.h:55
len
uint8_t len
Definition gsm_04_11.h:0

## CHANNEL_TYPE_ELEMENT_MAXLEN

#define CHANNEL_TYPE_ELEMENT_MAXLEN 11

## CHANNEL_TYPE_ELEMENT_MINLEN

#define CHANNEL_TYPE_ELEMENT_MINLEN 3

## ENCRYPT_INFO_ELEMENT_MINLEN

#define ENCRYPT_INFO_ELEMENT_MINLEN 1

## IP_PORT_LEN

#define IP_PORT_LEN 2

## IP_V4_ADDR_LEN

#define IP_V4_ADDR_LEN 4

## IP_V6_ADDR_LEN

#define IP_V6_ADDR_LEN 16

## Function Documentation

## cell_id_to_cgi()

static void cell_id_to_cgi | ( | struct osmo_cell_global_id * | dst,
|  | enum CELL_IDENT | discr,
|  | const union gsm0808_cell_id_u * | u
| ) |  |

static

References CELL_IDENT_BSS, CELL_IDENT_CI, CELL_IDENT_LAC, CELL_IDENT_LAC_AND_CI, CELL_IDENT_LAI_AND_LAC, CELL_IDENT_NO_CELL, CELL_IDENT_SAI, CELL_IDENT_UTRAN_LAC_RNC, CELL_IDENT_UTRAN_PLMN_LAC_RNC, CELL_IDENT_UTRAN_RNC, CELL_IDENT_WHOLE_GLOBAL, CELL_IDENT_WHOLE_GLOBAL_PS, osmo_cell_global_id::cell_identity, osmo_cell_global_id_ps::cell_identity, gsm0808_cell_id_u::ci, osmo_lac_and_ci_id::ci, gsm0808_cell_id_u::global, gsm0808_cell_id_u::global_ps, gsm0808_cell_id_u::lac, osmo_location_area_id::lac, osmo_routing_area_id::lac, osmo_lac_and_ci_id::lac, gsm0808_cell_id_u::lac_and_ci, osmo_cell_global_id::lai, osmo_service_area_id::lai, gsm0808_cell_id_u::lai_and_lac, osmo_cell_global_id_ps::rai, and gsm0808_cell_id_u::sai.

Referenced by gsm0808_cell_id_u_match(), and gsm0808_enc_cell_id_list2().

## decode_lai()

static void decode_lai | ( | const uint8_t * | data,
|  | struct osmo_location_area_id * | decoded
| ) |  |

static

References data, gsm48_decode_lai2(), lai, and len.

Referenced by gsm0808_decode_cell_id_u(), parse_cell_id_global_list(), parse_cell_id_lai_and_lac(), and parse_cell_id_sai_list().

## enc_speech_codec()

static uint8_t enc_speech_codec | ( | struct msgb * | msg,
|  | const struct gsm0808_speech_codec * | sc
| ) |  |

static

References GSM0808_SCT_CSD, GSM0808_SCT_FR1, GSM0808_SCT_FR2, GSM0808_SCT_FR3, GSM0808_SCT_FR4, GSM0808_SCT_FR5, GSM0808_SCT_HR1, GSM0808_SCT_HR3, GSM0808_SCT_HR4, GSM0808_SCT_HR6, header, len, msg, and OSMO_ASSERT.

Referenced by gsm0808_enc_speech_codec(), and gsm0808_enc_speech_codec_list().

## gsm0808_cell_id_u_match()

static bool gsm0808_cell_id_u_match | ( | enum CELL_IDENT | discr1,
|  | const union gsm0808_cell_id_u * | u1,
|  | enum CELL_IDENT | discr2,
|  | const union gsm0808_cell_id_u * | u2,
|  | bool | exact_match
| ) |  |

static

Return true if the common information between the two Cell Identifiers match.

For example, if a LAC+CI is compared to LAC, return true if the LAC are the same. Note that CELL_IDENT_NO_CELL will always return false. Also CELL_IDENT_BSS will always return false, since this function cannot possibly know the bounds of the BSS, so the caller must handle CELL_IDENT_BSS specially.

Parameters

  [in] | discr1 | Cell Identifier type.
  [in] | u1 | Cell Identifier value.
  [in] | discr2 | Other Cell Identifier type.
  [in] | u2 | Other Cell Identifier value.
  [in] | exact_match | If true, return true only if the CELL_IDENT types and all values are identical.

Returns
  True if the common fields of the above match.

References cell_id_to_cgi(), CELL_IDENT_BSS, CELL_IDENT_NO_CELL, CELL_IDENT_UTRAN_LAC_RNC, CELL_IDENT_UTRAN_PLMN_LAC_RNC, CELL_IDENT_UTRAN_RNC, len, and osmo_cgi_cmp().

Referenced by gsm0808_cell_id_matches_list(), and gsm0808_cell_ids_match().

## gsm0808_dec_gcr()

static int gsm0808_dec_gcr | ( | struct osmo_gcr_parsed * | gcr,
|  | const struct tlv_parsed * | tp
| ) |  |

static

Decode BSSMAP Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1.

Parameters

  [out] | gcr | Caller-provided memory to store Global Call Reference
  [in] | tp | IE values to be decoded

Returns
  number of bytes parsed; negative on error

References GSM0808_IE_GLOBAL_CALL_REF, len, osmo_dec_gcr(), OSMO_GCR_MIN_LEN, TLVP_LEN, and TLVP_VAL_MINLEN.

Referenced by gsm0808_dec_lcls().

## gsm0808_enc_gcr()

static uint8_t gsm0808_enc_gcr | ( | struct msgb * | msg,
|  | const struct osmo_gcr_parsed * | g
| ) |  |

static

Create BSSMAP Global Call Reference, 3GPP TS 48.008 §3.2.2.115.

Parameters

  [out] | msg | Message Buffer for appending IE
  [in] | g | Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1

Returns
  number of bytes added to msg or 0 on error

References g, GSM0808_IE_GLOBAL_CALL_REF, len, msg, msgb_tl_put(), and osmo_enc_gcr().

Referenced by gsm0808_enc_lcls().

## parse_cell_id_ci_list()

static int parse_cell_id_ci_list | ( | struct gsm0808_cell_id_list2 * | cil,
|  | const uint8_t * | data,
|  | size_t | remain,
|  | size_t * | consumed
| ) |  |

static

References gsm0808_cell_id_u::ci, data, GSM0808_CELL_ID_LIST2_MAXLEN, gsm0808_cell_id_list2::id_list, and len.

Referenced by gsm0808_dec_cell_id_list2().

## parse_cell_id_global_list()

static int parse_cell_id_global_list | ( | struct gsm0808_cell_id_list2 * | cil,
|  | const uint8_t * | data,
|  | size_t | remain,
|  | size_t * | consumed
| ) |  |

static

References data, decode_lai(), gsm0808_cell_id_u::global, GSM0808_CELL_ID_LIST2_MAXLEN, gsm0808_cell_id_list2::id_list, osmo_cell_global_id::lai, and len.

Referenced by gsm0808_dec_cell_id_list2().

## parse_cell_id_lac_and_ci_list()

static int parse_cell_id_lac_and_ci_list | ( | struct gsm0808_cell_id_list2 * | cil,
|  | const uint8_t * | data,
|  | size_t | remain,
|  | size_t * | consumed
| ) |  |

static

References data, GSM0808_CELL_ID_LIST2_MAXLEN, gsm0808_cell_id_list2::id_list, osmo_lac_and_ci_id::lac, gsm0808_cell_id_u::lac_and_ci, and len.

Referenced by gsm0808_dec_cell_id_list2().

## parse_cell_id_lac_list()

static int parse_cell_id_lac_list | ( | struct gsm0808_cell_id_list2 * | cil,
|  | const uint8_t * | data,
|  | size_t | remain,
|  | size_t * | consumed
| ) |  |

static

References data, GSM0808_CELL_ID_LIST2_MAXLEN, gsm0808_cell_id_list2::id_list, gsm0808_cell_id_u::lac, and len.

Referenced by gsm0808_dec_cell_id_list2().

## parse_cell_id_lai_and_lac()

static int parse_cell_id_lai_and_lac | ( | struct gsm0808_cell_id_list2 * | cil,
|  | const uint8_t * | data,
|  | size_t | remain,
|  | size_t * | consumed
| ) |  |

static

References data, decode_lai(), GSM0808_CELL_ID_LIST2_MAXLEN, gsm0808_cell_id_list2::id_list, gsm0808_cell_id_u::lai_and_lac, and len.

Referenced by gsm0808_dec_cell_id_list2().

## parse_cell_id_sai_list()

static int parse_cell_id_sai_list | ( | struct gsm0808_cell_id_list2 * | cil,
|  | const uint8_t * | data,
|  | size_t | remain,
|  | size_t * | consumed
| ) |  |

static

References data, decode_lai(), GSM0808_CELL_ID_LIST2_MAXLEN, gsm0808_cell_id_list2::id_list, osmo_service_area_id::lai, len, and gsm0808_cell_id_u::sai.

Referenced by gsm0808_dec_cell_id_list2().

## same_cell_id_list_entries()

static bool same_cell_id_list_entries | ( | const struct gsm0808_cell_id_list2 * | a,
|  | int | ai,
|  | const struct gsm0808_cell_id_list2 * | b,
|  | int | bi
| ) |  |

static

References msgb::data_len, gsm0808_enc_cell_id_list2(), gsm0808_cell_id_list2::id_discr, len, and msgb_reset().

Referenced by gsm0808_cell_id_list_add().

## Variable Documentation

## dbuf

__thread char dbuf[256]

static

Referenced by osmo_gcr_dump(), osmo_gcr_dump_buf(), osmo_lcls_dump(), and osmo_lcls_dump_buf().