2 * $RISS: if_arl/arlconfig/arlconfig.c,v 1.5 2004/03/16 05:00:21 count Exp $
9 #include <sys/socket.h>
10 #include <sys/ioctl.h>
13 #include <net/ethernet.h>
14 #include <netinet/in.h>
15 #include <netinet/if_ether.h>
25 #include <dev/arl/if_arlreg.h>
32 struct freq_list freq_list_1[] = {
47 struct freq_list freq_list_6[] = {
57 struct freq_list freq_list_9[] = {
67 struct freq_list freq_list_10[] = {
76 struct freq_list freq_list_11[] = {
81 struct freq_list freq_list_12[] = {
88 struct freq_list freq_list_13[] = {
95 struct freq_list freq_list_14[] = {
102 struct freq_list freq_list_15[] = {
107 #define MAXFREQ(a) sizeof(a)/sizeof(struct freq_list)
114 struct rate_list rate_list_2400[] = {
125 } radio_type_list [] = {
142 static struct ch_list {
146 struct rate_list* rate;
147 struct freq_list* freq;
150 { 0, 0, 0, 0, 0, 0 },
151 { 1, "900 Mhz", "Canada, U.S.A., Mexico", 0, freq_list_1, MAXFREQ(freq_list_1) },
152 { 2, 0, 0, 0, 0, 0 },
153 { 3, 0, 0, 0, 0, 0 },
154 { 4, 0, 0, 0, 0, 0 },
155 { 5, 0, 0, 0, 0, 0 },
156 { 6, "900 Mhz", "Australia", 0, freq_list_6, MAXFREQ(freq_list_6) },
157 { 7, 0, 0, 0, 0, 0 },
158 { 8, 0, 0, 0, 0, 0 },
159 { 9, "2400 Mhz", "North America", rate_list_2400, freq_list_9, MAXFREQ(freq_list_9) },
160 { 10, "2400 Mhz", "E.T.S.I", rate_list_2400, freq_list_10, MAXFREQ(freq_list_10) },
161 { 11, "2400 Mhz", "Japan", rate_list_2400, freq_list_11, MAXFREQ(freq_list_11) },
162 { 12, "2400 Mhz", "France", rate_list_2400, freq_list_12, MAXFREQ(freq_list_12) },
163 { 13, "2400 Mhz", "Australia", rate_list_2400, freq_list_13, MAXFREQ(freq_list_13) },
164 { 14, "2400 Mhz", "Germany", rate_list_2400, freq_list_14, MAXFREQ(freq_list_14) },
165 { 15, "2400 Mhz", "U.K.(MPT1349),Spain", rate_list_2400, freq_list_15, MAXFREQ(freq_list_15) }
168 char* registrationMode[] = {
174 char* priorityList[] = {
183 const char *progname = getprogname();
186 fprintf(stderr, "\nArlan configuration utility.\n\n");
188 fprintf(stderr, "Usage: %s <ifname> [<param> <value> ...]\n", progname);
189 fprintf(stderr, "\t<ifname>\tArlan interface name.\n");
190 fprintf(stderr, "\t<param>\t\tParameter name (see below).\n");
191 fprintf(stderr, "\t<value>\t\tNew value for parameter.\n");
192 fprintf(stderr, "Parameter name:\t\tValue:\n");
193 fprintf(stderr, "\tcountry\t\tset Country (9-15)\n");
194 fprintf(stderr, "\tpriority\tset Priority (normal, high, highest)\n");
195 fprintf(stderr, "\ttxretry\t\tset Arlan Tx retry.\n");
196 fprintf(stderr, "or: %s <ifname> stat\n", progname);
197 fprintf(stderr, "\tprint internal arlan statistics block\n");
199 fprintf(stderr,"or: %s <ifname> quality\n", progname);
200 fprintf(stderr,"\tprint receive packet level and quality\n");
206 print_al(struct arl_cfg_param *arl_io)
208 printf("Arlan-655(IC2000) type 0x%x v%d.%d, radio module type %s\n",
209 arl_io->hardwareType,
210 arl_io->majorHardwareVersion,
211 arl_io->minorHardwareVersion,
212 (arl_io->radioModule < 13) ?
213 radio_type_list[arl_io->radioModule].name : "Unknown" );
214 printf("\tname %s, sid 0x%06x, mode %s, num tx retry %d\n",
217 (arl_io->registrationMode < 3) ?
218 registrationMode[arl_io->registrationMode]:"Unknown",
220 printf("\tchannel set %d, %s, %s\n",
222 CHSET[arl_io->channelSet].fr,
223 CHSET[arl_io->channelSet].country);
224 printf("\tfrequency %s Mhz, bitrate %s kb/s, priority %s, receive mode %d\n",
225 (CHSET[arl_io->channelSet].freq &&
226 CHSET[arl_io->channelSet].max_freq > arl_io->channelNumber) ?
227 CHSET[arl_io->channelSet].freq[arl_io->channelNumber].name :
229 (CHSET[arl_io->channelSet].rate) ?
230 CHSET[arl_io->channelSet].rate[arl_io->spreadingCode].name :
232 arl_io->priority <= 2 ?
233 priorityList[arl_io->priority] : "unknown",
234 arl_io->receiveMode);
236 (char *)ether_ntoa((struct ether_addr *)arl_io->lanCardNodeId));
237 printf(" registered to %s\n",
238 (char *)ether_ntoa((struct ether_addr *)arl_io->specifiedRouter));
242 print_stb( struct arl_stats stb )
244 printf("Arlan internal statistics block\n\n");
245 printf("%8u\tdatagrams transmitted\n",
246 stb.numDatagramsTransmitted);
247 printf("%8u\tre-transmitted\n",
248 stb.numReTransmissions);
249 printf("%8u\tframes discarded internally in a router\n",
250 stb.numFramesDiscarded);
251 printf("%8u\tdatagrams received\n",
252 stb.numDatagramsReceived);
253 printf("%8u\tduplicate received frame\n",
254 stb.numDuplicateReceivedFrames);
255 printf("%8u\tdatagrams discarded due to unavailable mail box buffer\n",
256 stb.numDatagramsDiscarded);
257 printf("%8d\tmaximum of re-transmissions datagram\n",
258 stb.maxNumReTransmitDatagram);
259 printf("%8d\tmaximum of re-transmissions frame\n",
260 stb.maxNumReTransmitFrames);
261 printf("%8d\tmaximum of consecutive duplicate received frames\n",
262 stb.maxNumConsecutiveDuplicateFrames);
263 printf("%8u\tbytes transmitted\n",
264 stb.numBytesTransmitted);
265 printf("%8u\tbytes received\n",
266 stb.numBytesReceived);
267 printf("%8u\tCRC errors\n",
269 printf("%8u\tlength errors\n",
270 stb.numLengthErrors);
271 printf("%8u\tabort errors\n",
273 printf("%8u\tTX underuns\n",
275 printf("%8u\tRX overruns\n",
277 printf("%8u\tHold Offs (channel tested busy, tx delayed)\n",
279 printf("%8u\tframes transmitted\n",
280 stb.numFramesTransmitted);
281 printf("%8u\tframes received\n",
282 stb.numFramesReceived);
283 printf("%8u\treceive frames lost due unavailable buffer\n",
284 stb.numReceiveFramesLost);
285 printf("%8u\tRX buffer overflows \n",
286 stb.numRXBufferOverflows);
287 printf("%8u\tframes discarded due to Address mismatch\n",
288 stb.numFramesDiscardedAddrMismatch);
289 printf("%8u\tframes discarded due to SID mismatch\n",
290 stb.numFramesDiscardedSIDMismatch);
291 printf("%8u\tpolls transmitted\n",
292 stb.numPollsTransmistted);
293 printf("%8u\tpoll acknowledges received\n",
294 stb.numPollAcknowledges);
295 printf("%8u\tstatus vector timeout\n",
296 stb.numStatusVectorTimeouts);
297 printf("%8u\tNACK packets received\n",
298 stb.numNACKReceived);
303 print_qlt(struct arl_sigcache *qlt)
306 u_int8_t zero[6] = {0, 0, 0, 0, 0, 0};
308 for (i = 0; i < MAXARLCACHE && bcmp(qlt->macsrc, zero, 6); i++) {
309 printf("[%d]:", i+1);
310 printf(" %02x:%02x:%02x:%02x:%02x:%02x,",
316 qlt->macsrc[5]&0xff);
317 printf(" rx lvl/qlty: %d/%d,", qlt->level[ARLCACHE_RX],
318 qlt->quality[ARLCACHE_RX]);
319 printf(" tx lvl/qlty: %d/%d", qlt->level[ARLCACHE_TX],
320 qlt->quality[ARLCACHE_TX]);
328 main(int argc, char *argv[])
331 struct arl_req arl_io;
332 struct ether_addr *ea;
333 struct arl_stats stb;
334 struct arl_sigcache qlt[MAXARLCACHE];
335 int sd, argind, val = -1;
341 sd = socket(AF_INET, SOCK_DGRAM, 0);
344 strncpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name));
345 ifr.ifr_addr.sa_family = AF_INET;
346 bzero(&arl_io, sizeof(arl_io));
347 ifr.ifr_data = (caddr_t)&arl_io;
350 if (ioctl(sd, SIOCGARLALL, (caddr_t)&ifr))
352 print_al(&arl_io.cfg);
357 if (!strcasecmp(argv[2], "stat")) {
358 strncpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name));
359 ifr.ifr_addr.sa_family = AF_INET;
360 ifr.ifr_data = (caddr_t)&stb;
361 if (ioctl(sd, SIOCGARLSTB, (caddr_t)&ifr))
367 if (!strcasecmp( argv[2],"quality")) {
369 strncpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name));
370 ifr.ifr_addr.sa_family = AF_INET;
371 ifr.ifr_data = (caddr_t)qlt;
372 if (ioctl(sd, SIOCGARLQLT, (caddr_t)&ifr))
382 for (argind = 2; argind < argc; argind += 2) {
383 param = argv[argind];
384 value = argv[argind+1];
387 if (!strcasecmp(param, "priority")) {
388 if (!strcasecmp(value, "normal"))
390 else if (!strcasecmp(value, "high"))
392 else if (!strcasecmp(value, "highest"))
395 err( 1, "Bad priority - %s", value);
396 arl_io.cfg.priority = val;
397 arl_io.what_set |= ARLAN_SET_priority;
400 if (!strcasecmp(param, "parent")) {
401 if ((ea = (struct ether_addr*) ether_aton(value)) == NULL)
402 err (1, "Bad parent's MAC - %s", value);
403 for (val = 0; val < 6; val++) {
404 arl_io.cfg.specifiedRouter[val] =
405 (int) ea->octet[val];
407 arl_io.what_set |= ARLAN_SET_specifiedRouter;
410 if (!strcasecmp(param, "country")) {
411 arl_io.cfg.channelSet = atoi(value);
412 arl_io.what_set |= ARLAN_SET_channelSet;
415 if (!strcasecmp(param, "txretry")) {
416 arl_io.cfg.txRetry = atoi(value);
417 arl_io.what_set |= ARLAN_SET_txRetry;
421 if (arl_io.what_set) {
422 if (ioctl(sd, SIOCSARLALL, (caddr_t)&ifr))
424 if (ioctl(sd, SIOCGARLALL, (caddr_t)&ifr))
426 print_al(&arl_io.cfg);