blob: fb024e186860841d7a8978fc1bfa005dbc1e0217 [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;
36 u16 peer_type; /* peer type/subtype */
37 u8 pipe_handle;
38
39 u8 rx_credits;
Rémi Denis-Courmont9995a322008-10-05 11:14:48 -070040 u8 tx_credits;
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070041 u8 rx_fc; /* RX flow control */
42 u8 tx_fc; /* TX flow control */
43 u8 init_enable; /* auto-enable at creation */
Rémi Denis-Courmont9995a322008-10-05 11:14:48 -070044};
45
46static inline struct pep_sock *pep_sk(struct sock *sk)
47{
48 return (struct pep_sock *)sk;
49}
50
51extern const struct proto_ops phonet_stream_ops;
52
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070053/* Pipe protocol definitions */
54struct pnpipehdr {
55 u8 utid; /* transaction ID */
56 u8 message_id;
57 u8 pipe_handle;
58 union {
59 u8 state_after_connect; /* connect request */
60 u8 state_after_reset; /* reset request */
61 u8 error_code; /* any response */
62 u8 pep_type; /* status indication */
63 u8 data[1];
64 };
65};
66#define other_pep_type data[1]
67
68static inline struct pnpipehdr *pnp_hdr(struct sk_buff *skb)
69{
70 return (struct pnpipehdr *)skb_transport_header(skb);
71}
72
73#define MAX_PNPIPE_HEADER (MAX_PHONET_HEADER + 4)
74
75enum {
76 PNS_PIPE_DATA = 0x20,
77
78 PNS_PEP_CONNECT_REQ = 0x40,
79 PNS_PEP_CONNECT_RESP,
80 PNS_PEP_DISCONNECT_REQ,
81 PNS_PEP_DISCONNECT_RESP,
82 PNS_PEP_RESET_REQ,
83 PNS_PEP_RESET_RESP,
84 PNS_PEP_ENABLE_REQ,
85 PNS_PEP_ENABLE_RESP,
86 PNS_PEP_CTRL_REQ,
87 PNS_PEP_CTRL_RESP,
88 PNS_PEP_DISABLE_REQ = 0x4C,
89 PNS_PEP_DISABLE_RESP,
90
91 PNS_PEP_STATUS_IND = 0x60,
92 PNS_PIPE_CREATED_IND,
93 PNS_PIPE_RESET_IND = 0x63,
94 PNS_PIPE_ENABLED_IND,
95 PNS_PIPE_REDIRECTED_IND,
96 PNS_PIPE_DISABLED_IND = 0x66,
97};
98
99#define PN_PIPE_INVALID_HANDLE 0xff
100#define PN_PEP_TYPE_COMMON 0x00
101
102/* Phonet pipe status indication */
103enum {
104 PN_PEP_IND_FLOW_CONTROL,
105 PN_PEP_IND_ID_MCFC_GRANT_CREDITS,
106};
107
108/* Phonet pipe error codes */
109enum {
110 PN_PIPE_NO_ERROR,
111 PN_PIPE_ERR_INVALID_PARAM,
112 PN_PIPE_ERR_INVALID_HANDLE,
113 PN_PIPE_ERR_INVALID_CTRL_ID,
114 PN_PIPE_ERR_NOT_ALLOWED,
115 PN_PIPE_ERR_PEP_IN_USE,
116 PN_PIPE_ERR_OVERLOAD,
117 PN_PIPE_ERR_DEV_DISCONNECTED,
118 PN_PIPE_ERR_TIMEOUT,
119 PN_PIPE_ERR_ALL_PIPES_IN_USE,
120 PN_PIPE_ERR_GENERAL,
121 PN_PIPE_ERR_NOT_SUPPORTED,
122};
123
124/* Phonet pipe states */
125enum {
126 PN_PIPE_DISABLE,
127 PN_PIPE_ENABLE,
128};
129
130/* Phonet pipe sub-block types */
131enum {
132 PN_PIPE_SB_CREATE_REQ_PEP_SUB_TYPE,
133 PN_PIPE_SB_CONNECT_REQ_PEP_SUB_TYPE,
134 PN_PIPE_SB_REDIRECT_REQ_PEP_SUB_TYPE,
135 PN_PIPE_SB_NEGOTIATED_FC,
136 PN_PIPE_SB_REQUIRED_FC_TX,
137 PN_PIPE_SB_PREFERRED_FC_RX,
138};
139
140/* Phonet pipe flow control models */
141enum {
142 PN_NO_FLOW_CONTROL,
143 PN_LEGACY_FLOW_CONTROL,
144 PN_ONE_CREDIT_FLOW_CONTROL,
145 PN_MULTI_CREDIT_FLOW_CONTROL,
146};
147
148#define pn_flow_safe(fc) ((fc) >> 1)
149
150/* Phonet pipe flow control states */
151enum {
152 PEP_IND_EMPTY,
153 PEP_IND_BUSY,
154 PEP_IND_READY,
155};
156
Rémi Denis-Courmont9995a322008-10-05 11:14:48 -0700157#endif