Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 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 | |
| 23 | #include <osmocom/core/application.h> |
| 24 | #include <osmocom/core/utils.h> |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 25 | #include <osmocom/gsm/protocol/gsm_12_21.h> |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 26 | |
| 27 | #include <openbsc/gsm_data.h> |
| 28 | #include <openbsc/abis_nm.h> |
| 29 | #include <openbsc/debug.h> |
| 30 | |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 31 | static const uint8_t load_config[] = { |
| 32 | 0x42, 0x12, 0x00, 0x08, 0x31, 0x36, 0x38, 0x64, |
| 33 | 0x34, 0x37, 0x32, 0x00, 0x13, 0x00, 0x0b, 0x76, |
| 34 | 0x32, 0x30, 0x30, 0x62, 0x31, 0x34, 0x33, 0x64, |
| 35 | 0x30, 0x00, 0x42, 0x12, 0x00, 0x08, 0x31, 0x36, |
| 36 | 0x38, 0x64, 0x34, 0x37, 0x32, 0x00, 0x13, 0x00, |
| 37 | 0x0b, 0x76, 0x32, 0x30, 0x30, 0x62, 0x31, 0x34, |
| 38 | 0x33, 0x64, 0x31, 0x00 |
| 39 | }; |
| 40 | |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 41 | static void test_sw_selection(void) |
| 42 | { |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 43 | struct abis_nm_sw_desc descr[8], tmp; |
| 44 | uint16_t len0, len1; |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 45 | int rc, pos; |
| 46 | |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 47 | rc = abis_nm_get_sw_conf(load_config, ARRAY_SIZE(load_config), |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 48 | &descr[0], ARRAY_SIZE(descr)); |
| 49 | if (rc != 2) { |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 50 | printf("%s(): FAILED to parse the File Id/File version: %d\n", |
| 51 | __func__, rc); |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 52 | abort(); |
| 53 | } |
| 54 | |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 55 | len0 = abis_nm_sw_desc_len(&descr[0], true); |
| 56 | printf("len: %u\n", len0); |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 57 | printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len)); |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 58 | printf("file_ver: %s\n", osmo_hexdump(descr[0].file_version, descr[0].file_version_len)); |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 59 | |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 60 | len1 = abis_nm_sw_desc_len(&descr[1], true); |
| 61 | printf("len: %u\n", len1); |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 62 | printf("file_id: %s\n", osmo_hexdump(descr[1].file_id, descr[1].file_id_len)); |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 63 | printf("file_ver: %s\n", osmo_hexdump(descr[1].file_version, descr[1].file_version_len)); |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 64 | |
| 65 | /* start */ |
| 66 | pos = abis_nm_select_newest_sw(descr, rc); |
| 67 | if (pos != 1) { |
| 68 | printf("Selected the wrong version: %d\n", pos); |
| 69 | abort(); |
| 70 | } |
| 71 | printf("SELECTED: %d\n", pos); |
| 72 | |
| 73 | /* shuffle */ |
| 74 | tmp = descr[0]; |
| 75 | descr[0] = descr[1]; |
| 76 | descr[1] = tmp; |
| 77 | pos = abis_nm_select_newest_sw(descr, rc); |
| 78 | if (pos != 0) { |
| 79 | printf("Selected the wrong version: %d\n", pos); |
| 80 | abort(); |
| 81 | } |
| 82 | printf("SELECTED: %d\n", pos); |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 83 | printf("%s(): OK\n", __func__); |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 86 | int main(int argc, char **argv) |
| 87 | { |
| 88 | osmo_init_logging(&log_info); |
Max | 82df691 | 2017-03-24 21:04:57 +0100 | [diff] [blame] | 89 | |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 90 | test_sw_selection(); |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 91 | |
| 92 | return EXIT_SUCCESS; |
| 93 | } |