[PATCH i-g-t v5 2/3] tools/intel_hdcp: Add interactive menu mode to tool
Santhosh Reddy Guddati
santhosh.reddy.guddati at intel.com
Fri Aug 1 06:47:00 UTC 2025
Introduce text based menu mode for hdcp operations
and update command line options
v2: Add cleanup() at the end of main to clean resources.
Signed-off-by: Santhosh Reddy Guddati <santhosh.reddy.guddati at intel.com>
---
tools/intel_hdcp.c | 119 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 113 insertions(+), 6 deletions(-)
diff --git a/tools/intel_hdcp.c b/tools/intel_hdcp.c
index b9e91276f..d9496050a 100644
--- a/tools/intel_hdcp.c
+++ b/tools/intel_hdcp.c
@@ -80,7 +80,6 @@ static void igt_output_set_hdcp(data_t *data, igt_output_t *output, bool enable)
igt_plane_set_fb(primary, NULL);
igt_remove_fb(data->fd, &data->red);
- igt_output_set_pipe(output, PIPE_NONE);
igt_display_commit2(display, COMMIT_ATOMIC);
}
@@ -162,6 +161,23 @@ static void get_hdcp_info(data_t *data)
drmModeFreeResources(res);
}
+static void wait_for_keypress(void)
+{
+ printf("Press Enter to continue...");
+ fflush(stdout);
+ while (getchar() != '\n');
+}
+
+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 +185,74 @@ 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();
+ fflush(stdout);
+
+ 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);
+ wait_for_keypress();
+ break;
+
+ case 2:
+ printf("\n--- Enable HDCP ---\n");
+ get_hdcp_info(data);
+ printf("\nEnter connector ID to enable HDCP: ");
+ fflush(stdout);
+ 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);
+ }
+ wait_for_keypress();
+ break;
+
+ case 3:
+ printf("\n--- Disable HDCP ---\n");
+ get_hdcp_info(data);
+ printf("\nEnter connector ID to disable HDCP: ");
+ fflush(stdout);
+ 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);
+ }
+ wait_for_keypress();
+ break;
+
+ case 4:
+ printf("Exiting...\n");
+ return;
+
+ default:
+ printf("Invalid choice. Please try again.\n");
+ wait_for_keypress();
+ break;
+ }
+ }
+}
+
+static void test_cleanup(data_t *data)
+{
+ igt_display_reset(&data->display);
+ igt_display_commit2(&data->display, COMMIT_ATOMIC);
}
static void test_init(data_t *data)
@@ -180,28 +264,38 @@ static void test_init(data_t *data)
}
igt_display_require(&data->display, data->fd);
igt_display_require_output(&data->display);
+
+ igt_display_reset(&data->display);
+ igt_display_commit2(&data->display, COMMIT_ATOMIC);
}
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;
+ test_cleanup(&data);
+ return 0;
case 'e':
if (!optarg) {
fprintf(stderr, "Missing connector ID for enable\n");
@@ -209,19 +303,32 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
set_hdcp(&data, atoi(optarg), true);
- break;
+ test_cleanup(&data);
+ 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);
+ test_cleanup(&data);
+ return 0;
+ case 'm':
+ menu_mode = true;
break;
case 'h':
default:
print_usage();
- break;
+ test_cleanup(&data);
+ return (option == 'h') ? 0 : 1;
}
}
+
+ if (menu_mode)
+ interactive_menu(&data);
+
+ test_cleanup(&data);
+
+ return 0;
}
--
2.34.1
More information about the igt-dev
mailing list