blob: d02a191cae62ba26608a48b954e2852f3ede5122 [file] [log] [blame]
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -07001/**
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
Jaswinder Singh Rajput06f43ad2009-01-30 22:03:25 +053026#include <linux/types.h>
27
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070028/* Automatic protocol selection */
29#define PN_PROTO_TRANSPORT 0
30/* Phonet datagram socket */
31#define PN_PROTO_PHONET 1
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070032/* Phonet pipe */
33#define PN_PROTO_PIPE 2
34#define PHONET_NPROTO 3
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070035
Rémi Denis-Courmont02a47612008-10-05 11:16:16 -070036/* Socket options for SOL_PNPIPE level */
37#define PNPIPE_ENCAP 1
38#define PNPIPE_IFINDEX 2
39
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070040#define PNADDR_ANY 0
Rémi Denis-Courmont18a11662009-09-23 03:17:11 +000041#define PNADDR_BROADCAST 0xFC
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070042#define PNPORT_RESOURCE_ROUTING 0
43
Rémi Denis-Courmont02a47612008-10-05 11:16:16 -070044/* Values for PNPIPE_ENCAP option */
45#define PNPIPE_ENCAP_NONE 0
46#define PNPIPE_ENCAP_IP 1
47
Remi Denis-Courmontba113a92008-09-22 20:05:19 -070048/* ioctls */
49#define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
B Sampath Kumar2e4b6fc2010-05-18 12:31:45 +053050#define SIOCPNSETBINDFLAG (SIOCPROTOPRIVATE + 1)
Remi Denis-Courmontba113a92008-09-22 20:05:19 -070051
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070052/* Phonet protocol header */
53struct phonethdr {
54 __u8 pn_rdev;
55 __u8 pn_sdev;
56 __u8 pn_res;
57 __be16 pn_length;
58 __u8 pn_robj;
59 __u8 pn_sobj;
60} __attribute__((packed));
61
Remi Denis-Courmontbe0c52b2008-09-22 20:09:13 -070062/* Common Phonet payload header */
63struct phonetmsg {
64 __u8 pn_trans_id; /* transaction ID */
65 __u8 pn_msg_id; /* message type */
66 union {
67 struct {
68 __u8 pn_submsg_id; /* message subtype */
69 __u8 pn_data[5];
70 } base;
71 struct {
72 __u16 pn_e_res_id; /* extended resource ID */
73 __u8 pn_e_submsg_id; /* message subtype */
74 __u8 pn_e_data[3];
75 } ext;
76 } pn_msg_u;
77};
78#define PN_COMMON_MESSAGE 0xF0
Remi Denis-Courmontc3a90c72008-10-26 23:07:25 -070079#define PN_COMMGR 0x10
Remi Denis-Courmontbe0c52b2008-09-22 20:09:13 -070080#define PN_PREFIX 0xE0 /* resource for extended messages */
81#define pn_submsg_id pn_msg_u.base.pn_submsg_id
82#define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id
83#define pn_e_res_id pn_msg_u.ext.pn_e_res_id
84#define pn_data pn_msg_u.base.pn_data
85#define pn_e_data pn_msg_u.ext.pn_e_data
86
87/* data for unreachable errors */
88#define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01
89#define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14
90#define pn_orig_msg_id pn_data[0]
91#define pn_status pn_data[1]
92#define pn_e_orig_msg_id pn_e_data[0]
93#define pn_e_status pn_e_data[1]
94
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070095/* Phonet socket address structure */
96struct sockaddr_pn {
97 sa_family_t spn_family;
98 __u8 spn_obj;
99 __u8 spn_dev;
100 __u8 spn_resource;
101 __u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
102} __attribute__ ((packed));
103
Rémi Denis-Courmont02571f82009-09-09 00:00:06 +0000104/* Well known address */
105#define PN_DEV_PC 0x10
106
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -0700107static inline __u16 pn_object(__u8 addr, __u16 port)
108{
109 return (addr << 8) | (port & 0x3ff);
110}
111
112static inline __u8 pn_obj(__u16 handle)
113{
114 return handle & 0xff;
115}
116
117static inline __u8 pn_dev(__u16 handle)
118{
119 return handle >> 8;
120}
121
122static inline __u16 pn_port(__u16 handle)
123{
124 return handle & 0x3ff;
125}
126
127static inline __u8 pn_addr(__u16 handle)
128{
129 return (handle >> 8) & 0xfc;
130}
131
132static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
133{
134 spn->spn_dev &= 0x03;
135 spn->spn_dev |= addr & 0xfc;
136}
137
138static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
139{
140 spn->spn_dev &= 0xfc;
141 spn->spn_dev |= (port >> 8) & 0x03;
142 spn->spn_obj = port & 0xff;
143}
144
145static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
146 __u16 handle)
147{
148 spn->spn_dev = pn_dev(handle);
149 spn->spn_obj = pn_obj(handle);
150}
151
152static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
153 __u8 resource)
154{
155 spn->spn_resource = resource;
156}
157
158static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
159{
160 return spn->spn_dev & 0xfc;
161}
162
163static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
164{
165 return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
166}
167
168static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
169{
170 return pn_object(spn->spn_dev, spn->spn_obj);
171}
172
173static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
174{
175 return spn->spn_resource;
176}
177
Rémi Denis-Courmontf5bb1c52009-09-09 00:00:05 +0000178/* Phonet device ioctl requests */
179#ifdef __KERNEL__
180#define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0)
181
182struct if_phonet_autoconf {
183 uint8_t device;
184};
185
186struct if_phonet_req {
187 char ifr_phonet_name[16];
188 union {
189 struct if_phonet_autoconf ifru_phonet_autoconf;
190 } ifr_ifru;
191};
192#define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf
193#endif /* __KERNEL__ */
194
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -0700195#endif