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 /* Automatic protocol selection */
27 #define PN_PROTO_TRANSPORT 0
28 /* Phonet datagram socket */
29 #define PN_PROTO_PHONET 1
31 #define PN_PROTO_PIPE 2
32 #define PHONET_NPROTO 3
34 /* Socket options for SOL_PNPIPE level */
35 #define PNPIPE_ENCAP 1
36 #define PNPIPE_IFINDEX 2
39 #define PNPORT_RESOURCE_ROUTING 0
41 /* Values for PNPIPE_ENCAP option */
42 #define PNPIPE_ENCAP_NONE 0
43 #define PNPIPE_ENCAP_IP 1
46 #define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
48 /* Phonet protocol header */
56 } __attribute__((packed
));
58 /* Common Phonet payload header */
60 __u8 pn_trans_id
; /* transaction ID */
61 __u8 pn_msg_id
; /* message type */
64 __u8 pn_submsg_id
; /* message subtype */
68 __u16 pn_e_res_id
; /* extended resource ID */
69 __u8 pn_e_submsg_id
; /* message subtype */
74 #define PN_COMMON_MESSAGE 0xF0
75 #define PN_PREFIX 0xE0 /* resource for extended messages */
76 #define pn_submsg_id pn_msg_u.base.pn_submsg_id
77 #define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id
78 #define pn_e_res_id pn_msg_u.ext.pn_e_res_id
79 #define pn_data pn_msg_u.base.pn_data
80 #define pn_e_data pn_msg_u.ext.pn_e_data
82 /* data for unreachable errors */
83 #define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01
84 #define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14
85 #define pn_orig_msg_id pn_data[0]
86 #define pn_status pn_data[1]
87 #define pn_e_orig_msg_id pn_e_data[0]
88 #define pn_e_status pn_e_data[1]
90 /* Phonet socket address structure */
92 sa_family_t spn_family
;
96 __u8 spn_zero
[sizeof(struct sockaddr
) - sizeof(sa_family_t
) - 3];
97 } __attribute__ ((packed
));
99 static inline __u16
pn_object(__u8 addr
, __u16 port
)
101 return (addr
<< 8) | (port
& 0x3ff);
104 static inline __u8
pn_obj(__u16 handle
)
106 return handle
& 0xff;
109 static inline __u8
pn_dev(__u16 handle
)
114 static inline __u16
pn_port(__u16 handle
)
116 return handle
& 0x3ff;
119 static inline __u8
pn_addr(__u16 handle
)
121 return (handle
>> 8) & 0xfc;
124 static inline void pn_sockaddr_set_addr(struct sockaddr_pn
*spn
, __u8 addr
)
126 spn
->spn_dev
&= 0x03;
127 spn
->spn_dev
|= addr
& 0xfc;
130 static inline void pn_sockaddr_set_port(struct sockaddr_pn
*spn
, __u16 port
)
132 spn
->spn_dev
&= 0xfc;
133 spn
->spn_dev
|= (port
>> 8) & 0x03;
134 spn
->spn_obj
= port
& 0xff;
137 static inline void pn_sockaddr_set_object(struct sockaddr_pn
*spn
,
140 spn
->spn_dev
= pn_dev(handle
);
141 spn
->spn_obj
= pn_obj(handle
);
144 static inline void pn_sockaddr_set_resource(struct sockaddr_pn
*spn
,
147 spn
->spn_resource
= resource
;
150 static inline __u8
pn_sockaddr_get_addr(const struct sockaddr_pn
*spn
)
152 return spn
->spn_dev
& 0xfc;
155 static inline __u16
pn_sockaddr_get_port(const struct sockaddr_pn
*spn
)
157 return ((spn
->spn_dev
& 0x03) << 8) | spn
->spn_obj
;
160 static inline __u16
pn_sockaddr_get_object(const struct sockaddr_pn
*spn
)
162 return pn_object(spn
->spn_dev
, spn
->spn_obj
);
165 static inline __u8
pn_sockaddr_get_resource(const struct sockaddr_pn
*spn
)
167 return spn
->spn_resource
;