Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/netif/lo/lo.c

    r14f1db0 r19f857a  
    4343#include <ipc/services.h>
    4444
    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"
    5559
    5660/** Default hardware address.
     
    6468/** Loopback module name.
    6569 */
    66 #define NAME  "lo"
     70#define NAME    "lo - loopback interface"
    6771
    6872/** Network interface global data.
     
    7680 *  @returns EOK otherwise.
    7781 */
    78 int change_state_message(netif_device_t * device, device_state_t state);
     82int change_state_message(device_ref device, device_state_t state);
    7983
    8084/** Creates and returns the loopback network interface structure.
     
    8589 *  @returns ENOMEM if there is not enough memory left.
    8690 */
    87 int create(device_id_t device_id, netif_device_t * * device);
     91int create(device_id_t device_id, device_ref * device);
     92
     93/** Prints the module name.
     94 *  @see NAME
     95 */
     96void module_print_name(void);
    8897
    8998int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     
    103112        ERROR_DECLARE;
    104113
    105         netif_device_t * device;
     114        device_ref device;
    106115
    107116        if(! stats){
     
    113122}
    114123
    115 int change_state_message(netif_device_t * device, device_state_t state)
    116 {
    117         if (device->state != state) {
     124int change_state_message(device_ref device, device_state_t state){
     125        if(device->state != state){
    118126                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");
    123128                return state;
    124129        }
    125        
    126         return EOK;
    127 }
    128 
    129 int create(device_id_t device_id, netif_device_t * * device){
     130        return EOK;
     131}
     132
     133int create(device_id_t device_id, device_ref * device){
    130134        int index;
    131135
    132         if(netif_device_map_count(&netif_globals.device_map) > 0){
     136        if(device_map_count(&netif_globals.device_map) > 0){
    133137                return EXDEV;
    134138        }else{
    135                 *device = (netif_device_t *) malloc(sizeof(netif_device_t));
     139                *device = (device_ref) malloc(sizeof(device_t));
    136140                if(!(*device)){
    137141                        return ENOMEM;
     
    146150                (** device).nil_phone = -1;
    147151                (** 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);
    149153                if(index < 0){
    150154                        free(*device);
     
    163167}
    164168
     169void module_print_name(void){
     170        printf("%s", NAME);
     171}
     172
    165173int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
    166174        ERROR_DECLARE;
    167175
    168         netif_device_t * device;
     176        device_ref device;
    169177
    170178        // create a new device
    171179        ERROR_PROPAGATE(create(device_id, &device));
    172180        // 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);
    174182        return EOK;
    175183}
     
    178186        ERROR_DECLARE;
    179187
    180         netif_device_t * device;
     188        device_ref device;
    181189        size_t length;
    182190        packet_t next;
     
    204212}
    205213
    206 int netif_start_message(netif_device_t * device){
     214int netif_start_message(device_ref device){
    207215        return change_state_message(device, NETIF_ACTIVE);
    208216}
    209217
    210 int netif_stop_message(netif_device_t * device){
     218int netif_stop_message(device_ref device){
    211219        return change_state_message(device, NETIF_STOPPED);
    212220}
    213221
    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 
    263222/** @}
    264223 */
Note: See TracChangeset for help on using the changeset viewer.