Subversion Repositories HelenOS

Rev

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

Rev 4075 Rev 4163
Line 53... Line 53...
53
 
53
 
54
#define NAME    "lo - loopback interface"
54
#define NAME    "lo - loopback interface"
55
 
55
 
56
netif_globals_t netif_globals;
56
netif_globals_t netif_globals;
57
 
57
 
-
 
58
static struct lo_globals{
-
 
59
    measured_string_ref addr;
-
 
60
    int mtu;
-
 
61
} lo_globals;
-
 
62
 
58
int change_state_message( device_id_t device_id, device_state_t state );
63
int change_state_message( device_id_t device_id, device_state_t state );
59
int create( device_id_t device_id, device_ref * device );
64
int create( device_id_t device_id, device_ref * device );
60
int initialize( void );
65
int initialize( void );
61
void    netif_print_name( void );
66
void    netif_print_name( void );
62
int probe_auto_message( void );
67
int probe_auto_message( void );
63
int probe_message( device_id_t device_id, int irq, int io );
68
int probe_message( device_id_t device_id, int irq, int io );
64
int send_message( device_id_t device_id, packet_t packet );
69
int send_message( device_id_t device_id, packet_t packet );
65
int start_message( device_id_t device_id );
70
int start_message( device_id_t device_id );
66
int stop_message( device_id_t device_id );
71
int stop_message( device_id_t device_id );
-
 
72
measured_string_ref get_addr_message( device_id_t device_id );
-
 
73
 
-
 
74
measured_string_ref get_addr_message( device_id_t device_id ){
-
 
75
    return lo_globals.addr;
-
 
76
}
67
 
77
 
68
int change_state_message( device_id_t device_id, device_state_t state ){
78
int change_state_message( device_id_t device_id, device_state_t state ){
69
    ERROR_DECLARE;
79
    ERROR_DECLARE;
70
 
80
 
71
    device_ref  device;
81
    device_ref  device;
72
 
82
 
73
    ERROR_PROPAGATE( find_device( device_id, & device ));
83
    ERROR_PROPAGATE( find_device( device_id, & device ));
74
    if( device->state != state ){
84
    if( device->state != state ){
75
        device->state = state;
85
        device->state = state;
76
        nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL );
86
        nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL );
-
 
87
        printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" );
77
    }
88
    }
78
    return EOK;
89
    return EOK;
79
}
90
}
80
 
91
 
81
int create( device_id_t device_id, device_ref * device ){
92
int create( device_id_t device_id, device_ref * device ){
Line 89... Line 100...
89
        ( ** device ).device_id = device_id;
100
        ( ** device ).device_id = device_id;
90
        ( ** device ).nil_phone = -1;
101
        ( ** device ).nil_phone = -1;
91
        ( ** device ).specific = NULL;
102
        ( ** device ).specific = NULL;
92
        null_device_stats( &(( ** device ).stats ));
103
        null_device_stats( &(( ** device ).stats ));
93
        ( ** device ).state = NETIF_STOPPED;
104
        ( ** device ).state = NETIF_STOPPED;
94
        ( ** device ).flags = NULL;
-
 
95
        ( ** device ).mtu = DEFAULT_MTU;
-
 
96
        if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ))){
105
        if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ))){
97
            free( * device );
106
            free( * device );
98
            * device = NULL;
107
            * device = NULL;
99
            return ERROR_CODE;
108
            return ERROR_CODE;
100
        }
109
        }
Line 103... Line 112...
103
}
112
}
104
 
113
 
105
int initialize( void ){
114
int initialize( void ){
106
    ipcarg_t    phonehash;
115
    ipcarg_t    phonehash;
107
 
116
 
-
 
117
    lo_globals.addr = measured_string_create_bulk( "\0\0\0\0\0\0", 0 );
-
 
118
    if( ! lo_globals.addr ) return ENOMEM;
108
    return REGISTER_ME( SERVICE_LO, & phonehash );
119
    return REGISTER_ME( SERVICE_LO, & phonehash );
109
}
120
}
110
 
121
 
111
void netif_print_name( void ){
122
void netif_print_name( void ){
112
    printf( NAME );
123
    printf( NAME );
Line 143... Line 154...
143
        async_wait_for( message, NULL );
154
        async_wait_for( message, NULL );
144
        return ERROR_CODE;
155
        return ERROR_CODE;
145
    }
156
    }
146
    // MTU is the first one
157
    // MTU is the first one
147
    if( settings && ( settings[ 0 ].value )){
158
    if( settings && ( settings[ 0 ].value )){
148
        device->mtu = strtoul( settings[ 0 ].value, NULL, 0 );
159
        lo_globals.mtu = strtoul( settings[ 0 ].value, NULL, 0 );
149
    }else{
160
    }else{
150
        device->mtu = DEFAULT_MTU;
161
        lo_globals.mtu = DEFAULT_MTU;
151
    }
162
    }
152
    // print the settings
-
 
153
    printf("\n -MTU =\t%d", device->mtu );
-
 
154
    free( settings );
163
    free( settings );
155
    free( data );
164
    free( data );
156
    // end request
165
    // end request
157
    async_wait_for( message, NULL );
166
    async_wait_for( message, NULL );
-
 
167
    // print the settings
-
 
168
    printf("\nNew device registered:\n\tid\t= %d\n\tMTU\t= %d", device->device_id, lo_globals.mtu );
158
    return EOK;
169
    return EOK;
159
}
170
}
160
 
171
 
161
int send_message( device_id_t device_id, packet_t packet ){
172
int send_message( device_id_t device_id, packet_t packet ){
162
    ERROR_DECLARE;
173
    ERROR_DECLARE;