Changes in uspace/srv/net/netif/lo/lo.c [aadf01e:a000878c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netif/lo/lo.c
raadf01e ra000878c 64 64 /** Default address length. 65 65 */ 66 #define DEFAULT_ADDR_LEN ( sizeof(DEFAULT_ADDR) / sizeof(char))66 #define DEFAULT_ADDR_LEN ( sizeof( DEFAULT_ADDR ) / sizeof( char )) 67 67 68 68 /** Loopback module name. … … 80 80 * @returns EOK otherwise. 81 81 */ 82 int change_state_message(device_ref device, device_state_t state);82 int change_state_message( device_ref device, device_state_t state ); 83 83 84 84 /** Creates and returns the loopback network interface structure. … … 89 89 * @returns ENOMEM if there is not enough memory left. 90 90 */ 91 int create(device_id_t device_id, device_ref * device);91 int create( device_id_t device_id, device_ref * device ); 92 92 93 93 /** Prints the module name. 94 94 * @see NAME 95 95 */ 96 void module_print_name(void);97 98 int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){96 void module_print_name( void ); 97 98 int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ 99 99 return ENOTSUP; 100 100 } 101 101 102 int netif_get_addr_message(device_id_t device_id, measured_string_ref address){ 103 if(! address){ 104 return EBADMEM; 105 } 102 int netif_get_addr_message( device_id_t device_id, measured_string_ref address ){ 103 if( ! address ) return EBADMEM; 106 104 address->value = str_dup(DEFAULT_ADDR); 107 105 address->length = DEFAULT_ADDR_LEN; … … 109 107 } 110 108 111 int netif_get_device_stats( device_id_t device_id, device_stats_ref stats){109 int netif_get_device_stats( device_id_t device_id, device_stats_ref stats ){ 112 110 ERROR_DECLARE; 113 111 114 device_ref device; 115 116 if(! stats){ 117 return EBADMEM; 118 } 119 ERROR_PROPAGATE(find_device(device_id, &device)); 120 memcpy(stats, (device_stats_ref) device->specific, sizeof(device_stats_t)); 121 return EOK; 122 } 123 124 int change_state_message(device_ref device, device_state_t state){ 125 if(device->state != state){ 112 device_ref device; 113 114 if( ! stats ) return EBADMEM; 115 ERROR_PROPAGATE( find_device( device_id, & device )); 116 memcpy( stats, ( device_stats_ref ) device->specific, sizeof( device_stats_t )); 117 return EOK; 118 } 119 120 int change_state_message( device_ref device, device_state_t state ){ 121 if( device->state != state ){ 126 122 device->state = state; 127 printf( "State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED");123 printf( "State changed to %s\n", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); 128 124 return state; 129 125 } … … 131 127 } 132 128 133 int create( device_id_t device_id, device_ref * device){134 int 135 136 if( device_map_count(&netif_globals.device_map) > 0){129 int create( device_id_t device_id, device_ref * device ){ 130 int index; 131 132 if( device_map_count( & netif_globals.device_map ) > 0 ){ 137 133 return EXDEV; 138 134 }else{ 139 *device = (device_ref) malloc(sizeof(device_t)); 140 if(!(*device)){ 135 * device = ( device_ref ) malloc( sizeof( device_t )); 136 if( !( * device )) return ENOMEM; 137 ( ** device ).specific = malloc( sizeof( device_stats_t )); 138 if( ! ( ** device ).specific ){ 139 free( * device ); 141 140 return ENOMEM; 142 141 } 143 (** device).specific = malloc(sizeof(device_stats_t)); 144 if(! (** device).specific){ 145 free(*device); 146 return ENOMEM; 147 } 148 null_device_stats((device_stats_ref)(** device).specific); 149 (** device).device_id = device_id; 150 (** device).nil_phone = -1; 151 (** device).state = NETIF_STOPPED; 152 index = device_map_add(&netif_globals.device_map, (** device).device_id, * device); 153 if(index < 0){ 154 free(*device); 155 free((** device).specific); 156 *device = NULL; 142 null_device_stats(( device_stats_ref )( ** device ).specific ); 143 ( ** device ).device_id = device_id; 144 ( ** device ).nil_phone = -1; 145 ( ** device ).state = NETIF_STOPPED; 146 index = device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ); 147 if( index < 0 ){ 148 free( * device ); 149 free(( ** device ).specific ); 150 * device = NULL; 157 151 return index; 158 152 } … … 161 155 } 162 156 163 int netif_initialize( void){164 ipcarg_t 165 166 return REGISTER_ME( SERVICE_LO, &phonehash);167 } 168 169 void module_print_name( void){170 printf( "%s", NAME);171 } 172 173 int netif_probe_message( device_id_t device_id, int irq, uintptr_t io){157 int netif_initialize( void ){ 158 ipcarg_t phonehash; 159 160 return REGISTER_ME( SERVICE_LO, & phonehash ); 161 } 162 163 void module_print_name( void ){ 164 printf( "%s", NAME ); 165 } 166 167 int netif_probe_message( device_id_t device_id, int irq, uintptr_t io ){ 174 168 ERROR_DECLARE; 175 169 176 device_ref 170 device_ref device; 177 171 178 172 // create a new device 179 ERROR_PROPAGATE( create(device_id, &device));173 ERROR_PROPAGATE( create( device_id, & device )); 180 174 // print the settings 181 printf("New device created:\n\tid\t= %d\n", device->device_id );182 return EOK; 183 } 184 185 int netif_send_message( device_id_t device_id, packet_t packet, services_t sender){175 printf("New device created:\n\tid\t= %d\n", device->device_id ); 176 return EOK; 177 } 178 179 int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ 186 180 ERROR_DECLARE; 187 181 188 device_ref 189 size_t 190 packet_t 191 int 192 193 ERROR_PROPAGATE( find_device(device_id, &device));194 if( device->state != NETIF_ACTIVE){195 netif_pq_release( packet_get_id(packet));182 device_ref device; 183 size_t length; 184 packet_t next; 185 int phone; 186 187 ERROR_PROPAGATE( find_device( device_id, & device )); 188 if( device->state != NETIF_ACTIVE ){ 189 netif_pq_release( packet_get_id( packet )); 196 190 return EFORWARD; 197 191 } 198 192 next = packet; 199 193 do{ 200 ++ (( device_stats_ref) device->specific)->send_packets;201 ++ (( device_stats_ref) device->specific)->receive_packets;202 length = packet_get_data_length( next);203 (( device_stats_ref) device->specific)->send_bytes += length;204 (( device_stats_ref) device->specific)->receive_bytes += length;205 next = pq_next( next);206 }while( next);194 ++ (( device_stats_ref ) device->specific )->send_packets; 195 ++ (( device_stats_ref ) device->specific )->receive_packets; 196 length = packet_get_data_length( next ); 197 (( device_stats_ref ) device->specific )->send_bytes += length; 198 (( device_stats_ref ) device->specific )->receive_bytes += length; 199 next = pq_next( next ); 200 }while( next ); 207 201 phone = device->nil_phone; 208 fibril_rwlock_write_unlock( &netif_globals.lock);209 nil_received_msg( phone, device_id, packet, sender);210 fibril_rwlock_write_lock( &netif_globals.lock);211 return EOK; 212 } 213 214 int netif_start_message( device_ref device){215 return change_state_message( device, NETIF_ACTIVE);216 } 217 218 int netif_stop_message( device_ref device){219 return change_state_message( device, NETIF_STOPPED);202 fibril_rwlock_write_unlock( & netif_globals.lock ); 203 nil_received_msg( phone, device_id, packet, sender ); 204 fibril_rwlock_write_lock( & netif_globals.lock ); 205 return EOK; 206 } 207 208 int netif_start_message( device_ref device ){ 209 return change_state_message( device, NETIF_ACTIVE ); 210 } 211 212 int netif_stop_message( device_ref device ){ 213 return change_state_message( device, NETIF_STOPPED ); 220 214 } 221 215
Note:
See TracChangeset
for help on using the changeset viewer.