summaryrefslogtreecommitdiff
path: root/utils/MTP/MTP_DLL/sendfirm_win.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/MTP/MTP_DLL/sendfirm_win.cpp')
-rw-r--r--utils/MTP/MTP_DLL/sendfirm_win.cpp244
1 files changed, 159 insertions, 85 deletions
diff --git a/utils/MTP/MTP_DLL/sendfirm_win.cpp b/utils/MTP/MTP_DLL/sendfirm_win.cpp
index e895c024fd..0861b345b0 100644
--- a/utils/MTP/MTP_DLL/sendfirm_win.cpp
+++ b/utils/MTP/MTP_DLL/sendfirm_win.cpp
@@ -11,6 +11,26 @@
11#include "sac.h" 11#include "sac.h"
12#include "scclient.h" 12#include "scclient.h"
13 13
14class CProgressHelper :
15 public IWMDMProgress
16{
17 void (*m_callback)(unsigned int progress, unsigned int max);
18 DWORD m_max_ticks;
19 DWORD m_cur_ticks;
20 DWORD m_counter;
21
22public:
23 CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) );
24 ~CProgressHelper();
25 STDMETHOD(Begin)( DWORD dwEstimatedTicks );
26 STDMETHOD(Progress)( DWORD dwTranspiredTicks );
27 STDMETHOD(End)();
28
29 STDMETHOD(QueryInterface) ( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject );
30 STDMETHOD_(ULONG, AddRef)( void );
31 STDMETHOD_(ULONG, Release)( void );
32};
33
14/* 34/*
15 * Compilation requirements: 35 * Compilation requirements:
16 * 36 *
@@ -21,74 +41,66 @@
21 * 41 *
22 */ 42 */
23extern "C" { 43extern "C" {
24__declspec(dllexport) bool send_fw(LPWSTR file, int filesize) 44__declspec(dllexport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max))
25{ 45{
26 bool return_value = false; 46 bool return_value = false;
27 HRESULT hr; 47 HRESULT hr;
28 IComponentAuthenticate* pICompAuth; 48 IComponentAuthenticate* pICompAuth;
29 CSecureChannelClient *m_pSacClient = new CSecureChannelClient; 49 CSecureChannelClient *m_pSacClient = new CSecureChannelClient;
30 IWMDeviceManager3* m_pIdvMgr = NULL; 50 IWMDeviceManager3* m_pIdvMgr = NULL;
31 51
32 /* these are generic keys */ 52 /* these are generic keys */
33 BYTE abPVK[] = {0x00}; 53 BYTE abPVK[] = {0x00};
34 BYTE abCert[] = {0x00}; 54 BYTE abCert[] = {0x00};
35 55
36 CoInitialize(NULL); 56 CoInitialize(NULL);
37 57
38 /* get an authentication interface */ 58 /* get an authentication interface */
39 hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL ,IID_IComponentAuthenticate, (void **)&pICompAuth); 59 hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL ,IID_IComponentAuthenticate, (void **)&pICompAuth);
40 if SUCCEEDED(hr) 60 if SUCCEEDED(hr)
41 { 61 {
42 /* create a secure channel client certificate */ 62 /* create a secure channel client certificate */
43 hr = m_pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert, sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK)); 63 hr = m_pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert, sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK));
44 if SUCCEEDED(hr) 64 if SUCCEEDED(hr)
45 { 65 {
46 /* bind the authentication interface to the secure channel client */ 66 /* bind the authentication interface to the secure channel client */
47 m_pSacClient->SetInterface(pICompAuth); 67 m_pSacClient->SetInterface(pICompAuth);
48 68
49 /* trigger communication */ 69 /* trigger communication */
50 hr = m_pSacClient->Authenticate(SAC_PROTOCOL_V1); 70 hr = m_pSacClient->Authenticate(SAC_PROTOCOL_V1);
51 if SUCCEEDED(hr) 71 if SUCCEEDED(hr)
52 { 72 {
53 /* get main interface to media device manager */ 73 /* get main interface to media device manager */
54 hr = pICompAuth->QueryInterface(IID_IWMDeviceManager2, (void**)&m_pIdvMgr); 74 hr = pICompAuth->QueryInterface(IID_IWMDeviceManager2, (void**)&m_pIdvMgr);
55 if SUCCEEDED(hr) 75 if SUCCEEDED(hr)
56 { 76 {
57 /* enumerate devices... */ 77 /* enumerate devices... */
58 IWMDMEnumDevice *pIEnumDev; 78 IWMDMEnumDevice *pIEnumDev;
59 hr = m_pIdvMgr->EnumDevices2(&pIEnumDev); 79 hr = m_pIdvMgr->EnumDevices2(&pIEnumDev);
60 if SUCCEEDED(hr) 80 if SUCCEEDED(hr)
61 { 81 {
62 hr = pIEnumDev->Reset(); /* Next will now return the first device */ 82 hr = pIEnumDev->Reset(); /* Next will now return the first device */
63 if SUCCEEDED(hr) 83 if SUCCEEDED(hr)
64 { 84 {
65 IWMDMDevice3* pIDevice; 85 IWMDMDevice3* pIDevice;
66 unsigned long ulNumFetched; 86 unsigned long ulNumFetched;
67 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched); 87 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
68 while (SUCCEEDED(hr) && (hr != S_FALSE)) 88 while (SUCCEEDED(hr) && (hr != S_FALSE))
69 { 89 {
70#if 0 90 /* get storage info */
71 /* output device name */ 91 DWORD tempDW;
72 wchar_t pwsString[256]; 92 pIDevice->GetType(&tempDW);
73 hr = pIDevice->GetName(pwsString, 256); 93 if (tempDW & WMDM_DEVICE_TYPE_STORAGE)
74 if SUCCEEDED(hr)
75 wprintf(L"Found device %s\n", pwsString);
76#endif
77
78 /* get storage info */
79 DWORD tempDW;
80 pIDevice->GetType(&tempDW);
81 if (tempDW & WMDM_DEVICE_TYPE_STORAGE)
82 { 94 {
83 IWMDMEnumStorage *pIEnumStorage = NULL; 95 IWMDMEnumStorage *pIEnumStorage = NULL;
84 IWMDMStorage *pIStorage = NULL; 96 IWMDMStorage *pIStorage = NULL;
85 IWMDMStorage3 *pIFileStorage = NULL; 97 IWMDMStorage3 *pIFileStorage = NULL;
86 hr = pIDevice->EnumStorage(&pIEnumStorage); 98 hr = pIDevice->EnumStorage(&pIEnumStorage);
87 if SUCCEEDED(hr) 99 if SUCCEEDED(hr)
88 { 100 {
89 pIEnumStorage->Reset(); 101 pIEnumStorage->Reset();
90 hr = pIEnumStorage->Next(1, (IWMDMStorage **)&pIStorage, &ulNumFetched); 102 hr = pIEnumStorage->Next(1, (IWMDMStorage **)&pIStorage, &ulNumFetched);
91 while (SUCCEEDED(hr) && (hr != S_FALSE)) 103 while (SUCCEEDED(hr) && (hr != S_FALSE))
92 { 104 {
93 IWMDMStorage3 *pNewStorage; 105 IWMDMStorage3 *pNewStorage;
94 hr = pIStorage->QueryInterface(IID_IWMDMStorage3, (void **)&pNewStorage); 106 hr = pIStorage->QueryInterface(IID_IWMDMStorage3, (void **)&pNewStorage);
@@ -113,14 +125,15 @@ __declspec(dllexport) bool send_fw(LPWSTR file, int filesize)
113 if (SUCCEEDED(hr)) 125 if (SUCCEEDED(hr))
114 { 126 {
115 IWMDMStorage *pNewObject = NULL; 127 IWMDMStorage *pNewObject = NULL;
128 CProgressHelper *progress = new CProgressHelper(callback);
116 129
117 hr = pIWMDMStorageControl->Insert3( 130 hr = pIWMDMStorageControl->Insert3(
118 WMDM_MODE_BLOCK | WMDM_CONTENT_FILE, 131 WMDM_MODE_BLOCK | WMDM_CONTENT_FILE | WMDM_MODE_PROGRESS,
119 0, 132 0,
120 file, 133 file,
121 NULL, 134 NULL,
122 NULL, 135 NULL,
123 NULL, 136 (callback == NULL ? NULL : (IWMDMProgress*)progress),
124 pIWMDMMetaData, 137 pIWMDMMetaData,
125 NULL, 138 NULL,
126 (IWMDMStorage **)&pNewObject); 139 (IWMDMStorage **)&pNewObject);
@@ -135,27 +148,88 @@ __declspec(dllexport) bool send_fw(LPWSTR file, int filesize)
135 } 148 }
136 } 149 }
137 } 150 }
138 } 151 }
139 } 152 }
140 pIEnumStorage->Release(); 153 pIEnumStorage->Release();
141 } 154 }
142 155
143 /* move to next device */ 156 /* move to next device */
144 if(!return_value) 157 if(!return_value)
145 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched); 158 hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched);
146 } 159 }
147 pIEnumDev->Release(); 160 pIEnumDev->Release();
148 } 161 }
149 m_pIdvMgr->Release(); 162 m_pIdvMgr->Release();
150 } 163 }
151 pICompAuth->Release(); 164 pICompAuth->Release();
152 } 165 }
153 } 166 }
154 } 167 }
155 } 168 }
156 169
157 CoUninitialize(); 170 CoUninitialize();
158 171
159 return return_value; 172 return return_value;
173}
174}
175
176
177CProgressHelper::CProgressHelper( void (*callback)(unsigned int progress, unsigned int max) )
178{
179 m_cur_ticks = 0;
180 m_max_ticks = 0;
181 m_counter = 0;
182
183 m_callback = callback;
184}
185
186CProgressHelper::~CProgressHelper()
187{
160} 188}
189
190HRESULT CProgressHelper::Begin( DWORD dwEstimatedTicks )
191{
192 m_max_ticks = dwEstimatedTicks;
193
194 return S_OK;
195}
196
197HRESULT CProgressHelper::Progress( DWORD dwTranspiredTicks )
198{
199 m_cur_ticks = dwTranspiredTicks;
200
201 if(m_callback != NULL)
202 m_callback(m_cur_ticks, max(m_max_ticks, m_cur_ticks));
203
204 return S_OK;
205}
206
207HRESULT CProgressHelper::End()
208{
209 m_cur_ticks = m_max_ticks;
210
211 return S_OK;
212}
213
214HRESULT CProgressHelper::QueryInterface( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject )
215{
216 if(riid == IID_IWMDMProgress || riid == IID_IUnknown)
217 {
218 *ppvObject = this;
219 return S_OK;
220 }
221 else
222 {
223 *ppvObject = NULL;
224 return E_NOINTERFACE;
225 }
226}
227
228ULONG CProgressHelper::AddRef()
229{
230 return m_counter++;
231}
232ULONG CProgressHelper::Release()
233{
234 return m_counter--;
161} 235}