Index: uspace/lib/usbhid/src/hidiface.c
===================================================================
--- uspace/lib/usbhid/src/hidiface.c	(revision 266fcd8c981896a0b7c0c891dd44612adb7e6f96)
+++ uspace/lib/usbhid/src/hidiface.c	(revision 79ae36ddc409577eb0da3750b3a7280e034566a2)
@@ -43,20 +43,25 @@
 /** Ask for event array length.
  *
- * @param dev_phone Opened phone to DDF device providing USB HID interface.
+ * @param dev_sess Session to DDF device providing USB HID interface.
+ *
  * @return Number of usages returned or negative error code.
- */
-int usbhid_dev_get_event_length(int dev_phone, size_t *size)
-{
-	if (dev_phone < 0) {
-		return EINVAL;
-	}
-
+ *
+ */
+int usbhid_dev_get_event_length(async_sess_t *dev_sess, size_t *size)
+{
+	if (!dev_sess)
+		return EINVAL;
+	
+	async_exch_t *exch = async_exchange_begin(dev_sess);
+	
 	sysarg_t len;
-	int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE),
+	int rc = async_req_1_1(exch, DEV_IFACE_ID(USBHID_DEV_IFACE),
 	    IPC_M_USBHID_GET_EVENT_LENGTH, &len);
+	
+	async_exchange_end(exch);
+	
 	if (rc == EOK) {
-		if (size != NULL) {
+		if (size != NULL)
 			*size = (size_t) len;
-		}
 	}
 	
@@ -66,49 +71,52 @@
 /** Request for next event from HID device.
  *
- * @param[in] dev_phone Opened phone to DDF device providing USB HID interface.
+ * @param[in]  dev_sess    Session to DDF device providing USB HID interface.
  * @param[out] usage_pages Where to store usage pages.
- * @param[out] usages Where to store usages (actual data).
- * @param[in] usage_count Length of @p usage_pages and @p usages buffer
- *	(in items, not bytes).
+ * @param[out] usages      Where to store usages (actual data).
+ * @param[in]  usage_count Length of @p usage_pages and @p usages buffer
+ *                         (in items, not bytes).
  * @param[out] actual_usage_count Number of usages actually returned by the
- *	device driver.
- * @param[in] flags Flags (see USBHID_IFACE_FLAG_*).
+ *                                device driver.
+ * @param[in] flags        Flags (see USBHID_IFACE_FLAG_*).
+ *
  * @return Error code.
- */
-int usbhid_dev_get_event(int dev_phone, uint8_t *buf, 
+ *
+ */
+int usbhid_dev_get_event(async_sess_t *dev_sess, uint8_t *buf,
     size_t size, size_t *actual_size, int *event_nr, unsigned int flags)
 {
-	if (dev_phone < 0) {
-		return EINVAL;
-	}
-	if ((buf == NULL)) {
-		return ENOMEM;
-	}
-	if (size == 0) {
-		return EINVAL;
-	}
-	
-//	if (size == 0) {
-//		return EOK;
-//	}
-
+	if (!dev_sess)
+		return EINVAL;
+	
+	if ((buf == NULL))
+		return ENOMEM;
+	
+	if (size == 0)
+		return EINVAL;
+	
 	size_t buffer_size =  size;
 	uint8_t *buffer = malloc(buffer_size);
-	if (buffer == NULL) {
-		return ENOMEM;
-	}
-
+	if (buffer == NULL)
+		return ENOMEM;
+	
+	async_exch_t *exch = async_exchange_begin(dev_sess);
+	
 	ipc_call_t opening_request_call;
-	aid_t opening_request = async_send_2(dev_phone,
+	aid_t opening_request = async_send_2(exch,
 	    DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT,
 	    flags, &opening_request_call);
+	
 	if (opening_request == 0) {
+		async_exchange_end(exch);
 		free(buffer);
 		return ENOMEM;
 	}
-
+	
 	ipc_call_t data_request_call;
-	aid_t data_request = async_data_read(dev_phone, buffer, buffer_size,
+	aid_t data_request = async_data_read(exch, buffer, buffer_size,
 	    &data_request_call);
+	
+	async_exchange_end(exch);
+	
 	if (data_request == 0) {
 		async_wait_for(opening_request, NULL);
@@ -116,110 +124,111 @@
 		return ENOMEM;
 	}
-
+	
 	sysarg_t data_request_rc;
 	sysarg_t opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
-
+	
 	if (data_request_rc != EOK) {
 		/* Prefer return code of the opening request. */
-		if (opening_request_rc != EOK) {
+		if (opening_request_rc != EOK)
 			return (int) opening_request_rc;
-		} else {
+		else
 			return (int) data_request_rc;
-		}
-	}
-
-	if (opening_request_rc != EOK) {
+	}
+	
+	if (opening_request_rc != EOK)
 		return (int) opening_request_rc;
-	}
-
+	
 	size_t act_size = IPC_GET_ARG2(data_request_call);
-
+	
 	/* Copy the individual items. */
 	memcpy(buf, buffer, act_size);
-//	memcpy(usages, buffer + items, items * sizeof(int32_t));
-
-	if (actual_size != NULL) {
+	
+	if (actual_size != NULL)
 		*actual_size = act_size;
-	}
-	
-	if (event_nr != NULL) {
+	
+	if (event_nr != NULL)
 		*event_nr = IPC_GET_ARG1(opening_request_call);
-	}
-
+	
 	return EOK;
 }
 
-
-int usbhid_dev_get_report_descriptor_length(int dev_phone, size_t *size)
-{
-	if (dev_phone < 0) {
-		return EINVAL;
-	}
-
+int usbhid_dev_get_report_descriptor_length(async_sess_t *dev_sess,
+    size_t *size)
+{
+	if (!dev_sess)
+		return EINVAL;
+	
+	async_exch_t *exch = async_exchange_begin(dev_sess);
+	
 	sysarg_t arg_size;
-	int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE),
+	int rc = async_req_1_1(exch, DEV_IFACE_ID(USBHID_DEV_IFACE),
 	    IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size);
+	
+	async_exchange_end(exch);
+	
 	if (rc == EOK) {
-		if (size != NULL) {
+		if (size != NULL)
 			*size = (size_t) arg_size;
-		}
-	}
+	}
+	
 	return rc;
 }
 
-int usbhid_dev_get_report_descriptor(int dev_phone, uint8_t *buf, size_t size, 
-    size_t *actual_size)
-{
-	if (dev_phone < 0) {
-		return EINVAL;
-	}
-	if ((buf == NULL)) {
-		return ENOMEM;
-	}
-	if (size == 0) {
-		return EINVAL;
-	}
-
-	aid_t opening_request = async_send_1(dev_phone,
+int usbhid_dev_get_report_descriptor(async_sess_t *dev_sess, uint8_t *buf,
+    size_t size, size_t *actual_size)
+{
+	if (!dev_sess)
+		return EINVAL;
+	
+	if ((buf == NULL))
+		return ENOMEM;
+	
+	if (size == 0)
+		return EINVAL;
+	
+	async_exch_t *exch = async_exchange_begin(dev_sess);
+	
+	aid_t opening_request = async_send_1(exch,
 	    DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR,
 	    NULL);
 	if (opening_request == 0) {
-		return ENOMEM;
-	}
-
+		async_exchange_end(exch);
+		return ENOMEM;
+	}
+	
 	ipc_call_t data_request_call;
-	aid_t data_request = async_data_read(dev_phone, buf, size,
+	aid_t data_request = async_data_read(exch, buf, size,
 	    &data_request_call);
+	
+	async_exchange_end(exch);
+	
 	if (data_request == 0) {
 		async_wait_for(opening_request, NULL);
 		return ENOMEM;
 	}
-
+	
 	sysarg_t data_request_rc;
 	sysarg_t opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
-
+	
 	if (data_request_rc != EOK) {
 		/* Prefer return code of the opening request. */
-		if (opening_request_rc != EOK) {
+		if (opening_request_rc != EOK)
 			return (int) opening_request_rc;
-		} else {
+		else
 			return (int) data_request_rc;
-		}
-	}
-
-	if (opening_request_rc != EOK) {
+	}
+	
+	if (opening_request_rc != EOK)
 		return (int) opening_request_rc;
-	}
-
+	
 	size_t act_size = IPC_GET_ARG2(data_request_call);
-
-	if (actual_size != NULL) {
+	
+	if (actual_size != NULL)
 		*actual_size = act_size;
-	}
-
+	
 	return EOK;
 }
