Subversion Repositories HelenOS

Rev

Rev 3846 | Rev 3901 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3846 Rev 3886
1
/*
1
/*
2
 * Copyright (c) 2008 Lukas Mejdrech
2
 * Copyright (c) 2008 Lukas Mejdrech
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup net
29
/** @addtogroup net
30
 * @{
30
 * @{
31
 */
31
 */
32
 
32
 
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
 
39
#include <ipc/ipc.h>
39
#include <ipc/ipc.h>
40
#include <ipc/services.h>
40
#include <ipc/services.h>
41
//#include <sys/mman.h>
41
//#include <sys/mman.h>
42
 
42
 
43
#include "../err.h"
43
#include "../err.h"
44
#include "../messages.h"
44
#include "../messages.h"
45
#include "../modules.h"
45
#include "../modules.h"
-
 
46
 
46
#include "../packet.h"
47
#include "../structures/packet/packet.h"
47
 
48
 
48
#include "device.h"
49
#include "device.h"
49
#include "netif.h"
50
#include "netif.h"
50
 
51
 
51
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
52
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
52
#define IPC_GET_IRQ( call )     ( int ) IPC_GET_ARG2( * call )
53
#define IPC_GET_IRQ( call )     ( int ) IPC_GET_ARG2( * call )
53
#define IPC_GET_IO( call )      ( int ) IPC_GET_ARG3( * call )
54
#define IPC_GET_IO( call )      ( int ) IPC_GET_ARG3( * call )
54
#define IPC_GET_PHONE( call )       ( int ) IPC_GET_ARG5( * call )
55
#define IPC_GET_PHONE( call )       ( int ) IPC_GET_ARG5( * call )
55
 
56
 
56
extern netif_globals_t netif_globals;
57
extern netif_globals_t netif_globals;
57
 
58
 
58
extern int  initialize( void );
59
extern int  initialize( void );
59
extern int  probe_auto_message( void );
60
extern int  probe_auto_message( void );
60
extern int  probe_message( device_id_t device_id, int irq, int io );
61
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  send_message( device_id_t device_id, packet_t packet );
62
extern int  start_message( device_id_t device_id );
63
extern int  start_message( device_id_t device_id );
63
extern int  stop_message( device_id_t device_id );
64
extern int  stop_message( device_id_t device_id );
64
 
65
 
65
DEVICE_MAP_IMPLEMENT( device_map, device_t )
66
DEVICE_MAP_IMPLEMENT( device_map, device_t )
66
 
67
 
67
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
68
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
68
int netif_start_module( async_client_conn_t client_connection );
69
int netif_start_module( async_client_conn_t client_connection );
69
int register_message( device_id_t device_id, int phone );
70
int register_message( device_id_t device_id, int phone );
70
int get_device_stats( device_id_t device_id, device_stats_ref * stats );
71
int get_device_stats( device_id_t device_id, device_stats_ref * stats );
71
 
72
 
72
int find_device( device_id_t device_id, device_ref * device ){
73
int find_device( device_id_t device_id, device_ref * device ){
73
    * device = device_map_find( & netif_globals.device_map, device_id );
74
    * device = device_map_find( & netif_globals.device_map, device_id );
74
    if( ! * device ) return ENOENT;
75
    if( ! * device ) return ENOENT;
75
    if(( ** device ).state == NETIF_NULL ) return EPERM;
76
    if(( ** device ).state == NETIF_NULL ) return EPERM;
76
    return EOK;
77
    return EOK;
77
}
78
}
78
 
79
 
79
int get_device_stats( device_id_t device_id, device_stats_ref * stats ){
80
int get_device_stats( device_id_t device_id, device_stats_ref * stats ){
80
    ERROR_DECLARE;
81
    ERROR_DECLARE;
81
 
82
 
82
    device_ref  device;
83
    device_ref  device;
83
 
84
 
84
    if( ! stats ) return EINVAL;
85
    if( ! stats ) return EINVAL;
85
    ERROR_PROPAGATE( find_device( device_id, & device ));
86
    ERROR_PROPAGATE( find_device( device_id, & device ));
86
    * stats = & device->stats;
87
    * stats = & device->stats;
87
    return EOK;
88
    return EOK;
88
}
89
}
89
 
90
 
90
void null_device_stats( device_stats_ref stats ){
91
void null_device_stats( device_stats_ref stats ){
91
    memset( stats, 0, sizeof( device_stats_t ));
92
    memset( stats, 0, sizeof( device_stats_t ));
92
/*  stats->rx_packets = 0;
93
/*  stats->rx_packets = 0;
93
    stats->tx_packets = 0;
94
    stats->tx_packets = 0;
94
    stats->rx_bytes = 0;
95
    stats->rx_bytes = 0;
95
    stats->tx_bytes = 0;
96
    stats->tx_bytes = 0;
96
    stats->rx_errors = 0;
97
    stats->rx_errors = 0;
97
    stats->tx_errors = 0;
98
    stats->tx_errors = 0;
98
    stats->rx_dropped = 0;
99
    stats->rx_dropped = 0;
99
    stats->tx_dropped = 0;
100
    stats->tx_dropped = 0;
100
    stats->multicast = 0;
101
    stats->multicast = 0;
101
    stats->collisions = 0;
102
    stats->collisions = 0;
102
    stats->rx_length_errors = 0;
103
    stats->rx_length_errors = 0;
103
    stats->rx_over_errors = 0;
104
    stats->rx_over_errors = 0;
104
    stats->rx_crc_errors = 0;
105
    stats->rx_crc_errors = 0;
105
    stats->rx_frame_errors = 0;
106
    stats->rx_frame_errors = 0;
106
    stats->rx_fifo_errors = 0;
107
    stats->rx_fifo_errors = 0;
107
    stats->rx_missed_errors = 0;
108
    stats->rx_missed_errors = 0;
108
    stats->tx_aborted_errors = 0;
109
    stats->tx_aborted_errors = 0;
109
    stats->tx_carrier_errors = 0;
110
    stats->tx_carrier_errors = 0;
110
    stats->tx_fifo_errors = 0;
111
    stats->tx_fifo_errors = 0;
111
    stats->tx_heartbeat_errors = 0;
112
    stats->tx_heartbeat_errors = 0;
112
    stats->tx_window_errors = 0;
113
    stats->tx_window_errors = 0;
113
    stats->rx_compressed = 0;
114
    stats->rx_compressed = 0;
114
    stats->tx_compressed = 0;
115
    stats->tx_compressed = 0;
115
*/
116
*/
116
}
117
}
117
 
