Subversion Repositories HelenOS

Rev

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

Rev 3666 Rev 3685
Line 39... Line 39...
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 "../measured_strings.h"
44
#include "../messages.h"
45
#include "../messages.h"
45
#include "../modules.h"
46
#include "../modules.h"
46
 
47
 
47
#include "netif.h"
48
#include "netif.h"
48
 
49
 
Line 50... Line 51...
50
 
51
 
51
#define NAME    "lo - loopback interface"
52
#define NAME    "lo - loopback interface"
52
 
53
 
53
netif_globals_t netif_globals;
54
netif_globals_t netif_globals;
54
 
55
 
55
void    change_status( netif_device_ref device, netif_status_t status );
56
void    change_state( netif_device_ref device, netif_state_t state );
56
int change_status_message( netif_device_id_t device_id, netif_status_t status );
57
int change_state_message( netif_device_id_t device_id, netif_state_t state );
57
int netif_create( netif_device_id_t device_id, netif_device_ref * device );
58
int netif_create( netif_device_id_t device_id, netif_device_ref * device );
58
int netif_call( ipc_callid_t callid );
59
int netif_call( ipc_callid_t callid );
59
int netif_initialize( void );
60
int netif_initialize( void );
60
void    netif_print_name( void );
61
void    netif_print_name( void );
61
int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
62
int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
62
int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
63
int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
63
int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
64
int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
64
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
65
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
65
int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
66
int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
66
 
67
 
67
void change_status( netif_device_ref device, netif_status_t status ){
68
void change_state( netif_device_ref device, netif_state_t state ){
68
    device->status = status;
69
    device->state = state;
69
    ll_message( device, NET_LL_DEVICE_STATUS_CHANGED, device->status, NULL, NULL, NULL, NULL );
70
    ll_message( device, NET_LL_DEVICE_STATE_CHANGED, device->state, NULL, NULL, NULL, NULL );
70
}
71
}
71
 
72
 
72
int change_status_message( netif_device_id_t device_id, netif_status_t status ){
73
int change_state_message( netif_device_id_t device_id, netif_state_t state ){
73
    ERROR_DECLARE;
74
    ERROR_DECLARE;
74
 
75
 
75
    netif_device_ref    device;
76
    netif_device_ref    device;
76
 
77
 
77
    ERROR_PROPAGATE( netif_device_find( device_id, & device ));
78
    ERROR_PROPAGATE( netif_device_find( device_id, & device ));
78
    change_status( device, status );
79
    change_state( device, state );
79
    return EOK;
80
    return EOK;
80
}
81
}
81
 
82
 
