From 026531ec924f954cfb2dc9df1082e60f861a2d11 Mon Sep 17 00:00:00 2001 From: "Harald Welte (local)" Date: Sun, 16 Aug 2009 10:40:10 +0200 Subject: [PATCH] store all APDU's received from the MS in the database This helps us to analyze data such as RRLP location information for later analysis. --- openbsc/include/openbsc/db.h | 5 +++++ openbsc/src/db.c | 31 +++++++++++++++++++++++++++++++ openbsc/src/gsm_04_08.c | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/openbsc/include/openbsc/db.h b/openbsc/include/openbsc/db.h index 67436dfb3..07135937b 100644 --- a/openbsc/include/openbsc/db.h +++ b/openbsc/include/openbsc/db.h @@ -48,4 +48,9 @@ int db_sms_store(struct gsm_sms *sms); struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, int min_id); struct gsm_sms *db_sms_get_unsent_for_subscr(struct gsm_subscriber *subscr); int db_sms_mark_sent(struct gsm_sms *sms); + +/* APDU blob storage */ +int db_apdu_blob_store(struct gsm_subscriber *subscr, + u_int8_t apdu_id_flags, u_int8_t len, + u_int8_t *apdu); #endif /* _DB_H */ diff --git a/openbsc/src/db.c b/openbsc/src/db.c index d5e924db7..16a7f6ad7 100644 --- a/openbsc/src/db.c +++ b/openbsc/src/db.c @@ -109,6 +109,13 @@ static char *create_stmts[] = { "subscriber_id NUMERIC UNIQUE NOT NULL, " "last_bts NUMERIC NOT NULL " ")", + "CREATE TABLE IF NOT EXISTS ApduBlobs (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "created TIMESTAMP NOT NULL, " + "apdu_id_flags INTEGER NOT NULL, " + "subscriber_id INTEGER NOT NULL, " + "apdu BLOB " + ")", }; void db_error_func(dbi_conn conn, void* data) { @@ -771,3 +778,27 @@ int db_sms_inc_deliver_attempts(struct gsm_sms *sms) dbi_result_free(result); return 0; } + +int db_apdu_blob_store(struct gsm_subscriber *subscr, + u_int8_t apdu_id_flags, u_int8_t len, + u_int8_t *apdu) +{ + dbi_result result; + char *q_apdu; + + dbi_conn_quote_binary_copy(conn, apdu, len, &q_apdu); + + result = dbi_conn_queryf(conn, + "INSERT INTO ApduBlobs " + "(created,subscriber_id,apdu_id_flags,apdu) VALUES " + "(datetime('now'),%llu,%u,%s)", + subscr->id, apdu_id_flags, q_apdu); + + free(q_apdu); + + if (!result) + return -EIO; + + dbi_result_free(result); + return 0; +} diff --git a/openbsc/src/gsm_04_08.c b/openbsc/src/gsm_04_08.c index 9d9cde70d..b64d2536a 100644 --- a/openbsc/src/gsm_04_08.c +++ b/openbsc/src/gsm_04_08.c @@ -1839,7 +1839,7 @@ static int gsm48_rx_rr_app_info(struct msgb *msg) DEBUGP(DNM, "RX APPLICATION INFO id/flags=0x%02x apdu_len=%u apdu=%s", apdu_id_flags, apdu_len, hexdump(apdu_data, apdu_len)); - return 0; + return db_apdu_blob_store(msg->lchan->subscr, apdu_id_flags, apdu_len, apdu_data); }