Rev 4350 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4350 | Rev 4351 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup packet |
29 | /** @addtogroup packet |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * Packet client interface implementation for standalone remote modules. |
34 | * Packet client interface implementation for standalone remote modules. |
35 | * @see packet_client.h |
35 | * @see packet_client.h |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <async.h> |
38 | #include <async.h> |
39 | 39 | ||
40 | #include <ipc/ipc.h> |
40 | #include <ipc/ipc.h> |
41 | #include <sys/mman.h> |
41 | #include <sys/mman.h> |
42 | 42 | ||
43 | #include "../../err.h" |
43 | #include "../../err.h" |
44 | #include "../../messages.h" |
44 | #include "../../messages.h" |
45 | 45 | ||
46 | #include "packet.h" |
46 | #include "packet.h" |
47 | #include "packet_client.h" |
47 | #include "packet_client.h" |
48 | #include "packet_messages.h" |
48 | #include "packet_messages.h" |
49 | 49 | ||
50 | /** Obtains the packet from the packet server as the shared memory block. |
50 | /** Obtains the packet from the packet server as the shared memory block. |
51 | * Creates the local packet mapping as well. |
51 | * Creates the local packet mapping as well. |
52 | * @param phone The packet server module phone. Input parameter. |
52 | * @param phone The packet server module phone. Input parameter. |
53 | * @param packet The packet reference pointer to store the received packet reference. Output parameter. |
53 | * @param packet The packet reference pointer to store the received packet reference. Output parameter. |
54 | * @param packet_id The packet identifier. Input parameter. |
54 | * @param packet_id The packet identifier. Input parameter. |
55 | * @param size The packet total size in bytes. Input parameter. |
55 | * @param size The packet total size in bytes. Input parameter. |
56 | * @returns EOK on success. |
56 | * @returns EOK on success. |
57 | * \todo ipc_share_in_start() error? |
- | |
58 | * @returns Other error codes as defined for the pm_add() function. |
57 | * @returns Other error codes as defined for the pm_add() function. |
- | 58 | * @returns Other error codes as defined for the ipc_share_in_start() function. |
|
59 | */ |
59 | */ |
60 | int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ); |
60 | int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ); |
61 | 61 | ||
62 | int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){ |
62 | int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){ |
63 | ERROR_DECLARE; |
63 | ERROR_DECLARE; |
64 | 64 | ||
65 | unsigned int size; |
65 | unsigned int size; |
66 | 66 | ||
67 | if( ! packet ) return EINVAL; |
67 | if( ! packet ) return EINVAL; |
68 | * packet = pm_find( packet_id ); |
68 | * packet = pm_find( packet_id ); |
69 | if( * packet ) return EOK; |
69 | if( * packet ) return EOK; |
70 | ERROR_PROPAGATE( async_req_1_1( phone, NET_PACKET_GET_SIZE, packet_id, & size )); |
70 | ERROR_PROPAGATE( async_req_1_1( phone, NET_PACKET_GET_SIZE, packet_id, & size )); |
71 | return packet_return( phone, packet, packet_id, size ); |
71 | return packet_return( phone, packet, packet_id, size ); |
72 | } |
72 | } |
73 | 73 | ||
74 | int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ){ |
74 | int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ){ |
75 | ERROR_DECLARE; |
75 | ERROR_DECLARE; |
76 | 76 | ||
77 | aid_t message; |
77 | aid_t message; |
78 | ipc_call_t answer; |
78 | ipc_call_t answer; |
79 | ipcarg_t result; |
79 | ipcarg_t result; |
80 | 80 | ||
81 | message = async_send_1( phone, NET_PACKET_GET, packet_id, & answer ); |
81 | message = async_send_1( phone, NET_PACKET_GET, packet_id, & answer ); |
82 | * packet = ( packet_t ) as_get_mappable_page( size ); |
82 | * packet = ( packet_t ) as_get_mappable_page( size ); |
83 | if( ERROR_OCCURRED( ipc_share_in_start_0_0( phone, * packet, size )) |
83 | if( ERROR_OCCURRED( ipc_share_in_start_0_0( phone, * packet, size )) |
84 | || ERROR_OCCURRED( pm_add( * packet ))){ |
84 | || ERROR_OCCURRED( pm_add( * packet ))){ |
85 | munmap( * packet, size ); |
85 | munmap( * packet, size ); |
86 | async_wait_for( message, NULL ); |
86 | async_wait_for( message, NULL ); |
87 | return ERROR_CODE; |
87 | return ERROR_CODE; |
88 | } |
88 | } |
89 | async_wait_for( message, & result ); |
89 | async_wait_for( message, & result ); |
90 | return result; |
90 | return result; |
91 | } |
91 | } |
92 | 92 | ||
93 | packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){ |
93 | packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){ |
94 | ERROR_DECLARE; |
94 | ERROR_DECLARE; |
95 | 95 | ||
96 | packet_id_t packet_id; |
96 | packet_id_t packet_id; |
97 | unsigned int size; |
97 | unsigned int size; |
98 | packet_t packet; |
98 | packet_t packet; |
99 | 99 | ||
100 | if( ERROR_OCCURRED( async_req_4_2( phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, ( ipcarg_t * ) & packet_id, & size )) |
100 | if( ERROR_OCCURRED( async_req_4_2( phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, ( ipcarg_t * ) & packet_id, & size )) |
101 | || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
101 | || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
102 | return NULL; |
102 | return NULL; |
103 | } |
103 | } |
104 | return packet; |
104 | return packet; |
105 | } |
105 | } |
106 | 106 | ||
107 | packet_t packet_get_1( int phone, size_t content ){ |
107 | packet_t packet_get_1( int phone, size_t content ){ |
108 | ERROR_DECLARE; |
108 | ERROR_DECLARE; |
109 | 109 | ||
110 | packet_id_t packet_id; |
110 | packet_id_t packet_id; |
111 | unsigned int size; |
111 | unsigned int size; |
112 | packet_t packet; |
112 | packet_t packet; |
113 | 113 | ||
114 | if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, ( ipcarg_t * ) & packet_id, & size )) |
114 | if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, ( ipcarg_t * ) & packet_id, & size )) |
115 | || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
115 | || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
116 | return NULL; |
116 | return NULL; |
117 | } |
117 | } |
118 | return packet; |
118 | return packet; |
119 | } |
119 | } |
120 | 120 | ||
121 | void pq_release( int phone, packet_id_t packet_id ){ |
121 | void pq_release( int phone, packet_id_t packet_id ){ |
122 | async_msg_1( phone, NET_PACKET_RELEASE, packet_id ); |
122 | async_msg_1( phone, NET_PACKET_RELEASE, packet_id ); |
123 | } |
123 | } |
124 | 124 | ||
125 | /** @} |
125 | /** @} |
126 | */ |
126 | */ |
127 | 127 |