1 /** \file alc_channel.h \brief ALC channel
2  *
3  *  $Author: peltotal $ $Date: 2007/02/26 13:48:19 $ $Revision: 1.34 $
4  *
5  *  MAD-ALCLIB: Implementation of ALC/LCT protocols, Compact No-Code FEC,
6  *  Simple XOR FEC, Reed-Solomon FEC, and RLC Congestion Control protocol.
7  *  Copyright (c) 2003-2007 TUT - Tampere University of Technology
8  *  main authors/contacts: jani.peltotalo@tut.fi and sami.peltotalo@tut.fi
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  *
24  *  In addition, as a special exception, TUT - Tampere University of Technology
25  *  gives permission to link the code of this program with the OpenSSL library (or
26  *  with modified versions of OpenSSL that use the same license as OpenSSL), and
27  *  distribute linked combinations including the two. You must obey the GNU
28  *  General Public License in all respects for all of the code used other than
29  *  OpenSSL. If you modify this file, you may extend this exception to your version
30  *  of the file, but you are not obligated to do so. If you do not wish to do so,
31  *  delete this exception statement from your version.
32  */
33 
34 #ifndef _ALC_CHANNEL_H_
35 #define _ALC_CHANNEL_H_
36 
37 #ifdef _MSC_VER
38 #include <winsock2.h>
39 #include <ws2tcpip.h>
40 #endif
41 
42 #include "defines.h"
43 #include "utils.h"
44 #include "alc_session.h"
45 
46 #ifdef SSM
47 #include "linux_ssm.h"
48 #endif
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /** Structure for the ALC channel
55  * @struct alc_channel
56  */
57 
58 typedef struct alc_channel {
59 
60 	int ch_id;							/**< session level identifier for the channel */
61 	struct alc_session *s;				/**< pointer to the parent session */
62 
63 	const char *port;					/**< channel's port */
64 	const char *addr;					/**< channel's address */
65 	const char *intface;				/**< channel's interface */
66 	const char *intface_name;			/**< the name of channel's interface */
67 
68 	int tx_rate;						/**< transmission rate in kbit/s on this channel */
69 	int nb_tx_units;					/**< number of sent units per one loop */
70 	BOOL start_sending;					/**< start sending when TRUE in RLC CC */
71 	BOOL ready;							/**< channel ready when TRUE */
72 	int wait_after_sp;					/**< wait this number of loops before start sending in RLC CC */
73 
74 	BOOL previous_lost;					/**< is previous packet lost (with -P option) */
75 
76 #ifdef _MSC_VER
77 	SOCKET	rx_sock;					/**< receiving socket */
78 	SOCKET	tx_sock;					/**< transmitting socket */
79 #else
80 	int	rx_sock;						/**< receiving socket */
81 	int	tx_sock;						/**< transmitting socket */
82 #endif
83 
84 #ifdef SSM
85 	struct ip_mreq_source source_imr;	/**< for SSM join/leave */
86 
87 #ifdef LINUX
88 	struct group_source_req greqs;		/**< for MLDv2 SSM join/leave */
89 #endif
90 
91 #endif
92 
93 	struct ip_mreq imr;					/**< for join/leave */
94 	struct ipv6_mreq imr6;				/**< for IPv6 join/leave*/
95 
96 	struct sockaddr_in remote;			/**< remote multicast address */
97 	struct sockaddr_in6 remote6;		/**< remote IPv6 multicast address */
98 	struct addrinfo *addrinfo;			/**< structure which provides hints concerning the type of socket */
99 	struct tx_queue_struct *queue_ptr;  /**< list which stores packets to be sent */
100 
101 	struct alc_list *receiving_list;    /**< list which stores received packets */
102 
103 #ifdef _MSC_VER
104     HANDLE handle_rx_socket_thread;     /**< handle to thread which receives packets from the socket */
105     unsigned int rx_socket_thread_id;   /**< identifier for thread which receives packets from the socket */
106 #else
107     pthread_t rx_socket_thread_id;       /**< identifier for thread which receives packets from the socket */
108 #endif
109 } alc_channel_t;
110 
111 /**
112  * This function creates and initializes a new channel.
113  *
114  * @param ch pointer to the channel structure
115  * @param s pointer to the parent session structure
116  * @param port pointer to the port string
117  * @param addr pointer to the address string
118  * @param intface pointer to the interface string
119  * @param intface_name pointer to the interface name string
120  * @param tx_rate transmission rate
121  *
122  * @return identifier for created channel in success, -1 in error cases
123  *
124  */
125 
126 int open_alc_channel(alc_channel_t *ch, alc_session_t *s, const char *port,
127 					 const char *addr, const char *intface, const char *intface_name, int tx_rate);
128 
129 /**
130  * This function closes existing channel.
131  *
132  * @param ch pointer to the channel structure to be closed
133  * @param s pointer to the parent session structure
134  *
135  * @return 0 when closing was successful, -1 in error cases
136  *
137  */
138 
139 int close_alc_channel(alc_channel_t *ch, alc_session_t *s);
140 
141 #ifdef __cplusplus
142 }; //extern "C"
143 #endif
144 
145 #endif
146 
147