gsm23003.c File Reference
`#include <ctype.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <errno.h>`
`#include <string.h>`
`#include <osmocom/gsm/gsm23003.h>`
`#include <osmocom/gsm/protocol/gsm_23_003.h>`

## Functions

static bool | is_n_digits (const char *str, int min_digits, int max_digits)
bool | osmo_imsi_str_valid (const char *imsi)
| Determine whether the given IMSI is valid according to 3GPP TS 23.003. More...
bool | osmo_msisdn_str_valid (const char *msisdn)
| Determine whether the given MSISDN is valid according to 3GPP TS 23.003. More...
const char * | osmo_mcc_name (uint16_t mcc)
| Return MCC string as standardized 3-digit with leading zeros. More...
const char * | osmo_mnc_name (uint16_t mnc, bool mnc_3_digits)
| Return MNC string as standardized 2- or 3-digit with leading zeros. More...
static void | plmn_name (char *buf, size_t buflen, const struct osmo_plmn_id *plmn)
const char * | osmo_plmn_name (const struct osmo_plmn_id *plmn)
| Return MCC-MNC string as standardized 3-digit-dash-2/3-digit with leading zeros. More...
const char * | osmo_plmn_name2 (const struct osmo_plmn_id *plmn)
| Same as osmo_mcc_mnc_name(), but returning in a different static buffer. More...
const char * | osmo_lai_name (const struct osmo_location_area_id *lai)
| Return MCC-MNC-LAC as string, in a static buffer. More...
static const char * | _cgi_name (const struct osmo_cell_global_id *cgi, char *buf, size_t buflen)
const char * | osmo_cgi_name (const struct osmo_cell_global_id *cgi)
| Return MCC-MNC-LAC-CI as string, in a static buffer. More...
const char * | osmo_cgi_name2 (const struct osmo_cell_global_id *cgi)
| Same as osmo_cgi_name(), but uses a different static buffer. More...
static void | to_bcd (uint8_t *bcd, uint16_t val)
void | osmo_plmn_to_bcd (uint8_t *bcd_dst, const struct osmo_plmn_id *plmn)
void | osmo_plmn_from_bcd (const uint8_t *bcd_src, struct osmo_plmn_id *plmn)
int | osmo_mnc_from_str (const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits)
int | osmo_mnc_cmp (uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits)
int | osmo_plmn_cmp (const struct osmo_plmn_id *a, const struct osmo_plmn_id *b)

## Detailed Description

Utility function implementations related to 3GPP TS 23.003

## Function Documentation

## _cgi_name()

static const char* _cgi_name | ( | const struct osmo_cell_global_id * | cgi,
|  | char * | buf,
|  | size_t | buflen
| ) |  |

static

References osmo_cell_global_id::cell_identity, osmo_cell_global_id::lai, and osmo_lai_name().

Referenced by osmo_cgi_name(), and osmo_cgi_name2().

## is_n_digits()

static bool is_n_digits | ( | const char * | str,
|  | int | min_digits,
|  | int | max_digits
| ) |  |

static

References len.

Referenced by osmo_imsi_str_valid(), and osmo_msisdn_str_valid().

## osmo_cgi_name()

const char* osmo_cgi_name | ( | const struct osmo_cell_global_id * | cgi | ) |

Return MCC-MNC-LAC-CI as string, in a static buffer.

Parameters

  [in] | cgi | CGI to encode.

Returns
  Static string buffer.

References _cgi_name().

Referenced by gsm0808_cell_id_u_name().

## osmo_cgi_name2()

const char* osmo_cgi_name2 | ( | const struct osmo_cell_global_id * | cgi | ) |

Same as osmo_cgi_name(), but uses a different static buffer.

Useful for printing two distinct CGIs in the same printf format.

Parameters

  [in] | cgi | CGI to encode.

Returns
  Static string buffer.

References _cgi_name().

## osmo_imsi_str_valid()

bool osmo_imsi_str_valid | ( | const char * | imsi | ) |

Determine whether the given IMSI is valid according to 3GPP TS 23.003.

Parameters

  imsi | IMSI digits in ASCII string representation.

Returns
  true when the IMSI is valid, false for invalid characters or number of digits.

References GSM23003_IMSI_MAX_DIGITS, GSM23003_IMSI_MIN_DIGITS, and is_n_digits().

## osmo_lai_name()

const char* osmo_lai_name | ( | const struct osmo_location_area_id * | lai | ) |

