Subversion Repositories HelenOS

Rev

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

Rev 3914 Rev 4163
Line 32... Line 32...
32
 
32
 
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <async.h>
36
#include <async.h>
-
 
37
#include <mem.h>
37
#include <stdio.h>
38
#include <stdio.h>
38
 
39
 
39
#include <ipc/ipc.h>
40
#include <ipc/ipc.h>
40
#include <ipc/services.h>
41
#include <ipc/services.h>
41
//#include <sys/mman.h>
42
//#include <sys/mman.h>
Line 44... Line 45...
44
#include "../messages.h"
45
#include "../messages.h"
45
#include "../modules.h"
46
#include "../modules.h"
46
 
47
 
47
#include "../structures/packet/packet.h"
48
#include "../structures/packet/packet.h"
48
#include "../structures/packet/packet_client.h"
49
#include "../structures/packet/packet_client.h"
-
 
50
#include "../structures/measured_strings.h"
49
 
51
 
50
#include "device.h"
52
#include "device.h"
51
#include "netif.h"
53
#include "netif.h"
52
 
54
 
53
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
55
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
Line 62... Line 64...
62
extern int  probe_auto_message( void );
64
extern int  probe_auto_message( void );
63
extern int  probe_message( device_id_t device_id, int irq, int io );
65
extern int  probe_message( device_id_t device_id, int irq, int io );
64
extern int  send_message( device_id_t device_id, packet_t packet );
66
extern int  send_message( device_id_t device_id, packet_t packet );
65
extern int  start_message( device_id_t device_id );
67
extern int  start_message( device_id_t device_id );
66
extern int  stop_message( device_id_t device_id );
68
extern int  stop_message( device_id_t device_id );
-
 
69
extern measured_string_ref  get_addr_message( device_id_t device_id );
67
 
70
 
68
DEVICE_MAP_IMPLEMENT( device_map, device_t )
71
DEVICE_MAP_IMPLEMENT( device_map, device_t )
69
 
72
 
70
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
73
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
71
int netif_start_module( async_client_conn_t client_connection );
74
int netif_start_module( async_client_conn_t client_connection );
72
int register_message( device_id_t device_id, int phone );
75
int register_message( device_id_t device_id, int phone );
73
int get_device_stats( device_id_t device_id, device_stats_ref * stats );
76
int get_device_stats( device_id_t device_id, device_stats_ref * stats );
74
 
77
 
-
 
78
 
75
int find_device( device_id_t device_id, device_ref * device ){
79
int find_device( device_id_t device_id, device_ref * device ){
-
 
80
    if( ! device ) return EBADMEM;
76
    * device = device_map_find( & netif_globals.device_map, device_id );
81
    * device = device_map_find( & netif_globals.device_map, device_id );
77
    if( ! * device ) return ENOENT;
82
    if( ! * device ) return ENOENT;
78
    if(( ** device ).state == NETIF_NULL ) return EPERM;
83
    if(( ** device ).state == NETIF_NULL ) return EPERM;
79
    return EOK;
84
    return EOK;
80
}
85
}
Line 82... Line 87...
82
int get_device_stats( device_id_t device_id, device_stats_ref * stats ){
87
int get_device_stats( device_id_t device_id, device_stats_ref * stats ){
83
    ERROR_DECLARE;
88
    ERROR_DECLARE;
84
 
89
 
85
    device_ref  device;
90
    device_ref  device;
86
 
91
 
87
    if( ! stats ) return EINVAL;
92
    if( ! stats ) return EBADMEM;
88
    ERROR_PROPAGATE( find_device( device_id, & device ));
93
    ERROR_PROPAGATE( find_device( device_id, & device ));
89
    * stats = & device->stats;
94
    * stats = & device->stats;
90
    return EOK;
95
    return EOK;
91
}
96
}
92
 
97
 
