diff --git a/openair2/F1AP/CMakeLists.txt b/openair2/F1AP/CMakeLists.txt index e6490b96b0..78bc9435a2 100644 --- a/openair2/F1AP/CMakeLists.txt +++ b/openair2/F1AP/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(lib) add_subdirectory(MESSAGES) if(ENABLE_TESTS) @@ -5,4 +6,6 @@ if(ENABLE_TESTS) target_link_libraries(f1ap_ids_test UTIL HASHTABLE minimal_lib) add_dependencies(tests f1ap_ids_test) add_test(NAME F1AP_ID_test COMMAND f1ap_ids_test) + + add_subdirectory(tests) endif() diff --git a/openair2/F1AP/lib/CMakeLists.txt b/openair2/F1AP/lib/CMakeLists.txt new file mode 100644 index 0000000000..6ad2e38aaf --- /dev/null +++ b/openair2/F1AP/lib/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(f1ap_lib OBJECT + f1ap_lib_common.c +) +target_link_libraries(f1ap_lib PRIVATE asn1_f1ap) +target_include_directories(f1ap_lib PUBLIC + ${CMAKE_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/openair2/F1AP/lib/f1ap_lib_common.c b/openair2/F1AP/lib/f1ap_lib_common.c new file mode 100644 index 0000000000..09c1b83b42 --- /dev/null +++ b/openair2/F1AP/lib/f1ap_lib_common.c @@ -0,0 +1,41 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include "f1ap_lib_common.h" +#include "f1ap_messages_types.h" + +#include "OCTET_STRING.h" + +#include "common/utils/assertions.h" +#include "common/utils/utils.h" + +bool eq_f1ap_plmn(const f1ap_plmn_t *a, const f1ap_plmn_t *b) +{ + return a->mcc == b->mcc && a->mnc == b->mnc && a->mnc_digit_length == b->mnc_digit_length; +} + +uint8_t *cp_octet_string(const OCTET_STRING_t *os, int *len) +{ + uint8_t *buf = calloc_or_fail(os->size, sizeof(*buf)); + memcpy(buf, os->buf, os->size); + *len = os->size; + return buf; +} diff --git a/openair2/F1AP/lib/f1ap_lib_common.h b/openair2/F1AP/lib/f1ap_lib_common.h new file mode 100644 index 0000000000..fa1b6246d0 --- /dev/null +++ b/openair2/F1AP/lib/f1ap_lib_common.h @@ -0,0 +1,54 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef F1AP_LIB_COMMON_H_ +#define F1AP_LIB_COMMON_H_ + +#include +#include +#include + +/* macro to look up IE. If mandatory and not found, macro will print + * descriptive debug message to stderr and force exit in calling function */ +#define F1AP_LIB_FIND_IE(IE_TYPE, ie, container, IE_ID, mandatory) \ + do { \ + ie = NULL; \ + for (IE_TYPE **ptr = container->protocolIEs.list.array; \ + ptr < &container->protocolIEs.list.array[container->protocolIEs.list.count]; \ + ptr++) { \ + if ((*ptr)->id == IE_ID) { \ + ie = *ptr; \ + break; \ + } \ + } \ + if (mandatory && ie == NULL) { \ + fprintf(stderr, "%s(): could not find element " #IE_ID " with type " #IE_TYPE "\n", __func__); \ + return false; \ + } \ + } while (0) + +struct f1ap_plmn_t; +bool eq_f1ap_plmn(const struct f1ap_plmn_t *a, const struct f1ap_plmn_t *b); + +struct OCTET_STRING; +uint8_t *cp_octet_string(const struct OCTET_STRING *os, int *len); + +#endif /* F1AP_LIB_COMMON_H_ */ diff --git a/openair2/F1AP/lib/f1ap_lib_extern.h b/openair2/F1AP/lib/f1ap_lib_extern.h new file mode 100644 index 0000000000..88cc11d3b1 --- /dev/null +++ b/openair2/F1AP/lib/f1ap_lib_extern.h @@ -0,0 +1,25 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef F1AP_LIB_EXTERN_H_ +#define F1AP_LIB_EXTERN_H_ + +#endif /* F1AP_LIB_EXTERN_H_ */ diff --git a/openair2/F1AP/lib/f1ap_lib_includes.h b/openair2/F1AP/lib/f1ap_lib_includes.h new file mode 100644 index 0000000000..d68189d277 --- /dev/null +++ b/openair2/F1AP/lib/f1ap_lib_includes.h @@ -0,0 +1,27 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef F1AP_LIB_INCLUDES_H_ +#define F1AP_LIB_INCLUDES_H_ + +#include "F1AP_F1AP-PDU.h" + +#endif /* F1AP_LIB_INCLUDES_H_ */ diff --git a/openair2/F1AP/tests/CMakeLists.txt b/openair2/F1AP/tests/CMakeLists.txt new file mode 100644 index 0000000000..a73334051a --- /dev/null +++ b/openair2/F1AP/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(f1ap_lib_test f1ap_lib_test.c) +add_dependencies(tests f1ap_lib_test) +add_test(NAME f1ap_lib_test COMMAND f1ap_lib_test) +target_link_libraries(f1ap_lib_test PRIVATE f1ap_lib) +target_link_libraries(f1ap_lib_test PRIVATE asn1_f1ap) +target_include_directories(f1ap_lib_test PRIVATE ${CMAKE_SOURCE_DIR}) diff --git a/openair2/F1AP/tests/f1ap_lib_test.c b/openair2/F1AP/tests/f1ap_lib_test.c new file mode 100644 index 0000000000..39f69b5beb --- /dev/null +++ b/openair2/F1AP/tests/f1ap_lib_test.c @@ -0,0 +1,47 @@ +#include +#include +#include + +#include "common/utils/assertions.h" + +#include "f1ap_messages_types.h" +#include "F1AP_F1AP-PDU.h" + +void exit_function(const char *file, const char *function, const int line, const char *s, const int assert) +{ + printf("detected error at %s:%d:%s: %s\n", file, line, function, s); + abort(); +} + +static F1AP_F1AP_PDU_t *f1ap_encode_decode(const F1AP_F1AP_PDU_t *enc_pdu) +{ + //xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, enc_pdu); + + DevAssert(enc_pdu != NULL); + char errbuf[1024]; + size_t errlen = sizeof(errbuf); + int ret = asn_check_constraints(&asn_DEF_F1AP_F1AP_PDU, enc_pdu, errbuf, &errlen); + AssertFatal(ret == 0, "asn_check_constraints() failed: %s\n", errbuf); + + uint8_t msgbuf[16384]; + asn_enc_rval_t enc = aper_encode_to_buffer(&asn_DEF_F1AP_F1AP_PDU, NULL, enc_pdu, msgbuf, sizeof(msgbuf)); + AssertFatal(enc.encoded > 0, "aper_encode_to_buffer() failed\n"); + + F1AP_F1AP_PDU_t *dec_pdu = NULL; + asn_codec_ctx_t st = {.max_stack_size = 100 * 1000}; + asn_dec_rval_t dec = aper_decode(&st, &asn_DEF_F1AP_F1AP_PDU, (void **)&dec_pdu, msgbuf, enc.encoded, 0, 0); + AssertFatal(dec.code == RC_OK, "aper_decode() failed\n"); + + //xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, dec_pdu); + return dec_pdu; +} + +static void f1ap_msg_free(F1AP_F1AP_PDU_t *pdu) +{ + ASN_STRUCT_FREE(asn_DEF_F1AP_F1AP_PDU, pdu); +} + +int main() +{ + return 0; +}