[PATCH] openbsc[master]: oap: rename public API from oap_ to oap_client_

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Dec 12 16:07:17 UTC 2016


Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1387

to look at the new patch set (#2).

oap: rename public API from oap_ to oap_client_

Mainly to differentiate the OAP messaging API (osmo_oap_ in libosmocore) from
the OAP client.

This is in preparation for moving the oap client to libcommon, which is in turn
preparation for libvlr. Add the osmo_ prefix, as all public Osmocom API should
have. We also have OAP messages code in libosmocore, so clarify by naming this
osmo_oap_client, and by also renaming the oap_test to oap_client_test. This
reshuffling will allow an easy move of OAP to libosmocore if we should want to
do that. A number of patches will follow up on this.

Related: OS#1592
Change-Id: Id447d2bebc026a375567654adafa5f82439ea7e1
---
M openbsc/include/openbsc/gsup_client.h
M openbsc/include/openbsc/oap.h
M openbsc/include/openbsc/sgsn.h
M openbsc/src/gprs/gprs_gsup_client.c
M openbsc/src/gprs/oap.c
M openbsc/tests/oap/oap_test.c
6 files changed, 63 insertions(+), 57 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/87/1387/2

diff --git a/openbsc/include/openbsc/gsup_client.h b/openbsc/include/openbsc/gsup_client.h
index 551f76d..d21a54d 100644
--- a/openbsc/include/openbsc/gsup_client.h
+++ b/openbsc/include/openbsc/gsup_client.h
@@ -41,7 +41,7 @@
 	gsup_client_read_cb_t read_cb;
 	void *data;
 
-	struct oap_state oap_state;
+	struct oap_client_state oap_state;
 
 	struct osmo_timer_list ping_timer;
 	struct osmo_timer_list connect_timer;
@@ -52,7 +52,7 @@
 struct gsup_client *gsup_client_create(const char *ip_addr,
 				       unsigned int tcp_port,
 				       gsup_client_read_cb_t read_cb,
-				       struct oap_config *oap_config);
+				       struct oap_client_config *oap_config);
 
 void gsup_client_destroy(struct gsup_client *gsupc);
 int gsup_client_send(struct gsup_client *gsupc, struct msgb *msg);
diff --git a/openbsc/include/openbsc/oap.h b/openbsc/include/openbsc/oap.h
index 2206184..80c86d5 100644
--- a/openbsc/include/openbsc/oap.h
+++ b/openbsc/include/openbsc/oap.h
@@ -27,9 +27,10 @@
 struct msgb;
 struct osmo_oap_message;
 
