From 5d571ce044dc95763a5a557b11f0ac90ff925e99 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 26 May 2018 11:32:50 +0200 Subject: Introduce osmo_ss7_register_rx_unknown_cb() for unknown PPID/StreamID Applications may be interested in handling data for those SCTP PPID or IPA StreamID which libosmo-sigtran doesn't implement natively/internally. Let's add osmo_ss7_register_rx_unknown_cb() using which applications can register a call-back to implement whatever behaviour they'd want for those PPID/StreamIDs. Change-Id: I8616f914192000df0ec6547ff4ada80e0f9042a2 --- include/osmocom/sigtran/osmo_ss7.h | 11 +++++++++++ src/ipa.c | 4 +--- src/osmo_ss7.c | 40 ++++++++++++++++++++++++++++---------- src/xua_internal.h | 2 ++ 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h index fd3f103..a93c663 100644 --- a/include/osmocom/sigtran/osmo_ss7.h +++ b/include/osmocom/sigtran/osmo_ss7.h @@ -408,6 +408,17 @@ int osmo_ss7_asp_send(struct osmo_ss7_asp *asp, struct msgb *msg); int osmo_ss7_asp_restart(struct osmo_ss7_asp *asp); int osmo_ss7_asp_use_default_lm(struct osmo_ss7_asp *asp, int log_level); +/*! Weak function to handle payload for unknown/unsupported PPID or IPA StreamID. + * This function can be overridden by application code to implement whatever handling + * it wants for such additional payloads/streams. + * \param[in] asp Application Server Process through which data was received + * \param[in] ppid_sid SCTP PPID (in sigtran case) or IPA Stream ID + * \param[in] msg Message buffer containing received data. Continues to be owned by caller! + * \return 0 on success; negative on error */ +typedef int osmo_ss7_asp_rx_unknown_cb(struct osmo_ss7_asp *asp, int ppid_mux, struct msgb *msg); + +void osmo_ss7_register_rx_unknown_cb(osmo_ss7_asp_rx_unknown_cb *cb); + #define LOGPASP(asp, subsys, level, fmt, args ...) \ LOGP(subsys, level, "asp-%s: " fmt, (asp)->cfg.name, ## args) diff --git a/src/ipa.c b/src/ipa.c index 9f04746..0e6f683 100644 --- a/src/ipa.c +++ b/src/ipa.c @@ -288,9 +288,7 @@ int ipa_rx_msg(struct osmo_ss7_asp *asp, struct msgb *msg) rc = ipa_rx_msg_sccp(asp, msg); break; default: - LOGPASP(asp, DLSS7, LOGL_DEBUG, "Unknown Stream ID 0x%02x: %s\n", - hh->proto, msgb_hexdump(msg)); - rc = -1; + rc = ss7_asp_rx_unknown(asp, hh->proto, msg); } return rc; diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c index 275469e..025c21c 100644 --- a/src/osmo_ss7.c +++ b/src/osmo_ss7.c @@ -1450,11 +1450,8 @@ static int xua_srv_conn_cb(struct osmo_stream_srv *conn) rc = sua_rx_msg(asp, msg); else if (ppid == M3UA_PPID && asp->cfg.proto == OSMO_SS7_ASP_PROT_M3UA) rc = m3ua_rx_msg(asp, msg); - else { - LOGPASP(asp, DLSS7, LOGL_NOTICE, "SCTP chunk for unknown PPID %u " - "received\n", ppid); - rc = 0; - } + else + rc = ss7_asp_rx_unknown(asp, ppid, msg); out: msgb_free(msg); @@ -1591,11 +1588,8 @@ static int xua_cli_read_cb(struct osmo_stream_cli *conn) rc = sua_rx_msg(asp, msg); else if (ppid == M3UA_PPID && asp->cfg.proto == OSMO_SS7_ASP_PROT_M3UA) rc = m3ua_rx_msg(asp, msg); - else { - LOGPASP(asp, DLSS7, LOGL_NOTICE, "SCTP chunk for unknown PPID %u " - "received\n", ppid); - rc = 0; - } + else + rc = ss7_asp_rx_unknown(asp, ppid, msg); out: msgb_free(msg); @@ -1918,3 +1912,29 @@ enum osmo_ss7_as_traffic_mode osmo_ss7_tmode_from_xua(uint32_t in) return OSMO_SS7_AS_TMOD_BCAST; } } + +static osmo_ss7_asp_rx_unknown_cb *g_osmo_ss7_asp_rx_unknown_cb; + +int ss7_asp_rx_unknown(struct osmo_ss7_asp *asp, int ppid_mux, struct msgb *msg) +{ + if (g_osmo_ss7_asp_rx_unknown_cb) + return (*g_osmo_ss7_asp_rx_unknown_cb)(asp, ppid_mux, msg); + + switch(asp->cfg.proto) { + case OSMO_SS7_ASP_PROT_IPA: + LOGPASP(asp, DLSS7, LOGL_NOTICE, "Rx IPA for unknown Stream ID 0x%02x: %s\n", + ppid_mux, msgb_hexdump(msg)); + break; + default: + LOGPASP(asp, DLSS7, LOGL_NOTICE, "Rx SCTP chunk for unknown PPID %u: %s\n", + ppid_mux, msgb_hexdump(msg)); + break; + } + return 0; +} + +/*! Register a call-back function for unknown SCTP PPID / IPA Stream ID */ +void osmo_ss7_register_rx_unknown_cb(osmo_ss7_asp_rx_unknown_cb *cb) +{ + g_osmo_ss7_asp_rx_unknown_cb = cb; +} diff --git a/src/xua_internal.h b/src/xua_internal.h index 96bd153..d836fae 100644 --- a/src/xua_internal.h +++ b/src/xua_internal.h @@ -78,3 +78,5 @@ int osmo_isup_party_parse(char *out_digits, const uint8_t *in, int osmo_sccp_addr_parse(struct osmo_sccp_addr *out, const uint8_t *addr, unsigned int addrlen); int osmo_sccp_addr_encode(struct msgb *msg, const struct osmo_sccp_addr *in); + +int ss7_asp_rx_unknown(struct osmo_ss7_asp *asp, int ppid_mux, struct msgb *msg); -- cgit v1.2.3