Subversion Repositories HelenOS

Rev

Rev 4351 | Rev 4574 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2009 Lukas Mejdrech
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup net
  30.  *  @{
  31.  */
  32.  
  33. /** @file
  34.  *  Wrapper for the bundled networking and TCP/IP stact modules.
  35.  *  Distributes messages and initializes all module parts.
  36.  */
  37.  
  38. #include <stdio.h>
  39.  
  40. #include <ipc/ipc.h>
  41.  
  42. #include "../messages.h"
  43.  
  44. #include "../include/ip_interface.h"
  45.  
  46. #include "../structures/measured_strings.h"
  47. #include "../structures/module_map.h"
  48. #include "../structures/packet/packet_server.h"
  49.  
  50. #include "../il/arp/arp_module.h"
  51. #include "../il/ip/ip_module.h"
  52. #include "../tl/udp/udp_module.h"
  53. #include "../tl/tcp/tcp_module.h"
  54.  
  55. #include "net.h"
  56.  
  57. /** Networking module global data.
  58.  */
  59. extern net_globals_t    net_globals;
  60.  
  61. int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
  62.     if(( IPC_GET_METHOD( * call ) == IPC_M_CONNECT_TO_ME )
  63.     || IS_NET_IL_MESSAGE( call )){
  64.         switch( IPC_GET_TARGET( call )){
  65.             case SERVICE_IP:
  66.                 return ip_message( callid, call, answer, answer_count );
  67.             case SERVICE_ARP:
  68.                 return arp_message( callid, call, answer, answer_count );
  69.             default:
  70.                 return EINVAL;
  71.         }
  72.     }else if( IS_NET_TL_MESSAGE( call )){
  73.         switch( IPC_GET_TARGET( call )){
  74.             case SERVICE_UDP:
  75.                 return udp_message( callid, call, answer, answer_count );
  76.             case SERVICE_TCP:
  77.                 return tcp_message( callid, call, answer, answer_count );
  78.             default:
  79.                 return EINVAL;
  80.         }
  81.     }else if( IS_NET_IP_MESSAGE( call ) || IS_NET_NIL_MESSAGE( call )){
  82.         return ip_message( callid, call, answer, answer_count );
  83.     }else if( IS_NET_ARP_MESSAGE( call )){
  84.         return arp_message( callid, call, answer, answer_count );
  85. /*  }else if( IS_NET_RARP_MESSAGE( call )){
  86.         return rarp_message( callid, call, answer, answer_count );
  87.     }else if( IS_NET_ICMP_MESSAGE( call )){
  88.         return icmp_message( callid, call, answer, answer_count );
  89. */  }else if( IS_NET_UDP_MESSAGE( call )){
  90.         return udp_message( callid, call, answer, answer_count );
  91.     }else if( IS_NET_TCP_MESSAGE( call )){
  92.         return tcp_message( callid, call, answer, answer_count );
  93. /*  }else if( IS_NET_SOCKET_MESSAGE( call )){
  94.         return socket_message( callid, call, answer, answer_count );
  95. */  }else{
  96.         if( IS_NET_PACKET_MESSAGE( call )){
  97.             return packet_server_message( callid, call, answer, answer_count );
  98.         }else{
  99.             return net_message( callid, call, answer, answer_count );
  100.         }
  101.     }
  102. }
  103.  
  104. int net_initialize( async_client_conn_t client_connection ){
  105.     ERROR_DECLARE;
  106.  
  107.     ipcarg_t    phonehash;
  108.  
  109.     netifs_initialize( & net_globals.netifs );
  110.     char_map_initialize( & net_globals.netif_names );
  111.     modules_initialize( & net_globals.modules );
  112.     measured_strings_initialize( & net_globals.configuration );
  113.  
  114.     // run self tests
  115. //  ERROR_PROPAGATE( self_test());
  116.  
  117.     ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service ));
  118.     ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service ));
  119.  
  120.     ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
  121.     ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module ));
  122.     ERROR_PROPAGATE( ip_initialize( client_connection ));
  123.     ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
  124.     ERROR_PROPAGATE( arp_initialize( client_connection ));
  125. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash ));
  126. //  ERROR_PROPAGATE( rarp_initialize( client_connection ));
  127. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash ));
  128. //  ERROR_PROPAGATE( icmp_initialize( client_connection ));
  129.     ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash ));
  130.     ERROR_PROPAGATE( udp_initialize( client_connection ));
  131.     ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
  132.     ERROR_PROPAGATE( tcp_initialize( client_connection ));
  133. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash ));
  134. //  ERROR_PROPAGATE( socket_initialize( client_connection ));
  135. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash ));
  136. //  ERROR_PROPAGATE( ethernet_initialize( client_connection ));
  137.     return EOK;
  138. }
  139.  
  140. int read_netif_configuration( char * name, netif_ref netif ){
  141.     ERROR_DECLARE;
  142.  
  143.     if( str_lcmp( name, "lo", 2 ) == 0 ){
  144.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME ));
  145.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME ));
  146.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME ));
  147.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" ));
  148.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" ));
  149.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ));
  150.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "15535" ));
  151.     }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){
  152.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" ));
  153.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME ));
  154.         // ethernet bundled in dp8390
  155.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME ));
  156.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_MODE", "DIX" ));
  157.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME ));
  158.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" ));
  159.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" ));
  160.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" ));
  161.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" ));
  162.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" ));
  163.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.240" ));
  164.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" ));
  165.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" ));
  166.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" ));
  167.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" ));
  168.         ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" ));
  169.     }
  170.     return EOK;
  171. }
  172.  
  173. /** @}
  174.  */
  175.