Remi Denis-Courmont | 4b07b3f | 2008-09-22 20:02:10 -0700 | [diff] [blame] | 1 | /* |
| 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-Courmont | e214a8c | 2008-10-26 23:06:31 -0700 | [diff] [blame] | 30 | #define MAX_PHONET_HEADER (8 + MAX_HEADER) |
Remi Denis-Courmont | 4b07b3f | 2008-09-22 20:02:10 -0700 | [diff] [blame] | 31 | |
Remi Denis-Courmont | ba113a9 | 2008-09-22 20:05:19 -0700 | [diff] [blame] | 32 | /* |
| 33 | * Every Phonet* socket has this structure first in its |
| 34 | * protocol-specific structure under name c. |
| 35 | */ |
| 36 | struct pn_sock { |
| 37 | struct sock sk; |
| 38 | u16 sobject; |
| 39 | u8 resource; |
| 40 | }; |
| 41 | |
| 42 | static inline struct pn_sock *pn_sk(struct sock *sk) |
| 43 | { |
| 44 | return (struct pn_sock *)sk; |
| 45 | } |
| 46 | |
| 47 | extern const struct proto_ops phonet_dgram_ops; |
| 48 | |
Rémi Denis-Courmont | 6b0d07b | 2009-11-09 02:17:01 +0000 | [diff] [blame] | 49 | void pn_sock_init(void); |
Rémi Denis-Courmont | 5240488 | 2008-12-03 15:42:56 -0800 | [diff] [blame] | 50 | struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *sa); |
Rémi Denis-Courmont | f14001f | 2009-10-14 00:48:27 +0000 | [diff] [blame] | 51 | void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb); |
Remi Denis-Courmont | 87ab4e2 | 2008-09-22 20:08:39 -0700 | [diff] [blame] | 52 | void phonet_get_local_port_range(int *min, int *max); |
Remi Denis-Courmont | ba113a9 | 2008-09-22 20:05:19 -0700 | [diff] [blame] | 53 | void pn_sock_hash(struct sock *sk); |
| 54 | void pn_sock_unhash(struct sock *sk); |
| 55 | int pn_sock_get_port(struct sock *sk, unsigned short sport); |
| 56 | |
Remi Denis-Courmont | 107d0d9 | 2008-09-22 20:05:57 -0700 | [diff] [blame] | 57 | int pn_skb_send(struct sock *sk, struct sk_buff *skb, |
| 58 | const struct sockaddr_pn *target); |
| 59 | |
Remi Denis-Courmont | 4b07b3f | 2008-09-22 20:02:10 -0700 | [diff] [blame] | 60 | static inline struct phonethdr *pn_hdr(struct sk_buff *skb) |
| 61 | { |
| 62 | return (struct phonethdr *)skb_network_header(skb); |
| 63 | } |
| 64 | |
Remi Denis-Courmont | be0c52b | 2008-09-22 20:09:13 -0700 | [diff] [blame] | 65 | static inline struct phonetmsg *pn_msg(struct sk_buff *skb) |
| 66 | { |
| 67 | return (struct phonetmsg *)skb_transport_header(skb); |
| 68 | } |
| 69 | |
Remi Denis-Courmont | 4b07b3f | 2008-09-22 20:02:10 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Get the other party's sockaddr from received skb. The skb begins |
| 72 | * with a Phonet header. |
| 73 | */ |
| 74 | static inline |
| 75 | void pn_skb_get_src_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa) |
| 76 | { |
| 77 | struct phonethdr *ph = pn_hdr(skb); |
| 78 | u16 obj = pn_object(ph->pn_sdev, ph->pn_sobj); |
| 79 | |
| 80 | sa->spn_family = AF_PHONET; |
| 81 | pn_sockaddr_set_object(sa, obj); |
| 82 | pn_sockaddr_set_resource(sa, ph->pn_res); |
| 83 | memset(sa->spn_zero, 0, sizeof(sa->spn_zero)); |
| 84 | } |
| 85 | |
| 86 | static inline |
| 87 | void pn_skb_get_dst_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa) |
| 88 | { |
| 89 | struct phonethdr *ph = pn_hdr(skb); |
| 90 | u16 obj = pn_object(ph->pn_rdev, ph->pn_robj); |
| 91 | |
| 92 | sa->spn_family = AF_PHONET; |
| 93 | pn_sockaddr_set_object(sa, obj); |
| 94 | pn_sockaddr_set_resource(sa, ph->pn_res); |
| 95 | memset(sa->spn_zero, 0, sizeof(sa->spn_zero)); |
| 96 | } |
| 97 | |
| 98 | /* Protocols in Phonet protocol family. */ |
| 99 | struct phonet_protocol { |
Remi Denis-Courmont | ba113a9 | 2008-09-22 20:05:19 -0700 | [diff] [blame] | 100 | const struct proto_ops *ops; |
Remi Denis-Courmont | 4b07b3f | 2008-09-22 20:02:10 -0700 | [diff] [blame] | 101 | struct proto *prot; |
| 102 | int sock_type; |
| 103 | }; |
| 104 | |
| 105 | int phonet_proto_register(int protocol, struct phonet_protocol *pp); |
| 106 | void phonet_proto_unregister(int protocol, struct phonet_protocol *pp); |
| 107 | |
Remi Denis-Courmont | 87ab4e2 | 2008-09-22 20:08:39 -0700 | [diff] [blame] | 108 | int phonet_sysctl_init(void); |
| 109 | void phonet_sysctl_exit(void); |
Remi Denis-Courmont | 107d0d9 | 2008-09-22 20:05:57 -0700 | [diff] [blame] | 110 | int isi_register(void); |
| 111 | void isi_unregister(void); |
| 112 | |
Remi Denis-Courmont | 4b07b3f | 2008-09-22 20:02:10 -0700 | [diff] [blame] | 113 | #endif |