[PATCH i-g-t v4 2/2] tools/intel_hdcp: Add interactive menu mode to tool

Santhosh Reddy Guddati santhosh.reddy.guddati at intel.com
Mon Jul 14 17:42:45 UTC 2025


Introduce text based menu mode for hdcp operations
and update command line options

Signed-off-by: Santhosh Reddy Guddati <santhosh.reddy.guddati at intel.com>
---
 tools/intel_hdcp.c | 106 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 101 insertions(+), 5 deletions(-)

diff --git a/tools/intel_hdcp.c b/tools/intel_hdcp.c
index b9e91276f..664234581 100644
--- a/tools/intel_hdcp.c
+++ b/tools/intel_hdcp.c
@@ -162,6 +162,25 @@ static void get_hdcp_info(data_t *data)
 	drmModeFreeResources(res);
 }
 
+static void wait_for_keypress(void)
+{
+	int c;
+
+	do {
+		c = getchar();
+	} while (c != '\n' && c != EOF);
+}
+
+static void print_menu(void)
+{
+	printf("\n=== Intel HDCP Tool ===\n");
+	printf("1. Get HDCP Information\n");
+	printf("2. Enable HDCP on connector\n");
+	printf("3. Disable HDCP on connector\n");
+	printf("4. Exit\n");
+	printf("Enter your choice: ");
+}
+
 static void print_usage(void)
 {
 	fprintf(stderr, "Usage: intel_hdcp [OPTIONS]\n");
@@ -169,6 +188,69 @@ static void print_usage(void)
 	fprintf(stderr, "-i,	--info		Get HDCP Information\n");
 	fprintf(stderr, "-e,	--enable	Enable HDCP on the specified connector id\n");
 	fprintf(stderr, "-d,	--disable	Disable HDCP on the specified connector id\n");
+	fprintf(stderr, "-m,	--menu		Interactive menu mode (default if no options)\n");
+}
+
+static void interactive_menu(data_t *data)
+{
+	int choice, connector_id;
+	char input[256];
+
+	while (1) {
+		print_menu();
+
+		if (fgets(input, sizeof(input), stdin)) {
+			printf("\nExiting...\n");
+			break;
+		}
+
+		choice = atoi(input);
+
+		switch (choice) {
+		case 1:
+			printf("\n--- HDCP Information ---\n");
+			get_hdcp_info(data);
+			printf("\nPress Any Key to continue...");
+			wait_for_keypress();
+			break;
+
+		case 2:
+			printf("\n--- Enable HDCP ---\n");
+			get_hdcp_info(data);
+			printf("\nEnter connector ID to enable HDCP: ");
+			if (!fgets(input, sizeof(input), stdin)) {
+				connector_id = atoi(input);
+				printf("Enabling HDCP on connector %d...\n", connector_id);
+				set_hdcp(data, connector_id, true);
+			}
+			printf("\nPress Any Key to continue...");
+			wait_for_keypress();
+			break;
+
+		case 3:
+			printf("\n--- Disable HDCP ---\n");
+			get_hdcp_info(data);
+			printf("\nEnter connector ID to disable HDCP: ");
+			if (!fgets(input, sizeof(input), stdin)) {
+				connector_id = atoi(input);
+				printf("Disabling HDCP on connector %d...\n", connector_id);
+				set_hdcp(data, connector_id, false);
+			}
+			printf("\nPress Enter to continue...");
+			wait_for_keypress();
+			break;
+
+		case 4:
+			printf("Exiting...\n");
+			return;
+
+		default:
+			printf("Invalid choice. Please try again.\n");
+			printf("Press Enter to continue...");
+			wait_for_keypress();
+			break;
+		}
+	}
 }
 
 static void test_init(data_t *data)
@@ -186,22 +268,28 @@ int main(int argc, char **argv)
 {
 	data_t data;
 	int option;
-	static const char optstr[] = "hied:";
+	bool menu_mode = false;
+	static const char optstr[] = "hied:m";
 	struct option long_opts[] = {
 		{"help",	no_argument,		NULL,	'h'},
 		{"info",	no_argument,		NULL,	'i'},
 		{"enable",	required_argument,	NULL,	'e'},
 		{"disable",	required_argument,	NULL,	'd'},
+		{"menu",	no_argument,		NULL,	'm'},
 		{NULL,		0,			NULL,	 0 }
 	};
 
 	test_init(&data);
 
+	/* If no arguments provided, default to menu mode */
+	if (argc == 1)
+		menu_mode = true;
+
 	while ((option = getopt_long(argc, argv, optstr, long_opts, NULL)) != -1) {
 		switch (option) {
 		case 'i':
 			get_hdcp_info(&data);
-			break;
+			return 0;
 		case 'e':
 			if (!optarg) {
 				fprintf(stderr, "Missing connector ID for enable\n");
@@ -209,19 +297,27 @@ int main(int argc, char **argv)
 				exit(EXIT_FAILURE);
 			}
 			set_hdcp(&data, atoi(optarg), true);
-			break;
+			return 0;
 		case 'd':
 			if (!optarg) {
-				fprintf(stderr, "Missing connector ID for enable\n");
+				fprintf(stderr, "Missing connector ID for disable\n");
 				print_usage();
 				exit(EXIT_FAILURE);
 			}
 			set_hdcp(&data, atoi(optarg), false);
+			return 0;
+		case 'm':
+			menu_mode = true;
 			break;
 		case 'h':
 		default:
 			print_usage();
-			break;
+			return (option == 'h') ? 0 : 1;
 		}
 	}
+
+	if (menu_mode)
+		interactive_menu(&data);
+
+	return 0;
 }
-- 
2.34.1



More information about the igt-dev mailing list