libosmogsm  1.0.1
Osmocom GSM library
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_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 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. More...
 
int gsm0808_dec_speech_codec (struct gsm0808_speech_codec *sc, const uint8_t *elem, uint8_t len)
 Decode TS 08.08 Speech Codec IE. More...
 
uint8_t gsm0808_enc_speech_codec_list (struct msgb *msg, const struct gsm0808_speech_codec_list *scl)
 Encode TS 08.08 Speech Codec list. More...
 
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. More...
 
uint8_t gsm0808_enc_channel_type (struct msgb *msg, const struct gsm0808_channel_type *ct)
 Encode TS 08.08 Channel Type IE. More...
 
int gsm0808_dec_channel_type (struct gsm0808_channel_type *ct, const uint8_t *elem, uint8_t len)
 Decode TS 08.08 Channel Type IE. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
uint8_t gsm0808_enc_encrypt_info (struct msgb *msg, const struct gsm0808_encrypt_info *ei)
 Encode TS 08.08 Encryption Information IE. More...
 
int gsm0808_dec_encrypt_info (struct gsm0808_encrypt_info *ei, const uint8_t *elem, uint8_t len)
 Decode TS 08.08 Encryption Information IE. More...
 
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. More...
 
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. More...
 
static void decode_lai (const uint8_t *data, struct osmo_location_area_id *decoded)
 
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)
 
int gsm0808_dec_cell_id_list2 (struct gsm0808_cell_id_list2 *cil, const uint8_t *elem, uint8_t len)
 Decode Cell Identifier List IE. More...
 
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. More...
 
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. More...
 
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. More...
 
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). More...
 
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). More...
 
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. More...
 
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). More...
 
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. More...
 
void 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) More...
 
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. More...
 
static const char * gsm0808_cell_id_name_buf (const struct gsm0808_cell_id *cid, char *buf, size_t buflen)
 
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". More...
 
const char * gsm0808_cell_id_name2 (const struct gsm0808_cell_id *cid)
 Like gsm0808_cell_id_name() but uses a different static buffer. More...
 
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}". More...
 
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. More...
 
const char * gsm0808_channel_type_name (const struct gsm0808_channel_type *ct)
 

Variables

const struct value_string gsm0808_cell_id_discr_names []
 value_string[] for enum CELL_IDENT. More...
 

Macro Definition Documentation

#define APPEND_CELL_ID_U (   DISCR,
 
)    APPEND_THING(gsm0808_cell_id_u_name, DISCR, U)
#define APPEND_STR (   fmt,
  args... 
)    APPEND_THING(snprintf, fmt, ##args)
#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)
#define CHANNEL_TYPE_ELEMENT_MAXLEN   11
#define CHANNEL_TYPE_ELEMENT_MINLEN   3
#define ENCRYPT_INFO_ELEMENT_MINLEN   1
#define IP_PORT_LEN   2
#define IP_V4_ADDR_LEN   4
#define IP_V6_ADDR_LEN   16

Function Documentation

static void decode_lai ( const uint8_t *  data,
struct osmo_location_area_id decoded 
)
static
static const char* gsm0808_cell_id_name_buf ( const struct gsm0808_cell_id cid,
char *  buf,
size_t  buflen 
)
static
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]gcrCaller-provided memory to store Global Call Reference
[in]tpIE values to be decoded
Returns
number of bytes parsed; negative on error

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

Referenced by gsm0808_dec_lcls().

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]msgMessage Buffer for appending IE
[in]gGlobal Call Reference, 3GPP TS 29.205 Table B 2.1.9.1
Returns
number of bytes added to msg or 0 on error

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

Referenced by gsm0808_enc_lcls().

static int parse_cell_id_ci_list ( struct gsm0808_cell_id_list2 cil,
const uint8_t *  data,
size_t  remain,
size_t *  consumed 
)
static
static int parse_cell_id_global_list ( struct gsm0808_cell_id_list2 cil,
const uint8_t *  data,
size_t  remain,
size_t *  consumed 
)
static
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
static int parse_cell_id_lac_list ( struct gsm0808_cell_id_list2 cil,
const uint8_t *  data,
size_t  remain,
size_t *  consumed 
)
static
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
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