Subversion Repositories HelenOS

Rev

Rev 3846 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3666 mejdrech 1
/*
2
 * Copyright (c) 2008 Lukas Mejdrech
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
/** @addtogroup net
30
 * @{
31
 */
32
 
33
/** @file
34
 */
35
 
36
#include <async.h>
37
#include <stdio.h>
38
#include <ipc/ipc.h>
39
#include <ipc/services.h>
40
//#include <sys/mman.h>
41
 
42
#include "../err.h"
43
#include "../messages.h"
44
#include "../modules.h"
45
 
46
#include "netif.h"
47
#include "netif_device_id_type.h"
48
 
49
extern netif_globals_t netif_globals;
50
 
51
extern int  netif_initialize( void );
52
extern void netif_print_name( void );
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 );
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 );
58
 
59
DEVICE_MAP_IMPLEMENT( netif_device_map, netif_device_t )
60
 
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 );
62
int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall ));
63
 
64
int netif_device_find( netif_device_id_t device_id, netif_device_ref * device ){
65
    * device = netif_device_map_find( & netif_globals.netif_device_map, device_id );
66
    if( ! * device ) return ENOENT;
67
    if(( ** device ).status == NETIF_NULL ) return EPERM;
68
    return EOK;
69
}
70
 
71
void netif_device_stats_null( netif_device_stats_ref stats )
72
{
73
    //memset( stats, 0, sizeof( netif_device_t ));
74
    stats->rx_packets = 0;
75
    stats->tx_packets = 0;
76
    stats->rx_bytes = 0;
77
    stats->tx_bytes = 0;
78
    stats->rx_errors = 0;
79
    stats->tx_errors = 0;
80
    stats->rx_dropped = 0;
81
    stats->tx_dropped = 0;
82
    stats->multicast = 0;
83
    stats->collisions = 0;
84
    stats->rx_length_errors = 0;
85
    stats->rx_over_errors = 0;
86
    stats->rx_crc_errors = 0;
87
    stats->rx_frame_errors = 0;
88
    stats->rx_fifo_errors = 0;
89
    stats->rx_missed_errors = 0;
90
    stats->tx_aborted_errors = 0;
91
    stats->tx_carrier_errors = 0;
92
    stats->tx_fifo_errors = 0;
93
    stats->tx_heartbeat_errors = 0;
94
    stats->tx_window_errors = 0;
95
    stats->rx_compressed = 0;
96
    stats->tx_compressed = 0;
97
}
98
 
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 ){
100
    ERROR_DECLARE;
101
 
102
    size_t          length;
103
    netif_device_ref    device;
104
 
105
//  printf( "\nNETIF message %d", method );
106
    switch( method ){
107
        case IPC_M_PHONE_HUNGUP:
108
            return EOK;
109
        case NET_NETIF_PROBE_AUTO:
110
            return netif_probe_auto_message( arg1, arg2, arg3, result1, result2, result3 );
111
        case NET_NETIF_PROBE:
112
            return netif_probe_message( arg1, arg2, arg3, result1, result2, result3 );
113
        case NET_NETIF_REGISTER:
114
        case NET_LL_REGISTER:
115
            ERROR_PROPAGATE( netif_device_find( arg1, & device ));
116
            // TODO back phone
117
            device->ll_registered = callid;
118
            return EOK;
119
        case NET_NETIF_SEND:
120
            return netif_send_message( arg1, arg2, arg3, result1, result2, result3 );
121
        case NET_NETIF_START:
122
            return netif_start_message( arg1, arg2, arg3, result1, result2, result3 );
123
        case NET_NETIF_STATS:
124
            ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length ));
125
            if( length < sizeof( netif_device_stats_t )){
126
                ipc_answer_0( callid, EOVERFLOW );
127
                return EOVERFLOW;
128
            }
129
            if( ERROR_OCCURED( netif_device_find( arg1, & device ))){
130
                ipc_answer_0( callid, ERROR_CODE );
131
                return ERROR_CODE;
132
            }
133
            return ipc_data_read_finalize( callid, & device->stats, sizeof( netif_device_stats_t ));
134
        case NET_NETIF_STOP:
135
            return netif_stop_message( arg1, arg2, arg3, result1, result2, result3 );
136
    }
137
    return ENOTSUP;
138
}
139
 
140
int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){
141
/*  services_t  need[ 2 ];
142
    int *       need_phone[ 2 ];
143
 
144
    need[ 0 ] = SERVICE_NETWORKING;
145
    need[ 1 ] = NULL;
146
    need_phone[ 0 ] = & netif_globals.networking_phone;
147
    need_phone[ 1 ] = NULL;
148
*/  netif_device_map_initialize( & netif_globals.netif_device_map );
149
    return start_service( NULL, /*need, need_phone*/ NULL, NULL, client_connection, netif_initialize );
150
}
151
 
152
/** @}
153
 */