Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SNTP in WINCE 6.0

740 views
Skip to first unread message

Salim

unread,
Mar 8, 2010, 5:56:01 AM3/8/10
to
Hi,

I tried to sync my device (Win CE 6.0) time using SNTP. All the SNTP IOCTL
's are working except "IOCTL_SERVICE_CONTROL". When i call Service IOCTL ,
Invalid parameter error is occurring. I am using the following code

WCHAR szControlString[]=L"sync";
DWORD dwLenIn=sizeof(szControlString);
DWORD dwBytesReturned;

DeviceIoControl(hFile, IOCTL_SERVICE_CONTROL, szControlString, dwLenIn,
NULL, 0, &dwBytesReturned, NULL);
return 0;
}
and registry settings are

[HKEY_LOCAL_MACHINE\Services\TIMESVC]
"server"=multi_sz:"pool.ntp.org"

"AutoUpdate"=dword:1
"ServerRole"=dword:0
"refresh"=dword:1B7740
"recoveryrefresh"=dword:493E0
"threshold"=dword:DBBA0
"trustlocalclock"=dword:1

Even I tried by reducing the refresh and recovery time.

Following Sysgen variable are selected
SYSGEN_TIMESVC_API, SYSGEN_TIMESVC_DST and SYSGEN_TIMESVC_SNTP

Thanks,

Bruce Eitman [eMVP]

unread,
Mar 8, 2010, 10:08:54 AM3/8/10
to
> DWORD dwLenIn=sizeof(szControlString);

might not give you the length that you need.

Try DWORD dwLenIn=sizeof(L"sync");


--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT Eurotech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

Eurotech Inc.
www.Eurotech.com

"Salim" <Sa...@discussions.microsoft.com> wrote in message
news:5ABB8486-3A20-4FA2...@microsoft.com...

Fabrice MOUSSET

unread,
Mar 8, 2010, 11:07:20 AM3/8/10
to
I think there is a mistake with dwLenIn;

DWORD dwLenIn=sizeof(szControlString); ==> 4 which is the size of a
WCHAR pointer

DWORD dwLenIn=wcslen(szControlString); ==> size of the WCHAR string

regards

Fabrice

Le 08/03/2010 11:56, Salim a écrit :
> Hi,
>
> I tried to sync my device (Win CE 6.0) time using SNTP. All the SNTP IOCTL
> 's are working except "IOCTL_SERVICE_CONTROL". When i call Service IOCTL ,
> Invalid parameter error is occurring. I am using the following code
>
> WCHAR szControlString[]=L"sync";
> DWORD dwLenIn=sizeof(szControlString);
> DWORD dwBytesReturned;
>
> DeviceIoControl(hFile, IOCTL_SERVICE_CONTROL, szControlString, dwLenIn,

> NULL, 0,&dwBytesReturned, NULL);

Bruce Eitman [eMVP]

unread,
Mar 8, 2010, 11:25:42 AM3/8/10
to
I am not a fan of code that uses sizeof that way, but the SMTP server is
using sizeof(L"sync") to validate the parameters.

--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT Eurotech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

Eurotech Inc.
www.Eurotech.com

"Fabrice MOUSSET" <fabrice...@laposte.net> wrote in message
news:u9VFxlt...@TK2MSFTNGP02.phx.gbl...


I think there is a mistake with dwLenIn;

DWORD dwLenIn=sizeof(szControlString); ==> 4 which is the size of a
WCHAR pointer

DWORD dwLenIn=wcslen(szControlString); ==> size of the WCHAR string

regards

Fabrice

Le 08/03/2010 11:56, Salim a �crit :

Fabrice MOUSSET

unread,
Mar 8, 2010, 11:41:47 AM3/8/10
to
Hi Salim,
I also have create a little peace of software to resynchronize the RTC
with a time server.

bellow my code:

