IrDA Device Discovery

B

BeeEmm

I am trying to Discover Device using the following code snippet

byte[] buffer = irdaSocket.GetSocketOption((SocketOptionLevel)0xff,
SocketOptionName.DontRoute, 4 + (maxDevices * 32));

I found this somewhere on the web but I am tring to understand it a bit
more. Does anyone have a reference document that defines :

1. What format the data in "buffer" would be?
2. Why is (SocketOptionLevel)0xff used?
3. Why is SocketOptionName.DontRoute used?

The IRDA protocol I think will be TinyTP since it is windows but I'm
not sure.

By the way I am rolling my own code here because I want to use it on
..NET desktop not on the compact framework, so I cant use the assembly
provided there.

Thanks
BeeEmm
 
P

Peter Foot [MVP]

The IrDA classes as part of http://32feet.net work on both Compact and
desktop frameworks. It exposes additional functionality over and above the
..NETCF version.

Peter
 
B

BeeEmm

Peter,

Thanks for your reply. I think I have seen this site before but
unfortunately I cannot use it because it does not have source code and
I'm sure it is copyrighted. For my application I cannot use this
assembly.

I need to create my own source code. I would also like to get a better
understanding of IrDA communication within the .NET framework. I
especially want to knwo about the low level message format so I can
decode it.

Thanks
BeeEmm
 
P

Peter Foot [MVP]

Right, well under the hood it's all based around the IrDA extensions for
winsock which are included in the SDK in af_irda.h. This has all the Socket
Option constants and the definition of the structure used for device
information when you do a discovery.

Peter
 
A

Alan J. McFarlane

Seems Peter beat me to a reply, but I'm rather verbose as usual... :)

I am trying to Discover Device using the following code snippet

byte[] buffer = irdaSocket.GetSocketOption((SocketOptionLevel)0xff,
SocketOptionName.DontRoute, 4 + (maxDevices * 32));

I found this somewhere on the web but I am tring to understand it a
bit more. Does anyone have a reference document that defines :
[/QUOTE]
Firstly, note that this very very similar to a call from a native
program to the Winsock getsockopt function: there's little difference in
the call and no difference in the return data, so...
1. What format the data in "buffer" would be?
See
http://www.alanjmcf.me.uk/comms/infrared/Microsoft Windows IrDA programming.html#_Toc97565826

2. Why is (SocketOptionLevel)0xff used?
3. Why is SocketOptionName.DontRoute used?
See
http://www.alanjmcf.me.uk/comms/infrared/Microsoft Windows IrDA programming.html#_Toc97565825
and the contents for AF_Irda.h; nothing that:
#define SOL_IRLMP 0x00FF
...
#define IRLMP_ENUMDEVICES 0x00000010
And note that SocketOptionName.DontRoute has value 0x10.

For maintainability/understandability I would personally have written:
const int SOL_IRLMP = 0x00FF
const int IRLMP_ENUMDEVICES = 0x00000010
...
byte[] deviceList = sock.GetSocketOption(
(SocketOptionLevel))SOL_IRLMP,
(SocketOptionName)IRLMP_ENUMDEVICES,
SizeofULONG + numToDiscover*SizeofDEVICE_INFO);
(or similar :) )
The IRDA protocol I think will be TinyTP since it is windows but I'm
not sure.
Yup, see
http://www.alanjmcf.me.uk/comms/infrared/Microsoft Windows IrDA programming.html#_Toc97565837
By the way I am rolling my own code here because I want to use it on
.NET desktop not on the compact framework, so I cant use the assembly
provided there.
Well I can recommend Peter's 32feet.NET library, why reinvent the wheel?
Of course that depends on whether his license fits your needs...
 
B

BeeEmm

Alan and Peter thank you very much for your replies, I think I must be
talking to the 2 IRDA/.NET gurus. Your names appear everywhere on the
search engines.

The details provided are excellent. Alan I was put off a bit my some of
your code as it seemed to be unmanaged C++ MFC-type code. I do not have
access to AF_IrDA.h.

I have a question about a connection. When specifying the service name
in the follwoing call:

client = new IrDAClient(ServiceName);

How important is the service name? What happens with this value through
the IrDA stack and the IrDA message sent?

I have seen the following values:-
"SampleIrDAService"
"IrDAFtp"
"IrDA:IrCOMM"
"IrLPT"
....

Is this just free format text or is it interpreted?

In .NET how do you determine whether the connection will be TinyTP or
IrLMP (Non-TinyTP) mode?

Another thing I would like to clarify is the values passed to
- sock.GetSocketOption( )

What are the valid values for (SocketOptionLevel)?


Thanks,
BeeEmm
 
A

Alan J. McFarlane

Alan and Peter thank you very much for your replies, I think I must be
talking to the 2 IRDA/.NET gurus. Your names appear everywhere on the
search engines.

The details provided are excellent. Alan I was put off a bit my some
of your code as it seemed to be unmanaged C++ MFC-type code. I do not
have access to AF_IrDA.h.
[/QUOTE]
There were two pieces of code, the first was two lines of C quoted from
AF_IrDA.h just to show the correct option level and name values to
request an IrDA "enumerate devices" operation, and that they matched the
values (misnamed) in the sample you quoted.

The other bit of code was C# (with at least one typo), that showed doing
the operation and getting a byte array in return. If you prefer VB.NET,
it would be like:
Dim deviceList As byte() = sock.GetSocketOption( _
CType(SOL_IRLMP, SocketOptionLevel), _
CType(IRLMP_ENUMDEVICES, SocketOptionName), _
SizeofULONG + numToDiscover*SizeofDEVICE_INFO)
(with suitable definitions of the four constants)
I have a question about a connection. When specifying the service name
in the follwoing call:

client = new IrDAClient(ServiceName);

How important is the service name? What happens with this value
through the IrDA stack and the IrDA message sent?
Very important. When one's using TCP/IP the remote service's port
number is required, for instance 80 for HTTP, 25 for SMTP, etc etc.
IrDA locates services by name and thus the service name is required
(behind the scenes the Service Name is used to find a port number, by
querying the peer's IAS (Information Access Service) database, but in
Windows that's handled automagically by the stack).
I have seen the following values:-
"SampleIrDAService"
"IrDAFtp"
"IrDA:IrCOMM"
"IrLPT"
...
See my "IrDA uses" document
(http://www.alanjmcf.me.uk/comms/infrared/IrDA uses (brief).html)
for most of the common services one will find. If you're creating both
ends of the connection create a new one of the form "<myCorp>:<MySvc>"
e.g. "ACME:MeterReading", the max length appears to be 64 but you
shouldn't need anywhere near that length...
Is this just free format text or is it interpreted?
It's pretty much just a byte array that's compared byte by byte, but its
always ASCII really. As I noted above a query of the peer's IAS
database is carried out to find the port number, the name being in the
lookup.
In .NET how do you determine whether the connection will be TinyTP or
IrLMP (Non-TinyTP) mode?
As I noted previously, a connection is TinyTP unless set to IrLMP with
the respective socket option.
Another thing I would like to clarify is the values passed to
- sock.GetSocketOption( )

What are the valid values for (SocketOptionLevel)?
It depends which protocol stack you are delaing with. For IrDA, only
SOL_IRLMP is supported above the socket level's SOL_SOCKET, for TCP/IP
there are IPPROTO_IP and IPPROTO_TCP, see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/socket_options.asp
This is all Winsock stuff, see its documentation, or even BSD sockets
documentation... If you're not experience with sockets and socket
options that's yet another reason to use an IrDAClient class... :)

BTW MSDN's documentation of the IrDA stack is incomplete and incorrect,
use my reference...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top