ip_remote.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009 Lukas Mejdrech
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00042 #include <ip_remote.h>
00043 #include <ip_interface.h>
00044 #include <packet_client.h>
00045 #include <generic.h>
00046 
00047 #include <ipc/services.h>
00048 #include <ipc/il.h>
00049 #include <ipc/ip.h>
00050 
00051 #include <net/modules.h>
00052 #include <net/device.h>
00053 #include <net/inet.h>
00054 
00065 int ip_add_route_req_remote(int ip_phone, device_id_t device_id,
00066     in_addr_t address, in_addr_t netmask, in_addr_t gateway)
00067 {
00068         return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE,
00069             (sysarg_t) device_id, (sysarg_t) gateway.s_addr,
00070             (sysarg_t) address.s_addr, (sysarg_t) netmask.s_addr);
00071 }
00072 
00085 int ip_bind_service(services_t service, int protocol, services_t me,
00086     async_client_conn_t receiver)
00087 {
00088         return (int) bind_service(service, (sysarg_t) protocol, me, service,
00089             receiver);
00090 }
00091 
00097 int ip_connect_module(services_t service)
00098 {
00099         return connect_to_service(SERVICE_IP);
00100 }
00101 
00120 int ip_device_req_remote(int ip_phone, device_id_t device_id,
00121     services_t service)
00122 {
00123         return generic_device_req_remote(ip_phone, NET_IP_DEVICE, device_id, 0,
00124             service);
00125 }
00126 
00139 int ip_get_route_req_remote(int ip_phone, ip_protocol_t protocol,
00140     const struct sockaddr *destination, socklen_t addrlen,
00141     device_id_t *device_id, void **header, size_t *headerlen)
00142 {
00143         if (!destination || (addrlen == 0))
00144                 return EINVAL;
00145         
00146         if (!device_id || !header || !headerlen)
00147                 return EBADMEM;
00148         
00149         *header = NULL;
00150         
00151         ipc_call_t answer;
00152         aid_t message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE,
00153             (sysarg_t) protocol, &answer);
00154         
00155         if ((async_data_write_start(ip_phone, destination, addrlen) == EOK) &&
00156             (async_data_read_start(ip_phone, headerlen,
00157             sizeof(*headerlen)) == EOK) && (*headerlen > 0)) {
00158                 *header = malloc(*headerlen);
00159                 if (*header) {
00160                         if (async_data_read_start(ip_phone, *header,
00161                             *headerlen) != EOK)
00162                                 free(*header);
00163                 }
00164         }
00165         
00166         sysarg_t result;
00167         async_wait_for(message_id, &result);
00168         
00169         if ((result != EOK) && *header)
00170                 free(*header);
00171         else
00172                 *device_id = IPC_GET_DEVICE(answer);
00173         
00174         return (int) result;
00175 }
00176 
00187 int ip_packet_size_req_remote(int ip_phone, device_id_t device_id,
00188     packet_dimension_t *packet_dimension)
00189 {
00190         return generic_packet_size_req_remote(ip_phone, NET_IP_PACKET_SPACE,
00191             device_id, packet_dimension);
00192 }
00193 
00205 int ip_received_error_msg_remote(int ip_phone, device_id_t device_id,
00206     packet_t *packet, services_t target, services_t error)
00207 {
00208         return generic_received_msg_remote(ip_phone, NET_IP_RECEIVED_ERROR,
00209             device_id, packet_get_id(packet), target, error);
00210 }
00211 
00227 int ip_send_msg_remote(int ip_phone, device_id_t device_id, packet_t *packet,
00228     services_t sender, services_t error)
00229 {
00230         return generic_send_msg_remote(ip_phone, NET_IP_SEND, device_id,
00231             packet_get_id(packet), sender, error);
00232 }
00233 
00242 int ip_set_gateway_req_remote(int ip_phone, device_id_t device_id,
00243     in_addr_t gateway)
00244 {
00245         return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY,
00246             (sysarg_t) device_id, (sysarg_t) gateway.s_addr);
00247 }
00248 

Generated on Thu Jun 2 07:45:48 2011 for HelenOS/USB by  doxygen 1.4.7