00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00038 #include <async.h>
00039 #include <errno.h>
00040 #include <ipc/packet.h>
00041 #include <sys/mman.h>
00042
00043 #include <packet_client.h>
00044 #include <packet_remote.h>
00045
00046 #include <net/packet.h>
00047 #include <net/packet_header.h>
00048
00064 static int
00065 packet_return(int phone, packet_t **packet, packet_id_t packet_id, size_t size)
00066 {
00067 ipc_call_t answer;
00068 aid_t message;
00069 int rc;
00070
00071 message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
00072
00073 *packet = (packet_t *) as_get_mappable_page(size);
00074 rc = async_share_in_start_0_0(phone, *packet, size);
00075 if (rc != EOK) {
00076 munmap(*packet, size);
00077 async_wait_for(message, NULL);
00078 return rc;
00079 }
00080 rc = pm_add(*packet);
00081 if (rc != EOK) {
00082 munmap(*packet, size);
00083 async_wait_for(message, NULL);
00084 return rc;
00085 }
00086
00087 sysarg_t result;
00088 async_wait_for(message, &result);
00089
00090 return result;
00091 }
00092
00108 int packet_translate_remote(int phone, packet_t **packet, packet_id_t packet_id)
00109 {
00110 int rc;
00111
00112 if (!packet)
00113 return EINVAL;
00114
00115 *packet = pm_find(packet_id);
00116 if (!*packet) {
00117 sysarg_t size;
00118
00119 rc = async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id,
00120 &size);
00121 if (rc != EOK)
00122 return rc;
00123 rc = packet_return(phone, packet, packet_id, size);
00124 if (rc != EOK)
00125 return rc;
00126 }
00127 if ((*packet)->next) {
00128 packet_t *next;
00129
00130 return packet_translate_remote(phone, &next, (*packet)->next);
00131 }
00132
00133 return EOK;
00134 }
00135
00149 packet_t *packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
00150 size_t max_prefix, size_t max_suffix)
00151 {
00152 sysarg_t packet_id;
00153 sysarg_t size;
00154 int rc;
00155
00156 rc = async_req_4_2(phone, NET_PACKET_CREATE_4, max_content, addr_len,
00157 max_prefix, max_suffix, &packet_id, &size);
00158 if (rc != EOK)
00159 return NULL;
00160
00161
00162 packet_t *packet = pm_find(packet_id);
00163 if (!packet) {
00164 rc = packet_return(phone, &packet, packet_id, size);
00165 if (rc != EOK)
00166 return NULL;
00167 }
00168
00169 return packet;
00170 }
00171
00181 packet_t *packet_get_1_remote(int phone, size_t content)
00182 {
00183 sysarg_t packet_id;
00184 sysarg_t size;
00185 int rc;
00186
00187 rc = async_req_1_2(phone, NET_PACKET_CREATE_1, content, &packet_id,
00188 &size);
00189 if (rc != EOK)
00190 return NULL;
00191
00192 packet_t *packet = pm_find(packet_id);
00193 if (!packet) {
00194 rc = packet_return(phone, &packet, packet_id, size);
00195 if (rc != EOK)
00196 return NULL;
00197 }
00198
00199 return packet;
00200 }
00201
00212 void pq_release_remote(int phone, packet_id_t packet_id)
00213 {
00214 async_msg_1(phone, NET_PACKET_RELEASE, packet_id);
00215 }
00216