Rev 3912 | Rev 4192 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3912 | Rev 3990 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | #include <unistd.h> |
39 | #include <unistd.h> |
40 | //#include <stdio.h> |
40 | //#include <stdio.h> |
41 | #include <string.h> |
41 | #include <string.h> |
42 | 42 | ||
43 | #include <ipc/ipc.h> |
43 | #include <ipc/ipc.h> |
44 | #include <ipc/services.h> |
- | |
45 | #include <sys/mman.h> |
44 | #include <sys/mman.h> |
46 | 45 | ||
47 | #include "../../err.h" |
46 | #include "../../err.h" |
48 | #include "../../messages.h" |
47 | #include "../../messages.h" |
49 | 48 | ||
Line 61... | Line 60... | ||
61 | * \todo ipc_share_in_start() error? |
60 | * \todo ipc_share_in_start() error? |
62 | * @returns Other error codes as defined for the pm_add() function. |
61 | * @returns Other error codes as defined for the pm_add() function. |
63 | */ |
62 | */ |
64 | int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ); |
63 | int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ); |
65 | 64 | ||
66 | packet_t packet_copy( int phone, services_t owner, const packet_t packet ){ |
- | |
67 | packet_t new; |
- | |
68 | - | ||
69 | if( ! packet_is_valid( packet )) return NULL; |
- | |
70 | // new = ( packet_t ) mmap( NULL, packet->length, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0 ); |
- | |
71 | // if( new == MAP_FAILED ) return NULL; |
- | |
72 | // memcpy( new, packet, packet->length ); |
- | |
73 | new = packet_get_1( phone, owner, packet_get_data_length( packet )); |
- | |
74 | packet_copy_data( new, packet_get_data( packet ), packet_get_data_length( packet )); |
- | |
75 | return new; |
- | |
76 | } |
- | |
77 | - | ||
78 | int packet_copy_data( packet_t packet, const void * data, size_t length ){ |
65 | int packet_copy_data( packet_t packet, const void * data, size_t length ){ |
79 | if( ! packet_is_valid( packet )) return EINVAL; |
66 | if( ! packet_is_valid( packet )) return EINVAL; |
80 | if( packet->data_start + length >= packet->length ) return ENOMEM; |
67 | if( packet->data_start + length >= packet->length ) return ENOMEM; |
81 | memcpy(( void * ) packet + packet->data_start, data, length ); |
68 | memcpy(( void * ) packet + packet->data_start, data, length ); |
82 | if( packet->data_start + length > packet->data_end ){ |
69 | if( packet->data_start + length > packet->data_end ){ |
Line 125... | Line 112... | ||
125 | void * packet_get_data( const packet_t packet ){ |
112 | void * packet_get_data( const packet_t packet ){ |
126 | if( ! packet_is_valid( packet )) return NULL; |
113 | if( ! packet_is_valid( packet )) return NULL; |
127 | return ( void * ) packet + packet->data_start; |
114 | return ( void * ) packet + packet->data_start; |
128 | } |
115 | } |
129 | 116 | ||
130 | packet_mode_t packet_get_mode( const packet_t packet ){ |
- | |
131 | if( packet_is_valid( packet )) return packet->mode; |
- | |
132 | return PM_ONE_WAY; |
- | |
133 | } |
- | |
134 | - | ||
135 | int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len ){ |
117 | int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len ){ |
136 | size_t padding; |
118 | size_t padding; |
137 | 119 | ||
138 | if( ! packet_is_valid( packet )) return EINVAL; |
120 | if( ! packet_is_valid( packet )) return EINVAL; |
139 | if( packet->addr_len >= addr_len ) return ENOMEM; |
121 | if( packet->addr_len >= addr_len ) return ENOMEM; |
Line 151... | Line 133... | ||
151 | memset(( void * ) packet + packet->dest_addr + addr_len, 0, packet->addr_len ); |
133 | memset(( void * ) packet + packet->dest_addr + addr_len, 0, packet->addr_len ); |
152 | } |
134 | } |
153 | return EOK; |
135 | return EOK; |
154 | } |
136 | } |
155 | 137 | ||
156 | int packet_set_mode( packet_t packet, packet_mode_t mode ){ |
- | |
157 | if( ! packet_is_valid( packet )) return EINVAL; |
- | |
158 | packet->mode = mode; |
- | |
159 | return EOK; |
- | |
160 | } |
- | |
161 | - | ||
162 | int packet_set_owner( packet_t packet, services_t owner ){ |
- | |
163 | if( ! packet_is_valid( packet )) return EINVAL; |
- | |
164 | packet->owner = owner; |
- | |
165 | return EOK; |
- | |
166 | } |
- | |
167 | - | ||
168 | int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){ |
138 | int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){ |
169 | ERROR_DECLARE; |
139 | ERROR_DECLARE; |
170 | 140 | ||
171 | unsigned int size; |
141 | unsigned int size; |
172 | 142 | ||
Line 194... | Line 164... | ||
194 | } |
164 | } |
195 | async_wait_for( message, & result ); |
165 | async_wait_for( message, & result ); |
196 | return result; |
166 | return result; |
197 | } |
167 | } |
198 | 168 | ||
199 | packet_t packet_get_5( int phone, services_t owner, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){ |
169 | packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){ |
200 | ERROR_DECLARE; |
170 | ERROR_DECLARE; |
201 | 171 | ||
202 | packet_id_t packet_id; |
172 | packet_id_t packet_id; |
203 | unsigned int size; |
173 | unsigned int size; |
204 | packet_t packet; |
174 | packet_t packet; |
205 | 175 | ||
206 | if( ERROR_OCCURRED( async_req_5_2( phone, NET_PACKET_CREATE_5, owner, max_content, addr_len, max_prefix, max_suffix, & packet_id, & size )) |
176 | if( ERROR_OCCURRED( async_req_4_2( phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, & packet_id, & size )) |
207 | || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
177 | || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
208 | return NULL; |
178 | return NULL; |
209 | } |
179 | } |
210 | return packet; |
180 | return packet; |
211 | } |
181 | } |
212 | 182 | ||
213 | packet_t packet_get_1( int phone, services_t owner, size_t content ){ |
183 | packet_t packet_get_1( int phone, size_t content ){ |
214 | ERROR_DECLARE; |
184 | ERROR_DECLARE; |
215 | 185 | ||
216 | packet_id_t packet_id; |
186 | packet_id_t packet_id; |
217 | unsigned int size; |
187 | unsigned int size; |
218 | packet_t packet; |
188 | packet_t packet; |
219 | 189 | ||
220 | if( ERROR_OCCURRED( async_req_2_2( phone, NET_PACKET_CREATE_1, owner, content, & packet_id, & size )) |
190 | if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, & packet_id, & size )) |
221 | || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
191 | || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
222 | return NULL; |
192 | return NULL; |
223 | } |
193 | } |
224 | return packet; |
194 | return packet; |
225 | } |
195 | } |