1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * File: af_phonet.h 4 * 5 * Phonet sockets kernel definitions 6 * 7 * Copyright (C) 2008 Nokia Corporation. 8 */ 9 10 #ifndef AF_PHONET_H 11 #define AF_PHONET_H 12 13 /* 14 * The lower layers may not require more space, ever. Make sure it's 15 * enough. 16 */ 17 #define MAX_PHONET_HEADER (8 + MAX_HEADER) 18 19 /* 20 * Every Phonet* socket has this structure first in its 21 * protocol-specific structure under name c. 22 */ 23 struct pn_sock { 24 struct sock sk; 25 u16 sobject; 26 u16 dobject; 27 u8 resource; 28 }; 29 30 static inline struct pn_sock *pn_sk(struct sock *sk) 31 { 32 return (struct pn_sock *)sk; 33 } 34 35 extern const struct proto_ops phonet_dgram_ops; 36 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); 44 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); 49 50 int pn_skb_send(struct sock *sk, struct sk_buff *skb, 51 const struct sockaddr_pn *target); 52 53 static inline struct phonethdr *pn_hdr(struct sk_buff *skb) 54 { 55 return (struct phonethdr *)skb_network_header(skb); 56 } 57 58 static inline struct phonetmsg *pn_msg(struct sk_buff *skb) 59 { 60 return (struct phonetmsg *)skb_transport_header(skb); 61 } 62 63 /* 64 * Get the other party's sockaddr from received skb. The skb begins 65 * with a Phonet header. 66 */ 67 static inline 68 void pn_skb_get_src_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa) 69 { 70 struct phonethdr *ph = pn_hdr(skb); 71 u16 obj = pn_object(ph->pn_sdev, ph->pn_sobj); 72 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)); 77 } 78 79 static inline 80 void pn_skb_get_dst_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa) 81 { 82 struct phonethdr *ph = pn_hdr(skb); 83 u16 obj = pn_object(ph->pn_rdev, ph->pn_robj); 84 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)); 89 } 90 91 /* Protocols in Phonet protocol family. */ 92 struct phonet_protocol { 93 const struct proto_ops *ops; 94 struct proto *prot; 95 int sock_type; 96 }; 97 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); 102 103 int phonet_sysctl_init(void); 104 void phonet_sysctl_exit(void); 105 int isi_register(void); 106 void isi_unregister(void); 107 108 #endif 109