Changes in uspace/srv/net/netif/lo/lo.c [14f1db0:19f857a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netif/lo/lo.c
r14f1db0 r19f857a 43 43 #include <ipc/services.h> 44 44 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> 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" 55 59 56 60 /** Default hardware address. … … 64 68 /** Loopback module name. 65 69 */ 66 #define NAME "lo"70 #define NAME "lo - loopback interface" 67 71 68 72 /** Network interface global data. … … 76 80 * @returns EOK otherwise. 77 81 */ 78 int change_state_message( netif_device_t *device, device_state_t state);82 int change_state_message(device_ref device, device_state_t state); 79 83 80 84 /** Creates and returns the loopback network interface structure. … … 85 89 * @returns ENOMEM if there is not enough memory left. 86 90 */ 87 int create(device_id_t device_id, netif_device_t * * device); 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); 88 97 89 98 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ … … 103 112 ERROR_DECLARE; 104 113 105 netif_device_t *device;114 device_ref device; 106 115 107 116 if(! stats){ … … 113 122 } 114 123 115 int change_state_message(netif_device_t * device, device_state_t state) 116 { 117 if (device->state != state) { 124 int change_state_message(device_ref device, device_state_t state){ 125 if(device->state != state){ 118 126 device->state = state; 119 120 printf("%s: State changed to %s\n", NAME, 121 (state == NETIF_ACTIVE) ? "active" : "stopped"); 122 127 printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED"); 123 128 return state; 124 129 } 125 126 return EOK; 127 } 128 129 int create(device_id_t device_id, netif_device_t * * device){ 130 return EOK; 131 } 132 133 int create(device_id_t device_id, device_ref * device){ 130 134 int index; 131 135 132 if( netif_device_map_count(&netif_globals.device_map) > 0){136 if(device_map_count(&netif_globals.device_map) > 0){ 133 137 return EXDEV; 134 138 }else{ 135 *device = ( netif_device_t *) malloc(sizeof(netif_device_t));139 *device = (device_ref) malloc(sizeof(device_t)); 136 140 if(!(*device)){ 137 141 return ENOMEM; … … 146 150 (** device).nil_phone = -1; 147 151 (** device).state = NETIF_STOPPED; 148 index = netif_device_map_add(&netif_globals.device_map, (** device).device_id, * device);152 index = device_map_add(&netif_globals.device_map, (** device).device_id, * device); 149 153 if(index < 0){ 150 154 free(*device); … … 163 167 } 164 168 169 void module_print_name(void){ 170 printf("%s", NAME); 171 } 172 165 173 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){ 166 174 ERROR_DECLARE; 167 175 168 netif_device_t *device;176 device_ref device; 169 177 170 178 // create a new device 171 179 ERROR_PROPAGATE(create(device_id, &device)); 172 180 // print the settings 173 printf(" %s: Device created (id: %d)\n", NAME, device->device_id);181 printf("New device created:\n\tid\t= %d\n", device->device_id); 174 182 return EOK; 175 183 } … … 178 186 ERROR_DECLARE; 179 187 180 netif_device_t *device;188 device_ref device; 181 189 size_t length; 182 190 packet_t next; … … 204 212 } 205 213 206 int netif_start_message( netif_device_t *device){214 int netif_start_message(device_ref device){ 207 215 return change_state_message(device, NETIF_ACTIVE); 208 216 } 209 217 210 int netif_stop_message( netif_device_t *device){218 int netif_stop_message(device_ref device){ 211 219 return change_state_message(device, NETIF_STOPPED); 212 220 } 213 221 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 connection224 * - 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 263 222 /** @} 264 223 */
Note:
See TracChangeset
for help on using the changeset viewer.