Merge branch 'core/percpu' into stackprotector
[linux-2.6] / drivers / staging / winbond / mlmetxrx.c
1 //============================================================================
2 //  Module Name:
3 //    MLMETxRx.C
4 //
5 //  Description:
6 //    The interface between MDS (MAC Data Service) and MLME.
7 //
8 //  Revision History:
9 //  --------------------------------------------------------------------------
10 //          200209      UN20 Jennifer Xu
11 //                      Initial Release
12 //          20021108    PD43 Austin Liu
13 //          20030117    PD43 Austin Liu
14 //                      Deleted MLMEReturnPacket and MLMEProcThread()
15 //
16 //  Copyright (c) 1996-2002 Winbond Electronics Corp. All Rights Reserved.
17 //============================================================================
18 #include "os_common.h"
19
20 #include "mds_f.h"
21
22 //=============================================================================
23 u8 MLMESendFrame(struct wbsoft_priv * adapter, u8 *pMMPDU, u16 len, u8 DataType)
24 /*      DataType : FRAME_TYPE_802_11_MANAGEMENT, FRAME_TYPE_802_11_MANAGEMENT_CHALLENGE,
25                                 FRAME_TYPE_802_11_DATA */
26 {
27         if (adapter->sMlmeFrame.IsInUsed != PACKET_FREE_TO_USE) {
28                 adapter->sMlmeFrame.wNumTxMMPDUDiscarded++;
29                 return false;
30         }
31         adapter->sMlmeFrame.IsInUsed = PACKET_COME_FROM_MLME;
32
33         // Keep information for sending
34         adapter->sMlmeFrame.pMMPDU = pMMPDU;
35         adapter->sMlmeFrame.DataType = DataType;
36         // len must be the last setting due to QUERY_SIZE_SECOND of Mds
37         adapter->sMlmeFrame.len = len;
38         adapter->sMlmeFrame.wNumTxMMPDU++;
39
40         // H/W will enter power save by set the register. S/W don't send null frame
41         //with PWRMgt bit enbled to enter power save now.
42
43         // Transmit NDIS packet
44         Mds_Tx(adapter);
45         return true;
46 }
47
48 void MLME_GetNextPacket(struct wbsoft_priv *adapter, PDESCRIPTOR desc)
49 {
50         desc->InternalUsed = desc->buffer_start_index + desc->buffer_number;
51         desc->InternalUsed %= MAX_DESCRIPTOR_BUFFER_INDEX;
52         desc->buffer_address[desc->InternalUsed] = adapter->sMlmeFrame.pMMPDU;
53         desc->buffer_size[desc->InternalUsed] = adapter->sMlmeFrame.len;
54         desc->buffer_total_size += adapter->sMlmeFrame.len;
55         desc->buffer_number++;
56         desc->Type = adapter->sMlmeFrame.DataType;
57 }
58
59 static void MLMEfreeMMPDUBuffer(struct wbsoft_priv *adapter, s8 *pData)
60 {
61         int i;
62
63         // Reclaim the data buffer
64         for (i = 0; i < MAX_NUM_TX_MMPDU; i++) {
65                 if (pData == (s8 *)&(adapter->sMlmeFrame.TxMMPDU[i]))
66                         break;
67         }
68         if (adapter->sMlmeFrame.TxMMPDUInUse[i])
69                 adapter->sMlmeFrame.TxMMPDUInUse[i] = false;
70         else  {
71                 // Something wrong
72                 // PD43 Add debug code here???
73         }
74 }
75
76 void
77 MLME_SendComplete(struct wbsoft_priv * adapter, u8 PacketID, unsigned char SendOK)
78 {
79         MLME_TXCALLBACK TxCallback;
80
81     // Reclaim the data buffer
82         adapter->sMlmeFrame.len = 0;
83         MLMEfreeMMPDUBuffer( adapter, adapter->sMlmeFrame.pMMPDU );
84
85
86         TxCallback.bResult = MLME_SUCCESS;
87
88         // Return resource
89         adapter->sMlmeFrame.IsInUsed = PACKET_FREE_TO_USE;
90 }
91
92
93