Change in libosmocore[master]: gprs_ns2: add functions for SNS add/del/change-weight messages

lynxis lazus gerrit-no-reply at lists.osmocom.org
Tue Mar 2 09:15:17 UTC 2021


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/23186 )


Change subject: gprs_ns2: add functions for SNS add/del/change-weight messages
......................................................................

gprs_ns2: add functions for SNS add/del/change-weight messages

Change-Id: Ib9492e213e82c18c7dcce6ba7d64e897b4c74796
---
M src/gb/gprs_ns2_internal.h
M src/gb/gprs_ns2_message.c
2 files changed, 135 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/86/23186/1

diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index 7e235be..1bef753 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -329,6 +329,25 @@
 			 int ip4_ep_nr, int ip6_ep_nr);
 int ns2_tx_sns_size_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause);
 
+int ns2_tx_sns_add(struct gprs_ns2_vc *nsvc,
+		   uint8_t trans_id,
+		   const struct gprs_ns_ie_ip4_elem *ip4_elems,
+		   unsigned int num_ip4_elems,
+		   const struct gprs_ns_ie_ip6_elem *ip6_elems,
+		   unsigned int num_ip6_elems);
+int ns2_tx_sns_change_weight(struct gprs_ns2_vc *nsvc,
+			     uint8_t trans_id,
+			     const struct gprs_ns_ie_ip4_elem *ip4_elems,
+			     unsigned int num_ip4_elems,
+			     const struct gprs_ns_ie_ip6_elem *ip6_elems,
+			     unsigned int num_ip6_elems);
+int ns2_tx_sns_del(struct gprs_ns2_vc *nsvc,
+		   uint8_t trans_id,
+		   const struct gprs_ns_ie_ip4_elem *ip4_elems,
+		   unsigned int num_ip4_elems,
+		   const struct gprs_ns_ie_ip6_elem *ip6_elems,
+		   unsigned int num_ip6_elems);
+
 /* transmit message over a VC */
 int ns2_tx_block(struct gprs_ns2_vc *nsvc, uint8_t cause);
 int ns2_tx_block_ack(struct gprs_ns2_vc *nsvc);
diff --git a/src/gb/gprs_ns2_message.c b/src/gb/gprs_ns2_message.c
index ddf7285..ca764a4 100644
--- a/src/gb/gprs_ns2_message.c
+++ b/src/gb/gprs_ns2_message.c
@@ -481,6 +481,122 @@
 	return ns_vc_tx(nsvc, msg);
 }
 
