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