]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - Documentation/networking/phonet.txt
Phonet: provide pipe socket option to retrieve the pipe identifier
[mirror_ubuntu-zesty-kernel.git] / Documentation / networking / phonet.txt
CommitLineData
953f5517
RDC
1Linux Phonet protocol family
2============================
3
4Introduction
5------------
6
7Phonet is a packet protocol used by Nokia cellular modems for both IPC
8and RPC. With the Linux Phonet socket family, Linux host processes can
9receive and send messages from/to the modem, or any other external
10device attached to the modem. The modem takes care of routing.
11
12Phonet packets can be exchanged through various hardware connections
13depending on the device, such as:
14 - USB with the CDC Phonet interface,
15 - infrared,
16 - Bluetooth,
17 - an RS232 serial port (with a dedicated "FBUS" line discipline),
18 - the SSI bus with some TI OMAP processors.
19
20
21Packets format
22--------------
23
ac2dc8ca 24Phonet packets have a common header as follows:
953f5517
RDC
25
26 struct phonethdr {
27 uint8_t pn_media; /* Media type (link-layer identifier) */
28 uint8_t pn_rdev; /* Receiver device ID */
29 uint8_t pn_sdev; /* Sender device ID */
30 uint8_t pn_res; /* Resource ID or function */
31 uint16_t pn_length; /* Big-endian message byte length (minus 6) */
32 uint8_t pn_robj; /* Receiver object ID */
33 uint8_t pn_sobj; /* Sender object ID */
34 };
35
ac2dc8ca
RDC
36On Linux, the link-layer header includes the pn_media byte (see below).
37The next 7 bytes are part of the network-layer header.
38
19f59460 39The device ID is split: the 6 higher-order bits constitute the device
ac2dc8ca
RDC
40address, while the 2 lower-order bits are used for multiplexing, as are
41the 8-bit object identifiers. As such, Phonet can be considered as a
953f5517
RDC
42network layer with 6 bits of address space and 10 bits for transport
43protocol (much like port numbers in IP world).
44
ac2dc8ca
RDC
45The modem always has address number zero. All other device have a their
46own 6-bit address.
953f5517
RDC
47
48
49Link layer
50----------
51
52Phonet links are always point-to-point links. The link layer header
53consists of a single Phonet media type byte. It uniquely identifies the
54link through which the packet is transmitted, from the modem's
ac2dc8ca
RDC
55perspective. Each Phonet network device shall prepend and set the media
56type byte as appropriate. For convenience, a common phonet_header_ops
57link-layer header operations structure is provided. It sets the
58media type according to the network device hardware address.
59
60Linux Phonet network interfaces support a dedicated link layer packets
61type (ETH_P_PHONET) which is out of the Ethernet type range. They can
62only send and receive Phonet packets.
63
64The virtual TUN tunnel device driver can also be used for Phonet. This
65requires IFF_TUN mode, _without_ the IFF_NO_PI flag. In this case,
66there is no link-layer header, so there is no Phonet media type byte.
953f5517
RDC
67
68Note that Phonet interfaces are not allowed to re-order packets, so
69only the (default) Linux FIFO qdisc should be used with them.
70
71
72Network layer
73-------------
74
75The Phonet socket address family maps the Phonet packet header:
76
77 struct sockaddr_pn {
78 sa_family_t spn_family; /* AF_PHONET */
79 uint8_t spn_obj; /* Object ID */
80 uint8_t spn_dev; /* Device ID */
81 uint8_t spn_resource; /* Resource or function */
82 uint8_t spn_zero[...]; /* Padding */
83 };
84
85The resource field is only used when sending and receiving;
86It is ignored by bind() and getsockname().
87
88
89Low-level datagram protocol
90---------------------------
91
92Applications can send Phonet messages using the Phonet datagram socket
93protocol from the PF_PHONET family. Each socket is bound to one of the
942^10 object IDs available, and can send and receive packets with any
95other peer.
96
97 struct sockaddr_pn addr = { .spn_family = AF_PHONET, };
98 ssize_t len;
99 socklen_t addrlen = sizeof(addr);
100 int fd;
101
102 fd = socket(PF_PHONET, SOCK_DGRAM, 0);
103 bind(fd, (struct sockaddr *)&addr, sizeof(addr));
104 /* ... */
105
106 sendto(fd, msg, msglen, 0, (struct sockaddr *)&addr, sizeof(addr));
107 len = recvfrom(fd, buf, sizeof(buf), 0,
108 (struct sockaddr *)&addr, &addrlen);
109
110This protocol follows the SOCK_DGRAM connection-less semantics.
111However, connect() and getpeername() are not supported, as they did
112not seem useful with Phonet usages (could be added easily).
113
114
274a517e
RDC
115Resource subscription
116---------------------
117
118A Phonet datagram socket can be subscribed to any number of 8-bits
119Phonet resources, as follow:
120
121 uint32_t res = 0xXX;
122 ioctl(fd, SIOCPNADDRESOURCE, &res);
123
124Subscription is similarly cancelled using the SIOCPNDELRESOURCE I/O
125control request, or when the socket is closed.
126
127Note that no more than one socket can be subcribed to any given
128resource at a time. If not, ioctl() will return EBUSY.
129
130
95430c0b
RDC
131Phonet Pipe protocol
132--------------------
133
134The Phonet Pipe protocol is a simple sequenced packets protocol
135with end-to-end congestion control. It uses the passive listening
136socket paradigm. The listening socket is bound to an unique free object
137ID. Each listening socket can handle up to 255 simultaneous
138connections, one per accept()'d socket.
139
140 int lfd, cfd;
141
142 lfd = socket(PF_PHONET, SOCK_SEQPACKET, PN_PROTO_PIPE);
143 listen (lfd, INT_MAX);
144
145 /* ... */
146 cfd = accept(lfd, NULL, NULL);
147 for (;;)
148 {
149 char buf[...];
150 ssize_t len = read(cfd, buf, sizeof(buf));
151
152 /* ... */
153
154 write(cfd, msg, msglen);
155 }
156
157Connections are established between two endpoints by a "third party"
158application. This means that both endpoints are passive; so connect()
159is not possible.
160
161WARNING:
162When polling a connected pipe socket for writability, there is an
163intrinsic race condition whereby writability might be lost between the
164polling and the writing system calls. In this case, the socket will
3497b2f2
RM
165block until write becomes possible again, unless non-blocking mode
166is enabled.
95430c0b
RDC
167
168
169The pipe protocol provides two socket options at the SOL_PNPIPE level:
170
171 PNPIPE_ENCAP accepts one integer value (int) of:
172
173 PNPIPE_ENCAP_NONE: The socket operates normally (default).
174
175 PNPIPE_ENCAP_IP: The socket is used as a backend for a virtual IP
176 interface. This requires CAP_NET_ADMIN capability. GPRS data
177 support on Nokia modems can use this. Note that the socket cannot
178 be reliably poll()'d or read() from while in this mode.
179
180 PNPIPE_IFINDEX is a read-only integer value. It contains the
181 interface index of the network interface created by PNPIPE_ENCAP,
182 or zero if encapsulation is off.
183
acaf7df6
RDC
184 PNPIPE_HANDLE is a read-only integer value. It contains the underlying
185 identifier ("pipe handle") of the pipe. This is only defined for
186 socket descriptors that are already connected or being connected.
187
95430c0b 188
4d443a08
KS
189Phonet Pipe-controller Implementation
190-------------------------------------
191
192Phonet Pipe-controller is enabled by selecting the CONFIG_PHONET_PIPECTRLR Kconfig
193option. It is useful when communicating with those Nokia Modems which do not
194implement Pipe controller in them e.g. Nokia Slim Modem used in ST-Ericsson
195U8500 platform.
196
197The implementation is based on the Data Connection Establishment Sequence
198depicted in 'Nokia Wireless Modem API - Wireless_modem_user_guide.pdf'
199document.
200
201It allows a phonet sequenced socket (host-pep) to initiate a Pipe connection
202between itself and a remote pipe-end point (e.g. modem).
203
204The implementation adds socket options at SOL_PNPIPE level:
205
03789f26
RDC
206 PNPIPE_ENABLE accepts one integer value (int). If set to zero, the pipe
207 is disabled. If the value is non-zero, the pipe is enabled. If the pipe
208 is not (yet) connected, ENOTCONN is error is returned.
4d443a08 209
f20ce779
KS
210The implementation also adds socket 'connect'. On calling the 'connect', pipe
211will be created between the source socket and the destination, and the pipe
212state will be set to PIPE_DISABLED.
4d443a08 213
4d443a08
KS
214After a pipe has been created and enabled successfully, the Pipe data can be
215exchanged between the host-pep and remote-pep (modem).
216
f20ce779
KS
217User-space would typically follow below sequence with Pipe controller:-
218-socket
219-bind
220-setsockopt for PNPIPE_PIPE_HANDLE
221-connect
222-setsockopt for PNPIPE_ENCAP_IP
223-setsockopt for PNPIPE_ENABLE
224
225
953f5517
RDC
226Authors
227-------
228
229Linux Phonet was initially written by Sakari Ailus.
230Other contributors include Mikä Liljeberg, Andras Domokos,
231Carlos Chinea and Rémi Denis-Courmont.
232Copyright (C) 2008 Nokia Corporation.