4
* Phonet sockets kernel interface
6
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
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.
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.
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
23
#ifndef LINUX_PHONET_H
24
#define LINUX_PHONET_H
26
#include <linux/types.h>
27
#include <linux/socket.h>
29
/* Automatic protocol selection */
30
#define PN_PROTO_TRANSPORT 0
31
/* Phonet datagram socket */
32
#define PN_PROTO_PHONET 1
34
#define PN_PROTO_PIPE 2
35
#define PHONET_NPROTO 3
37
/* Socket options for SOL_PNPIPE level */
38
#define PNPIPE_ENCAP 1
39
#define PNPIPE_IFINDEX 2
40
#define PNPIPE_HANDLE 3
43
#define PNADDR_BROADCAST 0xFC
44
#define PNPORT_RESOURCE_ROUTING 0
46
/* Values for PNPIPE_ENCAP option */
47
#define PNPIPE_ENCAP_NONE 0
48
#define PNPIPE_ENCAP_IP 1
51
#define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
52
#define SIOCPNADDRESOURCE (SIOCPROTOPRIVATE + 14)
53
#define SIOCPNDELRESOURCE (SIOCPROTOPRIVATE + 15)
55
/* Phonet protocol header */
63
} __attribute__((packed));
65
/* Common Phonet payload header */
67
__u8 pn_trans_id; /* transaction ID */
68
__u8 pn_msg_id; /* message type */
71
__u8 pn_submsg_id; /* message subtype */
75
__u16 pn_e_res_id; /* extended resource ID */
76
__u8 pn_e_submsg_id; /* message subtype */
81
#define PN_COMMON_MESSAGE 0xF0
82
#define PN_COMMGR 0x10
83
#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
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]
98
/* Phonet socket address structure */
100
__kernel_sa_family_t spn_family;
104
__u8 spn_zero[sizeof(struct sockaddr) - sizeof(__kernel_sa_family_t) - 3];
105
} __attribute__((packed));
107
/* Well known address */
108
#define PN_DEV_PC 0x10
110
static inline __u16 pn_object(__u8 addr, __u16 port)
112
return (addr << 8) | (port & 0x3ff);
115
static inline __u8 pn_obj(__u16 handle)
117
return handle & 0xff;
120
static inline __u8 pn_dev(__u16 handle)
125
static inline __u16 pn_port(__u16 handle)
127
return handle & 0x3ff;
130
static inline __u8 pn_addr(__u16 handle)
132
return (handle >> 8) & 0xfc;
135
static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
137
spn->spn_dev &= 0x03;
138
spn->spn_dev |= addr & 0xfc;
141
static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
143
spn->spn_dev &= 0xfc;
144
spn->spn_dev |= (port >> 8) & 0x03;
145
spn->spn_obj = port & 0xff;
148
static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
151
spn->spn_dev = pn_dev(handle);
152
spn->spn_obj = pn_obj(handle);
155
static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
158
spn->spn_resource = resource;
161
static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
163
return spn->spn_dev & 0xfc;
166
static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
168
return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
171
static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
173
return pn_object(spn->spn_dev, spn->spn_obj);
176
static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
178
return spn->spn_resource;
181
/* Phonet device ioctl requests */
183
#define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0)
185
struct if_phonet_autoconf {
189
struct if_phonet_req {
190
char ifr_phonet_name[16];
192
struct if_phonet_autoconf ifru_phonet_autoconf;
195
#define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf
196
#endif /* __KERNEL__ */