Subversion Repositories HelenOS

Rev

Rev 4743 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4743 Rev 4756
Line 72... Line 72...
72
 */
72
 */
73
arp_globals_t   arp_globals;
73
arp_globals_t   arp_globals;
74
 
74
 
75
/** Creates new protocol specific data.
75
/** Creates new protocol specific data.
76
 *  Allocates and returns the needed memory block as the proto parameter.
76
 *  Allocates and returns the needed memory block as the proto parameter.
77
 *  @param proto The allocated protocol specific data. Output parameter.
77
 *  @param[out] proto The allocated protocol specific data.
78
 *  @param service The protocol module service. Input parameter.
78
 *  @param[in] service The protocol module service.
79
 *  @param address The actual protocol device address. Input parameter.
79
 *  @param[in] address The actual protocol device address.
80
 *  @returns EOK on success.
80
 *  @returns EOK on success.
81
 *  @returns ENOMEM if there is not enough memory left.
81
 *  @returns ENOMEM if there is not enough memory left.
82
 */
82
 */
83
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address );
83
int arp_proto_create( arp_proto_ref * proto, services_t service, measured_string_ref address );
84
 
84
 
85
/** Clears the device specific data.
85
/** Clears the device specific data.
86
 *  @param device The device specific data.
86
 *  @param[in] device The device specific data.
87
 */
87
 */
88
void    clear_device( arp_device_ref device );
88
void    arp_clear_device( arp_device_ref device );
89
 
89
 
90
/** @name Message processing functions
90
/** @name Message processing functions
91
 */
91
 */
92
/*@{*/
92
/*@{*/
93
 
93
 
94
/** Registers the device.
94
/** Registers the device.
95
 *  Creates new device entry in the cache or updates the protocol address if the device with the device identifier and the driver service exists.
95
 *  Creates new device entry in the cache or updates the protocol address if the device with the device identifier and the driver service exists.
96
 *  @param device_id The device identifier. Input parameter.
96
 *  @param[in] device_id The device identifier.
97
 *  @param service The device driver service. Input parameter.
97
 *  @param[in] service The device driver service.
98
 *  @param protocol The protocol service. Input parameter.
98
 *  @param[in] protocol The protocol service.
99
 *  @param address The actual device protocol address.
99
 *  @param[in] address The actual device protocol address.
100
 *  @returns EOK on success.
100
 *  @returns EOK on success.
101
 *  @returns EEXIST if another device with the same device identifier and different driver service exists.
101
 *  @returns EEXIST if another device with the same device identifier and different driver service exists.
102
 *  @returns ENOMEM if there is not enough memory left.
102
 *  @returns ENOMEM if there is not enough memory left.
103
 *  @returns Other error codes as defined for the measured_strings_return() function.
103
 *  @returns Other error codes as defined for the measured_strings_return() function.
104
 */
104
 */
105
int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address );
105
int arp_device_message( device_id_t device_id, services_t service, services_t protocol, measured_string_ref address );
106
 
106
 
107
/** Returns the hardware address for the given protocol address.
107
/** Returns the hardware address for the given protocol address.
108
 *  Sends the ARP request packet if the hardware address is not found in the cache.
108
 *  Sends the ARP request packet if the hardware address is not found in the cache.
109
 *  @param device_id The device identifier. Input parameter.
109
 *  @param[in] device_id The device identifier.
110
 *  @param protocol The protocol service. Input parameter.
110
 *  @param[in] protocol The protocol service.
111
 *  @param target The target protocol address. Input parameter.
111
 *  @param[in] target The target protocol address.
112
 *  @returns The hardware address of the target.
112
 *  @returns The hardware address of the target.
113
 *  @returns NULL if the target parameter is NULL.
113
 *  @returns NULL if the target parameter is NULL.
114
 *  @returns NULL if the device is not found.
114
 *  @returns NULL if the device is not found.
115
 *  @returns NULL if the device packet is too small to send a request.
115
 *  @returns NULL if the device packet is too small to send a request.
116
 *  @returns NULL if the hardware address is not found in the cache.
116
 *  @returns NULL if the hardware address is not found in the cache.
Line 118... Line 118...
118
measured_string_ref arp_translate_message( device_id_t device_id, services_t protocol, measured_string_ref target );
118
measured_string_ref arp_translate_message( device_id_t device_id, services_t protocol, measured_string_ref target );
119
 
119
 
120
/** Processes the received ARP packet.
120
/** Processes the received ARP packet.
121
 *  Updates the source hardware address if the source entry exists or the packet is targeted to my protocol address.
121
 *  Updates the source hardware address if the source entry exists or the packet is targeted to my protocol address.
122
 *  Responses to the ARP request if the packet is the ARP request and is targeted to my address.
122
 *  Responses to the ARP request if the packet is the ARP request and is targeted to my address.
123
 *  @param device_id The source device identifier. Input parameter.
123
 *  @param[in] device_id The source device identifier.
124
 *  @param packet The received packet. Input/output parameter.
124
 *  @param[in,out] packet The received packet.
125
 *  @returns EOK on success and the packet is no longer needed.
125
 *  @returns EOK on success and the packet is no longer needed.
126
 *  @returns 1 on success and the packet has been reused.
126
 *  @returns 1 on success and the packet has been reused.
127
 *  @returns EINVAL if the packet is too small to carry an ARP packet.
127
 *  @returns EINVAL if the packet is too small to carry an ARP packet.
128
 *  @returns EINVAL if the received address lengths differs from the registered values.
128
 *  @returns EINVAL if the received address lengths differs from the registered values.
129
 *  @returns ENOENT if the device is not found in the cache.
129
 *  @returns ENOENT if the device is not found in the cache.
Line 131... Line 131...
131
 *  @returns ENOMEM if there is not enough memory left.
131
 *  @returns ENOMEM if there is not enough memory left.
132
 */
