From patchwork Wed Mar 16 15:14:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Yanitskiy X-Patchwork-Id: 598481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 3qQFQL6JP5z9ssM for ; Thu, 17 Mar 2016 02:14:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=PgWSsHNs; dkim-atps=neutral Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 6F2D61B62E; Wed, 16 Mar 2016 15:14:33 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail-lb0-x233.google.com (mail-lb0-x233.google.com [IPv6:2a00:1450:4010:c04::233]) by lists.osmocom.org (Postfix) with ESMTP id 0C5091B61E for ; Wed, 16 Mar 2016 15:14:30 +0000 (UTC) Received: by mail-lb0-x233.google.com with SMTP id bc4so50075297lbc.2 for ; Wed, 16 Mar 2016 08:14:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mXSEIFzLDbfQkP6T0mhoOd/x2ZwzOORtsxLN+YEXepU=; b=PgWSsHNsVtqsPgYxkWpRsz41UTZw0A90meCI6N1uEGRuVRO1MVUa4iO02MbV9EctAj pBFx+swhvuDQIVJo3p5A+kUw2FC7WIcbsmNEACaJtMau+IM8mXbnRkzZaECRHTL346R2 j1f4EFXm7RUjjQfN6Y/uFlSw250CADQ0hHKThhqC3OPBiqsCvDmOXBvTCBdDiFVWPQzN YZ5DgmIERuEG79N0zZkQI8JyJoJKxe3avuSEkS91oib7whN6JHc9ShhYxGfTHkBUlaNB seTzIjHV1aHFOM6acNHQDLu+UBSG+WI+U7NdOXSCmE0Tebq7cf62T9ikLAHXyzm7KWeH 5ouQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mXSEIFzLDbfQkP6T0mhoOd/x2ZwzOORtsxLN+YEXepU=; b=T5ZANsgkAvv6Wl8XtI5z1ptLJJqHYXxl/NkfxRpp1e0C3GT4uvSZX0ePN/2oYLVFmh AzeWLSbyP0SoC/q9YIft6EGgSm08o1N+4iNgUomlcz+PjsBaGN6E9vBlWFgOq3BKEzou oFEkcHyC41vuO0gSbgq0Awxgmq+I1sRcUjQOPUhWX5nYElm4FE0OTg/JJNbuLlzsb2dU BpEnzJAIFvTKmWI/Vytspnfmoa5DTUyiBwn2nLycgNqP+StraNmht+VbfJfij6Q81Rjw g9z5lfUn68dU3wwO5TgBlNN2CSYeEzkuCjmOTVLzw5sqLXSob6HLAmcL9kY1V94sA6Ou Hesg== X-Gm-Message-State: AD7BkJLqV+mhgwP3BvBBR4t8sXLgUxeotti4WUD7J3ccgxtiZkIV6+o59qSvfisrReRbTw== X-Received: by 10.112.137.228 with SMTP id ql4mr1651716lbb.49.1458141270701; Wed, 16 Mar 2016 08:14:30 -0700 (PDT) Received: from DELL.lan ([212.164.216.34]) by smtp.gmail.com with ESMTPSA id un6sm607626lbb.18.2016.03.16.08.14.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Mar 2016 08:14:30 -0700 (PDT) From: axilirator@gmail.com To: openbsc@lists.osmocom.org Subject: [PATCH] move to hex TMSI representation Date: Wed, 16 Mar 2016 21:14:03 +0600 Message-Id: <1458141243-8236-1-git-send-email-axilirator@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <20160316102231.GK15482@nataraja> References: <20160316102231.GK15482@nataraja> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vadim Yanitskiy Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" From: Vadim Yanitskiy Signed-off-by: Vadim Yanitskiy --- openbsc/include/openbsc/gsm_subscriber.h | 2 +- openbsc/src/libmsc/db.c | 15 ++++++++------- openbsc/tests/db/db_test.c | 4 ++-- openbsc/tests/gsm0408/gsm0408_test.c | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/openbsc/include/openbsc/gsm_subscriber.h b/openbsc/include/openbsc/gsm_subscriber.h index 7d6c776..785dc36 100644 --- a/openbsc/include/openbsc/gsm_subscriber.h +++ b/openbsc/include/openbsc/gsm_subscriber.h @@ -14,7 +14,7 @@ #define GSM_SUBSCRIBER_FIRST_CONTACT 0x00000001 /* gprs_sgsn.h defines additional flags including and above bit 16 (0x10000) */ -#define tmsi_from_string(str) strtoul(str, NULL, 10) +#define tmsi_from_string(str) strtoul(str + 2, NULL, 16) #define GSM_SUBSCRIBER_NO_EXPIRATION 0x0 diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c index 0935fc5..952151e 100644 --- a/openbsc/src/libmsc/db.c +++ b/openbsc/src/libmsc/db.c @@ -893,9 +893,10 @@ struct gsm_subscriber *db_get_subscriber(enum gsm_subscriber_field field, subscr->id = dbi_result_get_ulonglong(result, "id"); db_set_from_query(subscr, result); - DEBUGP(DDB, "Found Subscriber: ID %llu, IMSI %s, NAME '%s', TMSI %u, EXTEN '%s', LAC %hu, AUTH %u\n", - subscr->id, subscr->imsi, subscr->name, subscr->tmsi, subscr->extension, - subscr->lac, subscr->authorized); + DEBUGP(DDB, "Found Subscriber: ID %llu, IMSI %s, NAME '%s', " + "TMSI 0x%08x, EXTEN '%s', LAC %hu, AUTH %u\n", + subscr->id, subscr->imsi, subscr->name, subscr->tmsi, + subscr->extension, subscr->lac, subscr->authorized); dbi_result_free(result); get_equipment_by_subscr(subscr); @@ -935,7 +936,7 @@ int db_subscriber_update(struct gsm_subscriber *subscr) int db_sync_subscriber(struct gsm_subscriber *subscriber) { dbi_result result; - char tmsi[14]; + char tmsi[11]; char *q_tmsi, *q_name, *q_extension; dbi_conn_quote_string_copy(conn, @@ -944,7 +945,7 @@ int db_sync_subscriber(struct gsm_subscriber *subscriber) subscriber->extension, &q_extension); if (subscriber->tmsi != GSM_RESERVED_TMSI) { - sprintf(tmsi, "%u", subscriber->tmsi); + sprintf(tmsi, "0x%08x", subscriber->tmsi); dbi_conn_quote_string_copy(conn, tmsi, &q_tmsi); @@ -1194,7 +1195,7 @@ int db_subscriber_expire(void *priv, void (*callback)(void *priv, long long unsi int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber) { dbi_result result = NULL; - char tmsi[14]; + char tmsi[11]; char *tmsi_quoted; for (;;) { @@ -1205,7 +1206,7 @@ int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber) if (subscriber->tmsi == GSM_RESERVED_TMSI) continue; - sprintf(tmsi, "%u", subscriber->tmsi); + sprintf(tmsi, "0x%08x", subscriber->tmsi); dbi_conn_quote_string_copy(conn, tmsi, &tmsi_quoted); result = dbi_conn_queryf(conn, "SELECT * FROM Subscriber " diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c index a02d1f8..faea820 100644 --- a/openbsc/tests/db/db_test.c +++ b/openbsc/tests/db/db_test.c @@ -200,7 +200,7 @@ int main() alice->lac=42; db_sync_subscriber(alice); /* Get by TMSI */ - snprintf(scratch_str, sizeof(scratch_str), "%"PRIu32, alice->tmsi); + snprintf(scratch_str, sizeof(scratch_str), "0x%08x", alice->tmsi); alice_db = db_get_subscriber(GSM_SUBSCRIBER_TMSI, scratch_str); COMPARE(alice, alice_db); SUBSCR_PUT(alice_db); @@ -227,7 +227,7 @@ int main() db_subscriber_assoc_imei(alice, "1234567890"); db_subscriber_assoc_imei(alice, "6543560920"); /* Get by TMSI */ - snprintf(scratch_str, sizeof(scratch_str), "%"PRIu32, alice->tmsi); + snprintf(scratch_str, sizeof(scratch_str), "0x%08x", alice->tmsi); alice_db = db_get_subscriber(GSM_SUBSCRIBER_TMSI, scratch_str); COMPARE(alice, alice_db); SUBSCR_PUT(alice_db); diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c index 781ef61..8ed57ca 100644 --- a/openbsc/tests/gsm0408/gsm0408_test.c +++ b/openbsc/tests/gsm0408/gsm0408_test.c @@ -93,7 +93,7 @@ static void test_mi_functionality(void) /* tmsi code */ mi_len = gsm48_generate_mid_from_tmsi(mi, tmsi); gsm48_mi_to_string(mi_parsed, sizeof(mi_parsed), mi + 2, mi_len - 2); - COMPARE((uint32_t)strtoul(mi_parsed, NULL, 10), ==, tmsi); + COMPARE((uint32_t)tmsi_from_string(mi_parsed), ==, tmsi); /* imsi code */ mi_len = gsm48_generate_mid_from_imsi(mi, imsi_odd);