Index: uspace/lib/drv/generic/driver.c
===================================================================
--- uspace/lib/drv/generic/driver.c	(revision 0d59d0e99709ef15e7ba51b20f1f96a86e8c7a45)
+++ uspace/lib/drv/generic/driver.c	(revision 1564c4b1a2bf98111c2afd867b51d67cce9139a4)
@@ -285,13 +285,12 @@
 	async_answer_0(iid, EOK);
 	
-	bool cont = true;
-	while (cont) {
+	while (true) {
 		ipc_call_t call;
 		ipc_callid_t callid = async_get_call(&call);
 		
+		if (!IPC_GET_IMETHOD(call))
+			break;
+		
 		switch (IPC_GET_IMETHOD(call)) {
-		case IPC_M_PHONE_HUNGUP:
-			cont = false;
-			continue;
 		case DRIVER_ADD_DEVICE:
 			driver_add_device(callid, &call);
@@ -303,9 +302,9 @@
 }
 
-/**
- * Generic client connection handler both for applications and drivers.
- *
- * @param drv		True for driver client, false for other clients
- *			(applications, services etc.).
+/** Generic client connection handler both for applications and drivers.
+ *
+ * @param drv True for driver client, false for other clients
+ *            (applications, services, etc.).
+ *
  */
 static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
@@ -317,5 +316,5 @@
 	devman_handle_t handle = IPC_GET_ARG2(*icall);
 	ddf_fun_t *fun = driver_get_function(&functions, handle);
-
+	
 	if (fun == NULL) {
 		printf("%s: driver_connection_gen error - no function with handle"
@@ -325,5 +324,4 @@
 	}
 	
-	
 	/*
 	 * TODO - if the client is not a driver, check whether it is allowed to
@@ -340,13 +338,11 @@
 		return;
 	
-	while (1) {
+	while (true) {
 		ipc_callid_t callid;
 		ipc_call_t call;
 		callid = async_get_call(&call);
 		sysarg_t method = IPC_GET_IMETHOD(call);
-		int iface_idx;
-		
-		switch  (method) {
-		case IPC_M_PHONE_HUNGUP:
+		
+		if (!method) {
 			/* Close device function */
 			if (fun->ops != NULL && fun->ops->close != NULL)
@@ -354,71 +350,68 @@
 			async_answer_0(callid, EOK);
 			return;
-		default:
-			/* convert ipc interface id to interface index */
-			
-			iface_idx = DEV_IFACE_IDX(method);
-			
-			if (!is_valid_iface_idx(iface_idx)) {
-				remote_handler_t *default_handler =
-				    function_get_default_handler(fun);
-				if (default_handler != NULL) {
-					(*default_handler)(fun, callid, &call);
-					break;
-				}
-				
-				/*
-				 * Function has no such interface and
-				 * default handler is not provided.
-				 */
-				printf("%s: driver_connection_gen error - "
-				    "invalid interface id %d.",
-				    driver->name, iface_idx);
-				async_answer_0(callid, ENOTSUP);
-				break;
-			}
-			
-			/* calling one of the function's interfaces */
-			
-			/* Get the interface ops structure. */
-			void *ops = function_get_ops(fun, iface_idx);
-			if (ops == NULL) {
-				printf("%s: driver_connection_gen error - ",
-				    driver->name);
-				printf("Function with handle %" PRIun " has no interface "
-				    "with id %d.\n", handle, iface_idx);
-				async_answer_0(callid, ENOTSUP);
+		}
+		
+		/* Convert ipc interface id to interface index */
+		
+		int iface_idx = DEV_IFACE_IDX(method);
+		
+		if (!is_valid_iface_idx(iface_idx)) {
+			remote_handler_t *default_handler =
+			    function_get_default_handler(fun);
+			if (default_handler != NULL) {
+				(*default_handler)(fun, callid, &call);
 				break;
 			}
 			
 			/*
-			 * Get the corresponding interface for remote request
-			 * handling ("remote interface").
+			 * Function has no such interface and
+			 * default handler is not provided.
 			 */
-			remote_iface_t *rem_iface = get_remote_iface(iface_idx);
-			assert(rem_iface != NULL);
-			
-			/* get the method of the remote interface */
-			sysarg_t iface_method_idx = IPC_GET_ARG1(call);
-			remote_iface_func_ptr_t iface_method_ptr =
-			    get_remote_method(rem_iface, iface_method_idx);
-			if (iface_method_ptr == NULL) {
-				/* The interface has not such method */
-				printf("%s: driver_connection_gen error - "
-				    "invalid interface method "
-				    "(index %" PRIun ").\n",
-				    driver->name, iface_method_idx);
-				async_answer_0(callid, ENOTSUP);
-				break;
-			}
-			
-			/*
-			 * Call the remote interface's method, which will
-			 * receive parameters from the remote client and it will
-			 * pass it to the corresponding local interface method
-			 * associated with the function by its driver.
-			 */
-			(*iface_method_ptr)(fun, ops, callid, &call);
+			printf("%s: driver_connection_gen error - "
+			    "invalid interface id %d.",
+			    driver->name, iface_idx);
+			async_answer_0(callid, ENOTSUP);
 			break;
 		}
+		
+		/* Calling one of the function's interfaces */
+		
+		/* Get the interface ops structure. */
+		void *ops = function_get_ops(fun, iface_idx);
+		if (ops == NULL) {
+			printf("%s: driver_connection_gen error - ", driver->name);
+			printf("Function with handle %" PRIun " has no interface "
+			    "with id %d.\n", handle, iface_idx);
+			async_answer_0(callid, ENOTSUP);
+			break;
+		}
+		
+		/*
+		 * Get the corresponding interface for remote request
+		 * handling ("remote interface").
+		 */
+		remote_iface_t *rem_iface = get_remote_iface(iface_idx);
+		assert(rem_iface != NULL);
+		
+		/* get the method of the remote interface */
+		sysarg_t iface_method_idx = IPC_GET_ARG1(call);
+		remote_iface_func_ptr_t iface_method_ptr =
+		    get_remote_method(rem_iface, iface_method_idx);
+		if (iface_method_ptr == NULL) {
+			/* The interface has not such method */
+			printf("%s: driver_connection_gen error - "
+			    "invalid interface method.", driver->name);
+			async_answer_0(callid, ENOTSUP);
+			break;
+		}
+		
+		/*
+		 * Call the remote interface's method, which will
+		 * receive parameters from the remote client and it will
+		 * pass it to the corresponding local interface method
+		 * associated with the function by its driver.
+		 */
+		(*iface_method_ptr)(fun, ops, callid, &call);
+		break;
 	}
 }
