Subversion Repositories HelenOS

Rev

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

Rev 3685 Rev 3846
Line 33... Line 33...
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <async.h>
36
#include <async.h>
37
#include <stdio.h>
37
#include <stdio.h>
-
 
38
 
38
#include <ipc/ipc.h>
39
#include <ipc/ipc.h>
39
#include <ipc/services.h>
40
#include <ipc/services.h>
40
//#include <sys/mman.h>
41
//#include <sys/mman.h>
41
 
42
 
42
#include "../err.h"
43
#include "../err.h"
43
#include "../messages.h"
44
#include "../messages.h"
44
#include "../modules.h"
45
#include "../modules.h"
-
 
46
#include "../packet.h"
45
 
47
 
-
 
48
#include "device.h"
46
#include "netif.h"
49
#include "netif.h"
47
#include "netif_device_id_type.h"
-
 
48
 
-
 
49
extern netif_globals_t netif_globals;
-
 
50
 
50
 
51
extern int  netif_initialize( void );
51
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
52
extern void netif_print_name( void );
52
#define IPC_GET_IRQ( call )     ( int ) IPC_GET_ARG2( * call )
53
extern int  netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
-
 
54
extern int  netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
-
 
55
extern int  netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
53
#define IPC_GET_IO( call )      ( int ) IPC_GET_ARG3( * call )
56
extern int  netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
-
 
57
extern int  netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
54
#define IPC_GET_PHONE( call )       ( int ) IPC_GET_ARG5( * call )
58
 
55
 
59
DEVICE_MAP_IMPLEMENT( netif_device_map, netif_device_t )
56
extern netif_globals_t netif_globals;
60
 
57
 
-
 
58
extern int  initialize( void );
-
 
59
extern int  probe_auto_message( void );
-
 
60
extern int  probe_message( device_id_t device_id, int irq, int io );
-
 
61
extern int  send_message( device_id_t device_id, packet_t packet );
-
 
62
extern int  start_message( device_id_t device_id );
-
 
63
extern int  stop_message( device_id_t device_id );
-
 
64
 
-
 
65
DEVICE_MAP_IMPLEMENT( device_map, device_t )
-
 
66
 
61
int netif_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
67
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
62
int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall ));
68
int netif_start_module( async_client_conn_t client_connection );
-
 
69
int register_message( device_id_t device_id, int phone );
-
 
70
int get_device_stats( device_id_t device_id, device_stats_ref * stats );
63
 
71
 
64
int netif_device_find( netif_device_id_t device_id, netif_device_ref * device ){
72
int find_device( device_id_t device_id, device_ref * device ){
65
    * device = netif_device_map_find( & netif_globals.netif_device_map, device_id );
73
    * device = device_map_find( & netif_globals.device_map, device_id );
66
    if( ! * device ) return ENOENT;
74
    if( ! * device ) return ENOENT;
67
    if(( ** device ).state == NETIF_NULL ) return EPERM;
75
    if(( ** device ).state == NETIF_NULL ) return EPERM;
68
    return EOK;
76
    return EOK;
69
}
77
}
70
 
78
 
71
void netif_device_stats_null( netif_device_stats_ref stats )
79
int get_device_stats( device_id_t device_id, device_stats_ref * stats ){
-
 
80
    ERROR_DECLARE;
-
 
81
 
-
 
82
    device_ref  device;
-
 
83
 
-
 
84
    if( ! stats ) return EINVAL;
-
 
85
    ERROR_PROPAGATE( find_device( device_id, & device ));
-
 
86
    * stats = & device->stats;
-
 
87
    return EOK;
72
{
88
}
-
 
89
 
-
 
90
void null_device_stats( device_stats_ref stats ){
73
    //memset( stats, 0, sizeof( netif_device_t ));
91
    memset( stats, 0, sizeof( device_stats_t ));
74
    stats->rx_packets = 0;
92
/*  stats->rx_packets = 0;
75
    stats->tx_packets = 0;
93
    stats->tx_packets = 0;
76
    stats->rx_bytes = 0;
94
    stats->rx_bytes = 0;
77
    stats->tx_bytes = 0;
95
    stats->tx_bytes = 0;
78
    stats->rx_errors = 0;
96
    stats->rx_errors = 0;
79
    stats->tx_errors = 0;
97
    stats->tx_errors = 0;
Line 92... Line 110...
92
    stats->tx_fifo_errors = 0;
110
    stats->tx_fifo_errors = 0;
93
    stats->tx_heartbeat_errors = 0;
111
    stats->tx_heartbeat_errors = 0;
94
    stats->tx_window_errors = 0;
112
    stats->tx_window_errors = 0;
95
    stats->rx_compressed = 0;
113
    stats->rx_compressed = 0;
96
    stats->tx_compressed = 0;
114
    stats->tx_compressed = 0;
-
 
115
*/
-
 
116
}
-
 
117
 
-
 
118
int register_message( device_id_t device_id, int phone ){
-
 
119
    ERROR_DECLARE;
-
 
120
 
-
 
121
    device_ref  device;
-
 
122
 
-
 
123
    ERROR_PROPAGATE( find_device( device_id, & device ));
-
 
124
    if( device->nil_phone ) return ELIMIT;
-
 
125
    device->nil_phone = phone;
-
 
126
    return EOK;
97
}
127
}
98
 
