Andreas Eversberg | 2c202cd | 2013-12-06 16:59:10 +0100 | [diff] [blame] | 1 | /* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu> |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as published by |
| 6 | * the Free Software Foundation; either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <osmocom/abis/trau_frame.h> |
| 20 | #include <openbsc/trau_mux.h> |
| 21 | #include <osmocom/core/msgb.h> |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <string.h> |
| 25 | #include <stdlib.h> |
| 26 | |
| 27 | void test_trau_fr_efr(unsigned char *data) |
| 28 | { |
| 29 | struct decoded_trau_frame tf; |
| 30 | struct msgb *msg; |
| 31 | struct gsm_data_frame *frame; |
| 32 | |
| 33 | printf("Testing TRAU FR transcoding.\n"); |
| 34 | data[0] = 0xd0; |
| 35 | trau_encode_fr(&tf, data); |
| 36 | tf.c_bits[11] = 0; /* clear BFI */ |
| 37 | msg = trau_decode_fr(1, &tf); |
| 38 | OSMO_ASSERT(msg != NULL); |
| 39 | frame = (struct gsm_data_frame *)msg->data; |
| 40 | OSMO_ASSERT(frame->msg_type == GSM_TCHF_FRAME); |
| 41 | OSMO_ASSERT(!memcmp(frame->data, data, 33)); |
| 42 | msgb_free(msg); |
| 43 | |
| 44 | printf("Testing TRAU EFR transcoding.\n"); |
| 45 | data[0] = 0xc0; |
| 46 | trau_encode_efr(&tf, data); |
| 47 | OSMO_ASSERT(tf.d_bits[0] == 1); /* spare bit must be 1 */ |
| 48 | tf.c_bits[11] = 0; /* clear BFI */ |
| 49 | msg = trau_decode_efr(1, &tf); |
| 50 | OSMO_ASSERT(msg != NULL); |
| 51 | frame = (struct gsm_data_frame *)msg->data; |
| 52 | OSMO_ASSERT(frame->msg_type == GSM_TCHF_FRAME_EFR); |
| 53 | OSMO_ASSERT(!memcmp(frame->data, data, 31)); |
| 54 | |
| 55 | printf("Testing TRAU EFR decoding with CRC error.\n"); |
| 56 | tf.d_bits[0] = 0; /* spare bit must be included */ |
| 57 | msg = trau_decode_efr(1, &tf); |
| 58 | OSMO_ASSERT(msg != NULL); |
| 59 | frame = (struct gsm_data_frame *)msg->data; |
Andreas Eversberg | eca4145 | 2014-01-31 09:02:01 +0100 | [diff] [blame] | 60 | OSMO_ASSERT(frame->msg_type == GSM_BAD_FRAME); |
Andreas Eversberg | 2c202cd | 2013-12-06 16:59:10 +0100 | [diff] [blame] | 61 | msgb_free(msg); |
| 62 | } |
| 63 | |
| 64 | int main() |
| 65 | { |
| 66 | unsigned char data[33]; |
| 67 | int i; |
| 68 | |
Neels Hofmeyr | 20215f1 | 2016-09-16 02:31:17 +0200 | [diff] [blame] | 69 | msgb_talloc_ctx_init(NULL, 0); |
| 70 | |
Andreas Eversberg | 2c202cd | 2013-12-06 16:59:10 +0100 | [diff] [blame] | 71 | memset(data, 0x00, sizeof(data)); |
| 72 | test_trau_fr_efr(data); |
| 73 | memset(data, 0xff, sizeof(data)); |
| 74 | test_trau_fr_efr(data); |
| 75 | srandom(42); |
| 76 | for (i = 0; i < sizeof(data); i++) |
| 77 | data[i] = random(); |
| 78 | test_trau_fr_efr(data); |
| 79 | printf("Done\n"); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | /* stubs */ |
| 84 | void vty_out() {} |