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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
|
/* $OpenBSD: rl2.c,v 1.2 1999/06/23 04:48:48 d Exp $ */
/*
* David Leonard <d@openbsd.org>, 1999. Public Domain.
*
* Driver for the Proxim RangeLAN2 wireless network adaptor.
*
* Information and ideas gleaned from disassembly of Dave Koberstein's
* <davek@komacke.com> Linux driver (apparently based on Proxim source),
* from Yoichi Shinoda's <shinoda@cs.washington.edu> BSDI driver, and
* Geoff Voelker's <voelker@cs.washington.edu> Linux port of the same.
*
*/
#include "bpfilter.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <net/if.h>
#include <net/if_media.h>
#ifdef INET
#include <netinet/in.h>
#include <netinet/if_ether.h>
#endif
#if NBPFILTER > 0
#include <net/bpf.h>
#include <net/bpfdesc.h>
#endif
#include <machine/bus.h>
#include <machine/intr.h>
#include <dev/ic/rl2.h>
#include <dev/ic/rl2var.h>
#include <dev/ic/rl2reg.h>
#include <dev/ic/rl2cmd.h>
/* Autoconfig definition of driver back-end. */
struct cfdriver rln_cd = {
NULL, "rln", DV_IFNET
};
static void rl2init __P((struct rl2_softc *));
static void rl2start __P((struct ifnet*));
static void rl2watchdog __P((struct ifnet*));
static int rl2ioctl __P((struct ifnet *, u_long, caddr_t));
static int rl2_probe __P((struct rl2_softc *));
static void rl2stop __P((struct rl2_softc *));
/* Interrupt handler. */
static void rl2softintr __P((void *));
/* Packet I/O. */
static int rl2_transmit __P((struct rl2_softc *, struct mbuf *,
int, int));
static struct mbuf * rl2get __P((struct rl2_softc *, struct rl2_mm_cmd *,
int));
/* Card protocol-level functions. */
static int rl2_getenaddr __P((struct rl2_softc *, u_int8_t *));
static int rl2_getpromvers __P((struct rl2_softc *, char *, int));
static int rl2_setparam __P((struct rl2_softc *));
#if 0
static int rl2_roamconfig __P((struct rl2_softc *));
static int rl2_roam __P((struct rl2_softc *));
static int rl2_multicast __P((struct rl2_softc *, int));
static int rl2_searchsync __P((struct rl2_softc *));
#endif
#if notyet
static int rl2_iosetparam __P((struct rl2_softc *, struct rl2_param *));
static int rl2_lockprom __P((struct rl2_softc *));
static int rl2_ito __P((struct rl2_softc *));
static int rl2_standby __P((struct rl2_softc *));
#endif
/* Back-end attach and configure. */
void
rl2config(sc)
struct rl2_softc * sc;
{
struct ifnet * ifp = &sc->sc_arpcom.ac_if;
char promvers[7];
int i;
dprintf(" [attach %p]", sc);
/* Use the flags supplied from config. */
sc->sc_cardtype |= sc->sc_dev.dv_cfdata->cf_flags;
/* Initialise values in the soft state. */
sc->sc_pktseq = 0; /* rl2_newseq() */
sc->sc_txseq = 0;
sc->sc_promisc = 0;
/* Initialise user-configurable params. */
sc->sc_param.rp_roamconfig = RL2_ROAM_NORMAL;
sc->sc_param.rp_security = RL2_SECURITY_DEFAULT;
sc->sc_param.rp_stationtype = RL2_STATIONTYPE_ALTMASTER;
sc->sc_param.rp_domain = 0;
sc->sc_param.rp_channel = 1;
sc->sc_param.rp_subchannel = 1;
bzero(sc->sc_param.rp_master, sizeof sc->sc_param.rp_master);
#if notyet
/* XXX hostname not available at autoconf time! */
/* Use this host's name as a master name. */
bcopy(hostname, sc->sc_param.rp_master,
min(hostnamelen, sizeof sc->sc_param.rp_master));
#endif
/* Initialise the message mailboxes. */
for (i = 0; i < RL2_NMBOX; i++)
sc->sc_mbox[i].mb_state = RL2MBOX_VOID;
/* Keep the sys admin informed. */
printf(", %s-piece",
(sc->sc_cardtype & RL2_CTYPE_ONE_PIECE) ? "one" : "two");
if (sc->sc_cardtype & RL2_CTYPE_OEM)
printf(" oem");
if (sc->sc_cardtype & RL2_CTYPE_UISA)
printf(" micro-isa");
/* Probe/reset the card. */
if (rl2_probe(sc))
return;
/* Read the card's PROM revision. */
if (rl2_getpromvers(sc, promvers, sizeof promvers)) {
printf(": could not read PROM version\n");
return;
}
printf(", fw %.7s", promvers);
/* Fetch the card's MAC address. */
if (rl2_getenaddr(sc, sc->sc_arpcom.ac_enaddr)) {
printf(": could not read MAC address\n");
return;
}
printf(", addr %s", ether_sprintf(sc->sc_arpcom.ac_enaddr));
/* Attach as a network interface. */
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
ifp->if_softc = sc;
ifp->if_start = rl2start;
ifp->if_ioctl = rl2ioctl;
ifp->if_watchdog = rl2watchdog;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
if_attach(ifp);
ether_ifattach(ifp);
#if NBPFILTER > 0
bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof (struct ether_header));
#endif
}
/* Bring device up. */
static void
rl2init(sc)
struct rl2_softc * sc;
{
/* LLDInit() */
struct ifnet * ifp = &sc->sc_arpcom.ac_if;
dprintf(" [init]");
sc->sc_intsel = 0;
sc->sc_status = 0;
sc->sc_control = 0;
ifp->if_flags &= ~IFF_RUNNING;
ifp->if_flags &= ~IFF_OACTIVE;
/* Do a hard reset. */
if (rl2_reset(sc)) {
printf("%s: could not reset card\n", sc->sc_dev.dv_xname);
goto fail;
}
sc->sc_state = 0;
rl2_enable(sc, 1);
/* Initialise operational params. */
if (rl2_setparam(sc)) {
printf("%s: could not set card parameters\n",
sc->sc_dev.dv_xname);
goto fail;
}
#if 0
rl2_roamconfig(sc);
/* rl2_lockprom(sc); */ /* XXX error? */
/* SendSetITO() */
rl2_multicast(sc, 1);
rl2_roam(sc);
/* Synchronise with something. */
rl2_searchsync(sc);
#endif
ifp->if_flags |= IFF_RUNNING;
rl2start(ifp);
return;
fail:
ifp->if_flags &= ~IFF_UP;
return;
}
/* Start outputting on interface. This is always called at splnet(). */
static void
rl2start(ifp)
struct ifnet * ifp;
{
struct rl2_softc * sc = (struct rl2_softc *)ifp->if_softc;
struct mbuf * m0;
int len, pad, ret;
dprintf(" start[");
/* Don't transmit if interface is busy or not running. */
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) {
dprintf(" %s] ", (ifp->if_flags & IFF_OACTIVE) ?
"busy" : "stopped");
return;
}
/* Don't transmit if we are not synchronised. */
if ((sc->sc_state & RL2_STATE_SYNC) == 0) {
dprintf(" nosync]");
return;
}
startagain:
IF_DEQUEUE(&ifp->if_snd, m0);
if (m0 == NULL) {
dprintf(" empty]");
return;
}
#if NBPFILTER > 0
/* Tap packet stream here for BPF listeners. */
if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, m0);
#endif
/* We need to use m->m_pkthdr.len, so require the header. */
if ((m0->m_flags & M_PKTHDR) == 0) {
printf("%s: no mbuf header\n", sc->sc_dev.dv_xname);
goto oerror;
}
len = m0->m_pkthdr.len;
#define PACKETMIN (sizeof (struct ether_header) + ETHERMIN)
#define PACKETMAX (sizeof (struct ether_header) + ETHERMTU + 4)
/* Packet size has to be an even number between 60 and 1518 octets. */
pad = len & 1;
if (len + pad < PACKETMIN)
pad = PACKETMIN - len;
if (len + pad > PACKETMAX) {
printf("%s: packet too big (%d > %d)\n",
sc->sc_dev.dv_xname, len + pad,
PACKETMAX);
++ifp->if_oerrors;
m_freem(m0);
goto startagain;
}
ret = rl2_transmit(sc, m0, len, pad);
if (ret)
goto oerror;
ifp->if_flags |= IFF_OACTIVE;
m_freem(m0);
dprintf(" sent]");
return;
oerror:
++ifp->if_oerrors;
m_freem(m0);
/* XXX reset card, start again? */
return;
}
/* Transmit one packet. */
static int
rl2_transmit(sc, m0, len, pad)
struct rl2_softc * sc;
struct mbuf * m0;
int len;
int pad;
{
struct mbuf * m;
int zfirst;
int actlen;
int tlen = len + pad;
struct rl2_msg_tx_state state;
static u_int8_t zeroes[60];
struct rl2_mm_sendpacket cmd = { RL2_MM_SENDPACKET };
/* Does the packet start with a zero bit? */
zfirst = ((*mtod(m0, u_int8_t *) & 1) == 0);
cmd.mode =
RL2_MM_SENDPACKET_MODE_BIT7 |
(zfirst ? RL2_MM_SENDPACKET_MODE_ZFIRST : 0) |
(0 ? RL2_MM_SENDPACKET_MODE_QFSK : 0), /* sc->qfsk? */
cmd.power = 0x70; /* 0x70 or 0xf0 */
cmd.length_lo = htons(4 + tlen) & 0xff;
cmd.length_hi = (htons(4 + tlen) >> 8) & 0xff;
cmd.xxx1 = 0;
cmd.xxx2 = 0;
cmd.xxx3 = 0;
/* A unique packet-level sequence number. XXX related to sc_seq? */
cmd.sequence = sc->sc_txseq;
sc->sc_txseq++;
if (sc->sc_txseq > 0x7c)
sc->sc_txseq = 0;
dprintf(" T[%d+%d", len, pad);
if (rl2_msg_tx_start(sc, &cmd, sizeof cmd + tlen, &state))
goto error;
cmd.mm_cmd.cmd_seq = rl2_newseq(sc);
#ifdef RL2DUMP
printf("%s: send %c%d seq %d data ", sc->sc_dev.dv_xname,
cmd.mm_cmd.cmd_letter, cmd.mm_cmd.cmd_fn, cmd.mm_cmd.cmd_seq);
RL2DUMPHEX(&cmd, sizeof cmd);
printf(":");
#endif
rl2_msg_tx_data(sc, &cmd, sizeof cmd, &state);
actlen = 0;
for (m = m0; m; m = m->m_next) {
if (m->m_len) {
#ifdef RL2DUMP
RL2DUMPHEX(mtod(m, void *), m->m_len);
printf("|");
#endif
rl2_msg_tx_data(sc, mtod(m, void *), m->m_len, &state);
}
actlen += m->m_len;
}
#ifdef DIAGNOSTIC
if (actlen != len)
panic("rl2_transmit: len %d != %d", actlen, len);
if (pad > sizeof zeroes)
panic("rl2_transmit: pad %d > %d", pad, sizeof zeroes);
#endif
if (pad) {
#ifdef RL2DUMP
RL2DUMPHEX(zeroes, pad);
#endif
rl2_msg_tx_data(sc, zeroes, pad, &state);
}
#ifdef RL2DUMP
printf("\n");
#endif
if (rl2_msg_tx_end(sc, &state))
goto error;
return (0);
error:
dprintf(" error]");
return (-1);
}
/* (Supposedly) called when interrupts are suspiciously absent. */
static void
rl2watchdog(ifp)
struct ifnet * ifp;
{
struct rl2_softc * sc = (struct rl2_softc *)ifp->if_softc;
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
++sc->sc_arpcom.ac_if.if_oerrors;
rl2_reset(sc);
rl2_enable(sc, 1);
}
/* Handle single card interrupt. */
int
rl2intr(arg)
void * arg;
{
struct rl2_softc * sc = (struct rl2_softc *)arg;
extern int cold;
dprintf("!");
/* Tell card not to interrupt any more. */
rl2_enable(sc, 0);
if (cold)
/* During autoconfig - must handle interrupts now. */
rl2softintr(sc);
else
/* Handle later. */
timeout(rl2softintr, sc, 1);
return (1);
}
/* Process earlier card interrupt at splnetintr. */
static void
rl2softintr(arg)
void * arg;
{
struct rl2_softc *sc = (struct rl2_softc *)arg;
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
int len;
u_int8_t w;
struct rl2_mm_cmd hdr;
dprintf(" si(");
again:
/* Save wakeup state. */
w = rl2_wakeup(sc, RL2_WAKEUP_SET);
if ((len = rl2_rx_request(sc, 300)) < 0) {
/* Error in transfer. */
/* XXX need reset? */
rl2_rx_end(sc);
} else if (len < sizeof hdr) {
/* Short message. */
rl2_rx_end(sc);
printf("%s: short msg (%d)\n", sc->sc_dev.dv_xname, len);
ifp->if_ierrors++;
} else {
/* Valid message: read header and process. */
rl2_rx_data(sc, &hdr, sizeof hdr);
rl2read(sc, &hdr, len);
}
/* Ensure that wakeup state is unchanged if transmitting. */
if (ifp->if_flags & IFF_OACTIVE)
w |= RL2_WAKEUP_NOCHANGE;
rl2_wakeup(sc, w);
/* Check for more interrupts. */
if (rl2_status_rx_ready(sc))
goto again;
/* Some cards need this? */
rl2_eoi(sc);
/* Re-enable card. */
rl2_enable(sc, 1);
dprintf(")");
}
/* Read and process a message from the card. */
void
rl2read(sc, hdr, len)
struct rl2_softc *sc;
struct rl2_mm_cmd *hdr;
int len;
{
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
struct mbuf *m;
struct ether_header *eh;
u_int8_t data[1538];
u_int8_t *buf;
size_t buflen;
struct rl2_pdata pd = RL2_PDATA_INIT;
struct rl2_mm_synchronised * syncp = (struct rl2_mm_synchronised *)data;
dprintf(" [read]");
/* Were we waiting for this message? */
if (rl2_mbox_lock(sc, hdr->cmd_seq, (void **)&buf, &buflen) == 0) {
#ifdef DIAGNOSTIC
if (buflen < sizeof *hdr)
panic("rl2read buflen");
#endif
bcopy(hdr, buf, sizeof *hdr);
buf += sizeof *hdr;
len -= sizeof *hdr;
buflen -= sizeof *hdr;
if (len) {
if (len == buflen) /* Expected size */
rl2_rx_pdata(sc, buf, len, &pd);
else if (len < buflen) { /* Underfill */
#ifdef DIAGNOSTIC
printf("%s: underfill %d<%d, cmd %c%d\n",
sc->sc_dev.dv_xname,
len, buflen,
hdr->cmd_letter, hdr->cmd_fn);
#endif
rl2_rx_pdata(sc, buf, len, &pd);
} else { /* Overflow */
#ifdef DIAGNOSTIC
printf("%s: overflow %d>%d, cmd %c%d\n",
sc->sc_dev.dv_xname,
len, buflen,
hdr->cmd_letter, hdr->cmd_fn);
#endif
rl2_rx_pdata(sc, buf, buflen, &pd);
/* Drain the rest somewhere. */
rl2_rx_pdata(sc, data, len - buflen, &pd);
}
}
rl2_rx_end(sc);
/* This message can now be handled by the waiter. */
rl2_mbox_unlock(sc, hdr->cmd_seq, len + sizeof *hdr);
return;
}
/* Otherwise, handle the message right here, right now. */
/* Check if we can cope with the size of this message. */
if (len > sizeof data) {
printf("%s: big msg (%d)\n", sc->sc_dev.dv_xname, len);
ifp->if_ierrors++;
rl2_rx_end(sc);
/* XXX may need reset */
return;
}
/* Check for error results. */
if (hdr->cmd_error & 0x80) {
printf("%s: command error 0x%02x command %c%d len=%d\n",
sc->sc_dev.dv_xname,
hdr->cmd_error & 0x7f,
hdr->cmd_letter, hdr->cmd_fn,
len);
ifp->if_ierrors++;
rl2_rx_end(sc);
/* XXX may need reset */
return;
}
/*
* "b1": Receiving a packet is a special case.
* We wish to read the data with pio straight into an
* mbuf to avoid a memory-memory copy.
*/
if (hdr->cmd_letter == 'b' && hdr->cmd_fn == 1) {
m = rl2get(sc, hdr, len);
rl2_rx_end(sc);
if (m == NULL)
return;
ifp->if_ipackets++;
#ifdef DIAGNOSTIC
if (bcmp(mtod(m, u_int8_t *), "prox", 4) == 0) {
printf("%s: proxim special packet received\n",
sc->sc_dev.dv_xname);
}
#endif
/* XXX Jean's driver dealt with RFC893 trailers here */
eh = mtod(m, struct ether_header *);
#if NBPFILTER > 0
if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, m);
#endif
m_adj(m, sizeof (struct ether_header));
ether_input(ifp, eh, m);
return;
}
/* Otherwise we read the packet into a buffer on the stack. */
bcopy(hdr, data, sizeof *hdr);
if (len > sizeof *hdr)
rl2_rx_pdata(sc, data + sizeof *hdr, len - sizeof *hdr, &pd);
rl2_rx_end(sc);
#ifdef RL2DUMP
printf("%s: recv %c%d seq %d data ", sc->sc_dev.dv_xname,
hdr->cmd_letter, hdr->cmd_fn, hdr->cmd_seq);
RL2DUMPHEX(hdr, sizeof hdr);
printf(":");
RL2DUMPHEX(data + sizeof hdr, len - sizeof hdr);
printf("\n");
#endif
switch (RL2_MM_CMD(hdr->cmd_letter, hdr->cmd_fn)) {
case RL2_MM_CMD('b', 0): /* b0: Transmit done. */
#ifdef DIAGNOSTIC
if (len != 7)
printf("%s: 'b0' len %d != 7\n",
sc->sc_dev.dv_xname, len);
#endif
ifp->if_flags &= ~IFF_OACTIVE;
ifp->if_opackets++;
rl2start(ifp);
break;
case RL2_MM_CMD('a', 20): /* a20: Card fault. */
printf("%s: hardware fault\n", sc->sc_dev.dv_xname);
/* Bring it down. */
rl2stop(sc);
ifp->if_oerrors++;
if_down(ifp); /* The next if_up() will cause a hard reset. */
break;
case RL2_MM_CMD('a', 4): /* a4: Sync'd. */
if (bcmp(syncp->enaddr, sc->sc_arpcom.ac_enaddr,
ETHER_ADDR_LEN) == 0) {
/* Sync'd to own enaddr. */
printf("%s: nothing to sync to; now master ",
sc->sc_dev.dv_xname);
}
else
printf("%s: synchronised to ", sc->sc_dev.dv_xname);
printf("%.11s (%s) channel %d/%d\n",
syncp->mastername,
ether_sprintf(syncp->enaddr),
syncp->channel,
syncp->subchannel);
/* Record the new circumstances. */
sc->sc_param.rp_channel = syncp->channel;
sc->sc_param.rp_subchannel = syncp->subchannel;
sc->sc_state |= RL2_STATE_SYNC;
/* Resume sending. */
rl2start(ifp);
break;
case RL2_MM_CMD('a', 5): /* a4: Lost sync. */
printf("%s: lost sync\n", sc->sc_dev.dv_xname);
sc->sc_state &= ~RL2_STATE_SYNC;
break;
case RL2_MM_CMD('a', 18): /* a18: Roaming. */
printf("%s: roaming\n", sc->sc_dev.dv_xname);
break;
default:
#ifdef DIAGNOSTIC
printf("%s: msg `%c%d' seq %d data {",
sc->sc_dev.dv_xname,
hdr->cmd_letter, hdr->cmd_fn, hdr->cmd_seq);
RL2DUMPHEX(hdr, sizeof hdr);
printf(":");
RL2DUMPHEX(data, len);
printf("}\n");
#endif
break;
}
}
/* Extract a received network packet from the card. */
static struct mbuf *
rl2get(sc, hdr, totlen)
struct rl2_softc *sc;
struct rl2_mm_cmd *hdr;
int totlen;
{
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
int len;
struct mbuf *m, **mp, *top;
struct rl2_pdata pd = RL2_PDATA_INIT;
u_int8_t hwhdr[20];
dprintf(" [get]");
#ifdef RL2DUMP
printf("%s: recv %c%d seq %d data ", sc->sc_dev.dv_xname,
hdr->cmd_letter, hdr->cmd_fn, hdr->cmd_seq);
RL2DUMPHEX(hdr, sizeof hdr);
printf(":");
#endif
totlen -= sizeof *hdr;
#ifdef DIAGNOSTIC
if (totlen <= 0) {
printf("%s: empty packet", sc->sc_dev.dv_xname);
goto drop;
}
#endif
totlen -= sizeof hwhdr;
/* Skip the hardware header. */
rl2_rx_pdata(sc, hwhdr, sizeof hwhdr, &pd);
#ifdef RL2DUMP
RL2DUMPHEX(hwhdr, sizeof hwhdr);
printf("/");
#endif
/* (Most of the following code fleeced from elink3.c.) */
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL)
goto drop;
m->m_pkthdr.rcvif = ifp;
m->m_pkthdr.len = totlen;
len = MHLEN;
top = 0;
mp = ⊤
while (totlen > 0) {
if (top) {
MGET(m, M_DONTWAIT, MT_DATA);
if (!m) {
m_freem(top);
goto drop;
}
len = MLEN;
}
if (top && totlen >= MINCLSIZE) {
MCLGET(m, M_DONTWAIT);
if (m->m_flags & M_EXT)
len = MCLBYTES;
}
len = min(totlen, len);
rl2_rx_pdata(sc, mtod(m, u_int8_t *), len, &pd);
#ifdef RL2DUMP
RL2DUMPHEX(mtod(m, u_int8_t *), len);
if (totlen != len)
printf("|");
#endif
m->m_len = len;
totlen -= len;
*mp = m;
mp = &m->m_next;
}
#ifdef RL2DUMP
printf("\n");
#endif
return m;
drop:
#ifdef RL2DUMP
printf(": drop\n");
#endif
ifp->if_iqdrops++;
return NULL;
}
/* Interface control. */
static int
rl2ioctl(ifp, cmd, data)
struct ifnet *ifp;
u_long cmd;
caddr_t data;
{
struct rl2_softc *sc = ifp->if_softc;
struct ifaddr *ifa = (struct ifaddr *)data;
int s, error = 0;
s = splnet();
if ((error = ether_ioctl(ifp, &sc->sc_arpcom, cmd, data)) > 0) {
splx(s);
return error;
}
switch (cmd) {
case SIOCSIFADDR:
/* Set address. */
ifp->if_flags |= IFF_UP;
switch (ifa->ifa_addr->sa_family) {
#ifdef INET
case AF_INET:
rl2init(sc);
arp_ifinit(&sc->sc_arpcom, ifa);
break;
#endif
default:
rl2init(sc);
break;
}
break;
case SIOCSIFFLAGS:
if ((ifp->if_flags & IFF_UP) == 0 &&
(ifp->if_flags & IFF_RUNNING) != 0) {
/* Was running, want down: stop. */
rl2stop(sc);
} else if ((ifp->if_flags & IFF_UP) != 0 &&
(ifp->if_flags & IFF_RUNNING) == 0) {
/* Was not running, want up: start. */
rl2init(sc);
}
if ((ifp->if_flags & IFF_RUNNING) != 0 &&
((ifp->if_flags & IFF_PROMISC) != sc->sc_promisc)) {
/* Promiscuity changed. */
sc->sc_promisc = ifp->if_flags & IFF_PROMISC;
rl2_setparam(sc);
}
/* XXX Deal with other flag changes? */
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
return (EOPNOTSUPP);
/* XXX There should be a way to change the channel & secid here. */
default:
error = EINVAL;
break;
}
splx(s);
return (error);
}
/* Stop output from the card. */
static void
rl2stop(sc)
struct rl2_softc *sc;
{
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
dprintf(" [stop]");
/* XXX Should kill interrupts? */
/* rl2_enable(sc, 0); */
ifp->if_flags &= ~IFF_RUNNING;
}
/* Test for existence of card. */
static int
rl2_probe(sc)
struct rl2_softc *sc;
{
dprintf(" [probe]");
/* If we can reset it, it's there. */
return(rl2_reset(sc));
}
/* Get MAC address from card. */
static int
rl2_getenaddr(sc, enaddr)
struct rl2_softc *sc;
u_int8_t * enaddr;
{
struct rl2_mm_cmd query = RL2_MM_GETENADDR;
struct rl2_mm_gotenaddr response = { RL2_MM_GETENADDR };
if (rl2_msg_txrx(sc, &query, sizeof query,
&response, sizeof response))
return (-1);
bcopy(response.enaddr, enaddr, sizeof response.enaddr);
return (0);
};
/* Get firmware version string from card. */
static int
rl2_getpromvers(sc, ver, verlen)
struct rl2_softc *sc;
char *ver;
int verlen;
{
struct rl2_mm_cmd query = RL2_MM_GETPROMVERSION;
struct rl2_mm_gotpromversion response = { RL2_MM_GOTPROMVERSION };
int i;
#ifdef DIAGNOSTIC
if (verlen != sizeof response.version)
panic("rl2_getpromvers");
#endif
if (rl2_msg_txrx(sc, &query, sizeof query,
&response, sizeof response))
return (-1);
bcopy(response.version, ver, verlen);
/* Nul trailing spaces. */
for (i = verlen - 1; i >= 0 && ver[i] <= ' '; i--)
ver[i] = '\0';
return (0);
};
/* Set default operational parameters on card. */
static int
rl2_setparam(sc)
struct rl2_softc *sc;
{
struct rl2_mm_setparam param = { RL2_MM_SETPARAM };
struct rl2_mm_paramset presponse;
#if 0
struct rl2_mm_setmagic magic = { RL2_MM_SETMAGIC };
struct rl2_mm_disablehopping hop = { RL2_MM_DISABLEHOPPING };
struct rl2_mm_cmd response;
#endif
bzero((char*)¶m + sizeof param.mm_cmd,
sizeof param - sizeof param.mm_cmd);
dprintf(" [setting parameters]");
param.opmode = (sc->sc_promisc ? RL2_MM_SETPARAM_OPMODE_PROMISC :
RL2_MM_SETPARAM_OPMODE_NORMAL);
param.stationtype = sc->sc_param.rp_stationtype;
/* Spread-spectrum frequency hopping. */
param.hop_period = 1;
param.bfreq = 2;
param.sfreq = 7;
/* Choose channel. */
param.channel = sc->sc_param.rp_channel;
param.subchannel = sc->sc_param.rp_subchannel;
param.domain = sc->sc_param.rp_domain;
/* Name of this station when acting as master. */
bcopy(sc->sc_param.rp_master, param.mastername, sizeof param.mastername);
/* Security params. */
param.sec1 = (sc->sc_param.rp_security & 0x0000ff) >> 0;
param.sec2 = (sc->sc_param.rp_security & 0x00ff00) >> 8;
param.sec3 = (sc->sc_param.rp_security & 0xff0000) >> 16;
param.sync_to = 1;
bzero(param.syncname, sizeof param.syncname);
if (rl2_msg_txrx(sc, ¶m, sizeof param,
&presponse, sizeof presponse))
return (-1);
#if 0
dprintf(" [setting magic]");
magic.fairness_slot = 3; /* lite: 1, norm: 3, off: -1 */
magic.deferral_slot = 3; /* lite: 0, norm: 3, off: -1 */
magic.regular_mac_retry = 7;
magic.frag_mac_retry = 10;
magic.regular_mac_qfsk = 2;
magic.frag_mac_qfsk = 5;
magic.xxx1 = 0xff;
magic.xxx2 = 0xff;
magic.xxx3 = 0xff;
magic.xxx4 = 0x00;
if (rl2_msg_txrx(sc, &magic, sizeof magic,
&response, sizeof response))
return (-1);
dprintf(" [disabling freq hopping]");
hop.hopflag = RL2_MM_DISABLEHOPPING_HOPFLAG_DISABLE;
if (rl2_msg_txrx(sc, &hop, sizeof hop,
&response, sizeof response))
return (-1);
#endif
return (0);
}
#if 0
/* Configure the way the card leaves a basestation. */
static int
rl2_roamconfig(sc)
struct rl2_softc *sc;
{
struct rl2_mm_setroaming roam = { RL2_MM_SETROAMING };
struct rl2_mm_cmd response;
static int retry[3] = { 6, 6, 4 };
static int rssi[3] = { 5, 15, 5 };
dprintf(" [roamconfig]");
#ifdef DIAGNOSTIC
if (sc->sc_param.rp_roamconfig > 2)
panic("roamconfig");
#endif
roam.sync_alarm = 0;
roam.retry_thresh = retry[sc->sc_param.rp_roamconfig];
roam.rssi_threshold = rssi[sc->sc_param.rp_roamconfig];
roam.xxx1 = 0x5a;
roam.sync_rssi_threshold = 0;
roam.xxx2 = 0x5a;
roam.missed_sync = 0x4;
if (rl2_msg_txrx(sc, &roam, sizeof roam,
&response, sizeof response))
return (-1);
return (0);
}
/* Enable roaming. */
static int
rl2_roam(sc)
struct rl2_softc *sc;
{
struct rl2_mm_cmd roam = RL2_MM_ROAM;
struct rl2_mm_cmd response;
return (rl2_msg_txrx(sc, &roam, sizeof roam,
&response, sizeof response));
}
/* Enable multicast capability. */
static int
rl2_multicast(sc, enable)
struct rl2_softc *sc;
int enable;
{
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
struct rl2_mm_multicast mcast = { RL2_MM_MULTICAST };
struct rl2_mm_cmd response;
int ret;
mcast.enable = enable;
ret = rl2_msg_txrx(sc, &mcast, sizeof mcast,
&response, sizeof response);
if (ret == 0) {
if (enable)
ifp->if_flags |= IFF_MULTICAST;
else
ifp->if_flags &= ~IFF_MULTICAST;
}
return (ret);
}
/* Search for and sync with any master. */
static int
rl2_searchsync(sc)
struct rl2_softc *sc;
{
struct rl2_mm_search search = { RL2_MM_SEARCH };
struct rl2_mm_searching response;
bzero(search.xxx1, sizeof search.xxx1);
search.domain = sc->sc_param.rp_domain;
search.roaming = 1;
search.xxx3 = 0;
search.xxx4 = 1;
search.xxx5 = 0;
bzero(search.xxx6, sizeof search.xxx6);
return (rl2_msg_txrx(sc, &search, sizeof search,
&response, sizeof response));
}
#endif
#if notyet /* unused */
/* Set values from an external parameter block. */
static int
rl2_iosetparam(sc, param)
struct rl2_softc *sc;
struct rl2_param *param;
{
int error = 0;
if (param->rp_roamconfig > 2)
error = EINVAL;
if (param->rp_security > 0x00ffffff)
error = EINVAL;
if (param->rp_stationtype > 2)
error = EINVAL;
if (param->rp_channel > 15)
error = EINVAL;
if (param->rp_subchannel > 15)
error = EINVAL;
if (error == 0) {
/* Apply immediately. */
bcopy(param, &sc->sc_param, sizeof *param);
if (rl2_setparam(sc))
error = EIO;
}
return (error);
}
/* Protect the eeprom from storing a security ID(?) */
static int
rl2_lockprom(sc)
struct rl2_softc *sc;
{
struct rl2_mm_cmd lock = RL2_MM_EEPROM_PROTECT;
struct rl2_mm_cmd response;
/* XXX Always yields an error? */
return (rl2_msg_txrx(sc, &lock, sizeof lock,
&response, sizeof response));
}
/* Set the h/w Inactivity Time Out timer on the card. */
static int
rl2_ito(sc)
struct rl2_softc * sc;
{
struct rl2_mm_setito ito = { RL2_MM_MULTICAST };
struct rl2_mm_cmd response;
ito.xxx = 3;
ito.timeout = LLDInactivityTimeOut /* enabler, 0 or 1 */;
ito.bd_wakeup = LLDBDWakeup /* 0 */;
ito.pm_sync = LLDPMSync /* 0 */;
ito.sniff_time = ito.timeout ? LLDSniffTime /* 0 */ : 0;
if (rl2_msg_txrx(sc, &ito, sizeof ito,
&response, sizeof response))
return (-1);
}
/* Put the card into standby mode. */
static int
rl2_standby(sc)
struct rl2_softc * sc;
{
struct rl2_mm_standby standby = { RL2_MM_STANDBY };
standby.xxx = 0;
if (rl2_msg_txrx(sc, &ito, sizeof ito, NULL, 0))
return (-1);
}
#endif
|