128
 
99
int netif_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
129
int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
100
    ERROR_DECLARE;
130
    ERROR_DECLARE;
101
 
131
 
102
    size_t          length;
132
    size_t          length;
103
    netif_device_ref    device;
133
    device_stats_ref    stats;
-
 
134
    packet_t        packet;
104
 
135
 
105
//  printf( "\nNETIF message %d", method );
136
//  printf( "\nNETIF message %d", method );
-
 
137
    * answer_count = 0;
106
    switch( method ){
138
    switch( IPC_GET_METHOD( * call )){
107
        case IPC_M_PHONE_HUNGUP:
139
        case IPC_M_PHONE_HUNGUP:
108
            return EOK;
140
            return EOK;
109
        case NET_NETIF_PROBE_AUTO:
141
        case NET_NETIF_PROBE_AUTO:
110
            return netif_probe_auto_message( arg1, arg2, arg3, result1, result2, result3 );
142
            return probe_auto_message();
111
        case NET_NETIF_PROBE:
143
        case NET_NETIF_PROBE:
112
            return netif_probe_message( arg1, arg2, arg3, result1, result2, result3 );
144
            return probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call ));
113
        case NET_NETIF_REGISTER:
-
 
114
        case NET_LL_REGISTER:
145
        case IPC_M_CONNECT_TO_ME:
115
            ERROR_PROPAGATE( netif_device_find( arg1, & device ));
-
 
116
            device->ll_registered = connect_to_service( arg2 );
146
            return register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
117
            return EOK;
-
 
118
        case NET_NETIF_SEND:
147
        case NET_NETIF_SEND:
-
 
148
            ERROR_PROPAGATE( packet_receive( & packet ));
119
            return netif_send_message( arg1, arg2, arg3, result1, result2, result3 );
149
            return send_message( IPC_GET_DEVICE( call ), packet );
120
        case NET_NETIF_START:
150
        case NET_NETIF_START:
121
            return netif_start_message( arg1, arg2, arg3, result1, result2, result3 );
151
            return start_message( IPC_GET_DEVICE( call ));
122
        case NET_NETIF_STATS:
152
        case NET_NETIF_STATS:
123
            ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length ));
153
            ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length ));
124
            if( length < sizeof( netif_device_stats_t )){
154
            if( length < sizeof( device_stats_t )) return EOVERFLOW;
125
                ipc_answer_0( callid, EOVERFLOW );
-
 
126
                return EOVERFLOW;
-
 
127
            }
-
 
128
            if( ERROR_OCCURED( netif_device_find( arg1, & device ))){
155
            ERROR_PROPAGATE( get_device_stats( IPC_GET_DEVICE( call ), & stats ));
129
                ipc_answer_0( callid, ERROR_CODE );
-
 
130
                return ERROR_CODE;
-
 
131
            }
-
 
132
            return ipc_data_read_finalize( callid, & device->stats, sizeof( netif_device_stats_t ));
156
            return ipc_data_read_finalize( callid, stats, sizeof( device_stats_t ));
133
        case NET_NETIF_STOP:
157
        case NET_NETIF_STOP:
134
            return netif_stop_message( arg1, arg2, arg3, result1, result2, result3 );
158
            return stop_message( IPC_GET_DEVICE( call ));
135
    }
159
    }
136
    return ENOTSUP;
160
    return ENOTSUP;
137
}
161
}
138
 
162
 
139
int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){
163
int netif_start_module( async_client_conn_t client_connection ){
140
    services_t  need[ 2 ];
164
    ERROR_DECLARE;
141
    int *       need_phone[ 2 ];
-
 
142
 
165
 
143
    need[ 0 ] = SERVICE_NETWORKING;
166
    async_set_client_connection( client_connection );
144
    need[ 1 ] = NULL;
-
 
145
    need_phone[ 0 ] = & netif_globals.networking_phone;
167
    netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
146
    need_phone[ 1 ] = NULL;
-
 
147
    netif_device_map_initialize( & netif_globals.netif_device_map );
168
    device_map_initialize( & netif_globals.device_map );
148
    return start_service( NULL, need, need_phone, client_connection, netif_initialize );
169
    ERROR_PROPAGATE( initialize());
-
 
170
 
-
 
171
    async_manager();
-
 
172
 
-
 
173
    return EOK;
149
}
174
}
150
 
175
 
151
/** @}
176
/** @}
152
 */
177
 */