[subscriber] Update the current_bts field on imsi detach and LOC accept
When sending LOCATION UPDATING REQUEST Accept or when getting
a IMSI Detach update the gsm_bts of the gsm_subscriber.
diff --git a/src/gsm_04_08.c b/src/gsm_04_08.c
index 4b2ecdc..a9183de 100644
--- a/src/gsm_04_08.c
+++ b/src/gsm_04_08.c
@@ -584,7 +584,7 @@
return 0;
db_subscriber_alloc_tmsi(subscr);
- subscr_update(subscr, bts);
+ subscr_update(subscr, bts, GSM_SUBSCRIBER_UPDATE_ATTACHED);
tmsi = strtoul(subscr->tmsi, NULL, 10);
@@ -806,10 +806,12 @@
break;
}
- if (subscr)
+ if (subscr) {
+ subscr_update(subscr, msg->trx->bts,
+ GSM_SUBSCRIBER_UPDATE_DETACHED);
DEBUGP(DMM, "Subscriber: %s\n",
subscr->name ? subscr->name : subscr->imsi);
- else
+ } else
DEBUGP(DMM, "Unknown Subscriber ?!?\n");
put_lchan(msg->lchan);
diff --git a/src/gsm_subscriber.c b/src/gsm_subscriber.c
index d4dfea4..e3cd5eb 100644
--- a/src/gsm_subscriber.c
+++ b/src/gsm_subscriber.c
@@ -90,8 +90,23 @@
return db_get_subscriber(GSM_SUBSCRIBER_EXTENSION, ext);
}
-int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts)
+int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason)
{
+ /* FIXME: Migrate pending requests from one BSC to another */
+ switch (reason) {
+ case GSM_SUBSCRIBER_UPDATE_ATTACHED:
+ s->current_bts = bts;
+ break;
+ case GSM_SUBSCRIBER_UPDATE_DETACHED:
+ /* Only detach if we are currently attached to this bts */
+ if (bts == s->current_bts)
+ s->current_bts = NULL;
+ break;
+ default:
+ fprintf(stderr, "subscr_update with unknown reason: %d\n",
+ reason);
+ break;
+ };
return db_sync_subscriber(s);
}