gb: Add bssgp_msgb_copy function

This function originates from openbsc/src/gprs but is just specific
to BSSGP/Gb on the same level like bssgp_msgb_alloc.

This commit puts the former gprs_msgb_copy function beside
bssgp_msgb_alloc.

Renamed function:

  gprs_msgb_copy -> bssgp_msgb_copy

Sponsored-by: On-Waves ehf
This commit is contained in:
Jacob Erlbeck 2015-11-17 09:53:23 +01:00 committed by Holger Hans Peter Freyther
parent ab0eb96dd9
commit f78ec5ce0d
5 changed files with 70 additions and 0 deletions

View File

@ -12,6 +12,7 @@
/* gprs_bssgp_util.c */
extern struct gprs_ns_inst *bssgp_nsi;
struct msgb *bssgp_msgb_alloc(void);
struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name);
const char *bssgp_cause_str(enum gprs_bssgp_cause cause);
/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,

View File

@ -79,6 +79,36 @@ struct msgb *bssgp_msgb_alloc(void)
return msg;
}
struct msgb *bssgp_msgb_copy(const struct msgb *msg, const char *name)
{
struct libgb_msgb_cb *old_cb, *new_cb;
struct msgb *new_msg;
new_msg = msgb_copy(msg, name);
if (!new_msg)
return NULL;
/* 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;
}
/* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */
int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei,
uint16_t bvci, uint16_t ns_bvci)

View File

@ -6,6 +6,7 @@ bssgp_fc_in;
bssgp_fc_init;
bssgp_fc_ms_init;
bssgp_msgb_alloc;
bssgp_msgb_copy;
bssgp_msgb_tlli_put;
bssgp_parse_cell_id;
bssgp_tx_bvc_block;

View File

@ -254,6 +254,39 @@ static void test_bssgp_flow_control_bvc(void)
printf("----- %s END\n", __func__);
}
static void test_bssgp_msgb_copy()
{
struct msgb *msg, *msg2;
uint16_t bvci_be = htons(2);
uint8_t cause = BSSGP_CAUSE_OML_INTERV;
printf("----- %s START\n", __func__);
msg = bssgp_msgb_alloc();
msg->l3h = msgb_data(msg);
msgb_v_put(msg, BSSGP_PDUT_BVC_RESET);
msgb_tvlv_put(msg, BSSGP_IE_BVCI, sizeof(bvci_be), (uint8_t *)&bvci_be);
msgb_tvlv_put(msg, BSSGP_IE_CAUSE, sizeof(cause), &cause);
msgb_bvci(msg) = 0xbad;
msgb_nsei(msg) = 0xbee;
printf("Old msgb: %s\n", msgb_hexdump(msg));
msg2 = bssgp_msgb_copy(msg, "test");
printf("New msgb: %s\n", msgb_hexdump(msg2));
OSMO_ASSERT(msgb_bvci(msg2) == 0xbad);
OSMO_ASSERT(msgb_nsei(msg2) == 0xbee);
OSMO_ASSERT(msgb_l3(msg2) == msgb_data(msg2));
OSMO_ASSERT(msgb_bssgph(msg2) == msgb_data(msg2));
OSMO_ASSERT(msgb_bssgp_len(msg2) == msgb_length(msg2));
msgb_free(msg);
msgb_free(msg2);
printf("----- %s END\n", __func__);
}
static struct log_info info = {};
int main(int argc, char **argv)
@ -278,6 +311,7 @@ int main(int argc, char **argv)
test_bssgp_status();
test_bssgp_bad_reset();
test_bssgp_flow_control_bvc();
test_bssgp_msgb_copy();
printf("===== BSSGP test END\n\n");
exit(EXIT_SUCCESS);

View File

@ -13,5 +13,9 @@ BSSGP primitive, SAP 16777221, prim = 11, op = 2, msg = 41 07 81 05 04 82 04 d2
Got message: 26 1e 81 2a 05 82 10 22 03 82 c0 40 01 82 08 11 1c 82 60 20
Got message: 26 1e 81 2a 05 82 10 22 03 82 c0 40 01 82 08 11 1c 82 60 20 3c 81 78 06 82 11 44
----- test_bssgp_flow_control_bvc END
----- test_bssgp_msgb_copy START
Old msgb: [L3]> 22 04 82 00 02 07 81 08
New msgb: [L3]> 22 04 82 00 02 07 81 08
----- test_bssgp_msgb_copy END
===== BSSGP test END