phonet.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. /* Well known address */
  91. #define PN_DEV_PC 0x10
  92. static inline __u16 pn_object(__u8 addr, __u16 port)
  93. {
  94. return (addr << 8) | (port & 0x3ff);
  95. }
  96. static inline __u8 pn_obj(__u16 handle)
  97. {
  98. return handle & 0xff;
  99. }
  100. static inline __u8 pn_dev(__u16 handle)
  101. {
  102. return handle >> 8;
  103. }
  104. static inline __u16 pn_port(__u16 handle)
  105. {
  106. return handle & 0x3ff;
  107. }
  108. static inline __u8 pn_addr(__u16 handle)
  109. {
  110. return (handle >> 8) & 0xfc;
  111. }
  112. static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
  113. {
  114. spn->spn_dev &= 0x03;
  115. spn->spn_dev |= addr & 0xfc;
  116. }
  117. static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
  118. {
  119. spn->spn_dev &= 0xfc;
  120. spn->spn_dev |= (port >> 8) & 0x03;
  121. spn->spn_obj = port & 0xff;
  122. }
  123. static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
  124. __u16 handle)
  125. {
  126. spn->spn_dev = pn_dev(handle);
  127. spn->spn_obj = pn_obj(handle);
  128. }
  129. static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
  130. __u8 resource)
  131. {
  132. spn->spn_resource = resource;
  133. }
  134. static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
  135. {
  136. return spn->spn_dev & 0xfc;
  137. }
  138. static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
  139. {
  140. return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
  141. }
  142. static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
  143. {
  144. return pn_object(spn->spn_dev, spn->spn_obj);
  145. }
  146. static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
  147. {
  148. return spn->spn_resource;
  149. }
  150. /* Phonet device ioctl requests */
  151. #ifdef __KERNEL__
  152. #define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0)
  153. struct if_phonet_autoconf {
  154. uint8_t device;
  155. };
  156. struct if_phonet_req {
  157. char ifr_phonet_name[16];
  158. union {
  159. struct if_phonet_autoconf ifru_phonet_autoconf;
  160. } ifr_ifru;
  161. };
  162. #define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf
  163. #endif /* __KERNEL__ */
  164. #endif