00001 /* 00002 * Copyright (c) 2010, FIP AUTHORS 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 are met: 00007 * 00008 * 1) Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 00011 * 2) 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 * 00015 * 3) Neither the name of the FIP AUTHORS nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 /** 00032 * @addtogroup fip_udp 00033 * @{ 00034 */ 00035 /** 00036 * @file 00037 * UDP Send/Receive 00038 * 00039 * @author 00040 * Colin O'Flynn 00041 */ 00042 00043 #ifndef FIP_UDP_H_ 00044 #define FIP_UDP_H_ 00045 00046 /** Have one extra connection for "default" */ 00047 #define FIP_UDP_NUM_CONNS (FIP_CONF_UDP_NUM_CONNS + 1) 00048 00049 typedef unsigned char fip_listenConnNum_t; 00050 00051 _PACKSTART 00052 typedef struct 00053 { 00054 uint16_t sourcePort; 00055 uint16_t destPort; 00056 uint16_t length; 00057 uint16_t checksum; 00058 } _PS fip_udp_header_t; 00059 _PACKEND 00060 00061 typedef struct 00062 { 00063 uint16_t sourcePort; /**< Source port message came from */ 00064 uint16_t destPort; /**< Dest port message came to */ 00065 fip_bool_t isPayloadValid; /**< Is payload valid yet, this flag 00066 gets set if space for the 00067 payload has been allocated 00068 when sending. */ 00069 } fip_udp_attr_t; 00070 00071 /** This structure holds information on any open "listen" ports. */ 00072 typedef struct 00073 { 00074 uint16_t listenPort; /**< UDP Port we listen on */ 00075 fip_ifnum_t ifnum; /**< Interface we listen on */ 00076 fip_ipnum_t ipnum; /**< IP Number we listen on */ 00077 void (*udpProcess)(char *); /**< Function called when new 00078 * data is received */ 00079 char * dataToPass; /**< Parameter passed to function 00080 when new data received */ 00081 } fip_udp_listenPortList_t; 00082 00083 00084 fip_return_t fip_udp_sendSetup(fip_ipversion_t ipVer, 00085 uint8_t * destIPAddr, 00086 uint16_t destPort, 00087 fip_listenConnNum_t listenConn, 00088 unsigned int payloadLength, 00089 fip_ifnum_t ifnum/*TEMP*/); 00090 uint8_t * fip_udp_sendGetPayloadPtr(void); 00091 void fip_udp_sendFinish(unsigned int payloadLen); 00092 00093 void fip_udp_send(fip_ip6addr_t * destAddr, uint16_t srcPort, uint16_t destPort, unsigned int numBytes); 00094 void fip_udp_process(void); 00095 00096 fip_listenConnNum_t fip_udp_openListenPort(uint16_t port, 00097 void (*udpCallback)(char *), 00098 char * parameter, 00099 fip_ipnum_t ipnum, 00100 fip_ifnum_t ifnum); 00101 00102 void fip_udp_closeConnection(fip_listenConnNum_t listen); 00103 00104 void fip_udp_defaultListenProcess(void (*udpCallback)(char *), 00105 char * parameter); 00106 00107 /* For debugging only */ 00108 extern fip_udp_listenPortList_t fip_udp_listenPortList[FIP_UDP_NUM_CONNS]; 00109 00110 /*---------------------------------------------------------------------------*/ 00111 /** addtogroup fip_udp 00112 * @{ */ 00113 /** Get a pointer to the UDP Buffer */ 00114 #define fip_packet_getPtrToUDPBuf() (fip_packet_getBufPtr(FIP_TLBUF)) 00115 /** Get an attribute from the UDP frame */ 00116 #define fip_udp_Attr(type) (fip_packet_spGetPtr(fip_udp_attr_t)->type) 00117 /** @} */ 00118 00119 00120 00121 00122 #endif /* FIP_UDP_H_ */ 00123 /** @} */