Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 1 | /* Test de-/encoding of HBNAP messages */ |
| 2 | |
| 3 | /* (C) 2015 by Daniel Willmann <dwillmann@sysmocom.de> |
| 4 | * (C) 2015 by sysmocom s.f.m.c GmbH |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "iu_helpers.h" |
Daniel Willmann | ea4c088 | 2015-11-27 16:14:09 +0100 | [diff] [blame] | 23 | #include "asn1helpers.h" |
Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 24 | |
| 25 | #include "hnbap_common.h" |
| 26 | #include "hnbap_ies_defs.h" |
| 27 | |
| 28 | #include <assert.h> |
| 29 | #define ASSERT(x) assert(x) |
| 30 | |
| 31 | #include <osmocom/core/utils.h> |
| 32 | #include <osmocom/core/logging.h> |
| 33 | |
| 34 | void *talloc_asn1_ctx; |
| 35 | |
Daniel Willmann | ea4c088 | 2015-11-27 16:14:09 +0100 | [diff] [blame] | 36 | static const unsigned char hnbap_reg_req[] = { |
| 37 | 0x00, 0x01, |
| 38 | 0x00, 0x57, 0x00, 0x00, 0x07, 0x00, 0x03, 0x00, |
| 39 | 0x15, 0x04, 0x80, 0x31, 0x30, 0x30, 0x30, 0x35, |
| 40 | 0x42, 0x39, 0x2d, 0x30, 0x30, 0x31, 0x30, 0x39, |
| 41 | 0x34, 0x32, 0x30, 0x35, 0x30, 0x40, 0x00, 0x08, |
| 42 | 0x00, 0x17, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 43 | 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 44 | 0x00, 0x11, 0x00, 0x05, 0x00, 0xc0, 0xa8, 0x00, |
| 45 | 0x32, 0x00, 0x09, 0x00, 0x03, 0x09, 0xf1, 0x99, |
| 46 | 0x00, 0x0b, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, |
| 47 | 0x00, 0x06, 0x00, 0x02, 0x40, 0x20, 0x00, 0x07, |
| 48 | 0x00, 0x01, 0x64, 0x00, 0x0a, 0x00, 0x02, 0x00, |
| 49 | 0x01 |
| 50 | }; |
| 51 | |
| 52 | static const unsigned char hnbap_reg_acc[] = { |
| 53 | 0x20, 0x01, |
| 54 | 0x00, 0x09, 0x00, 0x00, 0x01, 0x00, 0x0e, 0x00, |
| 55 | 0x02, 0x00, 0x00 |
| 56 | }; |
| 57 | |
Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 58 | static const unsigned char hnbap_ue_reg_req[] = { |
| 59 | 0x00, 0x03, |
| 60 | 0x00, 0x1a, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, |
| 61 | 0x09, 0x0a, 0x62, 0x02, 0x11, 0x32, 0x54, 0x76, |
| 62 | 0x98, 0xf0, 0x00, 0x0c, 0x40, 0x01, 0x40, 0x00, |
| 63 | 0x0d, 0x00, 0x01, 0x0d |
| 64 | }; |
| 65 | |
| 66 | static const unsigned char hnbap_ue_reg_acc[] = { |
| 67 | 0x20, 0x03, |
| 68 | 0x00, 0x17, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00, |
| 69 | 0x09, 0x0a, 0x62, 0x02, 0x11, 0x32, 0x54, 0x76, |
| 70 | 0x98, 0xf0, 0x00, 0x04, 0x00, 0x03, 0x17, 0x00, |
| 71 | 0x00 |
| 72 | }; |
| 73 | |
| 74 | void test_asn1_decoding(void) |
| 75 | { |
| 76 | int rc; |
| 77 | |
| 78 | HNBAP_PDU_t _pdu, *pdu = &_pdu; |
| 79 | InitiatingMessage_t *im; |
Daniel Willmann | 1a86955 | 2015-11-24 18:11:03 +0100 | [diff] [blame] | 80 | SuccessfulOutcome_t *so; |
Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 81 | UERegisterRequestIEs_t ies; |
Daniel Willmann | ea4c088 | 2015-11-27 16:14:09 +0100 | [diff] [blame] | 82 | HNBRegisterRequestIEs_t hnb_ies; |
Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 83 | |
| 84 | char imsi[16]; |
| 85 | |
| 86 | asn_dec_rval_t dec_ret; |
| 87 | |
| 88 | memset(pdu, 0, sizeof(*pdu)); |
| 89 | printf("Testing asn.1 HNBAP decoding\n"); |
| 90 | |
| 91 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
Daniel Willmann | ea4c088 | 2015-11-27 16:14:09 +0100 | [diff] [blame] | 92 | hnbap_reg_req, sizeof(hnbap_reg_req), 0, 0); |
| 93 | |
| 94 | |
| 95 | ASSERT(dec_ret.code == RC_OK); |
| 96 | ASSERT(pdu->present == HNBAP_PDU_PR_initiatingMessage); |
| 97 | |
| 98 | im = &pdu->choice.initiatingMessage; |
| 99 | |
| 100 | ASSERT(im->procedureCode == ProcedureCode_id_HNBRegister); |
| 101 | |
| 102 | rc = hnbap_decode_hnbregisterrequesties(&hnb_ies, &im->value); |
| 103 | ASSERT(rc >= 0); |
| 104 | |
| 105 | uint16_t lac, sac; |
| 106 | uint8_t rac; |
| 107 | uint32_t cid; |
| 108 | |
| 109 | lac = asn1str_to_u16(&hnb_ies.lac); |
| 110 | sac = asn1str_to_u16(&hnb_ies.sac); |
| 111 | rac = asn1str_to_u8(&hnb_ies.rac); |
| 112 | |
| 113 | ASSERT(lac == 0x4020); |
| 114 | ASSERT(sac == 0x0001); |
| 115 | ASSERT(rac == 0x64); |
| 116 | |
| 117 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 118 | hnbap_ue_reg_req, sizeof(hnbap_ue_reg_req), 0, 0); |
| 119 | |
| 120 | |
| 121 | ASSERT(dec_ret.code == RC_OK); |
| 122 | ASSERT(pdu->present == HNBAP_PDU_PR_initiatingMessage); |
| 123 | |
| 124 | im = &pdu->choice.initiatingMessage; |
| 125 | ASSERT(im->procedureCode == ProcedureCode_id_UERegister); |
| 126 | |
| 127 | rc = hnbap_decode_ueregisterrequesties(&ies, &im->value); |
| 128 | ASSERT(rc >= 0); |
| 129 | |
| 130 | ASSERT(ies.uE_Identity.present == UE_Identity_PR_iMSI); |
| 131 | decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf, |
| 132 | ies.uE_Identity.choice.iMSI.size); |
| 133 | |
Daniel Willmann | 1a86955 | 2015-11-24 18:11:03 +0100 | [diff] [blame] | 134 | printf("HNBAP UE Register request from IMSI %s\n", imsi); |
| 135 | |
| 136 | memset(pdu, 0, sizeof(*pdu)); |
| 137 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
| 138 | hnbap_ue_reg_acc, sizeof(hnbap_ue_reg_acc), 0, 0); |
| 139 | |
| 140 | |
| 141 | ASSERT(dec_ret.code == RC_OK); |
| 142 | ASSERT(pdu->present == HNBAP_PDU_PR_successfulOutcome); |
| 143 | |
| 144 | so = &pdu->choice.successfulOutcome; |
| 145 | ASSERT(so->procedureCode == ProcedureCode_id_UERegister); |
| 146 | |
| 147 | rc = hnbap_decode_ueregisteraccepties(&ies, &so->value); |
| 148 | ASSERT(rc >= 0); |
| 149 | |
| 150 | ASSERT(ies.uE_Identity.present == UE_Identity_PR_iMSI); |
| 151 | decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf, |
| 152 | ies.uE_Identity.choice.iMSI.size); |
| 153 | |
| 154 | printf("HNBAP UE Register accept to IMSI %s\n", imsi); |
| 155 | |
Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | |
| 159 | static const struct log_info osmo_log = { |
| 160 | .cat = NULL, |
| 161 | .num_cat = 0, |
| 162 | }; |
| 163 | |
| 164 | int main(int argc, char **argv) |
| 165 | { |
| 166 | int rc; |
| 167 | |
| 168 | rc = osmo_init_logging(&osmo_log); |
| 169 | if (rc < 0) { |
| 170 | printf("Error in init logging\n"); |
| 171 | return -1; |
| 172 | } |
| 173 | |
| 174 | test_asn1_decoding(); |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |