2008-10-28 21:48:09 +00:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Ralink Tech Inc .
* 5F . , No .36 , Taiyuan St . , Jhubei City ,
* Hsinchu County 302 ,
* Taiwan , R . O . C .
*
* ( c ) Copyright 2002 - 2007 , Ralink Technology , Inc .
*
* This program is free software ; you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* *
* This program is distributed in the hope that it will be useful , *
* but WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the *
* GNU General Public License for more details . *
* *
* You should have received a copy of the GNU General Public License *
* along with this program ; if not , write to the *
* Free Software Foundation , Inc . , *
* 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA . *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2009-10-13 00:28:11 +00:00
# include <linux/sched.h>
2008-10-28 21:48:09 +00:00
# include "rt_config.h"
2009-12-11 20:23:15 +00:00
unsigned long RTDebugLevel = RT_DEBUG_ERROR ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:14 +00:00
/* for wireless system event message */
2008-10-28 21:48:09 +00:00
char const * pWirelessSysEventText [ IW_SYS_EVENT_TYPE_NUM ] = {
2009-12-11 20:23:14 +00:00
/* system status event */
2009-12-11 20:23:13 +00:00
" had associated successfully " , /* IW_ASSOC_EVENT_FLAG */
" had disassociated " , /* IW_DISASSOC_EVENT_FLAG */
" had deauthenticated " , /* IW_DEAUTH_EVENT_FLAG */
" had been aged-out and disassociated " , /* IW_AGEOUT_EVENT_FLAG */
" occurred CounterMeasures attack " , /* IW_COUNTER_MEASURES_EVENT_FLAG */
" occurred replay counter different in Key Handshaking " , /* IW_REPLAY_COUNTER_DIFF_EVENT_FLAG */
" occurred RSNIE different in Key Handshaking " , /* IW_RSNIE_DIFF_EVENT_FLAG */
" occurred MIC different in Key Handshaking " , /* IW_MIC_DIFF_EVENT_FLAG */
" occurred ICV error in RX " , /* IW_ICV_ERROR_EVENT_FLAG */
" occurred MIC error in RX " , /* IW_MIC_ERROR_EVENT_FLAG */
" Group Key Handshaking timeout " , /* IW_GROUP_HS_TIMEOUT_EVENT_FLAG */
" Pairwise Key Handshaking timeout " , /* IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG */
" RSN IE sanity check failure " , /* IW_RSNIE_SANITY_FAIL_EVENT_FLAG */
" set key done in WPA/WPAPSK " , /* IW_SET_KEY_DONE_WPA1_EVENT_FLAG */
" set key done in WPA2/WPA2PSK " , /* IW_SET_KEY_DONE_WPA2_EVENT_FLAG */
" connects with our wireless client " , /* IW_STA_LINKUP_EVENT_FLAG */
" disconnects with our wireless client " , /* IW_STA_LINKDOWN_EVENT_FLAG */
" scan completed " /* IW_SCAN_COMPLETED_EVENT_FLAG */
" scan terminate!! Busy!! Enqueue fail!! " /* IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG */
} ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:14 +00:00
/* for wireless IDS_spoof_attack event message */
2008-10-28 21:48:09 +00:00
char const * pWirelessSpoofEventText [ IW_SPOOF_EVENT_TYPE_NUM ] = {
2009-12-11 20:23:13 +00:00
" detected conflict SSID " , /* IW_CONFLICT_SSID_EVENT_FLAG */
" detected spoofed association response " , /* IW_SPOOF_ASSOC_RESP_EVENT_FLAG */
" detected spoofed reassociation responses " , /* IW_SPOOF_REASSOC_RESP_EVENT_FLAG */
" detected spoofed probe response " , /* IW_SPOOF_PROBE_RESP_EVENT_FLAG */
" detected spoofed beacon " , /* IW_SPOOF_BEACON_EVENT_FLAG */
" detected spoofed disassociation " , /* IW_SPOOF_DISASSOC_EVENT_FLAG */
" detected spoofed authentication " , /* IW_SPOOF_AUTH_EVENT_FLAG */
" detected spoofed deauthentication " , /* IW_SPOOF_DEAUTH_EVENT_FLAG */
" detected spoofed unknown management frame " , /* IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG */
" detected replay attack " /* IW_REPLAY_ATTACK_EVENT_FLAG */
} ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:14 +00:00
/* for wireless IDS_flooding_attack event message */
2008-10-28 21:48:09 +00:00
char const * pWirelessFloodEventText [ IW_FLOOD_EVENT_TYPE_NUM ] = {
2009-12-11 20:23:13 +00:00
" detected authentication flooding " , /* IW_FLOOD_AUTH_EVENT_FLAG */
" detected association request flooding " , /* IW_FLOOD_ASSOC_REQ_EVENT_FLAG */
" detected reassociation request flooding " , /* IW_FLOOD_REASSOC_REQ_EVENT_FLAG */
" detected probe request flooding " , /* IW_FLOOD_PROBE_REQ_EVENT_FLAG */
" detected disassociation flooding " , /* IW_FLOOD_DISASSOC_EVENT_FLAG */
" detected deauthentication flooding " , /* IW_FLOOD_DEAUTH_EVENT_FLAG */
" detected 802.1x eap-request flooding " /* IW_FLOOD_EAP_REQ_EVENT_FLAG */
} ;
2008-10-28 21:48:09 +00:00
/* timeout -- ms */
2009-12-11 20:23:15 +00:00
void RTMP_SetPeriodicTimer ( struct timer_list * pTimer ,
2009-12-11 20:23:13 +00:00
IN unsigned long timeout )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
timeout = ( ( timeout * OS_HZ ) / 1000 ) ;
2008-10-28 21:48:09 +00:00
pTimer - > expires = jiffies + timeout ;
add_timer ( pTimer ) ;
}
/* convert NdisMInitializeTimer --> RTMP_OS_Init_Timer */
2009-12-11 20:23:16 +00:00
void RTMP_OS_Init_Timer ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
struct timer_list * pTimer ,
2009-12-11 20:23:15 +00:00
IN TIMER_FUNCTION function , void * data )
2008-10-28 21:48:09 +00:00
{
init_timer ( pTimer ) ;
2009-12-11 20:23:13 +00:00
pTimer - > data = ( unsigned long ) data ;
pTimer - > function = function ;
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:15 +00:00
void RTMP_OS_Add_Timer ( struct timer_list * pTimer ,
2009-12-11 20:23:13 +00:00
IN unsigned long timeout )
2008-10-28 21:48:09 +00:00
{
if ( timer_pending ( pTimer ) )
return ;
2009-12-11 20:23:13 +00:00
timeout = ( ( timeout * OS_HZ ) / 1000 ) ;
2008-10-28 21:48:09 +00:00
pTimer - > expires = jiffies + timeout ;
add_timer ( pTimer ) ;
}
2009-12-11 20:23:15 +00:00
void RTMP_OS_Mod_Timer ( struct timer_list * pTimer ,
2009-12-11 20:23:13 +00:00
IN unsigned long timeout )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
timeout = ( ( timeout * OS_HZ ) / 1000 ) ;
2008-10-28 21:48:09 +00:00
mod_timer ( pTimer , jiffies + timeout ) ;
}
2009-12-11 20:23:15 +00:00
void RTMP_OS_Del_Timer ( struct timer_list * pTimer ,
2009-12-11 20:23:13 +00:00
OUT BOOLEAN * pCancelled )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
if ( timer_pending ( pTimer ) ) {
2008-10-28 21:48:09 +00:00
* pCancelled = del_timer_sync ( pTimer ) ;
2009-12-11 20:23:13 +00:00
} else {
2008-10-28 21:48:09 +00:00
* pCancelled = TRUE ;
}
}
2009-12-11 20:23:16 +00:00
void RTMP_OS_Release_Packet ( struct rt_rtmp_adapter * pAd , struct rt_queue_entry * pEntry )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:14 +00:00
/*RTMPFreeNdisPacket(pAd, (struct sk_buff *)pEntry); */
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:14 +00:00
/* Unify all delay routine by using udelay */
2009-12-11 20:23:15 +00:00
void RTMPusecDelay ( unsigned long usec )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:15 +00:00
unsigned long i ;
2008-10-28 21:48:09 +00:00
for ( i = 0 ; i < ( usec / 50 ) ; i + + )
udelay ( 50 ) ;
if ( usec % 50 )
udelay ( usec % 50 ) ;
}
2009-12-11 20:23:13 +00:00
void RTMP_GetCurrentSystemTime ( LARGE_INTEGER * time )
2008-10-28 21:48:09 +00:00
{
time - > u . LowPart = jiffies ;
}
2009-12-11 20:23:14 +00:00
/* pAd MUST allow to be NULL */
2009-12-11 20:23:16 +00:00
int os_alloc_mem ( struct rt_rtmp_adapter * pAd , u8 * * mem , unsigned long size )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:15 +00:00
* mem = ( u8 * ) kmalloc ( size , GFP_ATOMIC ) ;
2008-10-28 21:48:09 +00:00
if ( * mem )
return ( NDIS_STATUS_SUCCESS ) ;
else
return ( NDIS_STATUS_FAILURE ) ;
}
2009-12-11 20:23:14 +00:00
/* pAd MUST allow to be NULL */
2009-12-11 20:23:16 +00:00
int os_free_mem ( struct rt_rtmp_adapter * pAd , void * mem )
2008-10-28 21:48:09 +00:00
{
ASSERT ( mem ) ;
kfree ( mem ) ;
return ( NDIS_STATUS_SUCCESS ) ;
}
2009-12-11 20:23:16 +00:00
void * RtmpOSNetPktAlloc ( struct rt_rtmp_adapter * pAd , IN int size )
2009-09-22 18:44:07 +00:00
{
struct sk_buff * skb ;
2009-12-11 20:23:13 +00:00
/* Add 2 more bytes for ip header alignment */
skb = dev_alloc_skb ( size + 2 ) ;
2009-09-22 18:44:07 +00:00
2009-12-11 20:23:15 +00:00
return ( ( void * ) skb ) ;
2009-09-22 18:44:07 +00:00
}
2009-12-11 20:23:16 +00:00
void * RTMP_AllocateFragPacketBuffer ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
unsigned long Length )
2008-10-28 21:48:09 +00:00
{
struct sk_buff * pkt ;
pkt = dev_alloc_skb ( Length ) ;
2009-12-11 20:23:13 +00:00
if ( pkt = = NULL ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " can't allocate frag rx %ld size packet \n " , Length ) ) ;
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:13 +00:00
if ( pkt ) {
2008-10-28 21:48:09 +00:00
RTMP_SET_PACKET_SOURCE ( OSPKT_TO_RTPKT ( pkt ) , PKTSRC_NDIS ) ;
}
2009-12-11 20:23:15 +00:00
return ( void * ) pkt ;
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:16 +00:00
void * RTMP_AllocateTxPacketBuffer ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
unsigned long Length ,
2009-12-11 20:23:13 +00:00
IN BOOLEAN Cached ,
2009-12-11 20:23:15 +00:00
void * * VirtualAddress )
2008-10-28 21:48:09 +00:00
{
struct sk_buff * pkt ;
pkt = dev_alloc_skb ( Length ) ;
2009-12-11 20:23:13 +00:00
if ( pkt = = NULL ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " can't allocate tx %ld size packet \n " , Length ) ) ;
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:13 +00:00
if ( pkt ) {
2008-10-28 21:48:09 +00:00
RTMP_SET_PACKET_SOURCE ( OSPKT_TO_RTPKT ( pkt ) , PKTSRC_NDIS ) ;
2009-12-11 20:23:15 +00:00
* VirtualAddress = ( void * ) pkt - > data ;
2009-12-11 20:23:13 +00:00
} else {
2009-12-11 20:23:15 +00:00
* VirtualAddress = ( void * ) NULL ;
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:15 +00:00
return ( void * ) pkt ;
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:16 +00:00
void build_tx_packet ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
void * pPacket ,
2009-12-11 20:23:15 +00:00
u8 * pFrame , unsigned long FrameLen )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * pTxPkt ;
2008-10-28 21:48:09 +00:00
ASSERT ( pPacket ) ;
pTxPkt = RTPKT_TO_OSPKT ( pPacket ) ;
NdisMoveMemory ( skb_put ( pTxPkt , FrameLen ) , pFrame , FrameLen ) ;
}
2009-12-11 20:23:16 +00:00
void RTMPFreeAdapter ( struct rt_rtmp_adapter * pAd )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:15 +00:00
struct os_cookie * os_cookie ;
2008-10-28 21:48:09 +00:00
int index ;
2009-12-11 20:23:15 +00:00
os_cookie = ( struct os_cookie * ) pAd - > OS_Cookie ;
2008-10-28 21:48:09 +00:00
2009-09-22 18:44:07 +00:00
if ( pAd - > BeaconBuf )
2009-12-11 20:23:13 +00:00
kfree ( pAd - > BeaconBuf ) ;
2008-10-28 21:48:09 +00:00
NdisFreeSpinLock ( & pAd - > MgmtRingLock ) ;
2009-09-22 18:44:07 +00:00
# ifdef RTMP_MAC_PCI
2008-10-28 21:48:09 +00:00
NdisFreeSpinLock ( & pAd - > RxRingLock ) ;
2009-09-22 18:44:24 +00:00
# ifdef RT3090
2009-12-11 20:23:13 +00:00
NdisFreeSpinLock ( & pAd - > McuCmdLock ) ;
2009-12-11 20:23:14 +00:00
# endif /* RT3090 // */
# endif /* RTMP_MAC_PCI // */
2009-09-22 18:44:07 +00:00
2009-12-11 20:23:13 +00:00
for ( index = 0 ; index < NUM_OF_TX_RING ; index + + ) {
NdisFreeSpinLock ( & pAd - > TxSwQueueLock [ index ] ) ;
2008-10-28 21:48:09 +00:00
NdisFreeSpinLock ( & pAd - > DeQueueLock [ index ] ) ;
pAd - > DeQueueRunning [ index ] = FALSE ;
}
NdisFreeSpinLock ( & pAd - > irq_lock ) ;
2009-12-11 20:23:16 +00:00
vfree ( pAd ) ; /* pci_free_consistent(os_cookie->pci_dev,sizeof(struct rt_rtmp_adapter),pAd,os_cookie->pAd_pa); */
2009-09-22 18:44:07 +00:00
if ( os_cookie )
2009-12-11 20:23:13 +00:00
kfree ( os_cookie ) ;
2008-10-28 21:48:09 +00:00
}
BOOLEAN OS_Need_Clone_Packet ( void )
{
return ( FALSE ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Routine Description :
clone an input NDIS PACKET to another one . The new internally created NDIS PACKET
must have only one NDIS BUFFER
return - byte copied . 0 means can ' t create NDIS PACKET
2009-12-11 20:23:15 +00:00
NOTE : internally created char should be destroyed by RTMPFreeNdisPacket
2008-10-28 21:48:09 +00:00
Arguments :
pAd Pointer to our adapter
pInsAMSDUHdr EWC A - MSDU format has extra 14 - bytes header . if TRUE , insert this 14 - byte hdr in front of MSDU .
* pSrcTotalLen return total packet length . This lenght is calculated with 802.3 format packet .
Return Value :
NDIS_STATUS_SUCCESS
NDIS_STATUS_FAILURE
Note :
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2009-12-11 20:23:16 +00:00
int RTMPCloneNdisPacket ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:13 +00:00
IN BOOLEAN pInsAMSDUHdr ,
2009-12-11 20:23:15 +00:00
void * pInPacket ,
void * * ppOutPacket )
2008-10-28 21:48:09 +00:00
{
struct sk_buff * pkt ;
ASSERT ( pInPacket ) ;
ASSERT ( ppOutPacket ) ;
2009-12-11 20:23:14 +00:00
/* 1. Allocate a packet */
2008-10-28 21:48:09 +00:00
pkt = dev_alloc_skb ( 2048 ) ;
2009-12-11 20:23:13 +00:00
if ( pkt = = NULL ) {
2008-10-28 21:48:09 +00:00
return NDIS_STATUS_FAILURE ;
}
2009-12-11 20:23:13 +00:00
skb_put ( pkt , GET_OS_PKT_LEN ( pInPacket ) ) ;
NdisMoveMemory ( pkt - > data , GET_OS_PKT_DATAPTR ( pInPacket ) ,
GET_OS_PKT_LEN ( pInPacket ) ) ;
2008-10-28 21:48:09 +00:00
* ppOutPacket = OSPKT_TO_RTPKT ( pkt ) ;
RTMP_SET_PACKET_SOURCE ( OSPKT_TO_RTPKT ( pkt ) , PKTSRC_NDIS ) ;
printk ( " ###Clone### \n " ) ;
return NDIS_STATUS_SUCCESS ;
}
2009-12-11 20:23:14 +00:00
/* the allocated NDIS PACKET must be freed via RTMPFreeNdisPacket() */
2009-12-11 20:23:16 +00:00
int RTMPAllocateNdisPacket ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
void * * ppPacket ,
2009-12-11 20:23:15 +00:00
u8 * pHeader ,
u32 HeaderLen ,
u8 * pData , u32 DataLen )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:15 +00:00
void * pPacket ;
2008-10-28 21:48:09 +00:00
ASSERT ( pData ) ;
ASSERT ( DataLen ) ;
2009-12-11 20:23:14 +00:00
/* 1. Allocate a packet */
2009-12-11 20:23:13 +00:00
pPacket =
2009-12-11 20:23:15 +00:00
( void * * ) dev_alloc_skb ( HeaderLen + DataLen +
2009-12-11 20:23:13 +00:00
RTMP_PKT_TAIL_PADDING ) ;
if ( pPacket = = NULL ) {
2008-10-28 21:48:09 +00:00
* ppPacket = NULL ;
# ifdef DEBUG
printk ( " RTMPAllocateNdisPacket Fail \n \n " ) ;
# endif
return NDIS_STATUS_FAILURE ;
}
2009-12-11 20:23:14 +00:00
/* 2. clone the frame content */
2008-10-28 21:48:09 +00:00
if ( HeaderLen > 0 )
NdisMoveMemory ( GET_OS_PKT_DATAPTR ( pPacket ) , pHeader , HeaderLen ) ;
if ( DataLen > 0 )
2009-12-11 20:23:13 +00:00
NdisMoveMemory ( GET_OS_PKT_DATAPTR ( pPacket ) + HeaderLen , pData ,
DataLen ) ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:14 +00:00
/* 3. update length of packet */
2009-12-11 20:23:13 +00:00
skb_put ( GET_OS_PKT_TYPE ( pPacket ) , HeaderLen + DataLen ) ;
2008-10-28 21:48:09 +00:00
RTMP_SET_PACKET_SOURCE ( pPacket , PKTSRC_NDIS ) ;
2009-12-11 20:23:14 +00:00
/* printk("%s : pPacket = %p, len = %d\n", __func__, pPacket, GET_OS_PKT_LEN(pPacket)); */
2008-10-28 21:48:09 +00:00
* ppPacket = pPacket ;
return NDIS_STATUS_SUCCESS ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Description :
2009-12-11 20:23:15 +00:00
This routine frees a miniport internally allocated char and its
2008-10-28 21:48:09 +00:00
corresponding NDIS_BUFFER and allocated memory .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2009-12-11 20:23:16 +00:00
void RTMPFreeNdisPacket ( struct rt_rtmp_adapter * pAd , void * pPacket )
2008-10-28 21:48:09 +00:00
{
dev_kfree_skb_any ( RTPKT_TO_OSPKT ( pPacket ) ) ;
}
2009-12-11 20:23:14 +00:00
/* IRQL = DISPATCH_LEVEL */
/* NOTE: we do have an assumption here, that Byte0 and Byte1 always reasid at the same */
/* scatter gather buffer */
2009-12-11 20:23:15 +00:00
int Sniff2BytesFromNdisBuffer ( char * pFirstBuffer ,
2009-12-11 20:23:15 +00:00
u8 DesiredOffset ,
u8 * pByte0 , u8 * pByte1 )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:15 +00:00
* pByte0 = * ( u8 * ) ( pFirstBuffer + DesiredOffset ) ;
* pByte1 = * ( u8 * ) ( pFirstBuffer + DesiredOffset + 1 ) ;
2008-10-28 21:48:09 +00:00
return NDIS_STATUS_SUCCESS ;
}
2009-12-11 20:23:15 +00:00
void RTMP_QueryPacketInfo ( void * pPacket ,
2009-12-11 20:23:16 +00:00
struct rt_packet_info * pPacketInfo ,
2009-12-11 20:23:15 +00:00
u8 * * pSrcBufVA , u32 * pSrcBufLen )
2008-10-28 21:48:09 +00:00
{
pPacketInfo - > BufferCount = 1 ;
2009-12-11 20:23:15 +00:00
pPacketInfo - > pFirstBuffer = ( char * ) GET_OS_PKT_DATAPTR ( pPacket ) ;
2008-10-28 21:48:09 +00:00
pPacketInfo - > PhysicalBufferCount = 1 ;
pPacketInfo - > TotalPacketLength = GET_OS_PKT_LEN ( pPacket ) ;
* pSrcBufVA = GET_OS_PKT_DATAPTR ( pPacket ) ;
* pSrcBufLen = GET_OS_PKT_LEN ( pPacket ) ;
}
2009-12-11 20:23:15 +00:00
void RTMP_QueryNextPacketInfo ( void * * ppPacket ,
2009-12-11 20:23:16 +00:00
struct rt_packet_info * pPacketInfo ,
2009-12-11 20:23:15 +00:00
u8 * * pSrcBufVA , u32 * pSrcBufLen )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:15 +00:00
void * pPacket = NULL ;
2008-10-28 21:48:09 +00:00
if ( * ppPacket )
pPacket = GET_OS_PKT_NEXT ( * ppPacket ) ;
2009-12-11 20:23:13 +00:00
if ( pPacket ) {
2008-10-28 21:48:09 +00:00
pPacketInfo - > BufferCount = 1 ;
2009-12-11 20:23:13 +00:00
pPacketInfo - > pFirstBuffer =
2009-12-11 20:23:15 +00:00
( char * ) GET_OS_PKT_DATAPTR ( pPacket ) ;
2008-10-28 21:48:09 +00:00
pPacketInfo - > PhysicalBufferCount = 1 ;
pPacketInfo - > TotalPacketLength = GET_OS_PKT_LEN ( pPacket ) ;
* pSrcBufVA = GET_OS_PKT_DATAPTR ( pPacket ) ;
* pSrcBufLen = GET_OS_PKT_LEN ( pPacket ) ;
* ppPacket = GET_OS_PKT_NEXT ( pPacket ) ;
2009-12-11 20:23:13 +00:00
} else {
2008-10-28 21:48:09 +00:00
pPacketInfo - > BufferCount = 0 ;
pPacketInfo - > pFirstBuffer = NULL ;
pPacketInfo - > PhysicalBufferCount = 0 ;
pPacketInfo - > TotalPacketLength = 0 ;
* pSrcBufVA = NULL ;
* pSrcBufLen = 0 ;
* ppPacket = NULL ;
}
}
2009-12-11 20:23:16 +00:00
void * DuplicatePacket ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
void * pPacket , u8 FromWhichBSSID )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * skb ;
2009-12-11 20:23:15 +00:00
void * pRetPacket = NULL ;
2009-12-11 20:23:15 +00:00
u16 DataSize ;
u8 * pData ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:15 +00:00
DataSize = ( u16 ) GET_OS_PKT_LEN ( pPacket ) ;
pData = ( u8 * ) GET_OS_PKT_DATAPTR ( pPacket ) ;
2008-10-28 21:48:09 +00:00
skb = skb_clone ( RTPKT_TO_OSPKT ( pPacket ) , MEM_ALLOC_FLAG ) ;
2009-12-11 20:23:13 +00:00
if ( skb ) {
2008-10-28 21:48:09 +00:00
skb - > dev = get_netdev_from_bssid ( pAd , FromWhichBSSID ) ;
pRetPacket = OSPKT_TO_RTPKT ( skb ) ;
}
return pRetPacket ;
}
2009-12-11 20:23:16 +00:00
void * duplicate_pkt ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
u8 * pHeader802_3 ,
u32 HdrLen ,
u8 * pData ,
unsigned long DataSize , u8 FromWhichBSSID )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * skb ;
2009-12-11 20:23:15 +00:00
void * pPacket = NULL ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
if ( ( skb =
__dev_alloc_skb ( HdrLen + DataSize + 2 , MEM_ALLOC_FLAG ) ) ! = NULL ) {
2008-10-28 21:48:09 +00:00
skb_reserve ( skb , 2 ) ;
2009-09-22 18:44:07 +00:00
NdisMoveMemory ( skb - > tail , pHeader802_3 , HdrLen ) ;
2008-10-28 21:48:09 +00:00
skb_put ( skb , HdrLen ) ;
2009-09-22 18:44:07 +00:00
NdisMoveMemory ( skb - > tail , pData , DataSize ) ;
2008-10-28 21:48:09 +00:00
skb_put ( skb , DataSize ) ;
skb - > dev = get_netdev_from_bssid ( pAd , FromWhichBSSID ) ;
pPacket = OSPKT_TO_RTPKT ( skb ) ;
}
return pPacket ;
}
# define TKIP_TX_MIC_SIZE 8
2009-12-11 20:23:16 +00:00
void * duplicate_pkt_with_TKIP_MIC ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
void * pPacket )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * skb , * newskb ;
2008-10-28 21:48:09 +00:00
skb = RTPKT_TO_OSPKT ( pPacket ) ;
2009-12-11 20:23:13 +00:00
if ( skb_tailroom ( skb ) < TKIP_TX_MIC_SIZE ) {
2009-12-11 20:23:14 +00:00
/* alloc a new skb and copy the packet */
2009-12-11 20:23:13 +00:00
newskb =
skb_copy_expand ( skb , skb_headroom ( skb ) , TKIP_TX_MIC_SIZE ,
GFP_ATOMIC ) ;
2008-10-28 21:48:09 +00:00
dev_kfree_skb_any ( skb ) ;
2009-12-11 20:23:13 +00:00
if ( newskb = = NULL ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " Extend Tx.MIC for packet failed!, dropping packet! \n " ) ) ;
2008-10-28 21:48:09 +00:00
return NULL ;
}
skb = newskb ;
}
return OSPKT_TO_RTPKT ( skb ) ;
}
2009-12-11 20:23:16 +00:00
void * ClonePacket ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
void * pPacket ,
2009-12-11 20:23:15 +00:00
u8 * pData , unsigned long DataSize )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * pRxPkt ;
struct sk_buff * pClonedPkt ;
2008-10-28 21:48:09 +00:00
ASSERT ( pPacket ) ;
pRxPkt = RTPKT_TO_OSPKT ( pPacket ) ;
2009-12-11 20:23:14 +00:00
/* clone the packet */
2008-10-28 21:48:09 +00:00
pClonedPkt = skb_clone ( pRxPkt , MEM_ALLOC_FLAG ) ;
2009-12-11 20:23:13 +00:00
if ( pClonedPkt ) {
2009-12-11 20:23:14 +00:00
/* set the correct dataptr and data len */
2009-12-11 20:23:13 +00:00
pClonedPkt - > dev = pRxPkt - > dev ;
pClonedPkt - > data = pData ;
pClonedPkt - > len = DataSize ;
pClonedPkt - > tail = pClonedPkt - > data + pClonedPkt - > len ;
2008-10-28 21:48:09 +00:00
ASSERT ( DataSize < 1530 ) ;
}
return pClonedPkt ;
}
2009-12-11 20:23:14 +00:00
/* */
/* change OS packet DataPtr and DataLen */
/* */
2009-12-11 20:23:16 +00:00
void update_os_packet_info ( struct rt_rtmp_adapter * pAd ,
struct rt_rx_blk * pRxBlk , u8 FromWhichBSSID )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * pOSPkt ;
2008-10-28 21:48:09 +00:00
ASSERT ( pRxBlk - > pRxPacket ) ;
pOSPkt = RTPKT_TO_OSPKT ( pRxBlk - > pRxPacket ) ;
pOSPkt - > dev = get_netdev_from_bssid ( pAd , FromWhichBSSID ) ;
pOSPkt - > data = pRxBlk - > pData ;
pOSPkt - > len = pRxBlk - > DataSize ;
pOSPkt - > tail = pOSPkt - > data + pOSPkt - > len ;
}
2009-12-11 20:23:16 +00:00
void wlan_802_11_to_802_3_packet ( struct rt_rtmp_adapter * pAd ,
struct rt_rx_blk * pRxBlk ,
2009-12-11 20:23:15 +00:00
u8 * pHeader802_3 ,
u8 FromWhichBSSID )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * pOSPkt ;
2008-10-28 21:48:09 +00:00
ASSERT ( pRxBlk - > pRxPacket ) ;
ASSERT ( pHeader802_3 ) ;
pOSPkt = RTPKT_TO_OSPKT ( pRxBlk - > pRxPacket ) ;
pOSPkt - > dev = get_netdev_from_bssid ( pAd , FromWhichBSSID ) ;
pOSPkt - > data = pRxBlk - > pData ;
pOSPkt - > len = pRxBlk - > DataSize ;
pOSPkt - > tail = pOSPkt - > data + pOSPkt - > len ;
2009-12-11 20:23:14 +00:00
/* */
/* copy 802.3 header */
/* */
/* */
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
NdisMoveMemory ( skb_push ( pOSPkt , LENGTH_802_3 ) , pHeader802_3 ,
LENGTH_802_3 ) ;
}
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:16 +00:00
void announce_802_3_packet ( struct rt_rtmp_adapter * pAd , void * pPacket )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * pRxPkt ;
2008-10-28 21:48:09 +00:00
ASSERT ( pPacket ) ;
pRxPkt = RTPKT_TO_OSPKT ( pPacket ) ;
2009-12-11 20:23:13 +00:00
/* Push up the protocol stack */
2008-10-28 21:48:09 +00:00
pRxPkt - > protocol = eth_type_trans ( pRxPkt , pRxPkt - > dev ) ;
netif_rx ( pRxPkt ) ;
}
2009-12-11 20:23:16 +00:00
struct rt_rtmp_sg_list *
rt_get_sg_list_from_packet ( void * pPacket , struct rt_rtmp_sg_list * sg )
2008-10-28 21:48:09 +00:00
{
sg - > NumberOfElements = 1 ;
2009-12-11 20:23:13 +00:00
sg - > Elements [ 0 ] . Address = GET_OS_PKT_DATAPTR ( pPacket ) ;
2008-10-28 21:48:09 +00:00
sg - > Elements [ 0 ] . Length = GET_OS_PKT_LEN ( pPacket ) ;
return ( sg ) ;
}
void hex_dump ( char * str , unsigned char * pSrcBufVA , unsigned int SrcBufLen )
{
unsigned char * pt ;
int x ;
if ( RTDebugLevel < RT_DEBUG_TRACE )
return ;
pt = pSrcBufVA ;
2009-12-11 20:23:13 +00:00
printk ( " %s: %p, len = %d \n " , str , pSrcBufVA , SrcBufLen ) ;
for ( x = 0 ; x < SrcBufLen ; x + + ) {
2008-10-28 21:48:09 +00:00
if ( x % 16 = = 0 )
printk ( " 0x%04x : " , x ) ;
printk ( " %02x " , ( ( unsigned char ) pt [ x ] ) ) ;
2009-12-11 20:23:13 +00:00
if ( x % 16 = = 15 )
printk ( " \n " ) ;
2008-10-28 21:48:09 +00:00
}
printk ( " \n " ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Routine Description :
Send log message through wireless event
Support standard iw_event with IWEVCUSTOM . It is used below .
iwreq_data . data . flags is used to store event_flag that is defined by user .
iwreq_data . data . length is the length of the event log .
The format of the event log is composed of the entry ' s MAC address and
the desired log message ( refer to pWirelessEventText ) .
ex : 11 : 22 : 33 : 44 : 55 : 66 has associated successfully
p . s . The requirement of Wireless Extension is v15 or newer .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2009-12-11 20:23:16 +00:00
void RTMPSendWirelessEvent ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
u16 Event_flag ,
u8 * pAddr , u8 BssIdx , char Rssi )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:14 +00:00
/*union iwreq_data wrqu; */
2009-12-11 20:23:15 +00:00
char * pBuf = NULL , * pBufPtr = NULL ;
u16 event , type , BufLen ;
u8 event_table_len = 0 ;
2008-10-28 21:48:09 +00:00
type = Event_flag & 0xFF00 ;
event = Event_flag & 0x00FF ;
2009-12-11 20:23:13 +00:00
switch ( type ) {
case IW_SYS_EVENT_FLAG_START :
event_table_len = IW_SYS_EVENT_TYPE_NUM ;
break ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
case IW_SPOOF_EVENT_FLAG_START :
event_table_len = IW_SPOOF_EVENT_TYPE_NUM ;
break ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
case IW_FLOOD_EVENT_FLAG_START :
event_table_len = IW_FLOOD_EVENT_TYPE_NUM ;
break ;
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:13 +00:00
if ( event_table_len = = 0 ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " %s : The type(%0x02x) is not valid. \n " , __func__ ,
type ) ) ;
2008-10-28 21:48:09 +00:00
return ;
}
2009-12-11 20:23:13 +00:00
if ( event > = event_table_len ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " %s : The event(%0x02x) is not valid. \n " , __func__ ,
event ) ) ;
2008-10-28 21:48:09 +00:00
return ;
}
2009-12-11 20:23:14 +00:00
/*Allocate memory and copy the msg. */
2009-12-11 20:23:13 +00:00
if ( ( pBuf = kmalloc ( IW_CUSTOM_MAX_LEN , GFP_ATOMIC ) ) ! = NULL ) {
2009-12-11 20:23:14 +00:00
/*Prepare the payload */
2008-10-28 21:48:09 +00:00
memset ( pBuf , 0 , IW_CUSTOM_MAX_LEN ) ;
pBufPtr = pBuf ;
if ( pAddr )
2009-12-11 20:23:13 +00:00
pBufPtr + =
sprintf ( pBufPtr ,
" (RT2860) STA(%02x:%02x:%02x:%02x:%02x:%02x) " ,
PRINT_MAC ( pAddr ) ) ;
2008-10-28 21:48:09 +00:00
else if ( BssIdx < MAX_MBSSID_NUM )
2009-12-11 20:23:13 +00:00
pBufPtr + =
sprintf ( pBufPtr , " (RT2860) BSS(wlan%d) " , BssIdx ) ;
2008-10-28 21:48:09 +00:00
else
pBufPtr + = sprintf ( pBufPtr , " (RT2860) " ) ;
if ( type = = IW_SYS_EVENT_FLAG_START )
2009-12-11 20:23:13 +00:00
pBufPtr + =
sprintf ( pBufPtr , " %s " ,
pWirelessSysEventText [ event ] ) ;
2008-10-28 21:48:09 +00:00
else if ( type = = IW_SPOOF_EVENT_FLAG_START )
2009-12-11 20:23:13 +00:00
pBufPtr + =
sprintf ( pBufPtr , " %s (RSSI=%d) " ,
pWirelessSpoofEventText [ event ] , Rssi ) ;
2008-10-28 21:48:09 +00:00
else if ( type = = IW_FLOOD_EVENT_FLAG_START )
2009-12-11 20:23:13 +00:00
pBufPtr + =
sprintf ( pBufPtr , " %s " ,
pWirelessFloodEventText [ event ] ) ;
2008-10-28 21:48:09 +00:00
else
pBufPtr + = sprintf ( pBufPtr , " %s " , " unknown event " ) ;
pBufPtr [ pBufPtr - pBuf ] = ' \0 ' ;
BufLen = pBufPtr - pBuf ;
2009-12-11 20:23:13 +00:00
RtmpOSWrielessEventSend ( pAd , IWEVCUSTOM , Event_flag , NULL ,
2009-12-11 20:23:15 +00:00
( u8 * ) pBuf , BufLen ) ;
2009-12-11 20:23:14 +00:00
/*DBGPRINT(RT_DEBUG_TRACE, ("%s : %s\n", __func__, pBuf)); */
2008-10-28 21:48:09 +00:00
kfree ( pBuf ) ;
2009-12-11 20:23:13 +00:00
} else
DBGPRINT ( RT_DEBUG_ERROR ,
( " %s : Can't allocate memory for wireless event. \n " ,
__func__ ) ) ;
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:16 +00:00
void send_monitor_packets ( struct rt_rtmp_adapter * pAd , struct rt_rx_blk * pRxBlk )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
struct sk_buff * pOSPkt ;
2009-12-11 20:23:16 +00:00
struct rt_wlan_ng_prism2_header * ph ;
2009-12-11 20:23:13 +00:00
int rate_index = 0 ;
2009-12-11 20:23:15 +00:00
u16 header_len = 0 ;
u8 temp_header [ 40 ] = { 0 } ;
2009-12-11 20:23:13 +00:00
2009-12-11 20:23:14 +00:00
u_int32_t ralinkrate [ 256 ] = { 2 , 4 , 11 , 22 , 12 , 18 , 24 , 36 , 48 , 72 , 96 , 108 , 109 , 110 , 111 , 112 , 13 , 26 , 39 , 52 , 78 , 104 , 117 , 130 , 26 , 52 , 78 , 104 , 156 , 208 , 234 , 260 , 27 , 54 , 81 , 108 , 162 , 216 , 243 , 270 , /* Last 38 */
2009-12-11 20:23:13 +00:00
54 , 108 , 162 , 216 , 324 , 432 , 486 , 540 , 14 , 29 , 43 , 57 , 87 , 115 ,
130 , 144 , 29 , 59 , 87 , 115 , 173 , 230 , 260 , 288 , 30 , 60 , 90 ,
120 , 180 , 240 , 270 , 300 , 60 , 120 , 180 , 240 , 360 , 480 , 540 ,
600 , 0 , 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
} ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
ASSERT ( pRxBlk - > pRxPacket ) ;
if ( pRxBlk - > DataSize < 10 ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " %s : Size is too small! (%d) \n " , __func__ ,
pRxBlk - > DataSize ) ) ;
2008-10-28 21:48:09 +00:00
goto err_free_sk_buff ;
2009-12-11 20:23:13 +00:00
}
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:16 +00:00
if ( pRxBlk - > DataSize + sizeof ( struct rt_wlan_ng_prism2_header ) >
2009-12-11 20:23:13 +00:00
RX_BUFFER_AGGRESIZE ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " %s : Size is too large! (%zu) \n " , __func__ ,
2009-12-11 20:23:16 +00:00
pRxBlk - > DataSize + sizeof ( struct rt_wlan_ng_prism2_header ) ) ) ;
2008-10-28 21:48:09 +00:00
goto err_free_sk_buff ;
2009-12-11 20:23:13 +00:00
}
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
pOSPkt = RTPKT_TO_OSPKT ( pRxBlk - > pRxPacket ) ;
2008-10-28 21:48:09 +00:00
pOSPkt - > dev = get_netdev_from_bssid ( pAd , BSS0 ) ;
2009-12-11 20:23:13 +00:00
if ( pRxBlk - > pHeader - > FC . Type = = BTYPE_DATA ) {
pRxBlk - > DataSize - = LENGTH_802_11 ;
if ( ( pRxBlk - > pHeader - > FC . ToDs = = 1 ) & &
( pRxBlk - > pHeader - > FC . FrDs = = 1 ) )
header_len = LENGTH_802_11_WITH_ADDR4 ;
else
header_len = LENGTH_802_11 ;
2009-12-11 20:23:14 +00:00
/* QOS */
2009-12-11 20:23:13 +00:00
if ( pRxBlk - > pHeader - > FC . SubType & 0x08 ) {
header_len + = 2 ;
2009-12-11 20:23:14 +00:00
/* Data skip QOS contorl field */
2009-12-11 20:23:13 +00:00
pRxBlk - > DataSize - = 2 ;
}
2009-12-11 20:23:14 +00:00
/* Order bit: A-Ralink or HTC+ */
2009-12-11 20:23:13 +00:00
if ( pRxBlk - > pHeader - > FC . Order ) {
header_len + = 4 ;
2009-12-11 20:23:14 +00:00
/* Data skip HTC contorl field */
2008-10-28 21:48:09 +00:00
pRxBlk - > DataSize - = 4 ;
2009-12-11 20:23:13 +00:00
}
2009-12-11 20:23:14 +00:00
/* Copy Header */
2009-12-11 20:23:13 +00:00
if ( header_len < = 40 )
NdisMoveMemory ( temp_header , pRxBlk - > pData , header_len ) ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:14 +00:00
/* skip HW padding */
2009-12-11 20:23:13 +00:00
if ( pRxBlk - > RxD . L2PAD )
pRxBlk - > pData + = ( header_len + 2 ) ;
else
pRxBlk - > pData + = header_len ;
2009-12-11 20:23:14 +00:00
} /*end if */
2008-10-28 21:48:09 +00:00
if ( pRxBlk - > DataSize < pOSPkt - > len ) {
2009-12-11 20:23:13 +00:00
skb_trim ( pOSPkt , pRxBlk - > DataSize ) ;
} else {
skb_put ( pOSPkt , ( pRxBlk - > DataSize - pOSPkt - > len ) ) ;
2009-12-11 20:23:14 +00:00
} /*end if */
2009-12-11 20:23:13 +00:00
if ( ( pRxBlk - > pData - pOSPkt - > data ) > 0 ) {
skb_put ( pOSPkt , ( pRxBlk - > pData - pOSPkt - > data ) ) ;
skb_pull ( pOSPkt , ( pRxBlk - > pData - pOSPkt - > data ) ) ;
2009-12-11 20:23:14 +00:00
} /*end if */
2009-12-11 20:23:13 +00:00
2009-12-11 20:23:16 +00:00
if ( skb_headroom ( pOSPkt ) < ( sizeof ( struct rt_wlan_ng_prism2_header ) + header_len ) ) {
2009-12-11 20:23:13 +00:00
if ( pskb_expand_head
2009-12-11 20:23:16 +00:00
( pOSPkt , ( sizeof ( struct rt_wlan_ng_prism2_header ) + header_len ) , 0 ,
2009-12-11 20:23:13 +00:00
GFP_ATOMIC ) ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " %s : Reallocate header size of sk_buff fail! \n " ,
__func__ ) ) ;
2008-10-28 21:48:09 +00:00
goto err_free_sk_buff ;
2009-12-11 20:23:14 +00:00
} /*end if */
} /*end if */
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
if ( header_len > 0 )
NdisMoveMemory ( skb_push ( pOSPkt , header_len ) , temp_header ,
header_len ) ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:16 +00:00
ph = ( struct rt_wlan_ng_prism2_header * ) skb_push ( pOSPkt ,
sizeof ( struct rt_wlan_ng_prism2_header ) ) ;
NdisZeroMemory ( ph , sizeof ( struct rt_wlan_ng_prism2_header ) ) ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
ph - > msgcode = DIDmsg_lnxind_wlansniffrm ;
2009-12-11 20:23:16 +00:00
ph - > msglen = sizeof ( struct rt_wlan_ng_prism2_header ) ;
2009-12-11 20:23:15 +00:00
strcpy ( ( char * ) ph - > devname , ( char * ) pAd - > net_dev - > name ) ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
ph - > hosttime . did = DIDmsg_lnxind_wlansniffrm_hosttime ;
2008-10-28 21:48:09 +00:00
ph - > hosttime . status = 0 ;
ph - > hosttime . len = 4 ;
ph - > hosttime . data = jiffies ;
ph - > mactime . did = DIDmsg_lnxind_wlansniffrm_mactime ;
ph - > mactime . status = 0 ;
ph - > mactime . len = 0 ;
ph - > mactime . data = 0 ;
2009-12-11 20:23:13 +00:00
ph - > istx . did = DIDmsg_lnxind_wlansniffrm_istx ;
2008-10-28 21:48:09 +00:00
ph - > istx . status = 0 ;
ph - > istx . len = 0 ;
ph - > istx . data = 0 ;
2009-12-11 20:23:13 +00:00
ph - > channel . did = DIDmsg_lnxind_wlansniffrm_channel ;
2008-10-28 21:48:09 +00:00
ph - > channel . status = 0 ;
ph - > channel . len = 4 ;
2009-12-11 20:23:13 +00:00
ph - > channel . data = ( u_int32_t ) pAd - > CommonCfg . Channel ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
ph - > rssi . did = DIDmsg_lnxind_wlansniffrm_rssi ;
2008-10-28 21:48:09 +00:00
ph - > rssi . status = 0 ;
ph - > rssi . len = 4 ;
2009-12-11 20:23:13 +00:00
ph - > rssi . data =
( u_int32_t ) RTMPMaxRssi ( pAd ,
ConvertToRssi ( pAd , pRxBlk - > pRxWI - > RSSI0 ,
RSSI_0 ) , ConvertToRssi ( pAd ,
pRxBlk - >
pRxWI - >
RSSI1 ,
RSSI_1 ) ,
ConvertToRssi ( pAd , pRxBlk - > pRxWI - > RSSI2 ,
RSSI_2 ) ) ; ;
2008-10-28 21:48:09 +00:00
ph - > signal . did = DIDmsg_lnxind_wlansniffrm_signal ;
ph - > signal . status = 0 ;
ph - > signal . len = 4 ;
2009-12-11 20:23:14 +00:00
ph - > signal . data = 0 ; /*rssi + noise; */
2008-10-28 21:48:09 +00:00
ph - > noise . did = DIDmsg_lnxind_wlansniffrm_noise ;
ph - > noise . status = 0 ;
ph - > noise . len = 4 ;
ph - > noise . data = 0 ;
2009-12-11 20:23:13 +00:00
if ( pRxBlk - > pRxWI - > PHYMODE > = MODE_HTMIX ) {
rate_index =
2009-12-11 20:23:15 +00:00
16 + ( ( u8 ) pRxBlk - > pRxWI - > BW * 16 ) +
( ( u8 ) pRxBlk - > pRxWI - > ShortGI * 32 ) +
( ( u8 ) pRxBlk - > pRxWI - > MCS ) ;
2009-12-11 20:23:13 +00:00
} else if ( pRxBlk - > pRxWI - > PHYMODE = = MODE_OFDM )
2009-12-11 20:23:15 +00:00
rate_index = ( u8 ) ( pRxBlk - > pRxWI - > MCS ) + 4 ;
2009-12-11 20:23:13 +00:00
else
2009-12-11 20:23:15 +00:00
rate_index = ( u8 ) ( pRxBlk - > pRxWI - > MCS ) ;
2009-12-11 20:23:13 +00:00
if ( rate_index < 0 )
rate_index = 0 ;
if ( rate_index > 255 )
rate_index = 255 ;
2008-10-28 21:48:09 +00:00
ph - > rate . did = DIDmsg_lnxind_wlansniffrm_rate ;
ph - > rate . status = 0 ;
ph - > rate . len = 4 ;
2009-12-11 20:23:13 +00:00
ph - > rate . data = ralinkrate [ rate_index ] ;
2008-10-28 21:48:09 +00:00
ph - > frmlen . did = DIDmsg_lnxind_wlansniffrm_frmlen ;
2009-12-11 20:23:13 +00:00
ph - > frmlen . status = 0 ;
2008-10-28 21:48:09 +00:00
ph - > frmlen . len = 4 ;
2009-12-11 20:23:13 +00:00
ph - > frmlen . data = ( u_int32_t ) pRxBlk - > DataSize ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
pOSPkt - > pkt_type = PACKET_OTHERHOST ;
pOSPkt - > protocol = eth_type_trans ( pOSPkt , pOSPkt - > dev ) ;
pOSPkt - > ip_summed = CHECKSUM_NONE ;
netif_rx ( pOSPkt ) ;
2008-10-28 21:48:09 +00:00
2009-12-11 20:23:13 +00:00
return ;
2008-10-28 21:48:09 +00:00
err_free_sk_buff :
RELEASE_NDIS_PACKET ( pAd , pRxBlk - > pRxPacket , NDIS_STATUS_FAILURE ) ;
return ;
}
2009-09-22 18:44:07 +00:00
/*******************************************************************************
Device IRQ related functions .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-12-11 20:23:15 +00:00
int RtmpOSIRQRequest ( struct net_device * pNetDev )
2009-09-22 18:44:07 +00:00
{
2009-10-21 20:44:42 +00:00
# ifdef RTMP_PCI_SUPPORT
2009-09-22 18:44:07 +00:00
struct net_device * net_dev = pNetDev ;
2009-12-11 20:23:16 +00:00
struct rt_rtmp_adapter * pAd = NULL ;
2009-09-22 18:44:07 +00:00
int retval = 0 ;
GET_PAD_FROM_NET_DEV ( pAd , pNetDev ) ;
ASSERT ( pAd ) ;
2009-12-11 20:23:13 +00:00
if ( pAd - > infType = = RTMP_DEV_INF_PCI ) {
2009-12-11 20:23:15 +00:00
struct os_cookie * _pObj = ( struct os_cookie * ) ( pAd - > OS_Cookie ) ;
2009-09-22 18:44:07 +00:00
RTMP_MSI_ENABLE ( pAd ) ;
2009-12-11 20:23:13 +00:00
retval =
request_irq ( _pObj - > pci_dev - > irq , rt2860_interrupt , SA_SHIRQ ,
( net_dev ) - > name , ( net_dev ) ) ;
2009-09-22 18:44:07 +00:00
if ( retval ! = 0 )
printk ( " RT2860: request_irq ERROR(%d) \n " , retval ) ;
}
return retval ;
2009-10-21 20:44:42 +00:00
# else
return 0 ;
# endif
2009-09-22 18:44:07 +00:00
}
2009-12-11 20:23:15 +00:00
int RtmpOSIRQRelease ( struct net_device * pNetDev )
2008-10-28 21:48:09 +00:00
{
2009-09-22 18:44:07 +00:00
struct net_device * net_dev = pNetDev ;
2009-12-11 20:23:16 +00:00
struct rt_rtmp_adapter * pAd = NULL ;
2009-09-22 18:44:07 +00:00
GET_PAD_FROM_NET_DEV ( pAd , net_dev ) ;
ASSERT ( pAd ) ;
# ifdef RTMP_PCI_SUPPORT
2009-12-11 20:23:13 +00:00
if ( pAd - > infType = = RTMP_DEV_INF_PCI ) {
2009-12-11 20:23:15 +00:00
struct os_cookie * pObj = ( struct os_cookie * ) ( pAd - > OS_Cookie ) ;
2009-09-22 18:44:07 +00:00
synchronize_irq ( pObj - > pci_dev - > irq ) ;
free_irq ( pObj - > pci_dev - > irq , ( net_dev ) ) ;
RTMP_MSI_DISABLE ( pAd ) ;
}
2009-12-11 20:23:14 +00:00
# endif /* RTMP_PCI_SUPPORT // */
2009-09-22 18:44:07 +00:00
return 0 ;
}
/*******************************************************************************
File open / close related functions .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-12-11 20:23:15 +00:00
struct file * RtmpOSFileOpen ( char * pPath , int flag , int mode )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:13 +00:00
struct file * filePtr ;
2009-09-22 18:44:07 +00:00
filePtr = filp_open ( pPath , flag , 0 ) ;
2009-12-11 20:23:13 +00:00
if ( IS_ERR ( filePtr ) ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " %s(): Error %ld opening %s \n " , __func__ ,
- PTR_ERR ( filePtr ) , pPath ) ) ;
2009-09-22 18:44:07 +00:00
}
2009-12-11 20:23:15 +00:00
return ( struct file * ) filePtr ;
2009-09-22 18:44:07 +00:00
}
2009-12-11 20:23:15 +00:00
int RtmpOSFileClose ( struct file * osfd )
2009-09-22 18:44:07 +00:00
{
filp_close ( osfd , NULL ) ;
return 0 ;
}
2009-12-11 20:23:15 +00:00
void RtmpOSFileSeek ( struct file * osfd , int offset )
2009-09-22 18:44:07 +00:00
{
osfd - > f_pos = offset ;
}
2009-12-11 20:23:15 +00:00
int RtmpOSFileRead ( struct file * osfd , char * pDataPtr , int readLen )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:14 +00:00
/* The object must have a read method */
2009-12-11 20:23:13 +00:00
if ( osfd - > f_op & & osfd - > f_op - > read ) {
return osfd - > f_op - > read ( osfd , pDataPtr , readLen , & osfd - > f_pos ) ;
} else {
2009-09-22 18:44:07 +00:00
DBGPRINT ( RT_DEBUG_ERROR , ( " no file read method \n " ) ) ;
return - 1 ;
}
}
2009-12-11 20:23:15 +00:00
int RtmpOSFileWrite ( struct file * osfd , char * pDataPtr , int writeLen )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:13 +00:00
return osfd - > f_op - > write ( osfd , pDataPtr , ( size_t ) writeLen ,
& osfd - > f_pos ) ;
2009-09-22 18:44:07 +00:00
}
/*******************************************************************************
Task create / management / kill related functions .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-12-11 20:23:16 +00:00
int RtmpOSTaskKill ( struct rt_rtmp_os_task * pTask )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:16 +00:00
struct rt_rtmp_adapter * pAd ;
2009-09-22 18:44:07 +00:00
int ret = NDIS_STATUS_FAILURE ;
2009-12-11 20:23:16 +00:00
pAd = ( struct rt_rtmp_adapter * ) pTask - > priv ;
2009-09-22 18:44:07 +00:00
# ifdef KTHREAD_SUPPORT
2009-12-11 20:23:13 +00:00
if ( pTask - > kthread_task ) {
2009-09-22 18:44:07 +00:00
kthread_stop ( pTask - > kthread_task ) ;
ret = NDIS_STATUS_SUCCESS ;
}
# else
2009-12-11 20:23:13 +00:00
CHECK_PID_LEGALITY ( pTask - > taskPID ) {
printk ( " Terminate the task(%s) with pid(%d)! \n " ,
pTask - > taskName , GET_PID_NUMBER ( pTask - > taskPID ) ) ;
2009-09-22 18:44:07 +00:00
mb ( ) ;
pTask - > task_killed = 1 ;
mb ( ) ;
ret = KILL_THREAD_PID ( pTask - > taskPID , SIGTERM , 1 ) ;
2009-12-11 20:23:13 +00:00
if ( ret ) {
printk ( KERN_WARNING
" kill task(%s) with pid(%d) failed(retVal=%d)! \n " ,
pTask - > taskName , GET_PID_NUMBER ( pTask - > taskPID ) ,
ret ) ;
} else {
2009-09-22 18:44:07 +00:00
wait_for_completion ( & pTask - > taskComplete ) ;
pTask - > taskPID = THREAD_PID_INIT_VALUE ;
pTask - > task_killed = 0 ;
ret = NDIS_STATUS_SUCCESS ;
}
}
# endif
return ret ;
}
2009-12-11 20:23:16 +00:00
int RtmpOSTaskNotifyToExit ( struct rt_rtmp_os_task * pTask )
2009-09-22 18:44:07 +00:00
{
# ifndef KTHREAD_SUPPORT
complete_and_exit ( & pTask - > taskComplete , 0 ) ;
# endif
return 0 ;
}
2009-12-11 20:23:16 +00:00
void RtmpOSTaskCustomize ( struct rt_rtmp_os_task * pTask )
2009-09-22 18:44:07 +00:00
{
# ifndef KTHREAD_SUPPORT
2009-12-11 20:23:15 +00:00
daemonize ( ( char * ) & pTask - > taskName [ 0 ] /*"%s",pAd->net_dev->name */ ) ;
2008-10-28 21:48:09 +00:00
allow_signal ( SIGTERM ) ;
allow_signal ( SIGKILL ) ;
current - > flags | = PF_NOFREEZE ;
2009-01-13 18:51:11 +00:00
/* signal that we've started the thread */
2009-09-22 18:44:07 +00:00
complete ( & pTask - > taskComplete ) ;
# endif
2008-10-28 21:48:09 +00:00
}
2009-12-11 20:23:16 +00:00
int RtmpOSTaskAttach ( struct rt_rtmp_os_task * pTask ,
2009-12-11 20:23:13 +00:00
IN int ( * fn ) ( void * ) , IN void * arg )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:15 +00:00
int status = NDIS_STATUS_SUCCESS ;
2009-09-22 18:44:07 +00:00
# ifdef KTHREAD_SUPPORT
pTask - > task_killed = 0 ;
pTask - > kthread_task = NULL ;
pTask - > kthread_task = kthread_run ( fn , arg , pTask - > taskName ) ;
if ( IS_ERR ( pTask - > kthread_task ) )
status = NDIS_STATUS_FAILURE ;
# else
pid_number = kernel_thread ( fn , arg , RTMP_OS_MGMT_TASK_FLAGS ) ;
2009-12-11 20:23:13 +00:00
if ( pid_number < 0 ) {
DBGPRINT ( RT_DEBUG_ERROR ,
( " Attach task(%s) failed! \n " , pTask - > taskName ) ) ;
2009-09-22 18:44:07 +00:00
status = NDIS_STATUS_FAILURE ;
2009-12-11 20:23:13 +00:00
} else {
2009-09-22 18:44:07 +00:00
pTask - > taskPID = GET_PID ( pid_number ) ;
2009-12-11 20:23:14 +00:00
/* Wait for the thread to start */
2009-09-22 18:44:07 +00:00
wait_for_completion ( & pTask - > taskComplete ) ;
status = NDIS_STATUS_SUCCESS ;
}
# endif
return status ;
}
2009-12-11 20:23:16 +00:00
int RtmpOSTaskInit ( struct rt_rtmp_os_task * pTask ,
2009-12-11 20:23:15 +00:00
char * pTaskName , void * pPriv )
2009-09-22 18:44:07 +00:00
{
int len ;
ASSERT ( pTask ) ;
# ifndef KTHREAD_SUPPORT
2009-12-11 20:23:16 +00:00
NdisZeroMemory ( ( u8 * ) ( pTask ) , sizeof ( struct rt_rtmp_os_task ) ) ;
2009-09-22 18:44:07 +00:00
# endif
len = strlen ( pTaskName ) ;
2009-12-11 20:23:13 +00:00
len =
len >
( RTMP_OS_TASK_NAME_LEN - 1 ) ? ( RTMP_OS_TASK_NAME_LEN - 1 ) : len ;
2009-09-22 18:44:07 +00:00
NdisMoveMemory ( & pTask - > taskName [ 0 ] , pTaskName , len ) ;
pTask - > priv = pPriv ;
# ifndef KTHREAD_SUPPORT
RTMP_SEM_EVENT_INIT_LOCKED ( & ( pTask - > taskSema ) ) ;
pTask - > taskPID = THREAD_PID_INIT_VALUE ;
2009-12-11 20:23:13 +00:00
init_completion ( & pTask - > taskComplete ) ;
2009-09-22 18:44:07 +00:00
# endif
return NDIS_STATUS_SUCCESS ;
}
2009-12-11 20:23:16 +00:00
void RTMP_IndicateMediaState ( struct rt_rtmp_adapter * pAd )
2008-10-28 21:48:09 +00:00
{
2009-12-11 20:23:13 +00:00
if ( pAd - > CommonCfg . bWirelessEvent ) {
if ( pAd - > IndicateMediaState = = NdisMediaStateConnected ) {
RTMPSendWirelessEvent ( pAd , IW_STA_LINKUP_EVENT_FLAG ,
pAd - > MacTab . Content [ BSSID_WCID ] .
Addr , BSS0 , 0 ) ;
} else {
RTMPSendWirelessEvent ( pAd , IW_STA_LINKDOWN_EVENT_FLAG ,
pAd - > MacTab . Content [ BSSID_WCID ] .
Addr , BSS0 , 0 ) ;
2008-10-28 21:48:09 +00:00
}
}
}
2009-12-11 20:23:16 +00:00
int RtmpOSWrielessEventSend ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
u32 eventType ,
int flags ,
u8 * pSrcMac ,
u8 * pData , u32 dataLen )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:13 +00:00
union iwreq_data wrqu ;
2009-09-22 18:44:07 +00:00
2009-12-11 20:23:13 +00:00
memset ( & wrqu , 0 , sizeof ( wrqu ) ) ;
2009-09-22 18:44:07 +00:00
2009-12-11 20:23:13 +00:00
if ( flags > - 1 )
wrqu . data . flags = flags ;
2009-09-22 18:44:07 +00:00
if ( pSrcMac )
memcpy ( wrqu . ap_addr . sa_data , pSrcMac , MAC_ADDR_LEN ) ;
2009-12-11 20:23:13 +00:00
if ( ( pData ! = NULL ) & & ( dataLen > 0 ) )
2009-09-22 18:44:07 +00:00
wrqu . data . length = dataLen ;
2009-12-11 20:23:13 +00:00
wireless_send_event ( pAd - > net_dev , eventType , & wrqu , ( char * ) pData ) ;
2009-09-22 18:44:07 +00:00
return 0 ;
}
2009-12-11 20:23:15 +00:00
int RtmpOSNetDevAddrSet ( struct net_device * pNetDev , u8 * pMacAddr )
2009-09-22 18:44:07 +00:00
{
struct net_device * net_dev ;
2009-12-11 20:23:16 +00:00
struct rt_rtmp_adapter * pAd ;
2009-09-22 18:44:07 +00:00
net_dev = pNetDev ;
GET_PAD_FROM_NET_DEV ( pAd , net_dev ) ;
2009-12-11 20:23:14 +00:00
/* work-around for the SuSE due to it has it's own interface name management system. */
2009-09-22 18:44:07 +00:00
{
NdisZeroMemory ( pAd - > StaCfg . dev_name , 16 ) ;
2009-12-11 20:23:13 +00:00
NdisMoveMemory ( pAd - > StaCfg . dev_name , net_dev - > name ,
strlen ( net_dev - > name ) ) ;
2009-09-22 18:44:07 +00:00
}
NdisMoveMemory ( net_dev - > dev_addr , pMacAddr , 6 ) ;
return 0 ;
}
/*
* Assign the network dev name for created Ralink WiFi interface .
*/
2009-12-11 20:23:16 +00:00
static int RtmpOSNetDevRequestName ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
struct net_device * dev ,
2009-12-11 20:23:15 +00:00
char * pPrefixStr , int devIdx )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:15 +00:00
struct net_device * existNetDev ;
2009-12-11 20:23:15 +00:00
char suffixName [ IFNAMSIZ ] ;
char desiredName [ IFNAMSIZ ] ;
2009-12-11 20:23:13 +00:00
int ifNameIdx , prefixLen , slotNameLen ;
2009-09-22 18:44:07 +00:00
int Status ;
prefixLen = strlen ( pPrefixStr ) ;
ASSERT ( ( prefixLen < IFNAMSIZ ) ) ;
2009-12-11 20:23:13 +00:00
for ( ifNameIdx = devIdx ; ifNameIdx < 32 ; ifNameIdx + + ) {
2009-09-22 18:44:07 +00:00
memset ( suffixName , 0 , IFNAMSIZ ) ;
memset ( desiredName , 0 , IFNAMSIZ ) ;
strncpy ( & desiredName [ 0 ] , pPrefixStr , prefixLen ) ;
sprintf ( suffixName , " %d " , ifNameIdx ) ;
slotNameLen = strlen ( suffixName ) ;
ASSERT ( ( ( slotNameLen + prefixLen ) < IFNAMSIZ ) ) ;
strcat ( desiredName , suffixName ) ;
existNetDev = RtmpOSNetDevGetByName ( dev , & desiredName [ 0 ] ) ;
if ( existNetDev = = NULL )
break ;
else
RtmpOSNetDeviceRefPut ( existNetDev ) ;
}
2009-12-11 20:23:13 +00:00
if ( ifNameIdx < 32 ) {
2009-09-22 18:44:07 +00:00
strcpy ( & dev - > name [ 0 ] , & desiredName [ 0 ] ) ;
Status = NDIS_STATUS_SUCCESS ;
2009-12-11 20:23:13 +00:00
} else {
2009-09-22 18:44:07 +00:00
DBGPRINT ( RT_DEBUG_ERROR ,
2009-12-11 20:23:13 +00:00
( " Cannot request DevName with preifx(%s) and in range(0~32) as suffix from OS! \n " ,
pPrefixStr ) ) ;
2009-09-22 18:44:07 +00:00
Status = NDIS_STATUS_FAILURE ;
}
return Status ;
}
2009-12-11 20:23:15 +00:00
void RtmpOSNetDevClose ( struct net_device * pNetDev )
2009-09-22 18:44:07 +00:00
{
dev_close ( pNetDev ) ;
}
2009-12-11 20:23:15 +00:00
void RtmpOSNetDevFree ( struct net_device * pNetDev )
2009-09-22 18:44:07 +00:00
{
ASSERT ( pNetDev ) ;
free_netdev ( pNetDev ) ;
}
2009-12-11 20:23:15 +00:00
int RtmpOSNetDevAlloc ( struct net_device * * new_dev_p , u32 privDataSize )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:14 +00:00
/* assign it as null first. */
2009-09-22 18:44:07 +00:00
* new_dev_p = NULL ;
2009-12-11 20:23:13 +00:00
DBGPRINT ( RT_DEBUG_TRACE ,
( " Allocate a net device with private data size=%d! \n " ,
privDataSize ) ) ;
2009-09-22 18:44:07 +00:00
* new_dev_p = alloc_etherdev ( privDataSize ) ;
if ( * new_dev_p )
return NDIS_STATUS_SUCCESS ;
else
return NDIS_STATUS_FAILURE ;
}
2009-12-11 20:23:15 +00:00
struct net_device * RtmpOSNetDevGetByName ( struct net_device * pNetDev , char * pDevName )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:15 +00:00
struct net_device * pTargetNetDev = NULL ;
2009-09-22 18:44:07 +00:00
pTargetNetDev = dev_get_by_name ( dev_net ( pNetDev ) , pDevName ) ;
return pTargetNetDev ;
}
2009-12-11 20:23:15 +00:00
void RtmpOSNetDeviceRefPut ( struct net_device * pNetDev )
2009-09-22 18:44:07 +00:00
{
/*
2009-12-11 20:23:13 +00:00
every time dev_get_by_name is called , and it has returned a valid struct
net_device * , dev_put should be called afterwards , because otherwise the
machine hangs when the device is unregistered ( since dev - > refcnt > 1 ) .
*/
if ( pNetDev )
2009-09-22 18:44:07 +00:00
dev_put ( pNetDev ) ;
}
2009-12-11 20:23:16 +00:00
int RtmpOSNetDevDestory ( struct rt_rtmp_adapter * pAd , struct net_device * pNetDev )
2009-09-22 18:44:07 +00:00
{
2009-12-11 20:23:14 +00:00
/* TODO: Need to fix this */
2009-09-22 18:44:07 +00:00
printk ( " WARNING: This function(%s) not implement yet!!! \n " , __func__ ) ;
return 0 ;
}
2009-12-11 20:23:15 +00:00
void RtmpOSNetDevDetach ( struct net_device * pNetDev )
2009-09-22 18:44:07 +00:00
{
unregister_netdev ( pNetDev ) ;
}
2009-12-11 20:23:15 +00:00
int RtmpOSNetDevAttach ( struct net_device * pNetDev ,
2009-12-11 20:23:16 +00:00
struct rt_rtmp_os_netdev_op_hook * pDevOpHook )
2009-09-22 18:44:07 +00:00
{
int ret , rtnl_locked = FALSE ;
DBGPRINT ( RT_DEBUG_TRACE , ( " RtmpOSNetDevAttach()---> \n " ) ) ;
2009-12-11 20:23:14 +00:00
/* If we need hook some callback function to the net device structrue, now do it. */
2009-12-11 20:23:13 +00:00
if ( pDevOpHook ) {
2009-12-11 20:23:16 +00:00
struct rt_rtmp_adapter * pAd = NULL ;
2009-09-22 18:44:07 +00:00
GET_PAD_FROM_NET_DEV ( pAd , pNetDev ) ;
pNetDev - > netdev_ops = pDevOpHook - > netdev_ops ;
/* OS specific flags, here we used to indicate if we are virtual interface */
pNetDev - > priv_flags = pDevOpHook - > priv_flags ;
2009-12-11 20:23:13 +00:00
if ( pAd - > OpMode = = OPMODE_STA ) {
2009-09-22 18:44:07 +00:00
pNetDev - > wireless_handlers = & rt28xx_iw_handler_def ;
}
2009-12-11 20:23:14 +00:00
/* copy the net device mac address to the net_device structure. */
2009-12-11 20:23:13 +00:00
NdisMoveMemory ( pNetDev - > dev_addr , & pDevOpHook - > devAddr [ 0 ] ,
MAC_ADDR_LEN ) ;
2009-09-22 18:44:07 +00:00
rtnl_locked = pDevOpHook - > needProtcted ;
}
if ( rtnl_locked )
ret = register_netdevice ( pNetDev ) ;
else
ret = register_netdev ( pNetDev ) ;
DBGPRINT ( RT_DEBUG_TRACE , ( " <---RtmpOSNetDevAttach(), ret=%d \n " , ret ) ) ;
if ( ret = = 0 )
return NDIS_STATUS_SUCCESS ;
else
return NDIS_STATUS_FAILURE ;
}
2009-12-11 20:23:16 +00:00
struct net_device * RtmpOSNetDevCreate ( struct rt_rtmp_adapter * pAd ,
2009-12-11 20:23:15 +00:00
int devType ,
int devNum ,
int privMemSize , char * pNamePrefix )
2009-09-22 18:44:07 +00:00
{
struct net_device * pNetDev = NULL ;
int status ;
/* allocate a new network device */
2009-12-11 20:23:13 +00:00
status = RtmpOSNetDevAlloc ( & pNetDev , 0 /*privMemSize */ ) ;
if ( status ! = NDIS_STATUS_SUCCESS ) {
2009-09-22 18:44:07 +00:00
/* allocation fail, exit */
2009-12-11 20:23:13 +00:00
DBGPRINT ( RT_DEBUG_ERROR ,
( " Allocate network device fail (%s)... \n " ,
pNamePrefix ) ) ;
2009-09-22 18:44:07 +00:00
return NULL ;
}
/* find a available interface name, max 32 interfaces */
status = RtmpOSNetDevRequestName ( pAd , pNetDev , pNamePrefix , devNum ) ;
2009-12-11 20:23:13 +00:00
if ( status ! = NDIS_STATUS_SUCCESS ) {
2009-09-22 18:44:07 +00:00
/* error! no any available ra name can be used! */
2009-12-11 20:23:13 +00:00
DBGPRINT ( RT_DEBUG_ERROR ,
( " Assign interface name (%s with suffix 0~32) failed... \n " ,
pNamePrefix ) ) ;
2009-09-22 18:44:07 +00:00
RtmpOSNetDevFree ( pNetDev ) ;
return NULL ;
2009-12-11 20:23:13 +00:00
} else {
DBGPRINT ( RT_DEBUG_TRACE ,
( " The name of the new %s interface is %s... \n " ,
pNamePrefix , pNetDev - > name ) ) ;
2009-09-22 18:44:07 +00:00
}
return pNetDev ;
}