int _tmain(int argc, TCHAR *argv[], TCHAR *envp[])
{
HANDLE
hFile=CreateFile(L"NTP0:",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);


WCHAR szControlString[]=L"sync";
DWORD dwLenIn=sizeof(szControlString);
DWORD dwBytesReturned;

if(INVALID_HANDLE_VALUE==hFile)
{
_tprintf(_T("NTP Driver openning error :-(\n"));
return 0;
}

_tprintf(_T("Starting NTP\n"));
DeviceIoControl(hFile, IOCTL_SERVICE_START, NULL, 0, NULL, 0, NULL,
NULL);

_tprintf(_T("Force NTP synchronization\n"));


DeviceIoControl(hFile, IOCTL_SERVICE_CONTROL, szControlString,
dwLenIn, NULL, 0, &dwBytesReturned, NULL);

CloseHandle(hFile);
return 0;
}

And the registry is like this
; Réglage du client SNTP pour forcée la mise à jour
; automatique de la date et de l'heure
[HKEY_LOCAL_MACHINE\Services\Timesvc]
"AutoUpdate"=dword:1
"ClientOnly"=dword:1
"AutoDST"=dword:1
"Trustlocalclock"=dword:0
"Refresh"=dword:48190800 ; 2 weeks
"RecoveryRefresh"=dword:1B7740 ; 30 minutes
"Threshold"=dword:5265C00 ; 1 day
"Server"="pool.ntp.org"


Hope this help

Fabrice

Le 08/03/2010 11:56, Salim a écrit :
> Hi,
>
> I tried to sync my device (Win CE 6.0) time using SNTP. All the SNTP IOCTL
> 's are working except "IOCTL_SERVICE_CONTROL". When i call Service IOCTL ,
> Invalid parameter error is occurring. I am using the following code
>
> WCHAR szControlString[]=L"sync";
> DWORD dwLenIn=sizeof(szControlString);
> DWORD dwBytesReturned;
>
> DeviceIoControl(hFile, IOCTL_SERVICE_CONTROL, szControlString, dwLenIn,

> NULL, 0,&dwBytesReturned, NULL);

Salim

unread,
Mar 9, 2010, 7:00:03 AM3/9/10
to
Thanks to all,

Let me check it.

"Fabrice MOUSSET" wrote:

> .
>

Salim

unread,
Mar 9, 2010, 9:36:01 AM3/9/10
to
Hi,

I tried by changing as you said but no luck. Still i am getting the same
error. Do i missing something in the sysgen or updates?

"Fabrice MOUSSET" wrote:

> .
>

Bruce Eitman [eMVP]

unread,
Mar 9, 2010, 9:51:44 AM3/9/10
to
You tried what that who said?

--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT Eurotech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

Eurotech Inc.
www.Eurotech.com

"Salim" <Sa...@discussions.microsoft.com> wrote in message
news:6AC102CC-A3B2-4600...@microsoft.com...

>> ; R�glage du client SNTP pour forc�e la mise � jour


>> ; automatique de la date et de l'heure
>> [HKEY_LOCAL_MACHINE\Services\Timesvc]
>> "AutoUpdate"=dword:1
>> "ClientOnly"=dword:1
>> "AutoDST"=dword:1
>> "Trustlocalclock"=dword:0
>> "Refresh"=dword:48190800 ; 2 weeks
>> "RecoveryRefresh"=dword:1B7740 ; 30 minutes
>> "Threshold"=dword:5265C00 ; 1 day
>> "Server"="pool.ntp.org"
>>
>>
>> Hope this help
>>
>> Fabrice
>>

>> Le 08/03/2010 11:56, Salim a �crit :

Paul G. Tobey [ eMVP ]

unread,
Mar 9, 2010, 3:51:02 PM3/9/10
to
There are a number of restrictions on the registry parameters for SNTP
synchronization that you have to respect. If the server won't sync, the
most-likely cause is that you've done something that you think makes sense
for quick testing, but which the service rejects as unreasonable, or that
you're malforming your IoControl command.

