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