Skip to content

Commit bce7b15

Browse files
Remi Denis-Courmontdavem330
authored andcommitted
Phonet: global definitions
Signed-off-by: Remi Denis-Courmont <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5c18245 commit bce7b15

File tree

6 files changed

+153
-4
lines changed

6 files changed

+153
-4
lines changed

include/linux/if_ether.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#define ETH_P_ECONET 0x0018 /* Acorn Econet */
101101
#define ETH_P_HDLC 0x0019 /* HDLC frames */
102102
#define ETH_P_ARCNET 0x001A /* 1A for ArcNet :-) */
103+
#define ETH_P_PHONET 0x00F5 /* Nokia Phonet frames */
103104

104105
/*
105106
* This is an Ethernet frame header.

include/linux/if_phonet.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* File: if_phonet.h
3+
*
4+
* Phonet interface kernel definitions
5+
*
6+
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
7+
*/
8+
9+
#define PHONET_HEADER_LEN 8 /* Phonet header length */
10+
11+
#define PHONET_MIN_MTU 6
12+
/* 6 bytes header + 65535 bytes payload */
13+
#define PHONET_MAX_MTU 65541
14+
#define PHONET_DEV_MTU PHONET_MAX_MTU

include/linux/phonet.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
26+
/* Automatic protocol selection */
27+
#define PN_PROTO_TRANSPORT 0
28+
/* Phonet datagram socket */
29+
#define PN_PROTO_PHONET 1
30+
#define PHONET_NPROTO 2
31+
32+
#define PNADDR_ANY 0
33+
#define PNPORT_RESOURCE_ROUTING 0
34+
35+
/* Phonet protocol header */
36+
struct phonethdr {
37+
__u8 pn_rdev;
38+
__u8 pn_sdev;
39+
__u8 pn_res;
40+
__be16 pn_length;
41+
__u8 pn_robj;
42+
__u8 pn_sobj;
43+
} __attribute__((packed));
44+
45+
/* Phonet socket address structure */
46+
struct sockaddr_pn {
47+
sa_family_t spn_family;
48+
__u8 spn_obj;
49+
__u8 spn_dev;
50+
__u8 spn_resource;
51+
__u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
52+
} __attribute__ ((packed));
53+
54+
static inline __u16 pn_object(__u8 addr, __u16 port)
55+
{
56+
return (addr << 8) | (port & 0x3ff);
57+
}
58+
59+
static inline __u8 pn_obj(__u16 handle)
60+
{
61+
return handle & 0xff;
62+
}
63+
64+
static inline __u8 pn_dev(__u16 handle)
65+
{
66+
return handle >> 8;
67+
}
68+
69+
static inline __u16 pn_port(__u16 handle)
70+
{
71+
return handle & 0x3ff;
72+
}
73+
74+
static inline __u8 pn_addr(__u16 handle)
75+
{
76+
return (handle >> 8) & 0xfc;
77+
}
78+
79+
static inline void pn_sockaddr_set_addr(struct sockaddr_pn *spn, __u8 addr)
80+
{
81+
spn->spn_dev &= 0x03;
82+
spn->spn_dev |= addr & 0xfc;
83+
}
84+
85+
static inline void pn_sockaddr_set_port(struct sockaddr_pn *spn, __u16 port)
86+
{
87+
spn->spn_dev &= 0xfc;
88+
spn->spn_dev |= (port >> 8) & 0x03;
89+
spn->spn_obj = port & 0xff;
90+
}
91+
92+
static inline void pn_sockaddr_set_object(struct sockaddr_pn *spn,
93+
__u16 handle)
94+
{
95+
spn->spn_dev = pn_dev(handle);
96+
spn->spn_obj = pn_obj(handle);
97+
}
98+
99+
static inline void pn_sockaddr_set_resource(struct sockaddr_pn *spn,
100+
__u8 resource)
101+
{
102+
spn->spn_resource = resource;
103+
}
104+
105+
static inline __u8 pn_sockaddr_get_addr(const struct sockaddr_pn *spn)
106+
{
107+
return spn->spn_dev & 0xfc;
108+
}
109+
110+
static inline __u16 pn_sockaddr_get_port(const struct sockaddr_pn *spn)
111+
{
112+
return ((spn->spn_dev & 0x03) << 8) | spn->spn_obj;
113+
}
114+
115+
static inline __u16 pn_sockaddr_get_object(const struct sockaddr_pn *spn)
116+
{
117+
return pn_object(spn->spn_dev, spn->spn_obj);
118+
}
119+
120+
static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
121+
{
122+
return spn->spn_resource;
123+
}
124+
125+
#endif

