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 struct pep_sock {
14 	struct pn_sock		pn_sk;
15 
16 	/* XXX: union-ify listening vs connected stuff ? */
17 	/* Listening socket stuff: */
18 	struct hlist_head	hlist;
19 
20 	/* Connected socket stuff: */
21 	struct sock		*listener;
22 	struct sk_buff_head	ctrlreq_queue;
23 #define PNPIPE_CTRLREQ_MAX	10
24 	atomic_t		tx_credits;
25 	int			ifindex;
26 	u16			peer_type;	/* peer type/subtype */
27 	u8			pipe_handle;
28 
29 	u8			rx_credits;
30 	u8			rx_fc;	/* RX flow control */
31 	u8			tx_fc;	/* TX flow control */
32 	u8			init_enable;	/* auto-enable at creation */
33 	u8			aligned;
34 };
35 
pep_sk(struct sock * sk)36 static inline struct pep_sock *pep_sk(struct sock *sk)
37 {
38 	return (struct pep_sock *)sk;
39 }
40 
41 extern const struct proto_ops phonet_stream_ops;
42 
43 /* Pipe protocol definitions */
44 struct pnpipehdr {
45 	u8			utid; /* transaction ID */
46 	u8			message_id;
47 	u8			pipe_handle;
48 	union {
49 		u8		state_after_connect;	/* connect request */
50 		u8		state_after_reset;	/* reset request */
51 		u8		error_code;		/* any response */
52 		u8		pep_type;		/* status indication */
53 		u8		data0;			/* anything else */
54 	};
55 	u8			data[];
56 };
57 #define other_pep_type		data[0]
58 
pnp_hdr(struct sk_buff * skb)59 static inline struct pnpipehdr *pnp_hdr(struct sk_buff *skb)
60 {
61 	return (struct pnpipehdr *)skb_transport_header(skb);
62 }
63 
64 #define MAX_PNPIPE_HEADER (MAX_PHONET_HEADER + 4)
65 
66 enum {
67 	PNS_PIPE_CREATE_REQ = 0x00,
68 	PNS_PIPE_CREATE_RESP,
69 	PNS_PIPE_REMOVE_REQ,
70 	PNS_PIPE_REMOVE_RESP,
71 
72 	PNS_PIPE_DATA = 0x20,
73 	PNS_PIPE_ALIGNED_DATA,
74 
75 	PNS_PEP_CONNECT_REQ = 0x40,
76 	PNS_PEP_CONNECT_RESP,
77 	PNS_PEP_DISCONNECT_REQ,
78 	PNS_PEP_DISCONNECT_RESP,
79 	PNS_PEP_RESET_REQ,
80 	PNS_PEP_RESET_RESP,
81 	PNS_PEP_ENABLE_REQ,
82 	PNS_PEP_ENABLE_RESP,
83 	PNS_PEP_CTRL_REQ,
84 	PNS_PEP_CTRL_RESP,
85 	PNS_PEP_DISABLE_REQ = 0x4C,
86 	PNS_PEP_DISABLE_RESP,
87 
88 	PNS_PEP_STATUS_IND = 0x60,
89 	PNS_PIPE_CREATED_IND,
90 	PNS_PIPE_RESET_IND = 0x63,
91 	PNS_PIPE_ENABLED_IND,
92 	PNS_PIPE_REDIRECTED_IND,
93 	PNS_PIPE_DISABLED_IND = 0x66,
94 };
95 
96 #define PN_PIPE_INVALID_HANDLE	0xff
97 #define PN_PEP_TYPE_COMMON	0x00
98 
99 /* Phonet pipe status indication */
100 enum {
101 	PN_PEP_IND_FLOW_CONTROL,
102 	PN_PEP_IND_ID_MCFC_GRANT_CREDITS,
103 };
104 
105 /* Phonet pipe error codes */
106 enum {
107 	PN_PIPE_NO_ERROR,
108 	PN_PIPE_ERR_INVALID_PARAM,
109 	PN_PIPE_ERR_INVALID_HANDLE,
110 	PN_PIPE_ERR_INVALID_CTRL_ID,
111 	PN_PIPE_ERR_NOT_ALLOWED,
112 	PN_PIPE_ERR_PEP_IN_USE,
113 	PN_PIPE_ERR_OVERLOAD,
114 	PN_PIPE_ERR_DEV_DISCONNECTED,
115 	PN_PIPE_ERR_TIMEOUT,
116 	PN_PIPE_ERR_ALL_PIPES_IN_USE,
117 	PN_PIPE_ERR_GENERAL,
118 	PN_PIPE_ERR_NOT_SUPPORTED,
119 };
120 
121 /* Phonet pipe states */
122 enum {
123 	PN_PIPE_DISABLE,
124 	PN_PIPE_ENABLE,
125 };
126 
127 /* Phonet pipe sub-block types */
128 enum {
129 	PN_PIPE_SB_CREATE_REQ_PEP_SUB_TYPE,
130 	PN_PIPE_SB_CONNECT_REQ_PEP_SUB_TYPE,
131 	PN_PIPE_SB_REDIRECT_REQ_PEP_SUB_TYPE,
132 	PN_PIPE_SB_NEGOTIATED_FC,
133 	PN_PIPE_SB_REQUIRED_FC_TX,
134 	PN_PIPE_SB_PREFERRED_FC_RX,
135 	PN_PIPE_SB_ALIGNED_DATA,
136 };
137 
138 /* Phonet pipe flow control models */
139 enum {
140 	PN_NO_FLOW_CONTROL,
141 	PN_LEGACY_FLOW_CONTROL,
142 	PN_ONE_CREDIT_FLOW_CONTROL,
143 	PN_MULTI_CREDIT_FLOW_CONTROL,
144 	PN_MAX_FLOW_CONTROL,
145 };
146 
147 #define pn_flow_safe(fc) ((fc) >> 1)
148 
149 /* Phonet pipe flow control states */
150 enum {
151 	PEP_IND_EMPTY,
152 	PEP_IND_BUSY,
153 	PEP_IND_READY,
154 };
155 
156 #endif
157