aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-05-21 11:07:16 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-05-28 12:28:40 +0200
commitb0e5eaf59adbefc44e01850a6784c9da0c3abbf9 (patch)
treec7c628b9dd7db86d584e23a8c6d1031928059711 /src
parent9a2845d491b088cb9e1962ba6dc8af5a4e279401 (diff)
tbf: Move IMSI to MS object
Currently the IMSI is stored in the TBFs. Since it directly refers to an MS, it should rather be stored in an MS object. This patch move the m_imsi field from gprs_rlcmac_tbf to GprsMs, changes gprs_rlcmac_tbf::imsi() to get the IMSI from the associated MS object, and adds getter and setter to GprsMs. Before changing the IMSI of the associated MS object, assign_imsi() checks if there is already another MS object with the same IMSI and eventually resets the IMSI of that one. So using update_ms() and assign_imsi() ensures that there are not two MS object entries is the storage with the same TLLI or the same IMSI. Ticket: #1674 Sponsored-by: On-Waves ehf
Diffstat (limited to 'src')
-rw-r--r--src/gprs_ms.cpp27
-rw-r--r--src/gprs_ms.h12
-rw-r--r--src/tbf.cpp42
-rw-r--r--src/tbf.h8
-rw-r--r--src/tbf_dl.cpp1
5 files changed, 76 insertions, 14 deletions
diff --git a/src/gprs_ms.cpp b/src/gprs_ms.cpp
index 4c2f7cc0..c2320a29 100644
--- a/src/gprs_ms.cpp
+++ b/src/gprs_ms.cpp
@@ -65,6 +65,8 @@ GprsMs::GprsMs(uint32_t tlli) :
m_list(this)
{
LOGP(DRLCMAC, LOGL_INFO, "Creating MS object, TLLI = 0x%08x\n", tlli);
+
+ m_imsi[0] = 0;
}
GprsMs::~GprsMs()
@@ -236,3 +238,28 @@ bool GprsMs::confirm_tlli(uint32_t tlli)
return true;
}
+
+void GprsMs::set_imsi(const char *imsi)
+{
+ if (!imsi) {
+ LOGP(DRLCMAC, LOGL_ERROR, "Expected IMSI!\n");
+ return;
+ }
+
+ if (imsi[0] && strlen(imsi) < 3) {
+ LOGP(DRLCMAC, LOGL_ERROR, "No valid IMSI '%s'!\n",
+ imsi);
+ return;
+ }
+
+ if (strcmp(imsi, m_imsi) == 0)
+ return;
+
+ LOGP(DRLCMAC, LOGL_INFO,
+ "Modifying MS object, TLLI = 0x%08x, IMSI '%s' -> '%s'\n",
+ tlli(), m_imsi, imsi);
+
+ strncpy(m_imsi, imsi, sizeof(m_imsi));
+ m_imsi[sizeof(m_imsi) - 1] = '\0';
+}
+
diff --git a/src/gprs_ms.h b/src/gprs_ms.h
index e84ff9e7..7f8af414 100644
--- a/src/gprs_ms.h
+++ b/src/gprs_ms.h
@@ -56,6 +56,9 @@ public:
bool confirm_tlli(uint32_t tlli);
bool check_tlli(uint32_t tlli);
+ const char *imsi() const;
+ void set_imsi(const char *imsi);
+
void attach_tbf(gprs_rlcmac_tbf *tbf);
void attach_ul_tbf(gprs_rlcmac_ul_tbf *tbf);
void attach_dl_tbf(gprs_rlcmac_dl_tbf *tbf);
@@ -82,6 +85,10 @@ private:
uint32_t m_tlli;
uint32_t m_new_ul_tlli;
uint32_t m_new_dl_tlli;
+
+ /* store IMSI for look-up and PCH retransmission */
+ char m_imsi[16];
+
bool m_is_idle;
int m_ref;
LListHead<GprsMs> m_list;
@@ -99,3 +106,8 @@ inline bool GprsMs::check_tlli(uint32_t tlli)
return tlli != 0 &&
(tlli == m_tlli || tlli == m_new_ul_tlli || tlli == m_new_dl_tlli);
}
+
+inline const char *GprsMs::imsi() const
+{
+ return m_imsi;
+}
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 51b2aa5c..0771969f 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -51,10 +51,42 @@ uint32_t gprs_rlcmac_tbf::tlli() const
return m_ms ? m_ms->tlli() : 0;
}
-void gprs_rlcmac_tbf::assign_imsi(const char *imsi)
+const char *gprs_rlcmac_tbf::imsi() const
{
- strncpy(m_imsi, imsi, sizeof(m_imsi));
- m_imsi[sizeof(m_imsi) - 1] = '\0';
+ static const char nullc = 0;
+ return m_ms ? m_ms->imsi() : &nullc;
+}
+
+void gprs_rlcmac_tbf::assign_imsi(const char *imsi_)
+{
+ GprsMs *old_ms;
+
+ if (!imsi_ || !m_ms) {
+ LOGP(DRLCMAC, LOGL_ERROR,
+ "%s failed to assign IMSI: missing IMSI or MS object\n",
+ name());
+ return;
+ }
+
+ if (strcmp(imsi_, imsi()) == 0)
+ return;
+
+ /* really change the IMSI */
+
+ old_ms = bts->ms_store().get_ms(0, 0, imsi_);
+ if (old_ms) {
+ /* We cannot find m_ms by IMSI since we know that it has a
+ * different IMSI */
+ OSMO_ASSERT(old_ms != m_ms);
+
+ LOGP(DRLCMAC, LOGL_INFO,
+ "%s the IMSI '%s' was already assigned to another "
+ "MS object: TLLI = 0x%08x, that IMSI will be removed\n",
+ name(), imsi_, old_ms->tlli());
+ old_ms->set_imsi("");
+ }
+
+ m_ms->set_imsi(imsi_);
}
void gprs_rlcmac_tbf::set_new_tbf(gprs_rlcmac_tbf *tbf)
@@ -404,9 +436,9 @@ void gprs_rlcmac_tbf::poll_timeout()
LOGP(DRLCMAC, LOGL_DEBUG, "Re-send dowlink assignment "
"for %s on PCH (IMSI=%s)\n",
tbf_name(dl_tbf),
- m_imsi);
+ imsi());
/* send immediate assignment */
- dl_tbf->bts->snd_dl_ass(dl_tbf, 0, m_imsi);
+ dl_tbf->bts->snd_dl_ass(dl_tbf, 0, imsi());
dl_tbf->m_wait_confirm = 1;
}
} else
diff --git a/src/tbf.h b/src/tbf.h
index 9dbbe51d..0820065f 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -223,9 +223,6 @@ struct gprs_rlcmac_tbf {
uint8_t m_tfi;
time_t m_created_ts;
- /* store IMSI for look-up and PCH retransmission */
- char m_imsi[16];
-
protected:
gprs_rlcmac_bts *bts_data() const;
@@ -300,11 +297,6 @@ inline uint8_t gprs_rlcmac_tbf::tfi() const
return m_tfi;
}
-inline const char *gprs_rlcmac_tbf::imsi() const
-{
- return m_imsi;
-}
-
inline gprs_rlcmac_tbf *gprs_rlcmac_tbf::new_tbf() const
{
return m_new_tbf;
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 605239a3..13811fa1 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -802,7 +802,6 @@ void gprs_rlcmac_dl_tbf::reuse_tbf(const uint8_t *data, const uint16_t len)
new_tbf->set_ms(ms());
new_tbf->ta = ta;
- new_tbf->assign_imsi(m_imsi);
/* Copy over all data to the new TBF */
new_tbf->m_llc.put_frame(data, len);