2 * Copyright (c) 2016 Adrian Chadd <adrian@FreeBSD.org>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
33 * This is a simple abstraction of the control channel used to access
34 * device specific data.
36 * In the past it used a ifnet socket on athX, but since those devices
37 * are now gone, they can use wlanX. However, there are debug cases
38 * where you'll instead want to talk to the hardware before any VAPs are
39 * up, so we should also handle the case of talking to /dev/athX.
41 * For now this'll be a drop-in replacement for the existing ioctl()
42 * based method until the /dev/athX (and associated new ioctls) land
46 #include <sys/param.h>
48 #include <sys/sockio.h>
49 #include <sys/socket.h>
52 #include <net/if_media.h>
53 #include <net/if_var.h>
64 #include "net80211/ieee80211_ioctl.h"
65 #include "net80211/ieee80211_radiotap.h"
66 #include "if_athioctl.h"
67 #include "if_athrate.h"
72 ath_driver_req_init(struct ath_driver_req *req)
75 bzero(req, sizeof(*req));
81 * Open a suitable file descriptor and populate the relevant interface
82 * information for ioctls.
84 * For file path based access the ifreq isn't required; it'll just be
85 * a direct ioctl on the file descriptor.
88 ath_driver_req_open(struct ath_driver_req *req, const char *ifname)
93 ath_driver_req_close(req);
95 /* For now, netif socket, not /dev/ filedescriptor */
96 s = socket(AF_INET, SOCK_DGRAM, 0);
98 warn("%s: socket", __func__);
101 req->ifname = strdup(ifname);
108 * Close an open descriptor.
111 ath_driver_req_close(struct ath_driver_req *req)
123 * Issue a diagnostic API request.
126 ath_driver_req_fetch_diag(struct ath_driver_req *req, unsigned long cmd,
131 ret = ioctl(req->s, cmd, ad);
133 warn("%s: ioctl", __func__);
138 * Issue a zero statistics API request.
141 ath_driver_req_zero_stats(struct ath_driver_req *req)
147 bzero(&ifr, sizeof(ifr));
148 strncpy(ifr.ifr_name, req->ifname, sizeof (ifr.ifr_name));
152 ret = ioctl(req->s, SIOCZATHSTATS, &ifr);
154 warn("%s: ioctl", __func__);
159 * Fetch general statistics.
162 ath_driver_req_fetch_stats(struct ath_driver_req *req, struct ath_stats *st)
168 bzero(&ifr, sizeof(ifr));
169 strncpy(ifr.ifr_name, req->ifname, sizeof (ifr.ifr_name));
170 ifr.ifr_data = (caddr_t) st;
173 ret = ioctl(req->s, SIOCGATHSTATS, &ifr);
175 warn("%s: ioctl", __func__);
180 * Fetch aggregate statistics.
183 ath_drive_req_fetch_aggr_stats(struct ath_driver_req *req,
184 struct ath_tx_aggr_stats *tx)
190 bzero(&ifr, sizeof(ifr));
191 strncpy(ifr.ifr_name, req->ifname, sizeof (ifr.ifr_name));
192 ifr.ifr_data = (caddr_t) tx;
195 ret = ioctl(req->s, SIOCGATHAGSTATS, &ifr);
197 warn("%s: ioctl", __func__);
203 * Fetch rate control statistics.
205 * Caller has to populate the interface name and MAC address.
208 ath_drive_req_fetch_ratectrl_stats(struct ath_driver_req *req,
209 struct ath_rateioctl *r)
214 ret = ioctl(req->s, SIOCGATHNODERATESTATS, r);
216 warn("%s: ioctl", __func__);