Subversion Repositories HelenOS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2008 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.  */
  35.  
  36. #include <async.h>
  37. #include <errno.h>
  38. #include <stdio.h>
  39. #include <task.h>
  40. #include <ipc/ipc.h>
  41. #include <ipc/services.h>
  42. //#include <sys/mman.h>
  43.  
  44. #include "../modules.h"
  45. #include "../messages.h"
  46.  
  47. #ifdef NETWORKING_module
  48.  
  49.     #include "../ip/ip.h"
  50.     #include "../tcp/tcp.h"
  51.  
  52. #endif
  53.  
  54. #define IS_IN_INTERVAL( item, first_inclusive, last_exclusive ) ((( item ) >= ( first_inclusive )) && (( item ) < ( last_exclusive )))
  55.  
  56. #define IS_NET_MESSAGE( call )          IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_FIRST, NET_LAST )
  57. #define IS_NET_NETWORKING_MESSAGE( call )   IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_NETWORKING_FIRST, NET_NETWORKING_LAST )
  58. #define IS_NET_IP_MESSAGE( call )       IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_IP_FIRST, NET_IP_LAST )
  59. #define IS_NET_ARP_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_ARP_FIRST, NET_ARP_LAST )
  60. #define IS_NET_RARP_MESSAGE( call )     IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_RARP_FIRST, NET_RARP_LAST )
  61. #define IS_NET_UDP_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_UDP_FIRST, NET_UDP_LAST )
  62. #define IS_NET_TCP_MESSAGE( call )      IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_TCP_FIRST, NET_TCP_LAST )
  63. #define IS_NET_SOCKET_MESSAGE( call )       IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_SOCKET_FIRST, NET_SOCKET_LAST )
  64. #define IS_NET_ETHERNET_MESSAGE( call )     IS_IN_INTERVAL( IPC_GET_METHOD( call ), NET_ETHERNET_FIRST, NET_SOCKET_LAST )
  65.  
  66. int networking_initialize( void );
  67. static void client_connection( ipc_callid_t iid, ipc_call_t * icall );
  68. int main( int argc, char * argv[] );
  69. int spawn( const char * fname );
  70. int networking_call( ipc_callid_t callid );
  71. int networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3 );
  72.  
  73. int networking_call( ipc_callid_t callid ){
  74.     return EOK;
  75. }
  76.  
  77. int networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3 ){
  78.     switch( method ){
  79.         case IPC_M_PHONE_HUNGUP:
  80.             return EOK;
  81.     }
  82.     return ENOTSUP;
  83. }
  84.  
  85. int spawn(const char *fname)
  86. {
  87.     const char *argv[2];
  88.     int res;
  89.  
  90.     printf("Spawning %s\n", fname);
  91.  
  92.     argv[0] = fname;
  93.     argv[1] = NULL;
  94.  
  95.     res = task_spawn(fname, argv);
  96.     if( res != 0 ){
  97.         /* Success */
  98.         sleep(1);
  99.     }else return EINVAL;
  100.  
  101.     return EOK;
  102. }
  103.  
  104. /** Initializes the module.
  105.  */
  106. int networking_initialize( void ){
  107.     ERROR_DECLARE;
  108.  
  109. #ifdef NETWORKING_modular
  110.     ERROR_PROPAGATE( spawn("/sbin/ip"));
  111. //  ERROR_PROPAGATE( spawn("/sbin/arp"));
  112. //  ERROR_PROPAGATE( spawn("/sbin/rarp"));
  113. //  ERROR_PROPAGATE( spawn("/sbin/icmp"));
  114. //  ERROR_PROPAGATE( spawn("/sbin/udp"));
  115.     ERROR_PROPAGATE( spawn("/sbin/tcp"));
  116. //  ERROR_PROPAGATE( spawn("/sbin/socket"));
  117. #else
  118. #ifdef NETWORKING_module
  119.     ipcarg_t phonehash;
  120.  
  121.     ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
  122.     ERROR_PROPAGATE( ip_initialize());
  123. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
  124. //  ERROR_PROPAGATE( arp_initialize());
  125. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash ));
  126. //  ERROR_PROPAGATE( rarp_initialize());
  127. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash ));
  128. //  ERROR_PROPAGATE( icmp_initialize());
  129. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash ));
  130. //  ERROR_PROPAGATE( udp_initialize());
  131.     ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
  132.     ERROR_PROPAGATE( tcp_initialize());
  133. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_SOCKET, & phonehash ));
  134. //  ERROR_PROPAGATE( socket_initialize());
  135. //  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ETHERNET, & phonehash ));
  136. //  ERROR_PROPAGATE( ethernet_initialize());
  137. #endif
  138. #endif
  139.     return EOK;
  140. }
  141.  
  142. /** Default thread for new connections.
  143.  */
  144. static void client_connection( ipc_callid_t iid, ipc_call_t * icall ){
  145.     ipc_callid_t callid;
  146.     ipc_call_t call;
  147.     ipcarg_t arg1, arg2, arg3;
  148.     int res;
  149.  
  150.     /* Accept the connection */
  151.     ipc_answer_0( iid, EOK );
  152.  
  153.     while( true ){
  154.         callid = async_get_call( & call );
  155.         arg1 = 0;
  156.         arg2 = 0;
  157.         arg3 = 0;
  158. #ifdef NETWORKING_module
  159.         if( IS_NET_IP_MESSAGE( call )){
  160.             res = ip_call( callid );
  161.             if( res == EOK ){
  162.                 res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  163.             }
  164. /*      }else if( IS_NET_ARP_MESSAGE( call )){
  165.             res = arp_call( callid );
  166.             if( res == EOK ){
  167.                 res = arp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  168.             }
  169. *//*        }else if( IS_NET_RARP_MESSAGE( call )){
  170.             res = rarp_call( callid );
  171.             if( res == EOK ){
  172.                 res = rarp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  173.             }
  174. *//*        }else if( IS_NET_ICMP_MESSAGE( call )){
  175.             res = icmp_call( callid );
  176.             if( res == EOK ){
  177.                 res = icmp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  178.             }
  179. *//*        }else if( IS_NET_UDP_MESSAGE( call )){
  180.             res = udp_call( callid );
  181.             if( res == EOK ){
  182.                 res = udp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  183.             }
  184. */      }else if( IS_NET_TCP_MESSAGE( call )){
  185.             res = tcp_call( callid );
  186.             if( res == EOK ){
  187.                 res = tcp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  188.             }
  189. /*      }else if( IS_NET_SOCKET_MESSAGE( call )){
  190.             res = socket_call( callid );
  191.             if( res == EOK ){
  192.                 res = socket_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  193.             }
  194. *//*        }else if( IS_NET_ETHERNET_MESSAGE( call )){
  195.             res = ethernet_call( callid );
  196.             if( res == EOK ){
  197.                 res = ethernet_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  198.             }
  199. */      }else{
  200. #endif
  201.             res = networking_call( callid );
  202.             if( res == EOK ){
  203.                 res = networking_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
  204.             }
  205. #ifdef NETWORKING_module
  206.         }
  207. #endif
  208.         ipc_answer_2( callid, EOK, arg1, arg2 );
  209.     }
  210. }
  211.  
  212. /** Starts the module.
  213.  *  Parameters are ignored.
  214.  */
  215. int main( int argc, char * argv[] ){
  216.  
  217.     printf("networking : HelenOS Networking subsystem\n");
  218.  
  219.     return start_service( SERVICE_NETWORKING, NULL, NULL, client_connection, networking_initialize );
  220. }
  221.  
  222. /** @}
  223.  */
  224.