1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS BDA Proxy
4  * FILE:            dll/directx/msdvbnp/ethernetfilter.cpp
5  * PURPOSE:         IBDA_EthernetFilter interface
6  *
7  * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 #include "precomp.h"
10 
11 class CEthernetFilter : public IBDA_EthernetFilter
12 {
13 public:
14     STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
15 
16     STDMETHODIMP_(ULONG) AddRef();
17     STDMETHODIMP_(ULONG) Release();
18 
19     //IBDA_EthernetFilter
20     HRESULT STDMETHODCALLTYPE GetMulticastListSize(ULONG *pulcbAddresses);
21     HRESULT STDMETHODCALLTYPE PutMulticastList(ULONG ulcbAddresses, BYTE * pAddressList);
22     HRESULT STDMETHODCALLTYPE GetMulticastList(ULONG *pulcbAddresses, BYTE *pAddressList);
23     HRESULT STDMETHODCALLTYPE PutMulticastMode(ULONG ulModeMask);
24     HRESULT STDMETHODCALLTYPE GetMulticastMode(ULONG *pulModeMask);
25 
26 
27     CEthernetFilter(IBDA_NetworkProvider * pNetworkProvider);
28     virtual ~CEthernetFilter();
29 
30 protected:
31     IBDA_NetworkProvider * m_pNetworkProvider;
32     ULONG m_ulcbAddresses;
33     BYTE * m_pAddressList;
34     ULONG m_ulModeMask;
35 };
36 
CEthernetFilter(IBDA_NetworkProvider * pNetworkProvider)37 CEthernetFilter::CEthernetFilter(
38     IBDA_NetworkProvider * pNetworkProvider) : m_pNetworkProvider(pNetworkProvider),
39                                                m_ulcbAddresses(0),
40                                                m_pAddressList(0),
41                                                m_ulModeMask(0)
42 {
43 }
44 
~CEthernetFilter()45 CEthernetFilter::~CEthernetFilter()
46 {
47     if (m_pAddressList)
48         CoTaskMemFree(m_pAddressList);
49 }
50 
51 HRESULT
52 STDMETHODCALLTYPE
QueryInterface(REFIID InterfaceId,PVOID * Interface)53 CEthernetFilter::QueryInterface(
54     REFIID InterfaceId,
55     PVOID* Interface)
56 {
57     assert(m_pNetworkProvider);
58     return m_pNetworkProvider->QueryInterface(InterfaceId, Interface);
59 }
60 
61 ULONG
62 STDMETHODCALLTYPE
AddRef()63 CEthernetFilter::AddRef()
64 {
65     assert(m_pNetworkProvider);
66     return m_pNetworkProvider->AddRef();
67 }
68 
69 ULONG
70 STDMETHODCALLTYPE
Release()71 CEthernetFilter::Release()
72 {
73     assert(m_pNetworkProvider);
74     return m_pNetworkProvider->Release();
75 }
76 
77 //-------------------------------------------------------------------
78 //IBDA_EthernetFilter
79 //
80 
81 HRESULT
82 STDMETHODCALLTYPE
PutMulticastList(ULONG ulcbAddresses,BYTE * pAddressList)83 CEthernetFilter::PutMulticastList(
84     ULONG ulcbAddresses,
85     BYTE * pAddressList)
86 {
87     if (!ulcbAddresses || !pAddressList)
88         return E_POINTER;
89 
90     if (m_pAddressList)
91         CoTaskMemFree(m_pAddressList);
92 
93     m_pAddressList = (BYTE*)CoTaskMemAlloc(ulcbAddresses);
94     if (!m_pAddressList)
95         return E_OUTOFMEMORY;
96 
97     CopyMemory(m_pAddressList, pAddressList, ulcbAddresses);
98     m_ulcbAddresses = ulcbAddresses;
99     return NOERROR;
100 }
101 
102 HRESULT
103 STDMETHODCALLTYPE
GetMulticastList(ULONG * pulcbAddresses,BYTE * pAddressList)104 CEthernetFilter::GetMulticastList(
105     ULONG *pulcbAddresses,
106     BYTE *pAddressList)
107 {
108     if (!pulcbAddresses || !pAddressList)
109         return E_POINTER;
110 
111     if (*pulcbAddresses < m_ulcbAddresses)
112         return E_OUTOFMEMORY;
113 
114     CopyMemory(pAddressList, m_pAddressList, m_ulcbAddresses);
115     *pulcbAddresses = m_ulcbAddresses;
116     return NOERROR;
117 }
118 
119 HRESULT
120 STDMETHODCALLTYPE
GetMulticastListSize(ULONG * pulcbAddresses)121 CEthernetFilter::GetMulticastListSize(
122     ULONG *pulcbAddresses)
123 {
124     if (!pulcbAddresses)
125         return E_POINTER;
126 
127     *pulcbAddresses = m_ulcbAddresses;
128     return NOERROR;
129 }
130 
131 HRESULT
132 STDMETHODCALLTYPE
PutMulticastMode(ULONG ulModeMask)133 CEthernetFilter::PutMulticastMode(
134     ULONG ulModeMask)
135 {
136     m_ulModeMask = ulModeMask;
137     return NOERROR;
138 }
139 
140 HRESULT
141 STDMETHODCALLTYPE
GetMulticastMode(ULONG * pulModeMask)142 CEthernetFilter::GetMulticastMode(
143     ULONG *pulModeMask)
144 {
145     *pulModeMask = m_ulModeMask;
146     return NOERROR;
147 }
148 
149 HRESULT
150 WINAPI
CEthernetFilter_fnConstructor(IBDA_NetworkProvider * pNetworkProvider,REFIID riid,LPVOID * ppv)151 CEthernetFilter_fnConstructor(
152     IBDA_NetworkProvider * pNetworkProvider,
153     REFIID riid,
154     LPVOID * ppv)
155 {
156     CEthernetFilter * filter = new CEthernetFilter(pNetworkProvider);
157 
158     if (!filter)
159         return E_OUTOFMEMORY;
160 
161     if (FAILED(filter->QueryInterface(riid, ppv)))
162     {
163         /* not supported */
164         delete filter;
165         return E_NOINTERFACE;
166     }
167 
168     return NOERROR;
169 }
170