phonet.h 4.5 KB

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