1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux 1 2 /** 3 * file phonet.h 4 * 5 * Phonet sockets kernel interface 6 * 7 * Copyright (C) 2008 Nokia Corporation. All r 8 * 9 * This program is free software; you can redi 10 * modify it under the terms of the GNU Genera 11 * version 2 as published by the Free Software 12 * 13 * This program is distributed in the hope tha 14 * WITHOUT ANY WARRANTY; without even the impl 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU 19 * along with this program; if not, write to t 20 * Foundation, Inc., 51 Franklin St, Fifth Flo 21 * 02110-1301 USA 22 */ 23 24 #ifndef _UAPILINUX_PHONET_H 25 #define _UAPILINUX_PHONET_H 26 27 #include <linux/types.h> 28 #include <linux/socket.h> 29 30 /* Automatic protocol selection */ 31 #define PN_PROTO_TRANSPORT 0 32 /* Phonet datagram socket */ 33 #define PN_PROTO_PHONET 1 34 /* Phonet pipe */ 35 #define PN_PROTO_PIPE 2 36 #define PHONET_NPROTO 3 37 38 /* Socket options for SOL_PNPIPE level */ 39 #define PNPIPE_ENCAP 1 40 #define PNPIPE_IFINDEX 2 41 #define PNPIPE_HANDLE 3 42 #define PNPIPE_INITSTATE 4 43 44 #define PNADDR_ANY 0 45 #define PNADDR_BROADCAST 0xFC 46 #define PNPORT_RESOURCE_ROUTING 0 47 48 /* Values for PNPIPE_ENCAP option */ 49 #define PNPIPE_ENCAP_NONE 0 50 #define PNPIPE_ENCAP_IP 1 51 52 /* ioctls */ 53 #define SIOCPNGETOBJECT (SIOCPROTOPRIV 54 #define SIOCPNENABLEPIPE (SIOCPROTOPRIV 55 #define SIOCPNADDRESOURCE (SIOCPROTOPRIV 56 #define SIOCPNDELRESOURCE (SIOCPROTOPRIV 57 58 /* Phonet protocol header */ 59 struct phonethdr { 60 __u8 pn_rdev; 61 __u8 pn_sdev; 62 __u8 pn_res; 63 __be16 pn_length; 64 __u8 pn_robj; 65 __u8 pn_sobj; 66 } __attribute__((packed)); 67 68 /* Common Phonet payload header */ 69 struct phonetmsg { 70 __u8 pn_trans_id; /* transaction 71 __u8 pn_msg_id; /* message typ 72 union { 73 struct { 74 __u8 pn_submsg_id; 75 __u8 pn_data[5]; 76 } base; 77 struct { 78 __u16 pn_e_res_id; 79 __u8 pn_e_submsg_id 80 __u8 pn_e_data[3]; 81 } ext; 82 } pn_msg_u; 83 }; 84 #define PN_COMMON_MESSAGE 0xF0 85 #define PN_COMMGR 0x10 86 #define PN_PREFIX 0xE0 /* resour 87 #define pn_submsg_id pn_msg_u.base. 88 #define pn_e_submsg_id pn_msg_u.ext.p 89 #define pn_e_res_id pn_msg_u.ext.p 90 #define pn_data pn_msg_u.base. 91 #define pn_e_data pn_msg_u.ext.p 92 93 /* data for unreachable errors */ 94 #define PN_COMM_SERVICE_NOT_IDENTIFIED_RESP 95 #define PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP 96 #define pn_orig_msg_id pn_data[0] 97 #define pn_status pn_data[1] 98 #define pn_e_orig_msg_id pn_e_data[0] 99 #define pn_e_status pn_e_data[1] 100 101 /* Phonet socket address structure */ 102 struct sockaddr_pn { 103 __kernel_sa_family_t spn_family; 104 __u8 spn_obj; 105 __u8 spn_dev; 106 __u8 spn_resource; 107 __u8 spn_zero[sizeof(struct sockaddr) 108 } __attribute__((packed)); 109 110 /* Well known address */ 111 #define PN_DEV_PC 0x10 112 113 static inline __u16 pn_object(__u8 addr, __u16 114 { 115 return (addr << 8) | (port & 0x3ff); 116 } 117 118 static inline __u8 pn_obj(__u16 handle) 119 { 120 return handle & 0xff; 121 } 122 123 static inline __u8 pn_dev(__u16 handle) 124 { 125 return handle >> 8; 126 } 127 128 static inline __u16 pn_port(__u16 handle) 129 { 130 return handle & 0x3ff; 131 } 132 133 static inline __u8 pn_addr(__u16 handle) 134 { 135 return (handle >> 8) & 0xfc; 136 } 137 138 static inline void pn_sockaddr_set_addr(struct 139 { 140 spn->spn_dev &= 0x03; 141 spn->spn_dev |= addr & 0xfc; 142 } 143 144 static inline void pn_sockaddr_set_port(struct 145 { 146 spn->spn_dev &= 0xfc; 147 spn->spn_dev |= (port >> 8) & 0x03; 148 spn->spn_obj = port & 0xff; 149 } 150 151 static inline void pn_sockaddr_set_object(stru 152 153 { 154 spn->spn_dev = pn_dev(handle); 155 spn->spn_obj = pn_obj(handle); 156 } 157 158 static inline void pn_sockaddr_set_resource(st 159 160 { 161 spn->spn_resource = resource; 162 } 163 164 static inline __u8 pn_sockaddr_get_addr(const 165 { 166 return spn->spn_dev & 0xfc; 167 } 168 169 static inline __u16 pn_sockaddr_get_port(const 170 { 171 return ((spn->spn_dev & 0x03) << 8) | 172 } 173 174 static inline __u16 pn_sockaddr_get_object(con 175 { 176 return pn_object(spn->spn_dev, spn->sp 177 } 178 179 static inline __u8 pn_sockaddr_get_resource(co 180 { 181 return spn->spn_resource; 182 } 183 184 /* Phonet device ioctl requests */ 185 186 #endif /* _UAPILINUX_PHONET_H */ 187
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.