diff options
author | Remi Denis-Courmont <remi.denis-courmont@nokia.com> | 2008-09-22 22:51:15 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-09-22 22:51:15 -0400 |
commit | bce7b15426cac3000bf6a9cf59d9356ef0be2dec (patch) | |
tree | ddee913be01db33130fa4a02a27c7a82c5d6ab26 /include/linux/phonet.h | |
parent | 5c1824587f0797373c95719a196f6098f7c6d20c (diff) |
Phonet: global definitions
Signed-off-by: Remi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/phonet.h')
-rw-r--r-- | include/linux/phonet.h | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/include/linux/phonet.h b/include/linux/phonet.h new file mode 100644 index 000000000000..6a764f8584a4 --- /dev/null +++ b/include/linux/phonet.h | |||
@@ -0,0 +1,125 @@ | |||
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 */ | ||
36 | struct 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 */ | ||
46 | struct 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 | |||
54 | static inline __u16 pn_object(__u8 addr, __u16 port) | ||
55 | { | ||
56 | return (addr << 8) | (port & 0x3ff); | ||
57 | } | ||
58 | |||
59 | static inline __u8 pn_obj(__u16 handle) | ||
60 | { | ||
61 | return handle & 0xff; | ||
62 | } | ||
63 | |||
64 | static inline __u8 pn_dev(__u16 handle) | ||
65 | { | ||
66 | return handle >> 8; | ||
67 | } | ||
68 | |||
69 | static inline __u16 pn_port(__u16 handle) | ||
70 | { | ||
71 | return handle & 0x3ff; | ||
72 | } | ||
73 | |||
74 | static inline __u8 pn_addr(__u16 handle) | ||
75 | { | ||
76 | return (handle >> 8) & 0xfc; | ||
77 | } | ||
78 | |||
79 | static 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 | |||
85 | static 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 | |||
92 | static 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 | |||
99 | static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn, | ||
100 | __u8 resource) | ||
101 | { | ||
102 | spn->spn_resource = resource; | ||
103 | } | ||
104 | |||
105 | static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn) | ||
106 | { | ||
107 | return spn->spn_dev & 0xfc; | ||
108 | } | ||
109 | |||
110 | static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn) | ||
111 | { | ||
112 | return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj; | ||
113 | } | ||
114 | |||
115 | static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn) | ||
116 | { | ||
117 | return pn_object(spn->spn_dev, spn->spn_obj); | ||
118 | } | ||
119 | |||
120 | static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn) | ||
121 | { | ||
122 | return spn->spn_resource; | ||
123 | } | ||
124 | |||
125 | #endif | ||