Max | 92db150 | 2016-05-25 18:13:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2016 by Sysmocom s.f.m.c. GmbH |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
Max | ec8f192 | 2016-05-31 14:50:21 +0200 | [diff] [blame] | 23 | #include <stdbool.h> |
Max | 92db150 | 2016-05-25 18:13:51 +0200 | [diff] [blame] | 24 | |
| 25 | #include <osmocom/core/utils.h> |
| 26 | #include <osmocom/codec/codec.h> |
| 27 | |
| 28 | const uint8_t sid_update[] = {0x20, 0x44, 0x29, 0xc2, 0x92, 0x91, 0xf4}; |
| 29 | const uint8_t sid_first[] = {0x20, 0x44, 0x00, 0x00, 0x00, 0x00, 0x04}; |
| 30 | |
| 31 | #define PAYLOAD_LEN 34 |
| 32 | #define SID_LEN 7 |
| 33 | |
| 34 | static const char * cmpr(int a, int b) |
| 35 | { |
| 36 | return (a == b) ? "OK" : "BAD"; |
| 37 | } |
| 38 | |
| 39 | static void test_sid_dec(const uint8_t *t, size_t len) |
| 40 | { |
Max | e9e5f8e | 2016-11-07 14:49:13 +0100 | [diff] [blame] | 41 | uint8_t cmr, tmp[SID_LEN], *t2 = NULL; |
Max | 92db150 | 2016-05-25 18:13:51 +0200 | [diff] [blame] | 42 | enum osmo_amr_type ft; |
| 43 | enum osmo_amr_quality bfi; |
| 44 | int8_t sti, cmi; |
Max | e9e5f8e | 2016-11-07 14:49:13 +0100 | [diff] [blame] | 45 | if (t) { |
| 46 | memcpy(tmp, t, SID_LEN); |
| 47 | t2 = tmp; |
| 48 | } |
| 49 | int rc = osmo_amr_rtp_dec(t2, len, &cmr, &cmi, &ft, &bfi, &sti); |
| 50 | if (rc < 0) |
| 51 | return; |
Max | 92db150 | 2016-05-25 18:13:51 +0200 | [diff] [blame] | 52 | printf("[%d] decode RTP %s%s: FT %s, CMR %s, CMI is %d, SID type %s\t", |
| 53 | rc, osmo_hexdump(tmp, len), cmpr(bfi, AMR_GOOD), |
| 54 | get_value_string(osmo_amr_type_names, ft), |
| 55 | get_value_string(osmo_amr_type_names, cmr), |
| 56 | cmi, sti ? "UPDATE" : "FIRST"); |
| 57 | if (sti == -1) |
| 58 | printf("FAIL: incompatible STI for SID\n"); |
| 59 | rc = osmo_amr_rtp_enc(tmp, cmr, ft, bfi); |
| 60 | printf("[%d] encode [%d]\n", rc, memcmp(tmp, t, SID_LEN)); |
| 61 | } |
| 62 | |
| 63 | static void test_amr_rt(uint8_t _cmr, enum osmo_amr_type _ft, |
| 64 | enum osmo_amr_quality _bfi) |
| 65 | { |
| 66 | uint8_t cmr, payload[PAYLOAD_LEN]; |
| 67 | enum osmo_amr_type ft; |
| 68 | enum osmo_amr_quality bfi; |
| 69 | int8_t sti, cmi; |
| 70 | int rc, re = osmo_amr_rtp_enc(payload, _cmr, _ft, _bfi); |
| 71 | rc = osmo_amr_rtp_dec(payload, PAYLOAD_LEN, &cmr, &cmi, &ft, &bfi, &sti); |
| 72 | printf("[%d/%d] %s, CMR: %s, FT: %s, BFI: %s, CMI: %d, STI: %d\n", re, |
| 73 | rc, get_value_string(osmo_amr_type_names, ft), |
| 74 | cmpr(_cmr, cmr), cmpr(_ft, ft), cmpr(_bfi, bfi), cmi, sti); |
| 75 | } |
| 76 | |
Max | ec8f192 | 2016-05-31 14:50:21 +0200 | [diff] [blame] | 77 | uint8_t fr[] = {0xd8, 0xa9, 0xb5, 0x1d, 0xda, 0xa8, 0x82, 0xcc, 0xec, 0x52, |
| 78 | 0x29, 0x05, 0xa8, 0xc3, 0xe3, 0x0e, 0xb0, 0x89, 0x7a, 0xee, |
| 79 | 0x42, 0xca, 0xc4, 0x97, 0x22, 0xe6, 0x9e, 0xa8, 0xb8, 0xec, |
| 80 | 0x52, 0x26, 0xbd}; |
| 81 | uint8_t sid_fr[] = {0xd7, 0x27, 0x93, 0xe5, 0xe3, 0x00, 0x00, 0x00, 0x00, |
| 82 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 83 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 84 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 85 | |
| 86 | uint8_t hr[] = {0x06, 0x46, 0x76, 0xb1, 0x8e, 0x48, 0x9a, 0x2f, 0x5e, 0x4c, |
| 87 | 0x22, 0x2b, 0x62, 0x25}; |
| 88 | uint8_t sid_hr[] = {0x03, 0x8e, 0xb6, 0xcb, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 89 | 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 90 | |
| 91 | static void test_sid_xr(uint8_t *t, size_t len, bool hr) |
| 92 | { |
| 93 | printf("%s SID ? %s:: %d\n", hr ? "HR" : "FR", osmo_hexdump(t, len), |
| 94 | hr ? osmo_hr_check_sid(t, len) : osmo_fr_check_sid(t, len)); |
| 95 | } |
| 96 | |
Harald Welte | 3851e8e | 2017-05-31 02:42:46 +0200 | [diff] [blame] | 97 | const uint8_t fr_sid1[33] = { 0xd7, 0xe0, 0xa3, 0x61, 0x2c, 0x00, 0x00, |
| 98 | 0x80, 0x49, 0x00, 0x00, 0x49, 0x00, 0x00, 0x80, 0x00, 0x04, |
| 99 | 0x00, 0x00, 0x00, 0x00, 0x12, 0x40, 0x00, 0x10, 0x08, 0x00, |
| 100 | 0x00, 0x00, 0x08, 0x2d, 0x04, 0x09 }; |
| 101 | |
| 102 | const uint8_t fr_sid2[33] = { 0xd7, 0xa2, 0xbb, 0x65, 0xe5, 0x00, 0x00, |
| 103 | 0x10, 0x00, 0x04, 0x82, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, |
| 104 | 0x02, 0x41, 0x00, 0x00, 0x00, 0x00, 0x20, 0x80, 0x01, 0x00, |
| 105 | 0x00, 0x00, 0x42, 0x40, 0x10, 0xd2 }; |
| 106 | |
| 107 | const uint8_t fr_sid3[33] = { 0xd9, 0x60, 0xab, 0x21, 0xea, 0x00, 0x00, |
| 108 | 0x80, 0x48, 0x20, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x24, |
| 109 | 0x80, 0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x10, 0x08, 0x00, |
| 110 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x08 }; |
| 111 | |
| 112 | const uint8_t fr_sid4[33] = { 0xd8, 0x21, 0xab, 0x25, 0xea, 0x00, 0x00, |
| 113 | 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, 0x02, 0x41, 0x00, |
| 114 | 0x02, 0x48, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, |
| 115 | 0x00, 0x00, 0x42, 0x00, 0x02, 0x50 }; |
| 116 | |
| 117 | const uint8_t fr_sid5[33] = { 0xd9, 0x61, 0x9a, 0x65, 0x60, 0x00, 0x00, |
| 118 | 0x10, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 119 | 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, |
| 120 | 0x00, 0x00, 0x02, 0x40, 0x82, 0x52 }; |
| 121 | |
| 122 | const uint8_t fr_sid6[33] = { 0xd9, 0xa5, 0x93, 0xe1, 0xa0, 0x00, 0x00, |
| 123 | 0x10, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x09, 0x00, |
| 124 | 0x02, 0x40, 0x00, 0x00, 0x00, 0x01, 0x20, 0x80, 0x01, 0x00, |
| 125 | 0x00, 0x90, 0x02, 0x40, 0x02, 0x02 }; |
| 126 | |
| 127 | const uint8_t fr_sid7[33] = { 0xd8, 0x20, 0xa3, 0xe5, 0xaa, 0x00, 0x00, |
| 128 | 0x80, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x80, 0x00, 0x04, |
| 129 | 0x80, 0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x12, 0x08, 0x00, |
| 130 | 0x00, 0x00, 0x00, 0x08, 0x00, 0x09 }; |
| 131 | |
| 132 | const uint8_t fr_sid8[33] = { 0xd7, 0xe0, 0xa3, 0xa1, 0x60, 0x00, 0x00, |
| 133 | 0x10, 0x00, 0x04, 0x92, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, |
| 134 | 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 135 | 0x00, 0x12, 0x00, 0x40, 0x12, 0x00 }; |
| 136 | |
| 137 | const uint8_t fr_sid9[33] = { 0xd8, 0x20, 0xa3, 0xa5, 0x62, 0x00, 0x00, |
| 138 | 0x10, 0x00, 0x04, 0x82, 0x00, 0x00, 0x00, 0x02, 0x49, 0x00, |
| 139 | 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x24, 0x00, 0x00, 0x00, |
| 140 | 0x00, 0x10, 0x02, 0x00, 0x82, 0x02 }; |
| 141 | |
| 142 | const uint8_t fr_sid10[33] = { 0xd4, 0xaa, 0xba, 0x6e, 0xbb, 0x00, 0x00, |
| 143 | 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x10, 0x00, 0x20, |
| 144 | 0x90, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x08, 0x00, |
| 145 | 0x00, 0x00, 0x08, 0x2c, 0x20, 0x00 }; |
| 146 | |
| 147 | const uint8_t fr_sid11[33] = { 0xd9, 0x64, 0xbb, 0x6d, 0x62, 0x00, 0x00, |
| 148 | 0x80, 0x41, 0x00, 0x00, 0x48, 0x00, 0x00, 0x10, 0x00, 0x04, |
| 149 | 0x90, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, |
| 150 | 0x00, 0x00, 0x00, 0x2c, 0x24, 0x01 }; |
| 151 | |
| 152 | const uint8_t fr_sid12[33] = { 0xd8, 0x61, 0xb2, 0xa5, 0x62, 0x00, 0x00, |
| 153 | 0x00, 0x41, 0x20, 0x00, 0x48, 0x00, 0x00, 0x10, 0x00, 0x04, |
| 154 | 0x90, 0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x10, 0x40, 0x00, |
| 155 | 0x00, 0x00, 0x01, 0x29, 0x24, 0x08 }; |
| 156 | |
| 157 | const uint8_t fr_sid13[33] = { 0xd9, 0x23, 0xba, 0xe5, 0xe2, 0x00, 0x00, |
| 158 | 0x80, 0x41, 0x20, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x04, |
| 159 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, |
| 160 | 0x00, 0x00, 0x09, 0x05, 0x20, 0x00 }; |
| 161 | |
| 162 | const uint8_t fr_sid14[33] = { 0xd8, 0x62, 0xa2, 0x61, 0x60, 0x00, 0x00, |
| 163 | 0x10, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, |
| 164 | 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, |
| 165 | 0x00, 0x80, 0x00, 0x40, 0x02, 0x40 }; |
| 166 | |
| 167 | const uint8_t fr_sid15[33] = { 0xd9, 0xe4, 0xc3, 0x6d, 0x12, 0x00, 0x00, |
| 168 | 0x80, 0x00, 0x20, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 169 | 0x10, 0x00, 0x00, 0x00, 0x10, 0x48, 0x00, 0x10, 0x48, 0x00, |
| 170 | 0x00, 0x00, 0x00, 0x2d, 0x04, 0x00 }; |
| 171 | |
| 172 | const uint8_t fr_sid16[33] = { 0xd9, 0xa4, 0xc3, 0x29, 0x59, 0x00, 0x00, |
| 173 | 0x10, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, |
| 174 | 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, |
| 175 | 0x00, 0x00, 0x42, 0x00, 0x12, 0x02 }; |
| 176 | |
| 177 | static const uint8_t *fr_sids[] = { fr_sid1, fr_sid2, fr_sid3, fr_sid4, |
| 178 | fr_sid5, fr_sid6, fr_sid7, fr_sid8, fr_sid9, fr_sid10, fr_sid11, |
| 179 | fr_sid12, fr_sid13, fr_sid14, fr_sid15, fr_sid16 }; |
| 180 | |
| 181 | static void test_sid_fr(void) |
| 182 | { |
| 183 | unsigned int i; |
| 184 | |
| 185 | for (i = 0; i < ARRAY_SIZE(fr_sids); i++) { |
| 186 | int rc = osmo_fr_check_sid(fr_sids[i], 33); |
| 187 | printf("FR SID %s: %d\n", osmo_hexdump(fr_sids[i], 33), rc); |
| 188 | } |
| 189 | } |
| 190 | |
Max | 92db150 | 2016-05-25 18:13:51 +0200 | [diff] [blame] | 191 | int main(int argc, char **argv) |
| 192 | { |
| 193 | printf("AMR RTP payload decoder test:\n"); |
| 194 | test_sid_dec(sid_first, 7); |
| 195 | test_sid_dec(sid_update, 7); |
Max | e9e5f8e | 2016-11-07 14:49:13 +0100 | [diff] [blame] | 196 | test_sid_dec(NULL, 7); |
Max | 92db150 | 2016-05-25 18:13:51 +0200 | [diff] [blame] | 197 | test_amr_rt(0, AMR_NO_DATA, AMR_BAD); |
| 198 | test_amr_rt(0, AMR_NO_DATA, AMR_GOOD); |
| 199 | test_amr_rt(AMR_12_2, AMR_12_2, AMR_BAD); |
| 200 | test_amr_rt(AMR_12_2, AMR_12_2, AMR_GOOD); |
| 201 | test_amr_rt(AMR_7_40, AMR_7_40, AMR_BAD); |
| 202 | test_amr_rt(AMR_7_40, AMR_7_40, AMR_GOOD); |
Max | ec8f192 | 2016-05-31 14:50:21 +0200 | [diff] [blame] | 203 | printf("FR RTP payload SID test:\n"); |
| 204 | test_sid_xr(sid_fr, 33, false); |
| 205 | test_sid_xr(fr, 33, false); |
| 206 | |
| 207 | printf("HR RTP payload SID test:\n"); |
| 208 | test_sid_xr(sid_hr, 14, true); |
| 209 | test_sid_xr(hr, 14, true); |
Max | 92db150 | 2016-05-25 18:13:51 +0200 | [diff] [blame] | 210 | |
Harald Welte | 3851e8e | 2017-05-31 02:42:46 +0200 | [diff] [blame] | 211 | printf("FR RTP payload SID test:\n"); |
| 212 | test_sid_fr(); |
| 213 | |
Max | 92db150 | 2016-05-25 18:13:51 +0200 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | |