[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
|
---|
| 34 | * Packet client interface implementation for standalone remote modules.
|
---|
| 35 | * @see packet_client.h
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <async.h>
|
---|
| 39 | #include <errno.h>
|
---|
| 40 | #include <ipc/ipc.h>
|
---|
| 41 | #include <sys/mman.h>
|
---|
| 42 |
|
---|
[849ed54] | 43 | #include <net_err.h>
|
---|
| 44 | #include <net_messages.h>
|
---|
| 45 | #include <packet/packet.h>
|
---|
| 46 | #include <packet/packet_client.h>
|
---|
| 47 | #include <packet/packet_header.h>
|
---|
| 48 | #include <packet/packet_messages.h>
|
---|
[21580dd] | 49 |
|
---|
| 50 | /** Obtains the packet from the packet server as the shared memory block.
|
---|
| 51 | * Creates the local packet mapping as well.
|
---|
| 52 | * @param[in] phone The packet server module phone.
|
---|
| 53 | * @param[out] packet The packet reference pointer to store the received packet reference.
|
---|
| 54 | * @param[in] packet_id The packet identifier.
|
---|
| 55 | * @param[in] size The packet total size in bytes.
|
---|
| 56 | * @returns EOK on success.
|
---|
| 57 | * @returns Other error codes as defined for the pm_add() function.
|
---|
| 58 | * @returns Other error codes as defined for the async_share_in_start() function.
|
---|
| 59 | */
|
---|
[aadf01e] | 60 | int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size);
|
---|
[21580dd] | 61 |
|
---|
[aadf01e] | 62 | int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){
|
---|
[21580dd] | 63 | ERROR_DECLARE;
|
---|
| 64 |
|
---|
[aadf01e] | 65 | ipcarg_t size;
|
---|
| 66 | packet_t next;
|
---|
[21580dd] | 67 |
|
---|
[aadf01e] | 68 | if(! packet){
|
---|
| 69 | return EINVAL;
|
---|
| 70 | }
|
---|
| 71 | *packet = pm_find(packet_id);
|
---|
| 72 | if(!(*packet)){
|
---|
| 73 | ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id, &size));
|
---|
| 74 | ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size));
|
---|
[21580dd] | 75 | }
|
---|
[aadf01e] | 76 | if((** packet).next){
|
---|
| 77 | return packet_translate(phone, &next, (** packet).next);
|
---|
[21580dd] | 78 | }else return EOK;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[aadf01e] | 81 | int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){
|
---|
[21580dd] | 82 | ERROR_DECLARE;
|
---|
| 83 |
|
---|
[aadf01e] | 84 | aid_t message;
|
---|
| 85 | ipc_call_t answer;
|
---|
| 86 | ipcarg_t result;
|
---|
[21580dd] | 87 |
|
---|
[aadf01e] | 88 | message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
|
---|
| 89 | *packet = (packet_t) as_get_mappable_page(size);
|
---|
| 90 | if(ERROR_OCCURRED(async_share_in_start_0_0(phone, * packet, size))
|
---|
| 91 | || ERROR_OCCURRED(pm_add(*packet))){
|
---|
| 92 | munmap(*packet, size);
|
---|
| 93 | async_wait_for(message, NULL);
|
---|
[21580dd] | 94 | return ERROR_CODE;
|
---|
| 95 | }
|
---|
[aadf01e] | 96 | async_wait_for(message, &result);
|
---|
[21580dd] | 97 | return result;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[aadf01e] | 100 | packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){
|
---|
[21580dd] | 101 | ERROR_DECLARE;
|
---|
| 102 |
|
---|
[7fb2ce3] | 103 | ipcarg_t packet_id;
|
---|
[8b901f9] | 104 | ipcarg_t size;
|
---|
[21580dd] | 105 | packet_t packet;
|
---|
| 106 |
|
---|
[aadf01e] | 107 | if(ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, &packet_id, &size))){
|
---|
[21580dd] | 108 | return NULL;
|
---|
| 109 | }
|
---|
[aadf01e] | 110 | packet = pm_find(packet_id);
|
---|
| 111 | if(! packet){
|
---|
| 112 | if(ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size))){
|
---|
[21580dd] | 113 | return NULL;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | return packet;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[aadf01e] | 119 | packet_t packet_get_1(int phone, size_t content){
|
---|
[21580dd] | 120 | ERROR_DECLARE;
|
---|
| 121 |
|
---|
[aadf01e] | 122 | ipcarg_t packet_id;
|
---|
| 123 | ipcarg_t size;
|
---|
| 124 | packet_t packet;
|
---|
[21580dd] | 125 |
|
---|
[aadf01e] | 126 | if(ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content, &packet_id, &size))){
|
---|
[21580dd] | 127 | return NULL;
|
---|
| 128 | }
|
---|
[aadf01e] | 129 | packet = pm_find(packet_id);
|
---|
| 130 | if(! packet){
|
---|
| 131 | if(ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size))){
|
---|
[21580dd] | 132 | return NULL;
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 | return packet;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[aadf01e] | 138 | void pq_release(int phone, packet_id_t packet_id){
|
---|
| 139 | async_msg_1(phone, NET_PACKET_RELEASE, packet_id);
|
---|
[21580dd] | 140 | }
|
---|
| 141 |
|
---|
| 142 | /** @}
|
---|
| 143 | */
|
---|