WirelessExtController.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #include "WirelessExtController.hh"
18 
19 // Custom includes
20 #include <string.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <sys/ioctl.h>
24 #include <math.h>
25 extern "C" {
26 #include <linux/if.h>
27 #include <linux/wireless.h>
28 }
30 #include <senf/Utils/Exception.hh>
31 
32 #define prefix_
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34 
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 // senf::emu::WirelessExtController
37 
39  : ifname_ (ifname), sockfd_ (NetdeviceController::sockfd())
40 {}
41 
43  : ifname_ (NetdeviceController(ifindex).interfaceName()),
44  sockfd_ (NetdeviceController::sockfd())
45 {}
46 
48  const
49 {
50  struct iwreq req;
51  bzero(&req, sizeof(req));
52  doIoctl(SIOCGIWFREQ, &req);
53  return (((double)req.u.freq.m) * pow(10,req.u.freq.e)) / 1000;
54 }
55 
57  const
58 {
59  struct iwreq req;
60  bzero(&req, sizeof(req));
61  char essid[IW_ESSID_MAX_SIZE + 1];
62  req.u.essid.pointer = (caddr_t)essid;
63  req.u.essid.length = IW_ESSID_MAX_SIZE;
64  req.u.essid.flags = 0;
65  doIoctl(SIOCGIWESSID, &req);
66  essid[req.u.essid.length] = 0;
67  return std::string(essid);
68 }
69 
71  const
72 {
73  struct iwreq req;
74  bzero(&req, sizeof(req));
75  doIoctl(SIOCGIWAP, &req);
76  return senf::MACAddress::from_data(req.u.ap_addr.sa_data);
77 }
78 
79 prefix_ void senf::emu::WirelessExtController::doIoctl(int ctl, struct iwreq * data)
80  const
81 {
82  strncpy(data->ifr_name, ifname_.c_str(), IFNAMSIZ-1);
83  data->ifr_name[IFNAMSIZ-1] = 0;
84  if (ioctl(sockfd_->fd, ctl, data) < 0)
85  SENF_THROW_SYSTEM_EXCEPTION("ioctl()");
86 }
87 
88 //-/////////////////////////////////////////////////////////////////////////////////////////////////
89 #undef prefix_
90 
91 
92 // Local Variables:
93 // mode: c++
94 // fill-column: 100
95 // comment-column: 40
96 // c-file-style: "senf"
97 // indent-tabs-mode: nil
98 // ispell-local-dictionary: "american"
99 // compile-command: "scons -u test"
100 // End:
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
WirelessExtController public header.
#define prefix_
u8 data[SPECTRAL_HT20_NUM_BINS]
WirelessExtController(std::string const &ifname)
#define doIoctl(ifr, errorMsg)
static MACAddress from_data(InputIterator i)