blob: f53a4167c5f41bb2d9ba9a30fdecc3805f97a2df [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>
Ben Hutchingsbcb949b2011-08-24 18:43:55 +000027#include <linux/socket.h>
Jaswinder Singh Rajput06f43ad2009-01-30 22:03:25 +053028
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070029/* Automatic protocol selection */
30#define PN_PROTO_TRANSPORT 0
31/* Phonet datagram socket */
32#define PN_PROTO_PHONET 1
Rémi Denis-Courmont96414582008-10-05 11:15:13 -070033/* Phonet pipe */
34#define PN_PROTO_PIPE 2
35#define PHONET_NPROTO 3
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070036
Rémi Denis-Courmont02a47612008-10-05 11:16:16 -070037/* Socket options for SOL_PNPIPE level */
38#define PNPIPE_ENCAP 1
39#define PNPIPE_IFINDEX 2
Rémi Denis-Courmontacaf7df2011-03-08 22:44:11 +000040#define PNPIPE_HANDLE 3
Rémi Denis-Courmont02a47612008-10-05 11:16:16 -070041
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070042#define PNADDR_ANY 0
Rémi Denis-Courmont18a11662009-09-23 03:17:11 +000043#define PNADDR_BROADCAST 0xFC
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070044#define PNPORT_RESOURCE_ROUTING 0
45
Rémi Denis-Courmont02a47612008-10-05 11:16:16 -070046/* Values for PNPIPE_ENCAP option */
47#define PNPIPE_ENCAP_NONE 0
48#define PNPIPE_ENCAP_IP 1
49
Remi Denis-Courmontba113a92008-09-22 20:05:19 -070050/* ioctls */
51#define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
Rémi Denis-Courmont7417fa82010-09-15 12:30:12 +000052#define SIOCPNADDRESOURCE (SIOCPROTOPRIVATE + 14)
53#define SIOCPNDELRESOURCE (SIOCPROTOPRIVATE + 15)
Remi Denis-Courmontba113a92008-09-22 20:05:19 -070054
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070055/* Phonet protocol header */
56struct phonethdr {
57 __u8 pn_rdev;
58 __u8 pn_sdev;
59 __u8 pn_res;
60 __be16 pn_length;
61 __u8 pn_robj;
62 __u8 pn_sobj;
Changli Gao09cd2b92010-08-22 17:25:05 +000063} __attribute__((packed));
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070064
Remi Denis-Courmontbe0c52b2008-09-22 20:09:13 -070065/* Common Phonet payload header */
66struct phonetmsg {
67 __u8 pn_trans_id; /* transaction ID */
68 __u8 pn_msg_id; /* message type */
69 union {
70 struct {
71 __u8 pn_submsg_id; /* message subtype */
72 __u8 pn_data[5];
73 } base;
74 struct {
75 __u16 pn_e_res_id; /* extended resource ID */
76 __u8 pn_e_submsg_id; /* message subtype */
77 __u8 pn_e_data[3];
78 } ext;
79 } pn_msg_u;
80};
81#define PN_COMMON_MESSAGE 0xF0
Remi Denis-Courmontc3a90c72008-10-26 23:07:25 -070082#define PN_COMMGR 0x10
Remi Denis-Courmontbe0c52b2008-09-22 20:09:13 -070083#define PN_PREFIX 0xE0 /* resource for extended messages */
84#define pn_submsg_id pn_msg_u.base.pn_submsg_id
85#define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id
86#define pn_e_res_id pn_msg_u.ext.pn_e_res_id
87#define pn_data pn_msg_u.base.pn_data
88#define pn_e_data pn_msg_u.ext.pn_e_data
89
90/* data for unreachable errors */
91#define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01
92#define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14
93#define pn_orig_msg_id pn_data[0]
94#define pn_status pn_data[1]
95#define pn_e_orig_msg_id pn_e_data[0]
96#define pn_e_status pn_e_data[1]
97
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -070098/* Phonet socket address structure */
99struct sockaddr_pn {
Ben Hutchingsbcb949b2011-08-24 18:43:55 +0000100 __kernel_sa_family_t spn_family;
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -0700101 __u8 spn_obj;
102 __u8 spn_dev;
103 __u8 spn_resource;
Ben Hutchingsbcb949b2011-08-24 18:43:55 +0000104 __u8 spn_zero[sizeof(struct sockaddr) - sizeof(__kernel_sa_family_t) - 3];
Changli Gao09cd2b92010-08-22 17:25:05 +0000105} __attribute__((packed));
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -0700106
Rémi Denis-Courmont02571f82009-09-09 00:00:06 +0000107/* Well known address */
108#define PN_DEV_PC 0x10
109
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -0700110static inline __u16 pn_object(__u8 addr, __u16 port)
111{
112 return (addr << 8) | (port & 0x3ff);
113}
114
115static inline __u8 pn_obj(__u16 handle)
116{
117 return handle & 0xff;
118}
119
120static inline __u8 pn_dev(__u16 handle)
121{
122 return handle >> 8;
123}
124
125static inline __u16 pn_port(__u16 handle)
126{
127 return handle & 0x3ff;
128}
129
130static inline __u8 pn_addr(__u16 handle)
131{
132 return (handle >> 8) & 0xfc;
133}
134
135static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
136{
137 spn->spn_dev &= 0x03;
138 spn->spn_dev |= addr & 0xfc;
139}
140
141static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
142{
143 spn->spn_dev &= 0xfc;
144 spn->spn_dev |= (port >> 8) & 0x03;
145 spn->spn_obj = port & 0xff;
146}
147
148static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
149 __u16 handle)
150{
151 spn->spn_dev = pn_dev(handle);
152 spn->spn_obj = pn_obj(handle);
153}
154
155static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
156 __u8 resource)
157{
158 spn->spn_resource = resource;
159}
160
161static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
162{
163 return spn->spn_dev & 0xfc;
164}
165
166static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
167{
168 return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
169}
170
171static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
172{
173 return pn_object(spn->spn_dev, spn->spn_obj);
174}
175
176static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
177{
178 return spn->spn_resource;
179}
180
Rémi Denis-Courmontf5bb1c52009-09-09 00:00:05 +0000181/* Phonet device ioctl requests */
182#ifdef __KERNEL__
183#define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0)
184
185struct if_phonet_autoconf {
186 uint8_t device;
187};
188
189struct if_phonet_req {
190 char ifr_phonet_name[16];
191 union {
192 struct if_phonet_autoconf ifru_phonet_autoconf;
193 } ifr_ifru;
194};
195#define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf
196#endif /* __KERNEL__ */
197
Remi Denis-Courmontbce7b152008-09-22 19:51:15 -0700198#endif