phonet.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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
  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. struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *sa);
  44. void pn_sock_hash(struct sock *sk);
  45. void pn_sock_unhash(struct sock *sk);
  46. int pn_sock_get_port(struct sock *sk, unsigned short sport);
  47. static inline struct phonethdr *pn_hdr(struct sk_buff *skb)
  48. {
  49. return (struct phonethdr *)skb_network_header(skb);
  50. }
  51. /*
  52. * Get the other party's sockaddr from received skb. The skb begins
  53. * with a Phonet header.
  54. */
  55. static inline
  56. void pn_skb_get_src_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)
  57. {
  58. struct phonethdr *ph = pn_hdr(skb);
  59. u16 obj = pn_object(ph->pn_sdev, ph->pn_sobj);
  60. sa->spn_family = AF_PHONET;
  61. pn_sockaddr_set_object(sa, obj);
  62. pn_sockaddr_set_resource(sa, ph->pn_res);
  63. memset(sa->spn_zero, 0, sizeof(sa->spn_zero));
  64. }
  65. static inline
  66. void pn_skb_get_dst_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)
  67. {
  68. struct phonethdr *ph = pn_hdr(skb);
  69. u16 obj = pn_object(ph->pn_rdev, ph->pn_robj);
  70. sa->spn_family = AF_PHONET;
  71. pn_sockaddr_set_object(sa, obj);
  72. pn_sockaddr_set_resource(sa, ph->pn_res);
  73. memset(sa->spn_zero, 0, sizeof(sa->spn_zero));
  74. }
  75. /* Protocols in Phonet protocol family. */
  76. struct phonet_protocol {
  77. const struct proto_ops *ops;
  78. struct proto *prot;
  79. int sock_type;
  80. };
  81. int phonet_proto_register(int protocol, struct phonet_protocol *pp);
  82. void phonet_proto_unregister(int protocol, struct phonet_protocol *pp);
  83. void phonet_netlink_register(void);
  84. #endif