Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 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 | |
| 23 | #ifndef LINUX_PHONET_H |
| 24 | #define LINUX_PHONET_H |
| 25 | |
Jaswinder Singh Rajput | 06f43ad | 2009-01-30 22:03:25 +0530 | [diff] [blame] | 26 | #include <linux/types.h> |
Ben Hutchings | bcb949b | 2011-08-24 18:43:55 +0000 | [diff] [blame] | 27 | #include <linux/socket.h> |
Jaswinder Singh Rajput | 06f43ad | 2009-01-30 22:03:25 +0530 | [diff] [blame] | 28 | |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 29 | /* Automatic protocol selection */ |
| 30 | #define PN_PROTO_TRANSPORT 0 |
| 31 | /* Phonet datagram socket */ |
| 32 | #define PN_PROTO_PHONET 1 |
Rémi Denis-Courmont | 9641458 | 2008-10-05 11:15:13 -0700 | [diff] [blame] | 33 | /* Phonet pipe */ |
| 34 | #define PN_PROTO_PIPE 2 |
| 35 | #define PHONET_NPROTO 3 |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 36 | |
Rémi Denis-Courmont | 02a4761 | 2008-10-05 11:16:16 -0700 | [diff] [blame] | 37 | /* Socket options for SOL_PNPIPE level */ |
| 38 | #define PNPIPE_ENCAP 1 |
| 39 | #define PNPIPE_IFINDEX 2 |
Rémi Denis-Courmont | acaf7df | 2011-03-08 22:44:11 +0000 | [diff] [blame] | 40 | #define PNPIPE_HANDLE 3 |
Dinesh Kumar Sharma | bdb6e69 | 2011-11-18 01:22:05 +0000 | [diff] [blame] | 41 | #define PNPIPE_INITSTATE 4 |
Rémi Denis-Courmont | 02a4761 | 2008-10-05 11:16:16 -0700 | [diff] [blame] | 42 | |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 43 | #define PNADDR_ANY 0 |
Rémi Denis-Courmont | 18a1166 | 2009-09-23 03:17:11 +0000 | [diff] [blame] | 44 | #define PNADDR_BROADCAST 0xFC |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 45 | #define PNPORT_RESOURCE_ROUTING 0 |
| 46 | |
Rémi Denis-Courmont | 02a4761 | 2008-10-05 11:16:16 -0700 | [diff] [blame] | 47 | /* Values for PNPIPE_ENCAP option */ |
| 48 | #define PNPIPE_ENCAP_NONE 0 |
| 49 | #define PNPIPE_ENCAP_IP 1 |
| 50 | |
Remi Denis-Courmont | ba113a9 | 2008-09-22 20:05:19 -0700 | [diff] [blame] | 51 | /* ioctls */ |
| 52 | #define SIOCPNGETOBJECT (SIOCPROTOPRIVATE + 0) |
Dinesh Kumar Sharma | bdb6e69 | 2011-11-18 01:22:05 +0000 | [diff] [blame] | 53 | #define SIOCPNENABLEPIPE (SIOCPROTOPRIVATE + 13) |
Rémi Denis-Courmont | 7417fa8 | 2010-09-15 12:30:12 +0000 | [diff] [blame] | 54 | #define SIOCPNADDRESOURCE (SIOCPROTOPRIVATE + 14) |
| 55 | #define SIOCPNDELRESOURCE (SIOCPROTOPRIVATE + 15) |
Remi Denis-Courmont | ba113a9 | 2008-09-22 20:05:19 -0700 | [diff] [blame] | 56 | |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 57 | /* Phonet protocol header */ |
| 58 | struct phonethdr { |
| 59 | __u8 pn_rdev; |
| 60 | __u8 pn_sdev; |
| 61 | __u8 pn_res; |
| 62 | __be16 pn_length; |
| 63 | __u8 pn_robj; |
| 64 | __u8 pn_sobj; |
Changli Gao | 09cd2b9 | 2010-08-22 17:25:05 +0000 | [diff] [blame] | 65 | } __attribute__((packed)); |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 66 | |
Remi Denis-Courmont | be0c52b | 2008-09-22 20:09:13 -0700 | [diff] [blame] | 67 | /* Common Phonet payload header */ |
| 68 | struct phonetmsg { |
| 69 | __u8 pn_trans_id; /* transaction ID */ |
| 70 | __u8 pn_msg_id; /* message type */ |
| 71 | union { |
| 72 | struct { |
| 73 | __u8 pn_submsg_id; /* message subtype */ |
| 74 | __u8 pn_data[5]; |
| 75 | } base; |
| 76 | struct { |
| 77 | __u16 pn_e_res_id; /* extended resource ID */ |
| 78 | __u8 pn_e_submsg_id; /* message subtype */ |
| 79 | __u8 pn_e_data[3]; |
| 80 | } ext; |
| 81 | } pn_msg_u; |
| 82 | }; |
| 83 | #define PN_COMMON_MESSAGE 0xF0 |
Remi Denis-Courmont | c3a90c7 | 2008-10-26 23:07:25 -0700 | [diff] [blame] | 84 | #define PN_COMMGR 0x10 |
Remi Denis-Courmont | be0c52b | 2008-09-22 20:09:13 -0700 | [diff] [blame] | 85 | #define PN_PREFIX 0xE0 /* resource for extended messages */ |
| 86 | #define pn_submsg_id pn_msg_u.base.pn_submsg_id |
| 87 | #define pn_e_submsg_id pn_msg_u.ext.pn_e_submsg_id |
| 88 | #define pn_e_res_id pn_msg_u.ext.pn_e_res_id |
| 89 | #define pn_data pn_msg_u.base.pn_data |
| 90 | #define pn_e_data pn_msg_u.ext.pn_e_data |
| 91 | |
| 92 | /* data for unreachable errors */ |
| 93 | #define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 0x01 |
| 94 | #define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 0x14 |
| 95 | #define pn_orig_msg_id pn_data[0] |
| 96 | #define pn_status pn_data[1] |
| 97 | #define pn_e_orig_msg_id pn_e_data[0] |
| 98 | #define pn_e_status pn_e_data[1] |
| 99 | |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 100 | /* Phonet socket address structure */ |
| 101 | struct sockaddr_pn { |
Ben Hutchings | bcb949b | 2011-08-24 18:43:55 +0000 | [diff] [blame] | 102 | __kernel_sa_family_t spn_family; |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 103 | __u8 spn_obj; |
| 104 | __u8 spn_dev; |
| 105 | __u8 spn_resource; |
Ben Hutchings | bcb949b | 2011-08-24 18:43:55 +0000 | [diff] [blame] | 106 | __u8 spn_zero[sizeof(struct sockaddr) - sizeof(__kernel_sa_family_t) - 3]; |
Changli Gao | 09cd2b9 | 2010-08-22 17:25:05 +0000 | [diff] [blame] | 107 | } __attribute__((packed)); |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 108 | |
Rémi Denis-Courmont | 02571f8 | 2009-09-09 00:00:06 +0000 | [diff] [blame] | 109 | /* Well known address */ |
| 110 | #define PN_DEV_PC 0x10 |
| 111 | |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 112 | static inline __u16 pn_object(__u8 addr, __u16 port) |
| 113 | { |
| 114 | return (addr << 8) | (port & 0x3ff); |
| 115 | } |
| 116 | |
| 117 | static inline __u8 pn_obj(__u16 handle) |
| 118 | { |
| 119 | return handle & 0xff; |
| 120 | } |
| 121 | |
| 122 | static inline __u8 pn_dev(__u16 handle) |
| 123 | { |
| 124 | return handle >> 8; |
| 125 | } |
| 126 | |
| 127 | static inline __u16 pn_port(__u16 handle) |
| 128 | { |
| 129 | return handle & 0x3ff; |
| 130 | } |
| 131 | |
| 132 | static inline __u8 pn_addr(__u16 handle) |
| 133 | { |
| 134 | return (handle >> 8) & 0xfc; |
| 135 | } |
| 136 | |
| 137 | static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr) |
| 138 | { |
| 139 | spn->spn_dev &= 0x03; |
| 140 | spn->spn_dev |= addr & 0xfc; |
| 141 | } |
| 142 | |
| 143 | static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port) |
| 144 | { |
| 145 | spn->spn_dev &= 0xfc; |
| 146 | spn->spn_dev |= (port >> 8) & 0x03; |
| 147 | spn->spn_obj = port & 0xff; |
| 148 | } |
| 149 | |
| 150 | static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn, |
| 151 | __u16 handle) |
| 152 | { |
| 153 | spn->spn_dev = pn_dev(handle); |
| 154 | spn->spn_obj = pn_obj(handle); |
| 155 | } |
| 156 | |
| 157 | static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn, |
| 158 | __u8 resource) |
| 159 | { |
| 160 | spn->spn_resource = resource; |
| 161 | } |
| 162 | |
| 163 | static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn) |
| 164 | { |
| 165 | return spn->spn_dev & 0xfc; |
| 166 | } |
| 167 | |
| 168 | static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn) |
| 169 | { |
| 170 | return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj; |
| 171 | } |
| 172 | |
| 173 | static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn) |
| 174 | { |
| 175 | return pn_object(spn->spn_dev, spn->spn_obj); |
| 176 | } |
| 177 | |
| 178 | static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn) |
| 179 | { |
| 180 | return spn->spn_resource; |
| 181 | } |
| 182 | |
Rémi Denis-Courmont | f5bb1c5 | 2009-09-09 00:00:05 +0000 | [diff] [blame] | 183 | /* Phonet device ioctl requests */ |
| 184 | #ifdef __KERNEL__ |
| 185 | #define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0) |
| 186 | |
| 187 | struct if_phonet_autoconf { |
| 188 | uint8_t device; |
| 189 | }; |
| 190 | |
| 191 | struct if_phonet_req { |
| 192 | char ifr_phonet_name[16]; |
| 193 | union { |
| 194 | struct if_phonet_autoconf ifru_phonet_autoconf; |
| 195 | } ifr_ifru; |
| 196 | }; |
| 197 | #define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf |
| 198 | #endif /* __KERNEL__ */ |
| 199 | |
Remi Denis-Courmont | bce7b15 | 2008-09-22 19:51:15 -0700 | [diff] [blame] | 200 | #endif |