blob: 68e509750caa4cb60d54b48d62cb23cf109dd17d [file] [log] [blame]
Remi Denis-Courmont4b07b3f2008-09-22 20:02:10 -07001/*
2 * File: af_phonet.h
3 *
4 * Phonet sockets kernel definitions
5 *
6 * Copyright (C) 2008 Nokia Corporation.
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 AF_PHONET_H
24#define AF_PHONET_H
25
26/*
27 * The lower layers may not require more space, ever. Make sure it's
28 * enough.
29 */
Remi Denis-Courmonte214a8c2008-10-26 23:06:31 -070030#define MAX_PHONET_HEADER (8 + MAX_HEADER)
Remi Denis-Courmont4b07b3f2008-09-22 20:02:10 -070031
Remi Denis-Courmontba113a92008-09-22 20:05:19 -070032/*
33 * Every Phonet* socket has this structure first in its
34 * protocol-specific structure under name c.
35 */
36struct pn_sock {
37 struct sock sk;
38 u16 sobject;
Rémi Denis-Courmonta8059512011-02-24 23:14:57 +000039 u16 dobject;
Remi Denis-Courmontba113a92008-09-22 20:05:19 -070040 u8 resource;
41};
42
43static inline struct pn_sock *pn_sk(struct sock *sk)
44{
45 return (struct pn_sock *)sk;
46}
47
48extern const struct proto_ops phonet_dgram_ops;
49
Rémi Denis-Courmont6b0d07b2009-11-09 02:17:01 +000050void pn_sock_init(void);
Rémi Denis-Courmont52404882008-12-03 15:42:56 -080051struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *sa);
Rémi Denis-Courmontf14001f2009-10-14 00:48:27 +000052void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb);
Remi Denis-Courmont87ab4e22008-09-22 20:08:39 -070053void phonet_get_local_port_range(int *min, int *max);
Remi Denis-Courmontba113a92008-09-22 20:05:19 -070054void pn_sock_hash(struct sock *sk);
55void pn_sock_unhash(struct sock *sk);
56int pn_sock_get_port(struct sock *sk, unsigned short sport);
57
Rémi Denis-Courmont4e3d16c2010-09-15 12:30:11 +000058struct sock *pn_find_sock_by_res(struct net *net, u8 res);
59int pn_sock_bind_res(struct sock *sock, u8 res);
60int pn_sock_unbind_res(struct sock *sk, u8 res);
61void pn_sock_unbind_all_res(struct sock *sk);
62
Remi Denis-Courmont107d0d92008-09-22 20:05:57 -070063int pn_skb_send(struct sock *sk, struct sk_buff *skb,
64 const struct sockaddr_pn *target);
65
Remi Denis-Courmont4b07b3f2008-09-22 20:02:10 -070066static inline struct phonethdr *pn_hdr(struct sk_buff *skb)
67{
68 return (struct phonethdr *)skb_network_header(skb);
69}
70
Remi Denis-Courmontbe0c52b2008-09-22 20:09:13 -070071static inline struct phonetmsg *pn_msg(struct sk_buff *skb)
72{
73 return (struct phonetmsg *)skb_transport_header(skb);
74}
75
Remi Denis-Courmont4b07b3f2008-09-22 20:02:10 -070076/*
77 * Get the other party's sockaddr from received skb. The skb begins
78 * with a Phonet header.
79 */
80static inline
81void pn_skb_get_src_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)
82{
83 struct phonethdr *ph = pn_hdr(skb);
84 u16 obj = pn_object(ph->pn_sdev, ph->pn_sobj);
85
86 sa->spn_family = AF_PHONET;
87 pn_sockaddr_set_object(sa, obj);
88 pn_sockaddr_set_resource(sa, ph->pn_res);
89 memset(sa->spn_zero, 0, sizeof(sa->spn_zero));
90}
91
92static inline
93void pn_skb_get_dst_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)
94{
95 struct phonethdr *ph = pn_hdr(skb);
96 u16 obj = pn_object(ph->pn_rdev, ph->pn_robj);
97
98 sa->spn_family = AF_PHONET;
99 pn_sockaddr_set_object(sa, obj);
100 pn_sockaddr_set_resource(sa, ph->pn_res);
101 memset(sa->spn_zero, 0, sizeof(sa->spn_zero));
102}
103
104/* Protocols in Phonet protocol family. */
105struct phonet_protocol {
Remi Denis-Courmontba113a92008-09-22 20:05:19 -0700106 const struct proto_ops *ops;
Remi Denis-Courmont4b07b3f2008-09-22 20:02:10 -0700107 struct proto *prot;
108 int sock_type;
109};
110
Dan Carpenterfacb4ed2011-01-10 04:06:58 +0000111int phonet_proto_register(unsigned int protocol, struct phonet_protocol *pp);
112void phonet_proto_unregister(unsigned int protocol, struct phonet_protocol *pp);
Remi Denis-Courmont4b07b3f2008-09-22 20:02:10 -0700113
Remi Denis-Courmont87ab4e22008-09-22 20:08:39 -0700114int phonet_sysctl_init(void);
115void phonet_sysctl_exit(void);
Remi Denis-Courmont107d0d92008-09-22 20:05:57 -0700116int isi_register(void);
117void isi_unregister(void);
118
Remi Denis-Courmont4b07b3f2008-09-22 20:02:10 -0700119#endif