sms: Increment the RP Message Reference for each transaction

Each RP-DATA should have a unique msg reference. Currently 42 is
used for all of these. Remember the last reference we used and
increment it on the next SMS. Do not track if the reference is
still in use a clash is a lot less likely now. First unless SMPP
is used only one SMS is delivered at a time, second the transaction
space is a lot smaller than the one for the reference.
diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c
index 38c1a6a..692ec90 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.c
+++ b/openbsc/tests/gsm0408/gsm0408_test.c
@@ -25,6 +25,7 @@
 #include <arpa/inet.h>
 
 #include <openbsc/gsm_04_08.h>
+#include <openbsc/gsm_04_11.h>
 #include <openbsc/gsm_subscriber.h>
 #include <openbsc/debug.h>
 #include <openbsc/arfcn_range_encode.h>
@@ -448,6 +449,29 @@
 	VERIFY(f0, ==, 1);
 }
 
+static void test_gsm411_rp_ref_wrap(void)
+{
+	struct gsm_subscriber_connection conn;
+	int res;
+
+	printf("testing RP-Reference wrap\n");
+
+	memset(&conn, 0, sizeof(conn));
+	conn.next_rp_ref = 255;
+
+	res = sms_next_rp_msg_ref(&conn);
+	printf("Allocated reference: %d\n", res);
+	OSMO_ASSERT(res == 255);
+
+	res = sms_next_rp_msg_ref(&conn);
+	printf("Allocated reference: %d\n", res);
+	OSMO_ASSERT(res == 0);
+
+	res = sms_next_rp_msg_ref(&conn);
+	printf("Allocated reference: %d\n", res);
+	OSMO_ASSERT(res == 1);
+}
+
 int main(int argc, char **argv)
 {
 	osmo_init_logging(&log_info);
@@ -460,6 +484,7 @@
 	test_arfcn_filter();
 	test_print_encoding();
 	test_range_encoding();
+	test_gsm411_rp_ref_wrap();
 
 	printf("Done.\n");
 	return EXIT_SUCCESS;