📄 utility.c
字号:
#define END_CHANNEL_FREQ_NUM (45)
// 802.11 WLAN channel-frequency table.
ULONG ulChannelFreqTable[END_CHANNEL_FREQ_NUM][2] = {
{ 1, 2412000 }, { 2, 2417000 }, { 3, 2422000 }, { 4, 2427000 },
{ 5, 2432000 }, { 6, 2437000 }, { 7, 2442000 }, { 8, 2447000 },
{ 9, 2452000 }, { 10, 2457000 }, { 11, 2462000 }, { 12, 2467000 },
{ 13, 2472000 }, { 14, 2484000 },
{ 16, 5080000 }, { 34, 5170000 }, { 36, 5180000 }, { 38, 5190000 },
{ 40, 5200000 }, { 42, 5210000 }, { 44, 5220000 }, { 46, 5230000 },
{ 48, 5240000 }, { 52, 5260000 }, { 56, 5280000 }, { 58, 5290000 },
{ 60, 5300000 }, { 64, 5320000 }, { 100,5500000 }, { 104,5520000 },
{ 108,5540000 }, { 112,5560000 }, { 116,5580000 }, { 120,5600000 },
{ 124,5620000 }, { 128,5640000 }, { 132,5660000 }, { 136,5680000 },
{ 140,5700000 }, { 145,5725000 }, { 149,5745000 }, { 153,5765000 },
{ 157,5785000 }, { 161,5805000 }, { 165,5825000 } };
ULONG i;
// Japan MKK 802.11a Channel Set:
// 7, 8, 9, 11, 12, 16, 34, 38, 42, 46, 183, 184, 185, 187, 188, 189, 192, 196
// NOTE: AIROHA 7230 only supports Frequencies 2.4 - 2.5 Ghz and 4.9 - 5.85 GHz,
// so channels 183, 184, 185, 187, 188, 189, 192, 196 are not included
// in the above list.
// FIXME: Need to handle these MKK channels with overlapping 802.11 b/g and 802.11a Frequencies:
// Chan 7 -> 2442000 & 5035000
// Chan 8 -> 2447000 & 5040000
// Chan 9 -> 2452000 & 5045000
// Chan 11 -> 2462000 & 5055000
// Chan 12 -> 2467000 & 5060000
// China 802.11a Channel Set:
// 145
for ( i=0; i<END_CHANNEL_FREQ_NUM; i++ )
{
if ( ulChannelFreqTable[i][0] == ulChannelFreq )
{
*pulFreqChannel = ulChannelFreqTable[i][1];
break;
}
else if ( ulChannelFreqTable[i][1] == ulChannelFreq )
{
*pulFreqChannel = ulChannelFreqTable[i][0];
break;
}
}
}
/*****************************************************************************
**
** NAME vENDgetRatesBitmapArray
**
** PARAMETERS ulNetworkType Network type in use (802.11 a/b/g).
** pulBasicRates Pointer to bitmap of basic rate set.
** pulComRates Pointer to bitmap of common rate set.
** pucRates Pointer to the rates array.
**
** DESCRIPTION This function returns rates array based on rates bitmaps
** or rates bitmaps based on rates array.
**
******************************************************************************/
VOID
vENDgetRatesBitmapArray( IN ULONG ulNetworkType, IN OUT PULONG pulBasicRates,
IN OUT PULONG pulComRates, IN OUT PUCHAR pucRates )
{
// Number of rates in rate set table.
#define END_PHY_11A_RATES_NUM (8)
#define END_PHY_11B_RATES_NUM (4)
#define END_PHY_11G_RATES_NUM (14)
// 802.11 WLAN rates table.
UCHAR uc802_11Rates[3][NDIS_802_11_LENGTH_RATES_EX] = {
// 6, 9, 12, 18, 24, 36, 48, 54
{ 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, 0, 0, 0, 0, 0, 0, 0, 0 },
// 1, 2, 5.5, 11
{ 0x02, 0x04, 0x0b, 0x16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
// 1, 2, 5.5, 6, 9, 11, 12, 18, 22, 24, 33, 36, 48, 54
{ 0x02, 0x04, 0x0b, 0x0c, 0x12, 0x16, 0x18, 0x24, 0x2c, 0x30, 0x42, 0x48, 0x60, 0x6c, 0, 0 } };
ULONG ulBasicRates=0, ulComRates=0;
ULONG i, j, ulMax=0, ulIndex;
if ( ulNetworkType == Ndis802_11OFDM5 )
{
ulMax = END_PHY_11A_RATES_NUM;
ulIndex = 0;
}
else if ( ulNetworkType == Ndis802_11DS )
{
ulMax = END_PHY_11B_RATES_NUM;
ulIndex = 1;
}
else if ( ulNetworkType == Ndis802_11OFDM24 )
{
ulMax = END_PHY_11G_RATES_NUM;
ulIndex = 2;
}
else
{
ulIndex = 0;
}
if ( *pulComRates )
{
ulBasicRates = *pulBasicRates;
ulComRates = *pulComRates;
// Translate rates bitmaps to array.
for ( i=0, j=0; i<ulMax; i++ )
{
if ( ulComRates & 0x01 )
{
pucRates[j] = uc802_11Rates[ulIndex][i];
if ( ulBasicRates & 0x01 )
pucRates[j] |= 0x80;
j ++;
}
ulComRates >>= 1;
ulBasicRates >>= 1;
}
for ( ; j<NDIS_802_11_LENGTH_RATES_EX; j++ )
pucRates[j] = 0;
}
else
{
// Translate rates array to bitmaps.
for ( i=0; i<NDIS_802_11_LENGTH_RATES_EX; i++ )
{
if ( pucRates[i] == 0 )
break;
else
{
UCHAR ucRate = pucRates[i] & 0x7f;
for ( j=0; j<ulMax; j++ )
{
if ( ucRate == uc802_11Rates[ulIndex][j] )
{
ulComRates |= (1 << j);
if ( pucRates[i] & 0x80 )
ulBasicRates |= (1 << j);
break;
}
}
}
}
*pulBasicRates = ulBasicRates;
*pulComRates = ulComRates;
}
}
/*****************************************************************************
**
** NAME vENDsetDefaultRateSet
**
** PARAMETERS ulProtocolType 802.11a, 802.11b or 802.11g mode.
** pucSupportedRates Pointer to default supported rate set.
** pucDesiredRates Pointer to default desired rate set.
**
** DESCRIPTION This function sets default rate sets based on protocol type.
**
******************************************************************************/
VOID
vENDsetDefaultRateSet( IN ULONG ulProtocolType, OUT PUCHAR pucSupportedRates, OUT PUCHAR pucDesiredRates )
{
ULONG ulBasicRates, ulComRates;
if ( ulProtocolType == Ndis802_11OFDM5 )
{
ulBasicRates = END_802_11A_BASIC_RATES;
ulComRates = END_802_11A_COMMON_RATES;
}
else if ( ulProtocolType == Ndis802_11DS )
{
ulBasicRates = END_802_11B_BASIC_RATES;
ulComRates = END_802_11B_COMMON_RATES;
}
else
{
ulBasicRates = END_802_11G_BASIC_RATES;
ulComRates = END_802_11G_COMMON_RATES;
}
vENDgetRatesBitmapArray( ulProtocolType, &ulBasicRates, &ulComRates, pucSupportedRates );
OS_MEMCPY( pucDesiredRates, pucSupportedRates, NDIS_802_11_LENGTH_RATES_EX );
}
/*****************************************************************************
**
** NAME boENDcheckFilterPacket
**
** PARAMETERS psPktDesc Pointer to NDIS packet descriptor.
**
** RETURNS TRUE if non-802.1X EAPOL packet, FALSE otherwise.
**
** DESCRIPTION This function checks whether need to filter the packet.
**
******************************************************************************/
BOOLEAN
boENDcheckFilterPacket( IN PNDIS_PACKET psPktDesc )
{
PVOID pvAddr;
USHORT usTmp, usTag;
BOOLEAN boFilter = TRUE;
PNDIS_BUFFER psFirstBuf;
ULONG ulLength;
NdisQueryPacket( psPktDesc, NULL, NULL, &psFirstBuf, NULL );
if ( psFirstBuf != NULL )
{
#ifdef NDIS51_MINIPORT
NdisQueryBufferSafe( psFirstBuf, &pvAddr, &ulLength, HighPagePriority );
#else
NdisQueryBuffer( psFirstBuf, &pvAddr, &ulLength );
#endif
if ( pvAddr != NULL )
{
usTmp = *(PUSHORT)(DAT_ETHERNET_TYPE(pvAddr));
usTag = ((usTmp & 0xff00) >> 8) | ((usTmp & 0x00ff) << 8);
if ( usTag == DAT_TYPE_EAPOL )
boFilter = FALSE;
}
}
return (boFilter);
}
/*****************************************************************************
**
** NAME vENDresetTimer
**
** PARAMETERS psFuncContext Pointer to Adapter context.
**
** DESCRIPTION This timer function is called when Miniport Reset issued.
** Re-initialize bus and re-download F/W.
**
******************************************************************************/
VOID
vENDresetTimer( IN PVOID pvSystemSpecific1, IN NDIS_HANDLE psFuncContext,
IN PVOID pvSystemSpecific2, IN PVOID pvSystemSpecific3 )
{
PEND_CONTEXT psAdapter = (PEND_CONTEXT)psFuncContext;
PHAL_CONTEXT psHAL = &psAdapter->sHAL;
LONG iStatus = 0;
DBG_LEV1(("Reset timer.\n"));
ASSERT( psAdapter->boResetInProgress == TRUE );
// Reinitialize SDIO.
iStatus = iENDinitializeSDIO( psAdapter );
if ( iStatus == 0 )
{
// Download F/W.
if ( !boHALdownload( psHAL, TRUE ) )
{
DBG_LEV0(("ERROR: Download F/W failed.\n"));
iStatus = -1;
}
else
{
// Enable interrupt after downloading F/W.
vHALenableInterrupt( psHAL );
}
}
psAdapter->boResetInProgress = FALSE;
if (psHAL->boNDISRequestedReset == TRUE)
{
// Return the final status of driver Reset to NDIS.
NdisMResetComplete( psAdapter->hMiniportAdapterHandle, iStatus, TRUE );
}
}
/* wpa_supplicant handles timer and disconnect under linux */
/*****************************************************************************
**
** NAME vENDmicFailTimer
**
** PARAMETERS psFuncContext Pointer to Adapter context.
**
** DESCRIPTION This timer function is called when MIC failure occurs.
** Send disconnect request w/ the reason code, FRAME_REASON_MIC_FAILURE
**
******************************************************************************/
VOID
vENDmicFailTimer( IN PVOID pvSystemSpecific1, IN NDIS_HANDLE psFuncContext,
IN PVOID pvSystemSpecific2, IN PVOID pvSystemSpecific3 )
{
PEND_CONTEXT psAdapter = (PEND_CONTEXT)psFuncContext;
PHAL_CONTEXT psHAL = &psAdapter->sHAL;
DBG_LEV0(("Send Disconnect Req after TXing 802.1X EAPOL packet for MIC failure\n"));
vHALsendDisconnectReq( psHAL, FRAME_REASON_MIC_FAILURE );
}
/*****************************************************************************
**
** NAME vENDindicateConnectionStatus
**
** PARAMETERS psAdapter Pointer to Adapter context.
** eMediaState NDIS media state disconnected or connected.
**
** DESCRIPTION This function indicates the connection status to NDIS.
**
******************************************************************************/
VOID
vENDindicateConnectionStatus( IN PEND_CONTEXT psAdapter, IN NDIS_MEDIA_STATE eMediaState )
{
psAdapter->eMediaState = eMediaState;
if ( eMediaState == NdisMediaStateDisconnected )
{
// Flush TX queues
vHALflushTxQueues( psAdapter );
psAdapter->boSendNoResourcesFlag = FALSE;
DBG_LEV1(("Indicate disconnect to NDIS.\n"));
// Indicate status media disconnect to upper.
NdisMIndicateStatus(
psAdapter->hMiniportAdapterHandle,
NDIS_STATUS_MEDIA_DISCONNECT,
NULL,
0);
}
else
{
DBG_LEV1(("Indicate connect to NDIS.\n"));
// Indicate status media connect to upper.
NdisMIndicateStatus(
psAdapter->hMiniportAdapterHandle,
NDIS_STATUS_MEDIA_CONNECT,
NULL,
0);
}
// Indicate status complete.
NdisMIndicateStatusComplete( psAdapter->hMiniportAdapterHandle );
}
/*************************************************************************/
/*** Static function definitions */
/*************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -