blob: 591f8350ff96045c1d4a7638010fdace9e969c31 [file] [log] [blame]
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +01001/*
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>
Maxfd2c1f92017-03-24 21:04:57 +010025#include <osmocom/gsm/protocol/gsm_12_21.h>
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +010026
27#include <openbsc/gsm_data.h>
28#include <openbsc/abis_nm.h>
29#include <openbsc/debug.h>
30
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010031static 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 Freyther2f257472012-11-22 19:04:10 +010041static void test_sw_selection(void)
42{
Maxfd2c1f92017-03-24 21:04:57 +010043 struct abis_nm_sw_desc descr[8], tmp;
44 uint16_t len0, len1;
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010045 int rc, pos;
46
Maxfd2c1f92017-03-24 21:04:57 +010047 rc = abis_nm_get_sw_conf(load_config, ARRAY_SIZE(load_config),
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010048 &descr[0], ARRAY_SIZE(descr));
49 if (rc != 2) {
Maxfd2c1f92017-03-24 21:04:57 +010050 printf("%s(): FAILED to parse the File Id/File version: %d\n",
51 __func__, rc);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010052 abort();
53 }
54
Maxfd2c1f92017-03-24 21:04:57 +010055 len0 = abis_nm_sw_desc_len(&descr[0], true);
56 printf("len: %u\n", len0);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010057 printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len));
Maxfd2c1f92017-03-24 21:04:57 +010058 printf("file_ver: %s\n", osmo_hexdump(descr[0].file_version, descr[0].file_version_len));
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010059
Maxfd2c1f92017-03-24 21:04:57 +010060 len1 = abis_nm_sw_desc_len(&descr[1], true);
61 printf("len: %u\n", len1);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010062 printf("file_id: %s\n", osmo_hexdump(descr[1].file_id, descr[1].file_id_len));
Maxfd2c1f92017-03-24 21:04:57 +010063 printf("file_ver: %s\n", osmo_hexdump(descr[1].file_version, descr[1].file_version_len));
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010064
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);
Maxfd2c1f92017-03-24 21:04:57 +010083 printf("%s(): OK\n", __func__);
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010084}
85
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +010086int main(int argc, char **argv)
87{
88 osmo_init_logging(&log_info);
Maxfd2c1f92017-03-24 21:04:57 +010089
Holger Hans Peter Freyther2f257472012-11-22 19:04:10 +010090 test_sw_selection();
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +010091
92 return EXIT_SUCCESS;
93}