summaryrefslogtreecommitdiffstats
path: root/wifi/interface_wireless.cpp
blob: 52513a5937c2d06f225ffe72d393e8b613868bff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/***************************************************************************
                          stuff.cpp  -  description
                             -------------------
    begin                : Sun May 6 2001
    copyright            : (C) 2001 by Stefan Winter
    email                : mail@stefan-winter.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "interface_wireless.h"
#include <tqdir.h>
#include <tqfile.h>
#include <tqstringlist.h>

#ifndef WITHOUT_ARTS
#include <arts/artsflow.h>
#include <arts/connect.h>
#include <arts/iomanager.h>
#include <arts/referenceclean.h>
#endif // WITHOUT_ARTS

#include <iostream>
#include <string>
#include <klocale.h>
#include <kprocio.h>
#include <kdebug.h>
#include <tqstring.h>
#include <arpa/inet.h>

Interface_wireless::Interface_wireless (TQStringList * ignoreInterfaces)
{
  this->ignoreInterfaces = ignoreInterfaces;
  has_frequency = false;
  frequency = 0.;
  has_mode = false;
  mode = 0;
  has_key = 0;
  key = "";
  key_size = 0;
  key_flags = 0;
  essid = "";
  access_point_address = "";
  ip_address = "";
  bitrate = 0.;
  socket = -1;
  has_range = false;
  for (int i = 0; i < MAX_HISTORY; i++)
    {
      sigLevel[i] = -255;
      noiseLevel[i] = -255;
      qual[i] = -255;
      valid[i] = false;
    }
  current = 0;
  sigLevelMin = 32000;
  noiseLevelMin = 32000;
  sigLevelMax = -32000;
  noiseLevelMax = -32000;

  already_warned = false;
}

bool Interface_wireless::get_device_freq (double &freq)
{
  if (has_frequency)
    {
      freq = frequency;
      return true;
    }
  else
    {
      return false;
    }
}

bool Interface_wireless::get_mode (int &ext_mode)
{
  if (has_mode)
    {
      ext_mode = mode;
      return true;
    }
  else
    {
      return false;
    }
}

bool Interface_wireless::get_key (TQString & ext_key,
						  int &ext_size,
						  int &ext_flags)
{
  if (has_key)
    {
      ext_key = key;
      ext_size = key_size;
      ext_flags = key_flags;
      return true;
    }
  else
    {
      return false;
    }
}

TQString Interface_wireless::get_essid ()
{
  return essid;
}

bool Interface_wireless::get_has_txpower()
{
  return has_txpower;
}

int Interface_wireless::get_txpower_disabled()
{
  return txpower_disabled;
}

bool Interface_wireless::get_AP_info (TQString & mac, TQString &/*ip*/)
{
  mac = access_point_address;
  return false;
}

TQString Interface_wireless::get_IP_info ()
{
  return ip_address;
}

double Interface_wireless::get_bitrate ()
{
  return bitrate;
}

TQString Interface_wireless::get_interface_name ()
{
  return interface_name;
}

bool Interface_wireless::get_current_quality (int &sig,
							      int &noi,
							      int &qua)
{
  if (valid[current])
    {
      sig = sigLevel[current];
      noi = noiseLevel[current];
      qua = qual[current];
      return true;
    }
  else
    return false;
}

#ifndef WITHOUT_ARTS

void
sinus_wave (double frequency)
{
  using namespace Arts;
  StdIOManager *limiter = new StdIOManager;
  Dispatcher dispatcher (limiter);
  MyTimeNotify *zeit = new MyTimeNotify (&dispatcher);
  Synth_FREQUENCY freq;
  Synth_WAVE_SIN sin;
  Synth_PLAY play;
  setValue (freq, frequency);
  connect (freq, sin);
  connect (sin, play, "invalue_left");
  freq.start ();
  sin.start ();
  play.start ();
  limiter->addTimer (240, zeit);
  dispatcher.run ();
  play.stop ();
  sin.stop ();
  freq.stop ();
}

void
MyTimeNotify::notifyTime ()
{
  test->terminate ();
}

#endif

TQString
whois (const char *MAC_ADR, TQStringList APList)
{
  for (TQStringList::Iterator it = APList.begin (); it != APList.end ();
       (it++)++)
    {
      if ((*it) == (TQString) MAC_ADR)
	return *(++it);
    }
  return i18n ("UNKNOWN");
}

#include "interface_wireless.moc"