Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Mon Nov 20, 2017 12:53 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Tue Jun 16, 2009 8:46 am 
Offline

Joined: Tue Jun 16, 2009 8:32 am
Posts: 6
I would like to get Raw Ethernet packets directly from Ethernet interface of a QTERM-G55, I tried to acquire packets with the following code:

Code:
'0x0800 = 2048 IP EtherType

dim proto as unibyte
init proto := 2048

dim EthernetReceiver as servercomm

func StartUp()
    handles MSG_INIT

    Enable (me, enabled)
    Attach (me, parent)
   
    EthernetReceiver = NetServerOpen(me, NET_RAW, proto)

endfunc

protected func CommReceive (data[] as byte) returns boolean
    handles MSG_COMM_RECEIVE

    return true
endfunc

protected func CommAccept (socket as comm)
    handles MSG_COMM_ACCEPT
    Label_1.value = "Connected"
    RegisterMsgHandler(me, msg_comm_receive, socket)
    return
endfunc



It compiles correctly and when uploaded to the device it seems unable to receive packets from ethernet interface. The same code, with the NET_UDP option, works correctly.

Is the NET_RAW option actually supported?
Can anybody help me?

Thanks a lot.

Andrea Trivisonno
Gruppo Sigla S.r.l.
Via Finocchiaro Aprile 31/5a
16129 Genova
Italy


Top
 Profile  
 
PostPosted: Tue Jun 16, 2009 8:56 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
NET_RAW requires 2.600 firmware or higher to function. Please make sure you are using at least 2.600. The NET_RAW option was in earlier versions as a place holder, but did not function.

Also, please be aware that NET_RAW is not simulated in any version of Qlarity Foundry.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Tue Jun 16, 2009 9:10 am 
Offline

Joined: Tue Jun 16, 2009 8:32 am
Posts: 6
Thank you for your quick answer, better than Messenger :)

I'm using the 2.600 firmware and I've also tried the 2.601b firmware downloaded from this URL:

http://www.qsicorp.com/engfiles/bleeding_edge/QlarityFoundry_Pre_2.61_TestBuild_4.zip

I've uploaded the 2.601b firmware to the QTERM and than uploaded the application to test, directly on the device in Development mode.

Unfortunately, it wasn't enough to solve my problem. The application still doesn't receive packets from ethernet intarface.

Do you have any example of NET_RAW usage?


Top
 Profile  
 
PostPosted: Tue Jun 16, 2009 2:07 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
I have not yet used NET_RAW myself. I have been trying to track down the engineer who tested that mode to see what sample code he has. However, he is out today. I do know that it was tested and some customers have successfully used it.

If you want my gut guess, you probably want to do NetServerOpen and open a server channel to accept all incoming Ethernet frames.

The documentation was modified in 2.6 to discuss (briefly) NET_RAW. Perhaps this could help:

Quote:
When NetOpen() is used with the NET_RAW protocol (for raw access to the Layer 2 interface), localport should contain the desired Ethertype field contents. foreignport is not used and should be set to any non-zero value. To create NET_RAW listening servers, use the NetServerOpen() API function. Up to 64 channels (32 TCP channels) may be open at any given time. Channels may be released by calling NetClose().
Quote:

When NetServerOpen() is used with the NET_RAW protocol (for raw access to the Layer 2 interface), localport should contain the desired Ethertype field contents. In this case, inbound network packets with Ethertype fields that match the specified localport are accepted. Up to 64 channels (32 TCP channels) may be open at any given time. Channels may be released by calling NetClose(). The server will continue to listen on the specified local port until it is closed by calling the NetServerClose() API function.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Wed Jun 17, 2009 12:25 am 
Offline

Joined: Tue Jun 16, 2009 8:32 am
Posts: 6
Thanks, I've read the 2.6 documentation about the NET_RAW.
I'm using the NET_RAW socket in the same way as NET_TCP and NET_UDP, opening channel with NetServerOpen and registering the MSG_COMM_RECEIVE when the application receive the MSG_COMM_ACCEPT message.
Is the procedure correct?

We need the NET_RAW option enabled because the QTERM-G55 must send command directly to a device that doesn't support TCP/IP or UDP/IP stack.

Thanks in advance for your help.


Top
 Profile  
 
PostPosted: Wed Jun 17, 2009 7:04 am 
Offline

Joined: Tue Jun 16, 2009 8:32 am
Posts: 6
I've successfully sent one single ethernet raw packet, using the NetOpen and passing to this function the MAC destination addres instead of the IP address, with a longer array of 6 integer. The function set correctly the EtherType field, but only for well known EtherType such as ARP or IP.
This is a small piece of the code of my application:

Code:

dim EthSendChannel as comm
init EthSendChannel := COM_INVALID

dim proto as unibyte
init proto := 2048
'IP EtherType

dim ipaddr[] as byte
init ipaddr := [0, 35, 125, 74, 115, 47]
'MAC address, not IP address

NetOpen(me, NET_RAW, proto, proto, ipaddr)

protected func CommAccept (socket as comm)
    handles MSG_COMM_ACCEPT

    if EthSendChannel == COM_INVALID then
        Connesso()
        EthSendChannel = socket
        RegisterMsgHandler(me, msg_comm_receive, socket)
        Transmit(EthSendChannel, "abcdefghilmnopqrstuvz", false)
        return
    endif
endfunc

protected func CommReceive (data[] as byte) returns boolean
    handles MSG_COMM_RECEIVE
    ListenToEthernet()
    return true
endfunc



With Wireshark, I can se the the packet sniffing on the destination ethernet card set up by ipaddr[] array.
But when I send packet to the QTERM, it doesn't call the ListenToEthernet() function.

I've also tried to open another NET_RAW server channel with NetServerOpen on MSG_COMM_ACCEPT callback, but it deosn't seem to work correctly.

