generic.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 
00037 #include <generic.h>
00038 #include <async.h>
00039 #include <ipc/services.h>
00040 #include <net/device.h>
00041 #include <adt/measured_strings.h>
00042 #include <net/packet.h>
00043 
00054 int
00055 generic_device_state_msg_remote(int phone, int message, device_id_t device_id,
00056     int state, services_t target)
00057 {
00058         async_msg_3(phone, (sysarg_t) message, (sysarg_t) device_id,
00059             (sysarg_t) state, target);
00060         
00061         return EOK;
00062 }
00063 
00076 int
00077 generic_device_req_remote(int phone, int message, device_id_t device_id,
00078     int arg2, services_t service)
00079 {
00080         return (int) async_req_3_0(phone, (sysarg_t) message,
00081             (sysarg_t) device_id, (sysarg_t) arg2, (sysarg_t) service);
00082 }
00083 
00097 int
00098 generic_get_addr_req(int phone, int message, device_id_t device_id,
00099     measured_string_t **address, uint8_t **data)
00100 {
00101         aid_t message_id;
00102         sysarg_t result;
00103         int string;
00104 
00105         if (!address || !data)
00106                 return EBADMEM;
00107 
00108         /* Request the address */
00109         message_id = async_send_1(phone, (sysarg_t) message,
00110             (sysarg_t) device_id, NULL);
00111         string = measured_strings_return(phone, address, data, 1);
00112         async_wait_for(message_id, &result);
00113 
00114         /* If not successful */
00115         if ((string == EOK) && (result != EOK)) {
00116                 /* Clear the data */
00117                 free(*address);
00118                 free(*data);
00119         }
00120         
00121         return (int) result;
00122 }
00123 
00135 int
00136 generic_packet_size_req_remote(int phone, int message, device_id_t device_id,
00137     packet_dimension_t *packet_dimension)
00138 {
00139         if (!packet_dimension)
00140                 return EBADMEM;
00141         
00142         sysarg_t addr_len;
00143         sysarg_t prefix;
00144         sysarg_t content;
00145         sysarg_t suffix;
00146         
00147         sysarg_t result = async_req_1_4(phone, (sysarg_t) message,
00148             (sysarg_t) device_id, &addr_len, &prefix, &content, &suffix);
00149         
00150         packet_dimension->prefix = (size_t) prefix;
00151         packet_dimension->content = (size_t) content;
00152         packet_dimension->suffix = (size_t) suffix;
00153         packet_dimension->addr_len = (size_t) addr_len;
00154         
00155         return (int) result;
00156 }
00157 
00169 int
00170 generic_received_msg_remote(int phone, int message, device_id_t device_id,
00171     packet_id_t packet_id, services_t target, services_t error)
00172 {
00173         if (error) {
00174                 async_msg_4(phone, (sysarg_t) message, (sysarg_t) device_id,
00175                     (sysarg_t) packet_id, (sysarg_t) target, (sysarg_t) error);
00176         } else {
00177                 async_msg_3(phone, (sysarg_t) message, (sysarg_t) device_id,
00178                     (sysarg_t) packet_id, (sysarg_t) target);
00179         }
00180         
00181         return EOK;
00182 }
00183 
00195 int
00196 generic_send_msg_remote(int phone, int message, device_id_t device_id,
00197     packet_id_t packet_id, services_t sender, services_t error)
00198 {
00199         if (error) {
00200                 async_msg_4(phone, (sysarg_t) message, (sysarg_t) device_id,
00201                     (sysarg_t) packet_id, (sysarg_t) sender, (sysarg_t) error);
00202         } else {
00203                 async_msg_3(phone, (sysarg_t) message, (sysarg_t) device_id,
00204                     (sysarg_t) packet_id, (sysarg_t) sender);
00205         }
00206         
00207         return EOK;
00208 }
00209 
00230 int
00231 generic_translate_req(int phone, int message, device_id_t device_id,
00232     services_t service, measured_string_t *configuration, size_t count,
00233     measured_string_t **translation, uint8_t **data)
00234 {
00235         aid_t message_id;
00236         sysarg_t result;
00237         int string;
00238 
00239         if (!configuration || (count == 0))
00240                 return EINVAL;
00241         if (!translation || !data)
00242                 return EBADMEM;
00243 
00244         /* Request the translation */
00245         message_id = async_send_3(phone, (sysarg_t) message,
00246             (sysarg_t) device_id, (sysarg_t) count, (sysarg_t) service, NULL);
00247         measured_strings_send(phone, configuration, count);
00248         string = measured_strings_return(phone, translation, data, count);
00249         async_wait_for(message_id, &result);
00250 
00251         /* If not successful */
00252         if ((string == EOK) && (result != EOK)) {
00253                 /* Clear the data */
00254                 free(*translation);
00255                 free(*data);
00256         }
00257 
00258         return (int) result;
00259 }
00260 

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