| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1 | #ifndef _CCID_H | 
 | 2 | #define _CCID_H | 
 | 3 | /* | 
 | 4 |  *  net/dccp/ccid.h | 
 | 5 |  * | 
 | 6 |  *  An implementation of the DCCP protocol | 
 | 7 |  *  Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 
 | 8 |  * | 
 | 9 |  *  CCID infrastructure | 
 | 10 |  * | 
 | 11 |  *	This program is free software; you can redistribute it and/or modify it | 
 | 12 |  *	under the terms of the GNU General Public License version 2 as | 
 | 13 |  *	published by the Free Software Foundation. | 
 | 14 |  */ | 
 | 15 |  | 
 | 16 | #include <net/sock.h> | 
| Arnaldo Carvalho de Melo | 88f964d | 2005-09-18 00:19:32 -0700 | [diff] [blame] | 17 | #include <linux/compiler.h> | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 18 | #include <linux/dccp.h> | 
 | 19 | #include <linux/list.h> | 
 | 20 | #include <linux/module.h> | 
 | 21 |  | 
 | 22 | #define CCID_MAX 255 | 
 | 23 |  | 
| Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 24 | struct tcp_info; | 
 | 25 |  | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 26 | struct ccid { | 
 | 27 | 	unsigned char	ccid_id; | 
 | 28 | 	const char	*ccid_name; | 
 | 29 | 	struct module	*ccid_owner; | 
 | 30 | 	int		(*ccid_init)(struct sock *sk); | 
 | 31 | 	void		(*ccid_exit)(struct sock *sk); | 
 | 32 | 	int		(*ccid_hc_rx_init)(struct sock *sk); | 
 | 33 | 	int		(*ccid_hc_tx_init)(struct sock *sk); | 
 | 34 | 	void		(*ccid_hc_rx_exit)(struct sock *sk); | 
 | 35 | 	void		(*ccid_hc_tx_exit)(struct sock *sk); | 
| Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 36 | 	void		(*ccid_hc_rx_packet_recv)(struct sock *sk, | 
 | 37 | 						  struct sk_buff *skb); | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 38 | 	int		(*ccid_hc_rx_parse_options)(struct sock *sk, | 
 | 39 | 						    unsigned char option, | 
 | 40 | 						    unsigned char len, u16 idx, | 
 | 41 | 						    unsigned char* value); | 
| Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 42 | 	void		(*ccid_hc_rx_insert_options)(struct sock *sk, | 
 | 43 | 						     struct sk_buff *skb); | 
 | 44 | 	void		(*ccid_hc_tx_insert_options)(struct sock *sk, | 
 | 45 | 						     struct sk_buff *skb); | 
 | 46 | 	void		(*ccid_hc_tx_packet_recv)(struct sock *sk, | 
 | 47 | 						  struct sk_buff *skb); | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 48 | 	int		(*ccid_hc_tx_parse_options)(struct sock *sk, | 
 | 49 | 						    unsigned char option, | 
 | 50 | 						    unsigned char len, u16 idx, | 
 | 51 | 						    unsigned char* value); | 
 | 52 | 	int		(*ccid_hc_tx_send_packet)(struct sock *sk, | 
| Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 53 | 						  struct sk_buff *skb, int len); | 
| Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 54 | 	void		(*ccid_hc_tx_packet_sent)(struct sock *sk, int more, | 
 | 55 | 						  int len); | 
| Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 56 | 	void		(*ccid_hc_rx_get_info)(struct sock *sk, | 
 | 57 | 					       struct tcp_info *info); | 
 | 58 | 	void		(*ccid_hc_tx_get_info)(struct sock *sk, | 
 | 59 | 					       struct tcp_info *info); | 
| Arnaldo Carvalho de Melo | 88f964d | 2005-09-18 00:19:32 -0700 | [diff] [blame] | 60 | 	int		(*ccid_hc_rx_getsockopt)(struct sock *sk, | 
 | 61 | 						 const int optname, int len, | 
 | 62 | 						 u32 __user *optval, | 
 | 63 | 						 int __user *optlen); | 
 | 64 | 	int		(*ccid_hc_tx_getsockopt)(struct sock *sk, | 
 | 65 | 						 const int optname, int len, | 
 | 66 | 						 u32 __user *optval, | 
 | 67 | 						 int __user *optlen); | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 68 | }; | 
 | 69 |  | 
 | 70 | extern int	   ccid_register(struct ccid *ccid); | 
 | 71 | extern int	   ccid_unregister(struct ccid *ccid); | 
 | 72 |  | 
 | 73 | extern struct ccid *ccid_init(unsigned char id, struct sock *sk); | 
 | 74 | extern void	   ccid_exit(struct ccid *ccid, struct sock *sk); | 
 | 75 |  | 
 | 76 | static inline void __ccid_get(struct ccid *ccid) | 
 | 77 | { | 
 | 78 | 	__module_get(ccid->ccid_owner); | 
 | 79 | } | 
 | 80 |  | 
 | 81 | static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, | 
| Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 82 | 					 struct sk_buff *skb, int len) | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 83 | { | 
 | 84 | 	int rc = 0; | 
 | 85 | 	if (ccid->ccid_hc_tx_send_packet != NULL) | 
| Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 86 | 		rc = ccid->ccid_hc_tx_send_packet(sk, skb, len); | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 87 | 	return rc; | 
 | 88 | } | 
 | 89 |  | 
 | 90 | static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, | 
 | 91 | 					  int more, int len) | 
 | 92 | { | 
 | 93 | 	if (ccid->ccid_hc_tx_packet_sent != NULL) | 
 | 94 | 		ccid->ccid_hc_tx_packet_sent(sk, more, len); | 
 | 95 | } | 
 | 96 |  | 
 | 97 | static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk) | 
 | 98 | { | 
 | 99 | 	int rc = 0; | 
 | 100 | 	if (ccid->ccid_hc_rx_init != NULL) | 
 | 101 | 		rc = ccid->ccid_hc_rx_init(sk); | 
 | 102 | 	return rc; | 
 | 103 | } | 
 | 104 |  | 
 | 105 | static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk) | 
 | 106 | { | 
 | 107 | 	int rc = 0; | 
 | 108 | 	if (ccid->ccid_hc_tx_init != NULL) | 
 | 109 | 		rc = ccid->ccid_hc_tx_init(sk); | 
 | 110 | 	return rc; | 
 | 111 | } | 
 | 112 |  | 
 | 113 | static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk) | 
 | 114 | { | 
| Arnaldo Carvalho de Melo | 777b25a | 2005-10-10 21:24:20 -0700 | [diff] [blame] | 115 | 	if (ccid != NULL && ccid->ccid_hc_rx_exit != NULL && | 
| Arnaldo Carvalho de Melo | 012e13e | 2005-08-23 21:51:13 -0700 | [diff] [blame] | 116 | 	    dccp_sk(sk)->dccps_hc_rx_ccid_private != NULL) | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 117 | 		ccid->ccid_hc_rx_exit(sk); | 
 | 118 | } | 
 | 119 |  | 
 | 120 | static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk) | 
 | 121 | { | 
| Arnaldo Carvalho de Melo | 777b25a | 2005-10-10 21:24:20 -0700 | [diff] [blame] | 122 | 	if (ccid != NULL && ccid->ccid_hc_tx_exit != NULL && | 
| Arnaldo Carvalho de Melo | 012e13e | 2005-08-23 21:51:13 -0700 | [diff] [blame] | 123 | 	    dccp_sk(sk)->dccps_hc_tx_ccid_private != NULL) | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 124 | 		ccid->ccid_hc_tx_exit(sk); | 
 | 125 | } | 
 | 126 |  | 
 | 127 | static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, | 
 | 128 | 					  struct sk_buff *skb) | 
 | 129 | { | 
 | 130 | 	if (ccid->ccid_hc_rx_packet_recv != NULL) | 
 | 131 | 		ccid->ccid_hc_rx_packet_recv(sk, skb); | 
 | 132 | } | 
 | 133 |  | 
 | 134 | static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, | 
 | 135 | 					  struct sk_buff *skb) | 
 | 136 | { | 
 | 137 | 	if (ccid->ccid_hc_tx_packet_recv != NULL) | 
 | 138 | 		ccid->ccid_hc_tx_packet_recv(sk, skb); | 
 | 139 | } | 
 | 140 |  | 
 | 141 | static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, | 
 | 142 | 					   unsigned char option, | 
 | 143 | 					   unsigned char len, u16 idx, | 
 | 144 | 					   unsigned char* value) | 
 | 145 | { | 
 | 146 | 	int rc = 0; | 
 | 147 | 	if (ccid->ccid_hc_tx_parse_options != NULL) | 
| Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 148 | 		rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx, | 
 | 149 | 						    value); | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 150 | 	return rc; | 
 | 151 | } | 
 | 152 |  | 
 | 153 | static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, | 
 | 154 | 					   unsigned char option, | 
 | 155 | 					   unsigned char len, u16 idx, | 
 | 156 | 					   unsigned char* value) | 
 | 157 | { | 
 | 158 | 	int rc = 0; | 
 | 159 | 	if (ccid->ccid_hc_rx_parse_options != NULL) | 
 | 160 | 		rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value); | 
 | 161 | 	return rc; | 
 | 162 | } | 
 | 163 |  | 
 | 164 | static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, | 
 | 165 | 					     struct sk_buff *skb) | 
 | 166 | { | 
 | 167 | 	if (ccid->ccid_hc_tx_insert_options != NULL) | 
 | 168 | 		ccid->ccid_hc_tx_insert_options(sk, skb); | 
 | 169 | } | 
 | 170 |  | 
 | 171 | static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, | 
 | 172 | 					     struct sk_buff *skb) | 
 | 173 | { | 
 | 174 | 	if (ccid->ccid_hc_rx_insert_options != NULL) | 
 | 175 | 		ccid->ccid_hc_rx_insert_options(sk, skb); | 
 | 176 | } | 
| Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 177 |  | 
 | 178 | static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk, | 
 | 179 | 				       struct tcp_info *info) | 
 | 180 | { | 
 | 181 | 	if (ccid->ccid_hc_rx_get_info != NULL) | 
 | 182 | 		ccid->ccid_hc_rx_get_info(sk, info); | 
 | 183 | } | 
 | 184 |  | 
 | 185 | static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk, | 
 | 186 | 				       struct tcp_info *info) | 
 | 187 | { | 
 | 188 | 	if (ccid->ccid_hc_tx_get_info != NULL) | 
 | 189 | 		ccid->ccid_hc_tx_get_info(sk, info); | 
 | 190 | } | 
| Arnaldo Carvalho de Melo | 88f964d | 2005-09-18 00:19:32 -0700 | [diff] [blame] | 191 |  | 
 | 192 | static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, | 
 | 193 | 					const int optname, int len, | 
 | 194 | 					u32 __user *optval, int __user *optlen) | 
 | 195 | { | 
 | 196 | 	int rc = -ENOPROTOOPT; | 
 | 197 | 	if (ccid->ccid_hc_rx_getsockopt != NULL) | 
 | 198 | 		rc = ccid->ccid_hc_rx_getsockopt(sk, optname, len, | 
 | 199 | 						 optval, optlen); | 
 | 200 | 	return rc; | 
 | 201 | } | 
 | 202 |  | 
 | 203 | static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk, | 
 | 204 | 					const int optname, int len, | 
 | 205 | 					u32 __user *optval, int __user *optlen) | 
 | 206 | { | 
 | 207 | 	int rc = -ENOPROTOOPT; | 
 | 208 | 	if (ccid->ccid_hc_tx_getsockopt != NULL) | 
 | 209 | 		rc = ccid->ccid_hc_tx_getsockopt(sk, optname, len, | 
 | 210 | 						 optval, optlen); | 
 | 211 | 	return rc; | 
 | 212 | } | 
| Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 213 | #endif /* _CCID_H */ |