gsm48: add compare function for struct gprs_ra_id

Comparing struct gprs_ra_id using memcmp can be error prone, so lets add
a compare function to compare two struct gprs_ra_id values reliably.

Change-Id: I4d7558c04d9d01761516526086be5104bb2eeada
Related: SYS#5103
This commit is contained in:
Philipp Maier 2021-02-03 22:11:46 +01:00
parent 700822b305
commit d11a5d5b9a
3 changed files with 21 additions and 0 deletions

View File

@ -104,6 +104,7 @@ int osmo_mobile_identity_encode_msgb(struct msgb *msg, const struct osmo_mobile_
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid);
int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) OSMO_DEPRECATED("Use gsm48_encode_ra() instead");
bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2);
int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc);

View File

@ -1298,6 +1298,25 @@ int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid)
return 6;
}
/*! Compare a TS 04.08 Routing Area Identifier
* \param[in] raid1 first Routing Area ID to compare.
* \param[in] raid2 second Routing Area ID to compare.
* \returns true if raid1 and raid2 match, false otherwise. */
bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2)
{
if (raid1->mcc != raid2->mcc)
return false;
if (raid1->mnc != raid2->mnc)
return false;
if (raid1->mnc_3_digits != raid2->mnc_3_digits)
return false;
if (raid1->lac != raid2->lac)
return false;
if (raid1->rac != raid2->rac)
return false;
return true;
}
/*! Determine number of paging sub-channels
* \param[in] chan_desc Control Channel Description
* \returns number of paging sub-channels

View File

@ -326,6 +326,7 @@ osmo_gsm48_rest_octets_si4_decode;
gsm48_rr_msg_name;
gsm48_cc_state_name;
gsm48_construct_ra;
gsm48_ra_equal;
gsm48_encode_ra;
gsm48_hdr_gmm_cipherable;
gsm48_decode_bcd_number;