Skip to content

Commit

Permalink
Phonet: Pipe End Point for Phonet Pipes protocol
Browse files Browse the repository at this point in the history
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 <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Rémi Denis-Courmont authored and davem330 committed Oct 5, 2008
1 parent 9995a32 commit 9641458
Show file tree
Hide file tree
Showing 5 changed files with 1,031 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/linux/phonet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#define PN_PROTO_TRANSPORT 0
/* Phonet datagram socket */
#define PN_PROTO_PHONET 1
#define PHONET_NPROTO 2
/* Phonet pipe */
#define PN_PROTO_PIPE 2
#define PHONET_NPROTO 3

#define PNADDR_ANY 0
#define PNPORT_RESOURCE_ROUTING 0
Expand Down
114 changes: 114 additions & 0 deletions include/net/phonet/pep.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@
struct pep_sock {
struct pn_sock pn_sk;

/* XXX: union-ify listening vs connected stuff ? */
/* Listening socket stuff: */
struct hlist_head ackq;
struct hlist_head hlist;

/* Connected socket stuff: */
struct sock *listener;
u16 peer_type; /* peer type/subtype */
u8 pipe_handle;

u8 rx_credits;
u8 tx_credits;
u8 rx_fc; /* RX flow control */
u8 tx_fc; /* TX flow control */
u8 init_enable; /* auto-enable at creation */
};

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

extern const struct proto_ops phonet_stream_ops;

/* Pipe protocol definitions */
struct pnpipehdr {
u8 utid; /* transaction ID */
u8 message_id;
u8 pipe_handle;
union {
u8 state_after_connect; /* connect request */
u8 state_after_reset; /* reset request */
u8 error_code; /* any response */
u8 pep_type; /* status indication */
u8 data[1];
};
};
#define other_pep_type data[1]

static inline struct pnpipehdr *pnp_hdr(struct sk_buff *skb)
{
return (struct pnpipehdr *)skb_transport_header(skb);
}

#define MAX_PNPIPE_HEADER (MAX_PHONET_HEADER + 4)

enum {
PNS_PIPE_DATA = 0x20,

PNS_PEP_CONNECT_REQ = 0x40,
PNS_PEP_CONNECT_RESP,
PNS_PEP_DISCONNECT_REQ,
PNS_PEP_DISCONNECT_RESP,
PNS_PEP_RESET_REQ,
PNS_PEP_RESET_RESP,
PNS_PEP_ENABLE_REQ,
PNS_PEP_ENABLE_RESP,
PNS_PEP_CTRL_REQ,
PNS_PEP_CTRL_RESP,
PNS_PEP_DISABLE_REQ = 0x4C,
PNS_PEP_DISABLE_RESP,

PNS_PEP_STATUS_IND = 0x60,
PNS_PIPE_CREATED_IND,
PNS_PIPE_RESET_IND = 0x63,
PNS_PIPE_ENABLED_IND,
PNS_PIPE_REDIRECTED_IND,
PNS_PIPE_DISABLED_IND = 0x66,
};

#define PN_PIPE_INVALID_HANDLE 0xff
#define PN_PEP_TYPE_COMMON 0x00

/* Phonet pipe status indication */
enum {
PN_PEP_IND_FLOW_CONTROL,
PN_PEP_IND_ID_MCFC_GRANT_CREDITS,
};

/* Phonet pipe error codes */
enum {
PN_PIPE_NO_ERROR,
PN_PIPE_ERR_INVALID_PARAM,
PN_PIPE_ERR_INVALID_HANDLE,
PN_PIPE_ERR_INVALID_CTRL_ID,
PN_PIPE_ERR_NOT_ALLOWED,
PN_PIPE_ERR_PEP_IN_USE,
PN_PIPE_ERR_OVERLOAD,
PN_PIPE_ERR_DEV_DISCONNECTED,
PN_PIPE_ERR_TIMEOUT,
PN_PIPE_ERR_ALL_PIPES_IN_USE,
PN_PIPE_ERR_GENERAL,
PN_PIPE_ERR_NOT_SUPPORTED,
};

/* Phonet pipe states */
enum {
PN_PIPE_DISABLE,
PN_PIPE_ENABLE,
};

/* Phonet pipe sub-block types */
enum {
PN_PIPE_SB_CREATE_REQ_PEP_SUB_TYPE,
PN_PIPE_SB_CONNECT_REQ_PEP_SUB_TYPE,
PN_PIPE_SB_REDIRECT_REQ_PEP_SUB_TYPE,
PN_PIPE_SB_NEGOTIATED_FC,
PN_PIPE_SB_REQUIRED_FC_TX,
PN_PIPE_SB_PREFERRED_FC_RX,
};

/* Phonet pipe flow control models */
enum {
PN_NO_FLOW_CONTROL,
PN_LEGACY_FLOW_CONTROL,
PN_ONE_CREDIT_FLOW_CONTROL,
PN_MULTI_CREDIT_FLOW_CONTROL,
};

#define pn_flow_safe(fc) ((fc) >> 1)

/* Phonet pipe flow control states */
enum {
PEP_IND_EMPTY,
PEP_IND_BUSY,
PEP_IND_READY,
};

#endif
4 changes: 3 additions & 1 deletion net/phonet/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
obj-$(CONFIG_PHONET) += phonet.o
obj-$(CONFIG_PHONET) += phonet.o pn_pep.o

phonet-objs := \
pn_dev.o \
Expand All @@ -7,3 +7,5 @@ phonet-objs := \
datagram.o \
sysctl.o \
af_phonet.o

pn_pep-objs := pep.o
3 changes: 3 additions & 0 deletions net/phonet/af_phonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
case SOCK_DGRAM:
protocol = PN_PROTO_PHONET;
break;
case SOCK_SEQPACKET:
protocol = PN_PROTO_PIPE;
break;
default:
return -EPROTONOSUPPORT;
}
Expand Down
Loading

0 comments on commit 9641458

Please sign in to comment.