summaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2009-07-23 19:21:02 +0200
committerHarald Welte <laforge@gnumonks.org>2009-07-23 19:21:02 +0200
commit761e944182255225bd2d48caa7d66a28ec7dea65 (patch)
treecc2ed755d1957f1d296ae0940aeadaef612dc6a8 /openbsc/src
parentb3c3faee940cda77afa9ba2500afa9ae9919851e (diff)
make sure subscr->net is always set
since a subscriber is an element of the gsm_network, we have to ensure subscr->net is always set correctly. We do this by using gsm_network as an argument to all functions that resolve or create a subscriber.
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/db.c14
-rw-r--r--openbsc/src/gsm_04_08.c27
-rw-r--r--openbsc/src/gsm_04_11.c3
-rw-r--r--openbsc/src/gsm_subscriber.c15
-rw-r--r--openbsc/src/vty_interface.c4
5 files changed, 40 insertions, 23 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 543f44ce2..fc2950a36 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -158,12 +158,13 @@ int db_fini() {
return 0;
}
-struct gsm_subscriber* db_create_subscriber(char *imsi) {
+struct gsm_subscriber* db_create_subscriber(struct gsm_network *net, char *imsi)
+{
dbi_result result;
struct gsm_subscriber* subscr;
/* Is this subscriber known in the db? */
- subscr = db_get_subscriber(GSM_SUBSCRIBER_IMSI, imsi);
+ subscr = db_get_subscriber(net, GSM_SUBSCRIBER_IMSI, imsi);
if (subscr) {
result = dbi_conn_queryf(conn,
"UPDATE Subscriber set updated = datetime('now') "
@@ -189,6 +190,7 @@ struct gsm_subscriber* db_create_subscriber(char *imsi) {
if (result==NULL) {
printf("DB: Failed to create Subscriber by IMSI.\n");
}
+ subscr->net = net;
subscr->id = dbi_conn_sequence_last(conn, NULL);
strncpy(subscr->imsi, imsi, GSM_IMSI_LENGTH-1);
dbi_result_free(result);
@@ -196,7 +198,10 @@ struct gsm_subscriber* db_create_subscriber(char *imsi) {
return subscr;
}
-struct gsm_subscriber *db_get_subscriber(enum gsm_subscriber_field field, const char *id) {
+struct gsm_subscriber *db_get_subscriber(struct gsm_network *net,
+ enum gsm_subscriber_field field,
+ const char *id)
+{
dbi_result result;
const char *string;
char *quoted;
@@ -246,6 +251,7 @@ struct gsm_subscriber *db_get_subscriber(enum gsm_subscriber_field field, const
}
subscr = subscr_alloc();
+ subscr->net = net;
subscr->id = dbi_result_get_ulonglong(result, "id");
string = dbi_result_get_string(result, "imsi");
if (string)
@@ -459,7 +465,7 @@ int db_sms_store(struct gsm_sms *sms)
}
/* retrieve the next unsent SMS with ID >= min_id */
-struct gsm_sms *db_sms_get_unsent(int min_id)
+struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, int min_id)
{
dbi_result result;
struct gsm_sms *sms = malloc(sizeof(*sms));
diff --git a/openbsc/src/gsm_04_08.c b/openbsc/src/gsm_04_08.c
index 4359f8709..507daf998 100644
--- a/openbsc/src/gsm_04_08.c
+++ b/openbsc/src/gsm_04_08.c
@@ -1131,6 +1131,8 @@ static int mm_rx_id_resp(struct msgb *msg)
{
struct gsm48_hdr *gh = msgb_l3(msg);
struct gsm_lchan *lchan = msg->lchan;
+ struct gsm_bts *bts = lchan->ts->trx->bts;
+ struct gsm_network *net = bts->network;
u_int8_t mi_type = gh->data[1] & GSM_MI_TYPE_MASK;
char mi_string[MI_SIZE];
@@ -1141,7 +1143,7 @@ static int mm_rx_id_resp(struct msgb *msg)
switch (mi_type) {
case GSM_MI_TYPE_IMSI:
if (!lchan->subscr)
- lchan->subscr = db_create_subscriber(mi_string);
+ lchan->subscr = db_create_subscriber(net, mi_string);
if (lchan->loc_operation)
lchan->loc_operation->waiting_for_imsi = 0;
break;
@@ -1198,6 +1200,7 @@ static int mm_rx_loc_upd_req(struct msgb *msg)
struct gsm48_loc_upd_req *lu;
struct gsm_subscriber *subscr = NULL;
struct gsm_lchan *lchan = msg->lchan;
+ struct gsm_bts *bts = lchan->ts->trx->bts;
u_int8_t mi_type;
char mi_string[MI_SIZE];
int rc;
@@ -1232,7 +1235,7 @@ static int mm_rx_loc_upd_req(struct msgb *msg)
lchan->loc_operation->waiting_for_imei = 1;
/* look up subscriber based on IMSI */
- subscr = db_create_subscriber(mi_string);
+ subscr = db_create_subscriber(bts->network, mi_string);
break;
case GSM_MI_TYPE_TMSI:
DEBUGPC(DMM, "\n");
@@ -1241,7 +1244,7 @@ static int mm_rx_loc_upd_req(struct msgb *msg)
lchan->loc_operation->waiting_for_imei = 1;
/* look up the subscriber based on TMSI, request IMSI if it fails */
- subscr = subscr_get_by_tmsi(mi_string);
+ subscr = subscr_get_by_tmsi(bts->network, mi_string);
if (!subscr) {
/* send IDENTITY REQUEST message to get IMSI */
rc = mm_tx_identity_req(lchan, GSM_MI_TYPE_IMSI);
@@ -1423,6 +1426,7 @@ static int gsm48_rx_mm_serv_req(struct msgb *msg)
u_int8_t mi_type;
char mi_string[MI_SIZE];
+ struct gsm_bts *bts = msg->lchan->ts->trx->bts;
struct gsm_subscriber *subscr;
struct gsm48_hdr *gh = msgb_l3(msg);
struct gsm48_service_request *req =
@@ -1457,7 +1461,7 @@ static int gsm48_rx_mm_serv_req(struct msgb *msg)
DEBUGPC(DMM, "serv_type=0x%02x mi_type=0x%02x M(%s)\n",
req->cm_service_type, mi_type, mi_string);
- subscr = subscr_get_by_tmsi(mi_string);
+ subscr = subscr_get_by_tmsi(bts->network, mi_string);
/* FIXME: if we don't know the TMSI, inquire abit IMSI and allocate new TMSI */
if (!subscr)
@@ -1480,6 +1484,7 @@ static int gsm48_rx_mm_serv_req(struct msgb *msg)
static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
{
+ struct gsm_bts *bts = msg->lchan->ts->trx->bts;
struct gsm48_hdr *gh = msgb_l3(msg);
struct gsm48_imsi_detach_ind *idi =
(struct gsm48_imsi_detach_ind *) gh->data;
@@ -1493,10 +1498,10 @@ static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
switch (mi_type) {
case GSM_MI_TYPE_TMSI:
- subscr = subscr_get_by_tmsi(mi_string);
+ subscr = subscr_get_by_tmsi(bts->network, mi_string);
break;
case GSM_MI_TYPE_IMSI:
- subscr = subscr_get_by_imsi(mi_string);
+ subscr = subscr_get_by_imsi(bts->network, mi_string);
break;
case GSM_MI_TYPE_IMEI:
case GSM_MI_TYPE_IMEISV:
@@ -1576,6 +1581,7 @@ static int gsm0408_rcv_mm(struct msgb *msg)
/* Receive a PAGING RESPONSE message from the MS */
static int gsm48_rr_rx_pag_resp(struct msgb *msg)
{
+ struct gsm_bts *bts = msg->lchan->ts->trx->bts;
struct gsm48_hdr *gh = msgb_l3(msg);
u_int8_t *classmark2_lv = gh->data + 1;
u_int8_t *mi_lv = gh->data + 2 + *classmark2_lv;
@@ -1590,10 +1596,10 @@ static int gsm48_rr_rx_pag_resp(struct msgb *msg)
mi_type, mi_string);
switch (mi_type) {
case GSM_MI_TYPE_TMSI:
- subscr = subscr_get_by_tmsi(mi_string);
+ subscr = subscr_get_by_tmsi(bts->network, mi_string);
break;
case GSM_MI_TYPE_IMSI:
- subscr = subscr_get_by_imsi(mi_string);
+ subscr = subscr_get_by_imsi(bts->network, mi_string);
break;
}
@@ -3381,9 +3387,10 @@ int mncc_send(struct gsm_network *net, int msg_type, void *arg)
}
/* New transaction due to setup, find subscriber */
if (data->called.number[0])
- subscr = subscr_get_by_extension(data->called.number);
+ subscr = subscr_get_by_extension(net,
+ data->called.number);
else
- subscr = subscr_get_by_imsi(data->imsi);
+ subscr = subscr_get_by_imsi(net, data->imsi);
/* If subscriber is not found */
if (!subscr) {
DEBUGP(DCC, "(bts - trx - ts - ti -- sub %s) "
diff --git a/openbsc/src/gsm_04_11.c b/openbsc/src/gsm_04_11.c
index 1b622b12b..8db402b33 100644
--- a/openbsc/src/gsm_04_11.c
+++ b/openbsc/src/gsm_04_11.c
@@ -154,6 +154,7 @@ static int gsm340_rx_sms_submit(struct msgb *msg, struct sms_submit *sms,
/* process an incoming TPDU (called from RP-DATA) */
static int gsm340_rx_tpdu(struct msgb *msg)
{
+ struct gsm_bts *bts = msg->lchan->ts->trx->bts;
u_int8_t *smsp = msgb_sms(msg);
struct sms_submit *sms;
struct gsm_sms *gsms;
@@ -257,7 +258,7 @@ static int gsm340_rx_tpdu(struct msgb *msg)
/* FIXME: sender refcount */
/* determine gsms->receiver based on dialled number */
- gsms->receiver = subscr_get_by_extension(sms->dest_addr);
+ gsms->receiver = subscr_get_by_extension(bts->network, sms->dest_addr);
if (!gsms->receiver) {
rc = 1; /* cause 1: unknown subscriber */
goto out;
diff --git a/openbsc/src/gsm_subscriber.c b/openbsc/src/gsm_subscriber.c
index 56f15951a..e89290623 100644
--- a/openbsc/src/gsm_subscriber.c
+++ b/openbsc/src/gsm_subscriber.c
@@ -126,7 +126,8 @@ static void subscr_free(struct gsm_subscriber *subscr)
talloc_free(subscr);
}
-struct gsm_subscriber *subscr_get_by_tmsi(const char *tmsi)
+struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_network *net,
+ const char *tmsi)
{
struct gsm_subscriber *subscr;
@@ -136,10 +137,11 @@ struct gsm_subscriber *subscr_get_by_tmsi(const char *tmsi)
return subscr_get(subscr);
}
- return db_get_subscriber(GSM_SUBSCRIBER_TMSI, tmsi);
+ return db_get_subscriber(net, GSM_SUBSCRIBER_TMSI, tmsi);
}
-struct gsm_subscriber *subscr_get_by_imsi(const char *imsi)
+struct gsm_subscriber *subscr_get_by_imsi(struct gsm_network *net,
+ const char *imsi)
{
struct gsm_subscriber *subscr;
@@ -148,10 +150,11 @@ struct gsm_subscriber *subscr_get_by_imsi(const char *imsi)
return subscr_get(subscr);
}
- return db_get_subscriber(GSM_SUBSCRIBER_IMSI, imsi);
+ return db_get_subscriber(net, GSM_SUBSCRIBER_IMSI, imsi);
}
-struct gsm_subscriber *subscr_get_by_extension(const char *ext)
+struct gsm_subscriber *subscr_get_by_extension(struct gsm_network *net,
+ const char *ext)
{
struct gsm_subscriber *subscr;
@@ -160,7 +163,7 @@ struct gsm_subscriber *subscr_get_by_extension(const char *ext)
return subscr_get(subscr);
}
- return db_get_subscriber(GSM_SUBSCRIBER_EXTENSION, ext);
+ return db_get_subscriber(net, GSM_SUBSCRIBER_EXTENSION, ext);
}
int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason)
diff --git a/openbsc/src/vty_interface.c b/openbsc/src/vty_interface.c
index 462689098..11b2ff60b 100644
--- a/openbsc/src/vty_interface.c
+++ b/openbsc/src/vty_interface.c
@@ -589,7 +589,7 @@ DEFUN(cfg_subscr,
const char *imsi = argv[0];
struct gsm_subscriber *subscr;
- subscr = subscr_get_by_imsi(imsi);
+ subscr = subscr_get_by_imsi(gsmnet, imsi);
if (!subscr) {
vty_out(vty, "%% No subscriber for IMSI %s%s",
imsi, VTY_NEWLINE);
@@ -855,7 +855,7 @@ DEFUN(show_subscr,
if (argc >= 1) {
imsi = argv[0];
- subscr = subscr_get_by_imsi(imsi);
+ subscr = subscr_get_by_imsi(gsmnet, imsi);
if (!subscr) {
vty_out(vty, "%% unknown subscriber%s",
VTY_NEWLINE);