Subversion Repositories HelenOS

Rev

Rev 4243 | Rev 4395 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4243 Rev 4307
Line 48... Line 48...
48
 
48
 
49
#include "packet.h"
49
#include "packet.h"
50
#include "packet_header.h"
50
#include "packet_header.h"
51
#include "packet_client.h"
51
#include "packet_client.h"
52
 
52
 
53
/** Obtains the packet from the packet server as the shared memory block.
-
 
54
 *  Creates the local packet mapping as well.
-
 
55
 *  @param phone The packet server module phone. Input parameter.
-
 
56
 *  @param packet The packet reference pointer to store the received packet reference. Output parameter.
-
 
57
 *  @param packet_id The packet identifier. Input parameter.
-
 
58
 *  @param size The packet total size in bytes. Input parameter.
-
 
59
 *  @returns EOK on success.
-
 
60
 *  \todo ipc_share_in_start() error?
-
 
61
 *  @returns Other error codes as defined for the pm_add() function.
-
 
62
 */
-
 
63
int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size );
-
 
64
 
-
 
65
int packet_copy_data( packet_t packet, const void * data, size_t length ){
53
int packet_copy_data( packet_t packet, const void * data, size_t length ){
66
    if( ! packet_is_valid( packet )) return EINVAL;
54
    if( ! packet_is_valid( packet )) return EINVAL;
67
    if( packet->data_start + length >= packet->length ) return ENOMEM;
55
    if( packet->data_start + length >= packet->length ) return ENOMEM;
68
    memcpy(( void * ) packet + packet->data_start, data, length );
56
    memcpy(( void * ) packet + packet->data_start, data, length );
69
    if( packet->data_start + length > packet->data_end ){
57
    if( packet->data_start + length > packet->data_end ){
Line 133... Line 121...
133
        bzero(( void * ) packet + packet->dest_addr + addr_len, packet->addr_len );
121
        bzero(( void * ) packet + packet->dest_addr + addr_len, packet->addr_len );
134
    }
122
    }
135
    return EOK;
123
    return EOK;
136
}
124
}
137
 
125
 
138
int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){
-
 
139
    ERROR_DECLARE;
-
 
140
 
-
 
141
    unsigned int        size;
-
 
142
 
-
 
143
    if( ! packet ) return EINVAL;
-
 
144
    * packet = pm_find( packet_id );
-
 
145
    if( * packet ) return EOK;
-
 
146
    ERROR_PROPAGATE( async_req_1_1( phone, NET_PACKET_GET_SIZE, packet_id, & size ));
-
 
147
    return packet_return( phone, packet, packet_id, size );
-
 
148
}
-
 
149
 
-
 
150
int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ){
-
 
151
    ERROR_DECLARE;
-
 
152
 
-
 
153
    aid_t       message;
-
 
154
    ipc_call_t  answer;
-
 
155
    ipcarg_t    result;
-
 
156
 
-
 
157
    message = async_send_1( phone, NET_PACKET_GET, packet_id, & answer );
-
 
158
    * packet = ( packet_t ) as_get_mappable_page( size );
-
 
159
    if( ERROR_OCCURRED( ipc_share_in_start_0_0( phone, * packet, size ))
-
 
160
    || ERROR_OCCURRED( pm_add( * packet ))){
-
 
161
        munmap( * packet, size );
-
 
162
        async_wait_for( message, NULL );
-
 
163
        return ERROR_CODE;
-
 
164
    }
-
 
165
    async_wait_for( message, & result );
-
 
166
    return result;
-
 
167
}
-
 
168
 
-
 
169
packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){
-
 
170
    ERROR_DECLARE;
-
 
171
 
-
 
172
    packet_id_t packet_id;
-
 
173
    unsigned int size;
-
 
174
    packet_t packet;
-
 
175
 
-
 
176
    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 ))
-
 
177
    || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){
-
 
178
        return NULL;
-
 
179
    }
-
 
180
    return packet;
-
 
181
}
-
 
182
 
-
 
183
packet_t packet_get_1( int phone, size_t content ){
-
 
184
    ERROR_DECLARE;
-
 
185
 
-
 
186
    packet_id_t packet_id;
-
 
187
    unsigned int    size;
-
 
188
    packet_t    packet;
-
 
189
 
-
 
190
    if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, ( ipcarg_t * ) & packet_id, & size ))
-
 
191
    || ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){
-
 
192
        return NULL;
-
 
193
    }
-
 
194
    return packet;
-
 
195
}
-
 
196
 
-
 
197
void pq_release( int phone, packet_id_t packet_id ){
-
 
198
    async_msg_1( phone, NET_PACKET_RELEASE, packet_id );
-
 
199
}
-
 
200
 
-
 
201
/** @}
126
/** @}
202
 */
127
 */