diff --git a/include/osmocom/hnbgw/ranap_rab_ass.h b/include/osmocom/hnbgw/ranap_rab_ass.h index b3406f0..eb18de8 100644 --- a/include/osmocom/hnbgw/ranap_rab_ass.h +++ b/include/osmocom/hnbgw/ranap_rab_ass.h @@ -15,4 +15,5 @@ int ranap_rab_ass_req_ies_replace_inet_addr(RANAP_RAB_AssignmentRequestIEs_t *ie int ranap_rab_ass_resp_ies_replace_inet_addr(RANAP_RAB_AssignmentResponseIEs_t *ies, struct osmo_sockaddr *addr, uint8_t rab_id); +bool ranap_rab_ass_req_ies_check_release(RANAP_RAB_AssignmentRequestIEs_t *ies, uint8_t rab_id); bool ranap_rab_ass_resp_ies_check_failure(RANAP_RAB_AssignmentResponseIEs_t *ies, uint8_t rab_id); diff --git a/src/osmo-hnbgw/ranap_rab_ass.c b/src/osmo-hnbgw/ranap_rab_ass.c index 030a1af..56886c7 100644 --- a/src/osmo-hnbgw/ranap_rab_ass.c +++ b/src/osmo-hnbgw/ranap_rab_ass.c @@ -135,6 +135,23 @@ static RANAP_ProtocolIE_FieldPair_t *prot_ie_field_pair_from_ass_req_ies(const R return protocol_ie_field_pair; } +/* Pick the indexed item from the RAB release-list list and return a pointer to it */ +static RANAP_IE_t *release_item_from_ass_req_ies(const RANAP_RAB_AssignmentRequestIEs_t *ies, unsigned int index) +{ + /* Make sure we indeed deal with a setup-or-modify list */ + if (!(ies->presenceMask & RAB_ASSIGNMENTREQUESTIES_RANAP_RAB_RELEASELIST_PRESENT)) { + RANAP_DEBUG + ("Decoding failed, the RANAP RAB AssignmentRequest did not contain a release list!\n"); + return NULL; + } + + /* Detect the end of the list */ + if (index >= ies->raB_ReleaseList.raB_ReleaseList_ies.list.count) + return NULL; + + return ies->raB_ReleaseList.raB_ReleaseList_ies.list.array[index]; +} + /* Pick the indexed item from the RAB setup-or-modified list and return a pointer to it */ static RANAP_IE_t *setup_or_modif_item_from_rab_ass_resp(const RANAP_RAB_AssignmentResponseIEs_t *ies, unsigned int index) @@ -261,6 +278,41 @@ static int decode_rab_smditms_from_req_ies(RANAP_RAB_SetupOrModifyItemFirst_t *i } } +static int decode_rab_relitms_from_req_ies(RANAP_RAB_ReleaseItemIEs_t *items_ies, + RANAP_RAB_AssignmentRequestIEs_t *ies, uint8_t rab_id) +{ + RANAP_IE_t *release_list_ie; + RANAP_RAB_ReleaseItem_t *rab_release_item; + int rc; + uint8_t rab_id_decoded; + unsigned int index = 0; + + while (1) { + release_list_ie = release_item_from_ass_req_ies(ies, index); + if (!release_list_ie) + return -EINVAL; + + if (release_list_ie->id != RANAP_ProtocolIE_ID_id_RAB_ReleaseItem) { + RANAP_DEBUG("Decoding failed, the protocol IE is not of type RANAP RAB ReleaseItem!\n"); + return -EINVAL; + } + + rc = ranap_decode_rab_releaseitemies_fromlist(items_ies, &release_list_ie->value); + if (rc < 0) + return -EINVAL; + + rab_release_item = &items_ies->raB_ReleaseItem; + /* The RAB-ID is defined as a bitstring with a size of 8 (1 byte), + * See also RANAP-IEs.asn, RAB-ID ::= BIT STRING (SIZE (8)) */ + rab_id_decoded = rab_release_item->rAB_ID.buf[0]; + if (rab_id_decoded == rab_id) + return index; + + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseItem, items_ies); + index++; + } +} + /*! Extract IP address and port from RANAP_RAB_AssignmentRequestIEs. * \ptmap[out] addr user provided memory to store extracted RTP stream IP-Address and port number. * \ptmap[out] rab_id pointer to store RAB-ID (optional, can be NULL). @@ -546,3 +598,25 @@ bool ranap_rab_ass_resp_ies_check_failure(RANAP_RAB_AssignmentResponseIEs_t *ies return result; } + +/*! Check if a specific RAB is present in an RAB-ReleaseList inside RANAP_RAB_AssignmentRequestIEs. + * \ptmap[in] ies user provided memory with RANAP_RAB_AssignmentRequestIEs. + * \ptmap[in] rab_id expected rab id to look for. + * \returns true when RAB is intended for release; false otherwise */ +bool ranap_rab_ass_req_ies_check_release(RANAP_RAB_AssignmentRequestIEs_t *ies, uint8_t rab_id) +{ + RANAP_RAB_ReleaseItemIEs_t _rab_release_items_ies; + RANAP_RAB_ReleaseItemIEs_t *rab_release_items_ies = &_rab_release_items_ies; + int rc; + bool result = true; + + /* If we can get a rlease list item for the specified RAB ID, then we know that the + * MSC intends to release the specified RAB */ + rc = decode_rab_relitms_from_req_ies(rab_release_items_ies, ies, rab_id); + if (rc < 0) + result = false; + + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_ReleaseItem, rab_release_items_ies); + + return result; +} diff --git a/tests/ranap_rab_ass/ranap_rab_ass_test.c b/tests/ranap_rab_ass/ranap_rab_ass_test.c index 5bb4efc..f7664e9 100644 --- a/tests/ranap_rab_ass/ranap_rab_ass_test.c +++ b/tests/ranap_rab_ass/ranap_rab_ass_test.c @@ -295,6 +295,31 @@ void test_ranap_rab_ass_resp_ies_check_failure(void) ranap_cn_rx_co_free(&message); } +void test_ranap_rab_ass_req_ies_check_release(void) +{ + int rc; + ranap_message message; + bool rab_release_req; + uint8_t testvec[] = { + 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x01, 0x00, + 0x29, 0x40, 0x0a, 0x00, 0x00, 0x01, 0x00, 0x28, + 0x40, 0x03, 0x05, 0xd0, 0x00 + }; + + rc = ranap_ran_rx_co_decode(talloc_asn1_ctx, &message, testvec, sizeof(testvec)); + OSMO_ASSERT(rc == 0); + + rab_release_req = + ranap_rab_ass_req_ies_check_release(&message.msg.raB_AssignmentRequestIEs, 23); + printf("ranap_rab_ass_req_ies_check_release rab_release_req=%u (RAB ID 23)\n", rab_release_req); + + rab_release_req = + ranap_rab_ass_req_ies_check_release(&message.msg.raB_AssignmentRequestIEs, 44); + printf("ranap_rab_ass_req_ies_check_release rab_release_req=%u (RAB ID 44, which is not in the message)\n", rab_release_req); + + ranap_ran_rx_co_free(&message); +} + static const struct log_info_cat log_cat[] = { [DRANAP] = { .name = "RANAP", .loglevel = LOGL_DEBUG, .enabled = 1, @@ -356,6 +381,7 @@ int main(int argc, char **argv) test_ranap_rab_ass_req_replace_inet_addr(); test_ranap_rab_ass_resp_replace_inet_addr(); test_ranap_rab_ass_resp_ies_check_failure(); + test_ranap_rab_ass_req_ies_check_release(); test_cleanup(); return 0; diff --git a/tests/ranap_rab_ass/ranap_rab_ass_test.ok b/tests/ranap_rab_ass/ranap_rab_ass_test.ok index d372550..688925c 100644 --- a/tests/ranap_rab_ass/ranap_rab_ass_test.ok +++ b/tests/ranap_rab_ass/ranap_rab_ass_test.ok @@ -16,3 +16,5 @@ ranap_rab_ass_resp_replace_inet_addr rc=0 after: addr=1.2.3.4, port=1234 ranap_rab_ass_resp_ies_check_failure rab_failed_at_hnb=1 (RAB ID 23) ranap_rab_ass_resp_ies_check_failure rab_failed_at_hnb=0 (RAB ID 44, which is not in the message) +ranap_rab_ass_req_ies_check_release rab_release_req=1 (RAB ID 23) +ranap_rab_ass_req_ies_check_release rab_release_req=0 (RAB ID 44, which is not in the message)