smscb: "Warning Security Information is always present in ETWS

As per TS 48.049 Table 8.1.3.1.1 the WRITE-REPLACE message always
has a Warning Security Information IE if it relates to ETWS.  This
is also implemented in the libosmocore CBSP parser.

As the previous Change Id369bb3676ba279bafc234378fbe21dbc7b0614b has
pointed out, the CBSP parser structure doesn't even permit any way
of handing a decoded message to us without the warning_sec_info
static struct member.

So as a result, there's also no need to dynamically allocate
bts_etws_state.input.sec_info via talloc.  We can have it in-line
as a static struct member and reduce code complexity and runtime
memory allocations.

Change-Id: Ib1b8e4af37b1f9f9398b81dad29942e82218c70b
This commit is contained in:
Harald Welte 2022-05-13 08:39:17 +02:00
parent 7111e00ee5
commit 35cac4dba8
2 changed files with 4 additions and 12 deletions

View File

@ -29,6 +29,7 @@
#include <osmocom/gsm/rxlev_stat.h>
#include <osmocom/gsm/protocol/gsm_08_58.h>
#include <osmocom/gsm/protocol/gsm_12_21.h>
#include <osmocom/gsm/protocol/gsm_03_41.h>
#include <osmocom/abis/e1_input.h>
#include <osmocom/bsc/meas_rep.h>
#include <osmocom/bsc/acc.h>
@ -1098,7 +1099,7 @@ struct bts_etws_state {
uint16_t msg_id;
uint16_t serial_nr;
uint16_t warn_type;
uint8_t *sec_info;
uint8_t sec_info[ETWS_SEC_INFO_SIZE];
} input;
/* encoded ETWS primary notification */
uint8_t primary[ETWS_PRIM_NOTIF_SIZE];

View File

@ -70,9 +70,7 @@ static int gen_etws_primary_notification(uint8_t *out, uint16_t serial_nr, uint1
osmo_store16be(serial_nr, out);
etws->msg_id = osmo_htons(msg_id);
etws->warning_type = osmo_htons(warn_type);
if (sec_info)
memcpy(etws->data, sec_info, ETWS_PRIM_NOTIF_SIZE - sizeof(*etws));
memcpy(etws->data, sec_info, ETWS_PRIM_NOTIF_SIZE - sizeof(*etws));
return ETWS_PRIM_NOTIF_SIZE;
}
@ -557,18 +555,11 @@ static int etws_primary_to_bts(struct gsm_bts *bts, const struct osmo_cbsp_write
}
}
if (bes->input.sec_info) {
talloc_free(bes->input.sec_info);
bes->input.sec_info = NULL;
}
/* copy over all the data to per-BTS private state */
bes->input.msg_id = wrepl->msg_id;
bes->input.serial_nr = wrepl->new_serial_nr;
bes->input.warn_type = wrepl->u.emergency.warning_type;
bes->input.sec_info = talloc_named_const(bts, ETWS_SEC_INFO_SIZE, "etws_sec_info");
if (bes->input.sec_info)
memcpy(bes->input.sec_info, wrepl->u.emergency.warning_sec_info, ETWS_SEC_INFO_SIZE);
memcpy(bes->input.sec_info, wrepl->u.emergency.warning_sec_info, sizeof(bes->input.sec_info));
/* generate the encoded ETWS PN */
gen_etws_primary_notification(bes->primary, bes->input.serial_nr, bes->input.msg_id,