FreeCalypso > hg > gsm-codec-lib
changeset 514:67b13a6a63c9
libgsmhr1: implement validation for *.dec frames
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 25 Aug 2024 19:14:40 +0000 |
parents | 03a40ac2e931 |
children | bb36ef735f25 |
files | libgsmhr1/Makefile libgsmhr1/paramval_dec.c |
diffstat | 2 files changed, 26 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libgsmhr1/Makefile Sun Aug 25 19:00:03 2024 +0000 +++ b/libgsmhr1/Makefile Sun Aug 25 19:14:40 2024 +0000 @@ -1,7 +1,7 @@ OBJS= dhf_packed.o dhf_params.o enc_out_order.o mathdp31.o mathhalf.o \ - pack_frame.o paramval_cod.o paramval_common.o rtp_in.o rtp_in_direct.o \ - sid_detect.o sid_reset.o sp_rom.o twts002_in.o twts002_out.o \ - unpack_frame.o + pack_frame.o paramval_cod.o paramval_common.o paramval_dec.o rtp_in.o \ + rtp_in_direct.o sid_detect.o sid_reset.o sp_rom.o twts002_in.o \ + twts002_out.o unpack_frame.o HDRS= enc_out_order.h mathdp31.h mathhalf.h namespace.h sp_rom.h tw_gsmhr.h \ typedefs.h LIB= libgsmhr1.a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgsmhr1/paramval_dec.c Sun Aug 25 19:14:40 2024 +0000 @@ -0,0 +1,23 @@ +/* + * The function implemented in this module examines a frame of 22 int16_t words + * that corresponds to GSM-HR decoder input format, and checks if the unused + * upper bits of each int16_t word are cleared as they should be. + * This function should be used when reading from ETSI-format *.dec files, + * to guard against reading garbage or wrong endian. + */ + +#include <stdint.h> +#include "tw_gsmhr.h" + +int gsmhr_check_decoder_params(const int16_t *params) +{ + if (params[18] < 0 || params[18] > 2) /* BFI */ + return -1; + if (params[19] < 0 || params[19] > 1) /* UFI */ + return -1; + if (params[20] < 0 || params[20] > 2) /* SID */ + return -1; + if (params[21] < 0 || params[21] > 1) /* TAF */ + return -1; + return gsmhr_check_common_params(params); +}