Philipp Maier | 40def49 | 2017-12-16 03:42:15 +0700 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2017 by sysmocom - s.f.m.c. GmbH |
| 3 | * (C) 2017 by Philipp Maier <pmaier@sysmocom.de> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
Philipp Maier | 40def49 | 2017-12-16 03:42:15 +0700 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <stdbool.h> |
| 20 | #include <string.h> |
| 21 | #include <stdint.h> |
| 22 | #include <errno.h> |
| 23 | |
Philipp Maier | 40def49 | 2017-12-16 03:42:15 +0700 | [diff] [blame] | 24 | #include <osmocom/codec/codec.h> |
| 25 | #include <osmocom/codec/ecu.h> |
| 26 | |
Harald Welte | 750d831 | 2019-08-01 20:05:05 +0200 | [diff] [blame] | 27 | /*********************************************************************** |
| 28 | * Integration with ECU core |
| 29 | ***********************************************************************/ |
| 30 | |
| 31 | static struct osmo_ecu_state *ecu_fr_init(void *ctx, enum osmo_ecu_codec codec) |
| 32 | { |
| 33 | struct osmo_ecu_state *st; |
| 34 | size_t size = sizeof(*st) + sizeof(struct osmo_ecu_fr_state); |
| 35 | |
| 36 | st = talloc_named_const(ctx, size, "ecu_state_FR"); |
| 37 | if (!st) |
| 38 | return NULL; |
| 39 | |
| 40 | memset(st, 0, size); |
| 41 | st->codec = codec; |
| 42 | |
| 43 | return st; |
| 44 | } |
| 45 | |
| 46 | static int ecu_fr_frame_in(struct osmo_ecu_state *st, bool bfi, const uint8_t *frame, |
| 47 | unsigned int frame_bytes) |
| 48 | { |
| 49 | struct osmo_ecu_fr_state *fr = (struct osmo_ecu_fr_state *) &st->data; |
| 50 | if (bfi) |
| 51 | return 0; |
| 52 | |
| 53 | osmo_ecu_fr_reset(fr, frame); |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int ecu_fr_frame_out(struct osmo_ecu_state *st, uint8_t *frame_out) |
| 58 | { |
| 59 | struct osmo_ecu_fr_state *fr = (struct osmo_ecu_fr_state *) &st->data; |
| 60 | |
| 61 | if (osmo_ecu_fr_conceal(fr, frame_out) == 0) |
| 62 | return GSM_FR_BYTES; |
| 63 | else |
| 64 | return -1; |
| 65 | } |
| 66 | |
| 67 | static const struct osmo_ecu_ops osmo_ecu_ops_fr = { |
| 68 | .init = ecu_fr_init, |
| 69 | .frame_in = ecu_fr_frame_in, |
| 70 | .frame_out = ecu_fr_frame_out, |
| 71 | }; |
| 72 | |
| 73 | static __attribute__((constructor)) void on_dso_load_ecu_fr(void) |
| 74 | { |
| 75 | osmo_ecu_register(&osmo_ecu_ops_fr, OSMO_ECU_CODEC_FR); |
| 76 | } |