xref: /openbmc/linux/include/uapi/linux/phonet.h (revision e2be04c7)
1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells /**
3607ca46eSDavid Howells  * file phonet.h
4607ca46eSDavid Howells  *
5607ca46eSDavid Howells  * Phonet sockets kernel interface
6607ca46eSDavid Howells  *
7607ca46eSDavid Howells  * Copyright (C) 2008 Nokia Corporation. All rights reserved.
8607ca46eSDavid Howells  *
9607ca46eSDavid Howells  * This program is free software; you can redistribute it and/or
10607ca46eSDavid Howells  * modify it under the terms of the GNU General Public License
11607ca46eSDavid Howells  * version 2 as published by the Free Software Foundation.
12607ca46eSDavid Howells  *
13607ca46eSDavid Howells  * This program is distributed in the hope that it will be useful, but
14607ca46eSDavid Howells  * WITHOUT ANY WARRANTY; without even the implied warranty of
15607ca46eSDavid Howells  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16607ca46eSDavid Howells  * General Public License for more details.
17607ca46eSDavid Howells  *
18607ca46eSDavid Howells  * You should have received a copy of the GNU General Public License
19607ca46eSDavid Howells  * along with this program; if not, write to the Free Software
20607ca46eSDavid Howells  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21607ca46eSDavid Howells  * 02110-1301 USA
22607ca46eSDavid Howells  */
23607ca46eSDavid Howells 
24607ca46eSDavid Howells #ifndef _UAPILINUX_PHONET_H
25607ca46eSDavid Howells #define _UAPILINUX_PHONET_H
26607ca46eSDavid Howells 
27607ca46eSDavid Howells #include <linux/types.h>
28607ca46eSDavid Howells #include <linux/socket.h>
29607ca46eSDavid Howells 
30607ca46eSDavid Howells /* Automatic protocol selection */
31607ca46eSDavid Howells #define PN_PROTO_TRANSPORT	0
32607ca46eSDavid Howells /* Phonet datagram socket */
33607ca46eSDavid Howells #define PN_PROTO_PHONET		1
34607ca46eSDavid Howells /* Phonet pipe */
35607ca46eSDavid Howells #define PN_PROTO_PIPE		2
36607ca46eSDavid Howells #define PHONET_NPROTO		3
37607ca46eSDavid Howells 
38607ca46eSDavid Howells /* Socket options for SOL_PNPIPE level */
39607ca46eSDavid Howells #define PNPIPE_ENCAP		1
40607ca46eSDavid Howells #define PNPIPE_IFINDEX		2
41607ca46eSDavid Howells #define PNPIPE_HANDLE		3
42607ca46eSDavid Howells #define PNPIPE_INITSTATE	4
43607ca46eSDavid Howells 
44607ca46eSDavid Howells #define PNADDR_ANY		0
45607ca46eSDavid Howells #define PNADDR_BROADCAST	0xFC
46607ca46eSDavid Howells #define PNPORT_RESOURCE_ROUTING	0
47607ca46eSDavid Howells 
48607ca46eSDavid Howells /* Values for PNPIPE_ENCAP option */
49607ca46eSDavid Howells #define PNPIPE_ENCAP_NONE	0
50607ca46eSDavid Howells #define PNPIPE_ENCAP_IP		1
51607ca46eSDavid Howells 
52607ca46eSDavid Howells /* ioctls */
53607ca46eSDavid Howells #define SIOCPNGETOBJECT		(SIOCPROTOPRIVATE + 0)
54607ca46eSDavid Howells #define SIOCPNENABLEPIPE	(SIOCPROTOPRIVATE + 13)
55607ca46eSDavid Howells #define SIOCPNADDRESOURCE	(SIOCPROTOPRIVATE + 14)
56607ca46eSDavid Howells #define SIOCPNDELRESOURCE	(SIOCPROTOPRIVATE + 15)
57607ca46eSDavid Howells 
58607ca46eSDavid Howells /* Phonet protocol header */
59607ca46eSDavid Howells struct phonethdr {
60607ca46eSDavid Howells 	__u8	pn_rdev;
61607ca46eSDavid Howells 	__u8	pn_sdev;
62607ca46eSDavid Howells 	__u8	pn_res;
63607ca46eSDavid Howells 	__be16	pn_length;
64607ca46eSDavid Howells 	__u8	pn_robj;
65607ca46eSDavid Howells 	__u8	pn_sobj;
66607ca46eSDavid Howells } __attribute__((packed));
67607ca46eSDavid Howells 
68607ca46eSDavid Howells /* Common Phonet payload header */
69607ca46eSDavid Howells struct phonetmsg {
70607ca46eSDavid Howells 	__u8	pn_trans_id;	/* transaction ID */
71607ca46eSDavid Howells 	__u8	pn_msg_id;	/* message type */
72607ca46eSDavid Howells 	union {
73607ca46eSDavid Howells 		struct {
74607ca46eSDavid Howells 			__u8	pn_submsg_id;	/* message subtype */
75607ca46eSDavid Howells 			__u8	pn_data[5];
76607ca46eSDavid Howells 		} base;
77607ca46eSDavid Howells 		struct {
78607ca46eSDavid Howells 			__u16	pn_e_res_id;	/* extended resource ID */
79607ca46eSDavid Howells 			__u8	pn_e_submsg_id;	/* message subtype */
80607ca46eSDavid Howells 			__u8	pn_e_data[3];
81607ca46eSDavid Howells 		} ext;
82607ca46eSDavid Howells 	} pn_msg_u;
83607ca46eSDavid Howells };
84607ca46eSDavid Howells #define PN_COMMON_MESSAGE	0xF0
85607ca46eSDavid Howells #define PN_COMMGR		0x10
86607ca46eSDavid Howells #define PN_PREFIX		0xE0 /* resource for extended messages */
87607ca46eSDavid Howells #define pn_submsg_id		pn_msg_u.base.pn_submsg_id
88607ca46eSDavid Howells #define pn_e_submsg_id		pn_msg_u.ext.pn_e_submsg_id
89607ca46eSDavid Howells #define pn_e_res_id		pn_msg_u.ext.pn_e_res_id
90607ca46eSDavid Howells #define pn_data			pn_msg_u.base.pn_data
91607ca46eSDavid Howells #define pn_e_data		pn_msg_u.ext.pn_e_data
92607ca46eSDavid Howells 
93607ca46eSDavid Howells /* data for unreachable errors */
94607ca46eSDavid Howells #define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP	0x01
95607ca46eSDavid Howells #define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP	0x14
96607ca46eSDavid Howells #define pn_orig_msg_id		pn_data[0]
97607ca46eSDavid Howells #define pn_status		pn_data[1]
98607ca46eSDavid Howells #define pn_e_orig_msg_id	pn_e_data[0]
99607ca46eSDavid Howells #define pn_e_status		pn_e_data[1]
100607ca46eSDavid Howells 
101607ca46eSDavid Howells /* Phonet socket address structure */
102607ca46eSDavid Howells struct sockaddr_pn {
103607ca46eSDavid Howells 	__kernel_sa_family_t spn_family;
104607ca46eSDavid Howells 	__u8 spn_obj;
105607ca46eSDavid Howells 	__u8 spn_dev;
106607ca46eSDavid Howells 	__u8 spn_resource;
107607ca46eSDavid Howells 	__u8 spn_zero[sizeof(struct sockaddr) - sizeof(__kernel_sa_family_t) - 3];
108607ca46eSDavid Howells } __attribute__((packed));
109607ca46eSDavid Howells 
110607ca46eSDavid Howells /* Well known address */
111607ca46eSDavid Howells #define PN_DEV_PC	0x10
112607ca46eSDavid Howells 
pn_object(__u8 addr,__u16 port)113607ca46eSDavid Howells static inline __u16 pn_object(__u8 addr, __u16 port)
114607ca46eSDavid Howells {
115607ca46eSDavid Howells 	return (addr << 8) | (port & 0x3ff);
116607ca46eSDavid Howells }
117607ca46eSDavid Howells 
pn_obj(__u16 handle)118607ca46eSDavid Howells static inline __u8 pn_obj(__u16 handle)
119607ca46eSDavid Howells {
120607ca46eSDavid Howells 	return handle & 0xff;
121607ca46eSDavid Howells }
122607ca46eSDavid Howells 
pn_dev(__u16 handle)123607ca46eSDavid Howells static inline __u8 pn_dev(__u16 handle)
124607ca46eSDavid Howells {
125607ca46eSDavid Howells 	return handle >> 8;
126607ca46eSDavid Howells }
127607ca46eSDavid Howells 
pn_port(__u16 handle)128607ca46eSDavid Howells static inline __u16 pn_port(__u16 handle)
129607ca46eSDavid Howells {
130607ca46eSDavid Howells 	return handle & 0x3ff;
131607ca46eSDavid Howells }
132607ca46eSDavid Howells 
pn_addr(__u16 handle)133607ca46eSDavid Howells static inline __u8 pn_addr(__u16 handle)
134607ca46eSDavid Howells {
135607ca46eSDavid Howells 	return (handle >> 8) & 0xfc;
136607ca46eSDavid Howells }
137607ca46eSDavid Howells 
pn_sockaddr_set_addr(struct sockaddr_pn * spn,__u8 addr)138607ca46eSDavid Howells static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
139607ca46eSDavid Howells {
140607ca46eSDavid Howells 	spn->spn_dev &= 0x03;
141607ca46eSDavid Howells 	spn->spn_dev |= addr & 0xfc;
142607ca46eSDavid Howells }
143607ca46eSDavid Howells 
pn_sockaddr_set_port(struct sockaddr_pn * spn,__u16 port)144607ca46eSDavid Howells static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
145607ca46eSDavid Howells {
146607ca46eSDavid Howells 	spn->spn_dev &= 0xfc;
147607ca46eSDavid Howells 	spn->spn_dev |= (port >> 8) & 0x03;
148607ca46eSDavid Howells 	spn->spn_obj = port & 0xff;
149607ca46eSDavid Howells }
150607ca46eSDavid Howells 
pn_sockaddr_set_object(struct sockaddr_pn * spn,__u16 handle)151607ca46eSDavid Howells static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
152607ca46eSDavid Howells 						__u16 handle)
153607ca46eSDavid Howells {
154607ca46eSDavid Howells 	spn->spn_dev = pn_dev(handle);
155607ca46eSDavid Howells 	spn->spn_obj = pn_obj(handle);
156607ca46eSDavid Howells }
157607ca46eSDavid Howells 
pn_sockaddr_set_resource(struct sockaddr_pn * spn,__u8 resource)158607ca46eSDavid Howells static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
159607ca46eSDavid Howells 						__u8 resource)
160607ca46eSDavid Howells {
161607ca46eSDavid Howells 	spn->spn_resource = resource;
162607ca46eSDavid Howells }
163607ca46eSDavid Howells 
pn_sockaddr_get_addr(const struct sockaddr_pn * spn)164607ca46eSDavid Howells static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
165607ca46eSDavid Howells {
166607ca46eSDavid Howells 	return spn->spn_dev & 0xfc;
167607ca46eSDavid Howells }
168607ca46eSDavid Howells 
pn_sockaddr_get_port(const struct sockaddr_pn * spn)169607ca46eSDavid Howells static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
170607ca46eSDavid Howells {
171607ca46eSDavid Howells 	return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
172607ca46eSDavid Howells }
173607ca46eSDavid Howells 
pn_sockaddr_get_object(const struct sockaddr_pn * spn)174607ca46eSDavid Howells static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
175607ca46eSDavid Howells {
176607ca46eSDavid Howells 	return pn_object(spn->spn_dev, spn->spn_obj);
177607ca46eSDavid Howells }
178607ca46eSDavid Howells 
pn_sockaddr_get_resource(const struct sockaddr_pn * spn)179607ca46eSDavid Howells static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
180607ca46eSDavid Howells {
181607ca46eSDavid Howells 	return spn->spn_resource;
182607ca46eSDavid Howells }
183607ca46eSDavid Howells 
184607ca46eSDavid Howells /* Phonet device ioctl requests */
185607ca46eSDavid Howells 
186607ca46eSDavid Howells #endif /* _UAPILINUX_PHONET_H */
187