132
 */
133
int arp_receive_message( device_id_t device_id, packet_t packet );
133
int arp_receive_message( device_id_t device_id, packet_t packet );
134
 
134
 
135
/** Updates the device content length according to the new MTU value.
135
/** Updates the device content length according to the new MTU value.
136
 *  @param device_id The device identifier. Input parameter.
136
 *  @param[in] device_id The device identifier.
137
 *  @param mtu The new mtu value. Input parameter.
137
 *  @param[in] mtu The new mtu value.
138
 *  @returns ENOENT if device is not found.
138
 *  @returns ENOENT if device is not found.
139
 *  @returns EOK on success.
139
 *  @returns EOK on success.
140
 */
140
 */
141
int arp_mtu_changed_message( device_id_t device_id, size_t mtu );
141
int arp_mtu_changed_message( device_id_t device_id, size_t mtu );
142
 
142
 
Line 159... Line 159...
159
    device = arp_cache_find( & arp_globals.cache, device_id );
159
    device = arp_cache_find( & arp_globals.cache, device_id );
160
    if( ! device ){
160
    if( ! device ){
161
        fibril_rwlock_write_unlock( & arp_globals.lock );
161
        fibril_rwlock_write_unlock( & arp_globals.lock );
162
        return ENOENT;
162
        return ENOENT;
163
    }
163
    }
164
    clear_device( device );
164
    arp_clear_device( device );
165
    printf( "Device %d cleared\n", device_id );
165
    printf( "Device %d cleared\n", device_id );
166
    fibril_rwlock_write_unlock( & arp_globals.lock );
166
    fibril_rwlock_write_unlock( & arp_globals.lock );
167
    return EOK;
167
    return EOK;
168
}
168
}
169
 
169
 
Line 193... Line 193...
193
 
193
 
194
    fibril_rwlock_write_lock( & arp_globals.lock );
194
    fibril_rwlock_write_lock( & arp_globals.lock );
195
    for( count = arp_cache_count( & arp_globals.cache ) - 1; count >= 0; -- count ){
195
    for( count = arp_cache_count( & arp_globals.cache ) - 1; count >= 0; -- count ){
196
        device = arp_cache_get_index( & arp_globals.cache, count );
196
        device = arp_cache_get_index( & arp_globals.cache, count );
197
        if( device ){
197
        if( device ){
198
            clear_device( device );
198
            arp_clear_device( device );
199
            if( device->addr_data ) free( device->addr_data );
199
            if( device->addr_data ) free( device->addr_data );
200
            if( device->broadcast_data ) free( device->broadcast_data );
200
            if( device->broadcast_data ) free( device->broadcast_data );
201
        }
201
        }
202
    }
202
    }
203
    arp_cache_clear( & arp_globals.cache );
203
    arp_cache_clear( & arp_globals.cache );
Line 479... Line 479...
479
        }
479
        }
480
    }
480
    }
481
    return EOK;
481
    return EOK;
482
}
482
}
483
 
483
 
484
void clear_device( arp_device_ref device ){
484
void arp_clear_device( arp_device_ref device ){
485
    int             count;
485
    int             count;
486
    arp_proto_ref   proto;
486
    arp_proto_ref   proto;
487
 
487
 
488
    for( count = arp_protos_count( & device->protos ) - 1; count >= 0; -- count ){
488
    for( count = arp_protos_count( & device->protos ) - 1; count >= 0; -- count ){
489
        proto = arp_protos_get_index( & device->protos, count );
489
        proto = arp_protos_get_index( & device->protos, count );