1 /*
2 * Copyright 2001 The Aerospace Corporation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of The Aerospace Corporation may not be used to endorse or
13 * promote products derived from this software.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30 /*-
31 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
32 * All rights reserved.
33 *
34 * This code is derived from software contributed to The NetBSD Foundation
35 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
36 * NASA Ames Research Center.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 * POSSIBILITY OF SUCH DAMAGE.
58 */
59
60 #include <sys/param.h>
61 #include <sys/ioctl.h>
62 #include <sys/socket.h>
63 #include <sys/sysctl.h>
64 #include <sys/time.h>
65
66 #include <net/ethernet.h>
67 #include <net/if.h>
68 #include <net/if_dl.h>
69 #include <net/if_types.h>
70 #include <net/if_media.h>
71 #include <net/route.h>
72
73 #include <net80211/ieee80211_ioctl.h>
74 #include <net80211/ieee80211_freebsd.h>
75 #include <net80211/ieee80211_superg.h>
76 #include <net80211/ieee80211_tdma.h>
77 #include <net80211/ieee80211_mesh.h>
78
79 #include <assert.h>
80 #include <ctype.h>
81 #include <err.h>
82 #include <errno.h>
83 #include <fcntl.h>
84 #include <inttypes.h>
85 #include <stdio.h>
86 #include <stdlib.h>
87 #include <string.h>
88 #include <unistd.h>
89 #include <stdarg.h>
90 #include <stddef.h> /* NB: for offsetof */
91
92 #include "lib80211_ioctl.h"
93
94 /*
95 * These implement basic net80211 accessor methods to wrap the IOCTL
96 * calls.
97 */
98
99 int
lib80211_get80211(int s,const char * name,int type,void * data,int len)100 lib80211_get80211(int s, const char *name, int type, void *data, int len)
101 {
102 struct ieee80211req ireq;
103
104 (void) memset(&ireq, 0, sizeof(ireq));
105 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
106 ireq.i_type = type;
107 ireq.i_data = data;
108 ireq.i_len = len;
109 return ioctl(s, SIOCG80211, &ireq);
110 }
111
112 int
lib80211_get80211len(int s,const char * name,int type,void * data,int len,int * plen)113 lib80211_get80211len(int s, const char *name, int type, void *data, int len, int *plen)
114 {
115 struct ieee80211req ireq;
116
117 (void) memset(&ireq, 0, sizeof(ireq));
118 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
119 ireq.i_type = type;
120 ireq.i_len = len;
121 assert(ireq.i_len == len); /* NB: check for 16-bit truncation */
122 ireq.i_data = data;
123 if (ioctl(s, SIOCG80211, &ireq) < 0)
124 return -1;
125 *plen = ireq.i_len;
126 return 0;
127 }
128
129 int
lib80211_get80211val(int s,const char * name,int type,int * val)130 lib80211_get80211val(int s, const char *name, int type, int *val)
131 {
132 struct ieee80211req ireq;
133
134 (void) memset(&ireq, 0, sizeof(ireq));
135 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
136 ireq.i_type = type;
137 if (ioctl(s, SIOCG80211, &ireq) < 0)
138 return -1;
139 *val = ireq.i_val;
140 return 0;
141 }
142
143 int
lib80211_set80211(int s,const char * name,int type,int val,int len,void * data)144 lib80211_set80211(int s, const char *name, int type, int val, int len, void *data)
145 {
146 struct ieee80211req ireq;
147
148 (void) memset(&ireq, 0, sizeof(ireq));
149 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
150 ireq.i_type = type;
151 ireq.i_val = val;
152 ireq.i_len = len;
153 assert(ireq.i_len == len); /* NB: check for 16-bit truncation */
154 ireq.i_data = data;
155 if (ioctl(s, SIOCS80211, &ireq) < 0)
156 return (-1);
157 return (0);
158 }
159
160