Subversion Repositories HelenOS

Rev

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

Rev 4192 Rev 4243
Line 47... Line 47...
47
 
47
 
48
#include "../structures/packet/packet.h"
48
#include "../structures/packet/packet.h"
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 "device.h"
52
#include "../include/device.h"
-
 
53
#include "../include/netif_messages.h"
-
 
54
 
53
#include "netif.h"
55
#include "netif.h"
54
#include "netif_interface.h"
56
#include "netif_interface.h"
55
 
-
 
56
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
-
 
57
#define IPC_GET_PACKET( call )      ( packet_id_t ) IPC_GET_ARG2( * call )
-
 
58
#define IPC_GET_IRQ( call )     ( int ) IPC_GET_ARG2( * call )
-
 
59
#define IPC_GET_IO( call )      ( int ) IPC_GET_ARG3( * call )
57
#include "netif_wrappers.h"
60
#define IPC_GET_PHONE( call )       ( int ) IPC_GET_ARG5( * call )
-
 
61
 
58
 
62
extern netif_globals_t netif_globals;
59
extern netif_globals_t netif_globals;
63
 
60
 
64
DEVICE_MAP_IMPLEMENT( device_map, device_t )
61
DEVICE_MAP_IMPLEMENT( device_map, device_t )
65
 
62
 
66
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
63
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
67
int netif_start_module( async_client_conn_t client_connection );
64
int netif_start_module( async_client_conn_t client_connection );
68
int register_message( device_id_t device_id, int phone );
65
int register_message( device_id_t device_id, int phone );
69
 
66
 
-
 
67
int netif_probe_wrapper( device_id_t device_id, int irq, int io ){
-
 
68
    int result;
-
 
69
 
-
 
70
    rwlock_write_lock( & netif_globals.lock );
-
 
71
    result = netif_probe_message( device_id, irq, io );
-
 
72
    rwlock_write_unlock( & netif_globals.lock );
-
 
73
    return result;
-
 
74
}
-
 
75
 
-
 
76
int netif_send_wrapper( device_id_t device_id, packet_t packet ){
-
 
77
    int result;
-
 
78
 
-
 
79
    rwlock_write_lock( & netif_globals.lock );
-
 
80
    result = netif_send_message( device_id, packet );
-
 
81
    rwlock_write_unlock( & netif_globals.lock );
-
 
82
    return result;
-
 
83
}
-
 
84
 
-
 
85
int netif_start_wrapper( device_id_t device_id ){
-
 
86
    int result;
-
 
87
 
-
 
88
    rwlock_write_lock( & netif_globals.lock );
-
 
89
    result = netif_start_message( device_id );
-
 
90
    rwlock_write_unlock( & netif_globals.lock );
-
 
91
    return result;
-
 
92
}
-
 
93
 
-
 
94
int netif_stop_wrapper( device_id_t device_id ){
-
 
95
    int result;
-
 
96
 
-
 
97
    rwlock_write_lock( & netif_globals.lock );
-
 
98
    result = netif_stop_message( device_id );
-
 
99
    rwlock_write_unlock( & netif_globals.lock );
-
 
100
    return result;
-
 
101
}
-
 
102
 
-
 
103
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address ){
-
 
104
    ERROR_DECLARE;
-
 
105
 
-
 
106
    measured_string_t   translation;
-
 
107
 
-
 
108
    if( ! address ) return EBADMEM;
-
 
109
    rwlock_read_lock( & netif_globals.lock );
-
 
110
    if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
-
 
111
        * address = measured_string_create_bulk( translation.value, translation.length );
-
 
112
        ERROR_CODE = ( * address ) ? EOK : ENOMEM;
-
 
113
    }
-
 
114
    rwlock_read_unlock( & netif_globals.lock );
-
 
115
    return ERROR_CODE;
-
 
116
}
-
 
117
 
70
int find_device( device_id_t device_id, device_ref * device ){
118
int find_device( device_id_t device_id, device_ref * device ){
71
    if( ! device ) return EBADMEM;
119
    if( ! device ) return EBADMEM;
72
    * device = device_map_find( & netif_globals.device_map, device_id );
120
    * device = device_map_find( & netif_globals.device_map, device_id );
73
    if( ! * device ) return ENOENT;
121
    if( ! * device ) return ENOENT;
74
    if(( ** device ).state == NETIF_NULL ) return EPERM;
122
    if(( ** device ).state == NETIF_NULL ) return EPERM;
Line 103... Line 151...
103
    switch( IPC_GET_METHOD( * call )){
151
    switch( IPC_GET_METHOD( * call )){
104
        case IPC_M_PHONE_HUNGUP:
152
        case IPC_M_PHONE_HUNGUP:
105
            return EOK;
153
            return EOK;
106
        case NET_NETIF_PROBE_AUTO:
154
        case NET_NETIF_PROBE_AUTO:
107
            rwlock_write_lock( & netif_globals.lock );
155
            rwlock_write_lock( & netif_globals.lock );
108
            ERROR_CODE = probe_auto_message();
156
            ERROR_CODE = netif_probe_auto_message();
109
            rwlock_write_unlock( & netif_globals.lock );
157
            rwlock_write_unlock( & netif_globals.lock );
110
            return ERROR_CODE;
158
            return ERROR_CODE;
111
        case NET_NETIF_PROBE:
159
        case NET_NETIF_PROBE:
112
            rwlock_write_lock( & netif_globals.lock );
-
 
113
            ERROR_CODE = probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call ));
160
            return netif_probe_wrapper( NETIF_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
114
            rwlock_write_unlock( & netif_globals.lock );
-
 
115
            return ERROR_CODE;
-
 
116
        case IPC_M_CONNECT_TO_ME:
161
        case IPC_M_CONNECT_TO_ME:
117
            rwlock_write_lock( & netif_globals.lock );
162
            rwlock_write_lock( & netif_globals.lock );
118
            ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
163
            ERROR_CODE = register_message( NETIF_GET_DEVICE( call ), IPC_GET_PHONE( call ));
119
            rwlock_write_unlock( & netif_globals.lock );
164
            rwlock_write_unlock( & netif_globals.lock );
120
            return ERROR_CODE;
165
            return ERROR_CODE;
121
        case NET_NETIF_SEND:
166
        case NET_NETIF_SEND:
122
            rwlock_write_lock( & netif_globals.lock );
-
 
123
            if( ! ERROR_OCCURRED( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call )))){
167
            ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, NETIF_GET_PACKET( call )));
