1 /* SPDX-License-Identifier: GPL-2.0-only */
5 * Phonet sockets kernel definitions
7 * Copyright (C) 2008 Nokia Corporation.
14 * The lower layers may not require more space, ever. Make sure it's
17 #define MAX_PHONET_HEADER (8 + MAX_HEADER)
20 * Every Phonet* socket has this structure first in its
21 * protocol-specific structure under name c.
30 static inline struct pn_sock
*pn_sk(struct sock
*sk
)
32 return (struct pn_sock
*)sk
;
35 extern const struct proto_ops phonet_dgram_ops
;
37 void pn_sock_init(void);
38 struct sock
*pn_find_sock_by_sa(struct net
*net
, const struct sockaddr_pn
*sa
);
39 void pn_deliver_sock_broadcast(struct net
*net
, struct sk_buff
*skb
);
40 void phonet_get_local_port_range(int *min
, int *max
);
41 int pn_sock_hash(struct sock
*sk
);
42 void pn_sock_unhash(struct sock
*sk
);
43 int pn_sock_get_port(struct sock
*sk
, unsigned short sport
);
45 struct sock
*pn_find_sock_by_res(struct net
*net
, u8 res
);
46 int pn_sock_bind_res(struct sock
*sock
, u8 res
);
47 int pn_sock_unbind_res(struct sock
*sk
, u8 res
);
48 void pn_sock_unbind_all_res(struct sock
*sk
);
50 int pn_skb_send(struct sock
*sk
, struct sk_buff
*skb
,
51 const struct sockaddr_pn
*target
);
53 static inline struct phonethdr
*pn_hdr(struct sk_buff
*skb
)
55 return (struct phonethdr
*)skb_network_header(skb
);
58 static inline struct phonetmsg
*pn_msg(struct sk_buff
*skb
)
60 return (struct phonetmsg
*)skb_transport_header(skb
);
64 * Get the other party's sockaddr from received skb. The skb begins
65 * with a Phonet header.
68 void pn_skb_get_src_sockaddr(struct sk_buff
*skb
, struct sockaddr_pn
*sa
)
70 struct phonethdr
*ph
= pn_hdr(skb
);
71 u16 obj
= pn_object(ph
->pn_sdev
, ph
->pn_sobj
);
73 sa
->spn_family
= AF_PHONET
;
74 pn_sockaddr_set_object(sa
, obj
);
75 pn_sockaddr_set_resource(sa
, ph
->pn_res
);
76 memset(sa
->spn_zero
, 0, sizeof(sa
->spn_zero
));
80 void pn_skb_get_dst_sockaddr(struct sk_buff
*skb
, struct sockaddr_pn
*sa
)
82 struct phonethdr
*ph
= pn_hdr(skb
);
83 u16 obj
= pn_object(ph
->pn_rdev
, ph
->pn_robj
);
85 sa
->spn_family
= AF_PHONET
;
86 pn_sockaddr_set_object(sa
, obj
);
87 pn_sockaddr_set_resource(sa
, ph
->pn_res
);
88 memset(sa
->spn_zero
, 0, sizeof(sa
->spn_zero
));
91 /* Protocols in Phonet protocol family. */
92 struct phonet_protocol
{
93 const struct proto_ops
*ops
;
98 int phonet_proto_register(unsigned int protocol
,
99 const struct phonet_protocol
*pp
);
100 void phonet_proto_unregister(unsigned int protocol
,
101 const struct phonet_protocol
*pp
);
103 int phonet_sysctl_init(void);
104 void phonet_sysctl_exit(void);
105 int isi_register(void);
106 void isi_unregister(void);