The Transmit() function works correctly with EtherType like IP or ARP, but doesn't work with custom ethertype, for example 0xABCD = 43981.

Any help appreciated.
Thanks in advance.


Top
 Profile  
 
PostPosted: Wed Jun 17, 2009 9:08 am 
Offline

Joined: Tue Jun 16, 2009 8:32 am
Posts: 6
There is another problem with the NET_RAW connection.
I've sent a packet with the Transmit() API function, over a connection previously created with NetOpen() and with the EtherType value 0x8000 that means IP packet.
I've captured the packet with Wireshark and the Transmit() function wrote automatically the IP packet size in the the bytes array where IP protocol writes IP packet length, even if I've set up a RAW connection, that resulted in a corruption of the byte array.

Is the NET_RAW socket actually supported by > 2.600 firmware?
I really need this function to set up a communication with a custom ethernet based protocol.

Thans in advance.


Top
 Profile  
 
PostPosted: Wed Jun 17, 2009 2:48 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
I apologize for the delay in this response. I have spent a fair portion of today playing with NET_RAW and making sure that it works.

NET_RAW has been a placeholder in our networking support since the original release of Qlarity. Almost as an afterthought, we added minimal NET_RAW support to 2.600. The documentation was barely touched with this feature and is severely lacking. I am working on that right now.

I have learned a number of key things about NET_RAW support that may be of use to you.

First of all, NET_RAW will not work properly with IP, ARP, or RARP. Those frames, on receipt, are sent to the network stack regardless of whether you are trying to receive them via NetOpen/NetServerOpen and NET_RAW. (I have submitted a bug report to have those APIs either throw when you attempt to use those values, or to properly give the Qlarity application priority on them when using NET_RAW). On Transmit, those frames may receive the appropriate IP, ARP or RARP headers.

Do not attempt to use the deprecated NetOpen syntax (of using a foreign port of 0) to open a server. It is not reliable. I have submitted a request to have NetOpen throw if you attempt this.

There is a bug with GetNetChannelInfo with NET_RAW, where the returned "IP address" is limited to the first four bytes of the sending MAC address.

Small Ethernet frames (i.e. those less than the minimum transmission unit) are automatically padded with garbage to reach the minimum Ethernet frame length. Your protocol will have to deal with that case.

When sending you specify the payload only (i.e. everything after the EtherType field and before the CRC field).

When receiving you will only receive the payload. The EtherType is implicit based on how you opened the communication channel. The source MAC can be obtained via a call to GetNetChannelInfo. (subject to the bug I mentioned earlier). The destination MAC cannot currently be obtained (but should be either the MAC of the G55 or a broadcast MAC).

I have attached a workspace that demonstrates this communication. It is EXTREMELY quick and dirty. Don't expect too much from it. Much error checking and quality of life stuff is missing. However, there is a simple client and simple server object in it.


Attachments:
File comment: Sample Qlarity NET_RAW workspace
delme.qly [13.78 KiB]
Downloaded 184 times

_________________
Jeremy
http://www.beijerinc.com
Top
 Profile  
 
PostPosted: Thu Jun 18, 2009 6:51 am 
Offline

Joined: Tue Jun 16, 2009 8:32 am
Posts: 6
Thanks a lot! :D Now It works.
I've succesfully sent one custom ethernet packet from my PC to the QTERM-G55 and then get one back.

Only one more question, does the QTERM-G55 support promiscuos mode for ethernet interface?

Thanks in advance.


Top
 Profile  
 
PostPosted: Thu Jun 18, 2009 6:56 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
To complete the circuit, the documentation has been modified as follows:

NET_RAW Information Only

When NetOpen() is used with the NET_RAW protocol (for raw access to the Layer 2 interface), the following information applies.
  • localport should contain the desired EtherType field contents. IP (0x0800), ARP (0x0806) and RARP (0x8035) are not supported and will cause unpredictable results
  • foreignport is not used and should be set to any non-zero value. (Setting this value to zero will cause unpredictable results).
  • ipaddr is the 6 byte MAC address of the destination device.
  • To create NET_RAW listening servers, use the NetServerOpen() API function.
  • When transmitting, if the amount of data you transmit would result in a Ethernet frame that is smaller than the minimum frame, the transmitted data will be padded with random bytes.
  • When transmitting you specify the Ethernet payload (the portion of the frame that falls after the EtherType field and before the CRC field). The source MAC, destination MAC, EtherType and CRC fields are filled automatically.
  • When receiving, you will receive the Ethernet payload only (see the previous item). You can call GetNetChannelInfo to determine the source MAC address.
  • NET_RAW may be deprecated on select hardware platforms in the future. If you plan to use NET_RAW, please ask your Qlarity support contact about the status of your specific hardware platform. NET_TCP and NET_UDP have no plans for deprecation.

We have flagged GetNetChannelInfo to be fixed for the next release (2.61). We would also like to either fix NetOpen/NetServerOpen to allow you to open the IP,ARP and RARP EtherTypes or to have the API throw if you attempt to do so. Which solution we select will depend on how invasive the changes are that would be needed to support overriding the

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Thu Jun 18, 2009 7:08 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
No, there is currently no way to from your Qlarity application to force the MAC interface to enter promiscuous mode.

The unit was never really intended as a protocol analyzer, and I cannot imagine that it would keep up very well as a protocol analyzer in any environment with a non-trivial amount of traffic.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Thu Jun 18, 2009 7:13 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Also, there are no plans to discontinue NET_RAW on the G55. There are actually no firm plans to directly discontinue NET_RAW on any platform. However some of our future design plans for some other platforms may make NET_RAW difficult to support, and we cannot say at this time if we will continue to support it everywhere.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group