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