implement support for 3-digit MNC with leading zeros

Add 3-digit flags and use the new RAI and LAI API from libosmocore throughout
the code base to be able to handle an MNC < 100 that has three digits (leading
zeros).

Note that in gbproxy_test.ok, 0-0 changes to 000-000 instead of 000-00, because
the parsed ra buffer is 000000 which results in 000-000, while 00f000 would
result in 000-00. IOW this is expected.

Change-Id: I7437dfaa586689e2bef0d4be6537e5577a8f6c26
diff --git a/src/gprs/gb_proxy_vty.c b/src/gprs/gb_proxy_vty.c
index 25ef756..423c582 100644
--- a/src/gprs/gb_proxy_vty.c
+++ b/src/gprs/gb_proxy_vty.c
@@ -71,9 +71,7 @@
 	gsm48_parse_ra(&raid, peer->ra);
 
 	vty_out(vty, "NSEI %5u, PTP-BVCI %5u, "
-		"RAI %u-%u-%u-%u",
-		peer->nsei, peer->bvci,
-		raid.mcc, raid.mnc, raid.lac, raid.rac);
+		"RAI %s", peer->nsei, peer->bvci, osmo_rai_name(&raid));
 	if (peer->blocked)
 		vty_out(vty, " [BVC-BLOCKED]");
 
@@ -89,12 +87,12 @@
 	vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
 		VTY_NEWLINE);
 
-	if (g_cfg->core_mcc > 0)
-		vty_out(vty, " core-mobile-country-code %d%s",
-			g_cfg->core_mcc, VTY_NEWLINE);
-	if (g_cfg->core_mnc > 0)
-		vty_out(vty, " core-mobile-network-code %d%s",
-			g_cfg->core_mnc, VTY_NEWLINE);
+	if (g_cfg->core_plmn.mcc > 0)
+		vty_out(vty, " core-mobile-country-code %s%s",
+			osmo_mcc_name(g_cfg->core_plmn.mcc), VTY_NEWLINE);
+	if (g_cfg->core_plmn.mnc > 0)
+		vty_out(vty, " core-mobile-network-code %s%s",
+			osmo_mnc_name(g_cfg->core_plmn.mnc, g_cfg->core_plmn.mnc_3_digits), VTY_NEWLINE);
 
 	for (match_id = 0; match_id < ARRAY_SIZE(g_cfg->matches); ++match_id) {
 		struct gbproxy_match *match = &g_cfg->matches[match_id];
@@ -170,7 +168,14 @@
       "core-mobile-network-code <1-999>",
       GBPROXY_CORE_MNC_STR "NCC value\n")
 {
-	g_cfg->core_mnc = atoi(argv[0]);
+	uint16_t mnc;
+	bool mnc_3_digits;
+	if (osmo_mnc_from_str(argv[0], &mnc, &mnc_3_digits)) {
+		vty_out(vty, "%% Invalid MNC: %s%s", argv[0], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+	g_cfg->core_plmn.mnc = mnc;
+	g_cfg->core_plmn.mnc_3_digits = mnc_3_digits;
 	return CMD_SUCCESS;
 }
 
@@ -179,7 +184,8 @@
       "no core-mobile-network-code",
       NO_STR GBPROXY_CORE_MNC_STR)
 {
-	g_cfg->core_mnc = 0;
+	g_cfg->core_plmn.mnc = 0;
+	g_cfg->core_plmn.mnc_3_digits = false;
 	return CMD_SUCCESS;
 }
 
@@ -190,7 +196,7 @@
       "core-mobile-country-code <1-999>",
       GBPROXY_CORE_MCC_STR "MCC value\n")
 {
-	g_cfg->core_mcc = atoi(argv[0]);
+	g_cfg->core_plmn.mcc = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -199,7 +205,7 @@
       "no core-mobile-country-code",
       NO_STR GBPROXY_CORE_MCC_STR)
 {
-	g_cfg->core_mcc = 0;
+	g_cfg->core_plmn.mcc = 0;
 	return CMD_SUCCESS;
 }