Subversion Repositories HelenOS

Rev

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

Rev 4243 Rev 4261
Line 49... Line 49...
49
#include "../structures/packet/packet_client.h"
49
#include "../structures/packet/packet_client.h"
50
#include "../structures/measured_strings.h"
50
#include "../structures/measured_strings.h"
51
 
51
 
52
#include "../include/device.h"
52
#include "../include/device.h"
53
#include "../include/netif_messages.h"
53
#include "../include/netif_messages.h"
-
 
54
#include "../include/nil_messages.h"
54
 
55
 
55
#include "netif.h"
56
#include "netif.h"
56
#include "netif_interface.h"
57
#include "netif_interface.h"
57
#include "netif_wrappers.h"
58
#include "netif_wrappers.h"
58
 
59
 
-
 
60
#if NIL_BUNDLE
-
 
61
 
-
 
62
    #include "../nil/nil_module.h"
-
 
63
 
-
 
64
#endif
-
 
65
 
59
extern netif_globals_t netif_globals;
66
extern netif_globals_t netif_globals;
60
 
67
 
61
DEVICE_MAP_IMPLEMENT( device_map, device_t )
68
DEVICE_MAP_IMPLEMENT( device_map, device_t )
62
 
69
 
63
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
70
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
Line 71... Line 78...
71
    result = netif_probe_message( device_id, irq, io );
78
    result = netif_probe_message( device_id, irq, io );
72
    rwlock_write_unlock( & netif_globals.lock );
79
    rwlock_write_unlock( & netif_globals.lock );
73
    return result;
80
    return result;
74
}
81
}
75
 
82
 
76
int netif_send_wrapper( device_id_t device_id, packet_t packet ){
83
int netif_send_wrapper( device_id_t device_id, packet_t packet, services_t sender ){
77
    int result;
84
    int result;
78
 
85
 
79
    rwlock_write_lock( & netif_globals.lock );
86
    rwlock_write_lock( & netif_globals.lock );
80
    result = netif_send_message( device_id, packet );
87
    result = netif_send_message( device_id, packet, sender );
81
    rwlock_write_unlock( & netif_globals.lock );
88
    rwlock_write_unlock( & netif_globals.lock );
82
    return result;
89
    return result;
83
}
90
}
84
 
91
 
85
int netif_start_wrapper( device_id_t device_id ){
92
int netif_start_wrapper( device_id_t device_id ){
-
 
93
    ERROR_DECLARE;
-
 
94
 
-
 
95
    device_ref  device;
86
    int result;
96
    int result;
-
 
97
    int phone;
87
 
98
 
88
    rwlock_write_lock( & netif_globals.lock );
99
    rwlock_write_lock( & netif_globals.lock );
-
 
100
    if( ERROR_OCCURRED( find_device( device_id, & device ))){
-
 
101
        rwlock_write_unlock( & netif_globals.lock );
-
 
102
        return ERROR_CODE;
-
 
103
    }
89
    result = netif_start_message( device_id );
104
    result = netif_start_message( device );
-
 
105
    if( result > NETIF_NULL ){
-
 
106
        phone = device->nil_phone;
-
 
107
        rwlock_write_unlock( & netif_globals.lock );
-
 
108
        nil_device_state_msg( phone, device_id, result );
-
 
109
        return EOK;
-
 
110
    }else{
90
    rwlock_write_unlock( & netif_globals.lock );
111
        rwlock_write_unlock( & netif_globals.lock );
-
 
112
    }
91
    return result;
113
    return result;
92
}
114
}
93
 
115
 
94
int netif_stop_wrapper( device_id_t device_id ){
116
int netif_stop_wrapper( device_id_t device_id ){
-
 
117
    ERROR_DECLARE;
-
 
118
 
-
 
119
    device_ref  device;
95
    int result;
120
    int result;
-
 
121
    int phone;
96
 
122
 
97
    rwlock_write_lock( & netif_globals.lock );
123
    rwlock_write_lock( & netif_globals.lock );
-
 
124
    if( ERROR_OCCURRED( find_device( device_id, & device ))){
-
 
125
        rwlock_write_unlock( & netif_globals.lock );
-
 
126
        return ERROR_CODE;
-
 
127
    }
98
    result = netif_stop_message( device_id );
128
    result = netif_stop_message( device );
-
 
129
    if( result > NETIF_NULL ){
-
 
130
        phone = device->nil_phone;
-
 
131
        rwlock_write_unlock( & netif_globals.lock );
-
 
132
        nil_device_state_msg( phone, device_id, result );
-
 
133
        return EOK;
-
 
134
    }else{
99
    rwlock_write_unlock( & netif_globals.lock );
135
        rwlock_write_unlock( & netif_globals.lock );
-
 
136
    }
100
    return result;
137
    return result;
101
}
138
}
102
 
