| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup usb
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * @brief Connection handling of calls from virtual device (implementation).
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <assert.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 | #include <usbvirt/hub.h>
|
|---|
| 39 |
|
|---|
| 40 | #include "conn.h"
|
|---|
| 41 | #include "hc.h"
|
|---|
| 42 |
|
|---|
| 43 | /** Handle data from device to function.
|
|---|
| 44 | */
|
|---|
| 45 | static void handle_data_from_device(ipc_callid_t iid, ipc_call_t icall,
|
|---|
| 46 | virtdev_connection_t *dev)
|
|---|
| 47 | {
|
|---|
| 48 | usb_endpoint_t endpoint = IPC_GET_ARG1(icall);
|
|---|
| 49 | usb_target_t target = {
|
|---|
| 50 | .address = dev->address,
|
|---|
| 51 | .endpoint = endpoint
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | dprintf("data from device %d [%d.%d]", dev->id,
|
|---|
| 55 | target.address, target.endpoint);
|
|---|
| 56 |
|
|---|
| 57 | size_t len;
|
|---|
| 58 | void * buffer;
|
|---|
| 59 | int rc = async_data_write_accept(&buffer, false,
|
|---|
| 60 | 1, USB_MAX_PAYLOAD_SIZE,
|
|---|
| 61 | 0, &len);
|
|---|
| 62 |
|
|---|
| 63 | if (rc != EOK) {
|
|---|
| 64 | ipc_answer_0(iid, rc);
|
|---|
| 65 | return;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | rc = hc_fillin_transaction_from_device(USB_TRANSFER_INTERRUPT, target, buffer, len);
|
|---|
| 69 |
|
|---|
| 70 | ipc_answer_0(iid, rc);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | /** Connection handler for communcation with virtual device.
|
|---|
| 74 | *
|
|---|
| 75 | * @param phone_hash Incoming phone hash.
|
|---|
| 76 | * @param dev Virtual device handle.
|
|---|
| 77 | */
|
|---|
| 78 | void connection_handler_device(ipcarg_t phone_hash, virtdev_connection_t *dev)
|
|---|
| 79 | {
|
|---|
| 80 | assert(dev != NULL);
|
|---|
| 81 |
|
|---|
| 82 | dprintf("phone%#x: virtual device %d connected [%d]",
|
|---|
| 83 | phone_hash, dev->id, dev->address);
|
|---|
| 84 |
|
|---|
| 85 | while (true) {
|
|---|
| 86 | ipc_callid_t callid;
|
|---|
| 87 | ipc_call_t call;
|
|---|
| 88 |
|
|---|
| 89 | callid = async_get_call(&call);
|
|---|
| 90 |
|
|---|
| 91 | switch (IPC_GET_METHOD(call)) {
|
|---|
| 92 | case IPC_M_PHONE_HUNGUP:
|
|---|
| 93 | ipc_hangup(dev->phone);
|
|---|
| 94 | ipc_answer_0(callid, EOK);
|
|---|
| 95 | dprintf("phone%#x: device %d [%d] hang-up",
|
|---|
| 96 | phone_hash, dev->id, dev->address);
|
|---|
| 97 | return;
|
|---|
| 98 |
|
|---|
| 99 | case IPC_M_CONNECT_TO_ME:
|
|---|
| 100 | ipc_answer_0(callid, ELIMIT);
|
|---|
| 101 | break;
|
|---|
| 102 |
|
|---|
| 103 | case IPC_M_USBVIRT_DATA_FROM_DEVICE:
|
|---|
| 104 | handle_data_from_device(callid, call, dev);
|
|---|
| 105 | break;
|
|---|
| 106 |
|
|---|
| 107 | default:
|
|---|
| 108 | ipc_answer_0(callid, EINVAL);
|
|---|
| 109 | break;
|
|---|
| 110 | }
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | /**
|
|---|
| 115 | * @}
|
|---|
| 116 | */
|
|---|