]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/phonet.h
Merge branch 'for-linus' of git://git.infradead.org/users/eparis/notify
[net-next-2.6.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
06f43adb
JSR
26#include <linux/types.h>
27
bce7b154
RDC
28/* Automatic protocol selection */
29#define PN_PROTO_TRANSPORT 0
30/* Phonet datagram socket */
31#define PN_PROTO_PHONET 1
9641458d
RDC
32/* Phonet pipe */
33#define PN_PROTO_PIPE 2
34#define PHONET_NPROTO 3
bce7b154 35
02a47617
RDC
36/* Socket options for SOL_PNPIPE level */
37#define PNPIPE_ENCAP 1
38#define PNPIPE_IFINDEX 2
39
bce7b154 40#define PNADDR_ANY 0
18a1166d 41#define PNADDR_BROADCAST 0xFC
bce7b154
RDC
42#define PNPORT_RESOURCE_ROUTING 0
43
02a47617
RDC
44/* Values for PNPIPE_ENCAP option */
45#define PNPIPE_ENCAP_NONE 0
46#define PNPIPE_ENCAP_IP 1
47
ba113a94
RDC
48/* ioctls */
49#define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
50
bce7b154
RDC
51/* Phonet protocol header */
52struct phonethdr {
53 __u8 pn_rdev;
54 __u8 pn_sdev;
55 __u8 pn_res;
56 __be16 pn_length;
57 __u8 pn_robj;
58 __u8 pn_sobj;
09cd2b99 59} __attribute__((packed));
bce7b154 60
be0c52bf
RDC
61/* Common Phonet payload header */
62struct phonetmsg {
63 __u8 pn_trans_id; /* transaction ID */
64 __u8 pn_msg_id; /* message type */
65 union {
66 struct {
67 __u8 pn_submsg_id; /* message subtype */
68 __u8 pn_data[5];
69 } base;
70 struct {
71 __u16 pn_e_res_id; /* extended resource ID */
72 __u8 pn_e_submsg_id; /* message subtype */
73 __u8 pn_e_data[3];
74 } ext;
75 } pn_msg_u;
76};
77#define PN_COMMON_MESSAGE 0xF0
c3a90c78 78#define PN_COMMGR 0x10
be0c52bf
RDC
79#define PN_PREFIX 0xE0 /* resource for extended messages */
80#define pn_submsg_id pn_msg_u.base.pn_submsg_id
81#define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id
82#define pn_e_res_id pn_msg_u.ext.pn_e_res_id
83#define pn_data pn_msg_u.base.pn_data
84#define pn_e_data pn_msg_u.ext.pn_e_data
85
86/* data for unreachable errors */
87#define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01
88#define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14
89#define pn_orig_msg_id pn_data[0]
90#define pn_status pn_data[1]
91#define pn_e_orig_msg_id pn_e_data[0]
92#define pn_e_status pn_e_data[1]
93
bce7b154
RDC
94/* Phonet socket address structure */
95struct sockaddr_pn {
96 sa_family_t spn_family;
97 __u8 spn_obj;
98 __u8 spn_dev;
99 __u8 spn_resource;
100 __u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
09cd2b99 101} __attribute__((packed));
bce7b154 102
02571f89
RDC
103/* Well known address */
104#define PN_DEV_PC 0x10
105
bce7b154
RDC
106static inline __u16 pn_object(__u8 addr, __u16 port)
107{
108 return (addr << 8) | (port & 0x3ff);
109}
110
111static inline __u8 pn_obj(__u16 handle)
112{
113 return handle & 0xff;
114}
115
116static inline __u8 pn_dev(__u16 handle)
117{
118 return handle >> 8;
119}
120
121static inline __u16 pn_port(__u16 handle)
122{
123 return handle & 0x3ff;
124}
125
126static inline __u8 pn_addr(__u16 handle)
127{
128 return (handle >> 8) & 0xfc;
129}
130
131static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
132{
133 spn->spn_dev &= 0x03;
134 spn->spn_dev |= addr & 0xfc;
135}
136
137static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
138{
139 spn->spn_dev &= 0xfc;
140 spn->spn_dev |= (port >> 8) & 0x03;
141 spn->spn_obj = port & 0xff;
142}
143
144static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
145 __u16 handle)
146{
147 spn->spn_dev = pn_dev(handle);
148 spn->spn_obj = pn_obj(handle);
149}
150
151static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
152 __u8 resource)
153{
154 spn->spn_resource = resource;
155}
156
157static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
158{
159 return spn->spn_dev & 0xfc;
160}
161
162static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
163{
164 return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
165}
166
167static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
168{
169 return pn_object(spn->spn_dev, spn->spn_obj);
170}
171
172static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
173{
174 return spn->spn_resource;
175}
176
f5bb1c55
RDC
177/* Phonet device ioctl requests */
178#ifdef __KERNEL__
179#define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0)
180
181struct if_phonet_autoconf {
182 uint8_t device;
183};
184
185struct if_phonet_req {
186 char ifr_phonet_name[16];
187 union {
188 struct if_phonet_autoconf ifru_phonet_autoconf;
189 } ifr_ifru;
190};
191#define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf
192#endif /* __KERNEL__ */
193
bce7b154 194#endif