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> |
| 17 | #include <linux/dccp.h> |
| 18 | #include <linux/list.h> |
| 19 | #include <linux/module.h> |
| 20 | |
| 21 | #define CCID_MAX 255 |
| 22 | |
| 23 | struct ccid { |
| 24 | unsigned char ccid_id; |
| 25 | const char *ccid_name; |
| 26 | struct module *ccid_owner; |
| 27 | int (*ccid_init)(struct sock *sk); |
| 28 | void (*ccid_exit)(struct sock *sk); |
| 29 | int (*ccid_hc_rx_init)(struct sock *sk); |
| 30 | int (*ccid_hc_tx_init)(struct sock *sk); |
| 31 | void (*ccid_hc_rx_exit)(struct sock *sk); |
| 32 | void (*ccid_hc_tx_exit)(struct sock *sk); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame^] | 33 | void (*ccid_hc_rx_packet_recv)(struct sock *sk, |
| 34 | struct sk_buff *skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 35 | int (*ccid_hc_rx_parse_options)(struct sock *sk, |
| 36 | unsigned char option, |
| 37 | unsigned char len, u16 idx, |
| 38 | unsigned char* value); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame^] | 39 | void (*ccid_hc_rx_insert_options)(struct sock *sk, |
| 40 | struct sk_buff *skb); |
| 41 | void (*ccid_hc_tx_insert_options)(struct sock *sk, |
| 42 | struct sk_buff *skb); |
| 43 | void (*ccid_hc_tx_packet_recv)(struct sock *sk, |
| 44 | struct sk_buff *skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 45 | int (*ccid_hc_tx_parse_options)(struct sock *sk, |
| 46 | unsigned char option, |
| 47 | unsigned char len, u16 idx, |
| 48 | unsigned char* value); |
| 49 | int (*ccid_hc_tx_send_packet)(struct sock *sk, |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 50 | struct sk_buff *skb, int len); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame^] | 51 | void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more, |
| 52 | int len); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | extern int ccid_register(struct ccid *ccid); |
| 56 | extern int ccid_unregister(struct ccid *ccid); |
| 57 | |
| 58 | extern struct ccid *ccid_init(unsigned char id, struct sock *sk); |
| 59 | extern void ccid_exit(struct ccid *ccid, struct sock *sk); |
| 60 | |
| 61 | static inline void __ccid_get(struct ccid *ccid) |
| 62 | { |
| 63 | __module_get(ccid->ccid_owner); |
| 64 | } |
| 65 | |
| 66 | 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] | 67 | struct sk_buff *skb, int len) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 68 | { |
| 69 | int rc = 0; |
| 70 | if (ccid->ccid_hc_tx_send_packet != NULL) |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 71 | rc = ccid->ccid_hc_tx_send_packet(sk, skb, len); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 72 | return rc; |
| 73 | } |
| 74 | |
| 75 | static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, |
| 76 | int more, int len) |
| 77 | { |
| 78 | if (ccid->ccid_hc_tx_packet_sent != NULL) |
| 79 | ccid->ccid_hc_tx_packet_sent(sk, more, len); |
| 80 | } |
| 81 | |
| 82 | static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk) |
| 83 | { |
| 84 | int rc = 0; |
| 85 | if (ccid->ccid_hc_rx_init != NULL) |
| 86 | rc = ccid->ccid_hc_rx_init(sk); |
| 87 | return rc; |
| 88 | } |
| 89 | |
| 90 | static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk) |
| 91 | { |
| 92 | int rc = 0; |
| 93 | if (ccid->ccid_hc_tx_init != NULL) |
| 94 | rc = ccid->ccid_hc_tx_init(sk); |
| 95 | return rc; |
| 96 | } |
| 97 | |
| 98 | static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk) |
| 99 | { |
| 100 | if (ccid->ccid_hc_rx_exit != NULL) |
| 101 | ccid->ccid_hc_rx_exit(sk); |
| 102 | } |
| 103 | |
| 104 | static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk) |
| 105 | { |
| 106 | if (ccid->ccid_hc_tx_exit != NULL) |
| 107 | ccid->ccid_hc_tx_exit(sk); |
| 108 | } |
| 109 | |
| 110 | static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, |
| 111 | struct sk_buff *skb) |
| 112 | { |
| 113 | if (ccid->ccid_hc_rx_packet_recv != NULL) |
| 114 | ccid->ccid_hc_rx_packet_recv(sk, skb); |
| 115 | } |
| 116 | |
| 117 | static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, |
| 118 | struct sk_buff *skb) |
| 119 | { |
| 120 | if (ccid->ccid_hc_tx_packet_recv != NULL) |
| 121 | ccid->ccid_hc_tx_packet_recv(sk, skb); |
| 122 | } |
| 123 | |
| 124 | static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, |
| 125 | unsigned char option, |
| 126 | unsigned char len, u16 idx, |
| 127 | unsigned char* value) |
| 128 | { |
| 129 | int rc = 0; |
| 130 | if (ccid->ccid_hc_tx_parse_options != NULL) |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame^] | 131 | rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx, |
| 132 | value); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 133 | return rc; |
| 134 | } |
| 135 | |
| 136 | static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, |
| 137 | unsigned char option, |
| 138 | unsigned char len, u16 idx, |
| 139 | unsigned char* value) |
| 140 | { |
| 141 | int rc = 0; |
| 142 | if (ccid->ccid_hc_rx_parse_options != NULL) |
| 143 | rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value); |
| 144 | return rc; |
| 145 | } |
| 146 | |
| 147 | static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, |
| 148 | struct sk_buff *skb) |
| 149 | { |
| 150 | if (ccid->ccid_hc_tx_insert_options != NULL) |
| 151 | ccid->ccid_hc_tx_insert_options(sk, skb); |
| 152 | } |
| 153 | |
| 154 | static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, |
| 155 | struct sk_buff *skb) |
| 156 | { |
| 157 | if (ccid->ccid_hc_rx_insert_options != NULL) |
| 158 | ccid->ccid_hc_rx_insert_options(sk, skb); |
| 159 | } |
| 160 | #endif /* _CCID_H */ |