Return MCC-MNC-LAC as string, in a static buffer.

Parameters

  [in] | lai | LAI to encode, the rac member is ignored.

Returns
  Static string buffer.

References gsm48_loc_area_id::lac, lai, and osmo_plmn_name().

Referenced by _cgi_name(), and gsm0808_cell_id_u_name().

## osmo_mcc_name()

const char* osmo_mcc_name | ( | uint16_t | mcc | ) |

Return MCC string as standardized 3-digit with leading zeros.

Parameters

  [in] | mcc | MCC value.

Returns
  string in static buffer.

Referenced by osmo_rai_name(), and plmn_name().

## osmo_mnc_cmp()

int osmo_mnc_cmp | ( | uint16_t | a_mnc,
|  | bool | a_mnc_3_digits,
|  | uint16_t | b_mnc,
|  | bool | b_mnc_3_digits
| ) |  |

Referenced by osmo_plmn_cmp().

## osmo_mnc_from_str()

int osmo_mnc_from_str | ( | const char * | mnc_str,
|  | uint16_t * | mnc,
|  | bool * | mnc_3_digits
| ) |  |

Referenced by osmo_mcc_from_str().

## osmo_mnc_name()

const char* osmo_mnc_name | ( | uint16_t | mnc,
|  | bool | mnc_3_digits
| ) |  |

Return MNC string as standardized 2- or 3-digit with leading zeros.

Parameters

  [in] | mnc | MNC value.
  [in] | mnc_3_digits | True if an MNC should fill three digits, only has an effect if MNC < 100.

Returns
  string in static buffer.

Referenced by osmo_rai_name(), and plmn_name().

## osmo_msisdn_str_valid()

bool osmo_msisdn_str_valid | ( | const char * | msisdn | ) |

Determine whether the given MSISDN is valid according to 3GPP TS 23.003.

Parameters

  msisdn | MSISDN digits in ASCII string representation.

Returns
  true when the MSISDN is valid, false for invalid characters or number of digits.

References is_n_digits().

## osmo_plmn_cmp()

int osmo_plmn_cmp | ( | const struct osmo_plmn_id * | a,
|  | const struct osmo_plmn_id * | b
| ) |  |

References osmo_plmn_id::mcc, osmo_plmn_id::mnc, osmo_plmn_id::mnc_3_digits, and osmo_mnc_cmp().

## osmo_plmn_from_bcd()

void osmo_plmn_from_bcd | ( | const uint8_t * | bcd_src,
|  | struct osmo_plmn_id * | plmn
| ) |  |

References osmo_plmn_id::mcc, osmo_plmn_id::mnc, and osmo_plmn_id::mnc_3_digits.

Referenced by gsm48_decode_lai2(), and gsm48_mcc_mnc_from_bcd().

## osmo_plmn_name()

const char* osmo_plmn_name | ( | const struct osmo_plmn_id * | plmn | ) |

Return MCC-MNC string as standardized 3-digit-dash-2/3-digit with leading zeros.

Parameters

  [in] | plmn | MCC-MNC value.

Returns
  string in static buffer.

References plmn_name().

Referenced by osmo_lai_name().

## osmo_plmn_name2()

const char* osmo_plmn_name2 | ( | const struct osmo_plmn_id * | plmn | ) |

Same as osmo_mcc_mnc_name(), but returning in a different static buffer.

Parameters

  [in] | plmn | MCC-MNC value.

Returns
  string in static buffer.

References plmn_name().

## osmo_plmn_to_bcd()

void osmo_plmn_to_bcd | ( | uint8_t * | bcd_dst,
|  | const struct osmo_plmn_id * | plmn
| ) |  |

References osmo_plmn_id::mcc, osmo_plmn_id::mnc, osmo_plmn_id::mnc_3_digits, and to_bcd().

Referenced by gsm48_generate_lai2(), and gsm48_mcc_mnc_to_bcd().

## plmn_name()

static void plmn_name | ( | char * | buf,
|  | size_t | buflen,
|  | const struct osmo_plmn_id * | plmn
| ) |  |

inline static

References osmo_plmn_id::mcc, osmo_plmn_id::mnc, osmo_plmn_id::mnc_3_digits, osmo_mcc_name(), and osmo_mnc_name().

Referenced by osmo_plmn_name(), and osmo_plmn_name2().

## to_bcd()

static void to_bcd | ( | uint8_t * | bcd,
|  | uint16_t | val
| ) |  |

static

Referenced by osmo_plmn_to_bcd().