Phonet: global definitions
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / phonet.h
CommitLineData
bce7b154
RDC
1/**
2 * file phonet.h
3 *
4 * Phonet sockets kernel interface
5 *
6 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
7 *
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.
11 *
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.
16 *
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
21 */
22
23#ifndef LINUX_PHONET_H
24#define LINUX_PHONET_H
25
26/* Automatic protocol selection */
27#define PN_PROTO_TRANSPORT 0
28/* Phonet datagram socket */
29#define PN_PROTO_PHONET 1
30#define PHONET_NPROTO 2
31
32#define PNADDR_ANY 0
33#define PNPORT_RESOURCE_ROUTING 0
34
35/* Phonet protocol header */
36struct phonethdr {
37 __u8 pn_rdev;
38 __u8 pn_sdev;
39 __u8 pn_res;
40 __be16 pn_length;
41 __u8 pn_robj;
42 __u8 pn_sobj;
43} __attribute__((packed));
44
45/* Phonet socket address structure */
46struct sockaddr_pn {
47 sa_family_t spn_family;
48 __u8 spn_obj;
49 __u8 spn_dev;
50 __u8 spn_resource;
51 __u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
52} __attribute__ ((packed));
53
54static inline __u16 pn_object(__u8 addr, __u16 port)
55{
56 return (addr << 8) | (port & 0x3ff);
57}
58
59static inline __u8 pn_obj(__u16 handle)
60{
61 return handle & 0xff;
62}
63
64static inline __u8 pn_dev(__u16 handle)
65{
66 return handle >> 8;
67}
68
69static inline __u16 pn_port(__u16 handle)
70{
71 return handle & 0x3ff;
72}
73
74static inline __u8 pn_addr(__u16 handle)
75{
76 return (handle >> 8) & 0xfc;
77}
78
79static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
80{
81 spn->spn_dev &= 0x03;
82 spn->spn_dev |= addr & 0xfc;
83}
84
85static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
86{
87 spn->spn_dev &= 0xfc;
88 spn->spn_dev |= (port >> 8) & 0x03;
89 spn->spn_obj = port & 0xff;
90}
91
92static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
93 __u16 handle)
94{
95 spn->spn_dev = pn_dev(handle);
96 spn->spn_obj = pn_obj(handle);
97}
98
99static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
100 __u8 resource)
101{
102 spn->spn_resource = resource;
103}
104
105static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
106{
107 return spn->spn_dev & 0xfc;
108}
109
110static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
111{
112 return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
113}
114
115static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
116{
117 return pn_object(spn->spn_dev, spn->spn_obj);
118}
119
120static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
121{
122 return spn->spn_resource;
123}
124
125#endif