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
30 #define PHONET_NPROTO 2
33 #define PNPORT_RESOURCE_ROUTING 0
35 /* Phonet protocol header */
43 } __attribute__((packed));
45 /* Phonet socket address structure */
47 sa_family_t spn_family;
51 __u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
52 } __attribute__ ((packed));
54 static inline __u16 pn_object(__u8 addr, __u16 port)
56 return (addr << 8) | (port & 0x3ff);
59 static inline __u8 pn_obj(__u16 handle)
64 static inline __u8 pn_dev(__u16 handle)
69 static inline __u16 pn_port(__u16 handle)
71 return handle & 0x3ff;
74 static inline __u8 pn_addr(__u16 handle)
76 return (handle >> 8) & 0xfc;
79 static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
82 spn->spn_dev |= addr & 0xfc;
85 static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
88 spn->spn_dev |= (port >> 8) & 0x03;
89 spn->spn_obj = port & 0xff;
92 static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
95 spn->spn_dev = pn_dev(handle);
96 spn->spn_obj = pn_obj(handle);
99 static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
102 spn->spn_resource = resource;
105 static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
107 return spn->spn_dev & 0xfc;
110 static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
112 return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
115 static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
117 return pn_object(spn->spn_dev, spn->spn_obj);
120 static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
122 return spn->spn_resource;