1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
5 * Phonet sockets kernel interface
7 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #ifndef _UAPILINUX_PHONET_H
25 #define _UAPILINUX_PHONET_H
27 #include <linux/types.h>
28 #include <linux/socket.h>
30 /* Automatic protocol selection */
31 #define PN_PROTO_TRANSPORT 0
32 /* Phonet datagram socket */
33 #define PN_PROTO_PHONET 1
35 #define PN_PROTO_PIPE 2
36 #define PHONET_NPROTO 3
38 /* Socket options for SOL_PNPIPE level */
39 #define PNPIPE_ENCAP 1
40 #define PNPIPE_IFINDEX 2
41 #define PNPIPE_HANDLE 3
42 #define PNPIPE_INITSTATE 4
45 #define PNADDR_BROADCAST 0xFC
46 #define PNPORT_RESOURCE_ROUTING 0
48 /* Values for PNPIPE_ENCAP option */
49 #define PNPIPE_ENCAP_NONE 0
50 #define PNPIPE_ENCAP_IP 1
53 #define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
54 #define SIOCPNENABLEPIPE (SIOCPROTOPRIVATE + 13)
55 #define SIOCPNADDRESOURCE (SIOCPROTOPRIVATE + 14)
56 #define SIOCPNDELRESOURCE (SIOCPROTOPRIVATE + 15)
58 /* Phonet protocol header */
66 } __attribute__((packed));
68 /* Common Phonet payload header */
70 __u8 pn_trans_id; /* transaction ID */
71 __u8 pn_msg_id; /* message type */
74 __u8 pn_submsg_id; /* message subtype */
78 __u16 pn_e_res_id; /* extended resource ID */
79 __u8 pn_e_submsg_id; /* message subtype */
84 #define PN_COMMON_MESSAGE 0xF0
85 #define PN_COMMGR 0x10
86 #define PN_PREFIX 0xE0 /* resource for extended messages */
87 #define pn_submsg_id pn_msg_u.base.pn_submsg_id
88 #define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id
89 #define pn_e_res_id pn_msg_u.ext.pn_e_res_id
90 #define pn_data pn_msg_u.base.pn_data
91 #define pn_e_data pn_msg_u.ext.pn_e_data
93 /* data for unreachable errors */
94 #define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01
95 #define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14
96 #define pn_orig_msg_id pn_data[0]
97 #define pn_status pn_data[1]
98 #define pn_e_orig_msg_id pn_e_data[0]
99 #define pn_e_status pn_e_data[1]
101 /* Phonet socket address structure */
103 __kernel_sa_family_t spn_family;
107 __u8 spn_zero[sizeof(struct sockaddr) - sizeof(__kernel_sa_family_t) - 3];
108 } __attribute__((packed));
110 /* Well known address */
111 #define PN_DEV_PC 0x10
113 static inline __u16 pn_object(__u8 addr, __u16 port)
115 return (addr << 8) | (port & 0x3ff);
118 static inline __u8 pn_obj(__u16 handle)
120 return handle & 0xff;
123 static inline __u8 pn_dev(__u16 handle)
128 static inline __u16 pn_port(__u16 handle)
130 return handle & 0x3ff;
133 static inline __u8 pn_addr(__u16 handle)
135 return (handle >> 8) & 0xfc;
138 static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
140 spn->spn_dev &= 0x03;
141 spn->spn_dev |= addr & 0xfc;
144 static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
146 spn->spn_dev &= 0xfc;
147 spn->spn_dev |= (port >> 8) & 0x03;
148 spn->spn_obj = port & 0xff;
151 static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
154 spn->spn_dev = pn_dev(handle);
155 spn->spn_obj = pn_obj(handle);
158 static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
161 spn->spn_resource = resource;
164 static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
166 return spn->spn_dev & 0xfc;
169 static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
171 return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
174 static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
176 return pn_object(spn->spn_dev, spn->spn_obj);
179 static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
181 return spn->spn_resource;
184 /* Phonet device ioctl requests */
186 #endif /* _UAPILINUX_PHONET_H */