Rajat Solanky (MCSE, MCSD)

Hi theres,
i am working with .net CF 2.0 for smart phone and pocket pc.
i have applied lots of search to get the help and still i am being with the stuff, if any one know some stuff about that how to get IMEI no to mobile please guide me.
with one condition that i need only logic how to get it, not need any dll, please concern my thoughts.
thanks
bye
regards Rajat.


Re: .NET Compact Framework how to get IMEI no.?

AlexFeinman

There is no way to get IMEI that would work on every device. Basically, the IMEI on device is protected from applications on purpose. If you need to be able to tie your application to the device, use GetDeviceUniqueID API (P/Invoke it) as shown in the SDK sample:

http://msdn2.microsoft.com/en-us/library/ms880643.aspx






Re: .NET Compact Framework how to get IMEI no.?

Rajat Solanky

Hi,
Thanks for concern me and my problem.
but i could not use GetDevice..... api because i need IMEI number only.
i hope you will concern my thought.
bye
regards Rajat





Re: .NET Compact Framework how to get IMEI no.?

Michael Koster

Hi Rajat

The Extended TAPI API lineGetGeneralInfo returns the IMEI number. MSDN has all the details on how to use it.

A managed sample can be found here: http://peterfoot.net/RetrieveIMEIThroughTAPI.aspx

The managed TAPI wrapper mensioned in this post is now a product from OpenNETCF.com (see here). If you do not want to license this library you'll most likely have to write your own wrapper library.

Regards

Michael






Re: .NET Compact Framework how to get IMEI no.?

Rajat Solanky

Hi AlexFeinman,
okay that we have to use separete application to get imei number for each mobile.
i am working with window mobile and at present i want to get imei number only for it.
i hope it will give some special way.
bye
regards Rajat.





Re: .NET Compact Framework how to get IMEI no.?

AlexFeinman

Michael Koster wrote:

Hi Rajat

The Extended TAPI API lineGetGeneralInfo returns the IMEI number. MSDN has all the details on how to use it.

A managed sample can be found here: http://peterfoot.net/RetrieveIMEIThroughTAPI.aspx

The managed TAPI wrapper mensioned in this post is now a product from OpenNETCF.com (see here). If you do not want to license this library you'll most likely have to write your own wrapper library.

Regards

Michael

Michael,

I wrote the aforementioned tapi wrapper. The reason I said there is no bulletproof way to get IMEI on every device is that on some of them lineGetgeneralInfo is a privileged call. Unless he can get a device certificate or an operator certificate from every operator he ships with, there is no way to guarantee this functionality. This is the primary reason I did not even suggest using TAPI.






Re: .NET Compact Framework how to get IMEI no.?

Rajat Solanky

Hi Michael Koster,
thnaks for sending the link but i already used it and i gives a error.
1)win32Exception was unhandled. (Tapi error : 6)
after coment the above line i will give new error.
2)Specified argument was out of the range of valid values.
this error is coming on line no. 11 of the getGeneralInfo methods.
may be this information will help you to suggest me what should do next.
thanks
bye
regards Rajat






Re: .NET Compact Framework how to get IMEI no.?

nortsiw_kaka

I can use RIL function to get it,

RIL_Initialize(1,
g_RHAP_RilResultCallBackFunc,
g_RHAP_RilNotifyCallBackFunc,
RIL_NCLASS_FUNCRESULT|RIL_NCLASS_MISC|RIL_NCLASS_RADIOSTATE,
0,
hRil);

//
// RIL callback function for init ril handle.
//
void CALLBACK g_RHAP_RilResultCallBackFunc(DWORD dwResultCode, HRESULT hrCommandID,
const void* pData, DWORD dwDataSize, DWORD dwParam)
{
LPRILEQUIPMENTINFO info =(LPRILEQUIPMENTINFO)pData;
memset(info,0,sizeof(info));

MultiByteToWideChar(CP_ACP,
MB_PRECOMPOSED,
(const char *)info->szRevision,
sizeof(info->szRevision),
g_szRevision,
128);
MultiByteToWideChar(CP_ACP,
MB_PRECOMPOSED,
(const char *)info->szSerialNumber,
sizeof(info->szSerialNumber),
g_szSerialNumber,
128);
g_cImei->ShowInfo();
}






Re: .NET Compact Framework how to get IMEI no.?

