diff mbox

[2/3] gprs: Remove gprs_msgb_resize_area and gprs_msgb_copy

Message ID 1451990563-4184-3-git-send-email-jerlbeck@sysmocom.de
State New
Headers show

Commit Message

Jacob Erlbeck Jan. 5, 2016, 10:42 a.m. UTC
These functions are moved to libosmocore.

This commit removes the definitions and changes the
names to to the corresponding libosmogb/libosmocore ones:

 gprs_msgb_copy        -> bssgp_msgb_copy (libosmogb)
 gprs_msgb_resize_area -> msgb_resize_area (libosmocore)

Sponsored-by: On-Waves ehf
---
 openbsc/include/openbsc/gprs_utils.h |  8 ++--
 openbsc/src/gprs/gb_proxy.c          |  8 ++--
 openbsc/src/gprs/gb_proxy_patch.c    |  4 +-
 openbsc/src/gprs/gprs_gmm.c          |  2 +-
 openbsc/src/gprs/gprs_utils.c        | 84 ------------------------------------
 openbsc/tests/gbproxy/gbproxy_test.c |  2 +-
 6 files changed, 13 insertions(+), 95 deletions(-)
diff mbox

Patch

diff --git a/openbsc/include/openbsc/gprs_utils.h b/openbsc/include/openbsc/gprs_utils.h
index 7af83ba..8942e40 100644
--- a/openbsc/include/openbsc/gprs_utils.h
+++ b/openbsc/include/openbsc/gprs_utils.h
@@ -27,9 +27,11 @@ 
 
 struct msgb;
 
-struct msgb *gprs_msgb_copy(const struct msgb *msg, const char *name);
-int gprs_msgb_resize_area(struct msgb *msg, uint8_t *area,
-			    size_t old_size, size_t new_size);
+char *gprs_apn_to_str(char *out_str, const uint8_t *apn_enc, size_t rest_chars)
+	OSMO_DEPRECATED("Use osmo_apn_to_str instead");
+int gprs_str_to_apn(uint8_t *apn_enc, size_t max_len, const char *str)
+	OSMO_DEPRECATED("Use osmo_apn_from_str instead");
+
 /* GSM 04.08, 10.5.7.3 GPRS Timer */
 int gprs_tmr_to_secs(uint8_t tmr);
 uint8_t gprs_secs_to_tmr_floor(int secs);
diff --git a/openbsc/src/gprs/gb_proxy.c b/openbsc/src/gprs/gb_proxy.c
index 6cad651..7a290d3 100644
--- a/openbsc/src/gprs/gb_proxy.c
+++ b/openbsc/src/gprs/gb_proxy.c
@@ -486,7 +486,7 @@  static int gbproxy_imsi_acquisition(struct gbproxy_peer *peer,
 	     msgb_nsei(msg),
 	     parse_ctx->llc_msg_name ? parse_ctx->llc_msg_name : "BSSGP");
 
