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