Michael Koster

Hi

I do not recommend using this approach at all.

Using the RIL directly is neither documented nor supported for all Windows Mobile platforms. The publically available documentation only applies to Windows Embedded CE 6.0.

Secondly the RIL APIs are considered privileged as well (see here).

So the only documented way of getting the IMEI number is to use TAPI.

Alex has a very valid point: The required TAPI API is privileged as well. Depending on the devices / Operator security configuration you have to sign your application with a privileged certificate accepted by the device.

Most Operators do support the Mobile2Market privileged certs.

If you really need the IMEI number take a look at the native C++ named 'ExTAPI' shipped in the Windows Mobile 5.0 SDKs (here). If this sample works for you - Id consider writing a small C/C++ DLL that uses TAPI to read and return the IMEI.






Re: .NET Compact Framework how to get IMEI no.?

shadowmite

While all these statements about this not being possible seem to be all over the net since Alex's codebase started being sold for astronomical amounts, the answer does still exist out there for free, try:
http://dotnetslackers.com/community/blogs/ruslantrifonov/archive/2007/07/10/_2200_How-To_2200_-Series_3A00_-Retrieving-IMSI-and-IMEI-on-Windows-Mobile.aspx




Re: .NET Compact Framework how to get IMEI no.?

Rajat Solanky

Hi,
THANKS A LOT.
i don't have words to say thank, but thanks to concern and sending me FINAL, ACCOMPLISH ANSWER.
may i get your e-mail id
please, despritally i am waiting.
bye
regards Rajat.





Re: .NET Compact Framework how to get IMEI no.?

Rajat Solanky

Hi nortsiw_kaka,
I am working with CF 2.0 for Windows Mobile usign .net.
here I am sending my code that will being easy for you to understand my problem.
=======CODE START=====a===
using System;
using System.Collections;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml;
using System.IO;

