diff options
author | Max <msuraev@sysmocom.de> | 2018-02-15 11:42:11 +0100 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2018-02-15 11:44:33 +0100 |
commit | ebf149234e1a4966bd74a4200eff21892cceac86 (patch) | |
tree | 2418ab5a7cbaf0dd13bd7fa19f0e8c39173d07aa /src | |
parent | d55d7d4fc7a7b66b5c45b431ce86a9786e095333 (diff) |
Add generic Mobile Identity encoder
Add generic function which allows caller to set Mobile Identity
explicitly. This allows to use IMEI or IMEISV for example. Make
gsm48_generate_mid_from_imsi() into wrapper around new function.
Change-Id: Id79be7abfff75ecd0d248bbeed93e605abeec9b3
Diffstat (limited to 'src')
-rw-r--r-- | src/gsm/gsm48.c | 31 | ||||
-rw-r--r-- | src/gsm/libosmogsm.map | 1 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c index 4570802c..b58e9e2c 100644 --- a/src/gsm/gsm48.c +++ b/src/gsm/gsm48.c @@ -584,32 +584,26 @@ int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi) return 7; } -/*! Generate TS 04.08 Mobile ID from IMSI +/*! Generate TS 24.008 ยง10.5.1.4 Mobile ID * \param[out] buf Caller-provided output buffer - * \param[in] imsi IMSI to be encoded + * \param[in] id Identity to be encoded * \returns number of bytes used in \a buf */ -int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi) +uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type) { - unsigned int length = strlen(imsi), i, off = 0; - uint8_t odd = (length & 0x1) == 1; + uint8_t length = strnlen(id, 255), i, off = 0, odd = (length & 1) == 1; buf[0] = GSM48_IE_MOBILE_ID; - buf[2] = osmo_char2bcd(imsi[0]) << 4 | GSM_MI_TYPE_IMSI | (odd << 3); + buf[2] = osmo_char2bcd(id[0]) << 4 | mi_type | (odd << 3); /* if the length is even we will fill half of the last octet */ - if (odd) - buf[1] = (length + 1) >> 1; - else - buf[1] = (length + 2) >> 1; + buf[1] = (length + (odd ? 1 : 2)) >> 1; for (i = 1; i < buf[1]; ++i) { - uint8_t lower, upper; - - lower = osmo_char2bcd(imsi[++off]); + uint8_t upper, lower = osmo_char2bcd(id[++off]); if (!odd && off + 1 == length) upper = 0x0f; else - upper = osmo_char2bcd(imsi[++off]) & 0x0f; + upper = osmo_char2bcd(id[++off]) & 0x0f; buf[2 + i] = (upper << 4) | lower; } @@ -617,6 +611,15 @@ int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi) return 2 + buf[1]; } +/*! Generate TS 04.08 Mobile ID from IMSI + * \param[out] buf Caller-provided output buffer + * \param[in] imsi IMSI to be encoded + * \returns number of bytes used in \a buf */ +int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi) +{ + return gsm48_generate_mid(buf, imsi, GSM_MI_TYPE_IMSI); +} + /*! Convert TS 04.08 Mobile Identity (10.5.1.4) to string * \param[out] string Caller-provided buffer for output * \param[in] str_len Length of \a string in bytes diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index 53b6f6e8..7a74718c 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -246,6 +246,7 @@ gsm48_encode_signal; gsm48_encode_ssversion; gsm48_encode_useruser; gsm48_generate_lai; +gsm48_generate_mid; gsm48_generate_mid_from_imsi; gsm48_generate_mid_from_tmsi; gsm48_mi_to_string; |