bsc_api: Allocate the subscriber_connection dynamically
This is a big change to the way we use the subscriber
connection. From now on it is is dynamically allocated
and we will slowly move from a 1:1 lchan to conn to
having more than one lchan per connection.
This is the first commit, the subscr_con* methods will
move to gsm_data once the use_count is removed from the
connection, the freeing of the connection will also change.
diff --git a/openbsc/src/bsc_api.c b/openbsc/src/bsc_api.c
index cac08be..92fe661 100644
--- a/openbsc/src/bsc_api.c
+++ b/openbsc/src/bsc_api.c
@@ -89,19 +89,23 @@
int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id)
{
int rc;
- struct gsm_subscriber_connection *conn;
struct bsc_api *api = msg->lchan->ts->trx->bts->network->bsc_api;
+ struct gsm_lchan *lchan;
- conn = &msg->lchan->conn;
- if (conn->allocated) {
- api->dtap(conn, msg);
+ lchan = msg->lchan;
+ if (lchan->conn) {
+ api->dtap(lchan->conn, msg);
} else {
- /* accept the connection or close the lchan */
- rc = api->compl_l3(conn, msg, 0);
- if (rc == BSC_API_CONN_POL_ACCEPT)
- conn->allocated = 1;
- else
- lchan_auto_release(msg->lchan);
+ rc = BSC_API_CONN_POL_REJECT;
+ lchan->conn = subscr_con_allocate(msg->lchan);
+
+ if (lchan->conn)
+ rc = api->compl_l3(lchan->conn, msg, 0);
+
+ if (rc != BSC_API_CONN_POL_ACCEPT) {
+ subscr_con_free(lchan->conn);
+ lchan_auto_release(lchan);
+ }
}
return 0;
@@ -111,6 +115,9 @@
{
struct bsc_api *api;
+ if (!conn)
+ return;
+
api = conn->bts->network->bsc_api;
if (!api || !api->sapi_n_reject)
return;
@@ -129,7 +136,7 @@
case BSC_RLLR_IND_REL_IND:
case BSC_RLLR_IND_ERR_IND:
case BSC_RLLR_IND_TIMEOUT:
- send_sapi_reject(&lchan->conn, OBSC_LINKID_CB(msg));
+ send_sapi_reject(lchan->conn, OBSC_LINKID_CB(msg));
msgb_free(msg);
break;
}
@@ -145,7 +152,7 @@
return 0;
lchan = (struct gsm_lchan *)signal_data;
- if (!lchan)
+ if (!lchan || !lchan->conn)
return 0;
@@ -153,7 +160,7 @@
if (!bsc || !bsc->clear_request)
return 0;
- bsc->clear_request(&lchan->conn, 0);
+ bsc->clear_request(lchan->conn, 0);
return 0;
}