aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/db.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2009-08-19 12:53:57 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2009-09-28 05:14:25 +0200
commit2223025e218263af6e1157ef1eeca1686cefe4b9 (patch)
treec3d9f36d3d14bf650f86b85d4bcc83492c741e1b /openbsc/src/db.c
parent6b0b103bdcfaf15ca1c33d3c61f211cb40661e92 (diff)
[tmsi] Make the tmsi a 4 octet number
tmsi is four octets long, there is no need to make it a string and then jump through hoops to convert it to a number. Keep the database using it as a string to benefit from the NULL handling of the db. Introduce the reserved tmsi which has all bits set to 1 according to GSM 03.03 ยง2.4 and start checking for it and make sure the db code will never allocate such a tmsi.
Diffstat (limited to 'openbsc/src/db.c')
-rw-r--r--openbsc/src/db.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 45c55aff9..270d4d90b 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -376,7 +376,7 @@ struct gsm_subscriber *db_get_subscriber(struct gsm_network *net,
string = dbi_result_get_string(result, "tmsi");
if (string)
- strncpy(subscr->tmsi, string, GSM_TMSI_LENGTH);
+ subscr->tmsi = tmsi_from_string(string);
string = dbi_result_get_string(result, "name");
if (string)
@@ -388,7 +388,7 @@ struct gsm_subscriber *db_get_subscriber(struct gsm_network *net,
subscr->lac = dbi_result_get_uint(result, "lac");
subscr->authorized = dbi_result_get_uint(result, "authorized");
- printf("DB: Found Subscriber: ID %llu, IMSI %s, NAME '%s', TMSI %s, EXTEN '%s', LAC %hu, AUTH %u\n",
+ printf("DB: 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);
dbi_result_free(result);
@@ -400,12 +400,15 @@ struct gsm_subscriber *db_get_subscriber(struct gsm_network *net,
int db_sync_subscriber(struct gsm_subscriber* subscriber) {
dbi_result result;
+ char tmsi[14];
char *q_tmsi;
- if (subscriber->tmsi[0])
+
+ if (subscriber->tmsi != GSM_RESERVED_TMSI) {
+ sprintf(tmsi, "%u", subscriber->tmsi);
dbi_conn_quote_string_copy(conn,
- subscriber->tmsi,
+ tmsi,
&q_tmsi);
- else
+ } else
q_tmsi = strdup("NULL");
result = dbi_conn_queryf(conn,
"UPDATE Subscriber "
@@ -475,10 +478,15 @@ int db_sync_equipment(struct gsm_equipment *equip)
int db_subscriber_alloc_tmsi(struct gsm_subscriber* subscriber) {
dbi_result result=NULL;
+ char tmsi[14];
char* tmsi_quoted;
for (;;) {
- sprintf(subscriber->tmsi, "%i", rand());
- dbi_conn_quote_string_copy(conn, subscriber->tmsi, &tmsi_quoted);
+ subscriber->tmsi = rand();
+ if (subscriber->tmsi == GSM_RESERVED_TMSI)
+ continue;
+
+ sprintf(tmsi, "%u", subscriber->tmsi);
+ dbi_conn_quote_string_copy(conn, tmsi, &tmsi_quoted);
result = dbi_conn_queryf(conn,
"SELECT * FROM Subscriber "
"WHERE tmsi = %s ",
@@ -495,7 +503,7 @@ int db_subscriber_alloc_tmsi(struct gsm_subscriber* subscriber) {
}
if (!dbi_result_next_row(result)) {
dbi_result_free(result);
- printf("DB: Allocated TMSI %s for IMSI %s.\n", subscriber->tmsi, subscriber->imsi);
+ printf("DB: Allocated TMSI %u for IMSI %s.\n", subscriber->tmsi, subscriber->imsi);
return db_sync_subscriber(subscriber);
}
dbi_result_free(result);