SS/USSD: implement an IUSE for getting RAN type(s)

Change-Id: I8d95413784b039df50a4cdcac49289060f0414c6
diff --git a/src/hlr_ussd.c b/src/hlr_ussd.c
index cc6aa8a..753e48b 100644
--- a/src/hlr_ussd.c
+++ b/src/hlr_ussd.c
@@ -320,6 +320,41 @@
 	return 0;
 }
 
+static int handle_ussd_get_ran(struct osmo_gsup_conn *conn, struct ss_session *ss,
+			       const struct osmo_gsup_message *gsup,
+			       const struct ss_request *req)
+{
+	struct hlr_subscriber subscr;
+	const char *response;
+	int rc;
+
+#define RAN_TYPE_DESC "Available RAN types: "
+
+	rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr);
+	switch (rc) {
+	case 0:
+		if (subscr.rat_types[OSMO_RAT_GERAN_A] && subscr.rat_types[OSMO_RAT_UTRAN_IU])
+			response = RAN_TYPE_DESC "GERAN-A (2G) & UTRAN-Iu (3G)";
+		else if (subscr.rat_types[OSMO_RAT_GERAN_A])
+			response = RAN_TYPE_DESC "GERAN-A (2G)";
+		else if (subscr.rat_types[OSMO_RAT_UTRAN_IU])
+			response = RAN_TYPE_DESC "UTRAN-Iu (3G)";
+		else
+			response = "No RAN types available";
+
+		rc = ss_tx_ussd_7bit(ss, true, req->invoke_id, response);
+		break;
+	case -ENOENT:
+		rc = ss_tx_error(ss, true, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER);
+		break;
+	case -EIO:
+	default:
+		rc = ss_tx_error(ss, true, GSM0480_ERR_CODE_SYSTEM_FAILURE);
+		break;
+	}
+
+	return rc;
+}
 
 static const struct hlr_iuse hlr_iuses[] = {
 	{
@@ -330,6 +365,10 @@
 		.name = "own-imsi",
 		.handle_ussd = handle_ussd_own_imsi,
 	},
+	{
+		.name = "get-ran",
+		.handle_ussd = handle_ussd_get_ran,
+	},
 };
 
 const struct hlr_iuse *iuse_find(const char *name)
diff --git a/src/hlr_vty.c b/src/hlr_vty.c
index 6706aa4..9ecf8a3 100644
--- a/src/hlr_vty.c
+++ b/src/hlr_vty.c
@@ -133,10 +133,11 @@
 #define UROUTE_STR "Routing Configuration\n"
 #define PREFIX_STR "Prefix-Matching Route\n" "USSD Prefix\n"
 
-#define INT_CHOICE "(own-msisdn|own-imsi)"
+#define INT_CHOICE "(own-msisdn|own-imsi|get-ran)"
 #define INT_STR "Internal USSD Handler\n" \
 		"Respond with subscribers' own MSISDN\n" \
-		"Respond with subscribers' own IMSI\n"
+		"Respond with subscribers' own IMSI\n" \
+		"Respond with available RAN types\n"
 
 #define EXT_STR "External USSD Handler\n" \
 		"Name of External USSD Handler (IPA CCM ID)\n"