139
 
103
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address ){
140
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address, char ** data ){
104
    ERROR_DECLARE;
141
    ERROR_DECLARE;
105
 
142
 
106
    measured_string_t   translation;
143
    measured_string_t   translation;
107
 
144
 
108
    if( ! address ) return EBADMEM;
145
    if( !( address && data )) return EBADMEM;
109
    rwlock_read_lock( & netif_globals.lock );
146
    rwlock_read_lock( & netif_globals.lock );
110
    if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
147
    if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
111
        * address = measured_string_create_bulk( translation.value, translation.length );
148
//      * address = measured_string_create_bulk( translation.value, translation.length );
-
 
149
        * address = ( measured_string_ref ) malloc( sizeof( measured_string_t ));
-
 
150
        if( * address ){
-
 
151
            * data = ( char * ) malloc( translation.length + 1 );
-
 
152
            if( * data ){
-
 
153
                memcpy( * data, translation.value, translation.length + 1 );
-
 
154
                ( ** address ).value = * data;
-
 
155
                ( ** address ).length = translation.length;
-
 
156
                rwlock_read_unlock( & netif_globals.lock );
-
 
157
                return EOK;
-
 
158
            }
-
 
159
            free( * address );
-
 
160
        }
112
        ERROR_CODE = ( * address ) ? EOK : ENOMEM;
161
        ERROR_CODE = ENOMEM;
113
    }
162
    }
114
    rwlock_read_unlock( & netif_globals.lock );
163
    rwlock_read_unlock( & netif_globals.lock );
115
    return ERROR_CODE;
164
    return ERROR_CODE;
116
}
165
}
117
 
166
 
Line 145... Line 194...
145
    size_t              length;
194
    size_t              length;
146
    device_stats_t      stats;
195
    device_stats_t      stats;
147
    packet_t            packet;
196
    packet_t            packet;
148
    measured_string_t   address;
197
    measured_string_t   address;
149
 
198
 
-
 
199
//  printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_NETIF_FIRST );
-
 
200
#if NIL_BUNDLE
-
 
201
    if( IS_NET_NIL_MESSAGE( call )){
-
 
202
        return nil_message( callid, call, answer, answer_count );
-
 
203
    }
-
 
204
#endif
150
    * answer_count = 0;
205
    * answer_count = 0;
151
    switch( IPC_GET_METHOD( * call )){
206
    switch( IPC_GET_METHOD( * call )){
152
        case IPC_M_PHONE_HUNGUP:
207
        case IPC_M_PHONE_HUNGUP:
153
            return EOK;
208
            return EOK;
154
        case NET_NETIF_PROBE_AUTO:
209
        case NET_NETIF_PROBE_AUTO:
155
            rwlock_write_lock( & netif_globals.lock );
210
            rwlock_write_lock( & netif_globals.lock );
156
            ERROR_CODE = netif_probe_auto_message();
211
            ERROR_CODE = netif_probe_auto_message();
157
            rwlock_write_unlock( & netif_globals.lock );
212
            rwlock_write_unlock( & netif_globals.lock );
158
            return ERROR_CODE;
213
            return ERROR_CODE;
159
        case NET_NETIF_PROBE:
214
        case NET_NETIF_PROBE:
160
            return netif_probe_wrapper( NETIF_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
215
            return netif_probe_wrapper( IPC_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
161
        case IPC_M_CONNECT_TO_ME:
216
        case IPC_M_CONNECT_TO_ME:
-
 
217
#if NIL_BUNDLE
-
 
218
            return nil_register_message( NIL_GET_PROTO( call ), IPC_GET_PHONE( call ));
-
 
219
#else
162
            rwlock_write_lock( & netif_globals.lock );
220
            rwlock_write_lock( & netif_globals.lock );
163
            ERROR_CODE = register_message( NETIF_GET_DEVICE( call ), IPC_GET_PHONE( call ));
221
            ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
164
            rwlock_write_unlock( & netif_globals.lock );
222
            rwlock_write_unlock( & netif_globals.lock );
165
            return ERROR_CODE;
223
            return ERROR_CODE;
-
 
224
#endif
166
        case NET_NETIF_SEND:
225
        case NET_NETIF_SEND:
-
 
226
        case NET_NIL_SEND:
167
            ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, NETIF_GET_PACKET( call )));
227
            ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call )));
