[21580dd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
| 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 packet
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
[14f1db0] | 34 | * Packet client interface implementation for remote modules.
|
---|
[21580dd] | 35 | * @see packet_client.h
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <async.h>
|
---|
| 39 | #include <errno.h>
|
---|
[c5b59ce] | 40 | #include <err.h>
|
---|
[21580dd] | 41 | #include <ipc/ipc.h>
|
---|
[d52fbaf] | 42 | #include <ipc/packet.h>
|
---|
[21580dd] | 43 | #include <sys/mman.h>
|
---|
| 44 |
|
---|
[849ed54] | 45 | #include <net_messages.h>
|
---|
[0a866eeb] | 46 | #include <packet_client.h>
|
---|
| 47 | #include <packet_remote.h>
|
---|
| 48 |
|
---|
[849ed54] | 49 | #include <packet/packet.h>
|
---|
| 50 | #include <packet/packet_header.h>
|
---|
[21580dd] | 51 |
|
---|
[14f1db0] | 52 | /** Obtain the packet from the packet server as the shared memory block.
|
---|
| 53 | *
|
---|
| 54 | * Create the local packet mapping as well.
|
---|
| 55 | *
|
---|
| 56 | * @param[in] phone The packet server module phone.
|
---|
| 57 | * @param[out] packet The packet reference pointer to store the received
|
---|
| 58 | * packet reference.
|
---|
| 59 | * @param[in] packet_id The packet identifier.
|
---|
| 60 | * @param[in] size The packet total size in bytes.
|
---|
| 61 | *
|
---|
| 62 | * @return EOK on success.
|
---|
| 63 | * @return Other error codes as defined for the pm_add() function.
|
---|
| 64 | * @return Other error codes as defined for the async_share_in_start() function.
|
---|
| 65 | *
|
---|
[21580dd] | 66 | */
|
---|
[2fa0ad9] | 67 | static int
|
---|
| 68 | packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size)
|
---|
| 69 | {
|
---|
[21580dd] | 70 | ERROR_DECLARE;
|
---|
[14f1db0] | 71 |
|
---|
[aadf01e] | 72 | ipc_call_t answer;
|
---|
[14f1db0] | 73 | aid_t message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
|
---|
[2fa0ad9] | 74 |
|
---|
[aadf01e] | 75 | *packet = (packet_t) as_get_mappable_page(size);
|
---|
[7c8267b] | 76 | if (ERROR_OCCURRED(async_share_in_start_0_0(phone, *packet, size)) ||
|
---|
| 77 | ERROR_OCCURRED(pm_add(*packet))) {
|
---|
[aadf01e] | 78 | munmap(*packet, size);
|
---|
| 79 | async_wait_for(message, NULL);
|
---|
[21580dd] | 80 | return ERROR_CODE;
|
---|
| 81 | }
|
---|
[14f1db0] | 82 |
|
---|
| 83 | ipcarg_t result;
|
---|
[aadf01e] | 84 | async_wait_for(message, &result);
|
---|
[14f1db0] | 85 |
|
---|
[21580dd] | 86 | return result;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[14f1db0] | 89 | int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id)
|
---|
| 90 | {
|
---|
[21580dd] | 91 | ERROR_DECLARE;
|
---|
[14f1db0] | 92 |
|
---|
| 93 | if (!packet)
|
---|
| 94 | return EINVAL;
|
---|
| 95 |
|
---|
| 96 | *packet = pm_find(packet_id);
|
---|
[2fa0ad9] | 97 | if (!*packet) {
|
---|
[14f1db0] | 98 | ipcarg_t size;
|
---|
| 99 |
|
---|
[2fa0ad9] | 100 | ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE,
|
---|
| 101 | packet_id, &size));
|
---|
[14f1db0] | 102 | ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size));
|
---|
| 103 | }
|
---|
[2fa0ad9] | 104 | if ((*packet)->next) {
|
---|
[14f1db0] | 105 | packet_t next;
|
---|
| 106 |
|
---|
[2fa0ad9] | 107 | return packet_translate_remote(phone, &next, (*packet)->next);
|
---|
[14f1db0] | 108 | }
|
---|
| 109 |
|
---|
| 110 | return EOK;
|
---|
| 111 | }
|
---|
[21580dd] | 112 |
|
---|
[14f1db0] | 113 | packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
|
---|
| 114 | size_t max_prefix, size_t max_suffix)
|
---|
| 115 | {
|
---|
| 116 | ERROR_DECLARE;
|
---|
| 117 |
|
---|
[7fb2ce3] | 118 | ipcarg_t packet_id;
|
---|
[8b901f9] | 119 | ipcarg_t size;
|
---|
[14f1db0] | 120 |
|
---|
[2fa0ad9] | 121 | if (ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4,
|
---|
| 122 | max_content, addr_len, max_prefix, max_suffix, &packet_id, &size)))
|
---|
[21580dd] | 123 | return NULL;
|
---|
[14f1db0] | 124 |
|
---|
| 125 |
|
---|
| 126 | packet_t packet = pm_find(packet_id);
|
---|
| 127 | if (!packet) {
|
---|
[2fa0ad9] | 128 | if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id,
|
---|
| 129 | size)))
|
---|
[21580dd] | 130 | return NULL;
|
---|
| 131 | }
|
---|
[14f1db0] | 132 |
|
---|
[21580dd] | 133 | return packet;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[14f1db0] | 136 | packet_t packet_get_1_remote(int phone, size_t content)
|
---|
| 137 | {
|
---|
[21580dd] | 138 | ERROR_DECLARE;
|
---|
[14f1db0] | 139 |
|
---|
[aadf01e] | 140 | ipcarg_t packet_id;
|
---|
| 141 | ipcarg_t size;
|
---|
[14f1db0] | 142 |
|
---|
| 143 | if (ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content,
|
---|
| 144 | &packet_id, &size)))
|
---|
[21580dd] | 145 | return NULL;
|
---|
[14f1db0] | 146 |
|
---|
| 147 | packet_t packet = pm_find(packet_id);
|
---|
| 148 | if (!packet) {
|
---|
[2fa0ad9] | 149 | if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id,
|
---|
| 150 | size)))
|
---|
[21580dd] | 151 | return NULL;
|
---|
| 152 | }
|
---|
[14f1db0] | 153 |
|
---|
[21580dd] | 154 | return packet;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[14f1db0] | 157 | void pq_release_remote(int phone, packet_id_t packet_id)
|
---|
| 158 | {
|
---|
[aadf01e] | 159 | async_msg_1(phone, NET_PACKET_RELEASE, packet_id);
|
---|
[21580dd] | 160 | }
|
---|
| 161 |
|
---|
| 162 | /** @}
|
---|
| 163 | */
|
---|