Changes in uspace/srv/net/netif/lo/lo.c [19f857a:14f1db0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netif/lo/lo.c
r19f857a r14f1db0 43 43 #include <ipc/services.h> 44 44 45 #include "../../err.h" 46 #include "../../messages.h" 47 #include "../../modules.h" 48 49 #include "../../structures/measured_strings.h" 50 #include "../../structures/packet/packet_client.h" 51 52 #include "../../include/device.h" 53 #include "../../include/nil_interface.h" 54 55 #include "../../nil/nil_messages.h" 56 57 #include "../netif.h" 58 #include "../netif_module.h" 45 #include <net_err.h> 46 #include <net_messages.h> 47 #include <net_modules.h> 48 #include <adt/measured_strings.h> 49 #include <packet/packet_client.h> 50 #include <net_device.h> 51 #include <nil_interface.h> 52 #include <nil_messages.h> 53 #include <netif_interface.h> 54 #include <netif_local.h> 59 55 60 56 /** Default hardware address. … … 68 64 /** Loopback module name. 69 65 */ 70 #define NAME "lo - loopback interface"66 #define NAME "lo" 71 67 72 68 /** Network interface global data. … … 80 76 * @returns EOK otherwise. 81 77 */ 82 int change_state_message( device_refdevice, device_state_t state);78 int change_state_message(netif_device_t * device, device_state_t state); 83 79 84 80 /** Creates and returns the loopback network interface structure. … … 89 85 * @returns ENOMEM if there is not enough memory left. 90 86 */ 91 int create(device_id_t device_id, device_ref * device); 92 93 /** Prints the module name. 94 * @see NAME 95 */ 96 void module_print_name(void); 87 int create(device_id_t device_id, netif_device_t * * device); 97 88 98 89 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ … … 112 103 ERROR_DECLARE; 113 104 114 device_refdevice;105 netif_device_t * device; 115 106 116 107 if(! stats){ … … 122 113 } 123 114 124 int change_state_message(device_ref device, device_state_t state){ 125 if(device->state != state){ 115 int change_state_message(netif_device_t * device, device_state_t state) 116 { 117 if (device->state != state) { 126 118 device->state = state; 127 printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED"); 119 120 printf("%s: State changed to %s\n", NAME, 121 (state == NETIF_ACTIVE) ? "active" : "stopped"); 122 128 123 return state; 129 124 } 130 return EOK; 131 } 132 133 int create(device_id_t device_id, device_ref * device){ 125 126 return EOK; 127 } 128 129 int create(device_id_t device_id, netif_device_t * * device){ 134 130 int index; 135 131 136 if( device_map_count(&netif_globals.device_map) > 0){132 if(netif_device_map_count(&netif_globals.device_map) > 0){ 137 133 return EXDEV; 138 134 }else{ 139 *device = ( device_ref) malloc(sizeof(device_t));135 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 140 136 if(!(*device)){ 141 137 return ENOMEM; … … 150 146 (** device).nil_phone = -1; 151 147 (** device).state = NETIF_STOPPED; 152 index = device_map_add(&netif_globals.device_map, (** device).device_id, * device);148 index = netif_device_map_add(&netif_globals.device_map, (** device).device_id, * device); 153 149 if(index < 0){ 154 150 free(*device); … … 167 163 } 168 164 169 void module_print_name(void){170 printf("%s", NAME);171 }172 173 165 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){ 174 166 ERROR_DECLARE; 175 167 176 device_refdevice;168 netif_device_t * device; 177 169 178 170 // create a new device 179 171 ERROR_PROPAGATE(create(device_id, &device)); 180 172 // print the settings 181 printf(" New device created:\n\tid\t= %d\n", device->device_id);173 printf("%s: Device created (id: %d)\n", NAME, device->device_id); 182 174 return EOK; 183 175 } … … 186 178 ERROR_DECLARE; 187 179 188 device_refdevice;180 netif_device_t * device; 189 181 size_t length; 190 182 packet_t next; … … 212 204 } 213 205 214 int netif_start_message( device_refdevice){206 int netif_start_message(netif_device_t * device){ 215 207 return change_state_message(device, NETIF_ACTIVE); 216 208 } 217 209 218 int netif_stop_message( device_refdevice){210 int netif_stop_message(netif_device_t * device){ 219 211 return change_state_message(device, NETIF_STOPPED); 220 212 } 221 213 214 /** Default thread for new connections. 215 * 216 * @param[in] iid The initial message identifier. 217 * @param[in] icall The initial message call structure. 218 * 219 */ 220 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall) 221 { 222 /* 223 * Accept the connection 224 * - Answer the first IPC_M_CONNECT_ME_TO call. 225 */ 226 ipc_answer_0(iid, EOK); 227 228 while(true) { 229 ipc_call_t answer; 230 int answer_count; 231 232 /* Clear the answer structure */ 233 refresh_answer(&answer, &answer_count); 234 235 /* Fetch the next message */ 236 ipc_call_t call; 237 ipc_callid_t callid = async_get_call(&call); 238 239 /* Process the message */ 240 int res = netif_module_message(NAME, callid, &call, &answer, 241 &answer_count); 242 243 /* End if said to either by the message or the processing result */ 244 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)) 245 return; 246 247 /* Answer the message */ 248 answer_call(callid, res, &answer, answer_count); 249 } 250 } 251 252 int main(int argc, char *argv[]) 253 { 254 ERROR_DECLARE; 255 256 /* Start the module */ 257 if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) 258 return ERROR_CODE; 259 260 return EOK; 261 } 262 222 263 /** @} 223 264 */
Note:
See TracChangeset
for help on using the changeset viewer.