-/* This is the config part for vty. It is essentially copied in oap_state,
- * where values are copied over once the config is considered valid. */
-struct oap_config {
+/* This is the config part for vty. It is essentially copied in
+ * oap_client_state, where values are copied over once the config is
+ * considered valid. */
+struct oap_client_config {
 	uint16_t client_id;
 	int secret_k_present;
 	uint8_t secret_k[16];
@@ -38,9 +39,10 @@
 };
 
 /* The runtime state of the OAP client. client_id and the secrets are in fact
- * duplicated from oap_config, so that a separate validation of the config data
- * is possible, and so that only a struct oap_state* is passed around. */
-struct oap_state {
+ * duplicated from oap_client_config, so that a separate validation of the
+ * config data is possible, and so that only a struct oap_client_state* is
+ * passed around. */
+struct oap_client_state {
 	enum {
 		OAP_UNINITIALIZED = 0,	/* just allocated. */
 		OAP_DISABLED,		/* disabled by config. */
@@ -56,23 +58,25 @@
 };
 
 /* From config, initialize state. Return 0 on success. */
-int oap_init(struct oap_config *config, struct oap_state *state);
+int oap_client_init(struct oap_client_config *config,
+		    struct oap_client_state *state);
 
 /* Construct an OAP registration message and return in *msg_tx. Use
  * state->client_id and update state->state.
  * Return 0 on success, or a negative value on error.
  * If an error is returned, *msg_tx is guaranteed to be NULL. */
-int oap_register(struct oap_state *state, struct msgb **msg_tx);
+int oap_client_register(struct oap_client_state *state, struct msgb **msg_tx);
 
 /* Decode and act on a received OAP message msg_rx. Update state->state.  If a
  * non-NULL pointer is returned in *msg_tx, that msgb should be sent to the OAP
  * server (and freed) by the caller. The received msg_rx is not freed.
  * Return 0 on success, or a negative value on error.
  * If an error is returned, *msg_tx is guaranteed to be NULL. */
-int oap_handle(struct oap_state *state, const struct msgb *msg_rx, struct msgb **msg_tx);
+int oap_client_handle(struct oap_client_state *state,
+		      const struct msgb *msg_rx, struct msgb **msg_tx);
 
-/* Allocate a msgb and in it, return the encoded oap_msg. Return NULL on
- * error. (Like oap_encode(), but also allocates a msgb.)
- * About the name: the idea is do_something(oap_encoded(my_struct)) */
-struct msgb *oap_encoded(const struct osmo_oap_message *oap_msg);
-
+/* Allocate a msgb and in it, return the encoded oap_client_msg. Return
+ * NULL on error. (Like oap_client_encode(), but also allocates a msgb.)
+ * About the name: the idea is do_something(oap_client_encoded(my_struct))
+ */
+struct msgb *oap_client_encoded(const struct osmo_oap_message *oap_client_msg);
diff --git a/openbsc/include/openbsc/sgsn.h b/openbsc/include/openbsc/sgsn.h
index 0045fae..c8dcc0d 100644
--- a/openbsc/include/openbsc/sgsn.h
+++ b/openbsc/include/openbsc/sgsn.h
@@ -92,7 +92,7 @@
 
 	int dynamic_lookup;
 
-	struct oap_config oap;
+	struct oap_client_config oap;
 
 	/* RFC1144 TCP/IP header compression */
 	struct {
diff --git a/openbsc/src/gprs/gprs_gsup_client.c b/openbsc/src/gprs/gprs_gsup_client.c
index b991563..0360e0a 100644
--- a/openbsc/src/gprs/gprs_gsup_client.c
+++ b/openbsc/src/gprs/gprs_gsup_client.c
@@ -116,7 +116,7 @@
 {
 	struct msgb *msg_tx;
 	int rc;
-	rc = oap_register(&gsupc->oap_state, &msg_tx);
+	rc = oap_client_register(&gsupc->oap_state, &msg_tx);
 
 	if ((rc < 0) || (!msg_tx)) {
 		LOGP(DLGSUP, LOGL_ERROR, "GSUP OAP set up, but cannot register.\n");
@@ -155,7 +155,7 @@
 	int rc;
 	struct msgb *msg_tx;
 
-	rc = oap_handle(&gsupc->oap_state, msg_rx, &msg_tx);
+	rc = oap_client_handle(&gsupc->oap_state, msg_rx, &msg_tx);
 	msgb_free(msg_rx);
 	if (rc < 0)
 		return rc;
@@ -265,7 +265,7 @@
 struct gsup_client *gsup_client_create(const char *ip_addr,
 				       unsigned int tcp_port,
 				       gsup_client_read_cb_t read_cb,
-				       struct oap_config *oap_config)
+				       struct oap_client_config *oap_config)
 {
 	struct gsup_client *gsupc;
 	int rc;
@@ -273,7 +273,7 @@
 	gsupc = talloc_zero(tall_bsc_ctx, struct gsup_client);
 	OSMO_ASSERT(gsupc);
 
-	rc = oap_init(oap_config, &gsupc->oap_state);
+	rc = oap_client_init(oap_config, &gsupc->oap_state);
 	if (rc != 0)
 		goto failed;
 
diff --git a/openbsc/src/gprs/oap.c b/openbsc/src/gprs/oap.c
index 7efbe81..ac2b2a4 100644
--- a/openbsc/src/gprs/oap.c
+++ b/openbsc/src/gprs/oap.c
@@ -29,7 +29,8 @@
 #include <openbsc/oap.h>
 #include <openbsc/debug.h>
 
-int oap_init(struct oap_config *config, struct oap_state *state)
+int oap_client_init(struct oap_client_config *config,
+		    struct oap_client_state *state)
 {
 	OSMO_ASSERT(state->state == OAP_UNINITIALIZED);
 
@@ -66,7 +67,7 @@
  * response message and update the state.
  * Return 0 on success; -1 if OAP is disabled; -2 if rx_random and rx_autn fail
  * the authentication check; -3 for any other errors. */
-static int oap_evaluate_challenge(const struct oap_state *state,
+static int oap_evaluate_challenge(const struct oap_client_state *state,
 				  const uint8_t *rx_random,
 				  const uint8_t *rx_autn,
 				  uint8_t *tx_xres)
@@ -119,7 +120,7 @@
 	return 0;
 }
 
-struct msgb *oap_encoded(const struct osmo_oap_message *oap_msg)
+struct msgb *oap_client_encoded(const struct osmo_oap_message *oap_msg)
 {
 	struct msgb *msg = msgb_alloc_headroom(1000, 64, __func__);
 	OSMO_ASSERT(msg);
@@ -140,10 +141,10 @@
 
 	oap_msg.message_type = OAP_MSGT_REGISTER_REQUEST;
 	oap_msg.client_id = client_id;
-	return oap_encoded(&oap_msg);
+	return oap_client_encoded(&oap_msg);
 }
 
-int oap_register(struct oap_state *state, struct msgb **msg_tx)
+int oap_client_register(struct oap_client_state *state, struct msgb **msg_tx)
 {
 	*msg_tx = oap_msg_register(state->client_id);
 	if (!(*msg_tx))
@@ -163,10 +164,10 @@
 	oap_reply.message_type = OAP_MSGT_CHALLENGE_RESULT;
 	memcpy(oap_reply.xres, xres, sizeof(oap_reply.xres));
 	oap_reply.xres_present = 1;
-	return oap_encoded(&oap_reply);
+	return oap_client_encoded(&oap_reply);
 }
 
-static int handle_challenge(struct oap_state *state,
+static int handle_challenge(struct oap_client_state *state,
 			    struct osmo_oap_message *oap_rx,
 			    struct msgb **msg_tx)
 {
@@ -203,7 +204,8 @@
 	return rc;
 }
 
-int oap_handle(struct oap_state *state, const struct msgb *msg_rx, struct msgb **msg_tx)
+int oap_client_handle(struct oap_client_state *state,
+		      const struct msgb *msg_rx, struct msgb **msg_tx)
 {
 	uint8_t *data = msgb_l2(msg_rx);
 	size_t data_len = msgb_l2len(msg_rx);
@@ -237,7 +239,7 @@
 		state->state = OAP_INITIALIZED;
 		if (state->registration_failures < 3) {
 			state->registration_failures ++;
-			return oap_register(state, msg_tx);
+			return oap_client_register(state, msg_tx);
 		}
 		return -11;
 
diff --git a/openbsc/tests/oap/oap_test.c b/openbsc/tests/oap/oap_test.c
index 68542fd..a6f54f6 100644
--- a/openbsc/tests/oap/oap_test.c
+++ b/openbsc/tests/oap/oap_test.c
@@ -31,11 +31,11 @@
 {
 	printf("Testing OAP API\n  - Config parsing\n");
 
-	struct oap_config _config;
-	struct oap_config *config = &_config;
+	struct oap_client_config _config;
+	struct oap_client_config *config = &_config;
 
-	struct oap_state _state;
-	struct oap_state *state = &_state;
+	struct oap_client_state _state;
+	struct oap_client_state *state = &_state;
 
 	memset(config, 0, sizeof(*config));
 	memset(state, 0, sizeof(*state));
@@ -50,7 +50,7 @@
 	config->client_id = 0;
 	config->secret_k_present = 0;
 	config->secret_opc_present = 0;
-	OSMO_ASSERT( oap_init(config, state) == 0 );
+	OSMO_ASSERT( oap_client_init(config, state) == 0 );
 	OSMO_ASSERT(state->state == OAP_DISABLED);
 
 	/* reset state */
@@ -60,7 +60,7 @@
 	config->client_id = 0;
 	config->secret_k_present = 1;
 	config->secret_opc_present = 1;
-	OSMO_ASSERT( oap_init(config, state) == 0 );
+	OSMO_ASSERT( oap_client_init(config, state) == 0 );
 	OSMO_ASSERT(state->state == OAP_DISABLED);
 
 	memset(state, 0, sizeof(*state));
@@ -69,7 +69,7 @@
 	config->client_id = 12345;
 	config->secret_k_present = 0;
 	config->secret_opc_present = 1;
-	OSMO_ASSERT( oap_init(config, state) == 0 );
+	OSMO_ASSERT( oap_client_init(config, state) == 0 );
 	OSMO_ASSERT(state->state == OAP_DISABLED);
 
 	memset(state, 0, sizeof(*state));
@@ -78,7 +78,7 @@
 	config->client_id = 12345;
 	config->secret_k_present = 1;
 	config->secret_opc_present = 0;
-	OSMO_ASSERT( oap_init(config, state) == 0 );
+	OSMO_ASSERT( oap_client_init(config, state) == 0 );
 	OSMO_ASSERT(state->state == OAP_DISABLED);
 
 	memset(state, 0, sizeof(*state));
@@ -89,7 +89,7 @@
 	config->secret_k_present = 1;
 	config->secret_opc_present = 1;
 	/*config->secret_* buffers are still set from the top */
-	OSMO_ASSERT( oap_init(config, state) == 0 );
+	OSMO_ASSERT( oap_client_init(config, state) == 0 );
 	OSMO_ASSERT(state->state == OAP_INITIALIZED);
 
 	printf("  - AUTN failures\n");
@@ -105,8 +105,8 @@
 	oap_rx.message_type = OAP_MSGT_CHALLENGE_REQUEST;
 	oap_rx.rand_present = 0;
 	oap_rx.autn_present = 0;
-	msg_rx = oap_encoded(&oap_rx);
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == -2);
+	msg_rx = oap_client_encoded(&oap_rx);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -2);
 	msgb_free(msg_rx);
 	OSMO_ASSERT(!msg_tx);
 
@@ -114,8 +114,8 @@
 	osmo_hexparse("0102030405060708090a0b0c0d0e0f10",
 		      oap_rx.rand, 16);
 	oap_rx.rand_present = 1;
-	msg_rx = oap_encoded(&oap_rx);
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == -2);
+	msg_rx = oap_client_encoded(&oap_rx);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -2);
 	msgb_free(msg_rx);
 	OSMO_ASSERT(!msg_tx);
 
@@ -124,8 +124,8 @@
 	osmo_hexparse("cec4e3848a33000086781158ca40f136",
 		      oap_rx.autn, 16);
 	oap_rx.autn_present = 1;
-	msg_rx = oap_encoded(&oap_rx);
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == -2);
+	msg_rx = oap_client_encoded(&oap_rx);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -2);
 	msgb_free(msg_rx);
 	OSMO_ASSERT(!msg_tx);
 
@@ -136,25 +136,25 @@
 		      oap_rx.autn, 16);
 	oap_rx.rand_present = 1;
 	oap_rx.autn_present = 1;
-	msg_rx = oap_encoded(&oap_rx);
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == -2);
+	msg_rx = oap_client_encoded(&oap_rx);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -2);
 	msgb_free(msg_rx);
 	OSMO_ASSERT(!msg_tx);
 
 	/* all data correct */
 	osmo_hexparse("cec4e3848a33000086781158ca40f136",
 		      oap_rx.autn, 16);
-	msg_rx = oap_encoded(&oap_rx);
+	msg_rx = oap_client_encoded(&oap_rx);
 
 	/* but refuse to evaluate in uninitialized state */
 	OSMO_ASSERT(state->state == OAP_INITIALIZED);
 
 	state->state = OAP_UNINITIALIZED;
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == -1);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -1);
 	OSMO_ASSERT(!msg_tx);
 
 	state->state = OAP_DISABLED;
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == -1);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -1);
 	OSMO_ASSERT(!msg_tx);
 
 	state->state = OAP_INITIALIZED;
