blob: def6cfa3f451ef7afe1bb96cb636810e9a5f4847 [file] [log] [blame]
Rémi Denis-Courmont9995a322008-10-05 11:14:48 -07001/*
2 * File: pep.h
3 *
4 * Phonet Pipe End Point sockets definitions
5 *
6 * Copyright (C) 2008 Nokia Corporation.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#ifndef NET_PHONET_PEP_H
24#define NET_PHONET_PEP_H
25
26struct pep_sock {
27 struct pn_sock pn_sk;
28
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070029 /* XXX: union-ify listening vs connected stuff ? */
Rémi Denis-Courmont9995a322008-10-05 11:14:48 -070030 /* Listening socket stuff: */
31 struct hlist_head ackq;
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070032 struct hlist_head hlist;
Rémi Denis-Courmont9995a322008-10-05 11:14:48 -070033
34 /* Connected socket stuff: */
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070035 struct sock *listener;
Rémi Denis-Courmontc41bd97f82008-10-05 11:15:43 -070036 struct sk_buff_head ctrlreq_queue;
37#define PNPIPE_CTRLREQ_MAX 10
Rémi Denis-Courmontbe677732008-12-17 15:48:31 -080038 atomic_t tx_credits;
Rémi Denis-Courmont02a47612008-10-05 11:16:16 -070039 int ifindex;
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070040 u16 peer_type; /* peer type/subtype */
41 u8 pipe_handle;
42
43 u8 rx_credits;
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070044 u8 rx_fc; /* RX flow control */
45 u8 tx_fc; /* TX flow control */
46 u8 init_enable; /* auto-enable at creation */
Rémi Denis-Courmontfea93ec2010-01-04 02:02:48 +000047 u8 aligned;
Kumar Sanghvi8d98efa2010-09-26 19:07:59 +000048#ifdef CONFIG_PHONET_PIPECTRLR
49 u16 remote_pep;
50 u8 pipe_state;
51#endif
Rémi Denis-Courmont9995a322008-10-05 11:14:48 -070052};
53
54static inline struct pep_sock *pep_sk(struct sock *sk)
55{
56 return (struct pep_sock *)sk;
57}
58
59extern const struct proto_ops phonet_stream_ops;
60
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070061/* Pipe protocol definitions */
62struct pnpipehdr {
63 u8 utid; /* transaction ID */
64 u8 message_id;
65 u8 pipe_handle;
66 union {
67 u8 state_after_connect; /* connect request */
68 u8 state_after_reset; /* reset request */
69 u8 error_code; /* any response */
70 u8 pep_type; /* status indication */
71 u8 data[1];
72 };
73};
74#define other_pep_type data[1]
75
76static inline struct pnpipehdr *pnp_hdr(struct sk_buff *skb)
77{
78 return (struct pnpipehdr *)skb_transport_header(skb);
79}
80
81#define MAX_PNPIPE_HEADER (MAX_PHONET_HEADER + 4)
82
83enum {
Rémi Denis-Courmont6482f552010-09-15 12:19:53 +000084 PNS_PIPE_CREATE_REQ = 0x00,
85 PNS_PIPE_CREATE_RESP,
86 PNS_PIPE_REMOVE_REQ,
87 PNS_PIPE_REMOVE_RESP,
88
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070089 PNS_PIPE_DATA = 0x20,
Rémi Denis-Courmontfc6a1102010-01-04 02:02:47 +000090 PNS_PIPE_ALIGNED_DATA,
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070091
92 PNS_PEP_CONNECT_REQ = 0x40,
93 PNS_PEP_CONNECT_RESP,
94 PNS_PEP_DISCONNECT_REQ,
95 PNS_PEP_DISCONNECT_RESP,
96 PNS_PEP_RESET_REQ,
97 PNS_PEP_RESET_RESP,
98 PNS_PEP_ENABLE_REQ,
99 PNS_PEP_ENABLE_RESP,
100 PNS_PEP_CTRL_REQ,
101 PNS_PEP_CTRL_RESP,
102 PNS_PEP_DISABLE_REQ = 0x4C,
103 PNS_PEP_DISABLE_RESP,
104
105 PNS_PEP_STATUS_IND = 0x60,
106 PNS_PIPE_CREATED_IND,
107 PNS_PIPE_RESET_IND = 0x63,
108 PNS_PIPE_ENABLED_IND,
109 PNS_PIPE_REDIRECTED_IND,
110 PNS_PIPE_DISABLED_IND = 0x66,
111};
112
113#define PN_PIPE_INVALID_HANDLE 0xff
114#define PN_PEP_TYPE_COMMON 0x00
115
116/* Phonet pipe status indication */
117enum {
118 PN_PEP_IND_FLOW_CONTROL,
119 PN_PEP_IND_ID_MCFC_GRANT_CREDITS,
120};
121
122/* Phonet pipe error codes */
123enum {
124 PN_PIPE_NO_ERROR,
125 PN_PIPE_ERR_INVALID_PARAM,
126 PN_PIPE_ERR_INVALID_HANDLE,
127 PN_PIPE_ERR_INVALID_CTRL_ID,
128 PN_PIPE_ERR_NOT_ALLOWED,
129 PN_PIPE_ERR_PEP_IN_USE,
130 PN_PIPE_ERR_OVERLOAD,
131 PN_PIPE_ERR_DEV_DISCONNECTED,
132 PN_PIPE_ERR_TIMEOUT,
133 PN_PIPE_ERR_ALL_PIPES_IN_USE,
134 PN_PIPE_ERR_GENERAL,
135 PN_PIPE_ERR_NOT_SUPPORTED,
136};
137
138/* Phonet pipe states */
139enum {
140 PN_PIPE_DISABLE,
141 PN_PIPE_ENABLE,
142};
143
144/* Phonet pipe sub-block types */
145enum {
146 PN_PIPE_SB_CREATE_REQ_PEP_SUB_TYPE,
147 PN_PIPE_SB_CONNECT_REQ_PEP_SUB_TYPE,
148 PN_PIPE_SB_REDIRECT_REQ_PEP_SUB_TYPE,
149 PN_PIPE_SB_NEGOTIATED_FC,
150 PN_PIPE_SB_REQUIRED_FC_TX,
151 PN_PIPE_SB_PREFERRED_FC_RX,
Rémi Denis-Courmontfea93ec2010-01-04 02:02:48 +0000152 PN_PIPE_SB_ALIGNED_DATA,
Rémi Denis-Courmont96414582008-10-05 11:15:13 -0700153};
154
155/* Phonet pipe flow control models */
156enum {
157 PN_NO_FLOW_CONTROL,
158 PN_LEGACY_FLOW_CONTROL,
159 PN_ONE_CREDIT_FLOW_CONTROL,
160 PN_MULTI_CREDIT_FLOW_CONTROL,
161};
162
163#define pn_flow_safe(fc) ((fc) >> 1)
164
165/* Phonet pipe flow control states */
166enum {
167 PEP_IND_EMPTY,
168 PEP_IND_BUSY,
169 PEP_IND_READY,
170};
171
Kumar Sanghvi8d98efa2010-09-26 19:07:59 +0000172#ifdef CONFIG_PHONET_PIPECTRLR
173#define PNS_PEP_CONNECT_UTID 0x02
174#define PNS_PIPE_CREATED_IND_UTID 0x04
175#define PNS_PIPE_ENABLE_UTID 0x0A
176#define PNS_PIPE_ENABLED_IND_UTID 0x0C
177#define PNS_PIPE_DISABLE_UTID 0x0F
178#define PNS_PIPE_DISABLED_IND_UTID 0x11
179#define PNS_PEP_DISCONNECT_UTID 0x06
180
181/* Used for tracking state of a pipe */
182enum {
183 PIPE_IDLE,
184 PIPE_DISABLED,
185 PIPE_ENABLED,
186};
187#endif /* CONFIG_PHONET_PIPECTRLR */
188
Rémi Denis-Courmont9995a322008-10-05 11:14:48 -0700189#endif