124
                ERROR_CODE = send_message( IPC_GET_DEVICE( call ), packet );
168
            return netif_send_wrapper( NETIF_GET_DEVICE( call ), packet );
125
            }
-
 
126
            rwlock_write_unlock( & netif_globals.lock );
-
 
127
            return ERROR_CODE;
-
 
128
        case NET_NETIF_START:
169
        case NET_NETIF_START:
129
            rwlock_write_lock( & netif_globals.lock );
-
 
130
            ERROR_CODE = start_message( IPC_GET_DEVICE( call ));
170
            return netif_start_wrapper( NETIF_GET_DEVICE( call ));
131
            rwlock_write_unlock( & netif_globals.lock );
-
 
132
            return ERROR_CODE;
-
 
133
        case NET_NETIF_STATS:
171
        case NET_NETIF_STATS:
134
            rwlock_read_lock( & netif_globals.lock );
172
            rwlock_read_lock( & netif_globals.lock );
135
            if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
173
            if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
136
                if( length < sizeof( device_stats_t )){
174
                if( length < sizeof( device_stats_t )){
137
                    ERROR_CODE = EOVERFLOW;
175
                    ERROR_CODE = EOVERFLOW;
138
                }else{
176
                }else{
139
                    if( ! ERROR_OCCURRED( get_device_stats( IPC_GET_DEVICE( call ), & stats ))){
177
                    if( ! ERROR_OCCURRED( netif_get_device_stats( NETIF_GET_DEVICE( call ), & stats ))){
140
                        ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
178
                        ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
141
                    }
179
                    }
142
                }
180
                }
143
            }
181
            }
144
            rwlock_read_unlock( & netif_globals.lock );
182
            rwlock_read_unlock( & netif_globals.lock );
145
            return ERROR_CODE;
183
            return ERROR_CODE;
146
        case NET_NETIF_STOP:
184
        case NET_NETIF_STOP:
147
            rwlock_write_lock( & netif_globals.lock );
-
 
148
            ERROR_CODE = stop_message( IPC_GET_DEVICE( call ));
185
            return netif_stop_wrapper( NETIF_GET_DEVICE( call ));
149
            rwlock_write_unlock( & netif_globals.lock );
-
 
150
            return ERROR_CODE;
-
 
151
        case NET_NETIF_GET_ADDR:
186
        case NET_NETIF_GET_ADDR:
152
            rwlock_read_lock( & netif_globals.lock );
187
            rwlock_read_lock( & netif_globals.lock );
153
            if( ! ERROR_OCCURRED( get_addr_message( IPC_GET_DEVICE( call ), & address ))){
188
            if( ! ERROR_OCCURRED( netif_get_addr_message( NETIF_GET_DEVICE( call ), & address ))){
154
                ERROR_CODE = measured_strings_reply( & address, 1 );
189
                ERROR_CODE = measured_strings_reply( & address, 1 );
155
            }
190
            }
156
            rwlock_read_unlock( & netif_globals.lock );
191
            rwlock_read_unlock( & netif_globals.lock );
157
            return ERROR_CODE;
192
            return ERROR_CODE;
158
    }
193
    }
159
    return specific_message( callid, call, answer, answer_count );
194
    return netif_specific_message( callid, call, answer, answer_count );
160
}
195
}
161
 
196
 
162
int netif_start_module( async_client_conn_t client_connection ){
197
int netif_start_module( async_client_conn_t client_connection ){
163
    ERROR_DECLARE;
198
    ERROR_DECLARE;
164
 
199
 
165
    async_set_client_connection( client_connection );
200
    async_set_client_connection( client_connection );
166
    netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
201
    netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
167
    device_map_initialize( & netif_globals.device_map );
202
    device_map_initialize( & netif_globals.device_map );
168
    ERROR_PROPAGATE( pm_init());
203
    ERROR_PROPAGATE( pm_init());
169
    rwlock_initialize( & netif_globals.lock );
204
    rwlock_initialize( & netif_globals.lock );
170
    if( ERROR_OCCURRED( initialize())){
205
    if( ERROR_OCCURRED( netif_initialize())){
171
        pm_destroy();
206
        pm_destroy();
172
        return ERROR_CODE;
207
        return ERROR_CODE;
173
    }
208
    }
174
 
209
 
175
    async_manager();
210
    async_manager();