Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 3 | |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 4 | #include <osmocom/core/conv.h> |
Max Suraev msuraev@sysmocom.de | 84da22f | 2016-04-29 13:17:22 +0200 | [diff] [blame] | 5 | #include <osmocom/gsm/gsm0503.h> |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 6 | |
Vadim Yanitskiy | 68930e8 | 2017-01-19 03:33:24 +0700 | [diff] [blame] | 7 | #include "conv.h" |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 8 | |
| 9 | /* ------------------------------------------------------------------------ */ |
| 10 | /* Test codes */ |
| 11 | /* ------------------------------------------------------------------------ */ |
| 12 | |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 13 | /* GMR-1 TCH3 Speech -> Non recursive code, tail-biting, punctured */ |
| 14 | static const uint8_t conv_gmr1_tch3_speech_next_output[][2] = { |
| 15 | { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 }, |
| 16 | { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 }, |
| 17 | { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 }, |
| 18 | { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 }, |
| 19 | { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 }, |
| 20 | { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 }, |
| 21 | { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 }, |
| 22 | { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 }, |
| 23 | { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 }, |
| 24 | { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 }, |
| 25 | { 3, 0 }, { 2, 1 }, { 0, 3 }, { 1, 2 }, |
| 26 | { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 }, |
| 27 | { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 }, |
| 28 | { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 }, |
| 29 | { 1, 2 }, { 0, 3 }, { 2, 1 }, { 3, 0 }, |
| 30 | { 2, 1 }, { 3, 0 }, { 1, 2 }, { 0, 3 }, |
| 31 | }; |
| 32 | |
| 33 | static const uint8_t conv_gmr1_tch3_speech_next_state[][2] = { |
| 34 | { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, |
| 35 | { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 }, |
| 36 | { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 }, |
| 37 | { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 }, |
| 38 | { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 }, |
| 39 | { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 }, |
| 40 | { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 }, |
| 41 | { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 }, |
| 42 | { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, |
| 43 | { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 }, |
| 44 | { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 }, |
| 45 | { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 }, |
| 46 | { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 }, |
| 47 | { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 }, |
| 48 | { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 }, |
| 49 | { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 }, |
| 50 | }; |
| 51 | |
| 52 | static const int conv_gmr1_tch3_speech_puncture[] = { |
| 53 | 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, |
| 54 | 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95, |
| 55 | -1, /* end */ |
| 56 | }; |
| 57 | |
| 58 | static const struct osmo_conv_code conv_gmr1_tch3_speech = { |
| 59 | .N = 2, |
| 60 | .K = 7, |
| 61 | .len = 48, |
| 62 | .term = CONV_TERM_TAIL_BITING, |
| 63 | .next_output = conv_gmr1_tch3_speech_next_output, |
| 64 | .next_state = conv_gmr1_tch3_speech_next_state, |
| 65 | .puncture = conv_gmr1_tch3_speech_puncture, |
| 66 | }; |
| 67 | |
| 68 | |
| 69 | /* WiMax FCH -> Non recursive code, tail-biting, non-punctured */ |
| 70 | static const uint8_t conv_wimax_fch_next_output[][2] = { |
| 71 | { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 }, |
| 72 | { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 }, |
| 73 | { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 }, |
| 74 | { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 }, |
| 75 | { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 }, |
| 76 | { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 }, |
| 77 | { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 }, |
| 78 | { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 }, |
| 79 | { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 }, |
| 80 | { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 }, |
| 81 | { 3, 0 }, { 1, 2 }, { 0, 3 }, { 2, 1 }, |
| 82 | { 0, 3 }, { 2, 1 }, { 3, 0 }, { 1, 2 }, |
| 83 | { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 }, |
| 84 | { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 }, |
| 85 | { 2, 1 }, { 0, 3 }, { 1, 2 }, { 3, 0 }, |
| 86 | { 1, 2 }, { 3, 0 }, { 2, 1 }, { 0, 3 }, |
| 87 | }; |
| 88 | |
| 89 | static const uint8_t conv_wimax_fch_next_state[][2] = { |
| 90 | { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, |
| 91 | { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 }, |
| 92 | { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 }, |
| 93 | { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 }, |
| 94 | { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 }, |
| 95 | { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 }, |
| 96 | { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 }, |
| 97 | { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 }, |
| 98 | { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, |
| 99 | { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 }, |
| 100 | { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 }, |
| 101 | { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 }, |
| 102 | { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 }, |
| 103 | { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 }, |
| 104 | { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 }, |
| 105 | { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 }, |
| 106 | }; |
| 107 | |
| 108 | static const struct osmo_conv_code conv_wimax_fch = { |
| 109 | .N = 2, |
| 110 | .K = 7, |
| 111 | .len = 48, |
| 112 | .term = CONV_TERM_TAIL_BITING, |
| 113 | .next_output = conv_wimax_fch_next_output, |
| 114 | .next_state = conv_wimax_fch_next_state, |
| 115 | }; |
| 116 | |
Vadim Yanitskiy | 1214295 | 2017-01-15 12:55:57 +0700 | [diff] [blame] | 117 | /** |
| 118 | * LTE PBCH |
| 119 | * Non recursive code, tail-biting, non-punctured |
| 120 | */ |
| 121 | static const uint8_t conv_lte_pbch_next_output[][2] = { |
| 122 | { 0, 7 }, { 3, 4 }, { 7, 0 }, { 4 , 3 }, |
| 123 | { 6, 1 }, { 5, 2 }, { 1, 6 }, { 2 , 5 }, |
| 124 | { 1, 6 }, { 2, 5 }, { 6, 1 }, { 5 , 2 }, |
| 125 | { 7, 0 }, { 4, 3 }, { 0, 7 }, { 3 , 4 }, |
| 126 | { 4, 3 }, { 7, 0 }, { 3, 4 }, { 0 , 7 }, |
| 127 | { 2, 5 }, { 1, 6 }, { 5, 2 }, { 6 , 1 }, |
| 128 | { 5, 2 }, { 6, 1 }, { 2, 5 }, { 1 , 6 }, |
| 129 | { 3, 4 }, { 0, 7 }, { 4, 3 }, { 7 , 0 }, |
| 130 | { 7, 0 }, { 4, 3 }, { 0, 7 }, { 3 , 4 }, |
| 131 | { 1, 6 }, { 2, 5 }, { 6, 1 }, { 5 , 2 }, |
| 132 | { 6, 1 }, { 5, 2 }, { 1, 6 }, { 2 , 5 }, |
| 133 | { 0, 7 }, { 3, 4 }, { 7, 0 }, { 4 , 3 }, |
| 134 | { 3, 4 }, { 0, 7 }, { 4, 3 }, { 7 , 0 }, |
| 135 | { 5, 2 }, { 6, 1 }, { 2, 5 }, { 1 , 6 }, |
| 136 | { 2, 5 }, { 1, 6 }, { 5, 2 }, { 6 , 1 }, |
| 137 | { 4, 3 }, { 7, 0 }, { 3, 4 }, { 0 , 7 }, |
| 138 | }; |
| 139 | |
| 140 | static const uint8_t conv_lte_pbch_next_state[][2] = { |
| 141 | { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, |
| 142 | { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 }, |
| 143 | { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 }, |
| 144 | { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 }, |
| 145 | { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 }, |
| 146 | { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 }, |
| 147 | { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 }, |
| 148 | { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 }, |
| 149 | { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, |
| 150 | { 8, 9 }, { 10, 11 }, { 12, 13 }, { 14, 15 }, |
| 151 | { 16, 17 }, { 18, 19 }, { 20, 21 }, { 22, 23 }, |
| 152 | { 24, 25 }, { 26, 27 }, { 28, 29 }, { 30, 31 }, |
| 153 | { 32, 33 }, { 34, 35 }, { 36, 37 }, { 38, 39 }, |
| 154 | { 40, 41 }, { 42, 43 }, { 44, 45 }, { 46, 47 }, |
| 155 | { 48, 49 }, { 50, 51 }, { 52, 53 }, { 54, 55 }, |
| 156 | { 56, 57 }, { 58, 59 }, { 60, 61 }, { 62, 63 }, |
| 157 | }; |
| 158 | |
| 159 | const struct osmo_conv_code conv_lte_pbch = { |
| 160 | .N = 3, |
| 161 | .K = 7, |
| 162 | .len = 40, |
| 163 | .term = CONV_TERM_TAIL_BITING, |
| 164 | .next_output = conv_lte_pbch_next_output, |
| 165 | .next_state = conv_lte_pbch_next_state, |
| 166 | }; |
| 167 | |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 168 | /* ------------------------------------------------------------------------ */ |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 169 | /* Main */ |
| 170 | /* ------------------------------------------------------------------------ */ |
| 171 | |
Jacob Erlbeck | 3c761c8 | 2013-08-14 18:13:46 +0200 | [diff] [blame] | 172 | int main(int argc, char *argv[]) |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 173 | { |
Vadim Yanitskiy | 68930e8 | 2017-01-19 03:33:24 +0700 | [diff] [blame] | 174 | const struct conv_test_vector *test; |
| 175 | int rc; |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 176 | |
Vadim Yanitskiy | 68930e8 | 2017-01-19 03:33:24 +0700 | [diff] [blame] | 177 | /* Random code -> Non recursive code, direct truncation, non-punctured */ |
Max Suraev msuraev@sysmocom.de | 84da22f | 2016-04-29 13:17:22 +0200 | [diff] [blame] | 178 | const struct osmo_conv_code conv_trunc = { |
| 179 | .N = 2, |
| 180 | .K = 5, |
| 181 | .len = 224, |
| 182 | .term = CONV_TERM_TRUNCATION, |
| 183 | .next_output = gsm0503_xcch.next_output, |
| 184 | .next_state = gsm0503_xcch.next_state, |
| 185 | }; |
| 186 | |
| 187 | const struct conv_test_vector tests[] = { |
| 188 | { |
| 189 | .name = "GSM xCCH (non-recursive, flushed, not punctured)", |
| 190 | .code = &gsm0503_xcch, |
| 191 | .in_len = 224, |
| 192 | .out_len = 456, |
| 193 | .has_vec = 1, |
| 194 | .vec_in = { 0xf3, 0x1d, 0xb4, 0x0c, 0x4d, 0x1d, 0x9d, 0xae, |
| 195 | 0xc0, 0x0a, 0x42, 0x57, 0x13, 0x60, 0x80, 0x96, |
| 196 | 0xef, 0x23, 0x7e, 0x4c, 0x1d, 0x96, 0x24, 0x19, |
| 197 | 0x17, 0xf2, 0x44, 0x99 }, |
| 198 | .vec_out = { 0xe9, 0x4d, 0x70, 0xab, 0xa2, 0x87, 0xf0, 0xe7, |
| 199 | 0x04, 0x14, 0x7c, 0xab, 0xaf, 0x6b, 0xa1, 0x16, |
| 200 | 0xeb, 0x30, 0x00, 0xde, 0xc8, 0xfd, 0x0b, 0x85, |
| 201 | 0x80, 0x41, 0x4a, 0xcc, 0xd3, 0xc0, 0xd0, 0xb6, |
| 202 | 0x26, 0xe5, 0x4e, 0x32, 0x49, 0x69, 0x38, 0x17, |
| 203 | 0x33, 0xab, 0xaf, 0xb6, 0xc1, 0x08, 0xf3, 0x9f, |
| 204 | 0x8c, 0x75, 0x6a, 0x4e, 0x08, 0xc4, 0x20, 0x5f, |
| 205 | 0x8f }, |
| 206 | }, |
| 207 | { |
| 208 | .name = "GSM TCH/AFS 7.95 (recursive, flushed, punctured)", |
| 209 | .code = &gsm0503_tch_afs_7_95, |
| 210 | .in_len = 165, |
| 211 | .out_len = 448, |
| 212 | .has_vec = 1, |
| 213 | .vec_in = { 0x87, 0x66, 0xc3, 0x58, 0x09, 0xd4, 0x06, 0x59, |
| 214 | 0x10, 0xbf, 0x6b, 0x7f, 0xc8, 0xed, 0x72, 0xaa, |
| 215 | 0xc1, 0x3d, 0xf3, 0x1e, 0xb0 }, |
| 216 | .vec_out = { 0x92, 0xbc, 0xde, 0xa0, 0xde, 0xbe, 0x01, 0x2f, |
| 217 | 0xbe, 0xe4, 0x61, 0x32, 0x4d, 0x4f, 0xdc, 0x41, |
| 218 | 0x43, 0x0d, 0x15, 0xe0, 0x23, 0xdd, 0x18, 0x91, |
| 219 | 0xe5, 0x36, 0x2d, 0xb7, 0xd9, 0x78, 0xb8, 0xb1, |
| 220 | 0xb7, 0xcb, 0x2f, 0xc0, 0x52, 0x8f, 0xe2, 0x8c, |
| 221 | 0x6f, 0xa6, 0x79, 0x88, 0xed, 0x0c, 0x2e, 0x9e, |
| 222 | 0xa1, 0x5f, 0x45, 0x4a, 0xfb, 0xe6, 0x5a, 0x9c }, |
| 223 | }, |
| 224 | { |
| 225 | .name = "GMR-1 TCH3 Speech (non-recursive, tail-biting, punctured)", |
| 226 | .code = &conv_gmr1_tch3_speech, |
| 227 | .in_len = 48, |
| 228 | .out_len = 72, |
| 229 | .has_vec = 1, |
Vadim Yanitskiy | d8494bc | 2017-01-15 13:00:47 +0700 | [diff] [blame] | 230 | .vec_in = { 0x4d, 0xcb, 0xfc, 0x72, 0xf4, 0x8c }, |
Max Suraev msuraev@sysmocom.de | 84da22f | 2016-04-29 13:17:22 +0200 | [diff] [blame] | 231 | .vec_out = { 0xc0, 0x86, 0x63, 0x4b, 0x8b, 0xd4, 0x6a, 0x76, 0xb2 }, |
| 232 | }, |
| 233 | { |
| 234 | .name = "WiMax FCH (non-recursive, tail-biting, not punctured)", |
| 235 | .code = &conv_wimax_fch, |
| 236 | .in_len = 48, |
| 237 | .out_len = 96, |
| 238 | .has_vec = 1, |
| 239 | .vec_in = { 0xfc, 0xa0, 0xa0, 0xfc, 0xa0, 0xa0 }, |
| 240 | .vec_out = { 0x19, 0x42, 0x8a, 0xed, 0x21, 0xed, 0x19, 0x42, |
| 241 | 0x8a, 0xed, 0x21, 0xed }, |
| 242 | }, |
| 243 | { |
Vadim Yanitskiy | 1214295 | 2017-01-15 12:55:57 +0700 | [diff] [blame] | 244 | .name = "LTE PBCH (non-recursive, tail-biting, non-punctured)", |
| 245 | .code = &conv_lte_pbch, |
| 246 | .in_len = 40, |
| 247 | .out_len = 120, |
| 248 | .has_vec = 0, |
| 249 | .vec_in = { }, |
| 250 | .vec_out = { }, |
| 251 | }, |
| 252 | { |
Max Suraev msuraev@sysmocom.de | 84da22f | 2016-04-29 13:17:22 +0200 | [diff] [blame] | 253 | .name = "??? (non-recursive, direct truncation, not punctured)", |
| 254 | .code = &conv_trunc, |
| 255 | .in_len = 224, |
| 256 | .out_len = 448, |
| 257 | .has_vec = 1, |
| 258 | .vec_in = { 0xe5, 0xe0, 0x85, 0x7e, 0xf7, 0x08, 0x19, 0x5a, |
| 259 | 0xb9, 0xad, 0x82, 0x37, 0x98, 0x8b, 0x26, 0xb9, |
| 260 | 0x81, 0x26, 0x9c, 0x75, 0xaf, 0xf3, 0xcb, 0x07, |
| 261 | 0xac, 0x63, 0xe2, 0x9c, |
| 262 | }, |
| 263 | .vec_out = { 0xea, 0x3b, 0x55, 0x0c, 0xd3, 0xf7, 0x85, 0x69, |
| 264 | 0xe5, 0x79, 0x83, 0xd3, 0xc3, 0x9f, 0xb8, 0x61, |
| 265 | 0x21, 0x63, 0x51, 0x18, 0xac, 0xcd, 0x32, 0x49, |
| 266 | 0x53, 0x5c, 0x13, 0x1d, 0xbe, 0x05, 0x11, 0x63, |
| 267 | 0x5c, 0xc3, 0x42, 0x05, 0x1c, 0x68, 0x0a, 0xb4, |
| 268 | 0x61, 0x15, 0xaa, 0x4d, 0x94, 0xed, 0xb3, 0x3a, |
| 269 | 0x5d, 0x1b, 0x09, 0xc2, 0x99, 0x01, 0xec, 0x68 }, |
| 270 | }, |
| 271 | { /* end */ }, |
| 272 | }; |
| 273 | |
Vadim Yanitskiy | 68930e8 | 2017-01-19 03:33:24 +0700 | [diff] [blame] | 274 | for (test = tests; test->name; test++) { |
| 275 | rc = do_check(test); |
| 276 | if (rc) |
| 277 | return rc; |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 278 | } |
| 279 | |
Sylvain Munaut | 29eb92d | 2011-11-24 17:48:42 +0100 | [diff] [blame] | 280 | return 0; |
| 281 | } |