1 /* $NetBSD: cnwctl.c,v 1.6 2001/08/18 17:10:04 ad Exp $ */
4 * Copyright (c) 1997 Berkeley Software Design, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that this notice is retained,
9 * the conditions in the following notices are met, and terms applying
10 * to contributors in the following notices also apply to Berkeley
11 * Software Design, Inc.
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by
21 * Berkeley Software Design, Inc.
22 * 4. Neither the name of the Berkeley Software Design, Inc. nor the names
23 * of its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN, INC. BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * PAO2 Id: cnwctl.c,v 1.1.1.1 1997/12/11 14:46:06 itojun Exp
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <sys/cdefs.h>
44 #include <sys/errno.h>
45 #include <sys/socket.h>
46 #include <sys/ioctl.h>
50 #include <dev/pcmcia/if_cnwioctl.h>
60 main(int argc
, char **argv
)
62 int c
, domain
, i
, key
, rate
, sflag
, Sflag
, skt
;
63 const char *interface
;
66 struct cnwistats cnwis
, onwis
;
67 struct cnwstatus cnws
;
76 while ((c
= getopt(argc
, argv
, "d:i:k:sS")) != -1)
79 domain
= strtol(optarg
, &e
, 0);
80 if (e
== optarg
|| *e
|| domain
& ~ 0x1ff)
81 errx(1, "%s: invalid domain", optarg
);
87 key
= strtol(optarg
, &e
, 0);
88 if (e
== optarg
|| *e
|| key
& ~ 0xffff)
89 errx(1, "%s: invalid scramble key", optarg
);
98 fprintf(stderr
, "usage: cnwctl [-i interface] [-d domain] [-k key] [-sS [rate]]\n");
102 switch (argc
- optind
) {
106 if (sflag
== 0 && Sflag
== 0)
109 errx(1, "only one of -s and -S may be specified with a rate");
110 rate
= strtol(argv
[optind
], &e
, 0);
111 if (e
== optarg
|| *e
|| rate
< 1)
112 errx(1, "%s: invalid rate", optarg
);
118 if ((skt
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
119 err(1, "socket(AF_INET, SOCK_DGRAM)");
122 memset(&ifr
, 0, sizeof(ifr
));
123 strncpy(ifr
.ifr_name
, interface
, sizeof(ifr
.ifr_name
));
125 if (ioctl(skt
, SIOCSCNWKEY
, (caddr_t
)&ifr
) < 0)
126 err(1, "SIOCSCNWKEY");
130 memset(&ifr
, 0, sizeof(ifr
));
131 strncpy(ifr
.ifr_name
, interface
, sizeof(ifr
.ifr_name
));
132 ifr
.ifr_domain
= domain
;
133 if (ioctl(skt
, SIOCSCNWDOMAIN
, (caddr_t
)&ifr
) < 0)
134 err(1, "SIOCSCNWDOMAIN");
137 if (sflag
== 0 && Sflag
== 0)
141 memset(&cnws
, 0, sizeof(cnws
));
142 strncpy(cnws
.ifr
.ifr_name
, interface
,
143 sizeof(cnws
.ifr
.ifr_name
));
144 if (ioctl(skt
, SIOCGCNWSTATUS
, (caddr_t
)&cnws
) < 0)
145 err(1, "SIOCGCNWSTATUS");
149 memset(&cnwis
, 0, sizeof(cnwis
));
150 strncpy(cnwis
.ifr
.ifr_name
, interface
,
151 sizeof(cnwis
.ifr
.ifr_name
));
152 if (ioctl(skt
, SIOCGCNWSTATS
, (caddr_t
)&cnwis
) < 0)
153 err(1, "SIOCGCNWSTATS");
154 cnwis
.stats
.nws_txretries
[0] = 0;
156 for (i
= 1; i
< 16; ++i
)
157 cnwis
.stats
.nws_txretries
[0] +=
158 cnwis
.stats
.nws_txretries
[i
] * i
;
161 if (rate
== 0 && sflag
) {
162 memset(&ifr
, 0, sizeof(ifr
));
163 strncpy(ifr
.ifr_name
, interface
, sizeof(ifr
.ifr_name
));
164 if (ioctl(skt
, SIOCGCNWDOMAIN
, (caddr_t
)&ifr
) < 0)
165 err(1, "SIOCGCNWDOMAIN");
166 printf("%s:\n 0x%03x domain\n", interface
, ifr
.ifr_domain
);
167 printf("%10llu rx\n", (unsigned long long)cnwis
.stats
.nws_rx
);
168 printf("%10llu rxoverflow\n",
169 (unsigned long long)cnwis
.stats
.nws_rxoverflow
);
170 printf("%10llu rxoverrun\n",
171 (unsigned long long)cnwis
.stats
.nws_rxoverrun
);
172 printf("%10llu rxcrcerror\n",
173 (unsigned long long)cnwis
.stats
.nws_rxcrcerror
);
174 printf("%10llu rxframe\n",
175 (unsigned long long)cnwis
.stats
.nws_rxframe
);
176 printf("%10llu rxerrors\n",
177 (unsigned long long)cnwis
.stats
.nws_rxerrors
);
178 printf("%10llu rxavail\n",
179 (unsigned long long)cnwis
.stats
.nws_rxavail
);
181 printf("%10llu tx\n", (unsigned long long)cnwis
.stats
.nws_tx
);
182 printf("%10llu txokay\n",
183 (unsigned long long)cnwis
.stats
.nws_txokay
);
184 printf("%10llu txabort\n",
185 (unsigned long long)cnwis
.stats
.nws_txabort
);
186 printf("%10llu txlostcd\n",
187 (unsigned long long)cnwis
.stats
.nws_txlostcd
);
188 printf("%10llu txerrors\n",
189 (unsigned long long)cnwis
.stats
.nws_txerrors
);
190 printf("%10llu txretries\n",
191 (unsigned long long)cnwis
.stats
.nws_txretries
[0]);
192 for (i
= 1; i
< 16; ++i
)
193 if (cnwis
.stats
.nws_txretries
[i
])
194 printf("%10s %10llu %dx retries\n", "",
196 cnwis
.stats
.nws_txretries
[i
],
200 if (rate
== 0 && Sflag
) {
201 printf(" 0x%02x link integrity field\n",
203 printf(" 0x%02x connection quality\n",
205 printf(" 0x%02x spu\n",
207 printf(" 0x%02x link quality\n",
209 printf(" 0x%02x hhc\n",
211 printf(" 0x%02x mhs\n",
213 printf(" %04x %04x revision\n",
214 *(u_short
*)&cnws
.data
[0x66], *(u_short
*)&cnws
.data
[0x68]);
216 cnws
.data
[0x6e], cnws
.data
[0x6f]);
222 if (ioctl(0, TIOCGWINSZ
, &ts
) < 0)
226 if (Sflag
) for (;;) {
228 printf("lif cq spu lq hhc mhs\n");
231 printf(" %02x %02x %02x %02x %02x %02x\n",
239 if (ioctl(skt
, SIOCGCNWSTATUS
, (caddr_t
)&cnws
) < 0)
240 err(1, "SIOCGCNWSTATUS");
246 printf("%10s %10s %10s %10s %10s %10s\n",
247 "tx-request", "tx-okay", "tx-error", "tx-retry",
250 memset(&onwis
, 0, sizeof(onwis
));
252 printf("%10llu ", (unsigned long long)
253 (cnwis
.stats
.nws_tx
- onwis
.stats
.nws_tx
));
254 printf("%10llu ", (unsigned long long)
255 (cnwis
.stats
.nws_txokay
- onwis
.stats
.nws_txokay
));
256 printf("%10llu ", (unsigned long long)
257 (cnwis
.stats
.nws_txerrors
- onwis
.stats
.nws_txerrors
));
258 printf("%10llu ", (unsigned long long)
259 (cnwis
.stats
.nws_txretries
[0] -
260 onwis
.stats
.nws_txretries
[0]));
261 printf("%10llu ", (unsigned long long)
262 (cnwis
.stats
.nws_rx
- onwis
.stats
.nws_rx
));
263 printf("%10llu\n", (unsigned long long)
264 (cnwis
.stats
.nws_rxerrors
- onwis
.stats
.nws_rxerrors
));
269 if (ioctl(skt
, SIOCGCNWSTATS
, (caddr_t
)&cnwis
) < 0)
270 err(1, "SIOCGCNWSTATS");
271 cnwis
.stats
.nws_txretries
[0] = 0;
272 for (i
= 1; i
< 16; ++i
)
273 cnwis
.stats
.nws_txretries
[0] +=
274 cnwis
.stats
.nws_txretries
[i
] * i
;