Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision 3ef91c88f73a57abf7e685d4ef082d173adbdb80)
+++ uspace/srv/hid/console/console.c	(revision a2a3763d62c2b0fb36d492a47f0f7d987c009a52)
@@ -57,4 +57,5 @@
 #include <io/style.h>
 #include <io/screenbuffer.h>
+#include <inttypes.h>
 
 #include "console.h"
@@ -67,4 +68,9 @@
 /** Interval for checking for new keyboard (1/4s). */
 #define HOTPLUG_WATCH_INTERVAL (1000 * 250)
+
+/* Kernel defines 32 but does not export it. */
+#define MAX_IPC_OUTGOING_PHONES 128
+/** To allow proper phone closing. */
+static ipc_callid_t driver_phones[MAX_IPC_OUTGOING_PHONES] = { 0 };
 
 /** Phone to the keyboard driver. */
@@ -90,4 +96,6 @@
 	                               contents and related settings. */
 } console_t;
+
+
 
 /** Array of data for virtual consoles */
@@ -401,4 +409,17 @@
 }
 
+static void close_driver_phone(ipc_callid_t hash)
+{
+	int i;
+	for (i = 0; i < MAX_IPC_OUTGOING_PHONES; i++) {
+		if (driver_phones[i] == hash) {
+			printf("Device %" PRIxn " gone.\n", hash);
+			driver_phones[i] = 0;
+			async_hangup(i);
+			return;
+		}
+	}
+}
+
 /** Handler for keyboard */
 static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
@@ -415,4 +436,5 @@
 		case IPC_M_PHONE_HUNGUP:
 			/* TODO: Handle hangup */
+			close_driver_phone(iid);
 			return;
 		case KBD_EVENT:
@@ -458,4 +480,5 @@
 		case IPC_M_PHONE_HUNGUP:
 			/* TODO: Handle hangup */
+			close_driver_phone(iid);
 			return;
 		case MEVENT_BUTTON:
@@ -715,4 +738,25 @@
 }
 
+static int async_connect_to_me_hack(int phone, sysarg_t arg1, sysarg_t arg2,
+sysarg_t arg3, async_client_conn_t client_receiver, ipc_callid_t *hash)
+{
+	sysarg_t task_hash;
+	sysarg_t phone_hash;
+	int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
+	    NULL, NULL, NULL, &task_hash, &phone_hash);
+	if (rc != EOK)
+		return rc;
+
+	if (client_receiver != NULL)
+		async_new_connection(task_hash, phone_hash, phone_hash, NULL,
+		    client_receiver);
+
+	if (hash != NULL) {
+		*hash = phone_hash;
+	}
+
+	return EOK;
+}
+
 static int connect_keyboard_or_mouse(const char *devname,
     async_client_conn_t handler, const char *path)
@@ -729,5 +773,7 @@
 	}
 	
-	int rc = async_connect_to_me(phone, SERVICE_CONSOLE, 0, 0, handler);
+	ipc_callid_t hash;
+	int rc = async_connect_to_me_hack(phone, SERVICE_CONSOLE, 0, phone,
+	    handler, &hash);
 	if (rc != EOK) {
 		printf(NAME ": " \
@@ -737,5 +783,7 @@
 	}
 	
-	printf(NAME ": found %s \"%s\".\n", devname, path);
+	driver_phones[phone] = hash;
+
+	printf(NAME ": found %s \"%s\" (%" PRIxn ").\n", devname, path, hash);
 
 	return phone;
