blob: fe7db4890ec520a690fee00e1712fef1ce9ff359 [file] [log] [blame]
Neels Hofmeyrb984f362016-02-18 01:18:20 +01001#include <osmocom/core/msgb.h>
2#include <osmocom/ranap/ranap_ies_defs.h>
3
Neels Hofmeyr4470f932016-04-19 00:13:53 +02004#include "hnb-test-layers.h"
5
Neels Hofmeyrb984f362016-02-18 01:18:20 +01006static const char *printstr(OCTET_STRING_t *s)
7{
Pau Espin Pedrol825a1e42021-01-14 11:10:04 +01008 return osmo_hexdump((const unsigned char*)s->buf, s->size);
Neels Hofmeyrb984f362016-02-18 01:18:20 +01009}
10
11#define PP(octet_string_t) \
12 printf(#octet_string_t " = %s\n",\
13 printstr(&octet_string_t))
14
Neels Hofmeyr4470f932016-04-19 00:13:53 +020015void hnb_test_rua_dt_handle_ranap(struct hnb_test *hnb,
16 struct ranap_message_s *ranap_msg)
Neels Hofmeyrb984f362016-02-18 01:18:20 +010017{
Neels Hofmeyr4470f932016-04-19 00:13:53 +020018 int len;
19 char *data;
Neels Hofmeyr4a0a69a2016-04-19 00:06:28 +020020 RANAP_PermittedIntegrityProtectionAlgorithms_t *algs;
21 RANAP_IntegrityProtectionAlgorithm_t *first_alg;
Neels Hofmeyrb984f362016-02-18 01:18:20 +010022
Neels Hofmeyr4470f932016-04-19 00:13:53 +020023 printf("rx ranap_msg->procedureCode %d\n",
24 ranap_msg->procedureCode);
Neels Hofmeyrb984f362016-02-18 01:18:20 +010025
Neels Hofmeyr4470f932016-04-19 00:13:53 +020026 switch (ranap_msg->procedureCode) {
27 case RANAP_ProcedureCode_id_DirectTransfer:
28 printf("rx DirectTransfer: presence = %hx\n",
29 ranap_msg->msg.directTransferIEs.presenceMask);
30 PP(ranap_msg->msg.directTransferIEs.nas_pdu);
Neels Hofmeyrb984f362016-02-18 01:18:20 +010031
Neels Hofmeyr4470f932016-04-19 00:13:53 +020032 len = ranap_msg->msg.directTransferIEs.nas_pdu.size;
33 data = ranap_msg->msg.directTransferIEs.nas_pdu.buf;
Neels Hofmeyrb984f362016-02-18 01:18:20 +010034
Neels Hofmeyr4470f932016-04-19 00:13:53 +020035 hnb_test_nas_rx_dtap(hnb, data, len);
36 return;
Neels Hofmeyr4a0a69a2016-04-19 00:06:28 +020037
38 case RANAP_ProcedureCode_id_SecurityModeControl:
39 printf("rx SecurityModeControl: presence = %hx\n",
40 ranap_msg->msg.securityModeCommandIEs.presenceMask);
41
42 /* Just pick the first available IP alg, don't care about
43 * encryption (yet?) */
44 algs = &ranap_msg->msg.securityModeCommandIEs.integrityProtectionInformation.permittedAlgorithms;
45 if (algs->list.count < 1) {
46 printf("Security Mode Command: No permitted algorithms.\n");
47 return;
48 }
49 first_alg = *algs->list.array;
50
51 hnb_test_rx_secmode_cmd(hnb, *first_alg);
52 return;
Neels Hofmeyrbde4d3b2016-04-19 02:38:16 +020053
54 case RANAP_ProcedureCode_id_Iu_Release:
55 hnb_test_rx_iu_release(hnb);
56 return;
Neels Hofmeyr4470f932016-04-19 00:13:53 +020057 }
Neels Hofmeyrb984f362016-02-18 01:18:20 +010058}
Neels Hofmeyr5ad72b92016-04-19 18:09:05 +020059
60void hnb_test_rua_cl_handle_ranap(struct hnb_test *hnb,
61 struct ranap_message_s *ranap_msg)
62{
63 char imsi[16];
64
65 printf("rx ranap_msg->procedureCode %d\n",
66 ranap_msg->procedureCode);
67
68 switch (ranap_msg->procedureCode) {
69 case RANAP_ProcedureCode_id_Paging:
70 if (ranap_msg->msg.pagingIEs.permanentNAS_UE_ID.present == RANAP_PermanentNAS_UE_ID_PR_iMSI) {
71 ranap_bcd_decode(imsi, sizeof(imsi),
72 ranap_msg->msg.pagingIEs.permanentNAS_UE_ID.choice.iMSI.buf,
73 ranap_msg->msg.pagingIEs.permanentNAS_UE_ID.choice.iMSI.size);
74 } else imsi[0] = '\0';
75
Pau Espin Pedrol4ab00db2020-03-20 20:19:47 +010076 printf("rx Paging: presence=%hx domain=%ld IMSI=%s\n",
Neels Hofmeyr5ad72b92016-04-19 18:09:05 +020077 ranap_msg->msg.pagingIEs.presenceMask,
78 ranap_msg->msg.pagingIEs.cN_DomainIndicator,
79 imsi
80 );
81
82 hnb_test_rx_paging(hnb, imsi);
83 return;
84 }
85}