Phonet: receive pipe control requests as out-of-band data
[deliverable/linux.git] / include / linux / phonet.h
CommitLineData
bce7b154
RDC
1/**
2 * file phonet.h
3 *
4 * Phonet sockets kernel interface
5 *
6 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#ifndef LINUX_PHONET_H
24#define LINUX_PHONET_H
25
26/* Automatic protocol selection */
27#define PN_PROTO_TRANSPORT 0
28/* Phonet datagram socket */
29#define PN_PROTO_PHONET 1
9641458d
RDC
30/* Phonet pipe */
31#define PN_PROTO_PIPE 2
32#define PHONET_NPROTO 3
bce7b154
RDC
33
34#define PNADDR_ANY 0
35#define PNPORT_RESOURCE_ROUTING 0
36
ba113a94
RDC
37/* ioctls */
38#define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
39
bce7b154
RDC
40/* Phonet protocol header */
41struct phonethdr {
42 __u8 pn_rdev;
43 __u8 pn_sdev;
44 __u8 pn_res;
45 __be16 pn_length;
46 __u8 pn_robj;
47 __u8 pn_sobj;
48} __attribute__((packed));
49
be0c52bf
RDC
50/* Common Phonet payload header */
51struct phonetmsg {
52 __u8 pn_trans_id; /* transaction ID */
53 __u8 pn_msg_id; /* message type */
54 union {
55 struct {
56 __u8 pn_submsg_id; /* message subtype */
57 __u8 pn_data[5];
58 } base;
59 struct {
60 __u16 pn_e_res_id; /* extended resource ID */
61 __u8 pn_e_submsg_id; /* message subtype */
62 __u8 pn_e_data[3];
63 } ext;
64 } pn_msg_u;
65};
66#define PN_COMMON_MESSAGE 0xF0
67#define PN_PREFIX 0xE0 /* resource for extended messages */
68#define pn_submsg_id pn_msg_u.base.pn_submsg_id
69#define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id
70#define pn_e_res_id pn_msg_u.ext.pn_e_res_id
71#define pn_data pn_msg_u.base.pn_data
72#define pn_e_data pn_msg_u.ext.pn_e_data
73
74/* data for unreachable errors */
75#define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01
76#define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14
77#define pn_orig_msg_id pn_data[0]
78#define pn_status pn_data[1]
79#define pn_e_orig_msg_id pn_e_data[0]
80#define pn_e_status pn_e_data[1]
81
bce7b154
RDC
82/* Phonet socket address structure */
83struct sockaddr_pn {
84 sa_family_t spn_family;
85 __u8 spn_obj;
86 __u8 spn_dev;
87 __u8 spn_resource;
88 __u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
89} __attribute__ ((packed));
90
91static inline __u16 pn_object(__u8 addr, __u16 port)
92{
93 return (addr << 8) | (port & 0x3ff);
94}
95
96static inline __u8 pn_obj(__u16 handle)
97{
98 return handle & 0xff;
99}
100
101static inline __u8 pn_dev(__u16 handle)
102{
103 return handle >> 8;
104}
105
106static inline __u16 pn_port(__u16 handle)
107{
108 return handle & 0x3ff;
109}
110
111static inline __u8 pn_addr(__u16 handle)
112{
113 return (handle >> 8) & 0xfc;
114}
115
116static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
117{
118 spn->spn_dev &= 0x03;
119 spn->spn_dev |= addr & 0xfc;
120}
121
122static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
123{
124 spn->spn_dev &= 0xfc;
125 spn->spn_dev |= (port >> 8) & 0x03;
126 spn->spn_obj = port & 0xff;
127}
128
129static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
130 __u16 handle)
131{
132 spn->spn_dev = pn_dev(handle);
133 spn->spn_obj = pn_obj(handle);
134}
135
136static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
137 __u8 resource)
138{
139 spn->spn_resource = resource;
140}
141
142static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
143{
144 return spn->spn_dev & 0xfc;
145}
146
147static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
148{
149 return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
150}
151
152static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
153{
154 return pn_object(spn->spn_dev, spn->spn_obj);
155}
156
157static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
158{
159 return spn->spn_resource;
160}
161
162#endif
This page took 0.038995 seconds and 5 git commands to generate.