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" |
| 23 | |
| 24 | #include "hnbap_common.h" |
| 25 | #include "hnbap_ies_defs.h" |
| 26 | |
| 27 | #include <assert.h> |
| 28 | #define ASSERT(x) assert(x) |
| 29 | |
| 30 | #include <osmocom/core/utils.h> |
| 31 | #include <osmocom/core/logging.h> |
| 32 | |
| 33 | void *talloc_asn1_ctx; |
| 34 | |
| 35 | static const unsigned char hnbap_ue_reg_req[] = { |
| 36 | 0x00, 0x03, |
| 37 | 0x00, 0x1a, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, |
| 38 | 0x09, 0x0a, 0x62, 0x02, 0x11, 0x32, 0x54, 0x76, |
| 39 | 0x98, 0xf0, 0x00, 0x0c, 0x40, 0x01, 0x40, 0x00, |
| 40 | 0x0d, 0x00, 0x01, 0x0d |
| 41 | }; |
| 42 | |
| 43 | static const unsigned char hnbap_ue_reg_acc[] = { |
| 44 | 0x20, 0x03, |
| 45 | 0x00, 0x17, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00, |
| 46 | 0x09, 0x0a, 0x62, 0x02, 0x11, 0x32, 0x54, 0x76, |
| 47 | 0x98, 0xf0, 0x00, 0x04, 0x00, 0x03, 0x17, 0x00, |
| 48 | 0x00 |
| 49 | }; |
| 50 | |
| 51 | void test_asn1_decoding(void) |
| 52 | { |
| 53 | int rc; |
| 54 | |
| 55 | HNBAP_PDU_t _pdu, *pdu = &_pdu; |
| 56 | InitiatingMessage_t *im; |
Daniel Willmann | 1a86955 | 2015-11-24 18:11:03 +0100 | [diff] [blame^] | 57 | SuccessfulOutcome_t *so; |
Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 58 | UERegisterRequestIEs_t ies; |
| 59 | |
| 60 | char imsi[16]; |
| 61 | |
| 62 | asn_dec_rval_t dec_ret; |
| 63 | |
| 64 | memset(pdu, 0, sizeof(*pdu)); |
| 65 | printf("Testing asn.1 HNBAP decoding\n"); |
| 66 | |
| 67 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
| 68 | hnbap_ue_reg_req, sizeof(hnbap_ue_reg_req), 0, 0); |
| 69 | |
| 70 | |
| 71 | ASSERT(dec_ret.code == RC_OK); |
| 72 | ASSERT(pdu->present == HNBAP_PDU_PR_initiatingMessage); |
| 73 | |
| 74 | im = &pdu->choice.initiatingMessage; |
| 75 | ASSERT(im->procedureCode == ProcedureCode_id_UERegister); |
| 76 | |
| 77 | rc = hnbap_decode_ueregisterrequesties(&ies, &im->value); |
| 78 | ASSERT(rc >= 0); |
| 79 | |
| 80 | ASSERT(ies.uE_Identity.present == UE_Identity_PR_iMSI); |
| 81 | decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf, |
| 82 | ies.uE_Identity.choice.iMSI.size); |
| 83 | |
Daniel Willmann | 1a86955 | 2015-11-24 18:11:03 +0100 | [diff] [blame^] | 84 | printf("HNBAP UE Register request from IMSI %s\n", imsi); |
| 85 | |
| 86 | memset(pdu, 0, sizeof(*pdu)); |
| 87 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
| 88 | hnbap_ue_reg_acc, sizeof(hnbap_ue_reg_acc), 0, 0); |
| 89 | |
| 90 | |
| 91 | ASSERT(dec_ret.code == RC_OK); |
| 92 | ASSERT(pdu->present == HNBAP_PDU_PR_successfulOutcome); |
| 93 | |
| 94 | so = &pdu->choice.successfulOutcome; |
| 95 | ASSERT(so->procedureCode == ProcedureCode_id_UERegister); |
| 96 | |
| 97 | rc = hnbap_decode_ueregisteraccepties(&ies, &so->value); |
| 98 | ASSERT(rc >= 0); |
| 99 | |
| 100 | ASSERT(ies.uE_Identity.present == UE_Identity_PR_iMSI); |
| 101 | decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf, |
| 102 | ies.uE_Identity.choice.iMSI.size); |
| 103 | |
| 104 | printf("HNBAP UE Register accept to IMSI %s\n", imsi); |
| 105 | |
Daniel Willmann | 39e643a | 2015-11-24 18:03:29 +0100 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
| 109 | static const struct log_info osmo_log = { |
| 110 | .cat = NULL, |
| 111 | .num_cat = 0, |
| 112 | }; |
| 113 | |
| 114 | int main(int argc, char **argv) |
| 115 | { |
| 116 | int rc; |
| 117 | |
| 118 | rc = osmo_init_logging(&osmo_log); |
| 119 | if (rc < 0) { |
| 120 | printf("Error in init logging\n"); |
| 121 | return -1; |
| 122 | } |
| 123 | |
| 124 | test_asn1_decoding(); |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |