^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * File: af_phonet.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Phonet sockets kernel definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2008 Nokia Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef AF_PHONET_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define AF_PHONET_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * The lower layers may not require more space, ever. Make sure it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define MAX_PHONET_HEADER (8 + MAX_HEADER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Every Phonet* socket has this structure first in its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * protocol-specific structure under name c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct pn_sock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct sock sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) u16 sobject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u16 dobject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) u8 resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static inline struct pn_sock *pn_sk(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return (struct pn_sock *)sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) extern const struct proto_ops phonet_dgram_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) void pn_sock_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) void phonet_get_local_port_range(int *min, int *max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int pn_sock_hash(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) void pn_sock_unhash(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int pn_sock_get_port(struct sock *sk, unsigned short sport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct sock *pn_find_sock_by_res(struct net *net, u8 res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int pn_sock_bind_res(struct sock *sock, u8 res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int pn_sock_unbind_res(struct sock *sk, u8 res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) void pn_sock_unbind_all_res(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int pn_skb_send(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) const struct sockaddr_pn *target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static inline struct phonethdr *pn_hdr(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return (struct phonethdr *)skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static inline struct phonetmsg *pn_msg(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return (struct phonetmsg *)skb_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * Get the other party's sockaddr from received skb. The skb begins
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * with a Phonet header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) void pn_skb_get_src_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct phonethdr *ph = pn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u16 obj = pn_object(ph->pn_sdev, ph->pn_sobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) sa->spn_family = AF_PHONET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) pn_sockaddr_set_object(sa, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) pn_sockaddr_set_resource(sa, ph->pn_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) memset(sa->spn_zero, 0, sizeof(sa->spn_zero));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) void pn_skb_get_dst_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct phonethdr *ph = pn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u16 obj = pn_object(ph->pn_rdev, ph->pn_robj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) sa->spn_family = AF_PHONET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) pn_sockaddr_set_object(sa, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) pn_sockaddr_set_resource(sa, ph->pn_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) memset(sa->spn_zero, 0, sizeof(sa->spn_zero));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* Protocols in Phonet protocol family. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct phonet_protocol {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) const struct proto_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct proto *prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int sock_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int phonet_proto_register(unsigned int protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) const struct phonet_protocol *pp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void phonet_proto_unregister(unsigned int protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) const struct phonet_protocol *pp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int phonet_sysctl_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) void phonet_sysctl_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int isi_register(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void isi_unregister(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #endif