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).

Depends: Id2240f7f518494c9df6c8bda52c0d5092f90f221 (libosmocore),
         Ib7176b1d65a03b76f41f94bc9d3293a8a07d24c6 (libosmocore)
Change-Id: I82f0016d9512ee8722a3489a3cb4b6c704a271fc
diff --git a/src/libmsc/a_iface_bssap.c b/src/libmsc/a_iface_bssap.c
index 224c5c9..7b86764 100644
--- a/src/libmsc/a_iface_bssap.c
+++ b/src/libmsc/a_iface_bssap.c
@@ -263,9 +263,7 @@
 		struct gsm48_loc_area_id lai;
 		uint16_t ci;
 	} __attribute__ ((packed)) lai_ci;
-	uint16_t mcc;
-	uint16_t mnc;
-	uint16_t lac;
+	struct osmo_location_area_id lai;
 	uint8_t data_length;
 	const uint8_t *data;
 	int rc;
@@ -301,18 +299,15 @@
 		     "Unable to parse element CELL IDENTIFIER (wrong cell identification discriminator) -- discarding message!\n");
 		return -EINVAL;
 	}
-	if (gsm48_decode_lai(&lai_ci.lai, &mcc, &mnc, &lac) != 0) {
-		LOGP(DBSSAP, LOGL_ERROR,
-		     "Unable to parse element CELL IDENTIFIER (lai decoding failed) -- discarding message!\n");
-		return -EINVAL;
-	}
+	gsm48_decode_lai2(&lai_ci.lai, &lai);
+	/* FIXME: Actually compare the MCC-MNC to the local network config?? */
 
 	/* Parse Layer 3 Information element */
 	msg->l3h = (uint8_t*)TLVP_VAL(tp, GSM0808_IE_LAYER_3_INFORMATION);
 	msgb_l3trim(msg, TLVP_LEN(tp, GSM0808_IE_LAYER_3_INFORMATION));
 
 	/* Create new subscriber context */
-	conn = subscr_conn_allocate_a(a_conn_info, network, lac, scu, a_conn_info->conn_id);
+	conn = subscr_conn_allocate_a(a_conn_info, network, lai.lac, scu, a_conn_info->conn_id);
 
 	/* Handover location update to the MSC code */
 	rc = msc_compl_l3(conn, msg, 0);
diff --git a/src/libmsc/gsm_04_08.c b/src/libmsc/gsm_04_08.c
index b928171..18f8412 100644
--- a/src/libmsc/gsm_04_08.c
+++ b/src/libmsc/gsm_04_08.c
@@ -222,15 +222,17 @@
 	struct gsm48_hdr *gh;
 	struct gsm48_loc_area_id *lai;
 	uint8_t *mid;
+	struct osmo_location_area_id laid = {
+		.plmn = conn->network->plmn,
+		.lac = conn->lac,
+	};
 
 	gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
 	gh->proto_discr = GSM48_PDISC_MM;
 	gh->msg_type = GSM48_MT_MM_LOC_UPD_ACCEPT;
 
 	lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
-	gsm48_generate_lai(lai, conn->network->country_code,
-			   conn->network->network_code,
-			   conn->lac);
+	gsm48_generate_lai2(lai, &laid);
 
 	if (send_tmsi == GSM_RESERVED_TMSI) {
 		/* we did not allocate a TMSI to the MS, so we need to
@@ -381,10 +383,8 @@
 		break;
 	}
 
-	gsm48_decode_lai(&lu->lai, &old_lai.plmn.mcc,
-			 &old_lai.plmn.mnc, &old_lai.lac);
-	new_lai.plmn.mcc = conn->network->country_code;
-	new_lai.plmn.mnc = conn->network->network_code;
+	gsm48_decode_lai2(&lu->lai, &old_lai);
+	new_lai.plmn = conn->network->plmn;
 	new_lai.lac = conn->lac;
 	DEBUGP(DMM, "LU/new-LAC: %u/%u\n", old_lai.lac, new_lai.lac);
 
@@ -701,8 +701,7 @@
 	bool is_utran;
 	int rc;
 
-	lai.plmn.mcc = conn->network->country_code;
-	lai.plmn.mnc = conn->network->network_code;
+	lai.plmn = conn->network->plmn;
 	lai.lac = conn->lac;
 
 	DEBUGP(DMM, "<- CM SERVICE REQUEST ");
@@ -1152,8 +1151,7 @@
 	struct osmo_location_area_id lai;
 	bool is_utran;
 
-	lai.plmn.mcc = conn->network->country_code;
-	lai.plmn.mnc = conn->network->network_code;
+	lai.plmn = conn->network->plmn;
 	lai.lac = conn->lac;
 
 	resp = (struct gsm48_pag_resp *) &gh->data[0];
diff --git a/src/libmsc/msc_vty.c b/src/libmsc/msc_vty.c
index ce608ba..503ae68 100644
--- a/src/libmsc/msc_vty.c
+++ b/src/libmsc/msc_vty.c
@@ -183,8 +183,9 @@
 	int i;
 
 	vty_out(vty, "network%s", VTY_NEWLINE);
-	vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
-	vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
+	vty_out(vty, " network country code %s%s", osmo_mcc_name(gsmnet->plmn.mcc), VTY_NEWLINE);
+	vty_out(vty, " mobile network code %s%s",
+		osmo_mnc_name(gsmnet->plmn.mnc, gsmnet->plmn.mnc_3_digits), VTY_NEWLINE);
 	vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
 	vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
 	vty_out(vty, " encryption a5");