For parameters:

1. Don't set the frequency of sync (Refresh), to less than 5 minutes, as the
server will reject that. The value for 5 minutes is, of course, 5*60*1000
milliseconds.

2. Set Threshold to a large number. If you set it small, the amount of
correction, particularly if your time zone is set wrong, will be too much and
the sync will fail. This shouldn't cause a parameter error, but the sync
will not happen.

3. Set the recovery interval (RecoveryRefresh), to 5 minutes or more, but to
a value less than the refresh interval. If it's greater than the refresh
interval, you'll get an error.

4. For the Server list, you might try double-null terminating the list
something like this:

"Server"=multi_sz:"pool.ntp.org\0\0"

or not using a multi_sz registry type for the data:

"Server"="pool.ntp.org"

I don't have any examples of setting the server in a REG file, but my code
always double-nulls the end of the list. Note that Fabrice's example does
NOT use multi_sz and the server seems to be OK with that.

For IoControl:

The control calls for Sync and Set don't have return data, so you don't need
to pass a return buffer or a pointer for return of bytesReturned.

Paul T.

"Bruce Eitman [eMVP]" wrote:

> >> ; Réglage du client SNTP pour forcée la mise à jour

> .
>

Salim

unread,
Mar 10, 2010, 3:01:01 AM3/10/10
to
Thanks Paul,

As you said i tried still no luck. Actually network is connected through
GPRS, is any other registry need for GPRS? My GPRS is connected and i am able
to browse.

Paul G. Tobey [ eMVP ]

unread,
Mar 10, 2010, 10:58:01 AM3/10/10
to

No. Your GPRS provider might not allow you to connect to ports other than
POP3, HTTP, and IMAP, though, and that would prevent things from working.
You don't have a means to try some other form of networking for comparison?

Paul T.

Salim

unread,
Mar 11, 2010, 5:28:01 AM3/11/10
to

Thanks Paul,

We have WiFi in the board. I tried with the WiFi. No change in the status. I
tested with the Rebex tool, through that tool i am able to receive the time.

Apart from using IO_CONTROL, is there any other way to test it. As we have
"Update Now" facility in PC.

Paul G. Tobey [ eMVP ]

unread,
Mar 11, 2010, 10:48:02 AM3/11/10
to
The fix is going to require you to debug the SNTP service, I think.
IoControl is the method of forcing an update right now. Once you've set the
parameters, of course, you've also configured the service to periodically
update the time, too.

So, build a DEBUG OS image, set some breakpoints in the SNTP service, run
your program and track down where the service is deciding that there's a
parameter problem. That will point you to the solution, which I'm betting is
a change to the registry settings, despite not seeing any problem with your
settings myself.

Paul T.

Salim

unread,
Mar 17, 2010, 9:29:01 AM3/17/10
to

Hi Paul,

Strange, it is working in debug build but it is not working in release
build. What could be the reason? Does it required some delay?

Thanks

"Paul G. Tobey [eMVP]" wrote:

Paul G. Tobey [ eMVP ]

unread,
Mar 17, 2010, 11:35:01 AM3/17/10
to
No. The transactions with the time server could be affected by the timing
differences in a DEBUG build, but the actual code operations never seemed to
be to me. Make sure that your various times, refresh interval, etc. are all
much longer than any time that you might spend debugging. The next time you
build the RETAIL build, do a Clean Sysgen. That's about all I can think of...

Paul T.

Salim

unread,
Mar 18, 2010, 3:09:01 AM3/18/10
to
Hi Paul,

I think i found the issue. I think there is some issue with the default
release timesvc.dll. I just rebuild the TIMESVC2 folder under
Private\servers\ .
Thanks for the help.

Paul G. Tobey [ eMVP ]

unread,
Mar 18, 2010, 11:29:02 AM3/18/10
to
You installed all of the QFEs? That's a pretty suspicious problem.
0 new messages