new retransmit part 3
[cor_2_6_31.git] / include / linux / phonet.h
blobee5e3c9e2bcaf0006b6b03f659cc6d323c15f3bb
1 /**
2 * file phonet.h
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
20 * 02110-1301 USA
23 #ifndef LINUX_PHONET_H
24 #define LINUX_PHONET_H
26 #include <linux/types.h>
28 /* Automatic protocol selection */
29 #define PN_PROTO_TRANSPORT 0
30 /* Phonet datagram socket */
31 #define PN_PROTO_PHONET 1
32 /* Phonet pipe */
33 #define PN_PROTO_PIPE 2
34 #define PHONET_NPROTO 3
36 /* Socket options for SOL_PNPIPE level */
37 #define PNPIPE_ENCAP 1
38 #define PNPIPE_IFINDEX 2
40 #define PNADDR_ANY 0
41 #define PNPORT_RESOURCE_ROUTING 0
43 /* Values for PNPIPE_ENCAP option */
44 #define PNPIPE_ENCAP_NONE 0
45 #define PNPIPE_ENCAP_IP 1
47 /* ioctls */
48 #define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
50 /* Phonet protocol header */
51 struct phonethdr {
52 __u8 pn_rdev;
53 __u8 pn_sdev;
54 __u8 pn_res;
55 __be16 pn_length;
56 __u8 pn_robj;
57 __u8 pn_sobj;
58 } __attribute__((packed));
60 /* Common Phonet payload header */
61 struct phonetmsg {
62 __u8 pn_trans_id; /* transaction ID */
63 __u8 pn_msg_id; /* message type */
64 union {
65 struct {
66 __u8 pn_submsg_id; /* message subtype */
67 __u8 pn_data[5];
68 } base;
69 struct {
70 __u16 pn_e_res_id; /* extended resource ID */
71 __u8 pn_e_submsg_id; /* message subtype */
72 __u8 pn_e_data[3];
73 } ext;
74 } pn_msg_u;
76 #define PN_COMMON_MESSAGE 0xF0
77 #define PN_COMMGR 0x10
78 #define PN_PREFIX 0xE0 /* resource for extended messages */
79 #define pn_submsg_id pn_msg_u.base.pn_submsg_id
80 #define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id
81 #define pn_e_res_id pn_msg_u.ext.pn_e_res_id
82 #define pn_data pn_msg_u.base.pn_data
83 #define pn_e_data pn_msg_u.ext.pn_e_data
85 /* data for unreachable errors */
86 #define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01
87 #define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14
88 #define pn_orig_msg_id pn_data[0]
89 #define pn_status pn_data[1]
90 #define pn_e_orig_msg_id pn_e_data[0]
91 #define pn_e_status pn_e_data[1]
93 /* Phonet socket address structure */
94 struct sockaddr_pn {
95 sa_family_t spn_family;
96 __u8 spn_obj;
97 __u8 spn_dev;
98 __u8 spn_resource;
99 __u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
100 } __attribute__ ((packed));
102 static inline __u16 pn_object(__u8 addr, __u16 port)
104 return (addr << 8) | (port & 0x3ff);
107 static inline __u8 pn_obj(__u16 handle)
109 return handle & 0xff;
112 static inline __u8 pn_dev(__u16 handle)
114 return handle >> 8;
117 static inline __u16 pn_port(__u16 handle)
119 return handle & 0x3ff;
122 static inline __u8 pn_addr(__u16 handle)
124 return (handle >> 8) & 0xfc;
127 static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
129 spn->spn_dev &= 0x03;
130 spn->spn_dev |= addr & 0xfc;
133 static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
135 spn->spn_dev &= 0xfc;
136 spn->spn_dev |= (port >> 8) & 0x03;
137 spn->spn_obj = port & 0xff;
140 static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
141 __u16 handle)
143 spn->spn_dev = pn_dev(handle);
144 spn->spn_obj = pn_obj(handle);
147 static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
148 __u8 resource)
150 spn->spn_resource = resource;
153 static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
155 return spn->spn_dev & 0xfc;
158 static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
160 return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
163 static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
165 return pn_object(spn->spn_dev, spn->spn_obj);
168 static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
170 return spn->spn_resource;
173 #endif