Skip to content

Commit 9641458

Browse files
Rémi Denis-Courmontdavem330
authored andcommitted
Phonet: Pipe End Point for Phonet Pipes protocol
This protocol provides some connection handling and negotiated congestion control. Nokia cellular modems use it for bulk transfers. It provides packet boundaries (hence SOCK_SEQPACKET). Congestion control is per packet rather per byte, so we do not re-use the generic socket memory accounting. Signed-off-by: Rémi Denis-Courmont <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9995a32 commit 9641458

File tree

5 files changed

+1031
-2
lines changed

5 files changed

+1031
-2
lines changed

include/linux/phonet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#define PN_PROTO_TRANSPORT 0
2828
/* Phonet datagram socket */
2929
#define PN_PROTO_PHONET 1
30-
#define PHONET_NPROTO 2
30+
/* Phonet pipe */
31+
#define PN_PROTO_PIPE 2
32+
#define PHONET_NPROTO 3
3133

3234
#define PNADDR_ANY 0
3335
#define PNPORT_RESOURCE_ROUTING 0

include/net/phonet/pep.h

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@
2626
struct pep_sock {
2727
struct pn_sock pn_sk;
2828

29+
/* XXX: union-ify listening vs connected stuff ? */
2930
/* Listening socket stuff: */
3031
struct hlist_head ackq;
32+
struct hlist_head hlist;
3133

3234
/* Connected socket stuff: */
35+
struct sock *listener;
36+
u16 peer_type; /* peer type/subtype */
37+
u8 pipe_handle;
38+
39+
u8 rx_credits;
3340
u8 tx_credits;
41+
u8 rx_fc; /* RX flow control */
42+
u8 tx_fc; /* TX flow control */
43+
u8 init_enable; /* auto-enable at creation */
3444
};
3545

3646
static inline struct pep_sock *pep_sk(struct sock *sk)
@@ -40,4 +50,108 @@ static inline struct pep_sock *pep_sk(struct sock *sk)
4050

4151
extern const struct proto_ops phonet_stream_ops;
4252

53+
/* Pipe protocol definitions */
54+
struct 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+
68+
static 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+
75+
enum {
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 */
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+
};
139+
140+
/* Phonet pipe flow control models */
141+
enum {
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 */
151+
enum {
152+
PEP_IND_EMPTY,
153+
PEP_IND_BUSY,
154+
PEP_IND_READY,
155+
};
156+
43157
#endif

net/phonet/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
obj-$(CONFIG_PHONET) += phonet.o
1+
obj-$(CONFIG_PHONET) += phonet.o pn_pep.o
22

33
phonet-objs := \
44
pn_dev.o \
@@ -7,3 +7,5 @@ phonet-objs := \
77
datagram.o \
88
sysctl.o \
99
af_phonet.o
10+
11+
pn_pep-objs := pep.o

net/phonet/af_phonet.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
5858
case SOCK_DGRAM:
5959
protocol = PN_PROTO_PHONET;
6060
break;
61+
case SOCK_SEQPACKET:
62+
protocol = PN_PROTO_PIPE;
63+
break;
6164
default:
6265
return -EPROTONOSUPPORT;
6366
}

0 commit comments

Comments
 (0)