Commit | Line | Data |
---|---|---|
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 | ||
ba113a94 RDC |
35 | /* ioctls */ |
36 | #define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0) | |
37 | ||
bce7b154 RDC |
38 | /* Phonet protocol header */ |
39 | struct phonethdr { | |
40 | __u8 pn_rdev; | |
41 | __u8 pn_sdev; | |
42 | __u8 pn_res; | |
43 | __be16 pn_length; | |
44 | __u8 pn_robj; | |
45 | __u8 pn_sobj; | |
46 | } __attribute__((packed)); | |
47 | ||
48 | /* Phonet socket address structure */ | |
49 | struct sockaddr_pn { | |
50 | sa_family_t spn_family; | |
51 | __u8 spn_obj; | |
52 | __u8 spn_dev; | |
53 | __u8 spn_resource; | |
54 | __u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3]; | |
55 | } __attribute__ ((packed)); | |
56 | ||
57 | static inline __u16 pn_object(__u8 addr, __u16 port) | |
58 | { | |
59 | return (addr << 8) | (port & 0x3ff); | |
60 | } | |
61 | ||
62 | static inline __u8 pn_obj(__u16 handle) | |
63 | { | |
64 | return handle & 0xff; | |
65 | } | |
66 | ||
67 | static inline __u8 pn_dev(__u16 handle) | |
68 | { | |
69 | return handle >> 8; | |
70 | } | |
71 | ||
72 | static inline __u16 pn_port(__u16 handle) | |
73 | { | |
74 | return handle & 0x3ff; | |
75 | } | |
76 | ||
77 | static inline __u8 pn_addr(__u16 handle) | |
78 | { | |
79 | return (handle >> 8) & 0xfc; | |
80 | } | |
81 | ||
82 | static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr) | |
83 | { | |
84 | spn->spn_dev &= 0x03; | |
85 | spn->spn_dev |= addr & 0xfc; | |
86 | } | |
87 | ||
88 | static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port) | |
89 | { | |
90 | spn->spn_dev &= 0xfc; | |
91 | spn->spn_dev |= (port >> 8) & 0x03; | |
92 | spn->spn_obj = port & 0xff; | |
93 | } | |
94 | ||
95 | static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn, | |
96 | __u16 handle) | |
97 | { | |
98 | spn->spn_dev = pn_dev(handle); | |
99 | spn->spn_obj = pn_obj(handle); | |
100 | } | |
101 | ||
102 | static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn, | |
103 | __u8 resource) | |
104 | { | |
105 | spn->spn_resource = resource; | |
106 | } | |
107 | ||
108 | static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn) | |
109 | { | |
110 | return spn->spn_dev & 0xfc; | |
111 | } | |
112 | ||
113 | static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn) | |
114 | { | |
115 | return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj; | |
116 | } | |
117 | ||
118 | static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn) | |
119 | { | |
120 | return pn_object(spn->spn_dev, spn->spn_obj); | |
121 | } | |
122 | ||
123 | static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn) | |
124 | { | |
125 | return spn->spn_resource; | |
126 | } | |
127 | ||
128 | #endif |