1 /* SPDX-License-Identifier: GPL-2.0-only */
5 * Phonet sockets kernel definitions
7 * Copyright (C) 2008 Nokia Corporation.
13 #include <linux/phonet.h>
14 #include <linux/skbuff.h>
18 * The lower layers may not require more space, ever. Make sure it's
21 #define MAX_PHONET_HEADER (8 + MAX_HEADER)
24 * Every Phonet* socket has this structure first in its
25 * protocol-specific structure under name c.
34 static inline struct pn_sock
*pn_sk(struct sock
*sk
)
36 return (struct pn_sock
*)sk
;
39 extern const struct proto_ops phonet_dgram_ops
;
41 void pn_sock_init(void);
42 struct sock
*pn_find_sock_by_sa(struct net
*net
, const struct sockaddr_pn
*sa
);
43 void pn_deliver_sock_broadcast(struct net
*net
, struct sk_buff
*skb
);
44 void phonet_get_local_port_range(int *min
, int *max
);
45 int pn_sock_hash(struct sock
*sk
);
46 void pn_sock_unhash(struct sock
*sk
);
47 int pn_sock_get_port(struct sock
*sk
, unsigned short sport
);
49 struct sock
*pn_find_sock_by_res(struct net
*net
, u8 res
);
50 int pn_sock_bind_res(struct sock
*sock
, u8 res
);
51 int pn_sock_unbind_res(struct sock
*sk
, u8 res
);
52 void pn_sock_unbind_all_res(struct sock
*sk
);
54 int pn_skb_send(struct sock
*sk
, struct sk_buff
*skb
,
55 const struct sockaddr_pn
*target
);
57 static inline struct phonethdr
*pn_hdr(struct sk_buff
*skb
)
59 return (struct phonethdr
*)skb_network_header(skb
);
62 static inline struct phonetmsg
*pn_msg(struct sk_buff
*skb
)
64 return (struct phonetmsg
*)skb_transport_header(skb
);
68 * Get the other party's sockaddr from received skb. The skb begins
69 * with a Phonet header.
72 void pn_skb_get_src_sockaddr(struct sk_buff
*skb
, struct sockaddr_pn
*sa
)
74 struct phonethdr
*ph
= pn_hdr(skb
);
75 u16 obj
= pn_object(ph
->pn_sdev
, ph
->pn_sobj
);
77 sa
->spn_family
= AF_PHONET
;
78 pn_sockaddr_set_object(sa
, obj
);
79 pn_sockaddr_set_resource(sa
, ph
->pn_res
);
80 memset(sa
->spn_zero
, 0, sizeof(sa
->spn_zero
));
84 void pn_skb_get_dst_sockaddr(struct sk_buff
*skb
, struct sockaddr_pn
*sa
)
86 struct phonethdr
*ph
= pn_hdr(skb
);
87 u16 obj
= pn_object(ph
->pn_rdev
, ph
->pn_robj
);
89 sa
->spn_family
= AF_PHONET
;
90 pn_sockaddr_set_object(sa
, obj
);
91 pn_sockaddr_set_resource(sa
, ph
->pn_res
);
92 memset(sa
->spn_zero
, 0, sizeof(sa
->spn_zero
));
95 /* Protocols in Phonet protocol family. */
96 struct phonet_protocol
{
97 const struct proto_ops
*ops
;
102 int phonet_proto_register(unsigned int protocol
,
103 const struct phonet_protocol
*pp
);
104 void phonet_proto_unregister(unsigned int protocol
,
105 const struct phonet_protocol
*pp
);
107 int phonet_sysctl_init(void);
108 void phonet_sysctl_exit(void);
109 int isi_register(void);
110 void isi_unregister(void);
112 static inline bool sk_is_phonet(struct sock
*sk
)
114 return sk
->sk_family
== PF_PHONET
;
117 static inline int phonet_sk_ioctl(struct sock
*sk
, unsigned int cmd
,
123 case SIOCPNADDRESOURCE
:
124 case SIOCPNDELRESOURCE
:
125 if (get_user(karg
, (int __user
*)arg
))
128 return sk
->sk_prot
->ioctl(sk
, cmd
, &karg
);
130 /* A positive return value means that the ioctl was not processed */