Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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. |
| 18 | * |
| 19 | * |
| 20 | * File: mac.c |
| 21 | * |
| 22 | * Purpose: MAC routines |
| 23 | * |
| 24 | * Author: Tevin Chen |
| 25 | * |
| 26 | * Date: May 21, 1996 |
| 27 | * |
| 28 | * Functions: |
| 29 | * |
| 30 | * Revision History: |
| 31 | */ |
| 32 | |
| 33 | |
| 34 | |
| 35 | #if !defined(__TMACRO_H__) |
| 36 | #include "tmacro.h" |
| 37 | #endif |
| 38 | #if !defined(__TBIT_H__) |
| 39 | #include "tbit.h" |
| 40 | #endif |
| 41 | #if !defined(__TETHER_H__) |
| 42 | #include "tether.h" |
| 43 | #endif |
| 44 | #if !defined(__DESC_H__) |
| 45 | #include "desc.h" |
| 46 | #endif |
| 47 | #if !defined(__MAC_H__) |
| 48 | #include "mac.h" |
| 49 | #endif |
| 50 | #if !defined(__80211hdr_H__) |
| 51 | #include "80211hdr.h" |
| 52 | #endif |
| 53 | #if !defined(__RNDIS_H__) |
| 54 | #include "rndis.h" |
| 55 | #endif |
| 56 | #if !defined(__CONTROL_H__) |
| 57 | #include "control.h" |
| 58 | #endif |
| 59 | /*--------------------- Static Definitions -------------------------*/ |
| 60 | //static int msglevel =MSG_LEVEL_DEBUG; |
| 61 | static int msglevel =MSG_LEVEL_INFO; |
| 62 | /*--------------------- Static Classes ----------------------------*/ |
| 63 | |
| 64 | /*--------------------- Static Variables --------------------------*/ |
| 65 | |
| 66 | /*--------------------- Static Functions --------------------------*/ |
| 67 | |
| 68 | /*--------------------- Export Variables --------------------------*/ |
| 69 | |
| 70 | /*--------------------- Export Functions --------------------------*/ |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | * Description: |
| 78 | * Set this hash index into multicast address register bit |
| 79 | * |
| 80 | * Parameters: |
| 81 | * In: |
| 82 | * byHashIdx - Hash index to set |
| 83 | * Out: |
| 84 | * none |
| 85 | * |
| 86 | * Return Value: none |
| 87 | * |
| 88 | */ |
| 89 | void MACvSetMultiAddrByHash (PSDevice pDevice, BYTE byHashIdx) |
| 90 | { |
| 91 | UINT uByteIdx; |
| 92 | BYTE byBitMask; |
| 93 | BYTE pbyData[2]; |
| 94 | |
| 95 | |
| 96 | // calculate byte position |
| 97 | uByteIdx = byHashIdx / 8; |
| 98 | |
| 99 | // calculate bit position |
| 100 | byBitMask = 1; |
| 101 | byBitMask <<= (byHashIdx % 8); |
| 102 | // turn on the bit |
| 103 | |
| 104 | pbyData[0] = byBitMask; |
| 105 | pbyData[1] = byBitMask; |
| 106 | |
| 107 | CONTROLnsRequestOut(pDevice, |
| 108 | MESSAGE_TYPE_WRITE_MASK, |
| 109 | (WORD) (MAC_REG_MAR0 + uByteIdx), |
| 110 | MESSAGE_REQUEST_MACREG, |
| 111 | 2, |
| 112 | pbyData); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | |
| 117 | /* |
| 118 | * Description: |
| 119 | * Write MAC Multicast Address Mask |
| 120 | * |
| 121 | * Parameters: |
| 122 | * In: |
| 123 | * uByteidx - Index of Mask |
| 124 | * byData - Mask Value to write |
| 125 | * Out: |
| 126 | * none |
| 127 | * |
| 128 | * Return Value: none |
| 129 | * |
| 130 | */ |
| 131 | VOID MACvWriteMultiAddr (PSDevice pDevice, UINT uByteIdx, BYTE byData) |
| 132 | { |
| 133 | BYTE byData1; |
| 134 | |
| 135 | byData1 = byData; |
| 136 | CONTROLnsRequestOut(pDevice, |
| 137 | MESSAGE_TYPE_WRITE, |
| 138 | (WORD) (MAC_REG_MAR0 + uByteIdx), |
| 139 | MESSAGE_REQUEST_MACREG, |
| 140 | 1, |
| 141 | &byData1); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /* |
| 146 | * Description: |
| 147 | * Shut Down MAC |
| 148 | * |
| 149 | * Parameters: |
| 150 | * In: |
| 151 | * Out: |
| 152 | * none |
| 153 | * |
| 154 | * Return Value: TRUE if success; otherwise FALSE |
| 155 | * |
| 156 | */ |
| 157 | BOOL MACbShutdown (PSDevice pDevice) |
| 158 | { |
| 159 | CONTROLnsRequestOutAsyn(pDevice, |
| 160 | MESSAGE_TYPE_MACSHUTDOWN, |
| 161 | 0, |
| 162 | 0, |
| 163 | 0, |
| 164 | NULL |
| 165 | ); |
| 166 | return TRUE; |
| 167 | } |
| 168 | |
| 169 | void MACvSetBBType(PSDevice pDevice,BYTE byType) |
| 170 | { |
| 171 | BYTE pbyData[2]; |
| 172 | |
| 173 | |
| 174 | pbyData[0] = byType; |
| 175 | pbyData[1] = EnCFG_BBType_MASK; |
| 176 | |
| 177 | CONTROLnsRequestOut(pDevice, |
| 178 | MESSAGE_TYPE_WRITE_MASK, |
| 179 | MAC_REG_ENCFG0, |
| 180 | MESSAGE_REQUEST_MACREG, |
| 181 | 2, |
| 182 | pbyData |
| 183 | ); |
| 184 | } |
| 185 | |
| 186 | void MACvSetMISCFifo (PSDevice pDevice, WORD wOffset, DWORD dwData) |
| 187 | { |
| 188 | BYTE pbyData[4]; |
| 189 | |
| 190 | if (wOffset > 273) |
| 191 | return; |
| 192 | pbyData[0] = (BYTE)dwData; |
| 193 | pbyData[1] = (BYTE)(dwData>>8); |
| 194 | pbyData[2] = (BYTE)(dwData>>16); |
| 195 | pbyData[3] = (BYTE)(dwData>>24); |
| 196 | |
| 197 | CONTROLnsRequestOut(pDevice, |
| 198 | MESSAGE_TYPE_WRITE_MISCFF, |
| 199 | wOffset, |
| 200 | 0, |
| 201 | 4, |
| 202 | pbyData |
| 203 | ); |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Description: |
| 208 | * Disable the Key Entry by MISCFIFO |
| 209 | * |
| 210 | * Parameters: |
| 211 | * In: |
| 212 | * dwIoBase - Base Address for MAC |
| 213 | * |
| 214 | * Out: |
| 215 | * none |
| 216 | * |
| 217 | * Return Value: none |
| 218 | * |
| 219 | */ |
| 220 | void MACvDisableKeyEntry (PSDevice pDevice, UINT uEntryIdx) |
| 221 | { |
| 222 | WORD wOffset; |
| 223 | BYTE byData; |
| 224 | |
| 225 | |
| 226 | byData = (BYTE) uEntryIdx; |
| 227 | |
| 228 | wOffset = MISCFIFO_KEYETRY0; |
| 229 | wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE); |
| 230 | |
| 231 | //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset); |
| 232 | //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0); |
| 233 | //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE); |
| 234 | |
| 235 | //issue write misc fifo command to device |
| 236 | CONTROLnsRequestOut(pDevice, |
| 237 | MESSAGE_TYPE_CLRKEYENTRY, |
| 238 | 0, |
| 239 | 0, |
| 240 | 1, |
| 241 | &byData |
| 242 | ); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /* |
| 247 | * Description: |
| 248 | * Set the Key by MISCFIFO |
| 249 | * |
| 250 | * Parameters: |
| 251 | * In: |
| 252 | * dwIoBase - Base Address for MAC |
| 253 | * |
| 254 | * Out: |
| 255 | * none |
| 256 | * |
| 257 | * Return Value: none |
| 258 | * |
| 259 | */ |
| 260 | void MACvSetKeyEntry (PSDevice pDevice, WORD wKeyCtl, UINT uEntryIdx, UINT uKeyIdx, PBYTE pbyAddr, PDWORD pdwKey) |
| 261 | { |
| 262 | PBYTE pbyKey; |
| 263 | WORD wOffset; |
| 264 | DWORD dwData1,dwData2; |
| 265 | int ii; |
| 266 | BYTE pbyData[24]; |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | if ( pDevice->byLocalID <= MAC_REVISION_A1 ) { |
| 273 | if ( pDevice->sMgmtObj.byCSSPK == KEY_CTL_CCMP ) |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | wOffset = MISCFIFO_KEYETRY0; |
| 278 | wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE); |
| 279 | |
| 280 | dwData1 = 0; |
| 281 | dwData1 |= wKeyCtl; |
| 282 | dwData1 <<= 16; |
| 283 | dwData1 |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5)); |
| 284 | |
| 285 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData1, wKeyCtl); |
| 286 | |
| 287 | //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset); |
| 288 | //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData); |
| 289 | //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE); |
| 290 | |
| 291 | //wOffset++; |
| 292 | |
| 293 | dwData2 = 0; |
| 294 | dwData2 |= *(pbyAddr+3); |
| 295 | dwData2 <<= 8; |
| 296 | dwData2 |= *(pbyAddr+2); |
| 297 | dwData2 <<= 8; |
| 298 | dwData2 |= *(pbyAddr+1); |
| 299 | dwData2 <<= 8; |
| 300 | dwData2 |= *(pbyAddr+0); |
| 301 | |
| 302 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2. wOffset: %d, Data: %lX\n", wOffset, dwData2); |
| 303 | |
| 304 | //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset); |
| 305 | //VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData); |
| 306 | //VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE); |
| 307 | |
| 308 | //wOffset++; |
| 309 | |
| 310 | //wOffset += (uKeyIdx * 4); |
| 311 | /* for (ii=0;ii<4;ii++) { |
| 312 | // alway push 128 bits |
| 313 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey); |
| 314 | VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii); |
| 315 | VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++); |
| 316 | VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE); |
| 317 | } |
| 318 | */ |
| 319 | pbyKey = (PBYTE)pdwKey; |
| 320 | |
| 321 | pbyData[0] = (BYTE)dwData1; |
| 322 | pbyData[1] = (BYTE)(dwData1>>8); |
| 323 | pbyData[2] = (BYTE)(dwData1>>16); |
| 324 | pbyData[3] = (BYTE)(dwData1>>24); |
| 325 | pbyData[4] = (BYTE)dwData2; |
| 326 | pbyData[5] = (BYTE)(dwData2>>8); |
| 327 | pbyData[6] = (BYTE)(dwData2>>16); |
| 328 | pbyData[7] = (BYTE)(dwData2>>24); |
| 329 | for(ii=8;ii<24;ii++) |
| 330 | pbyData[ii] = *pbyKey++; |
| 331 | |
| 332 | CONTROLnsRequestOut(pDevice, |
| 333 | MESSAGE_TYPE_SETKEY, |
| 334 | wOffset, |
| 335 | (WORD)uKeyIdx, |
| 336 | 24, |
| 337 | pbyData |
| 338 | ); |
| 339 | |
| 340 | |
| 341 | } |
| 342 | |
| 343 | |
| 344 | void MACvRegBitsOff(PSDevice pDevice, BYTE byRegOfs, BYTE byBits) |
| 345 | { |
| 346 | BYTE pbyData[2]; |
| 347 | |
| 348 | pbyData[0] = 0; |
| 349 | pbyData[1] = byBits; |
| 350 | |
| 351 | CONTROLnsRequestOut(pDevice, |
| 352 | MESSAGE_TYPE_WRITE_MASK, |
| 353 | byRegOfs, |
| 354 | MESSAGE_REQUEST_MACREG, |
| 355 | 2, |
| 356 | pbyData |
| 357 | ); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | void MACvRegBitsOn(PSDevice pDevice, BYTE byRegOfs, BYTE byBits) |
| 362 | { |
| 363 | BYTE pbyData[2]; |
| 364 | |
| 365 | |
| 366 | pbyData[0] = byBits; |
| 367 | pbyData[1] = byBits; |
| 368 | |
| 369 | CONTROLnsRequestOut(pDevice, |
| 370 | MESSAGE_TYPE_WRITE_MASK, |
| 371 | byRegOfs, |
| 372 | MESSAGE_REQUEST_MACREG, |
| 373 | 2, |
| 374 | pbyData |
| 375 | ); |
| 376 | } |
| 377 | |
| 378 | void MACvWriteWord(PSDevice pDevice, BYTE byRegOfs, WORD wData) |
| 379 | { |
| 380 | BYTE pbyData[2]; |
| 381 | |
| 382 | |
| 383 | pbyData[0] = (BYTE)(wData & 0xff); |
| 384 | pbyData[1] = (BYTE)(wData >> 8); |
| 385 | |
| 386 | CONTROLnsRequestOut(pDevice, |
| 387 | MESSAGE_TYPE_WRITE, |
| 388 | byRegOfs, |
| 389 | MESSAGE_REQUEST_MACREG, |
| 390 | 2, |
| 391 | pbyData |
| 392 | ); |
| 393 | |
| 394 | } |
| 395 | |
| 396 | void MACvWriteBSSIDAddress(PSDevice pDevice, PBYTE pbyEtherAddr) |
| 397 | { |
| 398 | BYTE pbyData[6]; |
| 399 | |
| 400 | |
| 401 | pbyData[0] = *((PBYTE)pbyEtherAddr); |
| 402 | pbyData[1] = *((PBYTE)pbyEtherAddr+1); |
| 403 | pbyData[2] = *((PBYTE)pbyEtherAddr+2); |
| 404 | pbyData[3] = *((PBYTE)pbyEtherAddr+3); |
| 405 | pbyData[4] = *((PBYTE)pbyEtherAddr+4); |
| 406 | pbyData[5] = *((PBYTE)pbyEtherAddr+5); |
| 407 | |
| 408 | CONTROLnsRequestOut(pDevice, |
| 409 | MESSAGE_TYPE_WRITE, |
| 410 | MAC_REG_BSSID0, |
| 411 | MESSAGE_REQUEST_MACREG, |
| 412 | 6, |
| 413 | pbyData |
| 414 | ); |
| 415 | } |
| 416 | |
| 417 | void MACvEnableProtectMD(PSDevice pDevice) |
| 418 | { |
| 419 | BYTE pbyData[2]; |
| 420 | |
| 421 | |
| 422 | pbyData[0] = EnCFG_ProtectMd; |
| 423 | pbyData[1] = EnCFG_ProtectMd; |
| 424 | |
| 425 | CONTROLnsRequestOut(pDevice, |
| 426 | MESSAGE_TYPE_WRITE_MASK, |
| 427 | MAC_REG_ENCFG0, |
| 428 | MESSAGE_REQUEST_MACREG, |
| 429 | 2, |
| 430 | pbyData |
| 431 | ); |
| 432 | } |
| 433 | |
| 434 | void MACvDisableProtectMD(PSDevice pDevice) |
| 435 | { |
| 436 | BYTE pbyData[2]; |
| 437 | |
| 438 | |
| 439 | pbyData[0] = 0; |
| 440 | pbyData[1] = EnCFG_ProtectMd; |
| 441 | |
| 442 | CONTROLnsRequestOut(pDevice, |
| 443 | MESSAGE_TYPE_WRITE_MASK, |
| 444 | MAC_REG_ENCFG0, |
| 445 | MESSAGE_REQUEST_MACREG, |
| 446 | 2, |
| 447 | pbyData |
| 448 | ); |
| 449 | } |
| 450 | |
| 451 | void MACvEnableBarkerPreambleMd(PSDevice pDevice) |
| 452 | { |
| 453 | BYTE pbyData[2]; |
| 454 | |
| 455 | |
| 456 | pbyData[0] = EnCFG_BarkerPream; |
| 457 | pbyData[1] = EnCFG_BarkerPream; |
| 458 | |
| 459 | CONTROLnsRequestOut(pDevice, |
| 460 | MESSAGE_TYPE_WRITE_MASK, |
| 461 | MAC_REG_ENCFG2, |
| 462 | MESSAGE_REQUEST_MACREG, |
| 463 | 2, |
| 464 | pbyData |
| 465 | ); |
| 466 | } |
| 467 | |
| 468 | void MACvDisableBarkerPreambleMd(PSDevice pDevice) |
| 469 | { |
| 470 | BYTE pbyData[2]; |
| 471 | |
| 472 | |
| 473 | pbyData[0] = 0; |
| 474 | pbyData[1] = EnCFG_BarkerPream; |
| 475 | |
| 476 | CONTROLnsRequestOut(pDevice, |
| 477 | MESSAGE_TYPE_WRITE_MASK, |
| 478 | MAC_REG_ENCFG2, |
| 479 | MESSAGE_REQUEST_MACREG, |
| 480 | 2, |
| 481 | pbyData |
| 482 | ); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | void MACvWriteBeaconInterval(PSDevice pDevice, WORD wInterval) |
| 487 | { |
| 488 | BYTE pbyData[2]; |
| 489 | |
| 490 | pbyData[0] = (BYTE) (wInterval & 0xff); |
| 491 | pbyData[1] = (BYTE) (wInterval >> 8); |
| 492 | |
| 493 | CONTROLnsRequestOut(pDevice, |
| 494 | MESSAGE_TYPE_WRITE, |
| 495 | MAC_REG_BI, |
| 496 | MESSAGE_REQUEST_MACREG, |
| 497 | 2, |
| 498 | pbyData |
| 499 | ); |
| 500 | } |