82
int netif_create( netif_device_id_t device_id, netif_device_ref * device ){
83
int netif_create( netif_device_id_t device_id, netif_device_ref * device ){
83
    ERROR_DECLARE;
84
    ERROR_DECLARE;
Line 85... Line 86...
85
    if( netif_device_map_count( & netif_globals.netif_device_map ) > 0 ){
86
    if( netif_device_map_count( & netif_globals.netif_device_map ) > 0 ){
86
        return EXDEV;
87
        return EXDEV;
87
    }else{
88
    }else{
88
        * device = ( netif_device_ref ) malloc( sizeof( netif_device_t ));
89
        * device = ( netif_device_ref ) malloc( sizeof( netif_device_t ));
89
        if( !( * device )) return ENOMEM;
90
        if( !( * device )) return ENOMEM;
90
//      ( ** device ).device_id = netif_device_id_generate( 1 );
-
 
91
        ( ** device ).device_id = device_id;
91
        ( ** device ).device_id = device_id;
92
        ( ** device ).ll_registered = NULL;
92
        ( ** device ).ll_registered = -1;
-
 
93
        ( ** device ).specific = NULL;
93
        netif_device_stats_null( &(( ** device ).stats ));
94
        netif_device_stats_null( &(( ** device ).stats ));
94
        ( ** device ).status = NETIF_STOPPED;
95
        ( ** device ).state = NETIF_STOPPED;
95
        ( ** device ).flags = NULL;
96
        ( ** device ).flags = NULL;
96
        ( ** device ).mtu = DEFAULT_MTU;
97
        ( ** device ).mtu = DEFAULT_MTU;
97
        if( ERROR_OCCURED( netif_device_map_add( & netif_globals.netif_device_map, ( ** device ).device_id, * device ))){
98
        if( ERROR_OCCURED( netif_device_map_add( & netif_globals.netif_device_map, ( ** device ).device_id, * device ))){
98
            free( * device );
99
            free( * device );
99
            * device = NULL;
100
            * device = NULL;
Line 106... Line 107...
106
int netif_call( ipc_callid_t callid ){
107
int netif_call( ipc_callid_t callid ){
107
    return EOK;
108
    return EOK;
108
}
109
}
109
 
110
 
110
int netif_initialize( void ){
111
int netif_initialize( void ){
111
    int phonehash;
112
    ipcarg_t    phonehash;
112
 
113
 
113
    return REGISTER_ME( SERVICE_LO, & phonehash );
114
    return REGISTER_ME( SERVICE_LO, & phonehash );
114
}
115
}
115
 
116
 
116
void netif_print_name( void ){
117
void netif_print_name( void ){
117
    printf( NAME );
118
    printf( NAME );
118
}
119
}
119
 
120
 
120
int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
121
int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
121
    ERROR_DECLARE;
122
/*  ERROR_DECLARE;
122
 
123
 
123
    netif_device_ref    device;
124
    netif_device_ref    device;
124
 
125
 
125
    ERROR_PROPAGATE( netif_create( arg1, & device ));
126
    ERROR_PROPAGATE( netif_create( arg1, & device ));
126
    networking_message( NET_NETWORKING_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL );
127
    ipc_call_sync_3_3( netif_globals.networking_phone, NET_NETWORKING_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL );
127
    return EOK;
128
*/  return ENOTSUP;
128
}
129
}
129
 
130
 
130
int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
131
int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
131
    ERROR_DECLARE;
132
    ERROR_DECLARE;
132
 
133
 
133
    netif_device_ref    device;
134
    netif_device_ref    device;
-
 
135
    aid_t           message;
-
 
136
    ipc_call_t      answer;
-
 
137
    measured_string_t   configuration[ 1 ] = {{ "MTU", 3 }};
-
 
138
    int         count = 1;
-
 
139
    measured_string_ref settings;
-
 
140
    char *          data;
134
 
141
 
-
 
142
    // create a new device
135
    ERROR_PROPAGATE( netif_create( arg1, & device ));
143
    ERROR_PROPAGATE( netif_create( arg1, & device ));
-
 
144
    // get configuration
-
 
145
    message = async_send_2( netif_globals.networking_phone, NET_NETWORKING_GET_DEVICE_CONFIGURATION, device->device_id, count, & answer );
-
 
146
    // send names and get settings
-
 
147
    if( ERROR_OCCURED( measured_strings_send( netif_globals.networking_phone, configuration, count ))
-
 
148
    || ERROR_OCCURED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){
-
 
149
        async_wait_for( message, NULL );
-
 
150
        return ERROR_CODE;
-
 
151
    }
-
 
152
    // MTU is the first one
-
 
153
    if( settings && ( settings[ 0 ].value )){
-
 
154
        device->mtu = strtoul( settings[ 0 ].value, NULL, 0 );
-
 
155
    }else{
-
 
156
        device->mtu = DEFAULT_MTU;
-
 
157
    }
-
 
158
    // print the settings
-
 
159
    printf("\n -MTU=%d", device->mtu );
-
 
160
    free( settings );
-
 
161
    free( data );
-
 
162
    // end request
-
 
163
    async_wait_for( message, NULL );
136
    return EOK;
164
    return EOK;
137
}
165
}
138
 
166
 
139
int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
167
int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
140
    ERROR_DECLARE;
168
    ERROR_DECLARE;
141
 
169
 
142
    netif_device_ref    device;
170
    netif_device_ref    device;
143
 
171
 
144
    ERROR_PROPAGATE( netif_device_find( arg1, & device ));
172
    ERROR_PROPAGATE( netif_device_find( arg1, & device ));
145
    if( device->status == NETIF_ACTIVE ){
173
    if( device->state == NETIF_ACTIVE ){
146
        ++ device->stats.tx_packets;
174
        ++ device->stats.tx_packets;
147
        ++ device->stats.rx_packets;
175
        ++ device->stats.rx_packets;
148
        // TODO packet size
176
        // TODO packet size
149
        //device->stats->tx_bytes += ;
177
        //device->stats->tx_bytes += ;
150
        //device->stats->rx_bytes += ;
178
        //device->stats->rx_bytes += ;
Line 154... Line 182...
154
        return EPERM;
182
        return EPERM;
155
    }
183
    }
156
}
184
}
157
 
185
 
158
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
186
int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
159
    return change_status_message( arg1, NETIF_ACTIVE );
187
    return change_state_message( arg1, NETIF_ACTIVE );
160
}
188
}
161
 
189
 
162
int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
190
int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
163
    return change_status_message( arg1, NETIF_STOPPED );
191
    return change_state_message( arg1, NETIF_STOPPED );
164
}
192
}
165
 
193
 
166
/** @}
194
/** @}
167
 */
195
 */