93
void null_device_stats( device_stats_ref stats ){
98
void null_device_stats( device_stats_ref stats ){
94
    memset( stats, 0, sizeof( device_stats_t ));
99
    bzero( stats, sizeof( device_stats_t ));
95
/*  stats->rx_packets = 0;
-
 
96
    stats->tx_packets = 0;
-
 
97
    stats->rx_bytes = 0;
-
 
98
    stats->tx_bytes = 0;
-
 
99
    stats->rx_errors = 0;
-
 
100
    stats->tx_errors = 0;
-
 
101
    stats->rx_dropped = 0;
-
 
102
    stats->tx_dropped = 0;
-
 
103
    stats->multicast = 0;
-
 
104
    stats->collisions = 0;
-
 
105
    stats->rx_length_errors = 0;
-
 
106
    stats->rx_over_errors = 0;
-
 
107
    stats->rx_crc_errors = 0;
-
 
108
    stats->rx_frame_errors = 0;
-
 
109
    stats->rx_fifo_errors = 0;
-
 
110
    stats->rx_missed_errors = 0;
-
 
111
    stats->tx_aborted_errors = 0;
-
 
112
    stats->tx_carrier_errors = 0;
-
 
113
    stats->tx_fifo_errors = 0;
-
 
114
    stats->tx_heartbeat_errors = 0;
-
 
115
    stats->tx_window_errors = 0;
-
 
116
    stats->rx_compressed = 0;
-
 
117
    stats->tx_compressed = 0;
-
 
118
*/
-
 
119
}
100
}
120
 
101
 
121
int register_message( device_id_t device_id, int phone ){
102
int register_message( device_id_t device_id, int phone ){
122
    ERROR_DECLARE;
103
    ERROR_DECLARE;
123
 
104
 
124
    device_ref  device;
105
    device_ref  device;
125
 
106
 
126
    ERROR_PROPAGATE( find_device( device_id, & device ));
107
    ERROR_PROPAGATE( find_device( device_id, & device ));
127
    if( device->nil_phone ) return ELIMIT;
108
    if( device->nil_phone > 0 ) return ELIMIT;
128
    device->nil_phone = phone;
109
    device->nil_phone = phone;
-
 
110
    printf( "\nNew receiver of the device %d registered:\n\tphone\t= %d", device->device_id, device->nil_phone );
129
    return EOK;
111
    return EOK;
130
}
112
}
131
 
113
 
132
int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
114
int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
133
    ERROR_DECLARE;
115
    ERROR_DECLARE;
134
 
116
 
135
    size_t          length;
117
    size_t              length;
136
    device_stats_ref    stats;
118
    device_stats_ref    stats;
137
    packet_t        packet;
119
    packet_t            packet;
-
 
120
    measured_string_ref address;
138
 
121
 
139
//  printf( "\nNETIF message %d", method );
122
//  printf( "\nNETIF message %d", method );
140
    * answer_count = 0;
123
    * answer_count = 0;
141
    switch( IPC_GET_METHOD( * call )){
124
    switch( IPC_GET_METHOD( * call )){
142
        case IPC_M_PHONE_HUNGUP:
125
        case IPC_M_PHONE_HUNGUP:
Line 157... Line 140...
157
            if( length < sizeof( device_stats_t )) return EOVERFLOW;
140
            if( length < sizeof( device_stats_t )) return EOVERFLOW;
158
            ERROR_PROPAGATE( get_device_stats( IPC_GET_DEVICE( call ), & stats ));
141
            ERROR_PROPAGATE( get_device_stats( IPC_GET_DEVICE( call ), & stats ));
159
            return ipc_data_read_finalize( callid, stats, sizeof( device_stats_t ));
142
            return ipc_data_read_finalize( callid, stats, sizeof( device_stats_t ));
160
        case NET_NETIF_STOP:
143
        case NET_NETIF_STOP:
161
            return stop_message( IPC_GET_DEVICE( call ));
144
            return stop_message( IPC_GET_DEVICE( call ));
-
 
145
        case NET_NETIF_GET_ADDR:
-
 
146
            address = get_addr_message( IPC_GET_DEVICE( call ));
-
 
147
            return address ? measured_strings_reply( address, 1 ) : ENOENT;
162
    }
148
    }
163
    return ENOTSUP;
149
    return ENOTSUP;
164
}
150
}
165
 
151
 
166
int netif_start_module( async_client_conn_t client_connection ){
152
int netif_start_module( async_client_conn_t client_connection ){