4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "Util/Macros.hpp"
26 #include "LogFile.hpp"
27 #include "UtilsSystem.hpp"
28 #include "LocalPath.hpp"
29 #include "IO/FileHandle.hpp"
30 #include "Util/CharUtil.hpp"
32 #if defined(WIN32) && (!defined(__GNUC__) || defined(_WIN32_WCE))
37 #include <windef.h> /* for MAX_PATH */
41 TCHAR asset_number
[100] = _T(""); //4G17DW31L0HY");
43 #ifdef HAVE_MODEL_TYPE
44 ModelType global_model_type
= ModelType::GENERIC
;
49 SetAssetNumber(const TCHAR
*p
)
52 while (length
< ARRAY_SIZE(asset_number
) - 1 && *p
!= _T('\0')) {
53 if (IsAlphaNumericASCII(*p
))
54 asset_number
[length
++] = *p
;
59 asset_number
[0] = _T('\0');
70 #if defined(_WIN32_WCE)
71 PROCESS_INFORMATION pi
;
73 if (CreateProcess(_T("\\windows\\CreateAssetFile.exe"), NULL
, NULL
, NULL
,
74 FALSE
, 0, NULL
, NULL
, NULL
, &pi
)) {
75 WaitForSingleObject(pi
.hProcess
, 1000);
76 CloseHandle(pi
.hProcess
);
77 CloseHandle(pi
.hThread
);
80 FileHandle
file(_T("\\windows\\cpqAssetData.dat"), _T("rb"));
81 if (!file
.IsOpen() || !file
.Seek(976, SEEK_SET
))
84 TCHAR buffer
[ARRAY_SIZE(asset_number
)];
85 size_t length
= file
.Read(buffer
, ARRAY_SIZE(buffer
) - 1, sizeof(buffer
[0]));
86 buffer
[length
] = _T('\0');
87 return SetAssetNumber(buffer
);
96 #if defined(_WIN32_WCE) && defined(IOCTL_HAL_GET_DEVICEID) && defined(FILE_DEVICE_HAL)
99 #define GUIDBuffsize 100
100 unsigned char GUIDbuffer
[GUIDBuffsize
];
104 unsigned long uNumReturned
=0;
106 unsigned long temp
, Asset
;
110 // approach followed: http://blogs.msdn.com/jehance/archive/2004/07/12/181116.aspx
111 // 1) send 16 byte buffer - some older devices need this
112 // 2) if buffer is wrong size, resize buffer accordingly and retry
113 // 3) take first 16 bytes of buffer and process. Buffer returned may be any size
114 // First try exactly 16 bytes, some older PDAs require exactly 16 byte buffer
116 asset_number
[0]= '\0';
118 iBuffSizeIn
= sizeof(Guid
);
119 memset(GUIDbuffer
, 0, iBuffSizeIn
);
120 fRes
= KernelIoControl(IOCTL_HAL_GET_DEVICEID
, 0, 0, GUIDbuffer
,
121 iBuffSizeIn
, &uNumReturned
);
124 eLast
= GetLastError();
125 if (ERROR_INSUFFICIENT_BUFFER
!= eLast
)
129 iBuffSizeIn
= uNumReturned
;
130 memset(GUIDbuffer
, 0, iBuffSizeIn
);
131 fRes
= KernelIoControl(IOCTL_HAL_GET_DEVICEID
, 0, 0, GUIDbuffer
,
132 iBuffSizeIn
, &uNumReturned
);
133 eLast
= GetLastError();
140 // here assume we have data in GUIDbuffer of length uNumReturned
141 memcpy(&Guid
, GUIDbuffer
, sizeof(Guid
));
147 Asset
= temp
^ Guid
.Data1
;
150 for(i
= 0; i
< 4; i
++) {
152 temp
+= Guid
.Data4
[i
];
155 Asset
= Asset
^ temp
;
158 for(i
= 0; i
< 4; i
++) {
160 temp
+= Guid
.Data4
[i
+ 4];
163 Asset
= Asset
^ temp
;
166 _stprintf(asset_number
, _T("%08X%08X"), Asset
, Guid
.Data1
);
167 return SetAssetNumber(buffer
);
176 if (ReadCompaqID()) {
177 LogFormat(_T("Asset ID: %s (compaq)"), asset_number
);
178 } else if (ReadUUID()) {
179 LogFormat(_T("Asset ID: %s (uuid)"), asset_number
);
181 _tcscpy(asset_number
, _T("AAA"));
182 LogFormat(_T("Asset ID: %s (fallback)"), asset_number
);