sm: Start using SNSM SAP

Related: OS#5501
Change-Id: Ic5525bfa92e2591757d999610c0d59849d022d8d
This commit is contained in:
Pau Espin 2023-04-13 17:44:49 +02:00
parent aa1102494f
commit dd17a692f9
12 changed files with 206 additions and 5 deletions

View File

@ -22,6 +22,7 @@ enum gprs_sm_ms_fsm_events {
GPRS_SM_MS_EV_TX_ACT_PDP_CTX_REQ,
GPRS_SM_MS_EV_RX_ACT_PDP_CTX_REJ, /* data: enum gsm48_gsm_cause *cause */
GPRS_SM_MS_EV_RX_ACT_PDP_CTX_ACC,
GPRS_SM_MS_EV_NSAPI_ACTIVATED,
GPRS_SM_MS_EV_TX_DEACT_PDP_CTX_REQ,
GPRS_SM_MS_EV_RX_DEACT_PDP_CTX_REQ,
GPRS_SM_MS_EV_RX_DEACT_PDP_CTX_ACC,

View File

@ -18,6 +18,7 @@
struct osmo_gprs_gmm_prim;
struct osmo_gprs_sndcp_prim;
/* 3GPP TS 24.007 */
enum osmo_gprs_sm_prim_sap {
@ -191,6 +192,9 @@ struct osmo_gprs_sm_prim {
typedef int (*osmo_gprs_sm_prim_up_cb)(struct osmo_gprs_sm_prim *sm_prim, void *up_user_data);
void osmo_gprs_sm_prim_set_up_cb(osmo_gprs_sm_prim_up_cb up_cb, void *up_user_data);
typedef int (*osmo_gprs_sm_prim_sndcp_up_cb)(struct osmo_gprs_sndcp_prim *sndcp_prim, void *sndcp_up_user_data);
void osmo_gprs_sm_prim_set_sndcp_up_cb(osmo_gprs_sm_prim_sndcp_up_cb sndcp_up_cb, void *sndcp_up_user_data);
typedef int (*osmo_gprs_sm_prim_down_cb)(struct osmo_gprs_sm_prim *sm_prim, void *down_user_data);
void osmo_gprs_sm_prim_set_down_cb(osmo_gprs_sm_prim_down_cb down_cb, void *down_user_data);
@ -198,6 +202,7 @@ typedef int (*osmo_gprs_sm_prim_gmm_down_cb)(struct osmo_gprs_gmm_prim *gmm_prim
void osmo_gprs_sm_prim_set_gmm_down_cb(osmo_gprs_sm_prim_gmm_down_cb gmm_down_cb, void *gmm_down_user_data);
int osmo_gprs_sm_prim_upper_down(struct osmo_gprs_sm_prim *sm_prim);
int osmo_gprs_sm_prim_sndcp_upper_down(struct osmo_gprs_sndcp_prim *sndcp_prim);
int osmo_gprs_sm_prim_lower_up(struct osmo_gprs_sm_prim *sm_prim);
int osmo_gprs_sm_prim_gmm_lower_up(struct osmo_gprs_gmm_prim *gmm_prim);

View File

@ -72,6 +72,9 @@ struct gprs_sm_ctx {
osmo_gprs_sm_prim_up_cb sm_up_cb;
void *sm_up_cb_user_data;
osmo_gprs_sm_prim_sndcp_up_cb sm_sndcp_up_cb;
void *sm_sndcp_up_cb_user_data;
osmo_gprs_sm_prim_down_cb sm_down_cb;
void *sm_down_cb_user_data;
@ -145,6 +148,7 @@ static inline struct gprs_sm_entity *gprs_sm_ms_get_pdp_ctx(struct gprs_sm_ms *m
int gprs_sm_prim_call_up_cb(struct osmo_gprs_sm_prim *sm_prim);
int gprs_sm_prim_call_down_cb(struct osmo_gprs_sm_prim *sm_prim);
int gprs_sm_prim_call_gmm_down_cb(struct osmo_gprs_gmm_prim *gmm_prim);
int gprs_sm_prim_call_sndcp_up_cb(struct osmo_gprs_sndcp_prim *sndcp_prim);
struct osmo_gprs_sm_prim *gprs_sm_prim_alloc_smreg_pdp_act_cnf(void);
struct osmo_gprs_sm_prim *gprs_sm_prim_alloc_smreg_pdp_act_ind(void);
@ -153,6 +157,7 @@ struct osmo_gprs_sm_prim *gprs_sm_prim_alloc_smreg_pdp_act_ind(void);
struct gprs_sm_ms *gprs_sm_ms_alloc(uint32_t ms_id);
void gprs_sm_ms_free(struct gprs_sm_ms *ms);
struct gprs_sm_ms *gprs_sm_find_ms_by_id(uint32_t ms_id);
struct gprs_sm_ms *gprs_sm_find_ms_by_tlli(uint32_t tlli);
struct gprs_sm_entity *gprs_sm_entity_alloc(struct gprs_sm_ms *ms, uint32_t nsapi);
void gprs_sm_entity_free(struct gprs_sm_entity *sme);
@ -160,6 +165,7 @@ struct gprs_sm_entity *gprs_sm_find_sme_by_sess_id(uint32_t sess_id);
int gprs_sm_submit_gmmsm_assign_req(const struct gprs_sm_entity *sme);
int gprs_sm_submit_smreg_pdp_act_cnf(const struct gprs_sm_entity *sme, enum gsm48_gsm_cause cause);
int gprs_sm_submit_snsm_act_ind(const struct gprs_sm_entity *sme);
int gprs_sm_tx_act_pdp_ctx_req(struct gprs_sm_entity *sme);
int gprs_sm_rx(struct gprs_sm_entity *sme, struct gsm48_hdr *gh, unsigned int len);

View File

@ -6,7 +6,7 @@ includedir=@includedir@
Name: Osmocom [E]GPRS SM (Session Management) Library
Description: C Utility Library
Version: @VERSION@
Requires: libosmo-gprs-gmm libosmocore
Requires: libosmo-gprs-gmm libosmo-gprs-sndcp libosmocore
Libs: -L${libdir} -losmo-gprs-sm
Libs.private: -ltalloc
Cflags: -I${includedir}/

View File

@ -34,6 +34,7 @@ libosmo_gprs_sm_la_LDFLAGS = \
libosmo_gprs_sm_la_LIBADD = \
$(top_builddir)/src/gmm/libosmo-gprs-gmm.la \
$(top_builddir)/src/sndcp/libosmo-gprs-sndcp.la \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
-lm \

View File

@ -27,6 +27,8 @@
#include <osmocom/core/tdef.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/gprs/sndcp/sndcp_prim.h>
#include <osmocom/gprs/sm/sm.h>
#include <osmocom/gprs/sm/sm_prim.h>
#include <osmocom/gprs/sm/sm_private.h>
@ -120,6 +122,17 @@ struct gprs_sm_ms *gprs_sm_find_ms_by_id(uint32_t ms_id)
return NULL;
}
struct gprs_sm_ms *gprs_sm_find_ms_by_tlli(uint32_t tlli)
{
struct gprs_sm_ms *ms;
llist_for_each_entry(ms, &g_sm_ctx->ms_list, list) {
if (ms->gmm.ptmsi == tlli)
return ms;
}
return NULL;
}
struct gprs_sm_entity *gprs_sm_entity_alloc(struct gprs_sm_ms *ms, uint32_t nsapi)
{
struct gprs_sm_entity *sme;
@ -202,6 +215,23 @@ int gprs_sm_submit_smreg_pdp_act_cnf(const struct gprs_sm_entity *sme, enum gsm4
return rc;
}
int gprs_sm_submit_snsm_act_ind(const struct gprs_sm_entity *sme)
{
struct osmo_gprs_sndcp_prim *sndcp_prim_tx;
int rc;
sndcp_prim_tx = osmo_gprs_sndcp_prim_alloc_snsm_activate_ind(
sme->ms->gmm.ptmsi,
sme->nsapi,
sme->llc_sapi);
//sndcp_prim_tx->snsm.activat_ind.qos_params = ; /* TODO */
//sndcp_prim_tx->snsm.activat_ind.radio_prio = 0; /* TODO */
rc = gprs_sm_prim_call_sndcp_up_cb(sndcp_prim_tx);
return rc;
}
/* Tx SM Activate PDP context request, 9.5.1 */
int gprs_sm_tx_act_pdp_ctx_req(struct gprs_sm_entity *sme)
{

View File

@ -75,6 +75,13 @@ static void st_sm_ms_pdp_active_pending(struct osmo_fsm_inst *fi, uint32_t event
gprs_sm_submit_smreg_pdp_act_cnf(ctx->sme, *((enum gsm48_gsm_cause *)data));
break;
case GPRS_SM_MS_EV_RX_ACT_PDP_CTX_ACC:
gprs_sm_submit_snsm_act_ind(ctx->sme);
/* Submitting SMREG-PDP-ACT-CNF is delayed until ,
* SNSM-ACTIVATE-RSP (GPRS_SM_MS_EV_NSAPI_ACTIVATED) is received
* from SNDCP, see TS 24.007 C.6 */
break;
case GPRS_SM_MS_EV_NSAPI_ACTIVATED:
/* see TS 24.007 C.6 */
sm_ms_fsm_state_chg(fi, GPRS_SM_MS_ST_PDP_ACTIVE);
gprs_sm_submit_smreg_pdp_act_cnf(ctx->sme, (enum gsm48_gsm_cause)0);
break;
@ -176,7 +183,8 @@ static struct osmo_fsm_state sm_ms_fsm_states[] = {
X(GPRS_SM_MS_EV_RX_GMM_ESTABLISH_CNF) |
X(GPRS_SM_MS_EV_RX_GMM_ESTABLISH_REJ) |
X(GPRS_SM_MS_EV_RX_ACT_PDP_CTX_REJ) |
X(GPRS_SM_MS_EV_RX_ACT_PDP_CTX_ACC),
X(GPRS_SM_MS_EV_RX_ACT_PDP_CTX_ACC) |
X(GPRS_SM_MS_EV_NSAPI_ACTIVATED),
.out_state_mask =
X(GPRS_SM_MS_ST_PDP_INACTIVE) |
X(GPRS_SM_MS_ST_PDP_ACTIVE_PENDING) |
@ -225,6 +233,7 @@ const struct value_string sm_ms_fsm_event_names[] = {
{ GPRS_SM_MS_EV_TX_ACT_PDP_CTX_REQ, "TX_ACT_PDP_CTX_REQ" },
{ GPRS_SM_MS_EV_RX_ACT_PDP_CTX_REJ, "RX_ACT_PDP_CTX_REJ" },
{ GPRS_SM_MS_EV_RX_ACT_PDP_CTX_ACC, "RX_ACT_PDP_CTX_ACC" },
{ GPRS_SM_MS_EV_NSAPI_ACTIVATED, "NSAPI_ACTIVATED" },
{ GPRS_SM_MS_EV_TX_DEACT_PDP_CTX_REQ, "TX_DEACT_PDP_CTX_REQ" },
{ GPRS_SM_MS_EV_RX_DEACT_PDP_CTX_REQ, "RX_DEACT_PDP_CTX_REQ" },
{ GPRS_SM_MS_EV_RX_DEACT_PDP_CTX_ACC, "RX_DEACT_PDP_CTX_ACC" },

View File

@ -30,6 +30,7 @@
#include <osmocom/gprs/sm/sm_prim.h>
#include <osmocom/gprs/sm/sm_private.h>
#include <osmocom/gprs/gmm/gmm_prim.h>
#include <osmocom/gprs/sndcp/sndcp_prim.h>
#define SM_MSGB_HEADROOM 0
@ -72,6 +73,12 @@ static int sm_up_cb_dummy(struct osmo_gprs_sm_prim *sm_prim, void *user_data)
return 0;
}
static int sm_sndcp_up_cb_dummy(struct osmo_gprs_sndcp_prim *sndcp_prim, void *user_data)
{
LOGSM(LOGL_INFO, "%s(%s)\n", __func__, osmo_gprs_sndcp_prim_name(sndcp_prim));
return 0;
}
static int sm_down_cb_dummy(struct osmo_gprs_sm_prim *sm_prim, void *user_data)
{
LOGSM(LOGL_INFO, "%s(%s)\n", __func__, osmo_gprs_sm_prim_name(sm_prim));
@ -91,6 +98,13 @@ void osmo_gprs_sm_prim_set_up_cb(osmo_gprs_sm_prim_up_cb up_cb, void *up_user_da
g_sm_ctx->sm_up_cb_user_data = up_user_data;
}
/* Set callback used by SM layer to push primitives to SNDCP higher layer in protocol stack */
void osmo_gprs_sm_prim_set_sndcp_up_cb(osmo_gprs_sm_prim_sndcp_up_cb sndcp_up_cb, void *sndcp_up_user_data)
{
g_sm_ctx->sm_sndcp_up_cb = sndcp_up_cb;
g_sm_ctx->sm_sndcp_up_cb_user_data = sndcp_up_user_data;
}
/* Set callback used by SM layer to push primitives to lower layers in protocol stack */
void osmo_gprs_sm_prim_set_down_cb(osmo_gprs_sm_prim_down_cb down_cb, void *down_user_data)
{
@ -186,6 +200,13 @@ static int gprs_sm_prim_handle_gmm_unsupported(struct osmo_gprs_gmm_prim *gmm_pr
return -ENOTSUP;
}
static int gprs_sm_prim_handle_sndcp_unsupported(struct osmo_gprs_sndcp_prim *sndcp_prim)
{
LOGSM(LOGL_ERROR, "Unsupported sndcp_prim! %s\n", osmo_gprs_sndcp_prim_name(sndcp_prim));
msgb_free(sndcp_prim->oph.msg);
return -ENOTSUP;
}
/********************************
* Handling from/to upper layers:
********************************/
@ -297,6 +318,93 @@ int osmo_gprs_sm_prim_upper_down(struct osmo_gprs_sm_prim *sm_prim)
return rc;
}
/* SM layer pushes SNDCP primitive up to higher layers (SNSM): */
int gprs_sm_prim_call_sndcp_up_cb(struct osmo_gprs_sndcp_prim *sndcp_prim)
{
int rc;
if (g_sm_ctx->sm_sndcp_up_cb)
rc = g_sm_ctx->sm_sndcp_up_cb(sndcp_prim, g_sm_ctx->sm_sndcp_up_cb_user_data);
else
rc = sm_sndcp_up_cb_dummy(sndcp_prim, g_sm_ctx->sm_sndcp_up_cb_user_data);
/* Special return value '1' means: do not free */
if (rc != 1)
msgb_free(sndcp_prim->oph.msg);
else
rc = 0;
return rc;
}
/* TS 24.007 6.6.1.1 SMREG-Attach.request:*/
static int gprs_sm_prim_handle_snsm_act_resp(struct osmo_gprs_sndcp_prim *sndcp_prim)
{
int rc;
struct gprs_sm_ms *ms;
struct gprs_sm_entity *sme;
ms = gprs_sm_find_ms_by_tlli(sndcp_prim->snsm.tlli);
if (!ms) {
LOGSM(LOGL_ERROR, "Rx %s: Unable to find MS with TLLI=0x%08x\n",
osmo_gprs_sndcp_prim_name(sndcp_prim), sndcp_prim->snsm.tlli);
return -ENOENT;
}
sme = gprs_sm_ms_get_pdp_ctx(ms, sndcp_prim->snsm.activate_rsp.nsapi);
if (!sme) {
LOGMS(ms, LOGL_ERROR, "Rx %s: Unable to find NSAPI=%u\n",
osmo_gprs_sndcp_prim_name(sndcp_prim),
sndcp_prim->snsm.activate_rsp.nsapi);
return -ENOENT;
}
rc = osmo_fsm_inst_dispatch(sme->ms_fsm.fi, GPRS_SM_MS_EV_NSAPI_ACTIVATED, NULL);
return rc;
}
/* SNDCP higher layers push SNDCP primitive (SNSM) down to SM layer: */
static int gprs_sm_prim_handle_sndcp_snsm(struct osmo_gprs_sndcp_prim *sndcp_prim)
{
int rc;
switch (OSMO_PRIM_HDR(&sndcp_prim->oph)) {
case OSMO_PRIM(OSMO_GPRS_SNDCP_SNSM_ACTIVATE, PRIM_OP_RESPONSE):
rc = gprs_sm_prim_handle_snsm_act_resp(sndcp_prim);
break;
case OSMO_PRIM(OSMO_GPRS_SNDCP_SNSM_DEACTIVATE, PRIM_OP_RESPONSE):
case OSMO_PRIM(OSMO_GPRS_SNDCP_SNSM_MODIFY, PRIM_OP_RESPONSE):
case OSMO_PRIM(OSMO_GPRS_SNDCP_SNSM_STATUS, PRIM_OP_REQUEST):
case OSMO_PRIM(OSMO_GPRS_SNDCP_SNSM_SEQUENCE, PRIM_OP_RESPONSE):
case OSMO_PRIM(OSMO_GPRS_SNDCP_SNSM_STOP_ASSIGN, PRIM_OP_RESPONSE):
default:
rc = gprs_sm_prim_handle_sndcp_unsupported(sndcp_prim);
}
return rc;
}
/* SM higher layers push SM primitive down to SM layer: */
int osmo_gprs_sm_prim_sndcp_upper_down(struct osmo_gprs_sndcp_prim *sndcp_prim)
{
int rc;
LOGSM(LOGL_INFO, "Rx from SNDCP layer: %s\n", osmo_gprs_sndcp_prim_name(sndcp_prim));
switch (sndcp_prim->oph.sap) {
case OSMO_GPRS_SNDCP_SAP_SNSM:
rc = gprs_sm_prim_handle_sndcp_snsm(sndcp_prim);
break;
default:
rc = gprs_sm_prim_handle_sndcp_unsupported(sndcp_prim);
rc = 1;
}
/* Special return value '1' means: do not free */
if (rc != 1)
msgb_free(sndcp_prim->oph.msg);
else
rc = 0;
return rc;
}
/********************************
* Handling from/to lower layers:
********************************/

View File

@ -21,13 +21,16 @@ EXTRA_DIST = \
sm_prim_test.ok \
$(NULL)
# libosmo-gprs-gmm.a is used below to access non-exported private symbols used in the test:
# libosmo-gprs-{gmm,sndcp}.a are used below to access non-exported private symbols used in the test:
# libosmo-gprs-gmm.a requires libosmo-gprs-llc.la
# libosmo-gprs-sndcp.a requires libosmo-gprs-llc.la, -lm
sm_prim_test_SOURCES = sm_prim_test.c
sm_prim_test_LDADD = \
$(top_builddir)/src/sm/libosmo-gprs-sm.la \
$(top_builddir)/src/sndcp/.libs/libosmo-gprs-sndcp.a \
$(top_builddir)/src/gmm/.libs/libosmo-gprs-gmm.a \
$(top_builddir)/src/llc/.libs/libosmo-gprs-llc.la \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOCORE_LIBS) \
-lm \
$(NULL)

View File

@ -31,6 +31,8 @@
#include <osmocom/gprs/gmm/gmm_prim.h>
#include <osmocom/gprs/gmm/gmm_private.h>
#include <osmocom/gprs/sndcp/sndcp_prim.h>
#include <osmocom/gprs/sndcp/sndcp_private.h>
#include <osmocom/gprs/sm/sm.h>
#include <osmocom/gprs/sm/sm_prim.h>
@ -130,7 +132,29 @@ int test_sm_prim_up_cb(struct osmo_gprs_sm_prim *sm_prim, void *user_data)
break;
default:
printf("%s(): Unexpected Rx %s\n", __func__, pdu_name);
OSMO_ASSERT(0)
OSMO_ASSERT(0);
}
break;
default:
printf("%s(): Unexpected Rx %s\n", __func__, pdu_name);
OSMO_ASSERT(0);
}
return 0;
}
int test_sm_prim_sndcp_up_cb(struct osmo_gprs_sndcp_prim *sndcp_prim, void *user_data)
{
const char *pdu_name = osmo_gprs_sndcp_prim_name(sndcp_prim);
switch (sndcp_prim->oph.sap) {
case OSMO_GPRS_SNDCP_SAP_SNSM:
switch (OSMO_PRIM_HDR(&sndcp_prim->oph)) {
case OSMO_PRIM(OSMO_GPRS_SNDCP_SNSM_ACTIVATE, PRIM_OP_INDICATION):
printf("%s(): Rx %s\n", __func__, pdu_name);
break;
default:
printf("%s(): Unexpected Rx %s\n", __func__, pdu_name);
OSMO_ASSERT(0);
}
break;
default:
@ -152,7 +176,7 @@ int test_sm_prim_down_cb(struct osmo_gprs_sm_prim *sm_prim, void *user_data)
break;
default:
printf("%s(): Unexpected Rx %s\n", __func__, pdu_name);
OSMO_ASSERT(0)
OSMO_ASSERT(0);
}
break;
default:
@ -199,6 +223,7 @@ static void test_sm_prim_ms(void)
{
struct osmo_gprs_sm_prim *sm_prim;
struct osmo_gprs_gmm_prim *gmm_prim;
struct osmo_gprs_sndcp_prim *sndcp_prim;
int rc;
uint8_t nsapi = 6;
enum osmo_gprs_sm_llc_sapi llc_sapi = OSMO_GPRS_SM_LLC_SAPI_SAPI3;
@ -217,6 +242,7 @@ static void test_sm_prim_ms(void)
OSMO_ASSERT(rc == 0);
osmo_gprs_sm_prim_set_up_cb(test_sm_prim_up_cb, NULL);
osmo_gprs_sm_prim_set_sndcp_up_cb(test_sm_prim_sndcp_up_cb, NULL);
osmo_gprs_sm_prim_set_down_cb(test_sm_prim_down_cb, NULL);
osmo_gprs_sm_prim_set_gmm_down_cb(test_sm_prim_gmm_down_cb, NULL);
@ -254,6 +280,15 @@ static void test_sm_prim_ms(void)
rc = osmo_gprs_sm_prim_gmm_lower_up(gmm_prim);
OSMO_ASSERT(rc == 0);
/* SM layer will trigger SNSM-ACTIVATE.ind to SNDCP layer here. Now,
* SNDCP is expected to do XID config and once done, answer with
* SNSM-ACTIVATE.rsp: */
sndcp_prim = gprs_sndcp_prim_alloc_snsm_activate_rsp(ptmsi, nsapi);
OSMO_ASSERT(sndcp_prim);
rc = osmo_gprs_sm_prim_sndcp_upper_down(sndcp_prim);
OSMO_ASSERT(rc == 0);
printf("==== %s() [end] ====\n", __func__);
}

View File

@ -8,4 +8,6 @@ DLGLOBAL INFO PDP(ID-0:NSAPI-6) Tx SM Activate PDP Context Request
DLGLOBAL INFO Rx from lower layers: GMMSM-UNITDATA.indication
DLGLOBAL INFO PDP(ID-0:NSAPI-6) Rx SM Activate PDP Context Accept
DLGLOBAL INFO SM_MS{PDP_ACTIVE_PENDING}: Received Event RX_ACT_PDP_CTX_ACC
DLGLOBAL INFO Rx from SNDCP layer: SNSM-ACTIVATE.response
DLGLOBAL INFO SM_MS{PDP_ACTIVE_PENDING}: Received Event NSAPI_ACTIVATED
DLGLOBAL INFO SM_MS{PDP_ACTIVE_PENDING}: state_chg to PDP_ACTIVE

View File

@ -1,5 +1,6 @@
==== test_sm_prim_ms() [start] ====
test_sm_prim_gmm_down_cb(): Rx GMMSM-ESTABLISH.request sess_id=0
test_sm_prim_gmm_down_cb(): Rx GMMSM-UNITDATA.request sess_id=0 SMPDU=[8a 41 06 03 01 00 06 01 21 00 00 00 00 28 04 27 01 00 ]
test_sm_prim_sndcp_up_cb(): Rx SNSM-ACTIVATE.indication
test_sm_prim_up_cb(): Rx SMREG-PDP_ACTIVATE.confirm
==== test_sm_prim_ms() [end] ====