xref: /linux/include/net/phonet/pep.h (revision e5d3a64e650c721f9e9b1f76e5df8c62f16b734d)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * File: pep.h
4  *
5  * Phonet Pipe End Point sockets definitions
6  *
7  * Copyright (C) 2008 Nokia Corporation.
8  */
9 
10 #ifndef NET_PHONET_PEP_H
11 #define NET_PHONET_PEP_H
12 
13 #include <linux/skbuff.h>
14 #include <net/phonet/phonet.h>
15 
16 struct pep_sock {
17 	struct pn_sock		pn_sk;
18 
19 	/* XXX: union-ify listening vs connected stuff ? */
20 	/* Listening socket stuff: */
21 	struct hlist_head	hlist;
22 
23 	/* Connected socket stuff: */
24 	struct sock		*listener;
25 	struct sk_buff_head	ctrlreq_queue;
26 #define PNPIPE_CTRLREQ_MAX	10
27 	atomic_t		tx_credits;
28 	int			ifindex;
29 	u16			peer_type;	/* peer type/subtype */
30 	u8			pipe_handle;
31 
32 	u8			rx_credits;
33 	u8			rx_fc;	/* RX flow control */
34 	u8			tx_fc;	/* TX flow control */
35 	u8			init_enable;	/* auto-enable at creation */
36 	u8			aligned;
37 };
38 
39 static inline struct pep_sock *pep_sk(struct sock *sk)
40 {
41 	return (struct pep_sock *)sk;
42 }
43 
44 extern const struct proto_ops phonet_stream_ops;
45 
46 /* Pipe protocol definitions */
47 struct pnpipehdr {
48 	u8			utid; /* transaction ID */
49 	u8			message_id;
50 	u8			pipe_handle;
51 	union {
52 		u8		state_after_connect;	/* connect request */
53 		u8		state_after_reset;	/* reset request */
54 		u8		error_code;		/* any response */
55 		u8		pep_type;		/* status indication */
56 		u8		data0;			/* anything else */
57 	};
58 	u8			data[];
59 };
60 #define other_pep_type		data[0]
61 
62 static inline struct pnpipehdr *pnp_hdr(struct sk_buff *skb)
63 {
64 	return (struct pnpipehdr *)skb_transport_header(skb);
65 }
66 
67 #define MAX_PNPIPE_HEADER (MAX_PHONET_HEADER + 4)
68 
69 enum {
70 	PNS_PIPE_CREATE_REQ = 0x00,
71 	PNS_PIPE_CREATE_RESP,
72 	PNS_PIPE_REMOVE_REQ,
73 	PNS_PIPE_REMOVE_RESP,
74 
75 	PNS_PIPE_DATA = 0x20,
76 	PNS_PIPE_ALIGNED_DATA,
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 */
103 enum {
104 	PN_PEP_IND_FLOW_CONTROL,
105 	PN_PEP_IND_ID_MCFC_GRANT_CREDITS,
106 };
107 
108 /* Phonet pipe error codes */
109 enum {
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 */
125 enum {
126 	PN_PIPE_DISABLE,
127 	PN_PIPE_ENABLE,
128 };
129 
130 /* Phonet pipe sub-block types */
131 enum {
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 	PN_PIPE_SB_ALIGNED_DATA,
139 };
140 
141 /* Phonet pipe flow control models */
142 enum {
143 	PN_NO_FLOW_CONTROL,
144 	PN_LEGACY_FLOW_CONTROL,
145 	PN_ONE_CREDIT_FLOW_CONTROL,
146 	PN_MULTI_CREDIT_FLOW_CONTROL,
147 	PN_MAX_FLOW_CONTROL,
148 };
149 
150 #define pn_flow_safe(fc) ((fc) >> 1)
151 
152 /* Phonet pipe flow control states */
153 enum {
154 	PEP_IND_EMPTY,
155 	PEP_IND_BUSY,
156 	PEP_IND_READY,
157 };
158 
159 #endif
160