2 * Copyright (c) 2017-2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by Bill Paul.
44 * 4. Neither the name of the author nor the names of any co-contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
52 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
53 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
56 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
58 * THE POSSIBILITY OF SUCH DAMAGE.
61 #include <sys/param.h>
62 #include <sys/ioctl.h>
63 #include <sys/socket.h>
64 #include <sys/sockio.h>
69 #include <net/ethernet.h>
71 #include <net/if_var.h>
72 #include <net/if_6lowpan_var.h>
73 #include <net/route.h>
85 #include <sys/cdefs.h>
88 static boolean_t is_sixlowpan_inited
= FALSE
;
89 static struct sixlowpanreq params
;
92 get6lowpan(int s
, struct ifreq
*ifr
, struct sixlowpanreq
*req
)
94 bzero((char *)req
, sizeof(*req
));
95 ifr
->ifr_data
= (caddr_t
)req
;
96 return ioctl(s
, SIOCGIF6LOWPAN
, (caddr_t
)ifr
);
100 sixlowpan_status(int s
)
102 struct sixlowpanreq req
;
104 if (get6lowpan(s
, &ifr
, &req
) != -1)
105 printf("\t6lowpan: parent interface: %s\n",
106 req
.parent
[0] == '\0' ?
107 "<none>" : req
.parent
);
112 set6lowpandev(const char *val
, int d
, int s
, const struct afswtch
*afp
)
114 struct sixlowpanreq req
;
116 strlcpy(params
.parent
, val
, sizeof(params
.parent
));
117 is_sixlowpan_inited
= TRUE
;
118 fprintf(stderr
, "val %s\n", val
);
120 strlcpy(req
.parent
, val
, sizeof(req
.parent
));
121 ifr
.ifr_data
= (caddr_t
) &req
;
122 if (ioctl(s
, SIOCSIF6LOWPAN
, (caddr_t
)&ifr
) == -1)
123 err(1, "SIOCSIF6LOWPAN");
127 unset6lowpandev(const char *val
, int d
, int s
, const struct afswtch
*afp
)
129 struct sixlowpanreq req
;
131 bzero((char *)&req
, sizeof(req
));
132 ifr
.ifr_data
= (caddr_t
)&req
;
134 if (ioctl(s
, SIOCGIF6LOWPAN
, (caddr_t
)&ifr
) == -1)
135 err(1, "SIOCGIF6LOWPAN");
137 bzero((char *)&req
, sizeof(req
));
138 if (ioctl(s
, SIOCSIF6LOWPAN
, (caddr_t
)&ifr
) == -1)
139 err(1, "SIOCSIF6LOWPAN");
143 sixlowpan_create(const char *val
, int d
, int s
, const struct afswtch
*afp
)
145 strlcpy(params
.parent
, val
, sizeof(params
.parent
));
146 is_sixlowpan_inited
= TRUE
;
150 sixlowpan_clone_cb(int s
, void *arg
)
152 if (is_sixlowpan_inited
== TRUE
&& params
.parent
[0] == '\0')
153 errx(1, "6lowpandev must be specified");
156 static struct cmd sixlowpan_cmds
[] = {
157 DEF_CLONE_CMD_ARG("6lowpandev", sixlowpan_create
),
158 DEF_CMD_OPTARG("6lowpansetdev", set6lowpandev
),
159 DEF_CMD_OPTARG("6lowpanunsetdev", unset6lowpandev
),
161 static struct afswtch af_6lowpan
= {
162 .af_name
= "af_6lowpan",
164 .af_other_status
= sixlowpan_status
,
167 static __constructor
void
170 #define N(a) (sizeof(a) / sizeof(a[0]))
173 for (i
= 0; i
< N(sixlowpan_cmds
); i
++)
174 cmd_register(&sixlowpan_cmds
[i
]);
175 af_register(&af_6lowpan
);
176 callback_register(sixlowpan_clone_cb
, NULL
);