phonet.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. * file phonet.h
  3. *
  4. * Phonet sockets kernel interface
  5. *
  6. * Copyright (C) 2008 Nokia Corporation. All rights reserved.
  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 LINUX_PHONET_H
  23. #define LINUX_PHONET_H
  24. #include <linux/types.h>
  25. /* Automatic protocol selection */
  26. #define PN_PROTO_TRANSPORT 0
  27. /* Phonet datagram socket */
  28. #define PN_PROTO_PHONET 1
  29. /* Phonet pipe */
  30. #define PN_PROTO_PIPE 2
  31. #define PHONET_NPROTO 3
  32. /* Socket options for SOL_PNPIPE level */
  33. #define PNPIPE_ENCAP 1
  34. #define PNPIPE_IFINDEX 2
  35. #define PNADDR_ANY 0
  36. #define PNPORT_RESOURCE_ROUTING 0
  37. /* Values for PNPIPE_ENCAP option */
  38. #define PNPIPE_ENCAP_NONE 0
  39. #define PNPIPE_ENCAP_IP 1
  40. /* ioctls */
  41. #define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0)
  42. /* Phonet protocol header */
  43. struct phonethdr {
  44. __u8 pn_rdev;
  45. __u8 pn_sdev;
  46. __u8 pn_res;
  47. __be16 pn_length;
  48. __u8 pn_robj;
  49. __u8 pn_sobj;
  50. } __attribute__((packed));
  51. /* Common Phonet payload header */
  52. struct phonetmsg {
  53. __u8 pn_trans_id; /* transaction ID */
  54. __u8 pn_msg_id; /* message type */
  55. union {
  56. struct {
  57. __u8 pn_submsg_id; /* message subtype */
  58. __u8 pn_data[5];
  59. } base;
  60. struct {
  61. __u16 pn_e_res_id; /* extended resource ID */
  62. __u8 pn_e_submsg_id; /* message subtype */
  63. __u8 pn_e_data[3];
  64. } ext;
  65. } pn_msg_u;
  66. };
  67. #define PN_COMMON_MESSAGE 0xF0
  68. #define PN_COMMGR 0x10
  69. #define PN_PREFIX 0xE0 /* resource for extended messages */
  70. #define pn_submsg_id pn_msg_u.base.pn_submsg_id
  71. #define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id
  72. #define pn_e_res_id pn_msg_u.ext.pn_e_res_id
  73. #define pn_data pn_msg_u.base.pn_data
  74. #define pn_e_data pn_msg_u.ext.pn_e_data
  75. /* data for unreachable errors */
  76. #define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01
  77. #define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14
  78. #define pn_orig_msg_id pn_data[0]
  79. #define pn_status pn_data[1]
  80. #define pn_e_orig_msg_id pn_e_data[0]
  81. #define pn_e_status pn_e_data[1]
  82. /* Phonet socket address structure */
  83. struct sockaddr_pn {
  84. sa_family_t spn_family;
  85. __u8 spn_obj;
  86. __u8 spn_dev;
  87. __u8 spn_resource;
  88. __u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
  89. } __attribute__ ((packed));
  90. static inline __u16 pn_object(__u8 addr, __u16 port)
  91. {
  92. return (addr << 8) | (port & 0x3ff);
  93. }
  94. static inline __u8 pn_obj(__u16 handle)
  95. {
  96. return handle & 0xff;
  97. }
  98. static inline __u8 pn_dev(__u16 handle)
  99. {
  100. return handle >> 8;
  101. }
  102. static inline __u16 pn_port(__u16 handle)
  103. {
  104. return handle & 0x3ff;
  105. }
  106. static inline __u8 pn_addr(__u16 handle)
  107. {
  108. return (handle >> 8) & 0xfc;
  109. }
  110. static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
  111. {
  112. spn->spn_dev &= 0x03;
  113. spn->spn_dev |= addr & 0xfc;
  114. }
  115. static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
  116. {
  117. spn->spn_dev &= 0xfc;
  118. spn->spn_dev |= (port >> 8) & 0x03;
  119. spn->spn_obj = port & 0xff;
  120. }
  121. static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
  122. __u16 handle)
  123. {
  124. spn->spn_dev = pn_dev(handle);
  125. spn->spn_obj = pn_obj(handle);
  126. }
  127. static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
  128. __u8 resource)
  129. {
  130. spn->spn_resource = resource;
  131. }
  132. static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
  133. {
  134. return spn->spn_dev & 0xfc;
  135. }
  136. static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
  137. {
  138. return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
  139. }
  140. static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
  141. {
  142. return pn_object(spn->spn_dev, spn->spn_obj);
  143. }
  144. static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
  145. {
  146. return spn->spn_resource;
  147. }
  148. /* Phonet device ioctl requests */
  149. #ifdef __KERNEL__
  150. #define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0)
  151. struct if_phonet_autoconf {
  152. uint8_t device;
  153. };
  154. struct if_phonet_req {
  155. char ifr_phonet_name[16];
  156. union {
  157. struct if_phonet_autoconf ifru_phonet_autoconf;
  158. } ifr_ifru;
  159. };
  160. #define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf
  161. #endif /* __KERNEL__ */
  162. #endif