2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Purpose: MAC routines
41 /*--------------------- Static Definitions -------------------------*/
42 //static int msglevel =MSG_LEVEL_DEBUG;
43 static int msglevel
=MSG_LEVEL_INFO
;
44 /*--------------------- Static Classes ----------------------------*/
46 /*--------------------- Static Variables --------------------------*/
48 /*--------------------- Static Functions --------------------------*/
50 /*--------------------- Export Variables --------------------------*/
52 /*--------------------- Export Functions --------------------------*/
60 * Set this hash index into multicast address register bit
64 * byHashIdx - Hash index to set
71 void MACvSetMultiAddrByHash (PSDevice pDevice
, BYTE byHashIdx
)
73 unsigned int uByteIdx
;
78 // calculate byte position
79 uByteIdx
= byHashIdx
/ 8;
81 // calculate bit position
83 byBitMask
<<= (byHashIdx
% 8);
86 pbyData
[0] = byBitMask
;
87 pbyData
[1] = byBitMask
;
89 CONTROLnsRequestOut(pDevice
,
90 MESSAGE_TYPE_WRITE_MASK
,
91 (WORD
) (MAC_REG_MAR0
+ uByteIdx
),
92 MESSAGE_REQUEST_MACREG
,
101 * Write MAC Multicast Address Mask
105 * uByteidx - Index of Mask
106 * byData - Mask Value to write
113 void MACvWriteMultiAddr(PSDevice pDevice
, unsigned int uByteIdx
, BYTE byData
)
118 CONTROLnsRequestOut(pDevice
,
120 (WORD
) (MAC_REG_MAR0
+ uByteIdx
),
121 MESSAGE_REQUEST_MACREG
,
136 * Return Value: TRUE if success; otherwise FALSE
139 BOOL
MACbShutdown (PSDevice pDevice
)
141 CONTROLnsRequestOutAsyn(pDevice
,
142 MESSAGE_TYPE_MACSHUTDOWN
,
151 void MACvSetBBType(PSDevice pDevice
,BYTE byType
)
157 pbyData
[1] = EnCFG_BBType_MASK
;
159 CONTROLnsRequestOut(pDevice
,
160 MESSAGE_TYPE_WRITE_MASK
,
162 MESSAGE_REQUEST_MACREG
,
168 void MACvSetMISCFifo (PSDevice pDevice
, WORD wOffset
, DWORD dwData
)
174 pbyData
[0] = (BYTE
)dwData
;
175 pbyData
[1] = (BYTE
)(dwData
>>8);
176 pbyData
[2] = (BYTE
)(dwData
>>16);
177 pbyData
[3] = (BYTE
)(dwData
>>24);
179 CONTROLnsRequestOut(pDevice
,
180 MESSAGE_TYPE_WRITE_MISCFF
,
190 * Disable the Key Entry by MISCFIFO
194 * dwIoBase - Base Address for MAC
202 void MACvDisableKeyEntry(PSDevice pDevice
, unsigned int uEntryIdx
)
208 byData
= (BYTE
) uEntryIdx
;
210 wOffset
= MISCFIFO_KEYETRY0
;
211 wOffset
+= (uEntryIdx
* MISCFIFO_KEYENTRYSIZE
);
213 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
214 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
215 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
217 //issue write misc fifo command to device
218 CONTROLnsRequestOut(pDevice
,
219 MESSAGE_TYPE_CLRKEYENTRY
,
230 * Set the Key by MISCFIFO
234 * dwIoBase - Base Address for MAC
242 void MACvSetKeyEntry(PSDevice pDevice
, WORD wKeyCtl
,
243 unsigned int uEntryIdx
, unsigned int uKeyIdx
,
244 PBYTE pbyAddr
, PDWORD pdwKey
)
248 DWORD dwData1
,dwData2
;
252 if ( pDevice
->byLocalID
<= MAC_REVISION_A1
) {
253 if ( pDevice
->sMgmtObj
.byCSSPK
== KEY_CTL_CCMP
)
257 wOffset
= MISCFIFO_KEYETRY0
;
258 wOffset
+= (uEntryIdx
* MISCFIFO_KEYENTRYSIZE
);
263 dwData1
|= MAKEWORD(*(pbyAddr
+4), *(pbyAddr
+5));
265 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset
, dwData1
, wKeyCtl
);
267 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
268 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
269 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
274 dwData2
|= *(pbyAddr
+3);
276 dwData2
|= *(pbyAddr
+2);
278 dwData2
|= *(pbyAddr
+1);
280 dwData2
|= *(pbyAddr
+0);
282 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"2. wOffset: %d, Data: %lX\n", wOffset
, dwData2
);
284 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
285 //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
286 //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
290 //wOffset += (uKeyIdx * 4);
291 /* for (ii=0;ii<4;ii++) {
292 // alway push 128 bits
293 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
294 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
295 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
296 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
299 pbyKey
= (PBYTE
)pdwKey
;
301 pbyData
[0] = (BYTE
)dwData1
;
302 pbyData
[1] = (BYTE
)(dwData1
>>8);
303 pbyData
[2] = (BYTE
)(dwData1
>>16);
304 pbyData
[3] = (BYTE
)(dwData1
>>24);
305 pbyData
[4] = (BYTE
)dwData2
;
306 pbyData
[5] = (BYTE
)(dwData2
>>8);
307 pbyData
[6] = (BYTE
)(dwData2
>>16);
308 pbyData
[7] = (BYTE
)(dwData2
>>24);
309 for (ii
= 8; ii
< 24; ii
++)
310 pbyData
[ii
] = *pbyKey
++;
312 CONTROLnsRequestOut(pDevice
,
324 void MACvRegBitsOff(PSDevice pDevice
, BYTE byRegOfs
, BYTE byBits
)
331 CONTROLnsRequestOut(pDevice
,
332 MESSAGE_TYPE_WRITE_MASK
,
334 MESSAGE_REQUEST_MACREG
,
341 void MACvRegBitsOn(PSDevice pDevice
, BYTE byRegOfs
, BYTE byBits
)
349 CONTROLnsRequestOut(pDevice
,
350 MESSAGE_TYPE_WRITE_MASK
,
352 MESSAGE_REQUEST_MACREG
,
358 void MACvWriteWord(PSDevice pDevice
, BYTE byRegOfs
, WORD wData
)
363 pbyData
[0] = (BYTE
)(wData
& 0xff);
364 pbyData
[1] = (BYTE
)(wData
>> 8);
366 CONTROLnsRequestOut(pDevice
,
369 MESSAGE_REQUEST_MACREG
,
376 void MACvWriteBSSIDAddress(PSDevice pDevice
, PBYTE pbyEtherAddr
)
381 pbyData
[0] = *((PBYTE
)pbyEtherAddr
);
382 pbyData
[1] = *((PBYTE
)pbyEtherAddr
+1);
383 pbyData
[2] = *((PBYTE
)pbyEtherAddr
+2);
384 pbyData
[3] = *((PBYTE
)pbyEtherAddr
+3);
385 pbyData
[4] = *((PBYTE
)pbyEtherAddr
+4);
386 pbyData
[5] = *((PBYTE
)pbyEtherAddr
+5);
388 CONTROLnsRequestOut(pDevice
,
391 MESSAGE_REQUEST_MACREG
,
397 void MACvEnableProtectMD(PSDevice pDevice
)
402 pbyData
[0] = EnCFG_ProtectMd
;
403 pbyData
[1] = EnCFG_ProtectMd
;
405 CONTROLnsRequestOut(pDevice
,
406 MESSAGE_TYPE_WRITE_MASK
,
408 MESSAGE_REQUEST_MACREG
,
414 void MACvDisableProtectMD(PSDevice pDevice
)
420 pbyData
[1] = EnCFG_ProtectMd
;
422 CONTROLnsRequestOut(pDevice
,
423 MESSAGE_TYPE_WRITE_MASK
,
425 MESSAGE_REQUEST_MACREG
,
431 void MACvEnableBarkerPreambleMd(PSDevice pDevice
)
436 pbyData
[0] = EnCFG_BarkerPream
;
437 pbyData
[1] = EnCFG_BarkerPream
;
439 CONTROLnsRequestOut(pDevice
,
440 MESSAGE_TYPE_WRITE_MASK
,
442 MESSAGE_REQUEST_MACREG
,
448 void MACvDisableBarkerPreambleMd(PSDevice pDevice
)
454 pbyData
[1] = EnCFG_BarkerPream
;
456 CONTROLnsRequestOut(pDevice
,
457 MESSAGE_TYPE_WRITE_MASK
,
459 MESSAGE_REQUEST_MACREG
,
466 void MACvWriteBeaconInterval(PSDevice pDevice
, WORD wInterval
)
470 pbyData
[0] = (BYTE
) (wInterval
& 0xff);
471 pbyData
[1] = (BYTE
) (wInterval
>> 8);
473 CONTROLnsRequestOut(pDevice
,
476 MESSAGE_REQUEST_MACREG
,