168
            return netif_send_wrapper( NETIF_GET_DEVICE( call ), packet );
228
            return netif_send_wrapper( IPC_GET_DEVICE( call ), packet, IPC_GET_SENDER( call ));
169
        case NET_NETIF_START:
229
        case NET_NETIF_START:
170
            return netif_start_wrapper( NETIF_GET_DEVICE( call ));
230
            return netif_start_wrapper( IPC_GET_DEVICE( call ));
171
        case NET_NETIF_STATS:
231
        case NET_NETIF_STATS:
172
            rwlock_read_lock( & netif_globals.lock );
232
            rwlock_read_lock( & netif_globals.lock );
173
            if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
233
            if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
174
                if( length < sizeof( device_stats_t )){
234
                if( length < sizeof( device_stats_t )){
175
                    ERROR_CODE = EOVERFLOW;
235
                    ERROR_CODE = EOVERFLOW;
176
                }else{
236
                }else{
177
                    if( ! ERROR_OCCURRED( netif_get_device_stats( NETIF_GET_DEVICE( call ), & stats ))){
237
                    if( ! ERROR_OCCURRED( netif_get_device_stats( IPC_GET_DEVICE( call ), & stats ))){
178
                        ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
238
                        ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
179
                    }
239
                    }
180
                }
240
                }
181
            }
241
            }
182
            rwlock_read_unlock( & netif_globals.lock );
242
            rwlock_read_unlock( & netif_globals.lock );
183
            return ERROR_CODE;
243
            return ERROR_CODE;
184
        case NET_NETIF_STOP:
244
        case NET_NETIF_STOP:
185
            return netif_stop_wrapper( NETIF_GET_DEVICE( call ));
245
            return netif_stop_wrapper( IPC_GET_DEVICE( call ));
186
        case NET_NETIF_GET_ADDR:
246
        case NET_NETIF_GET_ADDR:
-
 
247
        case NET_NIL_ADDR:
187
            rwlock_read_lock( & netif_globals.lock );
248
            rwlock_read_lock( & netif_globals.lock );
188
            if( ! ERROR_OCCURRED( netif_get_addr_message( NETIF_GET_DEVICE( call ), & address ))){
249
            if( ! ERROR_OCCURRED( netif_get_addr_message( IPC_GET_DEVICE( call ), & address ))){
189
                ERROR_CODE = measured_strings_reply( & address, 1 );
250
                ERROR_CODE = measured_strings_reply( & address, 1 );
190
            }
251
            }
191
            rwlock_read_unlock( & netif_globals.lock );
252
            rwlock_read_unlock( & netif_globals.lock );
192
            return ERROR_CODE;
253
            return ERROR_CODE;
193
    }
254
    }
Line 204... Line 265...
204
    rwlock_initialize( & netif_globals.lock );
265
    rwlock_initialize( & netif_globals.lock );
205
    if( ERROR_OCCURRED( netif_initialize())){
266
    if( ERROR_OCCURRED( netif_initialize())){
206
        pm_destroy();
267
        pm_destroy();
207
        return ERROR_CODE;
268
        return ERROR_CODE;
208
    }
269
    }
-
 
270
#if NIL_BUNDLE
-
 
271
    if( ERROR_OCCURRED( nil_initialize( netif_globals.networking_phone ))){
-
 
272
        pm_destroy();
-
 
273
        return ERROR_CODE;
-
 
274
    }
-
 
275
#endif
209
 
276
 
210
    async_manager();
277
    async_manager();
211
 
278
 
212
    pm_destroy();
279
    pm_destroy();
213
    return EOK;
280
    return EOK;