[MGW NAT] Implement 'nationalize' as inverse operation of 'internationalize'

This is required for MO calls from MSC -> MGW, where the called number
has a international type number and needs to become a national one.
diff --git a/src/mgw_nat.erl b/src/mgw_nat.erl
index 856fc26..adf78f1 100644
--- a/src/mgw_nat.erl
+++ b/src/mgw_nat.erl
@@ -147,6 +147,14 @@
 		_ ->
 			PartyNum
 	end;
+% Mangle IAM from MSC -> STP
+mangle_isup_number(from_msc, ?ISUP_MSGT_IAM, NumType, PartyNum) ->
+	case NumType of
+		?ISUP_PAR_CALLED_P_NUM ->
+			isup_party_nationalize(PartyNum, ?INTERN_PFX);
+		_ ->
+			PartyNum
+	end;
 % default case: no rewrite
 mangle_isup_number(from_msc, _, _, PartyNum) ->
 	PartyNum.
@@ -178,3 +186,24 @@
 			NatureOut = Nature
 	end,
 	PartyNum#party_number{phone_number = DigitsOut, nature_of_addr_ind = NatureOut}.
+
+isup_party_nationalize(PartyNum, CountryCode) ->
+	#party_number{phone_number = DigitsIn, nature_of_addr_ind = Nature} = PartyNum,
+	CountryCodeLen = length(CountryCode),
+	case Nature of
+		?ISUP_ADDR_NAT_INTERNATIONAL ->
+			Pfx = lists:sublist(DigitsIn, CountryCodeLen),
+			if Pfx == CountryCode ->
+				DigitsOut = lists:sublist(DigitsIn, CountryCodeLen+1,
+							  length(DigitsIn)-CountryCodeLen),
+				NatureOut = ?ISUP_ADDR_NAT_NATIONAL,
+				io:format("Nationalize: ~p -> ~p~n", [DigitsIn, DigitsOut]);
+			   true ->
+				DigitsOut = DigitsIn,
+				NatureOut = Nature
+			end;
+		_ ->
+			DigitsOut = DigitsIn,
+			NatureOut = Nature
+	end,
+	PartyNum#party_number{phone_number = DigitsOut, nature_of_addr_ind = NatureOut}.