From 736474ce451a92cdc17db5f290f55f8cf22a13a2 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 6 May 2016 23:28:52 +0200 Subject: move OAP messages implementations to libosmocore This corresponds to change-id If5099e60681a215e798b6675f21813f26769c253 in libosmocore, which is now required to build openbsc. Related: OS#1592 Change-Id: I2f06aaa6eb54eafa860cfed8e72e41d82ff1c4cf --- openbsc/configure.ac | 2 +- openbsc/include/openbsc/Makefile.am | 1 - openbsc/include/openbsc/oap_messages.h | 70 ------------- openbsc/src/gprs/Makefile.am | 1 - openbsc/src/gprs/oap.c | 2 +- openbsc/src/gprs/oap_messages.c | 178 --------------------------------- openbsc/tests/oap/Makefile.am | 1 - openbsc/tests/oap/oap_test.c | 3 +- openbsc/tests/sgsn/Makefile.am | 1 - 9 files changed, 3 insertions(+), 256 deletions(-) delete mode 100644 openbsc/include/openbsc/oap_messages.h delete mode 100644 openbsc/src/gprs/oap_messages.c diff --git a/openbsc/configure.ac b/openbsc/configure.ac index 4fe105019..0753834f9 100644 --- a/openbsc/configure.ac +++ b/openbsc/configure.ac @@ -33,7 +33,7 @@ AC_SUBST(LIBRARY_DL) PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.9.5) PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 0.3.0) PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl) -PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 0.9.4) +PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 0.9.5) PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.2.0) PKG_CHECK_MODULES(LIBOSMOGB, libosmogb >= 0.6.4) PKG_CHECK_MODULES(LIBOSMONETIF, libosmo-netif >= 0.0.1) diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am index 9f574e6e9..8ea95e0a8 100644 --- a/openbsc/include/openbsc/Makefile.am +++ b/openbsc/include/openbsc/Makefile.am @@ -55,7 +55,6 @@ noinst_HEADERS = \ nat_rewrite_trie.h \ network_listen.h \ oap.h \ - oap_messages.h \ openbscdefines.h \ osmo_bsc.h \ osmo_bsc_grace.h \ diff --git a/openbsc/include/openbsc/oap_messages.h b/openbsc/include/openbsc/oap_messages.h deleted file mode 100644 index ecb66df34..000000000 --- a/openbsc/include/openbsc/oap_messages.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Osmocom Authentication Protocol message encoder/decoder */ - -/* (C) 2015 by Sysmocom s.f.m.c. GmbH - * All Rights Reserved - * - * Author: Neels Hofmeyr - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#include -#include -#include - -/* Some numbers are out of sequence because (so far) they match gprs_gsup_iei. - */ -enum oap_iei { - OAP_CAUSE_IE = 0x02, - OAP_RAND_IE = 0x20, - OAP_AUTN_IE = 0x23, - OAP_XRES_IE = 0x24, - OAP_AUTS_IE = 0x25, - OAP_CLIENT_ID_IE = 0x30, -}; - -enum osmo_oap_message_type { - OAP_MSGT_REGISTER_REQUEST = 0b00000100, - OAP_MSGT_REGISTER_ERROR = 0b00000101, - OAP_MSGT_REGISTER_RESULT = 0b00000110, - - OAP_MSGT_CHALLENGE_REQUEST = 0b00001000, - OAP_MSGT_CHALLENGE_ERROR = 0b00001001, - OAP_MSGT_CHALLENGE_RESULT = 0b00001010, - - OAP_MSGT_SYNC_REQUEST = 0b00001100, - OAP_MSGT_SYNC_ERROR = 0b00001101, - OAP_MSGT_SYNC_RESULT = 0b00001110, -}; - -struct osmo_oap_message { - enum osmo_oap_message_type message_type; - enum gsm48_gmm_cause cause; - uint16_t client_id; - int rand_present; - uint8_t rand[16]; - int autn_present; - uint8_t autn[16]; - int xres_present; - uint8_t xres[8]; - int auts_present; - uint8_t auts[16]; -}; - -int osmo_oap_decode(struct osmo_oap_message *oap_msg, - const uint8_t *data, size_t data_len); -void osmo_oap_encode(struct msgb *msg, const struct osmo_oap_message *oap_msg); - diff --git a/openbsc/src/gprs/Makefile.am b/openbsc/src/gprs/Makefile.am index a827b77a1..ab2517eea 100644 --- a/openbsc/src/gprs/Makefile.am +++ b/openbsc/src/gprs/Makefile.am @@ -93,7 +93,6 @@ osmo_sgsn_SOURCES = \ sgsn_ares.c \ slhc.c \ oap.c \ - oap_messages.c \ gprs_llc_xid.c \ v42bis.c \ $(NULL) diff --git a/openbsc/src/gprs/oap.c b/openbsc/src/gprs/oap.c index c7c97774d..7efbe81cd 100644 --- a/openbsc/src/gprs/oap.c +++ b/openbsc/src/gprs/oap.c @@ -24,10 +24,10 @@ #include #include +#include #include #include -#include int oap_init(struct oap_config *config, struct oap_state *state) { diff --git a/openbsc/src/gprs/oap_messages.c b/openbsc/src/gprs/oap_messages.c deleted file mode 100644 index d81723fd6..000000000 --- a/openbsc/src/gprs/oap_messages.c +++ /dev/null @@ -1,178 +0,0 @@ -/* Osmocom Authentication Protocol message encoder/decoder */ - -/* (C) 2015 by Sysmocom s.f.m.c. GmbH - * All Rights Reserved - * - * Author: Neels Hofmeyr - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -#include -#include - -#include - -#include -#include - -#include - - -int osmo_oap_decode(struct osmo_oap_message *oap_msg, - const uint8_t *const_data, size_t data_len) -{ - int rc; - uint8_t tag; - /* the shift/match functions expect non-const pointers, but we'll - * either copy the data or cast pointers back to const before returning - * them - */ - uint8_t *data = (uint8_t *)const_data; - uint8_t *value; - size_t value_len; - - memset(oap_msg, 0, sizeof(*oap_msg)); - - /* message type */ - rc = osmo_shift_v_fixed(&data, &data_len, 1, &value); - if (rc < 0) - return -GMM_CAUSE_INV_MAND_INFO; - oap_msg->message_type = osmo_decode_big_endian(value, 1); - - /* specific parts */ - while (data_len > 0) { - enum oap_iei iei; - - rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len); - if (rc < 0) - return -GMM_CAUSE_PROTO_ERR_UNSPEC; - - iei = tag; - - switch (iei) { - case OAP_CLIENT_ID_IE: - if (value_len != 2) { - LOGP(DGPRS, LOGL_NOTICE, - "OAP IE type client ID (%d) should be 2 octets, but has %d\n", - (int)iei, (int)value_len); - return -GMM_CAUSE_PROTO_ERR_UNSPEC; - } - - oap_msg->client_id = osmo_decode_big_endian(value, value_len); - - if (oap_msg->client_id == 0) { - LOGP(DGPRS, LOGL_NOTICE, - "OAP IE type client ID (%d): client ID must be nonzero.\n", - (int)iei); - return -GMM_CAUSE_PROTO_ERR_UNSPEC; - } - break; - - case OAP_AUTN_IE: - if (value_len != sizeof(oap_msg->autn)) { - LOGP(DGPRS, LOGL_NOTICE, - "OAP IE type AUTN (%d) should be %d octets, but has %d\n", - (int)iei, (int)sizeof(oap_msg->autn), (int)value_len); - return -GMM_CAUSE_PROTO_ERR_UNSPEC; - } - memcpy(oap_msg->autn, value, value_len); - oap_msg->autn_present = value_len; - break; - - case OAP_RAND_IE: - if (value_len != sizeof(oap_msg->rand)) { - LOGP(DGPRS, LOGL_NOTICE, - "OAP IE type RAND (%d) should be %d octets, but has %d\n", - (int)iei, (int)sizeof(oap_msg->rand), (int)value_len); - return -GMM_CAUSE_PROTO_ERR_UNSPEC; - } - memcpy(oap_msg->rand, value, value_len); - oap_msg->rand_present = value_len; - break; - - case OAP_XRES_IE: - if (value_len != sizeof(oap_msg->xres)) { - LOGP(DGPRS, LOGL_NOTICE, - "OAP IE type XRES (%d) should be %d octets, but has %d\n", - (int)iei, (int)sizeof(oap_msg->xres), (int)value_len); - return -GMM_CAUSE_PROTO_ERR_UNSPEC; - } - memcpy(oap_msg->xres, value, value_len); - oap_msg->xres_present = value_len; - break; - - case OAP_AUTS_IE: - if (value_len != sizeof(oap_msg->auts)) { - LOGP(DGPRS, LOGL_NOTICE, - "OAP IE type AUTS (%d) should be %d octets, but has %d\n", - (int)iei, (int)sizeof(oap_msg->auts), (int)value_len); - return -GMM_CAUSE_PROTO_ERR_UNSPEC; - } - memcpy(oap_msg->auts, value, value_len); - oap_msg->auts_present = value_len; - break; - - case OAP_CAUSE_IE: - if (value_len > 1) { - LOGP(DGPRS, LOGL_ERROR, - "OAP cause may not exceed one octet, is %d", (int)value_len); - return -GMM_CAUSE_PROTO_ERR_UNSPEC; - } - oap_msg->cause = *value; - break; - - default: - LOGP(DGPRS, LOGL_NOTICE, - "OAP IE type %d unknown\n", iei); - continue; - } - } - - return 0; -} - -void osmo_oap_encode(struct msgb *msg, const struct osmo_oap_message *oap_msg) -{ - uint8_t u8; - - /* generic part */ - OSMO_ASSERT(oap_msg->message_type); - msgb_v_put(msg, (uint8_t)oap_msg->message_type); - - /* specific parts */ - if ((u8 = oap_msg->cause)) - msgb_tlv_put(msg, OAP_CAUSE_IE, sizeof(u8), &u8); - - if (oap_msg->client_id > 0) - msgb_tlv_put(msg, OAP_CLIENT_ID_IE, sizeof(oap_msg->client_id), - osmo_encode_big_endian(oap_msg->client_id, - sizeof(oap_msg->client_id))); - - if (oap_msg->rand_present) - msgb_tlv_put(msg, OAP_RAND_IE, sizeof(oap_msg->rand), oap_msg->rand); - - if (oap_msg->autn_present) - msgb_tlv_put(msg, OAP_AUTN_IE, sizeof(oap_msg->autn), oap_msg->autn); - - if (oap_msg->auts_present) - msgb_tlv_put(msg, OAP_AUTS_IE, sizeof(oap_msg->auts), oap_msg->auts); - - if (oap_msg->xres_present) - msgb_tlv_put(msg, OAP_XRES_IE, sizeof(oap_msg->xres), oap_msg->xres); - - msg->l2h = msg->data; -} - diff --git a/openbsc/tests/oap/Makefile.am b/openbsc/tests/oap/Makefile.am index 06ccf3386..bb9ebb247 100644 --- a/openbsc/tests/oap/Makefile.am +++ b/openbsc/tests/oap/Makefile.am @@ -28,7 +28,6 @@ oap_test_SOURCES = \ oap_test_LDADD = \ $(top_builddir)/src/gprs/oap.o \ - $(top_builddir)/src/gprs/oap_messages.o \ $(top_builddir)/src/gprs/gprs_utils.o \ $(top_builddir)/src/libcommon/libcommon.a \ $(LIBOSMOCORE_LIBS) \ diff --git a/openbsc/tests/oap/oap_test.c b/openbsc/tests/oap/oap_test.c index d200ed205..68542fd4d 100644 --- a/openbsc/tests/oap/oap_test.c +++ b/openbsc/tests/oap/oap_test.c @@ -19,11 +19,10 @@ */ #include +#include #include - #include -#include #include #include diff --git a/openbsc/tests/sgsn/Makefile.am b/openbsc/tests/sgsn/Makefile.am index c5d90f6fd..9e1a5a8e3 100644 --- a/openbsc/tests/sgsn/Makefile.am +++ b/openbsc/tests/sgsn/Makefile.am @@ -55,7 +55,6 @@ sgsn_test_LDADD = \ $(top_builddir)/src/gprs/gprs_subscriber.o \ $(top_builddir)/src/gprs/gprs_gb_parse.o \ $(top_builddir)/src/gprs/oap.o \ - $(top_builddir)/src/gprs/oap_messages.o \ $(top_builddir)/src/gprs/gprs_llc_xid.o \ $(top_builddir)/src/gprs/gprs_sndcp_xid.o \ $(top_builddir)/src/gprs/slhc.o \ -- cgit v1.2.3