phonet.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #ifndef AF_PHONET_H
  23. #define AF_PHONET_H
  24. /*
  25. * The lower layers may not require more space, ever. Make sure it's
  26. * enough.
  27. */
  28. #define MAX_PHONET_HEADER (8 + MAX_HEADER)
  29. /*
  30. * Every Phonet* socket has this structure first in its
  31. * protocol-specific structure under name c.
  32. */
  33. struct pn_sock {
  34. struct sock sk;
  35. u16 sobject;
  36. u8 resource;
  37. };
  38. static inline struct pn_sock *pn_sk(struct sock *sk)
  39. {
  40. return (struct pn_sock *)sk;
  41. }
  42. extern const struct proto_ops phonet_dgram_ops;
  43. void pn_sock_init(void);
  44. struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *sa);
  45. void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb);
  46. void phonet_get_local_port_range(int *min, int *max);
  47. void pn_sock_hash(struct sock *sk);
  48. void pn_sock_unhash(struct sock *sk);
  49. int pn_sock_get_port(struct sock *sk, unsigned short sport);
  50. struct sock *pn_find_sock_by_res(struct net *net, u8 res);
  51. int pn_sock_bind_res(struct sock *sock, u8 res);
  52. int pn_sock_unbind_res(struct sock *sk, u8 res);
  53. 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);
  56. static inline struct phonethdr *pn_hdr(struct sk_buff *skb)
  57. {
  58. return (struct phonethdr *)skb_network_header(skb);
  59. }
  60. static inline struct phonetmsg *pn_msg(struct sk_buff *skb)
  61. {
  62. return (struct phonetmsg *)skb_transport_header(skb);
  63. }
  64. /*
  65. * Get the other party's sockaddr from received skb. The skb begins
  66. * with a Phonet header.
  67. */
  68. static inline
  69. void pn_skb_get_src_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)
  70. {
  71. struct phonethdr *ph = pn_hdr(skb);
  72. 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));
  77. }
  78. static inline
  79. void pn_skb_get_dst_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)
  80. {
  81. struct phonethdr *ph = pn_hdr(skb);
  82. u16 obj = pn_object(ph->pn_rdev, ph->pn_robj);
  83. sa->spn_family = AF_PHONET;
  84. pn_sockaddr_set_object(sa, obj);
  85. pn_sockaddr_set_resource(sa, ph->pn_res);
  86. memset(sa->spn_zero, 0, sizeof(sa->spn_zero));
  87. }
  88. /* Protocols in Phonet protocol family. */
  89. struct phonet_protocol {
  90. const struct proto_ops *ops;
  91. struct proto *prot;
  92. int sock_type;
  93. };
  94. int phonet_proto_register(unsigned int protocol, struct phonet_protocol *pp);
  95. void phonet_proto_unregister(unsigned int protocol, struct phonet_protocol *pp);
  96. int phonet_sysctl_init(void);
  97. void phonet_sysctl_exit(void);
  98. int isi_register(void);
  99. void isi_unregister(void);
  100. #endif