+/*! Encode + Transmit a SNS-ADD/SNS-CHANGE-WEIGHT as per Section 9.3.2/9.3.3.
+ *  \param[in] nsvc NS-VC through which to transmit the SNS-CONFIG
+ *  \param[in] pdu The PDU type to send out
+ *  \param[in] trans_id The transaction id
+ *  \param[in] ip4_elems Array of IPv4 Elements
+ *  \param[in] num_ip4_elems number of ip4_elems
+ *  \param[in] ip6_elems Array of IPv6 Elements
+ *  \param[in] num_ip6_elems number of ip6_elems
+ *  \returns 0 on success; negative in case of error */
+static int ns2_tx_sns_procedure(struct gprs_ns2_vc *nsvc,
+				enum ns_pdu_type pdu,
+				uint8_t trans_id,
+				const struct gprs_ns_ie_ip4_elem *ip4_elems,
+				unsigned int num_ip4_elems,
+				const struct gprs_ns_ie_ip6_elem *ip6_elems,
+				unsigned int num_ip6_elems)
+{
+	struct msgb *msg;
+	struct gprs_ns_hdr *nsh;
+	uint16_t nsei;
+
+	if (!nsvc)
+		return -EINVAL;
+
+	if (!ip4_elems && !ip6_elems)
+		return -EINVAL;
+
+	msg = ns2_msgb_alloc();
+
+	log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
+	log_set_context(LOG_CTX_GB_NSVC, nsvc);
+	if (!msg)
+		return -ENOMEM;
+
+	if (!nsvc->nse->bss_sns_fi) {
+		LOGNSVC(nsvc, LOGL_ERROR, "Cannot transmit SNS on NSVC without SNS active\n");
+		msgb_free(msg);
+		return -EIO;
+	}
+
+	nsei = osmo_htons(nsvc->nse->nsei);
+
+	msg->l2h = msgb_put(msg, sizeof(*nsh));
+	nsh = (struct gprs_ns_hdr *) msg->l2h;
+	nsh->pdu_type = pdu;
+	msgb_tvlv_put(msg, NS_IE_NSEI, 2, (uint8_t *)&nsei);
+	msgb_v_put(msg, trans_id);
+
+	/* List of IP4 Elements 10.3.2c */
+	if (ip4_elems) {
+		msgb_tvlv_put(msg, NS_IE_IPv4_LIST, num_ip4_elems*sizeof(struct gprs_ns_ie_ip4_elem),
+			      (const uint8_t *)ip4_elems);
+	} else if (ip6_elems) {
+		/* List of IP6 elements 10.3.2d */
+		msgb_tvlv_put(msg, NS_IE_IPv6_LIST, num_ip6_elems*sizeof(struct gprs_ns_ie_ip6_elem),
+			      (const uint8_t *)ip6_elems);
+	}
+
+	return ns_vc_tx(nsvc, msg);
+}
+
+/*! Encode + Transmit a SNS-ADD as per Section 9.3.2.
+ *  \param[in] nsvc NS-VC through which to transmit the SNS-CONFIG
+ *  \param[in] trans_id The transaction id
+ *  \param[in] ip4_elems Array of IPv4 Elements
+ *  \param[in] num_ip4_elems number of ip4_elems
+ *  \param[in] ip6_elems Array of IPv6 Elements
+ *  \param[in] num_ip6_elems number of ip6_elems
+ *  \returns 0 on success; negative in case of error */
+int ns2_tx_sns_add(struct gprs_ns2_vc *nsvc,
+		   uint8_t trans_id,
+		   const struct gprs_ns_ie_ip4_elem *ip4_elems,
+		   unsigned int num_ip4_elems,
+		   const struct gprs_ns_ie_ip6_elem *ip6_elems,
+		   unsigned int num_ip6_elems)
+{
+	return ns2_tx_sns_procedure(nsvc, SNS_PDUT_ADD, trans_id, ip4_elems, num_ip4_elems, ip6_elems, num_ip6_elems);
+}
+
+/*! Encode + Transmit a SNS-CHANGE-WEIGHT as per Section 9.3.3.
+ *  \param[in] nsvc NS-VC through which to transmit the SNS-CONFIG
+ *  \param[in] trans_id The transaction id
+ *  \param[in] ip4_elems Array of IPv4 Elements
+ *  \param[in] num_ip4_elems number of ip4_elems
+ *  \param[in] ip6_elems Array of IPv6 Elements
+ *  \param[in] num_ip6_elems number of ip6_elems
+ *  \returns 0 on success; negative in case of error */
+int ns2_tx_sns_change_weight(struct gprs_ns2_vc *nsvc,
+			     uint8_t trans_id,
+			     const struct gprs_ns_ie_ip4_elem *ip4_elems,
+			     unsigned int num_ip4_elems,
+			     const struct gprs_ns_ie_ip6_elem *ip6_elems,
+			     unsigned int num_ip6_elems)
+{
+	return ns2_tx_sns_procedure(nsvc, SNS_PDUT_CHANGE_WEIGHT, trans_id, ip4_elems, num_ip4_elems, ip6_elems, num_ip6_elems);
+}
+
+/*! Encode + Transmit a SNS-DEL as per Section 9.3.6.
+ *  \param[in] nsvc NS-VC through which to transmit the SNS-CONFIG
+ *  \param[in] trans_id The transaction id
+ *  \param[in] ip4_elems Array of IPv4 Elements
+ *  \param[in] num_ip4_elems number of ip4_elems
+ *  \param[in] ip6_elems Array of IPv6 Elements
+ *  \param[in] num_ip6_elems number of ip6_elems
+ *  \returns 0 on success; negative in case of error */
+int ns2_tx_sns_del(struct gprs_ns2_vc *nsvc,
+		   uint8_t trans_id,
+		   const struct gprs_ns_ie_ip4_elem *ip4_elems,
+		   unsigned int num_ip4_elems,
+		   const struct gprs_ns_ie_ip6_elem *ip6_elems,
+		   unsigned int num_ip6_elems)
+{
+	/* TODO: IP Address field */
+	return ns2_tx_sns_procedure(nsvc, SNS_PDUT_DELETE, trans_id, ip4_elems, num_ip4_elems, ip6_elems, num_ip6_elems);
+}
+
 
 /*! Encode + Transmit a SNS-ACK as per Section 9.3.1.
  *  \param[in] nsvc NS-VC through which to transmit the ACK

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/23186
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ib9492e213e82c18c7dcce6ba7d64e897b4c74796
Gerrit-Change-Number: 23186
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210302/cc4ece7f/attachment.htm>


More information about the gerrit-log mailing list