Changeset aadf01e in mainline for uspace/srv/net/netif/lo/lo.c
- Timestamp:
- 2010-03-07T15:13:28Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 936835e
- Parents:
- aa85487
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netif/lo/lo.c
raa85487 raadf01e 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 ) return EBADMEM; 102 int netif_get_addr_message(device_id_t device_id, measured_string_ref address){ 103 if(! address){ 104 return EBADMEM; 105 } 104 106 address->value = str_dup(DEFAULT_ADDR); 105 107 address->length = DEFAULT_ADDR_LEN; … … 107 109 } 108 110 109 int netif_get_device_stats( device_id_t device_id, device_stats_ref stats){111 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){ 110 112 ERROR_DECLARE; 111 113 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 ){ 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){ 122 126 device->state = state; 123 printf( "State changed to %s\n", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED");127 printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED"); 124 128 return state; 125 129 } … … 127 131 } 128 132 129 int create( device_id_t device_id, device_ref * device){130 int 131 132 if( device_map_count( & netif_globals.device_map ) > 0){133 int create(device_id_t device_id, device_ref * device){ 134 int index; 135 136 if(device_map_count(&netif_globals.device_map) > 0){ 133 137 return EXDEV; 134 138 }else{ 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 ); 139 *device = (device_ref) malloc(sizeof(device_t)); 140 if(!(*device)){ 140 141 return ENOMEM; 141 142 } 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; 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; 151 157 return index; 152 158 } … … 155 161 } 156 162 157 int netif_initialize( void){158 ipcarg_t 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){163 int netif_initialize(void){ 164 ipcarg_t phonehash; 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){ 168 174 ERROR_DECLARE; 169 175 170 device_ref 176 device_ref device; 171 177 172 178 // create a new device 173 ERROR_PROPAGATE( create( device_id, & device));179 ERROR_PROPAGATE(create(device_id, &device)); 174 180 // print the settings 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){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){ 180 186 ERROR_DECLARE; 181 187 182 device_ref 183 size_t 184 packet_t 185 int 186 187 ERROR_PROPAGATE( find_device( device_id, & device));188 if( device->state != NETIF_ACTIVE){189 netif_pq_release( packet_get_id( packet));188 device_ref device; 189 size_t length; 190 packet_t next; 191 int phone; 192 193 ERROR_PROPAGATE(find_device(device_id, &device)); 194 if(device->state != NETIF_ACTIVE){ 195 netif_pq_release(packet_get_id(packet)); 190 196 return EFORWARD; 191 197 } 192 198 next = packet; 193 199 do{ 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);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); 201 207 phone = device->nil_phone; 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);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); 214 220 } 215 221
Note:
See TracChangeset
for help on using the changeset viewer.