00001 /**************************************************************** 00002 * (c) 2005 - 2007 Technische Universitaet Dresden * 00003 * This file is part of DROPS, which is distributed under the * 00004 * terms of the GNU General Public License 2. Please see the * 00005 * COPYING file for details. * 00006 ****************************************************************/ 00007 00008 /* Header file for the uIP-ORe library. This lib enables clients to communicate 00009 * through IP/UDP using the uIP stack and ORe. Originally uIP is not built as a 00010 * library, but needs to be linked statically against the application. 00011 * This lib (libuip-ore.a) intents to solve this problem. 00012 */ 00013 00014 #ifndef __UIP_ORE_H 00015 #define __UIP_ORE_H 00016 00017 #include <l4/sys/linkage.h> 00018 #include <arpa/inet.h> 00019 00020 //!\brief Configuration for the uIP library. 00021 typedef struct uip_ore_config 00022 { 00023 char ip[16]; //!< IP address 00024 unsigned short port_nr; //!< port number to use 00025 00026 /* Callback functions for uIP events 00027 * ================================= 00028 */ 00029 /*!\brief Received a packet. 00030 * \param buf the packet data 00031 * \param size data size in bytes 00032 * \param port port the data was received through 00033 * 00034 * NOTE: buf is invalid after returning from this function, so you 00035 * need to make a copy if necessary. 00036 */ 00037 L4_CV void (*recv_callback)(const void *buf, const unsigned size, unsigned port); 00038 00039 /*!\brief Send acknowledgement received. 00040 * 00041 * This is called so that the user is able to free dynamically allocated 00042 * buffers after they have been successfully sent. 00043 * 00044 * NOTE: When closing the connection, all pending data is dropped. For each 00045 * dropped packet the ack_callback() is also called, because also these 00046 * packets might be needed to be freed. 00047 * 00048 * \param addr address of the buffer that has been acknowledged/dropped. 00049 * \param port port this packet was sent through 00050 */ 00051 L4_CV void (*ack_callback)(void *addr, unsigned port); 00052 00053 /*!\brief Retransmit of message necessary. 00054 * 00055 * This could also be done by the library, 00056 * but the callback shall give you the opportunity to react upon such situations. 00057 * 00058 * \param addr packet needing to be retransmitted. Just call uip_ore_send() 00059 * again. 00060 * \param size size of packet 00061 * \param port port to resend to 00062 */ 00063 L4_CV void (*rexmit_callback)(void *addr, unsigned size, unsigned port); 00064 00065 /*!\brief Connection established. 00066 * 00067 * \param ip IP address remote host 00068 * \param port remote port 00069 */ 00070 L4_CV void (*connect_callback)(const struct in_addr ip, unsigned port); 00071 00072 /*!\brief Connection has been aborted. 00073 * \param port remote port 00074 */ 00075 L4_CV void (*abort_callback)(unsigned port); 00076 00077 /*!\brief Connection timed out. 00078 * \param port remote port 00079 */ 00080 L4_CV void (*timeout_callback)(unsigned port); 00081 00082 /*!\brief Connection closed. 00083 * \param port remote port 00084 */ 00085 L4_CV void (*close_callback)(unsigned port); 00086 00087 /*!\brief Periodic poll callback. 00088 * 00089 * uIP periodically polls the server callback function every 500 ms. If 00090 * you want to do something upon this period, this is the callback to 00091 * do so. 00092 */ 00093 L4_CV void (*poll_callback)(void); 00094 } uip_ore_config; 00095 00096 /*!\brief Config function for the uip_ore library. 00097 * \param conf configuration data 00098 */ 00099 L4_CV void uip_ore_initialize(uip_ore_config *conf); 00100 00101 /*!\brief Thread function for the uip-ore library. The library needs to run in a 00102 * new thread. 00103 */ 00104 L4_CV void uip_ore_thread(void *arg); 00105 00106 /*!\brief Send a packet. 00107 * 00108 * This function does however not actually send data, but 00109 * enqueues it into the uIP send list. The main thread will later on make 00110 * sure that this data is sent. 00111 * 00112 * NOTE: The packed will be truncated if it is too long for the underlying 00113 * network layer. 00114 * 00115 * NOTE: After the packet has been acknowledged, the ack_callback() function 00116 * will be called with the address of the send buffer. If you have allocated 00117 * the send buffer dynamically, this is the point where you should free 00118 * the buffer. 00119 * 00120 * \param buf send buffer 00121 * \param size buffer size 00122 */ 00123 L4_CV void uip_ore_send(const char *buf, unsigned size, unsigned port); 00124 00125 /*!\brief Connect to a given IP and port number. 00126 * 00127 * \param ip IP address of remote host 00128 * \param port port at remote host 00129 * 00130 * \return 0 connecting 00131 * \return !=0 error 00132 */ 00133 L4_CV int uip_ore_connect(struct in_addr ip, unsigned port); 00134 00135 /*!\brief Close connection on a given local port. 00136 * 00137 * \param port local port number 00138 */ 00139 L4_CV void uip_ore_close(unsigned port); 00140 00141 #endif