aboutsummaryrefslogtreecommitdiffstats
path: root/util/dib3000-watch/dib3000-watch.c
blob: 16bccb79211c07a4cdcd5a1a2cb33bb59421d9d2 (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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
 * Tool for watching the dib3000*-demodulators,
 * with an extended output.
 *
 * Copyright (C) 2005 by Patrick Boettcher <patrick.boettcher@desy.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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
 */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>

#include <getopt.h>

#include <signal.h>

#include <math.h>

#include <fcntl.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>

#include <linux/types.h>

#include "dib-i2c.h"
#include "dib3000-watch.h"
#include "dib3000.h"

void usage (void)
{
	verb("usage: dib3000-watch -d <i2c-device> -a <i2c-address> [-o <type>] [-i <seconds>]\n"
		 "   -d    normally one of /dev/i2c-[0-255]\n"
		 "   -a    is 8 for DiB3000M-B and 9, 10, 11 or 12 for DiB3000M-C or DiB3000-P\n"
		 "   -o    output type (print|csv) (default: print)\n"
		 "   -i    query interval in seconds (default: 0.1)\n"
		 "\n"
		 "Don't forget to run tzap or any other dvb-tune program (vdr, kaxtv) in order to tune a channel,\n"
		 "tuning isn't done by this tool.\n"
		 "\n"
		 "A lot of thing have been taken for the dibusb, dib3000m[bc] driver from kernel and\n"
		 "from t_demod-test software created by DiBcom. Both is GPL, so is dib-demod-watch.\n"
		 "\n"
		 "Copyright (C) 2005 by Patrick Boettcher <patrick.boettcher@desy.de>\n"
		 "\n"
		 "The source of this tool is released under the GPL.\n"
	);
	exit(1);
}

__u16 dib_read_reg(struct dib_demod *dib,__u16 reg)
{
	int ret;
	__u8 wb[] = { ((reg >> 8) | 0x80) & 0xff, reg & 0xff };
	__u8 rb[2];
	struct i2c_msg msg[] = {
		{ .addr = dib->i2c_addr, .flags = 0,        .buf = wb, .len = 2 },
		{ .addr = dib->i2c_addr, .flags = I2C_M_RD, .buf = rb, .len = 2 },
	};
	struct i2c_rdwr_ioctl_data i2c_data = {
		.msgs  = msg,
		.nmsgs = 2,
	};

	if ((ret = ioctl(dib->fd,I2C_RDWR,&i2c_data)) != 2) {
		err("i2c_rdwr read failed. (%d)\n",ret);
		return 0;
	}
	return (rb[0] << 8)| rb[1];
};

int dib_write_reg(struct dib_demod *dib, __u16 reg, __u16 val)
{
	int ret;
	__u8 b[] = {
		(reg >> 8) & 0xff, reg & 0xff,
		(val >> 8) & 0xff, val & 0xff,
	};
	struct i2c_msg msg[] = {
		{ .addr = dib->i2c_addr, .flags = 0, .buf = b, .len = 4 }
	};
	struct i2c_rdwr_ioctl_data i2c_data = {
		.msgs  = msg,
		.nmsgs = 1,
	};

	if ((ret = ioctl(dib->fd,I2C_RDWR,&i2c_data)) != 1) {
		err("i2c_rdwr write failed. (%d)\n",ret);
		return -1;
	}
	return 0;
}

int dib3000mb_monitoring(struct dib_demod *dib,struct dib3000mb_monitoring *m)
{
	int dds_freq, p_dds_freq,
		n_agc_power = dib_read_reg(dib,DIB3000MB_REG_AGC_POWER),
		rf_power = dib_read_reg(dib,DIB3000MB_REG_RF_POWER),
		timing_offset;
	double ad_power_dB, minor_power;

	m->invspec = dib_read_reg(dib,DIB3000MB_REG_DDS_INV);
	m->nfft = dib_read_reg(dib,DIB3000MB_REG_TPS_FFT);

	m->agc_lock = dib_read_reg(dib,DIB3000MB_REG_AGC_LOCK);
	m->carrier_lock = dib_read_reg(dib,DIB3000MB_REG_CARRIER_LOCK);
	m->tps_lock = dib_read_reg(dib,DIB3000MB_REG_TPS_LOCK);
	m->vit_lock = dib_read_reg(dib,DIB3000MB_REG_VIT_LCK);
	m->ts_sync_lock = dib_read_reg(dib,DIB3000MB_REG_TS_SYNC_LOCK);
	m->ts_data_lock = dib_read_reg(dib,DIB3000MB_REG_TS_RS_LOCK);

	p_dds_freq = ((dib_read_reg(dib,DIB3000MB_REG_DDS_FREQ_MSB) & 0xff) << 8) |
				 ((dib_read_reg(dib,DIB3000MB_REG_DDS_FREQ_LSB) & 0xff00) >> 8);
	dds_freq =   ((dib_read_reg(dib,DIB3000MB_REG_DDS_VALUE_MSB) & 0xff) << 8) |
				 ((dib_read_reg(dib,DIB3000MB_REG_DDS_VALUE_LSB) & 0xff00) >> 8);
	if (m->invspec)
		dds_freq = (1 << 16) - dds_freq;
	m->carrier_offset = (double)(dds_freq - p_dds_freq) / (double)(1 << 16) * DEF_SampFreq_KHz;

	m->ber = (double)((dib_read_reg(dib,DIB3000MB_REG_BER_MSB) << 16) | dib_read_reg(dib,DIB3000MB_REG_BER_LSB)) / (double) 1e8;
	m->per = dib_read_reg(dib,DIB3000MB_REG_PACKET_ERROR_RATE);
	m->unc = dib_read_reg(dib,DIB3000MB_REG_UNC);
	m->fft_pos = dib_read_reg(dib,DIB3000MB_REG_FFT_WINDOW_POS);
	m->snr = 10.0 * log10( (double)(dib_read_reg(dib,DIB3000MB_REG_SIGNAL_POWER) << 8) /
		(double)((dib_read_reg(dib,DIB3000MB_REG_NOISE_POWER_MSB) << 16) + dib_read_reg(dib,DIB3000MB_REG_NOISE_POWER_LSB)));

	m->mer = (double) ((dib_read_reg(dib,DIB3000MB_REG_MER_MSB) << 16) + dib_read_reg(dib,DIB3000MB_REG_MER_LSB))
		/ (double) (1<<9) / (m->nfft ? 767.0 : 191.0);

	if (n_agc_power == 0)
		n_agc_power = 1;
	ad_power_dB = 10 * log10( (double)(n_agc_power) / (double)(1<<16));
	minor_power = ad_power_dB - DEF_agc_ref_dB ;
	m->rf_power = -DEF_gain_slope_dB * (double)rf_power/(double)(1<<16) + DEF_gain_delta_dB + minor_power;

	timing_offset =
		(dib_read_reg(dib,DIB3000MB_REG_TIMING_OFFSET_MSB) << 16) + dib_read_reg(dib,DIB3000MB_REG_TIMING_OFFSET_LSB);
	if (timing_offset >= 0x800000)
		timing_offset |= 0xff000000;
	m->timing_offset_ppm = -(double)timing_offset / (double)(m->nfft ? 8192 : 2048) * 1e6 / (double)(1<<20);

	return 0;
}

int dib3000mb_print_monitoring(struct dib3000mb_monitoring *m)
{
	printf("DiB3000M-B status\n\n");
	printf(" AGC lock:                 %10d\n",m->agc_lock);
	printf(" carrier lock:             %10d\n",m->carrier_lock);
	printf(" TPS synchronize lock:     %10d\n",m->tps_lock);
	printf(" Viterbi lock:             %10d\n",m->vit_lock);
	printf(" MPEG TS synchronize lock: %10d\n",m->ts_sync_lock);
	printf(" MPEG TS data lock:        %10d\n",m->ts_data_lock);
	printf("\n\n");
	printf(" spectrum inversion:       %10d\n",m->invspec);
	printf(" carrier offset:           %3.7g\n",m->carrier_offset);
	printf("\n\n");
	printf(" bit error rate:           %3.7g\n",m->ber);
	printf(" packet error rate:        %10d\n",m->per);
	printf(" packet error count:       %10d\n",m->unc);
	printf("\n\n");
	printf(" fft position:             %10d\n",m->fft_pos);
	printf(" transmission mode:        %10s\n",m->nfft ? "8k" : "2k");
	printf("\n\n");
	printf(" C / (N + I) =             %3.7g\n",m->snr);
	printf(" MER  =                    %3.7g dB\n",m->mer);
	printf(" RF power =                %3.7g dBm\n",m->rf_power);
	printf(" timing offset =           %3.7g ppm\n",m->timing_offset_ppm);
	return 0;
}

int interrupted;

void sighandler (int sig)
{
	(void)sig;
	interrupted = 1;
}

typedef enum {
	OUT_PRINT = 0,
	OUT_CSV,
} dib3000m_output_t;

int main (int argc, char * const argv[])
{
	struct dib_demod dib;
	struct dib3000mb_monitoring mon;
	const char *dev = NULL;
	float intervall = 0.1;
	dib3000m_output_t out = OUT_PRINT;
	int c;

	while ((c = getopt(argc,argv,"d:a:o:i:")) != -1) {
		switch (c) {
			case 'd':
				dev = optarg;
				break;
			case 'a':
				dib.i2c_addr = atoi(optarg); /* The I2C address */
				break;
			case 'o':
				     if (strcasecmp(optarg,"print") == 0) out = OUT_PRINT;
				else if (strcasecmp(optarg,"csv") == 0)   out = OUT_CSV;
				else usage();
				break;
			case 'i':
				intervall = atof(optarg);
				break;
			default:
				usage();
		}
	}

	if (dev == NULL)
		usage();

	interrupted = 0;
	signal(SIGINT, sighandler);
	signal(SIGKILL, sighandler);
	signal(SIGHUP, sighandler);

	verb("will use '%s' as i2c-device and %d as i2c address.\n",dev,dib.i2c_addr);

	if ((dib.fd = open(dev,O_RDWR)) < 0) {
		err("could not open %s\n",dev);
		exit(1);
	}

    if (ioctl(dib.fd,I2C_SLAVE,dib.i2c_addr) < 0) {
		err("could not set i2c address\n");
		exit(1);
	}

	if (dib_read_reg(&dib,DIB3000_REG_MANUFACTOR_ID) != DIB3000_I2C_ID_DIBCOM) {
		err("could not find a dib3000 demodulator at i2c-address %d\n",dib.i2c_addr);
		exit(1);
	}

	switch (dib_read_reg(&dib,DIB3000_REG_DEVICE_ID)) {
		case DIB3000MB_DEVICE_ID:
			verb("found a DiB3000M-B demodulator.\n");
			dib.rev = DIB3000MB;
			break;
		case DIB3000MC_DEVICE_ID:
			verb("found a DiB3000M-C demodulator.\n");
			dib.rev = DIB3000MC;
			break;
		case DIB3000P_DEVICE_ID:
			verb("found a DiB3000-P demodulator.\n");
			dib.rev = DIB3000P;
			break;
		default:
			err("unsupported demodulator found.\n");
	}

	while (!interrupted) {
		switch (dib.rev) {
			case DIB3000MB:
				dib3000mb_monitoring(&dib,&mon);
				if (out == OUT_PRINT) {
					printf("\E[H\E[2J");
					dib3000mb_print_monitoring(&mon);
				} else if (out == OUT_CSV) {
					printf("no csv output implemented yet.\n");
				}
				break;
			default:
				interrupted=1;
				err("no monitoring writting for this demod, yet.\n");
		}
		usleep((int) (intervall * 1000000));
	}

	close(dib.fd);

	return 0;
}
>SIOCGIWTXPOW, &iwr) >= 0) { info->cap_txpower = 1; memcpy(&info->txpower, &iwr.u.txpower, sizeof(info->txpower)); } if (ioctl(skfd, SIOCGIWPOWER, &iwr) >= 0) { info->cap_power = 1; memcpy(&info->power, &iwr.u.power, sizeof(info->power)); } if (ioctl(skfd, SIOCGIWRETRY, &iwr) >= 0) { info->cap_retry = 1; memcpy(&info->retry, &iwr.u.retry, sizeof(info->retry)); } if (ioctl(skfd, SIOCGIWRTS, &iwr) >= 0) { info->cap_rts = 1; memcpy(&info->rts, &iwr.u.rts, sizeof(info->rts)); } if (ioctl(skfd, SIOCGIWFRAG, &iwr) >= 0) { info->cap_frag = 1; memcpy(&info->frag, &iwr.u.frag, sizeof(info->frag)); } if (ioctl(skfd, SIOCGIWMODE, &iwr) >= 0) { info->cap_mode = 1; info->mode = iwr.u.mode; } info->nkeys = ir->max_encoding_tokens; if (info->nkeys) { info->keys = calloc(info->nkeys, sizeof(*info->keys)); if (info->keys == NULL) err_sys("malloc(key array)"); /* Get index of default key first */ iwr.u.data.pointer = info->keys[0].key; iwr.u.data.length = sizeof(info->keys[0].key); iwr.u.data.flags = 0; if (ioctl(skfd, SIOCGIWENCODE, &iwr) < 0) { free(info->keys); info->keys = NULL; info->nkeys = 0; } else { info->active_key = iwr.u.data.flags & IW_ENCODE_INDEX; } } /* If successful, populate the key array */ for (i = 0; i < info->nkeys; i++) { iwr.u.data.pointer = info->keys[i].key; iwr.u.data.length = sizeof(info->keys->key); iwr.u.data.flags = i + 1; /* counts 1..n instead of 0..n-1 */ if (ioctl(skfd, SIOCGIWENCODE, &iwr) < 0) { free(info->keys); info->nkeys = 0; break; } info->keys[i].size = iwr.u.data.length; info->keys[i].flags = iwr.u.data.flags; /* Validate whether the current key is indeed active */ if (i + 1 == info->active_key && (info->keys[i].size == 0 || (info->keys[i].flags & IW_ENCODE_DISABLED))) info->active_key = 0; } if (ioctl(skfd, SIOCGIWAP, &iwr) >= 0) { info->cap_ap = 1; memcpy(&info->ap_addr, &iwr.u.ap_addr, sizeof(struct sockaddr)); } close(skfd); } void dyn_info_cleanup(struct iw_dyn_info *info) { if (info) free(info->keys); } /* * get range information */ void iw_getinf_range(const char *ifname, struct iw_range *range) { struct iwreq iwr; int skfd = socket(AF_INET, SOCK_DGRAM, 0); if (skfd < 0) err_sys("%s: can not open socket", __func__); memset(range, 0, sizeof(struct iw_range)); strncpy(iwr.ifr_name, ifname, IFNAMSIZ); iwr.u.data.pointer = (caddr_t) range; iwr.u.data.length = sizeof(struct iw_range); iwr.u.data.flags = 0; if (ioctl(skfd, SIOCGIWRANGE, &iwr) < 0) err_sys("can not get range information"); close(skfd); } /* * Obtain periodic IW statistics */ static int rand_wave(float *rlvl, float *step, float *rlvl_next, float range) { int i; for (i = 0; i < WAVE_RAND_SPREAD; i++) if (*rlvl < *rlvl_next) { if (*rlvl_next - *rlvl < *step) *step /= 2.0; *rlvl += *step; } else if (*rlvl > *rlvl_next) { if (*rlvl - *rlvl_next < *step) *step /= 2.0; *rlvl -= *step; } *step += (random() / (float)RAND_MAX) - 0.5; if (*rlvl == *rlvl_next || *step < 0.05) { *rlvl_next = (range * random()) / RAND_MAX; *step = random() / (float)RAND_MAX; } return *rlvl; } /* Random signal/noise/quality levels */ static void iw_getstat_random(struct iw_stat *iw) { static float rnd_sig, snext, sstep = 1.0, rnd_noise, nnext, nstep = 1.0; rand_wave(&rnd_sig, &sstep, &snext, conf.sig_max - conf.sig_min); rand_wave(&rnd_noise, &nstep, &nnext, conf.noise_max - conf.noise_min); if (iw->range.max_qual.qual == 0) iw->range.max_qual.qual = WAVE_RAND_QUAL_MAX; iw->stat.qual.level = dbm_to_u8(conf.sig_min + rnd_sig); iw->stat.qual.noise = dbm_to_u8(conf.noise_min + rnd_noise); iw->stat.qual.updated = IW_QUAL_DBM; iw->stat.qual.qual = map_range(conf.sig_min + rnd_sig, conf.sig_min, conf.sig_max, 0, iw->range.max_qual.qual); } static void iw_getstat_real(struct iw_statistics *stat) { struct iwreq wrq; int skfd = socket(AF_INET, SOCK_DGRAM, 0); if (skfd < 0) err_sys("%s: can not open socket", __func__); wrq.u.data.pointer = (caddr_t) stat; wrq.u.data.length = sizeof(*stat); wrq.u.data.flags = 0; strncpy(wrq.ifr_name, conf_ifname(), IFNAMSIZ); if (ioctl(skfd, SIOCGIWSTATS, &wrq) < 0) { /* * iw_handler_get_iwstats() returns EOPNOTSUPP if * there are no statistics. Bail out in this case. */ if (errno != EOPNOTSUPP) err_sys("can not obtain iw statistics"); errno = 0; memset(&wrq, 0, sizeof(wrq)); } close(skfd); } /* * Generate dBm values and perform sanity checks on values. * Code in part taken from wireless extensions #30 * @range: range information, read-only * @qual: wireless statistics, read-write * @dbm: dBm level information, write-only */ void iw_sanitize(struct iw_range *range, struct iw_quality *qual, struct iw_levelstat *dbm) { memset(dbm, 0, sizeof(*dbm)); if (qual->level != 0 || (qual->updated & (IW_QUAL_DBM | IW_QUAL_RCPI))) { /* * RCPI (IEEE 802.11k) statistics: * RCPI = int{(Power in dBm +110)*2} * for 0 dBm > Power > -110 dBm */ if (qual->updated & IW_QUAL_RCPI) { if (!(qual->updated & IW_QUAL_LEVEL_INVALID)) dbm->signal = (double)(qual->level / 2.0) - 110.0; if (!(qual->updated & IW_QUAL_NOISE_INVALID)) dbm->noise = (double)(qual->noise / 2.0) - 110.0; } else if ((qual->updated & IW_QUAL_DBM) || qual->level > range->max_qual.level) { if (!(qual->updated & IW_QUAL_LEVEL_INVALID)) dbm->signal = u8_to_dbm(qual->level); if (!(qual->updated & IW_QUAL_NOISE_INVALID)) dbm->noise = u8_to_dbm(qual->noise); } else { /* * Relative values (0 -> max) */ if (!(qual->updated & IW_QUAL_LEVEL_INVALID)) dbm->signal = mw2dbm(qual->level); if (!(qual->updated & IW_QUAL_NOISE_INVALID)) dbm->noise = mw2dbm(qual->noise); } } else { qual->updated |= IW_QUAL_ALL_INVALID; } /* * Value sanity checks * * These rules serve to avoid "insensible" level displays. Please do send * comments and/or bug reports if you encounter room for improvement. * * 1) if noise level is valid, but signal level is not, displaying just * the noise level does not reveal very much - can be omitted; * 2) if the noise level is below an "invalid" magic value (see iw_if.h), * declare the noise value to be invalid; * 3) SNR is only displayed if both signal and noise values are valid. */ if (qual->updated & IW_QUAL_LEVEL_INVALID) qual->updated |= IW_QUAL_NOISE_INVALID; if (dbm->noise <= NOISE_DBM_SANE_MIN) qual->updated |= IW_QUAL_NOISE_INVALID; } void iw_getstat(struct iw_stat *iw) { memset(&iw->stat, 0, sizeof(iw->stat)); if (conf.random) iw_getstat_random(iw); else iw_getstat_real(&iw->stat); iw_sanitize(&iw->range, &iw->stat.qual, &iw->dbm); } void dump_parameters(void) { struct iw_dyn_info info; struct iw_stat iw; struct if_stat nstat; int i; iw_getinf_range(conf_ifname(), &iw.range); dyn_info_get(&info, conf_ifname(), &iw.range); iw_getstat(&iw); if_getstat(conf_ifname(), &nstat); printf("\n"); printf("Configured device: %s (%s)\n", conf_ifname(), info.name); printf(" Security: %s\n", iw.range.enc_capa ? format_enc_capab(iw.range.enc_capa, ", ") : "WEP"); if (iw.range.num_encoding_sizes && iw.range.num_encoding_sizes < IW_MAX_ENCODING_SIZES) { printf(" Key sizes: "); for (i = 0; i < iw.range.num_encoding_sizes; i++) { if (i) printf(", "); if (iw.range.encoding_size[i] == 5) printf("WEP-40"); else if (iw.range.encoding_size[i] == 13) printf("WEP-104"); else printf("%u bits", iw.range.encoding_size[i] * 8); } printf("\n"); } printf(" WE version: %d (source version %d)\n\n", iw.range.we_version_compiled, iw.range.we_version_source); if (info.cap_essid) { if (info.essid_ct > 1) printf(" essid: \"%s\" [%d]\n", info.essid, info.essid_ct); else if (info.essid_ct) printf(" essid: \"%s\"\n", info.essid); else printf(" essid: off/any\n"); } if (info.cap_nickname) printf(" nick: \"%s\"\n", info.nickname); if (info.cap_nwid) { if (info.nwid.disabled) printf(" nwid: off/any\n"); else printf(" nwid: %X\n", info.nwid.value); } /* Some drivers only return the channel (e.g. ipw2100) */ if (info.cap_freq && info.freq < 256) info.freq = channel_to_freq(info.freq, &iw.range); if (info.cap_freq && info.freq > 1e3) { i = freq_to_channel(info.freq, &iw.range); if (i >= 0) printf(" channel: %d\n", i); printf(" frequency: %g GHz\n", info.freq / 1.0e9); } else printf(" frequency: n/a\n"); if (info.cap_sens) { if (info.sens < 0) printf(" sensitivity: %d dBm\n", info.sens); else printf(" sensitivity: %d/%d\n", info.sens, iw.range.sensitivity); } if (info.cap_txpower && info.txpower.disabled) printf(" tx-power: off\n"); else if (info.cap_txpower && info.txpower.fixed) printf(" tx-power: %s\n", format_txpower(&info.txpower)); else if (info.cap_txpower) printf(" TX-power: %s\n", format_txpower(&info.txpower)); printf(" mode: %s\n", iw_opmode(info.mode)); if (info.mode != 1 && info.cap_ap) printf(" access point: %s\n", format_bssid(&info.ap_addr)); if (info.bitrate) printf(" bitrate: %g Mbit/s\n", info.bitrate / 1.0e6); else printf(" bitrate: n/a\n"); printf(" retry: "); if (info.cap_retry) printf("%s\n", format_retry(&info.retry, &iw.range)); else printf("n/a\n"); printf(" rts thr: "); if (info.cap_rts) { if (info.rts.disabled) printf("off\n"); else printf("%d B %s\n", info.rts.value, info.rts.fixed ? "" : "(auto-select)"); } else printf("n/a\n"); printf(" frag thr: "); if (info.cap_frag) { if (info.frag.disabled) printf("off\n"); else printf("%d B %s\n", info.frag.value, info.frag.fixed ? "" : "(auto-select)"); } else { printf("n/a\n"); } printf(" encryption: "); if (!info.nkeys && has_net_admin_capability()) printf("no information available\n"); else if (!info.nkeys) printf("n/a (requires CAP_NET_ADMIN permissions)\n"); for (i = 0; i < info.nkeys; i++) { if (i) printf(" "); /* Current key is marked by `=' sign */ printf("[%u]%s ", i + 1, i + 1 == info.active_key ? "=" : ":"); if (info.keys[i].flags & IW_ENCODE_DISABLED || !info.keys[i].size) { printf("off\n"); } else { printf("%s", format_key(info.keys + i)); if (info.keys[i].flags & IW_ENCODE_RESTRICTED) printf(", restricted"); if (info.keys[i].flags & IW_ENCODE_OPEN) printf(", open"); printf("\n"); } } printf(" power management: "); if (info.cap_power) printf("%s\n", format_power(&info.power, &iw.range)); else printf("n/a\n"); printf("\n"); printf(" link quality: %d/%d\n", iw.stat.qual.qual, iw.range.max_qual.qual); printf(" signal level: %.0f dBm (%s)\n", iw.dbm.signal, dbm2units(iw.dbm.signal)); printf(" noise level: %.0f dBm (%s)\n", iw.dbm.noise, dbm2units(iw.dbm.noise)); printf(" SNR: %.0f dB\n", iw.dbm.signal - iw.dbm.noise); /* RX stats */ printf(" RX total: %'llu packets (%s)\n", nstat.rx_packets, byte_units(nstat.rx_bytes)); printf(" invalid nwid: %'u\n", iw.stat.discard.nwid); printf(" invalid key: %'u\n", iw.stat.discard.code); printf(" invalid fragm.: %'u\n", iw.stat.discard.fragment); printf(" missed beacons: %'u\n", iw.stat.miss.beacon); printf(" misc errors: %'u\n", iw.stat.discard.misc); /* TX stats */ printf(" TX total: %'llu packets (%s)\n", nstat.tx_packets, byte_units(nstat.tx_bytes)); printf(" exc. MAC retries: %'u\n", iw.stat.discard.retries); printf("\n"); dyn_info_cleanup(&info); }