-	stored_msg = gprs_msgb_copy(msg, "process_bssgp_ul");
+	stored_msg = bssgp_msgb_copy(msg, "process_bssgp_ul");
 	msgb_enqueue(&link_info->stored_msgs, stored_msg);
 
 	if (!link_info->imsi_acq_pending) {
@@ -750,7 +750,7 @@  static int gbprox_relay2sgsn(struct gbproxy_config *cfg, struct msgb *old_msg,
 {
 	/* create a copy of the message so the old one can
 	 * be free()d safely when we return from gbprox_rcvmsg() */
-	struct msgb *msg = gprs_msgb_copy(old_msg, "msgb_relay2sgsn");
+	struct msgb *msg = bssgp_msgb_copy(old_msg, "msgb_relay2sgsn");
 	int rc;
 
 	DEBUGP(DGPRS, "NSEI=%u proxying BTS->SGSN (NS_BVCI=%u, NSEI=%u)\n",
@@ -774,7 +774,7 @@  static int gbprox_relay2peer(struct msgb *old_msg, struct gbproxy_peer *peer,
 {
 	/* create a copy of the message so the old one can
 	 * be free()d safely when we return from gbprox_rcvmsg() */
-	struct msgb *msg = gprs_msgb_copy(old_msg, "msgb_relay2peer");
+	struct msgb *msg = bssgp_msgb_copy(old_msg, "msgb_relay2peer");
 	int rc;
 
 	DEBUGP(DGPRS, "NSEI=%u proxying SGSN->BSS (NS_BVCI=%u, NSEI=%u)\n",
@@ -1169,7 +1169,7 @@  static int gbprox_rx_sig_from_sgsn(struct gbproxy_config *cfg,
 		return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, orig_msg);
 	}
 
-	msg = gprs_msgb_copy(orig_msg, "rx_sig_from_sgsn");
+	msg = bssgp_msgb_copy(orig_msg, "rx_sig_from_sgsn");
 	gbprox_process_bssgp_dl(cfg, msg, NULL);
 	/* Update message info */
 	bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg);
diff --git a/openbsc/src/gprs/gb_proxy_patch.c b/openbsc/src/gprs/gb_proxy_patch.c
index 725a863..9c3510a 100644
--- a/openbsc/src/gprs/gb_proxy_patch.c
+++ b/openbsc/src/gprs/gb_proxy_patch.c
@@ -106,7 +106,7 @@  static void gbproxy_patch_apn_ie(struct msgb *msg,
 		     osmo_apn_to_str(str1, apn, apn_len));
 
 		*new_apn_ie_len = 0;
-		gprs_msgb_resize_area(msg, apn_ie, apn_ie_len, 0);
+		msgb_resize_area(msg, apn_ie, apn_ie_len, 0);
 	} else {
 		/* Resize the IE */
 		char str1[110];
@@ -123,7 +123,7 @@  static void gbproxy_patch_apn_ie(struct msgb *msg,
 				       peer->cfg->core_apn_size));
 
 		*new_apn_ie_len = peer->cfg->core_apn_size + 2;
-		gprs_msgb_resize_area(msg, apn, apn_len, peer->cfg->core_apn_size);
+		msgb_resize_area(msg, apn, apn_len, peer->cfg->core_apn_size);
 		memcpy(apn, peer->cfg->core_apn, peer->cfg->core_apn_size);
 		hdr->apn_len = peer->cfg->core_apn_size;
 	}
diff --git a/openbsc/src/gprs/gprs_gmm.c b/openbsc/src/gprs/gprs_gmm.c
index 115e898..5ad8fd2 100644
--- a/openbsc/src/gprs/gprs_gmm.c
+++ b/openbsc/src/gprs/gprs_gmm.c
@@ -1888,7 +1888,7 @@  static int gsm48_rx_gsm_act_pdp_req(struct sgsn_mm_ctx *mmctx,
 	 * and the dynamic resolution will be the right thing
 	 * in the long run.
 	 */
-	msg = gprs_msgb_copy(_msg, __func__);
+	msg = bssgp_msgb_copy(_msg, __func__);
 	if (!msg) {
 		struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(_msg);
 		uint8_t transaction_id = (gh->proto_discr >> 4);
diff --git a/openbsc/src/gprs/gprs_utils.c b/openbsc/src/gprs/gprs_utils.c
index 8a98ae6..ee6adfc 100644
--- a/openbsc/src/gprs/gprs_utils.c
+++ b/openbsc/src/gprs/gprs_utils.c
@@ -29,90 +29,6 @@ 
 
 #include <string.h>
 
-/* FIXME: this needs to go to libosmocore/msgb.c */
-struct msgb *gprs_msgb_copy(const struct msgb *msg, const char *name)
-{
-	struct libgb_msgb_cb *old_cb, *new_cb;
-	struct msgb *new_msg;
-
-	new_msg = msgb_alloc(msg->data_len, name);
-	if (!new_msg)
-		return NULL;
-
-	/* copy data */
-	memcpy(new_msg->_data, msg->_data, new_msg->data_len);
-
-	/* copy header */
-	new_msg->len = msg->len;
-	new_msg->data += msg->data - msg->_data;
-	new_msg->head += msg->head - msg->_data;
-	new_msg->tail += msg->tail - msg->_data;
-
-	if (msg->l1h)
-		new_msg->l1h = new_msg->_data + (msg->l1h - msg->_data);
-	if (msg->l2h)
-		new_msg->l2h = new_msg->_data + (msg->l2h - msg->_data);
-	if (msg->l3h)
-		new_msg->l3h = new_msg->_data + (msg->l3h - msg->_data);
-	if (msg->l4h)
-		new_msg->l4h = new_msg->_data + (msg->l4h - msg->_data);
-
-	/* copy GB specific data */
-	old_cb = LIBGB_MSGB_CB(msg);
-	new_cb = LIBGB_MSGB_CB(new_msg);
-
-	if (old_cb->bssgph)
-		new_cb->bssgph = new_msg->_data + (old_cb->bssgph - msg->_data);
-	if (old_cb->llch)
-		new_cb->llch = new_msg->_data + (old_cb->llch - msg->_data);
-
-	/* bssgp_cell_id is a pointer into the old msgb, so we need to make
-	 * it a pointer into the new msgb */
-	if (old_cb->bssgp_cell_id)
-		new_cb->bssgp_cell_id = new_msg->_data +
-			(old_cb->bssgp_cell_id - msg->_data);
-	new_cb->nsei = old_cb->nsei;
-	new_cb->bvci = old_cb->bvci;
-	new_cb->tlli = old_cb->tlli;
-
-	return new_msg;
-}
-
-/* TODO: Move this to libosmocore/msgb.c */
-int gprs_msgb_resize_area(struct msgb *msg, uint8_t *area,
-			    size_t old_size, size_t new_size)
-{
-	int rc;
-	uint8_t *rest = area + old_size;
-	int rest_len = msg->len - old_size - (area - msg->data);
-	int delta_size = (int)new_size - (int)old_size;
-
-	if (delta_size == 0)
-		return 0;
-
-	if (delta_size > 0) {
-		rc = msgb_trim(msg, msg->len + delta_size);
-		if (rc < 0)
-			return rc;
-	}
-
-	memmove(area + new_size, area + old_size, rest_len);
-
-	if (msg->l1h >= rest)
-		msg->l1h += delta_size;
-	if (msg->l2h >= rest)
-		msg->l2h += delta_size;
-	if (msg->l3h >= rest)
-		msg->l3h += delta_size;
-	if (msg->l4h >= rest)
-		msg->l4h += delta_size;
-
-	if (delta_size < 0)
-		msgb_trim(msg, msg->len + delta_size);
-
-	return 0;
-}
-
 /* GSM 04.08, 10.5.7.3 GPRS Timer */
 int gprs_tmr_to_secs(uint8_t tmr)
 {
diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c
index 97aa32f..d5284a9 100644
--- a/openbsc/tests/gbproxy/gbproxy_test.c
+++ b/openbsc/tests/gbproxy/gbproxy_test.c
@@ -1064,7 +1064,7 @@  int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg)
 
 	if (received_messages) {
 		struct msgb *msg_copy;
-		msg_copy = gprs_msgb_copy(msg, "received_messages");
+		msg_copy = bssgp_msgb_copy(msg, "received_messages");
 		llist_add_tail(&msg_copy->list, received_messages);
 	}