118
 
118
int register_message( device_id_t device_id, int phone ){
119
int register_message( device_id_t device_id, int phone ){
119
    ERROR_DECLARE;
120
    ERROR_DECLARE;
120
 
121
 
121
    device_ref  device;
122
    device_ref  device;
122
 
123
 
123
    ERROR_PROPAGATE( find_device( device_id, & device ));
124
    ERROR_PROPAGATE( find_device( device_id, & device ));
124
    if( device->nil_phone ) return ELIMIT;
125
    if( device->nil_phone ) return ELIMIT;
125
    device->nil_phone = phone;
126
    device->nil_phone = phone;
126
    return EOK;
127
    return EOK;
127
}
128
}
128
 
129
 
129
int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
130
int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
130
    ERROR_DECLARE;
131
    ERROR_DECLARE;
131
 
132
 
132
    size_t          length;
133
    size_t          length;
133
    device_stats_ref    stats;
134
    device_stats_ref    stats;
134
    packet_t        packet;
135
    packet_t        packet;
135
 
136
 
136
//  printf( "\nNETIF message %d", method );
137
//  printf( "\nNETIF message %d", method );
137
    * answer_count = 0;
138
    * answer_count = 0;
138
    switch( IPC_GET_METHOD( * call )){
139
    switch( IPC_GET_METHOD( * call )){
139
        case IPC_M_PHONE_HUNGUP:
140
        case IPC_M_PHONE_HUNGUP:
140
            return EOK;
141
            return EOK;
141
        case NET_NETIF_PROBE_AUTO:
142
        case NET_NETIF_PROBE_AUTO:
142
            return probe_auto_message();
143
            return probe_auto_message();
143
        case NET_NETIF_PROBE:
144
        case NET_NETIF_PROBE:
144
            return probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call ));
145
            return probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call ));
145
        case IPC_M_CONNECT_TO_ME:
146
        case IPC_M_CONNECT_TO_ME:
146
            return register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
147
            return register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
147
        case NET_NETIF_SEND:
148
        case NET_NETIF_SEND:
148
            ERROR_PROPAGATE( packet_receive( & packet ));
149
            ERROR_PROPAGATE( packet_receive( & packet ));
149
            return send_message( IPC_GET_DEVICE( call ), packet );
150
            return send_message( IPC_GET_DEVICE( call ), packet );
150
        case NET_NETIF_START:
151
        case NET_NETIF_START:
151
            return start_message( IPC_GET_DEVICE( call ));
152
            return start_message( IPC_GET_DEVICE( call ));
152
        case NET_NETIF_STATS:
153
        case NET_NETIF_STATS:
153
            ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length ));
154
            ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length ));
154
            if( length < sizeof( device_stats_t )) return EOVERFLOW;
155
            if( length < sizeof( device_stats_t )) return EOVERFLOW;
155
            ERROR_PROPAGATE( get_device_stats( IPC_GET_DEVICE( call ), & stats ));
156
            ERROR_PROPAGATE( get_device_stats( IPC_GET_DEVICE( call ), & stats ));
156
            return ipc_data_read_finalize( callid, stats, sizeof( device_stats_t ));
157
            return ipc_data_read_finalize( callid, stats, sizeof( device_stats_t ));
157
        case NET_NETIF_STOP:
158
        case NET_NETIF_STOP:
158
            return stop_message( IPC_GET_DEVICE( call ));
159
            return stop_message( IPC_GET_DEVICE( call ));
159
    }
160
    }
160
    return ENOTSUP;
161
    return ENOTSUP;
161
}
162
}
162
 
163
 
163
int netif_start_module( async_client_conn_t client_connection ){
164
int netif_start_module( async_client_conn_t client_connection ){
164
    ERROR_DECLARE;
165
    ERROR_DECLARE;
165
 
166
 
166
    async_set_client_connection( client_connection );
167
    async_set_client_connection( client_connection );
167
    netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
168
    netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
168
    device_map_initialize( & netif_globals.device_map );
169
    device_map_initialize( & netif_globals.device_map );
169
    ERROR_PROPAGATE( initialize());
170
    ERROR_PROPAGATE( initialize());
170
 
171
 
171
    async_manager();
172
    async_manager();
172
 
173
 
173
    return EOK;
174
    return EOK;
174
}
175
}
175
 
176
 
176
/** @}
177
/** @}
177
 */
178
 */
178
 
179