aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-trx/amr.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-09-22 16:41:54 +0200
committerHarald Welte <laforge@gnumonks.org>2015-09-22 16:41:54 +0200
commitf1fb0fa3af174c605f60458388bba61ef4f40fa8 (patch)
tree006e46f78dee0ac14ffd321e0bfae344d8160096 /src/osmo-bts-trx/amr.c
parent329085a8ff2c1162a32eb617068fa5614efcde06 (diff)
parentcaa648d92e48a05e676e87b48c21cb0b151c9b4e (diff)
Merge branch '201509-trx-rebase'0.4.0
Diffstat (limited to 'src/osmo-bts-trx/amr.c')
-rw-r--r--src/osmo-bts-trx/amr.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/osmo-bts-trx/amr.c b/src/osmo-bts-trx/amr.c
new file mode 100644
index 00000000..70d94ca9
--- /dev/null
+++ b/src/osmo-bts-trx/amr.c
@@ -0,0 +1,81 @@
+/* AMR support for OsmoBTS-TRX */
+
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+
+static int amr_len_by_ft[16] = {
+ 12, 13, 15, 17, 19, 20, 26, 31,
+ 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+int amr_decompose_payload(uint8_t *payload, int payload_len, uint8_t *_cmr,
+ uint8_t *_ft, uint8_t *_bfi)
+{
+ uint8_t cmr, f, ft, q;
+
+ if (payload_len < 2)
+ return -EINVAL;
+
+ cmr = payload[0] >> 4;
+ if (_cmr)
+ *_cmr = cmr;
+
+ f = payload[1] >> 7;
+
+ ft = (payload[1] >> 3) & 0xf;
+ if (_ft)
+ *_ft = ft;
+
+ q = (payload[1] >> 2) & 0x1;
+ if (_bfi)
+ *_bfi = !q;
+
+ if (f) {
+ fprintf(stderr, "%s: multiple payloads not supported\n",
+ __func__);
+ return -ENOTSUP;
+ }
+
+ if (payload_len - 2 < amr_len_by_ft[ft])
+ return -EINVAL;
+
+ return 2 + amr_len_by_ft[ft];
+}
+
+int amr_compose_payload(uint8_t *payload, uint8_t cmr, uint8_t ft, uint8_t bfi)
+{
+ if (cmr >= 16)
+ return -EINVAL;
+
+ if (ft >= 16)
+ return -EINVAL;
+
+ payload[0] = cmr << 4;
+
+ payload[1] = (ft << 3) | ((!bfi) << 2); /* F = 0 */
+
+ return 2 + amr_len_by_ft[ft];
+}
+