Ignore:
File:
1 edited

Legend:

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

    r19f857a r14f1db0  
    4343#include <ipc/services.h>
    4444
    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>
    5955
    6056/** Default hardware address.
     
    6864/** Loopback module name.
    6965 */
    70 #define NAME    "lo - loopback interface"
     66#define NAME  "lo"
    7167
    7268/** Network interface global data.
     
    8076 *  @returns EOK otherwise.
    8177 */
    82 int change_state_message(device_ref device, device_state_t state);
     78int change_state_message(netif_device_t * device, device_state_t state);
    8379
    8480/** Creates and returns the loopback network interface structure.
     
    8985 *  @returns ENOMEM if there is not enough memory left.
    9086 */
    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);
     87int create(device_id_t device_id, netif_device_t * * device);
    9788
    9889int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     
    112103        ERROR_DECLARE;
    113104
    114         device_ref device;
     105        netif_device_t * device;
    115106
    116107        if(! stats){
     
    122113}
    123114
    124 int change_state_message(device_ref device, device_state_t state){
    125         if(device->state != state){
     115int change_state_message(netif_device_t * device, device_state_t state)
     116{
     117        if (device->state != state) {
    126118                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               
    128123                return state;
    129124        }
    130         return EOK;
    131 }
    132 
    133 int create(device_id_t device_id, device_ref * device){
     125       
     126        return EOK;
     127}
     128
     129int create(device_id_t device_id, netif_device_t * * device){
    134130        int index;
    135131
    136         if(device_map_count(&netif_globals.device_map) > 0){
     132        if(netif_device_map_count(&netif_globals.device_map) > 0){
    137133                return EXDEV;
    138134        }else{
    139                 *device = (device_ref) malloc(sizeof(device_t));
     135                *device = (netif_device_t *) malloc(sizeof(netif_device_t));
    140136                if(!(*device)){
    141137                        return ENOMEM;
     
    150146                (** device).nil_phone = -1;
    151147                (** 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);
    153149                if(index < 0){
    154150                        free(*device);
     
    167163}
    168164
    169 void module_print_name(void){
    170         printf("%s", NAME);
    171 }
    172 
    173165int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
    174166        ERROR_DECLARE;
    175167
    176         device_ref device;
     168        netif_device_t * device;
    177169
    178170        // create a new device
    179171        ERROR_PROPAGATE(create(device_id, &device));
    180172        // 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);
    182174        return EOK;
    183175}
     
    186178        ERROR_DECLARE;
    187179
    188         device_ref device;
     180        netif_device_t * device;
    189181        size_t length;
    190182        packet_t next;
     
    212204}
    213205
    214 int netif_start_message(device_ref device){
     206int netif_start_message(netif_device_t * device){
    215207        return change_state_message(device, NETIF_ACTIVE);
    216208}
    217209
    218 int netif_stop_message(device_ref device){
     210int netif_stop_message(netif_device_t * device){
    219211        return change_state_message(device, NETIF_STOPPED);
    220212}
    221213
     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 */
     220static 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
     252int 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
    222263/** @}
    223264 */
Note: See TracChangeset for help on using the changeset viewer.