include/linux/rtnetlink.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ enum rtnetlink_groups {
582582
#define RTNLGRP_IPV6_RULE RTNLGRP_IPV6_RULE
583583
RTNLGRP_ND_USEROPT,
584584
#define RTNLGRP_ND_USEROPT RTNLGRP_ND_USEROPT
585+
RTNLGRP_PHONET_IFADDR,
586+
#define RTNLGRP_PHONET_IFADDR RTNLGRP_PHONET_IFADDR
587+
RTNLGRP_PHONET_ROUTE,
588+
#define RTNLGRP_PHONET_ROUTE RTNLGRP_PHONET_ROUTE
585589
__RTNLGRP_MAX
586590
};
587591
#define RTNLGRP_MAX (__RTNLGRP_MAX - 1)

include/linux/socket.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ struct ucred {
190190
#define AF_IUCV 32 /* IUCV sockets */
191191
#define AF_RXRPC 33 /* RxRPC sockets */
192192
#define AF_ISDN 34 /* mISDN sockets */
193-
#define AF_MAX 35 /* For now.. */
193+
#define AF_PHONET 35 /* Phonet sockets */
194+
#define AF_MAX 36 /* For now.. */
194195

195196
/* Protocol families, same as address families. */
196197
#define PF_UNSPEC AF_UNSPEC
@@ -227,6 +228,7 @@ struct ucred {
227228
#define PF_IUCV AF_IUCV
228229
#define PF_RXRPC AF_RXRPC
229230
#define PF_ISDN AF_ISDN
231+
#define PF_PHONET AF_PHONET
230232
#define PF_MAX AF_MAX
231233

232234
/* Maximum queue length specifiable by listen. */

net/core/sock.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ static const char *af_family_key_strings[AF_MAX+1] = {
154154
"sk_lock-AF_PPPOX" , "sk_lock-AF_WANPIPE" , "sk_lock-AF_LLC" ,
155155
"sk_lock-27" , "sk_lock-28" , "sk_lock-AF_CAN" ,
156156
"sk_lock-AF_TIPC" , "sk_lock-AF_BLUETOOTH", "sk_lock-IUCV" ,
157-
"sk_lock-AF_RXRPC" , "sk_lock-AF_ISDN" , "sk_lock-AF_MAX"
157+
"sk_lock-AF_RXRPC" , "sk_lock-AF_ISDN" , "sk_lock-AF_PHONET" ,
158+
"sk_lock-AF_MAX"
158159
};
159160
static const char *af_family_slock_key_strings[AF_MAX+1] = {
160161
"slock-AF_UNSPEC", "slock-AF_UNIX" , "slock-AF_INET" ,
@@ -168,7 +169,8 @@ static const char *af_family_slock_key_strings[AF_MAX+1] = {
168169
"slock-AF_PPPOX" , "slock-AF_WANPIPE" , "slock-AF_LLC" ,
169170
"slock-27" , "slock-28" , "slock-AF_CAN" ,
170171
"slock-AF_TIPC" , "slock-AF_BLUETOOTH", "slock-AF_IUCV" ,
171-
"slock-AF_RXRPC" , "slock-AF_ISDN" , "slock-AF_MAX"
172+
"slock-AF_RXRPC" , "slock-AF_ISDN" , "slock-AF_PHONET" ,
173+
"slock-AF_MAX"
172174
};
173175
static const char *af_family_clock_key_strings[AF_MAX+1] = {
174176
"clock-AF_UNSPEC", "clock-AF_UNIX" , "clock-AF_INET" ,
@@ -182,7 +184,8 @@ static const char *af_family_clock_key_strings[AF_MAX+1] = {
182184
"clock-AF_PPPOX" , "clock-AF_WANPIPE" , "clock-AF_LLC" ,
183185
"clock-27" , "clock-28" , "clock-AF_CAN" ,
184186
"clock-AF_TIPC" , "clock-AF_BLUETOOTH", "clock-AF_IUCV" ,
185-
"clock-AF_RXRPC" , "clock-AF_ISDN" , "clock-AF_MAX"
187+
"clock-AF_RXRPC" , "clock-AF_ISDN" , "clock-AF_PHONET" ,
188+
"clock-AF_MAX"
186189
};
187190
#endif
188191

0 commit comments

Comments
 (0)