@@ -162,7 +162,7 @@
 	/* now everything is correct */
 	printf("  - AUTN success\n");
 	/* a successful return value here indicates correct autn */
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == 0);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == 0);
 	msgb_free(msg_rx);
 
 	/* Expect the challenge response in msg_tx */
@@ -176,18 +176,18 @@
 	msgb_free(msg_tx);
 	msg_tx = 0;
 
-	struct oap_state saved_state = _state;
+	struct oap_client_state saved_state = _state;
 
 	printf("  - Registration failure\n");
 
 	memset(&oap_rx, 0, sizeof(oap_rx));
 	oap_rx.message_type = OAP_MSGT_REGISTER_ERROR;
 	oap_rx.cause = GMM_CAUSE_PROTO_ERR_UNSPEC;
-	msg_rx = oap_encoded(&oap_rx);
+	msg_rx = oap_client_encoded(&oap_rx);
 
 	/* Receive registration error for the first time. */
 	OSMO_ASSERT(state->registration_failures == 0);
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == 0);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == 0);
 	OSMO_ASSERT(state->registration_failures == 1);
 	OSMO_ASSERT(msg_tx);
 	OSMO_ASSERT(osmo_oap_decode(&oap_tx, msg_tx->data, msg_tx->len) == 0);
@@ -198,7 +198,7 @@
 
 	/* Receive registration error for the Nth time. */
 	state->registration_failures = 999;
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == -11);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == -11);
 	OSMO_ASSERT(!msg_tx);
 	OSMO_ASSERT(state->state == OAP_INITIALIZED);
 	msgb_free(msg_tx);
@@ -211,8 +211,8 @@
 	_state = saved_state;
 	memset(&oap_rx, 0, sizeof(oap_rx));
 	oap_rx.message_type = OAP_MSGT_REGISTER_RESULT;
-	msg_rx = oap_encoded(&oap_rx);
-	OSMO_ASSERT(oap_handle(state, msg_rx, &msg_tx) == 0);
+	msg_rx = oap_client_encoded(&oap_rx);
+	OSMO_ASSERT(oap_client_handle(state, msg_rx, &msg_tx) == 0);
 	OSMO_ASSERT(!msg_tx);
 	OSMO_ASSERT(state->state == OAP_REGISTERED);
 	msgb_free(msg_rx);

-- 
To view, visit https://gerrit.osmocom.org/1387
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Id447d2bebc026a375567654adafa5f82439ea7e1
Gerrit-PatchSet: 2
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list