From 50f1c0af567423b6ade9a84aaa5197ecf6237819 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 25 Apr 2016 19:01:26 +0200 Subject: move utils.h functions to libosmocore This needs the corresponding commit in libosmocore which imports the related functions --- openbsc/src/gprs/oap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsc/src/gprs/oap.c') diff --git a/openbsc/src/gprs/oap.c b/openbsc/src/gprs/oap.c index 1426702dd..f5d7a9570 100644 --- a/openbsc/src/gprs/oap.c +++ b/openbsc/src/gprs/oap.c @@ -20,10 +20,10 @@ * */ +#include #include #include -#include #include #include @@ -103,7 +103,7 @@ static int oap_evaluate_challenge(const struct oap_state *state, return -3; } - if (constant_time_cmp(vec.autn, rx_autn, sizeof(vec.autn)) != 0) { + if (osmo_constant_time_cmp(vec.autn, rx_autn, sizeof(vec.autn)) != 0) { LOGP(DGPRS, LOGL_ERROR, "OAP: AUTN mismatch!\n"); LOGP(DGPRS, LOGL_INFO, "OAP: AUTN from server: %s\n", osmo_hexdump_nospc(rx_autn, sizeof(vec.autn))); -- cgit v1.2.3 From 31760a1f6089fb59475ba79faa3eb97e4cf00f68 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 27 Apr 2016 15:17:14 +0200 Subject: oap_message.h: Remove dependency to openbsc include This is a first step to moving oap_messages.h to libosmocore --- openbsc/src/gprs/oap.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'openbsc/src/gprs/oap.c') diff --git a/openbsc/src/gprs/oap.c b/openbsc/src/gprs/oap.c index f5d7a9570..eb0dd19d1 100644 --- a/openbsc/src/gprs/oap.c +++ b/openbsc/src/gprs/oap.c @@ -20,6 +20,8 @@ * */ +#include + #include #include -- cgit v1.2.3 From 564c06525b9acb3f4b90d4c92970e7d9cc5b1d8e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 27 Apr 2016 18:14:14 +0200 Subject: OAP: use osmo_oap_ prefix for OAP, rather than plain oap_ this is in preparation of moving related code to libosmocore. --- openbsc/src/gprs/oap.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'openbsc/src/gprs/oap.c') diff --git a/openbsc/src/gprs/oap.c b/openbsc/src/gprs/oap.c index eb0dd19d1..0b8f48260 100644 --- a/openbsc/src/gprs/oap.c +++ b/openbsc/src/gprs/oap.c @@ -119,11 +119,11 @@ static int oap_evaluate_challenge(const struct oap_state *state, return 0; } -struct msgb *oap_encoded(const struct oap_message *oap_msg) +struct msgb *oap_encoded(const struct osmo_oap_message *oap_msg) { struct msgb *msg = msgb_alloc_headroom(1000, 64, __func__); OSMO_ASSERT(msg); - oap_encode(msg, oap_msg); + osmo_oap_encode(msg, oap_msg); return msg; } @@ -136,7 +136,7 @@ static struct msgb* oap_msg_register(uint16_t client_id) return NULL; } - struct oap_message oap_msg = {0}; + struct osmo_oap_message oap_msg = {0}; oap_msg.message_type = OAP_MSGT_REGISTER_REQUEST; oap_msg.client_id = client_id; return oap_encoded(&oap_msg); @@ -157,7 +157,7 @@ int oap_register(struct oap_state *state, struct msgb **msg_tx) * On error, return NULL. */ static struct msgb* oap_msg_challenge_response(uint8_t *xres) { - struct oap_message oap_reply = {0}; + struct osmo_oap_message oap_reply = {0}; oap_reply.message_type = OAP_MSGT_CHALLENGE_RESULT; memcpy(oap_reply.xres, xres, sizeof(oap_reply.xres)); @@ -166,7 +166,7 @@ static struct msgb* oap_msg_challenge_response(uint8_t *xres) } static int handle_challenge(struct oap_state *state, - struct oap_message *oap_rx, + struct osmo_oap_message *oap_rx, struct msgb **msg_tx) { int rc; @@ -209,11 +209,11 @@ int oap_handle(struct oap_state *state, const struct msgb *msg_rx, struct msgb * size_t data_len = msgb_l2len(msg_rx); int rc = 0; - struct oap_message oap_msg = {0}; + struct osmo_oap_message oap_msg = {0}; OSMO_ASSERT(data); - rc = oap_decode(data, data_len, &oap_msg); + rc = osmo_oap_decode(data, data_len, &oap_msg); if (rc < 0) { LOGP(DGPRS, LOGL_ERROR, "Decoding OAP message failed with error '%s' (%d)\n", -- cgit v1.2.3 From d8aa412c46638abea05488ebb2e9d70ca7fd628a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 27 Apr 2016 18:17:26 +0200 Subject: OAP: Various coding style fixes * we always declare stack variables at the top of the function / block * 'switch' is not a function, so there's space ahead of the opening ( --- openbsc/src/gprs/oap.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'openbsc/src/gprs/oap.c') diff --git a/openbsc/src/gprs/oap.c b/openbsc/src/gprs/oap.c index 0b8f48260..a9fee566b 100644 --- a/openbsc/src/gprs/oap.c +++ b/openbsc/src/gprs/oap.c @@ -71,12 +71,19 @@ static int oap_evaluate_challenge(const struct oap_state *state, const uint8_t *rx_autn, uint8_t *tx_xres) { + struct osmo_auth_vector vec; + + struct osmo_sub_auth_data auth = { + .type = OSMO_AUTH_TYPE_UMTS, + .algo = OSMO_AUTH_ALG_MILENAGE, + }; + osmo_static_assert(sizeof(((struct osmo_sub_auth_data*)0)->u.umts.k) == sizeof(state->secret_k), _secret_k_size_match); osmo_static_assert(sizeof(((struct osmo_sub_auth_data*)0)->u.umts.opc) == sizeof(state->secret_opc), _secret_opc_size_match); - switch(state->state) { + switch (state->state) { case OAP_UNINITIALIZED: case OAP_DISABLED: return -1; @@ -84,13 +91,6 @@ static int oap_evaluate_challenge(const struct oap_state *state, break; } - struct osmo_auth_vector vec; - - struct osmo_sub_auth_data auth = { - .type = OSMO_AUTH_TYPE_UMTS, - .algo = OSMO_AUTH_ALG_MILENAGE, - }; - memcpy(auth.u.umts.k, state->secret_k, sizeof(auth.u.umts.k)); memcpy(auth.u.umts.opc, state->secret_opc, sizeof(auth.u.umts.opc)); memset(auth.u.umts.amf, '\0', sizeof(auth.u.umts.amf)); @@ -131,12 +131,13 @@ struct msgb *oap_encoded(const struct osmo_oap_message *oap_msg) * On error, return NULL. */ static struct msgb* oap_msg_register(uint16_t client_id) { + struct osmo_oap_message oap_msg = {0}; + if (client_id < 1) { LOGP(DGPRS, LOGL_ERROR, "OAP: Invalid client ID: %d\n", client_id); return NULL; } - struct osmo_oap_message oap_msg = {0}; oap_msg.message_type = OAP_MSGT_REGISTER_REQUEST; oap_msg.client_id = client_id; return oap_encoded(&oap_msg); @@ -170,6 +171,8 @@ static int handle_challenge(struct oap_state *state, struct msgb **msg_tx) { int rc; + uint8_t xres[8]; + if (!(oap_rx->rand_present && oap_rx->autn_present)) { LOGP(DGPRS, LOGL_ERROR, "OAP challenge incomplete (rand_present: %d, autn_present: %d)\n", @@ -178,7 +181,6 @@ static int handle_challenge(struct oap_state *state, goto failure; } - uint8_t xres[8]; rc = oap_evaluate_challenge(state, oap_rx->rand, oap_rx->autn, @@ -203,13 +205,12 @@ failure: int oap_handle(struct oap_state *state, const struct msgb *msg_rx, struct msgb **msg_tx) { - *msg_tx = NULL; - uint8_t *data = msgb_l2(msg_rx); size_t data_len = msgb_l2len(msg_rx); + struct osmo_oap_message oap_msg = {0}; int rc = 0; - struct osmo_oap_message oap_msg = {0}; + *msg_tx = NULL; OSMO_ASSERT(data); -- cgit v1.2.3 From 5d547a4358edbd18744d1996d6ecb40328f09061 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 27 Apr 2016 18:21:16 +0200 Subject: osmo_oap_decode(): Use common argument ordering In general, if a function generates output data like a msgb (or in this case filling an osmo_oap_message structure), the output argument precedes the source. This is what we use all over libosmo*, and it is modelled after memcpy(), where dst is the first argument, before src. Let's align osmo_oap_decode(). Intestingly, osmo_oap_encode was already correct, so the encode/decode functions used different conventions before. --- openbsc/src/gprs/oap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsc/src/gprs/oap.c') diff --git a/openbsc/src/gprs/oap.c b/openbsc/src/gprs/oap.c index a9fee566b..c7c97774d 100644 --- a/openbsc/src/gprs/oap.c +++ b/openbsc/src/gprs/oap.c @@ -214,7 +214,7 @@ int oap_handle(struct oap_state *state, const struct msgb *msg_rx, struct msgb * OSMO_ASSERT(data); - rc = osmo_oap_decode(data, data_len, &oap_msg); + rc = osmo_oap_decode(&oap_msg, data, data_len); if (rc < 0) { LOGP(DGPRS, LOGL_ERROR, "Decoding OAP message failed with error '%s' (%d)\n", -- cgit v1.2.3