namespace TAPI
{
public static class PhoneInfo
{

public static void Get(out string manufacturer, out string model, out string revision, out string serialNumber, out string subsciberId)
{
IntPtr hLine;
int dwNumDev;
int num1 = 0x20000;
LINEINITIALIZEEXPARAMS lineInitializeParams = new LINEINITIALIZEEXPARAMS();
lineInitializeParams.dwTotalSize = (uint)Marshal.SizeOf(lineInitializeParams);
lineInitializeParams.dwNeededSize = lineInitializeParams.dwTotalSize;
lineInitializeParams.dwOptions = 2;
lineInitializeParams.hEvent = IntPtr.Zero;
lineInitializeParams.hCompletionPort = IntPtr.Zero;
#region lineInitializeEx
int result = Tapi.lineInitializeEx(out hLine, IntPtr.Zero,
IntPtr.Zero, null, out dwNumDev, ref num1, ref lineInitializeParams);
if (result != 0)
{
throw new ApplicationException(string.Format("lineInitializeEx failed!\n\nError Code:{0}", result.ToString()));
}
#endregion
#region lineNegotiateAPIVerison
int version;
int dwAPIVersionLow = 0x10004;
int dwAPIVersionHigh = 0x20000;
LINEEXTENSIONID lineExtensionID;
result = Tapi.lineNegotiateAPIVersion(hLine, 0, dwAPIVersionLow,dwAPIVersionHigh, out version, out lineExtensionID);
if (result != 0)
{
throw new ApplicationException(string.Format("lineNegotiateAPIVersion failed!\n\nError Code: {0}", result.ToString()));
}
#endregion

#region lineOpen
IntPtr hLine2 = IntPtr.Zero;
result = Tapi.lineOpen(hLine, 0, out hLine2, version, 0,IntPtr.Zero, 0x00000002, 0x00000004, IntPtr.Zero);
if (result != 0)
{
throw new ApplicationException(string.Format("lineNegotiateAPIVersion failed!\n\nError Code: {0}", result.ToString()));
}
#endregion

#region lineGetGeneralInfo
int structSize = Marshal.SizeOf(new LINEGENERALINFO());
byte[] bytes = new byte[structSize];
byte[] tmpBytes = BitConverter.GetBytes(structSize);

for (int index = 0; index < tmpBytes.Length; index++)
{
bytes[index] = tmpBytes[index];
}
#endregion

#region make initial query to retrieve necessary size
1 result = Tapi.lineGetGeneralInfo(hLine2, bytes);

// get the needed size
int neededSize = BitConverter.ToInt32(bytes, 4);

// resize the array
bytes = new byte[neededSize];

// write out the new allocated size to the byte stream
tmpBytes = BitConverter.GetBytes(neededSize);
for (int index = 0; index < tmpBytes.Length; index++)
{
bytes[index] = tmpBytes[index];
}

// fetch the information with properly size buffer
result = Tapi.lineGetGeneralInfo(hLine2, bytes);

if (result != 0)
{
throw new ApplicationException(Marshal.GetLastWin32Error().ToString());
}

#endregion

#region actual data fetching
int size;
int offset;

// manufacture
size = BitConverter.ToInt32(bytes, 12);
offset = BitConverter.ToInt32(bytes, 16);
manufacturer = Encoding.Unicode.GetString(bytes, offset, size);
manufacturer = manufacturer.Substring(0, manufacturer.IndexOf('\0'));

// model
size = BitConverter.ToInt32(bytes, 20);
offset = BitConverter.ToInt32(bytes, 24);
model = Encoding.Unicode.GetString(bytes, offset, size);
model = model.Substring(0, model.IndexOf('\0'));

// revision
size = BitConverter.ToInt32(bytes, 28);
offset = BitConverter.ToInt32(bytes, 32);
revision = Encoding.Unicode.GetString(bytes, offset, size);
revision = revision.Substring(0, revision.IndexOf('\0'));

// serial number
size = BitConverter.ToInt32(bytes, 36);
offset = BitConverter.ToInt32(bytes, 40);
serialNumber = Encoding.Unicode.GetString(bytes, offset, size);
serialNumber = serialNumber.Substring(0, serialNumber.IndexOf('\0'));

// subscriber id
//size = BitConverter.ToInt32(bytes, 44);
//offset = BitConverter.ToInt32(bytes, 48);
//subsciberId = Encoding.Unicode.GetString(bytes, offset, size);
//subsciberId = subsciberId.Substring(0, subsciberId.IndexOf('\0'));
subsciberId = "123";// serialNumber.Substring(0, serialNumber.IndexOf('\0'));

#endregion


//tear down
Tapi.lineClose(hLine2);
Tapi.lineShutdown(hLine);

}
}

}
========CODE END============
please consantrate the point 1 and bold line;
when I use the code on Pocket Pc 2003, It will run succssfully and "bytes" array type variable will fill exect required value, But The same code is raised a problam on the same line no 1 when I use Pocket Pc 2005.
Problem is the "bytes" variable does not fill this time with generalInfo of the system.
I dont know why is happening with 2005 for both system (pocket pc and smart phone 2005).
any one who has some idea about it please post me.
I would very thnakful to you.
bye
regards Rajat.






Re: .NET Compact Framework how to get IMEI no.?

Rajat Solanky

Hi,
Respectivally I am saying that I am respect your suggestion and I trust it but I need to get it.
Actually I need a unique thing for smart phone and pocket pc, I could get IMEI no for PPC, but asusual not for Smart phone.
so would you suggest any alternate approch to get unique Id for smart phone
I hope you got what I am saying, if yes than If you have any idea about it, send me or guide me.
I would very thankful to you.
bye
regards Rajat.






Re: .NET Compact Framework how to get IMEI no.?

Michael Koster

Hi Rajat

OK, you do only need a unique ID for a Windows Mobile device.

Provided that you do only need to support Windows Mobile 5.0 and newer use the API GetDeviceUniqueID for this purpose

Details see:

http://msdn2.microsoft.com/en-us/library/ms893522.aspx (API)

http://msdn2.microsoft.com/en-us/library/ms880643.aspx (Sample)

http://blogs.msdn.com/windowsmobile/archive/2006/01/09/510997.aspx

Regards

Michael






Re: .NET Compact Framework how to get IMEI no.?

Rajat Solanky

Hi Michael Koster,
thanks to be too fast to replly me.
I will soon send you feedback for GetDeviceUniqueId, because at present I am studing about it.
One major point let me think becuase I heared it that It has some kind of limitation and some time It will give same Id for devices, okay it is chance but It is possible.
So I am studing on it and soon I will send the result to my R&D.
but Once again I am very thankful to your's concern.
bye
regards Rajat.