blob: 629726b620e30c776361b7e66a9ddd9479a46885 [file] [log] [blame]
Neels Hofmeyrb984f362016-02-18 01:18:20 +01001#include <osmocom/core/msgb.h>
2#include <osmocom/ranap/ranap_ies_defs.h>
Pau Espin Pedrol634fd812021-01-14 11:19:06 +01003#include <osmocom/ranap/iu_helpers.h>
Neels Hofmeyrb984f362016-02-18 01:18:20 +01004
Neels Hofmeyr4470f932016-04-19 00:13:53 +02005#include "hnb-test-layers.h"
6
Neels Hofmeyrb984f362016-02-18 01:18:20 +01007static const char *printstr(OCTET_STRING_t *s)
8{
Pau Espin Pedrol825a1e42021-01-14 11:10:04 +01009 return osmo_hexdump((const unsigned char*)s->buf, s->size);
Neels Hofmeyrb984f362016-02-18 01:18:20 +010010}
11
12#define PP(octet_string_t) \
13 printf(#octet_string_t " = %s\n",\
14 printstr(&octet_string_t))
15
Neels Hofmeyr4470f932016-04-19 00:13:53 +020016void hnb_test_rua_dt_handle_ranap(struct hnb_test *hnb,
17 struct ranap_message_s *ranap_msg)
Neels Hofmeyrb984f362016-02-18 01:18:20 +010018{
Neels Hofmeyr4470f932016-04-19 00:13:53 +020019 int len;
Pau Espin Pedrol101fba22021-01-14 11:18:23 +010020 uint8_t *data;
Neels Hofmeyr4a0a69a2016-04-19 00:06:28 +020021 RANAP_PermittedIntegrityProtectionAlgorithms_t *algs;
22 RANAP_IntegrityProtectionAlgorithm_t *first_alg;
Neels Hofmeyrb984f362016-02-18 01:18:20 +010023
Neels Hofmeyr4470f932016-04-19 00:13:53 +020024 printf("rx ranap_msg->procedureCode %d\n",
25 ranap_msg->procedureCode);
Neels Hofmeyrb984f362016-02-18 01:18:20 +010026
Neels Hofmeyr4470f932016-04-19 00:13:53 +020027 switch (ranap_msg->procedureCode) {
28 case RANAP_ProcedureCode_id_DirectTransfer:
29 printf("rx DirectTransfer: presence = %hx\n",
30 ranap_msg->msg.directTransferIEs.presenceMask);
31 PP(ranap_msg->msg.directTransferIEs.nas_pdu);
Neels Hofmeyrb984f362016-02-18 01:18:20 +010032
Neels Hofmeyr4470f932016-04-19 00:13:53 +020033 len = ranap_msg->msg.directTransferIEs.nas_pdu.size;
34 data = ranap_msg->msg.directTransferIEs.nas_pdu.buf;
Neels Hofmeyrb984f362016-02-18 01:18:20 +010035
Neels Hofmeyr4470f932016-04-19 00:13:53 +020036 hnb_test_nas_rx_dtap(hnb, data, len);
37 return;
Neels Hofmeyr4a0a69a2016-04-19 00:06:28 +020038
39 case RANAP_ProcedureCode_id_SecurityModeControl:
40 printf("rx SecurityModeControl: presence = %hx\n",
41 ranap_msg->msg.securityModeCommandIEs.presenceMask);
42
43 /* Just pick the first available IP alg, don't care about
44 * encryption (yet?) */
45 algs = &ranap_msg->msg.securityModeCommandIEs.integrityProtectionInformation.permittedAlgorithms;
46 if (algs->list.count < 1) {
47 printf("Security Mode Command: No permitted algorithms.\n");
48 return;
49 }
50 first_alg = *algs->list.array;
51
52 hnb_test_rx_secmode_cmd(hnb, *first_alg);
53 return;
Neels Hofmeyrbde4d3b2016-04-19 02:38:16 +020054
55 case RANAP_ProcedureCode_id_Iu_Release:
56 hnb_test_rx_iu_release(hnb);
57 return;
Neels Hofmeyr4470f932016-04-19 00:13:53 +020058 }
Neels Hofmeyrb984f362016-02-18 01:18:20 +010059}
Neels Hofmeyr5ad72b92016-04-19 18:09:05 +020060
61void hnb_test_rua_cl_handle_ranap(struct hnb_test *hnb,
62 struct ranap_message_s *ranap_msg)
63{
64 char imsi[16];
65
66 printf("rx ranap_msg->procedureCode %d\n",
67 ranap_msg->procedureCode);
68
69 switch (ranap_msg->procedureCode) {
70 case RANAP_ProcedureCode_id_Paging:
71 if (ranap_msg->msg.pagingIEs.permanentNAS_UE_ID.present == RANAP_PermanentNAS_UE_ID_PR_iMSI) {
72 ranap_bcd_decode(imsi, sizeof(imsi),
73 ranap_msg->msg.pagingIEs.permanentNAS_UE_ID.choice.iMSI.buf,
74 ranap_msg->msg.pagingIEs.permanentNAS_UE_ID.choice.iMSI.size);
75 } else imsi[0] = '\0';
76
Pau Espin Pedrol4ab00db2020-03-20 20:19:47 +010077 printf("rx Paging: presence=%hx domain=%ld IMSI=%s\n",
Neels Hofmeyr5ad72b92016-04-19 18:09:05 +020078 ranap_msg->msg.pagingIEs.presenceMask,
79 ranap_msg->msg.pagingIEs.cN_DomainIndicator,
80 imsi
81 );
82
83 hnb_test_rx_paging(hnb, imsi);
84 return;
85 }
86}