aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-01-25 19:42:52 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2019-02-14 09:26:47 +0000
commit114bad8c48bb37d8cdf1b4956a0fd046a3b0783e (patch)
tree814db2fa61b0854b1231f408057da60bb09e24fd
parent3acfe68b8b1a0d59ddad0afcc85f06098280e380 (diff)
libmsc/osmo_msc.c: move connection ref-counting code to 'ran_conn.c'
The connection ref-counting implementation is specific to RAN connections, and is not applicable for anything else. Moreover, the API of this code is declared in 'ran_conn.h', so let's move the code to a more logical place. Change-Id: I593675d9bf56eaef12afdaf596ee1337b9a44259
-rw-r--r--src/libmsc/osmo_msc.c111
-rw-r--r--src/libmsc/ran_conn.c111
2 files changed, 111 insertions, 111 deletions
diff --git a/src/libmsc/osmo_msc.c b/src/libmsc/osmo_msc.c
index 1a1ba3c..9828da1 100644
--- a/src/libmsc/osmo_msc.c
+++ b/src/libmsc/osmo_msc.c
@@ -219,117 +219,6 @@ int ran_conn_clear_request(struct ran_conn *conn, uint32_t cause)
return 1;
}
-static const char *used_ref_counts_str(struct ran_conn *conn)
-{
- static char buf[256];
- int bit_nr;
- char *pos = buf;
- *pos = '\0';
-
- if (conn->use_tokens < 0)
- return "invalid";
-
-#define APPEND_STR(fmt, args...) do { \
- int remain = sizeof(buf) - (pos - buf) - 1; \
- int l = -1; \
- if (remain > 0) \
- l = snprintf(pos, remain, "%s" fmt, (pos == buf? "" : ","), ##args); \
- if (l < 0 || l > remain) { \
- buf[sizeof(buf) - 1] = '\0'; \
- return buf; \
- } \
- pos += l; \
- } while(0)
-
- for (bit_nr = 0; (1 << bit_nr) <= conn->use_tokens; bit_nr++) {
- if (conn->use_tokens & (1 << bit_nr)) {
- APPEND_STR("%s", get_value_string(ran_conn_use_names, bit_nr));
- }
- }
- return buf;
-#undef APPEND_STR
-}
-
-/* increment the ref-count. Needs to be called by every user */
-struct ran_conn *_ran_conn_get(struct ran_conn *conn, enum ran_conn_use balance_token,
- const char *file, int line)
-{
- OSMO_ASSERT(conn);
-
- if (balance_token != RAN_CONN_USE_UNTRACKED) {
- uint32_t flag = 1 << balance_token;
- OSMO_ASSERT(balance_token < 32);
- if (conn->use_tokens & flag)
- LOGPSRC(DREF, LOGL_ERROR, file, line,
- "%s: MSC conn use error: using an already used token: %s\n",
- vlr_subscr_name(conn->vsub),
- ran_conn_use_name(balance_token));
- conn->use_tokens |= flag;
- }
-
- conn->use_count++;
- LOGPSRC(DREF, LOGL_DEBUG, file, line,
- "%s: MSC conn use + %s == %u (0x%x: %s)\n",
- vlr_subscr_name(conn->vsub), ran_conn_use_name(balance_token),
- conn->use_count, conn->use_tokens, used_ref_counts_str(conn));
-
- return conn;
-}
-
-/* decrement the ref-count. Once it reaches zero, we release */
-void _ran_conn_put(struct ran_conn *conn, enum ran_conn_use balance_token,
- const char *file, int line)
-{
- OSMO_ASSERT(conn);
-
- if (balance_token != RAN_CONN_USE_UNTRACKED) {
- uint32_t flag = 1 << balance_token;
- OSMO_ASSERT(balance_token < 32);
- if (!(conn->use_tokens & flag))
- LOGPSRC(DREF, LOGL_ERROR, file, line,
- "%s: MSC conn use error: freeing an unused token: %s\n",
- vlr_subscr_name(conn->vsub),
- ran_conn_use_name(balance_token));
- conn->use_tokens &= ~flag;
- }
-
- if (conn->use_count == 0) {
- LOGPSRC(DREF, LOGL_ERROR, file, line,
- "%s: MSC conn use - %s failed: is already 0\n",
- vlr_subscr_name(conn->vsub),
- ran_conn_use_name(balance_token));
- return;
- }
-
- conn->use_count--;
- LOGPSRC(DREF, LOGL_DEBUG, file, line,
- "%s: MSC conn use - %s == %u (0x%x: %s)\n",
- vlr_subscr_name(conn->vsub), ran_conn_use_name(balance_token),
- conn->use_count, conn->use_tokens, used_ref_counts_str(conn));
-
- if (conn->use_count == 0)
- osmo_fsm_inst_dispatch(conn->fi, RAN_CONN_E_UNUSED, NULL);
-}
-
-bool ran_conn_used_by(struct ran_conn *conn, enum ran_conn_use token)
-{
- return conn && (conn->use_tokens & (1 << token));
-}
-
-const struct value_string ran_conn_use_names[] = {
- {RAN_CONN_USE_UNTRACKED, "UNTRACKED"},
- {RAN_CONN_USE_COMPL_L3, "compl_l3"},
- {RAN_CONN_USE_DTAP, "dtap"},
- {RAN_CONN_USE_AUTH_CIPH, "auth+ciph"},
- {RAN_CONN_USE_CM_SERVICE, "cm_service"},
- {RAN_CONN_USE_TRANS_CC, "trans_cc"},
- {RAN_CONN_USE_TRANS_SMS, "trans_sms"},
- {RAN_CONN_USE_TRANS_NC_SS, "trans_nc_ss"},
- {RAN_CONN_USE_SILENT_CALL, "silent_call"},
- {RAN_CONN_USE_RELEASE, "release"},
- {0, NULL},
-};
-
void msc_stop_paging(struct vlr_subscr *vsub)
{
DEBUGP(DPAG, "Paging can stop for %s\n", vlr_subscr_name(vsub));
diff --git a/src/libmsc/ran_conn.c b/src/libmsc/ran_conn.c
index 6629bf6..be6bde0 100644
--- a/src/libmsc/ran_conn.c
+++ b/src/libmsc/ran_conn.c
@@ -796,3 +796,114 @@ void ran_conn_sgs_release_sent(struct ran_conn *conn)
/* Note: In SGsAP there is no confirmation of a release. */
rx_close_complete(conn, "SGs Release Complete", &dummy_waiting_for_release_complete);
}
+
+const struct value_string ran_conn_use_names[] = {
+ { RAN_CONN_USE_UNTRACKED, "UNTRACKED" },
+ { RAN_CONN_USE_COMPL_L3, "compl_l3" },
+ { RAN_CONN_USE_DTAP, "dtap" },
+ { RAN_CONN_USE_AUTH_CIPH, "auth+ciph" },
+ { RAN_CONN_USE_CM_SERVICE, "cm_service" },
+ { RAN_CONN_USE_TRANS_CC, "trans_cc" },
+ { RAN_CONN_USE_TRANS_SMS, "trans_sms" },
+ { RAN_CONN_USE_TRANS_NC_SS, "trans_nc_ss" },
+ { RAN_CONN_USE_SILENT_CALL, "silent_call" },
+ { RAN_CONN_USE_RELEASE, "release" },
+ { 0, NULL }
+};
+
+static const char *used_ref_counts_str(struct ran_conn *conn)
+{
+ static char buf[256];
+ int bit_nr;
+ char *pos = buf;
+ *pos = '\0';
+
+ if (conn->use_tokens < 0)
+ return "invalid";
+
+#define APPEND_STR(fmt, args...) do { \
+ int remain = sizeof(buf) - (pos - buf) - 1; \
+ int l = -1; \
+ if (remain > 0) \
+ l = snprintf(pos, remain, "%s" fmt, (pos == buf? "" : ","), ##args); \
+ if (l < 0 || l > remain) { \
+ buf[sizeof(buf) - 1] = '\0'; \
+ return buf; \
+ } \
+ pos += l; \
+ } while(0)
+
+ for (bit_nr = 0; (1 << bit_nr) <= conn->use_tokens; bit_nr++) {
+ if (conn->use_tokens & (1 << bit_nr)) {
+ APPEND_STR("%s", get_value_string(ran_conn_use_names, bit_nr));
+ }
+ }
+ return buf;
+#undef APPEND_STR
+}
+
+/* increment the ref-count. Needs to be called by every user */
+struct ran_conn *_ran_conn_get(struct ran_conn *conn, enum ran_conn_use balance_token,
+ const char *file, int line)
+{
+ OSMO_ASSERT(conn);
+
+ if (balance_token != RAN_CONN_USE_UNTRACKED) {
+ uint32_t flag = 1 << balance_token;
+ OSMO_ASSERT(balance_token < 32);
+ if (conn->use_tokens & flag)
+ LOGPSRC(DREF, LOGL_ERROR, file, line,
+ "%s: MSC conn use error: using an already used token: %s\n",
+ vlr_subscr_name(conn->vsub),
+ ran_conn_use_name(balance_token));
+ conn->use_tokens |= flag;
+ }
+
+ conn->use_count++;
+ LOGPSRC(DREF, LOGL_DEBUG, file, line,
+ "%s: MSC conn use + %s == %u (0x%x: %s)\n",
+ vlr_subscr_name(conn->vsub), ran_conn_use_name(balance_token),
+ conn->use_count, conn->use_tokens, used_ref_counts_str(conn));
+
+ return conn;
+}
+
+/* decrement the ref-count. Once it reaches zero, we release */
+void _ran_conn_put(struct ran_conn *conn, enum ran_conn_use balance_token,
+ const char *file, int line)
+{
+ OSMO_ASSERT(conn);
+
+ if (balance_token != RAN_CONN_USE_UNTRACKED) {
+ uint32_t flag = 1 << balance_token;
+ OSMO_ASSERT(balance_token < 32);
+ if (!(conn->use_tokens & flag))
+ LOGPSRC(DREF, LOGL_ERROR, file, line,
+ "%s: MSC conn use error: freeing an unused token: %s\n",
+ vlr_subscr_name(conn->vsub),
+ ran_conn_use_name(balance_token));
+ conn->use_tokens &= ~flag;
+ }
+
+ if (conn->use_count == 0) {
+ LOGPSRC(DREF, LOGL_ERROR, file, line,
+ "%s: MSC conn use - %s failed: is already 0\n",
+ vlr_subscr_name(conn->vsub),
+ ran_conn_use_name(balance_token));
+ return;
+ }
+
+ conn->use_count--;
+ LOGPSRC(DREF, LOGL_DEBUG, file, line,
+ "%s: MSC conn use - %s == %u (0x%x: %s)\n",
+ vlr_subscr_name(conn->vsub), ran_conn_use_name(balance_token),
+ conn->use_count, conn->use_tokens, used_ref_counts_str(conn));
+
+ if (conn->use_count == 0)
+ osmo_fsm_inst_dispatch(conn->fi, RAN_CONN_E_UNUSED, NULL);
+}
+
+bool ran_conn_used_by(struct ran_conn *conn, enum ran_conn_use token)
+{
+ return conn && (conn->use_tokens & (1 << token));
+}