summaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2009-07-05 14:08:13 +0200
committerHarald Welte <laforge@gnumonks.org>2009-07-05 14:08:13 +0200
commitc2e302dc84490691b17fcfa6246e40eaf9a0ab32 (patch)
tree6d455dd1de967a12940df7ce120425d3f1128fe7 /openbsc/src
parent53833f6fd8f3cc24480dd48570a2524a41ccf555 (diff)
Store classmark1/2/3 in equipment SQL table
For further evaluation/analysis, this patch stores the classmark 1, 2 and 3 values of every equipment in the SQL database. We can use this non-volatile data to determine the supported features for each handset that we've ever seen on our network.
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/db.c38
-rw-r--r--openbsc/src/gsm_04_08.c21
2 files changed, 49 insertions, 10 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 600699ae7..543f44ce2 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -1,6 +1,7 @@
/* Simple HLR/VLR database backend using dbi */
/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2009 by Harald Welte <laforge@gnumonks.org>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
@@ -59,6 +60,9 @@ static char *create_stmts[] = {
"created TIMESTAMP NOT NULL, "
"updated TIMESTAMP NOT NULL, "
"name TEXT, "
+ "classmark1 NUMERIC, "
+ "classmark2 BLOB, "
+ "classmark3 BLOB, "
"imei NUMERIC UNIQUE NOT NULL"
")",
"CREATE TABLE IF NOT EXISTS EquipmentWatch ("
@@ -288,6 +292,37 @@ int db_sync_subscriber(struct gsm_subscriber* subscriber) {
return 0;
}
+int db_sync_equipment(struct gsm_equipment *equip)
+{
+ dbi_result result;
+ unsigned char *cm2, *cm3;
+
+ dbi_conn_quote_binary_copy(conn, equip->classmark2,
+ equip->classmark2_len, &cm2);
+ dbi_conn_quote_binary_copy(conn, equip->classmark3,
+ equip->classmark3_len, &cm3);
+
+ result = dbi_conn_queryf(conn,
+ "UPDATE Equipment SET "
+ "updated = datetime('now'), "
+ "classmark1 = %u, "
+ "classmark2 = %s, "
+ "classmark3 = %s "
+ "WHERE imei = '%s' ",
+ equip->classmark1, cm2, cm3, equip->imei);
+
+ free(cm2);
+ free(cm3);
+
+ if (!result) {
+ printf("DB: Failed to update Equipment\n");
+ return -EIO;
+ }
+
+ dbi_result_free(result);
+ return 0;
+}
+
int db_subscriber_alloc_tmsi(struct gsm_subscriber* subscriber) {
dbi_result result=NULL;
char* tmsi_quoted;
@@ -322,6 +357,9 @@ int db_subscriber_assoc_imei(struct gsm_subscriber* subscriber, char imei[GSM_IM
u_int64_t equipment_id, watch_id;
dbi_result result;
+ strncpy(subscriber->equipment.imei, imei,
+ sizeof(subscriber->equipment.imei)-1),
+
result = dbi_conn_queryf(conn,
"INSERT OR IGNORE INTO Equipment "
"(imei, created, updated) "
diff --git a/openbsc/src/gsm_04_08.c b/openbsc/src/gsm_04_08.c
index 2312e8abe..3e2d171ea 100644
--- a/openbsc/src/gsm_04_08.c
+++ b/openbsc/src/gsm_04_08.c
@@ -1469,8 +1469,9 @@ static int gsm48_rx_mm_serv_req(struct msgb *msg)
subscr_put(subscr);
}
- subscr->classmark2_len = classmark2_len;
- memcpy(subscr->classmark2, classmark2, classmark2_len);
+ subscr->equipment.classmark2_len = classmark2_len;
+ memcpy(subscr->equipment.classmark2, classmark2, classmark2_len);
+ db_sync_equipment(&subscr->equipment);
return gsm48_tx_mm_serv_ack(msg->lchan);
}
@@ -1602,8 +1603,9 @@ static int gsm48_rr_rx_pag_resp(struct msgb *msg)
DEBUGP(DRR, "<- Channel was requested by %s\n",
subscr->name ? subscr->name : subscr->imsi);
- subscr->classmark2_len = *classmark2_lv;
- memcpy(subscr->classmark2, classmark2_lv+1, *classmark2_lv);
+ subscr->equipment.classmark2_len = *classmark2_lv;
+ memcpy(subscr->equipment.classmark2, classmark2_lv+1, *classmark2_lv);
+ db_sync_equipment(&subscr->equipment);
if (!msg->lchan->subscr) {
msg->lchan->subscr = subscr;
@@ -1667,16 +1669,15 @@ static int gsm48_rx_rr_classmark(struct msgb *msg)
DEBUGPC(DRR, "CM3(len=%u)\n", cm3_len);
}
if (subscr) {
- subscr->classmark2_len = cm2_len;
- memcpy(subscr->classmark2, cm2, cm2_len);
+ subscr->equipment.classmark2_len = cm2_len;
+ memcpy(subscr->equipment.classmark2, cm2, cm2_len);
if (cm3) {
- subscr->classmark3_len = cm3_len;
- memcpy(subscr->classmark3, cm3, cm3_len);
+ subscr->equipment.classmark3_len = cm3_len;
+ memcpy(subscr->equipment.classmark3, cm3, cm3_len);
}
+ db_sync_equipment(&subscr->equipment);
}
- /* FIXME: store the classmark2/3 values with the equipment register */
-
return 0;
}