aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2013-10-14 22:06:47 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-10-15 09:48:41 +0200
commit96550e03214697be2d1b303a690ef10ea3bb12b7 (patch)
tree51c3ec209620c8e185aea2739dc800aefda3b01d
parent6901715124d53574dc607d540105128573808b24 (diff)
gb: Add functions to access the LL part of the NS-VC objects
Adds the functions gprs_ns_ll_copy() and gprs_ns_ll_clear(). Renames gprs_ns_format_peer() to gprs_ns_ll_str(). All of these functions uniformly access the link layer part within the NS-VC objects. Sponsored-by: On-Waves ehf
-rw-r--r--include/osmocom/gprs/gprs_ns.h8
-rw-r--r--src/gb/gprs_ns.c42
-rw-r--r--src/gb/libosmogb.map4
-rw-r--r--tests/gb/gprs_ns_test.c10
4 files changed, 52 insertions, 12 deletions
diff --git a/include/osmocom/gprs/gprs_ns.h b/include/osmocom/gprs/gprs_ns.h
index d16068b..7b0ec92 100644
--- a/include/osmocom/gprs/gprs_ns.h
+++ b/include/osmocom/gprs/gprs_ns.h
@@ -177,7 +177,13 @@ void gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause);
int gprs_ns_vty_init(struct gprs_ns_inst *nsi);
/* Resturn peer info as string (NOTE: the buffer is allocated statically) */
-const char *gprs_ns_format_peer(struct gprs_nsvc *nsvc);
+const char *gprs_ns_ll_str(struct gprs_nsvc *nsvc);
+
+/* Copy the link layer info from other into nsvc */
+void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other);
+
+/* Clear the link layer info (will never match a real link then) */
+void gprs_ns_ll_clear(struct gprs_nsvc *nsvc);
#define NS_ALLOC_SIZE 2048
#define NS_ALLOC_HEADROOM 20
diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c
index 7801b29..61a96d7 100644
--- a/src/gb/gprs_ns.c
+++ b/src/gb/gprs_ns.c
@@ -802,7 +802,7 @@ int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg,
return rc;
}
-const char *gprs_ns_format_peer(struct gprs_nsvc *nsvc)
+const char *gprs_ns_ll_str(struct gprs_nsvc *nsvc)
{
static char buf[80];
snprintf(buf, sizeof(buf), "%s:%u",
@@ -812,6 +812,38 @@ const char *gprs_ns_format_peer(struct gprs_nsvc *nsvc)
return buf;
}
+void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other)
+{
+ nsvc->ll = other->ll;
+
+ switch (nsvc->ll) {
+ case GPRS_NS_LL_UDP:
+ nsvc->ip = other->ip;
+ break;
+ case GPRS_NS_LL_FR_GRE:
+ nsvc->frgre = other->frgre;
+ break;
+ default:
+ break;
+ }
+}
+
+void gprs_ns_ll_clear(struct gprs_nsvc *nsvc)
+{
+ switch (nsvc->ll) {
+ case GPRS_NS_LL_UDP:
+ nsvc->ip.bts_addr.sin_addr.s_addr = INADDR_ANY;
+ nsvc->ip.bts_addr.sin_port = 0;
+ break;
+ case GPRS_NS_LL_FR_GRE:
+ nsvc->frgre.bts_addr.sin_addr.s_addr = INADDR_ANY;
+ nsvc->frgre.bts_addr.sin_port = 0;
+ break;
+ default:
+ break;
+ }
+}
+
/*! \brief Create/get NS-VC independently from underlying transport layer
* \param nsi NS instance to which the data belongs
* \param[in] msg message buffer containing newly-received data
@@ -841,7 +873,7 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg,
if (nsh->pdu_type == NS_PDUT_STATUS) {
LOGP(DNS, LOGL_INFO, "Ignoring NS STATUS from %s "
"for non-existing NS-VC\n",
- gprs_ns_format_peer(fallback_nsvc));
+ gprs_ns_ll_str(fallback_nsvc));
return GPRS_NS_CS_SKIPPED;
}
@@ -851,7 +883,7 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg,
log_set_context(GPRS_CTX_NSVC, fallback_nsvc);
LOGP(DNS, LOGL_INFO, "Rejecting NS PDU type 0x%0x "
"from %s for non-existing NS-VC\n",
- nsh->pdu_type, gprs_ns_format_peer(fallback_nsvc));
+ nsh->pdu_type, gprs_ns_ll_str(fallback_nsvc));
fallback_nsvc->nsvci = fallback_nsvc->nsei = 0xfffe;
fallback_nsvc->state = NSE_S_ALIVE;
@@ -859,7 +891,7 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg,
NS_CAUSE_PDU_INCOMP_PSTATE, 0, msg);
if (rc < 0) {
LOGP(DNS, LOGL_ERROR, "TX failed (%d) to peer %s\n",
- rc, gprs_ns_format_peer(fallback_nsvc));
+ rc, gprs_ns_ll_str(fallback_nsvc));
return rc;
}
return GPRS_NS_CS_REJECTED;
@@ -887,7 +919,7 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg,
*new_nsvc = gprs_nsvc_create(nsi, 0xffff);
log_set_context(GPRS_CTX_NSVC, *new_nsvc);
LOGP(DNS, LOGL_INFO, "Creating NS-VC for BSS at %s\n",
- gprs_ns_format_peer(fallback_nsvc));
+ gprs_ns_ll_str(fallback_nsvc));
return GPRS_NS_CS_CREATED;
}
diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map
index 0270db8..a21a7ac 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -54,7 +54,9 @@ gprs_ns_tx_reset;
gprs_ns_tx_status;
gprs_ns_tx_unblock;
gprs_ns_vty_init;
-gprs_ns_format_peer;
+gprs_ns_ll_str;
+gprs_ns_ll_copy;
+gprs_ns_ll_clear;
gprs_nsvc_create;
gprs_nsvc_delete;
diff --git a/tests/gb/gprs_ns_test.c b/tests/gb/gprs_ns_test.c
index c4fc228..1474fd4 100644
--- a/tests/gb/gprs_ns_test.c
+++ b/tests/gb/gprs_ns_test.c
@@ -134,31 +134,31 @@ static int test_signal(unsigned int subsys, unsigned int signal,
case S_NS_RESET:
printf("==> got signal NS_RESET, NS-VC 0x%04x/%s\n",
nssd->nsvc->nsvci,
- gprs_ns_format_peer(nssd->nsvc));
+ gprs_ns_ll_str(nssd->nsvc));
break;
case S_NS_ALIVE_EXP:
printf("==> got signal NS_ALIVE_EXP, NS-VC 0x%04x/%s\n",
nssd->nsvc->nsvci,
- gprs_ns_format_peer(nssd->nsvc));
+ gprs_ns_ll_str(nssd->nsvc));
break;
case S_NS_BLOCK:
printf("==> got signal NS_BLOCK, NS-VC 0x%04x/%s\n",
nssd->nsvc->nsvci,
- gprs_ns_format_peer(nssd->nsvc));
+ gprs_ns_ll_str(nssd->nsvc));
break;
case S_NS_UNBLOCK:
printf("==> got signal NS_UNBLOCK, NS-VC 0x%04x/%s\n",
nssd->nsvc->nsvci,
- gprs_ns_format_peer(nssd->nsvc));
+ gprs_ns_ll_str(nssd->nsvc));
break;
default:
printf("==> got signal %d, NS-VC 0x%04x/%s\n", signal,
nssd->nsvc->nsvci,
- gprs_ns_format_peer(nssd->nsvc));
+ gprs_ns_ll_str(nssd->nsvc));
break;
}